Prompt specification
Build or customize the Three.js 3D scene "Bench spacing route 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: Bench spacing route model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bench-spacing-route-model-x0461
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring public-route rest points. Place three benches along a miniature path with distance markers and shade patches; show unequal gaps clearly so the longest unsupported segment is easy to identify. Voxel style.
Working Three.js Starter (bench-spacing-route-model-x0461):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Public Route Rest Points</title>
<style>
:root {
--ink: #183a35;
--paper: #f7f1dc;
--teal: #2d6a60;
--shade: #6c8f89;
--gap: #dc654d;
--gold: #e5ad42;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8df;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
width: min(330px, calc(100vw - 48px));
padding: 16px 18px 15px;
background: rgba(247, 241, 220, 0.93);
border: 2px solid var(--ink);
box-shadow: 6px 6px 0 rgba(24, 58, 53, 0.13);
backdrop-filter: blur(8px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 0.96;
letter-spacing: -0.06em;
text-transform: uppercase;
}
h1 span {
display: block;
color: var(--teal);
}
.brand p {
margin: 12px 0 0;
font-size: 11px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
display: grid;
gap: 8px;
padding: 13px 15px;
background: rgba(247, 241, 220, 0.93);
border: 2px solid var(--ink);
box-shadow: 6px 6px 0 rgba(24, 58, 53, 0.13);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
white-space: nowrap;
}
.swatch {
width: 15px;
height: 15px;
border: 2px solid var(--ink);
}
.swatch.bench {
background: var(--teal);
}
.swatch.shade {
background:
linear-gradient(135deg, transparent 35%, rgba(24, 58, 53, 0.35) 35% 65%, transparent 65%),
#a9c1b7;
}
.swatch.gap {
background: var(--gap);
}
.stats {
position: absolute;
right: 24px;
bottom: 24px;
display: grid;
grid-template-columns: repeat(3, minmax(72px, 1fr));
min-width: 300px;
background: rgba(247, 241, 220, 0.94);
border: 2px solid var(--ink);
box-shadow: 6px 6px 0 rgba(24, 58, 53, 0.13);
backdrop-filter: blur(8px);
}
.stat {
padding: 12px 14px;
border-right: 1px solid rgba(24, 58, 53, 0.28);
}
.stat:last-child {
border-right: 0;
background: rgba(220, 101, 77, 0.13);
}
.stat span {
display: block;
margin-bottom: 5px;
color: #55716b;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.stat strong {
font-size: 18px;
letter-spacing: -0.04em;
}
.stat:last-child strong {
color: #a64031;
}
.controls {
position: absolute;
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 11px;
background: rgba(247, 241, 220, 0.9);
border: 2px solid var(--ink);
box-shadow: 4px 4px 0 rgba(24, 58, 53, 0.12);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
}
.controls kbd {
padding: 3px 5px;
background: var(--ink);
color: var(--paper);
font: inherit;
}
#reset {
pointer-events: auto;
border: 0;
padding: 5px 7px;
background: var(--gold);
color: var(--ink);
font: inherit;
font-size: 9px;
font-weight: 900;
cursor: pointer;
}
#reset:hover {
background: #f3c45c;
}
.scene-label {
position: fixed;
left: 0;
top: 0;
z-index: 20;
pointer-events: none;
white-space: nowrap;
will-change: transform, opacity;
}
.scene-label.max-gap {
min-width: 220px;
padding: 9px 12px 10px;
background: rgba(255, 244, 231, 0.97);
border: 2px solid var(--gap);
box-shadow: 5px 5px 0 rgba(120, 51, 40, 0.2);
text-align: center;
transform: translate(-50%, -100%);
}
.scene-label.max-gap::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 2px;
height: 18px;
background: var(--gap);
}
.max-gap .kicker {
display: block;
margin-bottom: 5px;
color: #a64031;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
}
.max-gap .value {
display: flex;
align-items: baseline;
justify-content: center;
gap: 8px;
}
.max-gap b {
color: var(--gap);
font-size: 24px;
letter-spacing: -0.05em;
}
.max-gap .no-rest {
font-size: 10px;
font-weight: 900;
}
.scene-label.short-gap {
padding: 5px 8px;
background: rgba(247, 241, 220, 0.92);
border: 1px solid var(--teal);
color: var(--teal);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.bench-tag {
display: flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
background: rgba(24, 58, 53, 0.94);
border: 2px solid #f7f1dc;
color: #f7f1dc;
box-shadow: 3px 3px 0 rgba(24, 58, 53, 0.18);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
}
.bench-tag b {
display: grid;
width: 20px;
height: 20px;
place-items: center;
background: var(--gold);
color: var(--ink);
font-size: 10px;
}
.bench-tag i {
color: #9ed0c4;
font-style: normal;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
padding: 12px 13px;
}
.brand p {
display: none;
}
.legend {
top: 14px;
right: 14px;
padding: 9px;
}
.legend-item {
font-size: 8px;
}
.swatch {
width: 12px;
height: 12px;
}
.stats {
right: 14px;
bottom: 14px;
min-width: 0;
grid-template-columns: repeat(3, 1fr);
}
.stat {
padding: 9px;
}
.stat strong {
font-size: 14px;
}
.controls {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 28px);
font-size: 8px;
}
.control-copy {
display: none;
}
.scene-label.max-gap {
min-width: 170px;
padding: 7px 9px;
}
.max-gap b {
font-size: 19px;
}
}
</style>
</head>
<body>
<div class="hud">
<header class="brand">
<div class="eyebrow">Public Route 07 · Spacing Study</div>
<h1>Rest <span>Points</span></h1>
<p>Three public benches at 16 m, 34 m and 70 m. The coral section has no intermediate rest point.</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-item"><i class="swatch bench"></i> PUBLIC REST BENCH</div>
<div class="legend-item"><i class="swatch shade"></i> SHADE PATCH</div>
<div class="legend-item"><i class="swatch gap"></i> LONGEST UNSUPPORTED SEGMENT</div>
</aside>
<div class="stats" aria-label="Route statistics">
<div class="stat">
<span>ROUTE LENGTH</span>
<strong>88 m</strong>
</div>
<div class="stat">
<span>REST POINTS</span>
<strong>03</strong>
</div>
<div class="stat">
<span>MAX GAP</span>
<strong>36 m</strong>
</div>
</div>
<div class="controls">
<span class="control-copy">DRAG ORBIT · WHEEL ZOOM ·</span>
<kbd>R</kbd>
<button id="reset" type="button">RESET VIEW</button>
</div>
</div>
<div id="longLabel" class="scene-label max-gap">
<span class="kicker">LONGEST UNSUPPORTED SEGMENT</span>
<span class="value"><b>36 m</b><span class="no-rest">NO REST POINT</span></span>
</div>
<div id="shortLabel" class="scene-label short-gap">18 m BETWEEN BENCHES</div>
<div id="bench01" class="scene-label bench-tag"><b>01</b><span>REST</span><i>16 m</i></div>
<div id="bench02" class="scene-label bench-tag"><b>02</b><span>REST</span><i>34 m</i></div>
<div id="bench03" class="scene-label bench-tag"><b>03</b><span>REST</span><i>70 m</i></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8df);
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 model of public-route rest points");
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 300);
const target = new THREE.Vector3(0, 0, 0);
const orbit = {
theta: 0.72,
phi: 0.88,
zoom: 1
};
const initialOrbit = { ...orbit };
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(70, 116 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function updateCamera() {
const radius = 110;
const horizontal = Math.sin(orbit.phi) * radius;
camera.position.set(
target.x + horizontal * Math.sin(orbit.theta),
target.y + radius * Math.cos(orbit.phi),
target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf2f7ee, 0x66725c, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffeed0, 3.1);
sun.position.set(-30, 65, -42);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -68;
sun.shadow.camera.right = 68;
sun.shadow.camera.top = 50;
sun.shadow.camera.bottom = -50;
sun.shadow.camera.near = 5;
sun.shadow.camera.far = 170;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xddeeff, 1.15);
fill.position.set(35, 24, 48);
scene.add(fill);
const materialCache = new Map();
const geometryCache = 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 geometry(w, h, d) {
const key = `${w}|${h}|${d}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometryCache.get(key);
}
function box(w, h, d, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
geometry(w, h, d),
color && color.isMaterial ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 72491;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// Layered miniature base.
box(98, 2.1, 46, 0x536956, 0, -2.5, 0);
box(96, 1.4, 44, 0x829e70, 0, -0.75, 0);
box(89, 0.12, 6.6, 0xb9a77e, 0, 0, 0);
// The route is made from individual square pavers.
const paverGeometry = new THREE.BoxGeometry(1.08, 0.2, 1.08);
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94
});
const xCount = 78;
const zCount = 6;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
xCount * zCount
);
const dummy = new THREE.Object3D();
const normalColors = [0xd8c397, 0xe0cba2, 0xceb68a, 0xd9c196];
const gapColors = [0xd96b50, 0xe17959, 0xca5d48, 0xdf7656];
let paverIndex = 0;
for (let ix = 0; ix < xCount; ix++) {
const x = -44 + ix * 1.14;
for (let iz = 0; iz < zCount; iz++) {
const z = -2.85 + iz * 1.14;
dummy.position.set(x, 0.14, z);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
const palette = x >= -10 && x < 26 ? gapColors : normalColors;
const color = new THREE.Color(palette[Math.floor(random() * palette.length)]);
pavers.setColorAt(paverIndex, color);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) pavers.instanceColor.needsUpdate = true;
pavers.receiveShadow = true;
scene.add(pavers);
// Chunky route edging.
const borderGeometry = new THREE.BoxGeometry(1.65, 0.28, 0.42);
const borderMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 });
const borderCount = 90;
const borders = new THREE.InstancedMesh(borderGeometry, borderMaterial, borderCount);
let borderIndex = 0;
for (let x = -44; x <= 44; x += 2.25) {
for (const z of [-3.55, 3.55]) {
dummy.position.set(x, 0.18, z);
dummy.updateMatrix();
borders.setMatrixAt(borderIndex, dummy.matrix);
const color = new THREE.Color(
x >= -10 && x < 26
? (Math.floor(random() * 2) ? 0x9e493a : 0xb65340)
: (Math.floor(random() * 2) ? 0xa89a78 : 0xbbaa85)
);
borders.setColorAt(borderIndex, color);
borderIndex++;
}
}
borders.instanceMatrix.needsUpdate = true;
if (borders.instanceColor) borders.instanceColor.needsUpdate = true;
borders.castShadow = true;
borders.receiveShadow = true;
scene.add(borders);
// Pixel arrows reinforce the direction of the public route.
function addPixelArrow(x, z) {
const color = 0xe7b23e;
box(1.55, 0.08, 0.38, color, x - 0.65, 0.29, z);
box(0.38, 0.08, 0.38, color, x + 0.55, 0.29, z);
box(0.38, 0.08, 0.38, color, x + 0.15, 0.29, z - 0.48);
box(0.38, 0.08, 0.38, color, x + 0.15, 0.29, z + 0.48);
box(0.38, 0.08, 0.38, color, x - 0.25, 0.29, z - 0.94);
box(0.38, 0.08, 0.38, color, x - 0.25, 0.29, z + 0.94);
}
[-38, -20, 0, 20, 38].forEach((x) => addPixelArrow(x, 0));
function createBench(x, index) {
const group = new THREE.Group();
group.position.set(x, 0, -5.15);
scene.add(group);
box(6.2, 0.1, 3.1, 0xb7ae8f, x, 0.08, -5.15);
const wood = index % 2 === 0 ? 0x285d55 : 0x34766a;
const woodLight = index % 2 === 0 ? 0x39766a : 0x438678;
// Four legs.
for (const lx of [-1.85, 1.85]) {
for (const lz of [-0.48, 0.48]) {
box(0.18, 0.94, 0.18, 0x263b38, lx, 0.55, lz, group);
}
}
// Seat slats.
for (let i = 0; i < 5; i++) {
box(
4.8,
0.18,
0.28,
i % 2 ? wood : woodLight,
0,
1.08,
-0.62 + i * 0.31,
group
);
}
// Backrest slats and supports.
box(0.18, 1.65, 0.18, 0x263b38, -1.85, 1.65, -0.75, group);
box(0.18, 1.65, 0.18, 0x263b38, 1.85, 1.65, -0.75, group);
for (let i = 0; i < 3; i++) {
box(
4.8,
0.27,
0.18,
i % 2 ? wood : woodLight,
0,
1.48 + i * 0.38,
-0.76,
group
);
}
// Gold end caps make the public furniture easy to spot.
box(0.3, 0.2, 1.55, 0xe5ad42, -2.35, 1.07, 0, group);
box(0.3, 0.2, 1.55, 0xe5ad42, 2.35, 1.07, 0, group);
box(0.12, 0.12, 1.55, 0xe5ad42, -2.18, 1.43, 0, group);
box(0.12, 0.12, 1.55, 0xe5ad42, 2.18, 1.43, 0, group);
}
[-28, -10, 26].forEach((x, index) => createBench(x, index));
// Transparent, block-shaped shade patches over the route.
const shadeMaterial = new THREE.MeshBasicMaterial({
color: 0x284f53,
transparent: true,
opacity: 0.2,
depthWrite: false
});
for (const centerX of [-28, -10, 26]) {
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -1; iz <= 1; iz++) {
if (Math.abs(ix) === 2 && Math.abs(iz) === 1) continue;
const tile = box(
1.0,
0.025,
1.0,
shadeMaterial,
centerX + ix * 1.03,
0.252,
0.1 + iz * 1.03
);
tile.castShadow = false;
tile.receiveShadow = false;
tile.renderOrder = 1;
}
}
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.72, 4.2, 0.72, 0x6b5038, 0, 2.1, 0, group);
box(0.38, 1.7, 0.38, 0x76583d, 0.8, 3.4, 0, group);
box(0.38, 1.45, 0.38, 0x76583d, -0.75, 3.65, 0, group);
box(5.2, 3.0, 4.2, 0x4d7748, 0, 5.45, 0, group);
box(3.5, 2.1, 3.0, 0x628e52, 0.25, 7.75, -0.2, group);
box(2.4, 2.5, 3.0, 0x426c43, -2.25, 5.6, 0.25, group);
box(2.5, 2.4, 2.8, 0x568149, 2.2, 5.75, -0.3, group);
box(2.4, 1.7, 2.6, 0x6a9658, -0.85, 7.6, 0.65, group);
box(1.8, 1.4, 2.0, 0x3f6942, 1.25, 8.7, -0.45, group);
}
createTree(-31, -12.4, 1.0);
createTree(-13, -12.8, 0.92);
createTree(23.5, -12.6, 1.04);
// Small voxel shrubs and grass tufts.
for (let i = 0; i < 18; i++) {
const x = -43 + random() * 86;
const z = random() > 0.5
? -18 - random() * 2
: 10 + random() * 8;
if (Math.abs(x + 13) < 5 && z < -9) continue;
const size = 0.45 + random() * 0.55;
box(size, size * 0.7, size, 0x668650, x, size * 0.35, z);
box(size * 0.65, size * 0.65, size * 0.75, 0x78975b, x + 0.25, size * 0.65, z);
}
for (let i = 0; i < 85; i++) {
const x = -45 + random() * 90;
const z = -20 + random() * 40;
if (Math.abs(z) < 4.3 || (z < -3.5 && z > -8.5)) continue;
if (Math.abs(x + 13) < 5 && z < -9) continue;
const h = 0.14 + random() * 0.22;
box(0.14, h, 0.14, 0x6e8e55, x, h / 2 + 0.02, z);
if (random() > 0.45) {
box(0.13, h * 0.7, 0.13, 0x79985d, x + 0.18, h * 0.35 + 0.02, z + 0.1);
}
}
// Dimension brackets: 18 m versus the conspicuous 36 m segment.
function addDimension(x1, x2, z, color, dense = false) {
box(0.24, 1.0, 0.24, color, x1, 0.54, z);
box(0.24, 1.0, 0.24, color, x2, 0.54, z);
const spacing = dense ? 1.55 : 2.0;
for (let x = x1 + 0.8; x < x2 - 0.3; x += spacing) {
box(dense ? 1.05 : 0.72, 0.12, 0.24, color, x, 0.27, z);
}
}
addDimension(-28, -10, 4.35, 0x2d6a60, true);
addDimension(-10, 26, 4.35, 0xf1bb40, false);
// Extra hazard ticks in the unsupported section.
for (let x = -6; x < 25; x += 6) {
box(0.38, 0.16, 0.72, 0xf1bb40, x, 0.32, 3.15);
box(0.18, 0.17, 0.72, 0x293a35, x + 0.52, 0.32, 3.15);
}
function makeMarkerTexture(kicker, value, accent) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f7f1dc";
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = accent;
ctx.fillRect(16, 16, 480, 20);
ctx.strokeStyle = "#183a35";
ctx.lineWidth = 12;
ctx.strokeRect(10, 10, 492, 236);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#183a35";
ctx.font = "bold 39px monospace";
ctx.fillText(kicker, 256, 91);
ctx.font = "bold 78px monospace";
ctx.fillText(value, 256, 177);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.NearestFilter;
return texture;
}
function createMarker(x, kicker, value, accent) {
box(0.18, 2.65, 0.18, 0x263d39, x, 1.32, 6.15);
box(0.38, 0.18, 0.38, accent, x, 2.73, 6.15);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeMarkerTexture(kicker, value, accent),
toneMapped: false,
depthTest: true
})
);
sprite.position.set(x, 3.55, 6.15);
sprite.scale.set(4.65, 2.33, 1);
sprite.renderOrder = 3;
scene.add(sprite);
}
createMarker(-44, "ROUTE START", "0 m", "#e5ad42");
createMarker(-28, "BENCH 01", "16 m", "#2d6a60");
createMarker(-10, "BENCH 02", "34 m", "#2d6a60");
createMarker(26, "BENCH 03", "70 m", "#2d6a60");
createMarker(44, "ROUTE END", "88 m", "#e5ad42");
// Tiny voxel walkers provide scale without obscuring the spacing study.
function createHiker(x, z, shirtColor, backpackColor) {
const group = new THREE.Group();
group.position.set(x, 0.28, z);
scene.add(group);
box(0.22, 0.72, 0.25, 0x293b39, -0.19, 0.36, 0, group);
box(0.22, 0.72, 0.25, 0x293b39, 0.19, 0.36, 0, group);
box(0.28, 0.16, 0.38, 0xe2ad40, -0.19, 0.08, 0.04, group);
box(0.28, 0.16, 0.38, 0xe2ad40, 0.19, 0.08, 0.04, group);
box(0.66, 0.8, 0.38, shirtColor, 0, 1.08, 0, group);
box(0.22, 0.68, 0.24, shirtColor, -0.43, 1.05, 0, group);
box(0.22, 0.68, 0.24, shirtColor, 0.43, 1.05, 0, group);
box(0.46, 0.46, 0.44, 0xd9a67f, 0, 1.72, 0, group);
box(0.56, 0.16, 0.54, backpackColor, 0, 1.94, 0, group);
box(0.42, 0.62, 0.2, backpackColor, 0, 1.08, -0.27, group);
}
createHiker(-20.5, 0.9, 0xdb664e, 0x2c5e58);
createHiker(11.5, 0.6, 0xe1ad3f, 0x3b625c);
// HTML labels are projected from their positions in the 3D scene.
const labelAnchors = [
{
element: document.getElementById("longLabel"),
position: new THREE.Vector3(8, 2.15, 4.35)
},
{
element: document.getElementById("shortLabel"),
position: new THREE.Vector3(-19, 1.25, 4.35)
},
{
element: document.getElementById("bench01"),
position: new THREE.Vector3(-28, 4.05, -5.15)
},
{
element: document.getElementById("bench02"),
position: new THREE.Vector3(-10, 4.05, -5.15)
},
{
element: document.getElementById("bench03"),
position: new THREE.Vector3(26, 4.05, -5.15)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labelAnchors) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// Camera controls implemented directly with pointer, wheel, touch and key events.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - deltaY * 0.005, 0.42, 1.35);
previousX = event.clientX;
previousY = event.clientY;
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}, { passive: false });
function resetView() {
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.zoom = initialOrbit.zoom;
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
if (event.key === "ArrowLeft") orbit.theta -= 0.08;
if (event.key === "ArrowRight") orbit.theta += 0.08;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.42, orbit.phi - 0.06);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.35, orbit.phi + 0.06);
});
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```