Prompt specification
Build or customize the Three.js 3D scene "Naqsh-e Jahan arcade bay and water-channel edge" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Naqsh-e Jahan arcade bay and water-channel edge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/naqsh-e-jahan-arcade-bay-and-water-channel-edge-x2917
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: Naqsh-e Jahan arcade bay and water-channel edge. Build a referenced arcade fragment beside a shallow channel and paved path. Simplify ornament while preserving the distinction between sheltered perimeter and open square. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (naqsh-e-jahan-arcade-bay-and-water-channel-edge-x2917):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Naqsh-e Jahan — Voxel Arcade Fragment</title>
<style>
:root {
--ink: #263c3d;
--muted: #607273;
--paper: rgba(248, 244, 231, 0.9);
--line: rgba(38, 60, 61, 0.17);
--tile: #287d8c;
--water: #66b8b6;
--stone: #b99e72;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd7d3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 45%, rgba(40, 57, 55, 0.12) 115%),
linear-gradient(to bottom, rgba(255, 255, 255, 0.04), rgba(60, 73, 66, 0.06));
}
.title-card {
position: fixed;
top: 22px;
left: 22px;
max-width: min(370px, calc(100vw - 44px));
padding: 16px 18px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(39, 56, 53, 0.12);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--tile);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
}
.subtitle {
margin: 8px 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #4d6262;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.controls-card {
position: fixed;
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 10px 28px rgba(39, 56, 53, 0.11);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.controls-card strong {
color: var(--ink);
font-weight: 750;
}
button {
padding: 8px 11px;
border: 1px solid rgba(38, 60, 61, 0.22);
border-radius: 8px;
background: #f7f1df;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fff9e9;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
padding: 13px 14px;
}
.subtitle {
margin-bottom: 9px;
}
.legend {
gap: 6px 10px;
}
.controls-card {
right: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<div class="title-card">
<div class="eyebrow">Isfahan · Architectural voxel study</div>
<h1>Naqsh-e Jahan</h1>
<p class="subtitle">
A simplified arcade fragment beside the shallow water channel and paved promenade.
</p>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch" style="background:#c7ac7c"></i>Sheltered arcade</span>
<span><i class="swatch" style="background:#68b8b7"></i>Water channel</span>
<span><i class="swatch" style="background:#aa8e65"></i>Paved path</span>
</div>
</div>
<div class="controls-card">
<span><strong>Drag</strong> orbit · <strong>Wheel</strong> zoom · <strong>Right-drag</strong> pan · <strong>Double-click</strong> reset</span>
<button id="reset" type="button">Reset view</button>
</div>
<div class="vignette"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd7d3);
scene.fog = new THREE.Fog(0xcbd7d3, 40, 78);
const camera = new THREE.OrthographicCamera(-20, 20, 13, -13, 0.1, 140);
const hemisphere = new THREE.HemisphereLight(0xe7f2ef, 0x8d7657, 1.55);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.25);
sun.position.set(-13, 25, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 23;
sun.shadow.camera.bottom = -23;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd7dc, 0.72);
fill.position.set(18, 12, -15);
scene.add(fill);
// ---------------------------------------------------------------------
// Shared materials and geometry helpers
// ---------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const tempObject = new THREE.Object3D();
const tempColor = new THREE.Color();
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
base: standard(0x776f5d),
earth: standard(0xb4a17a),
paleStone: standard(0xd7c29b),
warmStone: standard(0xc6ac7c),
midStone: standard(0xae9165),
darkStone: standard(0x705d48),
recess: standard(0x554b40),
navy: standard(0x244c62),
teal: standard(0x287e8e),
brightTeal: standard(0x48a5a8),
gold: standard(0xb28a46),
wood: standard(0x6c4c34),
darkWood: standard(0x48372c),
soil: standard(0x73654d),
foliage: standard(0x355b45),
foliageLight: standard(0x496e4f),
bronze: standard(0x3c4841),
lamp: standard(0xffbd61, {
emissive: 0xff8b24,
emissiveIntensity: 1.2,
roughness: 0.5
}),
water: standard(0x58aeb1, {
transparent: true,
opacity: 0.87,
roughness: 0.23,
metalness: 0.04,
depthWrite: false
}),
ripple: new THREE.MeshBasicMaterial({
color: 0xd8f0df,
transparent: true,
opacity: 0.32,
depthWrite: false
})
};
function addBox(w, h, d, x, y, z, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
function addInstances(items, material, options = {}) {
if (!items.length) return null;
const {
cast = true,
receive = true
} = options;
const mesh = new THREE.InstancedMesh(unitBox, material, items.length);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
for (let i = 0; i < items.length; i++) {
const item = items[i];
tempObject.position.set(item.x, item.y, item.z);
tempObject.scale.set(item.sx, item.sy, item.sz);
tempObject.rotation.set(0, item.ry || 0, 0);
tempObject.updateMatrix();
mesh.setMatrixAt(i, tempObject.matrix);
if (item.color !== undefined) {
if (item.color instanceof THREE.Color) {
tempColor.copy(item.color);
} else {
tempColor.set(item.color);
}
mesh.setColorAt(i, tempColor);
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
let randomSeed = 71839;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function variedStone(base = 0xc7ae81, amount = 0.18) {
const color = new THREE.Color(base);
color.multiplyScalar(0.88 + random() * amount);
color.offsetHSL((random() - 0.5) * 0.012, (random() - 0.5) * 0.035, 0);
return color;
}
// ---------------------------------------------------------------------
// Diorama base
// ---------------------------------------------------------------------
addBox(31.4, 0.68, 21.7, 0, -0.40, 0.25, materials.base);
addBox(30.9, 0.13, 21.15, 0, -0.015, 0.25, materials.earth);
const infiniteGround = new THREE.Mesh(
new THREE.PlaneGeometry(150, 150),
standard(0xb8c9c1, { roughness: 1 })
);
infiniteGround.rotation.x = -Math.PI / 2;
infiniteGround.position.y = -0.76;
infiniteGround.receiveShadow = true;
scene.add(infiniteGround);
// ---------------------------------------------------------------------
// Open-square paving: broad, pale, and sunlit
// ---------------------------------------------------------------------
const squarePavers = [];
const squareTileX = 1.25;
const squareTileZ = 1.23;
for (let ix = 0; ix < 24; ix++) {
for (let iz = 0; iz < 5; iz++) {
squarePavers.push({
x: -15 + squareTileX * (ix + 0.5),
y: 0.115,
z: -5.15 + squareTileZ * (iz + 0.5),
sx: 1.205,
sy: 0.11,
sz: 1.185,
color: variedStone(0xd4c099, 0.13)
});
}
}
addInstances(squarePavers, standard(0xffffff));
// ---------------------------------------------------------------------
// Narrower, darker promenade beside the water channel
// ---------------------------------------------------------------------
const pathPavers = [];
const pathTileZ = 0.61;
for (let ix = 0; ix < 24; ix++) {
for (let iz = 0; iz < 4; iz++) {
pathPavers.push({
x: -15 + squareTileX * (ix + 0.5),
y: 0.12,
z: 3.60 + pathTileZ * (iz + 0.5),
sx: 1.205,
sy: 0.12,
sz: 0.575,
color: variedStone(0xa78b63, 0.17)
});
}
}
addInstances(pathPavers, standard(0xffffff));
// Sparse foreground blocks keep the scene reading as an architectural fragment.
const foregroundStones = [];
for (let i = 0; i < 26; i++) {
foregroundStones.push({
x: -14 + random() * 28,
y: 0.10,
z: 6.5 + random() * 3.6,
sx: 0.35 + random() * 0.75,
sy: 0.12,
sz: 0.25 + random() * 0.5,
ry: (random() - 0.5) * 0.08,
color: variedStone(0xb4a07b, 0.18)
});
}
addInstances(foregroundStones, standard(0xffffff));
// ---------------------------------------------------------------------
// Shallow channel, stone curbs, and animated ripple marks
// ---------------------------------------------------------------------
addBox(30.5, 0.18, 1.95, 0, 0.02, 2.35, standard(0x315f62));
addBox(30.1, 0.065, 1.68, 0, 0.135, 2.35, materials.water, false, false);
const curbBlocks = [];
for (let x = -14.75; x < 15; x += 0.95) {
curbBlocks.push({
x,
y: 0.19,
z: 1.32,
sx: 0.91,
sy: 0.30,
sz: 0.34,
color: variedStone(0xceb68b, 0.13)
});
curbBlocks.push({
x: x + 0.475,
y: 0.19,
z: 3.39,
sx: 0.91,
sy: 0.30,
sz: 0.34,
color: variedStone(0xc4a97d, 0.13)
});
}
addInstances(curbBlocks, standard(0xffffff));
const ripples = [];
for (let i = 0; i < 18; i++) {
const ripple = addBox(
0.65 + random() * 0.9,
0.012,
0.025 + random() * 0.025,
-15 + random() * 30,
0.176,
1.72 + random() * 1.25,
materials.ripple,
false,
false
);
ripple.userData.speed = 0.42 + random() * 0.55;
ripple.userData.offset = random() * 30;
ripples.push(ripple);
}
// ---------------------------------------------------------------------
// Arcade: five deep, pointed, voxel-built bays
// ---------------------------------------------------------------------
const bayCount = 5;
const bayWidth = 3.8;
const bayCenters = [];
const facadeZ = -7.05;
const voxelSize = 0.31;
const facadeColumns = 12;
const facadeRows = 18;
for (let bay = 0; bay < bayCount; bay++) {
bayCenters.push(-7.6 + bay * bayWidth);
}
function openingHalfWidth(y) {
const springHeight = 2.46;
const apexHeight = 4.42;
if (y >= apexHeight) return 0;
if (y <= springHeight) return 1.38;
const t = (apexHeight - y) / (apexHeight - springHeight);
return Math.max(0, 1.38 * t);
}
const facadeBlocks = [];
for (const centerX of bayCenters) {
for (let row = 0; row < facadeRows; row++) {
const y = (row + 0.5) * voxelSize;
const halfWidth = openingHalfWidth(y);
for (let column = 0; column < facadeColumns; column++) {
const localX = (column + 0.5) * voxelSize - facadeColumns * voxelSize / 2;
// Leave the pointed opening empty.
if (halfWidth > 0 && Math.abs(localX) < halfWidth) continue;
facadeBlocks.push({
x: centerX + localX,
y,
z: facadeZ,
sx: voxelSize * 0.985,
sy: voxelSize * 0.985,
sz: 0.52,
color: variedStone(0xc7ad7d, 0.18)
});
}
}
}
addInstances(facadeBlocks, standard(0xffffff));
// Turquoise arch borders, deliberately simplified into pixel courses.
const archTiles = [];
for (const centerX of bayCenters) {
for (let row = 0; row < 14; row++) {
const y = (row + 0.5) * voxelSize;
const halfWidth = openingHalfWidth(y);
if (halfWidth <= 0) continue;
const tileColor = row % 3 === 0 ? 0x2b8494 : (row % 3 === 1 ? 0x20536a : 0x48a0a4);
archTiles.push({
x: centerX - halfWidth,
y,
z: facadeZ + 0.335,
sx: 0.23,
sy: 0.285,
sz: 0.14,
color: tileColor
});
archTiles.push({
x: centerX + halfWidth,
y,
z: facadeZ + 0.335,
sx: 0.23,
sy: 0.285,
sz: 0.14,
color: tileColor
});
}
archTiles.push({
x: centerX,
y: 4.45,
z: facadeZ + 0.34,
sx: 0.34,
sy: 0.22,
sz: 0.15,
color: 0x2b8494
});
}
addInstances(archTiles, standard(0xffffff));
// Projecting pilasters emphasize the sheltered perimeter.
const boundaries = [];
for (let i = 0; i <= bayCount; i++) {
boundaries.push(-9.5 + i * bayWidth);
}
for (const x of boundaries) {
addBox(0.54, 0.38, 0.76, x, 0.30, facadeZ + 0.20, materials.paleStone);
addBox(0.34, 4.15, 0.39, x, 2.61, facadeZ + 0.24, materials.warmStone);
addBox(0.56, 0.24, 0.60, x, 4.77, facadeZ + 0.23, materials.teal);
addBox(0.61, 0.18, 0.67, x, 4.97, facadeZ + 0.22, materials.paleStone);
}
// Upper tile frieze.
const friezeTiles = [];
for (let x = -9.25; x <= 9.25; x += 0.31) {
friezeTiles.push({
x,
y: 5.25,
z: facadeZ + 0.35,
sx: 0.285,
sy: 0.25,
sz: 0.17,
color: Math.round(x * 10) % 2 === 0 ? 0x2b8190 : 0x3f9b9e
});
}
addInstances(friezeTiles, standard(0xffffff));
// Deep roof slab and stepped cornice: the arcade casts a broad shadow.
addBox(20.35, 0.31, 1.86, 0, 5.73, -7.35, materials.paleStone);
addBox(20.65, 0.25, 0.38, 0, 5.58, -6.41, materials.warmStone);
addBox(20.10, 0.18, 0.28, 0, 5.91, -6.39, materials.teal);
const parapets = [];
for (let x = -9.7; x <= 9.7; x += 0.62) {
parapets.push({
x,
y: 6.04,
z: -7.38,
sx: 0.45,
sy: 0.34,
sz: 0.45,
color: variedStone(0xd0b98d, 0.13)
});
}
addInstances(parapets, standard(0xffffff));
// Recess, floor, and end walls.
addBox(20.25, 5.48, 0.28, 0, 2.77, -8.43, materials.recess);
addBox(20.25, 0.15, 2.05, 0, 0.10, -7.53, materials.darkStone);
addBox(0.34, 5.42, 1.80, -9.72, 2.74, -7.51, materials.midStone);
addBox(0.34, 5.42, 1.80, 9.72, 2.74, -7.51, materials.midStone);
// Simple stepped threshold between the shaded arcade and open square.
addBox(19.9, 0.24, 0.80, 0, 0.12, -6.24, materials.paleStone);
addBox(19.9, 0.12, 0.55, 0, 0.06, -5.78, materials.warmStone);
// ---------------------------------------------------------------------
// Recessed shop bays and lanterns
// ---------------------------------------------------------------------
const interiorLamps = [];
bayCenters.forEach((centerX, index) => {
// Recessed door and frame.
addBox(1.47, 2.86, 0.10, centerX, 1.53, -8.255, materials.navy);
addBox(1.15, 2.58, 0.08, centerX, 1.43, -8.18, materials.darkWood);
addBox(0.10, 2.74, 0.12, centerX - 0.66, 1.52, -8.14, materials.brightTeal);
addBox(0.10, 2.74, 0.12, centerX + 0.66, 1.52, -8.14, materials.brightTeal);
addBox(1.43, 0.11, 0.12, centerX, 2.91, -8.13, materials.brightTeal);
// Upper lattice window.
addBox(1.27, 0.80, 0.08, centerX, 3.83, -8.19, materials.navy);
for (let bar = -1; bar <= 1; bar++) {
addBox(0.055, 0.78, 0.10, centerX + bar * 0.30, 3.83, -8.12, materials.gold, false, false);
}
addBox(1.28, 0.06, 0.10, centerX, 3.83, -8.11, materials.gold, false, false);
// Stall counter and small goods.
addBox(2.12, 0.78, 0.58, centerX, 0.55, -7.83, materials.wood);
addBox(2.22, 0.11, 0.69, centerX, 0.98, -7.83, materials.midStone);
addBox(0.34, 0.24, 0.28, centerX - 0.55, 1.16, -7.80, materials.teal);
addBox(0.27, 0.22, 0.24, centerX + 0.20, 1.15, -7.82, materials.gold);
addBox(0.32, 0.18, 0.26, centerX + 0.67, 1.12, -7.80, materials.navy);
// Hanging lantern.
addBox(0.035, 0.65, 0.035, centerX, 4.26, -7.12, materials.bronze, false, false);
addBox(0.29, 0.36, 0.29, centerX, 3.79, -7.12, materials.lamp);
addBox(0.36, 0.07, 0.36, centerX, 3.99, -7.12, materials.bronze);
if (index % 2 === 0) {
const point = new THREE.PointLight(0xffa54c, 5.5, 4.8, 2);
point.position.set(centerX, 3.65, -7.15);
scene.add(point);
interiorLamps.push(point);
}
});
// ---------------------------------------------------------------------
// Edge trees, lamps, benches, and small figures for scale
// ---------------------------------------------------------------------
function addCypress(x, z) {
addBox(1.48, 0.34, 1.48, x, 0.31, z, materials.paleStone);
addBox(1.22, 0.08, 1.22, x, 0.51, z, materials.soil, false, true);
addBox(0.22, 2.65, 0.22, x, 1.76, z, materials.wood);
const levels = [
{ y: 1.58, w: 1.20, h: 0.68, d: 1.20 },
{ y: 2.10, w: 1.08, h: 0.70, d: 1.08 },
{ y: 2.64, w: 0.92, h: 0.72, d: 0.92 },
{ y: 3.18, w: 0.73, h: 0.70, d: 0.73 },
{ y: 3.69, w: 0.52, h: 0.62, d: 0.52 },
{ y: 4.13, w: 0.30, h: 0.48, d: 0.30 }
];
levels.forEach((level, index) => {
addBox(
level.w,
level.h,
level.d,
x + (index % 2 ? 0.035 : -0.025),
level.y,
z,
index % 2 ? materials.foliage : materials.foliageLight
);
});
}
addCypress(12.6, -3.65);
addCypress(-13.0, -1.95);
function addPathLamp(x, z) {
addBox(0.43, 0.18, 0.43, x, 0.28, z, materials.bronze);
addBox(0.13, 2.58, 0.13, x, 1.57, z, materials.bronze);
addBox(0.37, 0.08, 0.37, x, 2.91, z, materials.bronze);
addBox(0.28, 0.40, 0.28, x, 3.15, z, materials.lamp);
addBox(0.38, 0.09, 0.38, x, 3.39, z, materials.bronze);
}
[-11.5, -4.0, 4.0, 11.5].forEach(x => addPathLamp(x, 5.24));
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
const seat = new THREE.Mesh(unitBox, materials.wood);
seat.scale.set(1.85, 0.12, 0.42);
seat.position.y = 0.66;
seat.castShadow = true;
seat.receiveShadow = true;
group.add(seat);
const back = new THREE.Mesh(unitBox, materials.wood);
back.scale.set(1.85, 0.54, 0.11);
back.position.set(0, 0.96, -0.20);
back.castShadow = true;
group.add(back);
for (const side of [-0.68, 0.68]) {
const leg = new THREE.Mesh(unitBox, materials.bronze);
leg.scale.set(0.10, 0.58, 0.32);
leg.position.set(side, 0.38, 0);
leg.castShadow = true;
group.add(leg);
}
group.position.set(x, 0.16, z);
group.rotation.y = rotation;
scene.add(group);
}
addBench(-5.7, -5.67, 0);
addBench(5.7, -5.67, 0);
function addPerson(x, z, shirtColor, trouserColor, rotation = 0, scale = 1) {
const group = new THREE.Group();
const pieces = [
{ w: 0.16, h: 0.52, d: 0.18, x: -0.12, y: 0.31, z: 0, mat: trouserColor },
{ w: 0.16, h: 0.52, d: 0.18, x: 0.12, y: 0.31, z: 0, mat: trouserColor },
{ w: 0.43, h: 0.62, d: 0.26, x: 0.00, y: 0.86, z: 0, mat: shirtColor },
{ w: 0.11, h: 0.48, d: 0.14, x: -0.28, y: 0.83, z: 0, mat: shirtColor },
{ w: 0.11, h: 0.48, d: 0.14, x: 0.28, y: 0.83, z: 0, mat: shirtColor },
{ w: 0.28, h: 0.28, d: 0.28, x: 0.00, y: 1.35, z: 0, mat: 0xb98562 }
];
for (const piece of pieces) {
const mesh = new THREE.Mesh(unitBox, standard(piece.mat));
mesh.scale.set(piece.w, piece.h, piece.d);
mesh.position.set(piece.x, piece.y, piece.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
group.position.set(x, 0.18, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
}
addPerson(-3.8, -2.65, 0x2e7582, 0x655444, 0.35, 1.05);
addPerson(-2.9, -2.25, 0xa45f4e, 0x424c4d, -0.55, 0.95);
addPerson(2.4, -3.45, 0xd7b35f, 0x78604b, 0.8, 1.08);
addPerson(7.9, -0.55, 0x536b91, 0x4c4d49, -0.3, 0.92);
addPerson(-8.2, 0.10, 0x5b8d68, 0x765b47, 0.4, 1.0);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, pinch, and reset
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 1.85, -0.05);
const defaultTarget = target.clone();
let theta = 0.68;
let phi = 0.78;
let zoom = 1;
const cameraRadius = 34;
function applyCameraProjection() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(12.7, 19.0 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + cameraRadius * sinPhi * Math.sin(theta),
target.y + cameraRadius * Math.cos(phi),
target.z + cameraRadius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetView() {
theta = 0.68;
phi = 0.78;
zoom = 1;
target.copy(defaultTarget);
applyCameraProjection();
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
mode: event.pointerType === "mouse" && (event.button === 2 || event.shiftKey)
? "pan"
: "orbit"
});
if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
if (pointers.size === 1) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.mode === "orbit") {
theta -= dx * 0.005;
phi = THREE.MathUtils.clamp(phi - dy * 0.0045, 0.32, 1.37);
} else {
const scale = 0.027 / zoom;
const right = new THREE.Vector3(Math.cos(theta), 0, -Math.sin(theta));
const forward = new THREE.Vector3(Math.sin(theta), 0, Math.cos(theta));
target.addScaledVector(right, -dx * scale);
target.addScaledVector(forward, dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -12, 12);
target.z = THREE.MathUtils.clamp(target.z, -12, 12);
}
updateCamera();
} else if (pointers.size === 2) {
const oldDistance = pointerDistance();
pointer.x = event.clientX;
pointer.y = event.clientY;
const newDistance = pointerDistance();
if (oldDistance > 0 && newDistance > 0) {
zoom = THREE.MathUtils.clamp(zoom * (newDistance / oldDistance), 0.62, 1.85);
applyCameraProjection();
updateCamera();
}
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("pointerleave", event => {
if (event.buttons === 0) releasePointer(event);
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.85
);
applyCameraProjection();
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
applyCameraProjection();
updateCamera();
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const ripple of ripples) {
const travel = (elapsed * ripple.userData.speed + ripple.userData.offset) % 31;
ripple.position.x = -15.5 + travel;
ripple.material.opacity = 0.19 + 0.14 * (0.5 + 0.5 * Math.sin(elapsed * 1.6 + ripple.position.z));
}
interiorLamps.forEach((lamp, index) => {
lamp.intensity = 5.2 + Math.sin(elapsed * 2.1 + index * 1.7) * 0.35;
});
renderer.render(scene, camera);
}
applyCameraProjection();
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```