Prompt specification
Build or customize the Three.js 3D scene "Clinic marker and walking radius" 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: Clinic marker and walking radius
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/clinic-marker-and-walking-radius-x1281
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts service catchment areas. Place a clinic on a flat grid and draw a distance circle. Include a wall that makes one nearby house inaccessible despite falling inside the circle. Stylized solid forms.
Working Three.js Starter (clinic-marker-and-walking-radius-x1281):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Service Catchment Area</title>
<style>
:root {
--ink: #203747;
--muted: #617783;
--panel: rgba(250, 253, 252, 0.92);
--teal: #159f96;
--teal-soft: #d8f2ed;
--red: #e45f55;
--red-soft: #fde6e2;
--line: rgba(32, 55, 71, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
top: 24px;
left: 24px;
width: min(355px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(39, 68, 80, 0.15);
backdrop-filter: blur(12px);
user-select: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.description {
margin: 12px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 9px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #405966;
font-size: 12px;
line-height: 1.3;
}
.swatch {
flex: 0 0 auto;
width: 22px;
height: 12px;
border-radius: 4px;
}
.swatch.area {
border: 1px solid rgba(21, 159, 150, 0.65);
background: rgba(21, 159, 150, 0.22);
}
.swatch.route {
height: 4px;
background: var(--teal);
}
.swatch.blocked {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--red) 0 6px,
transparent 6px 10px
);
}
.swatch.wall {
background: #3d5668;
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
padding: 10px 13px;
color: var(--ink);
background: rgba(250, 253, 252, 0.92);
box-shadow: 0 8px 24px rgba(39, 68, 80, 0.12);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
.hint {
position: fixed;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
color: #526b77;
background: rgba(250, 253, 252, 0.82);
font-size: 11px;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.panel {
top: 12px;
left: 12px;
width: min(320px, calc(100vw - 24px));
padding: 16px 17px;
}
.description {
margin-bottom: 12px;
}
.legend {
gap: 6px;
padding-top: 11px;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D service catchment area"></canvas>
<aside class="panel">
<div class="eyebrow">Health Access / 01</div>
<h1>Service Catchment</h1>
<p class="description">
The clinic serves homes within a 12-minute distance radius. One home is
geometrically inside that radius, but a full-width wall blocks every route
that remains within the catchment.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch area"></span>
<span>12-minute service distance circle</span>
</div>
<div class="legend-row">
<span class="swatch route"></span>
<span>Reachable in-radius service routes</span>
</div>
<div class="legend-row">
<span class="swatch blocked"></span>
<span>Attempted route to the blocked home</span>
</div>
<div class="legend-row">
<span class="swatch wall"></span>
<span>Wall connects to both sides of the radius</span>
</div>
</div>
</aside>
<div class="controls">
<button id="reset-view" type="button">Reset view</button>
<button id="top-view" type="button">Top view</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click 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";
// ---------------------------------------------------------------------
// Renderer, scene, camera
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e8);
scene.fog = new THREE.Fog(0xdce9e8, 38, 72);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const target = new THREE.Vector3(0, 0.5, 0);
// ---------------------------------------------------------------------
// Custom orbit controls — no external controls or addons
// ---------------------------------------------------------------------
const orbit = {
theta: 0.76,
phi: 0.79,
radius: 34,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const spherical = new THREE.Spherical(
orbit.radius,
THREE.MathUtils.clamp(orbit.phi, 0.12, 1.42),
orbit.theta
);
camera.position.copy(
new THREE.Vector3().setFromSpherical(spherical).add(target)
);
camera.lookAt(target);
}
function resetCamera() {
orbit.theta = 0.76;
orbit.phi = 0.79;
orbit.radius = 34;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
orbit.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
17,
52
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#reset-view").addEventListener("click", resetCamera);
document.querySelector("#top-view").addEventListener("click", () => {
orbit.theta = 0.76;
orbit.phi = 0.12;
orbit.radius = 31;
updateCamera();
});
updateCamera();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf7ffff, 0x84968c, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6e7, 3.1);
sun.position.set(-13, 24, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fd5df, 0.65);
fill.position.set(18, 10, -16);
scene.add(fill);
// ---------------------------------------------------------------------
// Materials and helpers
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
const mats = {
ground: material(0xe8efe9),
groundEdge: material(0xc9d8d3),
clinic: material(0xfffaf0),
clinicRoof: material(0x3d6871),
coral: material(0xe56759),
teal: material(0x159f96),
tealDark: material(0x117b76),
navy: material(0x2f485c),
wall: material(0x3d5668),
wallCap: material(0x587181),
wallSeam: material(0x304758),
white: material(0xffffff),
glass: material(0x77aeb8, {
roughness: 0.3,
metalness: 0.08
}),
wood: material(0x916b50),
leaf: material(0x5b9c78, { flatShading: true }),
leafLight: material(0x83b890, { flatShading: true }),
trunk: material(0x806550)
};
function box(parent, width, height, depth, mat, x, y, z) {
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 makeRoundedRect(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 makeLabel(
text,
{
width = 7,
foreground = "#ffffff",
background = "#284454",
accent = null
} = {}
) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 192;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
ctx.shadowColor = "rgba(20, 40, 52, 0.2)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
makeRoundedRect(ctx, 12, 12, 744, 168, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.shadowColor = "transparent";
if (accent) {
ctx.fillStyle = accent;
ctx.fillRect(12, 12, 12, 168);
}
let fontSize = 54;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
while (ctx.measureText(text).width > 680 && fontSize > 25) {
fontSize -= 2;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.fillText(text, 390, 98);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeWallSign() {
const signCanvas = document.createElement("canvas");
signCanvas.width = 640;
signCanvas.height = 360;
const ctx = signCanvas.getContext("2d");
makeRoundedRect(ctx, 12, 12, 616, 336, 34);
ctx.fillStyle = "#263d4d";
ctx.fill();
ctx.fillStyle = "#e45f55";
ctx.fillRect(12, 12, 616, 66);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 48px system-ui, sans-serif";
ctx.fillStyle = "#ffffff";
ctx.fillText("NO ACCESS", 320, 46);
ctx.font = "700 29px system-ui, sans-serif";
ctx.fillStyle = "#dce9ed";
ctx.fillText("WALL BLOCKS ALL", 320, 142);
ctx.fillText("IN-RADIUS ROUTES", 320, 188);
ctx.strokeStyle = "#e45f55";
ctx.lineWidth = 12;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(252, 240);
ctx.lineTo(388, 304);
ctx.moveTo(388, 240);
ctx.lineTo(252, 304);
ctx.stroke();
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return new THREE.Mesh(
new THREE.PlaneGeometry(3.7, 2.1),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
}
// ---------------------------------------------------------------------
// Ground, grid, and service distance circle
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(44, 44),
mats.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.09;
ground.receiveShadow = true;
scene.add(ground);
const groundEdge = box(
scene,
44.4,
0.35,
44.4,
mats.groundEdge,
0,
-0.3,
0
);
groundEdge.castShadow = false;
const grid = new THREE.GridHelper(42, 42, 0x72928d, 0xa9bbb4);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const CATCHMENT_RADIUS = 12;
const WALL_Z = 2.5;
const catchment = new THREE.Mesh(
new THREE.CircleGeometry(CATCHMENT_RADIUS, 160),
new THREE.MeshBasicMaterial({
color: 0x159f96,
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
})
);
catchment.rotation.x = -Math.PI / 2;
catchment.position.y = 0.025;
catchment.renderOrder = 1;
scene.add(catchment);
const circlePoints = [];
for (let i = 0; i <= 160; i++) {
const angle = (i / 160) * Math.PI * 2;
circlePoints.push(
new THREE.Vector3(
Math.cos(angle) * CATCHMENT_RADIUS,
0.09,
Math.sin(angle) * CATCHMENT_RADIUS
)
);
}
const circleGeometry = new THREE.BufferGeometry().setFromPoints(circlePoints);
const circleLine = new THREE.Line(
circleGeometry,
new THREE.LineDashedMaterial({
color: 0x168e86,
dashSize: 0.58,
gapSize: 0.36,
transparent: true,
opacity: 0.9
})
);
circleLine.computeLineDistances();
scene.add(circleLine);
// Cardinal tick marks help communicate the circle as a measured radius.
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const tick = box(
scene,
0.08,
0.035,
0.42,
mats.tealDark,
Math.cos(angle) * CATCHMENT_RADIUS,
0.1,
Math.sin(angle) * CATCHMENT_RADIUS
);
tick.rotation.y = -angle;
tick.castShadow = false;
}
const radiusLabel = makeLabel("12-MINUTE DISTANCE RADIUS", {
width: 8.8,
background: "#26756f"
});
radiusLabel.position.set(-6.9, 1.1, -8.8);
scene.add(radiusLabel);
// ---------------------------------------------------------------------
// Community clinic
// ---------------------------------------------------------------------
const clinic = new THREE.Group();
scene.add(clinic);
box(clinic, 5.7, 0.16, 4.5, material(0xd7e2dc), 0, 0.08, 0);
box(clinic, 4.8, 2.4, 3.4, mats.clinic, 0, 1.28, 0);
box(clinic, 5.15, 0.26, 3.75, mats.clinicRoof, 0, 2.61, 0);
// Front windows and entrance.
box(clinic, 0.82, 0.9, 0.09, mats.glass, -1.55, 1.45, 1.74);
box(clinic, 0.82, 0.9, 0.09, mats.glass, -0.55, 1.45, 1.74);
box(clinic, 0.82, 0.9, 0.09, mats.glass, 1.55, 1.45, 1.74);
box(clinic, 0.78, 1.35, 0.1, mats.navy, 0.55, 0.83, 1.75);
const canopy = box(
clinic,
1.55,
0.16,
1.2,
mats.clinicRoof,
0.55,
1.6,
2.08
);
canopy.castShadow = true;
// Medical cross on the front facade.
box(clinic, 0.34, 1.02, 0.12, mats.coral, 0, 2.02, 1.82);
box(clinic, 1.02, 0.34, 0.12, mats.coral, 0, 2.02, 1.82);
// Roof cross, readable from the elevated camera.
box(clinic, 1.55, 0.12, 0.46, mats.coral, 0, 2.81, 0);
box(clinic, 0.46, 0.12, 1.55, mats.coral, 0, 2.81, 0);
const clinicLabel = makeLabel("COMMUNITY CLINIC", {
width: 7,
background: "#244b58",
accent: "#e56759"
});
clinicLabel.position.set(0, 4.25, 0);
scene.add(clinicLabel);
// ---------------------------------------------------------------------
// Wall: a chord extending exactly from one edge of the circle to the
// other, so the clinic and the home beyond it are separated within the
// service radius.
// ---------------------------------------------------------------------
const wallHalfWidth = Math.sqrt(
CATCHMENT_RADIUS * CATCHMENT_RADIUS - WALL_Z * WALL_Z
);
const wall = new THREE.Group();
scene.add(wall);
box(
wall,
wallHalfWidth * 2,
2.2,
0.7,
mats.wall,
0,
1.15,
WALL_Z
);
box(
wall,
wallHalfWidth * 2 + 0.35,
0.18,
0.86,
mats.wallCap,
0,
2.32,
WALL_Z
);
// Strong end posts emphasize that the wall touches the catchment edge.
box(wall, 0.48, 2.55, 0.92, mats.navy, -wallHalfWidth, 1.3, WALL_Z);
box(wall, 0.48, 2.55, 0.92, mats.navy, wallHalfWidth, 1.3, WALL_Z);
// Simple panel seams.
for (let x = -wallHalfWidth + 1.8; x < wallHalfWidth - 1; x += 2.2) {
box(wall, 0.035, 1.85, 0.73, mats.wallSeam, x, 1.12, WALL_Z);
}
// Crossing marker and mounted sign.
const crossingX = 0.45;
const crossA = box(
wall,
0.13,
0.9,
0.09,
mats.coral,
crossingX,
1.05,
WALL_Z + 0.41
);
crossA.rotation.z = Math.PI / 4;
const crossB = box(
wall,
0.13,
0.9,
0.09,
mats.coral,
crossingX,
1.05,
WALL_Z + 0.41
);
crossB.rotation.z = -Math.PI / 4;
const wallSign = makeWallSign();
wallSign.position.set(crossingX, 3.25, WALL_Z + 0.43);
wall.add(wallSign);
const wallLabel = makeLabel("FULL-WIDTH ACCESS WALL", {
width: 7.3,
background: "#3d5668"
});
wallLabel.position.set(-4.8, 3.35, WALL_Z);
scene.add(wallLabel);
// ---------------------------------------------------------------------
// Stylized houses
// ---------------------------------------------------------------------
function makeHouse({
x,
z,
wallColor,
roofColor = mats.navy,
blocked = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const bodyMaterial = material(wallColor);
const selectedRoof = material(roofColor);
box(group, 3.25, 0.12, 3.0, material(0xd8e2dc), 0, 0.06, 0);
box(group, 2.45, 1.8, 2.25, bodyMaterial, 0, 1.02, 0);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.82, 1.2, 4),
selectedRoof
);
roof.position.y = 2.5;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.82;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
box(group, 0.63, 1.18, 0.09, blocked ? mats.coral : mats.navy, 0.55, 0.72, 1.16);
box(group, 0.72, 0.68, 0.09, mats.glass, -0.58, 1.1, 1.16);
box(group, 0.38, 0.72, 0.38, mats.wallCap, 0.72, 2.73, -0.28);
if (blocked) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(1.78, 1.98, 64),
new THREE.MeshBasicMaterial({
color: 0xe45f55,
transparent: true,
opacity: 0.85,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.14;
group.add(ring);
group.userData.blockedRing = ring;
}
return group;
}
const accessibleHouses = [
{
x: -5.8,
z: -4.3,
wallColor: 0xf1d7b7,
roofColor: 0xcf6b57
},
{
x: 5.3,
z: -5.2,
wallColor: 0xc9ded9,
roofColor: 0x496f77
},
{
x: -7.5,
z: -0.4,
wallColor: 0xe5e3cf,
roofColor: 0x638b70
}
];
for (let i = 0; i < accessibleHouses.length; i++) {
makeHouse(accessibleHouses[i]);
const house = accessibleHouses[i];
const label = makeLabel(`HOME 0${i + 1} · REACHED`, {
width: 4.8,
background: "#167f78"
});
label.position.set(house.x, 3.8, house.z);
scene.add(label);
}
const blockedHouse = makeHouse({
x: 3.4,
z: 6.8,
wallColor: 0xf3c8bf,
roofColor: 0xb9504c,
blocked: true
});
const blockedLabel = makeLabel("HOME 08 · INSIDE RADIUS, UNREACHABLE", {
width: 9.2,
background: "#b94f49",
accent: "#ffe1da"
});
blockedLabel.position.set(3.4, 4.65, 6.8);
scene.add(blockedLabel);
// One house outside the circle provides a visual comparison.
makeHouse({
x: 14.1,
z: 6.2,
wallColor: 0xd4d9d6,
roofColor: 0x788995
});
const outsideLabel = makeLabel("HOME 09 · OUTSIDE RADIUS", {
width: 6.8,
background: "#71818a"
});
outsideLabel.position.set(14.1, 4.3, 6.2);
scene.add(outsideLabel);
// ---------------------------------------------------------------------
// Reachable service routes
// ---------------------------------------------------------------------
const routeCurves = [];
const routeMarkers = [];
function addRoute(points, markerOffset = 0) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.35
);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 56, 0.105, 8, false),
new THREE.MeshBasicMaterial({ color: 0x159f96 })
);
scene.add(tube);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.24, 16, 12),
new THREE.MeshBasicMaterial({ color: 0x45d2c4 })
);
marker.castShadow = true;
scene.add(marker);
routeCurves.push(curve);
routeMarkers.push({ mesh: marker, offset: markerOffset });
}
addRoute(
[
[0, 0.14, 1.8],
[-2.4, 0.14, 1.2],
[-4.6, 0.14, -1.4],
[-5.8, 0.14, -3.05]
],
0
);
addRoute(
[
[0, 0.14, 1.8],
[2.2, 0.14, 1.1],
[5.2, 0.14, -1.2],
[5.3, 0.14, -3.95]
],
0.33
);
addRoute(
[
[0, 0.14, 1.8],
[-2.1, 0.14, 0.7],
[-4.8, 0.14, 0.3],
[-7.5, 0.14, 0.85]
],
0.66
);
// Attempted route toward the blocked home.
const blockedRouteStart = new THREE.Vector3(0, 0.15, 1.8);
const blockedRouteEnd = new THREE.Vector3(3.4, 0.15, 6.8);
const blockedCrossing = new THREE.Vector3(
crossingX,
0.15,
WALL_Z
);
function makeDashedLine(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.42,
gapSize: 0.25,
transparent: true,
opacity: 0.9
})
);
line.computeLineDistances();
scene.add(line);
return line;
}
makeDashedLine(
[blockedRouteStart, blockedCrossing],
0xe45f55
);
makeDashedLine(
[blockedCrossing, blockedRouteEnd],
0xe45f55
);
const blockedMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 16, 12),
new THREE.MeshBasicMaterial({ color: 0xe45f55 })
);
blockedMarker.castShadow = true;
scene.add(blockedMarker);
// ---------------------------------------------------------------------
// Simple low-poly landscaping
// ---------------------------------------------------------------------
function makeTree(x, z, scale = 1, light = false) {
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.25, 1.2, 7),
mats.trunk
);
trunk.position.y = 0.6;
trunk.castShadow = true;
group.add(trunk);
const foliage = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 0),
light ? mats.leafLight : mats.leaf
);
foliage.position.y = 1.8;
foliage.castShadow = true;
foliage.receiveShadow = true;
group.add(foliage);
scene.add(group);
}
[
[-15, -10, 1.1, false],
[-15, 5, 0.9, true],
[-13, 12, 1.15, false],
[-8.5, 14, 0.85, true],
[8.5, 14, 1.05, false],
[15, 10, 0.95, true],
[16, -6, 1.15, false],
[13, -12, 0.9, true],
[-10, -11, 0.8, false],
[9, -10, 0.85, true],
[-9.6, -7.3, 0.65, false],
[9.5, -8.2, 0.7, true]
].forEach(([x, z, scale, light]) => makeTree(x, z, scale, light));
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
routeMarkers.forEach(({ mesh, offset }) => {
const progress = (elapsed * 0.105 + offset) % 1;
const point = routeCurves[routeMarkers.indexOf(routeMarkers[0])]
? null
: null;
// Find the curve corresponding to this marker.
const index = routeMarkers.findIndex((entry) => entry.mesh === mesh);
const curve = routeCurves[index];
const position = curve.getPointAt(progress);
mesh.position.copy(position);
mesh.position.y = 0.31;
});
// Red marker travels toward the wall and then returns to the clinic.
const blockedProgress = 0.5 - 0.5 * Math.cos(elapsed * 1.25);
blockedMarker.position.lerpVectors(
blockedRouteStart,
blockedCrossing,
blockedProgress
);
blockedMarker.position.y = 0.31;
const ring = blockedHouse.userData.blockedRing;
if (ring) {
const pulse = 1 + Math.sin(elapsed * 2.2) * 0.055;
ring.scale.setScalar(pulse);
ring.material.opacity = 0.65 + Math.sin(elapsed * 2.2) * 0.2;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// ---------------------------------------------------------------------
// Resize
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```