Prompt specification
Build or customize the Three.js 3D scene "Add a midpoint rest stop" 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: Add a midpoint rest stop
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/add-a-midpoint-rest-stop-x0462
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an animation of a walking marker pausing at available benches; adding one midpoint bench divides a long route segment while preserving the original destination and path length. Low-poly.
Working Three.js Starter (add-a-midpoint-rest-stop-x0462):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Midpoint Bench — Low-Poly Route Animation</title>
<style>
:root {
--ink: #183a34;
--muted: #617b74;
--green: #257d69;
--green-light: #dff3e9;
--orange: #e58a3a;
--paper: rgba(253, 255, 250, 0.9);
--border: rgba(31, 87, 74, 0.14);
--shadow: 0 18px 48px rgba(31, 65, 58, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcebe7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid var(--border);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.top {
position: absolute;
top: 24px;
left: 24px;
right: 24px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 20px;
}
.brand {
max-width: 500px;
padding: 19px 22px;
border-radius: 20px;
}
.eyebrow {
display: block;
margin-bottom: 8px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.brand p {
max-width: 440px;
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.destination {
display: flex;
align-items: center;
gap: 12px;
min-width: 255px;
padding: 14px 17px;
border-radius: 17px;
}
.destination-icon {
display: grid;
width: 38px;
height: 38px;
flex: 0 0 auto;
place-items: center;
border-radius: 12px;
background: #fbe8d3;
color: #b76120;
font-size: 20px;
}
.destination small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.destination strong {
display: block;
font-size: 14px;
}
.destination span:last-child {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.bottom {
position: absolute;
right: 24px;
bottom: 24px;
left: 24px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
}
.controls {
width: min(650px, 100%);
padding: 17px;
border-radius: 20px;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 13px;
}
.metric {
min-width: 0;
padding: 11px 12px;
border: 1px solid rgba(31, 87, 74, 0.09);
border-radius: 13px;
background: rgba(234, 244, 237, 0.62);
}
.metric span {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.055em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric strong {
display: block;
margin: 3px 0 1px;
font-size: 23px;
letter-spacing: -0.035em;
}
.metric small {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric.flash {
animation: metricFlash 0.8s ease;
}
@keyframes metricFlash {
0%, 100% {
transform: scale(1);
background: rgba(234, 244, 237, 0.62);
}
40% {
transform: scale(1.035);
background: #d9f4e6;
}
}
.button-row {
display: flex;
gap: 8px;
}
button {
min-height: 43px;
padding: 0 16px;
border: 0;
border-radius: 12px;
cursor: pointer;
font-size: 13px;
font-weight: 750;
transition:
transform 0.16s ease,
background 0.16s ease,
opacity 0.16s ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(1px);
}
button:focus-visible {
outline: 3px solid rgba(37, 125, 105, 0.25);
outline-offset: 2px;
}
button.primary {
flex: 1;
background: var(--green);
color: white;
}
button.primary:hover:not(:disabled) {
background: #1d6d5b;
}
button.secondary {
background: #e7efe9;
color: var(--ink);
}
button:disabled {
cursor: default;
opacity: 0.62;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--orange);
}
.swatch.green {
background: #43a987;
}
.swatch.pale {
background: #d7c8ad;
}
.status {
width: min(355px, 100%);
padding: 17px 18px;
border-radius: 20px;
}
.status-label {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #49b38e;
box-shadow: 0 0 0 4px rgba(73, 179, 142, 0.14);
}
#statusTitle {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
#statusDetail {
min-height: 18px;
margin: 5px 0 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #e2e9e3;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #e58a3a, #49aa83);
transition: width 0.08s linear;
}
.hint {
position: absolute;
right: 26px;
bottom: 194px;
padding: 8px 11px;
border-radius: 10px;
background: rgba(24, 58, 52, 0.68);
color: rgba(255, 255, 255, 0.86);
font-size: 10px;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
}
#toast {
position: absolute;
top: 50%;
left: 50%;
max-width: min(430px, calc(100% - 40px));
padding: 13px 17px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 13px;
background: rgba(22, 60, 52, 0.91);
box-shadow: 0 14px 38px rgba(20, 50, 44, 0.2);
color: white;
font-size: 13px;
font-weight: 650;
line-height: 1.4;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -42%) scale(0.96);
transition:
opacity 0.25s ease,
transform 0.25s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
@media (max-width: 850px) {
.top {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
max-width: 430px;
padding: 15px 17px;
}
.brand p {
display: none;
}
.destination {
min-width: auto;
padding: 11px 13px;
}
.destination span:last-child {
display: none;
}
.bottom {
right: 12px;
bottom: 12px;
left: 12px;
flex-direction: column-reverse;
align-items: stretch;
}
.controls,
.status {
width: 100%;
}
.status {
padding: 13px 16px;
}
#statusDetail {
margin-bottom: 9px;
}
.hint {
display: none;
}
}
@media (max-width: 520px) {
.destination {
display: none;
}
.brand {
width: 100%;
}
.brand h1 {
font-size: 27px;
}
.metrics {
gap: 5px;
}
.metric {
padding: 9px 8px;
}
.metric strong {
font-size: 20px;
}
.button-row {
flex-wrap: wrap;
}
button.primary {
flex-basis: 100%;
}
button.secondary {
flex: 1;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="top">
<section class="brand panel">
<span class="eyebrow">Urban route study · Low-poly demo</span>
<h1>One bench.<br />Same journey.</h1>
<p>
Add a midpoint bench to divide the long segment. The walker pauses
again, while the destination and total route length remain unchanged.
</p>
</section>
<section class="destination panel" aria-label="Original destination">
<div class="destination-icon">⚑</div>
<div>
<small>Original destination</small>
<strong>Lakeside Library</strong>
<span>Entrance position retained</span>
</div>
</section>
</header>
<div class="bottom">
<section class="controls panel">
<div class="metrics">
<div class="metric" id="lengthMetric">
<span>Route length</span>
<strong id="lengthValue">26.9 m</strong>
<small>preserved</small>
</div>
<div class="metric">
<span>Route segments</span>
<strong id="segmentValue">2</strong>
<small id="segmentDetail">longest 18.0 m</small>
</div>
<div class="metric">
<span>Available benches</span>
<strong id="benchValue">1</strong>
<small>automatic pauses</small>
</div>
</div>
<div class="button-row">
<button class="primary" id="addButton">
+ Add midpoint bench
</button>
<button class="secondary" id="playButton">Pause walk</button>
<button class="secondary" id="replayButton">Replay</button>
</div>
<div class="legend">
<span><i class="swatch"></i> highlighted segment</span>
<span><i class="swatch green"></i> available bench</span>
<span><i class="swatch pale"></i> original route</span>
</div>
</section>
<section class="status panel">
<div class="status-label">
<i class="status-dot"></i>
Live route status
</div>
<h2 id="statusTitle">Preparing the route</h2>
<p id="statusDetail">The walker will pause at every available bench.</p>
<div
class="progress-track"
role="progressbar"
aria-label="Route progress"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="0"
>
<div id="progressFill"></div>
</div>
</section>
</div>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
<div id="toast" role="status"></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcebe7);
scene.fog = new THREE.Fog(0xdcebe7, 38, 76);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf5fff8, 0x668577, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.2);
sun.position.set(-14, 27, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
// -------------------------------------------------------------------------
// Route geometry: the midpoint lies exactly halfway along a straight segment
// -------------------------------------------------------------------------
const ORIGIN = new THREE.Vector3(-14, 0, 5);
const FIRST_BENCH = new THREE.Vector3(-6, 0, 0);
const MIDPOINT = new THREE.Vector3(3, 0, 0);
const DESTINATION = new THREE.Vector3(12, 0, 0);
const firstSegmentLength = ORIGIN.distanceTo(FIRST_BENCH);
const longSegmentLength = FIRST_BENCH.distanceTo(DESTINATION);
const routeLength = firstSegmentLength + longSegmentLength;
let midpointAdded = false;
let midpointReveal = 0;
let midpointBench = null;
function computeRouteData() {
const points = midpointAdded
? [ORIGIN, FIRST_BENCH, MIDPOINT, DESTINATION]
: [ORIGIN, FIRST_BENCH, DESTINATION];
const segments = [];
let cumulative = 0;
for (let i = 0; i < points.length - 1; i++) {
const from = points[i];
const to = points[i + 1];
const length = from.distanceTo(to);
segments.push({
from,
to,
length,
start: cumulative,
end: cumulative + length
});
cumulative += length;
}
const benches = [
{
name: "Garden bench",
point: FIRST_BENCH,
distance: firstSegmentLength
}
];
if (midpointAdded) {
benches.push({
name: "Midpoint bench",
point: MIDPOINT,
distance: firstSegmentLength + longSegmentLength / 2
});
}
return { points, segments, benches, length: cumulative };
}
let routeData = computeRouteData();
function pointAtDistance(distance) {
const segment =
routeData.segments.find((item) => distance <= item.end) ||
routeData.segments[routeData.segments.length - 1];
const local = THREE.MathUtils.clamp(
(distance - segment.start) / segment.length,
0,
1
);
const point = segment.from.clone().lerp(segment.to, local);
const direction = segment.to.clone().sub(segment.from).normalize();
return { point, direction };
}
// -------------------------------------------------------------------------
// Text labels made from canvas textures
// -------------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(text, options = {}) {
const {
color = "#183a34",
background = "rgba(255,255,255,0.92)",
border = "rgba(31,87,74,0.13)",
height = 0.72
} = options;
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
const font = "700 38px Inter, system-ui, sans-serif";
context.font = font;
const textWidth = context.measureText(text).width;
canvas.width = Math.ceil(textWidth + 58);
canvas.height = 88;
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(
context,
3,
3,
canvas.width - 6,
canvas.height - 6,
22
);
context.fillStyle = background;
context.fill();
context.strokeStyle = border;
context.lineWidth = 3;
context.stroke();
context.font = font;
context.fillStyle = color;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
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(
(canvas.width / canvas.height) * height,
height,
1
);
sprite.renderOrder = 20;
return sprite;
}
function disposeChildren(group) {
for (const child of [...group.children]) {
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
group.remove(child);
}
}
// -------------------------------------------------------------------------
// Ground and low-poly environment
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xb9d5bc,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.18;
ground.receiveShadow = true;
scene.add(ground);
const park = new THREE.Mesh(
new THREE.CircleGeometry(25, 18),
new THREE.MeshStandardMaterial({
color: 0x91b995,
roughness: 1,
flatShading: true
})
);
park.rotation.x = -Math.PI / 2;
park.position.set(-1, -0.12, -1);
park.receiveShadow = true;
scene.add(park);
const patchColors = [0x9fc49c, 0x87af8e, 0xa9cba4];
const patchPositions = [
[-19, -7, 5.4],
[-10, 9, 4.1],
[3, 10, 5.8],
[17, 7, 4.6],
[20, -8, 5.1],
[-18, 10, 3.8],
[6, -12, 4.4]
];
patchPositions.forEach(([x, z, radius], index) => {
const patch = new THREE.Mesh(
new THREE.CircleGeometry(radius, 7),
new THREE.MeshStandardMaterial({
color: patchColors[index % patchColors.length],
roughness: 1,
flatShading: true
})
);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = index * 0.7;
patch.position.set(x, -0.095, z);
patch.receiveShadow = true;
scene.add(patch);
});
function makeTree(x, z, scale = 1, crownColor = 0x3f8060) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.27, 1.9, 5),
new THREE.MeshStandardMaterial({
color: 0x77543c,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.95;
trunk.castShadow = true;
group.add(trunk);
const crownMaterial = new THREE.MeshStandardMaterial({
color: crownColor,
roughness: 0.95,
flatShading: true
});
const lower = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25, 0),
crownMaterial
);
lower.scale.set(1, 1.08, 1);
lower.position.y = 2.35;
lower.castShadow = true;
group.add(lower);
const upper = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.88, 0),
crownMaterial
);
upper.position.set(0.15, 3.13, -0.05);
upper.castShadow = true;
group.add(upper);
scene.add(group);
}
const trees = [
[-23, -8, 1.1, 0x39765a],
[-21, 2, 0.85, 0x4d8d65],
[-16, -11, 1.2, 0x427e5e],
[-10, -9, 0.95, 0x5b976d],
[-3, -12, 1.15, 0x3f7e5c],
[8, -12, 1.05, 0x4a8961],
[20, -11, 1.2, 0x367357],
[23, 1, 0.9, 0x55916a],
[19, 11, 1.1, 0x3e7a59],
[7, 13, 0.85, 0x5b976d],
[-7, 13, 1.1, 0x47855f],
[-20, 12, 0.85, 0x4a8961]
];
trees.forEach((args) => makeTree(...args));
function makeRock(x, z, scale = 1) {
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.65, 0),
new THREE.MeshStandardMaterial({
color: 0x8fa19a,
roughness: 1,
flatShading: true
})
);
rock.position.set(x, 0.18, z);
rock.scale.set(scale * 1.3, scale * 0.65, scale);
rock.rotation.set(0.2, x, 0.15);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
[
[-18, -4, 0.7],
[-12, -6, 0.45],
[-7, 8, 0.5],
[0, -8, 0.65],
[8, 8, 0.48],
[16, -8, 0.75],
[20, 4, 0.55],
[-3, 11, 0.45]
].forEach((args) => makeRock(...args));
// Library pavilion at the unchanged destination.
const library = new THREE.Group();
library.position.set(14.3, 0, -4.5);
const walls = new THREE.Mesh(
new THREE.BoxGeometry(5.4, 2.5, 3.2),
new THREE.MeshStandardMaterial({
color: 0xeadfc7,
roughness: 0.92,
flatShading: true
})
);
walls.position.y = 1.25;
walls.castShadow = true;
walls.receiveShadow = true;
library.add(walls);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(4.1, 1.65, 4),
new THREE.MeshStandardMaterial({
color: 0x52756b,
roughness: 0.9,
flatShading: true
})
);
roof.rotation.y = Math.PI / 4;
roof.position.y = 3.25;
roof.castShadow = true;
library.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 1.65, 0.12),
new THREE.MeshStandardMaterial({
color: 0x315f55,
roughness: 0.8
})
);
door.position.set(-0.65, 0.83, 1.65);
library.add(door);
[-1.7, 1.7].forEach((x) => {
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.8, 0.12),
new THREE.MeshStandardMaterial({
color: 0x9fd6d0,
emissive: 0x315f55,
emissiveIntensity: 0.12,
roughness: 0.35
})
);
windowMesh.position.set(x, 1.35, 1.66);
library.add(windowMesh);
});
scene.add(library);
const libraryLabel = makeLabel("LAKESIDE LIBRARY", {
color: "#244c43",
background: "rgba(255,250,235,0.94)",
height: 0.68
});
libraryLabel.position.set(14.2, 4.65, -4.5);
scene.add(libraryLabel);
// Destination flag at the exact route endpoint.
const destinationGroup = new THREE.Group();
destinationGroup.position.copy(DESTINATION);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 2.7, 6),
new THREE.MeshStandardMaterial({
color: 0x52675f,
roughness: 0.8
})
);
pole.position.y = 1.35;
pole.castShadow = true;
destinationGroup.add(pole);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 2.55, 0, 1.25, 2.25, 0, 0, 1.85, 0],
3
)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: 0xe58a3a,
side: THREE.DoubleSide,
roughness: 0.8,
flatShading: true
})
);
flag.castShadow = true;
destinationGroup.add(flag);
const destinationRing = new THREE.Mesh(
new THREE.TorusGeometry(0.53, 0.055, 4, 18),
new THREE.MeshStandardMaterial({
color: 0xe58a3a,
emissive: 0xe58a3a,
emissiveIntensity: 0.12
})
);
destinationRing.rotation.x = Math.PI / 2;
destinationRing.position.y = 0.13;
destinationGroup.add(destinationRing);
scene.add(destinationGroup);
const destinationLabel = makeLabel("ORIGINAL DESTINATION", {
color: "#9c541f",
background: "rgba(255,244,225,0.95)",
height: 0.58
});
destinationLabel.position.set(12, 3.25, 0);
scene.add(destinationLabel);
// -------------------------------------------------------------------------
// Benches
// -------------------------------------------------------------------------
function makeBench(position, name) {
const group = new THREE.Group();
group.position.copy(position);
const wood = new THREE.MeshStandardMaterial({
color: 0x9b6844,
roughness: 0.88,
flatShading: true
});
const metal = new THREE.MeshStandardMaterial({
color: 0x315e55,
roughness: 0.65,
metalness: 0.25,
flatShading: true
});
[-0.24, 0, 0.24].forEach((z) => {
const slat = new THREE.Mesh(
new THREE.BoxGeometry(1.95, 0.13, 0.18),
wood
);
slat.position.set(0, 0.57, z);
slat.castShadow = true;
slat.receiveShadow = true;
group.add(slat);
});
[0.78, 1.02].forEach((y) => {
const back = new THREE.Mesh(
new THREE.BoxGeometry(1.95, 0.15, 0.12),
wood
);
back.position.set(0, y, -0.34);
back.castShadow = true;
group.add(back);
});
[-0.67, 0.67].forEach((x) => {
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.58, 0.56),
metal
);
support.position.set(x, 0.29, -0.04);
support.castShadow = true;
group.add(support);
const backSupport = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.72, 0.09),
metal
);
backSupport.position.set(x, 0.72, -0.36);
backSupport.castShadow = true;
group.add(backSupport);
});
const availableRing = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.045, 4, 20),
new THREE.MeshStandardMaterial({
color: 0x49b58b,
emissive: 0x49b58b,
emissiveIntensity: 0.17
})
);
availableRing.rotation.x = Math.PI / 2;
availableRing.position.y = 0.09;
group.add(availableRing);
const availableDot = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.11, 0),
new THREE.MeshStandardMaterial({
color: 0x64d4a7,
emissive: 0x49b58b,
emissiveIntensity: 0.25
})
);
availableDot.position.set(1.08, 1.03, -0.32);
group.add(availableDot);
const label = makeLabel(name.toUpperCase(), {
color: "#276653",
background: "rgba(238,251,242,0.95)",
height: 0.56
});
label.position.set(0, 1.75, 0);
group.add(label);
group.userData.ring = availableRing;
scene.add(group);
return group;
}
// Benches sit just beside the path, leaving the route itself unchanged.
const gardenBench = makeBench(
new THREE.Vector3(FIRST_BENCH.x, 0, FIRST_BENCH.z - 1.25),
"Garden bench"
);
// -------------------------------------------------------------------------
// Route rendering
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
function createRouteSegment(from, to, material, width = 0.78) {
const length = from.distanceTo(to);
const midpoint = from.clone().add(to).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.075, width),
material
);
mesh.position.set(midpoint.x, 0.025, midpoint.z);
mesh.rotation.y = -Math.atan2(to.z - from.z, to.x - from.x);
mesh.receiveShadow = true;
routeGroup.add(mesh);
return mesh;
}
function buildRouteVisuals() {
disposeChildren(routeGroup);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xd7c8ad,
roughness: 0.96,
flatShading: true
});
const highlightMaterial = new THREE.MeshStandardMaterial({
color: midpointAdded ? 0x58ad89 : 0xe59a55,
emissive: midpointAdded ? 0x246e56 : 0x8a4518,
emissiveIntensity: 0.08,
roughness: 0.9,
flatShading: true
});
routeData.segments.forEach((segment, index) => {
createRouteSegment(segment.from, segment.to, baseMaterial);
if (index === 1 || (midpointAdded && index === 2)) {
createRouteSegment(
segment.from,
segment.to,
highlightMaterial,
0.93
);
}
});
routeData.points.forEach((point, index) => {
if (index === 0 || index === routeData.points.length - 1) return;
const node = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.055, 12),
new THREE.MeshStandardMaterial({
color: midpointAdded ? 0x4aa17f : 0xf2e4cb,
roughness: 0.85
})
);
node.position.set(point.x, 0.115, point.z);
routeGroup.add(node);
});
if (midpointAdded) {
const splitGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(MIDPOINT.x, 0.17, -0.56),
new THREE.Vector3(MIDPOINT.x, 0.17, 0.56)
]);
const splitLine = new THREE.Line(
splitGeometry,
new THREE.LineBasicMaterial({ color: 0x2b8b6c })
);
routeGroup.add(splitLine);
const midpointBadge = makeLabel("SPLIT POINT", {
color: "#236b57",
background: "rgba(225,248,236,0.96)",
height: 0.52
});
midpointBadge.position.set(MIDPOINT.x, 2.55, 0);
routeGroup.add(midpointBadge);
const firstMeasure = makeLabel(`${(longSegmentLength / 2).toFixed(1)} m`, {
color: "#27705a",
background: "rgba(237,250,241,0.95)",
height: 0.58
});
firstMeasure.position.set(
(FIRST_BENCH.x + MIDPOINT.x) / 2,
0.98,
0
);
routeGroup.add(firstMeasure);
const secondMeasure = makeLabel(`${(longSegmentLength / 2).toFixed(1)} m`, {
color: "#27705a",
background: "rgba(237,250,241,0.95)",
height: 0.58
});
secondMeasure.position.set(
(MIDPOINT.x + DESTINATION.x) / 2,
0.98,
0
);
routeGroup.add(secondMeasure);
} else {
const measure = makeLabel(`${longSegmentLength.toFixed(1)} m segment`, {
color: "#a45b21",
background: "rgba(255,244,227,0.96)",
height: 0.62
});
measure.position.set(
(FIRST_BENCH.x + DESTINATION.x) / 2,
1.1,
0
);
routeGroup.add(measure);
}
}
buildRouteVisuals();
// -------------------------------------------------------------------------
// Low-poly walking marker
// -------------------------------------------------------------------------
const marker = new THREE.Group();
marker.position.copy(ORIGIN);
marker.position.y = 0.06;
const markerBody = new THREE.Group();
marker.add(markerBody);
const jacket = new THREE.MeshStandardMaterial({
color: 0xe7773c,
roughness: 0.86,
flatShading: true
});
const trousers = new THREE.MeshStandardMaterial({
color: 0x285d66,
roughness: 0.92,
flatShading: true
});
const skin = new THREE.MeshStandardMaterial({
color: 0xd99b73,
roughness: 0.9,
flatShading: true
});
const shoes = new THREE.MeshStandardMaterial({
color: 0x253b37,
roughness: 1
});
function createLimb(x, y, material, width, length) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
const limb = new THREE.Mesh(
new THREE.BoxGeometry(width, length, width),
material
);
limb.position.y = -length / 2;
limb.castShadow = true;
pivot.add(limb);
markerBody.add(pivot);
return pivot;
}
const leftLeg = createLimb(-0.14, 0.72, trousers, 0.16, 0.55);
const rightLeg = createLimb(0.14, 0.72, trousers, 0.16, 0.55);
const leftShoe = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.12, 0.31),
shoes
);
leftShoe.position.set(0, -0.55, 0.055);
leftShoe.castShadow = true;
leftLeg.add(leftShoe);
const rightShoe = leftShoe.clone();
rightLeg.add(rightShoe);
const torso = new THREE.Mesh(
new THREE.BoxGeometry(0.53, 0.68, 0.31),
jacket
);
torso.position.y = 1.13;
torso.castShadow = true;
markerBody.add(torso);
const backpack = new THREE.Mesh(
new THREE.BoxGeometry(0.39, 0.43, 0.18),
new THREE.MeshStandardMaterial({
color: 0x315f55,
roughness: 0.9,
flatShading: true
})
);
backpack.position.set(0, 1.18, -0.235);
backpack.castShadow = true;
markerBody.add(backpack);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.235, 0),
skin
);
head.position.y = 1.69;
head.castShadow = true;
markerBody.add(head);
const hair = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.245, 0),
new THREE.MeshStandardMaterial({
color: 0x3b342f,
roughness: 1,
flatShading: true
})
);
hair.scale.set(1, 0.45, 1);
hair.position.set(0, 1.83, -0.025);
markerBody.add(hair);
const leftArm = createLimb(-0.36, 1.37, jacket, 0.13, 0.5);
const rightArm = createLimb(0.36, 1.37, jacket, 0.13, 0.5);
const pauseRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.035, 4, 18),
new THREE.MeshBasicMaterial({
color: 0xf0a454,
transparent: true,
opacity: 0.18
})
);
pauseRing.rotation.x = Math.PI / 2;
pauseRing.position.y = 0.1;
marker.add(pauseRing);
scene.add(marker);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const PAUSE_DURATION = 1.8;
const WALK_SPEED = 2.35;
let distance = 0;
let running = true;
let phase = "walk";
let pauseElapsed = 0;
let currentBenchIndex = 0;
let startDelay = 0.7;
let walkPhase = 0;
const lengthValue = document.querySelector("#lengthValue");
const segmentValue = document.querySelector("#segmentValue");
const segmentDetail = document.querySelector("#segmentDetail");
const benchValue = document.querySelector("#benchValue");
const addButton = document.querySelector("#addButton");
const playButton = document.querySelector("#playButton");
const replayButton = document.querySelector("#replayButton");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const progressFill = document.querySelector("#progressFill");
const progressTrack = document.querySelector(".progress-track");
const lengthMetric = document.querySelector("#lengthMetric");
const toast = document.querySelector("#toast");
lengthValue.textContent = `${routeLength.toFixed(1)} m`;
let toastTimer = null;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
}
function updateStats() {
segmentValue.textContent = midpointAdded ? "3" : "2";
segmentDetail.textContent = midpointAdded
? "longest 9.0 m"
: `longest ${longSegmentLength.toFixed(1)} m`;
benchValue.textContent = midpointAdded ? "2" : "1";
addButton.disabled = midpointAdded;
addButton.textContent = midpointAdded
? "✓ Midpoint bench added"
: "+ Add midpoint bench";
}
function resetWalk() {
distance = 0;
running = true;
phase = "walk";
pauseElapsed = 0;
currentBenchIndex = 0;
startDelay = 0.6;
walkPhase = 0;
}
function addMidpointBench() {
if (midpointAdded) return;
const midpointDistance =
firstSegmentLength + longSegmentLength / 2;
midpointAdded = true;
routeData = computeRouteData();
buildRouteVisuals();
midpointBench = makeBench(
new THREE.Vector3(MIDPOINT.x, 0, MIDPOINT.z - 1.25),
"Midpoint bench"
);
midpointBench.scale.setScalar(0.001);
midpointReveal = 0;
updateStats();
lengthMetric.classList.remove("flash");
void lengthMetric.offsetWidth;
lengthMetric.classList.add("flash");
showToast(
`Midpoint bench added · route length remains ${routeLength.toFixed(1)} m`
);
// If the walker already passed the insertion point, replay to show
// the new pause without changing the original geometry.
if (distance > midpointDistance + 0.05) {
resetWalk();
showToast(
`Midpoint bench added · replaying the same ${routeLength.toFixed(1)} m route`
);
}
}
function updateWalk(delta) {
if (!running || phase === "arrived") return;
if (startDelay > 0) {
startDelay = Math.max(0, startDelay - delta);
return;
}
if (phase === "pause") {
pauseElapsed += delta;
if (pauseElapsed >= PAUSE_DURATION) {
currentBenchIndex++;
phase = "walk";
pauseElapsed = 0;
}
return;
}
const nextBench = routeData.benches[currentBenchIndex];
const targetDistance = nextBench
? nextBench.distance
: routeData.length;
distance = Math.min(
targetDistance,
distance + WALK_SPEED * delta
);
if (distance >= targetDistance - 0.0001) {
distance = targetDistance;
if (nextBench) {
phase = "pause";
pauseElapsed = 0;
} else {
phase = "arrived";
running = false;
}
}
}
function updateMarker(delta, direction) {
const isPaused = phase === "pause";
const isWalking = phase === "walk" && running && startDelay <= 0;
if (isWalking) {
walkPhase += delta * 9.5;
}
const swing = isWalking ? Math.sin(walkPhase) * 0.58 : 0;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = -swing;
leftArm.rotation.x = -swing * 0.75;
rightArm.rotation.x = swing * 0.75;
markerBody.position.y = isWalking
? Math.abs(Math.sin(walkPhase)) * 0.045
: 0;
const targetYaw = isPaused
? Math.PI
: Math.atan2(direction.x, direction.z);
const yawDifference = Math.atan2(
Math.sin(targetYaw - marker.rotation.y),
Math.cos(targetYaw - marker.rotation.y)
);
marker.rotation.y += yawDifference * Math.min(1, delta * 8);
pauseRing.material.opacity = isPaused
? 0.62 + Math.sin(performance.now() * 0.006) * 0.17
: 0.12;
const ringScale = isPaused
? 1 + Math.sin(performance.now() * 0.005) * 0.13
: 1;
pauseRing.scale.setScalar(ringScale);
}
function updateStatus() {
const nextBench = routeData.benches[currentBenchIndex];
if (phase === "arrived") {
statusTitle.textContent = "Arrived at Lakeside Library";
statusDetail.textContent =
`Original destination preserved · ${routeLength.toFixed(1)} m total`;
} else if (!running) {
statusTitle.textContent = "Walk paused";
statusDetail.textContent =
"Resume when ready, or replay the complete route.";
} else if (startDelay > 0) {
statusTitle.textContent = "Preparing the route";
statusDetail.textContent =
"The walker will pause at every available bench.";
} else if (phase === "pause" && nextBench) {
statusTitle.textContent = `Paused at ${nextBench.name.toLowerCase()}`;
statusDetail.textContent =
`Continuing in ${Math.max(0, PAUSE_DURATION - pauseElapsed).toFixed(1)} s`;
} else if (nextBench) {
const remaining = Math.max(0, nextBench.distance - distance);
statusTitle.textContent = `Walking toward ${nextBench.name.toLowerCase()}`;
statusDetail.textContent =
`${remaining.toFixed(1)} m until the next pause`;
} else {
const remaining = Math.max(0, routeData.length - distance);
statusTitle.textContent = "Walking to Lakeside Library";
statusDetail.textContent =
`${remaining.toFixed(1)} m to the original destination`;
}
playButton.textContent =
phase === "arrived"
? "Walk again"
: running
? "Pause walk"
: "Resume walk";
const progress = THREE.MathUtils.clamp(
(distance / routeData.length) * 100,
0,
100
);
progressFill.style.width = `${progress}%`;
progressTrack.setAttribute("aria-valuenow", progress.toFixed(0));
}
addButton.addEventListener("click", addMidpointBench);
playButton.addEventListener("click", () => {
if (phase === "arrived") {
resetWalk();
return;
}
running = !running;
});
replayButton.addEventListener("click", () => {
resetWalk();
showToast("Replaying the same route and destination");
});
// -------------------------------------------------------------------------
// Direct camera controls — no addons are used
// -------------------------------------------------------------------------
const orbit = {
radius: 35,
theta: 0.72,
phi: 0.86,
target: new THREE.Vector3(-1, 0, -0.5)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const canvas = renderer.domElement;
let dragging = false;
let dragMode = "orbit";
let previousX = 0;
let previousY = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.25,
1.35
);
} else {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const forward = orbit.target
.clone()
.sub(camera.position)
.setY(0)
.normalize();
const panScale = orbit.radius * 0.0013;
orbit.target.addScaledVector(right, -deltaX * panScale);
orbit.target.addScaledVector(forward, -deltaY * panScale);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
17,
55
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.radius = 35;
orbit.theta = 0.72;
orbit.phi = 0.86;
orbit.target.set(-1, 0, -0.5);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateWalk(delta);
const { point, direction } = pointAtDistance(distance);
marker.position.x = point.x;
marker.position.z = point.z;
marker.position.y = 0.06;
updateMarker(delta, direction);
if (midpointAdded && midpointBench) {
midpointReveal = Math.min(1, midpointReveal + delta * 2.4);
const t = midpointReveal;
const eased = 1 + 2.7 * Math.pow(t - 1, 3) + 1.7 * Math.pow(t - 1, 2);
midpointBench.scale.setScalar(Math.max(0.001, eased));
const ring = midpointBench.userData.ring;
const pulse = 1 + Math.sin(performance.now() * 0.005) * 0.08;
ring.scale.setScalar(pulse);
}
destinationRing.rotation.z = performance.now() * 0.00025;
gardenBench.userData.ring.rotation.z = performance.now() * 0.00012;
updateStatus();
renderer.render(scene, camera);
}
updateStats();
updateStatus();
animate();
</script>
</body>
</html>
```