Prompt specification
Build or customize the Three.js 3D scene "Stair access from Chelsea to an elevated path" 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: Stair access from Chelsea to an elevated path
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/stair-access-from-chelsea-to-an-elevated-path-x2770
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel access route from a Chelsea sidewalk to an elevated public walkway in New York. Model a compact street fragment with a nearby facade, one connected stair, its upper landing, and a short stretch of the elevated path. Use a referenced access arrangement while keeping the surrounding city selectively simplified. Animate a pedestrian approaching along the sidewalk, climbing each step, and joining the upper route. Match the character's vertical movement to the actual stair profile and keep its feet out of the masonry. A cutaway side view should make the change in level and the route continuity easy to inspect.
Working Three.js Starter (stair-access-from-chelsea-to-an-elevated-path-x2770):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chelsea Access — Voxel Level Study</title>
<style>
:root {
--ink: #183033;
--muted: #66787a;
--paper: #f4f3ed;
--accent: #e76545;
--teal: #385d5c;
--line: rgba(24, 48, 51, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eeeb;
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:active { cursor: grabbing; }
.masthead {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 780;
}
.subtitle {
margin: 12px 0 0;
max-width: 365px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.study-tag {
display: inline-flex;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(244, 243, 237, 0.66);
color: #52696a;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.panel {
position: fixed;
z-index: 6;
right: 24px;
top: 24px;
width: 242px;
padding: 15px 16px;
border: 1px solid rgba(24, 48, 51, 0.13);
border-radius: 13px;
background: rgba(247, 247, 241, 0.83);
box-shadow: 0 12px 35px rgba(40, 58, 58, 0.09);
backdrop-filter: blur(12px);
}
.panel-title {
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 13px 1fr auto;
gap: 9px;
align-items: center;
margin: 9px 0;
font-size: 11px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 2px;
background: var(--swatch);
border: 1px solid rgba(0, 0, 0, 0.08);
}
.legend-row span:nth-child(2) { color: #3e5657; }
.legend-row span:last-child {
color: #7a8889;
font-variant-numeric: tabular-nums;
font-size: 10px;
}
.controls {
position: fixed;
z-index: 7;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
width: min(820px, calc(100% - 32px));
padding: 11px 12px;
border: 1px solid rgba(24, 48, 51, 0.14);
border-radius: 15px;
background: rgba(248, 248, 243, 0.9);
box-shadow: 0 15px 45px rgba(39, 56, 57, 0.13);
backdrop-filter: blur(14px);
}
button {
appearance: none;
border: 1px solid rgba(24, 48, 51, 0.15);
border-radius: 9px;
padding: 9px 12px;
background: #fffef9;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease, color 120ms ease;
white-space: nowrap;
}
button:hover { background: #eeeee7; }
button:active { transform: translateY(1px); }
button.primary {
min-width: 76px;
border-color: var(--teal);
background: var(--teal);
color: white;
}
button.primary:hover { background: #294b4a; }
button.active {
border-color: rgba(231, 101, 69, 0.5);
background: #fff1eb;
color: #b64e34;
}
.timeline {
position: relative;
flex: 1;
min-width: 100px;
height: 24px;
display: flex;
align-items: center;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 4px;
outline: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--progress, 0%),
#d9ded9 var(--progress, 0%),
#d9ded9 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}
.timecode {
min-width: 67px;
color: #718182;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 27px;
color: rgba(40, 61, 62, 0.63);
font-size: 10px;
line-height: 1.5;
pointer-events: none;
}
.hint kbd {
padding: 2px 5px;
border: 1px solid rgba(24, 48, 51, 0.17);
border-radius: 4px;
background: rgba(255, 255, 255, 0.55);
font: inherit;
font-weight: 700;
}
.callout {
position: fixed;
z-index: 3;
left: 0;
top: 0;
padding: 7px 10px;
border-left: 2px solid var(--accent);
border-radius: 0 7px 7px 0;
background: rgba(250, 249, 243, 0.88);
box-shadow: 0 6px 20px rgba(33, 50, 51, 0.08);
color: #3f5758;
font-size: 10px;
line-height: 1.35;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(6px);
}
.callout strong {
display: block;
color: var(--ink);
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.callout span {
color: #79898a;
font-variant-numeric: tabular-nums;
}
.loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e9eeeb;
color: #496263;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.masthead { top: 17px; left: 18px; }
.subtitle, .study-tag, .panel, .hint, .callout { display: none; }
.controls {
bottom: 12px;
flex-wrap: wrap;
gap: 7px;
padding: 9px;
}
.timeline { order: 5; flex-basis: 100%; }
button { padding: 8px 10px; }
.timecode { min-width: 56px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel study of a Chelsea stair connecting a sidewalk to an elevated public walkway"></canvas>
<header class="masthead">
<div class="eyebrow">Chelsea / Level Study</div>
<h1>Sidewalk to<br>elevated route</h1>
<p class="subtitle">
A cutaway voxel study based on the direct access-stair arrangement used along
Chelsea’s High Line, with the surrounding city selectively simplified.
</p>
<div class="study-tag">Schematic arrangement · not a surveyed model</div>
</header>
<aside class="panel" aria-label="Scene legend">
<div class="panel-title">Level & material key</div>
<div class="legend-row">
<i class="swatch" style="--swatch:#d4ccbb"></i>
<span>Connected masonry stair</span><span>12 risers</span>
</div>
<div class="legend-row">
<i class="swatch" style="--swatch:#718987"></i>
<span>Elevated public walkway</span><span>+3.30 m</span>
</div>
<div class="legend-row">
<i class="swatch" style="--swatch:#e76545"></i>
<span>Measured stair profile</span><span>live</span>
</div>
<div class="legend-row">
<i class="swatch" style="--swatch:#e65f42"></i>
<span>Walking pedestrian</span><span>±0.00</span>
</div>
</aside>
<div id="label-sidewalk" class="callout">
<strong>Chelsea sidewalk</strong><span>route elevation +0.00 m</span>
</div>
<div id="label-stair" class="callout">
<strong>Access stair</strong><span>12 risers · +3.30 m</span>
</div>
<div id="label-landing" class="callout">
<strong>Upper landing</strong><span>continuous walking surface</span>
</div>
<div id="label-route" class="callout">
<strong>Elevated public path</strong><span>High Line–inspired route</span>
</div>
<div class="controls" aria-label="Animation controls">
<button id="play" class="primary">Pause</button>
<button id="restart">Restart</button>
<button id="side">Side view</button>
<button id="profile" class="active">Profile</button>
<div class="timeline">
<input id="scrub" type="range" min="0" max="1000" value="0" aria-label="Animation time">
</div>
<div id="timecode" class="timecode">00.0 / 14.0</div>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom<br>
<kbd>Space</kbd> play/pause <kbd>R</kbd> restart <kbd>S</kbd> side view
</div>
<div id="loading" class="loading">Building the level study…</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.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9eeeb");
scene.fog = new THREE.Fog("#e9eeeb", 28, 52);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0.1, 1.35, 0),
yaw: 0.19,
pitch: 0.39,
radius: 30,
zoom: 1
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * radius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const w = window.innerWidth;
const h = window.innerHeight;
const aspect = w / h;
const halfHeight = Math.max(6.1, 11.6 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(w, h);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemi = new THREE.HemisphereLight("#f7fbff", "#8a8072", 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff3dc", 3.25);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c7e4e7", 0.9);
fill.position.set(12, 6, -9);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02,
flatShading: true,
...options
});
const MAT = {
sidewalk: material("#d7d0c1"),
curb: material("#c8c1b3"),
road: material("#596468"),
lane: material("#d3b862"),
brick: material("#a85e48"),
brickDark: material("#824b3e"),
trim: material("#d9cbb7"),
window: material("#3f626c", { roughness: 0.28, metalness: 0.12 }),
windowLight: material("#8da9a5", { emissive: "#263f42", emissiveIntensity: 0.16 }),
stair: material("#c9c0ae"),
stairSide: material("#b8ae9b"),
path: material("#738b88"),
pathEdge: material("#526a69"),
steel: material("#294143", { roughness: 0.48, metalness: 0.52 }),
steelLight: material("#4d6665", { roughness: 0.55, metalness: 0.35 }),
accent: new THREE.MeshBasicMaterial({ color: "#e76545", depthTest: false }),
distant: material("#bdc8c5"),
distantDark: material("#aebbb8"),
soil: material("#665b4b"),
foliage: material("#718b66"),
foliageLight: material("#91a477"),
coat: material("#e55f43"),
pants: material("#29485b"),
shoe: material("#1c3035"),
skin: material("#d7a07b"),
hair: material("#40332f"),
bag: material("#eab04c"),
white: material("#ece9dd")
};
function addBox(w, h, d, mat, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(radius, height, mat, x, y, z, parent = scene, radial = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, radial),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function setSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.set(1, length, 1);
}
function segmentBetween(a, b, mat, radius = 0.035, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 7),
mat
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
setSegment(mesh, a, b);
return mesh;
}
// ------------------------------------------------------------------
// Level constants and the exact walking-surface profile
// ------------------------------------------------------------------
const STAIR_START = -2.60;
const STAIR_END = 3.40;
const STAIR_RISE = 3.30;
const STEP_COUNT = 12;
const STEP_RUN = (STAIR_END - STAIR_START) / STEP_COUNT;
const STEP_RISE = STAIR_RISE / STEP_COUNT;
const LANDING_END = 4.80;
const WALKWAY_END = 11.60;
const STAIR_DEPTH = 2.28;
function surfaceHeight(x) {
if (x <= STAIR_START) return 0;
if (x >= STAIR_END) return STAIR_RISE;
const index = Math.min(
STEP_COUNT - 1,
Math.max(0, Math.floor((x - STAIR_START) / STEP_RUN))
);
return (index + 1) * STEP_RISE;
}
// ------------------------------------------------------------------
// Compact city fragment
// ------------------------------------------------------------------
addBox(26, 0.44, 4.8, MAT.sidewalk, 0, -0.22, 0.20);
addBox(26, 0.36, 0.34, MAT.curb, 0, -0.18, 2.72);
addBox(28, 0.22, 5.4, MAT.road, 0, -0.51, 5.36);
for (let x = -12; x < 13; x += 2.2) {
addBox(1.15, 0.012, 0.075, MAT.lane, x, -0.391, 5.5, scene, false);
}
// A sliced facade close to the approach.
const facade = new THREE.Group();
scene.add(facade);
addBox(10.8, 7.4, 0.68, MAT.brick, -7.1, 3.7, -2.78, facade);
addBox(10.95, 0.30, 0.88, MAT.trim, -7.1, 0.12, -2.70, facade);
addBox(10.95, 0.26, 0.88, MAT.trim, -7.1, 7.38, -2.70, facade);
addBox(0.18, 7.4, 0.84, MAT.brickDark, -1.72, 3.7, -2.69, facade);
const windowXs = [-11.0, -8.45, -5.90, -3.35];
for (const x of windowXs) {
for (const y of [1.75, 4.65]) {
addBox(1.52, 1.92, 0.12, MAT.trim, x, y, -2.38, facade);
addBox(1.28, 1.68, 0.13, (x + y) % 3 > 1 ? MAT.window : MAT.windowLight, x, y, -2.30, facade);
addBox(0.07, 1.70, 0.15, MAT.trim, x, y, -2.22, facade);
addBox(1.30, 0.07, 0.15, MAT.trim, x, y, -2.22, facade);
addBox(1.78, 0.13, 0.38, MAT.trim, x, y - 1.02, -2.25, facade);
}
}
// Ground-floor door, partly screened by the stair in this sectional view.
addBox(1.25, 2.55, 0.16, MAT.trim, -2.60, 1.28, -2.34, facade);
addBox(1.00, 2.30, 0.17, MAT.windowLight, -2.60, 1.28, -2.23, facade);
addCylinder(0.035, 0.42, MAT.steel, -2.27, 1.18, -2.10, facade, 7);
// Selective background masses.
addBox(5.0, 8.0, 3.0, MAT.distant, 6.8, 3.8, -9.1);
addBox(4.0, 5.8, 3.2, MAT.distantDark, 12.2, 2.7, -10.0);
addBox(4.8, 10.5, 3.4, MAT.distant, -12.8, 5.0, -10.7);
addBox(7.0, 0.35, 4.0, MAT.distant, 7.5, 7.9, -9.0);
// Street lamp.
const lampX = -5.55;
const lampZ = 1.65;
addCylinder(0.055, 4.0, MAT.steel, lampX, 1.95, lampZ, scene, 8);
addBox(0.72, 0.10, 0.16, MAT.steel, lampX + 0.29, 3.91, lampZ);
addBox(0.46, 0.12, 0.30, MAT.white, lampX + 0.55, 3.82, lampZ);
// Small street tree.
const tree = new THREE.Group();
scene.add(tree);
addCylinder(0.11, 2.25, MAT.bark || material("#70594a"), -3.95, 1.10, 1.85, tree, 7);
const leafA = addBox(1.25, 1.05, 1.1, MAT.foliage, -3.95, 2.50, 1.85, tree);
leafA.rotation.y = 0.25;
const leafB = addBox(0.95, 0.86, 0.96, MAT.foliageLight, -3.63, 2.88, 1.82, tree);
leafB.rotation.set(0.15, 0.6, -0.12);
addBox(1.35, 0.26, 1.15, MAT.soil, -3.95, 0.08, 1.85, tree);
// ------------------------------------------------------------------
// Connected stair, upper landing, and short elevated path
// ------------------------------------------------------------------
const stairGroup = new THREE.Group();
scene.add(stairGroup);
for (let i = 0; i < STEP_COUNT; i++) {
const x = STAIR_START + (i + 0.5) * STEP_RUN;
const top = (i + 1) * STEP_RISE;
// Each solid block reaches the ground, so the exposed near face
// reads as an exact, continuous section through the risers.
addBox(
STEP_RUN + 0.004,
top,
STAIR_DEPTH,
i % 2 === 0 ? MAT.stair : MAT.stairSide,
x,
top * 0.5,
0,
stairGroup
);
// Thin warm nosing on the visible front edge.
addBox(
STEP_RUN - 0.025,
0.025,
0.075,
MAT.trim,
x,
top + 0.013,
STAIR_DEPTH * 0.5 + 0.005,
stairGroup,
false
);
}
// Landing and elevated walkway share exactly the same top elevation.
addBox(
LANDING_END - STAIR_END,
0.34,
2.46,
MAT.pathEdge,
(STAIR_END + LANDING_END) * 0.5,
STAIR_RISE - 0.17,
0
);
addBox(
WALKWAY_END - LANDING_END,
0.34,
2.46,
MAT.pathEdge,
(LANDING_END + WALKWAY_END) * 0.5,
STAIR_RISE - 0.17,
0
);
// Fine deck boards on the landing and path.
for (let x = STAIR_END + 0.16; x < WALKWAY_END; x += 0.34) {
addBox(
0.018,
0.012,
2.32,
MAT.steelLight,
x,
STAIR_RISE + 0.008,
0,
scene,
false
);
}
// Exposed understructure makes the elevation legible in section.
for (const x of [5.35, 8.72, 10.95]) {
addBox(0.26, 2.94, 0.26, MAT.steel, x, 1.47, -0.77);
addBox(0.26, 2.94, 0.26, MAT.steel, x, 1.47, 0.77);
addBox(0.34, 0.22, 1.85, MAT.steel, x, 2.87, 0);
}
addBox(6.6, 0.25, 0.30, MAT.steel, 8.15, 2.78, -0.77);
addBox(6.6, 0.25, 0.30, MAT.steel, 8.15, 2.78, 0.77);
function buildRailing(sideZ, fromX, toX, baseHeight, stepMode = false) {
const postMat = sideZ > 0 ? MAT.steel : MAT.steel;
if (stepMode) {
for (let i = 0; i <= STEP_COUNT; i += 2) {
const x = STAIR_START + i * STEP_RUN;
const y = i === 0 ? 0 : i * STEP_RISE;
addCylinder(0.028, 0.92, postMat, x, y + 0.46, sideZ, scene, 7);
}
const railPoints = [];
for (let i = 0; i <= STEP_COUNT; i += 2) {
const x = STAIR_START + i * STEP_RUN;
const y = i === 0 ? 0 : i * STEP_RISE;
railPoints.push(new THREE.Vector3(x, y + 0.92, sideZ));
}
for (let i = 0; i < railPoints.length - 1; i++) {
segmentBetween(railPoints[i], railPoints[i + 1], postMat, 0.035);
}
} else {
const count = Math.max(2, Math.floor((toX - fromX) / 1.18));
for (let i = 0; i <= count; i++) {
const x = THREE.MathUtils.lerp(fromX, toX, i / count);
addCylinder(0.028, 0.95, postMat, x, baseHeight + 0.475, sideZ, scene, 7);
}
segmentBetween(
new THREE.Vector3(fromX, baseHeight + 0.95, sideZ),
new THREE.Vector3(toX, baseHeight + 0.95, sideZ),
postMat,
0.035
);
segmentBetween(
new THREE.Vector3(fromX, baseHeight + 0.48, sideZ),
new THREE.Vector3(toX, baseHeight + 0.48, sideZ),
postMat,
0.022
);
}
}
buildRailing(-1.18, STAIR_START, STAIR_END, 0, true);
buildRailing(1.18, STAIR_START, STAIR_END, 0, true);
buildRailing(-1.18, STAIR_END, WALKWAY_END, STAIR_RISE, false);
buildRailing(1.18, STAIR_END, WALKWAY_END, STAIR_RISE, false);
// Planting on the elevated route: intentionally sparse and simplified.
for (const x of [7.10, 10.15]) {
addBox(1.0, 0.36, 0.62, MAT.steelLight, x, STAIR_RISE + 0.18, -0.66);
addBox(0.82, 0.08, 0.48, MAT.soil, x, STAIR_RISE + 0.37, -0.66);
for (let i = 0; i < 5; i++) {
const blade = addBox(
0.08,
0.42 + (i % 2) * 0.12,
0.08,
i % 2 ? MAT.foliage : MAT.foliageLight,
x - 0.30 + i * 0.15,
STAIR_RISE + 0.61,
-0.72 + (i % 3) * 0.07
);
blade.rotation.z = (i - 2) * 0.09;
}
}
// ------------------------------------------------------------------
// Live profile overlay
// ------------------------------------------------------------------
const profileGroup = new THREE.Group();
profileGroup.renderOrder = 20;
scene.add(profileGroup);
const profilePoints = [];
profilePoints.push(new THREE.Vector3(-10.1, 0.022, 1.235));
profilePoints.push(new THREE.Vector3(STAIR_START, 0.022, 1.235));
for (let i = 0; i < STEP_COUNT; i++) {
const x = STAIR_START + i * STEP_RUN;
const previousY = i * STEP_RISE;
const nextY = (i + 1) * STEP_RISE;
profilePoints.push(new THREE.Vector3(x, previousY + 0.022, 1.235));
profilePoints.push(new THREE.Vector3(x, nextY + 0.022, 1.235));
profilePoints.push(new THREE.Vector3(x + STEP_RUN, nextY + 0.022, 1.235));
}
profilePoints.push(new THREE.Vector3(WALKWAY_END, STAIR_RISE + 0.022, 1.235));
const profileLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(profilePoints),
new THREE.LineBasicMaterial({
color: "#e76545",
transparent: true,
opacity: 0.95,
depthTest: false
})
);
profileLine.renderOrder = 21;
profileGroup.add(profileLine);
for (let i = 0; i < STEP_COUNT; i++) {
const x = STAIR_START + (i + 0.5) * STEP_RUN;
const dot = new THREE.Mesh(new THREE.SphereGeometry(0.055, 8, 6), MAT.accent);
dot.position.set(x, (i + 1) * STEP_RISE + 0.025, 1.235);
dot.renderOrder = 22;
profileGroup.add(dot);
}
// ------------------------------------------------------------------
// Voxel-style pedestrian
// ------------------------------------------------------------------
const rig = new THREE.Group();
scene.add(rig);
const torso = addBox(0.50, 0.58, 0.35, MAT.coat, 0, 0.31, 0, rig);
const pelvis = addBox(0.43, 0.18, 0.34, MAT.pants, 0, 0.01, 0, rig);
const neck = addBox(0.13, 0.12, 0.13, MAT.skin, 0, 0.66, 0, rig);
const head = addBox(0.31, 0.32, 0.30, MAT.skin, 0, 0.82, 0, rig);
const hair = addBox(0.33, 0.10, 0.32, MAT.hair, -0.015, 0.99, 0, rig);
const nose = addBox(0.08, 0.07, 0.07, MAT.skin, 0.185, 0.81, 0, rig);
const backpack = addBox(0.20, 0.43, 0.30, MAT.bag, -0.32, 0.37, 0, rig);
const backpackPocket = addBox(0.11, 0.18, 0.24, material("#d69b3d"), -0.44, 0.28, 0, rig);
const legMeshes = [];
const footMeshes = [];
const armMeshes = [];
for (let i = 0; i < 2; i++) {
const thigh = new THREE.Mesh(
new THREE.CylinderGeometry(0.086, 0.095, 1, 6),
MAT.pants
);
const shin = new THREE.Mesh(
new THREE.CylinderGeometry(0.070, 0.082, 1, 6),
MAT.pants
);
thigh.castShadow = shin.castShadow = true;
scene.add(thigh, shin);
legMeshes.push({ thigh, shin });
const shoe = addBox(0.30, 0.105, 0.19, MAT.shoe, 0, 0.052, 0);
footMeshes.push(shoe);
const upperArm = new THREE.Mesh(
new THREE.CylinderGeometry(0.060, 0.066, 1, 6),
MAT.coat
);
const foreArm = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.060, 1, 6),
MAT.coat
);
const hand = addBox(0.11, 0.11, 0.10, MAT.skin, 0, 0, 0);
upperArm.castShadow = foreArm.castShadow = hand.castShadow = true;
scene.add(upperArm, foreArm);
armMeshes.push({ upperArm, foreArm, hand });
}
const FOOT_CLEARANCE = 0.018;
function createFoot(z, x) {
return {
x,
y: surfaceHeight(x) + FOOT_CLEARANCE,
supportY: surfaceHeight(x) + FOOT_CLEARANCE,
z,
state: "stance",
fromX: x,
fromY: surfaceHeight(x) + FOOT_CLEARANCE,
toX: x,
toY: surfaceHeight(x) + FOOT_CLEARANCE,
elapsed: 0,
duration: 0.36
};
}
let feet = [
createFoot(-0.145, -9.55),
createFoot(0.145, -9.15)
];
function resetFeet(bodyX) {
feet = [
createFoot(-0.145, bodyX - 0.20),
createFoot(0.145, bodyX + 0.20)
];
}
function updateFoot(foot, bodyX, dt) {
if (foot.state === "stance") {
foot.supportY = foot.y;
if (bodyX - foot.x > 0.38) {
foot.state = "swing";
foot.elapsed = 0;
foot.fromX = foot.x;
foot.fromY = foot.y;
foot.toX = bodyX + 0.52;
foot.toY = surfaceHeight(foot.toX) + FOOT_CLEARANCE;
}
} else {
foot.elapsed += dt;
const u = Math.min(1, foot.elapsed / foot.duration);
const eased = u * u * (3 - 2 * u);
foot.x = THREE.MathUtils.lerp(foot.fromX, foot.toX, eased);
foot.supportY = THREE.MathUtils.lerp(foot.fromY, foot.toY, eased);
const arc = Math.sin(Math.PI * u) * 0.34;
const floorGuard = surfaceHeight(foot.x) + FOOT_CLEARANCE;
foot.y = Math.max(foot.supportY + arc, floorGuard);
if (u >= 1) {
foot.state = "stance";
foot.x = foot.toX;
foot.y = foot.toY;
foot.supportY = foot.toY;
}
}
}
function solveKnee(hip, foot, upperLength, lowerLength) {
const direction = new THREE.Vector3().subVectors(foot, hip);
const rawDistance = direction.length();
const distance = THREE.MathUtils.clamp(rawDistance, 0.001, upperLength + lowerLength - 0.001);
direction.normalize();
const along =
(upperLength * upperLength - lowerLength * lowerLength + distance * distance) /
(2 * distance);
const height = Math.sqrt(Math.max(0, upperLength * upperLength - along * along));
const perpendicular = new THREE.Vector3(-direction.y, direction.x, 0);
if (perpendicular.lengthSq() < 0.0001) perpendicular.set(1, 0, 0);
perpendicular.normalize();
return hip.clone()
.addScaledVector(direction, along)
.addScaledVector(perpendicular, height);
}
const APPROACH_END = STAIR_START - 0.15;
const APPROACH_DURATION = 4.2;
const CLIMB_DURATION = 6.4;
const UPPER_DURATION = 3.4;
const TOTAL_DURATION = APPROACH_DURATION + CLIMB_DURATION + UPPER_DURATION;
function bodyXAtTime(t) {
if (t <= APPROACH_DURATION) {
return THREE.MathUtils.lerp(-9.4, APPROACH_END, t / APPROACH_DURATION);
}
if (t <= APPROACH_DURATION + CLIMB_DURATION) {
const u = (t - APPROACH_DURATION) / CLIMB_DURATION;
return THREE.MathUtils.lerp(APPROACH_END, STAIR_END + 0.15, u);
}
const u = (t - APPROACH_DURATION - CLIMB_DURATION) / UPPER_DURATION;
return THREE.MathUtils.lerp(STAIR_END + 0.15, 9.7, u);
}
function updateAvatar(t, dt) {
const bodyX = bodyXAtTime(t);
updateFoot(feet[0], bodyX, dt);
updateFoot(feet[1], bodyX, dt);
let pelvisY = (feet[0].supportY + feet[1].supportY) * 0.5 + 0.78;
pelvisY += Math.sin(t * 8.2) * 0.009;
const hipPoints = feet.map(foot =>
new THREE.Vector3(bodyX, pelvisY, foot.z)
);
// Raise the pelvis slightly if either leg would overextend.
for (let i = 0; i < feet.length; i++) {
const footPoint = new THREE.Vector3(feet[i].x, feet[i].y, feet[i].z);
const distance = hipPoints[i].distanceTo(footPoint);
if (distance > 0.89) pelvisY += distance - 0.89;
}
rig.position.set(bodyX, pelvisY, 0);
rig.rotation.y = 0;
const gaitPhase = t * 5.1;
for (let i = 0; i < 2; i++) {
const foot = feet[i];
const hip = new THREE.Vector3(bodyX, pelvisY, foot.z);
const footPoint = new THREE.Vector3(foot.x, foot.y, foot.z);
const knee = solveKnee(hip, footPoint, 0.46, 0.46);
setSegment(legMeshes[i].thigh, hip, knee);
setSegment(legMeshes[i].shin, knee, footPoint);
footMeshes[i].position.set(foot.x, foot.y + 0.0525, foot.z);
const side = i === 0 ? -1 : 1;
const shoulder = new THREE.Vector3(bodyX, pelvisY + 0.55, side * 0.265);
const hand = new THREE.Vector3(
bodyX + Math.sin(gaitPhase + (i ? Math.PI : 0)) * 0.18,
pelvisY + 0.12 + Math.max(0, Math.cos(gaitPhase + (i ? Math.PI : 0))) * 0.025,
side * 0.285
);
const elbow = shoulder.clone().lerp(hand, 0.52);
elbow.x += 0.045;
elbow.z += side * 0.025;
setSegment(armMeshes[i].upperArm, shoulder, elbow);
setSegment(armMeshes[i].foreArm, elbow, hand);
armMeshes[i].hand.position.copy(hand);
}
}
// ------------------------------------------------------------------
// Animation and UI
// ------------------------------------------------------------------
const playButton = document.getElementById("play");
const restartButton = document.getElementById("restart");
const sideButton = document.getElementById("side");
const profileButton = document.getElementById("profile");
const scrub = document.getElementById("scrub");
const timecode = document.getElementById("timecode");
let animationTime = 0;
let playing = true;
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause" : "Play";
}
playButton.addEventListener("click", () => {
if (!playing && animationTime >= TOTAL_DURATION - 0.01) {
animationTime = 0;
resetFeet(bodyXAtTime(0));
}
setPlaying(!playing);
});
restartButton.addEventListener("click", () => {
animationTime = 0;
resetFeet(bodyXAtTime(0));
updateAvatar(0, 0);
setPlaying(true);
});
sideButton.addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 0.22;
cameraState.target.set(0.0, 1.35, 0);
cameraState.zoom = 1;
updateCamera();
});
profileButton.addEventListener("click", () => {
profileGroup.visible = !profileGroup.visible;
profileButton.classList.toggle("active", profileGroup.visible);
});
scrub.addEventListener("input", () => {
setPlaying(false);
animationTime = (Number(scrub.value) / 1000) * TOTAL_DURATION;
resetFeet(bodyXAtTime(animationTime));
updateAvatar(animationTime, 0);
updateTimeline();
});
function updateTimeline() {
const progress = animationTime / TOTAL_DURATION;
scrub.value = Math.round(progress * 1000);
scrub.style.setProperty("--progress", `${progress * 100}%`);
timecode.textContent =
`${animationTime.toFixed(1).padStart(4, "0")} / ${TOTAL_DURATION.toFixed(1)}`;
}
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") restartButton.click();
if (event.key.toLowerCase() === "s") sideButton.click();
});
// ------------------------------------------------------------------
// Direct camera controls; no examples or addons are used
// ------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.10,
1.12
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
updateCamera();
}, { passive: false });
// ------------------------------------------------------------------
// Projected labels
// ------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-sidewalk"),
point: new THREE.Vector3(-6.7, 0.18, 1.35)
},
{
element: document.getElementById("label-stair"),
point: new THREE.Vector3(0.25, 2.15, 1.42)
},
{
element: document.getElementById("label-landing"),
point: new THREE.Vector3(4.10, 3.58, 1.30)
},
{
element: document.getElementById("label-route"),
point: new THREE.Vector3(8.65, 3.62, 1.30)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.point).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1 &&
x > -100 && x < width + 100 && y > -50 && y < height + 50;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------------
// Main loop
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
if (playing) {
animationTime += dt;
if (animationTime >= TOTAL_DURATION) {
animationTime = TOTAL_DURATION;
setPlaying(false);
}
}
updateAvatar(animationTime, playing ? dt : 0);
updateTimeline();
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
updateAvatar(0, 0);
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```