Prompt specification
Build or customize the Three.js 3D scene "Continuity Match Between Two Rooms" 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: Continuity Match Between Two Rooms
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/continuity-match-between-two-rooms-x3350
Scene Description Prompt:
Animate a voxel character carrying one distinctive parcel between rooms, preserving movement direction and parcel appearance across camera changes. One HTML file, Three.js from cdnjs.
Working Three.js Starter (continuity-match-between-two-rooms-x3350):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parcel Passage — Voxel Courier</title>
<style>
:root {
--ink: #eaf7f4;
--muted: #8ea9ad;
--panel: rgba(7, 20, 31, 0.78);
--line: rgba(164, 222, 214, 0.18);
--mint: #67e1cb;
--coral: #ff705f;
--cream: #f6e6b3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131f;
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;
cursor: grab;
}
canvas.grabbing {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
max-width: 420px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 14px var(--mint);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.42;
transform: scale(0.75);
}
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 44px);
font-weight: 850;
line-height: 0.95;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.heading-chip {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(7, 20, 31, 0.58);
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.heading-chip strong {
color: var(--cream);
font-size: 12px;
}
.camera-panel {
position: absolute;
top: 24px;
right: 24px;
width: 216px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.panel-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.camera-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
button {
border: 1px solid rgba(164, 222, 214, 0.16);
border-radius: 7px;
padding: 9px 8px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
font: 750 10px/1 inherit;
letter-spacing: 0.06em;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
border-color: rgba(103, 225, 203, 0.45);
color: var(--ink);
background: rgba(103, 225, 203, 0.08);
}
button.active {
border-color: var(--mint);
background: var(--mint);
color: #08201e;
}
.camera-help {
margin-top: 10px;
color: #66858a;
font-size: 9px;
line-height: 1.45;
}
.route-panel {
position: absolute;
bottom: 24px;
left: 24px;
width: min(420px, calc(100vw - 48px));
padding: 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px);
}
.route-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 11px;
}
.route-status {
font-size: 11px;
font-weight: 750;
}
.stop-count {
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.route-line {
position: relative;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.route-line::before {
content: "";
position: absolute;
top: 13px;
left: 10%;
right: 10%;
height: 1px;
background: linear-gradient(
90deg,
var(--mint) 0 35%,
rgba(164, 222, 214, 0.2) 35% 100%
);
}
.route-stop {
position: relative;
z-index: 1;
min-width: 0;
}
.stop-dot {
width: 26px;
height: 26px;
margin-bottom: 7px;
border: 1px solid rgba(164, 222, 214, 0.24);
border-radius: 50%;
background: #0c202d;
color: var(--muted);
font: 800 9px/24px/25px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
transition: 180ms ease;
}
.stop-name {
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.route-stop.active .stop-dot {
border-color: var(--mint);
background: var(--mint);
color: #08201e;
box-shadow: 0 0 18px rgba(103, 225, 203, 0.4);
}
.route-stop.active .stop-name {
color: var(--ink);
}
.route-stop.next .stop-dot {
border-color: var(--cream);
color: var(--cream);
}
.parcel-panel {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px);
}
.parcel-icon {
position: relative;
width: 39px;
height: 31px;
border: 2px solid #ff8a79;
border-radius: 3px;
background: var(--coral);
box-shadow: inset 0 -4px 0 rgba(90, 20, 20, 0.18);
}
.parcel-icon::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 15px;
width: 7px;
background: var(--cream);
}
.parcel-icon::after {
content: "";
position: absolute;
top: 12px;
left: 0;
right: 0;
height: 6px;
background: var(--cream);
}
.parcel-copy strong,
.parcel-copy span {
display: block;
}
.parcel-copy strong {
margin-bottom: 4px;
font-size: 10px;
letter-spacing: 0.08em;
}
.parcel-copy span {
color: var(--muted);
font-size: 9px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #07131f;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 16px;
left: 16px;
}
.subtitle {
display: none;
}
.camera-panel {
top: 16px;
right: 16px;
width: 150px;
padding: 9px;
}
.camera-help {
display: none;
}
.camera-buttons button {
padding: 8px 4px;
font-size: 8px;
}
.route-panel {
bottom: 16px;
left: 16px;
width: calc(100vw - 32px);
}
.parcel-panel {
display: none;
}
.heading-chip {
margin-top: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated voxel courier carrying a parcel between rooms"></canvas>
<div class="hud">
<section class="brand">
<div class="eyebrow"><span class="live-dot"></span> Live voxel courier</div>
<h1>Parcel<br>Passage</h1>
<p class="subtitle">
One courier, one parcel, four rooms. The route stays fixed in world space
while the camera moves independently.
</p>
<div class="heading-chip">
WORLD HEADING <strong id="heading">090° E</strong>
</div>
</section>
<section class="camera-panel" aria-label="Camera controls">
<div class="panel-title">Camera</div>
<div class="camera-buttons">
<button class="active" data-camera="overview" aria-pressed="true">Overview</button>
<button data-camera="follow" aria-pressed="false">Follow</button>
<button data-camera="side" aria-pressed="false">Side</button>
<button data-camera="top" aria-pressed="false">Top</button>
</div>
<div class="camera-help">
Drag to orbit · Wheel to zoom<br>
Keys 1–4 select camera presets
</div>
</section>
<section class="route-panel" aria-label="Courier route">
<div class="route-head">
<div class="route-status" id="routeStatus">Departing Atelier</div>
<div class="stop-count" id="stopCount">STOP 01 / 04</div>
</div>
<div class="route-line">
<div class="route-stop active" data-stop="0">
<div class="stop-dot">01</div>
<div class="stop-name">Atelier</div>
</div>
<div class="route-stop next" data-stop="1">
<div class="stop-dot">02</div>
<div class="stop-name">Print Shop</div>
</div>
<div class="route-stop" data-stop="2">
<div class="stop-dot">03</div>
<div class="stop-name">Gallery</div>
</div>
<div class="route-stop" data-stop="3">
<div class="stop-dot">04</div>
<div class="stop-name">Archive</div>
</div>
</div>
</section>
<section class="parcel-panel" aria-label="Parcel status">
<div class="parcel-icon"></div>
<div class="parcel-copy">
<strong>ONE PARCEL</strong>
<span>Coral box · cream tape · blue seal</span>
</div>
</section>
</div>
<div id="loading">Building the route…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const headingElement = document.querySelector("#heading");
const routeStatusElement = document.querySelector("#routeStatus");
const stopCountElement = document.querySelector("#stopCount");
const routeStopElements = [...document.querySelectorAll(".route-stop")];
const cameraButtons = [...document.querySelectorAll("[data-camera]")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131f);
scene.fog = new THREE.Fog(0x07131f, 22, 43);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const clock = new THREE.Clock();
const baseFloorY = 0.045;
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...options
});
}
function addBox(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbde8ef, 0x172536, 2.15));
const sun = new THREE.DirectionalLight(0xfff0cf, 3.4);
sun.position.set(-7, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x65c9ff, 1.15);
rimLight.position.set(10, 8, -9);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Voxel floor and room layout
// ---------------------------------------------------------------------
const floorBaseMaterial = standardMaterial(0x101f2b);
addBox(
scene,
[22.3, 0.28, 16.3],
[0, -0.18, 0],
floorBaseMaterial,
{ castShadow: false }
);
const tileGeometry = new THREE.BoxGeometry(1.93, 0.08, 1.93);
const tileMaterial = standardMaterial(0xffffff, { roughness: 0.94 });
const tileCount = 11 * 9;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
const tileTransform = new THREE.Object3D();
const palettes = [
new THREE.Color(0x294252), // x < 0, z > 0
new THREE.Color(0x35434e), // x > 0, z > 0
new THREE.Color(0x2b3b50), // x > 0, z < 0
new THREE.Color(0x3b424b) // x < 0, z < 0
];
let tileIndex = 0;
for (let iz = 0; iz < 9; iz++) {
const z = -8 + iz * 2;
for (let ix = 0; ix < 11; ix++) {
const x = -10 + ix * 2;
tileTransform.position.set(x, -0.04, z);
tileTransform.updateMatrix();
tiles.setMatrixAt(tileIndex, tileTransform.matrix);
const paletteIndex =
x < 0 ? (z > 0 ? 0 : 3) : (z > 0 ? 1 : 2);
const variation = ((ix * 13 + iz * 7) % 5 - 2) * 0.009;
const color = palettes[paletteIndex].clone();
color.offsetHSL(0, 0, variation);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
tiles.castShadow = false;
scene.add(tiles);
const wallMaterial = standardMaterial(0x38515f);
const wallTopMaterial = standardMaterial(0x496a75);
const trimMaterial = standardMaterial(0x71d9ca, {
emissive: 0x215c55,
emissiveIntensity: 0.3
});
function addWall(axis, fixed, start, end, height = 1.35) {
const length = end - start;
const middle = (start + end) * 0.5;
const size =
axis === "z"
? [0.24, height, length]
: [length, height, 0.24];
const position =
axis === "z"
? [fixed, height * 0.5, middle]
: [middle, height * 0.5, fixed];
addBox(scene, size, position, wallMaterial);
addBox(
scene,
axis === "z"
? [0.3, 0.12, length]
: [length, 0.12, 0.3],
axis === "z"
? [fixed, height + 0.06, middle]
: [middle, height + 0.06, fixed],
wallTopMaterial
);
}
// Low outer walls keep the rooms visible.
addWall("z", -11, -8, 8, 0.65);
addWall("z", 11, -8, 8, 0.65);
addWall("x", -8, -11, 11, 0.65);
addWall("x", 8, -11, 11, 0.65);
// Interior walls have door gaps centered on the courier's route.
addWall("z", 0, -8, -6.8);
addWall("z", 0, -5.2, 5.2);
addWall("z", 0, 6.8, 8);
addWall("x", 0, -11, -6.8);
addWall("x", 0, -5.2, 5.2);
addWall("x", 0, 6.8, 11);
function addDoorFrame(axis, fixed, center) {
const postPositions =
axis === "z"
? [
[fixed, 1.2, center - 0.91],
[fixed, 1.2, center + 0.91]
]
: [
[center - 0.91, 1.2, fixed],
[center + 0.91, 1.2, fixed]
];
postPositions.forEach((position) => {
addBox(scene, [0.3, 2.4, 0.3], position, wallTopMaterial);
});
addBox(
scene,
axis === "z" ? [0.32, 0.28, 2.12] : [2.12, 0.28, 0.32],
axis === "z"
? [fixed, 2.52, center]
: [center, 2.52, fixed],
trimMaterial
);
}
addDoorFrame("z", 0, 6);
addDoorFrame("z", 0, -6);
addDoorFrame("x", 0, 6);
addDoorFrame("x", 0, -6);
// ---------------------------------------------------------------------
// Route stops
// ---------------------------------------------------------------------
const stops = [
{
name: "Atelier",
position: new THREE.Vector3(-6, baseFloorY, 6),
color: 0x55d8c9
},
{
name: "Print Shop",
position: new THREE.Vector3(6, baseFloorY, 6),
color: 0xffbf69
},
{
name: "Gallery",
position: new THREE.Vector3(6, baseFloorY, -6),
color: 0xc695ff
},
{
name: "Archive",
position: new THREE.Vector3(-6, baseFloorY, -6),
color: 0xff7c70
}
];
stops.forEach((stop) => {
const padMaterial = standardMaterial(stop.color, {
emissive: stop.color,
emissiveIntensity: 0.12,
transparent: true,
opacity: 0.13,
depthWrite: false
});
addBox(
scene,
[4.65, 0.026, 4.65],
[stop.position.x, 0.025, stop.position.z],
padMaterial,
{ castShadow: false, receiveShadow: false }
);
const markerMaterial = standardMaterial(stop.color, {
emissive: stop.color,
emissiveIntensity: 1.5
});
addBox(
scene,
[0.42, 0.035, 0.42],
[stop.position.x, 0.065, stop.position.z],
markerMaterial,
{ castShadow: false }
);
});
// ---------------------------------------------------------------------
// Furniture helpers
// ---------------------------------------------------------------------
function makeDesk(x, z, accent) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const wood = standardMaterial(0x8a6954);
const dark = standardMaterial(0x253744);
const screen = standardMaterial(0x10242d, {
emissive: accent,
emissiveIntensity: 0.65
});
addBox(group, [2.65, 0.16, 1.12], [0, 1.02, 0], wood);
addBox(group, [0.16, 1.0, 0.16], [-1.08, 0.5, -0.36], dark);
addBox(group, [0.16, 1.0, 0.16], [1.08, 0.5, -0.36], dark);
addBox(group, [0.16, 1.0, 0.16], [-1.08, 0.5, 0.36], dark);
addBox(group, [0.16, 1.0, 0.16], [1.08, 0.5, 0.36], dark);
addBox(group, [0.16, 0.42, 0.16], [0, 1.31, -0.25], dark);
addBox(group, [1.15, 0.68, 0.13], [0, 1.7, -0.23], dark);
addBox(group, [0.94, 0.48, 0.025], [0, 1.7, -0.305], screen);
addBox(group, [0.72, 0.045, 0.28], [-0.58, 1.13, 0.16], accent);
addBox(group, [0.42, 0.045, 0.28], [0.56, 1.13, 0.13], dark);
}
function makeShelf(x, z, width = 3, accent = 0xffbf69) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const frame = standardMaterial(0x4a3c39);
const bookColors = [
0xe47c6b,
0x6ec8bc,
0xd9b568,
0x8a79bb,
0x6fa5cf
];
addBox(group, [width, 2.25, 0.12], [0, 1.13, -0.29], frame);
[-1, 1].forEach((side) => {
addBox(
group,
[0.16, 2.3, 0.62],
[side * (width * 0.5 - 0.08), 1.15, 0],
frame
);
});
[0.16, 0.8, 1.44, 2.08].forEach((height) => {
addBox(group, [width, 0.13, 0.62], [0, height, 0], frame);
});
for (let row = 0; row < 3; row++) {
let cursor = -width * 0.5 + 0.28;
while (cursor < width * 0.5 - 0.35) {
const bookWidth = 0.18 + ((row * 3 + cursor) % 4) * 0.035;
const bookHeight = 0.32 + ((row + 2) % 3) * 0.09;
const color = bookColors[Math.abs(Math.round(cursor * 3 + row)) % bookColors.length];
addBox(
group,
[bookWidth, bookHeight, 0.34],
[cursor + bookWidth * 0.5, 0.27 + row * 0.64 + bookHeight * 0.5, 0.02],
standardMaterial(color)
);
cursor += bookWidth + 0.055;
}
}
addBox(
group,
[0.32, 0.32, 0.34],
[width * 0.5 - 0.35, 1.97, 0.02],
standardMaterial(accent, {
emissive: accent,
emissiveIntensity: 0.45
})
);
}
function makePlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
const pot = standardMaterial(0xb86d55);
const stem = standardMaterial(0x3c8b65);
const leaf = standardMaterial(0x64bd85);
addBox(group, [0.62, 0.62, 0.62], [0, 0.31, 0], pot);
addBox(group, [0.15, 1.25, 0.15], [0, 1.13, 0], stem);
addBox(group, [0.72, 0.2, 0.34], [0.23, 1.18, 0], leaf);
addBox(group, [0.58, 0.18, 0.3], [-0.2, 1.52, 0.02], leaf);
addBox(group, [0.4, 0.18, 0.28], [0.08, 1.78, 0], leaf);
}
function makePedestal(x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, [1.2, 0.9, 1.2], [0, 0.45, 0], standardMaterial(0x45515c));
addBox(group, [0.75, 0.75, 0.75], [0, 1.27, 0], standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.25
}));
addBox(group, [0.34, 0.34, 0.34], [0.18, 1.83, 0.05], standardMaterial(0xf2dba7));
}
function makeCouch(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const fabric = standardMaterial(0x476978);
const cushion = standardMaterial(0x5c8090);
addBox(group, [2.55, 0.42, 1.05], [0, 0.45, 0], fabric);
addBox(group, [2.55, 0.92, 0.25], [0, 0.82, -0.4], fabric);
addBox(group, [0.25, 0.75, 1.05], [-1.15, 0.72, 0], fabric);
addBox(group, [0.25, 0.75, 1.05], [1.15, 0.72, 0], fabric);
addBox(group, [1.05, 0.2, 0.76], [-0.56, 0.75, 0.03], cushion);
addBox(group, [1.05, 0.2, 0.76], [0.56, 0.75, 0.03], cushion);
}
// Atelier
makeDesk(-8.0, 7.15, 0x67dfd0);
makePlant(-9.45, 4.4, 0.9);
// Print Shop
makeShelf(8.65, 7.15, 3.1, 0xffbf69);
addBox(
scene,
[1.7, 0.8, 0.9],
[3.9, 0.4, 7.15],
standardMaterial(0x7b5b4e)
);
addBox(
scene,
[1.85, 0.12, 1.02],
[3.9, 0.86, 7.15],
standardMaterial(0xb9825e)
);
// Gallery
makePedestal(8.35, -4.6, 0xb68af4);
makePedestal(8.35, -7.1, 0xf28579);
addBox(
scene,
[2.7, 0.18, 0.25],
[8.2, 2.05, -8.0],
standardMaterial(0x6b5877)
);
addBox(
scene,
[0.28, 1.3, 0.25],
[7.0, 1.42, -8.0],
standardMaterial(0x6b5877)
);
addBox(
scene,
[0.28, 1.3, 0.25],
[9.4, 1.42, -8.0],
standardMaterial(0x6b5877)
);
// Archive
makeShelf(-8.65, -7.15, 3.1, 0xff7c70);
makeCouch(-8.55, -4.55);
// ---------------------------------------------------------------------
// Voxel courier
// ---------------------------------------------------------------------
const courier = new THREE.Group();
courier.name = "Voxel courier";
courier.position.copy(stops[0].position);
scene.add(courier);
const shirtMaterial = standardMaterial(0xf3c45b);
const vestMaterial = standardMaterial(0x2d8290);
const trousersMaterial = standardMaterial(0x27475a);
const shoeMaterial = standardMaterial(0x172b36);
const skinMaterial = standardMaterial(0xe8a77d);
const hairMaterial = standardMaterial(0x30262b);
const badgeMaterial = standardMaterial(0x70e5cf, {
emissive: 0x36a896,
emissiveIntensity: 0.65
});
addBox(courier, [0.7, 0.7, 0.43], [0, 1.18, 0], shirtMaterial);
addBox(courier, [0.57, 0.52, 0.46], [0, 1.12, 0.015], vestMaterial);
addBox(courier, [0.15, 0.56, 0.025], [-0.16, 1.16, 0.246], vestMaterial);
addBox(courier, [0.15, 0.56, 0.025], [0.16, 1.16, 0.246], vestMaterial);
addBox(courier, [0.12, 0.12, 0.035], [0.14, 1.32, 0.275], badgeMaterial);
const head = new THREE.Group();
head.position.set(0, 1.73, 0);
courier.add(head);
addBox(head, [0.54, 0.51, 0.5], [0, 0, 0], skinMaterial);
addBox(head, [0.58, 0.17, 0.54], [0, 0.2, -0.015], hairMaterial);
addBox(head, [0.15, 0.24, 0.17], [-0.24, 0.01, 0], hairMaterial);
addBox(head, [0.08, 0.08, 0.025], [-0.11, 0.035, 0.263], shoeMaterial);
addBox(head, [0.08, 0.08, 0.025], [0.11, 0.035, 0.263], shoeMaterial);
addBox(head, [0.09, 0.09, 0.07], [0, -0.06, 0.275], skinMaterial);
function makeLeg(x) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.75, 0);
courier.add(pivot);
addBox(pivot, [0.25, 0.62, 0.27], [0, -0.31, 0], trousersMaterial);
addBox(pivot, [0.29, 0.18, 0.4], [0, -0.64, 0.07], shoeMaterial);
return pivot;
}
const leftLeg = makeLeg(-0.19);
const rightLeg = makeLeg(0.19);
function makeArm(x) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.46, 0);
courier.add(pivot);
addBox(pivot, [0.22, 0.58, 0.24], [0, -0.29, 0], shirtMaterial);
addBox(pivot, [0.24, 0.19, 0.26], [0, -0.63, 0], skinMaterial);
return pivot;
}
const leftArm = makeArm(-0.48);
const rightArm = makeArm(0.48);
// ---------------------------------------------------------------------
// The single distinctive parcel
// It is created once and remains permanently parented to the courier.
// Camera changes never rebuild or replace it.
// ---------------------------------------------------------------------
const parcel = new THREE.Group();
parcel.name = "The single coral parcel";
parcel.position.set(0, -0.38, 0.13);
rightArm.add(parcel);
const parcelBodyMaterial = standardMaterial(0xff705f, {
roughness: 0.72
});
const tapeMaterial = standardMaterial(0xf6e6b3, {
roughness: 0.68
});
const sealMaterial = standardMaterial(0x40bcd2, {
emissive: 0x155d69,
emissiveIntensity: 0.45
});
addBox(parcel, [0.72, 0.56, 0.58], [0, 0, 0], parcelBodyMaterial);
addBox(parcel, [0.16, 0.018, 0.59], [0, 0.289, 0], tapeMaterial);
addBox(parcel, [0.16, 0.57, 0.018], [0, 0, 0.299], tapeMaterial);
addBox(parcel, [0.018, 0.57, 0.16], [0.369, 0, 0], tapeMaterial);
// Pixel-style blue seal.
const sealPixels = [
[-0.055, 0.045],
[0.055, 0.045],
[-0.027, 0.095],
[0.027, 0.095],
[0, 0.14],
[0, -0.015]
];
sealPixels.forEach(([x, y]) => {
addBox(
parcel,
[0.036, 0.036, 0.025],
[0.19 + x, 0.035 + y, 0.319],
sealMaterial
);
});
function createParcelLabelTexture() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.fillStyle = "#f6e6b3";
context.fillRect(0, 0, 256, 128);
context.strokeStyle = "#214653";
context.lineWidth = 10;
context.strokeRect(7, 7, 242, 114);
context.fillStyle = "#214653";
context.font = "bold 55px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("P-01", 128, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const parcelLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.43, 0.215),
new THREE.MeshBasicMaterial({
map: createParcelLabelTexture(),
transparent: true,
depthWrite: false,
toneMapped: false,
side: THREE.DoubleSide
})
);
parcelLabel.rotation.x = -Math.PI * 0.5;
parcelLabel.position.set(0, 0.306, 0);
parcel.add(parcelLabel);
// ---------------------------------------------------------------------
// World-space route state
// ---------------------------------------------------------------------
const movementSpeed = 1.58;
let currentStopIndex = 0;
let targetStopIndex = 1;
let dwellTime = 0;
let completedStops = 0;
let walkPhase = 0;
let currentYaw = Math.PI * 0.5;
let moving = false;
const lastTravelDirection = new THREE.Vector3(1, 0, 0);
const directionToTarget = new THREE.Vector3();
const desiredYawHolder = new THREE.Vector3();
function angleLerp(a, b, t) {
const difference =
THREE.MathUtils.euclideanModulo(b - a + Math.PI, Math.PI * 2) - Math.PI;
return a + difference * t;
}
function updateCourier(delta) {
moving = false;
if (dwellTime > 0) {
dwellTime -= delta;
} else {
const target = stops[targetStopIndex].position;
directionToTarget.copy(target).sub(courier.position);
directionToTarget.y = 0;
const distance = directionToTarget.length();
if (distance < 0.025) {
courier.position.x = target.x;
courier.position.z = target.z;
currentStopIndex = targetStopIndex;
targetStopIndex = (targetStopIndex + 1) % stops.length;
completedStops++;
dwellTime = 0.85;
} else {
moving = true;
directionToTarget.normalize();
lastTravelDirection.copy(directionToTarget);
const step = Math.min(movementSpeed * delta, distance);
courier.position.addScaledVector(directionToTarget, step);
walkPhase += step * 7.2;
const desiredYaw = Math.atan2(
directionToTarget.x,
directionToTarget.z
);
currentYaw = angleLerp(
currentYaw,
desiredYaw,
1 - Math.exp(-12 * delta)
);
}
}
courier.rotation.y = currentYaw;
const stride = Math.sin(walkPhase);
const oppositeStride = Math.sin(walkPhase + Math.PI);
leftLeg.rotation.x = moving ? stride * 0.52 : 0;
rightLeg.rotation.x = moving ? oppositeStride * 0.52 : 0;
leftArm.rotation.x = moving ? oppositeStride * 0.4 : 0.02;
// The parcel-bearing arm remains comparatively steady.
rightArm.rotation.x = moving
? -0.08 + Math.sin(walkPhase) * 0.035
: -0.08;
courier.position.y =
baseFloorY + (moving ? Math.abs(Math.sin(walkPhase)) * 0.035 : 0);
updateHUD();
}
// ---------------------------------------------------------------------
// Custom camera controls — no addons
// ---------------------------------------------------------------------
let cameraMode = "overview";
const desiredCamera = {
target: new THREE.Vector3(0, 0.5, 0),
yaw: 0.68,
pitch: 0.78,
distance: 25
};
const actualCamera = {
target: desiredCamera.target.clone(),
yaw: desiredCamera.yaw,
pitch: desiredCamera.pitch,
distance: desiredCamera.distance
};
const presets = {
overview: {
yaw: 0.68,
pitch: 0.78,
distance: 25,
target: new THREE.Vector3(0, 0.5, 0)
},
follow: {
yaw: 0.68,
pitch: 0.44,
distance: 7.6,
target: new THREE.Vector3()
},
side: {
yaw: Math.PI * 0.5,
pitch: 0.31,
distance: 8.2,
target: new THREE.Vector3()
},
top: {
yaw: 0.05,
pitch: 1.25,
distance: 22,
target: new THREE.Vector3(0, 0, 0)
}
};
function setCameraMode(mode) {
cameraMode = mode;
const preset = presets[mode];
desiredCamera.yaw = preset.yaw;
desiredCamera.pitch = preset.pitch;
desiredCamera.distance = preset.distance;
desiredCamera.target.copy(preset.target);
cameraButtons.forEach((button) => {
const active = button.dataset.camera === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
cameraButtons.forEach((button) => {
button.addEventListener("click", () => {
setCameraMode(button.dataset.camera);
});
});
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.classList.add("grabbing");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
desiredCamera.yaw -= deltaX * 0.006;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + deltaY * 0.005,
0.18,
1.38
);
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("grabbing");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * Math.exp(event.deltaY * 0.001),
5,
34
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const modeByKey = {
"1": "overview",
"2": "follow",
"3": "side",
"4": "top"
};
if (modeByKey[event.key]) {
setCameraMode(modeByKey[event.key]);
}
if (event.key === "ArrowLeft") {
desiredCamera.yaw += 0.12;
}
if (event.key === "ArrowRight") {
desiredCamera.yaw -= 0.12;
}
if (event.key === "ArrowUp") {
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + 0.08,
0.18,
1.38
);
}
if (event.key === "ArrowDown") {
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch - 0.08,
0.18,
1.38
);
}
});
function updateCamera(delta) {
if (cameraMode === "follow" || cameraMode === "side") {
desiredCamera.target.set(
courier.position.x,
0.9,
courier.position.z
);
}
const smoothing = 1 - Math.exp(-5.5 * delta);
actualCamera.target.lerp(desiredCamera.target, smoothing);
actualCamera.yaw = angleLerp(
actualCamera.yaw,
desiredCamera.yaw,
smoothing
);
actualCamera.pitch = THREE.MathUtils.lerp(
actualCamera.pitch,
desiredCamera.pitch,
smoothing
);
actualCamera.distance = THREE.MathUtils.lerp(
actualCamera.distance,
desiredCamera.distance,
smoothing
);
const horizontalDistance =
actualCamera.distance * Math.cos(actualCamera.pitch);
camera.position.set(
actualCamera.target.x +
horizontalDistance * Math.sin(actualCamera.yaw),
actualCamera.target.y +
actualCamera.distance * Math.sin(actualCamera.pitch),
actualCamera.target.z +
horizontalDistance * Math.cos(actualCamera.yaw)
);
camera.lookAt(actualCamera.target);
}
// ---------------------------------------------------------------------
// HUD
// ---------------------------------------------------------------------
function getZoneName(position) {
const x = position.x;
const z = position.z;
if ((Math.abs(x) < 1.25 && Math.abs(z) > 4.4) ||
(Math.abs(z) < 1.25 && Math.abs(x) > 4.4)) {
return "Room threshold";
}
if (Math.abs(x) < 1.4 || Math.abs(z) < 1.4) {
return "Central passage";
}
if (x < 0 && z > 0) return "Atelier";
if (x > 0 && z > 0) return "Print Shop";
if (x > 0 && z < 0) return "Gallery";
return "Archive";
}
function updateHUD() {
const degrees =
(THREE.MathUtils.radToDeg(
Math.atan2(lastTravelDirection.x, lastTravelDirection.z)
) + 360) % 360;
const cardinals = [
"N", "NE", "E", "SE", "S", "SW", "W", "NW"
];
const cardinal = cardinals[Math.round(degrees / 45) % 8];
headingElement.textContent =
`${String(Math.round(degrees)).padStart(3, "0")}° ${cardinal}`;
const currentStop = stops[currentStopIndex];
const targetStop = stops[targetStopIndex];
if (moving) {
routeStatusElement.textContent = `Moving to ${targetStop.name}`;
} else {
routeStatusElement.textContent = `At ${currentStop.name} · parcel secured`;
}
stopCountElement.textContent =
`STOP ${String(currentStopIndex + 1).padStart(2, "0")} / 04`;
routeStopElements.forEach((element, index) => {
element.classList.toggle("active", index === currentStopIndex);
element.classList.toggle("next", index === targetStopIndex);
});
}
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
updateCourier(delta);
updateCamera(delta);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 250);
}
});
</script>
</body>
</html>
```