Prompt specification
Build or customize the Three.js 3D scene "Evacuation Route Sign and Alternate Path" 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: Evacuation Route Sign and Alternate Path
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/evacuation-route-sign-and-alternate-path-x3225
Scene Description Prompt:
Create a stylized fictional room with two exits and clearly visible primary and alternate evacuation paths. Three.js from cdnjs, one HTML file.
Working Three.js Starter (evacuation-route-sign-and-alternate-path-x3225):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Room 204 — Two-Way Evacuation</title>
<style>
:root {
--ink: #102033;
--panel: rgba(12, 25, 43, 0.91);
--panel-soft: rgba(255, 255, 255, 0.08);
--primary: #32d583;
--alternate: #ffb020;
--white: #f5f8fb;
--muted: #aebdca;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7edf2;
color: var(--white);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 20px 18px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 45px rgba(17, 32, 48, 0.18);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 8px;
color: #8fa4b7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
color: #c7f8dc;
letter-spacing: 0.08em;
}
.live::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--primary);
box-shadow: 0 0 12px rgba(50, 213, 131, 0.85);
content: "";
}
h1 {
margin: 0;
font-size: clamp(24px, 2.4vw, 34px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
position: absolute;
top: 180px;
left: 24px;
width: min(320px, calc(100vw - 48px));
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 45px rgba(17, 32, 48, 0.16);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.legend-title {
padding: 4px 5px 11px;
color: #91a5b8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.route-card {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
width: 100%;
margin-top: 7px;
padding: 11px;
border: 1px solid transparent;
border-radius: 12px;
background: rgba(255, 255, 255, 0.045);
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.route-card:hover {
background: rgba(255, 255, 255, 0.08);
transform: translateY(-1px);
}
.route-card.is-off {
opacity: 0.38;
filter: saturate(0.25);
}
.route-swatch {
position: relative;
width: 26px;
height: 26px;
border-radius: 8px;
background: var(--route-color);
box-shadow: 0 0 18px color-mix(in srgb, var(--route-color) 45%, transparent);
}
.route-swatch::after {
position: absolute;
top: 10px;
left: 8px;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 7px solid #102033;
content: "";
}
.route-name {
display: block;
margin-bottom: 3px;
font-size: 13px;
font-weight: 800;
}
.route-detail {
display: block;
color: var(--muted);
font-size: 11px;
}
.route-key {
color: #8195a8;
font-size: 10px;
font-weight: 700;
}
.legend-note {
margin: 11px 5px 2px;
color: #8398ab;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.button {
min-height: 42px;
padding: 0 16px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 12px;
background: var(--panel);
color: var(--white);
box-shadow: 0 12px 30px rgba(17, 32, 48, 0.16);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
}
.button:hover {
background: #1c334b;
}
.hint {
position: absolute;
bottom: 25px;
left: 50%;
padding: 10px 14px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.78);
color: #536779;
box-shadow: 0 8px 22px rgba(32, 54, 73, 0.1);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
transform: translateX(-50%);
white-space: nowrap;
}
.exit-count {
position: absolute;
top: 25px;
right: 25px;
display: flex;
align-items: center;
gap: 10px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 14px 32px rgba(17, 32, 48, 0.15);
color: #d7e4ed;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.exit-count strong {
color: var(--primary);
font-size: 18px;
}
@media (max-width: 700px) {
.brand {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px;
}
.brand p {
display: none;
}
.legend {
top: 126px;
left: 14px;
width: calc(100vw - 28px);
padding: 9px;
}
.legend-title,
.legend-note {
display: none;
}
.route-card {
margin-top: 4px;
padding: 8px;
}
.exit-count {
top: auto;
right: 14px;
bottom: 68px;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="brand">
<div class="eyebrow">
<span>Safety scenario / 02</span>
<span class="live">Routes active</span>
</div>
<h1>Two-Way<br />Evacuation</h1>
<p>Fictional common room with two verified exits. Colored floor routes remain separated from furniture and obstacles.</p>
</section>
<section class="legend" aria-label="Evacuation route legend">
<div class="legend-title">Evacuation routes</div>
<button class="route-card" data-route="primary" aria-pressed="true">
<span class="route-swatch" style="--route-color: var(--primary)"></span>
<span>
<span class="route-name">Primary route</span>
<span class="route-detail">Exit A · direct left-hand route</span>
</span>
<span class="route-key">A</span>
</button>
<button class="route-card" data-route="alternate" aria-pressed="true">
<span class="route-swatch" style="--route-color: var(--alternate)"></span>
<span>
<span class="route-name">Alternate route</span>
<span class="route-detail">Exit B · separated right-hand route</span>
</span>
<span class="route-key">B</span>
</button>
<p class="legend-note">Select a route to hide or show it. Animated markers show travel direction toward each exit.</p>
</section>
<div class="exit-count"><strong>2</strong> exits available</div>
<div class="controls">
<button id="reset-view" class="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · wheel to zoom · shift-drag to pan · double-click to reset</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 container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7edf2);
scene.fog = new THREE.Fog(0xe7edf2, 38, 78);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
// ---------- Lighting ----------
scene.add(new THREE.HemisphereLight(0xf4fbff, 0x718397, 2.35));
const sun = new THREE.DirectionalLight(0xffffff, 3.2);
sun.position.set(-9, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dcff, 1.1);
fill.position.set(14, 10, -12);
scene.add(fill);
// ---------- Shared materials ----------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...options
});
const floorMat = material(0xd8e0e3);
const wallMat = material(0xf3f5f4);
const wallSideMat = material(0xe5ebed);
const trimMat = material(0x31506a, { roughness: 0.55 });
const darkMat = material(0x15283b);
const sofaMat = material(0x344d69);
const cushionMat = material(0x52718d);
const woodMat = material(0xb8875b);
const whiteMat = material(0xf7f8f4);
const screenMat = material(0x8ed4d5, {
emissive: 0x376e73,
emissiveIntensity: 0.35,
roughness: 0.35
});
function addBox(width, height, depth, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(radius, height, x, y, z, mat, segments = 24, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ---------- Ground and room shell ----------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
material(0xdfe6e9)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
const backgroundGrid = new THREE.GridHelper(80, 80, 0xbdcbd1, 0xd2dde1);
backgroundGrid.position.y = -0.375;
backgroundGrid.material.transparent = true;
backgroundGrid.material.opacity = 0.35;
scene.add(backgroundGrid);
addBox(20.4, 0.36, 14.4, 0, -0.18, 0, floorMat);
// Subtle floor grid.
const tilePositions = [];
for (let x = -8; x <= 8; x += 2) {
tilePositions.push(x, 0.012, -6.7, x, 0.012, 6.7);
}
for (let z = -6; z <= 6; z += 2) {
tilePositions.push(-9.7, 0.012, z, 9.7, 0.012, z);
}
const tileGeometry = new THREE.BufferGeometry();
tileGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tilePositions, 3)
);
const tileLines = new THREE.LineSegments(
tileGeometry,
new THREE.LineBasicMaterial({
color: 0x8799a3,
transparent: true,
opacity: 0.18
})
);
scene.add(tileLines);
// Full rear wall and low cutaway walls.
addBox(20.5, 4.0, 0.28, 0, 2.0, -7.05, wallMat);
addBox(20.6, 0.14, 0.38, 0, 4.05, -7.05, trimMat);
const leftRanges = [
[-7.05, 1.78],
[4.92, 7.05]
];
const rightRanges = [
[-7.05, -4.92],
[-1.78, 7.05]
];
function addSideWall(side, ranges) {
ranges.forEach(([min, max]) => {
const length = max - min;
const center = (min + max) / 2;
addBox(0.28, 1.45, length, side * 10.02, 0.725, center, wallSideMat);
addBox(0.38, 0.13, length, side * 10.02, 1.49, center, trimMat);
});
}
addSideWall(-1, leftRanges);
addSideWall(1, rightRanges);
// Low front wall keeps the plan readable from the default camera.
addBox(20.4, 0.68, 0.28, 0, 0.34, 7.05, wallSideMat);
addBox(20.5, 0.13, 0.38, 0, 0.73, 7.05, trimMat);
// ---------- Exit portals ----------
const exits = {
primary: {
side: -1,
z: 3.35,
color: 0x32d583,
css: "#32d583",
title: "EXIT A",
subtitle: "PRIMARY EVACUATION ROUTE"
},
alternate: {
side: 1,
z: -3.35,
color: 0xffb020,
css: "#ffb020",
title: "EXIT B",
subtitle: "ALTERNATE EVACUATION ROUTE"
}
};
function makeBillboard(title, subtitle, accent, width = 4.4) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(12, 25, 43, 0.95)";
ctx.beginPath();
ctx.roundRect(8, 8, 752, 204, 28);
ctx.fill();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.roundRect(8, 8, 24, 204, 12);
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.beginPath();
ctx.roundRect(8, 8, 752, 204, 28);
ctx.stroke();
ctx.fillStyle = accent;
ctx.font = "800 70px Inter, Arial, sans-serif";
ctx.fillText(title, 62, 91);
ctx.fillStyle = "#d7e4ed";
ctx.font = "700 28px Inter, Arial, sans-serif";
ctx.fillText(subtitle, 64, 145);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (220 / 768), 1);
sprite.renderOrder = 20;
return sprite;
}
function addExitPortal(exit) {
const { side, z, color, title, subtitle, css } = exit;
// Tall portal frame.
[-1.72, 1.72].forEach((offset) => {
addBox(0.3, 3.25, 0.3, side * 10.03, 1.625, z + offset, trimMat);
});
addBox(0.32, 0.3, 3.75, side * 10.03, 3.18, z, trimMat);
// Open doorway glow.
const glowMat = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
});
const glow = new THREE.Mesh(new THREE.PlaneGeometry(3.12, 2.9), glowMat);
glow.rotation.y = Math.PI / 2;
glow.position.set(side * 10.02, 1.48, z);
scene.add(glow);
// Threshold.
addBox(0.42, 0.055, 3.05, side * 10.02, 0.035, z, material(color, {
emissive: color,
emissiveIntensity: 0.35
}));
// Exterior landing.
addBox(3.8, 0.18, 3.8, side * 12.0, -0.04, z, wallMat);
addBox(3.45, 0.025, 3.35, side * 12.0, 0.065, z, material(color, {
emissive: color,
emissiveIntensity: 0.16
}));
// Open door leaf.
const hinge = new THREE.Group();
hinge.position.set(side * 10.07, 0, z + (side < 0 ? 1.5 : -1.5));
hinge.rotation.y = 1.15;
scene.add(hinge);
const localZ = side < 0 ? -1.5 : 1.5;
addBox(0.12, 2.82, 3.0, 0, 1.41, localZ, material(0x36536b), hinge);
addBox(0.16, 0.18, 2.72, 0, 2.56, localZ, material(color, {
emissive: color,
emissiveIntensity: 0.16
}), hinge);
const sign = makeBillboard(title, subtitle, css, 4.65);
sign.position.set(side * 11.2, 3.83, z);
scene.add(sign);
}
addExitPortal(exits.primary);
addExitPortal(exits.alternate);
// ---------- Furniture and room details ----------
// Lounge sofa.
addBox(5.35, 0.52, 1.72, -3.2, 0.42, -4.75, sofaMat);
addBox(5.35, 1.25, 0.36, -3.2, 1.22, -5.49, sofaMat);
addBox(0.38, 0.92, 1.72, -5.73, 0.78, -4.75, sofaMat);
addBox(0.38, 0.92, 1.72, -0.67, 0.78, -4.75, sofaMat);
addBox(2.35, 0.3, 1.3, -4.35, 0.8, -4.65, cushionMat);
addBox(2.35, 0.3, 1.3, -2.05, 0.8, -4.65, cushionMat);
// Coffee table.
addCylinder(1.15, 0.42, -3.0, 0.39, -2.75, woodMat);
addCylinder(0.12, 0.48, -3.0, 0.25, -2.75, darkMat, 16);
// Small decorative book stack.
addBox(0.72, 0.09, 0.5, -3.35, 0.66, -2.7, material(0xd77a60));
addBox(0.62, 0.08, 0.45, -3.28, 0.75, -2.68, material(0x6c8eaa));
// Workstation against the rear wall.
addBox(3.4, 0.25, 1.2, 4.65, 1.05, -5.75, woodMat);
addBox(0.18, 1.0, 0.85, 3.2, 0.5, -5.75, darkMat);
addBox(0.18, 1.0, 0.85, 6.1, 0.5, -5.75, darkMat);
addBox(1.35, 0.88, 0.14, 4.65, 1.65, -6.0, darkMat);
addBox(1.15, 0.7, 0.025, 4.65, 1.65, -5.91, screenMat);
addBox(0.22, 0.28, 0.18, 4.65, 1.23, -5.95, darkMat);
// Cabinet.
addBox(2.2, 1.7, 0.75, 7.85, 0.85, -5.88, trimMat);
addBox(0.04, 1.42, 0.03, 7.85, 0.85, -5.48, material(0x66839a));
// Planters.
function addPlant(x, z, scale = 1) {
addCylinder(0.42 * scale, 0.65 * scale, x, 0.33 * scale, z, material(0xc6b19b));
addCylinder(0.055 * scale, 1.35 * scale, x, 1.05 * scale, z, material(0x557b62), 12);
const leafMat = material(0x4e8a67);
const positions = [
[-0.25, 1.25, 0.05],
[0.27, 1.5, -0.03],
[-0.1, 1.8, 0.08],
[0.12, 2.05, -0.04]
];
positions.forEach(([dx, dy, dz], index) => {
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.42 * scale, 12, 8),
leafMat
);
leaf.scale.set(0.65, 1.15, 0.45);
leaf.rotation.z = index % 2 ? 0.55 : -0.55;
leaf.position.set(x + dx * scale, dy * scale, z + dz * scale);
leaf.castShadow = true;
scene.add(leaf);
});
}
addPlant(-8.2, -5.75, 1.05);
addPlant(8.2, 5.55, 0.95);
// Wall-mounted room sign.
const panelCanvas = document.createElement("canvas");
panelCanvas.width = 1024;
panelCanvas.height = 256;
const panelCtx = panelCanvas.getContext("2d");
panelCtx.fillStyle = "#18324a";
panelCtx.beginPath();
panelCtx.roundRect(0, 0, 1024, 256, 30);
panelCtx.fill();
panelCtx.fillStyle = "#f5f8fb";
panelCtx.font = "800 66px Inter, Arial, sans-serif";
panelCtx.fillText("STUDIO 204", 56, 94);
panelCtx.fillStyle = "#aebdca";
panelCtx.font = "600 28px Inter, Arial, sans-serif";
panelCtx.fillText("COMMON ROOM / TWO VERIFIED EXIT ROUTES", 58, 150);
panelCtx.fillStyle = "#32d583";
panelCtx.beginPath();
panelCtx.roundRect(58, 186, 212, 34, 17);
panelCtx.fill();
panelCtx.fillStyle = "#ffb020";
panelCtx.beginPath();
panelCtx.roundRect(290, 186, 212, 34, 17);
panelCtx.fill();
const panelTexture = new THREE.CanvasTexture(panelCanvas);
panelTexture.colorSpace = THREE.SRGBColorSpace;
const wallPanel = new THREE.Mesh(
new THREE.PlaneGeometry(7.8, 1.95),
new THREE.MeshBasicMaterial({ map: panelTexture })
);
wallPanel.position.set(0, 2.65, -6.88);
scene.add(wallPanel);
// ---------- Evacuation path geometry ----------
const routes = {};
function makeRibbon(curve, width, color) {
const segments = 110;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const nx = -tangent.z;
const nz = tangent.x;
positions.push(
point.x + nx * width * 0.5,
point.y,
point.z + nz * width * 0.5,
point.x - nx * width * 0.5,
point.y,
point.z - nz * width * 0.5
);
uvs.push(0, t, 1, t);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 2, a + 3, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return new THREE.Mesh(
geometry,
material(color, {
emissive: color,
emissiveIntensity: 0.13,
roughness: 0.74,
side: THREE.DoubleSide
})
);
}
function createRoute(key, points, color, css, speed, arrowOffset = 0) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, y, z]) => new THREE.Vector3(x, y, z)),
false,
"centripetal",
0.42
);
const group = new THREE.Group();
scene.add(group);
const ribbon = makeRibbon(curve, 0.78, color);
ribbon.receiveShadow = true;
group.add(ribbon);
const lineMaterial = new THREE.MeshBasicMaterial({
color: new THREE.Color(color).lerp(new THREE.Color(0xffffff), 0.55),
transparent: true,
opacity: 0.88
});
const line = new THREE.Mesh(
new THREE.TubeGeometry(curve, 120, 0.035, 8, false),
lineMaterial
);
group.add(line);
// Direction arrows.
const arrowGeometry = new THREE.ConeGeometry(0.19, 0.58, 3);
const arrowMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const arrows = [];
[0.16, 0.34, 0.53, 0.72, 0.89].forEach((base, index) => {
const t = (base + arrowOffset) % 0.97;
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
tangent.y = 0;
tangent.normalize();
arrow.position.set(point.x, 0.18, point.z);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.scale.setScalar(index % 2 === 0 ? 1 : 0.86);
group.add(arrow);
arrows.push(arrow);
});
// Moving direction markers.
const dots = [];
const dotGeometry = new THREE.SphereGeometry(0.115, 12, 8);
const dotMaterial = new THREE.MeshBasicMaterial({
color: new THREE.Color(color).lerp(new THREE.Color(0xffffff), 0.72)
});
for (let i = 0; i < 7; i++) {
const dot = new THREE.Mesh(dotGeometry, dotMaterial);
group.add(dot);
dots.push(dot);
}
routes[key] = {
curve,
group,
dots,
speed,
ribbonMaterial: ribbon.material,
lineMaterial,
visible: true
};
}
createRoute(
"primary",
[
[0, 0.055, 1.2],
[-2.4, 0.055, 1.2],
[-4.7, 0.055, 2.2],
[-7.0, 0.055, 3.35],
[-10.0, 0.055, 3.35],
[-13.0, 0.055, 3.35]
],
0x20b96b,
"#32d583",
0.072,
0
);
createRoute(
"alternate",
[
[0, 0.058, 1.2],
[2.35, 0.058, 1.0],
[4.2, 0.058, 0.2],
[6.25, 0.058, -1.8],
[7.6, 0.058, -3.35],
[10.0, 0.058, -3.35],
[13.0, 0.058, -3.35]
],
0xe69a16,
"#ffb020",
0.061,
0.07
);
// Start point marker.
const startRing = new THREE.Mesh(
new THREE.RingGeometry(0.43, 0.58, 40),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
})
);
startRing.rotation.x = -Math.PI / 2;
startRing.position.set(0, 0.075, 1.2);
scene.add(startRing);
const startCore = new THREE.Mesh(
new THREE.CircleGeometry(0.35, 32),
new THREE.MeshBasicMaterial({ color: 0x18324a })
);
startCore.rotation.x = -Math.PI / 2;
startCore.position.set(0, 0.07, 1.2);
scene.add(startCore);
const startLabel = makeBillboard(
"START",
"ASSUMED OCCUPANCY POINT",
"#d9e5ec",
2.7
);
startLabel.position.set(0, 1.08, 1.2);
scene.add(startLabel);
const primaryLabel = makeBillboard(
"PRIMARY",
"FOLLOW GREEN TO EXIT A",
"#32d583",
3.4
);
primaryLabel.position.set(-5.45, 1.28, 2.72);
scene.add(primaryLabel);
const alternateLabel = makeBillboard(
"ALTERNATE",
"FOLLOW AMBER TO EXIT B",
"#ffb020",
3.4
);
alternateLabel.position.set(5.35, 1.22, -1.85);
scene.add(alternateLabel);
// ---------- Custom camera controls ----------
const target = new THREE.Vector3(0, 0.45, 0);
let azimuth = 0.57;
let elevation = 0.88;
let zoom = 1;
const cameraRadius = 31;
function updateCamera() {
const horizontal = cameraRadius * Math.sin(elevation);
camera.position.set(
target.x + horizontal * Math.sin(azimuth),
target.y + cameraRadius * Math.cos(elevation),
target.z + horizontal * Math.cos(azimuth)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(18.6, 31.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
function resetView() {
target.set(0, 0.45, 0);
azimuth = 0.57;
elevation = 0.88;
zoom = 1;
updateCamera();
}
let drag = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
drag = {
x: event.clientX,
y: event.clientY,
mode: event.shiftKey ? "pan" : "orbit"
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (drag.mode === "orbit") {
azimuth -= dx * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + dy * 0.005,
0.38,
1.38
);
} else {
const scale = 0.018 / zoom;
const forward = new THREE.Vector3(
-Math.sin(azimuth),
0,
-Math.cos(azimuth)
);
const right = new THREE.Vector3(
Math.cos(azimuth),
0,
-Math.sin(azimuth)
);
target.addScaledVector(right, -dx * scale);
target.addScaledVector(forward, -dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -8, 8);
target.z = THREE.MathUtils.clamp(target.z, -7, 7);
}
drag.x = event.clientX;
drag.y = event.clientY;
updateCamera();
});
function endDrag(event) {
if (drag && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
drag = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.66,
2.25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset-view").addEventListener("click", resetView);
window.addEventListener("resize", resize);
// Route visibility controls.
document.querySelectorAll(".route-card").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.route;
const route = routes[key];
route.visible = !route.visible;
route.group.visible = route.visible;
button.classList.toggle("is-off", !route.visible);
button.setAttribute("aria-pressed", String(route.visible));
});
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
resize();
updateCamera();
// ---------- Animation ----------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
Object.values(routes).forEach((route, routeIndex) => {
if (!route.visible) return;
route.dots.forEach((dot, index) => {
const t = (index / route.dots.length + elapsed * route.speed) % 1;
const point = route.curve.getPointAt(t);
dot.position.set(point.x, point.y + 0.16, point.z);
const pulse = 0.78 + Math.sin(elapsed * 4 + index * 0.7) * 0.16;
dot.scale.setScalar(pulse);
});
route.ribbonMaterial.emissiveIntensity =
0.13 + Math.sin(elapsed * 2.1 + routeIndex) * 0.045;
route.lineMaterial.opacity =
0.76 + Math.sin(elapsed * 3 + routeIndex) * 0.12;
});
const startPulse = 1 + Math.sin(elapsed * 2.4) * 0.08;
startRing.scale.setScalar(startPulse);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```