Prompt specification
Build or customize the Three.js 3D scene "Multilevel library access journey" 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: Multilevel library access journey
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/multilevel-library-access-journey-x0431
Scene Description Prompt:
Compose two library levels linked by stairs and lift; a visitor carrying books follows the lift route while an overhead trace preserves continuity between floors. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (multilevel-library-access-journey-x0431):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Ascending Archive</title>
<style>
:root {
color-scheme: dark;
--cyan: #63e9f4;
--amber: #ffbf69;
--ink: #07131d;
--glass: rgba(9, 24, 35, 0.76);
--line: rgba(151, 224, 236, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene 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% 42%, transparent 48%, rgba(2, 8, 13, 0.42) 100%),
linear-gradient(180deg, rgba(4, 14, 23, 0.22), transparent 28%, transparent 70%, rgba(4, 14, 23, 0.28));
z-index: 2;
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
color: #edf9fc;
}
.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: 16px;
background: linear-gradient(135deg, rgba(12, 31, 43, 0.88), rgba(7, 20, 30, 0.68));
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 15px rgba(99, 233, 244, 0.9);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.75);
}
}
h1 {
margin: 0;
font-size: clamp(24px, 3.2vw, 38px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin: 12px 0 17px;
color: rgba(229, 245, 248, 0.64);
font-size: 12px;
line-height: 1.55;
}
.level-strip {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.level {
position: relative;
overflow: hidden;
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.level strong {
display: block;
margin-top: 4px;
font-size: 12px;
letter-spacing: 0.02em;
}
.level span {
color: rgba(235, 248, 250, 0.45);
font-size: 9px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.level.active {
border-color: rgba(99, 233, 244, 0.42);
background: rgba(99, 233, 244, 0.09);
}
.status-card {
position: absolute;
left: 24px;
bottom: 24px;
width: min(350px, calc(100vw - 48px));
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--glass);
backdrop-filter: blur(14px);
}
.status-row {
display: flex;
align-items: center;
gap: 11px;
}
.route-swatch {
width: 31px;
height: 7px;
flex: none;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 13px rgba(99, 233, 244, 0.8);
}
.status-copy small {
display: block;
margin-bottom: 3px;
color: rgba(234, 249, 251, 0.43);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-copy strong {
display: block;
font-size: 12px;
font-weight: 650;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.button-row {
display: flex;
gap: 7px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 10px 13px;
color: #e9fbfd;
background: rgba(9, 25, 36, 0.82);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(99, 233, 244, 0.7);
background: rgba(23, 55, 69, 0.92);
transform: translateY(-1px);
}
.help {
padding: 8px 10px;
border-radius: 8px;
color: rgba(233, 249, 251, 0.48);
background: rgba(5, 16, 24, 0.5);
font-size: 10px;
letter-spacing: 0.04em;
}
@media (max-width: 680px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px;
}
.subtitle {
margin-bottom: 12px;
}
.status-card {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.controls {
right: 14px;
bottom: 92px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<main class="hud">
<section class="title-card">
<div class="eyebrow">
<span class="live-dot"></span>
Live spatial study
</div>
<h1>The Ascending Archive</h1>
<p class="subtitle">
A book-carrying visitor moves between two library levels by lift.
The suspended cyan trace preserves the route across the floor break.
</p>
<div class="level-strip">
<div class="level" id="levelOne">
<span>Level 01</span>
<strong>Reading Hall</strong>
</div>
<div class="level" id="levelTwo">
<span>Level 02</span>
<strong>Quiet Stacks</strong>
</div>
</div>
</section>
<section class="status-card">
<div class="status-row">
<div class="route-swatch"></div>
<div class="status-copy">
<small>Visitor route</small>
<strong id="routeStatus">Lower hall · approaching lift</strong>
</div>
</div>
</section>
<section class="controls">
<div class="button-row">
<button id="pauseButton" type="button">Pause route</button>
<button id="traceButton" type="button">Hide trace</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="help">Drag to orbit · Scroll / pinch to zoom · Arrow keys to rotate</div>
</section>
</main>
<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 host = document.getElementById("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.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081722);
scene.fog = new THREE.Fog(0x081722, 30, 68);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const clock = new THREE.Clock();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc5efff, 0x403127, 1.55));
const sun = new THREE.DirectionalLight(0xffe3bc, 3.25);
sun.position.set(9, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x77d9ef, 1.05);
coolFill.position.set(-12, 8, 4);
scene.add(coolFill);
const liftLight = new THREE.PointLight(0x57e8ff, 18, 9, 2);
liftLight.position.set(-7, 4.7, -1.4);
scene.add(liftLight);
const warmLight = new THREE.PointLight(0xffbb72, 15, 10, 2);
warmLight.position.set(2.5, 6.2, -2.5);
scene.add(warmLight);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function getMaterial(color, emissive = false) {
const key = `${color}-${emissive}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.03,
emissive: emissive ? color : 0x000000,
emissiveIntensity: emissive ? 1.25 : 0
})
);
}
return materialCache.get(key);
}
function addBox(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material =
color && color.isMaterial
? color
: new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.76,
metalness: options.metalness ?? 0.03,
emissive: options.emissive ? color : 0x000000,
emissiveIntensity: options.emissive ? (options.emissiveIntensity ?? 1.2) : 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addBeam(parent, start, end, thickness, color) {
const direction = end.clone().sub(start);
const length = direction.length();
const middle = start.clone().add(end).multiplyScalar(0.5);
const beam = addBox(
parent,
thickness,
thickness,
length,
color,
middle.x,
middle.y,
middle.z
);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return beam;
}
function makeLabel(text, width = 512, height = 128) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(6, 20, 29, 0.88)";
context.fillRect(0, 8, width, height - 16);
context.strokeStyle = "rgba(99, 233, 244, 0.72)";
context.lineWidth = 3;
context.strokeRect(2, 10, width - 4, height - 20);
context.fillStyle = "#eafcff";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `700 ${Math.round(height * 0.32)}px system-ui`;
context.fillText(text, width / 2, height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.3, 0.825, 1);
return sprite;
}
let randomSeed = 73129;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// ---------------------------------------------------------------------
// Foundation and voxel floors
// ---------------------------------------------------------------------
const outside = addBox(
scene,
90,
0.2,
90,
0x07131b,
0,
-0.48,
0,
{ castShadow: false }
);
addBox(scene, 21.2, 0.28, 13.2, 0x1b2930, 0, -0.31, 0);
const groundColors = [
0x806a52,
0x897158,
0x7f674f,
0x92785c,
0x826b53
];
for (let x = 0; x < 20; x++) {
for (let z = 0; z < 12; z++) {
const color = groundColors[(x + z * 2) % groundColors.length];
addBox(
scene,
0.965,
0.22,
0.965,
color,
-9.5 + x,
-0.11,
-5.5 + z
);
}
}
const upperColors = [
0x9a8263,
0xa18a6d,
0x927b5f,
0xaa9070,
0x9e8567
];
// Upper platform occupies the rear half, leaving the lower floor visible.
// A deliberate opening is left for the lift shaft.
for (let x = 0; x < 20; x++) {
for (let z = 0; z < 7; z++) {
const px = -9.5 + x;
const pz = -5.5 + z;
const inLiftOpening =
px >= -8 && px <= -6 &&
pz >= -4 && pz <= -1;
if (inLiftOpening) continue;
addBox(
scene,
0.965,
0.26,
0.965,
upperColors[(x * 2 + z) % upperColors.length],
px,
4.27,
pz
);
}
}
// Upper platform edge, interrupted by the stair landing.
addBox(scene, 15.1, 0.34, 0.18, 0x5f4936, -2.35, 4.22, 0.98);
addBox(scene, 2.2, 0.34, 0.18, 0x5f4936, 8.85, 4.22, 0.98);
// Voxel support columns.
[-9.2, -2.1, 2.2, 9.2].forEach((x) => {
addBox(scene, 0.38, 4.12, 0.38, 0x43545a, x, 2.06, 0.72);
addBox(scene, 0.62, 0.18, 0.62, 0x65777a, x, 0.12, 0.72);
addBox(scene, 0.62, 0.18, 0.62, 0x65777a, x, 4.02, 0.72);
});
// Back walls.
addBox(scene, 20.4, 3.15, 0.24, 0x30464f, 0, 1.57, -6.15);
addBox(scene, 20.4, 2.25, 0.24, 0x3c535b, 0, 5.53, -6.15);
// Upper window blocks.
[-6.3, -2.1, 2.1, 6.3].forEach((x) => {
addBox(scene, 2.3, 1.12, 0.06, 0x70c8d5, x, 5.65, -6.0, {
emissive: true,
emissiveIntensity: 0.42,
castShadow: false
});
addBox(scene, 0.08, 1.2, 0.09, 0x263b43, x, 5.65, -5.94);
addBox(scene, 2.4, 0.08, 0.09, 0x263b43, x, 5.65, -5.94);
});
// ---------------------------------------------------------------------
// Stairs
// ---------------------------------------------------------------------
const stairGroup = new THREE.Group();
scene.add(stairGroup);
const stepCount = 14;
const stepDepth = 0.33;
const stairStartZ = 5.45;
for (let i = 0; i < stepCount; i++) {
const top = ((i + 1) / stepCount) * 4.4;
const z = stairStartZ - i * stepDepth;
addBox(
stairGroup,
2.3,
top,
stepDepth + 0.025,
i % 2 === 0 ? 0x9a7957 : 0x89684b,
6.4,
top / 2,
z
);
addBox(
stairGroup,
2.12,
0.035,
0.13,
0xb99165,
6.4,
top + 0.02,
z + 0.09
);
}
// Blocky handrails.
[-1.19, 1.19].forEach((offset) => {
for (let i = 0; i < stepCount; i += 3) {
const top = ((i + 1) / stepCount) * 4.4;
const z = stairStartZ - i * stepDepth;
addBox(
stairGroup,
0.09,
0.95,
0.09,
0x293e45,
6.4 + offset,
top + 0.48,
z
);
}
addBeam(
stairGroup,
new THREE.Vector3(6.4 + offset, 1.35, 5.38),
new THREE.Vector3(6.4 + offset, 5.55, 1.18),
0.095,
0x293e45
);
});
// ---------------------------------------------------------------------
// Furniture helpers
// ---------------------------------------------------------------------
const bookColors = [
0xe36f54,
0xe3aa51,
0x65b5a6,
0x4f92bd,
0x8e72b5,
0xd5d1b8,
0xba635e,
0x759c64
];
function addBookcase(parent, x, y, z, width = 3.2, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
parent.add(group);
const height = 2.12;
const depth = 0.5;
const shelfColor = 0x60432f;
addBox(group, 0.16, height, depth, shelfColor, -width / 2 + 0.08, height / 2, 0);
addBox(group, 0.16, height, depth, shelfColor, width / 2 - 0.08, height / 2, 0);
addBox(group, width, height, 0.07, 0x49362b, 0, height / 2, -depth / 2 + 0.035);
const rows = 4;
for (let row = 0; row <= rows; row++) {
const shelfY = 0.08 + row * ((height - 0.16) / rows);
addBox(
group,
width - 0.08,
0.105,
depth,
shelfColor,
0,
shelfY,
0
);
if (row === rows) continue;
let cursor = -width / 2 + 0.25;
while (cursor < width / 2 - 0.25) {
const bookWidth = 0.12 + random() * 0.14;
const bookHeight = 0.34 + random() * 0.26;
const color = bookColors[Math.floor(random() * bookColors.length)];
addBox(
group,
bookWidth,
bookHeight,
0.3,
color,
cursor + bookWidth / 2,
shelfY + 0.055 + bookHeight / 2,
0.025
);
cursor += bookWidth + 0.035 + random() * 0.05;
}
}
addBox(group, width + 0.12, 0.14, depth + 0.1, 0x715039, 0, height, 0);
return group;
}
function addTable(parent, x, y, z, width = 2.2) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const topColor = 0xa9784e;
addBox(group, width, 0.16, 1.05, topColor, 0, 0.87, 0);
addBox(group, 0.18, 0.78, 0.18, 0x5a4334, -width / 2 + 0.2, 0.39, -0.34);
addBox(group, 0.18, 0.78, 0.18, 0x5a4334, width / 2 - 0.2, 0.39, -0.34);
addBox(group, 0.18, 0.78, 0.18, 0x5a4334, -width / 2 + 0.2, 0.39, 0.34);
addBox(group, 0.18, 0.78, 0.18, 0x5a4334, width / 2 - 0.2, 0.39, 0.34);
// Books left on the table.
addBox(group, 0.55, 0.09, 0.4, 0x4e91aa, -0.3, 1.0, 0.02);
addBox(group, 0.48, 0.08, 0.36, 0xe18855, -0.27, 1.085, 0.0);
addBox(group, 0.45, 0.07, 0.34, 0x8b70ae, -0.29, 1.16, -0.02);
return group;
}
function addChair(parent, x, y, z, rotation = 0, color = 0x567c7d) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
parent.add(group);
addBox(group, 0.58, 0.12, 0.58, color, 0, 0.48, 0);
addBox(group, 0.58, 0.55, 0.12, color, 0, 0.77, -0.25);
[-0.21, 0.21].forEach((lx) => {
[-0.21, 0.21].forEach((lz) => {
addBox(group, 0.09, 0.45, 0.09, 0x4b4037, lx, 0.23, lz);
});
});
return group;
}
function addPlant(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
addBox(group, 0.48, 0.48, 0.48, 0xb36f52, 0, 0.24, 0);
addBox(group, 0.14, 0.8, 0.14, 0x4e684a, 0, 0.75, 0);
addBox(group, 0.6, 0.25, 0.25, 0x5e8a57, 0, 0.9, 0);
addBox(group, 0.25, 0.25, 0.65, 0x729e5e, 0, 1.12, 0);
addBox(group, 0.42, 0.22, 0.22, 0x4e8054, 0.08, 1.38, 0.02);
return group;
}
// ---------------------------------------------------------------------
// Lower level furnishing
// ---------------------------------------------------------------------
addBox(scene, 6.4, 0.035, 3.5, 0x244957, -1.3, 0.02, 2.9);
addBox(scene, 5.9, 0.045, 3.0, 0x2b5965, -1.3, 0.035, 2.9);
addTable(scene, -2.7, 0, 2.5, 2.35);
addTable(scene, 0.5, 0, 2.6, 2.2);
addChair(scene, -2.7, 0, 1.55, 0, 0x9c6656);
addChair(scene, -2.7, 0, 3.42, Math.PI, 0x6b8b7b);
addChair(scene, 0.5, 0, 1.58, 0, 0x6b8b7b);
addChair(scene, 0.5, 0, 3.45, Math.PI, 0x9c6656);
addBookcase(scene, 1.0, 0, -5.52, 3.2);
addBookcase(scene, 5.7, 0, -5.52, 3.2);
addBookcase(scene, 9.35, 0, 1.65, 3.7, Math.PI / 2);
addPlant(scene, 9.05, 0, 4.85, 1.05);
addPlant(scene, -9.15, 0, 4.65, 0.9);
// ---------------------------------------------------------------------
// Upper level furnishing
// ---------------------------------------------------------------------
addBookcase(scene, -3.25, 4.4, -5.5, 3.15);
addBookcase(scene, 0.8, 4.4, -5.5, 3.35);
addBookcase(scene, 5.1, 4.4, -5.5, 3.2);
addTable(scene, 4.65, 4.4, -2.55, 2.25);
addChair(scene, 4.65, 4.4, -3.42, 0, 0x9c6656);
addChair(scene, 4.65, 4.4, -1.72, Math.PI, 0x658782);
addPlant(scene, 9.05, 4.4, -4.75, 0.9);
addPlant(scene, -4.5, 4.4, -2.0, 0.72);
// ---------------------------------------------------------------------
// Lift shaft and moving cabin
// ---------------------------------------------------------------------
const liftX = -7;
const liftZ = -2.5;
const upperFloorY = 4.4;
const shaft = new THREE.Group();
scene.add(shaft);
const shaftMetal = 0x31474f;
[-1.08, 1.08].forEach((dx) => {
[-1.08, 1.08].forEach((dz) => {
addBox(
shaft,
0.13,
7.05,
0.13,
shaftMetal,
liftX + dx,
3.525,
liftZ + dz
);
addBox(
shaft,
0.06,
6.75,
0.06,
0x5edeea,
liftX + dx,
3.5,
liftZ + dz,
{
emissive: true,
emissiveIntensity: 0.65,
castShadow: false
}
);
});
});
[0.18, 4.36, 7.0].forEach((y) => {
addBox(shaft, 2.3, 0.12, 2.3, shaftMetal, liftX, y, liftZ);
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x79dbe7,
roughness: 0.18,
metalness: 0.02,
transparent: true,
opacity: 0.12,
depthWrite: false
});
addBox(shaft, 2.0, 3.95, 0.035, glassMaterial, liftX, 3.55, liftZ - 1.04, {
castShadow: false
});
addBox(shaft, 0.035, 3.95, 2.0, glassMaterial, liftX - 1.04, 3.55, liftZ, {
castShadow: false
});
addBox(shaft, 0.035, 3.95, 2.0, glassMaterial, liftX + 1.04, 3.55, liftZ, {
castShadow: false
});
// Front door frame.
addBox(shaft, 0.13, 2.6, 0.14, 0x78dce7, liftX - 1.05, 1.3, liftZ + 1.05, {
emissive: true,
emissiveIntensity: 0.25
});
addBox(shaft, 0.13, 2.6, 0.14, 0x78dce7, liftX + 1.05, 1.3, liftZ + 1.05, {
emissive: true,
emissiveIntensity: 0.25
});
addBox(shaft, 2.2, 0.14, 0.14, 0x78dce7, liftX, 2.6, liftZ + 1.05, {
emissive: true,
emissiveIntensity: 0.25
});
const cabin = new THREE.Group();
cabin.position.set(liftX, 0, liftZ);
scene.add(cabin);
addBox(cabin, 1.94, 0.16, 1.94, 0x48616a, 0, -0.08, 0);
addBox(cabin, 1.94, 0.08, 1.94, 0x526d75, 0, 2.35, 0);
addBox(cabin, 0.09, 2.4, 0.09, 0x70dbe5, -0.92, 1.18, 0.92);
addBox(cabin, 0.09, 2.4, 0.09, 0x70dbe5, 0.92, 1.18, 0.92);
const cabinBack = addBox(
cabin,
1.82,
1.95,
0.025,
glassMaterial,
0,
1.14,
-0.92,
{ castShadow: false }
);
const cabinSide = addBox(
cabin,
0.025,
1.95,
1.82,
glassMaterial,
-0.92,
1.14,
0,
{ castShadow: false }
);
// Small warm cabin lamp.
const cabinGlow = new THREE.PointLight(0xffd29a, 4.5, 3.8, 2);
cabinGlow.position.set(0, 1.9, 0);
cabin.add(cabinGlow);
// ---------------------------------------------------------------------
// Voxel visitor carrying books
// ---------------------------------------------------------------------
function createVisitor() {
const root = new THREE.Group();
scene.add(root);
const body = new THREE.Group();
root.add(body);
// Torso, neck and head.
addBox(body, 0.48, 0.62, 0.3, 0xd66f4e, 0, 1.04, 0);
addBox(body, 0.38, 0.09, 0.24, 0xefc4a0, 0, 1.4, 0);
addBox(body, 0.42, 0.42, 0.4, 0xefc4a0, 0, 1.66, 0);
addBox(body, 0.44, 0.14, 0.42, 0x35343a, 0, 1.85, -0.015);
addBox(body, 0.44, 0.2, 0.12, 0x35343a, 0, 1.81, 0.2);
// Eyes.
addBox(body, 0.055, 0.06, 0.025, 0x17242b, -0.105, 1.68, 0.205, {
castShadow: false
});
addBox(body, 0.055, 0.06, 0.025, 0x17242b, 0.105, 1.68, 0.205, {
castShadow: false
});
// Legs with pivots.
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.13, 0.72, 0);
rightLeg.position.set(0.13, 0.72, 0);
body.add(leftLeg, rightLeg);
addBox(leftLeg, 0.18, 0.56, 0.2, 0x314957, 0, -0.28, 0);
addBox(rightLeg, 0.18, 0.56, 0.2, 0x314957, 0, -0.28, 0);
addBox(leftLeg, 0.21, 0.13, 0.34, 0x273038, 0, -0.59, 0.06);
addBox(rightLeg, 0.21, 0.13, 0.34, 0x273038, 0, -0.59, 0.06);
// Arms bent toward the books.
addBox(body, 0.16, 0.55, 0.17, 0xd66f4e, -0.32, 1.08, 0.02);
addBox(body, 0.16, 0.55, 0.17, 0xd66f4e, 0.32, 1.08, 0.02);
addBox(body, 0.17, 0.17, 0.38, 0xefc4a0, -0.27, 0.86, 0.19);
addBox(body, 0.17, 0.17, 0.38, 0xefc4a0, 0.27, 0.86, 0.19);
// A clearly visible stack of books.
const books = new THREE.Group();
books.position.set(0, 0.98, 0.37);
body.add(books);
addBox(books, 0.57, 0.11, 0.25, 0x4e91aa, 0, 0, 0);
addBox(books, 0.53, 0.1, 0.23, 0xe18855, -0.015, 0.105, 0);
addBox(books, 0.49, 0.09, 0.22, 0x8b70ae, -0.01, 0.2, 0);
addBox(books, 0.45, 0.08, 0.2, 0xd9d3bb, -0.005, 0.285, 0);
// Small backpack block.
addBox(body, 0.36, 0.42, 0.17, 0x536b78, 0, 1.04, -0.22);
return { root, body, leftLeg, rightLeg, books };
}
const visitor = createVisitor();
// ---------------------------------------------------------------------
// Continuous overhead trace
// ---------------------------------------------------------------------
const traceGroup = new THREE.Group();
scene.add(traceGroup);
const tracePoints = [
new THREE.Vector3(liftX, 1.78, 4.8),
new THREE.Vector3(liftX, 1.78, -1.15),
new THREE.Vector3(liftX, 1.78, liftZ),
new THREE.Vector3(liftX, 6.25, liftZ),
new THREE.Vector3(liftX, 6.25, -1.15),
new THREE.Vector3(-0.8, 6.25, -3.9)
];
const traceCurve = new THREE.CatmullRomCurve3(
tracePoints,
false,
"catmullrom",
0.12
);
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0x5be9f4,
transparent: true,
opacity: 0.14,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const glowTube = new THREE.Mesh(
new THREE.TubeGeometry(traceCurve, 220, 0.105, 8, false),
glowMaterial
);
glowTube.renderOrder = 3;
traceGroup.add(glowTube);
const traceTube = new THREE.Mesh(
new THREE.TubeGeometry(traceCurve, 220, 0.034, 8, false),
new THREE.MeshBasicMaterial({
color: 0x9af7ff,
transparent: true,
opacity: 0.96
})
);
traceTube.renderOrder = 4;
traceGroup.add(traceTube);
// Bright voxel beads make the route's continuity easy to follow.
const beadGeometry = new THREE.BoxGeometry(0.075, 0.075, 0.075);
const beadMaterial = new THREE.MeshBasicMaterial({
color: 0xc4fdff
});
for (let i = 0; i <= 54; i++) {
const point = traceCurve.getPointAt(i / 54);
const bead = new THREE.Mesh(beadGeometry, beadMaterial);
bead.position.copy(point);
bead.rotation.set(i * 0.17, i * 0.23, i * 0.11);
traceGroup.add(bead);
}
// Flat route markers reinforce the ground and upper walking paths.
const floorMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x55dce8,
emissive: 0x55dce8,
emissiveIntensity: 0.8,
roughness: 0.45
});
for (let z = 4.45; z > -0.85; z -= 0.56) {
addBox(
traceGroup,
0.2,
0.025,
0.2,
floorMarkerMaterial,
liftX,
0.035,
z,
{ castShadow: false }
);
}
for (let i = 0; i <= 11; i++) {
const t = i / 11;
const x = THREE.MathUtils.lerp(liftX, -0.8, t);
const z = THREE.MathUtils.lerp(-1.15, -3.9, t);
addBox(
traceGroup,
0.19,
0.025,
0.19,
floorMarkerMaterial,
x,
upperFloorY + 0.025,
z,
{ castShadow: false }
);
}
// ---------------------------------------------------------------------
// Scene labels
// ---------------------------------------------------------------------
const liftLabel = makeLabel("LIFT • 01–02");
liftLabel.position.set(liftX, 2.85, -1.22);
liftLabel.scale.set(2.6, 0.65, 1);
scene.add(liftLabel);
const upperLabel = makeLabel("QUIET STACKS");
upperLabel.position.set(0.9, 7.15, -5.75);
upperLabel.scale.set(3.6, 0.9, 1);
scene.add(upperLabel);
const stairLabel = makeLabel("STAIRS");
stairLabel.position.set(6.4, 2.0, 3.55);
stairLabel.scale.set(1.8, 0.45, 1);
scene.add(stairLabel);
const levelOneLabel = makeLabel("01");
levelOneLabel.position.set(-9.25, 1.0, 0.9);
levelOneLabel.scale.set(0.8, 0.2, 1);
scene.add(levelOneLabel);
const levelTwoLabel = makeLabel("02");
levelTwoLabel.position.set(-9.25, 5.35, 0.9);
levelTwoLabel.scale.set(0.8, 0.2, 1);
scene.add(levelTwoLabel);
// ---------------------------------------------------------------------
// Visitor route animation
// ---------------------------------------------------------------------
const routeKeys = [
{ t: 0.0, p: new THREE.Vector3(liftX, 0.03, 4.8) },
{ t: 4.4, p: new THREE.Vector3(liftX, 0.03, -1.1) },
{ t: 5.2, p: new THREE.Vector3(liftX, 0.03, liftZ) },
{ t: 10.0, p: new THREE.Vector3(liftX, 4.43, liftZ) },
{ t: 10.8, p: new THREE.Vector3(liftX, 4.43, -1.1) },
{ t: 16.0, p: new THREE.Vector3(-0.8, 4.43, -3.9) },
{ t: 20.5, p: new THREE.Vector3(-0.8, 4.43, -3.9) },
{ t: 25.0, p: new THREE.Vector3(liftX, 4.43, -1.1) },
{ t: 25.8, p: new THREE.Vector3(liftX, 4.43, liftZ) },
{ t: 30.5, p: new THREE.Vector3(liftX, 0.03, liftZ) },
{ t: 31.3, p: new THREE.Vector3(liftX, 0.03, -1.1) },
{ t: 35.0, p: new THREE.Vector3(liftX, 0.03, 4.8) },
{ t: 36.0, p: new THREE.Vector3(liftX, 0.03, 4.8) }
];
const routeCycle = routeKeys[routeKeys.length - 1].t;
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function sampleRoute(time) {
const t = ((time % routeCycle) + routeCycle) % routeCycle;
for (let i = 0; i < routeKeys.length - 1; i++) {
const a = routeKeys[i];
const b = routeKeys[i + 1];
if (t >= a.t && t <= b.t) {
const local = b.t === a.t ? 0 : (t - a.t) / (b.t - a.t);
const eased = smoothstep(local);
const position = a.p.clone().lerp(b.p, eased);
const direction = b.p.clone().sub(a.p);
const vertical = Math.abs(direction.y) > 0.01;
return {
t,
position,
direction,
walking: !vertical && direction.lengthSq() > 0.0001
};
}
}
return {
t,
position: routeKeys[0].p.clone(),
direction: new THREE.Vector3(),
walking: false
};
}
function lerpAngle(a, b, amount) {
const difference = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + difference * amount;
}
let currentYaw = Math.PI;
let simulationTime = 0;
let paused = false;
const routeStatus = document.getElementById("routeStatus");
const levelOne = document.getElementById("levelOne");
const levelTwo = document.getElementById("levelTwo");
function updateRouteUI(t) {
let message;
let upper = false;
if (t < 4.4) {
message = "Lower hall · approaching lift";
} else if (t < 5.2) {
message = "Entering the lift cabin";
} else if (t < 10) {
message = "Lift ascent · level 01 → 02";
upper = true;
} else if (t < 10.8) {
message = "Upper landing · exiting lift";
upper = true;
} else if (t < 20.5) {
message = "Upper stacks · carrying books";
upper = true;
} else if (t < 25) {
message = "Returning through quiet stacks";
upper = true;
} else if (t < 25.8) {
message = "Returning to the lift";
upper = true;
} else if (t < 30.5) {
message = "Lift descent · level 02 → 01";
} else if (t < 35) {
message = "Lower landing · route complete";
} else {
message = "Lower hall · approaching lift";
}
routeStatus.textContent = message;
levelOne.classList.toggle("active", !upper);
levelTwo.classList.toggle("active", upper);
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard and touch
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.15, 0),
theta: 0.68,
phi: 1.03,
radius: 25.5
};
const initialCameraState = {
theta: 0.68,
phi: 1.03,
radius: 25.5
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const canvas = renderer.domElement;
const pointers = new Map();
let singlePointerPrevious = null;
let previousPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
singlePointerPrevious = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && singlePointerPrevious) {
const dx = event.clientX - singlePointerPrevious.x;
const dy = event.clientY - singlePointerPrevious.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.35,
1.42
);
singlePointerPrevious = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
13,
43
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
singlePointerPrevious = null;
previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
13,
43
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.35, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.42, cameraState.phi + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(13, cameraState.radius - 1);
break;
case "-":
cameraState.radius = Math.min(43, cameraState.radius + 1);
break;
}
});
document.getElementById("resetButton").addEventListener("click", () => {
cameraState.theta = initialCameraState.theta;
cameraState.phi = initialCameraState.phi;
cameraState.radius = initialCameraState.radius;
cameraState.target.set(0, 2.15, 0);
});
const pauseButton = document.getElementById("pauseButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume route" : "Pause route";
});
const traceButton = document.getElementById("traceButton");
traceButton.addEventListener("click", () => {
traceGroup.visible = !traceGroup.visible;
traceButton.textContent = traceGroup.visible ? "Hide trace" : "Show trace";
});
// ---------------------------------------------------------------------
// Resize and animation loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta;
const sample = sampleRoute(simulationTime);
const walkCycle = simulationTime * 10;
visitor.root.position.copy(sample.position);
if (sample.walking) {
const targetYaw = Math.atan2(
sample.direction.x,
sample.direction.z
);
currentYaw = lerpAngle(currentYaw, targetYaw, 1 - Math.exp(-delta * 10));
const swing = Math.sin(walkCycle) * 0.58;
visitor.leftLeg.rotation.x = swing;
visitor.rightLeg.rotation.x = -swing;
visitor.body.position.y = Math.abs(Math.sin(walkCycle)) * 0.035;
visitor.books.rotation.z = Math.sin(walkCycle * 0.5) * 0.025;
} else {
const smoothing = 1 - Math.exp(-delta * 8);
visitor.leftLeg.rotation.x = THREE.MathUtils.lerp(
visitor.leftLeg.rotation.x,
0,
smoothing
);
visitor.rightLeg.rotation.x = THREE.MathUtils.lerp(
visitor.rightLeg.rotation.x,
0,
smoothing
);
visitor.body.position.y = THREE.MathUtils.lerp(
visitor.body.position.y,
0,
smoothing
);
visitor.books.rotation.z = THREE.MathUtils.lerp(
visitor.books.rotation.z,
0,
smoothing
);
}
visitor.root.rotation.y = currentYaw;
// Cabin follows the visitor exactly while the lift is moving.
const ascending = sample.t >= 5.2 && sample.t <= 10.0;
const descending = sample.t >= 25.8 && sample.t <= 30.5;
if (ascending || descending) {
cabin.position.y = sample.position.y;
} else if (sample.t >= 10.0 && sample.t < 25.8) {
cabin.position.y = upperFloorY + 0.03;
} else {
cabin.position.y = 0.03;
}
// Subtle light movement reinforces the lift's motion.
liftLight.intensity =
17 + Math.sin(simulationTime * 1.4) * 2.5;
updateRouteUI(sample.t);
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```