Prompt specification
Build or customize the Three.js 3D scene "Chair Assembly Naming Table" 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: Chair Assembly Naming Table
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/chair-assembly-naming-table-x3402
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a stylized chair-assembly naming table. Arrange a seat, back, four legs, and a few fasteners in an exploded layout above a work surface. Animate the components joining in a clear order, keeping each leg aligned with its attachment point before the seat settles. Selecting a part should highlight its meaningful group, such as the whole back assembly, rather than treating every mesh used to draw it as a separate physical item. Use contrasting wood and metal materials and short labels that follow the selected group. Finish with the complete chair beside a faint outline of the original exploded arrangement.
Working Three.js Starter (chair-assembly-naming-table-x3402):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<title>Chair Assembly — Naming Table</title>
<style>
:root{
--accent:#6fe3ff;
--accent-dim:#2c6f80;
--wood:#e3a866;
--metal:#c9d4de;
--ink:#e9eff5;
--panel:rgba(14,20,26,.72);
--line:rgba(255,255,255,.10);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;
background:radial-gradient(130% 95% at 50% 5%,#1d2833 0%,#0d1318 55%,#070b0e 100%);
color:var(--ink);
font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial;}
#c{position:fixed;inset:0;display:block;touch-action:none}
#leaders{position:fixed;inset:0;width:100%;height:100%;pointer-events:none}
#labels{position:fixed;inset:0;pointer-events:none}
.label{
position:absolute;left:0;top:0;pointer-events:auto;cursor:pointer;
font-size:10.5px;letter-spacing:.14em;text-transform:uppercase;font-weight:600;
color:#b9c6d2;white-space:nowrap;padding:3px 8px;border-radius:999px;
background:rgba(10,15,20,.55);border:1px solid rgba(255,255,255,.08);
backdrop-filter:blur(4px);transition:color .18s,border-color .18s,background .18s,opacity .18s;
opacity:.55;
}
.label:hover{opacity:1;border-color:rgba(111,227,255,.4)}
.label.sel{opacity:1;color:#04141a;background:var(--accent);border-color:#bff4ff;
box-shadow:0 0 0 4px rgba(111,227,255,.12),0 6px 18px rgba(0,0,0,.45)}
.label .cnt{opacity:.6;font-weight:500;margin-left:6px}
.label.sel .cnt{opacity:.75}
#panel{
position:fixed;top:16px;right:16px;width:288px;max-height:calc(100% - 120px);
overflow:auto;background:var(--panel);border:1px solid var(--line);border-radius:14px;
padding:16px 16px 14px;backdrop-filter:blur(14px);
box-shadow:0 18px 44px rgba(0,0,0,.45);
}
#panel h1{margin:0 0 2px;font-size:13px;letter-spacing:.22em;text-transform:uppercase;font-weight:700}
#panel h1 span{display:block;font-size:10px;letter-spacing:.2em;color:#7d8d9b;margin-top:3px;font-weight:500}
.hint{font-size:11px;line-height:1.5;color:#8e9dab;margin:11px 0 12px;
padding:8px 9px;border-left:2px solid var(--accent-dim);background:rgba(111,227,255,.05);border-radius:0 6px 6px 0}
.legend{display:flex;gap:14px;font-size:10px;letter-spacing:.1em;color:#8b98a5;margin-bottom:10px;text-transform:uppercase}
.legend i{display:inline-block;width:22px;height:8px;border-radius:3px;margin-right:6px;vertical-align:middle}
.sw-wood{background:linear-gradient(90deg,#8a5a2b,#d69a58)}
.sw-metal{background:linear-gradient(90deg,#6d7b86,#e3ecf4)}
ul#list{list-style:none;margin:0;padding:0}
ul#list li{display:flex;align-items:center;gap:9px;padding:7px 9px;border-radius:8px;cursor:pointer;
font-size:11.5px;letter-spacing:.05em;border:1px solid transparent;transition:.15s}
ul#list li:hover{background:rgba(255,255,255,.05)}
ul#list li.on{background:rgba(111,227,255,.13);border-color:rgba(111,227,255,.45);color:#dff7ff}
ul#list .dot{width:7px;height:7px;border-radius:50%;background:#54626e;flex:none}
ul#list li.on .dot{background:var(--accent);box-shadow:0 0 8px var(--accent)}
ul#list .nm{flex:1}
ul#list .ct{font-size:9.5px;color:#75838f;letter-spacing:.08em}
#detail{margin-top:12px;padding-top:11px;border-top:1px solid var(--line);font-size:11px;line-height:1.55;color:#93a2b0;min-height:66px}
#detail b{color:#dce6ee;font-weight:600;letter-spacing:.04em}
#detail .comp{display:inline-block;margin:3px 4px 0 0;padding:2px 7px;border-radius:5px;
background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.07);font-size:10px;color:#aebcc8}
#bar{position:fixed;left:50%;transform:translateX(-50%);bottom:16px;
display:flex;align-items:center;gap:14px;padding:10px 14px;border-radius:14px;
background:var(--panel);border:1px solid var(--line);backdrop-filter:blur(14px);
box-shadow:0 18px 44px rgba(0,0,0,.45);min-width:min(760px,92vw)}
button{font:inherit;font-size:10.5px;letter-spacing:.14em;text-transform:uppercase;font-weight:600;
color:#cfdbe5;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.12);
padding:7px 12px;border-radius:8px;cursor:pointer;transition:.15s}
button:hover{background:rgba(111,227,255,.16);border-color:rgba(111,227,255,.45);color:#eafcff}
button.on{background:rgba(111,227,255,.2);border-color:rgba(111,227,255,.5)}
#tl{flex:1;min-width:180px}
#track{position:relative;height:20px}
#seg{position:absolute;inset:0;display:flex;gap:2px}
#seg div{height:5px;border-radius:3px;background:rgba(255,255,255,.10);position:relative;overflow:hidden}
#seg div i{position:absolute;inset:0;width:0;background:linear-gradient(90deg,#3aa7c4,var(--accent));display:block}
#seg span{position:absolute;top:8px;font-size:8.5px;letter-spacing:.14em;color:#6e7d8a;text-transform:uppercase}
#scrub{position:absolute;inset:auto 0 6px 0;width:100%;height:5px;-webkit-appearance:none;appearance:none;
background:transparent;cursor:pointer}
#scrub::-webkit-slider-thumb{-webkit-appearance:none;width:13px;height:13px;border-radius:50%;
background:#eafcff;border:2px solid var(--accent);box-shadow:0 0 10px rgba(111,227,255,.8);cursor:pointer}
#scrub::-moz-range-thumb{width:13px;height:13px;border-radius:50%;background:#eafcff;border:2px solid var(--accent);cursor:pointer}
#phase{font-size:11px;letter-spacing:.18em;text-transform:uppercase;color:var(--accent);min-width:96px;text-align:right}
#fps{position:fixed;left:16px;top:16px;font-size:10px;letter-spacing:.16em;color:#6b7a87;text-transform:uppercase}
#fps b{color:#b6c6d2;font-weight:600}
</style>
</head>
<body>
<canvas id="c"></canvas>
<svg id="leaders"></svg>
<div id="labels"></div>
<div id="fps">Exploded <b id="st">0%</b> · phase <b id="ph">idle</b></div>
<aside id="panel">
<h1>Chair Assembly<span>Exploded naming table</span></h1>
<div class="hint">Click any part in the scene (or a row below). Selection highlights the whole <b>meaningful group</b> — e.g. the back posts, slats, rail and gussets light up as one item.</div>
<div class="legend"><span><i class="sw-wood"></i>wood</span><span><i class="sw-metal"></i>metal</span></div>
<ul id="list"></ul>
<div id="detail"></div>
</aside>
<div id="bar">
<button id="play">Pause</button>
<button id="restart">Reset</button>
<button id="explode">Explode</button>
<div id="tl">
<div id="track"><div id="seg"></div><input id="scrub" type="range" min="0" max="1000" value="0"></div>
</div>
<button id="ghostBtn" class="on">Outline</button>
<div id="phase">legs</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ setup */
const canvas = document.getElementById('c');
const renderer = new THREE.WebGLRenderer({canvas, antialias:true, alpha:true});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(38, innerWidth/innerHeight, 0.05, 120);
/* ------------------------------------------------------- textures / mats */
function woodTexture(){
const c = document.createElement('canvas'); c.width = 512; c.height = 512;
const x = c.getContext('2d');
x.fillStyle = '#c2884c'; x.fillRect(0,0,512,512);
for(let i=0;i<260;i++){
const y0 = Math.random()*512;
const amp = 4 + Math.random()*16, per = 40 + Math.random()*180;
x.beginPath(); x.moveTo(0, y0);
for(let px=0;px<=512;px+=8){
x.lineTo(px, y0 + Math.sin(px/per*Math.PI*2 + i)*amp*0.35 + Math.sin(px/23+i)*1.6);
}
x.strokeStyle = `rgba(${90+Math.random()*60|0},${50+Math.random()*40|0},20,${0.05+Math.random()*0.13})`;
x.lineWidth = 1 + Math.random()*3.4; x.stroke();
}
for(let i=0;i<1400;i++){
x.fillStyle = `rgba(60,34,12,${Math.random()*0.10})`;
x.fillRect(Math.random()*512, Math.random()*512, 2+Math.random()*3, 1);
}
const t = new THREE.CanvasTexture(c);
t.wrapS = t.wrapT = THREE.RepeatWrapping;
t.colorSpace = THREE.SRGBColorSpace;
return t;
}
const WOOD_MAP = woodTexture();
function gridTexture(){
const c = document.createElement('canvas'); c.width = c.height = 512;
const x = c.getContext('2d');
x.clearRect(0,0,512,512);
x.strokeStyle = 'rgba(190,215,235,0.16)'; x.lineWidth = 1;
for(let i=0;i<=512;i+=64){ x.beginPath(); x.moveTo(i,0); x.lineTo(i,512); x.stroke();
x.beginPath(); x.moveTo(0,i); x.lineTo(512,i); x.stroke(); }
x.strokeStyle = 'rgba(190,215,235,0.30)'; x.lineWidth = 2;
x.strokeRect(1,1,510,510);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}
const GRID_MAP = gridTexture();
/* environment (core-only PMREM from a gradient dome) */
function envDome(){
const c = document.createElement('canvas'); c.width = 128; c.height = 256;
const x = c.getContext('2d');
const g = x.createLinearGradient(0,0,0,256);
g.addColorStop(0,'#ffffff'); g.addColorStop(.42,'#d6dee6');
g.addColorStop(.52,'#66717d'); g.addColorStop(1,'#20242a');
x.fillStyle = g; x.fillRect(0,0,128,256);
const rg = x.createRadialGradient(30,44,2,30,44,52);
rg.addColorStop(0,'rgba(255,255,255,1)'); rg.addColorStop(1,'rgba(255,255,255,0)');
x.fillStyle = rg; x.fillRect(0,0,128,256);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}
{
const pmrem = new THREE.PMREMGenerator(renderer);
const es = new THREE.Scene();
es.add(new THREE.Mesh(new THREE.SphereGeometry(12,32,16),
new THREE.MeshBasicMaterial({map: envDome(), side: THREE.BackSide})));
scene.environment = pmrem.fromScene(es, 0.03).texture;
pmrem.dispose();
}
/* lights */
scene.add(new THREE.HemisphereLight(0xbcd6ea, 0x2a241d, 0.5));
const key = new THREE.DirectionalLight(0xfff1dd, 2.35);
key.position.set(2.3, 3.6, 2.7); key.castShadow = true;
key.shadow.mapSize.set(2048,2048);
key.shadow.camera.left=-3.2; key.shadow.camera.right=3.2;
key.shadow.camera.top=3.2; key.shadow.camera.bottom=-2.4;
key.shadow.camera.near=.5; key.shadow.camera.far=12; key.shadow.bias=-0.0009;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9dc4ff, 0.55); fill.position.set(-2.6,1.7,-2.2); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffd9a8, 0.45); rim.position.set(-0.4,1.2,3.2); scene.add(rim);
/* work surface */
const bench = new THREE.Mesh(
new THREE.BoxGeometry(6.4,0.18,3.6),
new THREE.MeshStandardMaterial({color:0x2c333b, roughness:0.92, metalness:0.06}));
bench.position.set(0.35,-0.09,0); bench.receiveShadow = true; scene.add(bench);
const mat = new THREE.Mesh(new THREE.PlaneGeometry(3.3,2.35),
new THREE.MeshBasicMaterial({map:GRID_MAP, transparent:true, opacity:.5, depthWrite:false}));
mat.rotation.x = -Math.PI/2; mat.position.set(0.2,0.002,0); scene.add(mat);
/* ------------------------------------------------------- geometry helpers */
const SEAT_Y = 0.45, SEAT_T = 0.055, LX = 0.175, LZ = 0.165;
const easeInOutCubic = k => k<.5 ? 4*k*k*k : 1-Math.pow(-2*k+2,3)/2;
const easeInOutQuad = k => k<.5 ? 2*k*k : 1-Math.pow(-2*k+2,2)/2;
const easeInCubic = k => k*k*k;
function roundedRect(w,d,r){
const s = new THREE.Shape(), x=-w/2, y=-d/2;
s.moveTo(x+r,y); s.lineTo(x+w-r,y); s.quadraticCurveTo(x+w,y,x+w,y+r);
s.lineTo(x+w,y+d-r); s.quadraticCurveTo(x+w,y+d,x+w-r,y+d);
s.lineTo(x+r,y+d); s.quadraticCurveTo(x,y+d,x,y+d-r);
s.lineTo(x,y+r); s.quadraticCurveTo(x,y,x+r,y); return s;
}
function extruded(shape, h){
const g = new THREE.ExtrudeGeometry(shape,{depth:h,bevelEnabled:true,
bevelThickness:0.005,bevelSize:0.005,bevelSegments:2,steps:1,curveSegments:10});
g.rotateX(-Math.PI/2);
g.computeBoundingBox(); g.translate(0,-g.boundingBox.min.y,0);
g.computeVertexNormals(); return g;
}
/* ------------------------------------------------------------ part system */
const PARTS = [], ANIMS = [], GUIDES = [], MARKERS = [];
function newMats(){
return {
wood: new THREE.MeshStandardMaterial({map:WOOD_MAP, roughness:.56, metalness:.03, envMapIntensity:.55}),
metal: new THREE.MeshStandardMaterial({color:0xdde5ec, roughness:.26, metalness:.95, envMapIntensity:1.15}),
dark: new THREE.MeshStandardMaterial({color:0x272b30, roughness:.62, metalness:.35, envMapIntensity:.6})
};
}
function regPart(p, obj, anchorLocal, fallbackOff, comps){
obj.traverse(o=>{
if(o.isMesh){
o.userData.partId = p.id; o.castShadow = true; o.receiveShadow = true;
p.meshes.push(o);
const eg = new THREE.EdgesGeometry(o.geometry, 26);
const ln = new THREE.LineSegments(eg, new THREE.LineBasicMaterial({
color:0x8ff0ff, transparent:true, opacity:.95, depthTest:true}));
ln.visible = false; ln.renderOrder = 2; o.add(ln); p.outlines.push(ln);
}
});
p.group = obj; scene.add(obj);
const anchor = new THREE.Object3D(); anchor.position.copy(anchorLocal); obj.add(anchor);
p.anchor = anchor;
p.fallbackOff = fallbackOff;
p.components = comps;
PARTS.push(p);
return p;
}
function mkPart(id, name, desc){
const mats = newMats();
return {id, name, desc, mats, meshes:[], outlines:[], comps:[],
matList:[mats.wood,mats.metal,mats.dark]};
}
function setDim(p, dim){
for(const m of p.matList){
m.transparent = dim; m.opacity = dim ? .16 : 1; m.depthWrite = !dim;
m.needsUpdate = true;
}
if(dim) p.outlines.forEach(o=>o.visible=false);
}
function makeLabel(p){
const el = document.createElement('div');
el.className = 'label';
el.innerHTML = `${p.name}<span class="cnt">${p.meshes.length}</span>`;
el.addEventListener('pointerdown', e=>e.stopPropagation());
el.addEventListener('click', e=>{ e.stopPropagation(); select(p.id); });
document.getElementById('labels').appendChild(el);
p.labelEl = el;
const ln = document.createElementNS('http://www.w3.org/2000/svg','line');
ln.setAttribute('stroke','#6fe3ff'); ln.setAttribute('stroke-width','1.2');
ln.setAttribute('stroke-dasharray','4 3'); ln.setAttribute('opacity','0');
document.getElementById('leaders').appendChild(ln);
p.leader = ln;
const ci = document.createElementNS('http://www.w3.org/2000/svg','circle');
ci.setAttribute('r','3.5'); ci.setAttribute('fill','none');
ci.setAttribute('stroke','#6fe3ff'); ci.setAttribute('stroke-width','1.4');
ci.setAttribute('opacity','0');
document.getElementById('leaders').appendChild(ci);
p.anchorDot = ci;
}
/* ------------------------------------------------------------------ legs */
const LEGS = [
{id:'legFL', name:'Leg · Front Left', sx:-1, sz: 1, a:0.02, b:0.17},
{id:'legFR', name:'Leg · Front Right',sx: 1, sz: 1, a:0.07, b:0.22},
{id:'legRL', name:'Leg · Rear Left', sx:-1, sz:-1, a:0.12, b:0.27},
{id:'legRR', name:'Leg · Rear Right', sx: 1, sz:-1, a:0.17, b:0.32}
];
for(const L of LEGS){
const p = mkPart(L.id, L.name,
'One structural leg: the tapered wooden post, its steel mounting bracket and the floor glide are a single physical item.');
const g = new THREE.Group();
const len = 0.45;
const postGeo = new THREE.CylinderGeometry(0.023,0.031,len,4,1);
postGeo.rotateY(Math.PI/4);
const post = new THREE.Mesh(postGeo, p.mats.wood);
post.position.y = -len/2; g.add(post); p.comps.push('Tapered post');
const br = new THREE.Mesh(new THREE.BoxGeometry(0.078,0.014,0.078), p.mats.metal);
br.position.y = -0.011; g.add(br); p.comps.push('Mounting bracket');
const plate = new THREE.Mesh(new THREE.BoxGeometry(0.05,0.035,0.05), p.mats.metal);
plate.position.y = -0.035; g.add(plate); p.comps.push('Tenon collar');
const gl = new THREE.Mesh(new THREE.CylinderGeometry(0.025,0.025,0.016,14), p.mats.dark);
gl.position.y = -len + 0.007; g.add(gl); p.comps.push('Floor glide');
const tilt = 0.075;
g.rotation.set(-L.sz*tilt, 0, L.sx*tilt);
const x = L.sx*LX, z = L.sz*LZ;
const to = new THREE.Vector3(x, SEAT_Y, z);
const from = new THREE.Vector3(x, SEAT_Y + 0.30, z);
g.position.copy(from);
regPart(p, g, new THREE.Vector3(0,-0.20,0), [L.sx*58, L.sz*8 + 10], p.comps);
ANIMS.push({obj:g, from, to, a:L.a, b:L.b, ease:easeInOutQuad});
GUIDES.push({kind:'leg', obj:g, x, z, toY:SEAT_Y, mat:null});
// socket ring marker
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.030,0.0035,8,28),
new THREE.MeshBasicMaterial({color:0x6fe3ff, transparent:true, opacity:.33}));
ring.rotation.x = -Math.PI/2; ring.position.set(x, SEAT_Y, z); scene.add(ring); MARKERS.push(ring);
}
/* ------------------------------------------------------------------ seat */
{
const p = mkPart('seat','Seat',
'The seat assembly: one panel plus four apron rails and four corner brackets — drawn with nine meshes, but named as one part.');
const g = new THREE.Group();
const panel = new THREE.Mesh(extruded(roundedRect(0.46,0.44,0.055), SEAT_T), p.mats.wood);
g.add(panel); p.comps.push('Seat panel');
const rail = (w,d,x,y,z)=>{ const m=new THREE.Mesh(new THREE.BoxGeometry(w,0.048,d),p.mats.wood); m.position.set(x,y,z); g.add(m); };
rail(0.42,0.028, 0,-0.036, 0.198); p.comps.push('Front apron');
rail(0.42,0.028, 0,-0.036,-0.198); p.comps.push('Rear apron');
rail(0.028,0.36,-0.212,-0.036,0); p.comps.push('Left apron');
rail(0.028,0.36, 0.212,-0.036,0); p.comps.push('Right apron');
for(const sx of [-1,1]) for(const sz of [-1,1]){
const br = new THREE.Mesh(new THREE.BoxGeometry(0.082,0.012,0.082), p.mats.metal);
br.position.set(sx*LX,-0.010,sz*LZ); g.add(br); p.comps.push('Corner bracket');
}
const to = new THREE.Vector3(0,SEAT_Y,0), from = new THREE.Vector3(0,SEAT_Y+0.40,0);
g.position.copy(from);
regPart(p, g, new THREE.Vector3(0,SEAT_T+0.01,0), [0,-56], p.comps);
ANIMS.push({obj:g, from, to, a:0.36, b:0.55, ease:easeInOutCubic, settle:true});
GUIDES.push({kind:'seat', obj:g, x:0, z:0, toY:SEAT_Y});
}
/* ------------------------------------------------------------ back group */
{
const p = mkPart('back','Back Assembly',
'The whole back: two posts, three slats, the top rail and both gussets belong to one back assembly — picking any of them selects the group.');
const g = new THREE.Group();
const frame = new THREE.Group(); frame.rotation.x = -0.14; g.add(frame);
const postGeo = new THREE.BoxGeometry(0.036,0.62,0.036);
for(const sx of [-1,1]){
const post = new THREE.Mesh(postGeo, p.mats.wood);
post.position.set(sx*0.115,0.31,0); frame.add(post); p.comps.push(sx<0?'Left post':'Right post');
}
for(const y of [0.30,0.42,0.54]){
const s = new THREE.Mesh(new THREE.BoxGeometry(0.30,0.068,0.022), p.mats.wood);
s.position.set(0,y,0); frame.add(s); p.comps.push('Slat');
}
const top = new THREE.Mesh(new THREE.BoxGeometry(0.335,0.046,0.032), p.mats.wood);
top.position.set(0,0.615,0); frame.add(top); p.comps.push('Top rail');
for(const sx of [-1,1]){
const gs = new THREE.Mesh(new THREE.BoxGeometry(0.062,0.095,0.012), p.mats.metal);
gs.position.set(sx*0.115,0.045,-0.006); g.add(gs); p.comps.push('Gusset');
}
const to = new THREE.Vector3(0,SEAT_Y,-0.20), from = new THREE.Vector3(0,SEAT_Y+0.58,-0.20);
g.position.copy(from);
regPart(p, g, new THREE.Vector3(0,0.44,-0.05), [0,-52], p.comps);
ANIMS.push({obj:g, from, to, a:0.60, b:0.79, ease:easeInOutCubic});
GUIDES.push({kind:'back', obj:g, x:0, z:-0.20, toY:SEAT_Y});
}
/* -------------------------------------------------------------- hardware */
{
const p = mkPart('hardware','Fasteners',
'The hardware set: four seat bolts and two back bolts are collected as one fastener group.');
const g = new THREE.Group();
const mkBolt = ()=>{
const b = new THREE.Group();
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.0075,0.0075,0.05,12), p.mats.metal);
shaft.position.y = -0.037; b.add(shaft); p.comps.push('Bolt shank');
const head = new THREE.Mesh(new THREE.CylinderGeometry(0.0145,0.0145,0.012,6), p.mats.metal);
head.position.y = -0.006; b.add(head); p.comps.push('Hex head');
const wash = new THREE.Mesh(new THREE.CylinderGeometry(0.020,0.020,0.004,18), p.mats.dark);
wash.position.y = -0.014; b.add(wash); p.comps.push('Washer');
return b;
};
const bolts = [];
for(const sx of [-1,1]) for(const sz of [-1,1]){
const b = mkBolt(); b.position.set(sx*LX, 0.925, sz*LZ); g.add(b);
bolts.push({obj:b, from:new THREE.Vector3(sx*LX,0.925,sz*LZ), to:new THREE.Vector3(sx*LX,SEAT_Y+SEAT_T,sz*LZ), a:0.82,b:0.94,spin:true});
}
for(const sx of [-1,1]){
const b = mkBolt(); b.rotation.x = -Math.PI/2;
b.position.set(sx*0.115, SEAT_Y+0.045, -0.42); g.add(b);
bolts.push({obj:b, from:new THREE.Vector3(sx*0.115,SEAT_Y+0.045,-0.42), to:new THREE.Vector3(sx*0.115,SEAT_Y+0.045,-0.215), a:0.88,b:0.99,spin:true});
}
g.position.set(0,0,0);
regPart(p, g, new THREE.Vector3(LX,0.925,LZ), [54,-14], p.comps);
bolts.forEach(b=>ANIMS.push({obj:b.obj, from:b.from, to:b.to, a:b.a, b:b.b, ease:easeInCubic, spin:true}));
}
/* labels + panel rows */
PARTS.forEach(makeLabel);
const listEl = document.getElementById('list');
PARTS.forEach(p=>{
const li = document.createElement('li');
li.innerHTML = `<span class="dot"></span><span class="nm">${p.name}</span><span class="ct">${p.meshes.length} mesh</span>`;
li.addEventListener('click', ()=>select(p.id));
listEl.appendChild(li); p.row = li;
});
const detailEl = document.getElementById('detail');
function updateDetail(){
const p = PARTS.find(q=>q.id===selected);
if(!p){ detailEl.innerHTML = '<b>Nothing selected.</b><br>Pick a part to see how its meshes are grouped into one named item.'; return; }
detailEl.innerHTML = `<b>${p.name}</b> — ${p.desc}<br>${p.components.map(c=>`<span class="comp">${c}</span>`).join('')}`;
}
/* --------------------------------------------------- ghost exploded outline */
const GHOST_MAT = new THREE.LineBasicMaterial({color:0x9ec6d8, transparent:true, opacity:0});
const ghostRoot = new THREE.Group();
ghostRoot.position.set(1.62, 0, 0.02);
ghostRoot.scale.setScalar(0.80);
scene.add(ghostRoot);
function ghostify(obj, parent){
for(const child of obj.children){
if(child.isMesh){
const lines = new THREE.LineSegments(new THREE.EdgesGeometry(child.geometry,26), GHOST_MAT);
lines.position.copy(child.position); lines.quaternion.copy(child.quaternion); lines.scale.copy(child.scale);
parent.add(lines);
} else if(child.isLineSegments){ /* skip highlight outlines */ }
else if(child.type === 'Object3D'){
const g = new THREE.Group();
g.position.copy(child.position); g.quaternion.copy(child.quaternion); g.scale.copy(child.scale);
parent.add(g); ghostify(child, g);
}
}
}
for(const a of ANIMS){
const parent = new THREE.Group();
parent.position.copy(a.from); parent.quaternion.copy(a.obj.quaternion);
ghostRoot.add(parent);
ghostify(a.obj, parent);
}
/* ------------------------------------------------------- alignment guides */
for(const gd of GUIDES){
const geo = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]);
const mat = new THREE.LineDashedMaterial({color:0x6fe3ff, dashSize:.035, gapSize:.030,
transparent:true, opacity:.0, depthWrite:false});
const line = new THREE.Line(geo, mat); scene.add(line);
gd.line = line; gd.mat = mat;
}
/* ------------------------------------------------------------- selection */
let selected = null;
function select(id){
selected = (selected === id) ? null : id;
PARTS.forEach(p=>{
const on = p.id === selected;
setDim(p, selected !== null && !on);
p.outlines.forEach(o=>o.visible = on);
p.labelEl.classList.toggle('sel', on);
p.labelEl.classList.toggle('muted', selected !== null && !on);
p.row.classList.toggle('on', on);
p.leader.setAttribute('opacity', on ? '.85' : '0');
p.anchorDot.setAttribute('opacity', on ? '1' : '0');
});
updateDetail();
}
document.getElementById('detail').innerHTML = ''; updateDetail();
/* ------------------------------------------------------- camera controls */
const cam = {
target:new THREE.Vector3(0.45,0.55,0), tTarget:new THREE.Vector3(0.45,0.55,0),
radius:3.5, tRadius:3.5, theta:0.60, tTheta:0.60, phi:1.06, tPhi:1.06
};
function camUpdate(dt){
const k = 1 - Math.exp(-9*dt);
cam.target.lerp(cam.tTarget,k); cam.radius += (cam.tRadius-cam.radius)*k;
cam.theta += (cam.tTheta-cam.theta)*k; cam.phi += (cam.tPhi-cam.phi)*k;
cam.phi = THREE.MathUtils.clamp(cam.phi, .16, 1.46);
camera.position.setFromSphericalCoords(cam.radius, cam.phi, cam.theta).add(cam.target);
camera.lookAt(cam.target);
}
let drag = null, moved = 0;
canvas.addEventListener('pointerdown', e=>{
canvas.setPointerCapture(e.pointerId);
drag = {x:e.clientX, y:e.clientY, pan:(e.button===2||e.shiftKey)}; moved = 0;
});
canvas.addEventListener('pointermove', e=>{
if(!drag) return;
const dx = e.clientX-drag.x, dy = e.clientY-drag.y; drag.x=e.clientX; drag.y=e.clientY;
moved += Math.abs(dx)+Math.abs(dy);
if(drag.pan){
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
cam.tTarget.addScaledVector(right,-dx*0.0035).addScaledVector(up, dy*0.0035);
} else {
cam.tTheta -= dx*0.0055; cam.tPhi -= dy*0.0045;
}
});
canvas.addEventListener('pointerup', e=>{
if(drag && moved < 6){
const hit = pick(e.clientX,e.clientY);
if(hit) select(hit); else select(null);
}
drag = null;
});
canvas.addEventListener('pointercancel', ()=>{drag=null;});
canvas.addEventListener('contextmenu', e=>e.preventDefault());
canvas.addEventListener('wheel', e=>{
e.preventDefault();
cam.tRadius = THREE.MathUtils.clamp(cam.tRadius * (1 + Math.sign(e.deltaY)*0.09), 1.4, 9);
}, {passive:false});
const ray = new THREE.Raycaster(), ndc = new THREE.Vector2();
const pickables = PARTS.flatMap(p=>p.meshes);
function pick(cx,cy){
ndc.x = (cx/innerWidth)*2-1; ndc.y = -(cy/innerHeight)*2+1;
ray.setFromCamera(ndc, camera);
const hits = ray.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.partId : null;
}
canvas.addEventListener('pointermove', e=>{
if(drag) return;
canvas.style.cursor = pick(e.clientX,e.clientY) ? 'pointer' : 'grab';
});
/* --------------------------------------------------------------- timeline */
const DURATION = 11.5;
const state = { t:0, playing:true, speed:1, ghost:true };
const scrub = document.getElementById('scrub'), playBtn = document.getElementById('play');
const phaseEl = document.getElementById('phase'), stEl = document.getElementById('st');
const PHASES = [
{n:'legs', a:0.02, b:0.32},
{n:'seat', a:0.36, b:0.55},
{n:'back', a:0.60, b:0.79},
{n:'fasteners', a:0.82, b:1.00}
];
const segEl = document.getElementById('seg');
PHASES.forEach(ph=>{
const d = document.createElement('div');
d.style.flex = (ph.b-ph.a)+''; d.innerHTML = '<i></i>';
const s = document.createElement('span'); s.textContent = ph.n;
d.appendChild(s); segEl.appendChild(d);
ph.bar = d.querySelector('i'); ph.el = d;
});
function applyTimeline(t){
for(const a of ANIMS){
const k = THREE.MathUtils.clamp((t-a.a)/(a.b-a.a),0,1);
const e = a.ease(k);
a.obj.position.lerpVectors(a.from, a.to, e);
if(a.spin) a.obj.rotation.y = (1-e)*Math.PI*3;
if(a.settle){
const u = THREE.MathUtils.clamp((k-0.70)/0.30,0,1);
a.obj.position.y += 0.028*Math.exp(-5.5*u)*Math.abs(Math.sin(u*Math.PI*3));
a.obj.rotation.z = 0.010*Math.exp(-5.5*u)*Math.sin(u*Math.PI*3);
}
}
// dashed alignment guides: leg tops stay directly above their sockets
for(const gd of GUIDES){
const k = THREE.MathUtils.clamp((t-gd.obj.userData.a ?? 0),0,1);
const cur = gd.obj.position.y;
const len = Math.max(0, cur - gd.toY);
const pts = [new THREE.Vector3(gd.x, cur, gd.z), new THREE.Vector3(gd.x, gd.toY, gd.z)];
gd.line.geometry.setFromPoints(pts); gd.line.geometry.computeBoundingSphere();
gd.line.computeLineDistances();
gd.mat.opacity = len > 0.012 ? 0.42*(1 - Math.min(1, len/0.30)) : 0;
}
// ghost outline fades in with the final reveal
const fade = THREE.MathUtils.smoothstep(t, .84, 1.0);
GHOST_MAT.opacity = state.ghost ? (0.10 + 0.34*fade) : 0;
// phase readouts
let cur = 'idle';
for(const ph of PHASES) if(t >= ph.a) cur = ph.n;
if(t < 0.02) cur = 'exploded';
phaseEl.textContent = cur;
stEl.textContent = Math.round(t*100)+'%';
PHASES.forEach(ph=>{ ph.bar.style.width = THREE.MathUtils.clamp((t-ph.a)/(ph.b-ph.a),0,1)*100+'%'; });
}
playBtn.addEventListener('click', ()=>{ state.playing = !state.playing; playBtn.textContent = state.playing?'Pause':'Play'; });
document.getElementById('restart').addEventListener('click', ()=>{ state.t=0; state.playing=true; playBtn.textContent='Pause'; });
document.getElementById('explode').addEventListener('click', ()=>{ state.t=0; state.playing=false; playBtn.textContent='Play'; });
document.getElementById('ghostBtn').addEventListener('click', e=>{ state.ghost=!state.ghost; e.target.classList.toggle('on',state.ghost); });
scrub.addEventListener('input', ()=>{ state.t = scrub.value/1000; state.playing=false; playBtn.textContent='Play'; });
/* ------------------------------------------------------------ label update */
const vTmp = new THREE.Vector3();
function updateLabels(){
const w = innerWidth, h = innerHeight;
const c = new THREE.Vector3(0,0.62,0).project(camera);
const cx = (c.x*.5+.5)*w, cy = (-c.y*.5+.5)*h;
for(const p of PARTS){
p.anchor.getWorldPosition(vTmp); vTmp.project(camera);
const x = (vTmp.x*.5+.5)*w, y = (-vTmp.y*.5+.5)*h;
p.screen = {x,y};
let dx = x-cx, dy = y-cy, d = Math.hypot(dx,dy);
let ox, oy;
if(d < 26){ ox = p.fallbackOff[0]; oy = p.fallbackOff[1]; }
else { ox = dx/d*54; oy = dy/d*34 - 6; }
const lx = THREE.MathUtils.clamp(x+ox, 70, w-70), ly = THREE.MathUtils.clamp(y+oy, 34, h-90);
p.labelEl.style.transform = `translate(-50%,-50%) translate(${lx}px,${ly}px)`;
p.leader.setAttribute('x1',x); p.leader.setAttribute('y1',y);
p.leader.setAttribute('x2',lx); p.leader.setAttribute('y2',ly);
p.anchorDot.setAttribute('cx',x); p.anchorDot.setAttribute('cy',y);
}
}
/* --------------------------------------------------------------- the loop */
let last = performance.now();
function loop(now){
const dt = Math.min(0.05,(now-last)/1000); last = now;
if(state.playing){
state.t += dt*state.speed/DURATION;
if(state.t >= 1){ state.t = 1; state.playing = false; playBtn.textContent='Play'; }
}
applyTimeline(state.t);
scrub.value = Math.round(state.t*1000);
camUpdate(dt);
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(loop);
}
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
requestAnimationFrame(loop);
</script>
</body>
</html>
```