Prompt specification
Build or customize the Three.js 3D scene "Split-level community entrance" 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: Split-level community entrance
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/split-level-community-entrance-x2223
Scene Description Prompt:
Create a community entrance with stairs, ramp, handrails, and turning landings. Animate a walker and wheeled mobility aid following separate collision-free paths to the same door. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (split-level-community-entrance-x2223):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Community Entrance</title>
<style>
:root {
--panel: rgba(15, 28, 42, 0.88);
--panel-border: rgba(255, 255, 255, 0.15);
--text: #f4f8fb;
--muted: #afc0cc;
--orange: #ffad42;
--cyan: #43d9e6;
--green: #8bdc88;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d9e8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.header {
position: absolute;
top: 20px;
left: 20px;
max-width: min(390px, calc(100vw - 40px));
padding: 17px 19px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(19, 37, 50, 0.2);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 6px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 29px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
font-size: 12px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}
.dot.walker {
background: var(--orange);
}
.dot.chair {
background: var(--cyan);
}
.controls {
position: absolute;
left: 20px;
bottom: 20px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 9px;
width: min(650px, calc(100vw - 40px));
padding: 12px;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(19, 37, 50, 0.22);
backdrop-filter: blur(14px);
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
background: rgba(255, 255, 255, 0.09);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.16);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: transparent;
background: var(--green);
color: #173126;
}
.speed {
display: flex;
align-items: center;
gap: 8px;
min-width: 180px;
margin-left: 2px;
color: var(--muted);
font-size: 12px;
}
input[type="range"] {
width: 105px;
accent-color: var(--green);
}
.status {
position: absolute;
right: 20px;
bottom: 20px;
max-width: min(330px, calc(100vw - 40px));
padding: 12px 15px;
border: 1px solid var(--panel-border);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(19, 37, 50, 0.22);
backdrop-filter: blur(14px);
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.status strong {
display: block;
margin-bottom: 3px;
color: var(--text);
font-size: 13px;
}
.hint {
position: absolute;
top: 20px;
right: 20px;
padding: 9px 12px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: rgba(15, 28, 42, 0.72);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(10px);
}
@media (max-width: 720px) {
.header {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
margin-bottom: 9px;
}
.controls {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.status,
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel community entrance"></canvas>
<div class="hud">
<section class="header">
<div class="eyebrow">Inclusive Access Study</div>
<h1>Community Entrance</h1>
<p class="subtitle">
A stair route and a step-free ramp route converge at the same automatic door.
</p>
<div class="legend">
<span><i class="dot walker"></i>Walking route</span>
<span><i class="dot chair"></i>Wheelchair route</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
<section class="controls" aria-label="Animation controls">
<button id="playPause" class="primary">Pause</button>
<button id="restart">Restart</button>
<button id="togglePaths" aria-pressed="true">Hide paths</button>
<button id="resetCamera">Reset camera</button>
<label class="speed">
Speed
<input id="speed" type="range" min="0.4" max="2" value="1" step="0.1" />
<span id="speedValue">1.0×</span>
</label>
</section>
<section class="status" aria-live="polite">
<strong id="statusTitle">Routes in motion</strong>
<span id="statusText">
The two routes remain separated until they meet on the shared entrance landing.
</span>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d9e8);
scene.fog = new THREE.Fog(0xb9d9e8, 28, 64);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
140
);
const cameraTarget = new THREE.Vector3(1.6, 1.0, 0.4);
let cameraTheta = 0.66;
let cameraPhi = 1.02;
let cameraRadius = 28;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xe6f6ff, 0x6d7864, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.1);
sun.position.set(-12, 22, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x92c9e8, 0.75);
fill.position.set(15, 8, -10);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Reusable voxel geometry helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
})
);
}
return materialCache.get(key);
}
function box(parent, width, height, depth, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color, options));
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
const UP = new THREE.Vector3(0, 1, 0);
function segmentBasis(a, b) {
const direction = new THREE.Vector3().subVectors(b, a).normalize();
let lateral = new THREE.Vector3().crossVectors(direction, UP);
if (lateral.lengthSq() < 0.0001) {
lateral.set(1, 0, 0);
} else {
lateral.normalize();
}
const vertical = new THREE.Vector3()
.crossVectors(lateral, direction)
.normalize();
const matrix = new THREE.Matrix4().makeBasis(
lateral,
vertical,
direction
);
return {
direction,
lateral,
vertical,
quaternion: new THREE.Quaternion().setFromRotationMatrix(matrix)
};
}
function beam(parent, a, b, width, height, color) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const basis = segmentBasis(a, b);
const mesh = new THREE.Mesh(
unitBox,
getMaterial(color, { roughness: 0.68 })
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(width, height, length);
mesh.quaternion.copy(basis.quaternion);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rampDeck(a, b, width, color, edgeColor = 0xf2c94c) {
const basis = segmentBasis(a, b);
const length = a.distanceTo(b);
const thickness = 0.18;
const deck = new THREE.Mesh(
unitBox,
getMaterial(color, { roughness: 0.74 })
);
deck.position
.copy(a)
.add(b)
.multiplyScalar(0.5)
.addScaledVector(basis.vertical, -thickness / 2);
deck.scale.set(width, thickness, length);
deck.quaternion.copy(basis.quaternion);
deck.castShadow = true;
deck.receiveShadow = true;
world.add(deck);
// Bright voxel-style edge strips.
for (const side of [-1, 1]) {
const strip = new THREE.Mesh(
unitBox,
getMaterial(edgeColor, { roughness: 0.65 })
);
strip.position
.copy(a)
.add(b)
.multiplyScalar(0.5)
.addScaledVector(basis.lateral, side * (width / 2 - 0.07))
.addScaledVector(basis.vertical, 0.085);
strip.scale.set(0.09, 0.035, length);
strip.quaternion.copy(basis.quaternion);
strip.castShadow = true;
world.add(strip);
}
// Block supports under the ramp.
const supportCount = Math.max(2, Math.floor(length / 1.6));
for (let i = 0; i <= supportCount; i++) {
const t = i / supportCount;
const point = new THREE.Vector3().lerpVectors(a, b, t);
const supportHeight = Math.max(0.08, point.y - 0.15);
box(
world,
0.24,
supportHeight,
0.24,
point.x,
supportHeight / 2,
point.z,
0x647783
);
}
return deck;
}
function handrail(a, b, lateralOffset = 0, color = 0x334c58) {
const basis = segmentBasis(a, b);
const lateral = basis.lateral.clone().multiplyScalar(lateralOffset);
const railA = a.clone().add(lateral).addScaledVector(UP, 0.95);
const railB = b.clone().add(lateral).addScaledVector(UP, 0.95);
beam(world, railA, railB, 0.09, 0.09, color);
const count = Math.max(2, Math.ceil(a.distanceTo(b) / 1.25));
for (let i = 0; i <= count; i++) {
const t = i / count;
const surface = new THREE.Vector3().lerpVectors(a, b, t).add(lateral);
const top = surface.clone().addScaledVector(UP, 0.95);
box(
world,
0.09,
0.95,
0.09,
surface.x,
surface.y + 0.475,
surface.z,
color
);
box(
world,
0.16,
0.07,
0.16,
top.x,
top.y,
top.z,
0xf2c94c
);
}
}
function landingRail(a, b, color = 0x334c58) {
const railA = a.clone().addScaledVector(UP, 0.95);
const railB = b.clone().addScaledVector(UP, 0.95);
beam(world, railA, railB, 0.09, 0.09, color);
const count = Math.max(1, Math.ceil(a.distanceTo(b) / 1.1));
for (let i = 0; i <= count; i++) {
const t = i / count;
const surface = new THREE.Vector3().lerpVectors(a, b, t);
const top = surface.clone().addScaledVector(UP, 0.95);
box(
world,
0.09,
0.95,
0.09,
surface.x,
surface.y + 0.475,
surface.z,
color
);
box(
world,
0.15,
0.07,
0.15,
top.x,
top.y,
top.z,
0xf2c94c
);
}
}
function makeTextPlane(text, width, height, options = {}) {
const canvasTexture = document.createElement("canvas");
canvasTexture.width = 768;
canvasTexture.height = 192;
const context = canvasTexture.getContext("2d");
context.fillStyle = options.background || "#203747";
context.fillRect(0, 0, canvasTexture.width, canvasTexture.height);
context.strokeStyle = options.border || "#8bdc88";
context.lineWidth = 12;
context.strokeRect(8, 8, canvasTexture.width - 16, canvasTexture.height - 16);
context.fillStyle = options.color || "#ffffff";
context.font = `800 ${options.fontSize || 70}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvasTexture.width / 2, canvasTexture.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvasTexture);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.8,
metalness: 0
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
mesh.castShadow = false;
return mesh;
}
// -------------------------------------------------------------------------
// Ground, paving and landscaping
// -------------------------------------------------------------------------
box(world, 44, 0.45, 38, 0, -0.27, 1, 0x91b58a, {
castShadow: false
});
const tileColors = [0xd9d4c7, 0xd1cec4, 0xe2ddd1, 0xcac8c0];
const tileGeometry = new THREE.BoxGeometry(1, 1, 1);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
});
const tileCount = 20 * 16;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
const tileMatrix = new THREE.Matrix4();
let tileIndex = 0;
for (let ix = 0; ix < 20; ix++) {
for (let iz = 0; iz < 16; iz++) {
const x = -14.75 + ix * 1.5;
const z = -6.25 + iz * 1.5;
tileMatrix.makeScale(1.42, 0.08, 1.42);
tileMatrix.setPosition(x, -0.025, z);
tiles.setMatrixAt(tileIndex, tileMatrix);
tiles.setColorAt(
tileIndex,
new THREE.Color(tileColors[(ix + iz * 3) % tileColors.length])
);
tileIndex++;
}
}
tiles.receiveShadow = true;
world.add(tiles);
function voxelTree(x, z, scale = 1) {
box(world, 0.42 * scale, 2.3 * scale, 0.42 * scale,
x, 1.15 * scale, z, 0x76543b);
box(world, 2.1 * scale, 1.35 * scale, 1.8 * scale,
x, 2.7 * scale, z, 0x4f985f);
box(world, 1.45 * scale, 1.15 * scale, 1.35 * scale,
x - 0.65 * scale, 3.35 * scale, z + 0.15 * scale, 0x62ad69);
box(world, 1.25 * scale, 1.0 * scale, 1.25 * scale,
x + 0.62 * scale, 3.5 * scale, z - 0.12 * scale, 0x73bd75);
}
voxelTree(-10.7, 6.5, 1.05);
voxelTree(-9.4, -3.6, 0.9);
voxelTree(13.2, 7.4, 1.0);
voxelTree(12.5, -3.6, 0.85);
voxelTree(-5.6, 11.8, 0.82);
function planter(x, z, color = 0xc87547) {
box(world, 1.8, 0.55, 1.8, x, 0.275, z, color);
box(world, 1.5, 0.12, 1.5, x, 0.56, z, 0x503c2f);
box(world, 0.42, 1.3, 0.42, x - 0.35, 1.15, z, 0x477f50);
box(world, 0.42, 1.0, 0.42, x + 0.35, 1.0, z, 0x5d9a5c);
box(world, 0.38, 0.8, 0.38, x, 0.82, z + 0.3, 0x79aa67);
}
planter(-4.6, -5.9);
planter(4.6, -5.9, 0xb86642);
planter(10.2, 8.9, 0x9a6846);
planter(-7.6, 2.0, 0x9a6846);
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, 2.2, 0.16, 0.62, 0, 0.62, 0, 0x9b6845);
box(group, 2.2, 0.65, 0.13, 0, 1.0, -0.28, 0x9b6845);
for (const side of [-0.82, 0.82]) {
box(group, 0.15, 0.62, 0.48, side, 0.31, 0, 0x334c58);
}
}
bench(-8.2, 0.2, Math.PI / 2);
bench(11.7, 1.8, -Math.PI / 2);
// -------------------------------------------------------------------------
// Community building
// -------------------------------------------------------------------------
box(world, 16.4, 1.4, 7.3, 0, 0.7, -10.5, 0x65717a);
box(world, 16, 4.9, 7, 0, 3.85, -10.5, 0xe3d3b7);
const brickColors = [0xd7c5a8, 0xe5d4b7, 0xcfbda1, 0xdfcdb0];
for (let x = -7; x <= 7; x += 1) {
for (let y = 1.8; y <= 6.1; y += 0.68) {
if (Math.abs(x) < 1.45 && y < 4.65) continue;
box(
world,
0.93,
0.59,
0.11,
x + (((y * 10) % 3) - 1) * 0.035,
y,
-6.94,
brickColors[(Math.abs(x * 3 + Math.round(y * 7))) % brickColors.length]
);
}
}
// Windows.
for (const x of [-5.7, 5.7]) {
box(world, 2.8, 2.25, 0.18, x, 3.55, -6.82, 0x334c58);
box(world, 2.42, 1.88, 0.12, x, 3.55, -6.69, 0x77bad1, {
roughness: 0.3,
metalness: 0.08
});
box(world, 0.09, 1.9, 0.14, x, 3.55, -6.58, 0x334c58);
box(world, 2.42, 0.09, 0.14, x, 3.55, -6.58, 0x334c58);
}
// Entrance recess and automatic sliding doors.
box(world, 2.55, 2.95, 0.18, 0, 2.88, -6.84, 0x233641);
const leftDoor = box(
world, 1.08, 2.62, 0.13,
-0.55, 2.72, -6.70,
0x2f7f87
);
const rightDoor = box(
world, 1.08, 2.62, 0.13,
0.55, 2.72, -6.70,
0x2f7f87
);
box(world, 0.055, 0.55, 0.07, -0.08, 2.72, -6.60, 0xe8e3d4);
box(world, 0.055, 0.55, 0.07, 0.08, 2.72, -6.60, 0xe8e3d4);
// Canopy and block supports.
box(world, 4.5, 0.32, 2.1, 0, 4.52, -6.1, 0x3a5968);
box(world, 0.26, 2.7, 0.26, -1.92, 3.1, -6.75, 0x3a5968);
box(world, 0.26, 2.7, 0.26, 1.92, 3.1, -6.75, 0x3a5968);
const buildingSign = makeTextPlane("COMMUNITY HUB", 4.5, 1.0, {
background: "#203747",
border: "#8bdc88",
color: "#ffffff"
});
buildingSign.position.set(0, 5.25, -6.79);
world.add(buildingSign);
// Roof details.
box(world, 16.4, 0.35, 7.3, 0, 6.45, -10.5, 0x3b5665);
box(world, 3.5, 0.55, 2.3, -4.5, 6.9, -10.3, 0x83939c);
box(world, 3.5, 0.16, 2.3, -4.5, 7.26, -10.3, 0x315c74);
// -------------------------------------------------------------------------
// Stairs, shared landing and railings
// -------------------------------------------------------------------------
const STAIR_CENTER_X = -1.6;
const STAIR_WIDTH = 2.8;
const STEP_COUNT = 8;
const STEP_DEPTH = 0.8;
const STEP_RISE = 0.175;
for (let i = 0; i < STEP_COUNT; i++) {
const top = (i + 1) * STEP_RISE;
const frontZ = 1 - i * STEP_DEPTH;
const centerZ = frontZ - STEP_DEPTH / 2;
box(
world,
STAIR_WIDTH,
top,
STEP_DEPTH,
STAIR_CENTER_X,
top / 2,
centerZ,
i % 2 === 0 ? 0xa9a79e : 0xb6b3a8
);
box(
world,
STAIR_WIDTH,
0.035,
0.075,
STAIR_CENTER_X,
top + 0.018,
frontZ - 0.035,
0xf2c94c
);
}
// Shared elevated entrance landing.
box(world, 5.6, 1.4, 1.8, -0.4, 0.7, -6.1, 0xabb0aa);
box(world, 5.6, 0.07, 1.8, -0.4, 1.435, -6.1, 0xc9cbc2);
const stairRailA = new THREE.Vector3(STAIR_CENTER_X, 0, 1.12);
const stairRailB = new THREE.Vector3(STAIR_CENTER_X, 1.4, -5.48);
handrail(stairRailA, stairRailB, -1.48);
handrail(stairRailA, stairRailB, 1.48);
// -------------------------------------------------------------------------
// Step-free ramp with turning landings
// -------------------------------------------------------------------------
// Lower ramp.
const ramp1A = new THREE.Vector3(8.2, 0, 10);
const ramp1B = new THREE.Vector3(8.2, 0.5, 4);
rampDeck(ramp1A, ramp1B, 2.4, 0x718c92);
// First turning landing.
box(world, 2.4, 0.5, 2.8, 8.2, 0.25, 2.8, 0x718c92);
box(world, 2.4, 0.06, 2.8, 8.2, 0.53, 2.8, 0x91a8aa);
// Upper ramp running back toward the entrance.
const ramp2A = new THREE.Vector3(7, 0.5, 2.75);
const ramp2B = new THREE.Vector3(2, 0.92, 2.75);
rampDeck(ramp2A, ramp2B, 2.4, 0x718c92);
// Second turning landing.
box(world, 2.0, 0.92, 2.7, 1.0, 0.46, 2.75, 0x718c92);
box(world, 2.0, 0.06, 2.7, 1.0, 0.95, 2.75, 0x91a8aa);
// Final ramp segment alongside the stairs.
const ramp3A = new THREE.Vector3(1.4, 0.92, 1.4);
const ramp3B = new THREE.Vector3(1.4, 1.4, -5.2);
rampDeck(ramp3A, ramp3B, 1.8, 0x718c92);
// Ramp handrails.
handrail(ramp1A, ramp1B, -1.17);
handrail(ramp1A, ramp1B, 1.17);
handrail(ramp2A, ramp2B, -1.17);
handrail(ramp2A, ramp2B, 1.17);
handrail(ramp3A, ramp3B, -0.87);
handrail(ramp3A, ramp3B, 0.87);
// Landing railings, with openings left for both route directions.
landingRail(
new THREE.Vector3(9.37, 0.5, 1.45),
new THREE.Vector3(9.37, 0.5, 4.15)
);
landingRail(
new THREE.Vector3(7.02, 0.5, 4.15),
new THREE.Vector3(7.72, 0.5, 4.15)
);
landingRail(
new THREE.Vector3(8.68, 0.5, 4.15),
new THREE.Vector3(9.37, 0.5, 4.15)
);
landingRail(
new THREE.Vector3(0.05, 0.92, 1.45),
new THREE.Vector3(0.05, 0.92, 4.08)
);
landingRail(
new THREE.Vector3(0.05, 0.92, 4.08),
new THREE.Vector3(1.95, 0.92, 4.08)
);
// Ramp sign.
const rampSignPost = new THREE.Group();
rampSignPost.position.set(10.05, 0, 7.5);
world.add(rampSignPost);
box(rampSignPost, 0.13, 2.25, 0.13, 0, 1.12, 0, 0x465f68);
const rampSign = makeTextPlane("STEP-FREE RAMP", 3.0, 0.72, {
background: "#176d78",
border: "#43d9e6",
color: "#ffffff",
fontSize: 62
});
rampSign.position.set(0, 2.05, 0.02);
rampSignPost.add(rampSign);
const stairsSignPost = new THREE.Group();
stairsSignPost.position.set(-4.65, 0, 1.7);
world.add(stairsSignPost);
box(stairsSignPost, 0.12, 1.8, 0.12, 0, 0.9, 0, 0x465f68);
const stairsSign = makeTextPlane("STAIRS", 1.8, 0.55, {
background: "#8c4f1f",
border: "#ffad42",
color: "#ffffff",
fontSize: 72
});
stairsSign.position.set(0, 1.72, 0.02);
stairsSignPost.add(stairsSign);
// -------------------------------------------------------------------------
// Explicit collision-free routes
// -------------------------------------------------------------------------
class PolylinePath {
constructor(points) {
this.points = points.map((point) => point.clone());
this.lengths = [0];
for (let i = 1; i < this.points.length; i++) {
this.lengths.push(
this.lengths[i - 1] +
this.points[i].distanceTo(this.points[i - 1])
);
}
this.length = this.lengths[this.lengths.length - 1];
this.horizontalTangents = this.points.map((_, index) => {
const candidates = [];
if (index > 0) {
candidates.push(
new THREE.Vector3().subVectors(
this.points[index],
this.points[index - 1]
)
);
}
if (index < this.points.length - 1) {
candidates.push(
new THREE.Vector3().subVectors(
this.points[index + 1],
this.points[index]
)
);
}
for (const candidate of candidates) {
candidate.y = 0;
if (candidate.lengthSq() > 0.0001) {
return candidate.normalize();
}
}
return new THREE.Vector3(0, 0, -1);
});
}
sample(distance, positionOut, tangentOut) {
const clamped = THREE.MathUtils.clamp(distance, 0, this.length);
let segment = 0;
while (
segment < this.lengths.length - 2 &&
clamped > this.lengths[segment + 1]
) {
segment++;
}
const segmentStart = this.lengths[segment];
const segmentLength = this.lengths[segment + 1] - segmentStart;
const alpha = segmentLength > 0
? (clamped - segmentStart) / segmentLength
: 0;
positionOut.lerpVectors(
this.points[segment],
this.points[segment + 1],
alpha
);
tangentOut.copy(this.horizontalTangents[segment]);
}
}
const walkerPoints = [
new THREE.Vector3(STAIR_CENTER_X, 0, 1.26),
new THREE.Vector3(STAIR_CENTER_X, 0, 1)
];
for (let i = 0; i < STEP_COUNT; i++) {
const top = (i + 1) * STEP_RISE;
const frontZ = 1 - i * STEP_DEPTH;
walkerPoints.push(
new THREE.Vector3(STAIR_CENTER_X, top, frontZ),
new THREE.Vector3(STAIR_CENTER_X, top, frontZ - STEP_DEPTH)
);
}
walkerPoints.push(
new THREE.Vector3(STAIR_CENTER_X, 1.4, -5.85),
new THREE.Vector3(0, 1.4, -7.08)
);
const chairPoints = [
new THREE.Vector3(8.2, 0, 10),
new THREE.Vector3(8.2, 0.5, 4),
new THREE.Vector3(8.2, 0.5, 2.75),
new THREE.Vector3(7, 0.5, 2.75),
new THREE.Vector3(2, 0.92, 2.75),
new THREE.Vector3(1.4, 0.92, 1.4),
new THREE.Vector3(1.4, 1.4, -5.2),
new THREE.Vector3(1.4, 1.4, -5.85),
new THREE.Vector3(0, 1.4, -7.08)
];
const walkerPath = new PolylinePath(walkerPoints);
const chairPath = new PolylinePath(chairPoints);
// Visible route overlays.
const pathGroup = new THREE.Group();
scene.add(pathGroup);
function addRouteLine(points, color, dashSize) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => point.clone().add(new THREE.Vector3(0, 0.08, 0)))
);
const material = new THREE.LineDashedMaterial({
color,
dashSize,
gapSize: 0.16,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
pathGroup.add(line);
}
addRouteLine(walkerPoints, 0xff9d32, 0.22);
addRouteLine(chairPoints, 0x32d8e8, 0.28);
// -------------------------------------------------------------------------
// Voxel walker
// -------------------------------------------------------------------------
const walker = new THREE.Group();
scene.add(walker);
const skin = 0xe7aa79;
const orangeShirt = 0xe97835;
const darkPants = 0x263c4a;
const hair = 0x3c2d27;
box(walker, 0.48, 0.58, 0.30, 0, 1.18, 0, orangeShirt);
box(walker, 0.39, 0.38, 0.36, 0, 1.70, 0, skin);
box(walker, 0.41, 0.12, 0.38, 0, 1.88, -0.01, hair);
box(walker, 0.10, 0.08, 0.06, 0, 1.73, 0.18, hair);
box(walker, 0.055, 0.055, 0.025, -0.085, 1.72, 0.192, 0x23313a);
box(walker, 0.055, 0.055, 0.025, 0.085, 1.72, 0.192, 0x23313a);
function createWalkerLimb(x, y, length, color, shoe = false) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
walker.add(pivot);
box(pivot, 0.14, length, 0.16, 0, -length / 2, 0, color);
if (shoe) {
box(pivot, 0.18, 0.10, 0.30, 0, -length - 0.02, 0.055, 0x20313a);
}
return pivot;
}
const leftLeg = createWalkerLimb(-0.14, 0.9, 0.46, darkPants, true);
const rightLeg = createWalkerLimb(0.14, 0.9, 0.46, darkPants, true);
const leftArm = createWalkerLimb(-0.32, 1.43, 0.48, orangeShirt);
const rightArm = createWalkerLimb(0.32, 1.43, 0.48, orangeShirt);
// Small voxel backpack.
box(walker, 0.34, 0.42, 0.18, 0, 1.18, -0.23, 0x3b756a);
// -------------------------------------------------------------------------
// Voxel wheelchair and occupant
// -------------------------------------------------------------------------
const chair = new THREE.Group();
scene.add(chair);
const chairFrame = 0x263943;
const chairSeat = 0x247f91;
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x253039,
roughness: 0.75
});
box(chair, 0.72, 0.13, 0.70, 0, 0.62, 0, chairSeat);
box(chair, 0.72, 0.70, 0.13, 0, 0.98, -0.30, chairSeat);
box(chair, 0.08, 0.55, 0.08, -0.40, 0.83, 0.26, chairFrame);
box(chair, 0.08, 0.55, 0.08, 0.40, 0.83, 0.26, chairFrame);
box(chair, 0.82, 0.08, 0.08, 0, 0.36, 0.27, chairFrame);
box(chair, 0.62, 0.08, 0.08, 0, 0.21, 0.53, chairFrame);
box(chair, 0.62, 0.08, 0.08, 0, 0.08, 0.53, chairFrame);
box(chair, 0.62, 0.08, 0.08, 0, 0.08, 0.57, 0x4b4f52);
const wheelRotors = [];
for (const side of [-1, 1]) {
const rotor = new THREE.Group();
rotor.position.set(side * 0.52, 0.39, -0.10);
chair.add(rotor);
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.39, 0.39, 0.12, 12),
wheelMaterial
);
wheel.rotation.z = Math.PI / 2;
wheel.castShadow = true;
rotor.add(wheel);
// Box spokes make wheel rotation visible.
box(rotor, 0.15, 0.66, 0.045, 0, 0, 0, 0xb9c3c7);
box(rotor, 0.15, 0.045, 0.66, 0, 0, 0, 0xb9c3c7);
box(rotor, 0.16, 0.13, 0.13, 0, 0, 0, 0xf2c94c);
wheelRotors.push(rotor);
const frontCaster = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.09, 10),
wheelMaterial
);
frontCaster.rotation.z = Math.PI / 2;
frontCaster.position.set(side * 0.36, 0.15, 0.52);
frontCaster.castShadow = true;
chair.add(frontCaster);
}
// Seated occupant.
box(chair, 0.43, 0.52, 0.29, 0, 1.02, -0.08, 0xd85f3b);
box(chair, 0.35, 0.35, 0.33, 0, 1.48, -0.07, skin);
box(chair, 0.37, 0.10, 0.35, 0, 1.63, -0.08, hair);
box(chair, 0.05, 0.05, 0.025, -0.07, 1.50, 0.105, 0x23313a);
box(chair, 0.05, 0.05, 0.025, 0.07, 1.50, 0.105, 0x23313a);
// Bent legs and shoes.
box(chair, 0.15, 0.16, 0.48, -0.14, 0.58, 0.25, 0x354b5a);
box(chair, 0.15, 0.16, 0.48, 0.14, 0.58, 0.25, 0x354b5a);
box(chair, 0.15, 0.34, 0.15, -0.14, 0.39, 0.45, 0x354b5a);
box(chair, 0.15, 0.34, 0.15, 0.14, 0.39, 0.45, 0x354b5a);
box(chair, 0.18, 0.10, 0.27, -0.14, 0.19, 0.49, 0x26333b);
box(chair, 0.18, 0.10, 0.27, 0.14, 0.19, 0.49, 0x26333b);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
let paused = false;
let simulationSpeed = 1;
let walkerDistance = 0;
let chairDistance = 0;
let cycleTime = 0;
let walkerArrivedAt = null;
let chairArrivedAt = null;
let gaitPhase = 0;
let wheelAngle = 0;
let doorOpen = 0;
const walkerPosition = new THREE.Vector3();
const chairPosition = new THREE.Vector3();
const walkerTangent = new THREE.Vector3();
const chairTangent = new THREE.Vector3();
let walkerYaw = Math.PI;
let chairYaw = Math.PI;
function angleTowards(current, target, lambda, dt) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * (1 - Math.exp(-lambda * dt));
}
function resetAnimation() {
walkerDistance = 0;
chairDistance = 0;
cycleTime = 0;
walkerArrivedAt = null;
chairArrivedAt = null;
gaitPhase = 0;
wheelAngle = 0;
doorOpen = 0;
walker.visible = true;
chair.visible = true;
walkerPath.sample(0, walkerPosition, walkerTangent);
chairPath.sample(0, chairPosition, chairTangent);
walker.position.copy(walkerPosition);
chair.position.copy(chairPosition);
}
resetAnimation();
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const playPauseButton = document.querySelector("#playPause");
const restartButton = document.querySelector("#restart");
const pathsButton = document.querySelector("#togglePaths");
const resetCameraButton = document.querySelector("#resetCamera");
const speedSlider = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const statusTitle = document.querySelector("#statusTitle");
const statusText = document.querySelector("#statusText");
playPauseButton.addEventListener("click", () => {
paused = !paused;
playPauseButton.textContent = paused ? "Play" : "Pause";
});
restartButton.addEventListener("click", resetAnimation);
pathsButton.addEventListener("click", () => {
pathGroup.visible = !pathGroup.visible;
pathsButton.textContent = pathGroup.visible ? "Hide paths" : "Show paths";
pathsButton.setAttribute("aria-pressed", String(pathGroup.visible));
});
resetCameraButton.addEventListener("click", () => {
cameraTheta = 0.66;
cameraPhi = 1.02;
cameraRadius = 28;
cameraTarget.set(1.6, 1.0, 0.4);
});
speedSlider.addEventListener("input", () => {
simulationSpeed = Number(speedSlider.value);
speedValue.textContent = `${simulationSpeed.toFixed(1)}×`;
});
// -------------------------------------------------------------------------
// Direct orbit, zoom and keyboard camera controls
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.005;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.004,
0.48,
1.38
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("pointerleave", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.018,
14,
43
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = event.shiftKey ? 0.35 : 0.15;
if (event.key === "ArrowLeft") {
cameraTarget.x -= step;
} else if (event.key === "ArrowRight") {
cameraTarget.x += step;
} else if (event.key === "ArrowUp") {
cameraTarget.z -= step;
} else if (event.key === "ArrowDown") {
cameraTarget.z += step;
} else if (event.code === "Space") {
event.preventDefault();
playPauseButton.click();
}
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const realDt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
const dt = paused ? 0 : realDt * simulationSpeed;
if (dt > 0) {
cycleTime += dt;
gaitPhase += dt * 8.3;
walkerDistance = Math.min(
walkerPath.length,
walkerDistance + dt * 1.25
);
const previousChairDistance = chairDistance;
chairDistance = Math.min(
chairPath.length,
chairDistance + dt * 1.08
);
wheelAngle += (chairDistance - previousChairDistance) / 0.39;
if (walkerDistance >= walkerPath.length && walkerArrivedAt === null) {
walkerArrivedAt = cycleTime;
}
if (chairDistance >= chairPath.length && chairArrivedAt === null) {
chairArrivedAt = cycleTime;
}
if (
walkerArrivedAt !== null &&
chairArrivedAt !== null &&
cycleTime - Math.max(walkerArrivedAt, chairArrivedAt) > 2.1
) {
resetAnimation();
}
}
walkerPath.sample(walkerDistance, walkerPosition, walkerTangent);
chairPath.sample(chairDistance, chairPosition, chairTangent);
const walkerTargetYaw = Math.atan2(walkerTangent.x, walkerTangent.z);
const chairTargetYaw = Math.atan2(chairTangent.x, chairTangent.z);
walkerYaw = angleTowards(walkerYaw, walkerTargetYaw, 9, realDt);
chairYaw = angleTowards(chairYaw, chairTargetYaw, 8, realDt);
const walkerBob = walkerArrivedAt === null
? Math.abs(Math.sin(gaitPhase)) * 0.035
: 0;
walker.position.copy(walkerPosition);
walker.position.y += walkerBob;
walker.rotation.y = walkerYaw;
leftLeg.rotation.x = Math.sin(gaitPhase) * 0.58;
rightLeg.rotation.x = -Math.sin(gaitPhase) * 0.58;
leftArm.rotation.x = -Math.sin(gaitPhase) * 0.48;
rightArm.rotation.x = Math.sin(gaitPhase) * 0.48;
chair.position.copy(chairPosition);
chair.rotation.y = chairYaw;
for (const rotor of wheelRotors) {
rotor.rotation.x = wheelAngle;
}
// The walker moves into the building before disappearing.
if (walkerArrivedAt !== null) {
walker.visible = cycleTime - walkerArrivedAt < 0.85;
}
if (chairArrivedAt !== null) {
chair.visible = cycleTime - chairArrivedAt < 0.85;
}
// Automatic doors open as either route reaches the entrance.
const doorTarget =
walkerArrivedAt !== null ||
chairDistance > chairPath.length - 3.1
? 1
: 0;
doorOpen = THREE.MathUtils.damp(doorOpen, doorTarget, 5, realDt);
leftDoor.position.x = -0.55 - doorOpen * 0.82;
rightDoor.position.x = 0.55 + doorOpen * 0.82;
// Status text.
if (paused) {
statusTitle.textContent = "Animation paused";
statusText.textContent = "Press Play to continue both routes.";
} else if (
walkerArrivedAt !== null &&
chairArrivedAt !== null
) {
statusTitle.textContent = "Both routes completed";
statusText.textContent =
"Both travelers reached the same door on separate, collision-free paths.";
} else if (walkerArrivedAt !== null) {
statusTitle.textContent = "Walker has arrived";
statusText.textContent =
"The wheelchair route is still navigating its ramp and turning landings.";
} else if (chairDistance > chairPath.length * 0.55) {
statusTitle.textContent = "Final accessible approach";
statusText.textContent =
"The mobility aid is following the raised ramp toward the shared landing.";
} else if (chairDistance > 0.05) {
statusTitle.textContent = "Routes in motion";
statusText.textContent =
"The stair walker and ramp user remain on separate approach paths.";
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```