Prompt specification
Build or customize the Three.js 3D scene "Connected sidewalk route puzzle" 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: Connected sidewalk route puzzle
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/connected-sidewalk-route-puzzle-x0472
Scene Description Prompt:
Find a continuous low-poly wheeled route across curb transitions and crossings, highlighting broken connections along failed shortcuts. Three.js from cdnjs, one HTML file.
Working Three.js Starter (connected-sidewalk-route-puzzle-x0472):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Accessible Route Finder</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(15, 23, 34, 0.92);
--border: rgba(255, 255, 255, 0.12);
--text: #eef5f7;
--muted: #9fb0ba;
--cyan: #32d8c4;
--amber: #ffbf5b;
--violet: #a58cff;
--red: #ff5b68;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfd8d5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(17, 29, 36, 0.28);
backdrop-filter: blur(16px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow .icon {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 8px;
background: rgba(50, 216, 196, 0.13);
font-size: 17px;
}
h1 {
margin: 9px 0 5px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.status {
padding: 13px 14px;
border: 1px solid rgba(50, 216, 196, 0.25);
border-radius: 12px;
background: rgba(50, 216, 196, 0.08);
}
.status.searching {
border-color: rgba(255, 191, 91, 0.3);
background: rgba(255, 191, 91, 0.08);
}
.status.error {
border-color: rgba(255, 91, 104, 0.35);
background: rgba(255, 91, 104, 0.09);
}
#statusTitle {
font-size: 14px;
font-weight: 800;
}
#statusDetail {
margin-top: 4px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 10px 0 14px;
}
.stat {
padding: 10px 8px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
text-align: center;
}
.stat strong {
display: block;
font-size: 18px;
}
.stat span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.button-row {
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 10px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.06);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.28);
background: rgba(255, 255, 255, 0.11);
transform: translateY(-1px);
}
button.primary {
flex: 1;
border-color: transparent;
background: var(--cyan);
color: #092522;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 18px 0 8px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.shortcut {
width: 100%;
margin: 7px 0;
padding: 11px;
text-align: left;
border-left: 3px solid var(--red);
background: rgba(255, 91, 104, 0.07);
}
.shortcut.repaired {
border-left-color: var(--cyan);
background: rgba(50, 216, 196, 0.07);
}
.shortcut-top {
display: flex;
justify-content: space-between;
gap: 10px;
font-size: 12px;
}
.shortcut-reason {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
font-weight: 500;
line-height: 1.35;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: var(--muted);
font-size: 12px;
cursor: pointer;
}
.toggle input {
accent-color: var(--cyan);
}
.legend {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px 13px;
max-width: min(430px, calc(100vw - 36px));
padding: 12px 14px;
border: 1px solid var(--border);
border-radius: 13px;
background: rgba(15, 23, 34, 0.86);
box-shadow: 0 10px 35px rgba(17, 29, 36, 0.2);
backdrop-filter: blur(12px);
color: #dbe5e8;
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 18px;
height: 4px;
border-radius: 10px;
background: var(--cyan);
}
.swatch.curb { background: var(--amber); }
.swatch.crossing { background: var(--violet); }
.swatch.broken {
height: 0;
border-top: 3px dashed var(--red);
background: none;
}
.hint {
position: fixed;
z-index: 10;
right: 18px;
top: 18px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(15, 23, 34, 0.78);
color: #d6e0e4;
font-size: 11px;
backdrop-filter: blur(10px);
}
#recenter {
position: fixed;
z-index: 11;
right: 18px;
top: 58px;
width: 38px;
height: 38px;
padding: 0;
border-radius: 50%;
background: rgba(15, 23, 34, 0.9);
font-size: 18px;
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: min(345px, calc(100vw - 20px));
max-height: 55vh;
padding: 16px;
}
h1 { font-size: 21px; }
.hint { display: none; }
#recenter { top: 10px; right: 10px; }
.legend {
right: 10px;
bottom: 10px;
left: 10px;
justify-content: center;
}
}
</style>
</head>
<body>
<section class="panel" aria-label="Accessible route planner">
<div class="eyebrow">
<span class="icon">♿</span>
Wheeled access network
</div>
<h1>Continuous route finder</h1>
<p class="intro">
Finds a connected route across curb transitions and marked crossings.
Broken shortcut links are excluded and highlighted in red.
</p>
<div id="status" class="status" aria-live="polite">
<div id="statusTitle">Preparing the route network…</div>
<div id="statusDetail">Checking curb cuts, crossing controls, and shortcut connections.</div>
</div>
<div class="stats">
<div class="stat"><strong id="distanceStat">—</strong><span>Route</span></div>
<div class="stat"><strong id="curbStat">—</strong><span>Curb cuts</span></div>
<div class="stat"><strong id="crossingStat">—</strong><span>Crossings</span></div>
</div>
<div class="button-row">
<button id="planButton" class="primary">Find continuous route</button>
<button id="resetButton" title="Restore broken shortcuts">Reset</button>
</div>
<div class="section-title">
Failed shortcuts <span>Click to repair and replan</span>
</div>
<div id="shortcutList"></div>
<label class="toggle">
<input id="networkToggle" type="checkbox" checked>
Show the complete access network
</label>
</section>
<div class="hint">Drag to orbit · right-drag to pan · scroll to zoom</div>
<button id="recenter" title="Recenter camera" aria-label="Recenter camera">⌖</button>
<div class="legend" aria-label="Map legend">
<div class="legend-item"><span class="swatch"></span>Sidewalk route</div>
<div class="legend-item"><span class="swatch curb"></span>Curb transition</div>
<div class="legend-item"><span class="swatch crossing"></span>Crossing</div>
<div class="legend-item"><span class="swatch broken"></span>Broken shortcut</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 statusBox = document.getElementById("status");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const distanceStat = document.getElementById("distanceStat");
const curbStat = document.getElementById("curbStat");
const crossingStat = document.getElementById("crossingStat");
const shortcutList = document.getElementById("shortcutList");
const networkToggle = document.getElementById("networkToggle");
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd6d3);
scene.fog = new THREE.Fog(0xcbd6d3, 45, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly city map with an accessible route and failed shortcut connections"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 20, -20, 0.1, 120);
const cameraTarget = new THREE.Vector3(0, 0, 0.5);
let cameraYaw = 0.72;
let cameraPitch = 0.78;
let cameraDistance = 44;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function recenter() {
cameraTarget.set(0, 0, 0.5);
cameraYaw = 0.72;
cameraPitch = 0.78;
camera.zoom = 1;
camera.updateProjectionMatrix();
updateCamera();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x71837f, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d2, 3.0);
sun.position.set(-18, 30, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0004;
scene.add(sun);
const mapGroup = new THREE.Group();
const networkGroup = new THREE.Group();
const shortcutGroup = new THREE.Group();
const routeGroup = new THREE.Group();
scene.add(mapGroup, networkGroup, shortcutGroup, routeGroup);
const mat = {
ground: new THREE.MeshStandardMaterial({
color: 0xb9c9c1, roughness: 1, flatShading: true
}),
road: new THREE.MeshStandardMaterial({
color: 0x34434b, roughness: 0.95, flatShading: true
}),
sidewalk: new THREE.MeshStandardMaterial({
color: 0xe7e2d6, roughness: 1, flatShading: true
}),
curb: new THREE.MeshStandardMaterial({
color: 0xf0ad4d, roughness: 0.8, flatShading: true
}),
marking: new THREE.MeshStandardMaterial({
color: 0xf8f5e8, roughness: 0.9, flatShading: true
}),
lane: new THREE.MeshStandardMaterial({
color: 0xe7c768, roughness: 0.9, flatShading: true
}),
route: new THREE.MeshStandardMaterial({
color: 0x25d6c2, emissive: 0x0b766c, emissiveIntensity: 0.8,
roughness: 0.45, flatShading: true
}),
routeUnder: new THREE.MeshBasicMaterial({
color: 0x16b9aa, transparent: true, opacity: 0.24, depthWrite: false
}),
routeCurb: new THREE.MeshStandardMaterial({
color: 0xffbd55, emissive: 0x7f4a0c, emissiveIntensity: 0.45,
roughness: 0.5, flatShading: true
}),
routeCrossing: new THREE.MeshStandardMaterial({
color: 0xa58cff, emissive: 0x3e287e, emissiveIntensity: 0.6,
roughness: 0.5, flatShading: true
}),
broken: new THREE.MeshBasicMaterial({ color: 0xff5664 }),
network: new THREE.LineBasicMaterial({
color: 0x6c7e82, transparent: true, opacity: 0.58
}),
graphNode: new THREE.MeshStandardMaterial({
color: 0x50666c, roughness: 0.9, flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x80634b, roughness: 1, flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x5e9275, roughness: 1, flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x76a783, roughness: 1, flatShading: true
}),
chair: new THREE.MeshStandardMaterial({
color: 0xf0a447, roughness: 0.7, flatShading: true
}),
wheel: new THREE.MeshStandardMaterial({
color: 0x1d2930, roughness: 0.8, flatShading: true
}),
skin: new THREE.MeshStandardMaterial({
color: 0xe6b68f, roughness: 0.9, flatShading: true
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x3f6f89, roughness: 0.9, flatShading: true
})
};
function box(w, h, d, x, y, z, material, parent = mapGroup) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius, radius, length, radialSegments, 1, false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
group.traverse(object => {
if (object.geometry) object.geometry.dispose();
});
group.clear();
}
// -------------------------------------------------------------------------
// Low-poly city
// -------------------------------------------------------------------------
box(46, 0.28, 34, 0, -0.16, 0, mat.ground);
box(44, 0.09, 8, 0, 0, 0, mat.road);
box(8, 0.09, 32, 0, 0, 0, mat.road);
// Four sidewalk blocks.
box(15, 0.28, 10, -11.5, 0.13, -9, mat.sidewalk);
box(15, 0.28, 11, -11.5, 0.13, 9.5, mat.sidewalk);
box(15, 0.28, 10, 11.5, 0.13, -9, mat.sidewalk);
box(15, 0.28, 11, 11.5, 0.13, 9.5, mat.sidewalk);
// Lane dashes.
for (let x = -21; x <= 21; x += 3) {
if (Math.abs(x) > 5.5) {
box(1.15, 0.025, 0.09, x, 0.065, 0, mat.lane);
}
}
for (let z = -15; z <= 15; z += 3) {
if (Math.abs(z) > 5.5) {
box(0.09, 0.025, 1.15, 0, 0.065, z, mat.lane);
}
}
// Crossings across the horizontal avenue.
for (const x of [-8, 8]) {
for (let z = -3; z <= 3; z += 1) {
box(2.7, 0.028, 0.34, x, 0.07, z, mat.marking);
}
}
// Crossing across the vertical street.
for (let x = -3; x <= 3; x += 1) {
box(0.34, 0.028, 2.5, x, 0.07, 5, mat.marking);
}
// Buildings.
const buildingPalette = [
0xd78d70, 0x91a8a4, 0xc7b274, 0x7f9eaf, 0xb68c9c
];
function building(x, z, w, d, h, index) {
const material = new THREE.MeshStandardMaterial({
color: buildingPalette[index % buildingPalette.length],
roughness: 0.9,
flatShading: true
});
box(w, h, d, x, 0.28 + h / 2, z, material);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.min(w, d) * 0.34, 0.65, 4),
material
);
roof.position.set(x, 0.28 + h + 0.325, z);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
mapGroup.add(roof);
}
building(-16.5, -11.4, 3.2, 3.4, 3.0, 0);
building(-8.6, -11.6, 3.8, 3.0, 4.1, 1);
building(14.9, -11.4, 3.3, 3.3, 3.5, 2);
building(8.1, -11.6, 3.3, 2.8, 4.5, 3);
building(-16.0, 10.2, 3.5, 3.4, 4.0, 4);
building(-8.2, 10.2, 3.8, 3.5, 2.8, 1);
building(15.6, 10.0, 3.8, 3.7, 3.2, 2);
building(8.1, 10.2, 3.3, 3.4, 4.4, 0);
function tree(x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.17, 1.15 * scale, 6),
mat.trunk
);
trunk.position.set(x, 0.82 * scale, z);
trunk.castShadow = true;
mapGroup.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.9 * scale, 2.0 * scale, 6),
Math.random() > 0.5 ? mat.leaf : mat.leafLight
);
crown.position.set(x, 2.0 * scale, z);
crown.rotation.y = Math.random() * Math.PI;
crown.castShadow = true;
mapGroup.add(crown);
}
[
[-19.3, -13.2], [-4.9, -13.3], [4.9, -13.3], [19.2, -13.2],
[-19.2, 13.8], [-4.9, 13.8], [4.9, 13.8], [19.2, 13.8],
[-19.2, -5.5], [19.2, -5.5]
].forEach(([x, z], i) => tree(x, z, 0.72 + (i % 3) * 0.08));
// -------------------------------------------------------------------------
// Access graph. Coordinates are shared by the route and the visible ramps.
// -------------------------------------------------------------------------
const nodes = {
start: { x: -14, z: -8, y: 0.30 },
approach: { x: -10, z: -8, y: 0.30 },
nwTop: { x: -8, z: -4, y: 0.30 },
nwFoot: { x: -8, z: -2, y: 0.10 },
swFoot: { x: -8, z: 2, y: 0.10 },
swTop: { x: -8, z: 4, y: 0.30 },
vWest: { x: -4, z: 5, y: 0.10 },
vEast: { x: 4, z: 5, y: 0.10 },
seTop: { x: 8, z: 4, y: 0.30 },
seFoot: { x: 8, z: 2, y: 0.10 },
neFoot: { x: 8, z: -2, y: 0.10 },
neTop: { x: 8, z: -4, y: 0.30 },
approach2: { x: 10, z: -8, y: 0.30 },
goal: { x: 14, z: -8, y: 0.30 }
};
const edges = [
{ id: "s-a", from: "start", to: "approach", kind: "sidewalk", valid: true },
{ id: "a-nw", from: "approach", to: "nwTop", kind: "sidewalk", valid: true },
{ id: "nw-ramp", from: "nwTop", to: "nwFoot", kind: "curb", valid: true },
{ id: "nw-cross", from: "nwFoot", to: "swFoot", kind: "crossing", valid: true },
{ id: "sw-ramp", from: "swFoot", to: "swTop", kind: "curb", valid: true },
{ id: "sw-vw", from: "swTop", to: "vWest", kind: "sidewalk", valid: true },
{ id: "vertical-cross", from: "vWest", to: "vEast", kind: "crossing", valid: true },
{ id: "ve-se", from: "vEast", to: "seTop", kind: "sidewalk", valid: true },
{ id: "se-ramp", from: "seTop", to: "seFoot", kind: "curb", valid: true },
{ id: "se-cross", from: "seFoot", to: "neFoot", kind: "crossing", valid: true },
{ id: "ne-ramp", from: "neFoot", to: "neTop", kind: "curb", valid: true },
{ id: "ne-a2", from: "neTop", to: "approach2", kind: "sidewalk", valid: true },
{ id: "a2-g", from: "approach2", to: "goal", kind: "sidewalk", valid: true },
{
id: "shortcut-plaza",
from: "start",
to: "vWest",
kind: "sidewalk",
valid: false,
shortcut: true,
reason: "Missing curb cut at the plaza corner"
},
{
id: "shortcut-center",
from: "nwFoot",
to: "vEast",
kind: "crossing",
valid: false,
shortcut: true,
reason: "Uncontrolled diagonal crossing; faded markings"
},
{
id: "shortcut-east",
from: "seFoot",
to: "goal",
kind: "sidewalk",
valid: false,
shortcut: true,
reason: "Stepped curb and blocked driveway at the east block"
}
];
const edgeById = new Map(edges.map(edge => [edge.id, edge]));
function nodeVector(id) {
const n = nodes[id];
return new THREE.Vector3(n.x, n.y, n.z);
}
function edgeLength(edge) {
return nodeVector(edge.from).distanceTo(nodeVector(edge.to));
}
function edgeWeight(edge) {
const factor = edge.kind === "crossing" ? 1.85 :
edge.kind === "curb" ? 1.25 : 1;
return edgeLength(edge) * factor;
}
// Physical curb ramps at the four valid curb-transition links.
function makeRamp(aId, bId) {
const a = nodeVector(aId);
const b = nodeVector(bId);
const direction = new THREE.Vector3().subVectors(b, a);
direction.y = 0;
direction.normalize();
const perpendicular = new THREE.Vector3(-direction.z, 0, direction.x);
const width = 1.15;
const point = (base, side, top) => {
const p = base.clone().addScaledVector(perpendicular, side * width / 2);
p.y = top ? base.y : 0.045;
return p;
};
const aL = point(a, 1, true);
const aR = point(a, -1, true);
const bL = point(b, 1, true);
const bR = point(b, -1, true);
const aLB = point(a, 1, false);
const aRB = point(a, -1, false);
const bLB = point(b, 1, false);
const bRB = point(b, -1, false);
const positions = new Float32Array([
...aL.toArray(), ...aR.toArray(), ...bL.toArray(), ...bR.toArray(),
...aLB.toArray(), ...aRB.toArray(), ...bLB.toArray(), ...bRB.toArray()
]);
const indices = [
0, 2, 1, 1, 2, 3,
4, 6, 5, 5, 6, 7,
0, 4, 6, 0, 6, 2,
1, 3, 7, 1, 7, 5,
0, 1, 5, 0, 5, 4,
2, 6, 7, 2, 7, 3
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const ramp = new THREE.Mesh(geometry, mat.curb);
ramp.castShadow = true;
ramp.receiveShadow = true;
mapGroup.add(ramp);
}
makeRamp("nwTop", "nwFoot");
makeRamp("swFoot", "swTop");
makeRamp("seTop", "seFoot");
makeRamp("neFoot", "neTop");
// Small crossing signal posts.
function signalPost(x, z, rotation = 0) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 1.5, 6),
mat.wheel
);
post.position.set(x, 0.75, z);
post.castShadow = true;
mapGroup.add(post);
const signal = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.48, 0.22),
mat.wheel
);
signal.position.set(x, 1.45, z);
signal.rotation.y = rotation;
signal.castShadow = true;
mapGroup.add(signal);
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.07, 8, 5),
new THREE.MeshBasicMaterial({ color: 0x64e6b0 })
);
light.position.set(x, 1.42, z + 0.13);
mapGroup.add(light);
}
signalPost(-9.05, -2.8);
signalPost(-6.95, 2.8);
signalPost(6.95, 2.8);
signalPost(9.05, -2.8);
signalPost(-4.7, 6.05, Math.PI / 2);
signalPost(4.7, 3.95, Math.PI / 2);
// Graph node dots.
Object.values(nodes).forEach(n => {
const dot = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.055, 10),
mat.graphNode
);
dot.position.set(n.x, n.y + 0.035, n.z);
dot.receiveShadow = true;
mapGroup.add(dot);
});
function makeLabel(text, x, z, color = "#183039") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(255,255,255,0.90)";
ctx.fillRect(5, 10, 502, 108);
ctx.strokeStyle = color;
ctx.lineWidth = 8;
ctx.strokeRect(5, 10, 502, 108);
ctx.fillStyle = color;
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.position.set(x, 1.25, z);
sprite.scale.set(4.6, 1.15, 1);
mapGroup.add(sprite);
return sprite;
}
makeLabel("START", -14, -10.3, "#167e72");
makeLabel("GOAL", 14, -10.3, "#167e72");
// -------------------------------------------------------------------------
// Dijkstra route finding
// -------------------------------------------------------------------------
function findRoute() {
const adjacency = new Map(Object.keys(nodes).map(id => [id, []]));
edges.forEach(edge => {
if (!edge.valid) return;
adjacency.get(edge.from).push({ to: edge.to, edge });
adjacency.get(edge.to).push({ to: edge.from, edge });
});
const distances = new Map(Object.keys(nodes).map(id => [id, Infinity]));
const previous = new Map();
const unvisited = new Set(Object.keys(nodes));
distances.set("start", 0);
while (unvisited.size) {
let current = null;
let best = Infinity;
for (const id of unvisited) {
if (distances.get(id) < best) {
best = distances.get(id);
current = id;
}
}
if (current === null || best === Infinity) break;
if (current === "goal") break;
unvisited.delete(current);
for (const connection of adjacency.get(current)) {
if (!unvisited.has(connection.to)) continue;
const candidate = best + edgeWeight(connection.edge);
if (candidate < distances.get(connection.to)) {
distances.set(connection.to, candidate);
previous.set(connection.to, {
node: current,
edge: connection.edge
});
}
}
}
if (!previous.has("goal")) return null;
const chain = [];
let cursor = "goal";
while (cursor !== "start") {
const step = previous.get(cursor);
if (!step) return null;
chain.push({
edge: step.edge,
from: step.node,
to: cursor
});
cursor = step.node;
}
chain.reverse();
return {
edges: chain,
weight: distances.get("goal")
};
}
// -------------------------------------------------------------------------
// Route and broken-link rendering
// -------------------------------------------------------------------------
let routeGroundPoints = [];
let routeDistance = 0;
let wheelchair;
const wheelchairWheels = [];
function routeMaterial(kind) {
if (kind === "crossing") return mat.routeCrossing;
if (kind === "curb") return mat.routeCurb;
return mat.route;
}
function drawRoute(result) {
clearGroup(routeGroup);
routeGroundPoints = [];
routeDistance = 0;
if (!result) {
wheelchair.visible = false;
return;
}
result.edges.forEach((step, index) => {
const a = nodeVector(step.from);
const b = nodeVector(step.to);
const raisedA = a.clone().add(new THREE.Vector3(0, 0.43, 0));
const raisedB = b.clone().add(new THREE.Vector3(0, 0.43, 0));
cylinderBetween(raisedA, raisedB, 0.25, mat.routeUnder, routeGroup, 6);
cylinderBetween(
raisedA, raisedB, 0.135,
routeMaterial(step.edge.kind), routeGroup, 6
);
const joint = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19, 0),
routeMaterial(step.edge.kind)
);
joint.position.copy(raisedB);
joint.castShadow = true;
routeGroup.add(joint);
if (index < result.edges.length - 1) {
const direction = raisedB.clone().sub(raisedA).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.28, 0.62, 3),
routeMaterial(step.edge.kind)
);
arrow.position.copy(raisedA).lerp(raisedB, 0.65);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0), direction
);
routeGroup.add(arrow);
}
routeGroundPoints.push(a.clone(), b.clone());
});
// Remove duplicate consecutive points while preserving the continuous path.
routeGroundPoints = routeGroundPoints.filter((point, index, array) =>
index === 0 || point.distanceTo(array[index - 1]) > 0.001
);
for (let i = 1; i < routeGroundPoints.length; i++) {
routeDistance += routeGroundPoints[i].distanceTo(routeGroundPoints[i - 1]);
}
wheelchair.visible = true;
}
let pickables = [];
function rebuildNetwork() {
clearGroup(networkGroup);
edges.forEach(edge => {
if (!edge.valid) return;
const a = nodeVector(edge.from).add(new THREE.Vector3(0, 0.07, 0));
const b = nodeVector(edge.to).add(new THREE.Vector3(0, 0.07, 0));
const geometry = new THREE.BufferGeometry().setFromPoints([a, b]);
const line = new THREE.Line(geometry, mat.network);
networkGroup.add(line);
});
networkGroup.visible = networkToggle.checked;
}
function rebuildShortcuts() {
clearGroup(shortcutGroup);
pickables = [];
edges.filter(edge => edge.shortcut && !edge.valid).forEach(edge => {
const a = nodeVector(edge.from).add(new THREE.Vector3(0, 0.48, 0));
const b = nodeVector(edge.to).add(new THREE.Vector3(0, 0.48, 0));
const direction = b.clone().sub(a);
const length = direction.length();
const dashCount = Math.max(5, Math.floor(length / 0.72));
for (let i = 0; i < dashCount; i++) {
const t0 = i / dashCount;
const t1 = t0 + 0.58 / dashCount;
const p0 = a.clone().lerp(b, t0);
const p1 = a.clone().lerp(b, t1);
cylinderBetween(p0, p1, 0.095, mat.broken, shortcutGroup, 5);
}
const midpoint = a.clone().lerp(b, 0.5);
const xAxis = new THREE.Vector3(0.4, 0, 0.4);
const zAxis = new THREE.Vector3(0.4, 0, -0.4);
cylinderBetween(
midpoint.clone().sub(xAxis),
midpoint.clone().add(xAxis),
0.11, mat.broken, shortcutGroup, 5
);
cylinderBetween(
midpoint.clone().sub(zAxis),
midpoint.clone().add(zAxis),
0.11, mat.broken, shortcutGroup, 5
);
const hit = new THREE.Mesh(
new THREE.SphereGeometry(0.7, 8, 6),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.copy(midpoint).add(new THREE.Vector3(0, 0.18, 0));
hit.userData.edgeId = edge.id;
shortcutGroup.add(hit);
pickables.push(hit);
});
}
function updateShortcutButtons() {
shortcutList.innerHTML = "";
edges.filter(edge => edge.shortcut).forEach((edge, index) => {
const button = document.createElement("button");
button.className = `shortcut${edge.valid ? " repaired" : ""}`;
const title = document.createElement("div");
title.className = "shortcut-top";
const name = document.createElement("span");
name.textContent = `Shortcut ${index + 1}`;
const action = document.createElement("span");
action.textContent = edge.valid ? "Repaired ✓" : "Broken ×";
title.append(name, action);
const reason = document.createElement("div");
reason.className = "shortcut-reason";
reason.textContent = edge.valid
? `${edge.reason} — repaired; route recalculated`
: edge.reason;
button.append(title, reason);
button.addEventListener("click", () => toggleShortcut(edge.id));
shortcutList.append(button);
});
}
function planRoute() {
statusBox.className = "status searching";
statusTitle.textContent = "Searching for a continuous route…";
statusDetail.textContent = "Evaluating valid links and their travel cost.";
window.setTimeout(() => {
const result = findRoute();
drawRoute(result);
rebuildNetwork();
if (!result) {
statusBox.className = "status error";
statusTitle.textContent = "No continuous route found";
statusDetail.textContent = "One or more required links are unavailable.";
distanceStat.textContent = "—";
curbStat.textContent = "—";
crossingStat.textContent = "—";
return;
}
const curbCount = result.edges.filter(s => s.edge.kind === "curb").length;
const crossingCount = result.edges.filter(s => s.edge.kind === "crossing").length;
const repairedUsed = result.edges.filter(s => s.edge.shortcut).length;
statusBox.className = "status";
statusTitle.textContent = "Continuous route found";
statusDetail.textContent = repairedUsed
? `The route uses ${repairedUsed} repaired shortcut. All selected links are traversable.`
: "The route avoids every broken connection and joins continuously at each transition.";
distanceStat.textContent = `${Math.round(routeDistance)} m`;
curbStat.textContent = curbCount;
crossingStat.textContent = crossingCount;
}, 180);
}
function toggleShortcut(id) {
const edge = edgeById.get(id);
edge.valid = !edge.valid;
rebuildNetwork();
rebuildShortcuts();
updateShortcutButtons();
planRoute();
}
function resetShortcuts() {
edges.forEach(edge => {
if (edge.shortcut) edge.valid = false;
});
rebuildNetwork();
rebuildShortcuts();
updateShortcutButtons();
planRoute();
}
// -------------------------------------------------------------------------
// Small low-poly wheelchair used to preview the route continuously.
// -------------------------------------------------------------------------
function createWheelchair() {
const group = new THREE.Group();
const seat = new THREE.Mesh(
new THREE.BoxGeometry(0.55, 0.12, 0.54),
mat.chair
);
seat.position.set(0, 0.68, 0);
seat.castShadow = true;
group.add(seat);
const back = new THREE.Mesh(
new THREE.BoxGeometry(0.56, 0.62, 0.10),
mat.chair
);
back.position.set(0, 1.0, -0.24);
back.castShadow = true;
group.add(back);
const frameLeft = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.65, 0.07),
mat.wheel
);
frameLeft.position.set(-0.28, 0.75, 0.23);
group.add(frameLeft);
const frameRight = frameLeft.clone();
frameRight.position.x = 0.28;
group.add(frameRight);
const largeWheelGeometry = new THREE.CylinderGeometry(
0.38, 0.38, 0.10, 10
);
for (const x of [-0.38, 0.38]) {
const wheel = new THREE.Mesh(largeWheelGeometry, mat.wheel);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.42, -0.05);
wheel.castShadow = true;
group.add(wheel);
wheelchairWheels.push(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.10, 0.12, 8),
mat.chair
);
hub.rotation.z = Math.PI / 2;
hub.position.set(x, 0.42, -0.05);
group.add(hub);
}
for (const x of [-0.25, 0.25]) {
const caster = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.09, 8),
mat.wheel
);
caster.rotation.z = Math.PI / 2;
caster.position.set(x, 0.17, 0.35);
caster.castShadow = true;
group.add(caster);
wheelchairWheels.push(caster);
}
const torso = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.44, 0.25),
mat.shirt
);
torso.position.set(0, 1.05, -0.10);
torso.castShadow = true;
group.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 8, 6),
mat.skin
);
head.position.set(0, 1.43, -0.08);
head.castShadow = true;
group.add(head);
group.visible = false;
scene.add(group);
return group;
}
wheelchair = createWheelchair();
// -------------------------------------------------------------------------
// Direct camera and pointer interaction (no controls add-on).
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerButton = 0;
let pointerX = 0;
let pointerY = 0;
let pointerTravel = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerButton = event.button;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
if (pointerButton === 2 || event.shiftKey) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = cameraTarget.clone().sub(camera.position);
forward.y = 0;
forward.normalize();
const scale = 0.025 / camera.zoom;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, dy * scale);
} else {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005, 0.35, 1.35
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && pointerTravel < 7 && pickables.length) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(pickables, false);
if (intersections.length) {
toggleShortcut(intersections[0].object.userData.edgeId);
}
}
pointerDown = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (event.deltaY > 0 ? 0.9 : 1.1), 0.65, 2.8
);
camera.updateProjectionMatrix();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", recenter);
document.getElementById("planButton").addEventListener("click", planRoute);
document.getElementById("resetButton").addEventListener("click", resetShortcuts);
document.getElementById("recenter").addEventListener("click", recenter);
networkToggle.addEventListener("change", () => {
networkGroup.visible = networkToggle.checked;
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(34, 44 / aspect);
camera.left = -frustumHeight * aspect / 2;
camera.right = frustumHeight * aspect / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function sampleRoute(distance) {
if (routeGroundPoints.length < 2) return null;
let remaining = THREE.MathUtils.clamp(distance, 0, routeDistance);
for (let i = 1; i < routeGroundPoints.length; i++) {
const a = routeGroundPoints[i - 1];
const b = routeGroundPoints[i];
const length = a.distanceTo(b);
if (remaining <= length || i === routeGroundPoints.length - 1) {
const t = length > 0 ? remaining / length : 0;
return {
position: a.clone().lerp(b, t),
direction: b.clone().sub(a).normalize()
};
}
remaining -= length;
}
return null;
}
function animate() {
const elapsed = clock.getElapsedTime();
if (wheelchair.visible && routeGroundPoints.length > 1 && routeDistance > 0) {
const phase = (elapsed * 0.075) % 2;
const forward = phase <= 1;
const progress = forward ? phase : 2 - phase;
const sample = sampleRoute(progress * routeDistance);
if (sample) {
wheelchair.position.copy(sample.position);
wheelchair.position.y += 0.035;
const yaw = Math.atan2(sample.direction.x, sample.direction.z);
wheelchair.rotation.y = forward ? yaw : yaw + Math.PI;
const roll = elapsed * 5;
wheelchairWheels.forEach(wheel => wheel.rotation.x = roll);
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
rebuildNetwork();
rebuildShortcuts();
updateShortcutButtons();
window.setTimeout(planRoute, 350);
</script>
</body>
</html>
```