Prompt specification
Build or customize the Three.js 3D scene "Cyclist passing a play and seating zone" 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: Cyclist passing a play and seating zone
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cyclist-passing-a-play-and-seating-zone-x2822
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Superkilen's public activity spaces in Copenhagen. Create a compact referenced park vignette with cyclist, seating, and play equipment. Keep the movement corridor distinct from stationary gathering and play areas. Voxel style.
Working Three.js Starter (cyclist-passing-a-play-and-seating-zone-x2822):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Superkilen — Public Activity Spaces</title>
<style>
:root {
--ink: #162521;
--paper: rgba(248, 246, 238, 0.92);
--red: #cf493c;
--sand: #d9c6a2;
--green: #708b55;
--dark: #303633;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-panel {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid rgba(22, 37, 33, 0.12);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(38, 57, 50, 0.12);
backdrop-filter: blur(10px);
}
.eyebrow {
margin: 0 0 8px;
color: #65736c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(32px, 5vw, 52px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.95;
}
.subtitle {
margin: 12px 0 17px;
color: #52625b;
font-size: 13px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 14px;
padding-top: 14px;
border-top: 1px solid rgba(22, 37, 33, 0.12);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 700;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border: 1px solid rgba(22, 37, 33, 0.18);
}
.swatch.red {
background: var(--red);
}
.swatch.sand {
background: var(--sand);
}
.swatch.green {
background: var(--green);
}
.swatch.dark {
background: var(--dark);
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 10px 9px 14px;
border: 1px solid rgba(22, 37, 33, 0.13);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 8px 28px rgba(38, 57, 50, 0.12);
pointer-events: auto;
}
.controls span {
color: #596861;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
button {
border: 0;
border-radius: 2px;
padding: 8px 11px;
background: var(--ink);
color: white;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: #34463f;
}
.caption {
left: 24px;
bottom: 24px;
max-width: 320px;
color: rgba(22, 37, 33, 0.72);
font-size: 10px;
font-weight: 650;
line-height: 1.45;
text-shadow: 0 1px 8px rgba(255, 255, 255, 0.85);
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 15px 16px;
}
.subtitle {
display: none;
}
.legend {
margin-top: 12px;
padding-top: 10px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span {
display: none;
}
.caption {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel vignette of Superkilen park"></div>
<header class="panel title-panel">
<p class="eyebrow">Copenhagen · Public Space Study</p>
<h1>Superkilen</h1>
<p class="subtitle">
A compact voxel interpretation of the park’s movement ribbon,
social terrace, and play pocket.
</p>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch red"></span>
Movement corridor
</div>
<div class="legend-item">
<span class="swatch sand"></span>
Gathering terrace
</div>
<div class="legend-item">
<span class="swatch green"></span>
Play area
</div>
<div class="legend-item">
<span class="swatch dark"></span>
Urban edge
</div>
</div>
</header>
<div class="panel caption">
Interpretive vignette, not a survey-accurate plan.<br />
Red, black, green, and pale civic surfaces reference Superkilen’s
distinctive spatial character.
</div>
<div class="panel controls">
<span>Drag to orbit · Shift-drag to pan · Wheel to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e3);
scene.fog = new THREE.Fog(0xdce8e3, 34, 72);
const camera = new THREE.OrthographicCamera(-15, 15, 9, -9, 0.1, 100);
const target = new THREE.Vector3(0, 0.2, 0);
let yaw = 0.72;
let pitch = 0.78;
let zoom = 1;
let frustumHeight = 18;
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x68736c, 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6df, 3.2);
sun.position.set(-10, 20, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9e7, 0.75);
fill.position.set(14, 8, -12);
scene.add(fill);
const root = new THREE.Group();
scene.add(root);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = root
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
typeof color === "number" || typeof color === "string"
? material(color)
: color
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(a, b, width, depth, color, parent = root) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const mesh = box(
width,
direction.length(),
depth,
color,
midpoint.x,
midpoint.y,
midpoint.z,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeLabel(text, x, y, z, accent = "#cf493c") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 140;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(22,37,33,0.92)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 15, canvas.height);
ctx.fillStyle = "#ffffff";
ctx.font = "800 34px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), 330, 72);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(5.4, 1.18, 1);
sprite.renderOrder = 20;
root.add(sprite);
return sprite;
}
// ------------------------------------------------------------
// Diorama base and urban edge
// ------------------------------------------------------------
box(26, 0.6, 16, 0x303633, 0, -0.36, 0);
box(26.25, 0.12, 16.25, 0x515b55, 0, -0.69, 0);
// A restrained architectural edge to suggest the dense city.
const facadeColors = [0xc5beb0, 0xb5c0ba, 0xd0c8b9];
for (let i = 0; i < 3; i++) {
const x = 3.8 + i * 3.25;
const height = 2.2 + (i % 2) * 0.8;
box(2.8, height, 1.45, facadeColors[i], x, height / 2 - 0.02, -7.1);
box(2.95, 0.16, 1.6, 0x8f9991, x, height + 0.03, -7.1);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 2; col++) {
box(
0.38,
0.47,
0.035,
0x52615c,
x - 0.66 + col * 1.32,
0.52 + row * 0.86,
-6.355
);
}
}
}
// ------------------------------------------------------------
// Movement corridor: a red, continuous diagonal ribbon
// ------------------------------------------------------------
const route = [
new THREE.Vector2(-11.1, 4.55),
new THREE.Vector2(-6.5, 3.45),
new THREE.Vector2(-2.0, 1.75),
new THREE.Vector2(2.1, -0.35),
new THREE.Vector2(6.1, -2.4),
new THREE.Vector2(11.0, -4.1)
];
const routeLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
const dx = b.x - a.x;
const dz = b.y - a.y;
const length = Math.hypot(dx, dz);
routeLengths.push(length);
totalRouteLength += length;
const angle = Math.atan2(dz, dx);
const segment = box(
length + 0.38,
0.24,
3.35,
0xcf493c,
(a.x + b.x) / 2,
0.08,
(a.y + b.y) / 2
);
segment.rotation.y = -angle;
// Pale modular markers reinforce the corridor's direction.
for (let d = 0.75; d < length - 0.45; d += 1.65) {
const t = d / length;
const marker = box(
0.68,
0.035,
0.12,
0xf4dfc3,
THREE.MathUtils.lerp(a.x, b.x, t),
0.215,
THREE.MathUtils.lerp(a.y, b.y, t)
);
marker.rotation.y = -angle;
marker.castShadow = false;
}
}
makeLabel("Movement corridor", -0.1, 1.05, 2.75, "#cf493c");
// ------------------------------------------------------------
// Gathering terrace: pale, level, and separate from circulation
// ------------------------------------------------------------
const gatheringTop = 0.18;
box(7.5, 0.22, 4.6, 0xd9c6a2, 4.7, 0.07, 4.3);
box(7.65, 0.06, 4.75, 0xc4ad86, 4.7, 0.005, 4.3);
makeLabel("Gathering terrace", 4.8, 1.02, 6.2, "#d9c6a2");
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, gatheringTop, z);
group.rotation.y = rotation;
root.add(group);
// Wooden seat slats.
for (let i = 0; i < 3; i++) {
box(
2.05,
0.11,
0.14,
0xa9673d,
0,
0.53,
-0.19 + i * 0.19,
group
);
}
// Back slats.
for (let i = 0; i < 2; i++) {
box(
2.05,
0.13,
0.11,
0xa9673d,
0,
0.88 + i * 0.2,
-0.3,
group
);
}
box(0.13, 0.5, 0.55, 0x424b46, -0.72, 0.28, 0, group);
box(0.13, 0.5, 0.55, 0x424b46, 0.72, 0.28, 0, group);
box(0.1, 0.7, 0.1, 0x424b46, -0.72, 0.78, -0.3, group);
box(0.1, 0.7, 0.1, 0x424b46, 0.72, 0.78, -0.3, group);
return group;
}
makeBench(2.55, 4.8, 0);
makeBench(5.55, 5.65, 0);
makeBench(7.25, 3.65, Math.PI / 2);
function makePerson(x, z, shirt, skin = 0xc88f6b, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, gatheringTop, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
root.add(group);
box(0.4, 0.62, 0.27, shirt, 0, 1.08, 0, group);
box(0.31, 0.31, 0.31, skin, 0, 1.59, 0, group);
box(0.12, 0.66, 0.15, 0x35454b, -0.12, 0.43, 0, group);
box(0.12, 0.66, 0.15, 0x35454b, 0.12, 0.43, 0, group);
box(0.11, 0.55, 0.13, skin, -0.29, 1.02, 0, group);
box(0.11, 0.55, 0.13, skin, 0.29, 1.02, 0, group);
return group;
}
function makeSeatedPerson(x, z, shirt, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, gatheringTop, z);
group.rotation.y = rotation;
root.add(group);
box(0.42, 0.6, 0.28, shirt, 0, 0.98, 0, group);
box(0.31, 0.31, 0.31, 0xc88f6b, 0, 1.47, 0, group);
box(0.14, 0.16, 0.55, 0x35454b, -0.12, 0.64, 0.22, group);
box(0.14, 0.16, 0.55, 0x35454b, 0.12, 0.64, 0.22, group);
box(0.12, 0.48, 0.13, 0x35454b, -0.12, 0.35, 0.43, group);
box(0.12, 0.48, 0.13, 0x35454b, 0.12, 0.35, 0.43, group);
box(0.1, 0.47, 0.12, 0xc88f6b, -0.28, 0.91, 0, group);
box(0.1, 0.47, 0.12, 0xc88f6b, 0.28, 0.91, 0, group);
return group;
}
makeSeatedPerson(2.75, 4.8, 0x3f7182, 0);
makePerson(4.25, 3.42, 0xe0a63c, 0x9c674f, -0.6);
makePerson(5.8, 3.65, 0x675d86, 0xe2b18d, 0.8);
makePerson(6.95, 5.0, 0x3e806a, 0x8e5c44, -0.2, 0.94);
// Square café tables and stools.
function makeTable(x, z) {
const group = new THREE.Group();
group.position.set(x, gatheringTop, z);
root.add(group);
box(0.85, 0.1, 0.85, 0xeee3ce, 0, 0.88, 0, group);
box(0.14, 0.8, 0.14, 0x4c5650, 0, 0.46, 0, group);
box(0.55, 0.08, 0.55, 0x4c5650, 0, 0.1, 0, group);
for (const side of [-1, 1]) {
box(0.42, 0.1, 0.42, 0x4c5650, side * 0.75, 0.48, 0, group);
box(0.1, 0.45, 0.1, 0x4c5650, side * 0.75, 0.25, 0, group);
}
}
makeTable(4.05, 5.55);
makeTable(7.0, 2.75);
// ------------------------------------------------------------
// Play pocket: green surface, climbing blocks, slide and swings
// ------------------------------------------------------------
const playTop = 0.16;
box(8.2, 0.2, 5.2, 0x708b55, -4.7, 0.06, -4.25);
box(8.35, 0.05, 5.35, 0x60784b, -4.7, 0.005, -4.25);
makeLabel("Play pocket", -4.7, 1.05, -6.45, "#708b55");
// Swing frame.
const swingFrame = new THREE.Group();
swingFrame.position.set(-6.55, playTop, -4.45);
root.add(swingFrame);
box(0.18, 2.65, 0.18, 0xe3a930, -1.45, 1.325, 0, swingFrame);
box(0.18, 2.65, 0.18, 0xe3a930, 1.45, 1.325, 0, swingFrame);
box(3.15, 0.18, 0.2, 0xe3a930, 0, 2.73, 0, swingFrame);
const swingPivots = [];
function makeSwing(x, withChild) {
const pivot = new THREE.Group();
pivot.position.set(x, 2.64, 0);
swingFrame.add(pivot);
box(0.035, 1.18, 0.035, 0x48504c, -0.21, -0.59, 0, pivot);
box(0.035, 1.18, 0.035, 0x48504c, 0.21, -0.59, 0, pivot);
box(0.58, 0.1, 0.35, 0x3f7771, 0, -1.2, 0, pivot);
if (withChild) {
box(0.31, 0.48, 0.24, 0xcf493c, 0, -0.85, 0, pivot);
box(0.28, 0.28, 0.28, 0xb97855, 0, -0.47, 0, pivot);
box(0.1, 0.42, 0.11, 0x3e4f54, -0.08, -1.36, 0, pivot);
box(0.1, 0.42, 0.11, 0x3e4f54, 0.08, -1.36, 0, pivot);
}
swingPivots.push(pivot);
}
makeSwing(-0.65, true);
makeSwing(0.65, false);
// Slide and ladder.
const slide = new THREE.Group();
slide.position.set(-3.15, playTop, -4.45);
root.add(slide);
box(1.15, 1.1, 1.1, 0x3f7771, -0.85, 0.55, 0, slide);
box(1.35, 0.12, 1.25, 0xe3a930, -0.85, 1.12, 0, slide);
const ramp = box(
2.55,
0.12,
1.02,
0xe3a930,
0.72,
0.7,
0,
slide
);
ramp.rotation.z = -0.25;
box(0.1, 1.2, 0.1, 0x48504c, -1.55, 0.65, -0.47, slide);
box(0.1, 1.2, 0.1, 0x48504c, -1.55, 0.65, 0.47, slide);
for (let i = 0; i < 4; i++) {
box(
0.1,
0.1,
0.95,
0x48504c,
-1.35,
0.18 + i * 0.25,
0,
slide
);
}
// Climbing blocks.
box(0.75, 0.65, 0.75, 0xcf493c, -0.65, 0.325, 1.95, slide);
box(0.85, 0.45, 0.85, 0xe3a930, 0.05, 0.225, 1.9, slide);
box(0.68, 0.95, 0.68, 0x477c87, 0.7, 0.475, 1.85, slide);
// Children in the play zone.
box(0.3, 0.46, 0.22, 0xe0a63c, -1.55, playTop + 0.68, -3.05);
box(0.26, 0.26, 0.26, 0x9b634b, -1.55, playTop + 1.05, -3.05);
box(0.09, 0.38, 0.11, 0x3e4f54, -1.64, playTop + 0.19, -3.05);
box(0.09, 0.38, 0.11, 0x3e4f54, -1.46, playTop + 0.19, -3.05);
// ------------------------------------------------------------
// Voxel trees, lamps, and small urban details
// ------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.02, z);
group.scale.setScalar(scale);
root.add(group);
box(0.42, 2.6, 0.42, 0x76513b, 0, 1.3, 0, group);
box(1.8, 1.25, 1.7, 0x64875a, 0, 2.65, 0, group);
box(1.35, 1.1, 1.25, 0x77985f, -0.28, 3.25, 0.1, group);
box(1.15, 0.95, 1.2, 0x55764f, 0.38, 3.48, -0.12, group);
box(1.05, 0.9, 1.05, 0x87a46d, -0.5, 3.42, -0.35, group);
}
makeTree(-10.4, -5.4, 1.02);
makeTree(-10.4, 5.6, 0.9);
makeTree(9.6, 5.8, 0.86);
makeTree(10.6, -5.7, 0.76);
makeTree(-8.4, -7.0, 0.72);
function makeLamp(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, -0.02, z);
group.rotation.y = rotation;
root.add(group);
box(0.11, 3.0, 0.11, 0x38433f, 0, 1.5, 0, group);
box(0.5, 0.15, 0.5, 0x38433f, 0, 0.08, 0, group);
box(0.48, 0.16, 0.25, 0xf1d9a8, 0.18, 3.0, 0, group);
}
makeLamp(-8.35, 1.55, -0.55);
makeLamp(8.25, -0.25, -0.9);
makeLamp(0.0, 6.65, 0);
// Low block seating at the corridor edge, without extending into it.
box(1.7, 0.42, 0.48, 0x8e6d4e, -8.2, 0.2, 1.2);
box(1.7, 0.1, 0.55, 0xb88a5e, -8.2, 0.47, 1.2);
// ------------------------------------------------------------
// Voxel cyclist
// ------------------------------------------------------------
const cyclist = new THREE.Group();
root.add(cyclist);
const bike = new THREE.Group();
cyclist.add(bike);
const tireGeometry = new THREE.CylinderGeometry(0.43, 0.43, 0.13, 8);
tireGeometry.rotateX(Math.PI / 2);
const wheelContainers = [];
function makeWheel(x) {
const container = new THREE.Group();
container.position.set(x, 0.43, 0);
bike.add(container);
const tire = new THREE.Mesh(tireGeometry, material(0x26302f));
tire.castShadow = true;
container.add(tire);
box(0.055, 0.69, 0.08, 0x8f9992, 0, 0, 0, container);
box(0.69, 0.055, 0.08, 0x8f9992, 0, 0, 0, container);
wheelContainers.push(container);
return container;
}
makeWheel(-0.66);
makeWheel(0.66);
const frameColor = 0xf2c342;
beam([-0.66, 0.43, 0], [-0.08, 0.76, 0], 0.075, 0.09, frameColor, bike);
beam([-0.66, 0.43, 0], [-0.3, 1.2, 0], 0.075, 0.09, frameColor, bike);
beam([-0.3, 1.2, 0], [-0.08, 0.76, 0], 0.075, 0.09, frameColor, bike);
beam([-0.3, 1.2, 0], [0.5, 1.2, 0], 0.075, 0.09, frameColor, bike);
beam([0.5, 1.2, 0], [-0.08, 0.76, 0], 0.075, 0.09, frameColor, bike);
beam([0.5, 1.2, 0], [0.66, 0.43, 0], 0.075, 0.09, frameColor, bike);
beam([0.5, 1.2, 0], [0.58, 1.42, 0], 0.075, 0.09, frameColor, bike);
box(0.36, 0.11, 0.19, 0x39423e, -0.3, 1.3, 0, bike);
box(0.08, 0.08, 0.65, 0x39423e, 0.58, 1.43, 0, bike);
box(0.22, 0.12, 0.34, 0x39423e, -0.08, 0.7, 0, bike);
// Rider.
box(0.44, 0.62, 0.3, 0xcf493c, -0.14, 1.57, 0, bike);
box(0.31, 0.31, 0.31, 0xc98c68, -0.02, 2.05, 0, bike);
box(0.36, 0.16, 0.37, 0xf2efe2, -0.03, 2.2, 0, bike);
beam([-0.18, 1.73, 0.13], [0.48, 1.45, 0.25], 0.11, 0.11, 0xc98c68, bike);
beam([-0.18, 1.73, -0.13], [0.48, 1.45, -0.25], 0.11, 0.11, 0xc98c68, bike);
beam([-0.16, 1.3, 0.12], [-0.02, 0.82, 0.16], 0.14, 0.14, 0x394b50, bike);
beam([-0.16, 1.3, -0.12], [-0.02, 0.82, -0.16], 0.14, 0.14, 0x394b50, bike);
box(0.16, 0.1, 0.28, 0x27312f, -0.04, 0.68, 0.18, bike);
box(0.16, 0.1, 0.28, 0x27312f, -0.04, 0.68, -0.18, bike);
let travel = 0;
function routePointAt(distance) {
let remaining = ((distance % totalRouteLength) + totalRouteLength) %
totalRouteLength;
for (let i = 0; i < routeLengths.length; i++) {
if (remaining <= routeLengths[i]) {
const t = remaining / routeLengths[i];
const a = route[i];
const b = route[i + 1];
return {
position: new THREE.Vector3(
THREE.MathUtils.lerp(a.x, b.x, t),
0.24,
THREE.MathUtils.lerp(a.y, b.y, t)
),
tangent: new THREE.Vector3(b.x - a.x, 0, b.y - a.y).normalize()
};
}
remaining -= routeLengths[i];
}
return {
position: new THREE.Vector3(route[0].x, 0.24, route[0].y),
tangent: new THREE.Vector3(1, 0, 0)
};
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// ------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
function updateCamera() {
const radius = 30;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
frustumHeight = aspect < 1 ? 28 / aspect : 18;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
function resetView() {
target.set(0, 0.2, 0);
yaw = 0.72;
pitch = 0.78;
zoom = 1;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3(Math.cos(yaw), 0, -Math.sin(yaw));
const forward = new THREE.Vector3(-Math.sin(yaw), 0, -Math.cos(yaw));
const scale = frustumHeight / camera.zoom / 500;
target.addScaledVector(right, -dx * scale);
target.addScaledVector(forward, dy * scale);
} else {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.3, 1.28);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.8
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", resize);
resize();
updateCamera();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
travel += delta * 2.55;
const sample = routePointAt(travel);
cyclist.position.copy(sample.position);
cyclist.rotation.y = -Math.atan2(sample.tangent.z, sample.tangent.x);
for (const wheel of wheelContainers) {
wheel.rotation.z = -travel / 0.43;
}
if (swingPivots.length) {
swingPivots[0].rotation.x = Math.sin(elapsed * 1.55) * 0.24;
swingPivots[1].rotation.x = Math.sin(elapsed * 1.55 + Math.PI) * 0.2;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```