Prompt specification
Build or customize the Three.js 3D scene "Door cycle and boarding state" 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: Door cycle and boarding state
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/door-cycle-and-boarding-state-x0430
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Animate a lift arriving, leveling, opening, boarding, and closing in sequence; the visitor moves only when the cabin is present and doors are fully open.
Working Three.js Starter (door-cycle-and-boarding-state-x0430):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Station Lift</title>
<style>
:root {
--ink: #17333b;
--muted: #61777d;
--panel: rgba(250, 252, 249, 0.92);
--line: rgba(23, 51, 59, 0.12);
--accent: #e47d4f;
--teal: #267a7c;
--green: #23845b;
--amber: #c98224;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9ec;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(340px, calc(100vw - 40px));
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(28, 62, 69, 0.14),
inset 0 0 0 1px rgba(255, 255, 255, 0.3);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--teal);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(228, 125, 79, 0.14);
}
h1 {
margin: 0;
font-size: clamp(1.45rem, 3vw, 2rem);
line-height: 1.05;
letter-spacing: -0.04em;
}
.intro {
margin: 9px 0 17px;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.status-label {
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
color: var(--muted);
}
.status-pill {
padding: 6px 9px;
border-radius: 999px;
background: #e6f0ed;
color: var(--teal);
font-size: 0.7rem;
font-weight: 800;
white-space: nowrap;
}
.progress-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 51, 59, 0.08);
}
.progress-fill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #59a6a0);
transform: scaleX(0);
transform-origin: left center;
}
.steps {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
margin: 18px 0;
padding: 0;
list-style: none;
}
.step {
min-width: 0;
color: #9aabad;
font-size: 0.58rem;
font-weight: 800;
letter-spacing: 0.05em;
text-align: center;
text-transform: uppercase;
}
.step::before {
content: "";
display: block;
width: 9px;
height: 9px;
margin: 0 auto 8px;
border: 2px solid #bdc9ca;
border-radius: 50%;
background: transparent;
transition: 180ms ease;
}
.step.active {
color: var(--accent);
}
.step.active::before {
border-color: var(--accent);
background: var(--accent);
box-shadow: 0 0 0 5px rgba(228, 125, 79, 0.14);
}
.step.done {
color: var(--teal);
}
.step.done::before {
border-color: var(--teal);
background: var(--teal);
}
.interlock {
display: flex;
align-items: center;
gap: 12px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.58);
}
.lock-dot {
flex: 0 0 auto;
width: 13px;
height: 13px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 5px rgba(201, 130, 36, 0.12);
transition: 180ms ease;
}
.interlock.unlocked .lock-dot {
background: var(--green);
box-shadow: 0 0 0 5px rgba(35, 132, 91, 0.12);
}
.interlock small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 0.61rem;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.interlock strong {
display: block;
font-size: 0.78rem;
line-height: 1.25;
}
.telemetry {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.telemetry div {
padding: 10px 11px;
border-radius: 12px;
background: rgba(23, 51, 59, 0.045);
color: var(--muted);
font-size: 0.66rem;
font-weight: 700;
text-transform: uppercase;
}
.telemetry b {
display: block;
margin-top: 4px;
color: var(--ink);
font-size: 0.9rem;
font-variant-numeric: tabular-nums;
text-transform: none;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 13px;
}
button {
flex: 1;
min-height: 38px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: #fff;
font: inherit;
font-size: 0.75rem;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
opacity 120ms ease,
background 120ms ease;
}
button:hover {
background: #244a52;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button.secondary {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
}
button:disabled {
opacity: 0.45;
cursor: default;
transform: none;
}
.camera-hint {
position: fixed;
z-index: 5;
right: 18px;
bottom: 18px;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 999px;
background: rgba(250, 252, 249, 0.78);
color: var(--muted);
font-size: 0.68rem;
font-weight: 700;
box-shadow: 0 8px 24px rgba(28, 62, 69, 0.1);
backdrop-filter: blur(10px);
pointer-events: none;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #dce9ec;
color: var(--ink);
font-weight: 800;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 600px) {
.hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
.intro {
display: none;
}
.steps {
margin: 14px 0;
}
.camera-hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section class="hud" aria-label="Lift animation controls and status">
<div class="eyebrow">Station 04 · Vertical Transit</div>
<h1>Platform Lift</h1>
<p class="intro">
A low-poly arrival cycle with a safety interlock: the visitor can move
only when the cabin is at the landing and both doors are fully open.
</p>
<div class="status-row">
<span class="status-label">Current state</span>
<span id="phaseStatus" class="status-pill" aria-live="polite">
Arriving
</span>
</div>
<div class="progress-track">
<div id="progressFill" class="progress-fill"></div>
</div>
<ol class="steps" aria-label="Lift sequence">
<li class="step active" data-phase="arriving">Arrive</li>
<li class="step" data-phase="leveling">Level</li>
<li class="step" data-phase="opening">Open</li>
<li class="step" data-phase="boarding">Board</li>
<li class="step" data-phase="closing">Close</li>
</ol>
<div id="interlock" class="interlock" aria-live="polite">
<span id="lockDot" class="lock-dot"></span>
<div>
<small>Visitor motion interlock</small>
<strong id="motionLabel">Locked — waiting for a level cabin</strong>
</div>
</div>
<div class="telemetry">
<div>Cabin offset<b id="cabinValue">−2.35 m</b></div>
<div>Door opening<b id="doorValue">0%</b></div>
</div>
<div class="buttons">
<button id="pauseButton" type="button">Pause</button>
<button id="replayButton" class="secondary" type="button">Replay cycle</button>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<div id="loading" class="loading">Building the station…</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 app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D station with an animated elevator and visitor"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9ec);
scene.fog = new THREE.Fog(0xdce9ec, 15, 32);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// -------------------------------------------------------------------------
// Custom camera controls: no addons are used.
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.64,
phi: 0.98,
radius: 13.2,
target: new THREE.Vector3(0.3, 0.35, 0.1)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const horizontal = radius * Math.sin(phi);
camera.position.set(
target.x + horizontal * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + horizontal * Math.cos(theta)
);
camera.lookAt(target);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.48,
1.36
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.01,
7.5,
19
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
if (!event.target.closest("button")) togglePause();
}
if (event.code === "ArrowLeft") {
cameraState.theta -= 0.08;
}
if (event.code === "ArrowRight") {
cameraState.theta += 0.08;
}
if (event.code === "ArrowUp") {
cameraState.phi = Math.max(0.48, cameraState.phi - 0.05);
}
if (event.code === "ArrowDown") {
cameraState.phi = Math.min(1.36, cameraState.phi + 0.05);
}
updateCamera();
});
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...options
});
}
const materials = {
platform: material(0xd7d1bd),
platformEdge: material(0xa99f88),
tileA: material(0xe6e1d1),
tileB: material(0xd9d5c7),
lowerFloor: material(0x9baeb0),
wall: material(0xe9e8df),
wallInset: material(0xcbd9d8),
steel: material(0x36535a, { metalness: 0.55, roughness: 0.4 }),
darkSteel: material(0x203b42, { metalness: 0.55, roughness: 0.4 }),
teal: material(0x2c7778),
tealDark: material(0x21585d),
door: material(0x438b8c, { metalness: 0.18, roughness: 0.48 }),
glass: material(0xa8d3d1, {
transparent: true,
opacity: 0.18,
depthWrite: false,
metalness: 0.05,
roughness: 0.2
}),
yellow: material(0xe0a844),
orange: material(0xdf7b4d),
green: material(0x5b8f68),
greenLight: material(0x78a875),
greenDark: material(0x3d6d53),
wood: material(0xa8754e),
navy: material(0x29455d),
skin: material(0xd59c76),
hair: material(0x46362f),
shoe: material(0x28353a),
white: material(0xf4f2e8),
sensor: material(0xe1a547, {
emissive: 0xe1a547,
emissiveIntensity: 0.65
})
};
function addMesh(parent, geometry, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, width, height, depth, x, y, z, mat) {
return addMesh(
parent,
new THREE.BoxGeometry(width, height, depth),
mat,
x,
y,
z
);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
x,
y,
z,
mat
) {
return addMesh(
parent,
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
mat,
x,
y,
z
);
}
function addTextSprite(text, color = "#244b53") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = color;
context.font = "800 92px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(4.4, 1.1, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf5fbff, 0x7f8274, 2.1));
const sun = new THREE.DirectionalLight(0xfff1d7, 3.0);
sun.position.set(-7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x9ed7dd, 1.25);
rimLight.position.set(7, 5, -7);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Environment
// -------------------------------------------------------------------------
const lowerGround = addMesh(
scene,
new THREE.PlaneGeometry(40, 40),
materials.lowerFloor,
0,
-2.62,
0
);
lowerGround.rotation.x = -Math.PI / 2;
lowerGround.castShadow = false;
addBox(scene, 12, 7.4, 0.3, -0.3, 1.05, -3.65, materials.wall);
for (const x of [-3.7, -1.7, 3.7]) {
addBox(
scene,
1.65,
2.65,
0.08,
x,
1.55,
-3.47,
materials.wallInset
);
}
const stationSign = addTextSprite("CENTRAL STATION");
stationSign.position.set(-1.6, 3.0, -3.35);
stationSign.scale.set(4.8, 1.2, 1);
scene.add(stationSign);
// Platform areas leave an opening for the vertical lift shaft.
function addPlatformArea(x0, x1, z0, z1) {
const width = x1 - x0;
const depth = z1 - z0;
addBox(
scene,
width,
0.36,
depth,
(x0 + x1) / 2,
-0.18,
(z0 + z1) / 2,
materials.platform
);
const step = 0.8;
const columns = Math.max(1, Math.round(width / step));
const rows = Math.max(1, Math.round(depth / step));
const tileWidth = width / columns;
const tileDepth = depth / rows;
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
const tile = addBox(
scene,
tileWidth - 0.035,
0.035,
tileDepth - 0.035,
x0 + tileWidth * (column + 0.5),
0.0175,
z0 + tileDepth * (row + 0.5),
(column + row) % 2 === 0
? materials.tileA
: materials.tileB
);
tile.castShadow = false;
}
}
}
addPlatformArea(-4.5, 0.15, -2.8, 4.0);
addPlatformArea(0.15, 4.5, 0.8, 4.0);
addPlatformArea(2.85, 4.5, -2.8, 0.8);
addPlatformArea(0.15, 2.85, -2.8, -1.8);
addPlatformArea(0.2, 2.8, 0.5, 0.8);
// Platform edge trim.
addBox(scene, 9.0, 0.12, 0.16, 0, -0.1, 3.92, materials.platformEdge);
addBox(scene, 0.16, 0.12, 6.8, -4.42, -0.1, 0.6, materials.platformEdge);
// Tactile safety strip in front of the lift.
addBox(scene, 2.25, 0.045, 0.18, 1.5, 0.045, 1.06, materials.yellow);
for (let index = 0; index < 10; index++) {
const dot = addCylinder(
scene,
0.035,
0.035,
0.018,
8,
0.52 + index * 0.22,
0.078,
1.06,
materials.orange
);
dot.castShadow = false;
}
// -------------------------------------------------------------------------
// Lift shaft
// -------------------------------------------------------------------------
const shaft = new THREE.Group();
scene.add(shaft);
// Transparent rear and side panels.
addBox(shaft, 2.68, 6.15, 0.055, 1.5, 0.42, -1.73, materials.glass);
addBox(shaft, 0.045, 6.15, 2.2, 0.11, 0.42, -0.6, materials.glass);
addBox(shaft, 0.045, 6.15, 2.2, 2.89, 0.42, -0.6, materials.glass);
// Structural frame.
for (const x of [0.1, 2.9]) {
addBox(shaft, 0.13, 6.25, 0.14, x, 0.48, 0.56, materials.steel);
addBox(shaft, 0.13, 6.25, 0.14, x, 0.48, -1.75, materials.steel);
}
addBox(shaft, 3.05, 0.18, 0.22, 1.5, 3.55, 0.56, materials.steel);
addBox(shaft, 3.05, 0.18, 0.22, 1.5, 3.55, -1.75, materials.steel);
addBox(shaft, 0.18, 0.18, 2.45, 0.1, 3.55, -0.6, materials.steel);
addBox(shaft, 0.18, 0.18, 2.45, 2.9, 3.55, -0.6, materials.steel);
// Guide rails.
addBox(shaft, 0.07, 6.2, 0.08, 0.37, 0.35, -1.52, materials.darkSteel);
addBox(shaft, 0.07, 6.2, 0.08, 2.63, 0.35, -1.52, materials.darkSteel);
// Lower landing inside the shaft.
addBox(shaft, 2.5, 0.16, 2.2, 1.5, -2.5, -0.6, materials.darkSteel);
addBox(shaft, 2.25, 0.025, 0.15, 1.5, -2.405, 0.28, materials.yellow);
// Top canopy.
addBox(shaft, 3.25, 0.18, 2.65, 1.5, 3.72, -0.6, materials.tealDark);
const liftSign = addTextSprite("LIFT 01", "#f5f2e7");
liftSign.position.set(1.5, 3.28, 0.72);
liftSign.scale.set(2.1, 0.58, 1);
shaft.add(liftSign);
// Door interlock indicator.
const sensorLight = addCylinder(
shaft,
0.085,
0.085,
0.055,
12,
2.63,
2.38,
0.66,
materials.sensor
);
sensorLight.rotation.x = Math.PI / 2;
// Call panel.
const callPanel = addBox(
scene,
0.3,
0.72,
0.16,
-0.12,
0.8,
0.5,
materials.darkSteel
);
callPanel.rotation.y = -0.12;
const callButton = addCylinder(
scene,
0.075,
0.075,
0.045,
12,
-0.13,
0.95,
0.61,
materials.orange
);
callButton.rotation.x = Math.PI / 2;
const callIndicator = addCylinder(
scene,
0.04,
0.04,
0.035,
10,
-0.13,
0.69,
0.61,
materials.green
);
callIndicator.rotation.x = Math.PI / 2;
// -------------------------------------------------------------------------
// Elevator cabin
// -------------------------------------------------------------------------
const LANDING_Y = 0;
const CABIN_START_Y = -2.35;
const cabin = new THREE.Group();
cabin.position.set(1.5, CABIN_START_Y, -0.55);
scene.add(cabin);
// Floor, ceiling, back and side walls.
addBox(cabin, 2.25, 0.16, 2.05, 0, -0.08, 0, materials.tealDark);
addBox(cabin, 2.25, 0.14, 2.05, 0, 2.5, 0, materials.tealDark);
addBox(cabin, 2.18, 2.38, 0.08, 0, 1.2, -1.0, materials.teal);
addBox(cabin, 0.065, 2.38, 2.0, -1.1, 1.2, 0, materials.glass);
addBox(cabin, 0.065, 2.38, 2.0, 1.1, 1.2, 0, materials.glass);
// Interior details.
addBox(cabin, 1.62, 0.75, 0.025, 0, 1.58, -0.945, materials.wallInset);
addBox(cabin, 1.18, 0.12, 0.07, 0, 1.1, -0.9, materials.steel);
addBox(cabin, 1.55, 0.035, 0.12, 0, 2.38, 0.1, materials.white);
const cabinLight = new THREE.PointLight(0xffe6b8, 8, 4.5, 2);
cabinLight.position.set(0, 2.15, 0.15);
cabin.add(cabinLight);
// Door frame.
addBox(cabin, 0.10, 2.34, 0.12, -1.1, 1.17, 1.04, materials.steel);
addBox(cabin, 0.10, 2.34, 0.12, 1.1, 1.17, 1.04, materials.steel);
addBox(cabin, 2.28, 0.10, 0.12, 0, 2.3, 1.04, materials.steel);
const doorWidth = 1.05;
const doorTravel = 1.055;
function createDoorLeaf() {
const leaf = new THREE.Group();
addBox(
leaf,
doorWidth,
2.18,
0.075,
0,
1.09,
0,
materials.door
);
addBox(
leaf,
0.57,
1.42,
0.022,
0,
1.33,
0.052,
materials.glass
);
addBox(
leaf,
0.035,
2.05,
0.025,
doorWidth * 0.5 - 0.06,
1.09,
0.055,
materials.tealDark
);
return leaf;
}
const leftDoor = createDoorLeaf();
const rightDoor = createDoorLeaf();
leftDoor.position.set(-doorWidth / 2, 0, 1.045);
rightDoor.position.set(doorWidth / 2, 0, 1.045);
cabin.add(leftDoor, rightDoor);
let doorOpen = 0;
function applyDoorState() {
leftDoor.position.x = -doorWidth / 2 - doorTravel * doorOpen;
rightDoor.position.x = doorWidth / 2 + doorTravel * doorOpen;
}
applyDoorState();
// -------------------------------------------------------------------------
// Low-poly visitor
// -------------------------------------------------------------------------
const visitor = new THREE.Group();
scene.add(visitor);
// Legs and shoes.
for (const x of [-0.11, 0.11]) {
addCylinder(visitor, 0.075, 0.065, 0.55, 6, x, 0.37, 0, materials.navy);
addBox(visitor, 0.17, 0.1, 0.28, x, 0.07, 0.045, materials.shoe);
}
// Torso.
addCylinder(visitor, 0.19, 0.14, 0.58, 6, 0, 0.91, 0, materials.orange);
// Neck and head.
addCylinder(visitor, 0.065, 0.065, 0.1, 6, 0, 1.25, 0, materials.skin);
const head = addMesh(
visitor,
new THREE.IcosahedronGeometry(0.17, 1),
materials.skin,
0,
1.43,
0
);
head.scale.set(0.9, 1.05, 0.92);
const hair = addMesh(
visitor,
new THREE.IcosahedronGeometry(0.165, 1),
materials.hair,
0,
1.53,
-0.025
);
hair.scale.set(0.93, 0.62, 0.92);
// Small nose indicates the visitor's forward direction.
const nose = addMesh(
visitor,
new THREE.ConeGeometry(0.035, 0.085, 5),
materials.skin,
0,
1.42,
0.16
);
nose.rotation.x = Math.PI / 2;
// Arms.
addCylinder(visitor, 0.06, 0.052, 0.52, 6, -0.245, 0.86, 0, materials.orange);
addCylinder(visitor, 0.06, 0.052, 0.52, 6, 0.245, 0.86, 0, materials.orange);
// Small backpack.
addBox(visitor, 0.3, 0.42, 0.15, 0, 0.96, -0.2, materials.tealDark);
addBox(visitor, 0.21, 0.15, 0.025, 0, 0.93, -0.285, materials.yellow);
const visitorPath = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-2.65, 0.045, 2.65),
new THREE.Vector3(-1.65, 0.045, 1.85),
new THREE.Vector3(-0.35, 0.045, 1.38),
new THREE.Vector3(1.5, 0.045, 1.38),
new THREE.Vector3(1.5, 0.045, 0.72),
new THREE.Vector3(1.5, 0.045, -0.28)
],
false,
"centripetal"
);
let visitorProgress = 0;
function placeVisitor(progress) {
const t = THREE.MathUtils.clamp(progress, 0, 1);
visitor.position.copy(visitorPath.getPointAt(t));
const tangent = visitorPath.getTangentAt(t);
visitor.rotation.y = Math.atan2(tangent.x, tangent.z);
}
placeVisitor(0);
// -------------------------------------------------------------------------
// Station props
// -------------------------------------------------------------------------
function addPlanter(x, z, scale = 1) {
const planter = new THREE.Group();
planter.position.set(x, 0, z);
planter.scale.setScalar(scale);
scene.add(planter);
addCylinder(planter, 0.31, 0.24, 0.45, 8, 0, 0.23, 0, materials.orange);
addCylinder(planter, 0.055, 0.07, 1.05, 6, 0, 0.88, 0, materials.wood);
const foliage = addMesh(
planter,
new THREE.IcosahedronGeometry(0.58, 0),
materials.green,
0,
1.55,
0
);
foliage.scale.set(0.9, 1.15, 0.85);
const foliage2 = addMesh(
planter,
new THREE.IcosahedronGeometry(0.38, 0),
materials.greenLight,
0.25,
1.35,
0.1
);
foliage2.scale.set(0.9, 1.0, 0.9);
}
addPlanter(-3.85, 3.1, 1.05);
addPlanter(3.85, 2.9, 0.9);
// Bench.
addBox(scene, 1.8, 0.12, 0.52, -3.25, 0.46, -1.75, materials.wood);
addBox(scene, 1.8, 0.62, 0.1, -3.25, 0.78, -2.0, materials.wood);
for (const x of [-3.85, -2.65]) {
addBox(scene, 0.12, 0.46, 0.42, x, 0.23, -1.75, materials.steel);
}
// -------------------------------------------------------------------------
// Lift sequence state machine
// -------------------------------------------------------------------------
const durations = {
arriving: 2.8,
leveling: 1.05,
opening: 1.25,
boarding: 3.4,
closing: 1.15
};
const phaseLabels = {
arriving: "Arriving",
leveling: "Leveling",
opening: "Opening",
boarding: "Boarding",
closing: "Closing",
complete: "Complete"
};
let phase = "arriving";
let phaseTime = 0;
let paused = false;
let completed = false;
const phaseStatus = document.querySelector("#phaseStatus");
const progressFill = document.querySelector("#progressFill");
const motionLabel = document.querySelector("#motionLabel");
const interlock = document.querySelector("#interlock");
const cabinValue = document.querySelector("#cabinValue");
const doorValue = document.querySelector("#doorValue");
const pauseButton = document.querySelector("#pauseButton");
const replayButton = document.querySelector("#replayButton");
const stepElements = [...document.querySelectorAll(".step")];
function smoothStep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function easeOut(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return 1 - Math.pow(1 - t, 3);
}
function setPhase(nextPhase) {
phase = nextPhase;
phaseTime = 0;
completed = nextPhase === "complete";
phaseStatus.textContent = phaseLabels[phase];
const order = [
"arriving",
"leveling",
"opening",
"boarding",
"closing"
];
const activeIndex = order.indexOf(phase);
stepElements.forEach((step, index) => {
step.classList.toggle(
"active",
phase !== "complete" && step.dataset.phase === phase
);
step.classList.toggle(
"done",
phase === "complete" || index < activeIndex
);
});
pauseButton.disabled = completed;
pauseButton.textContent = paused ? "Resume" : "Pause";
}
function transitionTo(nextPhase) {
setPhase(nextPhase);
}
function resetCycle() {
phase = "arriving";
phaseTime = 0;
paused = false;
completed = false;
visitorProgress = 0;
doorOpen = 0;
cabin.position.y = CABIN_START_Y;
applyDoorState();
placeVisitor(0);
setPhase("arriving");
pauseButton.textContent = "Pause";
updateTelemetry();
}
function togglePause() {
if (completed) return;
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
}
pauseButton.addEventListener("click", togglePause);
replayButton.addEventListener("click", resetCycle);
// -------------------------------------------------------------------------
// Safety interlock
// -------------------------------------------------------------------------
function cabinIsPresentAtLanding() {
return (
Math.abs(cabin.position.y - LANDING_Y) <= 0.025 &&
Math.abs(cabin.position.x - 1.5) <= 0.001 &&
Math.abs(cabin.position.z + 0.55) <= 0.001
);
}
function doorsAreFullyOpen() {
return doorOpen >= 0.999;
}
function visitorMayMove() {
return (
!paused &&
phase === "boarding" &&
cabinIsPresentAtLanding() &&
doorsAreFullyOpen()
);
}
function updateVisitor(dt) {
/*
* Important: the visitor's position is never changed outside this
* function, and this function only runs while both safety conditions
* are true: cabin at the landing and doors fully open.
*/
if (!visitorMayMove()) return;
visitorProgress = Math.min(1, visitorProgress + dt / durations.boarding);
placeVisitor(visitorProgress);
}
// -------------------------------------------------------------------------
// Simulation
// -------------------------------------------------------------------------
function updateSimulation(dt) {
if (paused || completed) return;
phaseTime += dt;
if (phase === "arriving") {
const progress = THREE.MathUtils.clamp(
phaseTime / durations.arriving,
0,
1
);
cabin.position.y = THREE.MathUtils.lerp(
CABIN_START_Y,
0.12,
smoothStep(progress)
);
if (progress >= 1) {
transitionTo("leveling");
}
} else if (phase === "leveling") {
const progress = THREE.MathUtils.clamp(
phaseTime / durations.leveling,
0,
1
);
cabin.position.y = THREE.MathUtils.lerp(
0.12,
LANDING_Y,
easeOut(progress)
);
if (progress >= 1) {
cabin.position.y = LANDING_Y;
transitionTo("opening");
}
} else if (phase === "opening") {
const progress = THREE.MathUtils.clamp(
phaseTime / durations.opening,
0,
1
);
doorOpen = smoothStep(progress);
applyDoorState();
if (progress >= 1) {
doorOpen = 1;
applyDoorState();
transitionTo("boarding");
}
} else if (phase === "boarding") {
// Doors stay fully open for the entire boarding phase.
doorOpen = 1;
applyDoorState();
updateVisitor(dt);
if (visitorProgress >= 1) {
transitionTo("closing");
}
} else if (phase === "closing") {
const progress = THREE.MathUtils.clamp(
phaseTime / durations.closing,
0,
1
);
doorOpen = 1 - smoothStep(progress);
applyDoorState();
if (progress >= 1) {
doorOpen = 0;
applyDoorState();
transitionTo("complete");
}
}
}
// -------------------------------------------------------------------------
// UI telemetry
// -------------------------------------------------------------------------
function currentPhaseProgress() {
if (phase === "complete") return 1;
if (phase === "boarding") {
return THREE.MathUtils.clamp(
visitorProgress / durations.boarding,
0,
1
);
}
return THREE.MathUtils.clamp(
phaseTime / durations[phase],
0,
1
);
}
function updateTelemetry() {
progressFill.style.transform = `scaleX(${currentPhaseProgress()})`;
const offset = cabin.position.y - LANDING_Y;
cabinValue.textContent = `${offset >= 0 ? "+" : "−"}${Math.abs(offset).toFixed(2)} m`;
doorValue.textContent = `${Math.round(doorOpen * 100)}%`;
const unlocked = visitorMayMove();
interlock.classList.toggle("unlocked", unlocked);
if (unlocked) {
motionLabel.textContent = "Unlocked — cabin present · doors 100% open";
} else if (visitorProgress >= 1) {
motionLabel.textContent = "Locked — visitor safely inside the cabin";
} else if (phase === "boarding") {
motionLabel.textContent = "Locked — checking cabin and door sensors";
} else {
motionLabel.textContent = "Locked — waiting for a level cabin";
}
const sensorsReady = cabinIsPresentAtLanding() && doorsAreFullyOpen();
materials.sensor.color.setHex(sensorsReady ? 0x43c889 : 0xe1a547);
materials.sensor.emissive.setHex(sensorsReady ? 0x43c889 : 0xe1a547);
materials.sensor.emissiveIntensity = sensorsReady ? 1.15 : 0.5;
}
// -------------------------------------------------------------------------
// Resize and render 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);
});
updateCamera();
resetCycle();
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateSimulation(dt);
updateTelemetry();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```