Prompt specification
Build or customize the Three.js 3D scene "Arrange evening stalls around fixed garden paths" 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: Arrange evening stalls around fixed garden paths
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/arrange-evening-stalls-around-fixed-garden-paths-x2960
Scene Description Prompt:
Arrange fictional low-poly food stalls in Forodhani Gardens, Zanzibar, preserving entrances, seating access, and pedestrian routes. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (arrange-evening-stalls-around-fixed-garden-paths-x2960):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Forodhani Gardens — Food Court Concept</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(18, 30, 29, 0.92);
--panel-soft: rgba(31, 47, 45, 0.82);
--line: rgba(255, 255, 255, 0.13);
--text: #f7f3e8;
--muted: #b9c8c1;
--accent: #f4c76b;
--route: #4ee1cd;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #8ebfc2;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel,
.toolbar,
.note,
.detail {
position: fixed;
z-index: 5;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.panel {
top: 16px;
left: 16px;
width: min(320px, calc(100vw - 32px));
padding: 18px;
border-radius: 16px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.08;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 14px;
}
.metric {
min-height: 58px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-soft);
}
.metric strong {
display: block;
margin-bottom: 3px;
color: var(--text);
font-size: 18px;
}
.metric span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.legend {
display: grid;
gap: 8px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 12px;
}
.swatch {
width: 20px;
height: 7px;
flex: 0 0 auto;
border-radius: 99px;
}
.swatch.route { background: var(--route); }
.swatch.path { background: #ead8ae; }
.swatch.seating { background: #82b985; }
.swatch.stall { background: #ef7b76; }
.help {
margin: 13px 0 0;
color: #93aaa2;
font-size: 11px;
line-height: 1.5;
}
.toolbar {
top: 16px;
right: 16px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: min(520px, calc(100vw - 32px));
padding: 7px;
border-radius: 13px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px 12px;
color: var(--text);
background: var(--panel-soft);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
border-color: rgba(255, 255, 255, 0.28);
transform: translateY(-1px);
}
button.active,
button[aria-pressed="true"] {
color: #172521;
background: var(--accent);
border-color: var(--accent);
}
.note {
right: 16px;
bottom: 16px;
max-width: 360px;
padding: 10px 13px;
border-radius: 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.detail {
left: 16px;
bottom: 16px;
width: min(320px, calc(100vw - 32px));
padding: 15px;
border-radius: 14px;
}
.detail[hidden] { display: none !important; }
.detail-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.detail h2 {
margin: 0;
font-size: 18px;
}
.detail p {
margin: 6px 0 10px;
color: var(--muted);
font-size: 12px;
}
.detail-meta {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.chip {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 99px;
color: #d6e1dc;
font-size: 10px;
}
#closeDetail {
padding: 4px 8px;
font-size: 16px;
line-height: 1;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: #17332f;
background: #9dcdcb;
font-size: 14px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.panel {
top: 10px;
left: 10px;
width: 245px;
padding: 13px;
}
h1 { font-size: 19px; }
.subtitle { margin-bottom: 10px; font-size: 11px; }
.metrics { grid-template-columns: repeat(2, 1fr); }
.metric { min-height: 48px; padding: 7px; }
.metric strong { font-size: 15px; }
.legend, .help { display: none; }
.toolbar {
top: auto;
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
}
button {
padding: 8px 9px;
font-size: 11px;
}
.note { display: none; }
.detail {
left: 10px;
bottom: 70px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<section class="panel" aria-label="Layout information">
<p class="eyebrow">Zanzibar · Concept Plan</p>
<h1>Forodhani Food Garden</h1>
<p class="subtitle">
Twelve fictional low-poly stalls arranged around a protected pedestrian
spine, with direct access to four garden entrances.
</p>
<div class="metrics">
<div class="metric">
<strong>12</strong>
<span>Food stalls</span>
</div>
<div class="metric">
<strong>4</strong>
<span>Open entrances</span>
</div>
<div class="metric">
<strong id="conflictValue">0</strong>
<span>Route conflicts</span>
</div>
<div class="metric">
<strong>8 m</strong>
<span>Main pedestrian spine</span>
</div>
<div class="metric">
<strong>3 m</strong>
<span>Seating access spurs</span>
</div>
<div class="metric">
<strong>4</strong>
<span>Seating pockets</span>
</div>
</div>
<div class="legend" aria-label="Plan legend">
<div class="legend-row">
<span class="swatch route"></span>
<span>Protected accessible route overlay</span>
</div>
<div class="legend-row">
<span class="swatch path"></span>
<span>Pedestrian paths and entrance aprons</span>
</div>
<div class="legend-row">
<span class="swatch seating"></span>
<span>Seating pockets with clear approach</span>
</div>
<div class="legend-row">
<span class="swatch stall"></span>
<span>Food stalls set behind route edges</span>
</div>
</div>
<p class="help">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · Click a stall
for details. In Walkthrough, use W/A/S/D to move and drag to look.
</p>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="orbitView" class="active" type="button">Orbit</button>
<button id="topView" type="button">Top plan</button>
<button id="walkView" type="button">Walkthrough</button>
<button id="resetView" type="button">Reset</button>
<button id="routeToggle" type="button" aria-pressed="true">Routes</button>
<button id="labelToggle" type="button" aria-pressed="true">Labels</button>
<button id="peopleToggle" type="button" aria-pressed="true">People</button>
</nav>
<section id="detail" class="detail" hidden aria-live="polite">
<div class="detail-header">
<div>
<h2 id="detailTitle"></h2>
<p id="detailDescription"></p>
</div>
<button id="closeDetail" type="button" aria-label="Close stall details">×</button>
</div>
<div class="detail-meta">
<span id="detailZone" class="chip"></span>
<span id="detailAccess" class="chip"></span>
<span id="detailFootprint" class="chip"></span>
</div>
</section>
<div class="note">
Conceptual arrangement—not a surveyed or regulatory drawing. Verify the
garden boundary, entrances, accessibility requirements, utilities, and
local approvals before implementation.
</div>
<div id="loading">Building the food garden…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bcdca);
scene.fog = new THREE.Fog(0x9bcdca, 125, 230);
const camera = new THREE.PerspectiveCamera(
48,
innerWidth / innerHeight,
0.1,
350
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xffe9c7, 0x476b63, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd6a0, 2.7);
sun.position.set(-48, 78, 35);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -85;
sun.shadow.camera.right = 85;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 180;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaee9ed, 0.8);
fill.position.set(55, 35, -50);
scene.add(fill);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xbfa775,
roughness: 1,
flatShading: true
}),
path: new THREE.MeshStandardMaterial({
color: 0xe8d5aa,
roughness: 0.95,
flatShading: true
}),
pathAccent: new THREE.MeshStandardMaterial({
color: 0xf1e1bb,
roughness: 0.95,
flatShading: true
}),
wall: new THREE.MeshStandardMaterial({
color: 0xc5b899,
roughness: 0.95,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x624631,
roughness: 0.92,
flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x342b27,
roughness: 0.88,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xfff1cf,
roughness: 0.85,
flatShading: true
}),
greenery: new THREE.MeshStandardMaterial({
color: 0x4e8f65,
roughness: 1,
flatShading: true
}),
planter: new THREE.MeshStandardMaterial({
color: 0x52745c,
roughness: 1,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x66716d,
roughness: 0.58,
metalness: 0.45,
flatShading: true
}),
route: new THREE.MeshBasicMaterial({
color: 0x42e1cc,
transparent: true,
opacity: 0.88,
depthWrite: false
})
};
const garden = new THREE.Group();
scene.add(garden);
const protectedPaths = new THREE.Group();
const routeOverlay = new THREE.Group();
const peopleGroup = new THREE.Group();
const labels = [];
const stallGroups = [];
garden.add(protectedPaths, routeOverlay, peopleGroup);
function addBox(parent, w, h, d, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
rTop,
rBottom,
height,
x,
y,
z,
material,
segments = 8,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addPath(w, d, x, z, material = materials.path) {
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, d), material);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.035, z);
mesh.receiveShadow = true;
protectedPaths.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeTextSprite(text, subtitle = "", accent = "#f4c76b") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 176;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 624, 160, 22);
ctx.fillStyle = "rgba(22, 34, 32, 0.91)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#fff7df";
ctx.font = "800 39px system-ui, sans-serif";
ctx.fillText(text, 320, subtitle ? 61 : 88, 590);
if (subtitle) {
ctx.fillStyle = "#c8d7d0";
ctx.font = "600 24px system-ui, sans-serif";
ctx.fillText(subtitle, 320, 117, 590);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: true
})
);
sprite.scale.set(7.2, 1.98, 1);
sprite.renderOrder = 8;
return sprite;
}
function dashedLine(x1, z1, x2, z2, width = 0.18, dash = 2.2, gap = 1.5) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
for (let distance = 0; distance < length; distance += dash + gap) {
const segmentLength = Math.min(dash, length - distance);
if (segmentLength <= 0) break;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.045, segmentLength),
materials.route
);
mesh.position.set(
x1 + (dx / length) * (distance + segmentLength / 2),
0.105,
z1 + (dz / length) * (distance + segmentLength / 2)
);
mesh.rotation.y = angle;
routeOverlay.add(mesh);
}
}
function entranceRing(x, z) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(2.15, 2.55, 32),
materials.route
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.105, z);
routeOverlay.add(ring);
}
// Garden base and primary pedestrian network.
addBox(garden, 120, 0.7, 82, 0, -0.35, 0, materials.ground);
addPath(116, 8, 0, 0); // East-west primary spine
addPath(8, 76, 0, 0); // North-south primary spine
addPath(104, 3.4, 0, -34); // North promenade
addPath(104, 3.4, 0, 34); // South promenade
addPath(3.4, 64.6, -52, 0); // West promenade
addPath(3.4, 64.6, 52, 0); // East promenade
// Seating spurs: 3 m wide and connected directly to the main spine.
for (const x of [-20, 20]) {
for (const z of [-7.75, 7.75]) {
addPath(3, 7.5, x, z, materials.pathAccent);
}
}
dashedLine(-56, 0, 56, 0);
dashedLine(0, -36, 0, 36);
dashedLine(-51, -34, 51, -34);
dashedLine(-51, 34, 51, 34);
dashedLine(-52, -33, -52, 33);
dashedLine(52, -33, 52, 33);
entranceRing(0, -38);
entranceRing(-58, 0);
entranceRing(58, 0);
entranceRing(0, 38);
// Boundary walls, interrupted at each entrance.
for (const z of [-38, 38]) {
addBox(garden, 53, 1.35, 0.5, -31.5, 0.65, z, materials.wall);
addBox(garden, 53, 1.35, 0.5, 31.5, 0.65, z, materials.wall);
}
for (const x of [-58, 58]) {
addBox(garden, 0.5, 1.35, 33, x, 0.65, -21.5, materials.wall);
addBox(garden, 0.5, 1.35, 33, x, 0.65, 21.5, materials.wall);
}
function createGate(x, z, axis, primary = false) {
const gate = new THREE.Group();
gate.position.set(x, 0, z);
if (axis === "z") {
addBox(gate, 0.42, 3.6, 0.42, 0, 1.8, -4.7, materials.wood);
addBox(gate, 0.42, 3.6, 0.42, 0, 1.8, 4.7, materials.wood);
addBox(gate, 0.42, 0.38, 10, 0, 3.45, 0, materials.wood);
} else {
addBox(gate, 0.42, 3.6, 0.42, -4.7, 1.8, 0, materials.wood);
addBox(gate, 0.42, 3.6, 0.42, 4.7, 1.8, 0, materials.wood);
addBox(gate, 10, 0.38, 0.42, 0, 3.45, 0, materials.wood);
}
const sign = makeTextSprite(
primary ? "MAIN STREET ENTRY" : "GARDEN GATE",
primary ? "Primary public access" : "Secondary open access",
primary ? "#f4c76b" : "#4ee1cd"
);
sign.position.set(0, 4.55, 0);
sign.scale.set(7.4, 2.05, 1);
gate.add(sign);
labels.push(sign);
garden.add(gate);
}
createGate(0, -38, "x", true);
createGate(-58, 0, "z");
createGate(58, 0, "z");
createGate(0, 38, "x");
// Corner planting beds.
const bedMaterial = new THREE.MeshStandardMaterial({
color: 0x5d845d,
roughness: 1,
flatShading: true
});
for (const x of [-45, 45]) {
for (const z of [-30, 30]) {
const bed = addBox(garden, 16, 0.14, 5, x, 0.02, z, bedMaterial, false);
bed.receiveShadow = true;
}
}
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addCylinder(tree, 0.35, 0.52, 3.3, 0, 1.65, 0, materials.wood, 6);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(0.36, 0.34, 0.36 + Math.random() * 0.07),
roughness: 1,
flatShading: true
});
const canopy = new THREE.Mesh(
new THREE.DodecahedronGeometry(2.65, 0),
canopyMaterial
);
canopy.position.set(0, 3.8, 0);
canopy.scale.set(1, 1.12, 0.9);
canopy.rotation.set(0.1, Math.random() * 2, 0.08);
canopy.castShadow = true;
tree.add(canopy);
const lower = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.8, 0),
canopyMaterial
);
lower.position.set(0.55, 3.05, 0.2);
lower.scale.set(1.1, 0.8, 0.9);
lower.castShadow = true;
tree.add(lower);
garden.add(tree);
}
[
[-48, -30], [-27, -30], [-12, -30], [12, -30], [27, -30], [48, -30],
[-48, 30], [-27, 30], [-12, 30], [12, 30], [27, 30], [48, 30],
[-47.5, -10], [-47.5, 10], [47.5, -10], [47.5, 10]
].forEach(([x, z], i) => createTree(x, z, 0.88 + (i % 4) * 0.06));
// Low-poly seating pockets.
function createChair(parent, x, z, angle) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
chair.rotation.y = angle;
const seatMaterial = new THREE.MeshStandardMaterial({
color: 0xb96f45,
roughness: 0.85,
flatShading: true
});
addBox(chair, 0.9, 0.14, 0.9, 0, 0.65, 0, seatMaterial);
addBox(chair, 0.9, 0.75, 0.13, 0, 1.02, -0.38, seatMaterial);
for (const lx of [-0.33, 0.33]) {
for (const lz of [-0.3, 0.3]) {
addBox(chair, 0.09, 0.62, 0.09, lx, 0.31, lz, materials.darkWood);
}
}
parent.add(chair);
}
function createSeatingPocket(x, z) {
const pocket = new THREE.Group();
const pad = new THREE.Mesh(
new THREE.CircleGeometry(5.5, 24),
new THREE.MeshStandardMaterial({
color: 0x9dbb88,
roughness: 1,
flatShading: true
})
);
pad.rotation.x = -Math.PI / 2;
pad.position.y = 0.075;
pad.receiveShadow = true;
pocket.add(pad);
addCylinder(pocket, 1.25, 1.25, 0.18, 0, 1.0, 0, materials.cream, 12);
addCylinder(pocket, 0.16, 0.23, 0.95, 0, 0.48, 0, materials.metal, 8);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
createChair(
pocket,
Math.cos(angle) * 2.7,
Math.sin(angle) * 2.7,
-angle - Math.PI / 2
);
}
garden.add(pocket);
}
for (const x of [-20, 20]) {
for (const z of [-12.5, 12.5]) {
createSeatingPocket(x, z);
}
}
function createBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
const seatMaterial = new THREE.MeshStandardMaterial({
color: 0x8f5d39,
roughness: 0.9,
flatShading: true
});
addBox(bench, 3.5, 0.18, 0.78, 0, 0.72, 0, seatMaterial);
addBox(bench, 3.5, 0.75, 0.14, 0, 1.08, -0.32, seatMaterial);
addBox(bench, 0.22, 0.7, 0.65, -1.25, 0.35, 0, materials.darkWood);
addBox(bench, 0.22, 0.7, 0.65, 1.25, 0.35, 0, materials.darkWood);
garden.add(bench);
}
createBench(-10, -29);
createBench(10, -29);
createBench(-10, 29);
createBench(10, 29);
// A small number of decorative lamps, all outside the clear route width.
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0x35413f,
roughness: 0.6,
metalness: 0.35
});
const lampGlow = new THREE.MeshStandardMaterial({
color: 0xffd77d,
emissive: 0xffa62f,
emissiveIntensity: 2.4,
roughness: 0.5
});
for (const [x, z] of [
[-6, -14], [6, -14], [-6, 14], [6, 14],
[-15, -6], [15, -6], [-15, 6], [15, 6]
]) {
addCylinder(garden, 0.1, 0.15, 3.4, x, 1.7, z, lampMaterial, 8);
addBox(garden, 0.7, 0.85, 0.7, x, 3.55, z, lampGlow);
addBox(garden, 0.9, 0.12, 0.9, x, 4.02, z, lampMaterial);
}
const stalls = [
{
id: "N1", name: "Manda Moon", dish: "Coconut fish stew",
x: -36, z: -24, rotation: 0, color: 0xe65f6f, kind: "manda",
zone: "North row"
},
{
id: "N2", name: "Zanzibar Pizza", dish: "Street-style baked pizza",
x: -21, z: -24, rotation: 0, color: 0xf2a84f, kind: "pizza",
zone: "North row"
},
{
id: "N3", name: "Tandoori Nights", dish: "Spiced skewers and flatbread",
x: 21, z: -24, rotation: 0, color: 0x8e65bd, kind: "skewer",
zone: "North row"
},
{
id: "N4", name: "Spice Garden", dish: "Spiced rice and vegetable plates",
x: 36, z: -24, rotation: 0, color: 0x4d9b75, kind: "rice",
zone: "North row"
},
{
id: "S1", name: "Mishkaki Point", dish: "Grilled meat and chutney",
x: -36, z: 24, rotation: Math.PI, color: 0xf08a4b, kind: "skewer",
zone: "South row"
},
{
id: "S2", name: "Fresh Catch", dish: "Grilled reef fish",
x: -21, z: 24, rotation: Math.PI, color: 0x4d91c1, kind: "fish",
zone: "South row"
},
{
id: "S3", name: "Juice Sun", dish: "Tropical fruit and sugarcane juice",
x: 21, z: 24, rotation: Math.PI, color: 0xf2c84b, kind: "juice",
zone: "South row"
},
{
id: "S4", name: "Chapati Club", dish: "Chapati rolls and spicy sauces",
x: 36, z: 24, rotation: Math.PI, color: 0xd76d94, kind: "chapati",
zone: "South row"
},
{
id: "W1", name: "Coconut Coffee", dish: "Coffee, tea and coconut sweets",
x: -44, z: -18, rotation: Math.PI / 2, color: 0x8d6a54, kind: "coffee",
zone: "West row"
},
{
id: "W2", name: "Urojo House", dish: "Spiced fried dough bowls",
x: -44, z: 18, rotation: Math.PI / 2, color: 0xc8703d, kind: "urojo",
zone: "West row"
},
{
id: "E1", name: "Sweet Palm", dish: "Coconut cakes and halwa",
x: 44, z: -18, rotation: -Math.PI / 2, color: 0xe7a94c, kind: "sweet",
zone: "East row"
},
{
id: "E2", name: "Skewer Street", dish: "Charcoal-grilled vegetable skewers",
x: 44, z: 18, rotation: -Math.PI / 2, color: 0x59a66d, kind: "vegetable",
zone: "East row"
}
];
function makeRoof(width, depth, eaveY, ridgeY) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-width / 2, eaveY, -depth / 2,
width / 2, eaveY, -depth / 2,
0, ridgeY, -depth / 2,
-width / 2, eaveY, depth / 2,
width / 2, eaveY, depth / 2,
0, ridgeY, depth / 2
], 3)
);
geometry.setIndex([
0, 1, 2,
3, 5, 4,
0, 2, 5,
0, 5, 3,
1, 4, 5,
1, 5, 2
]);
geometry.computeVertexNormals();
return geometry;
}
const roofGeometry = makeRoof(8.2, 6.2, 2.78, 4.12);
function addFoodProps(group, kind, colorMaterial) {
const counterY = 1.18;
if (kind === "manda") {
addCylinder(group, 0.52, 0.42, 0.62, 0, counterY + 0.31, 1.35, colorMaterial, 10);
addCylinder(group, 0.57, 0.57, 0.08, 0, counterY + 0.66, 1.35, materials.metal, 10);
for (const x of [-1.8, -1.2, 1.4, 2]) {
addCylinder(group, 0.23, 0.18, 0.15, x, counterY + 0.08, 1.35, materials.cream, 8);
}
} else if (kind === "pizza") {
for (const x of [-1.5, 0.2, 1.8]) {
const pizza = new THREE.Mesh(
new THREE.CircleGeometry(0.42, 12),
new THREE.MeshStandardMaterial({
color: 0xe5ad4e,
roughness: 0.9,
flatShading: true
})
);
pizza.rotation.x = -Math.PI / 2;
pizza.position.set(x, counterY + 0.025, 1.4);
group.add(pizza);
for (const dx of [-0.12, 0.12]) {
const topping = new THREE.Mesh(
new THREE.CircleGeometry(0.08, 8),
new THREE.MeshStandardMaterial({ color: 0xc74e46 })
);
topping.rotation.x = -Math.PI / 2;
topping.position.set(x + dx, counterY + 0.045, 1.4);
group.add(topping);
}
}
} else if (kind === "skewer" || kind === "vegetable") {
addBox(group, 2.4, 0.24, 0.85, 0, counterY + 0.08, 1.4, materials.darkWood);
for (let i = 0; i < 5; i++) {
const skewer = addCylinder(
group, 0.035, 0.035, 2.0, -0.8 + i * 0.4,
counterY + 0.32, 1.4, materials.cream, 6
);
skewer.rotation.z = Math.PI / 2;
}
} else if (kind === "fish") {
for (const x of [-1.6, 0, 1.6]) {
const fish = new THREE.Mesh(
new THREE.SphereGeometry(0.4, 8, 5),
new THREE.MeshStandardMaterial({
color: 0x91b7bd,
roughness: 0.7,
flatShading: true
})
);
fish.scale.set(1.7, 0.55, 0.7);
fish.position.set(x, counterY + 0.22, 1.4);
fish.castShadow = true;
group.add(fish);
}
} else if (kind === "juice") {
for (let i = 0; i < 6; i++) {
const x = -1.9 + i * 0.76;
const cup = addCylinder(
group, 0.18, 0.14, 0.55, x, counterY + 0.28, 1.4, materials.cream, 8
);
cup.material = new THREE.MeshStandardMaterial({
color: i % 2 ? 0xf2a63b : 0xe5584f,
roughness: 0.65,
flatShading: true
});
addCylinder(group, 0.025, 0.025, 0.55, x + 0.08, counterY + 0.72, 1.4, materials.cream, 5);
}
} else if (kind === "coffee") {
for (const x of [-1.6, -0.6, 0.6, 1.6]) {
addCylinder(group, 0.2, 0.15, 0.34, x, counterY + 0.17, 1.4, materials.cream, 8);
addCylinder(group, 0.19, 0.19, 0.035, x, counterY + 0.37, 1.4, materials.darkWood, 8);
}
} else if (kind === "chapati") {
for (let i = 0; i < 5; i++) {
addCylinder(
group, 0.48, 0.48, 0.07, -1.6 + i * 0.8,
counterY + 0.05 + i * 0.015, 1.4, materials.cream, 12
);
}
} else if (kind === "sweet") {
for (const x of [-1.5, 0, 1.5]) {
addBox(group, 0.8, 0.32, 0.65, x, counterY + 0.16, 1.4, colorMaterial);
}
} else if (kind === "urojo") {
for (const x of [-1.5, 0, 1.5]) {
addCylinder(group, 0.42, 0.25, 0.34, x, counterY + 0.17, 1.4, materials.cream, 10);
}
} else {
addBox(group, 2.5, 0.28, 0.8, 0, counterY + 0.14, 1.4, colorMaterial);
}
}
function createStall(stall) {
const group = new THREE.Group();
group.position.set(stall.x, 0, stall.z);
group.rotation.y = stall.rotation;
group.userData.stall = stall;
const colorMaterial = new THREE.MeshStandardMaterial({
color: stall.color,
roughness: 0.76,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: stall.color,
roughness: 0.72,
side: THREE.DoubleSide,
flatShading: true
});
addBox(group, 7.9, 0.24, 5.2, 0, 0.12, 0, materials.wood);
addBox(group, 7.3, 2.45, 0.18, 0, 1.45, -2.15, materials.darkWood);
addBox(group, 0.18, 2.45, 4.2, -3.55, 1.45, 0, materials.wood);
addBox(group, 0.18, 2.45, 4.2, 3.55, 1.45, 0, materials.wood);
addBox(group, 6.7, 1.02, 1.05, 0, 0.65, 1.7, colorMaterial);
addBox(group, 7.0, 0.16, 1.28, 0, 1.22, 1.7, materials.cream);
for (const x of [-3.5, 3.5]) {
for (const z of [-2.25, 2.4]) {
addBox(group, 0.16, 3.15, 0.16, x, 1.62, z, materials.wood);
}
}
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = 0.02;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
for (let i = 0; i < 8; i++) {
const stripeMaterial = i % 2 ? materials.cream : colorMaterial;
addBox(
group,
0.72,
0.52,
0.12,
-3.15 + i * 0.9,
2.58,
3.06,
stripeMaterial
);
}
// Front placard.
addBox(group, 5.8, 0.88, 0.16, 0, 2.55, 2.38, colorMaterial);
addBox(group, 4.7, 0.08, 0.03, 0, 2.55, 2.48, materials.cream);
// A menu board beside each counter.
addBox(group, 1.25, 1.65, 0.14, -2.6, 1.12, 2.6, materials.darkWood);
for (let i = 0; i < 4; i++) {
addBox(group, 0.72, 0.04, 0.02, -2.6, 1.62 - i * 0.26, 2.69, materials.cream);
}
addFoodProps(group, stall.kind, colorMaterial);
// Warm decorative lanterns under the canopy.
for (const x of [-2.3, 0, 2.3]) {
const glow = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 8, 6),
new THREE.MeshStandardMaterial({
color: 0xffd98d,
emissive: 0xffa737,
emissiveIntensity: 2.8,
roughness: 0.5
})
);
glow.position.set(x, 2.43, 1.9);
group.add(glow);
}
const label = makeTextSprite(
stall.name,
stall.dish,
"#" + stall.color.toString(16).padStart(6, "0")
);
label.position.set(0, 5.15, 0);
group.add(label);
labels.push(label);
garden.add(group);
stallGroups.push(group);
return group;
}
stalls.forEach(createStall);
// Decorative visitors. These are not route obstructions.
let randomSeed = 2026;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function createPerson(x, z, rotation = 0, scale = 1) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = rotation;
person.scale.setScalar(scale);
const shirt = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(random(), 0.48, 0.47),
roughness: 0.85,
flatShading: true
});
const skin = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(0.075, 0.38, 0.34 + random() * 0.16),
roughness: 0.9,
flatShading: true
});
addCylinder(person, 0.24, 0.3, 0.82, 0, 1.0, 0, shirt, 7);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.24, 8, 6), skin);
head.position.y = 1.61;
head.castShadow = true;
person.add(head);
addCylinder(person, 0.09, 0.11, 0.58, -0.13, 0.29, 0, materials.darkWood, 6);
addCylinder(person, 0.09, 0.11, 0.58, 0.13, 0.29, 0, materials.darkWood, 6);
const armA = addCylinder(person, 0.075, 0.075, 0.62, -0.32, 1.0, 0, shirt, 6);
const armB = addCylinder(person, 0.075, 0.075, 0.62, 0.32, 1.0, 0, shirt, 6);
armA.rotation.z = -0.14;
armB.rotation.z = 0.14;
peopleGroup.add(person);
}
for (const stall of stalls) {
const group = stallGroups.find(g => g.userData.stall === stall);
group.updateMatrixWorld(true);
for (let i = 0; i < 2; i++) {
const local = new THREE.Vector3(i === 0 ? -1.45 : 1.25, 0, 4.15 + random() * 0.55);
group.localToWorld(local);
createPerson(local.x, local.z, group.rotation.y + Math.PI, 0.9 + random() * 0.15);
}
}
for (const x of [-20, 20]) {
for (const z of [-12.5, 12.5]) {
for (let i = 0; i < 3; i++) {
const angle = random() * Math.PI * 2;
const radius = 1.4 + random() * 3.3;
createPerson(
x + Math.cos(angle) * radius,
z + Math.sin(angle) * radius,
random() * Math.PI * 2,
0.92 + random() * 0.12
);
}
}
}
// Route-clearance audit using conservative orthogonal footprints.
const protectedZones = [
{ name: "Main east-west route", minX: -58, maxX: 58, minZ: -4, maxZ: 4 },
{ name: "Main north-south route", minX: -4, maxX: 4, minZ: -38, maxZ: 38 },
{ name: "North promenade", minX: -52, maxX: 52, minZ: -35.7, maxZ: -32.3 },
{ name: "South promenade", minX: -52, maxX: 52, minZ: 32.3, maxZ: 35.7 },
{ name: "West promenade", minX: -53.7, maxX: -50.3, minZ: -32, maxZ: 32 },
{ name: "East promenade", minX: 50.3, maxX: 53.7, minZ: -32, maxZ: 32 },
{ name: "North entrance", minX: -5, maxX: 5, minZ: -38, maxZ: -30 },
{ name: "South entrance", minX: -5, maxX: 5, minZ: 30, maxZ: 38 },
{ name: "West entrance", minX: -58, maxX: -49, minZ: -5, maxZ: 5 },
{ name: "East entrance", minX: 49, maxX: 58, minZ: -5, maxZ: 5 },
{ name: "Northwest seating", minX: -25.5, maxX: -14.5, minZ: -18, maxZ: -7 },
{ name: "Northeast seating", minX: 14.5, maxX: 25.5, minZ: -18, maxZ: -7 },
{ name: "Southwest seating", minX: -25.5, maxX: -14.5, minZ: 7, maxZ: 18 },
{ name: "Southeast seating", minX: 14.5, maxX: 25.5, minZ: 7, maxZ: 18 }
];
function footprint(stall) {
const width = 7.9;
const depth = 5.2;
const rotated = Math.abs(Math.sin(stall.rotation)) > 0.5;
const halfX = rotated ? depth / 2 : width / 2;
const halfZ = rotated ? width / 2 : depth / 2;
return {
minX: stall.x - halfX,
maxX: stall.x + halfX,
minZ: stall.z - halfZ,
maxZ: stall.z + halfZ
};
}
function overlaps(a, b) {
return (
a.minX < b.maxX &&
a.maxX > b.minX &&
a.minZ < b.maxZ &&
a.maxZ > b.minZ
);
}
const conflicts = [];
for (const stall of stalls) {
const box = footprint(stall);
for (const zone of protectedZones) {
if (overlaps(box, zone)) {
conflicts.push(`${stall.id} / ${zone.name}`);
}
}
}
const conflictValue = document.getElementById("conflictValue");
conflictValue.textContent = String(conflicts.length);
conflictValue.style.color = conflicts.length ? "#ff7676" : "#f4c76b";
// North arrow.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 4.4);
arrowShape.lineTo(2.2, -2.8);
arrowShape.lineTo(0, -1.4);
arrowShape.lineTo(-2.2, -2.8);
arrowShape.closePath();
const arrow = new THREE.Mesh(
new THREE.ShapeGeometry(arrowShape),
new THREE.MeshBasicMaterial({ color: 0x315b55, side: THREE.DoubleSide })
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(45, 0.12, 25);
garden.add(arrow);
const northLabel = makeTextSprite("N", "North / street edge", "#f4c76b");
northLabel.position.set(45, 1.0, 29.5);
northLabel.scale.set(4.4, 1.3, 1);
garden.add(northLabel);
labels.push(northLabel);
// Selection marker.
const selectionGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(8.35, 0.15, 5.55)
);
const selectionMarker = new THREE.LineSegments(
selectionGeometry,
new THREE.LineBasicMaterial({ color: 0xffd166 })
);
selectionMarker.visible = false;
scene.add(selectionMarker);
const detail = document.getElementById("detail");
const detailTitle = document.getElementById("detailTitle");
const detailDescription = document.getElementById("detailDescription");
const detailZone = document.getElementById("detailZone");
const detailAccess = document.getElementById("detailAccess");
const detailFootprint = document.getElementById("detailFootprint");
function selectStall(stall) {
selectionMarker.visible = true;
selectionMarker.position.set(stall.x, 0.16, stall.z);
selectionMarker.rotation.y = stall.rotation;
detailTitle.textContent = stall.name;
detailDescription.textContent = stall.dish;
detailZone.textContent = stall.zone;
detailAccess.textContent = "Faces a clear pedestrian route";
detailFootprint.textContent = "7.9 × 5.2 m stall";
detail.hidden = false;
}
document.getElementById("closeDetail").addEventListener("click", () => {
detail.hidden = true;
selectionMarker.visible = false;
});
// Custom camera controls; no examples/addons are loaded.
const orbit = {
radius: 108,
theta: 0.68,
phi: 0.88,
target: new THREE.Vector3(0, 0, 0)
};
const walk = {
position: new THREE.Vector3(-55, 2.1, 0),
yaw: Math.PI / 2,
pitch: 0
};
let cameraMode = "orbit";
const keys = new Set();
function updateCamera() {
if (cameraMode === "orbit") {
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.setFromSpherical(spherical).add(orbit.target);
camera.lookAt(orbit.target);
} else {
const direction = new THREE.Vector3(
Math.sin(walk.yaw) * Math.cos(walk.pitch),
Math.sin(walk.pitch),
-Math.cos(walk.yaw) * Math.cos(walk.pitch)
);
camera.position.copy(walk.position);
camera.lookAt(walk.position.clone().add(direction));
}
}
function setActiveButton(id) {
["orbitView", "topView", "walkView"].forEach(buttonId => {
document.getElementById(buttonId).classList.toggle(
"active",
buttonId === id
);
});
}
function setCameraMode(mode) {
cameraMode = mode;
if (mode === "orbit") {
setActiveButton("orbitView");
} else if (mode === "walk") {
setActiveButton("walkView");
}
updateCamera();
}
document.getElementById("orbitView").addEventListener("click", () => {
setCameraMode("orbit");
});
document.getElementById("topView").addEventListener("click", () => {
cameraMode = "orbit";
orbit.radius = 112;
orbit.theta = 0.001;
orbit.phi = 0.075;
orbit.target.set(0, 0, 0);
setActiveButton("topView");
updateCamera();
});
document.getElementById("walkView").addEventListener("click", () => {
walk.position.set(-55, 2.1, 0);
walk.yaw = Math.PI / 2;
walk.pitch = 0;
setCameraMode("walk");
});
document.getElementById("resetView").addEventListener("click", () => {
orbit.radius = 108;
orbit.theta = 0.68;
orbit.phi = 0.88;
orbit.target.set(0, 0, 0);
cameraMode = "orbit";
setActiveButton("orbitView");
updateCamera();
});
document.getElementById("routeToggle").addEventListener("click", event => {
routeOverlay.visible = !routeOverlay.visible;
event.currentTarget.setAttribute(
"aria-pressed",
String(routeOverlay.visible)
);
});
document.getElementById("labelToggle").addEventListener("click", event => {
const visible = !labels[0].visible;
labels.forEach(label => label.visible = visible);
event.currentTarget.setAttribute("aria-pressed", String(visible));
});
document.getElementById("peopleToggle").addEventListener("click", event => {
peopleGroup.visible = !peopleGroup.visible;
event.currentTarget.setAttribute(
"aria-pressed",
String(peopleGroup.visible)
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointers = new Map();
let dragDistance = 0;
let lastPinchDistance = null;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragDistance = 0;
lastPinchDistance = null;
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * lastPinchDistance / distance,
24,
165
);
}
lastPinchDistance = distance;
} else {
dragDistance += Math.abs(dx) + Math.abs(dy);
if (cameraMode === "orbit" && (event.button === 2 || event.shiftKey)) {
const panScale = orbit.radius * 0.00125;
const right = new THREE.Vector3(
Math.cos(orbit.theta),
0,
-Math.sin(orbit.theta)
);
const forward = new THREE.Vector3(
-Math.sin(orbit.theta),
0,
-Math.cos(orbit.theta)
);
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(forward, -dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -55, 55);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -38, 38);
} else if (cameraMode === "orbit") {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.006,
0.075,
1.43
);
} else {
walk.yaw += dx * 0.004;
walk.pitch = THREE.MathUtils.clamp(
walk.pitch - dy * 0.004,
-0.85,
0.85
);
}
}
previous.x = event.clientX;
previous.y = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
const wasClick = dragDistance < 6 && event.button === 0 && pointers.size === 1;
pointers.delete(event.pointerId);
lastPinchDistance = null;
if (wasClick) {
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(stallGroups, true);
if (intersections.length) {
let object = intersections[0].object;
while (object && !object.userData.stall) {
object = object.parent;
}
if (object?.userData.stall) {
selectStall(object.userData.stall);
}
}
}
});
renderer.domElement.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
lastPinchDistance = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
if (cameraMode === "orbit") {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
24,
165
);
}
}, { passive: false });
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
keys.add(key);
if (cameraMode === "orbit") {
if (key === "arrowleft") orbit.theta += 0.08;
if (key === "arrowright") orbit.theta -= 0.08;
if (key === "arrowup") orbit.phi = Math.max(0.075, orbit.phi - 0.06);
if (key === "arrowdown") orbit.phi = Math.min(1.43, orbit.phi + 0.06);
if (key === "+" || key === "=") orbit.radius = Math.max(24, orbit.radius - 4);
if (key === "-") orbit.radius = Math.min(165, orbit.radius + 4);
}
});
window.addEventListener("keyup", event => {
keys.delete(event.key.toLowerCase());
});
window.addEventListener("blur", () => keys.clear());
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (cameraMode === "walk") {
const forwardInput =
Number(keys.has("w")) - Number(keys.has("s"));
const sideInput =
Number(keys.has("d")) - Number(keys.has("a"));
const forward = new THREE.Vector3(
Math.sin(walk.yaw),
0,
-Math.cos(walk.yaw)
);
const right = new THREE.Vector3(
Math.cos(walk.yaw),
0,
Math.sin(walk.yaw)
);
const movement = forward.multiplyScalar(forwardInput)
.add(right.multiplyScalar(sideInput));
if (movement.lengthSq() > 0) {
movement.normalize().multiplyScalar(7.5 * delta);
walk.position.add(movement);
walk.position.x = THREE.MathUtils.clamp(walk.position.x, -56, 56);
walk.position.z = THREE.MathUtils.clamp(walk.position.z, -36, 36);
walk.position.y = 2.1;
}
}
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```