Prompt specification
Build or customize the Three.js 3D scene "Schedule a build around limited access" 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: Schedule a build around limited access
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schedule-a-build-around-limited-access-x2188
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing construction stages with structural dependencies. Let users sequence a small pavilion's components with one crane access corridor. Reject orders that block a required delivery path or place elements before their supporting structure exists. Low-poly.
Working Three.js Starter (schedule-a-build-around-limited-access-x2188):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pavilion 07 — Structural Sequencing</title>
<style>
:root {
--ink: #17231f;
--muted: #69736e;
--paper: #f6f3eb;
--panel: #fbfaf6;
--line: #d9d4c8;
--green: #226b56;
--green-soft: #e1eee8;
--orange: #cf6d3e;
--orange-soft: #f7e7dc;
--red: #b8443d;
--red-soft: #f7dfdc;
--yellow: #d7a83e;
--shadow: 0 12px 30px rgba(24, 35, 31, 0.08);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
.app {
height: 100vh;
display: flex;
flex-direction: column;
}
.topbar {
min-height: 82px;
padding: 15px 22px;
display: flex;
align-items: center;
gap: 22px;
color: #f8f5ed;
background: var(--ink);
border-bottom: 1px solid rgba(255, 255, 255, 0.09);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 248px;
}
.brand-mark {
width: 43px;
height: 43px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.24);
background: rgba(255, 255, 255, 0.05);
}
.brand-mark svg {
width: 27px;
height: 27px;
}
.eyebrow {
margin: 0 0 3px;
font-size: 10px;
line-height: 1;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
opacity: 0.62;
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1.1;
letter-spacing: -0.02em;
}
.project-meta {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
color: rgba(255, 255, 255, 0.72);
font-size: 12px;
}
.meta-divider {
width: 1px;
height: 25px;
background: rgba(255, 255, 255, 0.16);
}
.top-actions {
margin-left: auto;
display: flex;
align-items: center;
gap: 9px;
}
.progress-pill {
min-width: 112px;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 999px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
}
.header-button {
height: 37px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.19);
border-radius: 4px;
color: white;
background: rgba(255, 255, 255, 0.06);
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition: background 150ms ease, border-color 150ms ease;
}
.header-button:hover {
background: rgba(255, 255, 255, 0.13);
border-color: rgba(255, 255, 255, 0.35);
}
.header-button.primary {
color: var(--ink);
background: #e4d8b9;
border-color: #e4d8b9;
}
.header-button.primary:hover {
background: #f0e6cb;
}
.header-button:disabled {
opacity: 0.45;
cursor: wait;
}
.workspace {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: 292px minmax(420px, 1fr) 292px;
gap: 1px;
background: var(--line);
}
.sidebar {
min-height: 0;
overflow: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #c8c1b4 transparent;
}
.panel-section {
padding: 19px 18px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
line-height: 1.2;
letter-spacing: 0.01em;
}
.section-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.section-count {
flex: none;
min-width: 29px;
height: 23px;
padding: 0 7px;
display: grid;
place-items: center;
border-radius: 99px;
background: #ece8de;
color: #5e675f;
font-size: 10px;
font-weight: 800;
}
.instruction {
display: flex;
gap: 10px;
margin-bottom: 13px;
padding: 11px;
border: 1px solid #ded7c8;
border-radius: 5px;
background: #f3efe5;
color: #636b65;
font-size: 11px;
line-height: 1.45;
}
.instruction svg {
flex: none;
width: 16px;
height: 16px;
margin-top: 1px;
color: var(--orange);
}
.component-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.component-card {
position: relative;
width: 100%;
padding: 11px 10px 10px 13px;
display: grid;
grid-template-columns: 30px minmax(0, 1fr);
gap: 10px;
border: 1px solid var(--line);
border-radius: 6px;
color: var(--ink);
background: #fffefa;
text-align: left;
cursor: pointer;
overflow: hidden;
transition:
transform 140ms ease,
border-color 140ms ease,
box-shadow 140ms ease,
background 140ms ease;
}
.component-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--component-color, #94a19b);
}
.component-card:hover:not(.built) {
transform: translateY(-1px);
border-color: #aaa293;
box-shadow: 0 5px 14px rgba(31, 41, 36, 0.07);
}
.component-card.selected {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(34, 107, 86, 0.11);
background: #f7fbf8;
}
.component-card.built {
background: #f0f4ef;
border-color: #cbd8cf;
}
.component-card.waiting {
opacity: 0.68;
}
.component-card.conflict {
border-color: #dfb1aa;
background: #fff8f5;
}
.component-card.pulse {
animation: card-pulse 750ms ease;
}
@keyframes card-pulse {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-4px); }
50% { transform: translateX(4px); }
75% { transform: translateX(-2px); }
}
.component-number {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 4px;
background: color-mix(in srgb, var(--component-color) 17%, white);
color: var(--component-color);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.04em;
}
.component-name {
display: block;
margin: 1px 0 4px;
font-size: 12px;
font-weight: 800;
line-height: 1.2;
}
.component-detail {
display: block;
min-height: 15px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.component-status {
display: inline-flex;
align-items: center;
gap: 5px;
margin-top: 7px;
color: #7c827d;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.component-status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #a6aaa6;
}
.component-card.ready .component-status {
color: var(--green);
}
.component-card.ready .component-status::before {
background: var(--green);
box-shadow: 0 0 0 3px rgba(34, 107, 86, 0.12);
}
.component-card.built .component-status {
color: var(--green);
}
.component-card.built .component-status::before {
background: var(--green);
}
.component-card.conflict .component-status {
color: var(--red);
}
.component-card.conflict .component-status::before {
background: var(--red);
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e6dd;
}
.scene-canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
cursor: grab;
touch-action: none;
}
.scene-canvas:active {
cursor: grabbing;
}
.viewport-top {
position: absolute;
top: 16px;
left: 16px;
right: 16px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
z-index: 3;
}
.site-badge {
padding: 10px 12px;
border: 1px solid rgba(23, 35, 31, 0.13);
border-radius: 4px;
background: rgba(250, 248, 241, 0.88);
backdrop-filter: blur(8px);
box-shadow: 0 5px 18px rgba(23, 35, 31, 0.07);
}
.site-badge strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.site-badge span {
color: var(--muted);
font-size: 10px;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
padding: 7px 9px;
border: 1px solid rgba(23, 35, 31, 0.12);
border-radius: 4px;
color: #505a54;
background: rgba(250, 248, 241, 0.88);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--dot);
}
.scene-tag {
position: absolute;
z-index: 4;
display: none;
min-width: 150px;
padding: 9px 11px;
border-left: 3px solid var(--green);
border-radius: 2px 5px 5px 2px;
color: var(--ink);
background: rgba(255, 253, 247, 0.94);
box-shadow: var(--shadow);
pointer-events: none;
transform: translate(-50%, -100%);
}
.scene-tag strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.scene-tag span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.viewport-help {
position: absolute;
left: 16px;
bottom: 104px;
z-index: 3;
padding: 7px 9px;
color: #67706a;
background: rgba(250, 248, 241, 0.77);
border-radius: 3px;
font-size: 9px;
pointer-events: none;
}
.north {
position: absolute;
right: 18px;
bottom: 108px;
z-index: 3;
display: grid;
justify-items: center;
gap: 4px;
color: #525c56;
font-size: 9px;
font-weight: 900;
pointer-events: none;
}
.north-arrow {
width: 0;
height: 0;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 20px solid #52605a;
}
.sequence-dock {
position: absolute;
left: 14px;
right: 14px;
bottom: 14px;
z-index: 5;
min-height: 74px;
padding: 12px 13px;
border: 1px solid rgba(23, 35, 31, 0.13);
border-radius: 6px;
background: rgba(250, 248, 241, 0.92);
backdrop-filter: blur(10px);
box-shadow: 0 8px 25px rgba(23, 35, 31, 0.09);
}
.dock-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #69716c;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sequence-list {
display: flex;
align-items: center;
gap: 6px;
min-height: 29px;
overflow-x: auto;
padding-bottom: 2px;
scrollbar-width: thin;
}
.sequence-empty {
color: #9a9c96;
font-size: 11px;
font-style: italic;
}
.sequence-chip {
flex: none;
display: flex;
align-items: center;
gap: 6px;
padding: 7px 9px;
border: 1px solid #d5d9d2;
border-radius: 3px;
background: #eef3ef;
color: #34594d;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.sequence-chip i {
width: 15px;
height: 15px;
display: grid;
place-items: center;
border-radius: 50%;
background: var(--green);
color: white;
font-size: 8px;
font-style: normal;
}
.sequence-arrow {
flex: none;
color: #b0b2ad;
font-size: 13px;
}
.toast {
position: absolute;
top: 70px;
left: 50%;
z-index: 12;
width: min(430px, calc(100% - 34px));
display: grid;
grid-template-columns: 34px 1fr;
gap: 11px;
padding: 13px;
border: 1px solid #d3aaa4;
border-radius: 6px;
background: rgba(255, 247, 243, 0.97);
box-shadow: 0 14px 40px rgba(65, 30, 25, 0.18);
transform: translate(-50%, -15px);
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast-icon {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border-radius: 50%;
color: white;
background: var(--red);
font-weight: 900;
}
.toast strong {
display: block;
margin-bottom: 3px;
color: #8e332e;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.toast span {
color: #5f5551;
font-size: 11px;
line-height: 1.4;
}
.route-alert {
position: absolute;
right: 16px;
top: 70px;
z-index: 7;
max-width: 245px;
padding: 10px 12px;
border: 1px solid #dca9a2;
border-radius: 4px;
color: #87342f;
background: rgba(255, 239, 235, 0.94);
box-shadow: var(--shadow);
font-size: 10px;
line-height: 1.4;
opacity: 0;
transform: translateY(-6px);
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
}
.route-alert.show {
opacity: 1;
transform: translateY(0);
}
.route-status {
padding: 13px;
border: 1px solid #cdded4;
border-radius: 6px;
background: #eef5f0;
}
.route-status.alert {
border-color: #dfb0aa;
background: var(--red-soft);
}
.route-status-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.route-status-head strong {
font-size: 12px;
}
.status-badge {
padding: 5px 7px;
border-radius: 99px;
color: var(--green);
background: #d9eade;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.route-status.alert .status-badge {
color: var(--red);
background: #f2cbc6;
}
.route-status p {
margin: 0;
color: #68736c;
font-size: 10px;
line-height: 1.5;
}
.route-status.alert p {
color: #78524d;
}
.clearance-meter {
position: relative;
height: 8px;
margin-top: 11px;
overflow: hidden;
border-radius: 99px;
background: #d9e2dc;
}
.clearance-meter::after {
content: "";
position: absolute;
inset: 0 32% 0 0;
border-radius: inherit;
background: var(--green);
transition: background 160ms ease;
}
.route-status.alert .clearance-meter::after {
background: var(--red);
}
.rule {
margin-bottom: 11px;
padding-bottom: 11px;
border-bottom: 1px dashed #ddd7ca;
}
.rule:last-child {
margin-bottom: 0;
padding-bottom: 0;
border-bottom: 0;
}
.rule-chain {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 5px;
}
.rule-node {
padding: 4px 6px;
border: 1px solid #ddd8cc;
border-radius: 3px;
color: #767b76;
background: #f2efe7;
font-size: 9px;
font-weight: 800;
}
.rule-node.done {
border-color: #bed2c5;
color: var(--green);
background: var(--green-soft);
}
.rule-node.missing {
border-color: #e5b9b2;
color: var(--red);
background: var(--red-soft);
}
.rule-arrow {
color: #aaa79f;
font-size: 11px;
}
.log {
display: flex;
flex-direction: column;
gap: 9px;
}
.log-entry {
display: grid;
grid-template-columns: 9px 1fr;
gap: 8px;
color: #68716b;
font-size: 10px;
line-height: 1.4;
}
.log-entry::before {
content: "";
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 50%;
background: #9ea59f;
box-shadow: 0 0 0 3px #ecece6;
}
.log-entry.success::before {
background: var(--green);
box-shadow: 0 0 0 3px var(--green-soft);
}
.log-entry.reject::before {
background: var(--red);
box-shadow: 0 0 0 3px var(--red-soft);
}
.log-entry strong {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 10px;
}
@media (max-width: 1150px) {
.workspace {
grid-template-columns: 260px minmax(380px, 1fr) 250px;
}
.panel-section {
padding: 16px 14px;
}
.project-meta {
display: none;
}
}
@media (max-width: 900px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
}
.topbar {
position: sticky;
top: 0;
flex-wrap: wrap;
padding: 12px 14px;
}
.brand {
min-width: 0;
}
.top-actions {
width: 100%;
margin-left: 0;
}
.progress-pill {
margin-right: auto;
}
.workspace {
display: flex;
flex-direction: column;
}
.viewport {
order: -1;
height: 60vh;
min-height: 440px;
}
.sidebar {
overflow: visible;
}
.right-sidebar {
display: grid;
grid-template-columns: 1fr 1fr;
}
.right-sidebar .panel-section:first-child {
grid-column: 1 / -1;
}
}
@media (max-width: 590px) {
.brand h1 {
font-size: 16px;
}
.brand-mark {
width: 37px;
height: 37px;
}
.header-button {
padding: 0 9px;
font-size: 10px;
}
.progress-pill {
min-width: 84px;
font-size: 9px;
}
.right-sidebar {
display: block;
}
.legend {
display: none;
}
.viewport-help {
display: none;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M4 25V12L16 5l12 7v13" stroke="currentColor" stroke-width="1.7"/>
<path d="M10 25V15l6-3.5 6 3.5v10M4 12h24" stroke="currentColor" stroke-width="1.7"/>
</svg>
</div>
<div>
<p class="eyebrow">Assembly Studio / 07</p>
<h1>Courtyard Pavilion</h1>
</div>
</div>
<div class="project-meta">
<span>LOW-POLY STUDY</span>
<span class="meta-divider"></span>
<span>7 required components · 1 crane corridor</span>
</div>
<div class="top-actions">
<div class="progress-pill" id="headerProgress">0 / 7 assembled</div>
<button class="header-button" id="undoButton" type="button" title="Undo the last component">Undo</button>
<button class="header-button" id="resetButton" type="button">Reset</button>
<button class="header-button primary" id="autoButton" type="button">Auto sequence</button>
</div>
</header>
<main class="workspace">
<aside class="sidebar left-sidebar">
<section class="panel-section">
<div class="section-heading">
<div>
<h2>Build sequence</h2>
<p>Select a component to place it.</p>
</div>
<span class="section-count" id="queueCount">8</span>
</div>
<div class="instruction">
<svg viewBox="0 0 20 20" fill="none" aria-hidden="true">
<circle cx="10" cy="10" r="8" stroke="currentColor" stroke-width="1.5"/>
<path d="M10 9v5M10 6.1v.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
<span>Dependencies and crane clearance are checked before every placement.</span>
</div>
<div class="component-list" id="componentList"></div>
</section>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive 3D construction site">
<div class="viewport-top">
<div class="site-badge">
<strong>Live construction model</strong>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="legend-dot" style="--dot:#b7b0a2"></span>Concrete</div>
<div class="legend-item"><span class="legend-dot" style="--dot:#41665d"></span>Structure</div>
<div class="legend-item"><span class="legend-dot" style="--dot:#d47849"></span>Cladding</div>
<div class="legend-item"><span class="legend-dot" style="--dot:#d7a83e"></span>Access</div>
</div>
</div>
<div class="scene-tag" id="sceneTag">
<strong id="sceneTagName"></strong>
<span id="sceneTagStatus"></span>
</div>
<div class="route-alert" id="routeAlert"></div>
<div class="toast" id="toast" role="status" aria-live="polite">
<div class="toast-icon">!</div>
<div>
<strong id="toastTitle">Order rejected</strong>
<span id="toastMessage"></span>
</div>
</div>
<div class="viewport-help">Double-click to reset the camera</div>
<div class="north" aria-hidden="true">
<span>N</span>
<div class="north-arrow"></div>
</div>
<div class="sequence-dock">
<div class="dock-heading">
<span>Installed order</span>
<span id="dockStage">Stage 0 / 7</span>
</div>
<div class="sequence-list" id="sequenceList">
<span class="sequence-empty">No components installed yet.</span>
</div>
</div>
</section>
<aside class="sidebar right-sidebar">
<section class="panel-section">
<div class="section-heading">
<div>
<h2>Structural dependencies</h2>
<p>Support must exist before installation.</p>
</div>
</div>
<div id="dependencyRules"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<div>
<h2>Crane access</h2>
<p>One protected delivery corridor.</p>
</div>
</div>
<div class="route-status" id="routeStatus">
<div class="route-status-head">
<strong>Corridor 01</strong>
<span class="status-badge" id="routeBadge">Clear</span>
</div>
<p id="routeDescription">
The 2.0 m route from the crane to the staging point is clear for deliveries.
</p>
<div class="clearance-meter"></div>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<div>
<h2>Assembly log</h2>
<p>Latest validation events.</p>
</div>
</div>
<div class="log" id="log"></div>
</section>
</aside>
</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 viewport = document.getElementById("viewport");
const componentList = document.getElementById("componentList");
const dependencyRules = document.getElementById("dependencyRules");
const sequenceList = document.getElementById("sequenceList");
const sceneTag = document.getElementById("sceneTag");
const sceneTagName = document.getElementById("sceneTagName");
const sceneTagStatus = document.getElementById("sceneTagStatus");
const toast = document.getElementById("toast");
const toastTitle = document.getElementById("toastTitle");
const toastMessage = document.getElementById("toastMessage");
const routeAlert = document.getElementById("routeAlert");
const routeStatus = document.getElementById("routeStatus");
const routeBadge = document.getElementById("routeBadge");
const routeDescription = document.getElementById("routeDescription");
const logElement = document.getElementById("log");
const definitions = [
{
id: "foundation",
code: "01",
name: "Foundation pad",
type: "Concrete base",
deps: [],
required: true,
color: "#a59e8f",
detail: "Level slab and isolated footings",
center: [-1.25, 0.25, -1]
},
{
id: "columns",
code: "02",
name: "Column grid",
type: "Primary steel",
deps: ["foundation"],
required: true,
color: "#41665d",
detail: "Six-point structural grid",
center: [-1.25, 1.8, -1.1]
},
{
id: "westScreen",
code: "03",
name: "West screen",
type: "Timber cladding",
deps: ["foundation"],
required: true,
color: "#cf7045",
detail: "Rear-to-front privacy screen",
center: [-4.72, 1.35, -1.25]
},
{
id: "eastScreen",
code: "04",
name: "East screen",
type: "Timber cladding",
deps: ["columns"],
required: true,
color: "#cf7045",
detail: "Partial screen; entry remains open",
center: [2.12, 1.35, -2]
},
{
id: "beams",
code: "05",
name: "Primary beams",
type: "Structural steel",
deps: ["columns"],
required: true,
color: "#38584f",
detail: "Cross and longitudinal beam frame",
center: [-1.25, 3.25, -1.1]
},
{
id: "deck",
code: "06",
name: "Timber deck",
type: "Finish layer",
deps: ["columns"],
required: true,
color: "#bf7c4c",
detail: "Interior floor boarding",
center: [-1.25, 0.38, -1]
},
{
id: "roof",
code: "07",
name: "Roof planes",
type: "Folded canopy",
deps: ["beams"],
required: true,
color: "#5c7b70",
detail: "Two-piece low-profile roof",
center: [-1.25, 3.9, -1]
},
{
id: "servicePod",
code: "08",
name: "Service pod",
type: "Optional module",
deps: ["deck"],
required: false,
color: "#855e50",
detail: "Optional delivery-side utility pod",
center: [3.25, 1.05, 1.05],
corridorFootprint: {
minX: 2.4,
maxX: 4.1,
minZ: -0.1,
maxZ: 2.2
}
}
];
const definitionById = Object.fromEntries(definitions.map((definition) => [definition.id, definition]));
const builtSet = new Set();
const builtOrder = [];
const componentGroups = new Map();
const ghostGroups = new Map();
const ghostMaterials = new Map();
const animations = [];
let selectedId = "foundation";
let toastTimer = null;
let routeAlertUntil = 0;
let autoRunning = false;
let dependencyLines = [];
let selectionRing = null;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e6dd);
scene.fog = new THREE.Fog(0xe9e6dd, 21, 39);
const camera = new THREE.PerspectiveCamera(37, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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;
renderer.domElement.className = "scene-canvas";
renderer.domElement.setAttribute("tabindex", "0");
viewport.prepend(renderer.domElement);
const cameraTarget = new THREE.Vector3(-0.45, 1.2, -0.55);
const defaultCamera = {
radius: 16.3,
theta: 0.66,
phi: 0.89
};
const cameraState = { ...defaultCamera };
function updateCamera() {
const { radius, theta, phi } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e7, 0x718079, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.4);
sun.position.set(7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8dce4, 0.7);
fill.position.set(-9, 6, -5);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.03,
flatShading: true,
...options
});
const materials = {
concrete: material(0xb8b2a5),
concreteDark: material(0x8d8a80),
steel: material(0x34554d, { metalness: 0.36, roughness: 0.56 }),
steelLight: material(0x648078, { metalness: 0.25 }),
timber: material(0xc87743),
timberDark: material(0x9d5e36),
roof: material(0x58776c, { metalness: 0.22 }),
roofEdge: material(0x304d46),
pod: material(0x81594d),
podTrim: material(0xc9a376),
crane: material(0xd39a36, { metalness: 0.24 }),
craneDark: material(0x3d4541, { metalness: 0.4 }),
rubber: material(0x2f3432),
glass: material(0x8ba7a5, { metalness: 0.15, roughness: 0.32 })
};
function box(parent, width, height, depth, mat, x, y, z, rotation = null) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, mat, x, y, z, radialSegments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, radialSegments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, start, end, thickness, mat) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, thickness, direction.length()),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function tagGroup(group, id) {
group.traverse((child) => {
if (child.isMesh) child.userData.componentId = id;
});
}
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 28),
material(0xd8d3c5)
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(0, -0.025, 1.5);
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x9f9d92, 0xb5b1a6);
grid.position.set(0, -0.015, 1.5);
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// One protected crane access corridor.
const corridor = {
minX: 2.3,
maxX: 4.3,
minZ: 0.5,
maxZ: 8.5
};
const corridorMaterial = new THREE.MeshBasicMaterial({
color: 0xd7a83e,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const corridorMesh = new THREE.Mesh(
new THREE.PlaneGeometry(corridor.maxX - corridor.minX, corridor.maxZ - corridor.minZ),
corridorMaterial
);
corridorMesh.rotation.x = -Math.PI / 2;
corridorMesh.position.set(
(corridor.minX + corridor.maxX) / 2,
0.018,
(corridor.minZ + corridor.maxZ) / 2
);
scene.add(corridorMesh);
const corridorLineMaterial = new THREE.LineDashedMaterial({
color: 0xb78922,
dashSize: 0.34,
gapSize: 0.22,
transparent: true,
opacity: 0.9
});
[corridor.minX, corridor.maxX].forEach((x) => {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.04, corridor.minZ),
new THREE.Vector3(x, 0.04, corridor.maxZ)
]);
const line = new THREE.Line(geometry, corridorLineMaterial);
line.computeLineDistances();
scene.add(line);
});
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xd2a43a,
side: THREE.DoubleSide
});
[1.6, 3.8, 6.0, 8.0].forEach((z) => {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
3.0, 0.045, z + 0.3,
3.6, 0.045, z + 0.3,
3.3, 0.045, z - 0.35
], 3)
);
geometry.computeVertexNormals();
const arrow = new THREE.Mesh(geometry, arrowMaterial);
scene.add(arrow);
});
const stagingPad = new THREE.Mesh(
new THREE.BoxGeometry(2.15, 0.055, 1.3),
material(0xbca66b)
);
stagingPad.position.set(3.3, 0.025, 0.15);
stagingPad.receiveShadow = true;
scene.add(stagingPad);
// Foundation.
const foundation = new THREE.Group();
box(foundation, 7.8, 0.28, 5.2, materials.concrete, -1.25, 0.15, -1);
box(foundation, 7.45, 0.055, 4.86, materials.concreteDark, -1.25, 0.315, -1);
[-4.2, -1.25, 1.8].forEach((x) => {
[-2.8, 0.6].forEach((z) => {
box(foundation, 0.62, 0.22, 0.62, materials.concreteDark, x, 0.28, z);
});
});
tagGroup(foundation, "foundation");
scene.add(foundation);
// Structural column grid.
const columns = new THREE.Group();
[-4.2, -1.25, 1.8].forEach((x) => {
[-2.8, 0.6].forEach((z) => {
box(columns, 0.24, 2.9, 0.24, materials.steel, x, 1.8, z);
box(columns, 0.48, 0.1, 0.48, materials.steelLight, x, 0.37, z);
});
});
tagGroup(columns, "columns");
scene.add(columns);
// West timber screen.
const westScreen = new THREE.Group();
box(westScreen, 0.14, 2.45, 4.35, materials.timberDark, -4.72, 1.55, -1.25);
for (let i = 0; i < 7; i++) {
box(westScreen, 0.12, 2.55, 0.39, materials.timber, -4.61, 1.55, -3.08 + i * 0.61);
}
tagGroup(westScreen, "westScreen");
scene.add(westScreen);
// East screen stops before the delivery opening.
const eastScreen = new THREE.Group();
box(eastScreen, 0.14, 2.45, 2.9, materials.timberDark, 2.12, 1.55, -2.0);
for (let i = 0; i < 5; i++) {
box(eastScreen, 0.12, 2.55, 0.38, materials.timber, 2.01, 1.55, -3.08 + i * 0.54);
}
tagGroup(eastScreen, "eastScreen");
scene.add(eastScreen);
// Primary beam frame.
const beams = new THREE.Group();
[-2.8, 0.6].forEach((z) => {
box(beams, 7.25, 0.25, 0.22, materials.steel, -1.25, 3.25, z);
});
[-4.2, -1.25, 1.8].forEach((x) => {
box(beams, 0.2, 0.21, 3.6, materials.steelLight, x, 3.22, -1.1);
});
tagGroup(beams, "beams");
scene.add(beams);
// Timber deck.
const deck = new THREE.Group();
for (let i = 0; i < 12; i++) {
const x = -4.62 + i * 0.62;
box(deck, 0.57, 0.075, 4.85, i % 3 === 0 ? materials.timberDark : materials.timber, x, 0.39, -1);
}
tagGroup(deck, "deck");
scene.add(deck);
// Folded low-poly roof.
const roof = new THREE.Group();
const roofAngle = 0.217;
const roofWidth = 3.94;
const leftRoof = box(
roof,
roofWidth,
0.17,
5.45,
materials.roof,
-3.18,
3.91,
-1,
new THREE.Euler(0, 0, roofAngle)
);
const rightRoof = box(
roof,
roofWidth,
0.17,
5.45,
materials.roof,
0.68,
3.91,
-1,
new THREE.Euler(0, 0, -roofAngle)
);
box(roof, 0.16, 0.16, 5.45, materials.roofEdge, -1.25, 4.37, -1);
leftRoof.castShadow = true;
rightRoof.castShadow = true;
tagGroup(roof, "roof");
scene.add(roof);
// Optional service pod. Its fixed position conflicts with the protected route.
const servicePod = new THREE.Group();
box(servicePod, 1.7, 2.1, 2.3, materials.pod, 3.25, 1.08, 1.05);
box(servicePod, 1.82, 0.13, 2.4, materials.podTrim, 3.25, 2.16, 1.05);
box(servicePod, 0.035, 0.7, 1.0, materials.glass, 2.385, 1.35, 1.1);
tagGroup(servicePod, "servicePod");
scene.add(servicePod);
const allGroups = {
foundation,
columns,
westScreen,
eastScreen,
beams,
deck,
roof,
servicePod
};
Object.entries(allGroups).forEach(([id, group]) => {
componentGroups.set(id, group);
const ghost = group.clone(true);
const ghostMaterialList = [];
ghost.traverse((child) => {
if (child.isMesh) {
const ghostMaterial = new THREE.MeshBasicMaterial({
color: 0x60786f,
transparent: true,
opacity: 0.035,
depthWrite: false,
wireframe: false
});
child.material = ghostMaterial;
child.castShadow = false;
child.receiveShadow = false;
ghostMaterialList.push(ghostMaterial);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(child.geometry, 24),
new THREE.LineBasicMaterial({
color: 0x557168,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
child.add(edges);
}
});
ghostGroups.set(id, ghost);
ghostMaterials.set(id, ghostMaterialList);
scene.add(ghost);
group.visible = false;
});
// Low-poly mobile crane beside the protected corridor.
const crane = new THREE.Group();
box(crane, 1.55, 0.45, 2.15, materials.crane, 5.35, 0.55, 4.75);
box(crane, 1.25, 1.0, 1.05, materials.craneDark, 5.55, 1.18, 5.05);
box(crane, 0.72, 0.65, 0.025, materials.glass, 5.55, 1.35, 5.59);
[-0.55, 0.55].forEach((zOffset) => {
[-0.77, 0.77].forEach((xOffset) => {
const wheel = cylinder(
crane,
0.35,
0.35,
0.25,
materials.rubber,
5.35 + xOffset,
0.35,
4.75 + zOffset,
10
);
wheel.rotation.z = Math.PI / 2;
});
});
cylinder(crane, 0.55, 0.7, 0.32, materials.craneDark, 5.0, 1.75, 4.4);
beamBetween(crane, [5.0, 1.85, 4.4], [-1.05, 4.65, -1.0], 0.26, materials.crane);
beamBetween(crane, [5.0, 1.85, 4.4], [7.25, 1.25, 6.25], 0.22, materials.craneDark);
beamBetween(crane, [5.0, 1.85, 4.4], [-1.05, 4.65, -1.0], 0.07, materials.craneDark);
cylinder(crane, 0.035, 0.035, 2.4, materials.craneDark, -1.05, 3.42, -1.0, 6);
box(crane, 0.7, 0.38, 0.7, materials.craneDark, -1.05, 2.25, -1.0);
scene.add(crane);
function addLog(type, title, detail) {
const entry = document.createElement("div");
entry.className = `log-entry ${type}`;
entry.innerHTML = `<div><strong>${title}</strong>${detail}</div>`;
logElement.prepend(entry);
while (logElement.children.length > 5) {
logElement.lastElementChild.remove();
}
}
function formatDependencies(ids) {
if (!ids.length) return "No prerequisites";
return "After " + ids.map((id) => definitionById[id].name).join(" + ");
}
function createCards() {
definitions.forEach((definition) => {
const card = document.createElement("button");
card.type = "button";
card.className = "component-card";
card.dataset.id = definition.id;
card.style.setProperty("--component-color", definition.color);
card.innerHTML = `
<span class="component-number">${definition.code}</span>
<span>
<span class="component-name">${definition.name}</span>
<span class="component-detail">${definition.detail}<br>${formatDependencies(definition.deps)}</span>
<span class="component-status">Waiting</span>
</span>
`;
card.addEventListener("click", () => attemptBuild(definition.id));
componentList.appendChild(card);
});
}
function createDependencyRules() {
const rules = [
["foundation", "columns", "beams", "roof"],
["foundation", "westScreen"],
["columns", "eastScreen"],
["columns", "deck"],
["deck", "servicePod"]
];
rules.forEach((ids) => {
const rule = document.createElement("div");
rule.className = "rule";
rule.dataset.rule = ids.join(",");
rule.innerHTML = ids.map((id, index) => {
const node = `<span class="rule-node" data-node="${id}">${definitionById[id].name}</span>`;
return index < ids.length - 1 ? `${node}<span class="rule-arrow">→</span>` : node;
}).join("");
dependencyRules.appendChild(rule);
});
}
function missingDependencies(definition) {
return definition.deps.filter((id) => !builtSet.has(id));
}
function corridorConflict(definition) {
if (!definition.corridorFootprint) return null;
const footprint = definition.corridorFootprint;
const overlapX = Math.min(corridor.maxX, footprint.maxX) - Math.max(corridor.minX, footprint.minX);
const overlapZ = Math.min(corridor.maxZ, footprint.maxZ) - Math.max(corridor.minZ, footprint.minZ);
if (overlapX > 0 && overlapZ > 0) {
return { overlapX, overlapZ };
}
return null;
}
function refreshUI() {
const requiredTotal = definitions.filter((definition) => definition.required).length;
const requiredBuilt = definitions.filter((definition) => definition.required && builtSet.has(definition.id)).length;
document.getElementById("headerProgress").textContent = `${requiredBuilt} / ${requiredTotal} assembled`;
document.getElementById("queueCount").textContent = definitions.length;
document.getElementById("dockStage").textContent = `Stage ${requiredBuilt} / ${requiredTotal}`;
document.getElementById("undoButton").disabled = builtOrder.length === 0;
definitions.forEach((definition) => {
const card = componentList.querySelector(`[data-id="${definition.id}"]`);
const status = card.querySelector(".component-status");
const missing = missingDependencies(definition);
const built = builtSet.has(definition.id);
const conflict = corridorConflict(definition);
card.classList.toggle("selected", selectedId === definition.id);
card.classList.toggle("built", built);
card.classList.toggle("waiting", !built && missing.length > 0);
card.classList.toggle("ready", !built && missing.length === 0 && !conflict);
card.classList.toggle("conflict", !built && Boolean(conflict));
if (built) {
status.textContent = "Installed";
} else if (missing.length) {
status.textContent = `Needs ${definitionById[missing[0]].name}`;
} else if (conflict) {
status.textContent = "Corridor conflict";
} else {
status.textContent = "Ready to place";
}
});
dependencyRules.querySelectorAll(".rule-node").forEach((node) => {
const id = node.dataset.node;
const definition = definitionById[id];
const missing = missingDependencies(definition);
node.classList.toggle("done", builtSet.has(id));
node.classList.toggle(
"missing",
!builtSet.has(id) && missing.length > 0 && definition.deps.length > 0
);
});
sequenceList.innerHTML = "";
if (!builtOrder.length) {
const empty = document.createElement("span");
empty.className = "sequence-empty";
empty.textContent = "No components installed yet.";
sequenceList.appendChild(empty);
} else {
builtOrder.forEach((id, index) => {
if (index > 0) {
const arrow = document.createElement("span");
arrow.className = "sequence-arrow";
arrow.textContent = "→";
sequenceList.appendChild(arrow);
}
const chip = document.createElement("span");
chip.className = "sequence-chip";
chip.innerHTML = `<i>${index + 1}</i>${definitionById[id].name}`;
sequenceList.appendChild(chip);
});
}
const routeIsAlerting = performance.now() < routeAlertUntil;
routeStatus.classList.toggle("alert", routeIsAlerting);
routeBadge.textContent = routeIsAlerting ? "Conflict" : "Clear";
routeDescription.textContent = routeIsAlerting
? "The proposed component intersects the protected crane access route."
: "The 2.0 m route from the crane to the staging point is clear for deliveries.";
updateGhostHighlight();
updateDependencyLines();
}
function showToast(title, message) {
toastTitle.textContent = title;
toastMessage.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 4200);
}
function pulseCard(id) {
const card = componentList.querySelector(`[data-id="${id}"]`);
if (!card) return;
card.classList.remove("pulse");
void card.offsetWidth;
card.classList.add("pulse");
setTimeout(() => card.classList.remove("pulse"), 800);
}
function rejectOrder(definition, reason, type = "dependency") {
selectedId = definition.id;
routeAlert.textContent = reason;
routeAlert.classList.add("show");
if (type === "corridor") {
routeAlertUntil = performance.now() + 3000;
setTimeout(() => routeAlert.classList.remove("show"), 3000);
} else {
setTimeout(() => routeAlert.classList.remove("show"), 3200);
}
showToast("Order rejected", reason);
addLog("reject", `${definition.name} rejected`, reason);
refreshUI();
}
function animateBuild(group) {
const meshes = [];
group.traverse((child) => {
if (child.isMesh) {
meshes.push({
mesh: child,
position: child.position.clone(),
scale: child.scale.clone()
});
}
});
animations.push({
start: performance.now(),
duration: 680,
meshes
});
}
function attemptBuild(id, automatic = false) {
const definition = definitionById[id];
if (builtSet.has(id)) {
selectedId = id;
refreshUI();
if (!automatic) showToast("Already installed", `${definition.name} is already part of the assembly.`);
return false;
}
const missing = missingDependencies(definition);
if (missing.length) {
const missingName = definitionById[missing[0]].name;
pulseCard(missing[0]);
rejectOrder(
definition,
`${definition.name} requires ${missingName} to be installed first.`,
"dependency"
);
return false;
}
const conflict = corridorConflict(definition);
if (conflict) {
const conflictLength = Math.max(conflict.overlapX, conflict.overlapZ).toFixed(1);
rejectOrder(
definition,
`${definition.name} overlaps the protected crane corridor by ${conflictLength} m. Keep the full 2.0 m delivery route clear.`,
"corridor"
);
return false;
}
builtSet.add(id);
builtOrder.push(id);
selectedId = id;
const group = componentGroups.get(id);
group.visible = true;
ghostGroups.get(id).visible = false;
animateBuild(group);
addLog(
"success",
`${definition.name} installed`,
`Stage ${builtOrder.length} accepted after structural and route checks.`
);
refreshUI();
return true;
}
function undoLast() {
if (!builtOrder.length) return;
const id = builtOrder.pop();
builtSet.delete(id);
selectedId = id;
const group = componentGroups.get(id);
group.visible = false;
ghostGroups.get(id).visible = true;
addLog("success", `${definitionById[id].name} removed`, "The last accepted placement was undone.");
refreshUI();
}
function resetProject() {
builtSet.clear();
builtOrder.length = 0;
animations.length = 0;
componentGroups.forEach((group, id) => {
group.visible = false;
ghostGroups.get(id).visible = true;
});
selectedId = "foundation";
routeAlertUntil = 0;
autoRunning = false;
document.getElementById("autoButton").disabled = false;
logElement.innerHTML = "";
addLog("success", "Model reset", "All components returned to the planning queue.");
refreshUI();
}
function autoSequence() {
if (autoRunning) return;
autoRunning = true;
document.getElementById("autoButton").disabled = true;
const priority = [
"foundation",
"columns",
"westScreen",
"eastScreen",
"beams",
"deck",
"roof"
];
let index = 0;
function next() {
if (index >= priority.length) {
autoRunning = false;
document.getElementById("autoButton").disabled = false;
showToast("Sequence complete", "All seven required components passed dependency and crane-access checks.");
return;
}
attemptBuild(priority[index], true);
index += 1;
setTimeout(next, 360);
}
next();
}
function updateGhostHighlight() {
definitions.forEach((definition) => {
const materialsForGhost = ghostMaterials.get(definition.id);
const selected = definition.id === selectedId;
const built = builtSet.has(definition.id);
materialsForGhost.forEach((mat) => {
mat.opacity = built ? 0 : selected ? 0.095 : 0.035;
mat.color.set(selected ? 0x2f7560 : 0x60786f);
});
ghostGroups.get(definition.id).traverse((child) => {
if (child.isLineSegments) {
child.material.opacity = built ? 0 : selected ? 0.48 : 0.16;
child.material.color.set(selected ? 0x246c58 : 0x557168);
}
});
});
}
function removeDependencyLines() {
dependencyLines.forEach((line) => {
scene.remove(line);
line.geometry.dispose();
line.material.dispose();
});
dependencyLines = [];
}
function updateDependencyLines() {
removeDependencyLines();
const selected = definitionById[selectedId];
if (!selected) return;
selected.deps.forEach((dependencyId) => {
const dependency = definitionById[dependencyId];
const start = new THREE.Vector3(
dependency.center[0],
Math.max(dependency.center[1], 0.45),
dependency.center[2]
);
const end = new THREE.Vector3(
selected.center[0],
Math.max(selected.center[1], 0.45),
selected.center[2]
);
const midpoint = start.clone().lerp(end, 0.5);
midpoint.y += 1.1;
const curve = new THREE.QuadraticBezierCurve3(start, midpoint, end);
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(40));
const isBuilt = builtSet.has(dependencyId);
const materialForLine = new THREE.LineDashedMaterial({
color: isBuilt ? 0x2f8064 : 0xb8443d,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.88,
depthTest: false
});
const line = new THREE.Line(geometry, materialForLine);
line.computeLineDistances();
line.renderOrder = 8;
scene.add(line);
dependencyLines.push(line);
});
if (selectionRing) {
scene.remove(selectionRing);
selectionRing.geometry.dispose();
selectionRing.material.dispose();
}
const conflict = corridorConflict(selected);
const ringPoints = [
new THREE.Vector3(-5.15, 0.055, -3.65),
new THREE.Vector3(2.65, 0.055, -3.65),
new THREE.Vector3(2.65, 0.055, 1.75),
new THREE.Vector3(-5.15, 0.055, 1.75)
];
selectionRing = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(ringPoints),
new THREE.LineBasicMaterial({
color: conflict ? 0xb8443d : 0x2f8064,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
selectionRing.renderOrder = 7;
scene.add(selectionRing);
}
function updateSceneTag() {
if (!selectedId) {
sceneTag.style.display = "none";
return;
}
const definition = definitionById[selectedId];
const world = new THREE.Vector3(...definition.center);
const projected = world.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
if (projected.z > 1 || x < 0 || x > viewport.clientWidth || y < 0 || y > viewport.clientHeight) {
sceneTag.style.display = "none";
return;
}
const built = builtSet.has(definition.id);
const missing = missingDependencies(definition);
sceneTag.style.display = "block";
sceneTag.style.left = `${x}px`;
sceneTag.style.top = `${y - 15}px`;
sceneTag.style.borderLeftColor = built ? "#226b56" : missing.length ? "#b8443d" : "#cf6d3e";
sceneTagName.textContent = definition.name;
sceneTagStatus.textContent = built
? "Installed"
: missing.length
? `Waiting for ${definitionById[missing[0]].name}`
: "Ready to place";
}
// Direct camera controls, implemented without addons.
let dragging = false;
let pointerMoved = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (
Math.abs(event.clientX - pointerStart.x) +
Math.abs(event.clientY - pointerStart.y) > 5
) {
pointerMoved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.0045, 0.34, 1.28);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const builtMeshes = [];
componentGroups.forEach((group, id) => {
if (builtSet.has(id)) {
group.traverse((child) => {
if (child.isMesh) builtMeshes.push(child);
});
}
});
const hits = raycaster.intersectObjects(builtMeshes, false);
if (hits.length) {
selectedId = hits[0].object.userData.componentId;
refreshUI();
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8.5,
25
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
});
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(viewport);
document.getElementById("undoButton").addEventListener("click", undoLast);
document.getElementById("resetButton").addEventListener("click", resetProject);
document.getElementById("autoButton").addEventListener("click", autoSequence);
createCards();
createDependencyRules();
addLog("success", "Planning model ready", "Choose a component to begin the assembly sequence.");
refreshUI();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
const now = performance.now();
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
const t = THREE.MathUtils.clamp((now - animation.start) / animation.duration, 0, 1);
const c1 = 1.70158;
const c3 = c1 + 1;
const eased = 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
const scale = 0.82 + eased * 0.18;
animation.meshes.forEach(({ mesh, position, scale: baseScale }) => {
mesh.position.y = position.y + (1 - t) * -1.15;
mesh.scale.set(
baseScale.x * scale,
baseScale.y * scale,
baseScale.z * scale
);
});
if (t >= 1) {
animation.meshes.forEach(({ mesh, position, scale: baseScale }) => {
mesh.position.copy(position);
mesh.scale.copy(baseScale);
});
animations.splice(i, 1);
}
}
const routeIsAlerting = now < routeAlertUntil;
const targetColor = routeIsAlerting ? 0xc9584e : 0xd7a83e;
corridorMaterial.color.lerp(new THREE.Color(targetColor), 0.12);
corridorMaterial.opacity = routeIsAlerting ? 0.32 : 0.2;
corridorLineMaterial.color.lerp(new THREE.Color(routeIsAlerting ? 0xb8443d : 0xb78922), 0.12);
if (routeIsAlerting !== routeStatus.classList.contains("alert")) {
refreshUI();
}
updateSceneTag();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```