Prompt specification
Build or customize the Three.js 3D scene "Route deliveries while a market stays open" 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: Route deliveries while a market stays open
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/route-deliveries-while-a-market-stays-open-x2384
Scene Description Prompt:
Schedule deliveries through a fictional voxel Ottoman bazaar, using courtyard storage to preserve customer passage. Make standalone HTML using Three.js from cdnjs.
Working Three.js Starter (route-deliveries-while-a-market-stays-open-x2384):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#183c3b">
<title>Sultanahmet Dispatch — Courtyard Bazaar</title>
<style>
:root {
--ink: #173b3a;
--ink-soft: #53706d;
--paper: #f8f2e7;
--paper-deep: #eee3d0;
--line: #ddcfba;
--terracotta: #bb5e42;
--terracotta-dark: #8d4232;
--gold: #d4a94d;
--teal: #238b83;
--teal-light: #d8ece6;
--orange: #e88a3d;
--danger: #b5483f;
--shadow: 0 18px 48px rgba(45, 39, 29, .15);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { color: inherit; }
#app {
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
gap: 20px;
padding: 0 24px;
color: #fffaf0;
background:
linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 24px 24px,
var(--ink);
border-bottom: 1px solid rgba(255,255,255,.08);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
width: 40px;
height: 40px;
display: grid;
place-items: center;
color: #f4d48a;
background: rgba(255,255,255,.08);
border: 1px solid rgba(255,255,255,.13);
border-radius: 12px;
}
.brand-mark svg { width: 25px; height: 25px; }
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 600;
letter-spacing: .02em;
}
.brand p {
margin: 2px 0 0;
color: #b8cbc7;
font-size: 11px;
letter-spacing: .12em;
text-transform: uppercase;
}
.header-stat {
display: flex;
align-items: center;
gap: 9px;
padding-left: 20px;
border-left: 1px solid rgba(255,255,255,.12);
color: #d9e7e3;
font-size: 13px;
}
.header-stat strong {
display: block;
color: #fff;
font-size: 13px;
font-weight: 650;
}
.header-stat span {
display: block;
margin-top: 2px;
color: #99b2ad;
font-size: 10px;
text-transform: uppercase;
letter-spacing: .1em;
}
.header-spacer { flex: 1; }
.live-pill {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-radius: 999px;
color: #dff4ec;
background: rgba(49, 148, 125, .18);
border: 1px solid rgba(113, 212, 179, .25);
font-size: 12px;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #69d6a9;
box-shadow: 0 0 0 4px rgba(105,214,169,.12);
}
main {
min-height: 0;
display: grid;
grid-template-template-columns: minmax(0, 1fr) 390px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d9c8a8;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active { cursor: grabbing; }
.scene-top {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
pointer-events: none;
z-index: 5;
}
.location-card {
max-width: 290px;
padding: 13px 15px;
border: 1px solid rgba(255,255,255,.5);
border-radius: 14px;
color: var(--ink);
background: rgba(250,246,236,.88);
backdrop-filter: blur(12px);
box-shadow: 0 8px 24px rgba(68,51,29,.11);
}
.eyebrow {
color: var(--terracotta-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.location-card h2 {
margin: 4px 0 3px;
font-family: Georgia, serif;
font-size: 19px;
font-weight: 600;
}
.location-card p {
margin: 0;
color: var(--ink-soft);
font-size: 12px;
}
.scene-tools {
display: flex;
gap: 8px;
pointer-events: auto;
}
.tool-group {
display: flex;
padding: 4px;
border-radius: 12px;
background: rgba(250,246,236,.9);
border: 1px solid rgba(255,255,255,.55);
box-shadow: 0 8px 24px rgba(68,51,29,.1);
backdrop-filter: blur(12px);
}
.tool-btn {
width: 35px;
height: 35px;
display: grid;
place-items: center;
border: 0;
border-radius: 9px;
background: transparent;
cursor: pointer;
font-size: 18px;
transition: background .18s, transform .18s;
}
.tool-btn:hover {
background: #eadfce;
transform: translateY(-1px);
}
.tool-btn svg {
width: 17px;
height: 17px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.scene-bottom {
position: absolute;
left: 18px;
right: 18px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 15px;
pointer-events: none;
z-index: 5;
}
.legend {
display: flex;
align-items: center;
gap: 15px;
padding: 10px 13px;
border-radius: 12px;
background: rgba(250,246,236,.9);
border: 1px solid rgba(255,255,255,.5);
box-shadow: 0 8px 24px rgba(68,51,29,.1);
backdrop-filter: blur(12px);
font-size: 11px;
color: var(--ink-soft);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.legend-swatch {
width: 17px;
height: 6px;
border-radius: 3px;
}
.legend-swatch.customer { background: var(--teal); }
.legend-swatch.delivery { background: var(--orange); }
.legend-swatch.storage { background: #9e7750; }
.gesture-hint {
padding: 9px 12px;
border-radius: 10px;
background: rgba(23,59,58,.83);
color: #e9f2ef;
font-size: 10px;
letter-spacing: .03em;
box-shadow: var(--shadow);
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 4;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border-radius: 8px;
background: rgba(255,251,241,.92);
border: 1px solid rgba(255,255,255,.7);
box-shadow: 0 5px 16px rgba(61,48,31,.14);
color: var(--ink);
font-size: 10px;
font-weight: 700;
letter-spacing: .04em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity .15s;
}
.scene-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--label-color, var(--teal));
box-shadow: 0 0 0 3px color-mix(in srgb, var(--label-color, var(--teal)) 18%, transparent);
}
.scene-label.customer { --label-color: var(--teal); }
.scene-label.delivery { --label-color: var(--orange); }
.scene-label.storage { --label-color: #9e7750; }
.scene-label.gate { --label-color: var(--terracotta); }
aside {
min-height: 0;
overflow-y: auto;
background: var(--paper);
border-left: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c9b89d transparent;
}
.panel-head {
padding: 22px 22px 18px;
border-bottom: 1px solid var(--line);
background:
radial-gradient(circle at 90% 0%, rgba(212,169,77,.15), transparent 36%),
var(--paper);
}
.panel-head-row {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: flex-start;
}
.panel-head h2 {
margin: 4px 0 0;
font-family: Georgia, serif;
font-size: 25px;
font-weight: 600;
}
.date-chip {
padding: 7px 9px;
border-radius: 8px;
color: var(--ink-soft);
background: #eee4d4;
font-size: 10px;
font-weight: 750;
letter-spacing: .06em;
text-transform: uppercase;
}
.panel-section {
padding: 18px 22px;
border-bottom: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.section-title h3 {
margin: 0;
font-size: 12px;
letter-spacing: .08em;
text-transform: uppercase;
font-weight: 800;
}
.section-title span {
color: var(--ink-soft);
font-size: 10px;
}
.passage-card {
padding: 14px;
border-radius: 13px;
color: #edf8f4;
background: linear-gradient(135deg, #1e5550, #183e3c);
box-shadow: 0 10px 24px rgba(23,59,58,.14);
}
.passage-card.warning {
color: #fff5e9;
background: linear-gradient(135deg, #9b513d, #743a31);
}
.passage-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.passage-card h4 {
margin: 4px 0 4px;
font-size: 15px;
}
.passage-card p {
margin: 0;
color: rgba(237,248,244,.68);
font-size: 11px;
line-height: 1.5;
}
.passage-card.warning p { color: rgba(255,245,233,.72); }
.clear-score {
min-width: 56px;
text-align: right;
color: #8ee3c4;
font-size: 20px;
font-weight: 750;
}
.warning .clear-score { color: #ffd0a2; }
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(255,255,255,.12);
}
.toggle-copy strong {
display: block;
font-size: 11px;
}
.toggle-copy span {
display: block;
margin-top: 2px;
color: rgba(237,248,244,.62);
font-size: 10px;
}
.switch {
position: relative;
width: 38px;
height: 22px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 999px;
background: rgba(255,255,255,.19);
cursor: pointer;
transition: .2s;
}
.switch span::after {
content: "";
position: absolute;
width: 16px;
height: 16px;
left: 3px;
top: 3px;
border-radius: 50%;
background: #fff;
box-shadow: 0 2px 5px rgba(0,0,0,.2);
transition: .2s;
}
.switch input:checked + span { background: #52b89d; }
.switch input:checked + span::after { transform: translateX(16px); }
.form-grid {
display: grid;
grid-template-columns: 1.5fr .8fr .75fr;
gap: 9px;
}
.field label {
display: block;
margin: 0 0 6px;
color: var(--ink-soft);
font-size: 9px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
}
.field input, .field select {
width: 100%;
height: 38px;
padding: 0 10px;
border: 1px solid #d5c5ae;
border-radius: 8px;
outline: none;
color: var(--ink);
background: #fffaf1;
font-size: 11px;
}
.field input:focus, .field select:focus {
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(35,139,131,.1);
}
.primary-btn {
width: 100%;
margin-top: 11px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
border: 0;
border-radius: 9px;
color: #fffaf1;
background: var(--terracotta);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: .06em;
text-transform: uppercase;
box-shadow: 0 7px 14px rgba(187,94,66,.2);
transition: transform .18s, background .18s;
}
.primary-btn:hover {
background: var(--terracotta-dark);
transform: translateY(-1px);
}
.primary-btn svg {
width: 14px;
height: 14px;
fill: none;
stroke: currentColor;
stroke-width: 2;
}
.queue {
display: grid;
gap: 9px;
}
.delivery-card {
position: relative;
display: grid;
grid-template-columns: 44px 1fr auto;
align-items: center;
gap: 11px;
padding: 11px;
border: 1px solid #dfd2be;
border-radius: 11px;
background: rgba(255,252,245,.72);
cursor: pointer;
transition: border-color .18s, background .18s, transform .18s;
}
.delivery-card:hover {
transform: translateY(-1px);
border-color: #c7ae87;
}
.delivery-card.active {
border-color: var(--terracotta);
background: #fff8eb;
box-shadow: inset 3px 0 var(--terracotta);
}
.time-block {
text-align: center;
padding-right: 10px;
border-right: 1px solid #e4d8c6;
}
.time-block strong {
display: block;
font-size: 13px;
}
.time-block span {
display: block;
margin-top: 2px;
color: var(--ink-soft);
font-size: 8px;
letter-spacing: .08em;
text-transform: uppercase;
}
.delivery-info strong {
display: block;
font-size: 11px;
}
.delivery-info span {
display: block;
margin-top: 3px;
color: var(--ink-soft);
font-size: 10px;
}
.delivery-meta {
text-align: right;
}
.bay-badge {
display: inline-grid;
min-width: 24px;
height: 24px;
place-items: center;
border-radius: 7px;
color: #fff;
background: #8a6b4a;
font-size: 10px;
font-weight: 800;
}
.status-text {
display: block;
margin-top: 3px;
color: var(--teal);
font-size: 8px;
font-weight: 700;
text-transform: uppercase;
}
.storage-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.storage-card {
padding: 10px;
border: 1px solid #ded1be;
border-radius: 10px;
background: #fbf6ed;
}
.storage-card.active {
border-color: var(--terracotta);
background: #fff7e9;
}
.storage-card header {
display: flex;
justify-content: space-between;
padding: 0;
color: var(--ink);
background: none;
border: 0;
font-size: 10px;
font-weight: 800;
}
.storage-card header span {
color: var(--ink-soft);
font-size: 9px;
font-weight: 600;
}
.capacity-bar {
height: 5px;
margin: 9px 0 6px;
overflow: hidden;
border-radius: 99px;
background: #e4dac9;
}
.capacity-bar i {
display: block;
height: 100%;
width: 0;
border-radius: inherit;
background: var(--teal);
transition: width .4s ease;
}
.storage-card small {
color: var(--ink-soft);
font-size: 8px;
}
.event-list {
display: grid;
gap: 11px;
}
.event {
display: grid;
grid-template-columns: 7px 1fr;
gap: 10px;
color: var(--ink-soft);
font-size: 10px;
line-height: 1.45;
}
.event::before {
content: "";
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(212,169,77,.12);
}
.event strong {
color: var(--ink);
font-weight: 650;
}
#toast {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 50;
padding: 12px 17px;
border-radius: 10px;
color: #fff;
background: rgba(23,59,58,.96);
box-shadow: 0 16px 40px rgba(0,0,0,.22);
font-size: 12px;
transform: translate(-50%, 18px);
opacity: 0;
pointer-events: none;
transition: .25s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 980px) {
main { grid-template-columns: minmax(0, 1fr) 340px; }
.header-stat { display: none; }
.brand { min-width: auto; }
}
@media (max-width: 760px) {
html, body { overflow: auto; }
#app {
height: auto;
min-height: 100%;
grid-template-rows: 64px auto;
}
header { padding: 0 14px; }
.brand p { display: none; }
.live-pill { font-size: 10px; }
main { display: block; }
#stage { height: 58vh; min-height: 420px; }
aside { overflow: visible; border-left: 0; }
.scene-bottom { left: 12px; right: 12px; bottom: 12px; }
.gesture-hint { display: none; }
.legend { gap: 9px; font-size: 9px; }
.location-card { max-width: 220px; }
.location-card h2 { font-size: 16px; }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32">
<path d="M5 27h22M8 24h16M11 21h10M12 8h8v13h-8zM10 8l6-5 6 5M15 3h2M9 14h14"/>
<path d="M14 12h4v4h-4z" fill="currentColor" stroke="none"/>
</svg>
</div>
<div>
<h1>Sultanahmet Dispatch</h1>
<p>Courtyard logistics · Istanbul</p>
</div>
</div>
<div class="header-stat">
<div class="live-dot"></div>
<div><strong>Market open</strong><span>Pedestrian flow · moderate</span></div>
</div>
<div class="header-stat">
<div><strong id="headerTime">09:18</strong><span>Local time</span></div>
</div>
<div class="header-spacer"></div>
<div class="live-pill">
<span class="live-dot"></span>
<span id="headerPassage">Passage protected</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive three-dimensional bazaar">
<div class="scene-top">
<div class="location-card">
<div class="eyebrow">Active Courtyard</div>
<h2>Kapalıçarşı Meydanı</h2>
<p>Voxel Ottoman bazaar · 6 merchant fronts</p>
</div>
<div class="scene-tools">
<div class="tool-group">
<button class="tool-btn" id="rotateLeft" title="Rotate left" aria-label="Rotate left">↶</button>
<button class="tool-btn" id="rotateRight" title="Rotate right" aria-label="Rotate right">↷</button>
</div>
<div class="tool-group">
<button class="tool-btn" id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button class="tool-btn" id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button class="tool-btn" id="resetView" title="Reset view" aria-label="Reset view">
<svg viewBox="0 0 20 20"><path d="M4 8a6 6 0 1 1 .7 6M4 8V4m0 4h4"/></svg>
</button>
</div>
</div>
</div>
<div id="labels"></div>
<div class="scene-bottom">
<div class="legend">
<div class="legend-item"><i class="legend-swatch customer"></i>Customer passage</div>
<div class="legend-item"><i class="legend-swatch delivery"></i>Active delivery</div>
<div class="legend-item"><i class="legend-swatch storage"></i>Storage bays</div>
</div>
<div class="gesture-hint">Drag to orbit · Scroll to zoom</div>
</div>
</section>
<aside>
<div class="panel-head">
<div class="panel-head-row">
<div>
<div class="eyebrow">Operations</div>
<h2>Dispatch Board</h2>
</div>
<div class="date-chip">Thu · 16 May</div>
</div>
</div>
<section class="panel-section">
<div class="passage-card" id="passageCard">
<div class="passage-top">
<div>
<div class="eyebrow" style="color:#8ee3c4">Live flow check</div>
<h4 id="passageTitle">Customer passage is clear</h4>
<p id="passageDescription">Deliveries are staged in courtyard storage, outside the public route.</p>
</div>
<div class="clear-score" id="clearScore">100%</div>
</div>
<div class="toggle-row">
<div class="toggle-copy">
<strong>Passage priority</strong>
<span>Stage instead of direct handoff</span>
</div>
<label class="switch">
<input id="priorityToggle" type="checkbox" checked>
<span aria-hidden="true"></span>
</label>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-title">
<h3>Schedule Delivery</h3>
<span>Courtyard intake</span>
</div>
<div class="form-grid">
<div class="field">
<label for="vendor">Merchant</label>
<select id="vendor">
<option value="Bahariye Coffee">Bahariye Coffee</option>
<option value="Ottoman Spice">Ottoman Spice</option>
<option value="Çayhane Roasters">Çayhane Roasters</option>
<option value="Silk House">Silk House</option>
<option value="Fig & Loom">Fig & Loom</option>
</select>
</div>
<div class="field">
<label for="time">Time</label>
<select id="time">
<option>08:30</option>
<option>09:00</option>
<option selected>09:30</option>
<option>10:00</option>
<option>10:30</option>
<option>11:00</option>
<option>11:30</option>
<option>12:00</option>
<option>12:30</option>
<option>13:00</option>
</select>
</div>
<div class="field">
<label for="units">Crates</label>
<input id="units" type="number" min="1" max="12" value="3">
</div>
</div>
<button class="primary-btn" id="scheduleBtn">
<svg viewBox="0 0 20 20"><path d="M10 4v12M4 10h12"/></svg>
Add to delivery schedule
</button>
</section>
<section class="panel-section">
<div class="section-title">
<h3>Today’s Route</h3>
<span id="deliveryCount">3 deliveries</span>
</div>
<div class="queue" id="queue"></div>
</section>
<section class="panel-section">
<div class="section-title">
<h3>Courtyard Storage</h3>
<span id="storageTotal">15 / 36 crates</span>
</div>
<div class="storage-grid" id="storageGrid"></div>
</section>
<section class="panel-section">
<div class="section-title">
<h3>Activity Log</h3>
<span>Live</span>
</div>
<div class="event-list" id="eventList"></div>
</section>
</aside>
</main>
</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";
/* ---------- Scene setup ---------- */
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9c8aa);
scene.fog = new THREE.Fog(0xd9c8aa, 48, 90);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 140);
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;
stage.prepend(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xfff0d1, 0x526d68, 2.25);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffe2aa, 3.25);
sun.position.set(-22, 34, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bcfd0, 0.8);
fill.position.set(24, 14, -20);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function mat(color, roughness = 0.82) {
const key = `${color}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({ color, roughness }));
}
return materialCache.get(key);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, options = {}) {
const mesh = new THREE.Mesh(unitBox, options.material || mat(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, color, x, y, z, segments = 8) {
const geo = new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments);
const mesh = new THREE.Mesh(geo, mat(color));
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createLabel(text, className, anchor) {
const el = document.createElement("div");
el.className = `scene-label ${className}`;
el.textContent = text;
document.querySelector("#labels").appendChild(el);
return { el, anchor: anchor.clone() };
}
const labels = [
createLabel("Customer passage", "customer", new THREE.Vector3(-8, 1.4, 0)),
createLabel("Dedicated service lane", "delivery", new THREE.Vector3(-5, 1.1, 16)),
createLabel("Courtyard storage", "storage", new THREE.Vector3(14, 5.5, 10)),
createLabel("Meydan Gate", "gate", new THREE.Vector3(-24, 4.8, 0)),
createLabel("Delivery gate", "gate", new THREE.Vector3(-21, 4.6, 16)),
createLabel("Şadırvan", "customer", new THREE.Vector3(0, 4.2, 0))
];
/* ---------- Voxel architecture ---------- */
const world = new THREE.Group();
scene.add(world);
box(world, 54, 0.8, 43, 0xa99875, 0, -0.55, 0);
box(world, 51, 0.22, 39, 0xc8b58d, 0, -0.08, 0);
// Courtyard paving
for (let x = -12; x <= 12; x += 2) {
for (let z = -10; z <= 10; z += 2) {
if (Math.abs(x) < 3 && Math.abs(z) < 3) continue;
const c = ((x + z) % 4 === 0) ? 0xd6c6a6 : 0xcdbc99;
box(world, 1.92, 0.12, 1.92, c, x, 0.09, z, { castShadow: false });
}
}
// Border walls
box(world, 51, 3.3, 0.65, 0xc8a878, 0, 1.65, -19);
box(world, 0.65, 3.3, 38, 0xc8a878, -25, 1.65, 0);
box(world, 0.65, 3.3, 38, 0xc8a878, 25, 1.65, 0);
for (let x = -23; x <= 23; x += 4) {
box(world, 3.7, 0.25, 0.8, 0xe0c99c, x, 3.3, -19);
}
function signTexture(text, background = "#234c48", foreground = "#f9dfaa") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 512, 128);
ctx.strokeStyle = foreground;
ctx.lineWidth = 5;
ctx.strokeRect(9, 9, 494, 110);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "600 40px Georgia";
ctx.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addSign(group, text, x, y, z, width = 4.5, bg = "#234c48") {
const texture = signTexture(text, bg);
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.75,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, width * 0.25), material);
mesh.position.set(x, y, z);
group.add(mesh);
return mesh;
}
function createDome(parent, radius = 3.4, baseY = 7.2) {
const dome = new THREE.Group();
dome.position.y = baseY;
const levels = 8;
for (let i = 0; i < levels; i++) {
const t = (i + 0.5) / levels;
const width = radius * 2 * Math.sqrt(Math.max(0.02, 1 - t * t));
box(dome, width, 0.3, width, i < 2 ? 0x57766c : 0x42665f, 0, i * 0.31, 0);
}
box(dome, 0.16, 0.8, 0.16, 0xd6ad50, 0, levels * 0.31 + 0.25, 0);
box(dome, 0.38, 0.18, 0.38, 0xd6ad50, 0, levels * 0.31 + 0.65, 0);
parent.add(dome);
}
function createShop({
x, z, w = 10, d = 7, h = 6.5, color = 0xb9694e,
trim = 0xf0d39c, sign = "BAZAR", rotation = 0, dome = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, w + .6, .45, d + .6, 0x8e7658, 0, .25, 0);
box(group, w, h, d, color, 0, h / 2 + .35, 0);
// Stone corner quoins
for (const sx of [-1, 1]) {
for (let i = 0; i < 5; i++) {
box(group, .72, .58, .72, i % 2 ? trim : 0xdec49a,
sx * (w / 2 - .35), .65 + i * .7, d / 2 - .2);
}
}
const facadeZ = d / 2 + .07;
// Voxel arch entrance
box(group, 2.35, 2.65, .18, 0x263d39, 0, 1.65, facadeZ);
box(group, .3, 2.9, .32, trim, -1.35, 1.7, facadeZ + .12);
box(group, .3, 2.9, .32, trim, 1.35, 1.7, facadeZ + .12);
box(group, 3.0, .35, .32, trim, 0, 3.18, facadeZ + .12);
box(group, 2.25, .28, .32, trim, 0, 3.48, facadeZ + .12);
box(group, 1.4, .24, .32, trim, 0, 3.72, facadeZ + .12);
// Windows and shutters
for (const sx of [-1, 1]) {
const wx = sx * (w * .31);
box(group, 1.25, 1.35, .14, 0x263f3d, wx, 3.4, facadeZ + .08);
box(group, .12, 1.5, .18, trim, wx - .72, 3.4, facadeZ + .12);
box(group, .12, 1.5, .18, trim, wx + .72, 3.4, facadeZ + .12);
box(group, 1.55, .12, .18, trim, wx, 3.4, facadeZ + .12);
}
// Awning
const awningWidth = w - 1;
const stripeCount = Math.ceil(awningWidth / .8);
const stripeWidth = awningWidth / stripeCount;
for (let i = 0; i < stripeCount; i++) {
box(group, stripeWidth, .16, 1.6, i % 2 ? 0xf3dfb2 : 0x7d3930,
-awningWidth / 2 + stripeWidth * (i + .5), 4.35, d / 2 + .75);
}
box(group, awningWidth, .12, .13, 0x6d3c31, 0, 4.28, d / 2 + 1.52);
// Roof lip and parapet
box(group, w + .75, .28, d + .75, trim, 0, h + .48, 0);
box(group, w + .2, .65, .25, color, 0, h + .82, -d / 2);
box(group, w + .2, .65, .25, color, 0, h + .82, d / 2);
box(group, .25, .65, d, color, -w / 2, h + .82, 0);
box(group, .25, .65, d, color, w / 2, h + .82, 0);
addSign(group, sign, 0, 5.35, facadeZ + .12, Math.min(w - 1, 5.6),
color === 0x7c9b89 ? "#315b53" : "#6c3c31");
// Hanging lanterns
for (const sx of [-1, 1]) {
const lx = sx * (w * .42);
box(group, .08, .8, .08, 0x4c4538, lx, 4.9, d / 2 + .55);
box(group, .42, .55, .42, 0xd69a43, lx, 4.22, d / 2 + .55);
box(group, .5, .12, .5, 0x5e4931, lx, 4.53, d / 2 + .55);
}
if (dome) createDome(group, Math.min(w, d) * .29, h + .75);
return group;
}
createShop({
x: -14.5, z: -14.5, w: 10, d: 7.5, h: 6.4,
color: 0xb9674d, sign: "BAHARİYE", dome: true
});
createShop({
x: 0, z: -14.5, w: 10.5, d: 7.5, h: 6.8,
color: 0x718f80, sign: "ZEYTİN & BAHARAT"
});
createShop({
x: 14.5, z: -14.5, w: 10, d: 7.5, h: 6.3,
color: 0xa85b43, sign: "ÇAYHANE"
});
createShop({
x: -19.5, z: -3.2, w: 9, d: 7, h: 5.8,
color: 0x789481, sign: "İPEK EVİ", rotation: Math.PI / 2
});
createShop({
x: 19.5, z: -3.2, w: 9, d: 7, h: 5.8,
color: 0xad6c51, sign: "İNCİR & DOKUMA", rotation: -Math.PI / 2
});
// Minaret
const minaret = new THREE.Group();
minaret.position.set(22.3, 0, -15.2);
world.add(minaret);
box(minaret, 2.2, 12, 2.2, 0xd7b783, 0, 6, 0);
box(minaret, 2.55, .35, 2.55, 0xe8cc91, 0, 8.9, 0);
box(minaret, 1.65, 3.2, 1.65, 0xe1c28c, 0, 10.8, 0);
box(minaret, 1.95, .3, 1.95, 0xf0d69b, 0, 12.5, 0);
box(minaret, 1.25, 1.2, 1.25, 0x446860, 0, 13.1, 0);
box(minaret, 1.55, .25, 1.55, 0xc29a55, 0, 13.85, 0);
box(minaret, .95, .8, .95, 0xd6b276, 0, 14.25, 0);
box(minaret, .12, 1.4, .12, 0xd6ad50, 0, 15.25, 0);
box(minaret, .34, .18, .34, 0xd6ad50, 0, 15.98, 0);
// Fountain
const fountain = new THREE.Group();
fountain.position.set(0, 0, 0);
world.add(fountain);
box(fountain, 6.2, .45, 6.2, 0x685d50, 0, .28, 0);
box(fountain, 5.4, .25, 5.4, 0xe4cc9e, 0, .62, 0);
box(fountain, 4.55, .28, 4.55, 0x2e9292, 0, .78, 0);
box(fountain, 4.75, .55, .3, 0xe8d2a4, 0, .98, -2.3);
box(fountain, 4.75, .55, .3, 0xe8d2a4, 0, .98, 2.3);
box(fountain, .3, .55, 4.75, 0xe8d2a4, -2.3, .98, 0);
box(fountain, .3, .55, 4.75, 0xe8d2a4, 2.3, .98, 0);
box(fountain, .85, 2.35, .85, 0xc5a778, 0, 1.85, 0);
box(fountain, 1.45, .28, 1.45, 0xe4cc9e, 0, 3.05, 0);
box(fountain, .55, .8, .55, 0xb89466, 0, 3.58, 0);
box(fountain, 1.8, .22, .22, 0xd6ad50, 0, 4.02, 0);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(fountain, .36, .38, .12, 0x287b80, sx * 1.65, .93, sz * 2.08);
}
}
// Gates
function createGate(x, z, rotation, title) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, 1.4, 5.3, 1.5, 0xb86a4d, -3.1, 2.65, 0);
box(group, 1.4, 5.3, 1.5, 0xb86a4d, 3.1, 2.65, 0);
box(group, 7.8, .9, 1.5, 0xc8a578, 0, 5.15, 0);
box(group, 6.4, .38, 1.7, 0xe3c996, 0, 5.7, 0);
for (let i = 0; i < 5; i++) {
const size = 4.8 - i * .55;
box(group, size, .35, 1.55, 0xe2c793, 0, 3.65 + i * .28, 0);
}
addSign(group, title, 0, 5.25, .82, 5.1, "#6d3d31");
return group;
}
createGate(-24.2, 0, Math.PI / 2, "MEYDAN KAPISI");
createGate(-21.5, 16.2, 0, "HİZMET GİRİŞİ");
// Storage arcade
const storage = new THREE.Group();
storage.position.set(14, 0, 10.5);
world.add(storage);
box(storage, 13.5, .25, 6.5, 0xb39a72, 0, .2, 0);
box(storage, 13.5, 4.6, .38, 0x8d694f, 0, 2.55, 2.8);
for (const x of [-6.2, -2.1, 2.1, 6.2]) {
box(storage, .58, 4.5, .58, 0xe0c495, x, 2.5, -2.7);
}
box(storage, 13.6, .35, 6.3, 0x496d63, 0, 4.85, 0);
box(storage, 14, .3, 6.7, 0xd2b781, 0, 5.16, 0);
addSign(storage, "AVLU DEPOLAMA", 0, 4.18, -3.02, 6.3, "#31574e");
const bayData = [
{ id: "A", x: -4.15, capacity: 12, used: 7, color: 0x7f9b87 },
{ id: "B", x: 0, capacity: 12, used: 5, color: 0xb46e4d },
{ id: "C", x: 4.15, capacity: 12, used: 3, color: 0xc39b54 }
];
const crateMeshes = {};
const bayHighlights = {};
for (const bay of bayData) {
bay.localX = bay.x;
bay.worldX = 14 + bay.x;
bay.crates = [];
const highlightMat = new THREE.MeshBasicMaterial({
color: 0xe88a3d,
transparent: true,
opacity: 0,
depthWrite: false
});
const highlight = box(storage, 3.65, .035, 4.65, 0xffffff, bay.x, .36, -.45, {
material: highlightMat,
castShadow: false,
receiveShadow: false
});
bayHighlights[bay.id] = { mesh: highlight, material: highlightMat };
for (let i = 0; i < bay.capacity; i++) {
const col = i % 4;
const row = Math.floor(i / 4) % 3;
const layer = Math.floor(i / 12);
const crate = box(storage, .72, .68, .72, i % 3 === 0 ? 0x9c7046 : 0xb18150,
bay.x - 1.05 + col * .7, .72 + layer * .7, -1.45 + row * .75);
box(storage, .76, .08, .09, 0x745233, crate.position.x, crate.position.y, crate.position.z + .37);
crate.visible = i < bay.used;
bay.crates.push(crate);
}
addSign(storage, bay.id, bay.x, 3.45, -3.03, 1.25, "#6d3d31");
}
// Trees
function createTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
world.add(g);
box(g, .6, 3.5, .6, 0x75563c, 0, 1.75, 0);
box(g, 2.8, 1.7, 2.5, 0x4f7751, 0, 4, 0);
box(g, 2.1, 1.5, 2.8, 0x5e8557, .5, 4.8, -.15);
box(g, 1.6, 1.2, 1.7, 0x73955d, -.65, 5.2, .2);
}
createTree(-22, 7, .9);
createTree(22, 6, .95);
createTree(-8, 12, .65);
createTree(7, -10.5, .6);
// String lights and poles
for (const z of [-10.5, 8.5]) {
for (const x of [-17, 0, 17]) {
box(world, .18, 5.2, .18, 0x4b5043, x, 2.6, z);
box(world, .8, .12, .12, 0x4b5043, x, 5.15, z);
}
}
const bulbMaterial = new THREE.MeshBasicMaterial({ color: 0xffd47a });
for (let x = -16; x <= 16; x += 2) {
const y = 5 - Math.abs(x) * .035;
const bulb = box(world, .16, .22, .16, 0xffffff, x, y, -10.5, { material: bulbMaterial });
bulb.castShadow = false;
}
/* ---------- Routes and people ---------- */
const customerPath = [
new THREE.Vector3(-24, .24, 0),
new THREE.Vector3(-16, .24, 0),
new THREE.Vector3(-8, .24, 0),
new THREE.Vector3(-3, .24, 0),
new THREE.Vector3(0, .24, 0),
new THREE.Vector3(0, .24, -8),
new THREE.Vector3(0, .24, -10.5)
];
function servicePathToBay(bayId) {
const bay = bayData.find(b => b.id === bayId);
return [
new THREE.Vector3(-21.5, .26, 16.2),
new THREE.Vector3(-16, .26, 16.2),
new THREE.Vector3(-6, .26, 16.2),
new THREE.Vector3(6, .26, 16.2),
new THREE.Vector3(bay.worldX, .26, 16.2),
new THREE.Vector3(bay.worldX, .26, 12),
new THREE.Vector3(bay.worldX, .26, 7.2)
];
}
function resamplePath(points, spacing = 1.2) {
const result = [];
let remaining = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i], b = points[i + 1];
const distance = a.distanceTo(b);
const direction = b.clone().sub(a).normalize();
let d = remaining;
while (d < distance) {
result.push(a.clone().addScaledVector(direction, d));
d += spacing;
}
remaining = distance - (d - spacing);
}
return result;
}
function addRoute(group, points, color, spacing = 1.1) {
for (const point of resamplePath(points, spacing)) {
box(group, .32, .08, .32, color, point.x, point.y, point.z, {
castShadow: false,
receiveShadow: false
});
}
}
const customerRouteGroup = new THREE.Group();
world.add(customerRouteGroup);
addRoute(customerRouteGroup, customerPath, 0x36a89c, 1.15);
// A second customer branch
addRoute(customerRouteGroup, [
new THREE.Vector3(0, .24, 0),
new THREE.Vector3(7, .24, 2),
new THREE.Vector3(14, .24, 3)
], 0x36a89c, 1.15);
const activeRouteGroup = new THREE.Group();
world.add(activeRouteGroup);
const conflictGroup = new THREE.Group();
world.add(conflictGroup);
const conflictMat = new THREE.MeshBasicMaterial({
color: 0xd65342,
transparent: true,
opacity: .65,
depthWrite: false
});
box(conflictGroup, 3.2, .05, 3.2, 0xffffff, 0, .32, 0, {
material: conflictMat,
castShadow: false,
receiveShadow: false
});
conflictGroup.visible = false;
function createPerson(color, scale = 1) {
const g = new THREE.Group();
g.scale.setScalar(scale);
box(g, .48, .7, .36, color, 0, .8, 0);
box(g, .38, .38, .36, 0xc58e6b, 0, 1.42, 0);
box(g, .5, .18, .42, 0xeee0bc, 0, 1.64, 0);
box(g, .16, .6, .18, 0x344e4b, -.14, .28, 0);
box(g, .16, .6, .18, 0x344e4b, .14, .28, 0);
return g;
}
const people = [];
for (let i = 0; i < 8; i++) {
const person = createPerson([0x9a4f3e, 0x426e68, 0xd19b48, 0x74516b][i % 4], .82 + (i % 3) * .08);
world.add(person);
people.push({
mesh: person,
offset: i / 8,
speed: .035 + (i % 4) * .005,
direction: i % 2 ? 1 : -1
});
}
// Delivery cart
const cart = new THREE.Group();
world.add(cart);
box(cart, 1.65, .32, 1.1, 0x6f5036, 0, .58, 0);
box(cart, 1.4, .8, .9, 0xb57743, 0, 1.12, 0);
box(cart, 1.5, .12, 1, 0xd19b51, 0, 1.57, 0);
for (const x of [-.52, .52]) {
for (const z of [-.52, .52]) {
const wheel = cylinder(cart, .25, .25, .16, 0x3d3730, x, .34, z, 10);
wheel.rotation.z = Math.PI / 2;
}
}
box(cart, .12, .12, 1.8, 0x685039, 0, .72, 1.15);
cart.position.set(-21.5, 0, 16.2);
cart.visible = false;
/* ---------- Application data ---------- */
const vendorLocations = {
"Bahariye Coffee": { x: -14.5, z: -10.5, preferred: "A" },
"Ottoman Spice": { x: 0, z: -10.5, preferred: "B" },
"Çayhane Roasters": { x: 14.5, z: -10.5, preferred: "C" },
"Silk House": { x: -16, z: -3.2, preferred: "A" },
"Fig & Loom": { x: 16, z: -3.2, preferred: "C" }
};
let deliveryCounter = 107;
let activeDeliveryId = "DV-104";
let passagePriority = true;
let cartAnimation = null;
let toastTimer;
const deliveries = [
{ id: "DV-104", time: "08:45", vendor: "Bahariye Coffee", units: 6, bay: "A", status: "Staged" },
{ id: "DV-105", time: "09:20", vendor: "Ottoman Spice", units: 5, bay: "B", status: "Staged" },
{ id: "DV-106", time: "10:00", vendor: "Çayhane Roasters", units: 4, bay: "C", status: "Queued" }
];
const events = [
{ title: "DV-104 cleared the service gate", detail: "6 crates moved to Bay A" },
{ title: "Public passage verified", detail: "Customer route remains unobstructed" },
{ title: "Storage bay B opened", detail: "5 crates reserved for Ottoman Spice" }
];
/* ---------- UI rendering ---------- */
const queueEl = document.querySelector("#queue");
const storageGridEl = document.querySelector("#storageGrid");
const eventListEl = document.querySelector("#eventList");
const passageCard = document.querySelector("#passageCard");
const priorityToggle = document.querySelector("#priorityToggle");
function currentDelivery() {
return deliveries.find(d => d.id === activeDeliveryId) || deliveries[0];
}
function showToast(message) {
const toast = document.querySelector("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
}
function renderQueue() {
queueEl.innerHTML = "";
for (const delivery of deliveries) {
const card = document.createElement("div");
card.className = `delivery-card${delivery.id === activeDeliveryId ? " active" : ""}`;
card.innerHTML = `
<div class="time-block">
<strong>${delivery.time}</strong>
<span>${delivery.id}</span>
</div>
<div class="delivery-info">
<strong>${delivery.vendor}</strong>
<span>${delivery.units} crate${delivery.units === 1 ? "" : "s"} · Bay ${delivery.bay}</span>
</div>
<div class="delivery-meta">
<span class="bay-badge">${delivery.bay}</span>
<span class="status-text">${delivery.status}</span>
</div>
`;
card.addEventListener("click", () => {
activeDeliveryId = delivery.id;
renderQueue();
renderStorage();
updateActiveRoute();
showToast(`${delivery.id} selected · ${delivery.vendor}`);
});
queueEl.appendChild(card);
}
document.querySelector("#deliveryCount").textContent =
`${deliveries.length} deliver${deliveries.length === 1 ? "y" : "ies"}`;
}
function renderStorage() {
storageGridEl.innerHTML = "";
for (const bay of bayData) {
const card = document.createElement("div");
card.className = `storage-card${currentDelivery()?.bay === bay.id ? " active" : ""}`;
card.innerHTML = `
<header>Bay ${bay.id}<span>${bay.used}/${bay.capacity}</span></header>
<div class="capacity-bar"><i></i></div>
<small>${bay.capacity - bay.used} spaces available</small>
`;
card.querySelector("i").style.width = `${bay.used / bay.capacity * 100}%`;
card.addEventListener("click", () => {
const related = deliveries.find(d => d.bay === bay.id);
if (related) {
activeDeliveryId = related.id;
renderQueue();
renderStorage();
updateActiveRoute();
} else {
showToast(`Bay ${bay.id} · ${bay.capacity - bay.used} spaces available`);
}
});
storageGridEl.appendChild(card);
}
const used = bayData.reduce((sum, bay) => sum + bay.used, 0);
const total = bayData.reduce((sum, bay) => sum + bay.capacity, 0);
document.querySelector("#storageTotal").textContent = `${used} / ${total} crates`;
for (const bay of bayData) {
bay.crates.forEach((crate, i) => crate.visible = i < bay.used);
}
}
function renderEvents() {
eventListEl.innerHTML = "";
for (const event of events.slice(0, 4)) {
const el = document.createElement("div");
el.className = "event";
el.innerHTML = `<div><strong>${event.title}</strong><br>${event.detail}</div>`;
eventListEl.appendChild(el);
}
}
function updatePassageUI() {
passageCard.classList.toggle("warning", !passagePriority);
if (passagePriority) {
document.querySelector("#passageTitle").textContent = "Customer passage is clear";
document.querySelector("#passageDescription").textContent =
"Deliveries are staged in courtyard storage, outside the public route.";
document.querySelector("#clearScore").textContent = "100%";
document.querySelector("#headerPassage").textContent = "Passage protected";
} else {
document.querySelector("#passageTitle").textContent = "Direct handoff conflict";
document.querySelector("#passageDescription").textContent =
"The active route crosses the public axis at the fountain.";
document.querySelector("#clearScore").textContent = "1";
document.querySelector("#headerPassage").textContent = "Passage conflict";
}
}
function updateActiveRoute() {
while (activeRouteGroup.children.length) {
const child = activeRouteGroup.children[0];
activeRouteGroup.remove(child);
}
const delivery = currentDelivery();
if (!delivery) return;
let points;
if (passagePriority) {
points = servicePathToBay(delivery.bay);
addRoute(activeRouteGroup, points, 0xee8a3a, .9);
conflictGroup.visible = false;
} else {
const location = vendorLocations[delivery.vendor];
points = [
new THREE.Vector3(-21.5, .27, 16.2),
new THREE.Vector3(-8, .27, 16.2),
new THREE.Vector3(0, .27, 16.2),
new THREE.Vector3(0, .27, 2),
new THREE.Vector3(0, .27, 0),
new THREE.Vector3(location.x, .27, 0),
new THREE.Vector3(location.x, .27, location.z)
];
addRoute(activeRouteGroup, points, 0xd95742, .9);
conflictGroup.position.set(0, 0, 0);
conflictGroup.visible = true;
}
for (const bay of bayData) {
bayHighlights[bay.id].material.opacity = delivery.bay === bay.id ? .2 : 0;
}
}
priorityToggle.addEventListener("change", () => {
passagePriority = priorityToggle.checked;
updatePassageUI();
updateActiveRoute();
showToast(passagePriority
? "Passage priority restored · storage staging enabled"
: "Direct handoff preview · one customer-route conflict");
});
document.querySelector("#scheduleBtn").addEventListener("click", () => {
const vendor = document.querySelector("#vendor").value;
const time = document.querySelector("#time").value;
const units = Math.max(1, Math.min(12, Number(document.querySelector("#units").value) || 1));
const location = vendorLocations[vendor];
const preferred = bayData.find(b => b.id === location.preferred);
let bay = preferred && preferred.capacity - preferred.used >= units
? preferred
: bayData.find(b => b.capacity - b.used >= units);
if (!bay) {
showToast("No storage bay has enough space for this delivery");
return;
}
bay.used += units;
const delivery = {
id: `DV-${deliveryCounter++}`,
time,
vendor,
units,
bay: bay.id,
status: "Queued"
};
deliveries.push(delivery);
activeDeliveryId = delivery.id;
events.unshift({
title: `${delivery.id} scheduled`,
detail: `${units} crates reserved in Bay ${bay.id} for ${time}`
});
renderQueue();
renderStorage();
renderEvents();
updateActiveRoute();
showToast(`${delivery.id} added · Bay ${bay.id} reserved`);
});
/* ---------- Custom orbit camera ---------- */
const orbit = {
target: new THREE.Vector3(0, 2.2, 0),
radius: 47,
yaw: .72,
pitch: .72
};
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.yaw),
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z + horizontal * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let dragDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
orbit.yaw -= dx * .006;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * .004, .32, 1.18);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointercancel", () => dragging = false);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * .035, 27, 70);
updateCamera();
}, { passive: false });
document.querySelector("#zoomIn").addEventListener("click", () => {
orbit.radius = Math.max(27, orbit.radius - 5);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
orbit.radius = Math.min(70, orbit.radius + 5);
updateCamera();
});
document.querySelector("#rotateLeft").addEventListener("click", () => {
orbit.yaw -= Math.PI / 8;
updateCamera();
});
document.querySelector("#rotateRight").addEventListener("click", () => {
orbit.yaw += Math.PI / 8;
updateCamera();
});
document.querySelector("#resetView").addEventListener("click", () => {
orbit.target.set(0, 2.2, 0);
orbit.radius = 47;
orbit.yaw = .72;
orbit.pitch = .72;
updateCamera();
});
/* ---------- Resize and animation ---------- */
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function pointOnPath(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let distance = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
return points[i].clone().lerp(points[i + 1], distance / lengths[i]);
}
distance -= lengths[i];
}
return points.at(-1).clone();
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Moving customers along the public axis
for (const person of people) {
const t = person.offset + elapsed * person.speed * person.direction;
const p = pointOnPath(customerPath, t);
const next = pointOnPath(customerPath, t + .002);
person.mesh.position.copy(p);
person.mesh.position.y = 0;
person.mesh.rotation.y = Math.atan2(next.x - p.x, next.z - p.z);
person.mesh.position.y = Math.abs(Math.sin(elapsed * 7 + person.offset * 10)) * .045;
}
// Active route pulse
activeRouteGroup.children.forEach((marker, i) => {
const scale = 1 + Math.sin(elapsed * 3.5 - i * .45) * .22;
marker.scale.y = .08 * scale;
});
// Storage highlight pulse
const active = currentDelivery();
if (active) {
const highlight = bayHighlights[active.bay];
highlight.material.opacity = passagePriority
? .14 + Math.sin(elapsed * 2.6) * .07
: 0;
conflictMat.opacity = .45 + Math.sin(elapsed * 4) * .18;
}
// Dispatch cart animation
if (cartAnimation) {
cartAnimation.progress += clock.getDelta() * .13;
const p = pointOnPath(cartAnimation.points, cartAnimation.progress);
const next = pointOnPath(cartAnimation.points, Math.min(1, cartAnimation.progress + .01));
cart.position.copy(p);
cart.position.y = 0;
cart.rotation.y = Math.atan2(next.x - p.x, next.z - p.z);
if (cartAnimation.progress >= 1) {
cartAnimation = null;
cart.visible = false;
}
}
// Project DOM labels
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.el.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * .5 + .5) * stage.clientWidth;
const y = (-projected.y * .5 + .5) * stage.clientHeight;
label.el.style.left = `${x}px`;
label.el.style.top = `${y}px`;
}
}
renderer.render(scene, camera);
}
renderQueue();
renderStorage();
renderEvents();
updatePassageUI();
updateActiveRoute();
animate();
function updateClock() {
const now = new Date();
document.querySelector("#headerTime").textContent =
now.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
}
updateClock();
setInterval(updateClock, 30000);
</script>
</body>
</html>
```