@adatechnology/game-interactables-three 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/effects.ts","../src/routed-particles.ts","../src/adapter.ts","../src/mesh.ts","../src/types.ts","../src/pose.ts","../src/merge.ts","../src/stand-out.ts","../src/mirrors.ts","../src/screen.ts","../src/sway.ts","../src/contents.ts","../src/cord.ts","../src/wires.ts"],"sourcesContent":["import type { ActiveEmitter, EmitterKind } from '@adatechnology/game-interactables'\nimport { warnOnce } from '@adatechnology/game-contracts'\nimport { isRoutedKind, routedParticleRequest } from './routed-particles'\nimport type { ParticleEffects, PoolKind } from './routed-particles'\nimport type { CanvasFactory, ThreeLib, ThreeNS } from './types'\n\nexport interface EffectsOptions {\n /** Where the particle objects are added (the `Points` of every kind, the water streams and the flame ring). Required. */\n scene: ThreeNS.Object3D\n /**\n * Camera whose vertical field of view sizes the sprites, read again every `update` so zoom and fov changes follow. Required: pass the\n * camera the scene is rendered with (a `PerspectiveCamera` fits), or a function returning the current one (`null` = 90 degree lens).\n */\n camera: PerspectiveLike | (() => PerspectiveLike | null) | null\n /** Total particles alive at once, shared by all kinds (split by weight). Default 800. */\n maxParticles?: number\n /** Used to paint the soft sprite on a canvas. Without it (or without a 2D context) a data texture is generated. */\n document?: CanvasFactory\n /** Seed of the random spread. Default 1. */\n seed?: number\n /** Wind vector [x, z] in m/s that bends smoke and steam. Default [0, 0]. */\n wind?: [number, number]\n /** Viewport height in pixels, used to size the point sprites. Update with `setViewHeight` on resize. Default 720. */\n viewHeight?: number\n /** Height (m) water streams fall to when the emitter has no `reach`. Default 0. */\n floorY?: number\n /** Most water streams drawn at once (one draw call each). Default 6. */\n maxStreams?: number\n /** Most gas flame rings drawn at once (all rings share one draw call). Default 16. */\n maxFlames?: number\n /**\n * The host's effects world, read at each particle. With one, smoke, steam, fire and sparks go through it and its one budget (`maxParticles` then only caps water);\n * without one every kind is drawn here with its own cap (deprecated, removed in the next major).\n */\n effects?: () => ParticleEffects | undefined\n}\n\n/** What the effects read from a camera. */\nexport interface PerspectiveLike {\n /** Vertical field of view in degrees. */\n fov: number\n zoom?: number\n}\n\nexport interface EffectsStats {\n alive: number\n capacity: number\n byKind: Record<PoolKind, number>\n}\n\nexport type { PoolKind }\n\nexport interface Effects {\n /**\n * Spawns for the active emitters and advances every particle by `dt` seconds, sizing the sprites for the camera given to\n * `createEffects` (or `setCamera`). No allocations per frame once warmed up. `camera` overrides it for this call (deprecated).\n */\n update(dt: number, emitters: readonly ActiveEmitter[], camera?: PerspectiveLike): void\n /** Replace the camera used for the sprite size (or `null` to go back to a 90 degree lens). */\n setCamera(camera: PerspectiveLike | (() => PerspectiveLike | null) | null): void\n setWind(x: number, z: number): void\n setViewHeight(px: number): void\n stats(): EffectsStats\n /** The Points objects (one per kind). */\n objects: Record<PoolKind, ThreeNS.Points>\n /** Water stream meshes (tapered, translucent, following the gravity arc) and the one mesh holding every gas flame ring. */\n meshes: { group: ThreeNS.Group; streams: ThreeNS.Mesh[]; flames: ThreeNS.Mesh }\n clear(): void\n dispose(): void\n}\n\nconst POOLS: PoolKind[] = ['smoke', 'steam', 'fire', 'water', 'spark']\nconst WEIGHT: Record<PoolKind, number> = { smoke: 0.27, steam: 0.15, fire: 0.2, water: 0.28, spark: 0.1 }\n\ninterface Pool {\n kind: PoolKind\n cap: number\n count: number\n pos: Float32Array\n vel: Float32Array\n age: Float32Array\n life: Float32Array\n size0: Float32Array\n size1: Float32Array\n tint: Float32Array\n flags: Uint8Array\n /** Water only: the height at which the particle ends (splashes, droplets). */\n ground: Float32Array\n aSize: ThreeNS.BufferAttribute\n aAlpha: ThreeNS.BufferAttribute\n aColor: ThreeNS.BufferAttribute\n aPos: ThreeNS.BufferAttribute\n points: ThreeNS.Points\n}\n\nconst VERT = /* glsl */ `\nattribute float aSize;\nattribute float aAlpha;\nattribute vec3 aColor;\nuniform float uScale;\nvarying float vAlpha;\nvarying vec3 vColor;\nvoid main() {\n vAlpha = aAlpha;\n vColor = aColor;\n vec4 mv = modelViewMatrix * vec4(position, 1.0);\n gl_PointSize = max(aSize * uScale / max(-mv.z, 0.05), 1.0);\n gl_Position = projectionMatrix * mv;\n}\n`\nconst FRAG = /* glsl */ `\nuniform sampler2D uMap;\nvarying float vAlpha;\nvarying vec3 vColor;\nvoid main() {\n vec4 t = texture2D(uMap, gl_PointCoord);\n gl_FragColor = vec4(vColor, vAlpha * t.a);\n}\n`\n\nfunction mulberry(seed: number): () => number {\n let a = seed >>> 0\n return () => {\n a = (a + 0x6d2b79f5) >>> 0\n let t = a\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\n/** Soft round sprite (alpha only matters). Canvas when possible, otherwise generated data. */\nfunction makeSprite(THREE: ThreeLib, doc: CanvasFactory | undefined): ThreeNS.Texture {\n const N = 64\n try {\n const canvas = doc?.createElement('canvas')\n const ctx = canvas?.getContext?.('2d')\n if (canvas && ctx && ctx.createRadialGradient) {\n canvas.width = N\n canvas.height = N\n const g = ctx.createRadialGradient(N / 2, N / 2, 0, N / 2, N / 2, N / 2)\n g.addColorStop(0, 'rgba(255,255,255,1)')\n g.addColorStop(0.4, 'rgba(255,255,255,0.55)')\n g.addColorStop(1, 'rgba(255,255,255,0)')\n ctx.fillStyle = g\n ctx.fillRect(0, 0, N, N)\n const tex = new THREE.CanvasTexture(canvas)\n return tex\n }\n } catch {\n // fall through to the data texture\n }\n const data = new Uint8Array(N * N * 4)\n for (let y = 0; y < N; y++) {\n for (let x = 0; x < N; x++) {\n const d = Math.hypot(x + 0.5 - N / 2, y + 0.5 - N / 2) / (N / 2)\n const a = d >= 1 ? 0 : Math.pow(1 - d, 1.6)\n const i = (y * N + x) * 4\n data[i] = data[i + 1] = data[i + 2] = 255\n data[i + 3] = Math.round(a * 255)\n }\n }\n const tex = new THREE.DataTexture(data, N, N, THREE.RGBAFormat)\n tex.needsUpdate = true\n return tex\n}\n\n/** Vertical streaks of water (alpha only matters); scrolled along the stream to show the flow. */\nfunction makeStreaks(THREE: ThreeLib): ThreeNS.DataTexture {\n const W = 16\n const H = 64\n const data = new Uint8Array(W * H * 4)\n const hash = (x: number, y: number): number => {\n let h = Math.imul(x + 1, 374761393) ^ Math.imul(y + 7, 668265263)\n h = Math.imul(h ^ (h >>> 13), 1274126177)\n return ((h ^ (h >>> 16)) >>> 0) / 4294967296\n }\n for (let y = 0; y < H; y++) {\n for (let x = 0; x < W; x++) {\n const col = 0.35 + 0.65 * hash(x, 0)\n const row = 0.55 + 0.45 * Math.sin(((y / H) * 3 + hash(x, 1) * 6) * Math.PI * 2)\n const i = (y * W + x) * 4\n data[i] = data[i + 1] = data[i + 2] = 255\n data[i + 3] = Math.round(255 * Math.min(1, col * row * 1.3))\n }\n }\n const tex = new THREE.DataTexture(data, W, H, THREE.RGBAFormat)\n tex.wrapS = THREE.RepeatWrapping\n tex.wrapT = THREE.RepeatWrapping\n tex.needsUpdate = true\n return tex\n}\n\n/**\n * Pooled particle effects: smoke, steam, fire (and the blue gas `flame` ring), water streams with drips, and sparks.\n * One `Points` per kind, fixed-size buffers, swap-remove; the total alive never exceeds `maxParticles`.\n */\nexport function createEffects(THREE: ThreeLib, options: EffectsOptions): Effects\n/** @deprecated Pass `{ scene, camera, ... }` as the one options argument. */\nexport function createEffects(THREE: ThreeLib, scene: ThreeNS.Object3D, options?: Partial<EffectsOptions>): Effects\nexport function createEffects(THREE: ThreeLib, a: EffectsOptions | ThreeNS.Object3D, b: Partial<EffectsOptions> = {}): Effects {\n const legacy = !!(a as ThreeNS.Object3D).isObject3D\n const options: Partial<EffectsOptions> = legacy ? { ...b, scene: a as ThreeNS.Object3D } : (a as EffectsOptions)\n const scene = options.scene\n if (!scene) throw new Error('createEffects: options.scene is required')\n if (!legacy && options.camera === undefined) throw new Error('createEffects: options.camera is required (pass null for a 90 degree lens)')\n const total = Math.max(POOLS.length, Math.floor(options.maxParticles ?? 800))\n const rand = mulberry(options.seed ?? 1)\n const wind: [number, number] = [options.wind?.[0] ?? 0, options.wind?.[1] ?? 0]\n const sprite = makeSprite(THREE, options.document)\n let viewHeight = options.viewHeight ?? 720\n let cameraSource: PerspectiveLike | (() => PerspectiveLike | null) | null = options.camera ?? null\n let camera: PerspectiveLike | null = typeof cameraSource === 'function' ? cameraSource() : cameraSource\n const scale = { value: 0 }\n /** Point size in pixels is size * viewHeight / (2 tan(fov / 2)) / distance. */\n const refreshScale = (cam: PerspectiveLike | null): void => {\n const fov = cam ? 2 * Math.atan(Math.tan((Math.min(Math.max(cam.fov, 1), 175) * Math.PI) / 360) / Math.max(cam.zoom ?? 1, 0.01)) : Math.PI / 2\n scale.value = viewHeight / (2 * Math.tan(fov / 2))\n }\n refreshScale(camera)\n\n const pools = {} as Record<PoolKind, Pool>\n const objects = {} as Record<PoolKind, ThreeNS.Points>\n let used = 0\n POOLS.forEach((kind, i) => {\n const cap = i === POOLS.length - 1 ? Math.max(1, total - used) : Math.max(1, Math.floor(total * WEIGHT[kind]))\n used += cap\n const geo = new THREE.BufferGeometry()\n const aPos = new THREE.BufferAttribute(new Float32Array(cap * 3), 3)\n const aSize = new THREE.BufferAttribute(new Float32Array(cap), 1)\n const aAlpha = new THREE.BufferAttribute(new Float32Array(cap), 1)\n const aColor = new THREE.BufferAttribute(new Float32Array(cap * 3), 3)\n for (const a of [aPos, aSize, aAlpha, aColor]) a.setUsage(THREE.DynamicDrawUsage)\n geo.setAttribute('position', aPos)\n geo.setAttribute('aSize', aSize)\n geo.setAttribute('aAlpha', aAlpha)\n geo.setAttribute('aColor', aColor)\n geo.setDrawRange(0, 0)\n const additive = kind === 'fire' || kind === 'spark'\n const mat = new THREE.ShaderMaterial({\n uniforms: { uMap: { value: sprite }, uScale: scale },\n vertexShader: VERT,\n fragmentShader: FRAG,\n transparent: true,\n depthWrite: false,\n blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending,\n })\n const points = new THREE.Points(geo, mat)\n points.frustumCulled = false\n points.name = `effects:${kind}`\n scene.add(points)\n objects[kind] = points\n pools[kind] = {\n kind,\n cap,\n count: 0,\n pos: new Float32Array(cap * 3),\n vel: new Float32Array(cap * 3),\n age: new Float32Array(cap),\n life: new Float32Array(cap),\n size0: new Float32Array(cap),\n size1: new Float32Array(cap),\n tint: new Float32Array(cap),\n flags: new Uint8Array(cap),\n ground: new Float32Array(cap).fill(-1e9),\n aSize,\n aAlpha,\n aColor,\n aPos,\n points,\n }\n })\n\n /** Fractional spawns carried over per emitter id (the Map only grows with distinct ids and is pruned by stamp). */\n const debt = new Map<string, { carry: number; stamp: number }>()\n let stamp = 0\n let clock = 0\n\n const spawn = (p: Pool, x: number, y: number, z: number, vx: number, vy: number, vz: number, life: number, s0: number, s1: number, tint: number, flag = 0, ground = -1e9): void => {\n const sink = isRoutedKind(p.kind) ? options.effects?.() : undefined\n if (sink) {\n sink.play(routedParticleRequest({ kind: p.kind, flag, position: [x, y, z], velocity: [vx, vy, vz], life, startSize: s0, endSize: s1, tint }))\n return\n }\n if (isRoutedKind(p.kind)) warnOnce('game-interactables-three.own-particles', 'game-interactables-three drew its smoke, steam, fire and sparks with pools of its own because the host lent no effects world (options.effects); pass the host effects so the particles share one budget')\n if (p.count >= p.cap) return\n const i = p.count++\n p.pos[i * 3] = x\n p.pos[i * 3 + 1] = y\n p.pos[i * 3 + 2] = z\n p.vel[i * 3] = vx\n p.vel[i * 3 + 1] = vy\n p.vel[i * 3 + 2] = vz\n p.age[i] = 0\n p.life[i] = life\n p.size0[i] = s0\n p.size1[i] = s1\n p.tint[i] = tint\n p.flags[i] = flag\n p.ground[i] = ground\n }\n\n const emitFrom = (e: ActiveEmitter, n: number): void => {\n const k = Math.min(1, Math.max(0, e.intensity))\n const size = e.size > 0 ? e.size : 0.2\n const [px, py, pz] = e.pos\n for (let j = 0; j < n; j++) {\n switch (e.kind) {\n case 'smoke':\n // thick, slow, wide plume\n spawn(pools.smoke, px + (rand() - 0.5) * size * 0.6, py, pz + (rand() - 0.5) * size * 0.6, (rand() - 0.5) * 0.2, 0.45 + rand() * 0.45, (rand() - 0.5) * 0.2, 2.8 + rand() * 1.8, size * 0.6, size * 2.6, 0.3 + rand() * 0.25, 0)\n break\n case 'steam':\n spawn(pools.steam, px + (rand() - 0.5) * size * 0.5, py, pz + (rand() - 0.5) * size * 0.5, (rand() - 0.5) * 0.12, 0.3 + rand() * 0.3, (rand() - 0.5) * 0.12, 1.3 + rand() * 1.1, size * 0.3, size * 1.3, 0.92, 0)\n break\n case 'fire':\n spawn(pools.fire, px + (rand() - 0.5) * size * 0.7, py, pz + (rand() - 0.5) * size * 0.7, (rand() - 0.5) * 0.25, 0.8 + rand() * 0.9 * k, (rand() - 0.5) * 0.25, 0.35 + rand() * 0.4, size * 0.75, size * 0.15, rand(), 0)\n break\n case 'flame': {\n // soft blue glow over the ring (the ring of little flames itself is a mesh)\n const a = rand() * Math.PI * 2\n const r = size * 0.8\n spawn(pools.fire, px + Math.cos(a) * r, py + 0.01, pz + Math.sin(a) * r, 0, 0.06 + rand() * 0.1, 0, 0.14 + rand() * 0.12, size * 0.55, size * 0.15, rand(), 1)\n break\n }\n case 'spark': {\n const a = rand() * Math.PI * 2\n const up = 0.4 + rand() * 0.6\n const sp = 1.2 + rand() * 2\n spawn(pools.spark, px, py, pz, Math.cos(a) * sp * (1 - up * 0.5), up * sp * 1.4, Math.sin(a) * sp * (1 - up * 0.5), 0.35 + rand() * 0.5, size * 0.18, size * 0.05, rand(), 0)\n break\n }\n case 'water':\n break\n }\n }\n }\n\n // ---- water: a tapered translucent stream along the gravity arc, droplets around it and a splash where it lands ----------------\n interface Arc {\n x: number\n y: number\n z: number\n vx: number\n vy: number\n vz: number\n /** Flight time to the landing height. */\n t: number\n stopY: number\n r0: number\n r1: number\n }\n const arc: Arc = { x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, stopY: 0, r0: 0, r1: 0 }\n const floorY = options.floorY ?? 0\n const arcOf = (e: ActiveEmitter, k: number): boolean => {\n let [dx, dy, dz] = e.dir\n const len = Math.hypot(dx, dy, dz)\n if (len < 1e-6) {\n dx = 0\n dy = -1\n dz = 0\n } else {\n dx /= len\n dy /= len\n dz /= len\n }\n const speed = 0.7 + 1.8 * k\n const stopY = e.reach !== undefined ? Math.max(e.pos[1] - e.reach, floorY) : floorY\n const drop = e.pos[1] - stopY\n if (drop < 0.02) return false\n const vy = dy * speed\n arc.x = e.pos[0]\n arc.y = e.pos[1]\n arc.z = e.pos[2]\n arc.vx = dx * speed\n arc.vy = vy\n arc.vz = dz * speed\n arc.t = Math.min(2.5, (vy + Math.sqrt(vy * vy + 19.6 * drop)) / 9.8)\n arc.stopY = stopY\n const size = e.size > 0 ? e.size : 0.05\n if (size < 0.1) {\n // a tap: a thin jet that narrows as it speeds up\n arc.r0 = Math.max(0.004, size * 0.5)\n arc.r1 = arc.r0 * 0.55\n } else {\n // a shower or a leak: a spray that opens a little\n arc.r0 = size * 0.45\n arc.r1 = arc.r0 * 1.2\n }\n // a stream into a bowl is never wider than the bowl\n if (e.bowl) {\n const most = Math.max(0.004, e.bowl.radius * 0.7)\n arc.r0 = Math.min(arc.r0, most)\n arc.r1 = Math.min(arc.r1, most)\n }\n return true\n }\n\n const emitWater = (e: ActiveEmitter, k: number, nSpray: number, nSplash: number, nMist: number): void => {\n const size = e.size > 0 ? e.size : 0.05\n const bowl = e.bowl\n // a spray opens out only on open floor: in a bowl its walls hold it in\n const wide = size >= 0.1 && !bowl\n // the walls of a bowl catch what splashes: no drop rises over its rim (v^2 = 2 g h) nor flies past its walls before it falls back (out and back in 2 vy / g)\n const riseMax = bowl ? Math.sqrt(2 * 9.8 * Math.max(0.01, bowl.depth)) * 0.85 : Infinity\n const outMax = (vy: number): number => (bowl ? (bowl.radius * 0.6 * 9.8) / (2 * Math.max(vy, 0.3)) : Infinity)\n const within = bowl ? bowl.radius * 0.3 : Infinity\n for (let j = 0; j < nSpray; j++) {\n const s = rand()\n const t = s * arc.t\n const r = (arc.r0 + (arc.r1 - arc.r0) * s) * (0.7 + rand() * 0.5)\n const a = rand() * Math.PI * 2\n const ox = Math.cos(a) * r\n const oz = Math.sin(a) * r\n spawn(\n pools.water,\n arc.x + arc.vx * t + ox,\n arc.y + arc.vy * t - 4.9 * t * t,\n arc.z + arc.vz * t + oz,\n arc.vx + (wide ? ox * 1.2 : 0) + (rand() - 0.5) * 0.25,\n arc.vy - 9.8 * t,\n arc.vz + (wide ? oz * 1.2 : 0) + (rand() - 0.5) * 0.25,\n 0.22 + rand() * 0.25,\n 0.011 + rand() * 0.012,\n 0.009 + rand() * 0.008,\n rand(),\n 2,\n arc.stopY,\n )\n }\n const ex = arc.x + arc.vx * arc.t\n const ez = arc.z + arc.vz * arc.t\n for (let j = 0; j < nSplash; j++) {\n const a = rand() * Math.PI * 2\n const r = Math.min(arc.r1, within) * Math.sqrt(rand())\n // drawn in the same order as on open floor, so a stream that lands on the floor draws the same drops\n const sp0 = (wide ? 0.5 : 0.25) + rand() * 0.7\n const vy0 = 0.9 + rand() * 1.3\n const vy = bowl ? riseMax * (0.5 + (0.5 * (vy0 - 0.9)) / 1.3) : vy0\n const sp = Math.min(sp0, outMax(vy))\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.005, ez + Math.sin(a) * r, Math.cos(a) * sp, vy, Math.sin(a) * sp, 0.3 + rand() * 0.25, 0.014 + rand() * 0.018, 0.01, rand(), 3, arc.stopY)\n }\n for (let j = 0; j < nMist; j++) {\n const a = rand() * Math.PI * 2\n const r = Math.min(arc.r1 * 1.4, within) * Math.sqrt(rand())\n const up0 = 0.18 + rand() * 0.15\n const life = 0.7 + rand() * 0.5\n // the haze over a bowl rises to its rim at most: it drifts without gravity, so its speed is the rise over its life\n const up = bowl ? Math.min(up0, Math.max(0.005, bowl.depth - 0.03) / life) : up0\n const drift = bowl ? Math.min(0.15, (bowl.radius * 0.5) / life) : 0.15\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.02, ez + Math.sin(a) * r, Math.cos(a) * drift, up, Math.sin(a) * drift, life, 0.06 + size * 0.2, 0.2 + size * 0.5, rand(), 4, arc.stopY)\n }\n void k\n }\n\n const emitDrip = (e: ActiveEmitter, n: number): void => {\n const size = e.size > 0 ? e.size : 0.05\n const stopY = e.reach !== undefined ? Math.max(e.pos[1] - e.reach, floorY) : floorY\n for (let j = 0; j < n; j++) {\n const sx = (rand() - 0.5) * 0.01\n const sz = (rand() - 0.5) * 0.01\n spawn(pools.water, e.pos[0] + sx, e.pos[1], e.pos[2] + sz, e.dir[0] * 0.08, e.dir[1] * 0.08, e.dir[2] * 0.08, 1.4, size * 0.22, size * 0.2, rand(), 1, stopY)\n }\n }\n\n const RATE: Record<EmitterKind, number> = { smoke: 42, steam: 48, fire: 150, flame: 55, spark: 40, water: 0 }\n\n // Stream meshes ----------------------------------------------------------------------------------------------------------------\n const SEG = 12\n const SIDES = 8\n const maxStreams = Math.max(0, Math.floor(options.maxStreams ?? 6))\n const streaksTex = makeStreaks(THREE)\n const streamMat = new THREE.MeshBasicMaterial({ color: 0x9cccff, map: streaksTex, vertexColors: true, transparent: true, opacity: 0.8, depthWrite: false, side: THREE.DoubleSide })\n const streamIndex: number[] = []\n for (let i = 0; i < SEG; i++) {\n for (let m = 0; m < SIDES; m++) {\n const a = i * (SIDES + 1) + m\n const b = a + SIDES + 1\n streamIndex.push(a, b, a + 1, a + 1, b, b + 1)\n }\n }\n const group = new THREE.Group()\n group.name = 'effects:meshes'\n scene.add(group)\n const streams: ThreeNS.Mesh[] = []\n for (let i = 0; i < maxStreams; i++) {\n const geo = new THREE.BufferGeometry()\n const n = (SEG + 1) * (SIDES + 1)\n geo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(n * 3), 3).setUsage(THREE.DynamicDrawUsage))\n geo.setAttribute('color', new THREE.BufferAttribute(new Float32Array(n * 4), 4).setUsage(THREE.DynamicDrawUsage))\n const uv = new Float32Array(n * 2)\n geo.setAttribute('uv', new THREE.BufferAttribute(uv, 2).setUsage(THREE.DynamicDrawUsage))\n geo.setIndex(streamIndex)\n const mesh = new THREE.Mesh(geo, streamMat)\n mesh.frustumCulled = false\n mesh.visible = false\n mesh.name = `effects:stream${i}`\n group.add(mesh)\n streams.push(mesh)\n }\n\n const writeStream = (mesh: ThreeNS.Mesh, k: number): void => {\n const geo = mesh.geometry\n const pos = (geo.getAttribute('position') as ThreeNS.BufferAttribute).array as Float32Array\n const col = (geo.getAttribute('color') as ThreeNS.BufferAttribute).array as Float32Array\n const uv = (geo.getAttribute('uv') as ThreeNS.BufferAttribute).array as Float32Array\n for (let i = 0; i <= SEG; i++) {\n const s = i / SEG\n const t = s * arc.t\n const cx = arc.x + arc.vx * t\n const cy = arc.y + arc.vy * t - 4.9 * t * t\n const cz = arc.z + arc.vz * t\n let tx = arc.vx\n let ty = arc.vy - 9.8 * t\n let tz = arc.vz\n const tl = Math.hypot(tx, ty, tz) || 1\n tx /= tl\n ty /= tl\n tz /= tl\n // binormal = tangent x up, normal = tangent x binormal\n let bx = tz\n const by = 0\n let bz = -tx\n const bl = Math.hypot(bx, bz)\n if (bl < 1e-4) {\n bx = 1\n bz = 0\n } else {\n bx /= bl\n bz /= bl\n }\n const nx = ty * bz - tz * by\n const ny = tz * bx - tx * bz\n const nz = tx * by - ty * bx\n const r = arc.r0 + (arc.r1 - arc.r0) * s\n const alpha = Math.min(1, s * 7) * (0.95 - 0.3 * s) * Math.min(1, 0.55 + k)\n for (let m = 0; m <= SIDES; m++) {\n const a = (m / SIDES) * Math.PI * 2\n const ca = Math.cos(a) * r\n const sa = Math.sin(a) * r\n const v = i * (SIDES + 1) + m\n pos[v * 3] = cx + bx * ca + nx * sa\n pos[v * 3 + 1] = cy + by * ca + ny * sa\n pos[v * 3 + 2] = cz + bz * ca + nz * sa\n col[v * 4] = col[v * 4 + 1] = col[v * 4 + 2] = 1\n col[v * 4 + 3] = alpha\n uv[v * 2] = (m / SIDES) * 3\n uv[v * 2 + 1] = s * arc.t * 2.2\n }\n }\n ;(geo.getAttribute('position') as ThreeNS.BufferAttribute).needsUpdate = true\n ;(geo.getAttribute('color') as ThreeNS.BufferAttribute).needsUpdate = true\n ;(geo.getAttribute('uv') as ThreeNS.BufferAttribute).needsUpdate = true\n mesh.visible = true\n }\n\n // Gas flame rings: every burner is a ring of small blue cones; all rings share one dynamic mesh (one draw call) ------------------\n const CONES = 16\n const maxFlames = Math.max(0, Math.floor(options.maxFlames ?? 16))\n const flameGeo = new THREE.BufferGeometry()\n const flamePos = new THREE.BufferAttribute(new Float32Array(maxFlames * CONES * 4 * 3), 3).setUsage(THREE.DynamicDrawUsage)\n const flameCol = new THREE.BufferAttribute(new Float32Array(maxFlames * CONES * 4 * 3), 3).setUsage(THREE.DynamicDrawUsage)\n flameGeo.setAttribute('position', flamePos)\n flameGeo.setAttribute('color', flameCol)\n const flameIdx: number[] = []\n for (let i = 0; i < maxFlames * CONES; i++) {\n const v = i * 4\n flameIdx.push(v, v + 1, v + 3, v + 1, v + 2, v + 3, v + 2, v, v + 3)\n }\n flameGeo.setIndex(flameIdx)\n flameGeo.setDrawRange(0, 0)\n const flames = new THREE.Mesh(\n flameGeo,\n new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide }),\n )\n flames.frustumCulled = false\n flames.visible = false\n flames.name = 'effects:flames'\n group.add(flames)\n\n const hashOf = (id: string): number => {\n let h = 2166136261\n for (let i = 0; i < id.length; i++) h = Math.imul(h ^ id.charCodeAt(i), 16777619)\n return ((h >>> 0) % 1000) / 1000\n }\n\n const writeFlame = (slot: number, e: ActiveEmitter, time: number): void => {\n const pa = flamePos.array as Float32Array\n const ca = flameCol.array as Float32Array\n const k = Math.min(1, Math.max(0, e.intensity))\n const size = e.size > 0 ? e.size : 0.05\n const R = size * 0.8\n const bw = Math.max(0.004, size * 0.13)\n const phase = hashOf(e.id) * 40\n for (let c = 0; c < CONES; c++) {\n const a = (c / CONES) * Math.PI * 2\n const ux = Math.cos(a)\n const uz = Math.sin(a)\n const bx = e.pos[0] + ux * R\n const bz = e.pos[2] + uz * R\n const by = e.pos[1]\n const h = (0.025 + size * 0.45) * k * (0.55 + 0.45 * Math.abs(Math.sin(time * 19 + c * 2.3 + phase)))\n const v = (slot * CONES + c) * 4\n // base triangle: tangent +, tangent -, radial out; apex leans slightly inwards\n const tx = -uz * bw\n const tz = ux * bw\n pa.set([bx + tx, by, bz + tz, bx - tx, by, bz - tz, bx + ux * bw * 0.9, by, bz + uz * bw * 0.9, bx - ux * h * 0.12, by + h, bz - uz * h * 0.12], v * 3)\n const lo = 0.3 * k\n ca.set([0.2 * k, 0.45 * k, 1 * k, 0.2 * k, 0.45 * k, 1 * k, 0.2 * k, 0.45 * k, 1 * k, 0.02 * lo, 0.1 * lo, 0.5 * lo], v * 3)\n }\n }\n\n const advance = (p: Pool, dt: number): void => {\n let i = 0\n const swayX = wind[0]\n const swayZ = wind[1]\n while (i < p.count) {\n p.age[i] += dt\n const age = p.age[i]\n const life = p.life[i]\n if (age >= life || (p.kind === 'water' && p.pos[i * 3 + 1] < p.ground[i])) {\n // swap-remove\n const last = --p.count\n if (i !== last) {\n p.pos.copyWithin(i * 3, last * 3, last * 3 + 3)\n p.vel.copyWithin(i * 3, last * 3, last * 3 + 3)\n p.age[i] = p.age[last]\n p.life[i] = p.life[last]\n p.size0[i] = p.size0[last]\n p.size1[i] = p.size1[last]\n p.tint[i] = p.tint[last]\n p.flags[i] = p.flags[last]\n p.ground[i] = p.ground[last]\n }\n continue\n }\n const j = i * 3\n switch (p.kind) {\n case 'smoke':\n case 'steam':\n p.vel[j] += (swayX - p.vel[j]) * Math.min(1, dt * 0.8)\n p.vel[j + 2] += (swayZ - p.vel[j + 2]) * Math.min(1, dt * 0.8)\n break\n case 'water':\n if (p.flags[i] !== 4) p.vel[j + 1] -= 9.8 * dt\n break\n case 'spark':\n p.vel[j + 1] -= 7 * dt\n break\n case 'fire':\n p.vel[j] += (swayX * 0.1 - p.vel[j]) * Math.min(1, dt * 2)\n break\n }\n p.pos[j] += p.vel[j] * dt\n p.pos[j + 1] += p.vel[j + 1] * dt\n p.pos[j + 2] += p.vel[j + 2] * dt\n if (p.kind === 'water' && p.pos[j + 1] < p.ground[i]) {\n // landed: stay on the surface and fade out this frame\n p.pos[j + 1] = p.ground[i]\n p.age[i] = p.life[i]\n }\n i++\n }\n }\n\n const write = (p: Pool): void => {\n const n = p.count\n const pa = p.aPos.array as Float32Array\n const sa = p.aSize.array as Float32Array\n const aa = p.aAlpha.array as Float32Array\n const ca = p.aColor.array as Float32Array\n for (let i = 0; i < n; i++) {\n const u = p.age[i] / p.life[i]\n const j = i * 3\n pa[j] = p.pos[j]\n pa[j + 1] = p.pos[j + 1]\n pa[j + 2] = p.pos[j + 2]\n sa[i] = p.size0[i] + (p.size1[i] - p.size0[i]) * u\n let alpha: number\n switch (p.kind) {\n case 'smoke':\n alpha = 0.55 * Math.min(1, u * 8) * (1 - u)\n ca[j] = ca[j + 1] = ca[j + 2] = p.tint[i]\n break\n case 'steam':\n alpha = 0.4 * Math.min(1, u * 6) * (1 - u)\n ca[j] = ca[j + 1] = ca[j + 2] = p.tint[i]\n break\n case 'fire':\n alpha = (p.flags[i] ? 0.95 : 0.8) * (1 - u * u)\n if (p.flags[i]) {\n ca[j] = 0.25 + 0.15 * p.tint[i]\n ca[j + 1] = 0.5 + 0.2 * p.tint[i]\n ca[j + 2] = 1\n } else {\n // yellow core -> orange -> red as it rises\n ca[j] = 1\n ca[j + 1] = Math.max(0.15, 0.85 - u * 0.7 - p.tint[i] * 0.1)\n ca[j + 2] = Math.max(0, 0.25 - u * 0.25)\n }\n break\n case 'spark':\n alpha = 1 - u\n ca[j] = 1\n ca[j + 1] = 0.75 - u * 0.4\n ca[j + 2] = 0.3\n break\n default: {\n const f = p.flags[i]\n alpha = f === 4 ? 0.16 * (1 - u) : f === 3 ? 0.8 * (1 - u * 0.5) : f === 2 ? 0.65 * (1 - u * 0.6) : 0.8\n ca[j] = f === 4 ? 0.85 : 0.5\n ca[j + 1] = f === 4 ? 0.92 : 0.74\n ca[j + 2] = 1\n }\n }\n aa[i] = alpha\n }\n p.aPos.needsUpdate = true\n p.aSize.needsUpdate = true\n p.aAlpha.needsUpdate = true\n p.aColor.needsUpdate = true\n p.points.geometry.setDrawRange(0, n)\n }\n\n return {\n objects,\n meshes: { group, streams, flames },\n update(dt, emitters, cam) {\n camera = cam ?? (typeof cameraSource === 'function' ? cameraSource() : cameraSource)\n refreshScale(camera)\n const step = Math.min(Math.max(dt, 0), 0.1)\n stamp++\n clock += step\n streaksTex.offset.y = -(clock * 2.4) % 1\n let nStreams = 0\n let nFlames = 0\n const due = (key: string, rate: number): number => {\n let d = debt.get(key)\n if (!d) {\n d = { carry: 0, stamp }\n debt.set(key, d)\n }\n d.stamp = stamp\n d.carry += rate * step\n const n = Math.floor(d.carry)\n d.carry -= n\n return n\n }\n for (let i = 0; i < emitters.length; i++) {\n const e = emitters[i]\n if (!(e.intensity > 0)) continue\n const k = Math.min(1, e.intensity)\n const size = e.size > 0 ? e.size : 0.05\n if (e.kind === 'water') {\n if (k < 0.25) {\n const n = due(e.id, 3 + k * 10)\n if (n > 0) emitDrip(e, n)\n } else if (arcOf(e, k)) {\n const nSpray = due(e.id, (60 + 260 * Math.min(size, 0.4)) * k)\n const nSplash = due(`${e.id}#s`, (45 + 90 * Math.min(size, 0.4)) * k)\n const nMist = due(`${e.id}#m`, 6 * k * (1 + size * 4))\n emitWater(e, k, nSpray, nSplash, nMist)\n if (nStreams < streams.length) writeStream(streams[nStreams++], k)\n }\n continue\n }\n if (e.kind === 'flame' && nFlames < maxFlames) writeFlame(nFlames++, e, clock)\n const n = due(e.id, RATE[e.kind] * k)\n if (n > 0) emitFrom(e, n)\n }\n for (let i = nStreams; i < streams.length; i++) streams[i].visible = false\n flames.visible = nFlames > 0\n flameGeo.setDrawRange(0, nFlames * CONES * 9)\n flamePos.needsUpdate = true\n flameCol.needsUpdate = true\n if (debt.size > emitters.length * 3 + 8) {\n for (const [id, d] of debt) if (d.stamp !== stamp) debt.delete(id)\n }\n for (const kind of POOLS) {\n advance(pools[kind], step)\n write(pools[kind])\n }\n },\n setWind(x, z) {\n wind[0] = x\n wind[1] = z\n },\n setCamera(cam) {\n cameraSource = cam\n camera = typeof cam === 'function' ? cam() : cam\n refreshScale(camera)\n },\n setViewHeight(px) {\n viewHeight = px\n refreshScale(camera)\n },\n stats() {\n const byKind = {} as Record<PoolKind, number>\n let alive = 0\n let capacity = 0\n for (const kind of POOLS) {\n byKind[kind] = pools[kind].count\n alive += pools[kind].count\n capacity += pools[kind].cap\n }\n return { alive, capacity, byKind }\n },\n clear() {\n for (const kind of POOLS) {\n pools[kind].count = 0\n write(pools[kind])\n }\n debt.clear()\n for (const m of streams) m.visible = false\n flames.visible = false\n },\n dispose() {\n for (const kind of POOLS) {\n scene.remove(objects[kind])\n objects[kind].geometry.dispose()\n ;(objects[kind].material as ThreeNS.Material).dispose()\n }\n scene.remove(group)\n for (const m of streams) m.geometry.dispose()\n flameGeo.dispose()\n ;(flames.material as ThreeNS.Material).dispose()\n streamMat.dispose()\n streaksTex.dispose()\n sprite.dispose()\n },\n }\n}\n","/** The kinds of particle pool of the effects, as `effects.ts` draws them. */\nexport type PoolKind = 'smoke' | 'steam' | 'fire' | 'spark' | 'water'\n\n/** What `EffectSink.play` of `game-contracts` takes, as a structural type. */\nexport interface ParticleEffectRequest {\n readonly effect: string\n readonly point: [number, number, number]\n readonly values: Readonly<Record<string, number>>\n}\n\n/** The host's effects world as far as the particles need it (`EffectSink` of `game-contracts` fits). */\nexport interface ParticleEffects {\n play(request: ParticleEffectRequest): unknown\n}\n\nexport interface RoutedParticle {\n readonly kind: PoolKind\n readonly flag: number\n readonly position: [number, number, number]\n readonly velocity: [number, number, number]\n readonly life: number\n readonly startSize: number\n readonly endSize: number\n readonly tint: number\n}\n\nconst channel = (value: number): number => Math.round(Math.min(1, Math.max(0, value)) * 255)\nconst rgb = (red: number, green: number, blue: number): number => (channel(red) << 16) | (channel(green) << 8) | channel(blue)\n\nconst EFFECT_OF: Readonly<Partial<Record<PoolKind, string>>> = { smoke: 'particle_puff', steam: 'particle_puff', fire: 'particle_glow', spark: 'particle_streak' }\n\n/** True for the kinds the effects world draws; water stays local because it ends at a height of its own. */\nexport const isRoutedKind = (kind: PoolKind): boolean => EFFECT_OF[kind] !== undefined\n\n/** The numbers of the local particle at birth: the colour and peak opacity the local shader gives it, its life, its two sizes (as a ratio). */\nexport function routedParticleRequest(particle: RoutedParticle): ParticleEffectRequest {\n const { kind, flag, tint } = particle\n const look = lookOf(kind, flag, tint)\n return {\n effect: EFFECT_OF[kind]!,\n point: particle.position,\n values: {\n vx: particle.velocity[0],\n vy: particle.velocity[1],\n vz: particle.velocity[2],\n life: particle.life,\n size: particle.startSize,\n grow: particle.endSize / particle.startSize,\n color: look.color,\n alpha: look.alpha,\n gravity: 0,\n drag: 0,\n },\n }\n}\n\nfunction lookOf(kind: PoolKind, flag: number, tint: number): { color: number; alpha: number } {\n if (kind === 'smoke') return { color: rgb(tint, tint, tint), alpha: 0.55 }\n if (kind === 'steam') return { color: rgb(tint, tint, tint), alpha: 0.4 }\n if (kind === 'spark') return { color: rgb(1, 0.75, 0.3), alpha: 1 }\n if (flag) return { color: rgb(0.25 + 0.15 * tint, 0.5 + 0.2 * tint, 1), alpha: 0.95 }\n return { color: rgb(1, Math.max(0.15, 0.85 - tint * 0.1), 0.25), alpha: 0.8 }\n}\n","import type { Motion, World } from '@adatechnology/game-interactables'\nimport type { LightBudget } from '@adatechnology/game-render-three'\nimport { createEffects, type Effects, type EffectsOptions } from './effects'\nimport { createCord, catenary } from '@adatechnology/game-shapes-three'\nimport { createMeshApi, type MeshApi, type MeshApiOptions } from './mesh'\nimport { createMirrors, type MirrorOptions, type Mirrors } from './mirrors'\nimport { applyPose, syncObject, type SyncOptions } from './pose'\nimport { createScreen, type Screen, type ScreenOptions } from './screen'\nimport { attachSway, swayMaterial, type SwayHandle, type SwayOptions } from './sway'\nimport type { CanvasFactory, Quality, ThreeLib, ThreeNS, Vec3 } from './types'\n\nexport interface ThreeAdapterOptions {\n /** Default for `createMeshApi` / `createScreen` / `createEffects`. */\n document?: CanvasFactory\n quality?: Quality\n materials?: MeshApiOptions['materials']\n /** `Reflector` and env map for `createMirrors`. */\n Reflector?: MirrorOptions['Reflector']\n envMap?: MirrorOptions['envMap']\n /** The host's light budget: the lamps of every mesh api this adapter makes become sources of it (see `MeshApiOptions.lights`). */\n lights?: LightBudget\n}\n\n/** The package functions with `THREE` and the common options already bound. */\nexport interface ThreeAdapter {\n THREE: ThreeLib\n createMeshApi(options?: MeshApiOptions): MeshApi\n applyPose<G extends ThreeNS.Object3D>(group: G, motion: Motion, t: number): G\n syncObject(world: World, objectId: string, parts: Record<string, ThreeNS.Object3D>, options?: SyncOptions): void\n swayMaterial(base: ThreeNS.Material, options?: SwayOptions): ReturnType<typeof swayMaterial>\n attachSway(mesh: ThreeNS.Mesh, options?: SwayOptions): SwayHandle\n createEffects(options: EffectsOptions): Effects\n /** @deprecated Pass `{ scene, camera, ... }`. */\n createEffects(scene: ThreeNS.Object3D, options?: Partial<EffectsOptions>): Effects\n createScreen(options?: Partial<ScreenOptions>): Screen\n createMirrors(options?: MirrorOptions): Mirrors\n createCord(points: readonly Vec3[], radius: number, material: ThreeNS.Material): ThreeNS.Mesh\n catenary: typeof catenary\n}\n\n/** Binds the host's `THREE` (and shared options) once, so the rest of the host code never passes it around. */\nexport function createThreeAdapter(THREE: ThreeLib, options: ThreeAdapterOptions = {}): ThreeAdapter {\n return {\n THREE,\n createMeshApi: (o = {}) => createMeshApi(THREE, { quality: options.quality, materials: options.materials, ...(options.lights ? { lights: options.lights } : {}), ...o }),\n applyPose: (group, motion, t) => applyPose(THREE, group, motion, t),\n syncObject: (world, objectId, parts, o) => syncObject(THREE, world, objectId, parts, o),\n swayMaterial: (base, o) => swayMaterial(THREE, base, o),\n attachSway: (mesh, o) => attachSway(THREE, mesh, o),\n createEffects: ((a: EffectsOptions | ThreeNS.Object3D, o: Partial<EffectsOptions> = {}) =>\n (a as ThreeNS.Object3D).isObject3D\n ? createEffects(THREE, a as ThreeNS.Object3D, { document: options.document, ...o })\n : createEffects(THREE, { document: options.document, ...(a as EffectsOptions) })) as ThreeAdapter['createEffects'],\n createScreen: (o = {}) => {\n const document = o.document ?? options.document\n if (!document) throw new Error('createScreen needs a document (option of createThreeAdapter or of the call)')\n return createScreen(THREE, { ...o, document })\n },\n createMirrors: (o = {}) => createMirrors(THREE, { Reflector: options.Reflector, envMap: options.envMap, ...o }),\n createCord: (points, radius, material) => createCord(THREE, points, radius, material),\n catenary,\n }\n}\n","import { markKitOrigin } from '@adatechnology/game-contracts'\nimport { LIGHT_PRIORITY } from '@adatechnology/game-render-three'\nimport type { LightBudget, SourceHandle } from '@adatechnology/game-render-three'\nimport type { ObjectSpec } from '@adatechnology/game-interactables'\nimport { createShapeRecorder } from '@adatechnology/game-props3d'\nimport { colorChannels, generate } from '@adatechnology/game-shapes'\nimport type { ShapeBatch, ShapePoint } from '@adatechnology/game-shapes'\nimport type { HouseholdApi, MaterialKey, Quality, ThreeLib, ThreeNS } from './types'\nimport { MATERIAL_KEYS } from './types'\nimport { mergeParts } from './merge'\nimport { standOutCoincidentBoxes } from './stand-out'\nimport { rememberRest } from './pose'\n\nexport type MaterialMap = Partial<Record<MaterialKey, ThreeNS.Material>>\n\nexport interface MeshApiOptions {\n /** Materials per key. Missing keys get a default (vertex-colored) material. */\n materials?: MaterialMap\n /** `high`: smoother cylinders and spheres, standard materials. `game`: fewer segments, Lambert materials. Default `high`. */\n quality?: Quality\n /** Cast and receive shadows on the merged meshes. Default true. */\n shadows?: boolean\n /** Make `plane` primitives double sided (applies to the default materials only). Default false. */\n doubleSidedPlanes?: boolean\n /**\n * Cut draw calls: `finish(spec)` merges the parts of one `PartSpec.group` that share a motion (blind slats) and the `cloth` soft\n * volumes (clothes on a line) into one mesh per material (see `mergeParts`). Needs the spec in `finish`. Default: on in `game` quality.\n */\n mergeParts?: boolean\n /** Move the pieces that share a plane with another apart by 2 mm (CLAUDE.md §13, `standOutCoincidentBoxes`). Off by default: it costs about as much as the build itself (shapes-bench); the builders draw their own gaps. */\n standOut?: boolean\n /** Idle flutter of merged cloth. Default 0.04. */\n swayAmplitude?: number\n /**\n * Material of one draw: called per mesh with its material key and the part id (`null` for the static body). Return the material the\n * host wants there (a per-room light mask, a flickering emissive...); the default is `materials[key]`. Merged groups (blind slats,\n * clothes) keep what you return, including its `onBeforeCompile`, `customProgramCacheKey`, `defines` and `userData`.\n */\n materialFor?: (key: MaterialKey, partId: string | null) => ThreeNS.Material | undefined\n /**\n * The host's light budget: each `api.light` becomes a source of it (it competes for a slot by distance, and following its bulb) instead of a `PointLight` of its own, so lamps coming and going\n * never change the lit materials' program key. Without it the lamps are real lights (deprecated, removed in the next major).\n */\n lights?: LightBudget\n}\n\nexport interface MeshResult {\n /** Root group: static meshes (one per material) plus one child group per part (merged parts share one group, see `mergeParts`). */\n group: ThreeNS.Group\n /** Part groups by id. Origin at the pivot, rotated by the part's `ry`; `userData.rest` holds the rest pose. A merged part maps to the shared group (`userData.merged`). */\n parts: Record<string, ThreeNS.Group>\n /** Real lights requested by the builders (already children of their group). Empty with `MeshApiOptions.lights`. */\n lights: ThreeNS.Light[]\n /** With `MeshApiOptions.lights`: the lamps as sources of the budget (`remove()` one when its lamp breaks or the object goes). Empty without it. */\n sources: SourceHandle[]\n}\n\nexport interface FinishOptions {\n /** Same as `MeshApiOptions.materialFor`; wins over it for this call. */\n materialFor?: MeshApiOptions['materialFor']\n}\n\nexport interface MeshApi {\n api: HouseholdApi\n /** Builds the groups from everything drawn so far. Call once; the api is spent afterwards. Pass the spec the pack returned to allow `mergeParts`. */\n finish(spec?: ObjectSpec, finishOptions?: FinishOptions): MeshResult\n /** Materials in use (defaults merged with the given ones). */\n materials: Record<MaterialKey, ThreeNS.Material>\n}\n\n/** Default materials: vertex colors everywhere (in `game` quality plain, metal, wood and fabric are one shared Lambert material), glass and water transparent, emissive unlit. */\nexport function createDefaultMaterials(THREE: ThreeLib, quality: Quality = 'high'): Record<MaterialKey, ThreeNS.Material> {\n // three warns about every parameter that is present but undefined: only pass the ones that are set\n const defined = <T extends object>(o: T): T => {\n const out = {} as T\n for (const k of Object.keys(o) as Array<keyof T>) if (o[k] !== undefined) out[k] = o[k]\n return out\n }\n const std = (p: ThreeNS.MeshStandardMaterialParameters): ThreeNS.Material =>\n quality === 'game'\n ? new THREE.MeshLambertMaterial(defined({ vertexColors: true, transparent: p.transparent, opacity: p.opacity, depthWrite: p.depthWrite, side: p.side }))\n : new THREE.MeshStandardMaterial(defined({ vertexColors: true, roughness: 0.85, metalness: 0, ...p }))\n // Lambert has no roughness or metalness: in `game` quality the opaque default materials are one and the same instance, so the\n // mesh api (which merges per material instance) draws plain, metal, wood and fabric together\n const solid = quality === 'game' ? std({}) : null\n return {\n plain: solid ?? std({}),\n metal: solid ?? std({ roughness: 0.35, metalness: 0.7 }),\n wood: solid ?? std({ roughness: 0.8 }),\n glass: std({ roughness: 0.05, transparent: true, opacity: 0.35, depthWrite: false }),\n fabric: solid ?? std({ roughness: 1 }),\n plant: std({ roughness: 0.9, side: THREE.DoubleSide }),\n water: std({ roughness: 0.1, transparent: true, opacity: 0.7, depthWrite: false }),\n emissive: new THREE.MeshBasicMaterial({ vertexColors: true }),\n atlas_picture: std({ roughness: 0.9 }),\n atlas_floor: std({ roughness: 1 }),\n }\n}\n\n/** The channels three stores for a hex here: linear (three r152+ with colour management on) or the raw sRGB numbers (off, or an older three). */\nconst colorSpaces = new WeakMap<object, 'linear' | 'srgb'>()\nfunction colorSpaceOf(THREE: ThreeLib): 'linear' | 'srgb' {\n const known = colorSpaces.get(THREE.Color)\n if (known) return known\n const space = detectColorSpace(THREE)\n colorSpaces.set(THREE.Color, space)\n return space\n}\nfunction detectColorSpace(THREE: ThreeLib): 'linear' | 'srgb' {\n const color = new THREE.Color()\n for (let c = 0; c < 256; c++) {\n color.setHex(c * 0x010101)\n if (color.r !== colorChannels(c * 0x010101, 'linear')[0]) {\n if (color.r !== c / 255) throw new Error('createMeshApi: this three.js stores colours in a space game-shapes does not know')\n return 'srgb'\n }\n }\n return 'linear'\n}\n\n/**\n * Mesh api for content packs. Every primitive is baked (vertex colors) into one `BufferGeometry` per material and per target\n * (the root, or a part), so the draw calls are the number of materials in use plus the same again for each part.\n *\n * The builders draw into a `game-shapes` schema (`createShapeRecorder` of game-props3d: unit templates, the item frame, parts and lights) and\n * `generate` bakes it; the bytes are the ones this api made with its own templates before (tests/exact-golden.test.ts).\n */\nexport function createMeshApi(THREE: ThreeLib, options: MeshApiOptions = {}): MeshApi {\n const quality: Quality = options.quality ?? 'high'\n const shadows = options.shadows !== false\n const materials = { ...createDefaultMaterials(THREE, quality), ...stripUndefined(options.materials) } as Record<MaterialKey, ThreeNS.Material>\n if (options.doubleSidedPlanes) for (const k of MATERIAL_KEYS) materials[k].side = THREE.DoubleSide\n let finished = false\n\n const recorder = quality === 'high' ? createShapeRecorder({ cylinderSegments: 12, sphereSegments: [12, 8] }) : createShapeRecorder({ cylinderSegments: 8, sphereSegments: [8, 6] })\n\n /** Keys that share a material instance share the geometry too: the first key stands for all of them. */\n const materialAlias: Record<string, string> = {}\n for (const k of MATERIAL_KEYS) {\n const first = MATERIAL_KEYS.find((o) => materials[o] === materials[k]) ?? k\n if (first !== k) materialAlias[k] = first\n }\n\n const lightsOut: ThreeNS.Light[] = []\n const sourcesOut: SourceHandle[] = []\n\n const build = (batches: readonly ShapeBatch[], points: readonly ShapePoint[], id: string | null, into: ThreeNS.Group, materialFor: MeshApiOptions['materialFor']): void => {\n for (const batch of batches) {\n const g = new THREE.BufferGeometry()\n g.setAttribute('position', new THREE.BufferAttribute(batch.positions, 3))\n g.setAttribute('normal', new THREE.BufferAttribute(batch.normals, 3))\n g.setAttribute('color', new THREE.BufferAttribute(batch.colors as Float32Array, 3))\n g.setAttribute('uv', new THREE.BufferAttribute(batch.uvs, 2))\n g.setIndex(new THREE.BufferAttribute(batch.indices as Uint16Array | Uint32Array, 1))\n g.computeBoundingSphere()\n g.computeBoundingBox()\n const key = batch.material as MaterialKey\n const mesh = new THREE.Mesh(g, materialFor?.(key, id) ?? materials[key])\n mesh.name = id === null ? `static:${key}` : `part:${id}`\n if (id !== null) mesh.userData.part = id\n mesh.userData.material = key\n // what the builder drew, primitive by primitive, in the mesh's own space: what a physics engine holds the mesh by, with no vertex read back (spec 019)\n if (batch.solids) mesh.userData.solids = batch.solids\n mesh.castShadow = shadows\n mesh.receiveShadow = shadows\n into.add(mesh)\n }\n for (const point of points) {\n const l = point.data as { color: number; range: number }\n if (options.lights) {\n const bulb = new THREE.Object3D()\n bulb.name = 'lamp'\n bulb.position.set(point.position[0], point.position[1], point.position[2])\n into.add(bulb)\n sourcesOut.push(options.lights.addSource({ owner: 'interactables.lamp', priority: LIGHT_PRIORITY.lamp, color: l.color, intensity: 1, distance: l.range, position: [0, 0, 0], follow: bulb }))\n continue\n }\n // eslint-disable-next-line no-restricted-syntax -- D2: legacy path without LightBudget, removed in the next major\n const light = new THREE.PointLight(l.color, 1, l.range)\n light.position.set(point.position[0], point.position[1], point.position[2])\n into.add(light)\n lightsOut.push(light)\n }\n }\n\n return {\n api: recorder.api,\n materials,\n finish(spec, finishOptions) {\n const materialFor = finishOptions?.materialFor ?? options.materialFor\n if (finished) throw new Error('createMeshApi: finish() was already called')\n finished = true\n const buffers = generate(options.standOut === true ? standOutCoincidentBoxes(recorder.schema()) : recorder.schema(), {\n colors: colorSpaceOf(THREE),\n materials: MATERIAL_KEYS,\n fallbackMaterial: 'plain',\n materialAlias,\n validate: false,\n key: false,\n solids: true,\n })\n const batches = buffers.levels[0]?.batches ?? []\n const of = (id: string | null): { batches: ShapeBatch[]; points: ShapePoint[] } => ({ batches: batches.filter((b) => b.part === id), points: buffers.points.filter((p) => p.part === id) })\n const group = markKitOrigin(new THREE.Group(), { owner: 'game-interactables-three', kind: 'furniture', ...(spec ? { id: spec.type } : {}) })\n group.name = 'interactable'\n const parts: Record<string, ThreeNS.Group> = {}\n const body = of(null)\n build(body.batches, body.points, null, group, materialFor)\n for (const part of recorder.parts) {\n const g = new THREE.Group()\n g.name = `part:${part.id}`\n g.userData.part = part.id\n g.position.set(part.pivot[0], part.pivot[1], part.pivot[2])\n g.rotation.y = part.ry\n g.updateMatrix()\n const drawn = of(part.id)\n build(drawn.batches, drawn.points, part.id, g, materialFor)\n rememberRest(g)\n group.add(g)\n parts[part.id] = g\n }\n if (spec && (options.mergeParts ?? quality === 'game')) mergeParts(THREE, group, parts, spec, { swayAmplitude: options.swayAmplitude })\n if (spec) tagDestruction(group, parts, spec)\n return { group, parts, lights: lightsOut, sources: sourcesOut }\n },\n }\n}\n\n/**\n * Copies the spec's destruction tags onto the objects: `userData.destructionMaterial` (SDK material id) and, on part groups,\n * `userData.destructionPart` (the part id, the key @adatechnology/game-destruction-three binds by), `userData.destructionPiece` and\n * `userData.destructionJoint`. Static meshes get the object default; the meshes of a part get the part's tags.\n * Parts merged into a shared group (blind slats) carry the tags of the first part of the group.\n */\nfunction tagDestruction(group: ThreeNS.Group, parts: Record<string, ThreeNS.Group>, spec: ObjectSpec): void {\n const body = spec.destruction\n const partGroups = new Set<ThreeNS.Object3D>(Object.values(parts))\n if (body) {\n for (const child of group.children) {\n if (!partGroups.has(child) && (child as ThreeNS.Mesh).isMesh) child.userData.destructionMaterial = body.material\n }\n }\n const done = new Set<ThreeNS.Object3D>()\n for (const ps of spec.parts ?? []) {\n const g = parts[ps.id]\n const d = ps.destruction\n if (!g || !d || done.has(g)) continue\n done.add(g)\n for (const o of [g, ...g.children]) {\n if (o !== g && !(o as ThreeNS.Mesh).isMesh) continue\n o.userData.destructionMaterial = d.material\n o.userData.destructionPart = ps.id\n if (d.piece) o.userData.destructionPiece = d.piece\n if (d.joint) o.userData.destructionJoint = d.joint\n }\n }\n}\n\nfunction stripUndefined<T extends object>(o: T | undefined): Partial<T> {\n const out: Partial<T> = {}\n if (o) for (const k of Object.keys(o) as Array<keyof T>) if (o[k] !== undefined) out[k] = o[k]\n return out\n}\n","import type * as ThreeNS from 'three'\nimport type { PropsApi } from '@adatechnology/game-props3d'\n\n/** The host's `THREE` namespace (or any object with the same classes). Always passed in, never imported at runtime. */\nexport type ThreeLib = typeof ThreeNS\nexport type { ThreeNS }\n\nexport type Vec3 = [number, number, number]\n\n/** Material keys the mesh api understands (same as `PropsApi` materials). */\nexport type MaterialKey = 'plain' | 'metal' | 'wood' | 'glass' | 'fabric' | 'plant' | 'water' | 'emissive' | 'atlas_picture' | 'atlas_floor'\n\nexport const MATERIAL_KEYS: readonly MaterialKey[] = ['plain', 'metal', 'wood', 'glass', 'fabric', 'plant', 'water', 'emissive', 'atlas_picture', 'atlas_floor']\n\nexport type Quality = 'high' | 'game'\n\n/**\n * What content packs draw through: the props primitives plus `part`.\n * `part(id, pivot, ry, draw)` runs `draw()` and routes every primitive drawn inside it into the movable part `id`.\n * `pivot` is object-local; the primitives drawn inside `draw` are in the part frame (relative to the pivot, turned by `ry`): the part's\n * group origin sits at `pivot`, turned by `ry` around +y.\n */\nexport interface HouseholdApi extends PropsApi {\n part(id: string, pivot: Vec3, ry: number, draw: () => void): void\n}\n\n/** Anything that can create a canvas (the global `document`, or a fake in tests). */\nexport interface CanvasFactory {\n createElement(tag: 'canvas'): HTMLCanvasElement\n}\n","import { poseOf as enginePoseOf } from '@adatechnology/game-interactables'\nimport type { Motion, World } from '@adatechnology/game-interactables'\nimport type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/** Pure pose of a part at `t`, in the part's own frame (the frame at rest: pivot at the origin, already turned by the part's `ry`). */\nexport interface Pose {\n /** Translation, part frame. */\n position: Vec3\n /** Rotation as a quaternion [x, y, z, w], part frame. */\n quaternion: [number, number, number, number]\n /** Scale per local axis. */\n scale: Vec3\n}\n\n/**\n * The engine's pose math, as a quaternion. This is the engine's own `poseOf` (same default angles and distances), so the rendered\n * part and the engine's `slotPosition`, colliders, mirrors and `fitSweep` always agree. `t` is clamped to [0, 1].\n */\nexport function poseOf(motion: Motion, t: number): Pose {\n const k = Math.min(1, Math.max(0, Number.isFinite(t) ? t : 0))\n const pose = enginePoseOf(motion, k)\n const [x, y, z] = pose.rotation.axis\n const l = Math.hypot(x, y, z) || 1\n const s = Math.sin(pose.rotation.angle / 2)\n return {\n position: [pose.position[0], pose.position[1], pose.position[2]],\n quaternion: [(x / l) * s, (y / l) * s, (z / l) * s, Math.cos(pose.rotation.angle / 2)],\n scale: [pose.scale[0], pose.scale[1], pose.scale[2]],\n }\n}\n\ninterface Rest {\n position: Vec3\n quaternion: [number, number, number, number]\n scale: Vec3\n}\n\n/** Remembers the rest transform of a part group in `userData.rest` (once). */\nexport function rememberRest(group: Pick<ThreeNS.Object3D, 'position' | 'quaternion' | 'scale' | 'userData'>): Rest {\n let rest = group.userData.rest as Rest | undefined\n if (!rest) {\n const p = group.position\n const q = group.quaternion\n const s = group.scale\n rest = { position: [p.x, p.y, p.z], quaternion: [q.x, q.y, q.z, q.w], scale: [s.x, s.y, s.z] }\n group.userData.rest = rest\n }\n return rest\n}\n\n/**\n * Poses `group` for a motion at `t`. The rest pose (position at the pivot, rotation `ry`) is saved in `group.userData.rest` the first\n * time, so calling this every frame never drifts. The motion axis lives in the part frame (after `ry`).\n */\nexport function applyPose<G extends import('three').Object3D>(THREE: ThreeLib, group: G, motion: Motion, t: number): G {\n const rest = rememberRest(group)\n const pose = poseOf(motion, t)\n const restQ = new THREE.Quaternion(rest.quaternion[0], rest.quaternion[1], rest.quaternion[2], rest.quaternion[3])\n const delta = new THREE.Quaternion(pose.quaternion[0], pose.quaternion[1], pose.quaternion[2], pose.quaternion[3])\n group.quaternion.copy(restQ).multiply(delta)\n const offset = new THREE.Vector3(pose.position[0], pose.position[1], pose.position[2]).applyQuaternion(restQ)\n group.position.set(rest.position[0] + offset.x, rest.position[1] + offset.y, rest.position[2] + offset.z)\n group.scale.set(rest.scale[0] * pose.scale[0], rest.scale[1] * pose.scale[1], rest.scale[2] * pose.scale[2])\n group.updateMatrix()\n return group\n}\n\nexport interface SyncOptions {\n /** Seconds, drives the idle flutter of sway shaders. Default 0. */\n time?: number\n}\n\n/**\n * Per-frame sync of one world object: every part group takes the motion of its `PartSpec` at the world's current t,\n * and every soft volume swings. A soft volume drives the group in `parts` under its `part` (or, failing that, its own id):\n * meshes patched with `attachSway` get the swing through their shader uniforms (so shadows follow), any other group is rotated\n * around the anchor line.\n */\nexport function syncObject(THREE: ThreeLib, world: World, objectId: string, parts: Record<string, import('three').Object3D>, options: SyncOptions = {}): void {\n const obj = world.get(objectId)\n if (!obj) return\n const motionOf = new Map<string, Motion>()\n for (const p of obj.spec.parts ?? []) {\n motionOf.set(p.id, p.motion)\n const g = parts[p.id]\n if (!g) continue\n const merged = g.userData.merged as { kind: string; apply?: (m: Motion, t: number) => void } | undefined\n if (merged) {\n // parts merged into one mesh: the batch poses every vertex around its own pivot (cloth batches stay at rest)\n merged.apply?.(p.motion, world.partT(objectId, p.id))\n continue\n }\n applyPose(THREE, g, p.motion, world.partT(objectId, p.id))\n }\n for (const soft of obj.spec.soft ?? []) {\n const key = soft.part ?? soft.id\n const g = parts[key] ?? parts[soft.id]\n if (!g) continue\n const { ax, az } = world.sway(objectId, soft.id)\n const batch = g.userData.merged as { kind: string; index?: Record<string, number>; setAt?: (i: number, ax: number, az: number) => void; setTime?: (t: number) => void } | undefined\n if (batch?.kind === 'sway') {\n const i = batch.index?.[soft.id]\n if (i !== undefined) batch.setAt?.(i, ax, az)\n if (options.time !== undefined) batch.setTime?.(options.time)\n continue\n }\n let shaded = false\n g.traverse((o) => {\n const sway = o.userData.sway as { set(ax: number, az: number, time?: number): void } | undefined\n if (sway) {\n sway.set(ax, az, options.time)\n shaded = true\n }\n })\n if (shaded) continue\n rememberRest(g)\n // rotate around the anchor line: the part's pose (if it has a motion) is already applied above\n if (!motionOf.has(key)) applyPose(THREE, g, { kind: 'hinge', angle: 0 }, 0)\n const rot = new THREE.Quaternion().setFromEuler(new THREE.Euler(ax, 0, az, 'XYZ'))\n const anchor = new THREE.Vector3(soft.anchor[0], soft.anchor[1], soft.anchor[2])\n g.position.sub(anchor).applyQuaternion(rot).add(anchor)\n g.quaternion.premultiply(rot)\n g.updateMatrix()\n }\n}\n","import type { Motion, ObjectSpec } from '@adatechnology/game-interactables'\nimport type { ShapeSolid } from '@adatechnology/game-shapes'\nimport { poseOf } from './pose'\nimport type { ThreeLib, ThreeNS } from './types'\n\nexport interface MergeOptions {\n /** Idle flutter of merged cloth (see `SwayOptions.amplitude`). Default 0.04. */\n swayAmplitude?: number\n}\n\n/** Posed by `syncObject` in place of the part groups it replaced. */\nexport interface PoseBatch {\n kind: 'pose'\n /** Part ids that moved into the batch. */\n ids: string[]\n /** Applies the motion at `t` to every vertex, each around its own pivot. */\n apply(motion: Motion, t: number): void\n}\n\n/** Cloth hanging from a line: every merged cloth swings with its own (ax, az). */\nexport interface SwayBatch {\n kind: 'sway'\n /** Soft volume id -> index. */\n index: Record<string, number>\n setAt(index: number, ax: number, az: number): void\n setTime(time: number): void\n}\n\nexport type MergedGroup = ThreeNS.Group & { userData: { merged: PoseBatch | SwayBatch } }\n\nconst QROT = /* glsl */ `\nvec3 batchRotate(vec4 q, vec3 v) { return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v); }\n`\n\nfunction patchProgram<M extends ThreeNS.Material>(material: M, key: string, patchShader: (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }) => void, inherit?: ThreeNS.Material): M {\n const previous = material.onBeforeCompile\n material.onBeforeCompile = (shader, renderer) => {\n previous?.call(material, shader, renderer)\n patchShader(shader)\n }\n const inherited = inherit?.customProgramCacheKey\n material.customProgramCacheKey = inherited && inherit ? () => `${inherited.call(inherit)}|${key}` : () => key\n return material\n}\n\n/**\n * `Material.clone()` drops `onBeforeCompile`, `customProgramCacheKey` and (for some classes) `defines`. A merged group must still look\n * like the material the host passed in (a light mask, a fog patch...), so the clone gets them back before the batch patch is chained on.\n */\nfunction cloneKeepingHooks(base: ThreeNS.Material): ThreeNS.Material {\n const clone = base.clone()\n if (base.defines) clone.defines = { ...(clone.defines ?? {}), ...base.defines }\n if (base.onBeforeCompile !== Object.getPrototypeOf(base).onBeforeCompile) clone.onBeforeCompile = base.onBeforeCompile\n clone.userData = { ...base.userData, mergedFrom: base.uuid }\n return clone\n}\n\n/** Material, depth material and distance material patched by the same function, so shadows follow the animation. */\nfunction patchedSet(THREE: ThreeLib, base: ThreeNS.Material, key: string, patchShader: (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }) => void) {\n return {\n material: patchProgram(cloneKeepingHooks(base), key, patchShader, base),\n depth: patchProgram(new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }), key, patchShader),\n distance: patchProgram(new THREE.MeshDistanceMaterial(), key, patchShader),\n }\n}\n\ninterface Piece {\n geometry: ThreeNS.BufferGeometry\n matrix: ThreeNS.Matrix4\n /** Per-vertex extra attributes of this piece. */\n extra: Record<string, number[]>\n /** The solids the piece's mesh carries (`userData.solids`), in the piece's own space. */\n solids?: readonly ShapeSolid[] | undefined\n}\n\n/** Concatenates pieces (positions and normals moved by their matrices) into one geometry with the extra attributes. */\nfunction concat(THREE: ThreeLib, pieces: readonly Piece[], extraSizes: Record<string, number>): ThreeNS.BufferGeometry {\n let verts = 0\n let idx = 0\n for (const p of pieces) {\n verts += p.geometry.getAttribute('position').count\n idx += p.geometry.index!.count\n }\n const pos = new Float32Array(verts * 3)\n const nor = new Float32Array(verts * 3)\n const col = new Float32Array(verts * 3)\n const uv = new Float32Array(verts * 2)\n const index = new Uint32Array(idx)\n const extra: Record<string, Float32Array> = {}\n for (const [k, n] of Object.entries(extraSizes)) extra[k] = new Float32Array(verts * n)\n const v = new THREE.Vector3()\n const n3 = new THREE.Matrix3()\n let vo = 0\n let io = 0\n for (const p of pieces) {\n const g = p.geometry\n const count = g.getAttribute('position').count\n n3.getNormalMatrix(p.matrix)\n const gp = g.getAttribute('position')\n const gn = g.getAttribute('normal')\n const gc = g.getAttribute('color')\n const gu = g.getAttribute('uv')\n for (let i = 0; i < count; i++) {\n v.fromBufferAttribute(gp, i).applyMatrix4(p.matrix)\n pos.set([v.x, v.y, v.z], (vo + i) * 3)\n v.fromBufferAttribute(gn, i).applyMatrix3(n3).normalize()\n nor.set([v.x, v.y, v.z], (vo + i) * 3)\n col.set([gc.getX(i), gc.getY(i), gc.getZ(i)], (vo + i) * 3)\n uv.set([gu.getX(i), gu.getY(i)], (vo + i) * 2)\n }\n for (const [k, values] of Object.entries(p.extra)) extra[k].set(values, vo * extraSizes[k])\n const gi = g.index!\n for (let i = 0; i < gi.count; i++) index[io + i] = gi.getX(i) + vo\n vo += count\n io += gi.count\n }\n const out = new THREE.BufferGeometry()\n out.setAttribute('position', new THREE.BufferAttribute(pos, 3))\n out.setAttribute('normal', new THREE.BufferAttribute(nor, 3))\n out.setAttribute('color', new THREE.BufferAttribute(col, 3))\n out.setAttribute('uv', new THREE.BufferAttribute(uv, 2))\n for (const [k, n] of Object.entries(extraSizes)) out.setAttribute(k, new THREE.BufferAttribute(extra[k], n))\n out.setIndex(new THREE.BufferAttribute(verts > 65535 ? index : new Uint16Array(index), 1))\n out.computeBoundingSphere()\n out.computeBoundingBox()\n return out\n}\n\n/**\n * The solids of the pieces joined in one mesh (spec 019): each piece's own (`userData.solids` of its mesh), carried by the piece's place and numbered after the vertices of\n * the pieces before it. None when a piece has none: a mesh that says only some of what it draws would be held by less than it is.\n */\nfunction mergedSolids(THREE: ThreeLib, pieces: readonly Piece[]): ShapeSolid[] | undefined {\n if (pieces.some((p) => !p.solids)) return undefined\n const out: ShapeSolid[] = []\n const position = new THREE.Vector3()\n const turn = new THREE.Quaternion()\n const scale = new THREE.Vector3()\n const centre = new THREE.Vector3()\n const own = new THREE.Quaternion()\n let first = 0\n for (const p of pieces) {\n p.matrix.decompose(position, turn, scale)\n for (const solid of p.solids ?? []) {\n centre.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(p.matrix)\n own.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]).premultiply(turn).normalize()\n out.push({\n ...solid,\n center: [centre.x, centre.y, centre.z],\n half: [solid.half[0] * Math.abs(scale.x), solid.half[1] * Math.abs(scale.y), solid.half[2] * Math.abs(scale.z)],\n rotation: [own.x, own.y, own.z, own.w],\n vertexStart: solid.vertexStart + first,\n })\n }\n first += p.geometry.getAttribute('position').count\n }\n return out\n}\n\nfunction meshesOf(group: ThreeNS.Object3D): ThreeNS.Mesh[] {\n return group.children.filter((c): c is ThreeNS.Mesh => (c as ThreeNS.Mesh).isMesh)\n}\n\n/**\n * Merges parts after `finish()` to cut draw calls (the `mergeParts` option of `createMeshApi`):\n *\n * - parts of one `PartSpec.group` with the same motion (blind slats) become one mesh per material whose vertices carry their own pivot;\n * `syncObject` poses them with one set of uniforms and the shadow materials follow;\n * - `cloth` soft volumes (clothes on a line) become one mesh per material with a per-vertex cloth index and anchor height; each\n * cloth keeps its own swing.\n *\n * The merged group is added to `root`, the part groups are removed, and `parts[id]` points at the merged group for every member.\n * Parts that carry a mirror, that are turned (`ry`) or that stand alone are left as they are.\n */\nexport function mergeParts(THREE: ThreeLib, root: ThreeNS.Group, parts: Record<string, ThreeNS.Group>, spec: ObjectSpec, options: MergeOptions = {}): void {\n const amplitude = options.swayAmplitude ?? 0.04\n const skip = new Set<string>()\n for (const m of spec.mirrors ?? []) if (m.part) skip.add(m.part)\n for (const [id, g] of Object.entries(parts)) if (Math.abs(g.rotation.y) > 1e-9 || g.userData.merged) skip.add(id)\n\n const take = (ids: string[]): ThreeNS.Group[] => ids.map((id) => parts[id])\n const retire = (ids: string[], merged: ThreeNS.Group): void => {\n for (const id of ids) {\n const g = parts[id]\n g.removeFromParent()\n for (const m of meshesOf(g)) m.geometry.dispose()\n parts[id] = merged\n }\n root.add(merged)\n }\n const byMaterial = (groups: ThreeNS.Group[], extra: (g: ThreeNS.Group, count: number) => Record<string, number[]>) => {\n const map = new Map<string, { base: ThreeNS.Material; pieces: Piece[]; mesh: ThreeNS.Mesh }>()\n for (const g of groups) {\n g.updateMatrix()\n for (const mesh of meshesOf(g)) {\n const key = `${String(mesh.userData.material)}|${(mesh.material as ThreeNS.Material).uuid}`\n let e = map.get(key)\n if (!e) {\n e = { base: mesh.material as ThreeNS.Material, pieces: [], mesh }\n map.set(key, e)\n }\n e.pieces.push({ geometry: mesh.geometry, matrix: g.matrix, extra: extra(g, mesh.geometry.getAttribute('position').count), solids: mesh.userData.solids as readonly ShapeSolid[] | undefined })\n }\n }\n return map\n }\n const finishMesh = (name: string, key: string, pieces: readonly Piece[], extraSizes: Record<string, number>, template: ThreeNS.Mesh, set: ReturnType<typeof patchedSet>, group: ThreeNS.Group): void => {\n const mesh = new THREE.Mesh(concat(THREE, pieces, extraSizes), set.material)\n mesh.name = `${name}:${key}`\n mesh.userData.material = key\n const solids = mergedSolids(THREE, pieces)\n if (solids) mesh.userData.solids = solids\n mesh.castShadow = template.castShadow\n mesh.receiveShadow = template.receiveShadow\n mesh.customDepthMaterial = set.depth\n mesh.customDistanceMaterial = set.distance\n group.add(mesh)\n }\n\n // ---- cloth: one swing per soft volume, merged per material -------------------------------------------------------------------\n const cloths = (spec.soft ?? []).filter((s) => s.kind === 'cloth' && parts[s.part ?? s.id] && !skip.has(s.part ?? s.id))\n const clothPart = (s: { id: string; part?: string }) => s.part ?? s.id\n const toggled = new Set<string>()\n for (const i of spec.interactions ?? []) {\n const a = i.action as { do: string; part?: string }\n if (a.do === 'toggle_part' && a.part) toggled.add(a.part)\n }\n const swing = cloths.filter((s) => !toggled.has(clothPart(s)))\n if (swing.length >= 2) {\n const ids = swing.map(clothPart)\n const index: Record<string, number> = {}\n swing.forEach((s, i) => (index[s.id] = i))\n const indexOfPart = new Map(swing.map((s, i) => [clothPart(s), i]))\n const anchorOfPart = new Map(swing.map((s) => [clothPart(s), s.anchor[1]]))\n const n = swing.length\n const uniforms = { time: { value: 0 }, axz: { value: Array.from({ length: n }, () => new THREE.Vector2()) } }\n const groups = take(ids)\n const partIdOf = new Map(groups.map((g, i) => [g, ids[i]]))\n const plan = byMaterial(groups, (g, count) => {\n const id = partIdOf.get(g)!\n return { swayId: new Array(count).fill(indexOf(indexOfPart, id)), swayAnchor: new Array(count).fill(anchorOfPart.get(id) ?? 0) }\n })\n const merged = new THREE.Group() as unknown as MergedGroup\n merged.name = 'merge:cloth'\n const patch = (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }): void => {\n shader.uniforms.swayTime = uniforms.time\n shader.uniforms.swayAxz = uniforms.axz\n shader.vertexShader =\n `attribute float swayId;\\nattribute float swayAnchor;\\nuniform float swayTime;\\nuniform vec2 swayAxz[${n}];\\n` +\n shader.vertexShader.replace(\n '#include <begin_vertex>',\n `#include <begin_vertex>\n{\n vec2 swayA = swayAxz[int(swayId + 0.5)];\n float swayHang = max(swayAnchor - position.y, 0.0);\n float swayFlutter = ${amplitude.toFixed(4)} * sin(swayTime * 1.9 + swayId * 1.7 + position.x * 4.0 + position.z * 3.0 + swayHang * 3.0);\n transformed.x += swayHang * (sin(swayA.y) + swayFlutter);\n transformed.z += swayHang * (-sin(swayA.x) + swayFlutter * 0.6);\n transformed.y += swayHang * (1.0 - cos(swayA.y) * cos(swayA.x));\n}`,\n )\n }\n for (const e of plan.values()) {\n const key = String(e.mesh.userData.material)\n const set = patchedSet(THREE, e.base, `swayBatch:${n}:${amplitude}`, patch)\n finishMesh('merge:cloth', key, e.pieces, { swayId: 1, swayAnchor: 1 }, e.mesh, set, merged)\n }\n const batch: SwayBatch = {\n kind: 'sway',\n index,\n setAt(i, ax, az) {\n uniforms.axz.value[i].set(ax, az)\n },\n setTime(t) {\n uniforms.time.value = t\n },\n }\n merged.userData.merged = batch\n retire(ids, merged)\n for (const id of ids) skip.add(id)\n }\n\n // ---- grouped parts with identical motion (blind slats) -----------------------------------------------------------------------\n const bySignature = new Map<string, string[]>()\n for (const p of spec.parts ?? []) {\n if (!p.group || !parts[p.id] || skip.has(p.id)) continue\n const sig = `${p.group}|${JSON.stringify(p.motion)}`\n const list = bySignature.get(sig)\n if (list) list.push(p.id)\n else bySignature.set(sig, [p.id])\n }\n for (const [sig, ids] of bySignature) {\n if (ids.length < 2) continue\n const motion = (spec.parts ?? []).find((p) => p.id === ids[0])!.motion\n const uniforms = { q: { value: new THREE.Vector4(0, 0, 0, 1) }, pos: { value: new THREE.Vector3() }, scale: { value: new THREE.Vector3(1, 1, 1) } }\n const groups = take(ids)\n const plan = byMaterial(groups, (g, count) => {\n const pv = new Array<number>(count * 3)\n for (let i = 0; i < count; i++) {\n pv[i * 3] = g.position.x\n pv[i * 3 + 1] = g.position.y\n pv[i * 3 + 2] = g.position.z\n }\n return { batchPivot: pv }\n })\n const merged = new THREE.Group() as unknown as MergedGroup\n merged.name = `merge:${sig.split('|')[0]}`\n const patch = (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }): void => {\n shader.uniforms.batchQ = uniforms.q\n shader.uniforms.batchPos = uniforms.pos\n shader.uniforms.batchScale = uniforms.scale\n let src = `attribute vec3 batchPivot;\\nuniform vec4 batchQ;\\nuniform vec3 batchPos;\\nuniform vec3 batchScale;\\n${QROT}${shader.vertexShader}`\n src = src.replace('#include <begin_vertex>', '#include <begin_vertex>\\ntransformed = batchPivot + batchRotate(batchQ, (position - batchPivot) * batchScale) + batchPos;')\n src = src.replace('#include <beginnormal_vertex>', '#include <beginnormal_vertex>\\nobjectNormal = batchRotate(batchQ, objectNormal);')\n shader.vertexShader = src\n }\n for (const e of plan.values()) {\n const key = String(e.mesh.userData.material)\n const set = patchedSet(THREE, e.base, 'poseBatch', patch)\n finishMesh(merged.name, key, e.pieces, { batchPivot: 3 }, e.mesh, set, merged)\n }\n const batch: PoseBatch = {\n kind: 'pose',\n ids,\n apply(m, t) {\n const pose = poseOf(m, t)\n uniforms.q.value.set(pose.quaternion[0], pose.quaternion[1], pose.quaternion[2], pose.quaternion[3])\n uniforms.pos.value.set(pose.position[0], pose.position[1], pose.position[2])\n uniforms.scale.value.set(pose.scale[0], pose.scale[1], pose.scale[2])\n },\n }\n batch.apply(motion, 0)\n merged.userData.merged = batch\n retire(ids, merged)\n }\n}\n\nfunction indexOf(map: Map<string, number>, id: string): number {\n return map.get(id) ?? 0\n}\n","import type { ShapeNode, ShapeSchema } from '@adatechnology/game-shapes'\n\ntype Vector = [number, number, number]\ntype Point2 = [number, number]\n/** Row-major 3x3. */\ntype Matrix = readonly number[]\n\n/** How far a face moves to leave the plane it shared (CLAUDE.md §13: a detail stands out or sinks at least 2 mm). */\nconst GAP = 0.002\n/** The guard's reach: two faces closer than this are one plane. */\nconst SAME_PLANE = 0.00105\n/** Faces whose normals differ by less than this (per component) are parallel to the guard. */\nconst SAME_DIRECTION = 0.0015\n/** Overlaps below this (m²) are edge contacts; the guard's own floor is 1e-4. */\nconst MIN_OVERLAP_AREA = 5e-5\n/** A piece thinner than this along the axis grows out instead of sinking in. */\nconst MIN_THICKNESS_TO_SINK = 0.012\nconst MAX_ROUNDS = 6\nconst IDENTITY: Matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\ntype Writable = { position?: Vector; rotation?: Vector; rotationOrder?: string; scale?: number | Vector; heading?: number; matrix?: unknown; children?: Writable[]; kind: string; radiusTop?: number; radiusBottom?: number; size?: Vector }\n\ntype Piece = {\n readonly node: Writable\n /** Rotation of the parent frame (frame to world). */\n readonly parentRotation: Matrix\n readonly center: Vector\n /** World direction of each local axis. */\n readonly axes: readonly [Vector, Vector, Vector]\n readonly half: Vector\n /** A cylinder only has flat faces on its own height axis. */\n readonly isCylinder: boolean\n /** A plane has one face and no thickness. */\n readonly isPlane: boolean\n}\n\ntype Face = { readonly piece: Piece; readonly axis: number; readonly sign: number; readonly normal: Vector; readonly offset: number }\n\nconst dot = (a: Vector, b: Vector): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2]\nconst cross = (a: Vector, b: Vector): Vector => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]\n\nfunction multiply(a: Matrix, b: Matrix): Matrix {\n const out: number[] = []\n for (let row = 0; row < 3; row++) for (let column = 0; column < 3; column++) out.push(a[row * 3]! * b[column]! + a[row * 3 + 1]! * b[3 + column]! + a[row * 3 + 2]! * b[6 + column]!)\n return out\n}\n\nfunction rotationAbout(axis: number, angle: number): Matrix {\n const c = Math.cos(angle)\n const s = Math.sin(angle)\n if (axis === 0) return [1, 0, 0, 0, c, -s, 0, s, c]\n if (axis === 1) return [c, 0, s, 0, 1, 0, -s, 0, c]\n return [c, -s, 0, s, c, 0, 0, 0, 1]\n}\n\n/** The rotation of a node as three composes it: the heading about y first, then the euler angles in their order (`'YXZ'` is Ry * Rx * Rz). */\nfunction rotationOf(node: Writable): Matrix {\n let matrix = node.heading ? rotationAbout(1, node.heading) : IDENTITY\n if (node.rotation) {\n for (const letter of node.rotationOrder ?? 'XYZ') matrix = multiply(matrix, rotationAbout('XYZ'.indexOf(letter), node.rotation['XYZ'.indexOf(letter)]!))\n }\n return matrix\n}\n\nfunction apply(matrix: Matrix, vector: Vector): Vector {\n return [0, 1, 2].map((row) => matrix[row * 3]! * vector[0] + matrix[row * 3 + 1]! * vector[1] + matrix[row * 3 + 2]! * vector[2]) as Vector\n}\n\nfunction transpose(matrix: Matrix): Matrix {\n return [matrix[0]!, matrix[3]!, matrix[6]!, matrix[1]!, matrix[4]!, matrix[7]!, matrix[2]!, matrix[5]!, matrix[8]!]\n}\n\nfunction pieceOf(node: Writable, parentOrigin: Vector, parentRotation: Matrix): Piece | undefined {\n if (node.matrix || node.size || !Array.isArray(node.scale) || !node.position) return undefined\n const isCylinder = node.kind === 'cylinder'\n const isPlane = node.kind === 'plane'\n if (isCylinder && (node.radiusTop ?? 1) !== (node.radiusBottom ?? 1)) return undefined\n const rotation = multiply(parentRotation, rotationOf(node))\n const axes = [0, 1, 2].map((column) => [rotation[column]!, rotation[3 + column]!, rotation[6 + column]!] as Vector) as unknown as Piece['axes']\n const half: Vector = isCylinder ? [node.scale[0]!, node.scale[1]! / 2, node.scale[2]!] : isPlane ? [node.scale[0]! / 2, node.scale[1]! / 2, 0] : [node.scale[0]! / 2, node.scale[1]! / 2, node.scale[2]! / 2]\n const offset = apply(parentRotation, node.position)\n return { node, parentRotation, center: [parentOrigin[0] + offset[0]!, parentOrigin[1] + offset[1]!, parentOrigin[2] + offset[2]!], axes, half, isCylinder, isPlane }\n}\n\nfunction collect(nodes: readonly ShapeNode[], origin: Vector, rotation: Matrix, out: Piece[]): void {\n for (const source of nodes) {\n const node = source as unknown as Writable\n if (node.kind === 'group') {\n if (node.matrix || node.scale !== undefined) continue\n const offset = apply(rotation, node.position ?? [0, 0, 0])\n collect((node.children ?? []) as unknown as readonly ShapeNode[], [origin[0] + offset[0]!, origin[1] + offset[1]!, origin[2] + offset[2]!], multiply(rotation, rotationOf(node)), out)\n } else if (node.kind === 'box' || node.kind === 'cylinder' || node.kind === 'plane') {\n const piece = pieceOf(node, origin, rotation)\n if (piece) out.push(piece)\n }\n }\n}\n\nfunction faceOf(piece: Piece, axis: number, sign: number): Face {\n const normal: Vector = [piece.axes[axis]![0] * sign, piece.axes[axis]![1] * sign, piece.axes[axis]![2] * sign]\n return { piece, axis, sign, normal, offset: dot(normal, piece.center) + piece.half[axis]! }\n}\n\nfunction facesOf(piece: Piece): Face[] {\n if (piece.isPlane) return [faceOf(piece, 2, 1)]\n return (piece.isCylinder ? [1] : [0, 1, 2]).flatMap((axis) => [faceOf(piece, axis, 1), faceOf(piece, axis, -1)])\n}\n\n/** The four corners of a face, in the plane's 2D basis (`u`, `v`). */\nfunction cornersOf(face: Face, u: Vector, v: Vector): Point2[] {\n const { piece, axis } = face\n const [first, second] = [0, 1, 2].filter((other) => other !== axis) as [number, number]\n return ([[1, 1], [1, -1], [-1, -1], [-1, 1]] as const).map(([a, b]) => {\n const point = [0, 1, 2].map((k) => piece.center[k]! + piece.axes[first]![k]! * piece.half[first]! * a + piece.axes[second]![k]! * piece.half[second]! * b) as Vector\n return [dot(point, u), dot(point, v)] as Point2\n })\n}\n\nconst side = (p: Point2, a: Point2, b: Point2): number => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0])\n\n/** Area of the overlap of two convex polygons (Sutherland-Hodgman). */\nfunction overlapArea(subject: Point2[], clip: Point2[]): number {\n let output = subject\n const orientation = Math.sign(side(clip[2]!, clip[0]!, clip[1]!)) || 1\n for (let i = 0; i < clip.length && output.length; i++) {\n const a = clip[i]!\n const b = clip[(i + 1) % clip.length]!\n const input = output\n output = []\n for (let j = 0; j < input.length; j++) {\n const current = input[j]!\n const previous = input[(j + input.length - 1) % input.length]!\n const currentInside = side(current, a, b) * orientation >= 0\n if (currentInside !== side(previous, a, b) * orientation >= 0) {\n const t = side(previous, a, b) / (side(previous, a, b) - side(current, a, b))\n output.push([previous[0] + (current[0] - previous[0]) * t, previous[1] + (current[1] - previous[1]) * t])\n }\n if (currentInside) output.push(current)\n }\n }\n let area = 0\n for (let i = 0; i < output.length; i++) {\n const p = output[i]!\n const q = output[(i + 1) % output.length]!\n area += p[0] * q[1] - q[0] * p[1]\n }\n return Math.abs(area) / 2\n}\n\nfunction planeBasis(normal: Vector): [Vector, Vector] {\n const side = cross(normal, Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0])\n const length = Math.hypot(...side)\n const u: Vector = [side[0] / length, side[1] / length, side[2] / length]\n return [u, cross(normal, u)]\n}\n\n/** How far the face reaches from the piece's centre along world axis `k`, over its two in-plane axes. */\nfunction faceReach(face: Face, k: number): number {\n const { piece, axis } = face\n let reach = 0\n for (let other = 0; other < 3; other++) if (other !== axis) reach += Math.abs(piece.axes[other]![k]!) * piece.half[other]!\n return reach\n}\n\n/** Whether the world boxes of two faces touch: a cheap test before clipping them. */\nfunction facesNear(a: Face, b: Face, slack = SAME_PLANE): boolean {\n for (let k = 0; k < 3; k++) {\n const centreA = a.piece.center[k]! + a.normal[k]! * a.piece.half[a.axis]!\n const centreB = b.piece.center[k]! + b.normal[k]! * b.piece.half[b.axis]!\n if (Math.abs(centreA - centreB) > faceReach(a, k) + faceReach(b, k) + slack) return false\n }\n return true\n}\n\nfunction fight(a: Face, b: Face): boolean {\n if (Math.abs(a.offset - b.offset) > SAME_PLANE) return false\n if ([0, 1, 2].some((k) => Math.abs(a.normal[k]! - b.normal[k]!) > SAME_DIRECTION)) return false\n if (!facesNear(a, b)) return false\n const [u, v] = planeBasis(a.normal)\n return overlapArea(cornersOf(a, u, v), cornersOf(b, u, v)) > MIN_OVERLAP_AREA\n}\n\n/** Moves a face of a piece by `amount` (positive: out) along its normal, in the piece's node. */\nfunction moveFace(face: Face, amount: number): void {\n const { piece, axis } = face\n const scale = piece.node.scale as Vector\n if (!piece.isPlane) {\n scale[axis] = scale[axis]! + amount\n piece.half[axis] = piece.half[axis]! + amount / 2\n }\n const shift = face.normal.map((component) => (component * amount) / (piece.isPlane ? 1 : 2)) as Vector\n for (let k = 0; k < 3; k++) piece.center[k] = piece.center[k]! + shift[k]!\n const inParent = apply(transpose(piece.parentRotation), shift)\n const position = piece.node.position as Vector\n for (let k = 0; k < 3; k++) position[k] = position[k]! + inParent[k]!\n}\n\n/** Faces looking the same way, grouped by their rounded normal: only faces in one group can share a plane. */\ntype FaceGroups = Map<number, Face[]>\n\nconst DIRECTION_SPAN = 2048\nconst directionKey = (normal: Vector): number =>\n ((Math.round(normal[0] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN + Math.round(normal[1] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN +\n Math.round(normal[2] / SAME_DIRECTION) + DIRECTION_SPAN / 2\n\nfunction groupFaces(pieces: readonly Piece[]): FaceGroups {\n const groups: FaceGroups = new Map()\n for (const piece of pieces) {\n for (const face of facesOf(piece)) {\n const key = directionKey(face.normal)\n const group = groups.get(key)\n if (group) group.push(face)\n else groups.set(key, [face])\n }\n }\n return groups\n}\n\n/** The same face as it is now: a piece moved earlier in the round has its face somewhere else. */\nconst liveFace = (face: Face): Face => faceOf(face.piece, face.axis, face.sign)\n\n/** Moves the face by the first of 2 mm in, 2 mm out, 4 mm in, 4 mm out (out first for a thin piece) that lands on no other piece's face. */\nfunction clearFace(face: Face, groups: FaceGroups): void {\n const { piece, axis, sign } = face\n const thick = piece.half[axis]! * 2 >= MIN_THICKNESS_TO_SINK\n const steps = piece.isPlane ? [GAP, 2 * GAP, 3 * GAP] : [GAP, -GAP, 2 * GAP, -2 * GAP].map((step) => (thick ? -step : step))\n const fits = (step: number): boolean => piece.isPlane || piece.half[axis]! * 2 + step >= 2 * GAP\n // only faces within the farthest step of this one, and near it, can be met: the rest of the group is skipped once\n const reach = 2 * GAP * 3 + 2 * SAME_PLANE\n const neighbours = (groups.get(directionKey(face.normal)) ?? []).filter((candidate) => candidate.piece !== piece && Math.abs(candidate.offset - face.offset) <= reach && facesNear(face, candidate, reach))\n const clear = (): boolean => {\n const moved = faceOf(piece, axis, sign)\n return neighbours.every((candidate) => !fight(moved, liveFace(candidate)))\n }\n let applied = 0\n for (const step of steps.filter(fits)) {\n moveFace(face, step - applied)\n applied = step\n if (clear()) return\n }\n moveFace(face, steps[0]! - applied)\n}\n\n/** Two coaxial round pieces whose radii differ by about a millimetre have facets on one plane: the smaller one's radius moves 2 mm away from the other. */\nfunction separateRadii(a: Piece, b: Piece): boolean {\n if (!a.isCylinder || !b.isCylinder || Math.abs(dot(a.axes[1], b.axes[1])) < 0.9999) return false\n const between: Vector = [b.center[0] - a.center[0], b.center[1] - a.center[1], b.center[2] - a.center[2]]\n const along = dot(between, a.axes[1])\n if (Math.hypot(between[0] - a.axes[1][0] * along, between[1] - a.axes[1][1] * along, between[2] - a.axes[1][2] * along) > SAME_PLANE) return false\n if (Math.abs(along) > a.half[1] + b.half[1] - 0.005 || Math.abs(a.half[0] - b.half[0]) > SAME_PLANE * 1.1) return false\n const [mover, other] = volumeOf(a) < volumeOf(b) ? [a, b] : [b, a]\n const amount = mover.half[0] >= other.half[0] ? GAP : -GAP\n const scale = mover.node.scale as Vector\n scale[0] = scale[0]! + amount\n scale[2] = scale[2]! + amount\n mover.half[0] += amount\n mover.half[2] += amount\n return true\n}\n\nconst volumeOf = (piece: Piece): number => piece.half[0] * piece.half[1] * piece.half[2]\n\n/** Calls `visit` with each pair of faces of different pieces on one plane (by offset), within each direction group: a sweep over the sorted offsets. */\nfunction forEachPlaneMate(groups: FaceGroups, visit: (a: Face, b: Face) => void): void {\n for (const group of groups.values()) {\n if (group.length < 2) continue\n group.sort((a, b) => a.offset - b.offset)\n for (let i = 0; i < group.length; i++) {\n const a = group[i]!\n for (let j = i + 1; j < group.length && group[j]!.offset - a.offset <= 2 * SAME_PLANE; j++) {\n if (group[j]!.piece !== a.piece) visit(a, group[j]!)\n }\n }\n }\n}\n\nfunction separateAllRadii(cylinders: readonly Piece[], moved: Set<Piece>): void {\n for (let i = 0; i < cylinders.length; i++) {\n for (let j = i + 1; j < cylinders.length; j++) {\n const a = cylinders[i]!\n const b = cylinders[j]!\n const reach = Math.max(a.half[0], a.half[1]) + Math.max(b.half[0], b.half[1]) + 0.01\n if (Math.abs(a.center[0] - b.center[0]) > reach || Math.abs(a.center[1] - b.center[1]) > reach || Math.abs(a.center[2] - b.center[2]) > reach) continue\n if (separateRadii(a, b)) {\n moved.add(a)\n moved.add(b)\n }\n }\n }\n}\n\n/**\n * Makes the boxes (and cylinders) of a schema stop sharing planes: when two pieces have a face on one plane, looking the same way and\n * overlapping, the smaller piece's face sinks 2 mm into the piece (or grows 2 mm out when the piece is thinner than 12 mm), CLAUDE.md §13.\n * Mutates the schema's nodes and returns it.\n */\nexport function standOutCoincidentBoxes(schema: ShapeSchema): ShapeSchema {\n const pieces: Piece[] = []\n collect((schema.root as { children?: readonly ShapeNode[] }).children ?? [], [0, 0, 0], IDENTITY, pieces)\n const cylinders = pieces.filter((piece) => piece.isCylinder)\n // after the first round only a piece that just moved can meet a new face: pairs of two still pieces were already settled\n let movedLast: Set<Piece> | undefined\n for (let round = 0; round < MAX_ROUNDS; round++) {\n const movedNow = new Set<Piece>()\n separateAllRadii(cylinders, movedNow)\n const groups = groupFaces(pieces)\n forEachPlaneMate(groups, (first, second) => {\n if (movedLast && !movedLast.has(first.piece) && !movedLast.has(second.piece)) return\n const a = liveFace(first)\n const b = liveFace(second)\n if (!fight(a, b)) return\n const mover = volumeOf(a.piece) < volumeOf(b.piece) ? a : b\n clearFace(mover, groups)\n movedNow.add(mover.piece)\n })\n if (!movedNow.size) break\n movedLast = movedNow\n }\n return schema\n}\n","import type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/** `Reflector` from `three/examples/jsm/objects/Reflector.js`, passed by the host. */\nexport type ReflectorConstructor = new (geometry: ThreeNS.BufferGeometry, options?: { textureWidth?: number; textureHeight?: number; clipBias?: number; color?: ThreeNS.ColorRepresentation }) => ThreeNS.Mesh\n\nexport interface MirrorOptions {\n /** Without it every mirror shows the env map only. */\n Reflector?: ReflectorConstructor\n /** Cube / equirect env map for the cheap look. */\n envMap?: ThreeNS.Texture | null\n /** Real reflectors alive at once. Default 1. */\n max?: number\n /** Reflector texture size in pixels. Default 512. */\n resolution?: number\n /** Where reflectors are added. Default: the root ancestor of the registered mesh. */\n scene?: ThreeNS.Object3D\n /** Distance in front of the plane, meters. Default 0.001. */\n offset?: number\n /**\n * three's `Reflector` renders the scene again inside the main `render()`, and that nested render resets `renderer.info` when\n * `info.autoReset` is on, so the counters would only show the reflector pass. With `keepInfo` (default true) the reflector adds\n * what was counted before it back, so `renderer.info.render.calls` covers the whole frame. Skipped when `info.autoReset` is off.\n */\n keepInfo?: boolean\n}\n\n/** The mirror entries of `world.mirrors(...)` (only these fields are read). */\nexport interface MirrorCandidate {\n id: string\n center: Vec3\n normal: Vec3\n}\n\nexport interface Mirrors {\n /** Registers the display mesh of a mirror (world id `objectId:mirrorId`). It gets the env-map material. `normal` is the world normal; default: the mesh's +z. */\n register(id: string, mesh: ThreeNS.Mesh, normal?: Vec3): void\n unregister(id: string): void\n /** Activates real reflectors for the nearest facing registered mirrors among `candidates`. Returns the active ids. */\n update(camera: ThreeNS.Camera, candidates: readonly MirrorCandidate[]): string[]\n /** Ids that currently have a real reflector. */\n active(): string[]\n /** The shared env-map material registered meshes use. */\n envMaterial: ThreeNS.Material\n dispose(): void\n}\n\ninterface Entry {\n mesh: ThreeNS.Mesh\n normal: Vec3 | null\n original: ThreeNS.Material | ThreeNS.Material[]\n}\n\ninterface Slot {\n reflector: ThreeNS.Mesh\n id: string | null\n}\n\n/**\n * Mirrors: every registered mirror shows an env-map material; the nearest `max` that face the camera get a real `Reflector`\n * (pooled and reused), placed `offset` in front of the plane with the mesh's rotation and size.\n */\nexport function createMirrors(THREE: ThreeLib, options: MirrorOptions = {}): Mirrors {\n const max = Math.max(0, Math.floor(options.max ?? 1))\n const resolution = options.resolution ?? 512\n const offset = options.offset ?? 0.001\n const envMaterial = new THREE.MeshStandardMaterial({ color: 0xdfe6ea, metalness: 1, roughness: 0.04, envMap: options.envMap ?? null })\n const entries = new Map<string, Entry>()\n const slots: Slot[] = []\n const geometry = new THREE.PlaneGeometry(1, 1)\n\n const worldNormal = (e: Entry, out: ThreeNS.Vector3): ThreeNS.Vector3 => {\n if (e.normal) return out.set(e.normal[0], e.normal[1], e.normal[2]).normalize()\n e.mesh.updateWorldMatrix(true, false)\n return out.set(0, 0, 1).transformDirection(e.mesh.matrixWorld)\n }\n\n const slotFor = (id: string): Slot | null => {\n if (!options.Reflector) return null\n const existing = slots.find((s) => s.id === id)\n if (existing) return existing\n const free = slots.find((s) => s.id === null)\n if (free) return free\n if (slots.length >= max) return null\n const reflector = new options.Reflector(geometry, { textureWidth: resolution, textureHeight: resolution, clipBias: 0.003 })\n reflector.name = 'mirror:reflector'\n if (options.keepInfo !== false) {\n const original = reflector.onBeforeRender\n reflector.onBeforeRender = function (this: ThreeNS.Mesh, renderer, scene, camera, geo, mat, grp) {\n const info = renderer.info\n if (!info.autoReset) return original.call(this, renderer, scene, camera, geo, mat, grp)\n const before = { calls: info.render.calls, triangles: info.render.triangles, points: info.render.points, lines: info.render.lines }\n original.call(this, renderer, scene, camera, geo, mat, grp)\n info.render.calls += before.calls\n info.render.triangles += before.triangles\n info.render.points += before.points\n info.render.lines += before.lines\n }\n }\n reflector.visible = false\n const s: Slot = { reflector, id: null }\n slots.push(s)\n return s\n }\n\n const release = (s: Slot): void => {\n s.id = null\n s.reflector.visible = false\n }\n\n const pos = new THREE.Vector3()\n const quat = new THREE.Quaternion()\n const scl = new THREE.Vector3()\n const n = new THREE.Vector3()\n const toEye = new THREE.Vector3()\n const box = new THREE.Box3()\n const size = new THREE.Vector3()\n const facing = new THREE.Vector3()\n const flip = new THREE.Quaternion(0, 1, 0, 0)\n\n return {\n envMaterial,\n register(id, mesh, normal) {\n const previous = entries.get(id)\n entries.set(id, { mesh, normal: normal ?? null, original: previous ? previous.original : mesh.material })\n mesh.material = envMaterial\n },\n unregister(id) {\n const e = entries.get(id)\n const s = slots.find((x) => x.id === id)\n if (s) release(s)\n if (e) e.mesh.material = e.original\n entries.delete(id)\n },\n update(camera, candidates) {\n const eye = camera.getWorldPosition(toEye)\n const wanted: Array<{ id: string; d: number }> = []\n for (const c of candidates) {\n const e = entries.get(c.id)\n if (!e) continue\n n.set(c.normal[0], c.normal[1], c.normal[2])\n const dx = eye.x - c.center[0]\n const dy = eye.y - c.center[1]\n const dz = eye.z - c.center[2]\n if (n.x * dx + n.y * dy + n.z * dz <= 0) continue\n wanted.push({ id: c.id, d: dx * dx + dy * dy + dz * dz })\n }\n wanted.sort((a, b) => a.d - b.d)\n const chosen = new Set<string>()\n for (let i = 0; i < wanted.length && chosen.size < max; i++) chosen.add(wanted[i].id)\n for (const s of slots) if (s.id !== null && !chosen.has(s.id)) release(s)\n for (const id of chosen) {\n const s = slotFor(id)\n if (!s) continue\n const e = entries.get(id)!\n e.mesh.updateWorldMatrix(true, false)\n e.mesh.matrixWorld.decompose(pos, quat, scl)\n if (!e.mesh.geometry.boundingBox) e.mesh.geometry.computeBoundingBox()\n box.copy(e.mesh.geometry.boundingBox!)\n box.getSize(size)\n worldNormal(e, n)\n s.reflector.position.copy(pos).addScaledVector(n, offset)\n s.reflector.quaternion.copy(quat)\n // a Reflector only renders for a camera in front of its +z: when the registered normal points the other way, turn it around\n if (facing.set(0, 0, 1).applyQuaternion(quat).dot(n) < 0) s.reflector.quaternion.multiply(flip)\n s.reflector.scale.set(Math.max(size.x * scl.x, 1e-3), Math.max(size.y * scl.y, 1e-3), 1)\n s.id = id\n s.reflector.visible = true\n if (!s.reflector.parent) {\n let top: ThreeNS.Object3D = e.mesh\n while (top.parent) top = top.parent\n ;(options.scene ?? top).add(s.reflector)\n }\n }\n return slots.filter((s) => s.id !== null).map((s) => s.id as string)\n },\n active() {\n return slots.filter((s) => s.id !== null).map((s) => s.id as string)\n },\n dispose() {\n for (const s of slots) s.reflector.removeFromParent()\n slots.length = 0\n for (const e of entries.values()) e.mesh.material = e.original\n entries.clear()\n envMaterial.dispose()\n geometry.dispose()\n },\n }\n}\n","import type { CanvasFactory, ThreeLib, ThreeNS } from './types'\n\nexport interface ScreenOptions {\n /** Where the canvas is created (the global `document`, or a fake). */\n document: CanvasFactory\n /** Canvas size in pixels. Default 128 x 72. */\n w?: number\n h?: number\n /** Seed of the static noise. Default 1. */\n seed?: number\n /** Redraws per second while on. Default 15. */\n fps?: number\n /** Emissive strength while on. Default 1. */\n intensity?: number\n}\n\nexport interface Screen {\n material: ThreeNS.MeshStandardMaterial\n texture: ThreeNS.CanvasTexture\n canvas: HTMLCanvasElement\n readonly on: boolean\n readonly channel: number\n setOn(on: boolean): void\n setChannel(channel: number): void\n /** Advance the animation; redraws the canvas at `fps` while on. */\n update(dt: number): void\n dispose(): void\n}\n\nconst BARS = ['#c0c0c0', '#c0c000', '#00c0c0', '#00c000', '#c000c0', '#c00000', '#0000c0']\n\nfunction mulberry(seed: number): () => number {\n let a = seed >>> 0\n return () => {\n a = (a + 0x6d2b79f5) >>> 0\n let t = a\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\n/**\n * A screen material backed by a canvas texture. Off: black canvas, no emission. On: the channel's content (0 color bars,\n * 1 static noise, 2 animated landscape, higher numbers repeat them with shifted hues) lights the surface.\n */\nexport function createScreen(THREE: ThreeLib, options: ScreenOptions): Screen {\n const w = options.w ?? 128\n const h = options.h ?? 72\n const canvas = options.document.createElement('canvas')\n canvas.width = w\n canvas.height = h\n // the canvas is uploaded to the GPU every redraw: tell the browser so it keeps a CPU-backed canvas (no readback warning)\n const ctx = canvas.getContext('2d', { willReadFrequently: true })\n const rand = mulberry(options.seed ?? 1)\n const period = 1 / Math.max(1, options.fps ?? 15)\n const intensity = options.intensity ?? 1\n\n const texture = new THREE.CanvasTexture(canvas)\n texture.colorSpace = THREE.SRGBColorSpace\n const material = new THREE.MeshStandardMaterial({\n color: 0x050505,\n roughness: 0.25,\n metalness: 0,\n map: texture,\n emissive: 0xffffff,\n emissiveMap: texture,\n emissiveIntensity: 0,\n })\n\n let on = false\n let channel = 0\n let clock = 0\n let acc = 0\n\n const fill = (style: string, x: number, y: number, rw: number, rh: number): void => {\n if (!ctx) return\n ctx.fillStyle = style\n ctx.fillRect(x, y, rw, rh)\n }\n\n const drawBars = (): void => {\n const n = BARS.length\n for (let i = 0; i < n; i++) fill(BARS[(i + channel) % n], Math.floor((i * w) / n), 0, Math.ceil(w / n), Math.floor(h * 0.75))\n fill('#101010', 0, Math.floor(h * 0.75), w, h - Math.floor(h * 0.75))\n const x = ((clock * 20) % (w + 12)) - 12\n fill('#ffffff', x, Math.floor(h * 0.8), 12, Math.floor(h * 0.1))\n }\n\n const drawNoise = (): void => {\n const cell = Math.max(2, Math.floor(w / 48))\n for (let y = 0; y < h; y += cell) {\n for (let x = 0; x < w; x += cell) {\n const g = Math.floor(rand() * 220 + 20)\n fill(`rgb(${g},${g},${g})`, x, y, cell, cell)\n }\n }\n }\n\n const drawScene = (): void => {\n const hue = (channel * 40) % 360\n fill(`hsl(${(200 + hue) % 360},60%,${55 + 10 * Math.sin(clock * 0.3)}%)`, 0, 0, w, Math.floor(h * 0.65))\n fill(`hsl(${(110 + hue) % 360},40%,32%)`, 0, Math.floor(h * 0.65), w, h - Math.floor(h * 0.65))\n const sx = (0.5 + 0.4 * Math.sin(clock * 0.5)) * w\n const sy = (0.3 - 0.15 * Math.cos(clock * 0.5)) * h\n fill('#ffe680', sx - 5, sy - 5, 10, 10)\n const bx = (clock * 25) % (w + 16) - 16\n fill('#e03030', bx, Math.floor(h * 0.7), 16, 10)\n }\n\n const draw = (): void => {\n if (!on) {\n fill('#000000', 0, 0, w, h)\n } else if (channel % 3 === 0) {\n drawBars()\n } else if (channel % 3 === 1) {\n drawNoise()\n } else {\n drawScene()\n }\n texture.needsUpdate = true\n }\n\n const apply = (): void => {\n material.emissiveIntensity = on ? intensity : 0\n material.color.setHex(on ? 0x111111 : 0x000000)\n draw()\n }\n apply()\n\n return {\n material,\n texture,\n canvas,\n get on() {\n return on\n },\n get channel() {\n return channel\n },\n setOn(value) {\n on = !!value\n acc = 0\n apply()\n },\n setChannel(n) {\n channel = Math.max(0, Math.floor(n))\n if (on) draw()\n },\n update(dt) {\n if (!on) return\n clock += dt\n acc += dt\n if (acc >= period) {\n acc %= period\n draw()\n }\n },\n dispose() {\n texture.dispose()\n material.dispose()\n },\n }\n}\n","import type { ThreeLib, ThreeNS } from './types'\n\nexport interface SwayOptions {\n /** Strength of the idle flutter (wind) in meters per meter of hang, 0..1. Default 0.04. */\n amplitude?: number\n /** Local y (geometry space) of the line the cloth hangs from. Default: top of the mesh's bounding box. */\n anchorY?: number\n}\n\nexport interface SwayUniforms {\n time: { value: number }\n ax: { value: number }\n az: { value: number }\n anchorY: { value: number }\n}\n\n/** Shared state of one swaying mesh: the three materials read the same uniforms. */\nexport interface SwayHandle {\n uniforms: SwayUniforms\n /** Sets the swing (radians around x and z) and, optionally, the clock for the idle flutter. */\n set(ax: number, az: number, time?: number): void\n}\n\nconst VERTEX_PATCH = /* glsl */ `\n#include <begin_vertex>\n{\n float swayHang = max(swayAnchorY - position.y, 0.0);\n float swayFlutter = swayAmplitude * sin(swayTime * 1.9 + position.x * 4.0 + position.z * 3.0 + swayHang * 3.0);\n transformed.x += swayHang * (sin(swayAz) + swayFlutter);\n transformed.z += swayHang * (-sin(swayAx) + swayFlutter * 0.6);\n transformed.y += swayHang * (1.0 - cos(swayAz) * cos(swayAx));\n}\n`\n\nconst VERTEX_UNIFORMS = /* glsl */ `\nuniform float swayTime;\nuniform float swayAx;\nuniform float swayAz;\nuniform float swayAnchorY;\nuniform float swayAmplitude;\n`\n\n/** Patches a vertex shader so the vertices hang from the anchor line and swing with the shared uniforms. */\nexport function patchSwayShader(shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }, uniforms: SwayUniforms, amplitude: number): void {\n shader.uniforms.swayTime = uniforms.time\n shader.uniforms.swayAx = uniforms.ax\n shader.uniforms.swayAz = uniforms.az\n shader.uniforms.swayAnchorY = uniforms.anchorY\n shader.uniforms.swayAmplitude = { value: amplitude }\n shader.vertexShader = VERTEX_UNIFORMS + shader.vertexShader.replace('#include <begin_vertex>', VERTEX_PATCH)\n}\n\nfunction patch<M extends ThreeNS.Material>(material: M, uniforms: SwayUniforms, amplitude: number): M {\n const previous = material.onBeforeCompile\n material.onBeforeCompile = (shader, renderer) => {\n previous?.call(material, shader, renderer)\n patchSwayShader(shader, uniforms, amplitude)\n }\n material.customProgramCacheKey = () => `sway:${amplitude}`\n return material\n}\n\n/**\n * Clones `base` and patches it with a vertex-shader sway (uniforms `time`, `ax`, `az`, `anchorY`). The returned material carries\n * `userData.sway` (a `SwayHandle`), `customDepthMaterial` and `customDistanceMaterial` patched with the same uniforms, so\n * directional / spot shadow maps and point-light shadow cubes follow the animation. Assign it to a mesh, and set\n * `mesh.customDepthMaterial` / `mesh.customDistanceMaterial` from the material (or just use `attachSway`).\n */\n/** A material `swayMaterial` made: it carries its sway handle and the shadow materials that follow it. */\nexport type SwayMaterial = ThreeNS.Material & {\n userData: { sway: SwayHandle; depthMaterial: ThreeNS.MeshDepthMaterial; distanceMaterial: ThreeNS.MeshDistanceMaterial }\n}\n\nexport function swayMaterial(THREE: ThreeLib, base: ThreeNS.Material, options: SwayOptions = {}): SwayMaterial {\n const amplitude = options.amplitude ?? 0.04\n const uniforms: SwayUniforms = { time: { value: 0 }, ax: { value: 0 }, az: { value: 0 }, anchorY: { value: options.anchorY ?? 0 } }\n const handle: SwayHandle = {\n uniforms,\n set(ax, az, time) {\n uniforms.ax.value = ax\n uniforms.az.value = az\n if (time !== undefined) uniforms.time.value = time\n },\n }\n const material = patch(base.clone(), uniforms, amplitude)\n const depth = patch(new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }), uniforms, amplitude)\n const distance = patch(new THREE.MeshDistanceMaterial(), uniforms, amplitude)\n material.userData.sway = handle\n material.userData.depthMaterial = depth\n material.userData.distanceMaterial = distance\n return material as SwayMaterial // userData filled just above\n}\n\n/**\n * Makes a mesh sway: replaces its material with `swayMaterial(...)` and sets `customDepthMaterial` and `customDistanceMaterial`.\n * `mesh.userData.sway` is the handle `syncObject` drives. Returns the handle.\n */\nexport function attachSway(THREE: ThreeLib, mesh: ThreeNS.Mesh, options: SwayOptions = {}): SwayHandle {\n let anchorY = options.anchorY\n if (anchorY === undefined) {\n if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox()\n anchorY = mesh.geometry.boundingBox ? mesh.geometry.boundingBox.max.y : 0\n }\n const base = Array.isArray(mesh.material) ? mesh.material[0] : mesh.material\n const m = swayMaterial(THREE, base, { ...options, anchorY })\n m.userData.sway.uniforms.anchorY.value = anchorY\n mesh.material = m\n mesh.customDepthMaterial = m.userData.depthMaterial\n mesh.customDistanceMaterial = m.userData.distanceMaterial\n mesh.userData.sway = m.userData.sway\n return m.userData.sway\n}\n","import type { ItemStack, PartSpec, World } from '@adatechnology/game-interactables'\nimport { discardObject3D } from '@adatechnology/game-shapes-three'\n\nimport { applyPose } from './pose'\nimport type { ThreeLib, ThreeNS } from './types'\n\n/** Draws one stack as the real item with the host's `THREE`: origin at the bottom centre, y up, metres (`createContainedItemModel` of `game-items-three`). Null draws nothing. */\nexport type ContentsItemBuilder = (stack: ItemStack, THREE: ThreeLib) => ThreeNS.Object3D | null\n\nexport interface ContentsViewOptions {\n world: World\n objectId: string\n /** The object's group, in the object-local frame (the `group` of `createMeshApi().finish`). The contents hang under it. */\n root: ThreeNS.Object3D\n /** The real model of each stack; the host injects it (the items catalogue's renderer), so this package never draws a stand-in. */\n buildItem: ContentsItemBuilder\n}\n\n/** One drawn stack. */\nexport interface ContentsViewItem {\n readonly container: string\n readonly slot: number\n readonly type: string\n readonly object: ThreeNS.Object3D\n}\n\n/** The items in an object's containers, drawn and moving with the part their slot rides on. */\nexport interface ContentsView {\n /** The group under `root` that holds every item. */\n readonly group: ThreeNS.Group\n /**\n * Brings the drawing in line with the world: draws the stacks that arrived, discards the ones taken, poses each slot's part at its current t and shows a\n * container from the first instant its access part leaves 0 (closed, it is hidden). Call it when the object is built and on every frame one of its parts moves.\n */\n sync(): void\n items(): ContentsViewItem[]\n /** Discards every item (`discardObject3D`) and the group. */\n dispose(): void\n}\n\ninterface Drawn {\n type: string\n object: ThreeNS.Object3D\n}\n\n/**\n * The contents of an object's containers as real items. Each slot on a part (a drawer, a door shelf) hangs under a carrier posed with the engine's own pose of\n * that part, so the items slide or swing with it from the first frame of the motion and `world.slotPosition` always agrees; nothing is built when the motion ends.\n */\nexport function createContentsView(THREE: ThreeLib, options: ContentsViewOptions): ContentsView {\n const { world, objectId, root, buildItem } = options\n const group = new THREE.Group()\n group.name = `contents:${objectId}`\n root.add(group)\n const carriers = new Map<string, ThreeNS.Group>()\n const drawn = new Map<string, Drawn>()\n const spec = world.get(objectId)?.spec\n const partsById = new Map<string, PartSpec>((spec?.parts ?? []).map((p) => [p.id, p]))\n\n const carrierOf = (partId: string | undefined): ThreeNS.Object3D => {\n const part = partId === undefined ? undefined : partsById.get(partId)\n if (!part) return group\n let carrier = carriers.get(part.id)\n if (!carrier) {\n carrier = new THREE.Group()\n carrier.name = `contents:${part.id}`\n carrier.position.set(part.pivot[0], part.pivot[1], part.pivot[2])\n carrier.rotation.set(0, part.ry ?? 0, 0)\n group.add(carrier)\n carriers.set(part.id, carrier)\n }\n return carrier\n }\n\n const place = (object: ThreeNS.Object3D, carrier: ThreeNS.Object3D, pos: readonly [number, number, number], part: PartSpec | undefined): void => {\n carrier.add(object)\n if (!part) {\n object.position.set(pos[0], pos[1], pos[2])\n return\n }\n // object-local point at rest -> the carrier's rest frame (pivot at the origin, turned by ry)\n const ry = part.ry ?? 0\n const x = pos[0] - part.pivot[0]\n const z = pos[2] - part.pivot[2]\n const c = Math.cos(ry)\n const s = Math.sin(ry)\n object.position.set(c * x - s * z, pos[1] - part.pivot[1], s * x + c * z)\n object.rotation.set(0, -ry, 0)\n }\n\n function sync(): void {\n const live = new Set<string>()\n for (const c of spec?.containers ?? []) {\n const shown = c.access === undefined || world.partT(objectId, c.access) > 0\n const stacks = world.contents(objectId, c.id)\n c.slots.forEach((slot, i) => {\n const stack = stacks[i]\n const key = `${c.id}#${i}`\n const had = drawn.get(key)\n if (had && (!stack || stack.type !== had.type)) {\n discardObject3D(had.object)\n drawn.delete(key)\n }\n if (!stack) return\n live.add(key)\n let now = drawn.get(key)\n if (!now) {\n const object = buildItem(stack, THREE)\n if (!object) return\n object.name = `contents_${c.id}_${i}`\n object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty }\n place(object, carrierOf(slot.part), slot.pos, slot.part === undefined ? undefined : partsById.get(slot.part))\n now = { type: stack.type, object }\n drawn.set(key, now)\n }\n now.object.visible = shown\n })\n }\n for (const [key, d] of drawn) {\n if (live.has(key)) continue\n discardObject3D(d.object)\n drawn.delete(key)\n }\n for (const [partId, carrier] of carriers) {\n const part = partsById.get(partId)\n if (part) applyPose(THREE, carrier, part.motion, world.partT(objectId, partId))\n }\n }\n\n return {\n group,\n sync,\n items: () =>\n [...drawn].map(([key, d]) => {\n const cut = key.lastIndexOf('#')\n return { container: key.slice(0, cut), slot: Number(key.slice(cut + 1)), type: d.type, object: d.object }\n }),\n dispose() {\n discardObject3D(group)\n drawn.clear()\n carriers.clear()\n },\n }\n}\n","/** @deprecated import `catenary` and `createCord` from '@adatechnology/game-shapes-three' */\nexport { catenary, createCord } from '@adatechnology/game-shapes-three'\n","// The wires of an object (conduit runs, cables, cords, drops: `ObjectSpec.wires`) as thin tubes. The kit's builders leave them to the host (\"the host draws them\n// as thin tubes\"); a house folds them into its own batches, any other host takes these meshes.\nimport { createCord } from '@adatechnology/game-shapes-three'\nimport type { ObjectSpec } from '@adatechnology/game-interactables'\n\nimport type { ThreeLib, ThreeNS } from './types'\n\ntype Wire = NonNullable<ObjectSpec['wires']>[number]\n\n/** The colour each kind of wire is drawn in (a grey PVC conduit, a black cable, a dark cord). */\nexport const WIRE_COLORS: Readonly<Record<Wire['kind'], number>> = { conduit: 0xcfcdc4, cable: 0x2a2724, drop: 0x151515, cord: 0x1b1b1d }\n/** Radius a wire is drawn with when its spec gives none, metres. */\nexport const WIRE_RADIUS = 0.006\n\n/** One tube per wire with two points or more, named by the wire's id, in the object's own space. */\nexport function wireMeshes(THREE: ThreeLib, wires: ObjectSpec['wires']): ThreeNS.Mesh[] {\n const meshes: ThreeNS.Mesh[] = []\n for (const wire of wires ?? []) {\n if (wire.points.length < 2) continue\n const material = new THREE.MeshStandardMaterial({ color: WIRE_COLORS[wire.kind], roughness: 0.8 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QAAQ,KAAK,UAAU,aAAa,QAAQ;AAChF,SAAK,OAAO,KAAK;AACjB,WAAO,KAAK,IAAI;AAAA,EAClB;AACA,SAAO;AACT;","names":["tex","a","b","n","patch","side","s","mulberry","channel","apply","catenary","createCord","createCord"]}
|
|
1
|
+
{"version":3,"sources":["../src/effects.ts","../src/routed-particles.ts","../src/adapter.ts","../src/mesh.ts","../src/types.ts","../src/pose.ts","../src/merge.ts","../src/stand-out.ts","../src/mirrors.ts","../src/screen.ts","../src/sway.ts","../src/contents.ts","../src/cord.ts","../src/wires.ts"],"sourcesContent":["import type { ActiveEmitter, EmitterKind } from '@adatechnology/game-interactables'\nimport { markKitOrigin, warnOnce } from '@adatechnology/game-contracts'\nimport { isRoutedKind, routedParticleRequest } from './routed-particles'\nimport type { ParticleEffects, PoolKind } from './routed-particles'\nimport type { CanvasFactory, ThreeLib, ThreeNS } from './types'\n\nexport interface EffectsOptions {\n /** Where the particle objects are added (the `Points` of every kind, the water streams and the flame ring). Required. */\n scene: ThreeNS.Object3D\n /**\n * Camera whose vertical field of view sizes the sprites, read again every `update` so zoom and fov changes follow. Required: pass the\n * camera the scene is rendered with (a `PerspectiveCamera` fits), or a function returning the current one (`null` = 90 degree lens).\n */\n camera: PerspectiveLike | (() => PerspectiveLike | null) | null\n /** Total particles alive at once, shared by all kinds (split by weight). Default 800. */\n maxParticles?: number\n /** Used to paint the soft sprite on a canvas. Without it (or without a 2D context) a data texture is generated. */\n document?: CanvasFactory\n /** Seed of the random spread. Default 1. */\n seed?: number\n /** Wind vector [x, z] in m/s that bends smoke and steam. Default [0, 0]. */\n wind?: [number, number]\n /** Viewport height in pixels, used to size the point sprites. Update with `setViewHeight` on resize. Default 720. */\n viewHeight?: number\n /** Height (m) water streams fall to when the emitter has no `reach`. Default 0. */\n floorY?: number\n /** Most water streams drawn at once (one draw call each). Default 6. */\n maxStreams?: number\n /** Most gas flame rings drawn at once (all rings share one draw call). Default 16. */\n maxFlames?: number\n /**\n * The host's effects world, read at each particle. With one, smoke, steam, fire and sparks go through it and its one budget (`maxParticles` then only caps water);\n * without one every kind is drawn here with its own cap (deprecated, removed in the next major).\n */\n effects?: () => ParticleEffects | undefined\n}\n\n/** What the effects read from a camera. */\nexport interface PerspectiveLike {\n /** Vertical field of view in degrees. */\n fov: number\n zoom?: number\n}\n\nexport interface EffectsStats {\n alive: number\n capacity: number\n byKind: Record<PoolKind, number>\n}\n\nexport type { PoolKind }\n\nexport interface Effects {\n /**\n * Spawns for the active emitters and advances every particle by `dt` seconds, sizing the sprites for the camera given to\n * `createEffects` (or `setCamera`). No allocations per frame once warmed up. `camera` overrides it for this call (deprecated).\n */\n update(dt: number, emitters: readonly ActiveEmitter[], camera?: PerspectiveLike): void\n /** Replace the camera used for the sprite size (or `null` to go back to a 90 degree lens). */\n setCamera(camera: PerspectiveLike | (() => PerspectiveLike | null) | null): void\n setWind(x: number, z: number): void\n setViewHeight(px: number): void\n stats(): EffectsStats\n /** The Points objects (one per kind). */\n objects: Record<PoolKind, ThreeNS.Points>\n /** Water stream meshes (tapered, translucent, following the gravity arc) and the one mesh holding every gas flame ring. */\n meshes: { group: ThreeNS.Group; streams: ThreeNS.Mesh[]; flames: ThreeNS.Mesh }\n clear(): void\n dispose(): void\n}\n\nconst POOLS: PoolKind[] = ['smoke', 'steam', 'fire', 'water', 'spark']\nconst WEIGHT: Record<PoolKind, number> = { smoke: 0.27, steam: 0.15, fire: 0.2, water: 0.28, spark: 0.1 }\n\ninterface Pool {\n kind: PoolKind\n cap: number\n count: number\n pos: Float32Array\n vel: Float32Array\n age: Float32Array\n life: Float32Array\n size0: Float32Array\n size1: Float32Array\n tint: Float32Array\n flags: Uint8Array\n /** Water only: the height at which the particle ends (splashes, droplets). */\n ground: Float32Array\n aSize: ThreeNS.BufferAttribute\n aAlpha: ThreeNS.BufferAttribute\n aColor: ThreeNS.BufferAttribute\n aPos: ThreeNS.BufferAttribute\n points: ThreeNS.Points\n}\n\nconst VERT = /* glsl */ `\nattribute float aSize;\nattribute float aAlpha;\nattribute vec3 aColor;\nuniform float uScale;\nvarying float vAlpha;\nvarying vec3 vColor;\nvoid main() {\n vAlpha = aAlpha;\n vColor = aColor;\n vec4 mv = modelViewMatrix * vec4(position, 1.0);\n gl_PointSize = max(aSize * uScale / max(-mv.z, 0.05), 1.0);\n gl_Position = projectionMatrix * mv;\n}\n`\nconst FRAG = /* glsl */ `\nuniform sampler2D uMap;\nvarying float vAlpha;\nvarying vec3 vColor;\nvoid main() {\n vec4 t = texture2D(uMap, gl_PointCoord);\n gl_FragColor = vec4(vColor, vAlpha * t.a);\n}\n`\n\nfunction mulberry(seed: number): () => number {\n let a = seed >>> 0\n return () => {\n a = (a + 0x6d2b79f5) >>> 0\n let t = a\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\n/** Soft round sprite (alpha only matters). Canvas when possible, otherwise generated data. */\nfunction makeSprite(THREE: ThreeLib, doc: CanvasFactory | undefined): ThreeNS.Texture {\n const N = 64\n try {\n const canvas = doc?.createElement('canvas')\n const ctx = canvas?.getContext?.('2d')\n if (canvas && ctx && ctx.createRadialGradient) {\n canvas.width = N\n canvas.height = N\n const g = ctx.createRadialGradient(N / 2, N / 2, 0, N / 2, N / 2, N / 2)\n g.addColorStop(0, 'rgba(255,255,255,1)')\n g.addColorStop(0.4, 'rgba(255,255,255,0.55)')\n g.addColorStop(1, 'rgba(255,255,255,0)')\n ctx.fillStyle = g\n ctx.fillRect(0, 0, N, N)\n const tex = new THREE.CanvasTexture(canvas)\n return tex\n }\n } catch {\n // fall through to the data texture\n }\n const data = new Uint8Array(N * N * 4)\n for (let y = 0; y < N; y++) {\n for (let x = 0; x < N; x++) {\n const d = Math.hypot(x + 0.5 - N / 2, y + 0.5 - N / 2) / (N / 2)\n const a = d >= 1 ? 0 : Math.pow(1 - d, 1.6)\n const i = (y * N + x) * 4\n data[i] = data[i + 1] = data[i + 2] = 255\n data[i + 3] = Math.round(a * 255)\n }\n }\n const tex = new THREE.DataTexture(data, N, N, THREE.RGBAFormat)\n tex.needsUpdate = true\n return tex\n}\n\n/** Vertical streaks of water (alpha only matters); scrolled along the stream to show the flow. */\nfunction makeStreaks(THREE: ThreeLib): ThreeNS.DataTexture {\n const W = 16\n const H = 64\n const data = new Uint8Array(W * H * 4)\n const hash = (x: number, y: number): number => {\n let h = Math.imul(x + 1, 374761393) ^ Math.imul(y + 7, 668265263)\n h = Math.imul(h ^ (h >>> 13), 1274126177)\n return ((h ^ (h >>> 16)) >>> 0) / 4294967296\n }\n for (let y = 0; y < H; y++) {\n for (let x = 0; x < W; x++) {\n const col = 0.35 + 0.65 * hash(x, 0)\n const row = 0.55 + 0.45 * Math.sin(((y / H) * 3 + hash(x, 1) * 6) * Math.PI * 2)\n const i = (y * W + x) * 4\n data[i] = data[i + 1] = data[i + 2] = 255\n data[i + 3] = Math.round(255 * Math.min(1, col * row * 1.3))\n }\n }\n const tex = new THREE.DataTexture(data, W, H, THREE.RGBAFormat)\n tex.wrapS = THREE.RepeatWrapping\n tex.wrapT = THREE.RepeatWrapping\n tex.needsUpdate = true\n return tex\n}\n\n/**\n * Pooled particle effects: smoke, steam, fire (and the blue gas `flame` ring), water streams with drips, and sparks.\n * One `Points` per kind, fixed-size buffers, swap-remove; the total alive never exceeds `maxParticles`.\n */\nexport function createEffects(THREE: ThreeLib, options: EffectsOptions): Effects\n/** @deprecated Pass `{ scene, camera, ... }` as the one options argument. */\nexport function createEffects(THREE: ThreeLib, scene: ThreeNS.Object3D, options?: Partial<EffectsOptions>): Effects\nexport function createEffects(THREE: ThreeLib, a: EffectsOptions | ThreeNS.Object3D, b: Partial<EffectsOptions> = {}): Effects {\n const legacy = !!(a as ThreeNS.Object3D).isObject3D\n const options: Partial<EffectsOptions> = legacy ? { ...b, scene: a as ThreeNS.Object3D } : (a as EffectsOptions)\n const scene = options.scene\n if (!scene) throw new Error('createEffects: options.scene is required')\n if (!legacy && options.camera === undefined) throw new Error('createEffects: options.camera is required (pass null for a 90 degree lens)')\n const total = Math.max(POOLS.length, Math.floor(options.maxParticles ?? 800))\n const rand = mulberry(options.seed ?? 1)\n const wind: [number, number] = [options.wind?.[0] ?? 0, options.wind?.[1] ?? 0]\n const sprite = makeSprite(THREE, options.document)\n let viewHeight = options.viewHeight ?? 720\n let cameraSource: PerspectiveLike | (() => PerspectiveLike | null) | null = options.camera ?? null\n let camera: PerspectiveLike | null = typeof cameraSource === 'function' ? cameraSource() : cameraSource\n const scale = { value: 0 }\n /** Point size in pixels is size * viewHeight / (2 tan(fov / 2)) / distance. */\n const refreshScale = (cam: PerspectiveLike | null): void => {\n const fov = cam ? 2 * Math.atan(Math.tan((Math.min(Math.max(cam.fov, 1), 175) * Math.PI) / 360) / Math.max(cam.zoom ?? 1, 0.01)) : Math.PI / 2\n scale.value = viewHeight / (2 * Math.tan(fov / 2))\n }\n refreshScale(camera)\n\n const pools = {} as Record<PoolKind, Pool>\n const objects = {} as Record<PoolKind, ThreeNS.Points>\n let used = 0\n POOLS.forEach((kind, i) => {\n const cap = i === POOLS.length - 1 ? Math.max(1, total - used) : Math.max(1, Math.floor(total * WEIGHT[kind]))\n used += cap\n const geo = new THREE.BufferGeometry()\n const aPos = new THREE.BufferAttribute(new Float32Array(cap * 3), 3)\n const aSize = new THREE.BufferAttribute(new Float32Array(cap), 1)\n const aAlpha = new THREE.BufferAttribute(new Float32Array(cap), 1)\n const aColor = new THREE.BufferAttribute(new Float32Array(cap * 3), 3)\n for (const a of [aPos, aSize, aAlpha, aColor]) a.setUsage(THREE.DynamicDrawUsage)\n geo.setAttribute('position', aPos)\n geo.setAttribute('aSize', aSize)\n geo.setAttribute('aAlpha', aAlpha)\n geo.setAttribute('aColor', aColor)\n geo.setDrawRange(0, 0)\n const additive = kind === 'fire' || kind === 'spark'\n const mat = new THREE.ShaderMaterial({\n uniforms: { uMap: { value: sprite }, uScale: scale },\n vertexShader: VERT,\n fragmentShader: FRAG,\n transparent: true,\n depthWrite: false,\n blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending,\n })\n const points = markKitOrigin(new THREE.Points(geo, mat), { owner: 'game-interactables-three', kind: 'effect', id: kind })\n points.frustumCulled = false\n points.name = `effects:${kind}`\n scene.add(points)\n objects[kind] = points\n pools[kind] = {\n kind,\n cap,\n count: 0,\n pos: new Float32Array(cap * 3),\n vel: new Float32Array(cap * 3),\n age: new Float32Array(cap),\n life: new Float32Array(cap),\n size0: new Float32Array(cap),\n size1: new Float32Array(cap),\n tint: new Float32Array(cap),\n flags: new Uint8Array(cap),\n ground: new Float32Array(cap).fill(-1e9),\n aSize,\n aAlpha,\n aColor,\n aPos,\n points,\n }\n })\n\n /** Fractional spawns carried over per emitter id (the Map only grows with distinct ids and is pruned by stamp). */\n const debt = new Map<string, { carry: number; stamp: number }>()\n let stamp = 0\n let clock = 0\n\n const spawn = (p: Pool, x: number, y: number, z: number, vx: number, vy: number, vz: number, life: number, s0: number, s1: number, tint: number, flag = 0, ground = -1e9): void => {\n const sink = isRoutedKind(p.kind) ? options.effects?.() : undefined\n if (sink) {\n sink.play(routedParticleRequest({ kind: p.kind, flag, position: [x, y, z], velocity: [vx, vy, vz], life, startSize: s0, endSize: s1, tint }))\n return\n }\n if (isRoutedKind(p.kind)) warnOnce('game-interactables-three.own-particles', 'game-interactables-three drew its smoke, steam, fire and sparks with pools of its own because the host lent no effects world (options.effects); pass the host effects so the particles share one budget')\n if (p.count >= p.cap) return\n const i = p.count++\n p.pos[i * 3] = x\n p.pos[i * 3 + 1] = y\n p.pos[i * 3 + 2] = z\n p.vel[i * 3] = vx\n p.vel[i * 3 + 1] = vy\n p.vel[i * 3 + 2] = vz\n p.age[i] = 0\n p.life[i] = life\n p.size0[i] = s0\n p.size1[i] = s1\n p.tint[i] = tint\n p.flags[i] = flag\n p.ground[i] = ground\n }\n\n const emitFrom = (e: ActiveEmitter, n: number): void => {\n const k = Math.min(1, Math.max(0, e.intensity))\n const size = e.size > 0 ? e.size : 0.2\n const [px, py, pz] = e.pos\n for (let j = 0; j < n; j++) {\n switch (e.kind) {\n case 'smoke':\n // thick, slow, wide plume\n spawn(pools.smoke, px + (rand() - 0.5) * size * 0.6, py, pz + (rand() - 0.5) * size * 0.6, (rand() - 0.5) * 0.2, 0.45 + rand() * 0.45, (rand() - 0.5) * 0.2, 2.8 + rand() * 1.8, size * 0.6, size * 2.6, 0.3 + rand() * 0.25, 0)\n break\n case 'steam':\n spawn(pools.steam, px + (rand() - 0.5) * size * 0.5, py, pz + (rand() - 0.5) * size * 0.5, (rand() - 0.5) * 0.12, 0.3 + rand() * 0.3, (rand() - 0.5) * 0.12, 1.3 + rand() * 1.1, size * 0.3, size * 1.3, 0.92, 0)\n break\n case 'fire':\n spawn(pools.fire, px + (rand() - 0.5) * size * 0.7, py, pz + (rand() - 0.5) * size * 0.7, (rand() - 0.5) * 0.25, 0.8 + rand() * 0.9 * k, (rand() - 0.5) * 0.25, 0.35 + rand() * 0.4, size * 0.75, size * 0.15, rand(), 0)\n break\n case 'flame': {\n // soft blue glow over the ring (the ring of little flames itself is a mesh)\n const a = rand() * Math.PI * 2\n const r = size * 0.8\n spawn(pools.fire, px + Math.cos(a) * r, py + 0.01, pz + Math.sin(a) * r, 0, 0.06 + rand() * 0.1, 0, 0.14 + rand() * 0.12, size * 0.55, size * 0.15, rand(), 1)\n break\n }\n case 'spark': {\n const a = rand() * Math.PI * 2\n const up = 0.4 + rand() * 0.6\n const sp = 1.2 + rand() * 2\n spawn(pools.spark, px, py, pz, Math.cos(a) * sp * (1 - up * 0.5), up * sp * 1.4, Math.sin(a) * sp * (1 - up * 0.5), 0.35 + rand() * 0.5, size * 0.18, size * 0.05, rand(), 0)\n break\n }\n case 'water':\n break\n }\n }\n }\n\n // ---- water: a tapered translucent stream along the gravity arc, droplets around it and a splash where it lands ----------------\n interface Arc {\n x: number\n y: number\n z: number\n vx: number\n vy: number\n vz: number\n /** Flight time to the landing height. */\n t: number\n stopY: number\n r0: number\n r1: number\n }\n const arc: Arc = { x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, stopY: 0, r0: 0, r1: 0 }\n const floorY = options.floorY ?? 0\n const arcOf = (e: ActiveEmitter, k: number): boolean => {\n let [dx, dy, dz] = e.dir\n const len = Math.hypot(dx, dy, dz)\n if (len < 1e-6) {\n dx = 0\n dy = -1\n dz = 0\n } else {\n dx /= len\n dy /= len\n dz /= len\n }\n const speed = 0.7 + 1.8 * k\n const stopY = e.reach !== undefined ? Math.max(e.pos[1] - e.reach, floorY) : floorY\n const drop = e.pos[1] - stopY\n if (drop < 0.02) return false\n const vy = dy * speed\n arc.x = e.pos[0]\n arc.y = e.pos[1]\n arc.z = e.pos[2]\n arc.vx = dx * speed\n arc.vy = vy\n arc.vz = dz * speed\n arc.t = Math.min(2.5, (vy + Math.sqrt(vy * vy + 19.6 * drop)) / 9.8)\n arc.stopY = stopY\n const size = e.size > 0 ? e.size : 0.05\n if (size < 0.1) {\n // a tap: a thin jet that narrows as it speeds up\n arc.r0 = Math.max(0.004, size * 0.5)\n arc.r1 = arc.r0 * 0.55\n } else {\n // a shower or a leak: a spray that opens a little\n arc.r0 = size * 0.45\n arc.r1 = arc.r0 * 1.2\n }\n // a stream into a bowl is never wider than the bowl\n if (e.bowl) {\n const most = Math.max(0.004, e.bowl.radius * 0.7)\n arc.r0 = Math.min(arc.r0, most)\n arc.r1 = Math.min(arc.r1, most)\n }\n return true\n }\n\n const emitWater = (e: ActiveEmitter, k: number, nSpray: number, nSplash: number, nMist: number): void => {\n const size = e.size > 0 ? e.size : 0.05\n const bowl = e.bowl\n // a spray opens out only on open floor: in a bowl its walls hold it in\n const wide = size >= 0.1 && !bowl\n // the walls of a bowl catch what splashes: no drop rises over its rim (v^2 = 2 g h) nor flies past its walls before it falls back (out and back in 2 vy / g)\n const riseMax = bowl ? Math.sqrt(2 * 9.8 * Math.max(0.01, bowl.depth)) * 0.85 : Infinity\n const outMax = (vy: number): number => (bowl ? (bowl.radius * 0.6 * 9.8) / (2 * Math.max(vy, 0.3)) : Infinity)\n const within = bowl ? bowl.radius * 0.3 : Infinity\n for (let j = 0; j < nSpray; j++) {\n const s = rand()\n const t = s * arc.t\n const r = (arc.r0 + (arc.r1 - arc.r0) * s) * (0.7 + rand() * 0.5)\n const a = rand() * Math.PI * 2\n const ox = Math.cos(a) * r\n const oz = Math.sin(a) * r\n spawn(\n pools.water,\n arc.x + arc.vx * t + ox,\n arc.y + arc.vy * t - 4.9 * t * t,\n arc.z + arc.vz * t + oz,\n arc.vx + (wide ? ox * 1.2 : 0) + (rand() - 0.5) * 0.25,\n arc.vy - 9.8 * t,\n arc.vz + (wide ? oz * 1.2 : 0) + (rand() - 0.5) * 0.25,\n 0.22 + rand() * 0.25,\n 0.011 + rand() * 0.012,\n 0.009 + rand() * 0.008,\n rand(),\n 2,\n arc.stopY,\n )\n }\n const ex = arc.x + arc.vx * arc.t\n const ez = arc.z + arc.vz * arc.t\n for (let j = 0; j < nSplash; j++) {\n const a = rand() * Math.PI * 2\n const r = Math.min(arc.r1, within) * Math.sqrt(rand())\n // drawn in the same order as on open floor, so a stream that lands on the floor draws the same drops\n const sp0 = (wide ? 0.5 : 0.25) + rand() * 0.7\n const vy0 = 0.9 + rand() * 1.3\n const vy = bowl ? riseMax * (0.5 + (0.5 * (vy0 - 0.9)) / 1.3) : vy0\n const sp = Math.min(sp0, outMax(vy))\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.005, ez + Math.sin(a) * r, Math.cos(a) * sp, vy, Math.sin(a) * sp, 0.3 + rand() * 0.25, 0.014 + rand() * 0.018, 0.01, rand(), 3, arc.stopY)\n }\n for (let j = 0; j < nMist; j++) {\n const a = rand() * Math.PI * 2\n const r = Math.min(arc.r1 * 1.4, within) * Math.sqrt(rand())\n const up0 = 0.18 + rand() * 0.15\n const life = 0.7 + rand() * 0.5\n // the haze over a bowl rises to its rim at most: it drifts without gravity, so its speed is the rise over its life\n const up = bowl ? Math.min(up0, Math.max(0.005, bowl.depth - 0.03) / life) : up0\n const drift = bowl ? Math.min(0.15, (bowl.radius * 0.5) / life) : 0.15\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.02, ez + Math.sin(a) * r, Math.cos(a) * drift, up, Math.sin(a) * drift, life, 0.06 + size * 0.2, 0.2 + size * 0.5, rand(), 4, arc.stopY)\n }\n void k\n }\n\n const emitDrip = (e: ActiveEmitter, n: number): void => {\n const size = e.size > 0 ? e.size : 0.05\n const stopY = e.reach !== undefined ? Math.max(e.pos[1] - e.reach, floorY) : floorY\n for (let j = 0; j < n; j++) {\n const sx = (rand() - 0.5) * 0.01\n const sz = (rand() - 0.5) * 0.01\n spawn(pools.water, e.pos[0] + sx, e.pos[1], e.pos[2] + sz, e.dir[0] * 0.08, e.dir[1] * 0.08, e.dir[2] * 0.08, 1.4, size * 0.22, size * 0.2, rand(), 1, stopY)\n }\n }\n\n const RATE: Record<EmitterKind, number> = { smoke: 42, steam: 48, fire: 150, flame: 55, spark: 40, water: 0 }\n\n // Stream meshes ----------------------------------------------------------------------------------------------------------------\n const SEG = 12\n const SIDES = 8\n const maxStreams = Math.max(0, Math.floor(options.maxStreams ?? 6))\n const streaksTex = makeStreaks(THREE)\n const streamMat = new THREE.MeshBasicMaterial({ color: 0x9cccff, map: streaksTex, vertexColors: true, transparent: true, opacity: 0.8, depthWrite: false, side: THREE.DoubleSide })\n const streamIndex: number[] = []\n for (let i = 0; i < SEG; i++) {\n for (let m = 0; m < SIDES; m++) {\n const a = i * (SIDES + 1) + m\n const b = a + SIDES + 1\n streamIndex.push(a, b, a + 1, a + 1, b, b + 1)\n }\n }\n const group = new THREE.Group()\n group.name = 'effects:meshes'\n scene.add(group)\n const streams: ThreeNS.Mesh[] = []\n for (let i = 0; i < maxStreams; i++) {\n const geo = new THREE.BufferGeometry()\n const n = (SEG + 1) * (SIDES + 1)\n geo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(n * 3), 3).setUsage(THREE.DynamicDrawUsage))\n geo.setAttribute('color', new THREE.BufferAttribute(new Float32Array(n * 4), 4).setUsage(THREE.DynamicDrawUsage))\n const uv = new Float32Array(n * 2)\n geo.setAttribute('uv', new THREE.BufferAttribute(uv, 2).setUsage(THREE.DynamicDrawUsage))\n geo.setIndex(streamIndex)\n const mesh = new THREE.Mesh(geo, streamMat)\n mesh.frustumCulled = false\n mesh.visible = false\n mesh.name = `effects:stream${i}`\n group.add(mesh)\n streams.push(mesh)\n }\n\n const writeStream = (mesh: ThreeNS.Mesh, k: number): void => {\n const geo = mesh.geometry\n const pos = (geo.getAttribute('position') as ThreeNS.BufferAttribute).array as Float32Array\n const col = (geo.getAttribute('color') as ThreeNS.BufferAttribute).array as Float32Array\n const uv = (geo.getAttribute('uv') as ThreeNS.BufferAttribute).array as Float32Array\n for (let i = 0; i <= SEG; i++) {\n const s = i / SEG\n const t = s * arc.t\n const cx = arc.x + arc.vx * t\n const cy = arc.y + arc.vy * t - 4.9 * t * t\n const cz = arc.z + arc.vz * t\n let tx = arc.vx\n let ty = arc.vy - 9.8 * t\n let tz = arc.vz\n const tl = Math.hypot(tx, ty, tz) || 1\n tx /= tl\n ty /= tl\n tz /= tl\n // binormal = tangent x up, normal = tangent x binormal\n let bx = tz\n const by = 0\n let bz = -tx\n const bl = Math.hypot(bx, bz)\n if (bl < 1e-4) {\n bx = 1\n bz = 0\n } else {\n bx /= bl\n bz /= bl\n }\n const nx = ty * bz - tz * by\n const ny = tz * bx - tx * bz\n const nz = tx * by - ty * bx\n const r = arc.r0 + (arc.r1 - arc.r0) * s\n const alpha = Math.min(1, s * 7) * (0.95 - 0.3 * s) * Math.min(1, 0.55 + k)\n for (let m = 0; m <= SIDES; m++) {\n const a = (m / SIDES) * Math.PI * 2\n const ca = Math.cos(a) * r\n const sa = Math.sin(a) * r\n const v = i * (SIDES + 1) + m\n pos[v * 3] = cx + bx * ca + nx * sa\n pos[v * 3 + 1] = cy + by * ca + ny * sa\n pos[v * 3 + 2] = cz + bz * ca + nz * sa\n col[v * 4] = col[v * 4 + 1] = col[v * 4 + 2] = 1\n col[v * 4 + 3] = alpha\n uv[v * 2] = (m / SIDES) * 3\n uv[v * 2 + 1] = s * arc.t * 2.2\n }\n }\n ;(geo.getAttribute('position') as ThreeNS.BufferAttribute).needsUpdate = true\n ;(geo.getAttribute('color') as ThreeNS.BufferAttribute).needsUpdate = true\n ;(geo.getAttribute('uv') as ThreeNS.BufferAttribute).needsUpdate = true\n mesh.visible = true\n }\n\n // Gas flame rings: every burner is a ring of small blue cones; all rings share one dynamic mesh (one draw call) ------------------\n const CONES = 16\n const maxFlames = Math.max(0, Math.floor(options.maxFlames ?? 16))\n const flameGeo = new THREE.BufferGeometry()\n const flamePos = new THREE.BufferAttribute(new Float32Array(maxFlames * CONES * 4 * 3), 3).setUsage(THREE.DynamicDrawUsage)\n const flameCol = new THREE.BufferAttribute(new Float32Array(maxFlames * CONES * 4 * 3), 3).setUsage(THREE.DynamicDrawUsage)\n flameGeo.setAttribute('position', flamePos)\n flameGeo.setAttribute('color', flameCol)\n const flameIdx: number[] = []\n for (let i = 0; i < maxFlames * CONES; i++) {\n const v = i * 4\n flameIdx.push(v, v + 1, v + 3, v + 1, v + 2, v + 3, v + 2, v, v + 3)\n }\n flameGeo.setIndex(flameIdx)\n flameGeo.setDrawRange(0, 0)\n const flames = new THREE.Mesh(\n flameGeo,\n new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide }),\n )\n flames.frustumCulled = false\n flames.visible = false\n flames.name = 'effects:flames'\n group.add(flames)\n\n const hashOf = (id: string): number => {\n let h = 2166136261\n for (let i = 0; i < id.length; i++) h = Math.imul(h ^ id.charCodeAt(i), 16777619)\n return ((h >>> 0) % 1000) / 1000\n }\n\n const writeFlame = (slot: number, e: ActiveEmitter, time: number): void => {\n const pa = flamePos.array as Float32Array\n const ca = flameCol.array as Float32Array\n const k = Math.min(1, Math.max(0, e.intensity))\n const size = e.size > 0 ? e.size : 0.05\n const R = size * 0.8\n const bw = Math.max(0.004, size * 0.13)\n const phase = hashOf(e.id) * 40\n for (let c = 0; c < CONES; c++) {\n const a = (c / CONES) * Math.PI * 2\n const ux = Math.cos(a)\n const uz = Math.sin(a)\n const bx = e.pos[0] + ux * R\n const bz = e.pos[2] + uz * R\n const by = e.pos[1]\n const h = (0.025 + size * 0.45) * k * (0.55 + 0.45 * Math.abs(Math.sin(time * 19 + c * 2.3 + phase)))\n const v = (slot * CONES + c) * 4\n // base triangle: tangent +, tangent -, radial out; apex leans slightly inwards\n const tx = -uz * bw\n const tz = ux * bw\n pa.set([bx + tx, by, bz + tz, bx - tx, by, bz - tz, bx + ux * bw * 0.9, by, bz + uz * bw * 0.9, bx - ux * h * 0.12, by + h, bz - uz * h * 0.12], v * 3)\n const lo = 0.3 * k\n ca.set([0.2 * k, 0.45 * k, 1 * k, 0.2 * k, 0.45 * k, 1 * k, 0.2 * k, 0.45 * k, 1 * k, 0.02 * lo, 0.1 * lo, 0.5 * lo], v * 3)\n }\n }\n\n const advance = (p: Pool, dt: number): void => {\n let i = 0\n const swayX = wind[0]\n const swayZ = wind[1]\n while (i < p.count) {\n p.age[i] += dt\n const age = p.age[i]\n const life = p.life[i]\n if (age >= life || (p.kind === 'water' && p.pos[i * 3 + 1] < p.ground[i])) {\n // swap-remove\n const last = --p.count\n if (i !== last) {\n p.pos.copyWithin(i * 3, last * 3, last * 3 + 3)\n p.vel.copyWithin(i * 3, last * 3, last * 3 + 3)\n p.age[i] = p.age[last]\n p.life[i] = p.life[last]\n p.size0[i] = p.size0[last]\n p.size1[i] = p.size1[last]\n p.tint[i] = p.tint[last]\n p.flags[i] = p.flags[last]\n p.ground[i] = p.ground[last]\n }\n continue\n }\n const j = i * 3\n switch (p.kind) {\n case 'smoke':\n case 'steam':\n p.vel[j] += (swayX - p.vel[j]) * Math.min(1, dt * 0.8)\n p.vel[j + 2] += (swayZ - p.vel[j + 2]) * Math.min(1, dt * 0.8)\n break\n case 'water':\n if (p.flags[i] !== 4) p.vel[j + 1] -= 9.8 * dt\n break\n case 'spark':\n p.vel[j + 1] -= 7 * dt\n break\n case 'fire':\n p.vel[j] += (swayX * 0.1 - p.vel[j]) * Math.min(1, dt * 2)\n break\n }\n p.pos[j] += p.vel[j] * dt\n p.pos[j + 1] += p.vel[j + 1] * dt\n p.pos[j + 2] += p.vel[j + 2] * dt\n if (p.kind === 'water' && p.pos[j + 1] < p.ground[i]) {\n // landed: stay on the surface and fade out this frame\n p.pos[j + 1] = p.ground[i]\n p.age[i] = p.life[i]\n }\n i++\n }\n }\n\n const write = (p: Pool): void => {\n const n = p.count\n const pa = p.aPos.array as Float32Array\n const sa = p.aSize.array as Float32Array\n const aa = p.aAlpha.array as Float32Array\n const ca = p.aColor.array as Float32Array\n for (let i = 0; i < n; i++) {\n const u = p.age[i] / p.life[i]\n const j = i * 3\n pa[j] = p.pos[j]\n pa[j + 1] = p.pos[j + 1]\n pa[j + 2] = p.pos[j + 2]\n sa[i] = p.size0[i] + (p.size1[i] - p.size0[i]) * u\n let alpha: number\n switch (p.kind) {\n case 'smoke':\n alpha = 0.55 * Math.min(1, u * 8) * (1 - u)\n ca[j] = ca[j + 1] = ca[j + 2] = p.tint[i]\n break\n case 'steam':\n alpha = 0.4 * Math.min(1, u * 6) * (1 - u)\n ca[j] = ca[j + 1] = ca[j + 2] = p.tint[i]\n break\n case 'fire':\n alpha = (p.flags[i] ? 0.95 : 0.8) * (1 - u * u)\n if (p.flags[i]) {\n ca[j] = 0.25 + 0.15 * p.tint[i]\n ca[j + 1] = 0.5 + 0.2 * p.tint[i]\n ca[j + 2] = 1\n } else {\n // yellow core -> orange -> red as it rises\n ca[j] = 1\n ca[j + 1] = Math.max(0.15, 0.85 - u * 0.7 - p.tint[i] * 0.1)\n ca[j + 2] = Math.max(0, 0.25 - u * 0.25)\n }\n break\n case 'spark':\n alpha = 1 - u\n ca[j] = 1\n ca[j + 1] = 0.75 - u * 0.4\n ca[j + 2] = 0.3\n break\n default: {\n const f = p.flags[i]\n alpha = f === 4 ? 0.16 * (1 - u) : f === 3 ? 0.8 * (1 - u * 0.5) : f === 2 ? 0.65 * (1 - u * 0.6) : 0.8\n ca[j] = f === 4 ? 0.85 : 0.5\n ca[j + 1] = f === 4 ? 0.92 : 0.74\n ca[j + 2] = 1\n }\n }\n aa[i] = alpha\n }\n p.aPos.needsUpdate = true\n p.aSize.needsUpdate = true\n p.aAlpha.needsUpdate = true\n p.aColor.needsUpdate = true\n p.points.geometry.setDrawRange(0, n)\n }\n\n return {\n objects,\n meshes: { group, streams, flames },\n update(dt, emitters, cam) {\n camera = cam ?? (typeof cameraSource === 'function' ? cameraSource() : cameraSource)\n refreshScale(camera)\n const step = Math.min(Math.max(dt, 0), 0.1)\n stamp++\n clock += step\n streaksTex.offset.y = -(clock * 2.4) % 1\n let nStreams = 0\n let nFlames = 0\n const due = (key: string, rate: number): number => {\n let d = debt.get(key)\n if (!d) {\n d = { carry: 0, stamp }\n debt.set(key, d)\n }\n d.stamp = stamp\n d.carry += rate * step\n const n = Math.floor(d.carry)\n d.carry -= n\n return n\n }\n for (let i = 0; i < emitters.length; i++) {\n const e = emitters[i]\n if (!(e.intensity > 0)) continue\n const k = Math.min(1, e.intensity)\n const size = e.size > 0 ? e.size : 0.05\n if (e.kind === 'water') {\n if (k < 0.25) {\n const n = due(e.id, 3 + k * 10)\n if (n > 0) emitDrip(e, n)\n } else if (arcOf(e, k)) {\n const nSpray = due(e.id, (60 + 260 * Math.min(size, 0.4)) * k)\n const nSplash = due(`${e.id}#s`, (45 + 90 * Math.min(size, 0.4)) * k)\n const nMist = due(`${e.id}#m`, 6 * k * (1 + size * 4))\n emitWater(e, k, nSpray, nSplash, nMist)\n if (nStreams < streams.length) writeStream(streams[nStreams++], k)\n }\n continue\n }\n if (e.kind === 'flame' && nFlames < maxFlames) writeFlame(nFlames++, e, clock)\n const n = due(e.id, RATE[e.kind] * k)\n if (n > 0) emitFrom(e, n)\n }\n for (let i = nStreams; i < streams.length; i++) streams[i].visible = false\n flames.visible = nFlames > 0\n flameGeo.setDrawRange(0, nFlames * CONES * 9)\n flamePos.needsUpdate = true\n flameCol.needsUpdate = true\n if (debt.size > emitters.length * 3 + 8) {\n for (const [id, d] of debt) if (d.stamp !== stamp) debt.delete(id)\n }\n for (const kind of POOLS) {\n advance(pools[kind], step)\n write(pools[kind])\n }\n },\n setWind(x, z) {\n wind[0] = x\n wind[1] = z\n },\n setCamera(cam) {\n cameraSource = cam\n camera = typeof cam === 'function' ? cam() : cam\n refreshScale(camera)\n },\n setViewHeight(px) {\n viewHeight = px\n refreshScale(camera)\n },\n stats() {\n const byKind = {} as Record<PoolKind, number>\n let alive = 0\n let capacity = 0\n for (const kind of POOLS) {\n byKind[kind] = pools[kind].count\n alive += pools[kind].count\n capacity += pools[kind].cap\n }\n return { alive, capacity, byKind }\n },\n clear() {\n for (const kind of POOLS) {\n pools[kind].count = 0\n write(pools[kind])\n }\n debt.clear()\n for (const m of streams) m.visible = false\n flames.visible = false\n },\n dispose() {\n for (const kind of POOLS) {\n scene.remove(objects[kind])\n objects[kind].geometry.dispose()\n ;(objects[kind].material as ThreeNS.Material).dispose()\n }\n scene.remove(group)\n for (const m of streams) m.geometry.dispose()\n flameGeo.dispose()\n ;(flames.material as ThreeNS.Material).dispose()\n streamMat.dispose()\n streaksTex.dispose()\n sprite.dispose()\n },\n }\n}\n","/** The kinds of particle pool of the effects, as `effects.ts` draws them. */\nexport type PoolKind = 'smoke' | 'steam' | 'fire' | 'spark' | 'water'\n\n/** What `EffectSink.play` of `game-contracts` takes, as a structural type. */\nexport interface ParticleEffectRequest {\n readonly effect: string\n readonly point: [number, number, number]\n readonly values: Readonly<Record<string, number>>\n}\n\n/** The host's effects world as far as the particles need it (`EffectSink` of `game-contracts` fits). */\nexport interface ParticleEffects {\n play(request: ParticleEffectRequest): unknown\n}\n\nexport interface RoutedParticle {\n readonly kind: PoolKind\n readonly flag: number\n readonly position: [number, number, number]\n readonly velocity: [number, number, number]\n readonly life: number\n readonly startSize: number\n readonly endSize: number\n readonly tint: number\n}\n\nconst channel = (value: number): number => Math.round(Math.min(1, Math.max(0, value)) * 255)\nconst rgb = (red: number, green: number, blue: number): number => (channel(red) << 16) | (channel(green) << 8) | channel(blue)\n\nconst EFFECT_OF: Readonly<Partial<Record<PoolKind, string>>> = { smoke: 'particle_puff', steam: 'particle_puff', fire: 'particle_glow', spark: 'particle_streak' }\n\n/** True for the kinds the effects world draws; water stays local because it ends at a height of its own. */\nexport const isRoutedKind = (kind: PoolKind): boolean => EFFECT_OF[kind] !== undefined\n\n/** The numbers of the local particle at birth: the colour and peak opacity the local shader gives it, its life, its two sizes (as a ratio). */\nexport function routedParticleRequest(particle: RoutedParticle): ParticleEffectRequest {\n const { kind, flag, tint } = particle\n const look = lookOf(kind, flag, tint)\n return {\n effect: EFFECT_OF[kind]!,\n point: particle.position,\n values: {\n vx: particle.velocity[0],\n vy: particle.velocity[1],\n vz: particle.velocity[2],\n life: particle.life,\n size: particle.startSize,\n grow: particle.endSize / particle.startSize,\n color: look.color,\n alpha: look.alpha,\n gravity: 0,\n drag: 0,\n },\n }\n}\n\nfunction lookOf(kind: PoolKind, flag: number, tint: number): { color: number; alpha: number } {\n if (kind === 'smoke') return { color: rgb(tint, tint, tint), alpha: 0.55 }\n if (kind === 'steam') return { color: rgb(tint, tint, tint), alpha: 0.4 }\n if (kind === 'spark') return { color: rgb(1, 0.75, 0.3), alpha: 1 }\n if (flag) return { color: rgb(0.25 + 0.15 * tint, 0.5 + 0.2 * tint, 1), alpha: 0.95 }\n return { color: rgb(1, Math.max(0.15, 0.85 - tint * 0.1), 0.25), alpha: 0.8 }\n}\n","import type { Motion, World } from '@adatechnology/game-interactables'\nimport type { LightBudget } from '@adatechnology/game-render-three'\nimport { createEffects, type Effects, type EffectsOptions } from './effects'\nimport { createCord, catenary } from '@adatechnology/game-shapes-three'\nimport { createMeshApi, type MeshApi, type MeshApiOptions } from './mesh'\nimport { createMirrors, type MirrorOptions, type Mirrors } from './mirrors'\nimport { applyPose, syncObject, type SyncOptions } from './pose'\nimport { createScreen, type Screen, type ScreenOptions } from './screen'\nimport { attachSway, swayMaterial, type SwayHandle, type SwayOptions } from './sway'\nimport type { CanvasFactory, Quality, ThreeLib, ThreeNS, Vec3 } from './types'\n\nexport interface ThreeAdapterOptions {\n /** Default for `createMeshApi` / `createScreen` / `createEffects`. */\n document?: CanvasFactory\n quality?: Quality\n materials?: MeshApiOptions['materials']\n /** `Reflector` and env map for `createMirrors`. */\n Reflector?: MirrorOptions['Reflector']\n envMap?: MirrorOptions['envMap']\n /** The host's light budget: the lamps of every mesh api this adapter makes become sources of it (see `MeshApiOptions.lights`). */\n lights?: LightBudget\n}\n\n/** The package functions with `THREE` and the common options already bound. */\nexport interface ThreeAdapter {\n THREE: ThreeLib\n createMeshApi(options?: MeshApiOptions): MeshApi\n applyPose<G extends ThreeNS.Object3D>(group: G, motion: Motion, t: number): G\n syncObject(world: World, objectId: string, parts: Record<string, ThreeNS.Object3D>, options?: SyncOptions): void\n swayMaterial(base: ThreeNS.Material, options?: SwayOptions): ReturnType<typeof swayMaterial>\n attachSway(mesh: ThreeNS.Mesh, options?: SwayOptions): SwayHandle\n createEffects(options: EffectsOptions): Effects\n /** @deprecated Pass `{ scene, camera, ... }`. */\n createEffects(scene: ThreeNS.Object3D, options?: Partial<EffectsOptions>): Effects\n createScreen(options?: Partial<ScreenOptions>): Screen\n createMirrors(options?: MirrorOptions): Mirrors\n createCord(points: readonly Vec3[], radius: number, material: ThreeNS.Material): ThreeNS.Mesh\n catenary: typeof catenary\n}\n\n/** Binds the host's `THREE` (and shared options) once, so the rest of the host code never passes it around. */\nexport function createThreeAdapter(THREE: ThreeLib, options: ThreeAdapterOptions = {}): ThreeAdapter {\n return {\n THREE,\n createMeshApi: (o = {}) => createMeshApi(THREE, { quality: options.quality, materials: options.materials, ...(options.lights ? { lights: options.lights } : {}), ...o }),\n applyPose: (group, motion, t) => applyPose(THREE, group, motion, t),\n syncObject: (world, objectId, parts, o) => syncObject(THREE, world, objectId, parts, o),\n swayMaterial: (base, o) => swayMaterial(THREE, base, o),\n attachSway: (mesh, o) => attachSway(THREE, mesh, o),\n createEffects: ((a: EffectsOptions | ThreeNS.Object3D, o: Partial<EffectsOptions> = {}) =>\n (a as ThreeNS.Object3D).isObject3D\n ? createEffects(THREE, a as ThreeNS.Object3D, { document: options.document, ...o })\n : createEffects(THREE, { document: options.document, ...(a as EffectsOptions) })) as ThreeAdapter['createEffects'],\n createScreen: (o = {}) => {\n const document = o.document ?? options.document\n if (!document) throw new Error('createScreen needs a document (option of createThreeAdapter or of the call)')\n return createScreen(THREE, { ...o, document })\n },\n createMirrors: (o = {}) => createMirrors(THREE, { Reflector: options.Reflector, envMap: options.envMap, ...o }),\n createCord: (points, radius, material) => createCord(THREE, points, radius, material),\n catenary,\n }\n}\n","import { markKitOrigin } from '@adatechnology/game-contracts'\nimport { LIGHT_PRIORITY } from '@adatechnology/game-render-three'\nimport type { LightBudget, SourceHandle } from '@adatechnology/game-render-three'\nimport type { ObjectSpec } from '@adatechnology/game-interactables'\nimport { createShapeRecorder } from '@adatechnology/game-props3d'\nimport { colorChannels, generate } from '@adatechnology/game-shapes'\nimport type { ShapeBatch, ShapePoint } from '@adatechnology/game-shapes'\nimport type { HouseholdApi, MaterialKey, Quality, ThreeLib, ThreeNS } from './types'\nimport { MATERIAL_KEYS } from './types'\nimport { mergeParts } from './merge'\nimport { standOutCoincidentBoxes } from './stand-out'\nimport { rememberRest } from './pose'\n\nexport type MaterialMap = Partial<Record<MaterialKey, ThreeNS.Material>>\n\nexport interface MeshApiOptions {\n /** Materials per key. Missing keys get a default (vertex-colored) material. */\n materials?: MaterialMap\n /** `high`: smoother cylinders and spheres, standard materials. `game`: fewer segments, Lambert materials. Default `high`. */\n quality?: Quality\n /** Cast and receive shadows on the merged meshes. Default true. */\n shadows?: boolean\n /** Make `plane` primitives double sided (applies to the default materials only). Default false. */\n doubleSidedPlanes?: boolean\n /**\n * Cut draw calls: `finish(spec)` merges the parts of one `PartSpec.group` that share a motion (blind slats) and the `cloth` soft\n * volumes (clothes on a line) into one mesh per material (see `mergeParts`). Needs the spec in `finish`. Default: on in `game` quality.\n */\n mergeParts?: boolean\n /** Move the pieces that share a plane with another apart by 2 mm (CLAUDE.md §13, `standOutCoincidentBoxes`). Off by default: it costs about as much as the build itself (shapes-bench); the builders draw their own gaps. */\n standOut?: boolean\n /** Idle flutter of merged cloth. Default 0.04. */\n swayAmplitude?: number\n /**\n * Material of one draw: called per mesh with its material key and the part id (`null` for the static body). Return the material the\n * host wants there (a per-room light mask, a flickering emissive...); the default is `materials[key]`. Merged groups (blind slats,\n * clothes) keep what you return, including its `onBeforeCompile`, `customProgramCacheKey`, `defines` and `userData`.\n */\n materialFor?: (key: MaterialKey, partId: string | null) => ThreeNS.Material | undefined\n /**\n * The host's light budget: each `api.light` becomes a source of it (it competes for a slot by distance, and following its bulb) instead of a `PointLight` of its own, so lamps coming and going\n * never change the lit materials' program key. Without it the lamps are real lights (deprecated, removed in the next major).\n */\n lights?: LightBudget\n}\n\nexport interface MeshResult {\n /** Root group: static meshes (one per material) plus one child group per part (merged parts share one group, see `mergeParts`). */\n group: ThreeNS.Group\n /** Part groups by id. Origin at the pivot, rotated by the part's `ry`; `userData.rest` holds the rest pose. A merged part maps to the shared group (`userData.merged`). */\n parts: Record<string, ThreeNS.Group>\n /** Real lights requested by the builders (already children of their group). Empty with `MeshApiOptions.lights`. */\n lights: ThreeNS.Light[]\n /** With `MeshApiOptions.lights`: the lamps as sources of the budget (`remove()` one when its lamp breaks or the object goes). Empty without it. */\n sources: SourceHandle[]\n}\n\nexport interface FinishOptions {\n /** Same as `MeshApiOptions.materialFor`; wins over it for this call. */\n materialFor?: MeshApiOptions['materialFor']\n}\n\nexport interface MeshApi {\n api: HouseholdApi\n /** Builds the groups from everything drawn so far. Call once; the api is spent afterwards. Pass the spec the pack returned to allow `mergeParts`. */\n finish(spec?: ObjectSpec, finishOptions?: FinishOptions): MeshResult\n /** Materials in use (defaults merged with the given ones). */\n materials: Record<MaterialKey, ThreeNS.Material>\n}\n\n/** Default materials: vertex colors everywhere (in `game` quality plain, metal, wood and fabric are one shared Lambert material), glass and water transparent, emissive unlit. */\nexport function createDefaultMaterials(THREE: ThreeLib, quality: Quality = 'high'): Record<MaterialKey, ThreeNS.Material> {\n // three warns about every parameter that is present but undefined: only pass the ones that are set\n const defined = <T extends object>(o: T): T => {\n const out = {} as T\n for (const k of Object.keys(o) as Array<keyof T>) if (o[k] !== undefined) out[k] = o[k]\n return out\n }\n const std = (p: ThreeNS.MeshStandardMaterialParameters): ThreeNS.Material =>\n quality === 'game'\n ? new THREE.MeshLambertMaterial(defined({ vertexColors: true, transparent: p.transparent, opacity: p.opacity, depthWrite: p.depthWrite, side: p.side }))\n : new THREE.MeshStandardMaterial(defined({ vertexColors: true, roughness: 0.85, metalness: 0, ...p }))\n // Lambert has no roughness or metalness: in `game` quality the opaque default materials are one and the same instance, so the\n // mesh api (which merges per material instance) draws plain, metal, wood and fabric together\n const solid = quality === 'game' ? std({}) : null\n return {\n plain: solid ?? std({}),\n metal: solid ?? std({ roughness: 0.35, metalness: 0.7 }),\n wood: solid ?? std({ roughness: 0.8 }),\n glass: std({ roughness: 0.05, transparent: true, opacity: 0.35, depthWrite: false }),\n fabric: solid ?? std({ roughness: 1 }),\n plant: std({ roughness: 0.9, side: THREE.DoubleSide }),\n water: std({ roughness: 0.1, transparent: true, opacity: 0.7, depthWrite: false }),\n emissive: new THREE.MeshBasicMaterial({ vertexColors: true }),\n atlas_picture: std({ roughness: 0.9 }),\n atlas_floor: std({ roughness: 1 }),\n }\n}\n\n/** The channels three stores for a hex here: linear (three r152+ with colour management on) or the raw sRGB numbers (off, or an older three). */\nconst colorSpaces = new WeakMap<object, 'linear' | 'srgb'>()\nfunction colorSpaceOf(THREE: ThreeLib): 'linear' | 'srgb' {\n const known = colorSpaces.get(THREE.Color)\n if (known) return known\n const space = detectColorSpace(THREE)\n colorSpaces.set(THREE.Color, space)\n return space\n}\nfunction detectColorSpace(THREE: ThreeLib): 'linear' | 'srgb' {\n const color = new THREE.Color()\n for (let c = 0; c < 256; c++) {\n color.setHex(c * 0x010101)\n if (color.r !== colorChannels(c * 0x010101, 'linear')[0]) {\n if (color.r !== c / 255) throw new Error('createMeshApi: this three.js stores colours in a space game-shapes does not know')\n return 'srgb'\n }\n }\n return 'linear'\n}\n\n/**\n * Mesh api for content packs. Every primitive is baked (vertex colors) into one `BufferGeometry` per material and per target\n * (the root, or a part), so the draw calls are the number of materials in use plus the same again for each part.\n *\n * The builders draw into a `game-shapes` schema (`createShapeRecorder` of game-props3d: unit templates, the item frame, parts and lights) and\n * `generate` bakes it; the bytes are the ones this api made with its own templates before (tests/exact-golden.test.ts).\n */\nexport function createMeshApi(THREE: ThreeLib, options: MeshApiOptions = {}): MeshApi {\n const quality: Quality = options.quality ?? 'high'\n const shadows = options.shadows !== false\n const materials = { ...createDefaultMaterials(THREE, quality), ...stripUndefined(options.materials) } as Record<MaterialKey, ThreeNS.Material>\n if (options.doubleSidedPlanes) for (const k of MATERIAL_KEYS) materials[k].side = THREE.DoubleSide\n let finished = false\n\n const recorder = quality === 'high' ? createShapeRecorder({ cylinderSegments: 12, sphereSegments: [12, 8] }) : createShapeRecorder({ cylinderSegments: 8, sphereSegments: [8, 6] })\n\n /** Keys that share a material instance share the geometry too: the first key stands for all of them. */\n const materialAlias: Record<string, string> = {}\n for (const k of MATERIAL_KEYS) {\n const first = MATERIAL_KEYS.find((o) => materials[o] === materials[k]) ?? k\n if (first !== k) materialAlias[k] = first\n }\n\n const lightsOut: ThreeNS.Light[] = []\n const sourcesOut: SourceHandle[] = []\n\n const build = (batches: readonly ShapeBatch[], points: readonly ShapePoint[], id: string | null, into: ThreeNS.Group, materialFor: MeshApiOptions['materialFor']): void => {\n for (const batch of batches) {\n const g = new THREE.BufferGeometry()\n g.setAttribute('position', new THREE.BufferAttribute(batch.positions, 3))\n g.setAttribute('normal', new THREE.BufferAttribute(batch.normals, 3))\n g.setAttribute('color', new THREE.BufferAttribute(batch.colors as Float32Array, 3))\n g.setAttribute('uv', new THREE.BufferAttribute(batch.uvs, 2))\n g.setIndex(new THREE.BufferAttribute(batch.indices as Uint16Array | Uint32Array, 1))\n g.computeBoundingSphere()\n g.computeBoundingBox()\n const key = batch.material as MaterialKey\n const mesh = new THREE.Mesh(g, materialFor?.(key, id) ?? materials[key])\n mesh.name = id === null ? `static:${key}` : `part:${id}`\n if (id !== null) mesh.userData.part = id\n mesh.userData.material = key\n // what the builder drew, primitive by primitive, in the mesh's own space: what a physics engine holds the mesh by, with no vertex read back (spec 019)\n if (batch.solids) mesh.userData.solids = batch.solids\n mesh.castShadow = shadows\n mesh.receiveShadow = shadows\n into.add(mesh)\n }\n for (const point of points) {\n const l = point.data as { color: number; range: number }\n if (options.lights) {\n const bulb = new THREE.Object3D()\n bulb.name = 'lamp'\n bulb.position.set(point.position[0], point.position[1], point.position[2])\n into.add(bulb)\n sourcesOut.push(options.lights.addSource({ owner: 'interactables.lamp', priority: LIGHT_PRIORITY.lamp, color: l.color, intensity: 1, distance: l.range, position: [0, 0, 0], follow: bulb }))\n continue\n }\n // eslint-disable-next-line no-restricted-syntax -- D2: legacy path without LightBudget, removed in the next major\n const light = new THREE.PointLight(l.color, 1, l.range)\n light.position.set(point.position[0], point.position[1], point.position[2])\n into.add(light)\n lightsOut.push(light)\n }\n }\n\n return {\n api: recorder.api,\n materials,\n finish(spec, finishOptions) {\n const materialFor = finishOptions?.materialFor ?? options.materialFor\n if (finished) throw new Error('createMeshApi: finish() was already called')\n finished = true\n const buffers = generate(options.standOut === true ? standOutCoincidentBoxes(recorder.schema()) : recorder.schema(), {\n colors: colorSpaceOf(THREE),\n materials: MATERIAL_KEYS,\n fallbackMaterial: 'plain',\n materialAlias,\n validate: false,\n key: false,\n solids: true,\n })\n const batches = buffers.levels[0]?.batches ?? []\n const of = (id: string | null): { batches: ShapeBatch[]; points: ShapePoint[] } => ({ batches: batches.filter((b) => b.part === id), points: buffers.points.filter((p) => p.part === id) })\n const group = markKitOrigin(new THREE.Group(), { owner: 'game-interactables-three', kind: 'furniture', ...(spec ? { id: spec.type } : {}) })\n group.name = 'interactable'\n const parts: Record<string, ThreeNS.Group> = {}\n const body = of(null)\n build(body.batches, body.points, null, group, materialFor)\n for (const part of recorder.parts) {\n const g = new THREE.Group()\n g.name = `part:${part.id}`\n g.userData.part = part.id\n g.position.set(part.pivot[0], part.pivot[1], part.pivot[2])\n g.rotation.y = part.ry\n g.updateMatrix()\n const drawn = of(part.id)\n build(drawn.batches, drawn.points, part.id, g, materialFor)\n rememberRest(g)\n group.add(g)\n parts[part.id] = g\n }\n if (spec && (options.mergeParts ?? quality === 'game')) mergeParts(THREE, group, parts, spec, { swayAmplitude: options.swayAmplitude })\n if (spec) tagDestruction(group, parts, spec)\n return { group, parts, lights: lightsOut, sources: sourcesOut }\n },\n }\n}\n\n/**\n * Copies the spec's destruction tags onto the objects: `userData.destructionMaterial` (SDK material id) and, on part groups,\n * `userData.destructionPart` (the part id, the key @adatechnology/game-destruction-three binds by), `userData.destructionPiece` and\n * `userData.destructionJoint`. Static meshes get the object default; the meshes of a part get the part's tags.\n * Parts merged into a shared group (blind slats) carry the tags of the first part of the group.\n */\nfunction tagDestruction(group: ThreeNS.Group, parts: Record<string, ThreeNS.Group>, spec: ObjectSpec): void {\n const body = spec.destruction\n const partGroups = new Set<ThreeNS.Object3D>(Object.values(parts))\n if (body) {\n for (const child of group.children) {\n if (!partGroups.has(child) && (child as ThreeNS.Mesh).isMesh) child.userData.destructionMaterial = body.material\n }\n }\n const done = new Set<ThreeNS.Object3D>()\n for (const ps of spec.parts ?? []) {\n const g = parts[ps.id]\n const d = ps.destruction\n if (!g || !d || done.has(g)) continue\n done.add(g)\n for (const o of [g, ...g.children]) {\n if (o !== g && !(o as ThreeNS.Mesh).isMesh) continue\n o.userData.destructionMaterial = d.material\n o.userData.destructionPart = ps.id\n if (d.piece) o.userData.destructionPiece = d.piece\n if (d.joint) o.userData.destructionJoint = d.joint\n }\n }\n}\n\nfunction stripUndefined<T extends object>(o: T | undefined): Partial<T> {\n const out: Partial<T> = {}\n if (o) for (const k of Object.keys(o) as Array<keyof T>) if (o[k] !== undefined) out[k] = o[k]\n return out\n}\n","import type * as ThreeNS from 'three'\nimport type { PropsApi } from '@adatechnology/game-props3d'\n\n/** The host's `THREE` namespace (or any object with the same classes). Always passed in, never imported at runtime. */\nexport type ThreeLib = typeof ThreeNS\nexport type { ThreeNS }\n\nexport type Vec3 = [number, number, number]\n\n/** Material keys the mesh api understands (same as `PropsApi` materials). */\nexport type MaterialKey = 'plain' | 'metal' | 'wood' | 'glass' | 'fabric' | 'plant' | 'water' | 'emissive' | 'atlas_picture' | 'atlas_floor'\n\nexport const MATERIAL_KEYS: readonly MaterialKey[] = ['plain', 'metal', 'wood', 'glass', 'fabric', 'plant', 'water', 'emissive', 'atlas_picture', 'atlas_floor']\n\nexport type Quality = 'high' | 'game'\n\n/**\n * What content packs draw through: the props primitives plus `part`.\n * `part(id, pivot, ry, draw)` runs `draw()` and routes every primitive drawn inside it into the movable part `id`.\n * `pivot` is object-local; the primitives drawn inside `draw` are in the part frame (relative to the pivot, turned by `ry`): the part's\n * group origin sits at `pivot`, turned by `ry` around +y.\n */\nexport interface HouseholdApi extends PropsApi {\n part(id: string, pivot: Vec3, ry: number, draw: () => void): void\n}\n\n/** Anything that can create a canvas (the global `document`, or a fake in tests). */\nexport interface CanvasFactory {\n createElement(tag: 'canvas'): HTMLCanvasElement\n}\n","import { poseOf as enginePoseOf } from '@adatechnology/game-interactables'\nimport type { Motion, World } from '@adatechnology/game-interactables'\nimport type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/** Pure pose of a part at `t`, in the part's own frame (the frame at rest: pivot at the origin, already turned by the part's `ry`). */\nexport interface Pose {\n /** Translation, part frame. */\n position: Vec3\n /** Rotation as a quaternion [x, y, z, w], part frame. */\n quaternion: [number, number, number, number]\n /** Scale per local axis. */\n scale: Vec3\n}\n\n/**\n * The engine's pose math, as a quaternion. This is the engine's own `poseOf` (same default angles and distances), so the rendered\n * part and the engine's `slotPosition`, colliders, mirrors and `fitSweep` always agree. `t` is clamped to [0, 1].\n */\nexport function poseOf(motion: Motion, t: number): Pose {\n const k = Math.min(1, Math.max(0, Number.isFinite(t) ? t : 0))\n const pose = enginePoseOf(motion, k)\n const [x, y, z] = pose.rotation.axis\n const l = Math.hypot(x, y, z) || 1\n const s = Math.sin(pose.rotation.angle / 2)\n return {\n position: [pose.position[0], pose.position[1], pose.position[2]],\n quaternion: [(x / l) * s, (y / l) * s, (z / l) * s, Math.cos(pose.rotation.angle / 2)],\n scale: [pose.scale[0], pose.scale[1], pose.scale[2]],\n }\n}\n\ninterface Rest {\n position: Vec3\n quaternion: [number, number, number, number]\n scale: Vec3\n}\n\n/** Remembers the rest transform of a part group in `userData.rest` (once). */\nexport function rememberRest(group: Pick<ThreeNS.Object3D, 'position' | 'quaternion' | 'scale' | 'userData'>): Rest {\n let rest = group.userData.rest as Rest | undefined\n if (!rest) {\n const p = group.position\n const q = group.quaternion\n const s = group.scale\n rest = { position: [p.x, p.y, p.z], quaternion: [q.x, q.y, q.z, q.w], scale: [s.x, s.y, s.z] }\n group.userData.rest = rest\n }\n return rest\n}\n\n/**\n * Poses `group` for a motion at `t`. The rest pose (position at the pivot, rotation `ry`) is saved in `group.userData.rest` the first\n * time, so calling this every frame never drifts. The motion axis lives in the part frame (after `ry`).\n */\nexport function applyPose<G extends import('three').Object3D>(THREE: ThreeLib, group: G, motion: Motion, t: number): G {\n const rest = rememberRest(group)\n const pose = poseOf(motion, t)\n const restQ = new THREE.Quaternion(rest.quaternion[0], rest.quaternion[1], rest.quaternion[2], rest.quaternion[3])\n const delta = new THREE.Quaternion(pose.quaternion[0], pose.quaternion[1], pose.quaternion[2], pose.quaternion[3])\n group.quaternion.copy(restQ).multiply(delta)\n const offset = new THREE.Vector3(pose.position[0], pose.position[1], pose.position[2]).applyQuaternion(restQ)\n group.position.set(rest.position[0] + offset.x, rest.position[1] + offset.y, rest.position[2] + offset.z)\n group.scale.set(rest.scale[0] * pose.scale[0], rest.scale[1] * pose.scale[1], rest.scale[2] * pose.scale[2])\n group.updateMatrix()\n return group\n}\n\nexport interface SyncOptions {\n /** Seconds, drives the idle flutter of sway shaders. Default 0. */\n time?: number\n}\n\n/**\n * Per-frame sync of one world object: every part group takes the motion of its `PartSpec` at the world's current t,\n * and every soft volume swings. A soft volume drives the group in `parts` under its `part` (or, failing that, its own id):\n * meshes patched with `attachSway` get the swing through their shader uniforms (so shadows follow), any other group is rotated\n * around the anchor line.\n */\nexport function syncObject(THREE: ThreeLib, world: World, objectId: string, parts: Record<string, import('three').Object3D>, options: SyncOptions = {}): void {\n const obj = world.get(objectId)\n if (!obj) return\n const motionOf = new Map<string, Motion>()\n for (const p of obj.spec.parts ?? []) {\n motionOf.set(p.id, p.motion)\n const g = parts[p.id]\n if (!g) continue\n const merged = g.userData.merged as { kind: string; apply?: (m: Motion, t: number) => void } | undefined\n if (merged) {\n // parts merged into one mesh: the batch poses every vertex around its own pivot (cloth batches stay at rest)\n merged.apply?.(p.motion, world.partT(objectId, p.id))\n continue\n }\n applyPose(THREE, g, p.motion, world.partT(objectId, p.id))\n }\n for (const soft of obj.spec.soft ?? []) {\n const key = soft.part ?? soft.id\n const g = parts[key] ?? parts[soft.id]\n if (!g) continue\n const { ax, az } = world.sway(objectId, soft.id)\n const batch = g.userData.merged as { kind: string; index?: Record<string, number>; setAt?: (i: number, ax: number, az: number) => void; setTime?: (t: number) => void } | undefined\n if (batch?.kind === 'sway') {\n const i = batch.index?.[soft.id]\n if (i !== undefined) batch.setAt?.(i, ax, az)\n if (options.time !== undefined) batch.setTime?.(options.time)\n continue\n }\n let shaded = false\n g.traverse((o) => {\n const sway = o.userData.sway as { set(ax: number, az: number, time?: number): void } | undefined\n if (sway) {\n sway.set(ax, az, options.time)\n shaded = true\n }\n })\n if (shaded) continue\n rememberRest(g)\n // rotate around the anchor line: the part's pose (if it has a motion) is already applied above\n if (!motionOf.has(key)) applyPose(THREE, g, { kind: 'hinge', angle: 0 }, 0)\n const rot = new THREE.Quaternion().setFromEuler(new THREE.Euler(ax, 0, az, 'XYZ'))\n const anchor = new THREE.Vector3(soft.anchor[0], soft.anchor[1], soft.anchor[2])\n g.position.sub(anchor).applyQuaternion(rot).add(anchor)\n g.quaternion.premultiply(rot)\n g.updateMatrix()\n }\n}\n","import type { Motion, ObjectSpec } from '@adatechnology/game-interactables'\nimport type { ShapeSolid } from '@adatechnology/game-shapes'\nimport { poseOf } from './pose'\nimport type { ThreeLib, ThreeNS } from './types'\n\nexport interface MergeOptions {\n /** Idle flutter of merged cloth (see `SwayOptions.amplitude`). Default 0.04. */\n swayAmplitude?: number\n}\n\n/** Posed by `syncObject` in place of the part groups it replaced. */\nexport interface PoseBatch {\n kind: 'pose'\n /** Part ids that moved into the batch. */\n ids: string[]\n /** Applies the motion at `t` to every vertex, each around its own pivot. */\n apply(motion: Motion, t: number): void\n}\n\n/** Cloth hanging from a line: every merged cloth swings with its own (ax, az). */\nexport interface SwayBatch {\n kind: 'sway'\n /** Soft volume id -> index. */\n index: Record<string, number>\n setAt(index: number, ax: number, az: number): void\n setTime(time: number): void\n}\n\nexport type MergedGroup = ThreeNS.Group & { userData: { merged: PoseBatch | SwayBatch } }\n\nconst QROT = /* glsl */ `\nvec3 batchRotate(vec4 q, vec3 v) { return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v); }\n`\n\nfunction patchProgram<M extends ThreeNS.Material>(material: M, key: string, patchShader: (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }) => void, inherit?: ThreeNS.Material): M {\n const previous = material.onBeforeCompile\n material.onBeforeCompile = (shader, renderer) => {\n previous?.call(material, shader, renderer)\n patchShader(shader)\n }\n const inherited = inherit?.customProgramCacheKey\n material.customProgramCacheKey = inherited && inherit ? () => `${inherited.call(inherit)}|${key}` : () => key\n return material\n}\n\n/**\n * `Material.clone()` drops `onBeforeCompile`, `customProgramCacheKey` and (for some classes) `defines`. A merged group must still look\n * like the material the host passed in (a light mask, a fog patch...), so the clone gets them back before the batch patch is chained on.\n */\nfunction cloneKeepingHooks(base: ThreeNS.Material): ThreeNS.Material {\n const clone = base.clone()\n if (base.defines) clone.defines = { ...(clone.defines ?? {}), ...base.defines }\n if (base.onBeforeCompile !== Object.getPrototypeOf(base).onBeforeCompile) clone.onBeforeCompile = base.onBeforeCompile\n clone.userData = { ...base.userData, mergedFrom: base.uuid }\n return clone\n}\n\n/** Material, depth material and distance material patched by the same function, so shadows follow the animation. */\nfunction patchedSet(THREE: ThreeLib, base: ThreeNS.Material, key: string, patchShader: (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }) => void) {\n return {\n material: patchProgram(cloneKeepingHooks(base), key, patchShader, base),\n depth: patchProgram(new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }), key, patchShader),\n distance: patchProgram(new THREE.MeshDistanceMaterial(), key, patchShader),\n }\n}\n\ninterface Piece {\n geometry: ThreeNS.BufferGeometry\n matrix: ThreeNS.Matrix4\n /** Per-vertex extra attributes of this piece. */\n extra: Record<string, number[]>\n /** The solids the piece's mesh carries (`userData.solids`), in the piece's own space. */\n solids?: readonly ShapeSolid[] | undefined\n}\n\n/** Concatenates pieces (positions and normals moved by their matrices) into one geometry with the extra attributes. */\nfunction concat(THREE: ThreeLib, pieces: readonly Piece[], extraSizes: Record<string, number>): ThreeNS.BufferGeometry {\n let verts = 0\n let idx = 0\n for (const p of pieces) {\n verts += p.geometry.getAttribute('position').count\n idx += p.geometry.index!.count\n }\n const pos = new Float32Array(verts * 3)\n const nor = new Float32Array(verts * 3)\n const col = new Float32Array(verts * 3)\n const uv = new Float32Array(verts * 2)\n const index = new Uint32Array(idx)\n const extra: Record<string, Float32Array> = {}\n for (const [k, n] of Object.entries(extraSizes)) extra[k] = new Float32Array(verts * n)\n const v = new THREE.Vector3()\n const n3 = new THREE.Matrix3()\n let vo = 0\n let io = 0\n for (const p of pieces) {\n const g = p.geometry\n const count = g.getAttribute('position').count\n n3.getNormalMatrix(p.matrix)\n const gp = g.getAttribute('position')\n const gn = g.getAttribute('normal')\n const gc = g.getAttribute('color')\n const gu = g.getAttribute('uv')\n for (let i = 0; i < count; i++) {\n v.fromBufferAttribute(gp, i).applyMatrix4(p.matrix)\n pos.set([v.x, v.y, v.z], (vo + i) * 3)\n v.fromBufferAttribute(gn, i).applyMatrix3(n3).normalize()\n nor.set([v.x, v.y, v.z], (vo + i) * 3)\n col.set([gc.getX(i), gc.getY(i), gc.getZ(i)], (vo + i) * 3)\n uv.set([gu.getX(i), gu.getY(i)], (vo + i) * 2)\n }\n for (const [k, values] of Object.entries(p.extra)) extra[k].set(values, vo * extraSizes[k])\n const gi = g.index!\n for (let i = 0; i < gi.count; i++) index[io + i] = gi.getX(i) + vo\n vo += count\n io += gi.count\n }\n const out = new THREE.BufferGeometry()\n out.setAttribute('position', new THREE.BufferAttribute(pos, 3))\n out.setAttribute('normal', new THREE.BufferAttribute(nor, 3))\n out.setAttribute('color', new THREE.BufferAttribute(col, 3))\n out.setAttribute('uv', new THREE.BufferAttribute(uv, 2))\n for (const [k, n] of Object.entries(extraSizes)) out.setAttribute(k, new THREE.BufferAttribute(extra[k], n))\n out.setIndex(new THREE.BufferAttribute(verts > 65535 ? index : new Uint16Array(index), 1))\n out.computeBoundingSphere()\n out.computeBoundingBox()\n return out\n}\n\n/**\n * The solids of the pieces joined in one mesh (spec 019): each piece's own (`userData.solids` of its mesh), carried by the piece's place and numbered after the vertices of\n * the pieces before it. None when a piece has none: a mesh that says only some of what it draws would be held by less than it is.\n */\nfunction mergedSolids(THREE: ThreeLib, pieces: readonly Piece[]): ShapeSolid[] | undefined {\n if (pieces.some((p) => !p.solids)) return undefined\n const out: ShapeSolid[] = []\n const position = new THREE.Vector3()\n const turn = new THREE.Quaternion()\n const scale = new THREE.Vector3()\n const centre = new THREE.Vector3()\n const own = new THREE.Quaternion()\n let first = 0\n for (const p of pieces) {\n p.matrix.decompose(position, turn, scale)\n for (const solid of p.solids ?? []) {\n centre.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(p.matrix)\n own.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]).premultiply(turn).normalize()\n out.push({\n ...solid,\n center: [centre.x, centre.y, centre.z],\n half: [solid.half[0] * Math.abs(scale.x), solid.half[1] * Math.abs(scale.y), solid.half[2] * Math.abs(scale.z)],\n rotation: [own.x, own.y, own.z, own.w],\n vertexStart: solid.vertexStart + first,\n })\n }\n first += p.geometry.getAttribute('position').count\n }\n return out\n}\n\nfunction meshesOf(group: ThreeNS.Object3D): ThreeNS.Mesh[] {\n return group.children.filter((c): c is ThreeNS.Mesh => (c as ThreeNS.Mesh).isMesh)\n}\n\n/**\n * Merges parts after `finish()` to cut draw calls (the `mergeParts` option of `createMeshApi`):\n *\n * - parts of one `PartSpec.group` with the same motion (blind slats) become one mesh per material whose vertices carry their own pivot;\n * `syncObject` poses them with one set of uniforms and the shadow materials follow;\n * - `cloth` soft volumes (clothes on a line) become one mesh per material with a per-vertex cloth index and anchor height; each\n * cloth keeps its own swing.\n *\n * The merged group is added to `root`, the part groups are removed, and `parts[id]` points at the merged group for every member.\n * Parts that carry a mirror, that are turned (`ry`) or that stand alone are left as they are.\n */\nexport function mergeParts(THREE: ThreeLib, root: ThreeNS.Group, parts: Record<string, ThreeNS.Group>, spec: ObjectSpec, options: MergeOptions = {}): void {\n const amplitude = options.swayAmplitude ?? 0.04\n const skip = new Set<string>()\n for (const m of spec.mirrors ?? []) if (m.part) skip.add(m.part)\n for (const [id, g] of Object.entries(parts)) if (Math.abs(g.rotation.y) > 1e-9 || g.userData.merged) skip.add(id)\n\n const take = (ids: string[]): ThreeNS.Group[] => ids.map((id) => parts[id])\n const retire = (ids: string[], merged: ThreeNS.Group): void => {\n for (const id of ids) {\n const g = parts[id]\n g.removeFromParent()\n for (const m of meshesOf(g)) m.geometry.dispose()\n parts[id] = merged\n }\n root.add(merged)\n }\n const byMaterial = (groups: ThreeNS.Group[], extra: (g: ThreeNS.Group, count: number) => Record<string, number[]>) => {\n const map = new Map<string, { base: ThreeNS.Material; pieces: Piece[]; mesh: ThreeNS.Mesh }>()\n for (const g of groups) {\n g.updateMatrix()\n for (const mesh of meshesOf(g)) {\n const key = `${String(mesh.userData.material)}|${(mesh.material as ThreeNS.Material).uuid}`\n let e = map.get(key)\n if (!e) {\n e = { base: mesh.material as ThreeNS.Material, pieces: [], mesh }\n map.set(key, e)\n }\n e.pieces.push({ geometry: mesh.geometry, matrix: g.matrix, extra: extra(g, mesh.geometry.getAttribute('position').count), solids: mesh.userData.solids as readonly ShapeSolid[] | undefined })\n }\n }\n return map\n }\n const finishMesh = (name: string, key: string, pieces: readonly Piece[], extraSizes: Record<string, number>, template: ThreeNS.Mesh, set: ReturnType<typeof patchedSet>, group: ThreeNS.Group): void => {\n const mesh = new THREE.Mesh(concat(THREE, pieces, extraSizes), set.material)\n mesh.name = `${name}:${key}`\n mesh.userData.material = key\n const solids = mergedSolids(THREE, pieces)\n if (solids) mesh.userData.solids = solids\n mesh.castShadow = template.castShadow\n mesh.receiveShadow = template.receiveShadow\n mesh.customDepthMaterial = set.depth\n mesh.customDistanceMaterial = set.distance\n group.add(mesh)\n }\n\n // ---- cloth: one swing per soft volume, merged per material -------------------------------------------------------------------\n const cloths = (spec.soft ?? []).filter((s) => s.kind === 'cloth' && parts[s.part ?? s.id] && !skip.has(s.part ?? s.id))\n const clothPart = (s: { id: string; part?: string }) => s.part ?? s.id\n const toggled = new Set<string>()\n for (const i of spec.interactions ?? []) {\n const a = i.action as { do: string; part?: string }\n if (a.do === 'toggle_part' && a.part) toggled.add(a.part)\n }\n const swing = cloths.filter((s) => !toggled.has(clothPart(s)))\n if (swing.length >= 2) {\n const ids = swing.map(clothPart)\n const index: Record<string, number> = {}\n swing.forEach((s, i) => (index[s.id] = i))\n const indexOfPart = new Map(swing.map((s, i) => [clothPart(s), i]))\n const anchorOfPart = new Map(swing.map((s) => [clothPart(s), s.anchor[1]]))\n const n = swing.length\n const uniforms = { time: { value: 0 }, axz: { value: Array.from({ length: n }, () => new THREE.Vector2()) } }\n const groups = take(ids)\n const partIdOf = new Map(groups.map((g, i) => [g, ids[i]]))\n const plan = byMaterial(groups, (g, count) => {\n const id = partIdOf.get(g)!\n return { swayId: new Array(count).fill(indexOf(indexOfPart, id)), swayAnchor: new Array(count).fill(anchorOfPart.get(id) ?? 0) }\n })\n const merged = new THREE.Group() as unknown as MergedGroup\n merged.name = 'merge:cloth'\n const patch = (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }): void => {\n shader.uniforms.swayTime = uniforms.time\n shader.uniforms.swayAxz = uniforms.axz\n shader.vertexShader =\n `attribute float swayId;\\nattribute float swayAnchor;\\nuniform float swayTime;\\nuniform vec2 swayAxz[${n}];\\n` +\n shader.vertexShader.replace(\n '#include <begin_vertex>',\n `#include <begin_vertex>\n{\n vec2 swayA = swayAxz[int(swayId + 0.5)];\n float swayHang = max(swayAnchor - position.y, 0.0);\n float swayFlutter = ${amplitude.toFixed(4)} * sin(swayTime * 1.9 + swayId * 1.7 + position.x * 4.0 + position.z * 3.0 + swayHang * 3.0);\n transformed.x += swayHang * (sin(swayA.y) + swayFlutter);\n transformed.z += swayHang * (-sin(swayA.x) + swayFlutter * 0.6);\n transformed.y += swayHang * (1.0 - cos(swayA.y) * cos(swayA.x));\n}`,\n )\n }\n for (const e of plan.values()) {\n const key = String(e.mesh.userData.material)\n const set = patchedSet(THREE, e.base, `swayBatch:${n}:${amplitude}`, patch)\n finishMesh('merge:cloth', key, e.pieces, { swayId: 1, swayAnchor: 1 }, e.mesh, set, merged)\n }\n const batch: SwayBatch = {\n kind: 'sway',\n index,\n setAt(i, ax, az) {\n uniforms.axz.value[i].set(ax, az)\n },\n setTime(t) {\n uniforms.time.value = t\n },\n }\n merged.userData.merged = batch\n retire(ids, merged)\n for (const id of ids) skip.add(id)\n }\n\n // ---- grouped parts with identical motion (blind slats) -----------------------------------------------------------------------\n const bySignature = new Map<string, string[]>()\n for (const p of spec.parts ?? []) {\n if (!p.group || !parts[p.id] || skip.has(p.id)) continue\n const sig = `${p.group}|${JSON.stringify(p.motion)}`\n const list = bySignature.get(sig)\n if (list) list.push(p.id)\n else bySignature.set(sig, [p.id])\n }\n for (const [sig, ids] of bySignature) {\n if (ids.length < 2) continue\n const motion = (spec.parts ?? []).find((p) => p.id === ids[0])!.motion\n const uniforms = { q: { value: new THREE.Vector4(0, 0, 0, 1) }, pos: { value: new THREE.Vector3() }, scale: { value: new THREE.Vector3(1, 1, 1) } }\n const groups = take(ids)\n const plan = byMaterial(groups, (g, count) => {\n const pv = new Array<number>(count * 3)\n for (let i = 0; i < count; i++) {\n pv[i * 3] = g.position.x\n pv[i * 3 + 1] = g.position.y\n pv[i * 3 + 2] = g.position.z\n }\n return { batchPivot: pv }\n })\n const merged = new THREE.Group() as unknown as MergedGroup\n merged.name = `merge:${sig.split('|')[0]}`\n const patch = (shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }): void => {\n shader.uniforms.batchQ = uniforms.q\n shader.uniforms.batchPos = uniforms.pos\n shader.uniforms.batchScale = uniforms.scale\n let src = `attribute vec3 batchPivot;\\nuniform vec4 batchQ;\\nuniform vec3 batchPos;\\nuniform vec3 batchScale;\\n${QROT}${shader.vertexShader}`\n src = src.replace('#include <begin_vertex>', '#include <begin_vertex>\\ntransformed = batchPivot + batchRotate(batchQ, (position - batchPivot) * batchScale) + batchPos;')\n src = src.replace('#include <beginnormal_vertex>', '#include <beginnormal_vertex>\\nobjectNormal = batchRotate(batchQ, objectNormal);')\n shader.vertexShader = src\n }\n for (const e of plan.values()) {\n const key = String(e.mesh.userData.material)\n const set = patchedSet(THREE, e.base, 'poseBatch', patch)\n finishMesh(merged.name, key, e.pieces, { batchPivot: 3 }, e.mesh, set, merged)\n }\n const batch: PoseBatch = {\n kind: 'pose',\n ids,\n apply(m, t) {\n const pose = poseOf(m, t)\n uniforms.q.value.set(pose.quaternion[0], pose.quaternion[1], pose.quaternion[2], pose.quaternion[3])\n uniforms.pos.value.set(pose.position[0], pose.position[1], pose.position[2])\n uniforms.scale.value.set(pose.scale[0], pose.scale[1], pose.scale[2])\n },\n }\n batch.apply(motion, 0)\n merged.userData.merged = batch\n retire(ids, merged)\n }\n}\n\nfunction indexOf(map: Map<string, number>, id: string): number {\n return map.get(id) ?? 0\n}\n","import type { ShapeNode, ShapeSchema } from '@adatechnology/game-shapes'\n\ntype Vector = [number, number, number]\ntype Point2 = [number, number]\n/** Row-major 3x3. */\ntype Matrix = readonly number[]\n\n/** How far a face moves to leave the plane it shared (CLAUDE.md §13: a detail stands out or sinks at least 2 mm). */\nconst GAP = 0.002\n/** The guard's reach: two faces closer than this are one plane. */\nconst SAME_PLANE = 0.00105\n/** Faces whose normals differ by less than this (per component) are parallel to the guard. */\nconst SAME_DIRECTION = 0.0015\n/** Overlaps below this (m²) are edge contacts; the guard's own floor is 1e-4. */\nconst MIN_OVERLAP_AREA = 5e-5\n/** A piece thinner than this along the axis grows out instead of sinking in. */\nconst MIN_THICKNESS_TO_SINK = 0.012\nconst MAX_ROUNDS = 6\nconst IDENTITY: Matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\ntype Writable = { position?: Vector; rotation?: Vector; rotationOrder?: string; scale?: number | Vector; heading?: number; matrix?: unknown; children?: Writable[]; kind: string; radiusTop?: number; radiusBottom?: number; size?: Vector }\n\ntype Piece = {\n readonly node: Writable\n /** Rotation of the parent frame (frame to world). */\n readonly parentRotation: Matrix\n readonly center: Vector\n /** World direction of each local axis. */\n readonly axes: readonly [Vector, Vector, Vector]\n readonly half: Vector\n /** A cylinder only has flat faces on its own height axis. */\n readonly isCylinder: boolean\n /** A plane has one face and no thickness. */\n readonly isPlane: boolean\n}\n\ntype Face = { readonly piece: Piece; readonly axis: number; readonly sign: number; readonly normal: Vector; readonly offset: number }\n\nconst dot = (a: Vector, b: Vector): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2]\nconst cross = (a: Vector, b: Vector): Vector => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]\n\nfunction multiply(a: Matrix, b: Matrix): Matrix {\n const out: number[] = []\n for (let row = 0; row < 3; row++) for (let column = 0; column < 3; column++) out.push(a[row * 3]! * b[column]! + a[row * 3 + 1]! * b[3 + column]! + a[row * 3 + 2]! * b[6 + column]!)\n return out\n}\n\nfunction rotationAbout(axis: number, angle: number): Matrix {\n const c = Math.cos(angle)\n const s = Math.sin(angle)\n if (axis === 0) return [1, 0, 0, 0, c, -s, 0, s, c]\n if (axis === 1) return [c, 0, s, 0, 1, 0, -s, 0, c]\n return [c, -s, 0, s, c, 0, 0, 0, 1]\n}\n\n/** The rotation of a node as three composes it: the heading about y first, then the euler angles in their order (`'YXZ'` is Ry * Rx * Rz). */\nfunction rotationOf(node: Writable): Matrix {\n let matrix = node.heading ? rotationAbout(1, node.heading) : IDENTITY\n if (node.rotation) {\n for (const letter of node.rotationOrder ?? 'XYZ') matrix = multiply(matrix, rotationAbout('XYZ'.indexOf(letter), node.rotation['XYZ'.indexOf(letter)]!))\n }\n return matrix\n}\n\nfunction apply(matrix: Matrix, vector: Vector): Vector {\n return [0, 1, 2].map((row) => matrix[row * 3]! * vector[0] + matrix[row * 3 + 1]! * vector[1] + matrix[row * 3 + 2]! * vector[2]) as Vector\n}\n\nfunction transpose(matrix: Matrix): Matrix {\n return [matrix[0]!, matrix[3]!, matrix[6]!, matrix[1]!, matrix[4]!, matrix[7]!, matrix[2]!, matrix[5]!, matrix[8]!]\n}\n\nfunction pieceOf(node: Writable, parentOrigin: Vector, parentRotation: Matrix): Piece | undefined {\n if (node.matrix || node.size || !Array.isArray(node.scale) || !node.position) return undefined\n const isCylinder = node.kind === 'cylinder'\n const isPlane = node.kind === 'plane'\n if (isCylinder && (node.radiusTop ?? 1) !== (node.radiusBottom ?? 1)) return undefined\n const rotation = multiply(parentRotation, rotationOf(node))\n const axes = [0, 1, 2].map((column) => [rotation[column]!, rotation[3 + column]!, rotation[6 + column]!] as Vector) as unknown as Piece['axes']\n const half: Vector = isCylinder ? [node.scale[0]!, node.scale[1]! / 2, node.scale[2]!] : isPlane ? [node.scale[0]! / 2, node.scale[1]! / 2, 0] : [node.scale[0]! / 2, node.scale[1]! / 2, node.scale[2]! / 2]\n const offset = apply(parentRotation, node.position)\n return { node, parentRotation, center: [parentOrigin[0] + offset[0]!, parentOrigin[1] + offset[1]!, parentOrigin[2] + offset[2]!], axes, half, isCylinder, isPlane }\n}\n\nfunction collect(nodes: readonly ShapeNode[], origin: Vector, rotation: Matrix, out: Piece[]): void {\n for (const source of nodes) {\n const node = source as unknown as Writable\n if (node.kind === 'group') {\n if (node.matrix || node.scale !== undefined) continue\n const offset = apply(rotation, node.position ?? [0, 0, 0])\n collect((node.children ?? []) as unknown as readonly ShapeNode[], [origin[0] + offset[0]!, origin[1] + offset[1]!, origin[2] + offset[2]!], multiply(rotation, rotationOf(node)), out)\n } else if (node.kind === 'box' || node.kind === 'cylinder' || node.kind === 'plane') {\n const piece = pieceOf(node, origin, rotation)\n if (piece) out.push(piece)\n }\n }\n}\n\nfunction faceOf(piece: Piece, axis: number, sign: number): Face {\n const normal: Vector = [piece.axes[axis]![0] * sign, piece.axes[axis]![1] * sign, piece.axes[axis]![2] * sign]\n return { piece, axis, sign, normal, offset: dot(normal, piece.center) + piece.half[axis]! }\n}\n\nfunction facesOf(piece: Piece): Face[] {\n if (piece.isPlane) return [faceOf(piece, 2, 1)]\n return (piece.isCylinder ? [1] : [0, 1, 2]).flatMap((axis) => [faceOf(piece, axis, 1), faceOf(piece, axis, -1)])\n}\n\n/** The four corners of a face, in the plane's 2D basis (`u`, `v`). */\nfunction cornersOf(face: Face, u: Vector, v: Vector): Point2[] {\n const { piece, axis } = face\n const [first, second] = [0, 1, 2].filter((other) => other !== axis) as [number, number]\n return ([[1, 1], [1, -1], [-1, -1], [-1, 1]] as const).map(([a, b]) => {\n const point = [0, 1, 2].map((k) => piece.center[k]! + piece.axes[first]![k]! * piece.half[first]! * a + piece.axes[second]![k]! * piece.half[second]! * b) as Vector\n return [dot(point, u), dot(point, v)] as Point2\n })\n}\n\nconst side = (p: Point2, a: Point2, b: Point2): number => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0])\n\n/** Area of the overlap of two convex polygons (Sutherland-Hodgman). */\nfunction overlapArea(subject: Point2[], clip: Point2[]): number {\n let output = subject\n const orientation = Math.sign(side(clip[2]!, clip[0]!, clip[1]!)) || 1\n for (let i = 0; i < clip.length && output.length; i++) {\n const a = clip[i]!\n const b = clip[(i + 1) % clip.length]!\n const input = output\n output = []\n for (let j = 0; j < input.length; j++) {\n const current = input[j]!\n const previous = input[(j + input.length - 1) % input.length]!\n const currentInside = side(current, a, b) * orientation >= 0\n if (currentInside !== side(previous, a, b) * orientation >= 0) {\n const t = side(previous, a, b) / (side(previous, a, b) - side(current, a, b))\n output.push([previous[0] + (current[0] - previous[0]) * t, previous[1] + (current[1] - previous[1]) * t])\n }\n if (currentInside) output.push(current)\n }\n }\n let area = 0\n for (let i = 0; i < output.length; i++) {\n const p = output[i]!\n const q = output[(i + 1) % output.length]!\n area += p[0] * q[1] - q[0] * p[1]\n }\n return Math.abs(area) / 2\n}\n\nfunction planeBasis(normal: Vector): [Vector, Vector] {\n const side = cross(normal, Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0])\n const length = Math.hypot(...side)\n const u: Vector = [side[0] / length, side[1] / length, side[2] / length]\n return [u, cross(normal, u)]\n}\n\n/** How far the face reaches from the piece's centre along world axis `k`, over its two in-plane axes. */\nfunction faceReach(face: Face, k: number): number {\n const { piece, axis } = face\n let reach = 0\n for (let other = 0; other < 3; other++) if (other !== axis) reach += Math.abs(piece.axes[other]![k]!) * piece.half[other]!\n return reach\n}\n\n/** Whether the world boxes of two faces touch: a cheap test before clipping them. */\nfunction facesNear(a: Face, b: Face, slack = SAME_PLANE): boolean {\n for (let k = 0; k < 3; k++) {\n const centreA = a.piece.center[k]! + a.normal[k]! * a.piece.half[a.axis]!\n const centreB = b.piece.center[k]! + b.normal[k]! * b.piece.half[b.axis]!\n if (Math.abs(centreA - centreB) > faceReach(a, k) + faceReach(b, k) + slack) return false\n }\n return true\n}\n\nfunction fight(a: Face, b: Face): boolean {\n if (Math.abs(a.offset - b.offset) > SAME_PLANE) return false\n if ([0, 1, 2].some((k) => Math.abs(a.normal[k]! - b.normal[k]!) > SAME_DIRECTION)) return false\n if (!facesNear(a, b)) return false\n const [u, v] = planeBasis(a.normal)\n return overlapArea(cornersOf(a, u, v), cornersOf(b, u, v)) > MIN_OVERLAP_AREA\n}\n\n/** Moves a face of a piece by `amount` (positive: out) along its normal, in the piece's node. */\nfunction moveFace(face: Face, amount: number): void {\n const { piece, axis } = face\n const scale = piece.node.scale as Vector\n if (!piece.isPlane) {\n scale[axis] = scale[axis]! + amount\n piece.half[axis] = piece.half[axis]! + amount / 2\n }\n const shift = face.normal.map((component) => (component * amount) / (piece.isPlane ? 1 : 2)) as Vector\n for (let k = 0; k < 3; k++) piece.center[k] = piece.center[k]! + shift[k]!\n const inParent = apply(transpose(piece.parentRotation), shift)\n const position = piece.node.position as Vector\n for (let k = 0; k < 3; k++) position[k] = position[k]! + inParent[k]!\n}\n\n/** Faces looking the same way, grouped by their rounded normal: only faces in one group can share a plane. */\ntype FaceGroups = Map<number, Face[]>\n\nconst DIRECTION_SPAN = 2048\nconst directionKey = (normal: Vector): number =>\n ((Math.round(normal[0] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN + Math.round(normal[1] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN +\n Math.round(normal[2] / SAME_DIRECTION) + DIRECTION_SPAN / 2\n\nfunction groupFaces(pieces: readonly Piece[]): FaceGroups {\n const groups: FaceGroups = new Map()\n for (const piece of pieces) {\n for (const face of facesOf(piece)) {\n const key = directionKey(face.normal)\n const group = groups.get(key)\n if (group) group.push(face)\n else groups.set(key, [face])\n }\n }\n return groups\n}\n\n/** The same face as it is now: a piece moved earlier in the round has its face somewhere else. */\nconst liveFace = (face: Face): Face => faceOf(face.piece, face.axis, face.sign)\n\n/** Moves the face by the first of 2 mm in, 2 mm out, 4 mm in, 4 mm out (out first for a thin piece) that lands on no other piece's face. */\nfunction clearFace(face: Face, groups: FaceGroups): void {\n const { piece, axis, sign } = face\n const thick = piece.half[axis]! * 2 >= MIN_THICKNESS_TO_SINK\n const steps = piece.isPlane ? [GAP, 2 * GAP, 3 * GAP] : [GAP, -GAP, 2 * GAP, -2 * GAP].map((step) => (thick ? -step : step))\n const fits = (step: number): boolean => piece.isPlane || piece.half[axis]! * 2 + step >= 2 * GAP\n // only faces within the farthest step of this one, and near it, can be met: the rest of the group is skipped once\n const reach = 2 * GAP * 3 + 2 * SAME_PLANE\n const neighbours = (groups.get(directionKey(face.normal)) ?? []).filter((candidate) => candidate.piece !== piece && Math.abs(candidate.offset - face.offset) <= reach && facesNear(face, candidate, reach))\n const clear = (): boolean => {\n const moved = faceOf(piece, axis, sign)\n return neighbours.every((candidate) => !fight(moved, liveFace(candidate)))\n }\n let applied = 0\n for (const step of steps.filter(fits)) {\n moveFace(face, step - applied)\n applied = step\n if (clear()) return\n }\n moveFace(face, steps[0]! - applied)\n}\n\n/** Two coaxial round pieces whose radii differ by about a millimetre have facets on one plane: the smaller one's radius moves 2 mm away from the other. */\nfunction separateRadii(a: Piece, b: Piece): boolean {\n if (!a.isCylinder || !b.isCylinder || Math.abs(dot(a.axes[1], b.axes[1])) < 0.9999) return false\n const between: Vector = [b.center[0] - a.center[0], b.center[1] - a.center[1], b.center[2] - a.center[2]]\n const along = dot(between, a.axes[1])\n if (Math.hypot(between[0] - a.axes[1][0] * along, between[1] - a.axes[1][1] * along, between[2] - a.axes[1][2] * along) > SAME_PLANE) return false\n if (Math.abs(along) > a.half[1] + b.half[1] - 0.005 || Math.abs(a.half[0] - b.half[0]) > SAME_PLANE * 1.1) return false\n const [mover, other] = volumeOf(a) < volumeOf(b) ? [a, b] : [b, a]\n const amount = mover.half[0] >= other.half[0] ? GAP : -GAP\n const scale = mover.node.scale as Vector\n scale[0] = scale[0]! + amount\n scale[2] = scale[2]! + amount\n mover.half[0] += amount\n mover.half[2] += amount\n return true\n}\n\nconst volumeOf = (piece: Piece): number => piece.half[0] * piece.half[1] * piece.half[2]\n\n/** Calls `visit` with each pair of faces of different pieces on one plane (by offset), within each direction group: a sweep over the sorted offsets. */\nfunction forEachPlaneMate(groups: FaceGroups, visit: (a: Face, b: Face) => void): void {\n for (const group of groups.values()) {\n if (group.length < 2) continue\n group.sort((a, b) => a.offset - b.offset)\n for (let i = 0; i < group.length; i++) {\n const a = group[i]!\n for (let j = i + 1; j < group.length && group[j]!.offset - a.offset <= 2 * SAME_PLANE; j++) {\n if (group[j]!.piece !== a.piece) visit(a, group[j]!)\n }\n }\n }\n}\n\nfunction separateAllRadii(cylinders: readonly Piece[], moved: Set<Piece>): void {\n for (let i = 0; i < cylinders.length; i++) {\n for (let j = i + 1; j < cylinders.length; j++) {\n const a = cylinders[i]!\n const b = cylinders[j]!\n const reach = Math.max(a.half[0], a.half[1]) + Math.max(b.half[0], b.half[1]) + 0.01\n if (Math.abs(a.center[0] - b.center[0]) > reach || Math.abs(a.center[1] - b.center[1]) > reach || Math.abs(a.center[2] - b.center[2]) > reach) continue\n if (separateRadii(a, b)) {\n moved.add(a)\n moved.add(b)\n }\n }\n }\n}\n\n/**\n * Makes the boxes (and cylinders) of a schema stop sharing planes: when two pieces have a face on one plane, looking the same way and\n * overlapping, the smaller piece's face sinks 2 mm into the piece (or grows 2 mm out when the piece is thinner than 12 mm), CLAUDE.md §13.\n * Mutates the schema's nodes and returns it.\n */\nexport function standOutCoincidentBoxes(schema: ShapeSchema): ShapeSchema {\n const pieces: Piece[] = []\n collect((schema.root as { children?: readonly ShapeNode[] }).children ?? [], [0, 0, 0], IDENTITY, pieces)\n const cylinders = pieces.filter((piece) => piece.isCylinder)\n // after the first round only a piece that just moved can meet a new face: pairs of two still pieces were already settled\n let movedLast: Set<Piece> | undefined\n for (let round = 0; round < MAX_ROUNDS; round++) {\n const movedNow = new Set<Piece>()\n separateAllRadii(cylinders, movedNow)\n const groups = groupFaces(pieces)\n forEachPlaneMate(groups, (first, second) => {\n if (movedLast && !movedLast.has(first.piece) && !movedLast.has(second.piece)) return\n const a = liveFace(first)\n const b = liveFace(second)\n if (!fight(a, b)) return\n const mover = volumeOf(a.piece) < volumeOf(b.piece) ? a : b\n clearFace(mover, groups)\n movedNow.add(mover.piece)\n })\n if (!movedNow.size) break\n movedLast = movedNow\n }\n return schema\n}\n","import type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/** `Reflector` from `three/examples/jsm/objects/Reflector.js`, passed by the host. */\nexport type ReflectorConstructor = new (geometry: ThreeNS.BufferGeometry, options?: { textureWidth?: number; textureHeight?: number; clipBias?: number; color?: ThreeNS.ColorRepresentation }) => ThreeNS.Mesh\n\nexport interface MirrorOptions {\n /** Without it every mirror shows the env map only. */\n Reflector?: ReflectorConstructor\n /** Cube / equirect env map for the cheap look. */\n envMap?: ThreeNS.Texture | null\n /** Real reflectors alive at once. Default 1. */\n max?: number\n /** Reflector texture size in pixels. Default 512. */\n resolution?: number\n /** Where reflectors are added. Default: the root ancestor of the registered mesh. */\n scene?: ThreeNS.Object3D\n /** Distance in front of the plane, meters. Default 0.001. */\n offset?: number\n /**\n * three's `Reflector` renders the scene again inside the main `render()`, and that nested render resets `renderer.info` when\n * `info.autoReset` is on, so the counters would only show the reflector pass. With `keepInfo` (default true) the reflector adds\n * what was counted before it back, so `renderer.info.render.calls` covers the whole frame. Skipped when `info.autoReset` is off.\n */\n keepInfo?: boolean\n}\n\n/** The mirror entries of `world.mirrors(...)` (only these fields are read). */\nexport interface MirrorCandidate {\n id: string\n center: Vec3\n normal: Vec3\n}\n\nexport interface Mirrors {\n /** Registers the display mesh of a mirror (world id `objectId:mirrorId`). It gets the env-map material. `normal` is the world normal; default: the mesh's +z. */\n register(id: string, mesh: ThreeNS.Mesh, normal?: Vec3): void\n unregister(id: string): void\n /** Activates real reflectors for the nearest facing registered mirrors among `candidates`. Returns the active ids. */\n update(camera: ThreeNS.Camera, candidates: readonly MirrorCandidate[]): string[]\n /** Ids that currently have a real reflector. */\n active(): string[]\n /** The shared env-map material registered meshes use. */\n envMaterial: ThreeNS.Material\n dispose(): void\n}\n\ninterface Entry {\n mesh: ThreeNS.Mesh\n normal: Vec3 | null\n original: ThreeNS.Material | ThreeNS.Material[]\n}\n\ninterface Slot {\n reflector: ThreeNS.Mesh\n id: string | null\n}\n\n/**\n * Mirrors: every registered mirror shows an env-map material; the nearest `max` that face the camera get a real `Reflector`\n * (pooled and reused), placed `offset` in front of the plane with the mesh's rotation and size.\n */\nexport function createMirrors(THREE: ThreeLib, options: MirrorOptions = {}): Mirrors {\n const max = Math.max(0, Math.floor(options.max ?? 1))\n const resolution = options.resolution ?? 512\n const offset = options.offset ?? 0.001\n const envMaterial = new THREE.MeshStandardMaterial({ color: 0xdfe6ea, metalness: 1, roughness: 0.04, envMap: options.envMap ?? null })\n const entries = new Map<string, Entry>()\n const slots: Slot[] = []\n const geometry = new THREE.PlaneGeometry(1, 1)\n\n const worldNormal = (e: Entry, out: ThreeNS.Vector3): ThreeNS.Vector3 => {\n if (e.normal) return out.set(e.normal[0], e.normal[1], e.normal[2]).normalize()\n e.mesh.updateWorldMatrix(true, false)\n return out.set(0, 0, 1).transformDirection(e.mesh.matrixWorld)\n }\n\n const slotFor = (id: string): Slot | null => {\n if (!options.Reflector) return null\n const existing = slots.find((s) => s.id === id)\n if (existing) return existing\n const free = slots.find((s) => s.id === null)\n if (free) return free\n if (slots.length >= max) return null\n const reflector = new options.Reflector(geometry, { textureWidth: resolution, textureHeight: resolution, clipBias: 0.003 })\n reflector.name = 'mirror:reflector'\n if (options.keepInfo !== false) {\n const original = reflector.onBeforeRender\n reflector.onBeforeRender = function (this: ThreeNS.Mesh, renderer, scene, camera, geo, mat, grp) {\n const info = renderer.info\n if (!info.autoReset) return original.call(this, renderer, scene, camera, geo, mat, grp)\n const before = { calls: info.render.calls, triangles: info.render.triangles, points: info.render.points, lines: info.render.lines }\n original.call(this, renderer, scene, camera, geo, mat, grp)\n info.render.calls += before.calls\n info.render.triangles += before.triangles\n info.render.points += before.points\n info.render.lines += before.lines\n }\n }\n reflector.visible = false\n const s: Slot = { reflector, id: null }\n slots.push(s)\n return s\n }\n\n const release = (s: Slot): void => {\n s.id = null\n s.reflector.visible = false\n }\n\n const pos = new THREE.Vector3()\n const quat = new THREE.Quaternion()\n const scl = new THREE.Vector3()\n const n = new THREE.Vector3()\n const toEye = new THREE.Vector3()\n const box = new THREE.Box3()\n const size = new THREE.Vector3()\n const facing = new THREE.Vector3()\n const flip = new THREE.Quaternion(0, 1, 0, 0)\n\n return {\n envMaterial,\n register(id, mesh, normal) {\n const previous = entries.get(id)\n entries.set(id, { mesh, normal: normal ?? null, original: previous ? previous.original : mesh.material })\n mesh.material = envMaterial\n },\n unregister(id) {\n const e = entries.get(id)\n const s = slots.find((x) => x.id === id)\n if (s) release(s)\n if (e) e.mesh.material = e.original\n entries.delete(id)\n },\n update(camera, candidates) {\n const eye = camera.getWorldPosition(toEye)\n const wanted: Array<{ id: string; d: number }> = []\n for (const c of candidates) {\n const e = entries.get(c.id)\n if (!e) continue\n n.set(c.normal[0], c.normal[1], c.normal[2])\n const dx = eye.x - c.center[0]\n const dy = eye.y - c.center[1]\n const dz = eye.z - c.center[2]\n if (n.x * dx + n.y * dy + n.z * dz <= 0) continue\n wanted.push({ id: c.id, d: dx * dx + dy * dy + dz * dz })\n }\n wanted.sort((a, b) => a.d - b.d)\n const chosen = new Set<string>()\n for (let i = 0; i < wanted.length && chosen.size < max; i++) chosen.add(wanted[i].id)\n for (const s of slots) if (s.id !== null && !chosen.has(s.id)) release(s)\n for (const id of chosen) {\n const s = slotFor(id)\n if (!s) continue\n const e = entries.get(id)!\n e.mesh.updateWorldMatrix(true, false)\n e.mesh.matrixWorld.decompose(pos, quat, scl)\n if (!e.mesh.geometry.boundingBox) e.mesh.geometry.computeBoundingBox()\n box.copy(e.mesh.geometry.boundingBox!)\n box.getSize(size)\n worldNormal(e, n)\n s.reflector.position.copy(pos).addScaledVector(n, offset)\n s.reflector.quaternion.copy(quat)\n // a Reflector only renders for a camera in front of its +z: when the registered normal points the other way, turn it around\n if (facing.set(0, 0, 1).applyQuaternion(quat).dot(n) < 0) s.reflector.quaternion.multiply(flip)\n s.reflector.scale.set(Math.max(size.x * scl.x, 1e-3), Math.max(size.y * scl.y, 1e-3), 1)\n s.id = id\n s.reflector.visible = true\n if (!s.reflector.parent) {\n let top: ThreeNS.Object3D = e.mesh\n while (top.parent) top = top.parent\n ;(options.scene ?? top).add(s.reflector)\n }\n }\n return slots.filter((s) => s.id !== null).map((s) => s.id as string)\n },\n active() {\n return slots.filter((s) => s.id !== null).map((s) => s.id as string)\n },\n dispose() {\n for (const s of slots) s.reflector.removeFromParent()\n slots.length = 0\n for (const e of entries.values()) e.mesh.material = e.original\n entries.clear()\n envMaterial.dispose()\n geometry.dispose()\n },\n }\n}\n","import type { CanvasFactory, ThreeLib, ThreeNS } from './types'\n\nexport interface ScreenOptions {\n /** Where the canvas is created (the global `document`, or a fake). */\n document: CanvasFactory\n /** Canvas size in pixels. Default 128 x 72. */\n w?: number\n h?: number\n /** Seed of the static noise. Default 1. */\n seed?: number\n /** Redraws per second while on. Default 15. */\n fps?: number\n /** Emissive strength while on. Default 1. */\n intensity?: number\n}\n\nexport interface Screen {\n material: ThreeNS.MeshStandardMaterial\n texture: ThreeNS.CanvasTexture\n canvas: HTMLCanvasElement\n readonly on: boolean\n readonly channel: number\n setOn(on: boolean): void\n setChannel(channel: number): void\n /** Advance the animation; redraws the canvas at `fps` while on. */\n update(dt: number): void\n dispose(): void\n}\n\nconst BARS = ['#c0c0c0', '#c0c000', '#00c0c0', '#00c000', '#c000c0', '#c00000', '#0000c0']\n\nfunction mulberry(seed: number): () => number {\n let a = seed >>> 0\n return () => {\n a = (a + 0x6d2b79f5) >>> 0\n let t = a\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\n/**\n * A screen material backed by a canvas texture. Off: black canvas, no emission. On: the channel's content (0 color bars,\n * 1 static noise, 2 animated landscape, higher numbers repeat them with shifted hues) lights the surface.\n */\nexport function createScreen(THREE: ThreeLib, options: ScreenOptions): Screen {\n const w = options.w ?? 128\n const h = options.h ?? 72\n const canvas = options.document.createElement('canvas')\n canvas.width = w\n canvas.height = h\n // the canvas is uploaded to the GPU every redraw: tell the browser so it keeps a CPU-backed canvas (no readback warning)\n const ctx = canvas.getContext('2d', { willReadFrequently: true })\n const rand = mulberry(options.seed ?? 1)\n const period = 1 / Math.max(1, options.fps ?? 15)\n const intensity = options.intensity ?? 1\n\n const texture = new THREE.CanvasTexture(canvas)\n texture.colorSpace = THREE.SRGBColorSpace\n const material = new THREE.MeshStandardMaterial({\n color: 0x050505,\n roughness: 0.25,\n metalness: 0,\n map: texture,\n emissive: 0xffffff,\n emissiveMap: texture,\n emissiveIntensity: 0,\n })\n\n let on = false\n let channel = 0\n let clock = 0\n let acc = 0\n\n const fill = (style: string, x: number, y: number, rw: number, rh: number): void => {\n if (!ctx) return\n ctx.fillStyle = style\n ctx.fillRect(x, y, rw, rh)\n }\n\n const drawBars = (): void => {\n const n = BARS.length\n for (let i = 0; i < n; i++) fill(BARS[(i + channel) % n], Math.floor((i * w) / n), 0, Math.ceil(w / n), Math.floor(h * 0.75))\n fill('#101010', 0, Math.floor(h * 0.75), w, h - Math.floor(h * 0.75))\n const x = ((clock * 20) % (w + 12)) - 12\n fill('#ffffff', x, Math.floor(h * 0.8), 12, Math.floor(h * 0.1))\n }\n\n const drawNoise = (): void => {\n const cell = Math.max(2, Math.floor(w / 48))\n for (let y = 0; y < h; y += cell) {\n for (let x = 0; x < w; x += cell) {\n const g = Math.floor(rand() * 220 + 20)\n fill(`rgb(${g},${g},${g})`, x, y, cell, cell)\n }\n }\n }\n\n const drawScene = (): void => {\n const hue = (channel * 40) % 360\n fill(`hsl(${(200 + hue) % 360},60%,${55 + 10 * Math.sin(clock * 0.3)}%)`, 0, 0, w, Math.floor(h * 0.65))\n fill(`hsl(${(110 + hue) % 360},40%,32%)`, 0, Math.floor(h * 0.65), w, h - Math.floor(h * 0.65))\n const sx = (0.5 + 0.4 * Math.sin(clock * 0.5)) * w\n const sy = (0.3 - 0.15 * Math.cos(clock * 0.5)) * h\n fill('#ffe680', sx - 5, sy - 5, 10, 10)\n const bx = (clock * 25) % (w + 16) - 16\n fill('#e03030', bx, Math.floor(h * 0.7), 16, 10)\n }\n\n const draw = (): void => {\n if (!on) {\n fill('#000000', 0, 0, w, h)\n } else if (channel % 3 === 0) {\n drawBars()\n } else if (channel % 3 === 1) {\n drawNoise()\n } else {\n drawScene()\n }\n texture.needsUpdate = true\n }\n\n const apply = (): void => {\n material.emissiveIntensity = on ? intensity : 0\n material.color.setHex(on ? 0x111111 : 0x000000)\n draw()\n }\n apply()\n\n return {\n material,\n texture,\n canvas,\n get on() {\n return on\n },\n get channel() {\n return channel\n },\n setOn(value) {\n on = !!value\n acc = 0\n apply()\n },\n setChannel(n) {\n channel = Math.max(0, Math.floor(n))\n if (on) draw()\n },\n update(dt) {\n if (!on) return\n clock += dt\n acc += dt\n if (acc >= period) {\n acc %= period\n draw()\n }\n },\n dispose() {\n texture.dispose()\n material.dispose()\n },\n }\n}\n","import type { ThreeLib, ThreeNS } from './types'\n\nexport interface SwayOptions {\n /** Strength of the idle flutter (wind) in meters per meter of hang, 0..1. Default 0.04. */\n amplitude?: number\n /** Local y (geometry space) of the line the cloth hangs from. Default: top of the mesh's bounding box. */\n anchorY?: number\n}\n\nexport interface SwayUniforms {\n time: { value: number }\n ax: { value: number }\n az: { value: number }\n anchorY: { value: number }\n}\n\n/** Shared state of one swaying mesh: the three materials read the same uniforms. */\nexport interface SwayHandle {\n uniforms: SwayUniforms\n /** Sets the swing (radians around x and z) and, optionally, the clock for the idle flutter. */\n set(ax: number, az: number, time?: number): void\n}\n\nconst VERTEX_PATCH = /* glsl */ `\n#include <begin_vertex>\n{\n float swayHang = max(swayAnchorY - position.y, 0.0);\n float swayFlutter = swayAmplitude * sin(swayTime * 1.9 + position.x * 4.0 + position.z * 3.0 + swayHang * 3.0);\n transformed.x += swayHang * (sin(swayAz) + swayFlutter);\n transformed.z += swayHang * (-sin(swayAx) + swayFlutter * 0.6);\n transformed.y += swayHang * (1.0 - cos(swayAz) * cos(swayAx));\n}\n`\n\nconst VERTEX_UNIFORMS = /* glsl */ `\nuniform float swayTime;\nuniform float swayAx;\nuniform float swayAz;\nuniform float swayAnchorY;\nuniform float swayAmplitude;\n`\n\n/** Patches a vertex shader so the vertices hang from the anchor line and swing with the shared uniforms. */\nexport function patchSwayShader(shader: { uniforms: Record<string, ThreeNS.IUniform>; vertexShader: string }, uniforms: SwayUniforms, amplitude: number): void {\n shader.uniforms.swayTime = uniforms.time\n shader.uniforms.swayAx = uniforms.ax\n shader.uniforms.swayAz = uniforms.az\n shader.uniforms.swayAnchorY = uniforms.anchorY\n shader.uniforms.swayAmplitude = { value: amplitude }\n shader.vertexShader = VERTEX_UNIFORMS + shader.vertexShader.replace('#include <begin_vertex>', VERTEX_PATCH)\n}\n\nfunction patch<M extends ThreeNS.Material>(material: M, uniforms: SwayUniforms, amplitude: number): M {\n const previous = material.onBeforeCompile\n material.onBeforeCompile = (shader, renderer) => {\n previous?.call(material, shader, renderer)\n patchSwayShader(shader, uniforms, amplitude)\n }\n material.customProgramCacheKey = () => `sway:${amplitude}`\n return material\n}\n\n/**\n * Clones `base` and patches it with a vertex-shader sway (uniforms `time`, `ax`, `az`, `anchorY`). The returned material carries\n * `userData.sway` (a `SwayHandle`), `customDepthMaterial` and `customDistanceMaterial` patched with the same uniforms, so\n * directional / spot shadow maps and point-light shadow cubes follow the animation. Assign it to a mesh, and set\n * `mesh.customDepthMaterial` / `mesh.customDistanceMaterial` from the material (or just use `attachSway`).\n */\n/** A material `swayMaterial` made: it carries its sway handle and the shadow materials that follow it. */\nexport type SwayMaterial = ThreeNS.Material & {\n userData: { sway: SwayHandle; depthMaterial: ThreeNS.MeshDepthMaterial; distanceMaterial: ThreeNS.MeshDistanceMaterial }\n}\n\nexport function swayMaterial(THREE: ThreeLib, base: ThreeNS.Material, options: SwayOptions = {}): SwayMaterial {\n const amplitude = options.amplitude ?? 0.04\n const uniforms: SwayUniforms = { time: { value: 0 }, ax: { value: 0 }, az: { value: 0 }, anchorY: { value: options.anchorY ?? 0 } }\n const handle: SwayHandle = {\n uniforms,\n set(ax, az, time) {\n uniforms.ax.value = ax\n uniforms.az.value = az\n if (time !== undefined) uniforms.time.value = time\n },\n }\n const material = patch(base.clone(), uniforms, amplitude)\n const depth = patch(new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }), uniforms, amplitude)\n const distance = patch(new THREE.MeshDistanceMaterial(), uniforms, amplitude)\n material.userData.sway = handle\n material.userData.depthMaterial = depth\n material.userData.distanceMaterial = distance\n return material as SwayMaterial // userData filled just above\n}\n\n/**\n * Makes a mesh sway: replaces its material with `swayMaterial(...)` and sets `customDepthMaterial` and `customDistanceMaterial`.\n * `mesh.userData.sway` is the handle `syncObject` drives. Returns the handle.\n */\nexport function attachSway(THREE: ThreeLib, mesh: ThreeNS.Mesh, options: SwayOptions = {}): SwayHandle {\n let anchorY = options.anchorY\n if (anchorY === undefined) {\n if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox()\n anchorY = mesh.geometry.boundingBox ? mesh.geometry.boundingBox.max.y : 0\n }\n const base = Array.isArray(mesh.material) ? mesh.material[0] : mesh.material\n const m = swayMaterial(THREE, base, { ...options, anchorY })\n m.userData.sway.uniforms.anchorY.value = anchorY\n mesh.material = m\n mesh.customDepthMaterial = m.userData.depthMaterial\n mesh.customDistanceMaterial = m.userData.distanceMaterial\n mesh.userData.sway = m.userData.sway\n return m.userData.sway\n}\n","import type { ItemStack, PartSpec, World } from '@adatechnology/game-interactables'\nimport { discardObject3D } from '@adatechnology/game-shapes-three'\n\nimport { applyPose } from './pose'\nimport type { ThreeLib, ThreeNS } from './types'\n\n/** Draws one stack as the real item with the host's `THREE`: origin at the bottom centre, y up, metres (`createContainedItemModel` of `game-items-three`). Null draws nothing. */\nexport type ContentsItemBuilder = (stack: ItemStack, THREE: ThreeLib) => ThreeNS.Object3D | null\n\nexport interface ContentsViewOptions {\n world: World\n objectId: string\n /** The object's group, in the object-local frame (the `group` of `createMeshApi().finish`). The contents hang under it. */\n root: ThreeNS.Object3D\n /** The real model of each stack; the host injects it (the items catalogue's renderer), so this package never draws a stand-in. */\n buildItem: ContentsItemBuilder\n}\n\n/** One drawn stack. */\nexport interface ContentsViewItem {\n readonly container: string\n readonly slot: number\n readonly type: string\n readonly object: ThreeNS.Object3D\n}\n\n/** The items in an object's containers, drawn and moving with the part their slot rides on. */\nexport interface ContentsView {\n /** The group under `root` that holds every item. */\n readonly group: ThreeNS.Group\n /**\n * Brings the drawing in line with the world: draws the stacks that arrived, discards the ones taken, poses each slot's part at its current t and shows a\n * container from the first instant its access part leaves 0 (closed, it is hidden). Call it when the object is built and on every frame one of its parts moves.\n */\n sync(): void\n items(): ContentsViewItem[]\n /** Discards every item (`discardObject3D`) and the group. */\n dispose(): void\n}\n\ninterface Drawn {\n type: string\n object: ThreeNS.Object3D\n}\n\n/**\n * The contents of an object's containers as real items. Each slot on a part (a drawer, a door shelf) hangs under a carrier posed with the engine's own pose of\n * that part, so the items slide or swing with it from the first frame of the motion and `world.slotPosition` always agrees; nothing is built when the motion ends.\n */\nexport function createContentsView(THREE: ThreeLib, options: ContentsViewOptions): ContentsView {\n const { world, objectId, root, buildItem } = options\n const group = new THREE.Group()\n group.name = `contents:${objectId}`\n root.add(group)\n const carriers = new Map<string, ThreeNS.Group>()\n const drawn = new Map<string, Drawn>()\n const spec = world.get(objectId)?.spec\n const partsById = new Map<string, PartSpec>((spec?.parts ?? []).map((p) => [p.id, p]))\n\n const carrierOf = (partId: string | undefined): ThreeNS.Object3D => {\n const part = partId === undefined ? undefined : partsById.get(partId)\n if (!part) return group\n let carrier = carriers.get(part.id)\n if (!carrier) {\n carrier = new THREE.Group()\n carrier.name = `contents:${part.id}`\n carrier.position.set(part.pivot[0], part.pivot[1], part.pivot[2])\n carrier.rotation.set(0, part.ry ?? 0, 0)\n group.add(carrier)\n carriers.set(part.id, carrier)\n }\n return carrier\n }\n\n const place = (object: ThreeNS.Object3D, carrier: ThreeNS.Object3D, pos: readonly [number, number, number], part: PartSpec | undefined): void => {\n carrier.add(object)\n if (!part) {\n object.position.set(pos[0], pos[1], pos[2])\n return\n }\n // object-local point at rest -> the carrier's rest frame (pivot at the origin, turned by ry)\n const ry = part.ry ?? 0\n const x = pos[0] - part.pivot[0]\n const z = pos[2] - part.pivot[2]\n const c = Math.cos(ry)\n const s = Math.sin(ry)\n object.position.set(c * x - s * z, pos[1] - part.pivot[1], s * x + c * z)\n object.rotation.set(0, -ry, 0)\n }\n\n function sync(): void {\n const live = new Set<string>()\n for (const c of spec?.containers ?? []) {\n const shown = c.access === undefined || world.partT(objectId, c.access) > 0\n const stacks = world.contents(objectId, c.id)\n c.slots.forEach((slot, i) => {\n const stack = stacks[i]\n const key = `${c.id}#${i}`\n const had = drawn.get(key)\n if (had && (!stack || stack.type !== had.type)) {\n discardObject3D(had.object)\n drawn.delete(key)\n }\n if (!stack) return\n live.add(key)\n let now = drawn.get(key)\n if (!now) {\n const object = buildItem(stack, THREE)\n if (!object) return\n object.name = `contents_${c.id}_${i}`\n object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty }\n place(object, carrierOf(slot.part), slot.pos, slot.part === undefined ? undefined : partsById.get(slot.part))\n now = { type: stack.type, object }\n drawn.set(key, now)\n }\n now.object.visible = shown\n })\n }\n for (const [key, d] of drawn) {\n if (live.has(key)) continue\n discardObject3D(d.object)\n drawn.delete(key)\n }\n for (const [partId, carrier] of carriers) {\n const part = partsById.get(partId)\n if (part) applyPose(THREE, carrier, part.motion, world.partT(objectId, partId))\n }\n }\n\n return {\n group,\n sync,\n items: () =>\n [...drawn].map(([key, d]) => {\n const cut = key.lastIndexOf('#')\n return { container: key.slice(0, cut), slot: Number(key.slice(cut + 1)), type: d.type, object: d.object }\n }),\n dispose() {\n discardObject3D(group)\n drawn.clear()\n carriers.clear()\n },\n }\n}\n","/** @deprecated import `catenary` and `createCord` from '@adatechnology/game-shapes-three' */\nexport { catenary, createCord } from '@adatechnology/game-shapes-three'\n","// The wires of an object (conduit runs, cables, cords, drops: `ObjectSpec.wires`) as thin tubes. The kit's builders leave them to the host (\"the host draws them\n// as thin tubes\"); a house folds them into its own batches, any other host takes these meshes.\nimport { createCord } from '@adatechnology/game-shapes-three'\nimport type { ObjectSpec } from '@adatechnology/game-interactables'\n\nimport type { ThreeLib, ThreeNS } from './types'\n\ntype Wire = NonNullable<ObjectSpec['wires']>[number]\n\n/** The colour each kind of wire is drawn in (a grey PVC conduit, a black cable, a dark cord). */\nexport const WIRE_COLORS: Readonly<Record<Wire['kind'], number>> = { conduit: 0xcfcdc4, cable: 0x2a2724, drop: 0x151515, cord: 0x1b1b1d }\n/** Radius a wire is drawn with when its spec gives none, metres. */\nexport const WIRE_RADIUS = 0.006\n\n/** One tube per wire with two points or more, named by the wire's id, in the object's own space. */\nexport function wireMeshes(THREE: ThreeLib, wires: ObjectSpec['wires']): ThreeNS.Mesh[] {\n const meshes: ThreeNS.Mesh[] = []\n for (const wire of wires ?? []) {\n if (wire.points.length < 2) continue\n const material = new THREE.MeshStandardMaterial({ color: WIRE_COLORS[wire.kind], roughness: 0.8 })\n const mesh = createCord(THREE, wire.points, wire.radius ?? WIR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;AACjG,UAAM,OAAOA,YAAW,OAAO,KAAK,QAAQ,KAAK,UAAU,aAAa,QAAQ;AAChF,SAAK,OAAO,KAAK;AACjB,WAAO,KAAK,IAAI;AAAA,EAClB;AACA,SAAO;AACT;","names":["tex","a","b","n","markKitOrigin","patch","side","markKitOrigin","s","mulberry","channel","apply","catenary","createCord","createCord"]}
|