Prompt specification
Build or customize the Three.js 3D scene "Short steep stairs and long ramp" 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: Short steep stairs and long ramp
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/short-steep-stairs-and-long-ramp-x1298
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring route distance and travel-time tradeoffs. Model a raised plaza reached by stairs or a winding ramp. Show length and elevation gain for both routes, keeping vertical destination height identical. Low-poly.
Working Three.js Starter (short-steep-stairs-and-long-ramp-x1298):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Summit Plaza — Route Tradeoff</title>
<style>
:root {
--ink: #17313a;
--muted: #64777d;
--panel: rgba(250, 249, 242, 0.91);
--line: rgba(28, 55, 63, 0.13);
--stairs: #f07b3f;
--ramp: #28a6a0;
--gold: #e9b949;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 72% 18%, rgba(255, 247, 207, 0.8), transparent 24%),
linear-gradient(180deg, #c9dfe5 0%, #e7eee7 52%, #e8dfc7 100%);
}
#scene,
#scene canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.header {
position: absolute;
top: 22px;
left: 24px;
z-index: 10;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
padding: 6px 9px;
border: 1px solid rgba(23, 49, 58, 0.15);
border-radius: 999px;
background: rgba(255, 255, 255, 0.58);
backdrop-filter: blur(8px);
color: #496169;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(233, 185, 73, 0.19);
content: "";
}
h1 {
margin: 0;
font-size: clamp(31px, 4vw, 54px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 850;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}
.header p {
max-width: 360px;
margin: 12px 0 0;
color: #516970;
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
top: 18px;
right: 18px;
z-index: 20;
width: 326px;
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(31, 52, 54, 0.14),
inset 0 0 0 1px rgba(27, 57, 65, 0.05);
backdrop-filter: blur(16px) saturate(1.15);
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 10px;
}
.panel-title {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#both-routes {
appearance: none;
border: 1px solid rgba(23, 49, 58, 0.13);
border-radius: 999px;
padding: 6px 10px;
background: #fff;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
#both-routes:hover,
#both-routes.active {
border-color: rgba(23, 49, 58, 0.28);
background: var(--ink);
color: white;
}
.route-card {
--route: var(--stairs);
display: block;
width: 100%;
margin-top: 9px;
padding: 13px 13px 11px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.68);
color: var(--ink);
text-align: left;
font: inherit;
cursor: pointer;
box-shadow: 0 3px 0 rgba(23, 49, 58, 0.02);
transition:
transform 160ms ease,
border-color 160ms ease,
box-shadow 160ms ease,
opacity 160ms ease;
}
.route-card:hover {
transform: translateY(-2px);
border-color: color-mix(in srgb, var(--route) 55%, transparent);
box-shadow: 0 7px 18px rgba(23, 49, 58, 0.08);
}
.route-card.active {
border-color: var(--route);
box-shadow:
0 0 0 1px var(--route),
0 8px 20px rgba(23, 49, 58, 0.08);
}
.route-card.dimmed {
opacity: 0.55;
}
.route-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.route-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 850;
}
.route-name::before {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--route);
content: "";
transform: rotate(45deg);
}
.route-type {
padding: 4px 7px;
border-radius: 999px;
background: color-mix(in srgb, var(--route) 13%, white);
color: color-mix(in srgb, var(--route) 78%, #17313a);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
.metrics {
display: grid;
grid-template-columns: 1.15fr 1fr 0.9fr;
gap: 7px;
margin-top: 12px;
}
.metric {
min-width: 0;
padding-right: 6px;
border-right: 1px solid var(--line);
}
.metric:last-child {
padding-right: 0;
border-right: 0;
}
.metric-label {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 19px;
line-height: 1;
font-weight: 850;
letter-spacing: -0.045em;
white-space: nowrap;
}
.metric-value.gain {
color: var(--route);
}
.profile {
display: block;
width: 100%;
height: 42px;
margin-top: 8px;
overflow: visible;
color: var(--route);
}
.profile-grid {
fill: none;
stroke: rgba(23, 49, 58, 0.08);
stroke-width: 1;
}
.profile-area {
fill: color-mix(in srgb, var(--route) 12%, transparent);
}
.profile-line {
fill: none;
stroke: currentColor;
stroke-width: 2.2;
stroke-linecap: round;
stroke-linejoin: round;
}
.shared-height {
display: flex;
align-items: center;
gap: 9px;
margin-top: 10px;
padding: 9px 10px;
border-radius: 12px;
background: rgba(233, 185, 73, 0.13);
color: #6e5720;
font-size: 10px;
font-weight: 650;
line-height: 1.35;
}
.shared-height strong {
color: #493b18;
white-space: nowrap;
}
.comparison {
margin: 10px 2px 1px;
color: #526970;
font-size: 10px;
line-height: 1.45;
}
.comparison strong {
color: var(--ink);
}
.note {
margin: 8px 2px 0;
color: #7b8b8f;
font-size: 8px;
line-height: 1.4;
}
.view-actions {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 20;
display: flex;
gap: 7px;
}
.view-actions button {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(250, 249, 242, 0.88);
color: var(--ink);
box-shadow: 0 8px 24px rgba(23, 49, 58, 0.12);
backdrop-filter: blur(10px);
cursor: pointer;
transition: 150ms ease;
}
.view-actions button:hover {
transform: translateY(-2px);
background: white;
}
.hint {
position: absolute;
left: 50%;
bottom: 21px;
z-index: 10;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(250, 249, 242, 0.7);
color: #5b6e73;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.03em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.world-label {
position: absolute;
z-index: 8;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(25, 48, 55, 0.82);
color: white;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.025em;
pointer-events: none;
transform: translate(-50%, calc(-100% - 8px));
box-shadow: 0 5px 16px rgba(18, 37, 42, 0.16);
white-space: nowrap;
backdrop-filter: blur(6px);
}
.world-label::after {
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
background: inherit;
content: "";
transform: translateX(-50%) rotate(45deg);
}
.world-label.stairs {
border-color: rgba(240, 123, 63, 0.75);
background: rgba(136, 58, 25, 0.86);
}
.world-label.ramp {
border-color: rgba(40, 166, 160, 0.78);
background: rgba(19, 91, 88, 0.87);
}
.world-label.destination {
border-color: rgba(233, 185, 73, 0.8);
background: rgba(95, 72, 20, 0.87);
}
@media (max-width: 760px) {
.header {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
.header p {
display: none;
}
h1 {
font-size: 34px;
}
.panel {
top: auto;
right: 10px;
bottom: 62px;
left: 10px;
width: auto;
padding: 10px;
border-radius: 16px;
}
.panel-top {
margin-bottom: 7px;
}
.routes {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.route-card {
min-width: 0;
margin-top: 0;
padding: 10px;
}
.route-type,
.profile,
.metric-label,
.note {
display: none;
}
.route-name {
font-size: 11px;
}
.metrics {
grid-template-columns: 1fr 1fr;
margin-top: 9px;
}
.metric {
border-right: 0;
}
.metric-value {
font-size: 17px;
}
.shared-height {
margin-top: 8px;
}
.comparison {
margin-top: 7px;
}
.view-actions {
right: 10px;
bottom: 12px;
}
.hint {
left: 14px;
bottom: 20px;
transform: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly route comparison scene"></div>
<header class="header">
<div class="eyebrow">Access study · 6 m rise</div>
<h1>Summit Plaza</h1>
<p>
Two ways to the same elevated destination. Compare the extra distance
of the winding ramp against the direct stair climb.
</p>
</header>
<aside class="panel" aria-label="Route comparison">
<div class="panel-top">
<span class="panel-title">Route tradeoffs</span>
<button id="both-routes" class="active" type="button">Both routes</button>
</div>
<div class="routes">
<button
id="stairs-card"
class="route-card active"
style="--route: var(--stairs)"
type="button"
aria-pressed="true"
>
<div class="route-head">
<span class="route-name">Direct stairs</span>
<span class="route-type">Steep</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Route length</span>
<span id="stairs-length" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Elevation gain</span>
<span id="stairs-gain" class="metric-value gain">—</span>
</div>
<div class="metric">
<span class="metric-label">Mean grade</span>
<span id="stairs-grade" class="metric-value">—</span>
</div>
</div>
<svg class="profile" id="stairs-profile" viewBox="0 0 280 52">
<path class="profile-grid" d="M8 12H272 M8 29H272 M8 46H272"></path>
<path class="profile-area"></path>
<path class="profile-line"></path>
</svg>
</button>
<button
id="ramp-card"
class="route-card active"
style="--route: var(--ramp)"
type="button"
aria-pressed="true"
>
<div class="route-head">
<span class="route-name">Winding ramp</span>
<span class="route-type">Longer</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Route length</span>
<span id="ramp-length" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Elevation gain</span>
<span id="ramp-gain" class="metric-value gain">—</span>
</div>
<div class="metric">
<span class="metric-label">Mean grade</span>
<span id="ramp-grade" class="metric-value">—</span>
</div>
</div>
<svg class="profile" id="ramp-profile" viewBox="0 0 280 52">
<path class="profile-grid" d="M8 12H272 M8 29H272 M8 46H272"></path>
<path class="profile-area"></path>
<path class="profile-line"></path>
</svg>
</button>
</div>
<div class="shared-height">
<span aria-hidden="true">↥</span>
<span>Shared destination elevation</span>
<strong>+6.0 m</strong>
</div>
<p class="comparison" id="comparison-copy"></p>
<p class="note">
Distances follow the visible 3D centerlines. The stair distance includes
both horizontal treads and vertical risers.
</p>
</aside>
<div id="label-start" class="world-label">TRAILHEAD · 0.0 m</div>
<div id="label-stairs" class="world-label stairs">STAIRS · 12.0 m · +6.0 m</div>
<div id="label-ramp" class="world-label ramp">RAMP · 35.0 m · +6.0 m</div>
<div id="label-destination" class="world-label destination">PLAZA · +6.0 m</div>
<div class="view-actions" aria-label="Camera controls">
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset-view" type="button" aria-label="Reset camera">↺</button>
</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll or pinch to zoom</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 container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd9e6e4, 38, 88);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemi = new THREE.HemisphereLight(0xe9f7ff, 0x718260, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.25);
sun.position.set(-13, 25, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 35;
sun.shadow.camera.bottom = -35;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dded, 0.65);
fill.position.set(15, 10, -18);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared route data
// -------------------------------------------------------------------------
const destination = new THREE.Vector3(-6, 6, 0);
const stairsPoints = [new THREE.Vector3(-12, 0, 0)];
for (let i = 0; i < 12; i++) {
const x = -12 + i * 0.5;
const y = (i + 1) * 0.5;
stairsPoints.push(new THREE.Vector3(x, y, 0));
stairsPoints.push(new THREE.Vector3(x + 0.5, y, 0));
}
const rampPoints = [
new THREE.Vector3(-12, 0.00, 0),
new THREE.Vector3(-14, 0.45, -4),
new THREE.Vector3(-13, 1.05, -8),
new THREE.Vector3(-8, 1.75, -9),
new THREE.Vector3(-5.5, 2.45, -7),
new THREE.Vector3(-8.5, 3.20, -3),
new THREE.Vector3(-10, 4.10, 2),
new THREE.Vector3(-8, 5.20, 4),
destination.clone()
];
function pathLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
}
return length;
}
function horizontalLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += Math.hypot(
points[i].x - points[i - 1].x,
points[i].z - points[i - 1].z
);
}
return length;
}
const elevationGain = 6;
const stairsLength = pathLength(stairsPoints);
const rampLength = pathLength(rampPoints);
const stairsGrade = elevationGain / horizontalLength(stairsPoints) * 100;
const rampGrade = elevationGain / horizontalLength(rampPoints) * 100;
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const materials = {
ground: material(0xaebf98),
trim: material(0x777d72),
support: material(0x747b71),
stairA: material(0xc7b994),
stairB: material(0xb5a680),
ramp: material(0x327f78, { vertexColors: true }),
rampSide: material(0x245c58, { side: THREE.DoubleSide }),
stairsLine: new THREE.MeshBasicMaterial({ color: 0xf07b3f }),
rampLine: new THREE.MeshBasicMaterial({ color: 0x37c1b8 }),
rail: material(0xe9eee4),
paving: [
material(0xd8d0b9),
material(0xcfc7af),
material(0xe1d9c4),
material(0xc9c0a7)
],
treeDark: material(0x4f7653),
treeLight: material(0x6e8d5d),
trunk: material(0x796147),
rock: material(0x9da598),
gold: material(0xe9b949),
coral: material(0xdb7952)
};
const up = new THREE.Vector3(0, 1, 0);
function addMesh(parent, geometry, mat, position, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, mat);
if (position) mesh.position.copy(position);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, mat, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function polylineCylinders(parent, points, radius, mat, offset = 0.055) {
const lifted = points.map(p => p.clone().addScaledVector(up, offset));
for (let i = 1; i < lifted.length; i++) {
cylinderBetween(parent, lifted[i - 1], lifted[i], radius, mat, 6);
}
}
let seed = 82731;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Faceted ground
// -------------------------------------------------------------------------
const groundGeometry = new THREE.PlaneGeometry(90, 90, 18, 18);
groundGeometry.rotateX(-Math.PI / 2);
const groundGeometryFlat = groundGeometry.toNonIndexed();
const groundColors = new Float32Array(
groundGeometryFlat.attributes.position.count * 3
);
const groundBase = new THREE.Color(0xaebe98);
const groundColor = new THREE.Color();
for (let i = 0; i < groundGeometryFlat.attributes.position.count; i += 3) {
groundColor.copy(groundBase);
groundColor.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.05,
(random() - 0.5) * 0.075
);
for (let j = 0; j < 3; j++) {
groundColor.toArray(groundColors, (i + j) * 3);
}
}
groundGeometryFlat.setAttribute(
"color",
new THREE.BufferAttribute(groundColors, 3)
);
groundGeometryFlat.computeVertexNormals();
const ground = new THREE.Mesh(
groundGeometryFlat,
material(0xffffff, { vertexColors: true })
);
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Distant low-poly landscape
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addMesh(
tree,
new THREE.CylinderGeometry(0.16, 0.24, 1.6, 5),
materials.trunk,
new THREE.Vector3(0, 0.8, 0)
);
addMesh(
tree,
new THREE.ConeGeometry(1.1, 2.35, 7),
materials.treeDark,
new THREE.Vector3(0, 2.2, 0)
);
addMesh(
tree,
new THREE.ConeGeometry(0.8, 1.8, 6),
materials.treeLight,
new THREE.Vector3(0.12, 3.0, -0.05)
);
scene.add(tree);
}
[
[-20, -13, 1.25],
[-18, 6, 1.0],
[-11, 15, 1.15],
[12, 15, 1.3],
[19, 9, 1.0],
[18, -11, 1.4],
[9, -17, 1.15],
[-2, -17, 1.25],
[-22, -2, 0.95],
[22, -1, 1.05],
[15, 3, 0.85],
[-5, 14, 0.8]
].forEach(args => addTree(...args));
for (let i = 0; i < 18; i++) {
const angle = random() * Math.PI * 2;
const radius = 19 + random() * 22;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.35 + random() * 0.55, 0),
materials.rock
);
rock.position.set(x, 0.15, z);
rock.scale.set(1, 0.6 + random() * 0.45, 0.8 + random() * 0.5);
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// Low-poly clouds.
const cloudMaterial = material(0xf4f5ec, {
transparent: true,
opacity: 0.78,
depthWrite: false
});
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addMesh(
cloud,
new THREE.IcosahedronGeometry(1.6, 0),
cloudMaterial,
new THREE.Vector3(0, 0, 0),
false,
false
);
addMesh(
cloud,
new THREE.IcosahedronGeometry(1.25, 0),
cloudMaterial,
new THREE.Vector3(1.45, -0.15, 0),
false,
false
);
addMesh(
cloud,
new THREE.IcosahedronGeometry(1.05, 0),
cloudMaterial,
new THREE.Vector3(-1.4, -0.25, 0.1),
false,
false
);
scene.add(cloud);
}
addCloud(-13, 16, -29, 1.15);
addCloud(10, 19, -34, 1.45);
addCloud(23, 14, -25, 0.9);
// -------------------------------------------------------------------------
// Elevated plaza
// -------------------------------------------------------------------------
const plaza = new THREE.Group();
scene.add(plaza);
// Open understructure with columns.
for (const x of [-3.8, 0.6, 5.3]) {
for (const z of [-4.2, 4.2]) {
addMesh(
plaza,
new THREE.BoxGeometry(1.15, 5.45, 1.15),
materials.support,
new THREE.Vector3(x, 2.725, z)
);
}
}
addMesh(
plaza,
new THREE.BoxGeometry(14.35, 0.28, 12.35),
materials.trim,
new THREE.Vector3(1, 5.43, 0)
);
addMesh(
plaza,
new THREE.BoxGeometry(14, 0.5, 12),
materials.stairA,
new THREE.Vector3(1, 5.75, 0)
);
// Paving tiles.
for (let ix = 0; ix < 7; ix++) {
for (let iz = 0; iz < 6; iz++) {
const x = -5 + ix * 2.1;
const z = -5 + iz * 2;
const tileMaterial =
materials.paving[(ix * 2 + iz) % materials.paving.length];
addMesh(
plaza,
new THREE.BoxGeometry(1.95, 0.08, 1.85),
tileMaterial,
new THREE.Vector3(x, 6.04, z)
);
}
}
// Parapets, leaving an opening on the west side.
addMesh(
plaza,
new THREE.BoxGeometry(14.1, 0.68, 0.35),
materials.stairA,
new THREE.Vector3(1, 6.34, -5.82)
);
addMesh(
plaza,
new THREE.BoxGeometry(14.1, 0.68, 0.35),
materials.stairA,
new THREE.Vector3(1, 6.34, 5.82)
);
addMesh(
plaza,
new THREE.BoxGeometry(0.35, 0.68, 12),
materials.stairA,
new THREE.Vector3(7.82, 6.34, 0)
);
for (const z of [-4.25, 4.25]) {
addMesh(
plaza,
new THREE.BoxGeometry(0.35, 0.68, 2.5),
materials.stairA,
new THREE.Vector3(-5.82, 6.34, z)
);
}
// Geometric plaza sculpture.
addMesh(
plaza,
new THREE.CylinderGeometry(1.25, 1.45, 0.25, 12),
materials.trim,
new THREE.Vector3(2.1, 6.17, 0)
);
addMesh(
plaza,
new THREE.CylinderGeometry(0.25, 0.5, 2.4, 5),
materials.coral,
new THREE.Vector3(2.1, 7.25, 0)
);
addMesh(
plaza,
new THREE.OctahedronGeometry(0.47, 0),
materials.gold,
new THREE.Vector3(2.1, 8.7, 0)
);
// -------------------------------------------------------------------------
// Stair route
// -------------------------------------------------------------------------
const stairsGroup = new THREE.Group();
scene.add(stairsGroup);
for (let i = 0; i < 12; i++) {
const height = (i + 1) * 0.5;
const x = -12 + i * 0.5 + 0.25;
addMesh(
stairsGroup,
new THREE.BoxGeometry(0.5, height, 3.2),
i % 2 ? materials.stairA : materials.stairB,
new THREE.Vector3(x, height * 0.5, 0)
);
}
polylineCylinders(
stairsGroup,
stairsPoints,
0.055,
materials.stairsLine,
0.07
);
// Stair handrails and posts.
for (const z of [-1.82, 1.82]) {
cylinderBetween(
stairsGroup,
new THREE.Vector3(-12, 1.0, z),
new THREE.Vector3(-6, 7.0, z),
0.045,
materials.rail,
6
);
for (let i = 0; i <= 6; i++) {
const x = -12 + i;
const stepIndex = Math.min(11, Math.floor((x + 12) / 0.5));
const stepTop = (stepIndex + 1) * 0.5;
addMesh(
stairsGroup,
new THREE.CylinderGeometry(0.035, 0.035, 0.95, 6),
materials.rail,
new THREE.Vector3(x, stepTop + 0.475, z),
true,
false
);
}
}
// -------------------------------------------------------------------------
// Ramp ribbon construction
// -------------------------------------------------------------------------
function rampBoundaries(points, width) {
const left = [];
const right = [];
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const d1 = new THREE.Vector3(
points[i].x - previous.x,
0,
points[i].z - previous.z
).normalize();
const d2 = new THREE.Vector3(
next.x - points[i].x,
0,
next.z - points[i].z
).normalize();
const n1 = new THREE.Vector3(-d1.z, 0, d1.x);
const n2 = new THREE.Vector3(-d2.z, 0, d2.x);
let miter = n1.clone().add(n2);
if (miter.lengthSq() < 0.0001) miter.copy(n2);
miter.normalize();
const denominator = Math.max(0.35, miter.dot(n2));
const offsetScale = Math.min(
width * 0.5,
(width * 0.5) / denominator
);
const offset = miter.multiplyScalar(offsetScale);
left.push(points[i].clone().add(offset));
right.push(points[i].clone().sub(offset));
}
return { left, right };
}
function buildRampTop(boundary) {
const positions = [];
const colors = [];
const base = new THREE.Color(0x2f8078);
const color = new THREE.Color();
for (let i = 0; i < boundary.left.length - 1; i++) {
const a = boundary.left[i];
const b = boundary.right[i];
const c = boundary.left[i + 1];
const d = boundary.right[i + 1];
positions.push(
a.x, a.y, a.z,
c.x, c.y, c.z,
b.x, b.y, b.z,
b.x, b.y, b.z,
c.x, c.y, c.z,
d.x, d.y, d.z
);
color.copy(base).offsetHSL(0, 0, i % 2 ? 0.025 : -0.018);
for (let j = 0; j < 6; j++) color.toArray(colors, colors.length);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function buildRampSide(points) {
const positions = [];
const indices = [];
const thickness = 0.2;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const start = positions.length / 3;
positions.push(
a.x, a.y, a.z,
a.x, a.y - thickness, a.z,
b.x, b.y, b.z,
b.x, b.y - thickness, b.z
);
indices.push(
start, start + 1, start + 2,
start + 2, start + 1, start + 3
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const rampGroup = new THREE.Group();
scene.add(rampGroup);
const rampBoundary = rampBoundaries(rampPoints, 2.25);
const rampTop = new THREE.Mesh(
buildRampTop(rampBoundary),
materials.ramp
);
rampTop.castShadow = true;
rampTop.receiveShadow = true;
rampGroup.add(rampTop);
for (const edge of [rampBoundary.left, rampBoundary.right]) {
const side = new THREE.Mesh(
buildRampSide(edge),
materials.rampSide
);
side.castShadow = true;
side.receiveShadow = true;
rampGroup.add(side);
}
// Ramp supports.
for (const point of rampPoints) {
if (point.y <= 0.2) continue;
const height = point.y - 0.2;
addMesh(
rampGroup,
new THREE.CylinderGeometry(0.14, 0.2, height, 6),
materials.support,
new THREE.Vector3(point.x, height * 0.5, point.z)
);
}
// Ramp guard rails.
for (const edge of [rampBoundary.left, rampBoundary.right]) {
for (let i = 0; i < edge.length - 1; i++) {
const a = edge[i].clone().addScaledVector(up, 0.78);
const b = edge[i + 1].clone().addScaledVector(up, 0.78);
cylinderBetween(rampGroup, a, b, 0.04, materials.rail, 6);
}
for (const point of edge) {
addMesh(
rampGroup,
new THREE.CylinderGeometry(0.035, 0.035, 0.8, 6),
materials.rail,
new THREE.Vector3(point.x, point.y + 0.4, point.z),
true,
false
);
}
}
polylineCylinders(
rampGroup,
rampPoints,
0.065,
materials.rampLine,
0.075
);
// Direction arrows on the ramp.
for (const index of [1, 3, 5]) {
const a = rampPoints[index];
const b = rampPoints[index + 1];
const direction = new THREE.Vector3().subVectors(b, a).normalize();
const middle = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.7, 3),
materials.rampLine
);
arrow.position.copy(middle).addScaledVector(up, 0.16);
arrow.quaternion.setFromUnitVectors(up, direction);
arrow.castShadow = true;
rampGroup.add(arrow);
}
// -------------------------------------------------------------------------
// Trailhead and destination markers
// -------------------------------------------------------------------------
const markers = new THREE.Group();
scene.add(markers);
addMesh(
markers,
new THREE.CylinderGeometry(1.05, 1.2, 0.16, 12),
materials.trim,
new THREE.Vector3(-12, 0.08, 0)
);
const startRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.085, 6, 24),
materials.rail
);
startRing.rotation.x = Math.PI / 2;
startRing.position.set(-12, 0.19, 0);
startRing.castShadow = true;
markers.add(startRing);
const destinationRing = new THREE.Mesh(
new THREE.TorusGeometry(0.78, 0.095, 6, 24),
materials.gold
);
destinationRing.rotation.x = Math.PI / 2;
destinationRing.position.copy(destination).addScaledVector(up, 0.1);
destinationRing.castShadow = true;
markers.add(destinationRing);
const beaconMaterial = new THREE.MeshBasicMaterial({
color: 0xe9b949,
transparent: true,
opacity: 0.32,
depthWrite: false
});
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 2.5, 6),
beaconMaterial
);
beacon.position.copy(destination).addScaledVector(up, 1.25);
markers.add(beacon);
const destinationGem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.3, 0),
materials.gold
);
destinationGem.position.copy(destination).addScaledVector(up, 2.55);
destinationGem.castShadow = true;
markers.add(destinationGem);
// -------------------------------------------------------------------------
// Metrics and elevation profiles
// -------------------------------------------------------------------------
const formatMeters = value => `${value.toFixed(1)} m`;
document.querySelector("#stairs-length").textContent =
formatMeters(stairsLength);
document.querySelector("#ramp-length").textContent =
formatMeters(rampLength);
document.querySelector("#stairs-gain").textContent =
`+${elevationGain.toFixed(1)} m`;
document.querySelector("#ramp-gain").textContent =
`+${elevationGain.toFixed(1)} m`;
document.querySelector("#stairs-grade").textContent =
`${stairsGrade.toFixed(0)}%`;
document.querySelector("#ramp-grade").textContent =
`${rampGrade.toFixed(1)}%`;
document.querySelector("#label-stairs").textContent =
`STAIRS · ${stairsLength.toFixed(1)} m · +${elevationGain.toFixed(1)} m`;
document.querySelector("#label-ramp").textContent =
`RAMP · ${rampLength.toFixed(1)} m · +${elevationGain.toFixed(1)} m`;
document.querySelector("#comparison-copy").innerHTML =
`The ramp travels <strong>${(rampLength / stairsLength).toFixed(1)}× farther</strong> ` +
`while gaining the <strong>same ${elevationGain.toFixed(1)} m</strong> of elevation.`;
function drawProfile(svg, points, color) {
const total = pathLength(points);
const maxElevation = Math.max(...points.map(p => p.y), 6);
const left = 8;
const right = 272;
const top = 9;
const bottom = 46;
let cumulative = 0;
const commands = [];
points.forEach((point, index) => {
if (index > 0) {
cumulative += point.distanceTo(points[index - 1]);
}
const x = left + (cumulative / total) * (right - left);
const y = bottom - (point.y / maxElevation) * (bottom - top);
commands.push(`${index === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`);
});
const linePath = commands.join(" ");
svg.style.color = color;
svg.querySelector(".profile-line").setAttribute("d", linePath);
svg.querySelector(".profile-area").setAttribute(
"d",
`${linePath} L${right},${bottom} L${left},${bottom} Z`
);
}
drawProfile(
document.querySelector("#stairs-profile"),
stairsPoints,
"#f07b3f"
);
drawProfile(
document.querySelector("#ramp-profile"),
rampPoints,
"#28a6a0"
);
// -------------------------------------------------------------------------
// Route isolation
// -------------------------------------------------------------------------
let focus = "both";
const bothButton = document.querySelector("#both-routes");
const stairsCard = document.querySelector("#stairs-card");
const rampCard = document.querySelector("#ramp-card");
function setFocus(nextFocus) {
focus = nextFocus;
stairsGroup.visible = focus !== "ramp";
rampGroup.visible = focus !== "stairs";
stairsCard.classList.toggle("active", focus !== "ramp");
rampCard.classList.toggle("active", focus !== "stairs");
stairsCard.classList.toggle("dimmed", focus === "ramp");
rampCard.classList.toggle("dimmed", focus === "stairs");
stairsCard.setAttribute("aria-pressed", String(focus !== "ramp"));
rampCard.setAttribute("aria-pressed", String(focus !== "stairs"));
bothButton.classList.toggle("active", focus === "both");
}
stairsCard.addEventListener("click", () => setFocus("stairs"));
rampCard.addEventListener("click", () => setFocus("ramp"));
bothButton.addEventListener("click", () => setFocus("both"));
// -------------------------------------------------------------------------
// Camera controls implemented directly
// -------------------------------------------------------------------------
const controls = {
theta: -0.79,
phi: 0.91,
radius: 38,
target: new THREE.Vector3(-1, 2, 0)
};
const desired = {
theta: controls.theta,
phi: controls.phi,
radius: controls.radius,
target: controls.target.clone()
};
const initialCamera = {
theta: controls.theta,
phi: controls.phi,
radius: controls.radius,
target: controls.target.clone()
};
const pointers = new Map();
let previousPinchDistance = 0;
function panCamera(dx, dy) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = desired.radius * 0.0015;
desired.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, -dy * scale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -18, 12);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -16, 16);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const points = [...pointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (event.shiftKey) {
panCamera(dx, dy);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.34,
1.28
);
}
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * previousPinchDistance / distance,
16,
62
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
16,
62
);
},
{ passive: false }
);
document.querySelector("#zoom-in").addEventListener("click", () => {
desired.radius = THREE.MathUtils.clamp(desired.radius * 0.86, 16, 62);
});
document.querySelector("#zoom-out").addEventListener("click", () => {
desired.radius = THREE.MathUtils.clamp(desired.radius * 1.16, 16, 62);
});
document.querySelector("#reset-view").addEventListener("click", () => {
desired.theta = initialCamera.theta;
desired.phi = initialCamera.phi;
desired.radius = initialCamera.radius;
desired.target.copy(initialCamera.target);
});
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") desired.theta += 0.08;
if (event.key === "ArrowRight") desired.theta -= 0.08;
if (event.key === "ArrowUp") {
desired.phi = Math.max(0.34, desired.phi - 0.06);
}
if (event.key === "ArrowDown") {
desired.phi = Math.min(1.28, desired.phi + 0.06);
}
});
// -------------------------------------------------------------------------
// World-space HTML labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-start"),
position: new THREE.Vector3(-12, 0.45, 0),
visible: () => true
},
{
element: document.querySelector("#label-stairs"),
position: new THREE.Vector3(-9.2, 4.3, 2.2),
visible: () => stairsGroup.visible
},
{
element: document.querySelector("#label-ramp"),
position: new THREE.Vector3(-10.8, 3.1, -8.7),
visible: () => rampGroup.visible
},
{
element: document.querySelector("#label-destination"),
position: new THREE.Vector3(1.0, 9.35, 0),
visible: () => true
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!onScreen || !label.visible()) {
label.element.style.display = "none";
continue;
}
label.element.style.display = "block";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-8 * delta);
controls.theta += (desired.theta - controls.theta) * smoothing;
controls.phi += (desired.phi - controls.phi) * smoothing;
controls.radius += (desired.radius - controls.radius) * smoothing;
controls.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```