Prompt specification
Build or customize the Three.js 3D scene "Rearrange market counters while preserving circulation" 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: Rearrange market counters while preserving circulation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rearrange-market-counters-while-preserving-circulation-x2768
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the French Market in New Orleans. Let users change temporary counter positions in a schematic market segment. Highlight accessible routes, blocked openings, and delivery conflicts without modifying the referenced permanent architecture. Voxel style.
Working Three.js Starter (rearrange-market-counters-while-preserving-circulation-x2768):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>French Market — Temporary Fixture Lab</title>
<style>
:root {
--ink: #183d37;
--ink-2: #315a52;
--paper: #f7f2e7;
--paper-2: #eee6d7;
--line: #d6ccbb;
--coral: #e36d4c;
--green: #1d9a69;
--green-soft: #d9eee4;
--amber: #e6a13b;
--amber-soft: #fae9c9;
--red: #c94f47;
--red-soft: #f5d9d4;
--white: #fffdf7;
--shadow: 0 14px 40px rgba(31, 51, 45, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#app {
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
width: 100%;
height: 100%;
}
aside {
position: relative;
z-index: 5;
min-width: 0;
overflow: auto;
background: var(--paper);
border-right: 1px solid var(--line);
box-shadow: 10px 0 30px rgba(27, 49, 44, 0.08);
}
.masthead {
padding: 22px 22px 18px;
color: var(--white);
background:
linear-gradient(135deg, rgba(255,255,255,.06), transparent 55%),
var(--ink);
border-bottom: 4px solid var(--coral);
}
.eyebrow {
margin-bottom: 7px;
color: #bcd4ca;
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 600;
line-height: 1;
letter-spacing: -.02em;
}
.masthead p {
margin: 9px 0 0;
color: #c9dad3;
font-size: 12px;
line-height: 1.45;
}
.panel-section {
padding: 17px 20px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--ink-2);
font-size: 10px;
font-weight: 850;
letter-spacing: .15em;
text-transform: uppercase;
}
.section-heading span {
color: #80938c;
font-size: 9px;
letter-spacing: .09em;
}
.scenario-card {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 12px;
padding: 13px;
background: var(--white);
border: 1px solid var(--line);
border-radius: 10px;
box-shadow: 0 4px 14px rgba(40, 55, 50, .05);
}
.scenario-card strong {
font-size: 13px;
}
.scenario-card small {
grid-column: 1 / -1;
color: #6e7f79;
font-size: 11px;
line-height: 1.45;
}
.pill {
align-self: start;
padding: 4px 7px;
color: var(--ink);
background: #e5e9df;
border-radius: 999px;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
white-space: nowrap;
}
.metrics {
display: grid;
gap: 8px;
}
.metric {
display: grid;
grid-template-columns: 40px 1fr auto;
align-items: center;
gap: 10px;
min-height: 61px;
padding: 10px 11px;
background: var(--white);
border: 1px solid var(--line);
border-left-width: 4px;
border-radius: 9px;
}
.metric.good { border-left-color: var(--green); }
.metric.bad { border-left-color: var(--red); }
.metric.warn { border-left-color: var(--amber); }
.metric-icon {
display: grid;
place-items: center;
width: 37px;
height: 37px;
color: var(--ink-2);
background: var(--paper-2);
border-radius: 9px;
font-size: 18px;
font-weight: 800;
}
.metric.good .metric-icon {
color: var(--green);
background: var(--green-soft);
}
.metric.bad .metric-icon {
color: var(--red);
background: var(--red-soft);
}
.metric.warn .metric-icon {
color: #9b681f;
background: var(--amber-soft);
}
.metric strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.metric small {
display: block;
color: #70817b;
font-size: 10px;
line-height: 1.35;
}
.metric-status {
padding: 4px 6px;
color: var(--ink-2);
background: var(--paper-2);
border-radius: 5px;
font-size: 8px;
font-weight: 900;
letter-spacing: .08em;
text-transform: uppercase;
}
.metric.good .metric-status { color: #116b49; background: var(--green-soft); }
.metric.bad .metric-status { color: #963c37; background: var(--red-soft); }
.metric.warn .metric-status { color: #8b5b18; background: var(--amber-soft); }
.counter-list {
display: grid;
gap: 6px;
max-height: 205px;
overflow: auto;
padding-right: 2px;
}
.counter-row {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 9px 10px;
text-align: left;
background: transparent;
border: 1px solid transparent;
border-radius: 8px;
}
.counter-row:hover { background: #eee8db; }
.counter-row.selected {
background: var(--white);
border-color: #d3a446;
box-shadow: inset 3px 0 0 var(--amber);
}
.counter-swatch {
width: 10px;
height: 25px;
border-radius: 3px;
}
.counter-name {
display: block;
margin-bottom: 2px;
font-size: 11px;
font-weight: 750;
}
.counter-position {
display: block;
color: #7c8b86;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.warning-dot {
width: 8px;
height: 8px;
background: var(--red);
border-radius: 50%;
box-shadow: 0 0 0 3px var(--red-soft);
}
.editor {
margin-top: 12px;
padding: 12px;
background: var(--white);
border: 1px solid var(--line);
border-radius: 10px;
}
.editor-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 10px;
}
.editor-title strong { font-size: 12px; }
.lock-note {
color: #70827b;
font-size: 9px;
line-height: 1.4;
}
.position-fields {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 10px 0;
}
.position-fields label {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
gap: 6px;
color: #6f807a;
font-size: 9px;
font-weight: 750;
}
.position-fields input {
min-width: 0;
width: 100%;
padding: 7px;
color: var(--ink);
background: #f4f0e7;
border: 1px solid var(--line);
border-radius: 6px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.button-row {
display: flex;
gap: 6px;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
min-height: 32px;
padding: 7px 10px;
background: var(--white);
border: 1px solid var(--line);
border-radius: 7px;
font-size: 10px;
font-weight: 750;
transition: transform .12s ease, background .12s ease;
}
.button:hover {
background: var(--paper-2);
transform: translateY(-1px);
}
.button.primary {
color: var(--white);
background: var(--ink);
border-color: var(--ink);
}
.button.primary:hover { background: #24564d; }
.button.danger {
color: #953e36;
border-color: #e3b8b2;
background: #fff8f6;
}
.nudge-pad {
display: grid;
grid-template-columns: repeat(3, 31px);
grid-template-rows: repeat(2, 27px);
justify-content: center;
gap: 4px;
margin-top: 10px;
}
.nudge-pad button {
padding: 0;
background: #f1ecdf;
border: 1px solid var(--line);
border-radius: 6px;
font-weight: 900;
}
.nudge-pad button:hover { background: #dfd6c5; }
.nudge-pad .empty { visibility: hidden; }
.issues {
display: grid;
gap: 6px;
}
.issue {
display: grid;
grid-template-columns: 8px 1fr;
gap: 8px;
padding: 9px 10px;
color: #75433e;
background: var(--red-soft);
border-radius: 7px;
font-size: 10px;
line-height: 1.4;
}
.issue::before {
content: "";
width: 7px;
height: 7px;
margin-top: 3px;
background: var(--red);
border-radius: 50%;
}
.issue.clear {
color: #32664f;
background: var(--green-soft);
}
.issue.clear::before { background: var(--green); }
.toggles {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
color: #526b63;
font-size: 10px;
cursor: pointer;
}
.toggle input {
width: 14px;
height: 14px;
accent-color: var(--green);
}
.immutable-note {
display: grid;
grid-template-columns: 28px 1fr;
gap: 9px;
padding: 10px;
color: #5d736c;
background: #e8eee8;
border-radius: 8px;
font-size: 10px;
line-height: 1.45;
}
.immutable-note b { color: var(--ink); }
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d7dfd7;
}
#canvas-wrap {
position: absolute;
inset: 0;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.scene-top {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
display: flex;
flex-wrap: wrap;
gap: 7px;
pointer-events: none;
}
.scene-badge {
padding: 7px 9px;
color: var(--white);
background: rgba(24, 61, 55, .92);
border: 1px solid rgba(255,255,255,.18);
border-radius: 7px;
box-shadow: 0 5px 14px rgba(23, 51, 46, .14);
font-size: 9px;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.scene-badge.good { background: rgba(25, 133, 91, .94); }
.scene-badge.bad { background: rgba(185, 67, 59, .94); }
.scene-badge.warn { background: rgba(193, 125, 31, .94); }
.toolbar {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
padding: 6px;
background: rgba(255, 253, 247, .91);
border: 1px solid rgba(83, 100, 93, .22);
border-radius: 10px;
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.toolbar .button {
min-height: 30px;
border-color: transparent;
}
.toolbar .button.active {
color: var(--white);
background: var(--ink);
}
.legend {
position: absolute;
z-index: 3;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 12px;
max-width: calc(100% - 36px);
padding: 10px 12px;
color: #4e665f;
background: rgba(255, 253, 247, .91);
border: 1px solid rgba(83, 100, 93, .22);
border-radius: 9px;
box-shadow: 0 7px 20px rgba(23, 51, 46, .11);
font-size: 9px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-swatch {
width: 15px;
height: 8px;
border-radius: 2px;
}
.legend-swatch.route { background: var(--green); }
.legend-swatch.clear { background: #66b896; }
.legend-swatch.blocked { background: var(--red); }
.legend-swatch.delivery { background: var(--amber); }
.legend-swatch.fixture { background: var(--coral); }
.help {
position: absolute;
z-index: 3;
right: 18px;
bottom: 18px;
padding: 8px 10px;
color: #597169;
background: rgba(255, 253, 247, .86);
border-radius: 7px;
font-size: 9px;
pointer-events: none;
}
#toast {
position: absolute;
z-index: 8;
left: 50%;
bottom: 76px;
max-width: min(420px, calc(100% - 36px));
padding: 10px 13px;
color: var(--white);
background: rgba(24, 61, 55, .95);
border-radius: 8px;
box-shadow: var(--shadow);
font-size: 11px;
line-height: 1.35;
opacity: 0;
transform: translate(-50%, 10px);
transition: opacity .18s ease, transform .18s ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
#app { grid-template-columns: 310px minmax(0, 1fr); }
.help { display: none; }
}
@media (max-width: 680px) {
html, body { overflow: auto; }
#app {
display: flex;
flex-direction: column;
height: auto;
min-height: 100%;
}
#viewport {
order: 0;
height: 54vh;
min-height: 390px;
}
aside {
order: 1;
overflow: visible;
border-right: 0;
}
.toolbar { top: 58px; left: 18px; right: auto; }
.scene-top { right: 18px; }
}
</style>
</head>
<body>
<div id="app">
<aside aria-label="Market layout controls">
<header class="masthead">
<div class="eyebrow">New Orleans · Layout study 02</div>
<h1>French Market</h1>
<p>Temporary fixture lab for the historic market shed.</p>
</header>
<section class="panel-section">
<div class="section-heading">Scenario <span>Editable</span></div>
<div class="scenario-card">
<strong>Market shed · Segment 02</strong>
<span class="pill">Live plan</span>
<small>Move only the colored temporary counters. Masonry, ironwork, openings, and the permanent floor remain fixed.</small>
</div>
</section>
<section class="panel-section">
<div class="section-heading">Live checks <span>Auto-updating</span></div>
<div class="metrics">
<div id="accessMetric" class="metric bad">
<div class="metric-icon">↗</div>
<div>
<strong>Accessible route</strong>
<small id="accessDetail">Checking 1.2 m clearance…</small>
</div>
<span id="accessStatus" class="metric-status">Checking</span>
</div>
<div id="openingMetric" class="metric bad">
<div class="metric-icon">▥</div>
<div>
<strong>Pedestrian openings</strong>
<small id="openingDetail">Checking entrance envelopes…</small>
</div>
<span id="openingStatus" class="metric-status">Checking</span>
</div>
<div id="deliveryMetric" class="metric warn">
<div class="metric-icon">▰</div>
<div>
<strong>Delivery interface</strong>
<small id="deliveryDetail">Checking service access…</small>
</div>
<span id="deliveryStatus" class="metric-status">Checking</span>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-heading">Temporary counters <span id="counterCount">6 fixtures</span></div>
<div id="counterList" class="counter-list"></div>
<div id="editor" class="editor">
<div class="editor-title">
<strong id="selectedName">Select a counter</strong>
<span class="pill">0.25 m snap</span>
</div>
<div class="lock-note">Coordinates are relative to the market segment center. X runs east/west; Z runs north/south.</div>
<div class="position-fields">
<label>
X
<input id="posX" type="number" step="0.25" aria-label="Counter X position" disabled>
</label>
<label>
Z
<input id="posZ" type="number" step="0.25" aria-label="Counter Z position" disabled>
</label>
</div>
<div class="button-row">
<button id="rotateButton" class="button" disabled>↻ Rotate 90°</button>
<button id="resetButton" class="button danger" style="margin-left:auto">Reset layout</button>
</div>
<div class="nudge-pad" aria-label="Nudge selected counter">
<button class="empty" disabled></button>
<button data-dx="0" data-dz="-1" disabled>↑</button>
<button class="empty" disabled></button>
<button data-dx="-1" data-dz="0" disabled>←</button>
<button data-dx="0" data-dz="1" disabled>↓</button>
<button data-dx="1" data-dz="0" disabled>→</button>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-heading">Conflict notes <span>Live</span></div>
<div id="issues" class="issues"></div>
</section>
<section class="panel-section">
<div class="section-heading">Analysis layers</div>
<div class="toggles">
<label class="toggle"><input id="routeToggle" type="checkbox" checked> Accessible route</label>
<label class="toggle"><input id="openingToggle" type="checkbox" checked> Opening envelopes</label>
<label class="toggle"><input id="deliveryToggle" type="checkbox" checked> Delivery bay</label>
<label class="toggle"><input id="labelToggle" type="checkbox" checked> Fixture labels</label>
</div>
</section>
<section class="panel-section">
<div class="immutable-note">
<div>▣</div>
<div><b>Permanent fabric is locked.</b> Historic walls, iron columns, fixed openings, and paving cannot be selected or moved by this tool.</div>
</div>
</section>
</aside>
<main id="viewport">
<div id="canvas-wrap"></div>
<div class="scene-top" aria-hidden="true">
<div class="scene-badge">Schematic · Segment 02</div>
<div id="routeBadge" class="scene-badge bad">Route blocked</div>
<div id="openingBadge" class="scene-badge bad">Opening blocked</div>
<div class="scene-badge">Permanent fabric locked</div>
</div>
<div class="toolbar" aria-label="Camera controls">
<button id="isoView" class="button active" title="Isometric camera">Isometric</button>
<button id="topView" class="button" title="Top-down camera">Top</button>
<button id="fitView" class="button" title="Fit the scene">Fit</button>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="legend-swatch route"></span> Accessible route</div>
<div class="legend-item"><span class="legend-swatch clear"></span> Clear opening</div>
<div class="legend-item"><span class="legend-swatch blocked"></span> Blocked opening</div>
<div class="legend-item"><span class="legend-swatch delivery"></span> Delivery bay</div>
<div class="legend-item"><span class="legend-swatch fixture"></span> Temporary fixture</div>
</div>
<div class="help">Drag a counter · drag background to orbit · shift/right-drag to pan · wheel to zoom</div>
<div id="toast" role="status" aria-live="polite"></div>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const viewport = $("#viewport");
const canvasWrap = $("#canvas-wrap");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e0d8);
scene.fog = new THREE.Fog(0xd8e0d8, 42, 78);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
canvasWrap.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 120);
const hemi = new THREE.HemisphereLight(0xfff5dc, 0x738e80, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.25);
sun.position.set(-13, 24, 17);
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 = 60;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d9dc, 0.8);
fill.position.set(15, 9, -15);
scene.add(fill);
const permanentGroup = new THREE.Group();
const counterGroup = new THREE.Group();
const overlayGroup = new THREE.Group();
scene.add(permanentGroup, counterGroup, overlayGroup);
const MAT = {
floor: new THREE.MeshStandardMaterial({ color: 0xc9c1af, roughness: .94 }),
tileA: new THREE.MeshStandardMaterial({ color: 0xd8d1bf, roughness: .95 }),
tileB: new THREE.MeshStandardMaterial({ color: 0xc5bead, roughness: .96 }),
brick: new THREE.MeshStandardMaterial({ color: 0xa9583f, roughness: .94 }),
iron: new THREE.MeshStandardMaterial({ color: 0x244b43, roughness: .72, metalness: .25 }),
ironLight: new THREE.MeshStandardMaterial({ color: 0x39635a, roughness: .75, metalness: .15 }),
stone: new THREE.MeshStandardMaterial({ color: 0xb4aa95, roughness: .92 }),
cream: new THREE.MeshStandardMaterial({ color: 0xe3d6b7, roughness: .91 }),
dark: new THREE.MeshStandardMaterial({ color: 0x3e4844, roughness: .8 }),
roof: new THREE.MeshStandardMaterial({ color: 0x54675f, roughness: .88 }),
glass: new THREE.MeshStandardMaterial({ color: 0x6e9898, roughness: .3, metalness: .18 }),
green: new THREE.MeshStandardMaterial({ color: 0x39a274, roughness: .58 }),
red: new THREE.MeshStandardMaterial({ color: 0xcf554b, roughness: .62 }),
amber: new THREE.MeshStandardMaterial({ color: 0xe8a23c, roughness: .65 })
};
function box(parent, width, height, depth, x, y, z, material, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
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 textTexture(text, subtitle = "", bg = "#183d37", fg = "#fffdf7") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
roundedRect(ctx, 0, 0, canvas.width, canvas.height, 26);
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.font = "700 74px Georgia, serif";
ctx.fillText(text, canvas.width / 2, subtitle ? 88 : 112);
if (subtitle) {
ctx.font = "700 27px Arial, sans-serif";
ctx.letterSpacing = "4px";
ctx.fillText(subtitle, canvas.width / 2, 160);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function textSprite(text, color = "#183d37", background = "#fffdf7") {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 80;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
roundedRect(ctx, 4, 4, 312, 72, 15);
ctx.fill();
ctx.fillStyle = color;
ctx.font = "800 27px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), 160, 40);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.2, .55, 1);
return sprite;
}
function addWarehouse(x, z, w, d, h, color) {
const g = new THREE.Group();
g.position.set(x, 0, z);
const bodyMat = new THREE.MeshStandardMaterial({
color,
roughness: .92
});
box(g, w, h, d, 0, h / 2, 0, bodyMat);
box(g, w + .35, .3, d + .35, 0, h + .15, 0, MAT.roof);
for (let zz = -d / 2 + 1.1; zz < d / 2; zz += 2) {
for (const xx of [-w * .25, w * .25]) {
box(g, .85, 1.25, .08, xx, h * .56, zz + d / 2 + .045, MAT.glass, false);
}
}
permanentGroup.add(g);
}
const columns = [
{ x: -8.3, z: -6 }, { x: -8.3, z: -2 },
{ x: -8.3, z: 2 }, { x: -8.3, z: 6 },
{ x: 8.3, z: -6 }, { x: 8.3, z: -2 },
{ x: 8.3, z: 2 }, { x: 8.3, z: 6 }
];
function buildArchitecture() {
box(permanentGroup, 90, .25, 90, 0, -.65, 0,
new THREE.MeshStandardMaterial({ color: 0xaebbb0, roughness: 1 }), false);
box(permanentGroup, 26.2, .48, 18.3, 0, -.25, 0, MAT.floor);
const tileGeometry = new THREE.BoxGeometry(.97, .07, .97);
const tileCount = 25 * 17;
const tiles = new THREE.InstancedMesh(tileGeometry, MAT.tileA, tileCount);
tiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let instance = 0;
for (let x = -12; x <= 12; x++) {
for (let z = -8; z <= 8; z++) {
matrix.makeTranslation(x, .035, z);
tiles.setMatrixAt(instance, matrix);
color.setHex(((x + z) & 1) ? 0xd7d0bf : 0xc7c0af);
tiles.setColorAt(instance, color);
instance++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
permanentGroup.add(tiles);
// Fixed cast-iron columns, plinths, and roof members.
for (const col of columns) {
box(permanentGroup, .82, .34, .82, col.x, .2, col.z, MAT.stone);
box(permanentGroup, .31, 3.65, .31, col.x, 2.18, col.z, MAT.iron);
box(permanentGroup, .58, .22, .58, col.x, 3.92, col.z, MAT.ironLight);
box(permanentGroup, .48, .22, .48, col.x, .52, col.z, MAT.ironLight);
}
box(permanentGroup, .23, .24, 17.2, -8.3, 4.08, 0, MAT.iron);
box(permanentGroup, .23, .24, 17.2, 8.3, 4.08, 0, MAT.iron);
for (const z of [-6, -2, 2, 6]) {
box(permanentGroup, 16.85, .18, .19, 0, 4.08, z, MAT.ironLight);
}
// Brick walls use one instanced mesh with staggered voxel courses.
const segments = [
{ axis: "x", start: -12.55, end: -1.75, fixed: 8.58 },
{ axis: "x", start: 1.75, end: 12.55, fixed: 8.58 },
{ axis: "x", start: -12.55, end: -1.75, fixed: -8.58 },
{ axis: "x", start: 1.75, end: 12.55, fixed: -8.58 },
{ axis: "z", start: -8.45, end: -1.55, fixed: 12.68 },
{ axis: "z", start: 1.55, end: 8.45, fixed: 12.68 },
{ axis: "z", start: -8.45, end: 8.45, fixed: -12.68 }
];
const brickTransforms = [];
const brickColors = [];
const brickLength = 1.24;
const rowHeight = .49;
for (const segment of segments) {
for (let row = 0; row < 7; row++) {
let start = segment.start - (row % 2) * brickLength * .5;
while (start < segment.end) {
const a = Math.max(start, segment.start);
const b = Math.min(start + brickLength, segment.end);
if (b - a > .08) {
const center = (a + b) * .5;
const y = .31 + row * rowHeight;
const rotation = segment.axis === "x" ? 0 : Math.PI / 2;
brickTransforms.push({
x: segment.axis === "x" ? center : segment.fixed,
y,
z: segment.axis === "x" ? segment.fixed : center,
rotation
});
brickColors.push([0xa85840, 0xb56348, 0x9e503b, 0xc06d4f][row % 4]);
}
start += brickLength;
}
}
}
const brickGeometry = new THREE.BoxGeometry(brickLength - .035, .45, .58);
const brickMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: .94
});
const bricks = new THREE.InstancedMesh(
brickGeometry,
brickMaterial,
brickTransforms.length
);
const brickMatrix = new THREE.Matrix4();
const brickQuaternion = new THREE.Quaternion();
const brickPosition = new THREE.Vector3();
const brickScale = new THREE.Vector3(1, 1, 1);
brickTransforms.forEach((t, i) => {
brickPosition.set(t.x, t.y, t.z);
brickQuaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), t.rotation);
brickMatrix.compose(brickPosition, brickQuaternion, brickScale);
bricks.setMatrixAt(i, brickMatrix);
bricks.setColorAt(i, color.setHex(brickColors[i]));
});
bricks.instanceMatrix.needsUpdate = true;
if (bricks.instanceColor) bricks.instanceColor.needsUpdate = true;
bricks.castShadow = true;
bricks.receiveShadow = true;
permanentGroup.add(bricks);
// Lintels make the permanent pedestrian and service openings legible.
box(permanentGroup, 3.9, .32, .72, 0, 3.38, 8.58, MAT.stone);
box(permanentGroup, 3.9, .32, .72, 0, 3.38, -8.58, MAT.stone);
box(permanentGroup, .72, .32, 3.5, 12.68, 3.38, 0, MAT.stone);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(5.5, 1.6),
new THREE.MeshBasicMaterial({
map: textTexture("FRENCH MARKET", "NEW ORLEANS · 1789"),
side: THREE.DoubleSide
})
);
sign.position.set(0, 3.55, 8.96);
sign.rotation.y = Math.PI;
permanentGroup.add(sign);
addWarehouse(-15.4, -2.7, 4.2, 9.4, 4.4, 0xcab792);
addWarehouse(15.25, -4.3, 4.1, 8.1, 3.6, 0xb8aa8d);
addWarehouse(-15.7, 7.0, 3.8, 4.6, 3.1, 0xd6c8a8);
}
buildArchitecture();
const initialCounters = [
{ id: "c1", name: "Crêpe cart", short: "CRÊPE", kind: "crepe", x: .55, z: 6.35, w: 1.8, d: 1.1, rot: 0, color: 0xe47a52 },
{ id: "c2", name: "Citrus & greens", short: "PRODUCE", kind: "produce", x: -3.8, z: 4.25, w: 2.25, d: 1.4, rot: 0, color: 0x3f9b75 },
{ id: "c3", name: "Fresh flowers", short: "FLOWERS", kind: "flowers", x: 2.45, z: 2.45, w: 1.8, d: 1.4, rot: 0, color: 0xbd6c91 },
{ id: "c4", name: "Seafood cart", short: "SEAFOOD", kind: "seafood", x: 10.35, z: .5, w: 2.2, d: 1.2, rot: 0, color: 0x4d8ea2 },
{ id: "c5", name: "Spice kiosk", short: "SPICE", kind: "spice", x: -2.35, z: -1.35, w: 2.0, d: 1.25, rot: 0, color: 0xd99b3e },
{ id: "c6", name: "Gumbo stand", short: "GUMBO", kind: "gumbo", x: 2.85, z: -5.15, w: 2.0, d: 1.35, rot: 0, color: 0x8c684e }
];
const counters = initialCounters.map(c => ({ ...c, initial: { x: c.x, z: c.z, rot: c.rot } }));
const counterPickMeshes = [];
let selectedId = "c1";
function addProduce(parent, x, y, z, color, size = .2) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: .65,
flatShading: true
});
return box(parent, size, size, size, x, y, z, material);
}
function createCounter(counter) {
const root = new THREE.Group();
root.userData.counterId = counter.id;
const bodyMaterial = new THREE.MeshStandardMaterial({
color: counter.color,
roughness: .74,
flatShading: true
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x294b43,
roughness: .7
});
const body = box(root, counter.w, .78, counter.d, 0, .58, 0, bodyMaterial);
const top = box(root, counter.w + .12, .14, counter.d + .12, 0, 1.04, 0, MAT.cream);
box(root, counter.w * .78, .13, counter.d * .8, 0, .16, 0, trimMaterial);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(counter.w + .16, .9, counter.d + .16)),
new THREE.LineBasicMaterial({
color: 0xf6c65b,
transparent: true,
opacity: .95
})
);
edge.position.y = .59;
edge.visible = false;
root.add(edge);
const ring = new THREE.Mesh(
new THREE.RingGeometry(.82, 1, 32),
new THREE.MeshBasicMaterial({
color: 0xf6c65b,
side: THREE.DoubleSide,
transparent: true,
opacity: .88,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = .085;
ring.scale.set(counter.w * .7, counter.d * .7, 1);
ring.visible = false;
root.add(ring);
if (counter.kind === "produce") {
const colors = [0xe6b635, 0x67a64c, 0xd96642, 0x7cab50];
for (let i = 0; i < 16; i++) {
addProduce(
root,
-counter.w * .38 + (i % 4) * counter.w * .25,
1.2 + Math.floor(i / 4) * .15,
-.36 + Math.floor((i % 4) / 2) * .55,
colors[i % colors.length],
.2
);
}
} else if (counter.kind === "flowers") {
const colors = [0xe17892, 0xe6bd4b, 0xc987be, 0xe6e0c7];
for (let i = 0; i < 12; i++) {
const px = -.58 + (i % 4) * .38;
const pz = -.38 + Math.floor(i / 4) * .36;
box(root, .045, .42, .045, px, 1.31, pz, MAT.green, false);
addProduce(root, px, 1.56, pz, colors[i % colors.length], .23);
}
} else if (counter.kind === "seafood") {
for (let i = 0; i < 3; i++) {
box(root, .48, .24, .68, -.62 + i * .62, 1.23, 0, MAT.glass);
for (let j = 0; j < 3; j++) {
addProduce(root, -.72 + i * .62 + (j % 2) * .16, 1.38, -.18 + j * .18, 0xaac9ca, .17);
}
}
} else if (counter.kind === "spice") {
const colors = [0xb94f38, 0xd49c35, 0x6f8c42, 0x8f5c3f];
for (let i = 0; i < 8; i++) {
addProduce(root, -.72 + (i % 4) * .48, 1.24, i < 4 ? -.31 : .31, colors[i % colors.length], .25);
}
} else if (counter.kind === "gumbo") {
box(root, .66, .36, .62, 0, 1.27, 0, MAT.dark);
box(root, .78, .08, .74, 0, 1.48, 0, trimMaterial);
box(root, .12, .72, .12, .58, 1.63, -.24, MAT.iron);
box(root, .12, .72, .12, .58, 1.63, .24, MAT.iron);
box(root, .22, .14, .22, .58, 1.96, 0, MAT.iron);
} else {
for (let i = 0; i < 7; i++) {
addProduce(root, -.55 + (i % 4) * .34, 1.16 + Math.floor(i / 4) * .11, i % 2 ? .24 : -.24, 0xd8a44d, .27);
}
}
const label = textSprite(counter.short, "#ffffff", "#183d37");
label.position.set(0, 2.25, 0);
root.add(label);
root.traverse(child => {
if (child.isMesh && child !== ring) {
child.userData.counterId = counter.id;
counterPickMeshes.push(child);
}
});
counter.root = root;
counter.body = body;
counter.top = top;
counter.edge = edge;
counter.ring = ring;
counter.label = label;
counterGroup.add(root);
updateCounterTransform(counter);
}
counters.forEach(createCounter);
function updateCounterTransform(counter) {
counter.root.position.set(counter.x, 0, counter.z);
counter.root.rotation.y = counter.rot;
}
function normalizedAngle(angle) {
const twoPi = Math.PI * 2;
return ((angle % twoPi) + twoPi) % twoPi;
}
function counterCorners(counter) {
const hw = counter.w / 2;
const hd = counter.d / 2;
const c = Math.cos(counter.rot);
const s = Math.sin(counter.rot);
return [
[-hw, -hd], [hw, -hd], [hw, hd], [-hw, hd]
].map(([lx, lz]) => ({
x: counter.x + lx * c + lz * s,
z: counter.z - lx * s + lz * c
}));
}
function rectCorners(rect) {
return [
{ x: rect.minX, z: rect.minZ },
{ x: rect.maxX, z: rect.minZ },
{ x: rect.maxX, z: rect.maxZ },
{ x: rect.minX, z: rect.maxZ }
];
}
function polygonsOverlap(a, b) {
for (const polygon of [a, b]) {
for (let i = 0; i < polygon.length; i++) {
const p1 = polygon[i];
const p2 = polygon[(i + 1) % polygon.length];
const axis = { x: -(p2.z - p1.z), z: p2.x - p1.x };
const length = Math.hypot(axis.x, axis.z);
if (length < 1e-7) continue;
axis.x /= length;
axis.z /= length;
let minA = Infinity, maxA = -Infinity;
let minB = Infinity, maxB = -Infinity;
for (const p of a) {
const projection = p.x * axis.x + p.z * axis.z;
minA = Math.min(minA, projection);
maxA = Math.max(maxA, projection);
}
for (const p of b) {
const projection = p.x * axis.x + p.z * axis.z;
minB = Math.min(minB, projection);
maxB = Math.max(maxB, projection);
}
if (maxA <= minB + 1e-6 || maxB <= minA + 1e-6) return false;
}
}
return true;
}
function counterIntersectsCircle(counter, circle) {
const c = Math.cos(counter.rot);
const s = Math.sin(counter.rot);
const dx = circle.x - counter.x;
const dz = circle.z - counter.z;
const localX = c * dx - s * dz;
const localZ = s * dx + c * dz;
const closestX = THREE.MathUtils.clamp(localX, -counter.w / 2, counter.w / 2);
const closestZ = THREE.MathUtils.clamp(localZ, -counter.d / 2, counter.d / 2);
return Math.hypot(localX - closestX, localZ - closestZ) < circle.radius;
}
function pointInsideCounter(counter, x, z, padding = 0) {
const c = Math.cos(counter.rot);
const s = Math.sin(counter.rot);
const dx = x - counter.x;
const dz = z - counter.z;
const localX = c * dx - s * dz;
const localZ = s * dx + c * dz;
return (
Math.abs(localX) <= counter.w / 2 + padding &&
Math.abs(localZ) <= counter.d / 2 + padding
);
}
function validPosition(candidate) {
const corners = counterCorners(candidate);
for (const corner of corners) {
if (
corner.x < -11.65 || corner.x > 11.65 ||
corner.z < -7.65 || corner.z > 7.65
) return false;
}
for (const column of columns) {
if (counterIntersectsCircle(candidate, { ...column, radius: .58 })) {
return false;
}
}
for (const other of counters) {
if (other.id === candidate.id) continue;
if (polygonsOverlap(corners, counterCorners(other))) return false;
}
return true;
}
function tryMove(counter, x, z, rotation = counter.rot) {
const candidate = {
...counter,
x: Math.round(x / .25) * .25,
z: Math.round(z / .25) * .25,
rot: normalizedAngle(rotation)
};
if (!validPosition(candidate)) {
showToast("Move blocked: temporary fixtures cannot overlap or enter the permanent fabric.");
return false;
}
counter.x = candidate.x;
counter.z = candidate.z;
counter.rot = candidate.rot;
updateCounterTransform(counter);
refresh();
return true;
}
const pedestrianOpenings = [
{
id: "south",
label: "South entrance",
minX: -1.75, maxX: 1.75,
minZ: 6.0, maxZ: 8.35
},
{
id: "north",
label: "North passage",
minX: -1.75, maxX: 1.75,
minZ: -8.35, maxZ: -6.0
}
];
const deliveryZone = {
id: "delivery",
label: "Service gate / unload",
minX: 9.25, maxX: 12.35,
minZ: -1.55, maxZ: 1.75
};
function blockersForZone(zone) {
return counters.filter(counter =>
polygonsOverlap(counterCorners(counter), rectCorners(zone))
);
}
function findGridPath(start, goal, clearance = .6) {
const cell = .4;
const minX = -11.2;
const maxX = 11.2;
const minZ = -7.2;
const maxZ = 7.2;
const nx = Math.floor((maxX - minX) / cell) + 1;
const nz = Math.floor((maxZ - minZ) / cell) + 1;
const count = nx * nz;
const blocked = new Uint8Array(count);
const parent = new Int32Array(count);
parent.fill(-1);
const index = (x, z) => z * nx + x;
const center = i => ({
x: minX + (i % nx) * cell,
z: minZ + Math.floor(i / nx) * cell
});
for (let z = 0; z < nz; z++) {
for (let x = 0; x < nx; x++) {
const wx = minX + x * cell;
const wz = minZ + z * cell;
let isBlocked = false;
for (const column of columns) {
if (Math.hypot(wx - column.x, wz - column.z) < .42 + clearance) {
isBlocked = true;
break;
}
}
if (!isBlocked) {
for (const counter of counters) {
if (pointInsideCounter(counter, wx, wz, clearance)) {
isBlocked = true;
break;
}
}
}
blocked[index(x, z)] = isBlocked ? 1 : 0;
}
}
const sx = THREE.MathUtils.clamp(Math.round((start.x - minX) / cell), 0, nx - 1);
const sz = THREE.MathUtils.clamp(Math.round((start.z - minZ) / cell), 0, nz - 1);
const gx = THREE.MathUtils.clamp(Math.round((goal.x - minX) / cell), 0, nx - 1);
const gz = THREE.MathUtils.clamp(Math.round((goal.z - minZ) / cell), 0, nz - 1);
const startIndex = index(sx, sz);
const goalIndex = index(gx, gz);
if (blocked[startIndex] || blocked[goalIndex]) return null;
const queue = new Int32Array(count);
let head = 0;
let tail = 0;
queue[tail++] = startIndex;
parent[startIndex] = startIndex;
const directions = [
[1, 0], [-1, 0], [0, 1], [0, -1]
];
while (head < tail) {
const current = queue[head++];
if (current === goalIndex) break;
const cx = current % nx;
const cz = Math.floor(current / nx);
for (const [dx, dz] of directions) {
const x = cx + dx;
const z = cz + dz;
if (x < 0 || x >= nx || z < 0 || z >= nz) continue;
const next = index(x, z);
if (blocked[next] || parent[next] !== -1) continue;
parent[next] = current;
queue[tail++] = next;
}
}
if (parent[goalIndex] === -1) return null;
const path = [];
let current = goalIndex;
while (current !== startIndex) {
path.push(center(current));
current = parent[current];
}
path.push(center(startIndex));
path.reverse();
path.unshift({ x: start.x, z: start.z });
path.push({ x: goal.x, z: goal.z });
let length = 0;
for (let i = 1; i < path.length; i++) {
length += Math.hypot(path[i].x - path[i - 1].x, path[i].z - path[i - 1].z);
}
return { path, length };
}
function computeMetrics() {
const openingBlockers = {};
for (const opening of pedestrianOpenings) {
openingBlockers[opening.id] = blockersForZone(opening);
}
const deliveryBlockers = blockersForZone(deliveryZone);
const route = findGridPath({ x: 0, z: 5.3 }, { x: 0, z: -6.5 }, .6);
const deliveryRoute = findGridPath({ x: 11.2, z: .5 }, { x: 11.2, z: -6.5 }, .45);
const pedestrianBlocked = pedestrianOpenings.some(o => openingBlockers[o.id].length);
const deliveryBlocked = deliveryBlockers.length > 0 || !deliveryRoute;
return {
openingBlockers,
deliveryBlockers,
route,
deliveryRoute,
pedestrianBlocked,
deliveryBlocked,
accessible: !!route && !pedestrianBlocked
};
}
function clearOverlayGroup() {
while (overlayGroup.children.length) {
const child = overlayGroup.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach(material => material.dispose());
}
});
}
}
function overlayMaterial(color, opacity = .28) {
return new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
}
function addOutlineRect(rect, color, y = .11) {
const width = rect.maxX - rect.minX;
const depth = rect.maxZ - rect.minZ;
const cx = (rect.minX + rect.maxX) / 2;
const cz = (rect.minZ + rect.maxZ) / 2;
const material = overlayMaterial(color, .95);
box(overlayGroup, width, .055, .075, cx, y, rect.minZ, material, false);
box(overlayGroup, width, .055, .075, cx, y, rect.maxZ, material, false);
box(overlayGroup, .075, .055, depth, rect.minX, y, cz, material, false);
box(overlayGroup, .075, .055, depth, rect.maxX, y, cz, material, false);
}
function addPath(path, color, width = .18) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .92,
depthWrite: false
});
for (let i = 1; i < path.length; i++) {
const a = path[i - 1];
const b = path[i];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < .001) continue;
const segment = box(
overlayGroup,
width,
.07,
length + width * .35,
(a.x + b.x) / 2,
.15,
(a.z + b.z) / 2,
material,
false
);
segment.rotation.y = Math.atan2(dx, dz);
segment.renderOrder = 4;
}
for (const point of path) {
const dot = box(
overlayGroup,
width * 1.5,
.075,
width * 1.5,
point.x,
.16,
point.z,
material,
false
);
dot.renderOrder = 4;
}
}
function addBlockedMarker(x, z, color) {
const material = overlayMaterial(color, .9);
const a = box(overlayGroup, 1.1, .08, .18, x, .19, z, material, false);
const b = box(overlayGroup, .18, .08, 1.1, x, .19, z, material, false);
a.rotation.y = Math.PI / 4;
b.rotation.y = Math.PI / 4;
}
function renderOverlays(metrics) {
clearOverlayGroup();
if ($("#openingToggle").checked) {
for (const opening of pedestrianOpenings) {
const blocked = metrics.openingBlockers[opening.id].length > 0;
const color = blocked ? 0xcd5148 : 0x48a878;
const width = opening.maxX - opening.minX;
const depth = opening.maxZ - opening.minZ;
const cx = (opening.minX + opening.maxX) / 2;
const cz = (opening.minZ + opening.maxZ) / 2;
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
overlayMaterial(color, blocked ? .27 : .16)
);
plane.rotation.x = -Math.PI / 2;
plane.position.set(cx, .095, cz);
plane.renderOrder = 2;
overlayGroup.add(plane);
addOutlineRect(opening, color, .12);
if (blocked) {
addBlockedMarker(cx, cz, color);
}
}
}
if ($("#deliveryToggle").checked) {
const width = deliveryZone.maxX - deliveryZone.minX;
const depth = deliveryZone.maxZ - deliveryZone.minZ;
const cx = (deliveryZone.minX + deliveryZone.maxX) / 2;
const cz = (deliveryZone.minZ + deliveryZone.maxZ) / 2;
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
overlayMaterial(0xe7a13c, .23)
);
plane.rotation.x = -Math.PI / 2;
plane.position.set(cx, .085, cz);
plane.renderOrder = 1;
overlayGroup.add(plane);
addOutlineRect(deliveryZone, metrics.deliveryBlocked ? 0xce6840 : 0xe3a23e, .11);
const stripeMaterial = overlayMaterial(0xd88b30, .65);
for (let i = 0; i < 5; i++) {
const stripe = box(
overlayGroup,
.12,
.045,
2.25,
deliveryZone.minX + .3 + i * .65,
.12,
cz,
stripeMaterial,
false
);
stripe.rotation.y = -.48;
}
}
if ($("#routeToggle").checked) {
if (metrics.route) {
addPath(metrics.route.path, 0x229b67, .2);
const startMaterial = overlayMaterial(0x176c4c, .95);
const goalMaterial = overlayMaterial(0x176c4c, .95);
box(overlayGroup, .42, .09, .42, 0, .19, 5.3, startMaterial, false);
box(overlayGroup, .42, .09, .42, 0, .19, -6.5, goalMaterial, false);
} else {
addBlockedMarker(0, 5.3, 0xcd5148);
}
if (metrics.deliveryRoute) {
addPath(metrics.deliveryRoute.path, 0xd99435, .16);
} else {
addBlockedMarker(11.2, .5, 0xce6840);
}
}
}
function metricClass(element, state) {
element.classList.remove("good", "bad", "warn");
element.classList.add(state);
}
function renderCounterList(metrics) {
const warningIds = new Set([
...Object.values(metrics.openingBlockers).flat(),
...metrics.deliveryBlockers
].map(counter => counter.id));
$("#counterList").innerHTML = counters.map(counter => `
<button class="counter-row ${counter.id === selectedId ? "selected" : ""}" data-counter="${counter.id}">
<span class="counter-swatch" style="background:#${counter.color.toString(16).padStart(6, "0")}"></span>
<span>
<span class="counter-name">${counter.name}</span>
<span class="counter-position">X ${counter.x.toFixed(2)} · Z ${counter.z.toFixed(2)} · ${Math.round(counter.rot * 180 / Math.PI)}°</span>
</span>
${warningIds.has(counter.id) ? '<span class="warning-dot" title="This fixture creates a conflict"></span>' : ""}
</button>
`).join("");
$$(".counter-row").forEach(button => {
button.addEventListener("click", () => selectCounter(button.dataset.counter));
});
}
function renderIssues(metrics) {
const issues = [];
for (const opening of pedestrianOpenings) {
const blockers = metrics.openingBlockers[opening.id];
if (blockers.length) {
issues.push(`${opening.label} blocked by ${blockers.map(c => c.name).join(", ")}.`);
}
}
if (!metrics.route && !metrics.pedestrianBlocked) {
issues.push("No continuous 1.2 m accessible route connects the two pedestrian openings.");
}
if (metrics.deliveryBlockers.length) {
issues.push(`Delivery bay occupied by ${metrics.deliveryBlockers.map(c => c.name).join(", ")}.`);
} else if (!metrics.deliveryRoute) {
issues.push("The service corridor to the rear dock is obstructed.");
}
const issuesElement = $("#issues");
if (!issues.length) {
issuesElement.innerHTML = `
<div class="issue clear">No conflicts. Both pedestrian openings, the accessible route, and delivery interface are clear.</div>
`;
return;
}
issuesElement.innerHTML = issues.map(issue => `<div class="issue">${issue}</div>`).join("");
}
function updateEditor() {
const counter = counters.find(c => c.id === selectedId);
const selected = Boolean(counter);
$("#selectedName").textContent = selected ? counter.name : "Select a counter";
$("#posX").disabled = !selected;
$("#posZ").disabled = !selected;
$("#rotateButton").disabled = !selected;
$$("[data-dx]").forEach(button => button.disabled = !selected);
if (selected) {
$("#posX").value = counter.x.toFixed(2);
$("#posZ").value = counter.z.toFixed(2);
}
}
function renderUI(metrics) {
const accessMetric = $("#accessMetric");
const openingMetric = $("#openingMetric");
const deliveryMetric = $("#deliveryMetric");
if (metrics.accessible) {
metricClass(accessMetric, "good");
$("#accessStatus").textContent = "Clear";
$("#accessDetail").textContent = `${metrics.route.length.toFixed(1)} m continuous · 1.2 m clearance`;
} else {
metricClass(accessMetric, "bad");
$("#accessStatus").textContent = "Blocked";
$("#accessDetail").textContent = metrics.pedestrianBlocked
? "A pedestrian opening is obstructed"
: "No continuous 1.2 m route found";
}
const clearOpenings = pedestrianOpenings.filter(
opening => metrics.openingBlockers[opening.id].length === 0
).length;
metricClass(openingMetric, clearOpenings === pedestrianOpenings.length ? "good" : "bad");
$("#openingStatus").textContent = `${clearOpenings}/${pedestrianOpenings.length}`;
$("#openingDetail").textContent = clearOpenings === pedestrianOpenings.length
? "South entrance and north passage are clear"
: `${pedestrianOpenings.length - clearOpenings} pedestrian opening obstructed`;
metricClass(deliveryMetric, metrics.deliveryBlocked ? "bad" : "good");
$("#deliveryStatus").textContent = metrics.deliveryBlocked ? "Conflict" : "Clear";
$("#deliveryDetail").textContent = metrics.deliveryBlocked
? "Service bay or delivery corridor is obstructed"
: "Unload bay and rear-dock route are clear";
const routeBadge = $("#routeBadge");
routeBadge.textContent = metrics.accessible ? "Route clear" : "Route blocked";
routeBadge.className = `scene-badge ${metrics.accessible ? "good" : "bad"}`;
const openingBadge = $("#openingBadge");
openingBadge.textContent = clearOpenings === pedestrianOpenings.length
? "Openings clear"
: "Opening blocked";
openingBadge.className = `scene-badge ${clearOpenings === pedestrianOpenings.length ? "good" : "bad"}`;
counters.forEach(counter => {
counter.ring.visible = counter.id === selectedId;
counter.edge.visible = counter.id === selectedId;
counter.label.visible = $("#labelToggle").checked;
});
renderCounterList(metrics);
updateEditor();
renderIssues(metrics);
}
function refresh() {
const metrics = computeMetrics();
renderOverlays(metrics);
renderUI(metrics);
}
function selectCounter(id) {
selectedId = id;
refresh();
}
let toastTimeout;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimeout);
toastTimeout = setTimeout(() => toast.classList.remove("show"), 2300);
}
// Camera controls implemented directly, without Three.js addons.
const controls = {
target: new THREE.Vector3(0, .4, 0),
azimuth: .68,
polar: .86,
zoom: 1
};
function updateCamera() {
const radius = 36;
const sinPhi = Math.sin(controls.polar);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.azimuth),
controls.target.y + radius * Math.cos(controls.polar),
controls.target.z + radius * sinPhi * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
camera.updateProjectionMatrix();
}
function resize() {
const width = Math.max(1, canvasWrap.clientWidth);
const height = Math.max(1, canvasWrap.clientHeight);
const aspect = width / height;
const verticalSize = 19 / controls.zoom;
camera.left = -verticalSize * aspect / 2;
camera.right = verticalSize * aspect / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(canvasWrap);
function setCameraMode(mode) {
if (mode === "top") {
controls.azimuth = 0;
controls.polar = .035;
controls.target.set(0, .3, 0);
controls.zoom = 1.04;
$("#topView").classList.add("active");
$("#isoView").classList.remove("active");
} else {
controls.azimuth = .68;
controls.polar = .86;
controls.target.set(0, .4, 0);
controls.zoom = 1;
$("#isoView").classList.add("active");
$("#topView").classList.remove("active");
}
resize();
updateCamera();
}
$("#isoView").addEventListener("click", () => setCameraMode("iso"));
$("#topView").addEventListener("click", () => setCameraMode("top"));
$("#fitView").addEventListener("click", () => {
controls.target.set(0, .4, 0);
controls.zoom = 1;
resize();
updateCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const floorPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -.08);
const floorPoint = new THREE.Vector3();
let pointerMode = null;
let draggedCounter = null;
let dragOffset = { x: 0, z: 0 };
let lastPointer = { x: 0, y: 0 };
function setPointer(event) {
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;
}
function getFloorPoint() {
raycaster.setFromCamera(pointer, camera);
return raycaster.ray.intersectPlane(floorPlane, floorPoint);
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
setPointer(event);
lastPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
if (event.button === 0 && !event.shiftKey && !event.altKey) {
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(counterPickMeshes, false);
if (hits.length) {
const id = hits[0].object.userData.counterId;
draggedCounter = counters.find(counter => counter.id === id);
selectedId = id;
const point = getFloorPoint();
if (point) {
dragOffset.x = draggedCounter.x - point.x;
dragOffset.z = draggedCounter.z - point.z;
}
pointerMode = "counter";
refresh();
return;
}
}
pointerMode = event.button === 0 && !event.shiftKey ? "orbit" : "pan";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerMode) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
if (pointerMode === "counter" && draggedCounter) {
setPointer(event);
const point = getFloorPoint();
if (point) {
tryMove(
draggedCounter,
point.x + dragOffset.x,
point.z + dragOffset.z
);
}
} else if (pointerMode === "orbit") {
controls.azimuth -= dx * .006;
controls.polar = THREE.MathUtils.clamp(controls.polar + dy * .005, .035, 1.23);
updateCamera();
} else if (pointerMode === "pan") {
const scale = 24 / controls.zoom / Math.max(1, canvasWrap.clientHeight);
const right = new THREE.Vector3(Math.cos(controls.azimuth), 0, -Math.sin(controls.azimuth));
const forward = new THREE.Vector3(Math.sin(controls.azimuth), 0, Math.cos(controls.azimuth));
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, dy * scale);
updateCamera();
}
lastPointer = { x: event.clientX, y: event.clientY };
});
function endPointer(event) {
pointerMode = null;
draggedCounter = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * .0012);
controls.zoom = THREE.MathUtils.clamp(controls.zoom * factor, .68, 2.25);
resize();
}, { passive: false });
function commitCoordinates() {
const counter = counters.find(c => c.id === selectedId);
if (!counter) return;
const x = Number.parseFloat($("#posX").value);
const z = Number.parseFloat($("#posZ").value);
if (!Number.isFinite(x) || !Number.isFinite(z)) {
updateEditor();
return;
}
tryMove(counter, x, z);
}
$("#posX").addEventListener("change", commitCoordinates);
$("#posZ").addEventListener("change", commitCoordinates);
$("#rotateButton").addEventListener("click", () => {
const counter = counters.find(c => c.id === selectedId);
if (counter) tryMove(counter, counter.x, counter.z, counter.rot + Math.PI / 2);
});
$$("[data-dx]").forEach(button => {
button.addEventListener("click", () => {
const counter = counters.find(c => c.id === selectedId);
if (!counter) return;
tryMove(
counter,
counter.x + Number(button.dataset.dx) * .25,
counter.z + Number(button.dataset.dz) * .25
);
});
});
$("#resetButton").addEventListener("click", () => {
for (const counter of counters) {
counter.x = counter.initial.x;
counter.z = counter.initial.z;
counter.rot = counter.initial.rot;
updateCounterTransform(counter);
}
refresh();
showToast("Temporary counter layout restored to the study baseline.");
});
["routeToggle", "openingToggle", "deliveryToggle", "labelToggle"].forEach(id => {
$(`#${id}`).addEventListener("change", refresh);
});
function animate() {
requestAnimationFrame(animate);
const selected = counters.find(counter => counter.id === selectedId);
if (selected?.ring.visible) {
const pulse = 1 + Math.sin(performance.now() * .0035) * .035;
selected.ring.scale.set(selected.w * .7 * pulse, selected.d * .7 * pulse, 1);
}
renderer.render(scene, camera);
}
resize();
updateCamera();
refresh();
animate();
</script>
</body>
</html>
```