Prompt specification
Build or customize the Three.js 3D scene "Procession follows a prepared route" 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: Procession follows a prepared route
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/procession-follows-a-prepared-route-x3918
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows wedding preparations, procession, and seating. Animate a few participants entering in a defined order and taking marked positions; each person stops before the next enters the same narrow aisle segment. Low-poly.
Working Three.js Starter (procession-follows-a-prepared-route-x3918):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>The Wedding Procession — Low-Poly Chapel</title>
<style>
:root{
--gold:#e2c48a; --cream:#f4ecdc; --ink:#0e0b09;
--glass:rgba(20,14,11,.78); --line:rgba(226,196,138,.28);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#0b0908;
font-family:Georgia,"Times New Roman",serif;color:var(--cream)}
canvas{display:block}
.panel{position:absolute;background:var(--glass);border:1px solid var(--line);
border-radius:12px;backdrop-filter:blur(6px);box-shadow:0 10px 34px rgba(0,0,0,.5)}
#brand{top:14px;left:14px;padding:12px 18px}
#brand h1{margin:0;font-size:15px;letter-spacing:.28em;text-transform:uppercase;color:var(--gold)}
#brand p{margin:5px 0 0;font-size:12px;opacity:.72;font-style:italic}
#phase{margin-top:9px;display:inline-block;font-size:11px;letter-spacing:.2em;
padding:4px 11px;border-radius:20px;border:1px solid var(--line);color:var(--gold)}
#roster{top:14px;right:14px;width:288px;padding:12px 12px 10px;max-height:72vh;overflow:auto}
#roster h2{margin:0 0 8px;font-size:11px;letter-spacing:.24em;color:var(--gold);text-transform:uppercase}
.row{display:flex;align-items:center;gap:9px;padding:5px 4px;border-bottom:1px dashed rgba(226,196,138,.12);
font-size:12.5px;cursor:default}
.row:last-child{border-bottom:none}
.num{width:19px;height:19px;flex:0 0 19px;border-radius:50%;border:1px solid var(--line);
font-size:10px;display:grid;place-items:center;color:var(--gold);opacity:.85}
.nm{flex:1;line-height:1.25}
.st{font-size:10px;letter-spacing:.08em;text-transform:uppercase;opacity:.6;white-space:nowrap}
.row.active .st{opacity:1;color:var(--gold)}
.row.done .st{opacity:.42}
#gatebox{bottom:14px;right:14px;padding:11px 14px;width:288px}
#gate{font-size:11px;letter-spacing:.16em;text-transform:uppercase;color:#7ee2a8;
display:flex;align-items:center;gap:8px}
#gate .dot{width:9px;height:9px;border-radius:50%;background:#7ee2a8;box-shadow:0 0 10px currentColor}
#gate.busy{color:#ff8d7a} #gate.busy .dot{background:#ff8d7a}
#now{margin-top:7px;font-size:12px;opacity:.85;font-style:italic;line-height:1.35}
#controls{bottom:14px;left:14px;padding:9px 11px;display:flex;gap:6px;align-items:center;flex-wrap:wrap;max-width:56vw}
button{font-family:inherit;font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--cream);
background:rgba(255,255,255,.05);border:1px solid var(--line);border-radius:7px;padding:6px 10px;cursor:pointer}
button:hover{background:rgba(226,196,138,.16);color:#fff}
button.on{background:rgba(226,196,138,.24);color:#fff;border-color:var(--gold)}
.sep{width:1px;height:20px;background:var(--line);margin:0 3px}
#hint{position:absolute;top:14px;left:50%;transform:translateX(-50%);font-size:10.5px;
letter-spacing:.16em;text-transform:uppercase;opacity:.45;pointer-events:none}
@media(max-width:900px){#roster{width:220px}#gatebox{width:220px}#hint{display:none}}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="brand" class="panel">
<h1>The Wedding Procession</h1>
<p>Low-poly chapel · preparations → procession → seating</p>
<div id="phase">PREPARATIONS</div>
</div>
<div id="roster" class="panel"><h2>Processional Order</h2><div id="rows"></div></div>
<div id="gatebox" class="panel">
<div id="gate"><span class="dot"></span><span id="gatetext">Narrow segment · clear</span></div>
<div id="now">The party gathers in the narthex…</div>
</div>
<div id="controls" class="panel">
<button id="play">⏸ Pause</button>
<button class="spd" data-s="1">1×</button>
<button class="spd on" data-s="2">2×</button>
<button class="spd" data-s="4">4×</button>
<button id="restart">↺ Restart</button>
<span class="sep"></span>
<button class="cam on" data-c="wide">Wide</button>
<button class="cam" data-c="aisle">Aisle</button>
<button class="cam" data-c="altar">Altar</button>
<button class="cam" data-c="prep">Prep</button>
<span class="sep"></span>
<button id="follow" class="on">Follow</button>
</div>
<div id="hint">drag to orbit · scroll to zoom</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================ utils */
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
const ease=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2;
const TAU=Math.PI*2;
function angLerp(a,b,t){let d=((b-a+Math.PI)%TAU+TAU)%TAU-Math.PI;return a+d*t;}
const M=new Map();
function MAT(color,extra){const k=color+'|'+(extra?JSON.stringify(extra):'');
if(!M.has(k))M.set(k,new THREE.MeshLambertMaterial(Object.assign({color,flatShading:true},extra||{})));
return M.get(k);}
/* ============================================================ renderer / scene */
const canvas=document.getElementById('c');
const renderer=new THREE.WebGLRenderer({canvas,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;
const scene=new THREE.Scene();
scene.background=new THREE.Color(0x121722);
scene.fog=new THREE.Fog(0x121722,48,110);
const camera=new THREE.PerspectiveCamera(46,innerWidth/innerHeight,0.1,250);
scene.add(new THREE.HemisphereLight(0xffe3bd,0x241a14,0.55));
const sun=new THREE.DirectionalLight(0xfff0d6,1.05);
sun.position.set(-11,18,16); sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
Object.assign(sun.shadow.camera,{left:-15,right:15,top:26,bottom:-26,near:1,far:70});
sun.shadow.bias=-0.0013;
sun.target.position.set(0,0,-2); scene.add(sun,sun.target);
const flick=[];
[[0,3.2,7],[0,3.2,-1],[0,3.4,-8.5],[-4.6,2.4,15.2],[0,3.6,-11.5]].forEach((p,i)=>{
const l=new THREE.PointLight(0xffb774,i===4?0.9:0.65,16,2); l.position.set(...p); scene.add(l); flick.push(l);
});
/* ============================================================ geometry helpers */
function addBox(w,h,d,color,x,y,z,opt){
const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),MAT(color,opt));
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; scene.add(m); return m;
}
function addCyl(rt,rb,h,seg,color,x,y,z,opt){
const m=new THREE.Mesh(new THREE.CylinderGeometry(rt,rb,h,seg),MAT(color,opt));
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; scene.add(m); return m;
}
function blossoms(x,y,z,n,cols,spread=0.28){
const g=new THREE.Group(); g.position.set(x,y,z);
for(let i=0;i<n;i++){
const b=new THREE.Mesh(new THREE.IcosahedronGeometry(0.13+Math.random()*0.05,0),
MAT(cols[i%cols.length]));
b.position.set((Math.random()-.5)*spread*2,(Math.random()-.5)*spread*1.2,(Math.random()-.5)*spread*2);
b.castShadow=true; g.add(b);
}
scene.add(g); return g;
}
/* ============================================================ the chapel */
const Z0=-15.5, Z1=17.0, HW=7.0, ROWS=[11,8,5,2,-1,-4];
const WALL=0xdccdb2, WOOD=0x5d3a24, DARKWOOD=0x3d2617;
function buildChapel(){
// floor + planks
addBox(HW*2,0.3,Z1-Z0,0x6d4c34,0,-0.15,(Z0+Z1)/2);
for(let x=-6;x<=6;x+=1.2) addBox(0.05,0.02,Z1-Z0,0x5b3f2b,x,0.005,(Z0+Z1)/2);
// aisle carpet + gold border
addBox(2.6,0.05,21.0,0x8d2f3d,0,0.025,2.6);
addBox(0.14,0.055,21.0,0xd9b45a,-1.37,0.028,2.6);
addBox(0.14,0.055,21.0,0xd9b45a, 1.37,0.028,2.6);
// narthex stone
addBox(HW*2,0.06,4.0,0x8b8177,0,0.03,15.0);
// walls
addBox(5.0,9,0.3,WALL,-4.5,4.5,Z1+0.15);
addBox(5.0,9,0.3,WALL, 4.5,4.5,Z1+0.15);
addBox(4.0,3.0,0.3,WALL,0,7.5,Z1+0.15);
addBox(HW*2,9,0.3,WALL,0,4.5,Z0-0.15);
addBox(0.3,9,Z1-Z0,WALL,-HW-0.15,4.5,(Z0+Z1)/2);
addBox(0.3,9,Z1-Z0,WALL, HW+0.15,4.5,(Z0+Z1)/2);
// wainscot
addBox(0.36,1.35,Z1-Z0,DARKWOOD,-HW+0.05,0.67,(Z0+Z1)/2);
addBox(0.36,1.35,Z1-Z0,DARKWOOD, HW-0.05,0.67,(Z0+Z1)/2);
addBox(HW*2,1.35,0.36,DARKWOOD,0,0.67,Z0+0.05);
// open doorway with daylight
const glow=new THREE.Mesh(new THREE.PlaneGeometry(4.0,6.0),new THREE.MeshBasicMaterial({color:0xffe6b4}));
glow.position.set(0,3.0,Z1-0.06); glow.rotation.y=Math.PI; scene.add(glow);
addBox(0.22,6.2,0.5,DARKWOOD,-2.05,3.1,Z1-0.1);
addBox(0.22,6.2,0.5,DARKWOOD, 2.05,3.1,Z1-0.1);
addBox(4.3,0.3,0.5,DARKWOOD,0,6.2,Z1-0.1);
// roof trusses
for(let z=-12;z<=12;z+=6){
const a=addBox(0.22,0.22,14,DARKWOOD,-3.6,6.6,z); a.rotation.z=-0.62;
const b=addBox(0.22,0.22,14,DARKWOOD, 3.6,6.6,z); b.rotation.z= 0.62;
addBox(0.3,0.3,14,DARKWOOD,0,7.55,z);
}
// stained glass side windows
const paneCols=[0x3f7bd6,0xc0392b,0xe0b13d,0x3fa06b,0x8e44ad];
[-1,1].forEach(s=>{
[-11,-6,-1,4,9].forEach((z,i)=>{
addBox(0.16,3.4,1.9,DARKWOOD,s*6.94,4.3,z);
for(let k=0;k<4;k++){
const p=new THREE.Mesh(new THREE.BoxGeometry(0.07,1.25,0.78),
new THREE.MeshBasicMaterial({color:paneCols[(i+k)%paneCols.length]}));
p.position.set(s*6.83,3.7+ (k%2)*1.35, z-0.55+(k>>1)*1.1); scene.add(p);
}
});
});
// rose window above the door
const rose=new THREE.Group(); rose.position.set(0,6.6,Z1-0.08);
for(let i=0;i<10;i++){
const s=new THREE.Mesh(new THREE.CircleGeometry(1.45,6,i*TAU/10,TAU/10),
new THREE.MeshBasicMaterial({color:paneCols[i%paneCols.length]}));
s.rotation.y=Math.PI; rose.add(s);
}
const hub=new THREE.Mesh(new THREE.CircleGeometry(0.45,10),new THREE.MeshBasicMaterial({color:0xf3e6c8}));
hub.rotation.y=Math.PI; rose.add(hub); scene.add(rose);
// pews
ROWS.forEach(z=>{
[-1,1].forEach(s=>{
const cx=s*4.35;
addBox(4.2,0.12,0.62,0x7d5433,cx,0.36,z);
addBox(4.2,0.72,0.12,0x6b4529,cx,0.72,z+0.30);
addBox(4.2,0.10,0.30,0x5b3a22,cx,0.22,z-0.42);
addBox(4.2,0.06,0.06,0xd9b45a,cx,0.30,z-0.56);
[-1,1].forEach(e=>addBox(0.12,0.9,0.62,0x6b4529,cx+e*2.1,0.45,z));
});
});
// altar platform + steps
addBox(9.4,0.45,4.6,0xcfc6b6,0,0.225,-11.3);
addBox(2.6,0.05,4.6,0x8d2f3d,0,0.475,-11.3);
addBox(4.0,0.22,0.7,0xcfc6b6,0,0.11,-8.65);
addBox(3.2,0.11,0.5,0xcfc6b6,0,0.055,-8.15);
// altar table, arch, flowers, candles
addBox(1.9,0.95,0.7,DARKWOOD,0,0.925,-12.3);
addBox(2.05,0.07,0.85,0xf6f1e6,0,1.43,-12.3);
[-1,1].forEach(s=>{
addCyl(0.22,0.25,5.4,8,0xe8ddc8,s*2.7,3.15,-13.2);
blossoms(s*2.7,0.75,-12.75,10,[0xf6e7d8,0xe8a3b6,0xc9d8a0],0.42);
});
addBox(6.0,0.34,0.42,0xe8ddc8,0,5.85,-13.2);
const med=new THREE.Mesh(new THREE.TorusGeometry(0.55,0.08,6,14),MAT(0xd9b45a));
med.position.set(0,6.5,-13.2); scene.add(med);
blossoms(0,1.55,-12.3,9,[0xf6e7d8,0xe8a3b6,0xc9d8a0],0.5);
[-1.8,-0.9,0,0.9,1.8].forEach(x=>{
addCyl(0.05,0.05,0.26,6,0xf6efe2,x,1.60,-12.3);
const fl=new THREE.Mesh(new THREE.ConeGeometry(0.035,0.11,5),new THREE.MeshBasicMaterial({color:0xffca6a}));
fl.position.set(x,1.79,-12.3); scene.add(fl);
});
// the narrow processional gate
[-1,1].forEach(s=>{
addCyl(0.27,0.31,3.4,8,0xd6c9b2,s*1.62,1.7,12.0);
addCyl(0.34,0.34,0.2,8,0xe8ddc8,s*1.62,3.45,12.0);
const lamp=new THREE.Mesh(new THREE.BoxGeometry(0.22,0.3,0.22),new THREE.MeshBasicMaterial({color:0xffd79a}));
lamp.position.set(s*1.62,3.75,12.0); scene.add(lamp);
blossoms(s*1.62,0.42,12.0,8,[0xf6e7d8,0xe8a3b6,0xc9d8a0],0.34);
});
addBox(3.9,0.3,0.45,0xe8ddc8,0,3.55,12.0);
// aisle-end urns
[-1,1].forEach(s=>{
addCyl(0.3,0.24,0.7,8,0xd6c9b2,s*2.1,0.35,-7.6);
blossoms(s*2.1,0.9,-7.6,11,[0xf6e7d8,0xe8a3b6,0xc9d8a0],0.36);
});
// preparation corner (narthex, back-left)
addBox(2.8,0.03,2.8,0xb98a92,-5.4,0.035,15.1);
addBox(1.9,0.12,0.62,0xe3d7bf,-5.4,0.86,16.2);
[-1,1].forEach(s=>[-1,1].forEach(t=>addBox(0.08,0.85,0.08,DARKWOOD,-5.4+s*0.8,0.42,16.2+t*0.24)));
addBox(1.35,1.7,0.09,0xd9b45a,-5.4,1.95,16.82);
const mir=new THREE.Mesh(new THREE.PlaneGeometry(1.1,1.45),new THREE.MeshBasicMaterial({color:0xbcd0d6}));
mir.position.set(-5.4,1.95,16.76); mir.rotation.y=Math.PI; scene.add(mir);
addBox(0.58,0.1,0.58,0xd9b45a,-5.4,0.46,15.3);
addBox(0.58,0.72,0.1,0xd9b45a,-5.4,0.82,15.58);
[-1,1].forEach(s=>[-1,1].forEach(t=>addBox(0.07,0.46,0.07,DARKWOOD,-5.4+s*0.22,0.23,15.3+t*0.22)));
addCyl(0.04,0.04,1.5,6,0x8a6a3f,-6.5,0.75,15.9);
addCyl(0.17,0.30,0.72,8,0xf6f1e6,-6.5,1.35,15.9);
addBox(0.08,2.6,2.2,0x9c4a5c,-3.55,1.3,14.6);
// gate floor light (shows narrow-segment state)
const strip=new THREE.Mesh(new THREE.BoxGeometry(2.35,0.02,2.0),new THREE.MeshBasicMaterial({color:0x3ddc84}));
strip.position.set(0,0.065,12.0); scene.add(strip); return strip;
}
const gateStrip=buildChapel();
const gateBeacon=(()=>{const b=new THREE.Mesh(new THREE.SphereGeometry(0.16,10,8),new THREE.MeshBasicMaterial({color:0x3ddc84}));
b.position.set(0,4.15,12.0); scene.add(b); return b;})();
/* ============================================================ characters */
function buildPerson(o){
const p={root:new THREE.Group(),opt:o};
const root=p.root; root.scale.setScalar(o.scale||1);
const cloth=MAT(o.cloth), skin=MAT(o.skin), hair=MAT(o.hair), legsC=MAT(o.legs||0x35343d);
const hips=new THREE.Group(); hips.position.y=0.82; root.add(hips); p.hips=hips;
hips.add(new THREE.Mesh(new THREE.BoxGeometry(0.32,0.20,0.22),cloth));
if(o.dress){
const L=o.skirtLen||0.52;
const sk=new THREE.Mesh(new THREE.CylinderGeometry(0.2,o.skirtR||0.34,L,8),MAT(o.dressColor||o.cloth));
sk.position.y=-L/2-0.04; hips.add(sk); p.skirt=sk;
}
const torso=new THREE.Group(); torso.position.y=0.10; hips.add(torso); p.torso=torso;
const chest=new THREE.Mesh(new THREE.CylinderGeometry(0.20,0.245,0.50,6),cloth);
chest.position.y=0.25; torso.add(chest);
if(o.shirt){const sh=new THREE.Mesh(new THREE.BoxGeometry(0.15,0.22,0.05),MAT(o.shirt));
sh.position.set(0,0.33,-0.21); torso.add(sh);}
const neck=new THREE.Mesh(new THREE.CylinderGeometry(0.055,0.065,0.10,6),skin); neck.position.y=0.53; torso.add(neck);
const head=new THREE.Mesh(new THREE.SphereGeometry(0.15,8,6),skin); head.position.y=0.68; torso.add(head); p.head=head;
const cap=new THREE.Mesh(new THREE.SphereGeometry(0.158,8,6,0,TAU,0,1.55),hair); cap.position.y=0.69; torso.add(cap);
if(o.longHair){const bk=new THREE.Mesh(new THREE.BoxGeometry(0.25,0.34,0.13),hair); bk.position.set(0,0.56,0.10); torso.add(bk);}
if(o.veil){
const vm=new THREE.MeshLambertMaterial({color:0xffffff,transparent:true,opacity:0.42,side:THREE.DoubleSide,depthWrite:false});
const veil=new THREE.Mesh(new THREE.ConeGeometry(0.26,0.58,10,1,true),vm);
veil.position.set(0,0.60,0.11); veil.rotation.x=0.18; torso.add(veil); p.veil=veil; p.veilMat=vm;
}
p.arms=[]; p.armBase=[0,0];
[-1,1].forEach((s,i)=>{
const sh=new THREE.Group(); sh.position.set(s*0.245,0.45,0); torso.add(sh);
const up=new THREE.Mesh(new THREE.CylinderGeometry(0.055,0.05,0.30,6),o.bareArms?skin:cloth);
up.position.y=-0.15; sh.add(up);
const el=new THREE.Group(); el.position.y=-0.30; sh.add(el);
const fo=new THREE.Mesh(new THREE.CylinderGeometry(0.05,0.045,0.26,6),o.bareArms?skin:cloth);
fo.position.y=-0.13; el.add(fo);
const hand=new THREE.Group(); hand.position.y=-0.27; el.add(hand);
const hm=new THREE.Mesh(new THREE.SphereGeometry(0.055,6,4),skin); hand.add(hm);
p.arms.push({sh,el,hand}); if(i===1)p.rightHand=hand;
});
p.legs=[];
[-1,1].forEach(s=>{
const hip=new THREE.Group(); hip.position.set(s*0.10,-0.06,0); hips.add(hip);
const th=new THREE.Mesh(new THREE.CylinderGeometry(0.08,0.07,0.38,6),legsC); th.position.y=-0.19; hip.add(th);
const kn=new THREE.Group(); kn.position.y=-0.38; hip.add(kn);
const sh2=new THREE.Mesh(new THREE.CylinderGeometry(0.065,0.055,0.34,6),legsC); sh2.position.y=-0.17; kn.add(sh2);
const ft=new THREE.Mesh(new THREE.BoxGeometry(0.11,0.07,0.2),MAT(0x241d18)); ft.position.set(0,-0.34,-0.04); kn.add(ft);
p.legs.push({hip,kn});
});
p.seed=Math.random()*10;
return p;
}
function buildGuest(cloth,skin,hair,sc){
const g=new THREE.Group(); g.scale.setScalar(sc);
const t=new THREE.Mesh(new THREE.CylinderGeometry(0.23,0.27,0.60,6),MAT(cloth)); t.position.y=0.72; g.add(t);
const h=new THREE.Mesh(new THREE.SphereGeometry(0.15,7,5),MAT(skin)); h.position.y=1.16; g.add(h);
const c=new THREE.Mesh(new THREE.SphereGeometry(0.158,7,5,0,TAU,0,1.55),MAT(hair)); c.position.y=1.17; g.add(c);
[-1,1].forEach(s=>{const a=new THREE.Mesh(new THREE.BoxGeometry(0.09,0.44,0.12),MAT(cloth));
a.position.set(s*0.26,0.74,0.02); a.rotation.z=s*0.13; g.add(a);});
const lap=new THREE.Mesh(new THREE.BoxGeometry(0.40,0.12,0.42),MAT(cloth)); lap.position.set(0,0.08,-0.18); g.add(lap);
g.position.y=0.42; return g;
}
function makeBouquet(cols){
const g=new THREE.Group();
const stem=new THREE.Mesh(new THREE.CylinderGeometry(0.03,0.03,0.22,5),MAT(0x3d6b3a)); stem.rotation.z=0.3; g.add(stem);
for(let i=0;i<8;i++){const b=new THREE.Mesh(new THREE.IcosahedronGeometry(0.075,0),MAT(cols[i%cols.length]));
b.position.set(Math.cos(i/8*TAU)*0.10,0.16+Math.random()*0.06,Math.sin(i/8*TAU)*0.10); g.add(b);}
const leaf=new THREE.Mesh(new THREE.ConeGeometry(0.13,0.24,5),MAT(0x4f7a42)); leaf.position.set(0.06,-0.05,0); leaf.rotation.z=-0.7; g.add(leaf);
return g;
}
function makePillow(){
const g=new THREE.Group();
g.add(new THREE.Mesh(new THREE.BoxGeometry(0.20,0.06,0.20),MAT(0xf5f0e6)));
const r=new THREE.Mesh(new THREE.TorusGeometry(0.035,0.012,5,10),MAT(0xe6c98d)); r.rotation.x=Math.PI/2; r.position.y=0.045; g.add(r);
return g;
}
/* ============================================================ the cast */
const C={};
function cast(name,o){const p=buildPerson(o); p.root.position.set(o.x||0,0,o.z||0); scene.add(p.root); p.name=name; C[name]=p; return p;}
cast('usher', {cloth:0x3c4f66,shirt:0xf3efe6,skin:0xe0b38c,hair:0x332a24,legs:0x2b2b33,scale:1.03,x:3.9,z:15.3});
cast('flower', {cloth:0xf3bcc9,dress:true,dressColor:0xf3bcc9,skirtLen:0.46,skirtR:0.30,bareArms:true,
skin:0xf1c9a4,hair:0x8a5a2b,scale:0.62,x:2.9,z:15.3});
cast('ring', {cloth:0x5d7290,shirt:0xf6f3ec,skin:0xd9a97f,hair:0x4a3323,legs:0x39424f,scale:0.70,x:2.0,z:15.3});
cast('maid', {cloth:0xc9788f,dress:true,dressColor:0xc9788f,skirtLen:0.60,skirtR:0.36,bareArms:true,
skin:0xf0c6a2,hair:0x3b2418,longHair:true,scale:0.96,x:1.0,z:15.3});
cast('bestman', {cloth:0x24344d,shirt:0xf6f3ec,skin:0xd6a87e,hair:0x1f1a17,legs:0x20242e,scale:1.04,x:0.1,z:15.3});
cast('mother', {cloth:0x8f7fb0,dress:true,dressColor:0x8f7fb0,skirtLen:0.56,skirtR:0.34,bareArms:true,
skin:0xefc9ab,hair:0x6a5340,longHair:true,scale:0.95,x:-0.8,z:15.3});
cast('father', {cloth:0x4b4b55,shirt:0xf3efe6,skin:0xd8ab84,hair:0x59504a,legs:0x2f2f36,scale:1.01,x:-1.7,z:15.3});
cast('bride', {cloth:0xf7f2e9,dress:true,dressColor:0xf7f2e9,skirtLen:0.80,skirtR:0.44,bareArms:true,
skin:0xf3cfb0,hair:0x6b4423,longHair:true,veil:true,scale:0.98,x:-2.6,z:15.3});
cast('groom', {cloth:0x1f2b3a,shirt:0xffffff,skin:0xdcae86,hair:0x2b211c,legs:0x1c2330,scale:1.05,x:4.8,z:-6.5});
cast('mrsAlv', {cloth:0x3e6b6a,dress:true,dressColor:0x3e6b6a,skirtLen:0.54,skirtR:0.33,bareArms:true,
skin:0xefc7a6,hair:0x3c2b20,longHair:true,scale:0.96,x:5.6,z:15.3});
cast('mrAlv', {cloth:0x7a5c3a,shirt:0xf3efe6,skin:0xc99a70,hair:0x2d241d,legs:0x3a3128,scale:1.00,x:4.8,z:15.3});
cast('officiant',{cloth:0x2b2b35,shirt:0xf6f3ec,skin:0xd9ad85,hair:0x8b8b8b,legs:0x24242c,scale:1.02,x:0,z:-12.4});
// props
const bouquetBride=makeBouquet([0xf8f2e6,0xf0b9c6,0xf6d9a8]);
const bouquetMaid=makeBouquet([0xf8f2e6,0xe8a3b6,0xf6d9a8]);
const pillow=makePillow();
C.maid.rightHand.add(bouquetMaid); bouquetMaid.position.set(0,-0.1,0);
C.maid.armBase[1]=0.55;
C.ring.arms.forEach(a=>a.sh.rotation.x=0.85);
C.ring.rightHand.add(pillow); pillow.position.set(0,-0.08,0);
C.bride.armBase[1]=0.5;
// seated guests
const guestSpots=[
[-3.0,11],[-4.2,11],[-5.4,11],[3.0,11],[4.2,11],[5.4,11],
[-2.9,8],[-4.1,8],[-5.3,8],[2.9,8],[4.1,8],[5.3,8],
[-3.2,5],[-4.4,5],[-5.6,5],[3.2,5],[4.4,5],[5.6,5],
[-4.8,2],[-5.9,2],[3.0,2],[4.2,2],[5.4,2],
[-3.0,-1],[-4.2,-1],[-5.4,-1],[3.0,-1],[4.2,-1],[5.4,-1],
[-4.2,-4],[-5.4,-4],[4.2,-4],[5.4,-4]];
const clothPal=[0x7d5a8a,0x4a6b7c,0x8a6a4a,0x5c6b4a,0x9a5a5a,0x3f5f6b,0x7a7a55,0x6b4a6b];
const skinPal=[0xf1c9a4,0xd9a97f,0xefc7a6,0xb9845c,0x8a5a3b];
const hairPal=[0x2b211c,0x6b4423,0x8a5a2b,0x59504a,0x3c2b20,0xb8b0a4];
guestSpots.forEach(([x,z])=>{
const g=buildGuest(clothPal[(Math.random()*clothPal.length)|0],skinPal[(Math.random()*skinPal.length)|0],
hairPal[(Math.random()*hairPal.length)|0],0.92+Math.random()*0.14);
g.position.set(x+(Math.random()-.5)*0.15,0.42,z+0.05);
g.rotation.y=(Math.random()-.5)*0.16; scene.add(g);
});
/* ============================================================ markers */
const markers=[];
function marker(n,x,y,z,col){
const g=new THREE.Group(); g.position.set(x,y,z);
const r=new THREE.Mesh(new THREE.TorusGeometry(0.36,0.032,6,18),new THREE.MeshBasicMaterial({color:col}));
r.rotation.x=-Math.PI/2; g.add(r);
const c=document.createElement('canvas'); c.width=c.height=128;
const x2=c.getContext('2d'); x2.fillStyle='rgba(250,242,225,0.93)';
x2.beginPath(); x2.arc(64,64,50,0,TAU); x2.fill();
x2.strokeStyle='rgba(120,84,40,0.8)'; x2.lineWidth=4; x2.stroke();
x2.fillStyle='#4a351c'; x2.font='bold 58px Georgia'; x2.textAlign='center'; x2.textBaseline='middle';
x2.fillText(String(n),64,66);
const tex=new THREE.CanvasTexture(c); tex.colorSpace=THREE.SRGBColorSpace;
const sp=new THREE.Sprite(new THREE.SpriteMaterial({map:tex,transparent:true}));
sp.scale.set(0.52,0.52,1); sp.position.y=0.72; g.add(sp);
scene.add(g); markers.push(g); return g;
}
const M1=marker(1,-1.70,0.02,-5.60,0xd9b45a);
const M2=marker(2,-1.15,0.02,-6.60,0xf0b9c6);
const M3=marker(3, 1.15,0.02,-6.60,0x9fb6d6);
const M4=marker(4, 2.30,0.02,-7.30,0xe8a3b6);
const M5=marker(5, 3.50,0.02,-7.80,0xd9b45a);
const M6=marker(6, 3.00,0.44,-3.95,0xc9b8e6);
const M7=marker(7,-3.00,0.44,-3.95,0xc9b8e6);
const M8=marker(8, 0.75,0.47,-10.60,0xd9b45a);
const M9=marker(9,-0.75,0.47,-10.60,0xf6e7d8);
const MA=marker(10,-2.60,0.44,2.05,0x9fd0c9);
const MB=marker(11,-3.70,0.44,2.05,0x9fd0c9);
/* ============================================================ actors / units */
const allActors=[];
function actor(cfg){
const a={
p:cfg.p, name:cfg.p.name, path:cfg.path.map(v=>new THREE.Vector3(v[0],v[1]||0,v[2])),
wi:0, state:'wait', speed:cfg.speed||1.9, yaw:cfg.yaw||0, gait:Math.random()*TAU,
sit:cfg.sit||null, waitAt:cfg.waitAt||null, startWhen:cfg.startWhen||null,
status:'waiting', statusText:'waiting'
};
cfg.p.root.position.copy(a.path[0]);
cfg.p.root.rotation.y=cfg.yaw||0;
allActors.push(a); return a;
}
const seatY=s=>0.42-0.82*s;
const usher=actor({p:C.usher,yaw:Math.PI,speed:2.1,path:[
[3.9,0,15.3],[2.0,0,13.8],[0.1,0,13.4],[0.0,0,9],[0.0,0,2],[0.0,0,-3],[-1.70,0,-5.60]]});
const flower=actor({p:C.flower,yaw:0,speed:1.75,path:[
[2.9,0,15.3],[1.2,0,13.7],[0.2,0,12.2],[0.1,0,7],[0.0,0,1],[-0.5,0,-4.2],[-1.15,0,-6.60]]});
const ringb=actor({p:C.ring,yaw:0,speed:1.9,path:[
[2.0,0,15.3],[1.0,0,13.7],[0.4,0,12.2],[0.4,0,6],[0.5,0,0],[0.8,0,-3.5],[1.15,0,-6.60]]});
const maid=actor({p:C.maid,yaw:0,speed:1.85,path:[
[1.0,0,15.3],[0.6,0,13.7],[0.4,0,12.0],[0.3,0,6],[0.3,0,0],[0.6,0,-4],[1.6,0,-6.8],[2.30,0,-7.30]]});
const best=actor({p:C.bestman,yaw:0,speed:2.0,path:[
[0.1,0,15.3],[0.2,0,13.7],[0.2,0,12.0],[0.15,0,6],[0.2,0,0],[0.8,0,-4],[2.2,0,-7.0],[3.50,0,-7.80]]});
const mother=actor({p:C.mother,yaw:0,speed:1.8,sit:{x:3.00,y:seatY(0.95),z:-3.95},path:[
[-0.8,0,15.3],[0.45,0,13.7],[0.45,0,12.0],[0.45,0,6],[0.45,0,0],[0.55,0,-3.0],[2.2,0,-3.5],[3.00,0,-3.95]]});
const father=actor({p:C.father,yaw:0,speed:1.8,sit:{x:-3.00,y:seatY(1.01),z:-3.95},path:[
[-1.7,0,15.3],[-0.45,0,13.7],[-0.45,0,12.0],[-0.45,0,6],[-0.45,0,0],[-0.5,0,-3.0],[-1.7,0,-3.5],[-3.00,0,-3.95]]});
const groom=actor({p:C.groom,yaw:Math.PI,speed:1.7,path:[
[4.8,0,-6.5],[3.2,0,-8.0],[1.6,0,-9.4],[0.75,0.45,-10.60]]});
const bride=actor({p:C.bride,yaw:-Math.PI/2,speed:1.55,path:[
[-2.6,0,15.3],[-1.0,0,13.8],[0.0,0,12.2],[0.0,0,6],[0.0,0,0],[0.0,0,-5.0],[0.0,0.22,-8.6],[0.0,0.45,-9.4],[-0.75,0.45,-10.60]]});
const usherBack=actor({p:C.usher,yaw:Math.PI,speed:2.2,waitAt:{index:7,cond:'aisleClear'},path:[
[-1.70,0,-5.60],[-1.0,0,-1.0],[-0.7,0,5],[-0.4,0,11.4],[0.6,0,13.5],[3.2,0,14.6],[4.2,0,15.0],
[0.3,0,13.3],[-0.6,0,9],[-0.9,0,3],[-1.2,0,-2],[-1.70,0,-5.60]]});
const mrsAlv=actor({p:C.mrsAlv,yaw:0,speed:1.85,sit:{x:-2.60,y:seatY(0.96),z:2.05},path:[
[5.6,0,15.3],[2.6,0,13.8],[0.8,0,12.2],[0.35,0,7],[0.35,0,4],[0.35,0,3.0],[-0.9,0,2.55],[-1.9,0,2.25],[-2.60,0,2.05]]});
const mrAlv=actor({p:C.mrAlv,yaw:0,speed:1.85,sit:{x:-3.70,y:seatY(1.00),z:2.05},path:[
[4.8,0,15.3],[2.0,0,13.8],[0.0,0,12.2],[-0.35,0,7],[-0.35,0,4],[-0.35,0,3.0],[-1.5,0,2.55],[-2.6,0,2.25],[-3.70,0,2.05]]});
mrsAlv.startWhen={actor:usherBack,index:6};
mrAlv.startWhen={actor:usherBack,index:6};
const units=[
{name:'Mr. Halloway — the usher', actors:[usher], label:'usher'},
{name:'Pippa — the flower girl', actors:[flower], label:'flower'},
{name:'Theo — the ring bearer', actors:[ringb], label:'ring'},
{name:'Elena — the maid of honour', actors:[maid], label:'maid'},
{name:'Marcus — the best man', actors:[best], label:'best'},
{name:'Mr & Mrs. Bennett — the parents',actors:[mother,father],label:'parents'},
{name:'Elias — the groom', actors:[groom], label:'groom'},
{name:'Ava — the bride (solo entrance)', actors:[bride], label:'bride'},
{name:'The late arrivals, seated by the usher',actors:[mrsAlv,mrAlv,usherBack],label:'late'}
];
units.forEach((u,i)=>u.idx=i);
/* ============================================================ simulation state */
const sim={time:0,speed:2,paused:false,phase:'prep',prepT:0,unit:-1,unitT:0,done:false};
const GATE={z0:11.0,z1:13.0,holder:null};
function aisleOccupants(except){
const out=[];
for(const a of allActors){
if(a===except)continue;
if(a.state!=='walk'&&a.state!=='hold')continue;
const p=a.p.root.position;
if(Math.abs(p.x)<1.45&&p.z>-5.6&&p.z<13.0)out.push(a);
}
return out;
}
/* ---- petals ---- */
const petals=[];
const petalMat=new THREE.MeshBasicMaterial({color:0xf4c3cf,side:THREE.DoubleSide});
for(let i=0;i<70;i++){
const m=new THREE.Mesh(new THREE.PlaneGeometry(0.075,0.045),petalMat);
m.visible=false; m.rotation.x=-Math.PI/2; scene.add(m);
petals.push({m,life:0,vx:0,vy:0,vz:0,rest:false});
}
let petalPtr=0;
function dropPetal(x,y,z){
const p=petals[petalPtr++%petals.length];
p.m.visible=true; p.m.position.set(x+(Math.random()-.5)*0.5,y+0.5,z+(Math.random()-.5)*0.4);
p.m.rotation.set(-Math.PI/2,Math.random()*TAU,0);
p.vx=(Math.random()-.5)*0.25; p.vy=0.1; p.vz=(Math.random()-.5)*0.25; p.life=0; p.rest=false;
}
function updatePetals(dt){
for(const p of petals){
if(!p.m.visible)continue;
if(p.rest)continue;
p.life+=dt; p.vy-=2.6*dt;
p.m.position.x+=p.vx*dt; p.m.position.z+=p.vz*dt; p.m.position.y+=p.vy*dt;
p.m.rotation.z+=dt*1.5;
if(p.m.position.y<=0.09){p.m.position.y=0.09;p.rest=true;}
}
}
/* ---- actor movement ---- */
function stepActor(a,dt){
if(a.state==='wait'){
if(a.startWhen&&!(a.startWhen.actor.wi>=a.startWhen.index&&a.startWhen.actor.state!=='wait'))return;
a.state='walk'; a.status='walking';
}
if(a.state==='hold'){
if(a.holdReason==='gate'&&(!GATE.holder||GATE.holder===a)){a.state='walk'; a.holdReason=null;}
else if(a.holdReason!=='gate'&&a.waitAt?.cond==='aisleClear'&&aisleOccupants(a).length===0)a.state='walk';
else return;
}
if(a.state!=='walk')return;
if(a.waitAt&&a.wi===a.waitAt.index&&!a.waitAt.used){
a.waitAt.used=true; a.state='hold'; a.statusText='waiting for the aisle to clear'; return;
}
const root=a.p.root, tgt=a.path[a.wi];
const dx=tgt.x-root.position.x, dz=tgt.z-root.position.z, dy=tgt.y-root.position.y;
const dist=Math.hypot(dx,dz);
const step=a.speed*dt;
const z=root.position.z;
const inRegion=v=>v>=GATE.z0&&v<=GATE.z1;
const nz=z+(dz/(dist||1))*Math.min(step,dist||0);
// narrow-segment token: only one body may be inside the gate at a time
if(!inRegion(z)&&inRegion(nz)&&GATE.holder&&GATE.holder!==a){
a.state='hold'; a.statusText='waiting for the narrow segment'; a.holdReason='gate'; return;
}
if(dist<=step){
root.position.copy(tgt); a.wi++;
if(a.wi>=a.path.length){ arrive(a); return; }
}else{
root.position.x+=dx/dist*step;
root.position.z+=dz/dist*step;
root.position.y+=(dy/dist)*step;
const want=Math.atan2(-dx,-dz);
a.yaw=angLerp(a.yaw,want,1-Math.pow(0.001,dt));
root.rotation.y=a.yaw;
a.gait+=step*3.1;
// walk cycle
const s=Math.sin(a.gait), c=Math.cos(a.gait);
a.p.legs[0].hip.rotation.x=s*0.55; a.p.legs[1].hip.rotation.x=-s*0.55;
a.p.legs[0].kn.rotation.x=Math.max(0,-s)*0.35; a.p.legs[1].kn.rotation.x=Math.max(0,s)*0.35;
a.p.arms[0].sh.rotation.x=-s*0.32+a.p.armBase[0]; a.p.arms[1].sh.rotation.x=s*0.32+a.p.armBase[1];
a.p.arms[0].el.rotation.x=-0.12; a.p.arms[1].el.rotation.x=-0.12;
a.p.hips.position.y=0.82+Math.abs(c)*0.025;
if(a===flower&&Math.random()<dt*7)dropPetal(root.position.x,0.1,root.position.z);
}
// gate token bookkeeping
const z2=root.position.z;
if(a.holdsGate&&(z2<GATE.z0-0.05||z2>GATE.z1+0.05)){GATE.holder=null;a.holdsGate=false;}
if(!a.holdsGate&&inRegion(z2)&&!GATE.holder){GATE.holder=a;a.holdsGate=true;}
}
function arrive(a){
a.state='done'; a.status='done';
if(a.sit){
a.sitting=true; a.sitT=0; a.sitFrom=a.p.root.position.clone();
a.sitTo=new THREE.Vector3(a.sit.x,a.sit.y,a.sit.z);
a.state='sitting';
}else{
a.yaw=a.path.length? (a.cfgYaw!==undefined?a.cfgYaw:a.yaw):a.yaw;
a.p.root.rotation.y=a.yaw;
a.statusText='at the marker';
}
}
function updateSitting(a,dt){
a.sitT=Math.min(1,a.sitT+dt/0.75); const t=ease(a.sitT);
a.p.root.position.lerpVectors(a.sitFrom,a.sitTo,t);
a.p.legs.forEach((L,i)=>{L.hip.rotation.x=t*Math.PI/2; L.kn.rotation.x=-t*Math.PI/2;});
a.p.arms[0].sh.rotation.x=-0.25; a.p.arms[1].sh.rotation.x=-0.25;
a.p.arms[0].el.rotation.x=-0.5; a.p.arms[1].el.rotation.x=-0.5;
a.p.hips.position.y=0.82;
if(a.sitT>=1){a.state='done';a.statusText='seated';}
}
/* ============================================================ unit director */
let unitPause=0;
function beginUnit(i){
sim.unit=i; sim.unitT=0;
const u=units[i];
u.actors.forEach(a=>{if(a.state==='wait'){a.state='wait';a.status='walking';}});
u.actors.forEach(a=>{a.status='walking';});
document.getElementById('phase').textContent=(i>=8)?'SEATING':'PROCESSION';
}
function updateDirector(dt){
const u=units[sim.unit];
if(!u){ // preparation phase
sim.prepT+=dt;
updatePrep(dt);
if(sim.prepT>=9.6){beginUnit(0);setCam('aisle');}
return;
}
sim.unitT+=dt;
let allDone=true;
for(const a of u.actors){
if(a.state==='sitting')updateSitting(a,dt);
else stepActor(a,dt);
if(a.state!=='done')allDone=false;
}
if(allDone){
unitPause+=dt;
if(unitPause>1.6){
unitPause=0;
if(sim.unit+1<units.length)beginUnit(sim.unit+1);
else {sim.done=true;document.getElementById('phase').textContent='THE CEREMONY';}
}
}
}
/* ============================================================ preparation phase */
const prep={stage:0,blend:0,twirl:0};
function updatePrep(dt){
const b=C.bride, m=C.maid;
if(prep.stage===0){ // bouquet handoff
prep.blend=Math.min(1,prep.blend+dt/2.4);
const bhand=new THREE.Vector3(), mhand=new THREE.Vector3();
m.rightHand.getWorldPosition(mhand); b.rightHand.getWorldPosition(bhand);
bouquetMaid.position.set(0,-0.1,0);
if(prep.blend<1){
scene.attach(bouquetMaid);
const tgt=mhand.clone().lerp(bhand,prep.blend); tgt.y+=0.12;
bouquetMaid.position.copy(tgt); bouquetMaid.rotation.set(0,0,0.4);
m.armBase[1]=0.9;
}else{
b.rightHand.add(bouquetMaid); bouquetMaid.position.set(0,-0.1,0); bouquetMaid.rotation.set(0,0,0);
prep.stage=1; prep.blend=0;
}
}else if(prep.stage===1){ // veil
prep.blend=Math.min(1,prep.blend+dt/1.8);
b.veil.scale.set(1,prep.blend,1); b.veilMat.opacity=0.42*prep.blend;
if(prep.blend>=1)prep.stage=2;
}else if(prep.stage===2){ // twirl
prep.twirl+=dt/2.2;
b.root.rotation.y=prep.twirl*TAU;
b.arms[0].sh.rotation.x=-1.0; b.arms[1].sh.rotation.x=-1.0;
b.skirt.rotation.z=Math.sin(prep.twirl*Math.PI)*0.12;
if(prep.twirl>=1){b.root.rotation.y=0;b.skirt.rotation.z=0;prep.stage=3;}
}else if(prep.stage===3){ // walk to the narthex line
if(prep.stage===3&&!prep.walked){
prep.walked=true;
prepActorB=actor({p:C.bride,speed:1.5,path:[[-5.4,0,15.3],[-4.2,0,15.4],[-2.6,0,15.3]]});
prepActorM=actor({p:C.maid,speed:1.5,path:[[-4.6,0,15.5],[-3.0,0,15.4],[1.0,0,15.3]]});
prepActorB.state='walk'; prepActorM.state='walk';
}
if(prepActorB&&prepActorB.state!=='done')stepActor(prepActorB,dt);
if(prepActorM&&prepActorM.state!=='done')stepActor(prepActorM,dt);
if(prepActorB&&prepActorM&&prepActorB.state==='done'&&prepActorM.state==='done')prep.stage=4;
}
}
let prepActorB=null,prepActorM=null;
/* ============================================================ camera */
const cam={tx:0,ty:1.2,tz:-1,th:0.42,ph:0.88,r:24,
cx:0,cy:1.2,cz:-1,cth:0.42,cph:0.88,cr:24};
const presets={
wide :{t:[0,1.2,-1], th:0.42,ph:0.88,r:24},
aisle:{t:[0,1.4,4], th:0.10,ph:1.15,r:9},
altar:{t:[0,1.6,-10.5],th:0.35,ph:1.10,r:8},
prep :{t:[-5.2,1.4,15.0],th:2.40,ph:1.20,r:5.5}
};
function setCam(k){
const p=presets[k]; if(!p)return;
cam.tx=p.t[0];cam.ty=p.t[1];cam.tz=p.t[2];cam.th=p.th;cam.ph=p.ph;cam.r=p.r;
document.querySelectorAll('.cam').forEach(b=>b.classList.toggle('on',b.dataset.c===k));
follow=false;document.getElementById('follow').classList.remove('on');
}
let follow=true,dragging=false,lx=0,ly=0;
canvas.addEventListener('pointerdown',e=>{dragging=true;lx=e.clientX;ly=e.clientY;canvas.setPointerCapture(e.pointerId);});
canvas.addEventListener('pointermove',e=>{if(!dragging)return;const dx=e.clientX-lx,dy=e.clientY-ly;lx=e.clientX;ly=e.clientY;
cam.th-=dx*0.005;cam.ph=clamp(cam.ph-dy*0.004,0.30,1.45);});
canvas.addEventListener('pointerup',()=>dragging=false);
canvas.addEventListener('pointercancel',()=>dragging=false);
canvas.addEventListener('wheel',e=>{cam.r=clamp(cam.r+e.deltaY*0.02,4,40);e.preventDefault();},{passive:false});
function updateCamera(dt){
const u=units[sim.unit];
if(follow&&u&&!sim.done){
const a=u.actors.find(x=>x.state==='walk'||x.state==='hold'||x.state==='sitting');
if(a){const p=a.p.root.position;cam.tx=lerp(cam.tx,p.x*0.55,1-Math.pow(0.2,dt));cam.tz=lerp(cam.tz,p.z*0.55,1-Math.pow(0.2,dt));}
}
if(sim.done)cam.th+=dt*0.035;
const k=1-Math.pow(0.0015,dt);
cam.cx=lerp(cam.cx,cam.tx,k);cam.cy=lerp(cam.cy,cam.ty,k);cam.cz=lerp(cam.cz,cam.tz,k);
cam.cth=lerp(cam.cth,cam.th,k);cam.cph=lerp(cam.cph,cam.ph,k);cam.cr=lerp(cam.cr,cam.r,k);
const sp=Math.sin(cam.cph),cp=Math.cos(cam.cph);
camera.position.set(cam.cx+cam.cr*sp*Math.sin(cam.cth),cam.cy+cam.cr*cp,cam.cz+cam.cr*sp*Math.cos(cam.cth));
camera.lookAt(cam.cx,cam.cy,cam.cz);
}
/* ============================================================ HUD */
const rowsEl=document.getElementById('rows');
function buildRoster(){
rowsEl.innerHTML=units.map((u,i)=>`<div class="row" id="row${i}"><span class="num">${i+1}</span><span class="nm">${u.name}</span><span class="st" id="st${i}">waiting</span></div>`).join('');
}
buildRoster();
const gateEl=document.getElementById('gate'), gateText=document.getElementById('gatetext'), nowEl=document.getElementById('now');
let hudT=0;
function updateHUD(dt){
hudT+=dt; if(hudT<0.12)return; hudT=0;
units.forEach((u,i)=>{
const st=u.actors.map(a=>a.statusText||a.status).join(' · ');
document.getElementById('st'+i).textContent=st;
const row=document.getElementById('row'+i);
row.classList.toggle('active',sim.unit===i);
row.classList.toggle('done',u.actors.every(a=>a.state==='done'));
});
const busy=!!GATE.holder;
gateEl.classList.toggle('busy',busy);
gateText.textContent=busy?('Narrow segment · occupied by '+GATE.holder.name):'Narrow segment · clear';
gateStrip.material.color.set(busy?0xff5a4a:0x3ddc84);
gateBeacon.material.color.set(busy?0xff5a4a:0x3ddc84);
let msg='';
if(sim.unit<0){
msg=prep.stage===0?'The maid hands the bouquet to the bride':
prep.stage===1?'The veil is set':
prep.stage===2?'A turn, for luck':
'The party gathers at the narthex';
}else if(sim.done){msg='The aisle is still. The ceremony begins.';}
else{
const u=units[sim.unit];
const moving=u.actors.filter(a=>a.state==='walk');
const holding=u.actors.filter(a=>a.state==='hold');
if(moving.length)msg=moving.map(a=>a.name+' is walking the aisle').join(' · ');
else if(holding.length)msg=holding.map(a=>a.statusText).join(' · ');
else msg=u.name+' — at the marker';
if(sim.unit+1<units.length&&u.actors.every(a=>a.state==='done'))
msg='Next in the order: '+units[sim.unit+1].name;
}
nowEl.textContent=msg;
}
/* ============================================================ controls */
document.getElementById('play').onclick=e=>{sim.paused=!sim.paused;e.target.textContent=sim.paused?'▶ Resume':'⏸ Pause';};
document.querySelectorAll('.spd').forEach(b=>b.onclick=()=>{
sim.speed=+b.dataset.s;document.querySelectorAll('.spd').forEach(x=>x.classList.toggle('on',x===b));});
document.querySelectorAll('.cam').forEach(b=>b.onclick=()=>setCam(b.dataset.c));
document.getElementById('follow').onclick=e=>{follow=!follow;e.target.classList.toggle('on',follow);};
document.getElementById('restart').onclick=()=>location.reload();
/* ============================================================ loop */
let last=performance.now();
function tick(now){
requestAnimationFrame(tick);
const dt=Math.min(0.05,(now-last)/1000); last=now;
const sdt=sim.paused?0:dt*sim.speed;
if(sdt>0){
sim.time+=sdt;
updateDirector(sdt);
updatePetals(sdt);
// idle breathing for waiting characters
allActors.forEach(a=>{
if(a.state!=='wait'&&a.state!=='done'&&a.state!=='sitting')return;
if(a.state==='done'&&a.sit)return;
const t=sim.time*1.3+a.p.seed;
a.p.torso.rotation.z=Math.sin(t)*0.022;
a.p.arms[0].sh.rotation.x=Math.sin(t*0.8)*0.05+a.p.armBase[0];
a.p.arms[1].sh.rotation.x=Math.sin(t*0.8+1)*0.05+a.p.armBase[1];
});
}
// candle flicker
flick.forEach((l,i)=>{l.intensity=(i===4?0.9:0.65)*(0.88+Math.sin(sim.time*7+i*2.3)*0.09+Math.random()*0.05);});
updateCamera(dt);
updateHUD(dt);
renderer.render(scene,camera);
}
requestAnimationFrame(tick);
window.addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
setCam('prep');
</script>
</body>
</html>
```