Prompt specification
Build or customize the Three.js 3D scene "Stair and ramp endpoint model" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Stair and ramp endpoint model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/stair-and-ramp-endpoint-model-x0457
Scene Description Prompt:
Build a small platform reached by stairs and a ramp with identical endpoints; show rise and horizontal distance using simple guides without asserting regulatory dimensions. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (stair-and-ramp-endpoint-model-x0457):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Access Study</title>
<style>
:root {
--ink: #25313b;
--muted: #637078;
--paper: #fffdf7;
--stair: #e9ad32;
--ramp: #e86f51;
--shared: #258b76;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(37, 49, 59, 0.12);
border-radius: 18px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 0 12px 35px rgba(62, 55, 43, 0.1);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--shared);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.metrics {
position: absolute;
top: 24px;
right: 24px;
display: grid;
gap: 8px;
width: 220px;
}
.metric,
.legend-row {
padding: 11px 13px;
border: 1px solid rgba(37, 49, 59, 0.1);
border-radius: 13px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 0 8px 24px rgba(62, 55, 43, 0.08);
backdrop-filter: blur(10px);
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
font-size: 12px;
}
.metric strong {
font-size: 18px;
letter-spacing: -0.03em;
}
.metric span {
color: var(--muted);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 700;
}
.swatch {
width: 13px;
height: 13px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.swatch.stair {
background: var(--stair);
}
.swatch.ramp {
background: var(--ramp);
}
.note {
position: absolute;
left: 24px;
bottom: 24px;
max-width: 460px;
padding: 11px 14px;
border: 1px solid rgba(37, 49, 59, 0.1);
border-radius: 12px;
background: rgba(255, 253, 247, 0.88);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
backdrop-filter: blur(8px);
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid rgba(37, 49, 59, 0.1);
border-radius: 12px;
background: rgba(255, 253, 247, 0.88);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #e9e3d6;
color: var(--ink);
font-size: 14px;
font-weight: 700;
z-index: 20;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro p {
display: none;
}
.metrics {
top: 112px;
left: 12px;
right: auto;
width: 175px;
}
.metric {
padding: 8px 10px;
}
.metric strong {
font-size: 15px;
}
.legend-row {
padding: 8px 10px;
}
.note {
left: 12px;
right: 12px;
bottom: 12px;
max-width: none;
}
.controls {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the voxel scene…</div>
<div class="hud">
<section class="intro">
<div class="eyebrow">Access geometry · voxel study</div>
<h1>One platform.<br />Two routes.</h1>
<p>
Stairs and a ramp connect the same shared lower landing and upper
platform. Simple guides identify the rise and horizontal distance.
</p>
</section>
<section class="metrics">
<div class="metric">
<span>Vertical rise Δh</span>
<strong>2.4 u</strong>
</div>
<div class="metric">
<span>Horizontal L</span>
<strong>6.0 u</strong>
</div>
<div class="legend-row">
<i class="swatch stair"></i>
Stair route
</div>
<div class="legend-row">
<i class="swatch ramp"></i>
Ramp route
</div>
</section>
<div class="note">
“u” means illustrative scene units. The guides describe this model only
and do not assert regulatory, accessibility, or code-compliance dimensions.
</div>
<div class="controls">
Drag to orbit · Wheel/pinch to zoom · Double-click to reset
</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 loading = document.querySelector("#loading");
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene showing stairs and a ramp connecting a lower landing to an upper platform."
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d6);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x817866, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc9e4ef, 0.75);
fill.position.set(7, 6, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared dimensions
// -------------------------------------------------------------------------
const RISE = 2.4;
const RUN = 6.0;
const START_Z = 5.0;
const END_Z = -1.0;
const GROUND_TOP = -0.2;
const stairX = -1.55;
const rampX = 1.55;
const routeWidth = 1.8;
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0
}),
platform: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.83,
metalness: 0
}),
foundation: new THREE.MeshStandardMaterial({
color: 0x345d61,
roughness: 0.95
}),
stair: new THREE.MeshStandardMaterial({
color: 0xe9ad32,
roughness: 0.72
}),
stairAlt: new THREE.MeshStandardMaterial({
color: 0xf2bd4b,
roughness: 0.72
}),
stairEdge: new THREE.MeshStandardMaterial({
color: 0xa86e16,
roughness: 0.8
}),
ramp: new THREE.MeshStandardMaterial({
color: 0xe86f51,
roughness: 0.76,
side: THREE.DoubleSide
}),
rampSupport: new THREE.MeshStandardMaterial({
color: 0x9d4938,
roughness: 0.92
}),
rail: new THREE.MeshStandardMaterial({
color: 0x354d58,
roughness: 0.62
}),
marking: new THREE.MeshStandardMaterial({
color: 0xffe3c4,
roughness: 0.85
}),
endpoint: new THREE.MeshStandardMaterial({
color: 0x36a98e,
roughness: 0.65
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x805a3b,
roughness: 1
}),
leafA: new THREE.MeshStandardMaterial({
color: 0x557a4d,
roughness: 1
}),
leafB: new THREE.MeshStandardMaterial({
color: 0x78935b,
roughness: 1
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addInstancedBoxes(
positions,
geometry,
material,
colorForPosition = null
) {
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
positions.forEach((position, index) => {
dummy.position.copy(position);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (colorForPosition) {
color.set(colorForPosition(position, index));
mesh.setColorAt(index, color);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function beamBetween(start, end, thickness, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const beam = new THREE.Mesh(
new THREE.BoxGeometry(thickness, thickness, length),
material
);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
scene.add(beam);
return beam;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel(mainText, subText, accent, worldWidth = 3.0) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 200;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 752, 184, 25);
ctx.fillStyle = "rgba(255, 253, 247, 0.95)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 28, 28, 12, 144, 6);
ctx.fill();
let mainSize = 46;
ctx.font = `800 ${mainSize}px system-ui, sans-serif`;
const measured = ctx.measureText(mainText).width;
if (measured > 650) {
mainSize = Math.max(28, mainSize * (650 / measured));
ctx.font = `800 ${mainSize}px system-ui, sans-serif`;
}
ctx.fillStyle = "#25313b";
ctx.textBaseline = "middle";
ctx.fillText(mainText, 65, subText ? 72 : 100);
if (subText) {
ctx.fillStyle = "#68747b";
ctx.font = "500 28px system-ui, sans-serif";
ctx.fillText(subText, 65, 131);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * (200 / 768), 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function dashedGuide(points, color = 0x304c5a) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.18,
gapSize: 0.12,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 18;
scene.add(line);
return line;
}
function solidGuide(points, color = 0x304c5a) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 18;
scene.add(line);
return line;
}
// -------------------------------------------------------------------------
// Voxel ground
// -------------------------------------------------------------------------
addBox(
new THREE.Vector3(15, 0.3, 14.5),
new THREE.Vector3(0, -0.55, -0.25),
new THREE.MeshStandardMaterial({
color: 0xb8ad98,
roughness: 1
}),
false
);
const tilePositions = [];
for (let x = -9; x <= 9; x++) {
for (let z = -9; z <= 8; z++) {
tilePositions.push(new THREE.Vector3(x * 0.75, -0.3, z * 0.75));
}
}
addInstancedBoxes(
tilePositions,
new THREE.BoxGeometry(0.72, 0.2, 0.72),
materials.ground,
(position) => {
const variation = ((position.x * 13 + position.z * 7) % 5 + 5) % 5;
const colors = [
0xc9c3ad,
0xd0c8b2,
0xc2bda7,
0xd7cfb9,
0xc8c0a9
];
return colors[variation];
}
);
// -------------------------------------------------------------------------
// Shared lower landing and upper platform
// -------------------------------------------------------------------------
const landingPositions = [];
for (let x = 0; x < 10; x++) {
for (let z = 0; z < 2; z++) {
landingPositions.push(
new THREE.Vector3(-2.7 + x * 0.6, -0.1, 5.3 + z * 0.6)
);
}
}
addInstancedBoxes(
landingPositions,
new THREE.BoxGeometry(0.595, 0.2, 0.595),
materials.foundation
);
const platformBasePositions = [];
for (let x = 0; x < 10; x++) {
for (let z = 0; z < 4; z++) {
platformBasePositions.push(
new THREE.Vector3(-2.7 + x * 0.6, -0.1, -1.3 - z * 0.6)
);
}
}
addInstancedBoxes(
platformBasePositions,
new THREE.BoxGeometry(0.595, 0.2, 0.595),
materials.foundation
);
const blockGeometry = new THREE.BoxGeometry(0.595, 0.595, 0.595);
for (let layer = 0; layer < 4; layer++) {
const positions = [];
for (let x = 0; x < 10; x++) {
for (let z = 0; z < 4; z++) {
positions.push(
new THREE.Vector3(
-2.7 + x * 0.6,
0.3 + layer * 0.6,
-1.3 - z * 0.6
)
);
}
}
addInstancedBoxes(
positions,
blockGeometry,
materials.platform,
(position) => {
const topLayer = layer === 3;
const alternating = (Math.round(position.x * 10) +
Math.round(position.z * 10)) % 2;
return topLayer
? alternating
? 0x3c7c78
: 0x438984
: alternating
? 0x315f63
: 0x37686a;
}
);
}
// -------------------------------------------------------------------------
// Stair route: 12 discrete voxel steps
// -------------------------------------------------------------------------
const stepCount = 12;
const stepRun = RUN / stepCount;
const stepRise = RISE / stepCount;
for (let i = 0; i < stepCount; i++) {
const top = (i + 1) * stepRise;
const highZ = START_Z - i * stepRun;
const lowZ = highZ - stepRun;
const centerZ = (highZ + lowZ) / 2;
const bottom = GROUND_TOP;
const height = top - bottom;
const step = addBox(
new THREE.Vector3(routeWidth, height, stepRun),
new THREE.Vector3(stairX, bottom + height / 2, centerZ),
i % 2 === 0 ? materials.stair : materials.stairAlt
);
step.receiveShadow = true;
// Contrasting nosing makes each step easy to read.
addBox(
new THREE.Vector3(routeWidth - 0.04, 0.05, 0.065),
new THREE.Vector3(stairX, top - 0.025, highZ - 0.035),
materials.stairEdge
);
}
// -------------------------------------------------------------------------
// Ramp route: continuous sloping surface with voxel supports
// -------------------------------------------------------------------------
function rampHeightAt(z) {
return RISE * ((START_Z - z) / RUN);
}
function createRampGeometry() {
const left = rampX - routeWidth / 2;
const right = rampX + routeWidth / 2;
const thickness = 0.22;
const vertices = [
// Top surface
left, 0, START_Z,
right, 0, START_Z,
right, RISE, END_Z,
left, RISE, END_Z,
// Bottom surface
left, -thickness, START_Z,
right, -thickness, START_Z,
right, RISE - thickness, END_Z,
left, RISE - thickness, END_Z
];
const indices = [
0, 1, 2, 0, 2, 3,
4, 6, 5, 4, 7, 6,
0, 4, 5, 0, 5, 1,
3, 2, 6, 3, 6, 7,
0, 3, 7, 0, 7, 4,
1, 5, 6, 1, 6, 2
];
let geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry = geometry.toNonIndexed();
geometry.computeVertexNormals();
return geometry;
}
const rampMesh = new THREE.Mesh(
createRampGeometry(),
materials.ramp
);
rampMesh.castShadow = true;
rampMesh.receiveShadow = true;
scene.add(rampMesh);
// Stepped voxel piers under the ramp.
const supportZ = [4.45, 3.3, 2.15, 1.0, -0.15, -0.75];
supportZ.forEach((z, index) => {
const underside = rampHeightAt(z) - 0.32;
const stackHeight = Math.ceil(
(underside - GROUND_TOP) / 0.2
) * 0.2;
for (let layer = 0; layer < stackHeight / 0.2; layer++) {
addBox(
new THREE.Vector3(1.45, 0.2, 0.45),
new THREE.Vector3(
rampX,
GROUND_TOP + 0.1 + layer * 0.2,
z + (index % 2 === 0 ? 0 : 0.06)
),
materials.rampSupport
);
}
});
// Pale directional bars on the ramp surface.
const slopeAngle = Math.atan(RISE / RUN);
for (let i = 0; i < 6; i++) {
const z = 4.35 - i * 0.9;
const stripe = addBox(
new THREE.Vector3(1.35, 0.025, 0.075),
new THREE.Vector3(rampX, rampHeightAt(z) + 0.035, z),
materials.marking,
false
);
stripe.rotation.x = slopeAngle;
}
// Low ramp curbs.
beamBetween(
new THREE.Vector3(rampX - routeWidth / 2 - 0.03, 0.08, START_Z),
new THREE.Vector3(rampX - routeWidth / 2 - 0.03, RISE + 0.08, END_Z),
0.11,
materials.rampSupport
);
beamBetween(
new THREE.Vector3(rampX + routeWidth / 2 + 0.03, 0.08, START_Z),
new THREE.Vector3(rampX + routeWidth / 2 + 0.03, RISE + 0.08, END_Z),
0.11,
materials.rampSupport
);
// -------------------------------------------------------------------------
// Railings
// -------------------------------------------------------------------------
// Stair handrail on the outer side.
const stairRailX = -2.58;
const stairPostData = [
[4.75, 0.2],
[3.25, 0.8],
[1.75, 1.4],
[0.25, 2.0],
[-0.95, 2.4]
];
stairPostData.forEach(([z, baseY]) => {
addBox(
new THREE.Vector3(0.12, 0.72, 0.12),
new THREE.Vector3(stairRailX, baseY + 0.36, z),
materials.rail
);
});
beamBetween(
new THREE.Vector3(stairRailX, 0.88, 4.85),
new THREE.Vector3(stairRailX, RISE + 0.75, -0.9),
0.12,
materials.rail
);
// Ramp handrail.
const rampRailX = 2.58;
const rampPostZ = [4.65, 3.2, 1.75, 0.3, -0.75];
rampPostZ.forEach((z) => {
const baseY = rampHeightAt(z);
addBox(
new THREE.Vector3(0.12, 0.72, 0.12),
new THREE.Vector3(rampRailX, baseY + 0.36, z),
materials.rail
);
});
beamBetween(
new THREE.Vector3(rampRailX, 0.82, START_Z),
new THREE.Vector3(rampRailX, RISE + 0.82, END_Z),
0.12,
materials.rail
);
// Platform guardrails on the back and sides.
[-2.8, -1.4, 0, 1.4, 2.8].forEach((x) => {
addBox(
new THREE.Vector3(0.12, 0.72, 0.12),
new THREE.Vector3(x, RISE + 0.36, -3.28),
materials.rail
);
});
beamBetween(
new THREE.Vector3(-2.86, RISE + 0.74, -3.28),
new THREE.Vector3(2.86, RISE + 0.74, -3.28),
0.12,
materials.rail
);
[-2.88, 2.88].forEach((x) => {
[-3.25, -2.1, -1.08].forEach((z) => {
addBox(
new THREE.Vector3(0.12, 0.72, 0.12),
new THREE.Vector3(x, RISE + 0.36, z),
materials.rail
);
});
beamBetween(
new THREE.Vector3(x, RISE + 0.74, -3.28),
new THREE.Vector3(x, RISE + 0.74, -1.05),
0.12,
materials.rail
);
});
// -------------------------------------------------------------------------
// Common endpoint markers
// -------------------------------------------------------------------------
[stairX, rampX].forEach((x) => {
addBox(
new THREE.Vector3(0.18, 0.18, 0.18),
new THREE.Vector3(x, 0.09, START_Z - 0.09),
materials.endpoint
);
addBox(
new THREE.Vector3(0.18, 0.18, 0.18),
new THREE.Vector3(x, RISE + 0.09, END_Z + 0.09),
materials.endpoint
);
});
// -------------------------------------------------------------------------
// Dimension guides: relative scene geometry, not a regulatory claim
// -------------------------------------------------------------------------
// Horizontal distance between common route endpoint planes.
dashedGuide([
new THREE.Vector3(0, 0.035, START_Z),
new THREE.Vector3(0, 0.035, END_Z)
]);
solidGuide([
new THREE.Vector3(-0.28, 0.035, START_Z),
new THREE.Vector3(0.28, 0.035, START_Z)
]);
solidGuide([
new THREE.Vector3(-0.28, 0.035, END_Z),
new THREE.Vector3(0.28, 0.035, END_Z)
]);
// Vertical rise at the platform end.
dashedGuide([
new THREE.Vector3(-3.52, 0, -0.78),
new THREE.Vector3(-3.52, RISE, -0.78)
]);
solidGuide([
new THREE.Vector3(-3.78, 0, -0.78),
new THREE.Vector3(-3.26, 0, -0.78)
]);
solidGuide([
new THREE.Vector3(-3.78, RISE, -0.78),
new THREE.Vector3(-3.26, RISE, -0.78)
]);
const riseLabel = makeLabel(
"RISE Δh",
"2.4 scene units",
"#e86f51",
2.65
);
riseLabel.position.set(-3.85, 1.2, -0.72);
const runLabel = makeLabel(
"HORIZONTAL L",
"6.0 scene units",
"#258b76",
3.05
);
runLabel.position.set(0, 0.28, 2.0);
const startLabel = makeLabel(
"SHARED START",
"lower landing · level 0",
"#258b76",
2.55
);
startLabel.position.set(0, 0.38, 6.35);
const finishLabel = makeLabel(
"SHARED FINISH",
"upper platform · level 2.4",
"#258b76",
2.75
);
finishLabel.position.set(0, 2.88, -3.52);
// -------------------------------------------------------------------------
// Small voxel landscaping
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
addBox(
new THREE.Vector3(0.35 * scale, 0.85 * scale, 0.35 * scale),
new THREE.Vector3(x, GROUND_TOP + 0.425 * scale, z),
materials.trunk
);
addBox(
new THREE.Vector3(0.9 * scale, 0.85 * scale, 0.9 * scale),
new THREE.Vector3(x, GROUND_TOP + 1.05 * scale, z),
materials.leafA
);
addBox(
new THREE.Vector3(0.75 * scale, 0.7 * scale, 0.75 * scale),
new THREE.Vector3(
x + 0.35 * scale,
GROUND_TOP + 1.55 * scale,
z - 0.08 * scale
),
materials.leafB
);
}
addTree(-5.1, 4.65, 0.9);
addTree(5.05, -4.75, 0.95);
addTree(-5.35, -3.85, 0.72);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel/pinch zoom, keyboard, reset
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.75, 1.15),
yaw: 0.52,
pitch: 0.82,
radius: 14.5
};
const initialControls = {
yaw: controls.yaw,
pitch: controls.pitch,
radius: controls.radius
};
const pointers = new Map();
let dragging = false;
let lastX = 0;
let lastY = 0;
let lastPinchDistance = 0;
function clampControls() {
controls.pitch = THREE.MathUtils.clamp(
controls.pitch,
0.35,
1.3
);
controls.radius = THREE.MathUtils.clamp(
controls.radius,
8.5,
25
);
}
function updateCamera() {
clampControls();
const portraitFactor = camera.aspect < 0.8
? 1.45
: camera.aspect < 1.15
? 1.18
: 1;
const radius = controls.radius * portraitFactor;
const sinPitch = Math.sin(controls.pitch);
camera.position.set(
controls.target.x +
radius * sinPitch * Math.sin(controls.yaw),
controls.target.y +
radius * Math.cos(controls.pitch),
controls.target.z +
radius * sinPitch * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
controls.radius *= lastPinchDistance / distance;
updateCamera();
}
lastPinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
controls.yaw -= dx * 0.006;
controls.pitch += dy * 0.005;
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragging = false;
lastPinchDistance = 0;
renderer.domElement.classList.remove("dragging");
} else if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
controls.yaw = initialControls.yaw;
controls.pitch = initialControls.pitch;
controls.radius = initialControls.radius;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") controls.yaw += 0.08;
else if (key === "arrowright") controls.yaw -= 0.08;
else if (key === "arrowup") controls.pitch -= 0.06;
else if (key === "arrowdown") controls.pitch += 0.06;
else if (key === "+" || key === "=") controls.radius *= 0.9;
else if (key === "-") controls.radius *= 1.1;
else if (key === "r") {
resetCamera();
return;
} else {
return;
}
event.preventDefault();
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));
updateCamera();
});
updateCamera();
renderer.setAnimationLoop(() => renderer.render(scene, camera));
loading.remove();
</script>
</body>
</html>
```