Prompt specification
Build or customize the Three.js 3D scene "Tailor workflow scheduling puzzle" 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: Tailor workflow scheduling puzzle
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tailor-workflow-scheduling-puzzle-x0552
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: tailor workflow scheduling puzzle. Create several fictional alteration requests with different step sequences; users route tagged garments through measurement, stitching, and collection without losing order identity or using a station twice simultaneously. Return one self-contained HTML file.
Working Three.js Starter (tailor-workflow-scheduling-puzzle-x0552):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Threadline — Alteration Routing Puzzle</title>
<style>
:root {
--ink: #20313d;
--muted: #6d777c;
--paper: #f7f2e9;
--paper-deep: #e9dfd1;
--line: rgba(32, 49, 61, 0.14);
--coral: #d96f55;
--teal: #347d72;
--gold: #d5a64b;
--shadow: 0 18px 45px rgba(43, 47, 44, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background:
radial-gradient(circle at 52% 22%, rgba(255,255,255,.92), rgba(255,255,255,0) 38%),
linear-gradient(145deg, #eee8de 0%, #ddd3c4 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
height: 64px;
display: flex;
align-items: center;
gap: 18px;
padding: 10px 12px 10px 16px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 18px;
background: rgba(250,247,240,.84);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border-radius: 12px;
background: var(--ink);
box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--paper);
border-radius: 999px;
}
.brand-mark::before {
width: 17px;
height: 5px;
left: 8px;
top: 12px;
transform: rotate(-28deg);
}
.brand-mark::after {
width: 5px;
height: 18px;
right: 9px;
top: 10px;
transform: rotate(28deg);
}
.brand-title {
font-size: 15px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
letter-spacing: .04em;
}
.header-stats {
display: flex;
gap: 8px;
margin-left: auto;
}
.stat {
min-width: 94px;
padding: 7px 11px;
border-radius: 11px;
background: rgba(32,49,61,.055);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 2px;
color: var(--ink);
font-size: 16px;
letter-spacing: 0;
}
.top-actions {
display: flex;
gap: 8px;
}
.button {
border: 1px solid var(--line);
border-radius: 11px;
padding: 9px 12px;
color: var(--ink);
background: rgba(255,255,255,.72);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover {
transform: translateY(-1px);
border-color: rgba(32,49,61,.28);
background: #fff;
}
.button:active { transform: translateY(0); }
.button.primary {
border-color: var(--ink);
color: white;
background: var(--ink);
}
.panel {
position: fixed;
z-index: 8;
top: 96px;
bottom: 22px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 20px;
background: rgba(249,246,239,.86);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
overflow: hidden;
}
#orders-panel {
left: 20px;
width: 310px;
display: flex;
flex-direction: column;
}
#stations-panel {
right: 20px;
width: 286px;
display: flex;
flex-direction: column;
}
.panel-head {
padding: 18px 18px 13px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
color: var(--coral);
font-size: 10px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
.panel-title {
margin: 5px 0 0;
font-size: 19px;
line-height: 1.15;
letter-spacing: -.02em;
}
.panel-note {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.order-list {
flex: 1;
min-height: 0;
overflow: auto;
padding: 12px;
}
.ticket {
position: relative;
width: 100%;
margin: 0 0 10px;
padding: 14px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 15px;
color: var(--ink);
background: rgba(255,255,255,.68);
text-align: left;
cursor: pointer;
transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.ticket:hover {
transform: translateY(-1px);
border-color: rgba(32,49,61,.3);
}
.ticket.selected {
border-color: var(--ticket-color);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--ticket-color) 22%, transparent);
}
.ticket::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--ticket-color);
}
.ticket-top {
display: flex;
align-items: flex-start;
gap: 10px;
}
.ticket-id {
flex: 0 0 auto;
min-width: 46px;
padding: 5px 6px;
border-radius: 8px;
color: var(--ink);
background: color-mix(in srgb, var(--ticket-color) 22%, white);
font-size: 10px;
font-weight: 900;
letter-spacing: .07em;
text-align: center;
}
.ticket-name {
font-size: 14px;
font-weight: 820;
}
.ticket-request {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.ticket-state {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 720;
letter-spacing: .035em;
}
.ticket-state.ready { color: var(--teal); }
.ticket-state.done { color: var(--teal); }
.sequence {
display: flex;
align-items: center;
gap: 4px;
margin-top: 10px;
}
.sequence-pip {
flex: 1;
min-width: 0;
padding: 6px 3px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--muted);
background: rgba(32,49,61,.025);
font-size: 8px;
font-weight: 850;
letter-spacing: .04em;
text-align: center;
text-transform: uppercase;
}
.sequence-pip.current {
border-color: var(--ticket-color);
color: var(--ink);
background: color-mix(in srgb, var(--ticket-color) 19%, white);
}
.sequence-pip.done {
border-color: transparent;
color: white;
background: var(--teal);
}
.sequence-arrow {
color: rgba(32,49,61,.3);
font-size: 9px;
}
.station-list {
padding: 12px;
}
.station-card {
margin-bottom: 10px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255,255,255,.64);
}
.station-card.busy {
border-color: rgba(213,166,75,.65);
background: rgba(255,247,220,.8);
}
.station-row {
display: flex;
align-items: center;
gap: 10px;
}
.station-number {
width: 29px;
height: 29px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 9px;
color: white;
background: var(--ink);
font-size: 10px;
font-weight: 900;
}
.station-name {
font-size: 12px;
font-weight: 850;
}
.station-occupancy {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: .06em;
text-transform: uppercase;
}
.station-occupancy.closed { color: var(--coral); }
.station-action {
width: 100%;
margin-top: 11px;
padding: 8px 9px;
border: 1px solid rgba(32,49,61,.18);
border-radius: 9px;
color: var(--ink);
background: rgba(32,49,61,.045);
cursor: pointer;
font-size: 10px;
font-weight: 820;
letter-spacing: .025em;
transition: background .15s ease, transform .15s ease;
}
.station-action:hover:not(:disabled) {
transform: translateY(-1px);
background: rgba(32,49,61,.09);
}
.station-action:disabled {
cursor: wait;
opacity: .72;
}
.progress {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(32,49,61,.09);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--gold);
}
.rules {
margin: 0 12px 12px;
padding: 12px;
border-radius: 13px;
background: rgba(52,125,114,.08);
}
.rule {
display: flex;
gap: 8px;
margin: 7px 0;
color: #4d625f;
font-size: 10px;
line-height: 1.35;
}
.rule::before {
content: "✓";
color: var(--teal);
font-weight: 900;
}
.activity {
flex: 1;
min-height: 78px;
margin-top: auto;
padding: 13px 16px 16px;
border-top: 1px solid var(--line);
overflow: hidden;
}
.activity-title {
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: .13em;
text-transform: uppercase;
}
.activity-entry {
margin-top: 7px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.activity-entry strong { color: var(--ink); }
.route-hint {
position: fixed;
z-index: 7;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
max-width: min(520px, calc(100vw - 660px));
padding: 11px 15px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 14px;
background: rgba(31,47,58,.9);
box-shadow: 0 12px 35px rgba(32,49,61,.2);
color: white;
font-size: 11px;
text-align: center;
backdrop-filter: blur(12px);
}
.route-hint strong { color: #ffd4c7; }
kbd {
margin-left: 7px;
padding: 3px 6px;
border: 1px solid rgba(255,255,255,.24);
border-radius: 5px;
color: rgba(255,255,255,.76);
background: rgba(255,255,255,.08);
font: inherit;
font-size: 9px;
}
.toast {
position: fixed;
z-index: 30;
top: 96px;
left: 50%;
max-width: min(480px, calc(100vw - 40px));
padding: 11px 16px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 12px;
background: rgba(31,47,58,.94);
box-shadow: 0 12px 35px rgba(32,49,61,.22);
color: white;
font-size: 11px;
font-weight: 650;
opacity: 0;
transform: translate(-50%, -10px);
pointer-events: none;
transition: opacity .2s ease, transform .2s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error { background: rgba(166,72,55,.96); }
.toast.success { background: rgba(45,112,101,.96); }
.modal-wrap {
position: fixed;
z-index: 40;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(29,40,47,.42);
backdrop-filter: blur(8px);
}
.modal-wrap.hidden { display: none; }
.modal {
width: min(500px, 100%);
padding: 26px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 22px;
background: #f8f3eb;
box-shadow: 0 28px 80px rgba(25,35,40,.3);
}
.modal h2 {
margin: 6px 0 10px;
font-size: 27px;
letter-spacing: -.035em;
}
.modal p,
.modal li {
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.modal ol {
margin: 16px 0;
padding-left: 20px;
}
.modal li { margin: 9px 0; }
.modal-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 20px;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #e9e1d5;
font-size: 13px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
@media (max-width: 1050px) {
#orders-panel { width: 276px; }
#stations-panel { width: 252px; }
.route-hint { max-width: calc(100vw - 570px); }
.brand { min-width: 210px; }
.stat { min-width: 76px; }
}
@media (max-width: 780px) {
.topbar { left: 10px; right: 10px; top: 10px; height: 58px; }
.brand-subtitle, .header-stats { display: none; }
.brand { min-width: 0; }
.brand-title { font-size: 13px; }
.top-actions .button { padding: 8px 9px; font-size: 10px; }
#orders-panel {
left: 10px;
top: 78px;
width: calc(100% - 20px);
bottom: auto;
max-height: 34vh;
}
.panel-head { padding: 11px 13px 9px; }
.panel-title { font-size: 15px; }
.panel-note { display: none; }
.order-list {
display: flex;
gap: 8px;
padding: 9px;
overflow-x: auto;
overflow-y: hidden;
}
.ticket { min-width: 235px; margin: 0; }
#stations-panel {
left: 10px;
right: 10px;
top: auto;
bottom: 10px;
width: auto;
max-height: 38vh;
}
.stations-scroll { overflow: auto; }
.station-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.station-card { margin: 0; }
.rules, .activity { display: none; }
.route-hint { display: none; }
.toast { top: 74px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D tailoring atelier"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-title">Threadline</div>
<div class="brand-subtitle">Alteration routing puzzle · Shift 04</div>
</div>
</div>
<div class="header-stats">
<div class="stat">At studio<strong id="atStudioStat">2 / 5</strong></div>
<div class="stat">Collected<strong id="collectedStat">0 / 5</strong></div>
</div>
<div class="top-actions">
<button class="button" id="helpBtn">How to play</button>
<button class="button primary" id="resetBtn">Reset shift</button>
</div>
</header>
<aside class="panel" id="orders-panel">
<div class="panel-head">
<div class="eyebrow">Order tickets</div>
<h2 class="panel-title">Keep every identity intact.</h2>
<p class="panel-note">Select a ticket, then route it to the next station in its required sequence.</p>
</div>
<div class="order-list" id="orderList"></div>
</aside>
<aside class="panel" id="stations-panel">
<div class="panel-head">
<div class="eyebrow">Station control</div>
<h2 class="panel-title">One garment per bay.</h2>
<p class="panel-note">Open a bay to route the selected ticket. Process its current occupant before reusing it.</p>
</div>
<div class="stations-scroll">
<div class="station-list" id="stationList"></div>
<div class="rules">
<div class="rule">Each station has a single working bay.</div>
<div class="rule">Tickets must follow their printed sequence.</div>
<div class="rule">The same tagged garment moves between stations.</div>
</div>
</div>
<div class="activity">
<div class="activity-title">Shift activity</div>
<div id="activity"></div>
</div>
</aside>
<div class="route-hint" id="routeHint">
<strong>Select a ticket</strong> and click its next station.
<kbd>1–5</kbd><kbd>M / S / C</kbd>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="modal-wrap hidden" id="modalWrap">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="eyebrow" id="modalEyebrow">Threadline guide</div>
<h2 id="modalTitle">How to run the shift</h2>
<div id="modalBody"></div>
<div class="modal-actions">
<button class="button primary" id="modalAction">Got it</button>
</div>
</div>
</div>
<div id="loading">Opening the atelier…</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const STATIONS = {
measurement: {
label: 'Measurement',
short: 'M',
number: '01',
color: 0xd7a647,
duration: 1450,
position: new THREE.Vector3(-4.15, 0, -0.35)
},
stitching: {
label: 'Stitching',
short: 'S',
number: '02',
color: 0x347d72,
duration: 2250,
position: new THREE.Vector3(0, 0, -0.35)
},
collection: {
label: 'Collection',
short: 'C',
number: '03',
color: 0xd96f55,
duration: 1100,
position: new THREE.Vector3(4.15, 0, -0.35)
}
};
const orders = [
{
id: 'M-17',
name: 'Mara Voss',
shortName: 'Mara',
item: 'Ivory trench coat',
request: 'Shorten sleeves and replace the cuff',
steps: ['stitching', 'measurement', 'collection'],
color: '#d3a34a',
threeColor: 0xd3a34a,
location: 'ready',
stepIndex: 0,
complete: false
},
{
id: 'E-04',
name: 'Elio Park',
shortName: 'Elio',
item: 'Charcoal suit jacket',
request: 'Taper the shoulders and adjust the back',
steps: ['stitching', 'measurement', 'collection'],
color: '#507fa0',
threeColor: 0x507fa0,
location: 'stitching',
stepIndex: 0,
complete: false
},
{
id: 'N-09',
name: 'Niko Bell',
shortName: 'Niko',
item: 'Rust waistcoat',
request: 'Take in both side seams',
steps: ['measurement', 'stitching', 'collection'],
color: '#c76e4b',
threeColor: 0xc76e4b,
location: 'measurement',
stepIndex: 0,
complete: false
},
{
id: 'A-21',
name: 'Ari Sen',
shortName: 'Ari',
item: 'Sage overcoat',
request: 'Reline the body and repair the vent',
steps: ['measurement', 'stitching', 'collection'],
color: '#65866d',
threeColor: 0x65866d,
location: 'ready',
stepIndex: 0,
complete: false
},
{
id: 'S-12',
name: 'Sol Reed',
shortName: 'Sol',
item: 'Plum tuxedo',
request: 'Shorten the trouser hem',
steps: ['stitching', 'measurement', 'collection'],
color: '#956483',
threeColor: 0x956483,
location: 'ready',
stepIndex: 0,
complete: false
}
];
const orderMap = new Map(orders.map(order => [order.id, order]));
let selectedOrderId = null;
let busy = null;
let toastTimer = null;
let activity = [
{ text: '<strong>Shift opened.</strong> Niko is at Measurement; Elio is at Stitching.' }
];
let shiftWon = false;
const orderList = document.getElementById('orderList');
const stationList = document.getElementById('stationList');
const activityEl = document.getElementById('activity');
const toastEl = document.getElementById('toast');
const routeHint = document.getElementById('routeHint');
const modalWrap = document.getElementById('modalWrap');
// ---------- Scene setup ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e1d5);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute('aria-label', '3D tailoring workshop with measurement, stitching and collection stations');
document.getElementById('scene').appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8ed, 0x887a68, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1dc, 3.0);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e4df, 1.1);
fill.position.set(8, 6, -4);
scene.add(fill);
const warmLamp = new THREE.PointLight(0xffbd78, 14, 9, 2);
warmLamp.position.set(0, 4.5, -2);
scene.add(warmLamp);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide,
depthWrite: options.depthWrite ?? true
}));
}
return materialCache.get(key);
}
function addBox(parent, width, height, depth, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, top, bottom, height, segments, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(top, bottom, height, segments),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextSprite(title, subtitle, accent = '#d96f55', width = 640, height = 180) {
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 5, 5, width - 10, height - 10, 24);
ctx.fillStyle = 'rgba(250,247,240,0.94)';
ctx.fill();
ctx.strokeStyle = 'rgba(32,49,61,0.16)';
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 24, 25, 10, height - 50, 5);
ctx.fill();
ctx.fillStyle = accent;
ctx.font = '800 24px system-ui, sans-serif';
ctx.letterSpacing = '3px';
ctx.fillText(subtitle.toUpperCase(), 55, 60);
ctx.fillStyle = '#20313d';
ctx.font = '850 53px system-ui, sans-serif';
ctx.fillText(title, 53, 122);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(width / 180, height / 180, 1);
return sprite;
}
function makeTagSprite(order) {
const canvas = document.createElement('canvas');
canvas.width = 320;
canvas.height = 120;
const ctx = canvas.getContext('2d');
roundedRect(ctx, 5, 5, 310, 110, 18);
ctx.fillStyle = '#fbf8f1';
ctx.fill();
ctx.strokeStyle = 'rgba(32,49,61,.25)';
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = order.color;
roundedRect(ctx, 16, 16, 14, 88, 7);
ctx.fill();
ctx.fillStyle = '#20313d';
ctx.font = '900 40px system-ui, sans-serif';
ctx.fillText(order.id, 48, 60);
ctx.fillStyle = '#6d777c';
ctx.font = '700 23px system-ui, sans-serif';
ctx.fillText(order.shortName, 49, 91);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(1.25, 0.47, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------- Atelier architecture ----------
const atelier = new THREE.Group();
scene.add(atelier);
addBox(atelier, 18, 0.22, 13, 0xd7cbbb, 0, -0.16, 0, { roughness: 0.95 });
addBox(atelier, 18, 5.2, 0.22, 0xeee5d8, 0, 2.48, -5.25, { roughness: 0.92 });
addBox(atelier, 18, 0.22, 0.28, 0x3b4b53, 0, 0.15, -5.08);
addBox(atelier, 0.22, 5.2, 11.6, 0xeee5d8, -8.85, 2.48, 0, { roughness: 0.92 });
// Floor tile seams.
for (let x = -8; x <= 8; x += 2) {
addBox(atelier, 0.025, 0.012, 12.5, 0xc8bba8, x, -0.038, 0, { castShadow: false });
}
for (let z = -5; z <= 5; z += 2) {
addBox(atelier, 17.5, 0.012, 0.025, 0xc8bba8, 0, -0.037, z, { castShadow: false });
}
// Back-wall windows.
function addWindow(x) {
addBox(atelier, 2.45, 2.05, 0.12, 0x8fa9aa, x, 2.75, -5.08, {
transparent: true,
opacity: 0.55,
roughness: 0.35,
castShadow: false
});
addBox(atelier, 0.10, 2.12, 0.16, 0x53656b, x, 2.75, -4.99);
addBox(atelier, 2.52, 0.10, 0.16, 0x53656b, x, 2.75, -4.99);
addBox(atelier, 2.72, 0.13, 0.30, 0xf7f1e7, x, 1.66, -4.94);
}
addWindow(-5.2);
addWindow(5.2);
const wallLogo = makeTextSprite('THREADLINE', 'Alteration studio · shift 04', '#d96f55', 720, 190);
wallLogo.position.set(0, 3.88, -5.0);
wallLogo.scale.set(4.1, 1.08, 1);
atelier.add(wallLogo);
// Intake rail for ready garments.
const rail = new THREE.Group();
atelier.add(rail);
addCylinder(rail, 0.07, 0.07, 3.5, 8, 0x58656a, -5.25, 1.55, 3.05);
addCylinder(rail, 0.07, 0.07, 3.5, 8, 0x58656a, 5.25, 1.55, 3.05);
const railBar = addCylinder(rail, 0.075, 0.075, 10.5, 10, 0x58656a, 0, 3.12, 3.05);
railBar.rotation.z = Math.PI / 2;
const readySign = makeTextSprite('HOLDING RAIL', 'Awaiting routing', '#6d777c', 560, 160);
readySign.position.set(0, 3.63, 3.0);
readySign.scale.set(2.15, 0.61, 1);
atelier.add(readySign);
// Small low-poly plant.
function addPlant(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
atelier.add(group);
addCylinder(group, 0.34, 0.25, 0.5, 8, 0xb66f52, 0, 0.25, 0);
addCylinder(group, 0.035, 0.05, 1.1, 6, 0x586e4d, 0, 0.9, 0);
const leafGeo = new THREE.ConeGeometry(0.24, 0.65, 5);
[
[-0.16, 1.12, 0.02, -0.45],
[0.18, 1.35, 0.01, 0.55],
[0.02, 1.58, 0.0, 0.05]
].forEach(([lx, ly, lz, rz]) => {
const leaf = new THREE.Mesh(leafGeo, material(0x5f7b58));
leaf.position.set(lx, ly, lz);
leaf.rotation.z = rz;
leaf.castShadow = true;
group.add(leaf);
});
}
addPlant(-7.35, -3.65);
addPlant(7.25, -3.7);
const stationObjects = {};
const stationHitboxes = [];
function createStationBase(station) {
const group = new THREE.Group();
group.position.copy(station.position);
atelier.add(group);
const rug = new THREE.Mesh(
new THREE.CylinderGeometry(1.52, 1.52, 0.035, 32),
material(station.id === 'collection' ? 0xe5c6b7 : 0xc9d8cf, { roughness: 0.95 })
);
rug.position.y = 0.015;
rug.receiveShadow = true;
group.add(rug);
const ring = new THREE.Mesh(
new THREE.RingGeometry(1.10, 1.17, 40),
new THREE.MeshBasicMaterial({
color: station.color,
transparent: true,
opacity: 0.36,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.045;
group.add(ring);
const hit = new THREE.Mesh(
new THREE.BoxGeometry(3.0, 3.5, 3.0),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.set(0, 1.45, -0.1);
hit.userData.stationId = station.id;
group.add(hit);
stationHitboxes.push(hit);
const sign = makeTextSprite(
station.label,
`Station ${station.number} · one bay`,
`#${station.color.toString(16).padStart(6, '0')}`,
620,
175
);
sign.position.set(0, 3.65, -0.65);
group.add(sign);
stationObjects[station.id] = { group, ring, hit, sign };
}
Object.entries(STATIONS).forEach(([id, station]) => createStationBase({ ...station, id }));
// Measurement station.
{
const g = stationObjects.measurement.group;
addBox(g, 2.1, 0.13, 1.05, 0xd9c4a7, 0.35, 1.02, -0.72);
[-0.5, 1.2].forEach(x => {
[-1.05, -0.38].forEach(z => addBox(g, 0.09, 0.95, 0.09, 0x6c665d, x, 0.5, z));
});
addCylinder(g, 0.42, 0.42, 0.06, 16, 0x596267, -0.52, 0.06, -0.47);
addCylinder(g, 0.045, 0.055, 1.15, 8, 0x596267, -0.52, 0.62, -0.47);
const dressPoints = [
new THREE.Vector2(0.04, 0),
new THREE.Vector2(0.38, 0.04),
new THREE.Vector2(0.48, 0.25),
new THREE.Vector2(0.39, 0.55),
new THREE.Vector2(0.52, 0.72),
new THREE.Vector2(0.43, 1.03),
new THREE.Vector2(0.25, 1.28),
new THREE.Vector2(0.06, 1.36)
];
const dressForm = new THREE.Mesh(
new THREE.LatheGeometry(dressPoints, 9),
material(0xc7aa8b)
);
dressForm.position.set(-0.52, 0.95, -0.47);
dressForm.castShadow = true;
g.add(dressForm);
const tape = new THREE.Mesh(
new THREE.TorusGeometry(0.24, 0.035, 6, 18, Math.PI * 1.55),
material(0xe4b84f)
);
tape.position.set(0.4, 1.2, -0.28);
tape.rotation.x = Math.PI / 2;
g.add(tape);
addBox(g, 0.38, 0.05, 0.25, 0x52696c, 0.93, 1.13, -0.62);
}
// Stitching station.
{
const g = stationObjects.stitching.group;
addBox(g, 2.35, 0.14, 1.18, 0xcfae83, 0, 1.0, -0.72);
[-0.95, 0.95].forEach(x => {
[-1.13, -0.31].forEach(z => addBox(g, 0.10, 0.94, 0.10, 0x5c625f, x, 0.5, z));
});
addBox(g, 0.95, 0.10, 0.52, 0x314b4c, -0.05, 1.12, -0.69);
addBox(g, 0.22, 0.67, 0.32, 0x3f6965, -0.35, 1.43, -0.69);
addBox(g, 0.87, 0.20, 0.32, 0x3f6965, 0.0, 1.69, -0.69);
const needle = addBox(g, 0.055, 0.45, 0.055, 0x485154, 0.31, 1.42, -0.69);
stationObjects.stitching.needle = needle;
addCylinder(g, 0.13, 0.13, 0.28, 10, 0xd96f55, -0.43, 1.91, -0.69);
addCylinder(g, 0.14, 0.14, 0.06, 10, 0x394b4e, -0.43, 2.07, -0.69);
addBox(g, 0.6, 0.12, 0.42, 0x7b8f8a, 0.85, 1.13, -0.66);
const foldedCloth = addBox(g, 0.47, 0.08, 0.35, 0x8e9b91, 0.85, 1.23, -0.66);
foldedCloth.rotation.y = 0.12;
}
// Collection station and completed garment rack.
{
const g = stationObjects.collection.group;
addBox(g, 1.9, 0.12, 0.92, 0xcfae83, -0.35, 0.93, -0.72);
[-1.05, 0.35].forEach(x => {
[-1.02, -0.42].forEach(z => addBox(g, 0.09, 0.88, 0.09, 0x5c625f, x, 0.46, z));
});
// Rear rack used for completed garments.
const rack = new THREE.Group();
rack.position.set(0.65, 0, -2.05);
g.add(rack);
[-1.38, 1.38].forEach(x => {
addCylinder(rack, 0.045, 0.045, 3.25, 8, 0x59666a, x, 1.62, 0);
});
[0.82, 1.72, 2.62].forEach(y => {
const bar = addCylinder(rack, 0.035, 0.035, 2.76, 8, 0x59666a, 0, y, 0);
bar.rotation.z = Math.PI / 2;
});
addBox(rack, 2.7, 0.07, 0.7, 0xc5b194, 0, 0.76, 0);
addBox(g, 0.65, 0.14, 0.44, 0xe7dccf, -0.55, 1.09, -0.72);
addBox(g, 0.43, 0.12, 0.38, 0x7b9290, -0.55, 1.21, -0.72);
}
// ---------- Garment tokens ----------
function makeGarmentShape() {
const shape = new THREE.Shape();
shape.moveTo(-0.26, 0.69);
shape.lineTo(-0.70, 0.46);
shape.lineTo(-0.49, 0.08);
shape.lineTo(-0.34, 0.20);
shape.lineTo(-0.36, -0.73);
shape.lineTo(0.36, -0.73);
shape.lineTo(0.34, 0.20);
shape.lineTo(0.49, 0.08);
shape.lineTo(0.70, 0.46);
shape.lineTo(0.26, 0.69);
shape.lineTo(0.14, 0.57);
shape.lineTo(-0.14, 0.57);
shape.closePath();
return shape;
}
const garmentGeometry = new THREE.ExtrudeGeometry(makeGarmentShape(), {
depth: 0.12,
bevelEnabled: true,
bevelThickness: 0.025,
bevelSize: 0.025,
bevelSegments: 1,
steps: 1
});
garmentGeometry.center();
const tokenMap = new Map();
function createToken(order, index) {
const group = new THREE.Group();
group.userData.orderId = order.id;
const pivot = new THREE.Group();
group.add(pivot);
const garment = new THREE.Mesh(
garmentGeometry,
new THREE.MeshStandardMaterial({
color: order.threeColor,
roughness: 0.88,
metalness: 0,
flatShading: true
})
);
garment.castShadow = true;
garment.receiveShadow = true;
pivot.add(garment);
const seamMaterial = new THREE.LineBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.35 });
const seamPoints = [
new THREE.Vector3(0, 0.52, 0.085),
new THREE.Vector3(0, -0.61, 0.085)
];
pivot.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints(seamPoints), seamMaterial));
const hangerPoints = [
new THREE.Vector3(-0.58, 0.73, 0),
new THREE.Vector3(0, 1.03, 0),
new THREE.Vector3(0.58, 0.73, 0)
];
const hanger = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(hangerPoints),
new THREE.LineBasicMaterial({ color: 0x4d5d60 })
);
pivot.add(hanger);
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.10, 0.018, 5, 12, Math.PI * 1.5),
material(0x4d5d60, { metalness: 0.25 })
);
hook.position.set(0, 1.07, 0);
pivot.add(hook);
const tag = makeTagSprite(order);
tag.position.set(0.30, 0.36, 0.16);
pivot.add(tag);
const selectionDisc = new THREE.Mesh(
new THREE.RingGeometry(0.61, 0.66, 28),
new THREE.MeshBasicMaterial({
color: order.threeColor,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
selectionDisc.rotation.x = -Math.PI / 2;
selectionDisc.position.y = -0.91;
group.add(selectionDisc);
group.scale.setScalar(0.001);
atelier.add(group);
tokenMap.set(order.id, {
group,
pivot,
garment,
selectionDisc,
target: new THREE.Vector3(),
phase: index * 0.83
});
}
orders.forEach(createToken);
// ---------- Game state and UI ----------
function stationOccupant(stationId) {
return orders.find(order => order.location === stationId);
}
function expectedStation(order) {
return order.complete ? null : order.steps[order.stepIndex];
}
function stateText(order) {
if (order.complete) return 'Collected — ticket complete';
if (busy && busy.orderId === order.id) return `Processing at ${STATIONS[busy.stationId].label}`;
if (order.location === 'ready') return `Ready · next: ${STATIONS[expectedStation(order)].label}`;
return `At ${STATIONS[order.location].label}`;
}
function renderOrders() {
orderList.innerHTML = orders.map(order => {
const selected = order.id === selectedOrderId;
const sequence = order.steps.map((step, index) => {
let className = 'sequence-pip';
if (order.complete || index < order.stepIndex) className += ' done';
else if (index === order.stepIndex) className += ' current';
return `<span class="${className}">${STATIONS[step].short} · ${STATIONS[step].label}</span>`;
}).join('<span class="sequence-arrow">›</span>');
const statusClass = order.complete || order.location === 'ready' ? 'ready' : '';
return `
<button class="ticket ${selected ? 'selected' : ''}" data-order="${order.id}" style="--ticket-color:${order.color}">
<div class="ticket-top">
<span class="ticket-id">${order.id}</span>
<div>
<div class="ticket-name">${order.name}</div>
<div class="ticket-request">${order.item} · ${order.request}</div>
</div>
</div>
<div class="ticket-state ${statusClass}">${stateText(order)}</div>
<div class="sequence">${sequence}</div>
</button>
`;
}).join('');
const inStudio = orders.filter(order => order.location !== 'ready' && !order.complete).length;
const collected = orders.filter(order => order.complete).length;
document.getElementById('atStudioStat').textContent = `${inStudio} / ${orders.length}`;
document.getElementById('collectedStat').textContent = `${collected} / ${orders.length}`;
}
function renderStations() {
stationList.innerHTML = Object.entries(STATIONS).map(([id, station]) => {
const occupant = stationOccupant(id);
const isBusy = busy && busy.stationId === id;
const occupancy = isBusy
? `Processing ${busy.orderId}`
: occupant
? `Occupied · ${occupant.id}`
: 'Open · one bay';
let buttonText = 'Route selected ticket';
let disabled = false;
if (isBusy) {
buttonText = 'Working…';
disabled = true;
} else if (occupant) {
buttonText = `Process ${occupant.id} · ${(station.duration / 1000).toFixed(1)}s`;
} else if (!selectedOrderId) {
buttonText = 'Select a ticket to route';
disabled = true;
}
return `
<div class="station-card ${isBusy ? 'busy' : ''}">
<div class="station-row">
<span class="station-number">${station.number}</span>
<div>
<div class="station-name">${station.label}</div>
<div class="station-occupancy ${occupant ? 'closed' : ''}">${occupancy}</div>
</div>
</div>
<button class="station-action" data-station-action="${id}" ${disabled ? 'disabled' : ''}>
${buttonText}
</button>
${isBusy ? `<div class="progress" data-progress="${id}"><div class="progress-fill"></div></div>` : ''}
</div>
`;
}).join('');
}
function renderActivity() {
activityEl.innerHTML = activity.slice(0, 4).map(entry => `<div class="activity-entry">${entry.text}</div>`).join('');
}
function updateHint() {
if (shiftWon) {
routeHint.innerHTML = '<strong>Shift complete.</strong> Every ticket was collected without mixing identities.';
return;
}
const selected = orderMap.get(selectedOrderId);
if (!selected) {
routeHint.innerHTML = '<strong>Select a ticket</strong> and click its next station. <kbd>1–5</kbd><kbd>M / S / C</kbd>';
} else if (selected.complete) {
routeHint.innerHTML = `<strong>${selected.id} is collected.</strong> Select another ticket to continue.`;
} else {
routeHint.innerHTML = `<strong>${selected.id} · ${selected.shortName}</strong> next stop: ${STATIONS[expectedStation(selected)].label}. <kbd>Enter</kbd> process current bay`;
}
}
function updateTokenTargets() {
const readyOrders = orders.filter(order => order.location === 'ready');
const completedOrders = orders.filter(order => order.complete);
orders.forEach(order => {
const token = tokenMap.get(order.id);
if (!token) return;
if (order.location === 'ready') {
const index = readyOrders.indexOf(order);
const x = (index - (readyOrders.length - 1) / 2) * 1.78;
token.target.set(x, 2.02, 3.05);
} else if (order.location !== 'complete') {
const station = STATIONS[order.location];
token.target.set(station.position.x, 1.52, station.position.z + 1.02);
} else {
const index = completedOrders.indexOf(order);
token.target.set(3.42 + index * 0.88, 1.55, -2.45);
}
});
}
function renderAll() {
renderOrders();
renderStations();
renderActivity();
updateHint();
updateTokenTargets();
}
function showToast(message, type = '') {
clearTimeout(toastTimer);
toastEl.textContent = message;
toastEl.className = `toast ${type} show`;
toastTimer = setTimeout(() => {
toastEl.className = 'toast';
}, 2800);
}
function selectOrder(orderId, quiet = false) {
if (!orderMap.has(orderId)) return;
selectedOrderId = orderId;
renderAll();
if (!quiet) {
const order = orderMap.get(orderId);
showToast(`${order.id} selected. Next stop: ${STATIONS[expectedStation(order)].label}.`);
}
}
function routeSelected(stationId) {
if (!selectedOrderId) {
showToast('Select an order ticket before choosing a station.', 'error');
return;
}
const order = orderMap.get(selectedOrderId);
if (order.complete) {
showToast(`${order.id} has already been collected.`, 'error');
return;
}
if (order.location !== 'ready') {
showToast(`${order.id} is already at ${STATIONS[order.location].label}. Process that bay first.`, 'error');
return;
}
const required = expectedStation(order);
if (stationId !== required) {
showToast(`${order.id} must go to ${STATIONS[required].label} next.`, 'error');
return;
}
const occupant = stationOccupant(stationId);
if (occupant) {
showToast(`${STATIONS[stationId].label} is occupied by ${occupant.id}. Process it before routing.`, 'error');
return;
}
if (busy && busy.stationId === stationId) {
showToast(`${STATIONS[stationId].label} is still working.`, 'error');
return;
}
order.location = stationId;
activity.unshift({
text: `<strong>${order.id}</strong> routed to ${STATIONS[stationId].label}. Tag retained.`
});
showToast(`${order.id} routed to ${STATIONS[stationId].label}.`, 'success');
renderAll();
}
function processStation(stationId) {
if (busy) {
showToast('A station is already processing. Wait for the current operation.', 'error');
return;
}
const occupant = stationOccupant(stationId);
if (!occupant) {
routeSelected(stationId);
return;
}
busy = {
stationId,
orderId: occupant.id,
startedAt: performance.now(),
duration: STATIONS[stationId].duration
};
activity.unshift({
text: `<strong>${occupant.id}</strong> began ${STATIONS[stationId].label.toLowerCase()} work.`
});
renderAll();
}
function finishProcessing(now) {
if (!busy) return;
const order = orderMap.get(busy.orderId);
const stationId = busy.stationId;
const station = STATIONS[stationId];
order.stepIndex += 1;
if (stationId === 'collection' && order.stepIndex >= order.steps.length) {
order.complete = true;
order.location = 'complete';
activity.unshift({
text: `<strong>${order.id}</strong> collected and archived. Identity verified.`
});
showToast(`${order.id} collected. The ticket is complete.`, 'success');
} else {
order.location = 'ready';
activity.unshift({
text: `<strong>${order.id}</strong> finished ${station.label.toLowerCase()}; ready for ${STATIONS[expectedStation(order)].label}.`
});
showToast(`${order.id} finished at ${station.label}. Route it to ${STATIONS[expectedStation(order)].label}.`, 'success');
}
busy = null;
renderAll();
if (orders.every(item => item.complete) && !shiftWon) {
shiftWon = true;
setTimeout(showWinModal, 550);
}
}
function resetShift() {
busy = null;
selectedOrderId = null;
shiftWon = false;
orders.forEach(order => {
order.location = 'ready';
order.stepIndex = 0;
order.complete = false;
});
orderMap.get('N-09').location = 'measurement';
orderMap.get('E-04').location = 'stitching';
activity = [{ text: '<strong>Shift reset.</strong> Niko is at Measurement; Elio is at Stitching.' }];
showToast('Shift reset. Follow every ticket’s printed sequence.', 'success');
renderAll();
}
orderList.addEventListener('click', event => {
const ticket = event.target.closest('[data-order]');
if (!ticket) return;
const id = ticket.dataset.order;
selectOrder(id, selectedOrderId === id);
});
stationList.addEventListener('click', event => {
const button = event.target.closest('[data-station-action]');
if (!button || button.disabled) return;
processStation(button.dataset.stationAction);
});
document.getElementById('resetBtn').addEventListener('click', resetShift);
// ---------- Modal ----------
function openModal({ eyebrow, title, body, actionText = 'Close', action = closeModal }) {
document.getElementById('modalEyebrow').textContent = eyebrow;
document.getElementById('modalTitle').textContent = title;
document.getElementById('modalBody').innerHTML = body;
const actionButton = document.getElementById('modalAction');
actionButton.textContent = actionText;
actionButton.onclick = action;
modalWrap.classList.remove('hidden');
}
function closeModal() {
modalWrap.classList.add('hidden');
}
document.getElementById('helpBtn').addEventListener('click', () => {
openModal({
eyebrow: 'Threadline guide',
title: 'How to run the shift',
body: `
<ol>
<li><strong>Select a ticket</strong> from the order panel or press 1–5.</li>
<li><strong>Route it</strong> to the next station shown on its ticket. You can click the station in the 3D atelier, use the station panel, or press M, S, or C.</li>
<li><strong>Process the occupied bay.</strong> Once work is finished, the same tagged garment becomes ready for its next required stop.</li>
<li><strong>Finish at Collection.</strong> Every station has only one bay, so no two garments may use it simultaneously.</li>
</ol>
<p>Drag the atelier to rotate the camera, use the mouse wheel to zoom, and right-drag to pan. Your objective is to collect all five fictional alteration requests without mixing up their identities.</p>
`,
actionText: 'Start routing'
});
});
function showWinModal() {
openModal({
eyebrow: 'Shift complete',
title: 'Every order found its way home.',
body: `
<p>All five alteration tickets were completed in the correct order. Each garment kept its original ID through measurement, stitching, and collection, and no station handled two garments at once.</p>
<p><strong>Completed:</strong> ${orders.map(order => order.id).join(' · ')}</p>
`,
actionText: 'Run another shift',
action: () => {
closeModal();
resetShift();
}
});
}
modalWrap.addEventListener('click', event => {
if (event.target === modalWrap) closeModal();
});
// ---------- Custom camera controls and station picking ----------
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const targetGoal = cameraTarget.clone();
const cameraState = {
yaw: 0.49,
pitch: 0.69,
yawGoal: 0.49,
pitchGoal: 0.69,
zoom: 1,
zoomGoal: 1
};
const pointer = {
down: false,
moved: false,
mode: 'orbit',
x: 0,
y: 0,
startX: 0,
startY: 0
};
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
let hoverStationId = null;
function updatePointerNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickStation(event) {
updatePointerNdc(event);
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(stationHitboxes, false);
return hits.length ? hits[0].object.userData.stationId : null;
}
renderer.domElement.addEventListener('pointerdown', event => {
pointer.down = true;
pointer.moved = false;
pointer.mode = event.button === 2 || event.shiftKey ? 'pan' : 'orbit';
pointer.x = pointer.startX = event.clientX;
pointer.y = pointer.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (pointer.down) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (Math.hypot(event.clientX - pointer.startX, event.clientY - pointer.startY) > 4) {
pointer.moved = true;
}
if (pointer.mode === 'orbit') {
cameraState.yawGoal -= dx * 0.006;
cameraState.pitchGoal = THREE.MathUtils.clamp(cameraState.pitchGoal - dy * 0.005, 0.36, 1.18);
} else {
const scale = 0.012 / cameraState.zoom;
targetGoal.x -= dx * scale * Math.cos(cameraState.yaw);
targetGoal.z += dx * scale * Math.sin(cameraState.yaw);
targetGoal.z -= dy * scale;
targetGoal.x = THREE.MathUtils.clamp(targetGoal.x, -4.5, 4.5);
targetGoal.z = THREE.MathUtils.clamp(targetGoal.z, -2.5, 3.5);
}
pointer.x = event.clientX;
pointer.y = event.clientY;
} else {
hoverStationId = pickStation(event);
renderer.domElement.style.cursor = hoverStationId ? 'pointer' : 'grab';
}
});
renderer.domElement.addEventListener('pointerup', event => {
pointer.down = false;
if (!pointer.moved) {
const stationId = pickStation(event);
if (stationId) {
const occupant = stationOccupant(stationId);
if (occupant && selectedOrderId !== occupant.id) {
selectOrder(occupant.id, true);
showToast(`${occupant.id} selected. Process ${STATIONS[stationId].label} or route another ticket.`);
} else {
routeSelected(stationId);
}
}
}
try { renderer.domElement.releasePointerCapture(event.pointerId); } catch (_) {}
});
renderer.domElement.addEventListener('pointercancel', () => {
pointer.down = false;
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
cameraState.zoomGoal = THREE.MathUtils.clamp(
cameraState.zoomGoal * Math.exp(-event.deltaY * 0.001),
0.72,
1.8
);
}, { passive: false });
renderer.domElement.addEventListener('contextmenu', event => event.preventDefault());
window.addEventListener('keydown', event => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
if (!modalWrap.classList.contains('hidden')) {
if (event.key === 'Escape') closeModal();
return;
}
const key = event.key.toLowerCase();
if (/^[1-5]$/.test(key)) {
const order = orders[Number(key) - 1];
selectOrder(order.id);
} else if (key === 'm') {
routeSelected('measurement');
} else if (key === 's') {
routeSelected('stitching');
} else if (key === 'c') {
routeSelected('collection');
} else if (event.key === 'Enter') {
const order = orderMap.get(selectedOrderId);
if (order && order.location !== 'ready' && !order.complete) {
processStation(order.location);
}
}
});
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(11.4, 18 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener('resize', resize);
resize();
// ---------- Animation ----------
const clock = new THREE.Clock();
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 10);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, cameraState.yawGoal, smoothing);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, cameraState.pitchGoal, smoothing);
cameraState.zoom = THREE.MathUtils.lerp(cameraState.zoom, cameraState.zoomGoal, smoothing);
cameraTarget.lerp(targetGoal, smoothing);
const radius = 18;
const horizontal = Math.sin(cameraState.pitch) * radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraState.yaw),
cameraTarget.y + radius * Math.cos(cameraState.pitch),
cameraTarget.z + horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function updateStations(now, time) {
Object.entries(STATIONS).forEach(([id, station]) => {
const object = stationObjects[id];
const occupant = stationOccupant(id);
const isBusy = busy && busy.stationId === id;
const selected = orderMap.get(selectedOrderId);
const isExpected = selected && !selected.complete && selected.location === 'ready' && expectedStation(selected) === id;
let color = station.color;
let opacity = 0.34;
if (occupant) {
color = orderMap.get(occupant.id).threeColor;
opacity = 0.72;
}
if (isExpected) {
color = 0xd96f55;
opacity = 0.72 + Math.sin(time * 4.5) * 0.16;
}
if (hoverStationId === id) {
color = 0xd96f55;
opacity = Math.max(opacity, 0.74);
}
if (isBusy) {
color = 0xd5a64b;
opacity = 0.75 + Math.sin(time * 8) * 0.2;
}
object.ring.material.color.setHex(color);
object.ring.material.opacity = opacity;
object.ring.scale.setScalar(isExpected ? 1.06 + Math.sin(time * 4) * 0.035 : 1);
});
const needle = stationObjects.stitching.needle;
if (busy && busy.stationId === 'stitching') {
needle.position.y = 1.42 + Math.sin(now * 0.035) * 0.12;
} else {
needle.position.y = THREE.MathUtils.lerp(needle.position.y, 1.42, 0.08);
}
}
function updateTokens(dt, time) {
orders.forEach(order => {
const token = tokenMap.get(order.id);
const positionSmoothing = 1 - Math.exp(-dt * 6.5);
token.group.position.lerp(token.target, positionSmoothing);
const selected = order.id === selectedOrderId;
const scale = selected ? 1.07 : 1;
const nextScale = THREE.MathUtils.lerp(token.group.scale.x, scale, 1 - Math.exp(-dt * 8));
token.group.scale.setScalar(nextScale);
token.selectionDisc.material.opacity = selected ? 0.65 : 0;
token.pivot.rotation.y = Math.sin(time * 0.8 + token.phase) * (order.location === 'ready' ? 0.14 : 0.055);
token.pivot.position.y = order.location === 'ready' ? Math.sin(time * 1.25 + token.phase) * 0.045 : 0;
});
}
function updateProgress(now) {
if (!busy) return;
const elapsed = now - busy.startedAt;
const percent = Math.min(100, elapsed / busy.duration * 100);
const fill = document.querySelector(`[data-progress="${busy.stationId}"] .progress-fill`);
if (fill) fill.style.width = `${percent}%`;
const button = stationList.querySelector(`[data-station-action="${busy.stationId}"]`);
if (button) button.textContent = `Processing ${busy.orderId} · ${Math.round(percent)}%`;
}
let firstFrame = true;
renderer.setAnimationLoop(now => {
const dt = Math.min(clock.getDelta(), 0.05);
const time = now * 0.001;
updateCamera(dt);
updateStations(now, time);
updateTokens(dt, time);
updateProgress(now);
if (busy && now - busy.startedAt >= busy.duration) {
finishProcessing(now);
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById('loading').remove();
}
});
renderAll();
</script>
</body>
</html>
```