Prompt specification
Build or customize the Three.js 3D scene "Boarding ramp alignment test" 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: Boarding ramp alignment test
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/boarding-ramp-alignment-test-x0406
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel bus boarding-ramp alignment test. Model a short bus doorway and floor section on one side, with three interchangeable curb modules of different heights on the other. The ramp hinges from the doorway and lowers toward the selected curb. Show its end contact, any remaining gap, and the continuous surface available to a small wheeled proxy. Allow the platform height to move slowly so the contact changes are easy to see. Use fictional dimensions in this geometric illustration.
Working Three.js Starter (boarding-ramp-alignment-test-x0406):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Bus Ramp Alignment Test</title>
<style>
:root {
color-scheme: dark;
--bg: #081018;
--panel: rgba(12, 22, 31, 0.88);
--panel-border: rgba(157, 196, 218, 0.2);
--text: #e8f1f5;
--muted: #91a8b5;
--cyan: #59e1dc;
--green: #74ed9b;
--amber: #ffbd59;
--red: #ff7272;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
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;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 18px 45px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(12px);
}
#controls {
top: 18px;
left: 18px;
width: 292px;
padding: 17px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 21px;
line-height: 1.12;
letter-spacing: -0.025em;
}
.intro {
margin: 8px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.section-label {
margin: 15px 0 8px;
color: #bed0da;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.module-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
button {
border: 1px solid rgba(160, 196, 214, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
font: inherit;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(89, 225, 220, 0.1);
border-color: rgba(89, 225, 220, 0.45);
}
button:active {
transform: translateY(1px);
}
.module-button {
min-height: 53px;
padding: 7px 4px;
text-align: center;
}
.module-button strong,
.module-button small {
display: block;
}
.module-button strong {
font-size: 11px;
letter-spacing: 0.06em;
}
.module-button small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.module-button.active {
border-color: var(--cyan);
background: rgba(89, 225, 220, 0.13);
box-shadow: inset 0 0 18px rgba(89, 225, 220, 0.06);
}
.range-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 12px;
}
output {
color: var(--amber);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--cyan);
cursor: pointer;
}
input[type="range"]:disabled {
cursor: default;
opacity: 0.55;
}
#cycleButton {
width: 100%;
margin-top: 10px;
padding: 9px 10px;
font-size: 12px;
font-weight: 700;
}
.hint {
margin: 12px 0 0;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#status {
top: 18px;
right: 18px;
width: 255px;
padding: 16px;
}
.status-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.status-heading strong {
font-size: 12px;
letter-spacing: 0.04em;
}
#stateChip {
padding: 5px 8px;
border: 1px solid currentColor;
border-radius: 999px;
color: var(--green);
background: rgba(116, 237, 155, 0.08);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.065);
}
.metric span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric strong {
font-size: 13px;
text-align: right;
font-variant-numeric: tabular-nums;
}
.legend {
display: grid;
gap: 7px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 8px currentColor;
}
#cameraHint {
position: absolute;
bottom: 15px;
left: 50%;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: rgba(5, 12, 18, 0.65);
color: #91a8b5;
font-size: 10px;
letter-spacing: 0.04em;
white-space: nowrap;
}
@media (max-width: 760px) {
#controls {
top: 10px;
left: 10px;
width: 245px;
padding: 13px;
}
#status {
top: auto;
right: 10px;
bottom: 46px;
width: 210px;
padding: 12px;
}
h1 {
font-size: 17px;
}
.intro,
.legend {
display: none;
}
.section-label {
margin-top: 10px;
}
#cameraHint {
bottom: 9px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="hud">
<section id="controls" class="panel">
<p class="eyebrow">Geometric illustration</p>
<h1>Voxel Bus Ramp Lab</h1>
<p class="intro">
Select one of three interchangeable curbs. The hinged ramp aligns
to it while the selected platform moves slowly to reveal contact
and separation.
</p>
<div class="section-label">Curb module</div>
<div class="module-grid">
<button class="module-button" data-index="0">
<strong>LOW</strong>
<small>0.72 m</small>
</button>
<button class="module-button active" data-index="1">
<strong>MID</strong>
<small>0.92 m</small>
</button>
<button class="module-button" data-index="2">
<strong>HIGH</strong>
<small>1.12 m</small>
</button>
</div>
<div class="section-label">Platform motion</div>
<div class="range-row">
<label for="dropSlider">Selected platform lowered</label>
<output id="dropOutput" for="dropSlider">0 mm</output>
</div>
<input
id="dropSlider"
type="range"
min="0"
max="320"
step="1"
value="0"
disabled
>
<button id="cycleButton" type="button">Pause slow height cycle</button>
<p class="hint">
All dimensions are fictional. The cyan line marks the available
route; green indicates a continuous bridge to the curb.
</p>
</section>
<section id="status" class="panel" aria-live="polite">
<div class="status-heading">
<strong>Surface test</strong>
<span id="stateChip">CONTACT</span>
</div>
<div class="metric">
<span>Remaining gap</span>
<strong id="gapValue">0 mm</strong>
</div>
<div class="metric">
<span>Ramp angle</span>
<strong id="slopeValue">0.0°</strong>
</div>
<div class="metric">
<span>Proxy route</span>
<strong id="proxyValue">Continuous</strong>
</div>
<div class="metric">
<span>Selected curb</span>
<strong id="curbValue">MID · 0.92 m</strong>
</div>
<div class="legend">
<div class="legend-row">
<span class="dot" style="color:#74ed9b;background:#74ed9b"></span>
Contact and continuous surface
</div>
<div class="legend-row">
<span class="dot" style="color:#ffbd59;background:#ffbd59"></span>
Remaining vertical gap
</div>
<div class="legend-row">
<span class="dot" style="color:#59e1dc;background:#59e1dc"></span>
Hinged ramp path
</div>
</div>
</section>
<div id="cameraHint">
Drag: orbit · Shift-drag: pan · Wheel: zoom · Double-click: reset view
</div>
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0x081018);
scene.fog = new THREE.Fog(0x081018, 17, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbfe8ff, 0x18202b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d9, 3.25);
sun.position.set(6, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x54c8ff, 1.15);
rim.position.set(-7, 5, -6);
scene.add(rim);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x101923,
roughness: 0.96,
metalness: 0.03
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.04;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x355064, 0x1a2a37);
grid.position.y = -0.025;
grid.material.transparent = true;
grid.material.opacity = 0.52;
scene.add(grid);
function makeBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(title, subtitle = "", accent = "#59e1dc") {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 96;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.45, 0.435, 1);
sprite.renderOrder = 20;
sprite.userData.canvas = canvas;
sprite.userData.context = context;
sprite.userData.texture = texture;
sprite.userData.title = "";
sprite.userData.subtitle = "";
sprite.userData.accent = "";
setTextSprite(sprite, title, subtitle, accent);
return sprite;
}
function setTextSprite(sprite, title, subtitle, accent) {
if (
sprite.userData.title === title &&
sprite.userData.subtitle === subtitle &&
sprite.userData.accent === accent
) {
return;
}
sprite.userData.title = title;
sprite.userData.subtitle = subtitle;
sprite.userData.accent = accent;
const context = sprite.userData.context;
const canvas = sprite.userData.canvas;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 16, 23, 0.92)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = accent;
context.lineWidth = 4;
context.strokeRect(2, 2, canvas.width - 4, canvas.height - 4);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = accent;
context.font = "800 28px system-ui, sans-serif";
context.fillText(title, canvas.width / 2, 32);
context.fillStyle = "#d9e8ef";
context.font = "600 17px system-ui, sans-serif";
context.fillText(subtitle, canvas.width / 2, 66);
sprite.userData.texture.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Fictional bus doorway and floor section
// ---------------------------------------------------------------------
const BUS_FLOOR_Y = 1.35;
const HINGE = new THREE.Vector3(-2.13, BUS_FLOOR_Y, 0);
const busDeckMaterial = new THREE.MeshStandardMaterial({
color: 0x364653,
roughness: 0.82,
metalness: 0.08
});
const busWallMaterial = new THREE.MeshStandardMaterial({
color: 0x607b8c,
roughness: 0.76,
metalness: 0.08
});
const busTrimMaterial = new THREE.MeshStandardMaterial({
color: 0x1f9fa8,
roughness: 0.58,
metalness: 0.2
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x8bc6d6,
transparent: true,
opacity: 0.38,
roughness: 0.22,
metalness: 0.08
});
makeBox(
3.2,
0.22,
3.8,
busDeckMaterial,
-3.75,
BUS_FLOOR_Y - 0.11,
0
);
// Floor seams.
const floorSeamMaterial = new THREE.MeshBasicMaterial({
color: 0x182733
});
for (let x = -5.05; x < -2.2; x += 0.48) {
makeBox(
0.018,
0.008,
3.68,
floorSeamMaterial,
x,
BUS_FLOOR_Y + 0.005,
0
);
}
for (let z = -1.45; z <= 1.45; z += 0.48) {
makeBox(
3.08,
0.008,
0.018,
floorSeamMaterial,
-3.75,
BUS_FLOOR_Y + 0.005,
z
);
}
// Back wall and short side wall sections.
makeBox(0.22, 2.2, 3.8, busWallMaterial, -5.35, 2.45, 0);
makeBox(3.2, 0.18, 0.18, busTrimMaterial, -3.75, 3.48, -1.8);
makeBox(3.2, 0.18, 0.18, busTrimMaterial, -3.75, 3.48, 1.8);
// Doorway: two voxel posts and a header.
makeBox(0.25, 2.02, 0.19, busTrimMaterial, -2.12, 2.37, -1.02);
makeBox(0.25, 2.02, 0.19, busTrimMaterial, -2.12, 2.37, 1.02);
makeBox(0.28, 0.22, 2.24, busTrimMaterial, -2.12, 3.43, 0);
// Window panels on the rear wall.
makeBox(0.025, 0.78, 1.25, windowMaterial, -5.225, 2.63, -0.92);
makeBox(0.025, 0.78, 1.25, windowMaterial, -5.225, 2.63, 0.92);
// Bench and small voxel details.
const seatMaterial = new THREE.MeshStandardMaterial({
color: 0x315264,
roughness: 0.82
});
makeBox(0.82, 0.16, 1.28, seatMaterial, -4.85, 1.66, -0.95);
makeBox(0.16, 0.48, 1.28, seatMaterial, -5.18, 1.45, -0.95);
makeBox(0.25, 0.25, 0.25, busTrimMaterial, -2.96, 1.48, 1.38);
const busLabel = makeTextSprite(
"BUS FLOOR",
"hinge elevation 1.35 m",
"#59e1dc"
);
busLabel.position.set(-4.05, 3.88, 0);
scene.add(busLabel);
// ---------------------------------------------------------------------
// Three interchangeable curb modules
// ---------------------------------------------------------------------
const moduleNames = ["LOW", "MID", "HIGH"];
const nominalHeights = [0.72, 0.92, 1.12];
const moduleZ = [-2.25, 0, 2.25];
const moduleFrontX = 1.45;
const contactTargetX = 1.55;
const curbMaterial = new THREE.MeshStandardMaterial({
color: 0x71818a,
roughness: 0.9,
metalness: 0.03
});
const curbSideMaterial = new THREE.MeshStandardMaterial({
color: 0x3e515d,
roughness: 0.92,
metalness: 0.04
});
const curbEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x6a7d88,
transparent: true,
opacity: 0.85
});
const modules = [];
for (let i = 0; i < 3; i++) {
const root = new THREE.Group();
root.position.set(2.65, nominalHeights[i], moduleZ[i]);
scene.add(root);
const slab = makeBox(
2.4,
0.22,
1.75,
curbMaterial,
0,
-0.11,
0,
root
);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(slab.geometry),
curbEdgeMaterial.clone()
);
edges.position.copy(slab.position);
root.add(edges);
// Block support whose height changes with the selected platform.
const support = makeBox(
1,
1,
1,
curbSideMaterial,
0.18,
0,
0,
root
);
// Deck seams.
const seamMaterial = new THREE.MeshBasicMaterial({
color: 0x43535c
});
for (const localX of [-0.78, 0, 0.78]) {
makeBox(
0.015,
0.009,
1.67,
seamMaterial,
localX,
0.006,
0,
root
);
}
for (const localZ of [-0.55, 0.55]) {
makeBox(
2.31,
0.009,
0.015,
seamMaterial,
0,
0.006,
localZ,
root
);
}
const label = makeTextSprite(
`${moduleNames[i]} CURB`,
`nominal ${nominalHeights[i].toFixed(2)} m`,
i === 1 ? "#59e1dc" : "#8fa9b6"
);
label.position.set(0.62, 0.67, 0);
root.add(label);
const selectionRing = new THREE.Mesh(
new THREE.RingGeometry(0.16, 0.23, 32),
new THREE.MeshBasicMaterial({
color: 0x59e1dc,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
selectionRing.rotation.x = -Math.PI / 2;
selectionRing.position.set(0.83, 0.025, 0);
root.add(selectionRing);
modules.push({
root,
support,
edges,
selectionRing,
nominal: nominalHeights[i],
z: moduleZ[i]
});
}
// ---------------------------------------------------------------------
// Hinged, extending ramp
// ---------------------------------------------------------------------
const rampYaw = new THREE.Group();
rampYaw.position.copy(HINGE);
scene.add(rampYaw);
const rampPitch = new THREE.Group();
rampYaw.add(rampPitch);
const rampMaterial = new THREE.MeshStandardMaterial({
color: 0x4f6775,
roughness: 0.68,
metalness: 0.18,
emissive: 0x10282c,
emissiveIntensity: 0.35
});
const rampRailMaterial = new THREE.MeshStandardMaterial({
color: 0x243c48,
roughness: 0.7,
metalness: 0.25
});
const treadMaterial = new THREE.MeshStandardMaterial({
color: 0x79b9c0,
roughness: 0.74,
metalness: 0.1
});
const rampGeometry = new THREE.BoxGeometry(1, 0.11, 1.24);
rampGeometry.translate(0.5, 0, 0);
const rampDeck = new THREE.Mesh(rampGeometry, rampMaterial);
rampDeck.position.y = -0.055;
rampDeck.castShadow = true;
rampDeck.receiveShadow = true;
rampPitch.add(rampDeck);
const railGeometry = new THREE.BoxGeometry(1, 0.1, 0.075);
railGeometry.translate(0.5, 0, 0);
const leftRail = new THREE.Mesh(railGeometry, rampRailMaterial);
leftRail.position.set(0, -0.025, -0.625);
leftRail.castShadow = true;
rampPitch.add(leftRail);
const rightRail = leftRail.clone();
rightRail.position.z = 0.625;
rampPitch.add(rightRail);
const treads = [];
for (let i = 0; i < 15; i++) {
const tread = makeBox(
0.055,
0.018,
1.16,
treadMaterial,
0,
0.012,
0,
rampPitch
);
treads.push(tread);
}
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0xffc45c,
roughness: 0.38,
metalness: 0.62
});
const hingePin = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 1.58, 20),
hingeMaterial
);
hingePin.rotation.x = Math.PI / 2;
hingePin.position.copy(HINGE);
hingePin.castShadow = true;
scene.add(hingePin);
const hingeLabel = makeTextSprite(
"RAMP HINGE",
"selectable curb alignment",
"#ffc45c"
);
hingeLabel.scale.set(1.25, 0.375, 1);
hingeLabel.position.copy(HINGE).add(new THREE.Vector3(0, 0.6, 0));
scene.add(hingeLabel);
// ---------------------------------------------------------------------
// Contact marker, gap indicator, and labels
// ---------------------------------------------------------------------
const contactDot = new THREE.Mesh(
new THREE.SphereGeometry(0.07, 18, 12),
new THREE.MeshBasicMaterial({ color: 0x74ed9b })
);
scene.add(contactDot);
const contactRing = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.18, 36),
new THREE.MeshBasicMaterial({
color: 0x74ed9b,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.92,
depthWrite: false
})
);
contactRing.rotation.x = -Math.PI / 2;
scene.add(contactRing);
const gapMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd59,
transparent: true,
opacity: 0.95
});
const gapLine = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 1, 10),
gapMaterial
);
scene.add(gapLine);
const gapCap = new THREE.Mesh(
new THREE.SphereGeometry(0.032, 12, 8),
gapMaterial
);
scene.add(gapCap);
const contactLabel = makeTextSprite(
"CONTACT",
"continuous surface",
"#74ed9b"
);
contactLabel.scale.set(1.32, 0.395, 1);
scene.add(contactLabel);
// ---------------------------------------------------------------------
// Small wheeled proxy
// ---------------------------------------------------------------------
const proxy = new THREE.Group();
scene.add(proxy);
const proxyBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xf2b84b,
roughness: 0.55,
metalness: 0.16
});
const proxyCabMaterial = new THREE.MeshStandardMaterial({
color: 0x4cc8c6,
roughness: 0.45,
metalness: 0.15
});
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x111820,
roughness: 0.9
});
const hubMaterial = new THREE.MeshStandardMaterial({
color: 0xb8d5dc,
roughness: 0.36,
metalness: 0.62
});
makeBox(0.54, 0.2, 0.38, proxyBodyMaterial, 0, 0.31, 0, proxy);
makeBox(0.25, 0.16, 0.3, proxyCabMaterial, -0.08, 0.48, 0, proxy);
makeBox(0.12, 0.09, 0.2, hubMaterial, 0.27, 0.34, 0, proxy);
const wheels = [];
for (const x of [-0.17, 0.17]) {
for (const z of [-0.235, 0.235]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.085, 18),
wheelMaterial
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.12, z);
wheel.castShadow = true;
proxy.add(wheel);
wheels.push(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.092, 12),
hubMaterial
);
hub.rotation.x = Math.PI / 2;
hub.position.copy(wheel.position);
proxy.add(hub);
}
}
// Route guide lines.
const routeLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0x59e1dc,
transparent: true,
opacity: 0.85
})
);
routeLine.renderOrder = 10;
scene.add(routeLine);
const bridgeLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0x74ed9b,
transparent: true,
opacity: 0.95
})
);
bridgeLine.renderOrder = 10;
scene.add(bridgeLine);
// ---------------------------------------------------------------------
// UI and simulation state
// ---------------------------------------------------------------------
const moduleButtons = [...document.querySelectorAll(".module-button")];
const dropSlider = document.getElementById("dropSlider");
const dropOutput = document.getElementById("dropOutput");
const cycleButton = document.getElementById("cycleButton");
const stateChip = document.getElementById("stateChip");
const gapValue = document.getElementById("gapValue");
const slopeValue = document.getElementById("slopeValue");
const proxyValue = document.getElementById("proxyValue");
const curbValue = document.getElementById("curbValue");
let selectedIndex = 1;
let dropOffset = 0;
let autoRunning = true;
let autoPhase = 0;
const maxAutoDrop = 0.32;
const targetTip = new THREE.Vector3(
contactTargetX,
nominalHeights[selectedIndex],
moduleZ[selectedIndex]
);
const currentTip = targetTip.clone();
let rampTransition = null;
let proxyDistance = 0;
let proxyWait = 0;
function nominalTargetFor(index) {
return new THREE.Vector3(
contactTargetX,
nominalHeights[index],
moduleZ[index]
);
}
function setSelectedModule(index) {
if (index === selectedIndex) {
return;
}
selectedIndex = index;
targetTip.copy(nominalTargetFor(index));
rampTransition = {
from: currentTip.clone(),
to: targetTip.clone(),
elapsed: 0,
duration: 1.15
};
// Return the platform to contact before beginning the new alignment.
dropOffset = 0;
autoPhase = 0;
dropSlider.value = "0";
dropOutput.textContent = "0 mm";
proxyDistance = 0;
proxyWait = 0;
moduleButtons.forEach((button, i) => {
button.classList.toggle("active", i === selectedIndex);
});
curbValue.textContent =
`${moduleNames[index]} · ${nominalHeights[index].toFixed(2)} m`;
}
moduleButtons.forEach((button) => {
button.addEventListener("click", () => {
setSelectedModule(Number(button.dataset.index));
});
});
cycleButton.addEventListener("click", () => {
autoRunning = !autoRunning;
dropSlider.disabled = autoRunning;
if (autoRunning) {
const normalized = THREE.MathUtils.clamp(
dropOffset / maxAutoDrop,
0,
1
);
autoPhase = Math.acos(THREE.MathUtils.clamp(1 - 2 * normalized, -1, 1));
cycleButton.textContent = "Pause slow height cycle";
} else {
dropSlider.value = String(Math.round(dropOffset * 1000));
cycleButton.textContent = "Resume slow height cycle";
}
});
dropSlider.addEventListener("input", () => {
autoRunning = false;
dropSlider.disabled = false;
cycleButton.textContent = "Resume slow height cycle";
dropOffset = Number(dropSlider.value) / 1000;
dropOutput.textContent = `${dropSlider.value} mm`;
});
// ---------------------------------------------------------------------
// Direct camera controls, without addons
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.1, 1.05, 0);
const cameraOffset = new THREE.Vector3(8.8, 5.6, 9.8);
const spherical = new THREE.Spherical().setFromVector3(cameraOffset);
const initialTarget = cameraTarget.clone();
const initialSpherical = spherical.clone();
function updateCamera() {
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const cameraUp = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = spherical.radius * 0.00135;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(cameraUp, dy * panScale);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.32,
1.42
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
6.2,
22
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraTarget.copy(initialTarget);
spherical.copy(initialSpherical);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Proxy path helpers
// ---------------------------------------------------------------------
const busStart = new THREE.Vector3(-4.83, BUS_FLOOR_Y, 0);
const platformEnd = new THREE.Vector3();
function updateProxy(
delta,
aligned,
contact,
gap,
selectedActualHeight
) {
platformEnd.set(
2.9,
selectedActualHeight,
moduleZ[selectedIndex]
);
const points = [busStart, HINGE, currentTip, platformEnd];
const lengths = [];
let totalLength = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
totalLength += length;
}
const busLength = lengths[0];
const rampLength = lengths[1];
if (!aligned) {
proxyDistance = Math.min(proxyDistance, busLength);
proxyWait = 0;
} else {
const maximumDistance = contact
? totalLength
: busLength + Math.max(0, rampLength - 0.2);
if (!contact && proxyDistance > maximumDistance) {
proxyDistance = maximumDistance;
proxyWait = 0;
}
proxyDistance += delta * 0.9;
if (proxyDistance >= maximumDistance) {
proxyDistance = maximumDistance;
if (contact) {
proxyWait += delta;
if (proxyWait > 1.0) {
proxyDistance = 0;
proxyWait = 0;
}
}
} else {
proxyWait = 0;
}
}
let remaining = proxyDistance;
let segment = 0;
while (
segment < lengths.length - 1 &&
remaining > lengths[segment]
) {
remaining -= lengths[segment];
segment++;
}
segment = Math.min(segment, lengths.length - 1);
const start = points[segment];
const end = points[segment + 1];
const fraction = lengths[segment] > 0
? remaining / lengths[segment]
: 0;
const position = start.clone().lerp(end, fraction);
const tangent = end.clone().sub(start).normalize();
// Build a stable local frame: X forward, Y up, Z sideways.
const side = tangent.clone().cross(new THREE.Vector3(0, 1, 0));
if (side.lengthSq() < 0.00001) {
side.set(0, 0, 1);
} else {
side.normalize();
}
const up = side.clone().cross(tangent).normalize();
const basis = new THREE.Matrix4().makeBasis(
tangent,
up,
side
);
proxy.position.copy(position);
proxy.quaternion.setFromRotationMatrix(basis);
const rolling = aligned && (
contact ||
proxyDistance < busLength + rampLength - 0.2
);
for (const wheel of wheels) {
if (rolling) {
wheel.rotation.y -= delta * 8.5;
}
}
routeLine.geometry.setFromPoints([
busStart,
HINGE,
currentTip
]);
routeLine.material.color.set(contact ? 0x59e1dc : 0xffbd59);
bridgeLine.geometry.setFromPoints([
currentTip,
platformEnd
]);
bridgeLine.material.color.set(contact ? 0x74ed9b : 0xff7272);
bridgeLine.material.opacity = contact ? 0.95 : 0.45;
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const rampBaseColor = new THREE.Color(0x4f6775);
const rampContactColor = new THREE.Color(0x527f79);
const rampGapColor = new THREE.Color(0x806c4e);
const greenColor = new THREE.Color(0x74ed9b);
const amberColor = new THREE.Color(0xffbd59);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Slowly lower and raise the selected platform.
if (autoRunning) {
autoPhase += delta * 0.34;
dropOffset =
maxAutoDrop * (0.5 - 0.5 * Math.cos(autoPhase));
const millimeters = Math.round(dropOffset * 1000);
dropSlider.value = String(millimeters);
dropOutput.textContent = `${millimeters} mm`;
}
// Interpolate the ramp toward the selected curb.
if (rampTransition) {
rampTransition.elapsed += delta;
const t = THREE.MathUtils.clamp(
rampTransition.elapsed / rampTransition.duration,
0,
1
);
const eased = t * t * (3 - 2 * t);
currentTip.lerpVectors(
rampTransition.from,
rampTransition.to,
eased
);
if (t >= 1) {
currentTip.copy(rampTransition.to);
rampTransition = null;
}
} else {
currentTip.copy(targetTip);
}
// Update the three module positions and highlights.
for (let i = 0; i < modules.length; i++) {
const module = modules[i];
const isSelected = i === selectedIndex;
const actualHeight =
module.nominal - (isSelected ? dropOffset : 0);
module.root.position.y = actualHeight;
const supportHeight = Math.max(0.08, actualHeight - 0.22);
module.support.scale.y = supportHeight;
module.support.position.y = -(actualHeight + 0.22) / 2;
module.edges.material.color.set(
isSelected ? 0x59e1dc : 0x6a7d88
);
module.edges.material.opacity = isSelected ? 1 : 0.45;
module.selectionRing.visible = isSelected;
if (isSelected) {
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.09;
module.selectionRing.scale.setScalar(pulse);
module.selectionRing.material.opacity = 0.72 + Math.sin(elapsed * 3.2) * 0.16;
}
}
const selectedActualHeight =
nominalHeights[selectedIndex] - dropOffset;
// Set the ramp hinge yaw and pitch.
const dx = currentTip.x - HINGE.x;
const dy = currentTip.y - HINGE.y;
const dz = currentTip.z - HINGE.z;
const horizontalLength = Math.hypot(dx, dz);
const rampLength = Math.hypot(horizontalLength, dy);
const yaw = -Math.atan2(dz, dx);
const pitch = Math.atan2(dy, horizontalLength);
rampYaw.rotation.y = yaw;
rampPitch.rotation.z = pitch;
rampDeck.scale.x = rampLength;
leftRail.scale.x = rampLength;
rightRail.scale.x = rampLength;
for (let i = 0; i < treads.length; i++) {
treads[i].position.x =
rampLength * ((i + 0.5) / treads.length);
}
const alignmentError = currentTip.distanceTo(targetTip);
const aligned = alignmentError < 0.025;
const signedGap = currentTip.y - selectedActualHeight;
const visibleGap = Math.max(0, signedGap);
const contact = aligned && signedGap <= 0.012;
// Update contact and gap visualization.
contactDot.position.copy(currentTip);
contactDot.material.color.copy(contact ? greenColor : amberColor);
contactRing.position.set(
contactTargetX,
selectedActualHeight + 0.018,
moduleZ[selectedIndex]
);
contactRing.material.color.copy(contact ? greenColor : amberColor);
contactRing.scale.setScalar(
1 + Math.sin(elapsed * 4.2) * (contact ? 0.12 : 0.04)
);
gapLine.visible = visibleGap > 0.009;
gapCap.visible = gapLine.visible;
if (gapLine.visible) {
gapLine.scale.y = visibleGap;
gapLine.position.set(
currentTip.x,
selectedActualHeight + visibleGap / 2,
currentTip.z
);
gapCap.position.set(
currentTip.x,
selectedActualHeight,
currentTip.z
);
}
const markerColor = contact
? greenColor
: aligned
? amberColor
: new THREE.Color(0x59e1dc);
rampMaterial.color
.copy(rampBaseColor)
.lerp(
contact
? rampContactColor
: aligned
? rampGapColor
: rampBaseColor,
0.72
);
rampMaterial.emissive.copy(markerColor).multiplyScalar(
contact ? 0.085 : 0.035
);
contactLabel.position.copy(currentTip).add(
new THREE.Vector3(0, 0.48, 0)
);
if (!aligned) {
setTextSprite(
contactLabel,
"ALIGNING",
"ramp moving to curb",
"#59e1dc"
);
} else if (contact) {
setTextSprite(
contactLabel,
"CONTACT",
"continuous surface",
"#74ed9b"
);
} else {
const gapMillimeters = Math.round(visibleGap * 1000);
setTextSprite(
contactLabel,
`GAP ${gapMillimeters} mm`,
"proxy held at lip",
"#ffbd59"
);
}
updateProxy(
delta,
aligned,
contact,
visibleGap,
selectedActualHeight
);
// Update the status panel.
const gapMillimeters = Math.round(visibleGap * 1000);
const slopeDegrees =
Math.abs(Math.atan2(dy, horizontalLength)) * 180 / Math.PI;
gapValue.textContent = aligned
? `${gapMillimeters} mm`
: "—";
slopeValue.textContent = `${slopeDegrees.toFixed(1)}°`;
if (!aligned) {
stateChip.textContent = "ALIGNING";
stateChip.style.color = "#59e1dc";
stateChip.style.background = "rgba(89,225,220,.08)";
proxyValue.textContent = "Waiting";
} else if (contact) {
stateChip.textContent = "CONTACT";
stateChip.style.color = "#74ed9b";
stateChip.style.background = "rgba(116,237,155,.08)";
proxyValue.textContent = "Continuous";
} else {
stateChip.textContent = "GAP";
stateChip.style.color = "#ffbd59";
stateChip.style.background = "rgba(255,189,89,.08)";
proxyValue.textContent = "Held at lip";
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```