Prompt specification
Build or customize the Three.js 3D scene "Bus ramp deployment section" 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: Bus ramp deployment section
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bus-ramp-deployment-section-x0405
Scene Description Prompt:
Model a bus doorway, hinged boarding ramp, and curb segment; show the ramp's pivot and landing contact in a side view with clear height differences. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (bus-ramp-deployment-section-x0405):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bus Doorway & Hinged Boarding Ramp</title>
<style>
:root {
--ink: #172a35;
--muted: #62727b;
--paper: rgba(255, 255, 255, 0.88);
--teal: #147f83;
--orange: #f47b32;
--line: rgba(23, 42, 53, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
background:
radial-gradient(circle at 74% 22%, rgba(255, 255, 255, 0.94), transparent 34%),
linear-gradient(155deg, #f8f3e9 0%, #ebe8df 58%, #dce3df 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.tag {
position: absolute;
min-width: 112px;
padding: 8px 10px 8px 12px;
border: 1px solid rgba(23, 42, 53, 0.13);
border-radius: 8px;
background: rgba(255, 255, 255, 0.91);
box-shadow: 0 8px 24px rgba(31, 45, 52, 0.1);
backdrop-filter: blur(8px);
transform: translate(-50%, -50%);
white-space: nowrap;
transition: opacity 180ms ease;
}
.tag::before {
content: "";
position: absolute;
top: 50%;
left: -5px;
width: 9px;
height: 9px;
border: 2px solid white;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 1px rgba(23, 42, 53, 0.16);
transform: translateY(-50%);
}
.tag b {
display: block;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.035em;
text-transform: uppercase;
}
.tag span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.01em;
}
.tag.pivot,
.tag.contact {
border-color: rgba(244, 123, 50, 0.34);
}
.tag.pivot::before,
.tag.contact::before {
background: var(--orange);
}
.tag.dimension::before {
background: #cf6d2d;
}
.panel {
position: fixed;
z-index: 5;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px;
border: 1px solid rgba(23, 42, 53, 0.12);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(34, 48, 54, 0.12);
backdrop-filter: blur(16px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 19px;
height: 2px;
background: var(--teal);
}
h1 {
margin: 9px 0 6px;
font-size: clamp(22px, 3vw, 30px);
line-height: 1.03;
letter-spacing: -0.04em;
}
.subtitle {
margin: 0;
max-width: 290px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin: 14px 0;
}
.stat {
padding: 8px 6px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.5);
text-align: center;
}
.stat strong {
display: block;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.stat small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
display: flex;
gap: 8px;
}
button {
min-height: 36px;
padding: 0 12px;
border: 1px solid rgba(23, 42, 53, 0.16);
border-radius: 8px;
color: var(--ink);
background: white;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #f7faf9;
}
button.primary {
flex: 1;
border-color: var(--teal);
color: white;
background: var(--teal);
}
button.primary:hover {
background: #0d6f72;
}
.footer {
position: fixed;
z-index: 5;
right: 22px;
bottom: 20px;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 12px;
border: 1px solid rgba(23, 42, 53, 0.12);
border-radius: 9px;
color: var(--muted);
background: rgba(255, 255, 255, 0.76);
backdrop-filter: blur(10px);
font-size: 10px;
}
.legend {
display: flex;
align-items: center;
gap: 12px;
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
}
.legend i.contact-dot {
background: var(--orange);
}
.hint {
position: fixed;
z-index: 4;
left: 22px;
bottom: 20px;
color: rgba(23, 42, 53, 0.62);
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: #f2eee6;
font-size: 12px;
transition: opacity 250ms ease;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.subtitle,
.stats {
display: none;
}
h1 {
margin-bottom: 0;
font-size: 20px;
}
.controls {
margin-top: 10px;
}
.tag {
min-width: 92px;
padding: 6px 8px;
}
.tag b {
font-size: 9px;
}
.tag span {
font-size: 8px;
}
.footer {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Stylized side elevation of a bus doorway and hinged boarding ramp"></canvas>
<div id="labels">
<div class="tag pivot" id="tag-pivot">
<b>Hinged pivot</b>
<span>Bus threshold hinge</span>
</div>
<div class="tag contact" id="tag-contact">
<b>Landing contact</b>
<span>Underside meets curb</span>
</div>
<div class="tag dimension" id="tag-floor">
<b>Bus floor · 1.28 m</b>
<span>Height above street</span>
</div>
<div class="tag dimension" id="tag-curb">
<b>Curb · 0.26 m</b>
<span>Height above street</span>
</div>
<div class="tag dimension" id="tag-slope">
<b>13.0° ramp</b>
<span>Deployed slope</span>
</div>
<div class="tag dimension" id="tag-run">
<b>3.90 m run</b>
<span>Horizontal distance</span>
</div>
</div>
<section class="panel" aria-label="Scene controls">
<div class="eyebrow">Side elevation / 01</div>
<h1>Bus doorway &<br />boarding ramp</h1>
<p class="subtitle">
A dimensional study of the threshold hinge, curb landing, and clear
difference between the bus floor and street.
</p>
<div class="stats" aria-label="Scene dimensions">
<div class="stat">
<strong>1.28 m</strong>
<small>Bus floor</small>
</div>
<div class="stat">
<strong>0.26 m</strong>
<small>Curb</small>
</div>
<div class="stat">
<strong>13.0°</strong>
<small>Ramp</small>
</div>
</div>
<div class="controls">
<button class="primary" id="toggle-ramp" type="button">Stow ramp</button>
<button id="reset-view" type="button" title="Reset camera">Reset view</button>
</div>
</section>
<div class="hint">Drag to orbit slightly · Scroll to zoom · Double-click to reset</div>
<div class="footer">
<div class="legend">
<span><i></i> Fixed structure</span>
<span><i class="contact-dot"></i> Ramp contact</span>
</div>
<span>Dimensions in meters</span>
</div>
<div id="loading">Loading Three.js scene…</div>
</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.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(-0.12, 1.36, 0);
let yaw = 0.025;
let pitch = 0.075;
let zoom = 1;
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
const material = {
bus: new THREE.MeshStandardMaterial({
color: 0x177f83,
roughness: 0.58,
metalness: 0.04
}),
busDark: new THREE.MeshStandardMaterial({
color: 0x0d5d63,
roughness: 0.7
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf5ead4,
roughness: 0.7
}),
glass: new THREE.MeshStandardMaterial({
color: 0x173d4a,
roughness: 0.18,
metalness: 0.2
}),
glassLight: new THREE.MeshStandardMaterial({
color: 0x2d6370,
roughness: 0.15,
metalness: 0.12
}),
interior: new THREE.MeshStandardMaterial({
color: 0x23333a,
roughness: 0.88
}),
tire: new THREE.MeshStandardMaterial({
color: 0x182126,
roughness: 0.94
}),
hub: new THREE.MeshStandardMaterial({
color: 0xb8c1c0,
roughness: 0.38,
metalness: 0.52
}),
ramp: new THREE.MeshStandardMaterial({
color: 0xcbd9dc,
roughness: 0.62,
metalness: 0.08
}),
rampEdge: new THREE.MeshStandardMaterial({
color: 0x526d73,
roughness: 0.58
}),
grip: new THREE.MeshStandardMaterial({
color: 0x263b42,
roughness: 0.96
}),
orange: new THREE.MeshStandardMaterial({
color: 0xf47b32,
roughness: 0.48,
metalness: 0.08
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xf1b840,
roughness: 0.66
}),
road: new THREE.MeshStandardMaterial({
color: 0x34444c,
roughness: 0.93
}),
curb: new THREE.MeshStandardMaterial({
color: 0xc9b99e,
roughness: 0.88
}),
curbTop: new THREE.MeshStandardMaterial({
color: 0xe4d8c3,
roughness: 0.9
}),
backdrop: new THREE.MeshStandardMaterial({
color: 0xe7e2d8,
roughness: 1
})
};
// ------------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------------
function addBox(
width,
height,
depth,
mat,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x20343b, opacity = 0.2) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 20),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return mesh;
}
function addLine(points, mat, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const line = new THREE.Line(geometry, mat);
parent.add(line);
return line;
}
function addTextPlane({
text,
width,
height,
x,
y,
z,
background = "#17343e",
foreground = "#fff6dd",
fontSize = 52
}) {
const textCanvas = document.createElement("canvas");
textCanvas.width = 768;
textCanvas.height = 160;
const context = textCanvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, textCanvas.width, textCanvas.height);
context.fillStyle = foreground;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, textCanvas.width / 2, textCanvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffffff,
0x8b806f,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2dc, 3.2);
sun.position.set(-3.5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e4e7, 0.7);
fill.position.set(6, 4, -5);
scene.add(fill);
// ------------------------------------------------------------------
// Street and curb
// ------------------------------------------------------------------
const road = addBox(
9.95,
0.12,
3.1,
material.road,
1.425,
-0.06,
0,
scene,
false
);
road.receiveShadow = true;
const sidewalk = addBox(
2.45,
0.26,
2.55,
material.curb,
-4.775,
0.13,
0,
scene,
false
);
sidewalk.receiveShadow = true;
const curbTop = addBox(
2.45,
0.025,
2.55,
material.curbTop,
-4.775,
0.2725,
0,
scene,
false
);
curbTop.receiveShadow = true;
// Curb edge is aligned with the ramp's lower landing.
addBox(
0.055,
0.22,
2.56,
material.cream,
-3.548,
0.13,
0
);
// A restrained tactile strip on the sidewalk.
addBox(
0.28,
0.026,
1.65,
material.yellow,
-3.98,
0.298,
0,
scene,
false
);
for (let i = 0; i < 7; i++) {
addBox(
0.018,
0.008,
1.5,
material.grip,
-4.08 + i * 0.034,
0.316,
0,
scene,
false
);
}
// ------------------------------------------------------------------
// Bus body
// ------------------------------------------------------------------
const bus = new THREE.Group();
scene.add(bus);
const chassis = addBox(
6.0,
0.32,
1.7,
material.busDark,
2.55,
0.66,
0,
bus
);
addEdges(chassis);
const lowerBody = addBox(
4.24,
1.12,
1.7,
material.bus,
3.38,
1.39,
0,
bus
);
addEdges(lowerBody);
const upperBody = addBox(
4.24,
1.35,
1.7,
material.cream,
3.38,
2.575,
0,
bus
);
addEdges(upperBody);
const roof = addBox(
6.0,
0.34,
1.7,
material.cream,
2.55,
3.38,
0,
bus
);
addEdges(roof);
const frontNose = addBox(
0.16,
1.16,
1.7,
material.bus,
-0.37,
1.39,
0,
bus
);
addEdges(frontNose);
// Door header and open doorway.
const doorHeader = addBox(
1.65,
0.28,
1.7,
material.cream,
0.55,
3.22,
0,
bus
);
addEdges(doorHeader);
const interiorRecess = addBox(
1.48,
1.89,
0.06,
material.interior,
0.53,
2.225,
-0.79,
bus,
false
);
interiorRecess.receiveShadow = true;
const threshold = addBox(
1.64,
0.14,
1.66,
material.busDark,
0.55,
1.21,
0,
bus
);
addEdges(threshold, 0x10272c, 0.3);
// Door frame.
addBox(0.11, 1.95, 0.12, material.cream, -0.22, 2.25, 0.89, bus);
addBox(0.11, 1.95, 0.12, material.cream, 1.31, 2.25, 0.89, bus);
// A narrow folded glass leaf at the rear edge of the doorway.
addBox(
0.075,
1.78,
0.075,
material.glassLight,
1.265,
2.25,
0.925,
bus
);
// Side windows.
const windowCenters = [1.83, 3.32, 4.81];
for (const x of windowCenters) {
const windowMesh = addBox(
1.25,
1.03,
0.045,
material.glass,
x,
2.56,
0.875,
bus,
false
);
addEdges(windowMesh, 0x0e3039, 0.35);
// Small reflection slashes.
const reflection = new THREE.Mesh(
new THREE.PlaneGeometry(0.085, 0.87),
new THREE.MeshBasicMaterial({
color: 0xcceff0,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
reflection.position.set(x - 0.27, 2.57, 0.901);
reflection.rotation.z = -0.44;
bus.add(reflection);
}
// Cream belt line and lower accent.
addBox(4.22, 0.11, 0.06, material.cream, 3.38, 1.76, 0.89, bus);
addBox(4.18, 0.055, 0.06, material.yellow, 3.38, 1.59, 0.90, bus);
// Interior grab rails visible through the doorway.
for (const x of [0.12, 1.02]) {
const rail = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 1.62, 12),
material.yellow
);
rail.position.set(x, 2.12, -0.42);
rail.castShadow = true;
bus.add(rail);
}
// Wheels, shown as near-side cylinders.
for (const x of [1.58, 4.72]) {
const tire = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.29, 36),
material.tire
);
tire.rotation.x = Math.PI / 2;
tire.position.set(x, 0.62, 0.93);
tire.castShadow = true;
bus.add(tire);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.34, 28),
material.hub
);
hub.rotation.x = Math.PI / 2;
hub.position.set(x, 0.62, 1.0);
hub.castShadow = true;
bus.add(hub);
const hubCenter = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.36, 20),
material.busDark
);
hubCenter.rotation.x = Math.PI / 2;
hubCenter.position.set(x, 0.62, 1.015);
bus.add(hubCenter);
}
addTextPlane({
text: "BOARDING • 24",
width: 1.25,
height: 0.27,
x: 0.54,
y: 3.04,
z: 0.94,
background: "#193740",
foreground: "#f5df9a",
fontSize: 48
});
addTextPlane({
text: "CITY TRANSIT",
width: 1.72,
height: 0.30,
x: 3.38,
y: 1.31,
z: 0.905,
background: "#177f83",
foreground: "#f5ead4",
fontSize: 47
});
// ------------------------------------------------------------------
// Hinged ramp
// ------------------------------------------------------------------
const pivot = new THREE.Vector3(0.35, 1.28, 0);
// The ramp surface slopes from the bus floor to a point just above the
// curb. Its lower edge therefore meets the curb top at the landing.
const landingSurface = new THREE.Vector3(-3.58, 0.376, 0);
const landingContact = new THREE.Vector3(-3.553, 0.26, 0);
const rampLength = pivot.distanceTo(landingSurface);
const deployedAngle = THREE.MathUtils.euclideanModulo(
Math.atan2(
landingSurface.y - pivot.y,
landingSurface.x - pivot.x
),
Math.PI * 2
);
const stowedAngle = Math.PI / 2;
let currentAngle = deployedAngle;
let targetAngle = deployedAngle;
let isDeployed = true;
let contactVisibility = 1;
const rampPivot = new THREE.Group();
rampPivot.position.copy(pivot);
rampPivot.rotation.z = currentAngle;
scene.add(rampPivot);
const rampThickness = 0.12;
const rampWidth = 1.26;
// Because the local +Y direction points toward the ramp underside in
// the deployed position, the slab is offset by half its thickness.
const rampSurface = addBox(
rampLength,
rampThickness,
rampWidth,
material.ramp,
rampLength / 2,
rampThickness / 2,
0,
rampPivot
);
addEdges(rampSurface, 0x29464c, 0.32);
// Raised edge rails.
for (const z of [-0.63, 0.63]) {
addBox(
rampLength,
0.095,
0.065,
material.rampEdge,
rampLength / 2,
-0.045,
z,
rampPivot
);
}
// Anti-slip transverse strips.
const gripCount = 17;
for (let i = 0; i < gripCount; i++) {
const x = 0.2 + (i * (rampLength - 0.42)) / (gripCount - 1);
addBox(
0.042,
0.022,
1.11,
material.grip,
x,
-0.014,
0,
rampPivot,
false
);
}
// Small landing shoe attached to the lower edge.
addBox(
0.17,
0.032,
1.10,
material.grip,
rampLength - 0.085,
0.084,
0,
rampPivot
);
// Visible pivot axle.
const hingeAxle = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.10, 1.58, 28),
material.orange
);
hingeAxle.rotation.x = Math.PI / 2;
hingeAxle.position.copy(pivot);
hingeAxle.castShadow = true;
scene.add(hingeAxle);
const hingeCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.155, 0.155, 0.065, 28),
material.orange
);
hingeCap.rotation.x = Math.PI / 2;
hingeCap.position.set(pivot.x, pivot.y, 0.82);
hingeCap.castShadow = true;
scene.add(hingeCap);
const pivotRing = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.025, 10, 44),
new THREE.MeshBasicMaterial({
color: 0xff9b58,
depthTest: false
})
);
pivotRing.position.set(pivot.x, pivot.y, 0.865);
pivotRing.renderOrder = 6;
scene.add(pivotRing);
// A triangular hinge bracket fixed to the threshold.
const bracketShape = new THREE.Shape();
bracketShape.moveTo(pivot.x + 0.02, pivot.y + 0.02);
bracketShape.lineTo(pivot.x - 0.29, pivot.y - 0.41);
bracketShape.lineTo(pivot.x + 0.28, pivot.y - 0.41);
bracketShape.closePath();
const hingeBracket = new THREE.Mesh(
new THREE.ShapeGeometry(bracketShape),
material.orange
);
hingeBracket.position.z = 0.72;
hingeBracket.castShadow = true;
scene.add(hingeBracket);
// Landing contact ring, lying on the curb.
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.24, 0.027, 10, 48),
new THREE.MeshBasicMaterial({
color: 0xf47b32,
transparent: true,
opacity: 0.96,
depthTest: false
})
);
contactRing.rotation.x = Math.PI / 2;
contactRing.position.set(
landingContact.x,
landingContact.y + 0.018,
0.79
);
contactRing.renderOrder = 6;
scene.add(contactRing);
const contactDot = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 16, 10),
new THREE.MeshBasicMaterial({
color: 0xf47b32,
depthTest: false
})
);
contactDot.position.copy(contactRing.position);
contactDot.renderOrder = 7;
scene.add(contactDot);
// ------------------------------------------------------------------
// Dimension lines and annotations
// ------------------------------------------------------------------
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0xc66a2d,
transparent: true,
opacity: 0.9
});
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x73868c,
transparent: true,
opacity: 0.55,
dashSize: 0.1,
gapSize: 0.07
});
// Bus floor height above the street.
addLine(
[
[1.95, 0, 1.12],
[1.95, 1.28, 1.12]
],
dimensionMaterial
);
addLine(
[
[1.81, 0, 1.12],
[2.09, 0, 1.12]
],
dimensionMaterial
);
addLine(
[
[1.81, 1.28, 1.12],
[2.09, 1.28, 1.12]
],
dimensionMaterial
);
addLine(
[
[1.28, 1.28, 1.12],
[1.95, 1.28, 1.12]
],
guideMaterial
).computeLineDistances();
// Curb height above the street.
addLine(
[
[-4.16, 0, 1.12],
[-4.16, 0.26, 1.12]
],
dimensionMaterial
);
addLine(
[
[-4.29, 0, 1.12],
[-4.03, 0, 1.12]
],
dimensionMaterial
);
addLine(
[
[-4.29, 0.26, 1.12],
[-4.03, 0.26, 1.12]
],
dimensionMaterial
);
// Horizontal run.
addLine(
[
[landingContact.x, -0.39, 1.10],
[pivot.x, -0.39, 1.10]
],
guideMaterial
).computeLineDistances();
addLine(
[
[landingContact.x, -0.51, 1.10],
[landingContact.x, -0.27, 1.10]
],
guideMaterial
).computeLineDistances();
addLine(
[
[pivot.x, -0.51, 1.10],
[pivot.x, -0.27, 1.10]
],
guideMaterial
).computeLineDistances();
// Angle arc at the pivot.
const arcPoints = [];
for (let i = 0; i <= 24; i++) {
const t = i / 24;
const angle = Math.PI + (deployedAngle - Math.PI) * t;
arcPoints.push([
pivot.x + Math.cos(angle) * 0.72,
pivot.y + Math.sin(angle) * 0.72,
1.02
]);
}
addLine(arcPoints, dimensionMaterial);
// ------------------------------------------------------------------
// HTML labels projected from 3D anchors
// ------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#tag-pivot"),
anchor: new THREE.Vector3(0.35, 1.28, 0.9),
offset: [69, -48]
},
{
element: document.querySelector("#tag-contact"),
anchor: new THREE.Vector3(
landingContact.x,
landingContact.y,
0.88
),
offset: [-65, 38],
opacity: () => contactVisibility
},
{
element: document.querySelector("#tag-floor"),
anchor: new THREE.Vector3(1.95, 0.64, 1.12),
offset: [64, 0]
},
{
element: document.querySelector("#tag-curb"),
anchor: new THREE.Vector3(-4.16, 0.13, 1.12),
offset: [-55, 0]
},
{
element: document.querySelector("#tag-slope"),
anchor: new THREE.Vector3(-0.57, 1.30, 1.02),
offset: [-4, -43],
opacity: () => Math.min(1, contactVisibility * 1.5)
},
{
element: document.querySelector("#tag-run"),
anchor: new THREE.Vector3(
(landingContact.x + pivot.x) / 2,
-0.39,
1.1
),
offset: [0, 25],
opacity: () => Math.min(1, contactVisibility * 1.5)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
projected.copy(definition.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
definition.element.style.transform = `
translate(-50%, -50%)
translate(${definition.offset[0]}px, ${definition.offset[1]}px)
`;
const opacity = definition.opacity
? definition.opacity()
: 1;
definition.element.style.opacity = String(opacity);
}
}
// ------------------------------------------------------------------
// Custom camera controls — no external controls addon
// ------------------------------------------------------------------
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 deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
yaw = THREE.MathUtils.clamp(yaw + deltaX * 0.003, -0.42, 0.42);
pitch = THREE.MathUtils.clamp(pitch + deltaY * 0.002, -0.08, 0.22);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.6
);
},
{ passive: false }
);
function resetCamera() {
yaw = 0.025;
pitch = 0.075;
zoom = 1;
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
const toggleButton = document.querySelector("#toggle-ramp");
toggleButton.addEventListener("click", () => {
isDeployed = !isDeployed;
targetAngle = isDeployed ? deployedAngle : stowedAngle;
toggleButton.textContent = isDeployed ? "Stow ramp" : "Deploy ramp";
});
function updateCamera() {
const distance = 18;
camera.position.set(
cameraTarget.x +
Math.sin(yaw) * Math.cos(pitch) * distance,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z +
Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Keep the full side elevation in frame on both wide and narrow screens.
const viewWidth = width < 700 ? 12.7 : 13.25;
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewWidth / aspect / 2;
camera.bottom = -viewWidth / aspect / 2;
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-delta * 4.8);
currentAngle = THREE.MathUtils.lerp(
currentAngle,
targetAngle,
easing
);
rampPivot.rotation.z = currentAngle;
contactVisibility = THREE.MathUtils.clamp(
(currentAngle - stowedAngle) / (deployedAngle - stowedAngle),
0,
1
);
contactRing.material.opacity = contactVisibility * 0.96;
contactDot.material.opacity = contactVisibility;
updateCamera();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.style.opacity = "0";
loading.style.pointerEvents = "none";
setTimeout(() => loading.remove(), 300);
}
});
</script>
</body>
</html>
```