Prompt specification
Build or customize the Three.js 3D scene "Stall layout route graph" 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: Stall layout route graph
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stall-layout-route-graph-x0505
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: stall layout route graph. Place six stalls on a small square with visible entrance markers; overlay nodes and connecting paths so blocked and open connections are easy to compare. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (stall-layout-route-graph-x0505):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stall Layout — Route Graph</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf7ff;
--muted: #91a8b8;
--panel: rgba(8, 18, 29, 0.82);
--line: rgba(150, 209, 231, 0.18);
--open: #59f2c2;
--blocked: #ff6178;
--entry: #63d8ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111b;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--entry);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 9px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #c9dbe5;
font-size: 12px;
}
.swatch {
display: inline-block;
flex: 0 0 auto;
width: 30px;
}
.swatch.open {
height: 4px;
border-radius: 999px;
background: var(--open);
box-shadow: 0 0 11px rgba(89, 242, 194, 0.7);
}
.swatch.blocked {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--blocked) 0 7px,
transparent 7px 12px
);
}
.swatch.entry {
width: 18px;
height: 18px;
margin-left: 6px;
margin-right: 6px;
border: 3px solid var(--entry);
border-radius: 50%;
box-shadow: 0 0 10px rgba(99, 216, 255, 0.55);
}
.controls {
top: 22px;
right: 22px;
width: 245px;
padding: 16px;
border-radius: 18px;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 14px;
}
.stat {
min-width: 0;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
text-align: center;
}
.stat strong {
display: block;
font-size: 20px;
line-height: 1;
}
.stat span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.stat.blocked strong {
color: var(--blocked);
}
.button-row {
display: grid;
gap: 8px;
}
button {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(99, 216, 255, 0.5);
background: rgba(99, 216, 255, 0.09);
transform: translateY(-1px);
}
button.primary {
border-color: rgba(89, 242, 194, 0.35);
background: rgba(89, 242, 194, 0.1);
}
.hint {
right: 22px;
bottom: 20px;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.hint b {
color: #d7e9f2;
font-weight: 700;
}
.status {
position: fixed;
z-index: 9;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 18, 29, 0.78);
color: var(--muted);
font-size: 11px;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--open);
box-shadow: 0 0 10px var(--open);
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.subtitle {
display: none;
}
.legend {
grid-template-columns: repeat(3, auto);
gap: 13px;
margin-top: 13px;
padding-top: 12px;
}
.legend-row {
font-size: 10px;
}
.swatch {
width: 21px;
}
.swatch.entry {
width: 14px;
height: 14px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
width: 210px;
padding: 11px;
}
.stats {
margin-bottom: 9px;
}
.stat {
padding: 7px 4px;
}
.stat strong {
font-size: 16px;
}
.button-row {
grid-template-columns: 1fr 1fr;
gap: 6px;
}
button {
padding: 8px 6px;
font-size: 10px;
}
.button-row .primary {
grid-column: 1 / -1;
}
.hint,
.status {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D stall layout with route graph"></div>
<section class="panel intro">
<div class="eyebrow">Market flow / visual survey</div>
<h1>Courtyard Route Graph</h1>
<p class="subtitle">
Six stalls arranged around a compact square. Compare open routes, blocked
links, and entrance points from the overlaid circulation graph.
</p>
<div class="legend" aria-label="Graph legend">
<div class="legend-row">
<span class="swatch open"></span>
<span>Open connection</span>
</div>
<div class="legend-row">
<span class="swatch blocked"></span>
<span>Blocked connection</span>
</div>
<div class="legend-row">
<span class="swatch entry"></span>
<span>Entrance marker</span>
</div>
</div>
</section>
<aside class="panel controls">
<div class="stats">
<div class="stat">
<strong>6</strong>
<span>Stalls</span>
</div>
<div class="stat">
<strong>9</strong>
<span>Links</span>
</div>
<div class="stat blocked">
<strong>2</strong>
<span>Blocked</span>
</div>
</div>
<div class="button-row">
<button id="toggleGraph" class="primary" type="button">Hide route graph</button>
<button id="focusClosures" type="button">Focus closures</button>
<button id="resetView" type="button">Reset view</button>
</div>
</aside>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">Route graph visible</span>
</div>
<div class="panel hint">
<b>Drag</b> to orbit · <b>Shift-drag</b> to pan · <b>Scroll</b> to zoom · <b>Double-click</b> to reset
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
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.12;
renderer.domElement.setAttribute("aria-label", "3D market courtyard and route graph");
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.Fog(0x07111b, 30, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls: no external control modules are used.
const controls = {
target: new THREE.Vector3(0, 0.35, 0),
yaw: 0.62,
pitch: 0.88,
radius: 25.5,
dragging: false,
panning: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const horizontal = Math.sin(controls.pitch) * controls.radius;
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.yaw),
controls.target.y + Math.cos(controls.pitch) * controls.radius,
controls.target.z + horizontal * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(0, 0.35, 0);
controls.yaw = 0.62;
controls.pitch = 0.88;
controls.radius = 25.5;
updateCamera();
}
function focusClosures() {
controls.target.set(0, 0.25, 1.6);
controls.yaw = 0.48;
controls.pitch = 1.02;
controls.radius = 19.5;
updateCamera();
}
updateCamera();
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.panning = event.shiftKey || event.button === 2;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
if (controls.panning) {
const right = new THREE.Vector3(Math.cos(controls.yaw), 0, -Math.sin(controls.yaw));
const forward = new THREE.Vector3(-Math.sin(controls.yaw), 0, -Math.cos(controls.yaw));
const panScale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(forward, dy * panScale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -8, 8);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -8, 8);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(controls.pitch + dy * 0.005, 0.34, 1.36);
}
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
11,
39
);
updateCamera();
},
{ passive: false }
);
// Lighting
scene.add(new THREE.HemisphereLight(0xc8efff, 0x17202d, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(7, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x40cfff, 22, 18, 2);
cyanLight.position.set(-8, 5, 6);
scene.add(cyanLight);
const coralLight = new THREE.PointLight(0xff526d, 15, 14, 2);
coralLight.position.set(7, 4, 4);
scene.add(coralLight);
// Helpers
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const animatedEntranceRings = [];
const routePulses = [];
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function labelTexture(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(
ctx,
7,
7,
498,
114,
options.radius ?? 26
);
ctx.fillStyle = options.background ?? "rgba(6, 17, 28, 0.88)";
ctx.fill();
if (options.border !== "none") {
ctx.lineWidth = options.borderWidth ?? 3;
ctx.strokeStyle = options.border ?? "rgba(120, 194, 224, 0.35)";
ctx.stroke();
}
ctx.fillStyle = options.color ?? "#eaf7ff";
ctx.font = `${options.weight ?? 800} ${options.size ?? 42}px Inter, system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
return texture;
}
function makeSprite(text, options = {}) {
const material = new THREE.SpriteMaterial({
map: labelTexture(text, options),
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const width = options.width ?? 2;
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 10;
return sprite;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.05,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function cylinderBetween(group, a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(mesh);
return mesh;
}
// Courtyard slab
const slab = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.5, 18),
standardMaterial(0x0c1721, { roughness: 0.92, metalness: 0.02 })
);
slab.position.y = -0.28;
slab.receiveShadow = true;
scene.add(slab);
const plaza = new THREE.Mesh(
new THREE.PlaneGeometry(17.2, 17.2),
standardMaterial(0x111e29, { roughness: 0.94 })
);
plaza.rotation.x = -Math.PI / 2;
plaza.position.y = -0.015;
plaza.receiveShadow = true;
scene.add(plaza);
const grid = new THREE.GridHelper(16, 16, 0x426777, 0x1c3441);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const borderMaterial = new THREE.MeshBasicMaterial({
color: 0x31596a,
transparent: true,
opacity: 0.8
});
const borderPieces = [
[0, 8.45, 17.2, 0.07, 0.08],
[0, -8.45, 17.2, 0.07, 0.08],
[8.45, 0, 0.07, 0.08, 17.2],
[-8.45, 0, 0.07, 0.08, 17.2]
];
for (const [x, z, width, height, depth] of borderPieces) {
const strip = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
borderMaterial
);
strip.position.set(x, 0.04, z);
scene.add(strip);
}
const cornerMaterial = new THREE.MeshBasicMaterial({ color: 0x63d8ff });
for (const x of [-8.35, 8.35]) {
for (const z of [-8.35, 8.35]) {
const corner = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.08, 16),
cornerMaterial
);
corner.position.set(x, 0.07, z);
scene.add(corner);
}
}
// Six stalls
const stalls = [
{ letter: "A", name: "CITRUS", color: 0x53e1b5, x: -5, z: 4.65 },
{ letter: "B", name: "BAKERY", color: 0xffbc57, x: 0, z: 4.65 },
{ letter: "C", name: "FLOWERS", color: 0xff7083, x: 5, z: 4.65 },
{ letter: "D", name: "TEA", color: 0x5ca8ff, x: -5, z: -4.65 },
{ letter: "E", name: "PRINT", color: 0xa78bfa, x: 0, z: -4.65 },
{ letter: "F", name: "COFFEE", color: 0xf472b6, x: 5, z: -4.65 }
];
const stallBodyMaterial = standardMaterial(0x172a38, { roughness: 0.78 });
const stallDarkMaterial = standardMaterial(0x08131c, { roughness: 0.92 });
const stallBaseMaterial = standardMaterial(0x233d4b, { roughness: 0.8 });
const creamMaterial = standardMaterial(0xe8eee8, { roughness: 0.85 });
function createStall(stall) {
const group = new THREE.Group();
group.position.set(stall.x, 0, stall.z);
// Local front is +Z; far-row stalls rotate toward the center.
group.rotation.y = stall.z > 0 ? Math.PI : 0;
const accentMaterial = standardMaterial(stall.color, {
roughness: 0.6,
emissive: stall.color,
emissiveIntensity: 0.08
});
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(2.95, 0.18, 1.82),
stallBaseMaterial
);
plinth.position.y = 0.1;
plinth.castShadow = true;
plinth.receiveShadow = true;
group.add(plinth);
const body = new THREE.Mesh(
new THREE.BoxGeometry(2.7, 1.65, 1.55),
stallBodyMaterial
);
body.position.y = 0.98;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const opening = new THREE.Mesh(
new THREE.BoxGeometry(2.12, 0.76, 0.06),
stallDarkMaterial
);
opening.position.set(0, 1.02, 0.805);
group.add(opening);
const counter = new THREE.Mesh(
new THREE.BoxGeometry(2.42, 0.16, 0.46),
accentMaterial
);
counter.position.set(0, 0.67, 0.96);
counter.castShadow = true;
group.add(counter);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(3.05, 0.22, 1.95),
accentMaterial
);
roof.position.y = 1.94;
roof.castShadow = true;
group.add(roof);
// Striped canopy
for (let i = 0; i < 5; i++) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.12, 0.7),
i % 2 === 0 ? accentMaterial : creamMaterial
);
stripe.position.set(-1.08 + i * 0.54, 1.69, 1.08);
stripe.rotation.x = 0.12;
stripe.castShadow = true;
group.add(stripe);
}
const signTexture = labelTexture(`${stall.letter} ${stall.name}`, {
color: "#f1fbff",
border: `#${stall.color.toString(16).padStart(6, "0")}`,
borderWidth: 5,
size: 40
});
const frontSign = new THREE.Mesh(
new THREE.PlaneGeometry(1.88, 0.47),
new THREE.MeshBasicMaterial({
map: signTexture,
transparent: true,
depthWrite: false
})
);
frontSign.position.set(0, 1.48, 0.842);
group.add(frontSign);
// Rear sign keeps the far row legible from the default camera.
const rearSign = new THREE.Mesh(
new THREE.PlaneGeometry(1.88, 0.47),
new THREE.MeshBasicMaterial({
map: signTexture,
transparent: true,
depthWrite: false
})
);
rearSign.position.set(0, 1.48, -0.842);
rearSign.rotation.y = Math.PI;
group.add(rearSign);
const label = makeSprite(`${stall.letter} · ${stall.name}`, {
color: "#f2fbff",
border: `#${stall.color.toString(16).padStart(6, "0")}`,
borderWidth: 4,
width: 2.35,
size: 36
});
label.position.set(0, 2.58, 0);
group.add(label);
scene.add(group);
// Entrance marker between each stall and the center aisle.
const entranceZ = stall.z > 0 ? 2.8 : -2.8;
const entrance = new THREE.Group();
entrance.position.set(stall.x, 0, entranceZ);
const markerDisc = new THREE.Mesh(
new THREE.CircleGeometry(0.42, 32),
new THREE.MeshBasicMaterial({
color: 0x63d8ff,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
markerDisc.rotation.x = -Math.PI / 2;
markerDisc.position.y = 0.045;
entrance.add(markerDisc);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.055, 8, 36),
new THREE.MeshBasicMaterial({ color: 0x63d8ff })
);
markerRing.rotation.x = Math.PI / 2;
markerRing.position.y = 0.085;
entrance.add(markerRing);
animatedEntranceRings.push(markerRing);
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 0.23);
arrowShape.lineTo(-0.15, -0.08);
arrowShape.lineTo(0, -0.02);
arrowShape.lineTo(0.15, -0.08);
arrowShape.closePath();
const arrow = new THREE.Mesh(
new THREE.ShapeGeometry(arrowShape),
new THREE.MeshBasicMaterial({
color: 0xb8efff,
side: THREE.DoubleSide
})
);
arrow.rotation.x = stall.z > 0 ? Math.PI / 2 : -Math.PI / 2;
arrow.position.y = 0.065;
entrance.add(arrow);
const entryLabel = makeSprite(`ENTRY ${stall.letter}`, {
color: "#bfefff",
border: "rgba(99, 216, 255, 0.65)",
width: 1.5,
size: 37
});
entryLabel.position.set(0, 0.66, 0);
entrance.add(entryLabel);
scene.add(entrance);
}
stalls.forEach(createStall);
// Main entrance gate
const gate = new THREE.Group();
gate.position.set(0, 0, 7.75);
const gatePostMaterial = standardMaterial(0x28576a, {
roughness: 0.55,
metalness: 0.3,
emissive: 0x1b718d,
emissiveIntensity: 0.28
});
for (const x of [-1.12, 1.12]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.14, 1.65, 10),
gatePostMaterial
);
post.position.set(x, 0.82, 0);
post.castShadow = true;
gate.add(post);
}
const gateBar = new THREE.Mesh(
new THREE.BoxGeometry(2.42, 0.14, 0.18),
gatePostMaterial
);
gateBar.position.y = 1.58;
gate.add(gateBar);
const gateLabel = makeSprite("MAIN ENTRY", {
color: "#d5f6ff",
border: "rgba(99, 216, 255, 0.8)",
borderWidth: 4,
width: 2.1,
size: 39
});
gateLabel.position.set(0, 2.05, 0);
gate.add(gateLabel);
scene.add(gate);
// Graph node and edge styling
const openMaterial = new THREE.MeshBasicMaterial({ color: 0x59f2c2 });
const openGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x59f2c2,
transparent: true,
opacity: 0.14,
depthWrite: false
});
const blockedMaterial = new THREE.MeshBasicMaterial({ color: 0xff6178 });
const nodeMaterial = standardMaterial(0xe9fbff, {
roughness: 0.35,
metalness: 0.15,
emissive: 0x16404b,
emissiveIntensity: 0.55
});
const nodePositions = {
GATE: new THREE.Vector3(0, 0.16, 7.05),
HUB: new THREE.Vector3(0, 0.16, 0),
WEST: new THREE.Vector3(-4, 0.16, 0),
EAST: new THREE.Vector3(4, 0.16, 0),
A: new THREE.Vector3(-5, 0.16, 2.8),
B: new THREE.Vector3(0, 0.16, 2.8),
C: new THREE.Vector3(5, 0.16, 2.8),
D: new THREE.Vector3(-5, 0.16, -2.8),
E: new THREE.Vector3(0, 0.16, -2.8),
F: new THREE.Vector3(5, 0.16, -2.8)
};
function addGraphNode(name, position, label = null, hub = false) {
const group = new THREE.Group();
group.position.copy(position);
const radius = hub ? 0.31 : 0.22;
const node = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.08, 0.17, 18),
nodeMaterial
);
node.position.y = 0.025;
group.add(node);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius + 0.14, 0.035, 8, 28),
new THREE.MeshBasicMaterial({ color: hub ? 0x59f2c2 : 0xdff8ff })
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.13;
group.add(ring);
if (label) {
const nodeLabel = makeSprite(label, {
color: hub ? "#baffdf" : "#d9edf6",
border: hub ? "rgba(89, 242, 194, 0.65)" : "rgba(167, 214, 234, 0.4)",
width: hub ? 1.35 : 1.15,
size: 38
});
nodeLabel.position.y = hub ? 0.76 : 0.62;
group.add(nodeLabel);
}
routeGroup.add(group);
}
addGraphNode("GATE", nodePositions.GATE, "GATE");
addGraphNode("HUB", nodePositions.HUB, "HUB", true);
addGraphNode("WEST", nodePositions.WEST, "WEST");
addGraphNode("EAST", nodePositions.EAST, "EAST");
for (const name of ["A", "B", "C", "D", "E", "F"]) {
addGraphNode(name, nodePositions[name]);
}
function addOpenEdge(startName, endName) {
const start = nodePositions[startName];
const end = nodePositions[endName];
cylinderBetween(routeGroup, start, end, 0.115, openGlowMaterial);
cylinderBetween(routeGroup, start, end, 0.058, openMaterial);
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xe6fff8 })
);
routeGroup.add(pulse);
routePulses.push({
mesh: pulse,
start: start.clone(),
end: end.clone(),
offset: Math.random(),
speed: 0.17 + Math.random() * 0.08
});
}
function addBlockedEdge(startName, endName) {
const start = nodePositions[startName];
const end = nodePositions[endName];
const direction = new THREE.Vector3().subVectors(end, start);
const distance = direction.length();
const unit = direction.clone().normalize();
const dashLength = 0.34;
const gap = 0.22;
for (let offset = 0; offset < distance; offset += dashLength + gap) {
const segmentStart = start.clone().addScaledVector(unit, offset);
const segmentEnd = start
.clone()
.addScaledVector(unit, Math.min(offset + dashLength, distance));
cylinderBetween(routeGroup, segmentStart, segmentEnd, 0.075, blockedMaterial, 10);
}
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const crossSize = 0.34;
cylinderBetween(
routeGroup,
midpoint.clone().add(new THREE.Vector3(-crossSize, 0, 0)),
midpoint.clone().add(new THREE.Vector3(crossSize, 0, 0)),
0.07,
blockedMaterial,
10
);
cylinderBetween(
routeGroup,
midpoint.clone().add(new THREE.Vector3(0, 0, -crossSize)),
midpoint.clone().add(new THREE.Vector3(0, 0, crossSize)),
0.07,
blockedMaterial,
10
);
const blockedLabel = makeSprite("BLOCKED", {
color: "#ffd5dc",
border: "rgba(255, 97, 120, 0.85)",
borderWidth: 4,
width: 1.65,
size: 39
});
blockedLabel.position.copy(midpoint);
blockedLabel.position.y = 0.72;
routeGroup.add(blockedLabel);
}
addOpenEdge("GATE", "HUB");
addOpenEdge("HUB", "WEST");
addOpenEdge("HUB", "EAST");
addOpenEdge("HUB", "B");
addOpenEdge("HUB", "E");
addOpenEdge("WEST", "D");
addOpenEdge("EAST", "F");
addBlockedEdge("WEST", "A");
addBlockedEdge("EAST", "C");
// Small decorative bollards around the square.
const bollardMaterial = standardMaterial(0x2b5263, {
roughness: 0.55,
metalness: 0.25,
emissive: 0x153d4b,
emissiveIntensity: 0.25
});
for (const x of [-7.6, 7.6]) {
for (const z of [-6.5, 0, 6.5]) {
const bollard = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.14, 0.52, 10),
bollardMaterial
);
bollard.position.set(x, 0.26, z);
bollard.castShadow = true;
scene.add(bollard);
}
}
// UI controls
const toggleButton = document.getElementById("toggleGraph");
const statusText = document.getElementById("statusText");
let graphVisible = true;
toggleButton.addEventListener("click", () => {
graphVisible = !graphVisible;
routeGroup.visible = graphVisible;
toggleButton.textContent = graphVisible ? "Hide route graph" : "Show route graph";
statusText.textContent = graphVisible ? "Route graph visible" : "Route graph hidden";
});
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("focusClosures").addEventListener("click", focusClosures);
// Resize
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Animation
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
animatedEntranceRings.forEach((ring, index) => {
const scale = 1 + Math.sin(elapsed * 2.2 + index * 0.7) * 0.075;
ring.scale.set(scale, scale, scale);
});
routePulses.forEach((pulse) => {
const progress = (elapsed * pulse.speed + pulse.offset) % 1;
pulse.mesh.position.lerpVectors(pulse.start, pulse.end, progress);
pulse.mesh.position.y += 0.09;
const fade = Math.sin(progress * Math.PI);
pulse.mesh.scale.setScalar(0.65 + fade * 0.55);
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```