Prompt specification
Build or customize the Three.js 3D scene "Inclusive community cloakroom" 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: Inclusive community cloakroom
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inclusive-community-cloakroom-x0008
Scene Description Prompt:
Create a low-poly cloakroom with high and low hooks; selected visitors demonstrate unobstructed reach. Three.js from cdnjs in one HTML file.
Working Three.js Starter (inclusive-community-cloakroom-x0008):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cloakroom — Reach & Obstruction Study</title>
<style>
:root{
--bg:#0f1319; --panel:#161c25; --line:#2b3441; --ink:#e9eef6; --dim:#8d9aab;
--ok:#53e08a; --bad:#ff6b6b; --hi:#4d8fbd; --lo:#c88a4a;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:var(--bg);color:var(--ink);
font-family:ui-sans-serif,system-ui,"Segoe UI",Roboto,Helvetica,Arial}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
.card{position:fixed;background:rgba(22,28,37,.92);border:1px solid var(--line);
border-radius:4px;backdrop-filter:blur(3px)}
#title{left:16px;top:14px;padding:12px 16px}
#title h1{margin:0;font-size:20px;letter-spacing:.22em;font-weight:700}
#title p{margin:4px 0 0;font-size:11px;color:var(--dim);letter-spacing:.12em;text-transform:uppercase}
#panel{left:16px;top:92px;width:286px;padding:12px 14px 14px;max-height:calc(100vh - 120px);overflow:auto}
#panel h2{margin:0 0 8px;font-size:10px;letter-spacing:.2em;color:var(--dim);text-transform:uppercase}
.vlist{display:flex;flex-direction:column;gap:4px;margin-bottom:10px}
.vbtn{display:flex;justify-content:space-between;align-items:center;gap:8px;width:100%;
background:#1e2632;border:1px solid #2b3441;color:var(--ink);border-radius:3px;padding:7px 9px;
font:inherit;font-size:12.5px;cursor:pointer;text-align:left}
.vbtn:hover{background:#253040;border-color:#3c485a}
.vbtn.sel{background:#2a3a4d;border-color:var(--hi);box-shadow:inset 3px 0 0 var(--hi)}
.vbtn .h{font-size:11px;color:var(--dim);font-variant-numeric:tabular-nums}
.vbtn.sel .h{color:#b9c6d6}
#detail{border-top:1px solid var(--line);padding-top:10px;font-size:12.5px;line-height:1.55}
#detail .big{font-size:15px;font-weight:600;margin-bottom:2px}
#detail .sub{color:var(--dim);font-size:11px;margin-bottom:8px}
.stat{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:8px}
.chip{border:1px solid var(--line);background:#1b2husk;padding:2px 7px;border-radius:2px;font-size:11px}
.chip.ok{color:var(--ok);border-color:#2c5c41}
.chip.bad{color:var(--bad);border-color:#5c2c2c}
.chip.taken{color:#9aa7b7;border-color:#39424f}
.rows{margin:0;padding:0;list-style:none}
.rows li{display:flex;justify-content:space-between;gap:8px;padding:2px 0;border-bottom:1px dotted #222b37;font-size:11.5px}
.rows li span:last-child{color:var(--dim);text-align:right}
.ctrls{display:flex;flex-wrap:wrap;gap:6px;margin-top:11px;border-top:1px solid var(--line);padding-top:10px}
.ctrls button,.ctrls label{font:inherit;font-size:11px;background:#1e2632;color:var(--ink);
border:1px solid #39424f;border-radius:3px;padding:5px 9px;cursor:pointer;user-select:none}
.ctrls button:hover,.ctrls label:hover{background:#27313f}
.ctrls label{display:flex;align-items:center;gap:5px}
#legend{right:16px;bottom:16px;padding:10px 13px;font-size:11px;line-height:1.9;color:var(--dim)}
#legend b{color:var(--ink);font-weight:600}
#legend .k{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:7px;vertical-align:1px}
#hint{left:50%;transform:translateX(-50%);bottom:16px;padding:7px 14px;font-size:11px;
color:var(--dim);letter-spacing:.05em;white-space:nowrap}
#tip{position:fixed;pointer-events:none;display:none;background:rgba(12,16,22,.95);
border:1px solid var(--line);border-radius:3px;padding:5px 9px;font-size:11.5px;z-index:5;max-width:230px}
#tip b{color:#fff}
#tip .r{color:var(--dim)}
@media(max-width:820px){#panel{width:238px}#legend{display:none}#hint{display:none}}
</style>
</head>
<body>
<div id="app"></div>
<div id="title" class="card">
<h1>CLOAKROOM</h1>
<p>Reach & obstruction study · low poly</p>
</div>
<div id="panel" class="card">
<h2>Visitors</h2>
<div class="vlist" id="vlist"></div>
<div id="detail"></div>
<div class="ctrls">
<button id="tour">Auto tour</button>
<button id="reset">Reset view</button>
<label><input type="checkbox" id="lbl" checked> labels</label>
<label><input type="checkbox" id="sph" checked> reach shell</label>
</div>
</div>
<div id="legend" class="card">
<div><span class="k" style="background:#53e08a"></span><b>clear</b> — reachable, line of sight unobstructed</div>
<div><span class="k" style="background:#ff6b6b"></span><b>blocked</b> — arm span fits, path obstructed</div>
<div><span class="k" style="background:#98a4b3"></span><b>taken</b> — a coat is already hanging</div>
<div><span class="k" style="background:#39424f"></span><b>out of reach</b> — beyond arm span</div>
</div>
<div id="hint" class="card">drag to orbit · wheel zoom · right-drag pan · click a visitor, then a hook</div>
<div id="tip"></div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ───────────────────────────── renderer / scene ───────────────────────────── */
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.outputColorSpace = THREE.SRGBColorSpace;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0f1319);
scene.fog = new THREE.Fog(0x0f1319, 22, 46);
const camera = new THREE.PerspectiveCamera(40, innerWidth/innerHeight, 0.1, 120);
/* ───────────────────────────── helpers ───────────────────────────── */
const M = (c,o={}) => new THREE.MeshStandardMaterial({ color:c, roughness:.88, metalness:0, flatShading:true, ...o });
const matWall = M(0x5f6b79);
const matLower = M(0x4a5461);
const matBeam = M(0x39424e);
const matWood = M(0xa9794c);
const matWood2 = M(0x8a6239);
const matBrass = M(0xd8a94a,{metalness:.65,roughness:.35});
const matSteel = M(0x9aa6b2,{metalness:.5,roughness:.45});
const matHi = M(0x35566e);
const matLo = M(0x6d4a2c);
const matGreen = M(0x3f7a55);
const matLeaf = M(0x4e7f4a);
const matLeaf2 = M(0x3d6b3e);
const matPot = M(0x9c5a44);
function add(geo, material, x=0,y=0,z=0, parent=scene){
const m = new THREE.Mesh(geo, material);
m.position.set(x,y,z);
m.castShadow = true; m.receiveShadow = true;
parent.add(m); return m;
}
function box(w,h,d,material,x,y,z,parent=scene){
return add(new THREE.BoxGeometry(w,h,d), material, x,y,z,parent);
}
function cyl(rt,rb,h,seg,material,x,y,z,parent=scene){
return add(new THREE.CylinderGeometry(rt,rb,h,seg), material, x,y,z,parent);
}
function ico(r,material,x,y,z,parent=scene,det=0){
return add(new THREE.IcosahedronGeometry(r,det), material, x,y,z,parent);
}
/* canvas helpers */
function canvasTex(w,h,draw){
const c=document.createElement('canvas'); c.width=w; c.height=h;
draw(c.getContext('2d'),w,h);
const t=new THREE.CanvasTexture(c); t.colorSpace=THREE.SRGBColorSpace; return t;
}
function checkerTexture(a,b,n=8){
const t=canvasTex(256,256,(g)=>{
const s=256/n;
for(let i=0;i<n;i++) for(let j=0;j<n;j++){
g.fillStyle=((i+j)%2)?a:b; g.fillRect(i*s,j*s,s,s);
}
});
t.wrapS=t.wrapT=THREE.RepeatWrapping; t.repeat.set(6.5,4.5); return t;
}
function textSprite(text,{bg='rgba(16,20,26,.72)',fg='#e9eef6',fs=44,w=256,h=64,scale=[0.44,0.11]}={}){
const t=canvasTex(w,h,(g)=>{
g.fillStyle=bg; g.fillRect(0,0,w,h);
g.fillStyle=fg; g.font=`600 ${fs}px ui-sans-serif,system-ui,sans-serif`;
g.textAlign='center'; g.textBaseline='middle'; g.fillText(text,w/2,h/2+1);
});
const s=new THREE.Sprite(new THREE.SpriteMaterial({map:t,transparent:true,depthTest:false}));
s.scale.set(scale[0],scale[1],1); s.renderOrder=8; return s;
}
/* ───────────────────────────── room ───────────────────────────── */
const RW=13, RD=9, RH=4, WALLZ=-4.5;
const floorTex = checkerTexture('#8b8172','#9a9080');
const floor = add(new THREE.PlaneGeometry(RW,RD), M(0xffffff,{map:floorTex}), 0,0,0);
floor.rotation.x = -Math.PI/2; floor.castShadow=false;
box(RW,RH,0.2,matWall,0,RH/2,WALLZ-0.1);
box(RW,0.95,0.06,matLower,0,0.475,WALLZ+0.02);
box(RW,0.07,0.05,matWood2,0,0.95,WALLZ+0.05);
box(0.2,RH,RD,matWall,-RW/2-0.1,RH/2,0);
box(0.2,RH,RD,matWall, RW/2+0.1,RH/2,0);
box(RW,0.16,0.16,matBeam,0,RH-0.08,2.0);
box(RW,0.16,0.16,matBeam,0,RH-0.08,-1.4);
box(0.16,0.16,RD,matBeam,-3.2,RH-0.08,0);
box(0.16,0.16,RD,matBeam, 3.2,RH-0.08,0);
/* pilaster (shallow, hooks pass in front of it) */
box(0.52,RH,0.14,matLower,0,RH/2,WALLZ+0.07);
box(0.66,0.12,0.2,matWood2,0,RH-0.06,WALLZ+0.1);
/* wall signage */
{
const t=canvasTex(1024,200,(g,w,h)=>{
g.fillStyle='#22303c'; g.fillRect(0,0,w,h);
g.strokeStyle='#d8a94a'; g.lineWidth=6; g.strokeRect(8,8,w-16,h-16);
g.fillStyle='#f2f6fb'; g.font='700 92px ui-sans-serif,system-ui'; g.textAlign='center';
g.textBaseline='middle'; g.fillText('C L O A K R O O M',w/2,h/2-4);
});
const sign=add(new THREE.PlaneGeometry(4.4,0.86), new THREE.MeshBasicMaterial({map:t}), 0,3.42,WALLZ+0.02);
sign.castShadow=false;
}
function plaque(text,y){
const t=canvasTex(512,80,(g,w,h)=>{
g.fillStyle='#1b2632'; g.fillRect(0,0,w,h);
g.fillStyle='#8fa3b8'; g.font='600 34px ui-sans-serif,system-ui'; g.textAlign='center';
g.textBaseline='middle'; g.fillText(text,w/2,h/2+1);
});
const p=add(new THREE.PlaneGeometry(2.6,0.41), new THREE.MeshBasicMaterial({map:t,transparent:true}), 0,y,WALLZ+0.03);
p.castShadow=false;
}
plaque('HIGH HOOKS · 2.30 m', 2.72);
plaque('LOW HOOKS · 1.25 m', 1.66);
/* ───────────────────────────── hooks ───────────────────────────── */
const HOOK_Z = -4.06;
const hooks = [];
const pickables = [];
function makeCoat(color,scale=1){
const g=new THREE.Group();
const body=add(new THREE.CylinderGeometry(0.15,0.33,0.78,6), M(color), 0,-0.42,0,g);
const sh=box(0.40,0.13,0.22,M(color),0,-0.05,0,g);
const col=cyl(0.10,0.12,0.12,6,M(color),0,0.02,0,g);
g.scale.setScalar(scale);
return g;
}
const rows=[
{id:'high', y:2.30, cap:'H', plate:matHi},
{id:'low', y:1.25, cap:'L', plate:matLo}
];
const HOOK_X=[]; for(let i=0;i<11;i++) HOOK_X.push((i-5)*0.9);
/* rails */
box(12.0,0.17,0.09,matWood,0,2.38,WALLZ+0.05);
box(12.0,0.17,0.09,matWood,0,1.33,WALLZ+0.05);
rows.forEach(row=>{
HOOK_X.forEach((x,i)=>{
const num=i+1;
/* backing plate on the wall */
const plate=add(new THREE.CircleGeometry(0.115,10), row.plate, x,row.y,WALLZ+0.012);
plate.castShadow=false;
/* peg */
const peg=box(0.085,0.085,0.36,matBrass,x,row.y,WALLZ+0.17);
const tip=box(0.085,0.17,0.085,matBrass,x,row.y+0.075,WALLZ+0.35);
/* status light */
const light=add(new THREE.OctahedronGeometry(0.082,0),
new THREE.MeshBasicMaterial({color:0x39424f}), x,row.y+0.075,HOOK_Z+0.03);
light.castShadow=false; light.visible=false;
/* number label */
const lab=textSprite(`${row.cap}${num}`,{bg:'rgba(16,20,26,.62)',fg:'#b9c6d6',fs:38,w:200,h:70,scale:[0.40,0.14]});
lab.position.set(x,row.y+0.33,HOOK_Z); scene.add(lab);
/* invisible pick target */
const pick=add(new THREE.SphereGeometry(0.16,8,6),
new THREE.MeshBasicMaterial({transparent:true,opacity:0,depthWrite:false}), x,row.y,HOOK_Z);
pick.castShadow=false; pick.userData={type:'hook',hook:null};
const h={ id:`${row.cap}${num}`, row:row.id, x, y:row.y, z:HOOK_Z, peg, tip, light, label:lab,
occupied:false, coat:null };
pick.userData.hook=h;
pickables.push(pick);
hooks.push(h);
});
});
/* pre-hung coats */
const taken=[['high',-1.8],['low',2.7],['high',4.5]];
const coatColors=[0xc85b4b,0x4f8ac9,0x6bbf7a,0xd9a441,0x8d6bb5,0x4c6f8f];
taken.forEach(([r,x],i)=>{
const h=hooks.find(o=>o.row===r&&Math.abs(o.x-x)<0.01);
if(h){ h.occupied=true; const c=makeCoat(coatColors[i%coatColors.length]); c.position.set(h.x,h.y,HOOK_Z+0.03); scene.add(c); h.coat=c; }
});
/* ───────────────────────────── obstacles ───────────────────────────── */
const obstacles=[];
function obstacle(name,min,max){ obstacles.push({name,min,max}); }
/* luggage trolley (blocks Ada's low hook) */
{
const x=-2.7, z=-2.92;
box(0.92,0.07,0.36,matSteel,x,0.17,z);
box(0.60,1.15,0.30,M(0x3f5a72),x,0.78,z);
box(0.16,0.36,0.06,matSteel,x-0.30,1.02,z);
box(0.16,0.36,0.06,matSteel,x+0.30,1.02,z);
box(0.66,0.05,0.05,matSteel,x,1.58,z);
cyl(0.06,0.06,0.05,8,matSteel,x-0.32,0.06,z-0.12).rotation.x=Math.PI/2;
cyl(0.06,0.06,0.05,8,matSteel,x+0.32,0.06,z-0.12).rotation.x=Math.PI/2;
obstacle('luggage trolley',{x:-3.16,y:0,z:-3.10},{x:-2.24,y:1.63,z:-2.74});
}
/* cabinet (blocks Ivo's left hook) */
{
const x=-4.75,z=-3.2;
box(1.10,2.45,0.80,matWood2,x,1.225,z);
box(1.16,0.08,0.86,matWood,x,2.49,z);
box(0.86,1.90,0.03,M(0x2f3a46),x,1.30,z+0.41);
box(0.05,0.26,0.05,matBrass,x+0.36,1.30,z+0.44);
obstacle('cabinet',{x:-5.30,y:0,z:-3.60},{x:-4.20,y:2.53,z:-2.80});
}
/* big plant (blocks Dmitri's right hook) */
{
const x=1.75,z=-2.9;
cyl(0.42,0.34,0.55,9,matPot,x,0.275,z);
cyl(0.07,0.09,1.45,6,M(0x6b563c),x,0.95,z);
ico(0.62,matLeaf,x,1.92,z);
ico(0.44,matLeaf2,x-0.34,1.62,z-0.06);
ico(0.40,matLeaf,x+0.32,1.70,z+0.05);
ico(0.30,matLeaf2,x+0.05,2.32,z-0.04);
obstacle('plant',{x:1.15,y:0,z:-3.40},{x:2.35,y:2.45,z:-2.40});
}
/* coat rack (blocks Bo's left low hook) */
{
const x=-0.7,z=-3.55;
cyl(0.035,0.035,1.78,6,matSteel,x-0.35,0.89,z);
cyl(0.035,0.035,1.78,6,matSteel,x+0.35,0.89,z);
box(0.86,0.05,0.05,matSteel,x,1.72,z);
box(0.86,0.04,0.42,matSteel,x,0.06,z);
[0x7f5aa8,0x4f8ac9,0xc85b4b].forEach((c,i)=>{
const co=makeCoat(c,0.92); co.position.set(x-0.28+i*0.28,1.72,z+0.02); scene.add(co);
});
obstacle('coat rack',{x:-1.10,y:0,z:-3.70},{x:-0.30,y:1.80,z:-3.40});
}
/* bench + counter + extras */
{
box(2.0,0.10,0.55,matWood,-5.3,0.45,0.9);
[-5.95,-4.65].forEach(x=>box(0.10,0.42,0.50,matWood2,x,0.21,0.9));
const c=makeCoat(0x9a5b8f,1.1); c.position.set(-5.9,0.95,0.92); c.rotation.z=0.15; scene.add(c);
/* counter */
box(2.3,0.92,0.72,matWood2,4.6,0.46,1.1);
box(2.42,0.09,0.82,matWood,4.6,0.97,1.1);
for(let i=0;i<7;i++) box(0.14,0.012,0.10,M(0xf2efe4),3.85+i*0.05,1.03,0.95);
cyl(0.09,0.09,0.13,8,matSteel,5.4,1.08,1.0);
}
[-6.0,6.0].forEach(x=>{
cyl(0.30,0.24,0.42,8,matPot,x,0.21,3.5);
ico(0.42,matLeaf,x,0.72,3.5);
ico(0.30,matLeaf2,x+0.16,0.95,3.5);
});
/* pendant lamps */
[-3.6,0.6,3.6].forEach((x,i)=>{
cyl(0.02,0.02,0.55,5,matSteel,x,3.55,0.2);
cyl(0.10,0.44,0.36,10,M(i===1?0xe8c07a:0xd7dde5),x,3.05,0.2);
const bulb=add(new THREE.SphereGeometry(0.13,8,6),new THREE.MeshBasicMaterial({color:0xffe6b8}),x,2.93,0.2);
bulb.castShadow=false;
const pl=new THREE.PointLight(0xffd9a0, i===1?26:16, 13, 2);
pl.position.set(x,2.9,0.2); scene.add(pl);
});
/* ───────────────────────────── lights ───────────────────────────── */
scene.add(new THREE.HemisphereLight(0xbcd2ea,0x38302a,0.85));
const sun=new THREE.DirectionalLight(0xffe6c4,1.15);
sun.position.set(5.5,8.5,7.5); sun.target.position.set(0,1,-2.5);
sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
Object.assign(sun.shadow.camera,{left:-9,right:9,top:9,bottom:-6,near:1,far:32});
sun.shadow.bias=-0.0012; sun.shadow.normalBias=0.02;
scene.add(sun,sun.target);
const fill=new THREE.DirectionalLight(0x93b4d8,0.35); fill.position.set(-6,4,-2); scene.add(fill);
/* ───────────────────────────── people ───────────────────────────── */
const visitors=[];
function makePerson(height,shirt,trouser,hair){
const g=new THREE.Group();
const s=height/1.80;
const skin=M(0xe8bd97), sk=M(0xcaa07c);
const legs=new THREE.Group(); g.add(legs);
[-0.11,0.11].forEach(x=>{
box(0.145,0.80,0.16,trouser,x,0.44,0,legs);
box(0.16,0.09,0.26,M(0x2a2f36),x,0.045,0.03,legs);
});
const torso=box(0.44,0.60,0.25,shirt,0,1.13,0,g);
box(0.50,0.13,0.26,shirt,0,1.42,0,g);
cyl(0.055,0.06,0.10,6,sk,0,1.50,0,g);
ico(0.145,sk,0,1.64,0,g);
cyl(0.145,0.145,0.07,8,hair,0,1.74,0,g);
const arms=[];
[-0.29,0.29].forEach((x,i)=>{
const a=new THREE.Group(); a.position.set(x,1.38,0); g.add(a);
box(0.10,0.34,0.11,shirt,0,-0.17,0,a);
box(0.09,0.24,0.10,sk,0,-0.44,0,a);
arms.push(a);
});
g.scale.setScalar(s);
g.userData={arms,torso,legs};
return g;
}
function addVisitor(name,role,height,x,z,colors){
const grp=makePerson(height,M(colors[0]),M(colors[1]),M(colors[2]));
grp.position.set(x,0,z); grp.rotation.y=Math.PI; scene.add(grp);
const pick=add(new THREE.BoxGeometry(0.62,height,0.55),
new THREE.MeshBasicMaterial({transparent:true,opacity:0,depthWrite:false}),x,height/2,z);
pick.castShadow=false;
const v={ name, role, height, pos:new THREE.Vector3(x,0,z), group:grp, arms:grp.userData.arms,
shoulderY:height*0.82, maxReach:height+0.18, occupied:false,
walk:null, armLift:0, pick };
pick.userData={type:'visitor',visitor:v};
pickables.push(pick);
visitors.push(v);
return v;
}
addVisitor('Ada K.','adult',1.78,-3.2,-2.4,[0x3f7f9c,0x37414d,0x2f2a26]);
addVisitor('Bo T.','child',1.36, 0.0,-2.85,[0xd06a4e,0x3c4550,0x4a3222]);
addVisitor('Cleo M.','teen',1.50, 3.6,-2.9,[0x5b8f5a,0x333b46,0x22201f]);
addVisitor('Dmitri S.','tall adult',1.94,0.5,-2.55,[0x6d5b9c,0x2f3742,0x3a2b22]);
addVisitor('Ivo P.','adult',1.62,-4.2,-2.4,[0x9c7b3f,0x3a3a42,0x2b2320]);
/* attendant behind the counter */
{
const a=makePerson(1.72,M(0x2f3a49),M(0x22282f),M(0x1d1a19));
a.position.set(4.6,0,0.25); scene.add(a);
}
/* ───────────────────────────── reach math ───────────────────────────── */
function inBox(p,b){ return p.x>=b.min.x&&p.x<=b.max.x&&p.y>=b.min.y&&p.y<=b.max.y&&p.z>=b.min.z&&p.z<=b.max.z; }
function segAABB(p0,p1,b){
let t0=0,t1=1;
for(const ax of ['x','y','z']){
const d=p1[ax]-p0[ax], mn=b.min[ax], mx=b.max[ax];
if(Math.abs(d)<1e-9){ if(p0[ax]<mn||p0[ax]>mx) return false; }
else{
let ta=(mn-p0[ax])/d, tb=(mx-p0[ax])/d;
if(ta>tb){const s=ta;ta=tb;tb=s;}
t0=Math.max(t0,ta); t1=Math.min(t1,tb);
if(t0>t1) return false;
}
}
return true;
}
function evaluate(v,h){
const s=new THREE.Vector3(v.pos.x,v.shoulderY,v.pos.z);
const p=new THREE.Vector3(h.x,h.y,h.z);
const dist=s.distanceTo(p);
const inReach=dist<=v.maxReach;
let blocker=null;
if(inReach){
for(const ob of obstacles){
if(inBox(s,ob)) continue;
if(segAABB(s,p,ob)){ blocker=ob.name; break; }
}
}
return { dist, inReach, blocker, clear:inReach&&!blocker };
}
/* ───────────────────────────── selection UI state ───────────────────────────── */
const vlist=document.getElementById('vlist');
const detail=document.getElementById('detail');
let selected=null, hovered=null;
const vlistBtns=new Map();
visitors.forEach(v=>{
const b=document.createElement('button');
b.className='vbtn';
b.innerHTML=`<span>${v.name}</span><span class="h">${v.height.toFixed(2)} m</span>`;
b.onclick=()=>selectVisitor(v);
vlist.appendChild(b); vlistBtns.set(v,b);
});
function selectVisitor(v){
selected=v;
vlistBtns.forEach((b,o)=>b.classList.toggle('sel',o===v));
updateMarkers(); updateDetail();
}
function updateDetail(){
if(!selected){
detail.innerHTML=`<div class="big">No visitor selected</div>
<div class="sub">Pick a person in the list or click one in the scene to evaluate unobstructed reach.</div>`;
return;
}
const v=selected;
const rows=hooks.map(h=>({h,...evaluate(v,h)}));
const clear=rows.filter(r=>r.clear);
const blocked=rows.filter(r=>!r.clear&&r.inReach);
const far=rows.filter(r=>!r.inReach);
const taken=clear.filter(r=>r.h.occupied);
detail.innerHTML=`
<div class="big">${v.name}</div>
<div class="sub">${v.role} · ${v.height.toFixed(2)} m tall · max reach ${v.maxReach.toFixed(2)} m</div>
<div class="stat">
<span class="chip ok">${clear.length} clear</span>
<span class="chip bad">${blocked.length} blocked</span>
<span class="chip taken">${far.length} out of reach</span>
</div>
<ul class="rows">
${clear.slice(0,6).map(r=>`<li><span>${r.h.id} · ${r.h.row}</span><span>${r.h.occupied?'coat hanging':'unobstructed'}</span></li>`).join('')}
${blocked.slice(0,4).map(r=>`<li><span>${r.h.id} · ${r.h.row}</span><span>blocked by ${r.blocker}</span></li>`).join('')}
</ul>`;
}
function updateMarkers(){
hooks.forEach(h=>{
h.light.visible=!!selected;
if(!selected) return;
if(h.occupied){ h.light.material.color.set(0x98a4b3); return; }
const r=evaluate(selected,h);
h.light.material.color.set(r.clear?0x53e08a:(r.inReach?0xff6b6b:0x39424f));
});
}
/* reach overlays */
const reachLines=new THREE.LineSegments(new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({color:0x53e08a,transparent:true,opacity:0.20}));
reachLines.visible=false; scene.add(reachLines);
const reachShell=new THREE.Mesh(new THREE.SphereGeometry(1,18,12),
new THREE.MeshBasicMaterial({color:0x53e08a,wireframe:true,transparent:true,opacity:0.075}));
reachShell.visible=false; scene.add(reachShell);
const reachDisc=new THREE.Mesh(new THREE.RingGeometry(0.965,1,64),
new THREE.MeshBasicMaterial({color:0x53e08a,transparent:true,opacity:0.16,side:THREE.DoubleSide}));
reachDisc.rotation.x=-Math.PI/2; reachDisc.visible=false; scene.add(reachDisc);
function updateOverlays(){
const on=!!selected;
reachLines.visible=on; reachShell.visible=on&&showShell; reachDisc.visible=on&&showShell;
if(!on) return;
const v=selected, s=new THREE.Vector3(v.pos.x,v.shoulderY,v.pos.z);
const pts=[];
hooks.forEach(h=>{
const r=evaluate(v,h);
if(r.clear) pts.push(s.x,s.y,s.z,h.x,h.y,h.z);
});
reachLines.geometry.dispose();
const g=new THREE.BufferGeometry();
g.setAttribute('position',new THREE.Float32BufferAttribute(pts,3));
reachLines.geometry=g;
reachShell.position.copy(s); reachShell.scale.setScalar(v.maxReach);
reachDisc.position.set(v.pos.x,0.02,v.pos.z); reachDisc.scale.setScalar(v.maxReach);
}
/* hover ray */
function makeRay(color){
const geo=new THREE.CylinderGeometry(0.016,0.016,1,6); geo.translate(0,0.5,0);
const m=new THREE.Mesh(geo,new THREE.MeshBasicMaterial({color,transparent:true,opacity:0.9,depthTest:false}));
m.renderOrder=9; m.visible=false; scene.add(m); return m;
}
const rayOK=makeRay(0x53e08a), rayBad=makeRay(0xff6b6b);
function setRay(mesh,from,to){
const dir=new THREE.Vector3().subVectors(to,from), len=dir.length();
mesh.position.copy(from);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0),dir.normalize());
mesh.scale.set(1,len,1); mesh.visible=true;
}
/* badges */
const badges=[];
function badge(text,color,pos){
const t=canvasTex(640,150,(g,w,h)=>{
g.fillStyle=color; g.fillRect(0,0,w,h);
g.strokeStyle='rgba(0,0,0,.35)'; g.lineWidth=7; g.strokeRect(4,4,w-8,h-8);
g.fillStyle='#fff'; let fs=54;
g.font=`700 ${fs}px ui-sans-serif,system-ui`;
while(g.measureText(text).width>w-40&&fs>18){fs-=2;g.font=`700 ${fs}px ui-sans-serif,system-ui`;}
g.textAlign='center'; g.textBaseline='middle'; g.fillText(text,w/2,h/2+2);
});
const s=new THREE.Sprite(new THREE.SpriteMaterial({map:t,transparent:true,depthTest:false}));
s.scale.set(2.3,0.54,1); s.position.copy(pos); s.renderOrder=12;
scene.add(s); badges.push({s,t:0,life:2.8});
}
/* ───────────────────────────── actions ───────────────────────────── */
function standSpot(h){
const cands=[];
for(const z of [-3.35,-3.05,-2.75,-2.45])
for(const dx of [0.55,-0.55,0]){
const p=new THREE.Vector3(h.x+dx,0,z);
const inside=obstacles.some(o=>p.x>o.min.x-0.05&&p.x<o.max.x+0.05&&p.z>o.min.z-0.05&&p.z<o.max.z+0.05);
if(!inside) cands.push(p);
}
return cands[0]||new THREE.Vector3(h.x+0.6,0,-2.6);
}
function goToHook(h){
const v=selected; if(!v) return;
const r=evaluate(v,h);
const from=new THREE.Vector3(v.pos.x,v.shoulderY,v.pos.z);
const to=new THREE.Vector3(h.x,h.y,h.z);
if(!r.inReach){
setRay(rayBad,from,to);
badge(`OUT OF REACH · ${(r.dist-v.maxReach).toFixed(2)} m short`,'#6d2b2b',new THREE.Vector3(h.x,h.y+0.75,h.z));
return;
}
if(r.blocker){
setRay(rayBad,from,to);
badge(`BLOCKED · ${r.blocker}`,'#6d2b2b',new THREE.Vector3(h.x,h.y+0.75,h.z));
return;
}
/* clear: walk over, then hang / collect */
const target=standSpot(h);
v.walk={from:v.pos.clone(),to:target,t:0,dur:1.15};
v.hook=h;
v.action=h.occupied?'collect':'hang';
v.group.rotation.y=Math.PI;
}
function finishHook(v){
const h=v.hook; const r=evaluate(v,h);
const from=new THREE.Vector3(v.pos.x,v.shoulderY,v.pos.z);
const to=new THREE.Vector3(h.x,h.y,h.z);
if(r.clear){
setRay(rayOK,from,to);
if(v.action==='collect'&&h.coat){
h.occupied=false;
h.coat.userData.fade=1; h.coat.userData.shrink=true; h.coat=null;
badge('✓ CLEAR REACH · coat collected','#1f5c3a',new THREE.Vector3(h.x,h.y+0.75,h.z));
}else{
h.occupied=true;
const c=makeCoat(coatColors[(hooks.indexOf(h))%coatColors.length]);
c.position.set(h.x,h.y,h.z+0.03); c.scale.setScalar(0.01); c.userData.grow=true;
scene.add(c); h.coat=c;
badge('✓ CLEAR REACH · coat hung','#1f5c3a',new THREE.Vector3(h.x,h.y+0.75,h.z));
}
}else{
setRay(rayBad,from,to);
badge(r.blocker?`BLOCKED · ${r.blocker}`:'OUT OF REACH','#6d2b2b',new THREE.Vector3(h.x,h.y+0.75,h.z));
}
updateMarkers(); updateDetail(); updateOverlays();
}
/* ───────────────────────────── camera controls (hand rolled) ───────────────────────────── */
const cam={ tgt:new THREE.Vector3(0,1.55,-2.4), r:15.6, th:0.0, ph:1.40,
cr:15.6, cth:0.0, cph:1.40 };
function applyCamera(){
const s=Math.sin(cam.cph);
camera.position.set(cam.tgt.x+cam.cr*s*Math.sin(cam.cth),
cam.tgt.y+cam.cr*Math.cos(cam.cph),
cam.tgt.z+cam.cr*s*Math.cos(cam.cth));
camera.lookAt(cam.tgt);
}
let drag=null, moved=0;
const cv=renderer.domElement;
cv.addEventListener('contextmenu',e=>e.preventDefault());
cv.addEventListener('pointerdown',e=>{
drag={x:e.clientX,y:e.clientY,pan:(e.button===2||e.shiftKey)}; moved=0; cv.setPointerCapture(e.pointerId);
});
cv.addEventListener('pointermove',e=>{
if(drag){
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);
const k=cam.cr*0.0012;
cam.tgt.addScaledVector(right,-dx*k).addScaledVector(up,dy*k);
cam.tgt.y=Math.max(0.4,Math.min(3.2,cam.tgt.y));
}else{
cam.cth=THREE.MathUtils.clamp(cam.cth-dx*0.0042,-1.15,1.15);
cam.cph=THREE.MathUtils.clamp(cam.cph-dy*0.0034,0.55,1.52);
}
}else{ hoverTest(e); }
});
cv.addEventListener('pointerup',e=>{
if(drag&&moved<6) clickTest(e);
drag=null;
});
cv.addEventListener('pointerleave',()=>{ drag=null; hideTip(); });
cv.addEventListener('wheel',e=>{
e.preventDefault();
cam.cr=THREE.MathUtils.clamp(cam.cr*(1+Math.sign(e.deltaY)*0.09),6,24);
},{passive:false});
/* ───────────────────────────── picking ───────────────────────────── */
const ray=new THREE.Raycaster(), ndc=new THREE.Vector2();
function pickAt(e){
ndc.x=(e.clientX/innerWidth)*2-1; ndc.y=-(e.clientY/innerHeight)*2+1;
ray.setFromCamera(ndc,camera);
const hits=ray.intersectObjects(pickables,false);
return hits.length?hits[0].object.userData:null;
}
function clickTest(e){
const d=pickAt(e); if(!d) return;
if(d.type==='visitor'){ selectVisitor(d.visitor); return; }
if(d.type==='hook'){
if(!selected){
/* auto-select the closest visitor */
let best=null,bd=1e9;
visitors.forEach(v=>{ const dd=v.pos.distanceTo(new THREE.Vector3(d.hook.x,0,d.hook.z)); if(dd<bd){bd=dd;best=v;} });
selectVisitor(best);
}
goToHook(d.hook);
}
}
const tip=document.getElementById('tip');
function hideTip(){ tip.style.display='none'; }
function hoverTest(e){
const d=pickAt(e);
hovered = d&&d.type==='hook'?d.hook:null;
if(!hovered){ hideTip(); rayOK.visible=false; rayBad.visible=false; return; }
const h=hovered;
let txt=`<b>${h.id}</b> · ${h.row} hook · ${h.y.toFixed(2)} m<br><span class="r">`;
if(h.occupied) txt+='coat hanging — click to collect';
else if(!selected) txt+='select a visitor to test reach';
else{
const r=evaluate(selected,h);
txt+= r.clear?'clear reach — click to hang a coat'
: (r.inReach?`blocked by ${r.blocker}`:`out of reach by ${(r.dist-selected.maxReach).toFixed(2)} m`);
}
txt+='</span>';
tip.innerHTML=txt; tip.style.display='block';
const p=new THREE.Vector3(h.x,h.y+0.45,h.z).project(camera);
tip.style.left=((p.x*0.5+0.5)*innerWidth+14)+'px';
tip.style.top=((-p.y*0.5+0.5)*innerHeight-10)+'px';
}
/* ───────────────────────────── controls ───────────────────────────── */
let showShell=true, labelsOn=true, tourTimer=null;
document.getElementById('lbl').onchange=e=>{
labelsOn=e.target.checked;
hooks.forEach(h=>h.label.visible=labelsOn);
};
document.getElementById('sph').onchange=e=>{ showShell=e.target.checked; updateOverlays(); };
document.getElementById('reset').onclick=()=>{ cam.cr=15.6;cam.cth=0;cam.cph=1.40;cam.tgt.set(0,1.55,-2.4); };
document.getElementById('tour').onclick=function(){
if(tourTimer){ clearInterval(tourTimer); tourTimer=null; this.textContent='Auto tour'; return; }
this.textContent='Stop tour';
let i=0;
tourTimer=setInterval(()=>{ selectVisitor(visitors[i%visitors.length]); i++; },4200);
};
/* ───────────────────────────── loop ───────────────────────────── */
const clock=new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt=Math.min(clock.getDelta(),0.05);
/* camera smoothing */
cam.r+=(cam.cr-cam.r)*0.12; cam.th+=(cam.cth-cam.th)*0.12; cam.ph+=(cam.cph-cam.ph)*0.12;
cam.tgt.lerp(cam.tgt.clone(),0.0001);
applyCamera();
/* visitors */
visitors.forEach(v=>{
if(v.walk){
v.walk.t=Math.min(1,v.walk.t+dt/v.walk.dur);
const e=v.walk.t<0.5?2*v.walk.t*v.walk.t:1-Math.pow(-2*v.walk.t+2,2)/2;
v.pos.lerpVectors(v.walk.from,v.walk.to,e);
v.group.position.set(v.pos.x,0,v.pos.z);
if(v.walk.t>=1){ v.walk=null; v.armLift=1; finishHook(v); }
}
/* arm lift toward the wall */
const target=v.armLift? -1.9 : 0;
v.arms.forEach((a,i)=>{
const dir=i===1?1:-1;
const t=v.armLift? -1.9*dir : 0;
a.rotation.x += (t-a.rotation.x)*0.12;
});
if(v.armLift){
v.armLift=Math.max(0,v.armLift-dt*0.55);
v.arms.forEach((a,i)=>{ const t=v.armLift?-1.9*(i===1?1:-1):0; a.rotation.x+=(t-a.rotation.x)*0.15; });
}
/* walking bob */
if(v.walk) v.group.position.y=Math.abs(Math.sin(v.walk.t*Math.PI*6))*0.045;
});
/* coat grow / shrink */
scene.traverse(o=>{
if(o.userData&&o.userData.grow){ o.scale.setScalar(Math.min(1,o.scale.x+dt*2.2)); if(o.scale.x>=0.999) o.userData.grow=false; }
if(o.userData&&o.userData.shrink){ const s=Math.max(0.01,o.scale.x-dt*1.6); o.scale.setScalar(s); if(s<=0.02){ scene.remove(o); o.userData.shrink=false; } }
});
/* badges */
for(let i=badges.length-1;i>=0;i--){
const b=badges[i]; b.t+=dt;
b.s.position.y+=dt*0.28;
b.s.material.opacity=Math.min(1,Math.max(0,1-Math.pow(Math.max(0,(b.t-(b.life-0.7))/0.7),2)));
if(b.t>b.life){ scene.remove(b.s); b.s.material.map.dispose(); b.s.material.dispose(); badges.splice(i,1); }
}
/* hover ray preview */
if(hovered&&selected){
const r=evaluate(selected,hovered);
const from=new THREE.Vector3(selected.pos.x,selected.shoulderY,selected.pos.z);
const to=new THREE.Vector3(hovered.x,hovered.y,hovered.z);
if(r.clear){ rayBad.visible=false; setRay(rayOK,from,to); }
else if(r.inReach){ rayOK.visible=false; setRay(rayBad,from,to); }
else{ rayOK.visible=false; rayBad.visible=false; }
}else{ rayOK.visible=false; rayBad.visible=false; }
renderer.render(scene,camera);
}
/* init */
selectVisitor(visitors[3]);
updateOverlays();
window.addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
animate();
</script>
</body>
</html>
```