Prompt specification
Build or customize the Three.js 3D scene "Costume wardrobe adjustment corner" 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: Costume wardrobe adjustment corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/costume-wardrobe-adjustment-corner-x0567
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a scene with a costume rack with belts, tunics, and accessory bins; a helper adjusts a belt on a mannequin while matching components remain grouped by costume. Voxel style.
Working Three.js Starter (costume-wardrobe-adjustment-corner-x0567):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Costume Workshop</title>
<style>
:root{
--bg:#101623; --panel:rgba(16,22,35,.82); --line:rgba(150,190,255,.22);
--txt:#e7eef8; --dim:#9fb0c8;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:var(--bg);
font-family:"Courier New",ui-monospace,Menlo,Consolas,monospace;color:var(--txt)}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
#ui{position:fixed;inset:0;pointer-events:none}
#panel{
position:absolute;top:14px;left:14px;width:268px;padding:14px 14px 12px;
background:var(--panel);border:2px solid var(--line);border-radius:10px;
backdrop-filter:blur(6px);pointer-events:auto;
box-shadow:0 10px 30px rgba(0,0,0,.45)}
#panel h1{margin:0;font-size:16px;letter-spacing:2px;text-transform:uppercase}
#panel .sub{margin:4px 0 10px;font-size:11px;color:var(--dim);line-height:1.5}
.crow{display:flex;align-items:center;gap:8px;font-size:12px;padding:5px 0;
border-top:1px dashed rgba(255,255,255,.08)}
.crow .nm{flex:1;letter-spacing:.5px}
.sw{display:flex;align-items:center;gap:6px;cursor:pointer}
.sw i{width:12px;height:12px;border-radius:2px;display:inline-block;
box-shadow:0 0 0 1px rgba(0,0,0,.5)}
.sw input{accent-color:#6ea8ff;width:12px;height:12px}
button{font:inherit;font-size:11px;padding:4px 8px;color:var(--txt);
background:rgba(110,168,255,.14);border:1px solid var(--line);border-radius:5px;
cursor:pointer}
button:hover{background:rgba(110,168,255,.3)}
.btns{display:flex;gap:6px;margin-top:9px}
#status{margin-top:9px;font-size:11px;color:var(--dim);line-height:1.6;
border-top:1px solid var(--line);padding-top:8px;min-height:46px}
#status b{color:#ffd58a}
.hint{margin-top:8px;font-size:10px;color:#7d8ea8;line-height:1.5}
#badge{position:absolute;right:16px;top:16px;font-size:11px;color:var(--dim);
background:var(--panel);border:2px solid var(--line);border-radius:8px;padding:8px 12px}
#badge b{color:#ffd58a}
</style>
</head>
<body>
<div id="app"></div>
<div id="ui">
<div id="panel">
<h1>Costume Workshop</h1>
<div class="sub">Voxel rack · every kit (tunic + belt + bin + mannequin) stays grouped in one scene group.</div>
<div id="rows"></div>
<div class="btns">
<button id="allBtn">Show all</button>
<button id="orbitBtn">Auto-orbit</button>
</div>
<div id="status"></div>
<div class="hint">drag = orbit · wheel = zoom · shift-drag = pan<br>click a kit = focus · keys 1-4 = views</div>
</div>
<div id="badge"><b>WORKSHOP</b> · rack A / B / C</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 app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({antialias: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.06;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const BG = new THREE.Color(0x111827);
scene.background = BG;
scene.fog = new THREE.Fog(0x111827, 26, 62);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, .1, 200);
/* -------------------------------------------------------------- utilities */
const geoCache = new Map();
function geo(w,h,d){
const k = `${w}|${h}|${d}`;
if(!geoCache.has(k)) geoCache.set(k, new THREE.BoxGeometry(w,h,d));
return geoCache.get(k);
}
/** voxel block: unique material per mesh so kits can be dimmed/highlighted */
function box(w,h,d,color,x=0,y=0,z=0,opts={}){
const m = new THREE.Mesh(geo(w,h,d), new THREE.MeshStandardMaterial({
color, roughness:.88, metalness:0, flatShading:true, ...opts}));
m.position.set(x,y,z);
m.castShadow = true; m.receiveShadow = true;
m.userData.base = new THREE.Color(color);
return m;
}
const clamp=(v,a,b)=>Math.max(a,Math.min(b,v));
const lerp=(a,b,t)=>a+(b-a)*t;
const smooth=t=>t*t*(3-2*t);
function lerpAngle(a,b,t){let d=((b-a+Math.PI)%(Math.PI*2)+Math.PI*2)%(Math.PI*2)-Math.PI;
return a+d*t;}
/* ------------------------------------------------------------- lighting */
scene.add(new THREE.HemisphereLight(0xbcd6ff,0x3a2b22,.72));
const sun = new THREE.DirectionalLight(0xffe6c4,1.15);
sun.position.set(9,15,11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048,2048);
sun.shadow.camera.left=-22; sun.shadow.camera.right=22;
sun.shadow.camera.top=18; sun.shadow.camera.bottom=-12;
sun.shadow.camera.far=50; sun.shadow.bias=-0.0006;
scene.add(sun);
const fill = new THREE.PointLight(0xffc27a,.55,16,2);
fill.position.set(0,4.2,2.5);
scene.add(fill);
/* ------------------------------------------------------------ floor / wall */
function floorTexture(){
const c=document.createElement('canvas'); c.width=c.height=64;
const x=c.getContext('2d');
x.fillStyle='#6b4f3a'; x.fillRect(0,0,64,64);
x.fillStyle='#755740'; x.fillRect(0,0,32,32); x.fillRect(32,32,32,32);
x.fillStyle='#5d4532'; x.fillRect(32,0,32,32); x.fillRect(0,32,32,32);
const t=new THREE.CanvasTexture(c);
t.magFilter=THREE.NearestFilter; t.minFilter=THREE.NearestFilter;
t.wrapS=t.wrapT=THREE.RepeatWrapping; t.repeat.set(9,7);
return t;
}
const floor = new THREE.Mesh(new THREE.PlaneGeometry(46,32),
new THREE.MeshStandardMaterial({map:floorTexture(),roughness:1}));
floor.rotation.x=-Math.PI/2; floor.receiveShadow=true; scene.add(floor);
const base = box(46,0.5,32,0x2a2233,0,-0.26,0); base.receiveShadow=true; scene.add(base);
const wall = box(46,13,0.6,0x2c3648,0,6.4,-9.2); wall.receiveShadow=true; scene.add(wall);
scene.add(box(46,1.6,0.8,0x3c4a63,0,0.8,-9.0));
for(let i=-5;i<=5;i++) scene.add(box(1.7,3.2,0.25,0x1d2534,i*4.2,3.4,-8.85));
/* ------------------------------------------------------------- the rack */
const rack = new THREE.Group(); scene.add(rack);
const WOOD=0x8a5a3b, WOOD2=0x6f452c, IRON=0x9aa5b2;
function post(x){
rack.add(box(.65,7.2,.65,WOOD,x,3.6,-5.6));
rack.add(box(.85,.35,.85,WOOD2,x,.18,-5.6));
rack.add(box(.9,.3,.9,IRON,x,7.15,-5.6));
}
[-10.5,-3.5,3.5,10.5].forEach(post);
rack.add(box(21.9,.55,.55,WOOD,0,6.9,-5.6)); // top rail
rack.add(box(21.9,.45,.45,WOOD2,0,3.4,-5.6)); // back rail
rack.add(box(21.4,.28,1.7,WOOD2,0,2.4,-5.6)); // shelf
rack.add(box(21.4,.3,.4,WOOD,0,.5,-5.9)); // stretcher
for(let i=0;i<10;i++) rack.add(box(.35,.28,1.7,WOOD,-10+i*2.2,2.4,-5.6));
for(let i=0;i<14;i++){ // hooks under the top rail
const h=box(.12,.45,.12,IRON,-9.9+i*1.55,6.42,-5.6,{metalness:.7,roughness:.35});
rack.add(h); rack.add(box(.42,.12,.12,IRON,-9.9+i*1.55+0.15,6.2,-5.6,{metalness:.7,roughness:.35}));
}
/* hanging lanterns */
[[ -6.6, 6.0 ],[6.6,6.0]].forEach(([lx,ly])=>{
rack.add(box(.08,.8,.08,IRON,lx,ly+0.5,-5.6,{metalness:.7}));
const l=box(.55,.7,.55,0xffd9a0,lx,ly,-5.6,{emissive:0xffb45a,emissiveIntensity:2.2,roughness:.4});
rack.add(l);
});
/* ----------------------------------------------------------- kit builders */
const STATION_X=[-7,0,7];
const DEFS=[
{id:'knight',name:'Knight Kit', accent:0x5b8ddb,tunic:0x2f4a7d,tunic2:0x223a63,belt:0x3a3f4d,trim:0xd9e0ec},
{id:'ranger',name:'Forest Ranger',accent:0x7ab552,tunic:0x3d6b39,tunic2:0x2f522c,belt:0x5a4327,trim:0xc9a35b},
{id:'jester',name:'Court Jester', accent:0xe07b3c,tunic:0xb0384f,tunic2:0x8d2a3d,belt:0x2a2233,trim:0xf2c14e}
];
function buildTunic(d){
const g=new THREE.Group();
g.add(box(.1,.7,.1,0x9aa5b2,0,.35,0,{metalness:.7,roughness:.35}));
g.add(box(.34,.12,.12,0x9aa5b2,.13,.72,0,{metalness:.7,roughness:.35}));
g.add(box(1.35,1.5,.35,d.tunic,0,-1.05,0));
g.add(box(1.7,.45,.42,d.tunic2,0,-.2,0));
g.add(box(.45,1.0,.35,d.tunic,-1.05,-.65,0));
g.add(box(.45,1.0,.35,d.tunic, 1.05,-.65,0));
g.add(box(.5,.2,.38,d.trim,-1.05,-1.2,0));
g.add(box(.5,.2,.38,d.trim, 1.05,-1.2,0));
g.add(box(.6,.3,.44,d.trim,0,.1,0));
g.add(box(1.4,.22,.38,d.trim,0,-1.85,0));
g.add(box(.55,.55,.12,d.accent,0,-.85,.2));
g.add(box(.22,.22,.18,d.trim,0,-.85,.27));
return g;
}
function buildHangingBelt(d){
const g=new THREE.Group();
g.add(box(.1,.6,.1,0x9aa5b2,0,.35,0,{metalness:.7}));
for(let i=0;i<5;i++) g.add(box(.25,.25,.2,d.belt,-.5+i*.25,-.05,0));
for(let i=0;i<5;i++) g.add(box(.25,.25,.2,d.belt,-.5+i*.25,-.95,0));
for(let i=0;i<2;i++){ g.add(box(.25,.3,.2,d.belt,-.5,-.35+i*.3,0)); g.add(box(.25,.3,.2,d.belt,.5,-.35+i*.3,0)); }
g.add(box(.4,.32,.26,0xd9b44a,0,-.95,.1,{metalness:.75,roughness:.3}));
g.add(box(.25,.55,.2,d.belt,.15,-1.2,0));
return g;
}
function buildBin(d){
const g=new THREE.Group(), W=0x8a6a44, W2=0x6d5236;
g.add(box(1.9,.16,1.4,W,0,.08,0));
g.add(box(1.9,.8,.16,W,0,.48,.68));
g.add(box(1.9,.8,.16,W,0,.48,-.68));
g.add(box(.16,.8,1.4,W2,-.92,.48,0));
g.add(box(.16,.8,1.4,W2, .92,.48,0));
g.add(box(1.95,.16,1.45,W2,0,.92,0));
// contents per kit
if(d.id==='knight'){
g.add(box(.85,.5,.7,0xb9c4d2,0,.42,-.15,{metalness:.5,roughness:.4}));
g.add(box(.7,.12,.12,0x2a2f38,0,.42,.24));
g.add(box(.14,1.7,.14,0xd6dde8,.6,.95,.1,{metalness:.7,roughness:.3}));
g.add(box(.5,.16,.16,0x7a5a34,.6,.42,.1,{metalness:.6}));
g.add(box(.45,.45,.2,0x5b8ddb,-.55,.4,.42));
} else if(d.id==='ranger'){
g.add(box(1.1,.14,.9,0x5a4327,0,.3,0));
g.add(box(.6,.42,.6,0x6d5236,0,.55,0));
g.add(box(.85,.2,.85,0x7ab552,0,.8,0));
g.add(box(.5,.5,.45,0x8a6a44,-.5,.42,.3));
g.add(box(.3,.7,.3,0x3d6b39,.55,.5,-.2));
for(let i=0;i<4;i++) g.add(box(.05,.9,.05,0xc9a35b,.35+i*.14,1.05,-.2));
} else {
g.add(box(.9,.45,.8,0xb0384f,0,.38,0));
g.add(box(.45,.25,.45,0xf2c14e,0,.72,0));
for(let i=0;i<3;i++){
g.add(box(.12,.55,.12,0xf2c14e,(i-1)*.38,.75,.1));
g.add(box(.22,.22,.22,0xf2c14e,(i-1)*.38,1.05,.1));
}
g.add(box(.6,.4,.16,0xf2c14e,-.5,.36,.45));
g.add(box(.12,.12,.06,0x2a2233,-.62,.38,.54));
g.add(box(.12,.12,.06,0x2a2233,-.38,.38,.54));
g.add(box(.1,1.3,.1,0x6b4f3a,.55,.75,-.35));
g.add(box(.3,.3,.3,0xf2c14e,.55,1.45,-.35));
}
return g;
}
function buildWornBelt(d){
const g=new THREE.Group();
g.add(box(1.5,.28,.18,d.belt,0,0,.36));
g.add(box(1.5,.28,.18,d.belt,0,0,-.36));
g.add(box(.18,.28,.55,d.belt,-.66,0,0));
g.add(box(.18,.28,.55,d.belt, .66,0,0));
g.add(box(.36,.3,.14,0xd9b44a,0,0,.47,{metalness:.75,roughness:.3}));
return g;
}
function buildMannequin(d){
const g=new THREE.Group(), WD=0xd8b08a, WD2=0xb98f68;
g.add(box(2.3,.3,2.3,0x4a4a56,0,.15,0));
g.add(box(1.9,.12,1.9,0x5d5d6a,0,.36,0));
g.add(box(.5,1.1,.5,WD,-.35,.97,0));
g.add(box(.5,1.1,.5,WD, .35,.97,0));
g.add(box(.56,.2,.78,WD2,-.35,.45,.1));
g.add(box(.56,.2,.78,WD2, .35,.45,.1));
g.add(box(1.3,.45,.55,WD2,0,1.745,0));
g.add(box(1.35,1.05,.6,WD,0,2.495,0));
g.add(box(.3,.9,.35,WD,-.85,2.62,0));
g.add(box(.3,.9,.35,WD, .85,2.62,0));
g.add(box(.5,.2,.2,WD2,0,3.1,0));
g.add(box(.8,.8,.78,WD,0,3.6,0));
g.add(box(.82,.22,.8,WD2,0,4.06,0));
// worn costume
g.add(box(1.48,1.1,.68,d.tunic,0,2.5,0));
g.add(box(1.72,.28,.74,d.tunic2,0,3.04,0));
g.add(box(.42,.9,.42,d.tunic,-.95,2.6,0));
g.add(box(.42,.9,.42,d.tunic, .95,2.6,0));
g.add(box(1.52,.2,.7,d.trim,0,1.93,0));
g.add(box(.5,.5,.14,d.accent,0,2.55,.35));
const belt=buildWornBelt(d); belt.position.y=2.05; g.add(belt);
return {group:g, wornBelt:belt};
}
/* ------------------------------------------------------------ label sprite */
function makeLabel(text,color='#ffffff'){
const c=document.createElement('canvas'); c.width=320;c.height=72;
const x=c.getContext('2d');
x.fillStyle='rgba(10,14,22,.72)'; x.fillRect(0,0,320,72);
x.strokeStyle=color; x.lineWidth=4; x.strokeRect(4,4,312,64);
x.font='bold 30px "Courier New",monospace'; x.textAlign='center'; x.textBaseline='middle';
x.fillStyle=color; x.fillText(text.toUpperCase(),160,38);
const t=new THREE.CanvasTexture(c); t.magFilter=THREE.NearestFilter;
const s=new THREE.Sprite(new THREE.SpriteMaterial({map:t,transparent:true}));
s.scale.set(3.1,.7,1);
return s;
}
/* ------------------------------------------------- assemble costume kits */
const COSTUMES=[];
DEFS.forEach((d,i)=>{
const g=new THREE.Group(); g.userData.costumeId=d.id; scene.add(g);
const sx=STATION_X[i];
// rug marks the station and belongs to the kit group
g.add(box(3.4,.07,3.2,d.tunic2,sx,.04,.6));
const tunic=buildTunic(d); tunic.position.set(sx-2.3,5.75,-5.6); g.add(tunic);
const hbelt=buildHangingBelt(d); hbelt.position.set(sx+.05,5.95,-5.25); g.add(hbelt);
const bin=buildBin(d); bin.position.set(sx+2.5,2.56,-5.6); g.add(bin);
const man=buildMannequin(d); man.group.position.set(sx,0,.5); g.add(man.group);
const lab=makeLabel(d.name,'#'+d.accent.toString(16).padStart(6,'0'));
lab.position.set(sx,4.95,.5); g.add(lab);
COSTUMES.push({...d, group:g, stationX:sx, wornBelt:man.wornBelt, beltBaseY:2.05});
});
/* --------------------------------------------------------- the helper */
function buildHelper(){
const g=new THREE.Group();
const SKIN=0xecb98d, SHIRT=0x3fa89a, SHIRT2=0x2f8a7e, PANTS=0x33415c,
APRON=0xf0d089, HAIR=0x4a2f1d, BOOT=0x2a2320;
const rig=new THREE.Group(); g.add(rig);
const mkArm=(sx)=>{
const p=new THREE.Group(); p.position.set(sx,2.3,0); rig.add(p);
p.add(box(.3,.8,.3,SHIRT,0,-.4,0));
p.add(box(.33,.28,.33,SKIN,0,-.92,0));
return p;
};
const mkLeg=(sx)=>{
const p=new THREE.Group(); p.position.set(sx,1.25,0); g.add(p);
p.add(box(.4,.75,.4,PANTS,0,-.375,0));
p.add(box(.45,.3,.62,BOOT,0,-.9,.08));
return p;
};
const armL=mkArm(-.66), armR=mkArm(.66);
const legL=mkLeg(-.28), legR=mkLeg(.28);
rig.add(box(1.05,1.1,.55,SHIRT,0,1.8,0));
rig.add(box(1.12,.28,.58,SHIRT2,0,2.22,0));
rig.add(box(.85,.95,.12,APRON,0,1.78,-.31));
rig.add(box(.85,.18,.14,APRON,0,1.28,-.31));
rig.add(box(.3,.2,.3,SKIN,0,2.45,0));
rig.add(box(.65,.65,.62,SKIN,0,2.85,0));
rig.add(box(.68,.22,.64,HAIR,0,3.12,0));
rig.add(box(.68,.18,.2,HAIR,0,2.95,-.28));
rig.add(box(.12,.12,.08,0x22262f,-.16,2.88,-.32));
rig.add(box(.12,.12,.08,0x22262f, .16,2.88,-.32));
rig.add(box(.14,.1,.08,SKIN,0,2.68,-.33));
return {group:g,rig,armL,armR,legL,legR};
}
const helper=buildHelper(); scene.add(helper.group);
helper.group.position.set(-9,0,1.85);
/* -------------------------------------------------- sparkle voxels (fx) */
const sparks=new THREE.Group(); scene.add(sparks);
const sparkList=[];
for(let i=0;i<14;i++){
const s=box(.09,.09,.09,0xffe9a8,0,0,0,{emissive:0xffcf6a,emissiveIntensity:1.6});
s.castShadow=false; s.visible=false; sparks.add(s);
sparkList.push({m:s,ph:i/14*Math.PI*2,sp:.5+Math.random()*.8,r:.2+Math.random()*.45});
}
/* ------------------------------------------------------- set dressing */
function buildProps(){
const W=0x8a5a3b, W2=0x6f452c;
// stool
const st=new THREE.Group(); st.position.set(-11.6,0,2.4);
st.add(box(1.3,.16,1.3,0x9a6a44,0,1.5,0));
[[-.5,-.5],[.5,-.5],[-.5,.5],[.5,.5]].forEach(([x,z])=>st.add(box(.18,1.5,.18,W2,x,.75,z)));
scene.add(st);
// fabric bolts
const fb=new THREE.Group(); fb.position.set(11.8,0,2.6);
const cols=[0x2f4a7d,0x3d6b39,0xb0384f];
for(let i=0;i<3;i++) fb.add(box(1.5,.5,2.2,cols[i],0,.26+i*.5,0));
fb.add(box(.2,.2,2.3,0xd8cbb0,0,1.0,0));
scene.add(fb);
// potted plant
const pl=new THREE.Group(); pl.position.set(13.6,0,1.2);
pl.add(box(.9,.7,.9,0xa06a45,0,.35,0));
pl.add(box(.35,1.3,.35,0x4a7a3a,0,1.3,0));
for(let i=0;i<4;i++){
const a=i*Math.PI/2;
pl.add(box(.75,.3,.35,0x5f9a45,Math.cos(a)*.45,1.65+Math.random()*.4,Math.sin(a)*.45));
}
scene.add(pl);
// ladder
const ld=new THREE.Group(); ld.position.set(13.2,0,-4.2); ld.rotation.z=-0.16;
ld.add(box(.16,5.6,.16,W,-.5,2.8,0));
ld.add(box(.16,5.6,.16,W, .5,2.8,0));
for(let i=0;i<6;i++) ld.add(box(1.0,.14,.14,W2,0,.6+i*.9,0));
scene.add(ld);
}
buildProps();
/* ------------------------------------------------------- camera (custom) */
let az=0.0, pol=1.16, rad=27;
const tgt=new THREE.Vector3(0,2.9,-1.2);
let autoOrbit=false;
function updateCam(){
const x=tgt.x+rad*Math.sin(pol)*Math.sin(az);
const y=tgt.y+rad*Math.cos(pol);
const z=tgt.z+rad*Math.sin(pol)*Math.cos(az);
camera.position.set(x,y,z); camera.lookAt(tgt);
}
let drag=false, px=0, py=0, panning=false, moved=0;
renderer.domElement.addEventListener('pointerdown',e=>{
drag=true;panning=e.shiftKey||e.button===2;moved=0;px=e.clientX;py=e.clientY;
renderer.domElement.setPointerCapture(e.pointerId);
});
renderer.domElement.addEventListener('pointermove',e=>{
if(!drag)return;
const dx=e.clientX-px, dy=e.clientY-py; px=e.clientX;py=e.clientY; moved+=Math.abs(dx)+Math.abs(dy);
if(panning){
const right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
tgt.addScaledVector(right,-dx*rad*0.0016).addScaledVector(up,dy*rad*0.0016);
}else{
az-=dx*0.006; pol=clamp(pol-dy*0.005,0.22,1.48);
}
updateCam();
});
addEventListener('pointerup',()=>{drag=false;});
renderer.domElement.addEventListener('contextmenu',e=>e.preventDefault());
renderer.domElement.addEventListener('wheel',e=>{
e.preventDefault(); rad=clamp(rad*(1+Math.sign(e.deltaY)*0.08),7,60); updateCam();
},{passive:false});
addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
/* ------------------------------------------------------------- selection */
const ray=new THREE.Raycaster(), mouse=new THREE.Vector2();
let focusId=null;
function setFocus(id){
focusId=id;
COSTUMES.forEach(c=>{
const sel=(id===null)||(c.id===id);
c.group.traverse(o=>{
if(!o.isMesh||!o.userData.base)return;
if(sel){ o.material.color.copy(o.userData.base); o.material.emissive.set(c.accent); o.material.emissiveIntensity=.10; }
else{ o.material.color.copy(o.userData.base).lerp(BG,.55); o.material.emissive.set(0x000000); o.material.emissiveIntensity=0; }
});
});
updateRows();
const c=COSTUMES.find(c=>c.id===id);
if(c){ tgt.set(c.stationX,2.6,.4); rad=13; }
else { tgt.set(0,2.9,-1.2); rad=27; }
updateCam();
}
renderer.domElement.addEventListener('pointerup',e=>{
if(moved>6)return;
mouse.x=(e.clientX/innerWidth)*2-1; mouse.y=-(e.clientY/innerHeight)*2+1;
ray.setFromCamera(mouse,camera);
const hits=ray.intersectObjects(scene.children,true).filter(h=>h.object.isMesh);
if(hits.length){
let o=hits[0].object;
while(o){ if(o.userData.costumeId){ setFocus(focusId===o.userData.costumeId?null:o.userData.costumeId); return; } o=o.parent; }
}
setFocus(null);
});
/* ------------------------------------------------------------------- UI */
const rowsEl=document.getElementById('rows'), statusEl=document.getElementById('status');
function updateRows(){
[...rowsEl.children].forEach(r=>{
r.classList.toggle('on', r.dataset.id===focusId);
r.style.opacity = r.style.opacity; // keep
});
}
COSTUMES.forEach(c=>{
const row=document.createElement('div'); row.className='crow'; row.dataset.id=c.id;
row.innerHTML=`<label class="sw"><input type="checkbox" checked><i style="background:#${c.accent.toString(16).padStart(6,'0')}"></i></label>
<span class="nm">${c.name}</span><button>focus</button>`;
row.querySelector('input').addEventListener('change',e=>{ c.group.visible=e.target.checked; });
row.querySelector('button').addEventListener('click',()=>setFocus(focusId===c.id?null:c.id));
rowsEl.appendChild(row);
});
document.getElementById('allBtn').onclick=()=>setFocus(null);
document.getElementById('orbitBtn').onclick=e=>{ autoOrbit=!autoOrbit; e.target.textContent=autoOrbit?'Stop orbit':'Auto-orbit'; };
addEventListener('keydown',e=>{
if(e.key==='1')setFocus(null);
if(e.key==='2')setFocus('knight');
if(e.key==='3')setFocus('ranger');
if(e.key==='4')setFocus('jester');
});
/* ------------------------------------------------------------- animation */
const clock=new THREE.Clock();
let hState='walk', hTarget=0, hAdjust=0, walkPhase=0;
const stations=STATION_X.slice();
function updateHelper(dt,t){
const g=helper.group;
COSTUMES.forEach(c=>{ c.wornBelt.scale.set(1,1,1); c.wornBelt.position.y=c.beltBaseY; });
if(hState==='walk'){
const tx=stations[hTarget], dx=tx-g.position.x;
if(Math.abs(dx)<.07){ g.position.x=tx; hState='adjust'; hAdjust=0; }
else{
const sp=2.7, step=Math.sign(dx)*Math.min(Math.abs(dx),sp*dt);
g.position.x+=step; g.position.z=1.85;
g.rotation.y=lerpAngle(g.rotation.y, dx>0?-Math.PI/2:Math.PI/2, 1-Math.exp(-9*dt));
walkPhase+=dt*8.2;
const sw=Math.sin(walkPhase)*.52;
helper.legL.rotation.x=sw; helper.legR.rotation.x=-sw;
helper.armL.rotation.x=-sw*.55; helper.armR.rotation.x=sw*.55;
helper.armL.rotation.z=lerp(helper.armL.rotation.z,0,1-Math.exp(-8*dt));
helper.armR.rotation.z=lerp(helper.armR.rotation.z,0,1-Math.exp(-8*dt));
helper.rig.position.y=Math.abs(Math.cos(walkPhase))*.05;
}
}else{
hAdjust+=dt;
g.rotation.y=lerpAngle(g.rotation.y,0,1-Math.exp(-8*dt));
const ramp=smooth(clamp(hAdjust/1.1,0,1))*(1-smooth(clamp((hAdjust-3.1)/.9,0,1)));
const wig=Math.sin(t*9)*.07*ramp;
helper.armL.rotation.x=1.25*ramp+wig; helper.armR.rotation.x=1.25*ramp-wig;
helper.armL.rotation.z=-.13*ramp; helper.armR.rotation.z=.13*ramp;
helper.legL.rotation.x=lerp(helper.legL.rotation.x,0,1-Math.exp(-7*dt));
helper.legR.rotation.x=lerp(helper.legR.rotation.x,0,1-Math.exp(-7*dt));
helper.rig.position.y=lerp(helper.rig.position.y,0,1-Math.exp(-7*dt));
const c=COSTUMES[hTarget], b=c.wornBelt;
b.scale.x=1+.05*Math.sin(t*10)*ramp; b.scale.z=1+.03*Math.sin(t*10)*ramp;
b.position.y=c.beltBaseY+.035*Math.sin(t*8)*ramp;
// sparkle burst at the buckle
const on=ramp>.05;
sparks.visible=on;
if(on){
sparks.position.set(c.stationX,2.05,.5);
sparkList.forEach(s=>{
const a=t*2.2+s.ph;
s.m.visible=true;
s.m.position.set(Math.cos(a)*s.r, ((t*s.sp+s.ph)%1.6)*.8-.3, Math.sin(a)*s.r*.6);
s.m.rotation.set(a,a*1.3,a*.7);
});
} else sparkList.forEach(s=>s.m.visible=false);
if(hAdjust>4.3){ hTarget=(hTarget+1)%COSTUMES.length; hState='walk'; }
}
// status readout
const c=COSTUMES[hTarget];
if(hState==='adjust'){
statusEl.innerHTML=`Helper: <b>tightening the belt</b> on the <b>${c.name}</b> mannequin.<br>Kit group highlighted: tunic, belt, bin, rug.`;
}else{
statusEl.innerHTML=`Helper: walking toward the <b>${c.name}</b> station.<br>Tip: click a kit on the rack to focus its group.`;
}
}
setFocus(null);
updateCam();
function animate(){
requestAnimationFrame(animate);
const dt=Math.min(clock.getDelta(),.05), t=clock.elapsedTime;
updateHelper(dt,t);
if(autoOrbit) az+=dt*.12;
updateCam();
renderer.render(scene,camera);
}
animate();
</script>
</body>
</html>
```