Prompt specification
Build or customize the Three.js 3D scene "Community Square Co-Design Workshop" 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: Community Square Co-Design Workshop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-square-co-design-workshop-x3243
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: community square co-design workshop. Show residents rearranging shade, seating, play, and market modules on a planning table. Preserve requested access routes and make unresolved tradeoffs visible. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (community-square-co-design-workshop-x3243):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Ground — Community Square Co-Design Workshop</title>
<style>
:root {
--ink: #20312d;
--muted: #687872;
--paper: #fbf8ef;
--panel: rgba(251, 248, 239, 0.94);
--green: #34a66f;
--green-soft: #dff3e6;
--cyan: #1ab7aa;
--cyan-soft: #d8f5ef;
--amber: #e6a12c;
--amber-soft: #fff0cf;
--red: #d95656;
--line: rgba(32, 49, 45, 0.13);
--shadow: 0 18px 50px rgba(31, 49, 44, 0.17);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe4df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 22px;
left: 24px;
display: flex;
align-items: stretch;
gap: 12px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 15px 12px 12px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 15px;
background: rgba(251,248,239,.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-3deg);
}
.brand-mark i {
display: block;
border-radius: 3px;
background: var(--green);
}
.brand-mark i:nth-child(1),
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(9) { background: var(--cyan); }
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(8) { background: var(--amber); }
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(6) { background: #89c8a6; }
.eyebrow {
margin: 0 0 3px;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
color: var(--muted);
}
h1 {
margin: 0;
font-size: 19px;
line-height: 1.1;
letter-spacing: -.025em;
}
.subtitle {
margin: 4px 0 0;
font-size: 11px;
color: var(--muted);
}
.live-pill {
align-self: center;
display: flex;
align-items: center;
gap: 8px;
padding: 11px 13px;
border-radius: 13px;
color: #245a41;
background: rgba(223,243,230,.94);
box-shadow: var(--shadow);
font-size: 10px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 5px rgba(52,166,111,.14);
animation: live 2s ease-in-out infinite;
}
@keyframes live {
50% { box-shadow: 0 0 0 8px rgba(52,166,111,0); }
}
.panel {
position: fixed;
z-index: 30;
top: 22px;
right: 22px;
bottom: 22px;
width: 344px;
display: flex;
flex-direction: column;
overflow: hidden;
border: 1px solid rgba(255,255,255,.76);
border-radius: 19px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel-head {
padding: 19px 19px 16px;
border-bottom: 1px solid var(--line);
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.panel-title {
margin: 0;
font-size: 19px;
letter-spacing: -.025em;
}
.count-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border-radius: 999px;
background: var(--amber-soft);
color: #82570e;
font-size: 10px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.count-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
}
.panel-copy {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.panel-actions {
display: flex;
gap: 8px;
margin-top: 14px;
}
.small-button {
min-height: 32px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,.64);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: .18s ease;
}
.small-button:hover {
transform: translateY(-1px);
border-color: rgba(32,49,45,.25);
background: white;
}
.small-button.primary {
border-color: transparent;
background: var(--ink);
color: white;
}
.tradeoff-list {
flex: 1;
overflow-y: auto;
padding: 12px;
scrollbar-width: thin;
scrollbar-color: rgba(32,49,45,.18) transparent;
}
.tradeoff-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 38px 1fr;
gap: 11px;
margin: 0 0 10px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.62);
color: inherit;
text-align: left;
cursor: pointer;
transition: .18s ease;
}
.tradeoff-card:hover,
.tradeoff-card.active {
border-color: rgba(230,161,44,.72);
background: #fffaf0;
transform: translateX(-2px);
box-shadow: 0 8px 24px rgba(102,75,21,.09);
}
.tradeoff-number {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 10px;
background: var(--amber-soft);
color: #8b5b0b;
font-size: 12px;
font-weight: 900;
box-shadow: inset 0 -3px 0 rgba(139,91,11,.08);
}
.tradeoff-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 4px;
}
.tradeoff-meta span:first-child {
color: #946416;
font-size: 9px;
font-weight: 900;
letter-spacing: .13em;
text-transform: uppercase;
}
.open-tag {
padding: 3px 5px;
border-radius: 5px;
background: rgba(230,161,44,.12);
color: #8c5d13;
font-size: 8px;
font-weight: 900;
letter-spacing: .09em;
}
.tradeoff-title {
display: block;
margin-bottom: 4px;
font-size: 13px;
font-weight: 800;
letter-spacing: -.01em;
}
.tradeoff-desc {
display: block;
margin-bottom: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.42;
}
.tag-row {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.tag {
padding: 4px 6px;
border-radius: 5px;
background: rgba(32,49,45,.055);
color: #52625d;
font-size: 8px;
font-weight: 800;
letter-spacing: .06em;
text-transform: uppercase;
}
.panel-foot {
padding: 14px 16px 16px;
border-top: 1px solid var(--line);
background: rgba(255,255,255,.48);
}
.access-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.access-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
}
.access-title::before {
content: "";
width: 19px;
height: 8px;
border-radius: 2px;
background: var(--green);
box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.access-status {
padding: 5px 7px;
border-radius: 6px;
background: var(--green-soft);
color: #277249;
font-size: 9px;
font-weight: 900;
letter-spacing: .05em;
text-transform: uppercase;
}
.access-status.bad {
background: #f8dddd;
color: #9d3535;
}
.protected-copy {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.toolbar {
position: fixed;
z-index: 25;
right: 384px;
top: 22px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 13px;
background: rgba(251,248,239,.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.tool {
height: 34px;
min-width: 34px;
padding: 0 10px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: .04em;
transition: .16s ease;
}
.tool:hover,
.tool[aria-pressed="true"] {
background: var(--cyan-soft);
color: #116e67;
}
.tool:disabled {
opacity: .35;
cursor: default;
}
.legend {
position: fixed;
z-index: 22;
left: 24px;
bottom: 22px;
width: 245px;
padding: 13px 14px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 14px;
background: rgba(251,248,239,.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.legend-title {
margin: 0 0 9px;
font-size: 9px;
font-weight: 900;
letter-spacing: .14em;
text-transform: uppercase;
color: var(--muted);
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
font-size: 10px;
font-weight: 650;
}
.swatch {
width: 14px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.route { background: var(--green); }
.swatch.selected { background: var(--cyan); }
.swatch.tradeoff { background: var(--amber); }
.swatch.blocked { background: var(--red); }
.selection-note {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.selection-note strong {
color: var(--ink);
}
.help {
position: fixed;
z-index: 22;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 999px;
background: rgba(251,248,239,.86);
box-shadow: var(--shadow);
color: var(--muted);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(14px);
pointer-events: none;
white-space: nowrap;
}
.help b { color: var(--ink); }
.key {
padding: 3px 6px;
border: 1px solid rgba(32,49,45,.14);
border-bottom-width: 2px;
border-radius: 5px;
background: white;
color: var(--ink);
font-size: 9px;
}
#labels {
position: fixed;
inset: 0;
z-index: 8;
overflow: hidden;
pointer-events: none;
}
#labels.hidden { display: none; }
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
border: 1px solid rgba(32,49,45,.15);
border-radius: 7px;
background: rgba(255,255,255,.88);
box-shadow: 0 5px 15px rgba(32,49,45,.12);
color: var(--ink);
font-size: 8px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
transform: translate(-50%, -100%);
white-space: nowrap;
transition: border-color .16s, background .16s;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 9px;
background: rgba(32,49,45,.35);
}
.world-label .dot {
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--cyan);
}
.world-label.selected {
border-color: var(--cyan);
background: #e9fffa;
box-shadow: 0 6px 18px rgba(26,183,170,.24);
}
.tradeoff-label {
position: absolute;
display: flex;
align-items: center;
gap: 5px;
padding: 4px 7px 4px 4px;
border: 1px solid rgba(230,161,44,.8);
border-radius: 999px;
background: #fff4d8;
box-shadow: 0 7px 18px rgba(116,77,15,.2);
color: #81560f;
font-size: 8px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
transform: translate(-50%, -100%);
white-space: nowrap;
}
.tradeoff-label b {
width: 19px;
height: 19px;
display: grid;
place-items: center;
border-radius: 50%;
background: var(--amber);
color: white;
font-size: 8px;
}
.route-label {
position: absolute;
padding: 4px 7px;
border: 1px solid rgba(52,166,111,.35);
border-radius: 6px;
background: rgba(231,248,237,.92);
color: #277249;
font-size: 8px;
font-weight: 900;
letter-spacing: .08em;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
}
#toast {
position: fixed;
z-index: 50;
left: 50%;
top: 88px;
max-width: min(460px, calc(100vw - 40px));
padding: 11px 15px;
border-radius: 10px;
background: rgba(32,49,45,.94);
box-shadow: 0 12px 35px rgba(32,49,45,.23);
color: white;
font-size: 11px;
font-weight: 700;
line-height: 1.4;
text-align: center;
opacity: 0;
transform: translate(-50%, -8px);
transition: .22s ease;
pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: rgba(156,47,47,.96); }
#toast.warn { background: rgba(132,86,15,.96); }
@media (max-width: 900px) {
.panel { width: 300px; }
.toolbar { right: 338px; }
.live-pill { display: none; }
.help { display: none; }
.subtitle { display: none; }
}
@media (max-width: 680px) {
.topbar { top: 12px; left: 12px; }
.brand { padding: 9px 11px 9px 9px; }
.brand-mark { width: 31px; height: 31px; }
h1 { font-size: 15px; }
.eyebrow { font-size: 8px; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 39vh;
border-radius: 15px;
}
.panel-head { padding: 12px 14px; }
.panel-copy, .panel-actions, .panel-foot { display: none; }
.tradeoff-list { display: flex; gap: 9px; overflow-x: auto; overflow-y: hidden; }
.tradeoff-card { min-width: 270px; margin: 0; }
.toolbar { top: 76px; right: 12px; }
.legend { display: none; }
.world-label { font-size: 7px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel community square co-design workshop"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div>
<p class="eyebrow">Community square / Co-design lab</p>
<h1>Common Ground</h1>
<p class="subtitle">Residents are testing the shared square, module by module.</p>
</div>
</div>
<div class="live-pill"><span class="live-dot"></span>Live workshop · 14 residents</div>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button class="tool" id="routesBtn" aria-pressed="true" title="Show protected access routes">Routes</button>
<button class="tool" id="labelsBtn" aria-pressed="true" title="Show module labels">Labels</button>
<button class="tool" id="undoBtn" title="Undo the last valid move" disabled>Undo</button>
<button class="tool" id="resetBtn" title="Restore the workshop's starting layout">Reset</button>
</nav>
<aside class="panel" aria-label="Unresolved tradeoffs">
<div class="panel-head">
<div class="panel-kicker">
<h2 class="panel-title">Decision queue</h2>
<span class="count-badge" id="openCount">3 unresolved</span>
</div>
<p class="panel-copy">
These tensions are still open. Amber flags on the table connect each tradeoff to the affected modules.
</p>
<div class="panel-actions">
<button class="small-button primary" id="walkBtn">Reveal next</button>
<button class="small-button" id="showAllBtn">Show all</button>
</div>
</div>
<div class="tradeoff-list" id="tradeoffList"></div>
<div class="panel-foot">
<div class="access-row">
<div class="access-title">Protected access</div>
<div class="access-status" id="accessStatus">4 / 4 clear</div>
</div>
<p class="protected-copy">
Green corridors must remain open. A move that blocks access or overlaps another module is returned to its previous position.
</p>
</div>
</aside>
<section class="legend" aria-label="Scene legend">
<p class="legend-title">Reading the table</p>
<div class="legend-grid">
<div class="legend-item"><span class="swatch route"></span>Protected route</div>
<div class="legend-item"><span class="swatch selected"></span>Selected module</div>
<div class="legend-item"><span class="swatch tradeoff"></span>Open tradeoff</div>
<div class="legend-item"><span class="swatch blocked"></span>Blocked move</div>
</div>
<div class="selection-note" id="selectionNote">
<strong>Try it:</strong> drag a module across the planning table.
</div>
</section>
<div class="help">
<span><b>Drag</b> modules</span>
<span>·</span>
<span><b>Drag empty space</b> to orbit</span>
<span>·</span>
<span><b>Scroll</b> to zoom</span>
<span>·</span>
<span><span class="key">↑↓←→</span> nudge</span>
</div>
<div id="labels"></div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const toast = document.querySelector("#toast");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dbe4df");
scene.fog = new THREE.Fog("#dbe4df", 22, 39);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 80);
const cameraTarget = new THREE.Vector3(0.7, 0.8, 0);
let cameraTheta = 0.56;
let cameraPhi = 0.78;
let cameraRadius = 15.2;
const hemi = new THREE.HemisphereLight(0xf7fcff, 0x8a7462, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedcf, 3.2);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 34;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8d9df, 0.75);
fill.position.set(8, 7, -8);
scene.add(fill);
const TABLE_Y = 1.44;
const MODULE_Y = 1.47;
const TABLE_X = 4.35;
const TABLE_Z = 2.82;
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
}));
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || material(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function lineSegments(points, color, opacity = 1) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(points, 3));
const lines = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({ color, transparent: opacity < 1, opacity })
);
scene.add(lines);
return lines;
}
function makeFloorGrid() {
const points = [];
for (let x = -10; x <= 10; x += 1) {
points.push(x, -0.045, -8, x, -0.045, 8);
}
for (let z = -8; z <= 8; z += 1) {
points.push(-10, -0.045, z, 10, -0.045, z);
}
lineSegments(points, 0xaebcb5, 0.34);
}
function makeTableGrid() {
const points = [];
for (let x = -4; x <= 4; x += 0.5) {
points.push(x, 1.447, -2.8, x, 1.447, 2.8);
}
for (let z = -2.5; z <= 2.5; z += 0.5) {
points.push(-4.3, 1.447, z, 4.3, 1.447, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(points, 3));
const grid = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({ color: 0x72857e, transparent: true, opacity: 0.19 })
);
scene.add(grid);
}
// Workshop room.
box(scene, [21, 0.3, 17], [0, -0.2, 0], "#cbd6cf");
makeFloorGrid();
box(scene, [21, 5.7, 0.32], [0, 2.65, -8.2], "#e8e6dc");
box(scene, [0.32, 5.7, 17], [-10.35, 2.65, 0], "#dce1da");
box(scene, [21, 0.18, 0.13], [0, 0.08, -8.01], "#aebbb3");
box(scene, [0.13, 0.18, 17], [-10.16, 0.08, 0], "#aebbb3");
// Voxel window and pinned design wall.
box(scene, [4.5, 2.45, 0.16], [-6.2, 3.25, -7.98], "#8ebbc0");
box(scene, [4.25, 2.2, 0.08], [-6.2, 3.25, -7.87], "#b9dde0");
box(scene, [0.12, 2.35, 0.12], [-6.2, 3.25, -7.78], "#edf0e9");
box(scene, [4.35, 0.12, 0.12], [-6.2, 3.25, -7.78], "#edf0e9");
box(scene, [5.25, 2.5, 0.16], [0.7, 3.25, -7.97], "#a77e56");
box(scene, [5.02, 2.28, 0.08], [0.7, 3.25, -7.86], "#f1eee2");
const noteColors = ["#f2c66d", "#f28e79", "#7fc5b6", "#9bb9d8", "#d8b4d4"];
const notePositions = [
[-1.25, 3.72, 1.05, .72], [-.05, 3.74, .9, .62], [1.1, 3.66, 1.15, .78],
[-1.1, 2.8, 1.25, .68], [.05, 2.84, .85, .74], [1.38, 2.82, .95, .68],
[2.35, 3.55, .68, .82]
];
notePositions.forEach((p, i) => {
box(scene, [p[2], p[3], .035], [p[0], p[1], -7.79], noteColors[i % noteColors.length]);
});
box(scene, [0.04, 2.1, .06], [0.68, 3.25, -7.74], "#b9ad95");
box(scene, [4.8, .035, .06], [0.68, 3.25, -7.74], "#b9ad95");
// Shelving and workshop supplies.
box(scene, [0.8, .12, 4.2], [-9.72, 1.4, -1.8], "#9a7858");
box(scene, [0.8, .12, 4.2], [-9.72, 2.7, -1.8], "#9a7858");
for (let i = 0; i < 6; i++) {
box(scene, [.45, .55, .55], [-9.65, 1.75, -3.25 + i * .62], i % 2 ? "#83b5a3" : "#d8b56f");
box(scene, [.45, .45, .5], [-9.65, 3.0, -3.25 + i * .62], i % 2 ? "#d9a274" : "#91b9c8");
}
// Planning table.
const table = new THREE.Group();
scene.add(table);
box(table, [9.5, .25, 6.4], [0, 1.28, 0], "#a77b54");
box(table, [9.25, .06, 6.16], [0, 1.43, 0], "#e9dfca");
[-3.9, 3.9].forEach(x => {
[-2.55, 2.55].forEach(z => {
box(table, [.34, 1.16, .34], [x, .58, z], "#5e685f");
});
});
box(table, [8.15, .18, .22], [0, .98, -2.55], "#5e685f");
box(table, [8.15, .18, .22], [0, .98, 2.55], "#5e685f");
makeTableGrid();
// Small workshop tools and loose plans.
box(table, [.46, .04, .32], [-1.85, 1.485, 2.35], "#f6f1e4", { castShadow: false });
box(table, [.36, .04, .27], [-1.35, 1.49, 2.43], "#f6f1e4", { castShadow: false });
box(table, [.22, .36, .22], [3.95, 1.64, -2.35], "#416f67");
for (let i = 0; i < 4; i++) {
box(table, [.035, .32, .035], [3.87 + i * .05, 1.86, -2.35], i % 2 ? "#e5a83e" : "#e26f62");
}
// Requested access routes.
const routeDefs = [
{ id: "A", x: -3.6, z: -0.875, w: .75, d: 4.05 },
{ id: "B", x: 0, z: 1.35, w: 7.4, d: .75 },
{ id: "C", x: 2.75, z: -.675, w: .75, d: 3.3 },
{ id: "D", x: 3.75, z: 2.1, w: 1.35, d: 1.0 }
];
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMaterials = [];
function makeRoute(route) {
const group = new THREE.Group();
group.position.set(route.x, 0, route.z);
routeGroup.add(group);
const fillMaterial = new THREE.MeshBasicMaterial({
color: 0x34a66f,
transparent: true,
opacity: .22,
depthWrite: false
});
routeMaterials.push(fillMaterial);
box(group, [route.w, .016, route.d], [0, 1.46, 0], fillMaterial, {
castShadow: false,
receiveShadow: false
});
const borderMaterial = new THREE.MeshBasicMaterial({
color: 0x248c5b,
transparent: true,
opacity: .72,
depthWrite: false
});
routeMaterials.push(borderMaterial);
box(group, [route.w, .022, .035], [0, 1.476, -route.d / 2], borderMaterial, { castShadow: false });
box(group, [route.w, .022, .035], [0, 1.476, route.d / 2], borderMaterial, { castShadow: false });
box(group, [.035, .022, route.d], [-route.w / 2, 1.476, 0], borderMaterial, { castShadow: false });
box(group, [.035, .022, route.d], [route.w / 2, 1.476, 0], borderMaterial, { castShadow: false });
if (route.w > route.d) {
for (let x = -route.w / 2 + .25; x < route.w / 2; x += .42) {
box(group, [.18, .023, .035], [x, 1.482, 0], 0xa5e2b8, { castShadow: false });
}
} else {
for (let z = -route.d / 2 + .25; z < route.d / 2; z += .42) {
box(group, [.035, .023, .18], [0, 1.482, z], 0xa5e2b8, { castShadow: false });
}
}
}
routeDefs.forEach(makeRoute);
const moduleSpecs = [
{ id: "shade", label: "Shade canopy", x: -1.25, z: -1.7, w: 1.8, d: 1.15, color: "#2da9a1" },
{ id: "seating", label: "Seating", x: 1.2, z: -2.15, w: 1.5, d: 1.0, color: "#6aa77e" },
{ id: "play", label: "Play", x: -.75, z: -.05, w: 1.75, d: 1.25, color: "#e6a12c" },
{ id: "market", label: "Market", x: 1.15, z: -.15, w: 1.7, d: 1.1, color: "#df765e" }
];
const moduleGroups = [];
const moduleById = new Map();
function addSelectionFrame(root, w, d) {
const frameMaterial = new THREE.MeshBasicMaterial({
color: 0x1ab7aa,
transparent: true,
opacity: .92,
depthWrite: false
});
const group = new THREE.Group();
group.position.y = .025;
root.add(group);
box(group, [w, .028, .035], [0, 0, -d / 2], frameMaterial, { castShadow: false });
box(group, [w, .028, .035], [0, 0, d / 2], frameMaterial, { castShadow: false });
box(group, [.035, .028, d], [-w / 2, 0, 0], frameMaterial, { castShadow: false });
box(group, [.035, .028, d], [w / 2, 0, 0], frameMaterial, { castShadow: false });
return { group, material: frameMaterial };
}
function buildShade(root) {
box(root, [1.72, .07, 1.08], [0, .05, 0], "#bad9cd");
[-.68, .68].forEach(x => {
[-.4, .4].forEach(z => {
box(root, [.09, .92, .09], [x, .49, z], "#8c6847");
});
});
box(root, [1.72, .12, 1.06], [0, .98, 0], "#38a9a3");
for (let i = 0; i < 6; i++) {
box(root, [.13, .025, 1.02], [-.68 + i * .27, 1.055, 0], "#d9efe4");
}
box(root, [.08, .08, .92], [-.62, .8, 0], "#257e79");
box(root, [.08, .08, .92], [.62, .8, 0], "#257e79");
}
function buildSeating(root) {
box(root, [1.45, .06, .95], [0, .05, 0], "#a9c8a2");
[-.3, .3].forEach(z => {
box(root, [.98, .12, .23], [0, .24, z], "#a8794f");
box(root, [.98, .04, .055], [0, .32, z - .07], "#c49462");
box(root, [.98, .04, .055], [0, .32, z + .07], "#c49462");
[-.37, .37].forEach(x => box(root, [.08, .2, .15], [x, .13, z], "#5f6257"));
});
box(root, [.3, .22, .3], [.54, .19, .28], "#be6f55");
box(root, [.18, .22, .18], [.54, .39, .28], "#5b9b67");
box(root, [.12, .12, .12], [.54, .56, .28], "#7cba78");
}
function buildPlay(root) {
box(root, [1.7, .07, 1.2], [0, .05, 0], "#efd48a");
box(root, [.34, .34, .34], [-.57, .25, -.34], "#5ca8b6");
box(root, [.28, .28, .28], [-.18, .22, -.36], "#e47862");
box(root, [.4, .22, .4], [-.55, .16, .28], "#7db879");
box(root, [.24, .48, .24], [.35, .31, -.34], "#6c7dba");
box(root, [.25, .34, .25], [.58, .24, -.3], "#eea740");
// A stepped voxel slide.
box(root, [.28, .18, .35], [.18, .16, .38], "#e46f5d");
box(root, [.28, .34, .35], [.43, .25, .38], "#e46f5d");
box(root, [.28, .5, .35], [.68, .33, .38], "#e46f5d");
box(root, [.52, .08, .33], [.58, .58, .31], "#f29c68");
box(root, [.08, .35, .08], [.28, .45, .19], "#5e8e8b");
box(root, [.08, .35, .08], [.28, .45, .57], "#5e8e8b");
}
function buildMarket(root) {
box(root, [1.65, .06, 1.05], [0, .05, 0], "#e8d6b8");
[-.54, .05, .61].forEach((x, i) => {
box(root, [.46, .38, .42], [x, .27, -.15], "#93694a");
box(root, [.53, .09, .48], [x, .5, -.15], i % 2 ? "#e37b63" : "#6ba99b");
box(root, [.12, .53, .12], [x - .21, .38, .12], "#75573e");
box(root, [.12, .53, .12], [x + .21, .38, .12], "#75573e");
for (let s = 0; s < 4; s++) {
box(root, [.12, .025, .48], [x - .19 + s * .13, .56, -.15], i % 2 ? "#f2c278" : "#d9efe4");
}
});
box(root, [.3, .22, .28], [-.27, .19, .38], "#a76d42");
box(root, [.28, .18, .25], [.28, .17, .39], "#d3a650");
box(root, [.2, .17, .2], [.66, .16, .38], "#7fa568");
}
moduleSpecs.forEach(spec => {
const root = new THREE.Group();
root.position.set(spec.x, MODULE_Y, spec.z);
root.userData.moduleId = spec.id;
scene.add(root);
const padMaterial = new THREE.MeshBasicMaterial({
color: 0x1ab7aa,
transparent: true,
opacity: 0,
depthWrite: false
});
const pad = box(root, [spec.w, .018, spec.d], [0, .012, 0], padMaterial, {
castShadow: false,
receiveShadow: false
});
if (spec.id === "shade") buildShade(root);
if (spec.id === "seating") buildSeating(root);
if (spec.id === "play") buildPlay(root);
if (spec.id === "market") buildMarket(root);
const frame = addSelectionFrame(root, spec.w, spec.d);
frame.group.visible = false;
spec.root = root;
spec.pad = pad;
spec.padMaterial = padMaterial;
spec.frame = frame;
spec.home = { x: spec.x, z: spec.z };
moduleGroups.push(root);
moduleById.set(spec.id, spec);
});
// Voxel residents.
function createResident(options) {
const group = new THREE.Group();
group.position.set(options.x, 0, options.z);
scene.add(group);
const skin = options.skin || "#c98f68";
const shirt = options.shirt || "#4d8e86";
const hair = options.hair || "#3e342d";
const trousers = options.trousers || "#344c55";
box(group, [.46, .62, .31], [0, 1.05, 0], shirt);
box(group, [.33, .18, .28], [0, 1.42, 0], skin);
box(group, [.38, .36, .34], [0, 1.72, 0], skin);
box(group, [.4, .13, .36], [0, 1.91, -.01], hair);
box(group, [.14, .67, .16], [-.13, .39, 0], trousers);
box(group, [.14, .67, .16], [.13, .39, 0], trousers);
box(group, [.18, .13, .29], [-.13, .055, .07], "#26312f");
box(group, [.18, .13, .29], [.13, .055, .07], "#26312f");
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-.31, 1.29, 0);
armR.position.set(.31, 1.29, 0);
group.add(armL, armR);
box(armL, [.13, .52, .15], [0, -.22, 0], shirt);
box(armR, [.13, .52, .15], [0, -.22, 0], shirt);
box(armL, [.13, .14, .15], [0, -.52, 0], skin);
box(armR, [.13, .14, .15], [0, -.52, 0], skin);
if (options.clipboard) {
box(group, [.4, .48, .055], [.12, 1.08, .27], "#d9a65c");
box(group, [.31, .38, .02], [.12, 1.1, .305], "#f4efe2");
}
group.rotation.y = options.rotation || 0;
group.userData = {
armL,
armR,
baseX: options.x,
baseZ: options.z,
targetX: options.x,
targetZ: options.z,
phase: options.phase || 0,
active: false,
activeUntil: 0,
assigned: options.assigned || null
};
return group;
}
const residents = [
createResident({ x: -2.4, z: -3.65, shirt: "#4c9b8d", assigned: "shade", phase: .4 }),
createResident({ x: -.35, z: -3.65, shirt: "#d77662", skin: "#9b674a", hair: "#292725", assigned: "play", phase: 1.3 }),
createResident({ x: 1.55, z: -3.65, shirt: "#6f8fb4", skin: "#e2ad82", assigned: "seating", phase: 2.1 }),
createResident({ x: 3.55, z: -3.65, shirt: "#d29c40", skin: "#b97c58", assigned: "market", phase: 2.8 }),
createResident({ x: .6, z: 3.75, shirt: "#7a65a2", skin: "#d7a078", clipboard: true, phase: .8 }),
createResident({ x: -5.05, z: .65, shirt: "#b26774", skin: "#e2b18c", phase: 1.8, rotation: 1.5 })
];
// Unresolved tradeoffs and physical table markers.
const tradeoffs = [
{
id: "t1",
number: "01",
title: "Shade ↔ continuous play",
description: "Seasonal sun comfort competes with an uninterrupted play edge.",
modules: ["shade", "play"],
tags: ["Shade", "Play"],
x: -.75,
z: -.9,
markerSize: 1.25
},
{
id: "t2",
number: "02",
title: "Market ↔ quiet seating",
description: "More stall frontage leaves less room for a calm, social perch.",
modules: ["market", "seating"],
tags: ["Market", "Seating"],
x: 1.25,
z: -1.55,
markerSize: 1.15
},
{
id: "t3",
number: "03",
title: "Step-free arrival ↔ event load-in",
description: "A continuous accessible approach reduces space for event servicing.",
modules: ["market"],
tags: ["Access D", "Service"],
x: 3.73,
z: 2.1,
markerSize: 1.15
}
];
const markerGroup = new THREE.Group();
scene.add(markerGroup);
function createTradeoffMarker(tradeoff) {
const root = new THREE.Group();
root.position.set(tradeoff.x, MODULE_Y + .02, tradeoff.z);
markerGroup.add(root);
const material = new THREE.MeshBasicMaterial({
color: 0xe6a12c,
transparent: true,
opacity: .84,
depthWrite: false
});
const s = tradeoff.markerSize;
box(root, [s, .025, .035], [0, .02, -s / 2], material, { castShadow: false });
box(root, [s, .025, .035], [0, .02, s / 2], material, { castShadow: false });
box(root, [.035, .025, s], [-s / 2, .02, 0], material, { castShadow: false });
box(root, [.035, .025, s], [s / 2, .02, 0], material, { castShadow: false });
box(root, [.045, .68, .045], [-s / 2, .35, -s / 2], 0xb77c19);
box(root, [.3, .2, .045], [-s / 2 + .13, .61, -s / 2], 0xf0b33d);
box(root, [.07, .07, .06], [-s / 2 + .12, .61, -s / 2 - .04], 0x805711);
root.userData = {
tradeoff,
material,
pulse: 0,
phase: Math.random() * Math.PI * 2
};
return root;
}
tradeoffs.forEach(t => {
t.marker = createTradeoffMarker(t);
});
// DOM labels projected from their 3D anchors.
const labelEntries = [];
moduleSpecs.forEach(spec => {
const element = document.createElement("div");
element.className = "world-label";
element.innerHTML = `<span class="dot"></span>${spec.label}`;
labelsLayer.appendChild(element);
labelEntries.push({
element,
anchor: new THREE.Vector3(0, spec.id === "shade" ? 1.25 : .95, 0),
object: spec.root,
kind: "module",
id: spec.id
});
});
tradeoffs.forEach(t => {
const element = document.createElement("div");
element.className = "tradeoff-label";
element.innerHTML = `<b>${t.number}</b>Open tradeoff`;
labelsLayer.appendChild(element);
labelEntries.push({
element,
anchor: new THREE.Vector3(0, .95, 0),
object: t.marker,
kind: "tradeoff",
id: t.id
});
});
const routeLabelElement = document.createElement("div");
routeLabelElement.className = "route-label";
routeLabelElement.textContent = "Access · 1.5 m minimum";
labelsLayer.appendChild(routeLabelElement);
const routeLabelEntry = {
element: routeLabelElement,
anchor: new THREE.Vector3(-.4, .25, 0),
object: new THREE.Object3D(),
kind: "route"
};
routeLabelEntry.object.position.set(-.4, 1.7, 1.35);
labelEntries.push(routeLabelEntry);
// Blocked-move beacon.
const invalidBeacon = new THREE.Group();
scene.add(invalidBeacon);
const invalidMaterial = new THREE.MeshBasicMaterial({
color: 0xd95656,
transparent: true,
opacity: .72,
depthWrite: false
});
box(invalidBeacon, [.75, .028, .035], [0, .03, -.375], invalidMaterial, { castShadow: false });
box(invalidBeacon, [.75, .028, .035], [0, .03, .375], invalidMaterial, { castShadow: false });
box(invalidBeacon, [.035, .028, .75], [-.375, .03, 0], invalidMaterial, { castShadow: false });
box(invalidBeacon, [.035, .028, .75], [.375, .03, 0], invalidMaterial, { castShadow: false });
box(invalidBeacon, [.06, .55, .06], [0, .3, 0], 0xc83f46);
box(invalidBeacon, [.19, .19, .07], [0, .58, 0], 0xd95656);
invalidBeacon.visible = false;
// Decision queue cards.
const tradeoffList = document.querySelector("#tradeoffList");
tradeoffList.innerHTML = tradeoffs.map(t => `
<button class="tradeoff-card" data-id="${t.id}" type="button">
<span class="tradeoff-number">${t.number}</span>
<span>
<span class="tradeoff-meta">
<span>Decision tension</span>
<span class="open-tag">Open</span>
</span>
<span class="tradeoff-title">${t.title}</span>
<span class="tradeoff-desc">${t.description}</span>
<span class="tag-row">${t.tags.map(tag => `<span class="tag">${tag}</span>`).join("")}</span>
</span>
</button>
`).join("");
const cards = [...document.querySelectorAll(".tradeoff-card")];
let selectedModule = null;
let tradeoffFocus = null;
let dragState = null;
let orbitState = null;
let returnTween = null;
let invalidUntil = 0;
let routesVisible = true;
let labelsVisible = true;
let toastTimer = null;
const history = [];
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -(MODULE_Y + .025));
const planePoint = new THREE.Vector3();
function showToast(message, type = "ok") {
toast.textContent = message;
toast.className = "show";
if (type === "bad") toast.classList.add("bad");
if (type === "warn") toast.classList.add("warn");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.className = "";
}, 2800);
}
function rectsOverlap(a, b, margin = 0) {
return (
a.x - a.w / 2 < b.x + b.w / 2 + margin &&
a.x + a.w / 2 > b.x - b.w / 2 - margin &&
a.z - a.d / 2 < b.z + b.d / 2 + margin &&
a.z + a.d / 2 > b.z - b.d / 2 - margin
);
}
function evaluatePlacement(spec, x, z) {
const candidate = { x, z, w: spec.w, d: spec.d };
if (
x - spec.w / 2 < -TABLE_X ||
x + spec.w / 2 > TABLE_X ||
z - spec.d / 2 < -TABLE_Z ||
z + spec.d / 2 > TABLE_Z
) {
return { valid: false, reason: "Keep the module fully on the planning table." };
}
for (const route of routeDefs) {
if (rectsOverlap(candidate, route, .015)) {
return {
valid: false,
reason: "Access held: keep the green 1.5 m route clear.",
route: route.id
};
}
}
for (const other of moduleSpecs) {
if (other.id === spec.id) continue;
const otherRect = {
x: other.root.position.x,
z: other.root.position.z,
w: other.w,
d: other.d
};
if (rectsOverlap(candidate, otherRect, .025)) {
return {
valid: false,
reason: "Modules need their own clear space on the table."
};
}
}
return { valid: true };
}
function updateModuleVisuals() {
moduleSpecs.forEach(spec => {
const isSelected = selectedModule === spec.id;
const related = tradeoffs.find(t => t.id === tradeoffFocus && t.modules.includes(spec.id));
const isDragging = dragState?.spec.id === spec.id;
const invalid = isDragging && !dragState.valid;
spec.frame.group.visible = isSelected || Boolean(related) || isDragging;
spec.padMaterial.opacity = isSelected ? .22 : isDragging ? .18 : 0;
spec.padMaterial.color.set(invalid ? 0xd95656 : related ? 0xe6a12c : 0x1ab7aa);
const color = invalid ? 0xd95656 : related ? 0xe6a12c : 0x1ab7aa;
spec.frame.material.color.set(color);
spec.frame.material.opacity = isSelected || invalid ? .96 : .66;
});
labelEntries.forEach(entry => {
if (entry.kind === "module") {
entry.element.classList.toggle("selected", entry.id === selectedModule);
}
});
cards.forEach(card => {
card.classList.toggle("active", card.dataset.id === tradeoffFocus);
});
const selected = moduleById.get(selectedModule);
document.querySelector("#selectionNote").innerHTML = selected
? `<strong>${selected.label}:</strong> drag to test a position, or use arrow keys to nudge.`
: `<strong>Try it:</strong> drag a module across the planning table.`;
}
function updateAccessStatus() {
let threatened = 0;
moduleSpecs.forEach(spec => {
const rect = { x: spec.root.position.x, z: spec.root.position.z, w: spec.w, d: spec.d };
if (routeDefs.some(route => rectsOverlap(rect, route, .01))) threatened++;
});
const status = document.querySelector("#accessStatus");
if (threatened) {
status.textContent = `${threatened} threatened`;
status.classList.add("bad");
} else {
status.textContent = `${routeDefs.length} / ${routeDefs.length} clear`;
status.classList.remove("bad");
}
}
function setSelected(id) {
selectedModule = id;
updateModuleVisuals();
}
function focusTradeoff(id, announce = true) {
tradeoffFocus = id;
tradeoffs.forEach(t => {
t.marker.userData.pulse = t.id === id ? 1 : 0;
});
updateModuleVisuals();
if (announce) {
const t = tradeoffs.find(item => item.id === id);
showToast(`Open decision ${t.number}: ${t.title}. Both sides remain visible.`, "warn");
}
}
cards.forEach(card => {
card.addEventListener("click", () => focusTradeoff(card.dataset.id));
});
let walkIndex = 0;
document.querySelector("#walkBtn").addEventListener("click", () => {
const t = tradeoffs[walkIndex % tradeoffs.length];
walkIndex++;
focusTradeoff(t.id);
});
document.querySelector("#showAllBtn").addEventListener("click", () => {
tradeoffFocus = null;
tradeoffs.forEach(t => t.marker.userData.pulse = 0);
updateModuleVisuals();
showToast("All unresolved decisions and access routes are visible.");
});
function updatePointer(event) {
const rect = canvas.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);
}
function pickModule(event) {
updatePointer(event);
const hits = raycaster.intersectObjects(moduleGroups, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object && !object.userData.moduleId) object = object.parent;
return object?.userData.moduleId || null;
}
function findResidentForModule(id) {
return residents.find(resident => resident.userData.assigned === id);
}
function workerTarget(spec) {
const x = spec.root.position.x;
const z = spec.root.position.z;
const options = [
{ d: 3.55 - z, x, z: 3.55 },
{ d: z + 3.55, x, z: -3.55 },
{ d: x + 4.95, x: -4.95, z },
{ d: 4.95 - x, x: 4.95, z }
];
options.sort((a, b) => a.d - b.d);
return options[0];
}
function beginDrag(event, spec) {
raycaster.ray.intersectPlane(dragPlane, planePoint);
if (!planePoint) return;
setSelected(spec.id);
const worker = findResidentForModule(spec.id);
if (worker) {
worker.userData.active = true;
worker.userData.activeUntil = performance.now() + 4000;
}
dragState = {
spec,
offsetX: spec.root.position.x - planePoint.x,
offsetZ: spec.root.position.z - planePoint.z,
original: { x: spec.root.position.x, z: spec.root.position.z },
moved: false,
valid: true,
reason: ""
};
canvas.style.cursor = "grabbing";
updateModuleVisuals();
}
function moveDrag(event) {
if (!dragState) return;
updatePointer(event);
if (!raycaster.ray.intersectPlane(dragPlane, planePoint)) return;
const spec = dragState.spec;
const rawX = planePoint.x + dragState.offsetX;
const rawZ = planePoint.z + dragState.offsetZ;
const x = THREE.MathUtils.clamp(
Math.round(rawX / .25) * .25,
-TABLE_X + spec.w / 2,
TABLE_X - spec.w / 2
);
const z = THREE.MathUtils.clamp(
Math.round(rawZ / .25) * .25,
-TABLE_Z + spec.d / 2,
TABLE_Z - spec.d / 2
);
spec.root.position.x = x;
spec.root.position.z = z;
const distance = Math.hypot(x - dragState.original.x, z - dragState.original.z);
if (distance > .08) dragState.moved = true;
const result = evaluatePlacement(spec, x, z);
dragState.valid = result.valid;
dragState.reason = result.reason;
invalidBeacon.visible = !result.valid;
if (!result.valid) {
invalidBeacon.position.set(x, MODULE_Y + .02, z);
invalidUntil = performance.now() + 250;
}
updateModuleVisuals();
updateAccessStatus();
}
function startTween(spec, to, duration = 430) {
returnTween = {
spec,
fromX: spec.root.position.x,
fromZ: spec.root.position.z,
toX: to.x,
toZ: to.z,
start: performance.now(),
duration
};
}
function finishDrag() {
if (!dragState) return;
const state = dragState;
dragState = null;
if (state.moved && state.valid) {
history.push({
id: state.spec.id,
from: { ...state.original },
to: { x: state.spec.root.position.x, z: state.spec.root.position.z }
});
document.querySelector("#undoBtn").disabled = false;
showToast(`${state.spec.label} placed · all protected access routes remain clear.`);
} else if (state.moved && !state.valid) {
startTween(state.spec, state.original);
showToast(state.reason || "That move was blocked.", "bad");
invalidUntil = performance.now() + 1100;
} else {
showToast(`${state.spec.label} selected · drag to test another position.`);
}
const worker = findResidentForModule(state.spec.id);
if (worker) worker.userData.activeUntil = performance.now() + 1200;
updateModuleVisuals();
updateAccessStatus();
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
const id = pickModule(event);
if (id) {
beginDrag(event, moduleById.get(id));
canvas.setPointerCapture(event.pointerId);
} else {
orbitState = {
x: event.clientX,
y: event.clientY,
theta: cameraTheta,
phi: cameraPhi
};
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
}
});
canvas.addEventListener("pointermove", event => {
if (dragState) {
moveDrag(event);
} else if (orbitState) {
const dx = event.clientX - orbitState.x;
const dy = event.clientY - orbitState.y;
cameraTheta = orbitState.theta - dx * .006;
cameraPhi = THREE.MathUtils.clamp(orbitState.phi - dy * .004, .45, 1.23);
} else {
const id = pickModule(event);
canvas.style.cursor = id ? "grab" : "default";
}
});
canvas.addEventListener("pointerup", event => {
if (dragState) finishDrag();
orbitState = null;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
});
canvas.addEventListener("pointercancel", () => {
if (dragState) finishDrag();
orbitState = null;
canvas.style.cursor = "default";
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(cameraRadius + event.deltaY * .008, 10.5, 22);
}, { passive: false });
document.querySelector("#routesBtn").addEventListener("click", event => {
routesVisible = !routesVisible;
routeGroup.visible = routesVisible;
routeLabelElement.style.display = routesVisible ? "" : "none";
event.currentTarget.setAttribute("aria-pressed", String(routesVisible));
showToast(routesVisible ? "Protected access routes shown." : "Routes hidden visually; route protection remains active.");
});
document.querySelector("#labelsBtn").addEventListener("click", event => {
labelsVisible = !labelsVisible;
labelsLayer.classList.toggle("hidden", !labelsVisible);
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
});
document.querySelector("#undoBtn").addEventListener("click", () => {
const move = history.pop();
if (!move) return;
const spec = moduleById.get(move.id);
startTween(spec, move.from);
document.querySelector("#undoBtn").disabled = history.length === 0;
showToast(`Last valid move reversed for ${spec.label}.`);
});
document.querySelector("#resetBtn").addEventListener("click", () => {
moduleSpecs.forEach(spec => {
spec.root.position.set(spec.home.x, MODULE_Y, spec.home.z);
});
history.length = 0;
document.querySelector("#undoBtn").disabled = true;
tradeoffFocus = null;
tradeoffs.forEach(t => t.marker.userData.pulse = 0);
invalidBeacon.visible = false;
updateModuleVisuals();
updateAccessStatus();
showToast("The starting workshop layout has been restored.");
});
// Keyboard nudging keeps the same protected-route rules.
window.addEventListener("keydown", event => {
if (!selectedModule) return;
const spec = moduleById.get(selectedModule);
const step = event.shiftKey ? .5 : .25;
let dx = 0;
let dz = 0;
if (event.key === "ArrowLeft") dx = -step;
if (event.key === "ArrowRight") dx = step;
if (event.key === "ArrowUp") dz = -step;
if (event.key === "ArrowDown") dz = step;
if (!dx && !dz) return;
event.preventDefault();
const x = spec.root.position.x + dx;
const z = spec.root.position.z + dz;
const result = evaluatePlacement(spec, x, z);
if (!result.valid) {
showToast(result.reason, "bad");
return;
}
const from = { x: spec.root.position.x, z: spec.root.position.z };
spec.root.position.x = x;
spec.root.position.z = z;
history.push({ id: spec.id, from, to: { x, z } });
document.querySelector("#undoBtn").disabled = false;
showToast(`${spec.label} nudged · access remains clear.`);
updateAccessStatus();
});
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function updateResidents(time) {
residents.forEach((resident, index) => {
const data = resident.userData;
const assigned = moduleById.get(data.assigned);
if (assigned && (data.active || time < data.activeUntil)) {
const target = workerTarget(assigned);
data.targetX = target.x;
data.targetZ = target.z;
data.active = true;
}
const dx = data.targetX - resident.position.x;
const dz = data.targetZ - resident.position.z;
resident.position.x += dx * .035;
resident.position.z += dz * .035;
if (Math.hypot(dx, dz) > .08) {
const desired = Math.atan2(dx, dz);
let delta = desired - resident.rotation.y;
delta = Math.atan2(Math.sin(delta), Math.cos(delta));
resident.rotation.y += delta * .07;
}
const isActive = data.active && time < data.activeUntil;
const idle = Math.sin(time * 2 + data.phase) * .025;
resident.position.y = idle;
data.armL.rotation.x = isActive ? -1.05 + Math.sin(time * 7 + index) * .12 : .08 + idle;
data.armR.rotation.x = isActive ? -1.05 - Math.sin(time * 7 + index) * .12 : -.08 - idle;
data.armL.rotation.z = isActive ? -.28 : -.05;
data.armR.rotation.z = isActive ? .28 : .05;
if (time > data.activeUntil) data.active = false;
});
}
function updateTradeoffMarkers(time) {
tradeoffs.forEach(t => {
const data = t.marker.userData;
data.pulse = Math.max(0, data.pulse - .012);
const bob = Math.sin(time * 2.2 + data.phase) * .025;
t.marker.position.y = MODULE_Y + .02 + bob;
const focused = tradeoffFocus === t.id;
const pulse = focused ? 1 + Math.sin(time * 6) * .06 : 1;
t.marker.scale.set(pulse, 1, pulse);
data.material.opacity = focused ? 1 : .76;
});
}
function updateTween(time) {
if (!returnTween) return;
const tween = returnTween;
const t = THREE.MathUtils.clamp((time - tween.start) / tween.duration, 0, 1);
const eased = 1 - Math.pow(1 - t, 3);
tween.spec.root.position.x = THREE.MathUtils.lerp(tween.fromX, tween.toX, eased);
tween.spec.root.position.z = THREE.MathUtils.lerp(tween.fromZ, tween.toZ, eased);
if (t >= 1) returnTween = null;
}
const projected = new THREE.Vector3();
function updateLabels() {
if (!labelsVisible) return;
labelEntries.forEach(entry => {
projected.copy(entry.anchor);
entry.object.localToWorld(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
entry.element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * .5 + .5) * window.innerWidth;
const y = (-projected.y * .5 + .5) * window.innerHeight;
entry.element.style.left = `${x}px`;
entry.element.style.top = `${y}px`;
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateModuleVisuals();
updateAccessStatus();
updateCamera();
function animate(time) {
requestAnimationFrame(animate);
updateCamera();
updateResidents(time);
updateTradeoffMarkers(time);
updateTween(time);
if (!invalidBeacon.visible && time > invalidUntil) {
invalidBeacon.visible = false;
}
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```