Prompt specification
Build or customize the Three.js 3D scene "Reversible fastening comparison exhibit" 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: Reversible fastening comparison exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reversible-fastening-comparison-exhibit-x0248
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts locking cable ties. Build a maintenance table comparing releasable straps, clips, and one-way ties; users assemble and undo bundles while the exhibit distinguishes reusable actions from destructive removal. Low-poly.
Working Three.js Starter (reversible-fastening-comparison-exhibit-x0248):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Locking Cable Ties — Maintenance Bench</title>
<style>
:root{
--bg:#0b0e13; --panel:#11161e; --line:#222c3a; --ink:#dfe7f1; --dim:#8fa0b6;
--reusable:#2fd6bd; --clip:#ffb020; --tie:#ff4f79;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
font-family:"Segoe UI",system-ui,-apple-system,Roboto,Helvetica,Arial,sans-serif}
#app{display:flex;height:100vh;overflow:hidden}
#stage{flex:1;position:relative;min-width:0}
canvas{display:block;width:100%;height:100%;cursor:grab}
canvas:active{cursor:grabbing}
#hud{position:absolute;inset:0;pointer-events:none;padding:18px 20px;
display:flex;flex-direction:column;justify-content:space-between}
.hudTop{max-width:520px}
h1{margin:0;font-size:19px;letter-spacing:.14em;text-transform:uppercase;font-weight:700}
.sub{margin-top:6px;font-size:12.5px;color:var(--dim);line-height:1.5;max-width:460px}
.legend{display:flex;gap:16px;flex-wrap:wrap;font-size:11.5px;color:var(--dim)}
.legend b{color:var(--ink);font-weight:600}
.lg{display:flex;align-items:center;gap:7px}
.sw{width:11px;height:11px;border-radius:3px;display:inline-block}
#hint{font-size:11px;color:#66788e;letter-spacing:.04em}
#panel{width:462px;flex:none;background:var(--panel);border-left:1px solid var(--line);
padding:16px 16px 22px;overflow-y:auto;display:flex;flex-direction:column;gap:14px}
#panel h2{margin:0;font-size:12px;letter-spacing:.2em;text-transform:uppercase;color:var(--dim)}
.ptitle{font-size:15px;font-weight:600;margin:0}
.pdesc{font-size:11.5px;color:var(--dim);margin:4px 0 0;line-height:1.55}
table{width:100%;border-collapse:collapse;font-size:11.5px}
th{text-align:left;font-size:9.5px;letter-spacing:.13em;color:#6d7f95;font-weight:600;
padding:0 6px 7px;border-bottom:1px solid var(--line)}
td{padding:9px 6px;border-bottom:1px solid #1a222d;vertical-align:top}
tr.sel td{background:#151d28}
tr.sel td:first-child{box-shadow:inset 3px 0 0 var(--reusable)}
.fname{font-weight:600;font-size:12.5px;display:flex;align-items:center;gap:7px}
.dot{width:9px;height:9px;border-radius:50%;flex:none}
.fsub{color:#718399;font-size:10.5px;margin-top:3px;max-width:120px;line-height:1.35}
.tag{display:inline-block;font-size:9px;letter-spacing:.1em;padding:3px 6px;border-radius:4px;font-weight:700}
.tag.reuse{color:#0b2b26;background:var(--reusable)}
.tag.single{color:#2a0a12;background:var(--tie)}
.btn{font:inherit;font-size:10.5px;font-weight:600;letter-spacing:.03em;color:var(--ink);
background:#1b2431;border:1px solid #2c3949;border-radius:5px;padding:5px 9px;cursor:pointer;
transition:.15s;white-space:nowrap}
.btn:hover:not(:disabled){background:#25313f;border-color:#3d4d63}
.btn:disabled{opacity:.32;cursor:not-allowed}
.btn.go{border-color:#2c6d64;color:#8ef0e0}
.btn.go:hover:not(:disabled){background:#14312d}
.btn.un{border-color:#6d4a22;color:#ffce7a}
.btn.un:hover:not(:disabled){background:#33240f}
.btn.un.d{border-color:#6d2b3c;color:#ff9db0}
.btn.un.d:hover:not(:disabled){background:#33131c}
.stack{display:flex;flex-direction:column;gap:5px;align-items:flex-start}
.m{font-weight:600;font-size:11px}
.r{color:#718399;font-size:10.5px;line-height:1.4;margin-top:3px;max-width:118px}
.stats{display:grid;grid-template-columns:repeat(2,1fr);gap:8px}
.card{background:#151c25;border:1px solid #1f2833;border-radius:7px;padding:9px 11px}
.card .v{font-size:19px;font-weight:700;font-variant-numeric:tabular-nums;line-height:1.1}
.card .l{font-size:9.5px;letter-spacing:.11em;color:#6d7f95;margin-top:4px;text-transform:uppercase}
.rowbtns{display:flex;gap:7px;flex-wrap:wrap}
.note{font-size:10.5px;color:#63758b;line-height:1.5;border-top:1px solid var(--line);padding-top:10px}
.note b{color:#9fb0c4}
@media (max-width:980px){
#app{flex-direction:column}
#panel{width:auto;border-left:none;border-top:1px solid var(--line);max-height:52vh}
}
</style>
</head>
<body>
<div id="app">
<div id="stage">
<canvas id="view"></canvas>
<div id="hud">
<div class="hudTop">
<h1>Locking Cable Ties</h1>
<div class="sub">Maintenance bench exhibit — assemble a bundle, then undo it.
Reusable fasteners open and return to the tray; one-way ties must be cut and are destroyed.</div>
<div class="legend" style="margin-top:12px">
<span class="lg"><i class="sw" style="background:var(--reusable)"></i><b>Reusable</b> — reversible</span>
<span class="lg"><i class="sw" style="background:var(--clip)"></i><b>Reusable</b> — reversible</span>
<span class="lg"><i class="sw" style="background:var(--tie)"></i><b>Single-use</b> — destructive</span>
</div>
</div>
<div id="hint">drag to orbit · scroll to zoom · click a bundle to select</div>
</div>
</div>
<aside id="panel">
<div>
<h2>Maintenance table</h2>
<p class="ptitle">Fastener selection & removal</p>
<p class="pdesc">Select a row, then <b>Assemble</b> a bundle or <b>Undo</b> it.
The undo method is dictated by the fastener class — reusable actions preserve the fastener,
destructive removal consumes it.</p>
</div>
<table>
<thead>
<tr>
<th style="width:25%">Fastener</th>
<th style="width:17%">Class</th>
<th style="width:30%">Actions</th>
<th style="width:28%">Removal method / result</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
<div>
<h2 style="margin-bottom:8px">Bench log</h2>
<div class="stats">
<div class="card"><div class="v" id="s-formed">0</div><div class="l">Bundles formed</div></div>
<div class="card"><div class="v" id="s-reuse" style="color:var(--reusable)">0</div><div class="l">Reusable releases</div></div>
<div class="card"><div class="v" id="s-cuts" style="color:var(--tie)">0</div><div class="l">Destructive removals</div></div>
<div class="card"><div class="v" id="s-scrap">0</div><div class="l">Fasteners scrapped</div></div>
</div>
</div>
<div class="rowbtns">
<button class="btn" id="btn-assemble-all">+ Assemble all</button>
<button class="btn" id="btn-undo-all">↩ Undo all</button>
<button class="btn" id="btn-reset">⟲ Reset bench</button>
</div>
<div class="note">
<b>Read the exhibit:</b> the strap and the clip are <b>reusable</b> — undoing a bundle releases the
fastener and it flies back to its tray, ready for the next bundle. The one-way tie is
<b>single-use</b> — undoing requires snipping the tail, after which the fastener is scrap and a fresh
tie must be drawn from the supply roll. Keys: <b>1/2/3</b> select a row, <b>A</b> assemble, <b>U</b> undo.
</div>
</aside>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================ constants ============================ */
const C = {
strap:0x2fd6bd, strapDark:0x177f70,
clip:0xffb020, clipDark:0x8a5c00,
tie:0xff4f79, tieDark:0x8c2340,
cableA:0x39424f, cableB:0x59646f, cableC:0x7d6a52,
bench:0x2b3440, benchTop:0x354050, tray:0x1a222e, grid:0x44546a
};
const hex = n => '#' + n.toString(16).padStart(6,'0');
const DEFS = [
{ key:'strap', name:'Releasable strap', sub:'Re-locking nylon strap',
color:C.strap, css:hex(C.strap), reuse:true, undoLabel:'Release',
method:'Release lever', result:'Strap opens, returns to the tray. No consumable.' },
{ key:'clip', name:'Cable clip', sub:'Reusable C-clip',
color:C.clip, css:hex(C.clip), reuse:true, undoLabel:'Unclip',
method:'Unclip & lift', result:'Clip opens, returns to the tray. No consumable.' },
{ key:'tie', name:'One-way tie', sub:'Single-use lock',
color:C.tie, css:hex(C.tie), reuse:false, undoLabel:'Cut',
method:'Cut the tail', result:'Tie is destroyed — scrap discarded, new tie needed.' }
];
/* ============================ renderer ============================ */
const canvas = document.getElementById('view');
const renderer = new THREE.WebGLRenderer({ canvas, antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d1117);
scene.fog = new THREE.Fog(0x0d1117, 16, 34);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 120);
/* lights */
scene.add(new THREE.HemisphereLight(0x9fb6d4, 0x1b2029, 0.62));
const key = new THREE.DirectionalLight(0xffffff, 1.15);
key.position.set(4.5, 7.5, 5.5); key.castShadow = true;
key.shadow.mapSize.set(1024,1024);
key.shadow.camera.left=-7; key.shadow.camera.right=7;
key.shadow.camera.top=6; key.shadow.camera.bottom=-6;
key.shadow.bias = -0.0012;
scene.add(key);
const fill = new THREE.DirectionalLight(0x86a6cc, 0.42); fill.position.set(-5,3.5,-4.5); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffc58a, 0.28); rim.position.set(0,2,-7); scene.add(rim);
/* ============================ materials ============================ */
function mat(color, extra={}){
return new THREE.MeshStandardMaterial({ color, roughness:.85, metalness:.05, flatShading:true, ...extra });
}
/* ============================ tween engine ============================ */
const tweens = [];
function tw(dur, delay, ease, fn, onDone){
tweens.push({ t:-(delay||0), dur, ease:ease||((k)=>k), fn, onDone });
}
function stepTweens(dt){
for(let i=tweens.length-1; i>=0; i--){
const t = tweens[i]; t.t += dt;
if(t.t < 0) continue;
const k = Math.min(1, t.t / t.dur);
t.fn(t.ease(k), k);
if(k >= 1){ tweens.splice(i,1); if(t.onDone) t.onDone(); }
}
}
const easeOutCubic = k => 1 - Math.pow(1-k, 3);
const easeInQuad = k => k*k;
const easeInOutCubic = k => k<0.5 ? 4*k*k*k : 1 - Math.pow(-2*k+2,3)/2;
const easeOutBack = k => { const c1=1.70158,c3=c1+1; return 1 + c3*Math.pow(k-1,3) + c1*Math.pow(k-1,2); };
/* ============================ workbench ============================ */
const bench = new THREE.Group(); scene.add(bench);
{
const top = new THREE.Mesh(new THREE.BoxGeometry(11.4, 0.08, 5.6), mat(C.benchTop));
top.position.y = -0.04; top.receiveShadow = true; bench.add(top);
const apron = new THREE.Mesh(new THREE.BoxGeometry(11.1, 0.22, 5.3), mat(C.bench));
apron.position.y = -0.19; apron.receiveShadow = true; bench.add(apron);
const legGeo = new THREE.BoxGeometry(0.22, 1.5, 0.22);
[[-5.2,-2.2],[5.2,-2.2],[-5.2,2.2],[5.2,2.2]].forEach(p=>{
const l = new THREE.Mesh(legGeo, mat(0x1d242e)); l.position.set(p[0],-1.1,p[1]); l.castShadow=true; bench.add(l);
});
// faint table grid
const pts = [];
for(let x=-5.4; x<=5.4; x+=0.6) pts.push(x,0.002,-2.7, x,0.002,2.7);
for(let z=-2.7; z<=2.7; z+=0.6) pts.push(-5.4,0.002,z, 5.4,0.002,z);
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pts,3));
bench.add(new THREE.LineSegments(g, new THREE.LineBasicMaterial({ color:C.grid, transparent:true, opacity:.20 })));
}
/* ============================ sprite helpers ============================ */
function roundRect(ctx,x,y,w,h,r){
ctx.beginPath();
ctx.moveTo(x+r,y); ctx.lineTo(x+w-r,y); ctx.quadraticCurveTo(x+w,y,x+w,y+r);
ctx.lineTo(x+w,y+h-r); ctx.quadraticCurveTo(x+w,y+h,x+w-r,y+h);
ctx.lineTo(x+r,y+h); ctx.quadraticCurveTo(x,y+h,x,y+h-r);
ctx.lineTo(x,y+r); ctx.quadraticCurveTo(x,y,x+r,y); ctx.closePath();
}
function drawIcon(ctx, kind, x, y, r, color){
ctx.save(); ctx.strokeStyle = color; ctx.fillStyle = color; ctx.lineWidth = 5; ctx.lineCap='round';
if(kind === 'reuse'){
ctx.beginPath(); ctx.arc(x,y,r, Math.PI*0.35, Math.PI*1.85); ctx.stroke();
const a = Math.PI*0.35;
const hx = x + Math.cos(a)*r, hy = y + Math.sin(a)*r;
ctx.beginPath();
ctx.moveTo(hx + Math.cos(a+2.6)*9, hy + Math.sin(a+2.6)*9);
ctx.lineTo(hx, hy);
ctx.lineTo(hx + Math.cos(a-2.6)*9, hy + Math.sin(a-2.6)*9);
ctx.closePath(); ctx.fill();
} else {
ctx.beginPath();
ctx.moveTo(x-r*0.55, y-r*0.75); ctx.lineTo(x+r*0.55, y+r*0.75);
ctx.moveTo(x+r*0.55, y-r*0.75); ctx.lineTo(x-r*0.55, y+r*0.75);
ctx.stroke();
}
ctx.restore();
}
function makeSprite(lines, colorHex, opts={}){
const W = opts.W || 640, H = opts.H || 200;
const c = document.createElement('canvas'); c.width=W; c.height=H;
const ctx = c.getContext('2d');
ctx.clearRect(0,0,W,H);
if(!opts.noBg){
ctx.fillStyle = 'rgba(9,13,19,0.86)';
roundRect(ctx,4,10,W-8,H-20,16); ctx.fill();
ctx.strokeStyle = colorHex; ctx.lineWidth=3.5; ctx.globalAlpha=.75;
roundRect(ctx,4,10,W-8,H-20,16); ctx.stroke(); ctx.globalAlpha=1;
}
if(opts.icon) drawIcon(ctx, opts.icon, 62, H/2, 26, colorHex);
const off = opts.icon ? 120 : 0;
let y = H/2 - (lines.length-1)*(opts.lineGap||30)/2 + 6;
ctx.textAlign='center'; ctx.textBaseline='middle';
lines.forEach(l=>{
ctx.fillStyle = l.color || '#dfe7f1';
ctx.font = `${l.weight||600} ${l.size}px "Segoe UI", system-ui, sans-serif`;
ctx.fillText(l.text, off + (W-off)/2, y);
y += (opts.lineGap||30);
});
const tex = new THREE.CanvasTexture(c); tex.colorSpace = THREE.SRGBColorSpace;
const spr = new THREE.Sprite(new THREE.SpriteMaterial({ map:tex, transparent:true, depthTest:opts.depthTest!==false }));
spr.scale.set(opts.scaleW||1.9, (opts.scaleW||1.9)*H/W, 1);
return spr;
}
/* ============================ cable geometry ============================ */
const cableGeo = new THREE.TubeGeometry(
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.62, 0, -0.02), new THREE.Vector3(-0.25, 0.014, 0.03),
new THREE.Vector3(0.12, -0.010, -0.028), new THREE.Vector3(0.62, 0, 0.016)
]), 20, 0.026, 5, false);
/* ============================ fastener builders ============================ */
function makeStrap(){
const g = new THREE.Group();
const m = mat(C.strap), m2 = mat(C.strapDark);
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.1, 0.02, 4, 18), m);
ring.rotation.y = Math.PI/2; ring.scale.set(1.6, 0.55, 1); ring.castShadow = true; g.add(ring);
const head = new THREE.Group(); head.position.set(0,0,-0.155); g.add(head);
const body = new THREE.Mesh(new THREE.BoxGeometry(0.075,0.06,0.055), m); body.castShadow=true; head.add(body);
const slot = new THREE.Mesh(new THREE.BoxGeometry(0.034,0.02,0.062), mat(0x0d2b27)); slot.position.set(0,0.012,0); head.add(slot);
const lever = new THREE.Mesh(new THREE.BoxGeometry(0.02,0.09,0.05), m2);
lever.position.set(0,-0.015,-0.048); lever.rotation.x = -0.15; head.add(lever);
const tail = new THREE.Mesh(new THREE.BoxGeometry(0.035,0.012,0.22), m2);
tail.position.set(0,0.028,-0.11); tail.rotation.x = 0.12; head.add(tail);
g.userData = { head, lever, tail, ring, kind:'strap' };
return g;
}
function makeClip(){
const g = new THREE.Group();
const m = mat(C.clip), m2 = mat(C.clipDark);
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.1, 0.028, 4, 14, Math.PI*1.72), m);
ring.rotation.y = Math.PI/2; ring.scale.set(1.6, 0.55, 1); ring.castShadow = true; g.add(ring);
const tabA = new THREE.Mesh(new THREE.BoxGeometry(0.05,0.035,0.07), m); tabA.position.set(0,0,-0.145); g.add(tabA);
const tabB = new THREE.Mesh(new THREE.BoxGeometry(0.05,0.035,0.07), m2); tabB.position.set(0,-0.03,-0.11); g.add(tabB);
g.userData = { tabA, tabB, ring, kind:'clip' };
return g;
}
function makeTie(){
const g = new THREE.Group();
const m = mat(C.tie), m2 = mat(C.tieDark);
const geoA = new THREE.TorusGeometry(0.1, 0.016, 4, 14, Math.PI);
const arcA = new THREE.Mesh(geoA, m); arcA.rotation.y = Math.PI/2; arcA.scale.set(1.6,0.55,1); arcA.castShadow=true; g.add(arcA);
const geoB = new THREE.TorusGeometry(0.1, 0.016, 4, 14, Math.PI); geoB.rotateZ(Math.PI);
const arcB = new THREE.Mesh(geoB, m); arcB.rotation.y = Math.PI/2; arcB.scale.set(1.6,0.55,1); arcB.castShadow=true; g.add(arcB);
const head = new THREE.Mesh(new THREE.BoxGeometry(0.062,0.078,0.05), m); head.position.set(0,0,-0.155); head.castShadow=true; g.add(head);
const pawl = new THREE.Mesh(new THREE.BoxGeometry(0.032,0.05,0.042), m2); pawl.position.set(0,0.012,-0.184); g.add(pawl);
const tail = new THREE.Mesh(new THREE.BoxGeometry(0.03,0.011,0.26), m2);
tail.position.set(0,0.042,-0.28); tail.castShadow=true; g.add(tail);
g.userData = { head, pawl, tail, arcA, arcB, kind:'tie' };
return g;
}
/* ============================ scissors ============================ */
const scissors = new THREE.Group();
{
const bladeM = mat(0xc3cedb), handleM = mat(0xe0566a);
const armA = new THREE.Group(), armB = new THREE.Group();
const bA = new THREE.Mesh(new THREE.BoxGeometry(0.013,0.24,0.032), bladeM); bA.position.set(0.012,-0.12,0); bA.rotation.z=-0.1;
const bB = new THREE.Mesh(new THREE.BoxGeometry(0.013,0.24,0.032), bladeM); bB.position.set(-0.012,-0.12,0); bB.rotation.z=0.1;
const hA = new THREE.Mesh(new THREE.TorusGeometry(0.05,0.013,4,9), handleM); hA.position.set(0.05,0.035,0); hA.rotation.y=Math.PI/2;
const hB = new THREE.Mesh(new THREE.TorusGeometry(0.05,0.013,4,9), handleM); hB.position.set(-0.05,0.035,0); hB.rotation.y=Math.PI/2;
armA.add(bA,hA); armB.add(bB,hB);
const pivot = new THREE.Mesh(new THREE.CylinderGeometry(0.02,0.02,0.034,6), bladeM); pivot.rotation.z=Math.PI/2; scissors.add(pivot);
scissors.add(armA, armB);
scissors.userData = { armA, armB };
scissors.visible = false; scene.add(scissors);
}
/* ============================ stations ============================ */
const stations = [];
const pickables = [];
const ephemeral = [];
let selected = 0;
function tagPick(obj, st){ obj.traverse(o => { if(o.isMesh){ o.userData.stIndex = st.index; pickables.push(o); } }); }
function buildStation(def, sx, index){
const g = new THREE.Group(); g.position.set(sx,0,0); scene.add(g);
const decal = new THREE.Mesh(new THREE.RingGeometry(0.66,0.8,28,1),
new THREE.MeshBasicMaterial({ color:def.color, transparent:true, opacity:.15, side:THREE.DoubleSide, depthWrite:false }));
decal.rotation.x = -Math.PI/2; decal.position.y = 0.007; g.add(decal);
// parts tray (behind the station)
const tray = new THREE.Group(); tray.position.set(0,0,1.95); g.add(tray);
const base = new THREE.Mesh(new THREE.BoxGeometry(1.05,0.05,0.66), mat(C.tray));
base.position.y = 0.025; base.receiveShadow = true; tray.add(base);
const rimM = mat(def.color, { roughness:.55 });
[[0,0.33,0],[0,-0.33,0]].forEach(([x,z])=>{
const r = new THREE.Mesh(new THREE.BoxGeometry(1.09,0.035,0.045), rimM); r.position.set(x,0.055,z); tray.add(r);
});
[[0.53,0],[ -0.53,0]].forEach(([x,z])=>{
const r = new THREE.Mesh(new THREE.BoxGeometry(0.045,0.035,0.7), rimM); r.position.set(x,0.055,z); tray.add(r);
});
const st = { def, g, sx, index, tray, decal, state:'loose', token:0, cables:[], fastener:null, tie:null };
// cable set
const cableCols = [C.cableA, C.cableB, C.cableC];
const tight = [{z:-0.075,r:0},{z:0,r:0},{z:0.075,r:0}];
const loose = [{x:-0.13,z:-0.47,r:0.26},{x:0.05,z:0.03,r:-0.12},{x:0.15,z:0.47,r:-0.24}];
for(let i=0;i<3;i++){
const holder = new THREE.Group();
holder.position.set(loose[i].x, 0.05, loose[i].z);
holder.rotation.y = loose[i].r;
const mesh = new THREE.Mesh(cableGeo, mat(cableCols[i], { roughness:.7 }));
mesh.castShadow = true; holder.add(mesh);
g.add(holder);
st.cables.push({ holder, tight:tight[i], loose:loose[i] });
}
// fastener parked in the tray
if(def.key === 'strap'){ st.fastener = makeStrap(); st.fastener.position.set(0,0.075,1.95); st.fastener.scale.setScalar(0.8); }
if(def.key === 'clip'){ st.fastener = makeClip(); st.fastener.position.set(0,0.075,1.95); st.fastener.scale.setScalar(0.8); }
if(def.key === 'tie'){
// supply roll of fresh ties
const roll = new THREE.Group(); roll.position.set(0,0.06,1.95);
for(let i=0;i<3;i++){
const coil = new THREE.Mesh(new THREE.TorusGeometry(0.115,0.032,4,12), mat(C.tie));
coil.rotation.x = Math.PI/2; coil.position.y = i*0.055; coil.castShadow=true; roll.add(coil);
}
g.add(roll);
}
if(st.fastener) g.add(st.fastener);
tagPick(g, st);
// station label
const label = makeSprite([
{ text:def.name.toUpperCase(), size:44, color:def.css },
{ text:def.reuse ? 'REUSABLE · reversible removal' : 'SINGLE-USE · destructive removal', size:25, color:'#8fa0b6' }
], def.css, { W:640, H:200, scaleW:2.15 });
label.position.set(0,1.25,0); g.add(label);
stations.push(st);
return st;
}
buildStation(DEFS[0], -2.75, 0);
buildStation(DEFS[1], 0.00, 1);
buildStation(DEFS[2], 2.75, 2);
/* selection ring */
const selRing = new THREE.Mesh(new THREE.RingGeometry(0.84,0.95,32),
new THREE.MeshBasicMaterial({ color:0xffffff, transparent:true, opacity:.5, side:THREE.DoubleSide, depthWrite:false }));
selRing.rotation.x = -Math.PI/2; selRing.position.set(stations[0].sx, 0.012, 0); scene.add(selRing);
/* ============================ badges & flashes ============================ */
function showBadge(st, kind, colorHex, text){
const spr = makeSprite([{ text, size:46, color:colorHex }],
colorHex, { W:640, H:120, scaleW:1.75, icon:kind, depthTest:false });
spr.position.set(0,0.78,0); st.g.add(spr); ephemeral.push(spr);
tw(1.35, 0, easeOutCubic, k => {
spr.position.y = 0.78 + k*0.42;
spr.material.opacity = k < 0.65 ? 1 : 1 - (k-0.65)/0.35;
const s = 1 + 0.10*Math.sin(Math.min(1,k)*Math.PI);
spr.scale.set(1.75*s, 1.75*(120/640)*s, 1);
}, () => { st.g.remove(spr); spr.material.map.dispose(); spr.material.dispose(); });
}
function flashCut(st){
const f = new THREE.Mesh(new THREE.SphereGeometry(0.06,6,4),
new THREE.MeshBasicMaterial({ color:0xff5c7a, transparent:true, opacity:.95 }));
f.position.set(0,0.055,-0.30); st.g.add(f); ephemeral.push(f);
tw(0.5, 0, easeOutCubic, k => { f.scale.setScalar(1 + k*3.2); f.material.opacity = 0.95*(1-k); },
() => { st.g.remove(f); f.material.dispose(); });
}
function fallAndVanish(obj, dur, delay, drift){
const start = obj.position.clone(), rot0 = obj.rotation.clone();
const mats = [];
obj.traverse(o => { if(o.material){ mats.push(o.material); o.material.transparent = true; } });
tw(dur, delay||0, easeInQuad, k => {
obj.position.set(start.x + drift.x*k, start.y - 0.5*k*k, start.z + drift.z*k);
obj.rotation.set(rot0.x + 1.4*k, rot0.y, rot0.z + drift.z*1.6*k);
mats.forEach(m => m.opacity = 1-k);
}, () => { if(obj.parent) obj.parent.remove(obj); mats.forEach(m => m.dispose()); });
}
/* ============================ operations ============================ */
let bundlesFormed = 0, reusableReleases = 0, destructiveRemovals = 0, scrapped = 0;
function gatherCables(st, delay){
st.cables.forEach((c,i) => {
const from = c.holder.position.clone(), fr = c.holder.rotation.y;
const to = new THREE.Vector3(0, 0.05, c.tight.z);
tw(0.55, (delay||0) + i*0.05, easeInOutCubic, k => {
c.holder.position.lerpVectors(from, to, k);
c.holder.rotation.y = fr + (0 - fr)*k;
});
});
}
function spreadCables(st, delay){
st.cables.forEach((c,i) => {
const from = c.holder.position.clone(), fr = c.holder.rotation.y;
const to = new THREE.Vector3(c.loose.x, 0.05, c.loose.z);
tw(0.6, (delay||0) + i*0.05, easeInOutCubic, k => {
c.holder.position.lerpVectors(from, to, k);
c.holder.rotation.y = fr + (c.loose.r - fr)*k;
});
});
}
function assembleStation(st){
if(st.state !== 'loose') return;
st.token++; const token = st.token;
st.state = 'assembling';
gatherCables(st, 0);
const f = st.def.key === 'tie' ? makeTie() : st.fastener;
if(st.def.key === 'tie'){
if(st.tie && st.tie.parent) st.g.remove(st.tie);
st.tie = f; f.position.set(0,0.10,1.95); f.scale.setScalar(0.85); st.g.add(f);
}
const src = f.position.clone();
const dst = new THREE.Vector3(0,0.055,0);
tw(0.62, 0.22, easeInOutCubic, k => {
f.position.lerpVectors(src, dst, k);
f.rotation.y = (1-k)*0.7;
f.scale.setScalar(0.85 + 0.15*k);
}, () => {
if(st.token !== token) return;
closeFastener(st, f, token);
});
}
function closeFastener(st, f, token){
const u = f.userData;
tw(0.3, 0, easeOutCubic, k => {
if(u.kind === 'strap'){
u.lever.rotation.x = -0.95 + (0.80)*k;
u.tail.position.z = -0.11 + (0.08)*k;
} else if(u.kind === 'clip'){
u.tabB.position.z = -0.11 - 0.03*k;
u.tabB.rotation.y = -1.25 + 1.25*k;
} else {
u.tail.position.z = -0.35 + (0.13)*k;
u.pawl.rotation.x = -0.5 + 0.5*k;
}
}, () => {
if(st.token !== token) return;
st.state = 'bound';
bundlesFormed++;
updatePanel();
});
}
function releaseStation(st){ /* reusable */
if(st.state !== 'bound' || !st.def.reuse) return;
st.token++; const token = st.token;
st.state = 'releasing';
const f = st.fastener, u = f.userData;
tw(0.35, 0, easeOutCubic, k => {
if(u.kind === 'strap'){
u.lever.rotation.x = -0.15 + (-0.85+0.15)*k;
u.tail.position.z = -0.03 + (-0.09+0.03)*k;
} else {
u.tabB.position.z = -0.14 - 0.05*k;
u.tabB.rotation.y = -1.25*k;
}
});
const from = f.position.clone(), to = new THREE.Vector3(0,0.075,1.95);
tw(0.8, 0.28, easeInOutCubic, k => {
f.position.lerpVectors(from, to, k);
f.rotation.y = (1-k)*0.7;
f.scale.setScalar(1 - 0.2*k);
}, () => {
if(st.token !== token) return;
f.position.copy(to); f.scale.setScalar(0.8);
st.state = 'loose';
reusableReleases++;
updatePanel();
});
spreadCables(st, 0.3);
showBadge(st, 'reuse', st.def.css, 'REUSABLE · RELEASED');
}
function cutStation(st){ /* destructive */
if(st.state !== 'bound') return;
st.token++; const token = st.token;
st.state = 'cutting';
const f = st.tie;
const sc = scissors, arms = sc.userData;
const start = new THREE.Vector3(st.sx + 0.85, 1.05, -0.85);
const mid = new THREE.Vector3(st.sx, 0.52, -0.30);
const end = new THREE.Vector3(st.sx, 0.075, -0.30);
sc.position.copy(start);
sc.rotation.set(0,0,0);
arms.armA.rotation.z = 0.30; arms.armB.rotation.z = -0.30;
tw(0.45, 0, easeInOutCubic, k => { sc.position.lerpVectors(start, mid, k); });
tw(0.38, 0.45, easeInOutCubic, k => { sc.position.lerpVectors(mid, end, k); });
tw(0.16, 0.83, easeOutCubic, k => {
arms.armA.rotation.z = 0.30 - 0.28*k;
arms.armB.rotation.z = -0.30 + 0.28*k;
}, () => {
if(st.token !== token) return;
flashCut(st);
showBadge(st, 'cut', hex(C.tie), 'DESTRUCTIVE · CUT');
// severed tail scrap
const stub = new THREE.Mesh(new THREE.BoxGeometry(0.03,0.011,0.13), mat(C.tieDark));
stub.position.set(0, 0.055, -0.365); st.g.add(stub); ephemeral.push(stub);
fallAndVanish(stub, 0.75, 0.1, { x:0.25, z:0.15 });
// the tie itself becomes scrap and falls away
fallAndVanish(f, 0.9, 0.22, { x:-0.18, z:0.08 });
st.tie = null;
spreadCables(st, 0.35);
destructiveRemovals++; scrapped++;
tw(0.55, 0.95, easeInOutCubic, k => {
sc.position.set(end.x + k*0.85, end.y + k*0.85, end.z - k*0.45);
}, () => { sc.visible = false; });
tw(0.3, 0.9, null, () => {}, () => {
if(st.token !== token) return;
st.state = 'loose';
updatePanel();
});
});
}
function undoStation(st){
if(st.state !== 'bound') return;
st.def.reuse ? releaseStation(st) : cutStation(st);
}
/* ============================ panel ============================ */
const tbody = document.getElementById('tbody');
DEFS.forEach((def, i) => {
const tr = document.createElement('tr');
tr.dataset.i = i;
tr.innerHTML = `
<td>
<div class="fname"><i class="dot" style="background:${def.css}"></i>${def.name}</div>
<div class="fsub">${def.sub}</div>
</td>
<td><span class="tag ${def.reuse?'reuse':'single'}">${def.reuse?'REUSABLE':'SINGLE-USE'}</span></td>
<td>
<div class="stack">
<button class="btn go" data-act="assemble">+ Assemble</button>
<button class="btn un ${def.reuse?'':'d'}" data-act="undo">${def.reuse?'↩ ':'✂ '}${def.undoLabel}</button>
</div>
</td>
<td><div class="m">${def.method}</div><div class="r">${def.result}</div></td>`;
tbody.appendChild(tr);
tr.addEventListener('click', e => {
if(e.target.tagName === 'BUTTON') return;
select(i);
});
tr.querySelector('[data-act="assemble"]').addEventListener('click', () => { select(i); assembleStation(stations[i]); });
tr.querySelector('[data-act="undo"]').addEventListener('click', () => { select(i); undoStation(stations[i]); });
});
function select(i){
selected = i;
selRing.position.set(stations[i].sx, 0.012, 0);
[...tbody.children].forEach((r,k) => r.classList.toggle('sel', k === i));
}
function updatePanel(){
document.getElementById('s-formed').textContent = bundlesFormed;
document.getElementById('s-reuse').textContent = reusableReleases;
document.getElementById('s-cuts').textContent = destructiveRemovals;
document.getElementById('s-scrap').textContent = scrapped;
[...tbody.children].forEach((tr, i) => {
const st = stations[i];
const a = tr.querySelector('[data-act="assemble"]');
const u = tr.querySelector('[data-act="undo"]');
a.disabled = st.state !== 'loose';
u.disabled = st.state !== 'bound';
const state = { loose:'loose', assembling:'assembling', bound:'bundled', releasing:'releasing', cutting:'cutting' }[st.state];
let badge = tr.querySelector('.st');
if(!badge){ badge = document.createElement('div'); badge.className='fsub st'; tr.querySelector('td').appendChild(badge); }
badge.textContent = state;
});
}
document.getElementById('btn-assemble-all').addEventListener('click', () => stations.forEach(assembleStation));
document.getElementById('btn-undo-all').addEventListener('click', () => {
[...stations].reverse().forEach(undoStation);
});
document.getElementById('btn-reset').addEventListener('click', resetBench);
function resetBench(){
tweens.length = 0;
bundlesFormed = reusableReleases = destructiveRemovals = scrapped = 0;
ephemeral.forEach(o => { if(o.parent) o.parent.remove(o); });
ephemeral.length = 0;
scissors.visible = false;
stations.forEach(st => {
st.token++; st.state = 'loose';
if(st.tie && st.tie.parent){ st.g.remove(st.tie); }
st.tie = null;
st.cables.forEach(c => {
c.holder.position.set(c.loose.x, 0.05, c.loose.z);
c.holder.rotation.set(0, c.loose.r, 0);
});
if(st.fastener){
const f = st.fastener, u = f.userData;
f.position.set(0,0.075,1.95); f.scale.setScalar(0.8); f.rotation.set(0,0,0);
if(u.kind === 'strap'){ u.lever.rotation.x = -0.95; u.tail.position.z = -0.11; }
if(u.kind === 'clip'){ u.tabB.position.z = -0.16; u.tabB.rotation.y = 0; }
}
});
updatePanel();
}
/* keyboard */
window.addEventListener('keydown', e => {
if(e.key === '1' || e.key === '2' || e.key === '3') select(+e.key - 1);
if(e.key.toLowerCase() === 'a') assembleStation(stations[selected]);
if(e.key.toLowerCase() === 'u') undoStation(stations[selected]);
});
/* ============================ camera controls ============================ */
const cam = {
az:0.18, el:0.60, dist:9.4, tx:0, ty:0.25, tz:0,
azT:0.18, elT:0.60, distT:9.4, txT:0, tyT:0.25, tzT:0
};
function updateCamera(dt){
const k = 1 - Math.pow(0.0015, dt);
cam.az += (cam.azT - cam.az)*k; cam.el += (cam.elT - cam.el)*k; cam.dist += (cam.distT - cam.dist)*k;
cam.tx += (cam.txT - cam.tx)*k; cam.ty += (cam.tyT - cam.ty)*k; cam.tz += (cam.tzT - cam.tz)*k;
const ce = Math.cos(cam.el);
camera.position.set(
cam.tx + Math.sin(cam.az)*ce*cam.dist,
cam.ty + Math.sin(cam.el)*cam.dist,
cam.tz + Math.cos(cam.az)*ce*cam.dist
);
camera.lookAt(cam.tx, cam.ty, cam.tz);
}
let drag = null;
canvas.addEventListener('pointerdown', e => {
drag = { x:e.clientX, y:e.clientY, moved:false };
canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener('pointermove', e => {
if(!drag) return;
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
if(Math.abs(dx) + Math.abs(dy) > 4) drag.moved = true;
cam.azT -= dx*0.006;
cam.elT = Math.max(0.12, Math.min(1.32, cam.elT + dy*0.004));
drag.x = e.clientX; drag.y = e.clientY;
});
canvas.addEventListener('pointerup', e => {
if(drag && !drag.moved) pick(e);
drag = null;
});
canvas.addEventListener('wheel', e => {
e.preventDefault();
cam.distT = Math.max(4.2, Math.min(15, cam.distT * (1 + Math.sign(e.deltaY)*0.09)));
}, { passive:false });
const ray = new THREE.Raycaster();
function pick(e){
const r = canvas.getBoundingClientRect();
const ndc = new THREE.Vector2(((e.clientX - r.left)/r.width)*2-1, -((e.clientY - r.top)/r.height)*2+1);
ray.setFromCamera(ndc, camera);
const hit = ray.intersectObjects(pickables, false)[0];
if(hit && hit.object.userData.stIndex !== undefined) select(hit.object.userData.stIndex);
}
/* ============================ resize & loop ============================ */
function resize(){
const w = canvas.clientWidth, h = canvas.clientHeight;
renderer.setSize(w, h, false);
camera.aspect = w/h; camera.updateProjectionMatrix();
}
window.addEventListener('resize', resize);
resize();
const clock = new THREE.Clock();
function loop(){
requestAnimationFrame(loop);
const dt = Math.min(0.05, clock.getDelta());
stepTweens(dt);
updateCamera(dt);
const pulse = 0.42 + 0.16*Math.sin(performance.now()*0.005);
selRing.material.opacity = pulse;
selRing.scale.setScalar(1 + 0.03*Math.sin(performance.now()*0.004));
stations.forEach(st => { st.decal.material.opacity = st.index === selected ? 0.30 : 0.13; });
renderer.render(scene, camera);
}
select(0);
updatePanel();
loop();
</script>
</body>
</html>
```