Prompt specification
Build or customize the Three.js 3D scene "Apartment moving-day cutaway" 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: Apartment moving-day cutaway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/apartment-moving-day-cutaway-x3883
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: apartment moving-day cutaway. Build a small old apartment and new apartment linked by a loading zone; movers carry a limited set of recognizable objects along continuous uncluttered routes.
Working Three.js Starter (apartment-moving-day-cutaway-x3883):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Between Two Homes — Voxel Moving Day</title>
<style>
:root {
--ink: #263331;
--muted: #64716e;
--paper: rgba(250, 248, 239, 0.9);
--accent: #e9a63a;
--green: #398d78;
--line: rgba(38, 51, 49, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e1dc;
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;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(38, 51, 49, 0.12);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(233, 166, 58, 0.16);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
max-width: 330px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.scene-card {
position: absolute;
top: 24px;
right: 24px;
min-width: 210px;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(38, 51, 49, 0.1);
backdrop-filter: blur(14px);
}
.scene-card strong {
display: block;
margin-bottom: 9px;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.item-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.chip {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.55);
color: #4d5c58;
font-size: 11px;
font-weight: 700;
}
.chip::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
border-radius: 2px;
background: var(--chip, var(--green));
vertical-align: 1px;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 11px;
padding: 10px 13px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(38, 51, 49, 0.08);
backdrop-filter: blur(12px);
}
button:hover {
background: #fffdf6;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: absolute;
left: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--paper);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(12px);
}
.hint b {
color: var(--ink);
}
@media (max-width: 760px) {
.title-card {
top: 14px;
left: 14px;
width: min(330px, calc(100vw - 28px));
padding: 15px 16px;
}
.scene-card {
top: auto;
right: 14px;
bottom: 64px;
min-width: 0;
}
.scene-card strong,
.subtitle {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 190px);
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<div class="eyebrow">
<span class="live-dot"></span>
Voxel moving day
</div>
<h1>Between Two Homes</h1>
<p class="subtitle">
A small apartment transition, seen in cutaway. Three movers keep the
sofa, refrigerator, and chair on one continuous, obstacle-free route.
</p>
</section>
<aside class="scene-card">
<strong>Moving inventory</strong>
<div class="item-row">
<span class="chip" style="--chip:#d59b39">Sofa</span>
<span class="chip" style="--chip:#78a9c1">Refrigerator</span>
<span class="chip" style="--chip:#5a9d79">Armchair</span>
</div>
</aside>
<div class="hint">
<b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Shift-drag</b> pan
</div>
<div class="controls">
<button id="pause" type="button">Pause movers</button>
<button id="reset" type="button">Reset view</button>
</div>
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e1dc);
scene.fog = new THREE.Fog(0xd9e1dc, 34, 72);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const target = new THREE.Vector3(0, 0.8, 0);
const desiredTarget = target.clone();
const view = {
theta: 0.57,
phi: 1.03,
radius: 27
};
const desiredView = {
theta: view.theta,
phi: view.phi,
radius: view.radius
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff6e6, 0x60726d, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d0, 3.2);
sun.position.set(-12, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9dceb, 1.1);
fill.position.set(15, 9, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Voxel helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(parent, size, position, color, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
typeof color === "string" || typeof color === "number" ? material(color) : color
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function labelSprite(text, background, foreground, width = 3.4) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(8, 8, 624, 134, 24);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,.34)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 54px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 76);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 150 / 640, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Ground, floors, and apartment shells
// ---------------------------------------------------------------------
box(scene, [29, 0.4, 12], [0, -0.28, 0], 0xb9c5be);
box(scene, [28.6, 0.05, 11.6], [0, -0.055, 0], 0xcbd4cc);
// Old apartment floor.
box(scene, [9.7, 0.18, 7.4], [-7.8, 0.015, 0], 0xb98562);
box(scene, [9.45, 0.04, 7.15], [-7.8, 0.12, 0], 0xc99570);
// New apartment floor.
box(scene, [9.7, 0.18, 7.4], [7.8, 0.015, 0], 0xb8c7c1);
box(scene, [9.45, 0.04, 7.15], [7.8, 0.12, 0], 0xcbd9d2);
// Loading zone.
box(scene, [5.8, 0.18, 7.4], [0, 0.015, 0], 0x9faaa4);
box(scene, [5.55, 0.04, 7.15], [0, 0.12, 0], 0xb8c0b9);
// Subtle plank/tile seams.
for (let x = -12.1; x <= -3.5; x += 0.72) {
box(scene, [0.025, 0.018, 7.05], [x, 0.145, 0], 0xa86e4f);
}
for (let x = 4.2; x <= 11.5; x += 0.72) {
box(scene, [0.025, 0.018, 7.05], [x, 0.145, 0], 0xaabbb3);
}
for (let z = -2.8; z <= 2.8; z += 0.9) {
box(scene, [5.4, 0.018, 0.025], [0, 0.145, z], 0x9da8a1);
}
const oldWall = 0xe6d4b7;
const oldWallSide = 0xd9c29f;
const newWall = 0xd9e6df;
const newWallSide = 0xc4d5cd;
// Back walls.
box(scene, [9.7, 2.7, 0.24], [-7.8, 1.48, -3.78], oldWall);
box(scene, [9.7, 2.7, 0.24], [7.8, 1.48, -3.78], newWall);
// Cutaway outer walls.
box(scene, [0.24, 1.25, 7.45], [-12.68, 0.74, 0], oldWallSide);
box(scene, [0.24, 1.25, 7.45], [12.68, 0.74, 0], newWallSide);
// Entrance wall segments, leaving a wide continuous doorway.
box(scene, [0.22, 1.25, 3.52], [-2.95, 0.74, -1.98], oldWallSide);
box(scene, [0.22, 1.25, 3.52], [2.95, 0.74, -1.98], newWallSide);
// Door frames and lintels.
for (const x of [-2.95, 2.95]) {
const frameColor = x < 0 ? 0x8c5f43 : 0x71958a;
box(scene, [0.32, 2.25, 0.18], [x, 1.23, -0.18], frameColor);
box(scene, [0.32, 2.25, 0.18], [x, 1.23, 3.58], frameColor);
box(scene, [0.32, 0.18, 3.94], [x, 2.28, 1.7], frameColor);
}
// Exposed cutaway caps.
box(scene, [0.27, 0.08, 3.5], [-2.95, 1.39, -1.98], 0xa98262);
box(scene, [0.27, 0.08, 3.5], [2.95, 1.39, -1.98], 0x789b8e);
// Windows.
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x9ed3e7,
emissive: 0x315c70,
emissiveIntensity: 0.3,
roughness: 0.45
});
function addWindow(x, z, width = 2.1) {
box(scene, [width, 1.18, 0.08], [x, 1.72, z], windowMaterial);
box(scene, [0.09, 1.24, 0.13], [x, 1.72, z + 0.025], 0xf2eadb);
box(scene, [width + 0.13, 0.09, 0.13], [x, 1.72, z + 0.025], 0xf2eadb);
box(scene, [width + 0.2, 0.1, 0.22], [x, 1.1, z + 0.04], 0xf2eadb);
}
addWindow(-9.75, -3.62);
addWindow(8.5, -3.62, 2.7);
// ---------------------------------------------------------------------
// Continuous route: a rounded rectangular loop with a direct old-to-new
// outbound lane and a separate return lane.
// ---------------------------------------------------------------------
const routeMaterial = new THREE.MeshStandardMaterial({
color: 0x4da68f,
roughness: 0.8,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const dashMaterial = new THREE.MeshStandardMaterial({
color: 0xf2bd52,
roughness: 0.75,
emissive: 0x7d4e08,
emissiveIntensity: 0.08
});
const FRONT_Z = 0.7;
const BACK_Z = 3.1;
const ARC_RADIUS = (BACK_Z - FRONT_Z) / 2;
const STRAIGHT_LENGTH = 18.4;
const ARC_LENGTH = Math.PI * ARC_RADIUS;
const ROUTE_LENGTH = STRAIGHT_LENGTH * 2 + ARC_LENGTH * 2;
// Flat lane surfaces.
box(scene, [18.4, 0.028, 1.05], [0, 0.17, FRONT_Z], routeMaterial);
box(scene, [18.4, 0.028, 1.05], [0, 0.17, BACK_Z], routeMaterial);
function sampleRoute(distance) {
let s = ((distance % ROUTE_LENGTH) + ROUTE_LENGTH) % ROUTE_LENGTH;
if (s < STRAIGHT_LENGTH) {
return {
x: -9.2 + s,
z: FRONT_Z,
dx: 1,
dz: 0
};
}
s -= STRAIGHT_LENGTH;
if (s < ARC_LENGTH) {
const a = -Math.PI / 2 + s / ARC_RADIUS;
return {
x: 9.2 + ARC_RADIUS * Math.cos(a),
z: 1.9 + ARC_RADIUS * Math.sin(a),
dx: -Math.sin(a),
dz: Math.cos(a)
};
}
s -= ARC_LENGTH;
if (s < STRAIGHT_LENGTH) {
return {
x: 9.2 - s,
z: BACK_Z,
dx: -1,
dz: 0
};
}
s -= STRAIGHT_LENGTH;
const a = Math.PI / 2 + s / ARC_RADIUS;
return {
x: -9.2 + ARC_RADIUS * Math.cos(a),
z: 1.9 + ARC_RADIUS * Math.sin(a),
dx: -Math.sin(a),
dz: Math.cos(a)
};
}
// Pixel-like dashes following the entire route.
for (let s = 0; s < ROUTE_LENGTH; s += 0.78) {
const p = sampleRoute(s);
const heading = Math.atan2(-p.dz, p.dx);
box(scene, [0.42, 0.035, 0.095], [p.x, 0.205, p.z], dashMaterial, heading);
}
// Pixel arrows on the outbound old-to-new lane.
for (const x of [-7.6, 0, 7.6]) {
box(scene, [0.5, 0.045, 0.13], [x - 0.14, 0.215, FRONT_Z], dashMaterial);
box(scene, [0.29, 0.045, 0.11], [x + 0.16, 0.215, FRONT_Z - 0.09], dashMaterial, Math.PI / 4);
box(scene, [0.29, 0.045, 0.11], [x + 0.16, 0.215, FRONT_Z + 0.09], dashMaterial, -Math.PI / 4);
}
// ---------------------------------------------------------------------
// Loading-zone truck and safety markings
// ---------------------------------------------------------------------
const truck = new THREE.Group();
truck.position.set(0.2, 0, -2.45);
scene.add(truck);
box(truck, [3.35, 0.18, 1.18], [-0.25, 0.48, 0], 0x56635f);
box(truck, [2.1, 1.25, 1.08], [0.55, 1.12, 0], 0x4e8e83);
box(truck, [1.05, 1.0, 1.05], [-1.37, 0.98, 0], 0xe1ad49);
box(truck, [0.06, 0.42, 0.8], [-1.91, 1.13, 0], 0x8ac0cd);
box(truck, [0.08, 0.11, 1.1], [0.52, 0.74, 0], 0xe9bd58);
box(truck, [2.13, 0.09, 1.1], [0.55, 1.77, 0], 0x376d66);
for (const x of [-1.5, -0.3, 0.9]) {
for (const z of [-0.58, 0.58]) {
box(truck, [0.5, 0.5, 0.18], [x, 0.36, z], 0x35413e);
box(truck, [0.18, 0.18, 0.2], [x, 0.36, z], 0x9ba7a1);
}
}
for (let i = 0; i < 7; i++) {
box(
scene,
[0.42, 0.04, 0.52],
[-2.25 + i * 0.72, 0.175, -3.17],
i % 2 === 0 ? 0xe9ae3e : 0x4b5753
);
}
// ---------------------------------------------------------------------
// Old apartment details
// ---------------------------------------------------------------------
// Bed.
box(scene, [2.5, 0.42, 1.65], [-9.2, 0.36, -2.25], 0x76513f);
box(scene, [2.4, 0.28, 1.55], [-9.2, 0.7, -2.25], 0xe9e1cd);
box(scene, [1.45, 0.08, 1.56], [-8.75, 0.87, -2.25], 0x6f8f84);
box(scene, [0.72, 0.18, 0.62], [-10.02, 0.91, -2.66], 0xf7efe0);
box(scene, [2.58, 1.1, 0.14], [-9.2, 0.7, -3.1], 0x876048);
// Bookcase.
box(scene, [1.65, 2.05, 0.52], [-5.1, 1.16, -3.33], 0x78543e);
box(scene, [1.45, 0.12, 0.08], [-5.1, 0.3, -3.03], 0x9b7352);
box(scene, [1.45, 0.12, 0.08], [-5.1, 0.86, -3.03], 0x9b7352);
box(scene, [1.45, 0.12, 0.08], [-5.1, 1.42, -3.03], 0x9b7352);
box(scene, [1.45, 0.12, 0.08], [-5.1, 1.98, -3.03], 0x9b7352);
const bookColors = [0xc26d52, 0x527e77, 0xe0b24f, 0x6d7893, 0x9c7657];
for (let i = 0; i < 8; i++) {
box(
scene,
[0.12, 0.34 + (i % 3) * 0.05, 0.28],
[-5.68 + i * 0.16, 1.1, -3.1],
bookColors[i % bookColors.length]
);
}
// Plant made entirely from blocks.
function plant(x, z, potColor = 0xa76348) {
box(scene, [0.58, 0.55, 0.58], [x, 0.4, z], potColor);
box(scene, [0.16, 1.05, 0.16], [x, 1.15, z], 0x73583e);
box(scene, [0.86, 0.58, 0.65], [x, 1.55, z], 0x66865c);
box(scene, [0.55, 0.72, 0.55], [x + 0.33, 1.82, z - 0.1], 0x789866);
box(scene, [0.48, 0.45, 0.5], [x - 0.3, 1.85, z + 0.08], 0x4f7657);
}
plant(-11.45, -2.65, 0x9e5f47);
// Old wall patches suggest age without adding clutter.
box(scene, [0.46, 0.19, 0.04], [-7.3, 2.02, -3.64], 0xc8ae87);
box(scene, [0.21, 0.12, 0.04], [-7.12, 1.92, -3.64], 0xc8ae87);
box(scene, [0.38, 0.1, 0.04], [-6.1, 0.69, -3.64], 0xc8ae87);
// ---------------------------------------------------------------------
// New apartment details
// ---------------------------------------------------------------------
box(scene, [3.1, 0.035, 2.15], [8.2, 0.16, -1.8], 0x8fb6aa);
box(scene, [2.78, 0.02, 1.84], [8.2, 0.19, -1.8], 0xa8c7bc);
plant(11.45, -2.65, 0x71968a);
// Minimal framed print.
box(scene, [1.05, 0.78, 0.08], [5.45, 1.92, -3.62], 0x6c8d84);
box(scene, [0.86, 0.59, 0.04], [5.45, 1.92, -3.56], 0xd9c58e);
box(scene, [0.38, 0.3, 0.03], [5.45, 1.88, -3.53], 0x7c9b8a);
// ---------------------------------------------------------------------
// Labels
// ---------------------------------------------------------------------
const oldLabel = labelSprite("OLD APARTMENT", "#704c39", "#fff7e8", 3.8);
oldLabel.position.set(-8.15, 3.18, -3.35);
scene.add(oldLabel);
const loadingLabel = labelSprite("LOADING ZONE", "#c58a31", "#fffaf0", 3.35);
loadingLabel.position.set(0, 2.62, -3.38);
scene.add(loadingLabel);
const newLabel = labelSprite("NEW APARTMENT", "#537c70", "#f8fff9", 3.8);
newLabel.position.set(8.15, 3.18, -3.35);
scene.add(newLabel);
// ---------------------------------------------------------------------
// Movers and the three recognizable moving items
// ---------------------------------------------------------------------
function createDolly(parent, width = 1.05) {
box(parent, [0.86, 0.09, width], [0, 0.25, 0], 0x46514d);
for (const x of [-0.29, 0.29]) {
for (const z of [-width * 0.36, width * 0.36]) {
box(parent, [0.18, 0.18, 0.18], [x, 0.19, z], 0x303936);
}
}
}
function createPerson(parent, shirtColor) {
const person = new THREE.Group();
person.position.set(-0.94, 0, 0);
parent.add(person);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(0, 0.78, -0.16);
legRight.position.set(0, 0.78, 0.16);
person.add(legLeft, legRight);
box(legLeft, [0.19, 0.55, 0.2], [0, -0.28, 0], 0x3b4c56);
box(legRight, [0.19, 0.55, 0.2], [0, -0.28, 0], 0x32434c);
box(legLeft, [0.3, 0.14, 0.23], [0.08, -0.55, 0], 0x303633);
box(legRight, [0.3, 0.14, 0.23], [0.08, -0.55, 0], 0x303633);
box(person, [0.53, 0.64, 0.36], [0, 1.1, 0], shirtColor);
box(person, [0.57, 0.1, 0.38], [0, 0.8, 0], 0x6f543e);
box(person, [0.4, 0.4, 0.38], [0, 1.64, 0], 0xe3b58c);
box(person, [0.43, 0.13, 0.4], [0, 1.84, 0], shirtColor);
box(person, [0.44, 0.07, 0.19], [0.12, 1.83, 0], shirtColor);
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(0.16, 1.37, -0.28);
armRight.position.set(0.16, 1.37, 0.28);
person.add(armLeft, armRight);
box(armLeft, [0.18, 0.48, 0.18], [0.2, -0.2, 0], shirtColor);
box(armRight, [0.18, 0.48, 0.18], [0.2, -0.2, 0], shirtColor);
box(armLeft, [0.17, 0.17, 0.17], [0.2, -0.46, 0], 0xe3b58c);
box(armRight, [0.17, 0.17, 0.17], [0.2, -0.46, 0], 0xe3b58c);
return { person, legLeft, legRight, armLeft, armRight };
}
function createSofa(parent) {
createDolly(parent, 1.58);
box(parent, [0.75, 0.3, 1.5], [0.05, 0.52, 0], 0xd09a3d);
box(parent, [0.22, 0.68, 1.5], [-0.27, 0.85, 0], 0xb97e2e);
box(parent, [0.76, 0.48, 0.18], [0.04, 0.69, -0.66], 0xc58b32);
box(parent, [0.76, 0.48, 0.18], [0.04, 0.69, 0.66], 0xc58b32);
box(parent, [0.16, 0.13, 1.34], [0.32, 0.72, 0], 0xe0ad51);
}
function createFridge(parent) {
// Hand truck frame.
box(parent, [0.1, 1.45, 0.12], [-0.34, 0.98, -0.38], 0x515d59);
box(parent, [0.1, 1.45, 0.12], [-0.34, 0.98, 0.38], 0x515d59);
box(parent, [0.1, 0.1, 0.85], [-0.34, 1.68, 0], 0x515d59);
box(parent, [0.7, 0.09, 0.85], [-0.08, 0.3, 0], 0x515d59);
box(parent, [0.67, 1.27, 0.82], [0.05, 0.97, 0], 0xe6e9e3);
box(parent, [0.025, 0.035, 0.72], [0.395, 1.18, 0], 0xaab2ae);
box(parent, [0.055, 0.34, 0.055], [0.43, 1.1, 0.25], 0x75807b);
box(parent, [0.055, 0.34, 0.055], [0.43, 1.1, -0.25], 0x75807b);
// Pixel magnets.
box(parent, [0.025, 0.11, 0.11], [0.407, 1.45, -0.12], 0xd96c55);
box(parent, [0.025, 0.1, 0.1], [0.407, 1.28, 0.13], 0x5d9caf);
box(parent, [0.025, 0.08, 0.08], [0.407, 1.45, 0.14], 0xe4b84f);
}
function createChair(parent) {
createDolly(parent, 1.12);
box(parent, [0.7, 0.28, 0.98], [0.04, 0.52, 0], 0x568d74);
box(parent, [0.2, 0.7, 0.98], [-0.25, 0.84, 0], 0x477863);
box(parent, [0.7, 0.46, 0.16], [0.04, 0.68, -0.43], 0x477863);
box(parent, [0.7, 0.46, 0.16], [0.04, 0.68, 0.43], 0x477863);
box(parent, [0.14, 0.12, 0.82], [0.29, 0.71, 0], 0x6ba086);
}
function createMover(type, shirtColor) {
const root = new THREE.Group();
scene.add(root);
const person = createPerson(root, shirtColor);
if (type === "sofa") createSofa(root);
if (type === "fridge") createFridge(root);
if (type === "chair") createChair(root);
return { root, ...person, type };
}
const movers = [
createMover("sofa", 0xd77c48),
createMover("fridge", 0x4e8ca4),
createMover("chair", 0x8b6aa7)
];
// Positions along the same continuous route.
const moverOffsets = [4.2, 19.2, 33.2];
// ---------------------------------------------------------------------
// Small exterior details
// ---------------------------------------------------------------------
// Pavement blocks at the far front.
for (let i = 0; i < 11; i++) {
box(
scene,
[0.72, 0.07, 0.42],
[-12 + i * 2.4, 0.005, 4.48],
i % 2 === 0 ? 0xaab6ae : 0xb5c0b8
);
}
// Small bollards keep the transfer path visually protected.
for (const x of [-3.85, 3.85]) {
for (const z of [-0.7, 3.9]) {
box(scene, [0.22, 0.62, 0.22], [x, 0.42, z], 0xe0a23c);
box(scene, [0.24, 0.12, 0.24], [x, 0.56, z], 0xf2c76f);
box(scene, [0.34, 0.1, 0.34], [x, 0.16, z], 0x505b56);
}
}
// ---------------------------------------------------------------------
// Custom camera controls: orbit, zoom, pan, and touch pinch
// ---------------------------------------------------------------------
const pointers = new Map();
let lastPinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
if (event.shiftKey || event.buttons === 2) {
const right = new THREE.Vector3(
Math.cos(desiredView.theta),
0,
-Math.sin(desiredView.theta)
);
const forward = new THREE.Vector3(
Math.sin(desiredView.theta),
0,
Math.cos(desiredView.theta)
);
desiredTarget.addScaledVector(right, -dx * 0.025);
desiredTarget.addScaledVector(forward, -dy * 0.025);
desiredTarget.x = clamp(desiredTarget.x, -5.5, 5.5);
desiredTarget.z = clamp(desiredTarget.z, -3.2, 3.2);
} else {
desiredView.theta -= dx * 0.006;
desiredView.phi = clamp(desiredView.phi - dy * 0.005, 0.48, 1.42);
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
desiredView.radius = clamp(
desiredView.radius * (lastPinchDistance / distance),
12,
62
);
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
12,
62
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
desiredView.theta = 0.57;
desiredView.phi = 1.03;
desiredView.radius = 27;
desiredTarget.set(0, 0.8, 0);
});
let paused = false;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume movers" : "Pause movers";
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 49 : 42;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let movingTime = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) movingTime += dt;
// Smooth camera motion.
view.theta += (desiredView.theta - view.theta) * 0.1;
view.phi += (desiredView.phi - view.phi) * 0.1;
view.radius += (desiredView.radius - view.radius) * 0.1;
target.lerp(desiredTarget, 0.1);
updateCamera();
movers.forEach((mover, index) => {
const distance = movingTime * 1.05 + moverOffsets[index];
const p = sampleRoute(distance);
const heading = Math.atan2(-p.dz, p.dx);
mover.root.position.set(p.x, 0, p.z);
mover.root.rotation.y = heading;
const stride = Math.sin(distance * 4.1);
mover.legLeft.rotation.z = stride * 0.34;
mover.legRight.rotation.z = -stride * 0.34;
mover.armLeft.rotation.z = -stride * 0.12;
mover.armRight.rotation.z = stride * 0.12;
mover.person.position.y = Math.abs(Math.sin(distance * 4.1)) * 0.025;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```