@adatechnology/game-interactables-three 0.1.5 → 0.1.7
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/README.md +3 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.global.js +2337 -225
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +62 -173
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/effects.ts","../src/cord.ts","../src/types.ts","../src/pose.ts","../src/merge.ts","../src/mesh.ts","../src/mirrors.ts","../src/screen.ts","../src/sway.ts","../src/adapter.ts"],"sourcesContent":["import type { ActiveEmitter, EmitterKind } from '@adatechnology/game-interactables'\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\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 = 'smoke' | 'steam' | 'fire' | 'water' | 'spark'\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 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 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 wide = size >= 0.1\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 = arc.r1 * Math.sqrt(rand())\n const sp = (wide ? 0.5 : 0.25) + rand() * 0.7\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.005, ez + Math.sin(a) * r, Math.cos(a) * sp, 0.9 + rand() * 1.3, 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 = arc.r1 * 1.4 * Math.sqrt(rand())\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.02, ez + Math.sin(a) * r, Math.cos(a) * 0.15, 0.18 + rand() * 0.15, Math.sin(a) * 0.15, 0.7 + rand() * 0.5, 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","import type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/**\n * Points of a hanging cord between `a` and `b` (n points including both ends, n >= 2). The deepest point sits `sag` meters below\n * the straight line between the ends, on a real catenary (y = a cosh(x/a)); when the ends differ in height the curve is\n * measured against the straight line between them.\n */\nexport function catenary(a: Vec3, b: Vec3, sag: number, n = 12): Vec3[] {\n const count = Math.max(2, Math.floor(n))\n const span = Math.hypot(b[0] - a[0], b[2] - a[2]) || Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2])\n const depth = Math.max(0, sag)\n const out: Vec3[] = []\n // Solve depth = c (cosh(span / 2c) - 1) for c by bisection (depth grows as c shrinks).\n let shape: (s: number) => number = () => 0\n if (depth > 1e-6 && span > 1e-6) {\n let lo = 1e-4\n let hi = span * 1000\n for (let i = 0; i < 80; i++) {\n const c = (lo + hi) / 2\n const d = c * (Math.cosh(span / (2 * c)) - 1)\n if (d > depth) lo = c\n else hi = c\n }\n const c = (lo + hi) / 2\n shape = (s) => c * (Math.cosh(((s - 0.5) * span) / c) - Math.cosh(span / (2 * c)))\n }\n for (let i = 0; i < count; i++) {\n const s = i / (count - 1)\n out.push([a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s + shape(s), a[2] + (b[2] - a[2]) * s])\n }\n return out\n}\n\n/** A thin tube through `points` (Catmull-Rom smoothed) for wires, cords and conduits. */\nexport function createCord(THREE: ThreeLib, points: readonly Vec3[], radius: number, material: ThreeNS.Material, radialSegments = 5): ThreeNS.Mesh {\n if (points.length < 2) throw new Error('createCord needs at least two points')\n const curve = new THREE.CatmullRomCurve3(points.map((p) => new THREE.Vector3(p[0], p[1], p[2])), false, 'centripetal')\n const segments = Math.max(4, (points.length - 1) * 4)\n const mesh = new THREE.Mesh(new THREE.TubeGeometry(curve, segments, radius, radialSegments, false), material)\n mesh.name = 'cord'\n mesh.castShadow = true\n return mesh\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'): any\n}\n","import { poseOf as enginePoseOf } from '@adatechnology/game-interactables'\nimport type { Motion, World } from '@adatechnology/game-interactables'\nimport type { ThreeLib, 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: { position: any; quaternion: any; scale: any; userData: Record<string, any> }): 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 { 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, any>; 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, any>; 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}\n\n/** Concatenates pieces (positions and normals moved by their matrices) into one geometry with the extra attributes. */\nfunction concat(THREE: ThreeLib, pieces: 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\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) })\n }\n }\n return map\n }\n const finishMesh = (name: string, key: string, geometry: ThreeNS.BufferGeometry, template: ThreeNS.Mesh, set: ReturnType<typeof patchedSet>, group: ThreeNS.Group): void => {\n const mesh = new THREE.Mesh(geometry, set.material)\n mesh.name = `${name}:${key}`\n mesh.userData.material = key\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, any>; 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, concat(THREE, 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, any>; 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, concat(THREE, 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 { ObjectSpec } from '@adatechnology/game-interactables'\nimport type { CylinderShape, PropItem, Uv } from '@adatechnology/game-props3d'\nimport type { HouseholdApi, MaterialKey, Quality, ThreeLib, ThreeNS, Vec3 } from './types'\nimport { MATERIAL_KEYS } from './types'\nimport { mergeParts } from './merge'\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 /** 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\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). */\n lights: ThreeNS.Light[]\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/** Growing arrays for one (target, material) pair. */\ninterface Acc {\n pos: number[]\n nor: number[]\n col: number[]\n uv: number[]\n idx: number[]\n}\n\ninterface Target {\n id: string | null\n pivot: Vec3\n ry: number\n acc: Map<string, Acc>\n lights: Array<{ x: number; y: number; z: number; color: number; range: number }>\n}\n\ninterface Template {\n pos: Float32Array\n nor: Float32Array\n uv: Float32Array\n idx: ArrayLike<number>\n}\n\nconst IDENT_UV: Uv = { u0: 0, v0: 0, u1: 1, v1: 1 }\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 */\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\n const root: Target = { id: null, pivot: [0, 0, 0], ry: 0, acc: new Map(), lights: [] }\n const partTargets = new Map<string, Target>()\n const stack: Target[] = []\n let current = root\n let finished = false\n\n const templates = new Map<string, Template>()\n const template = (key: string, make: () => ThreeNS.BufferGeometry): Template => {\n let t = templates.get(key)\n if (!t) {\n const g = make()\n t = {\n pos: g.getAttribute('position').array as Float32Array,\n nor: g.getAttribute('normal').array as Float32Array,\n uv: g.getAttribute('uv').array as Float32Array,\n idx: g.index ? (g.index.array as ArrayLike<number>) : Array.from({ length: g.getAttribute('position').count }, (_, i) => i),\n }\n templates.set(key, t)\n }\n return t\n }\n const segs = quality === 'high' ? { cyl: 12, sphereW: 12, sphereH: 8 } : { cyl: 8, sphereW: 8, sphereH: 6 }\n const tBox = () => template('box', () => new THREE.BoxGeometry(1, 1, 1))\n const tCyl = (shape: CylinderShape | undefined) => {\n switch (shape) {\n case 'cyl6':\n return template('cyl6', () => new THREE.CylinderGeometry(1, 1, 1, 6))\n case 'cone':\n return template('cone', () => new THREE.CylinderGeometry(0, 1, 1, segs.cyl))\n case 'sphere':\n return template('sphere', () => new THREE.SphereGeometry(1, segs.sphereW, segs.sphereH))\n default:\n return template('cyl', () => new THREE.CylinderGeometry(1, 1, 1, segs.cyl))\n }\n }\n const tPlane = () => template('plane', () => new THREE.PlaneGeometry(1, 1))\n const tLeaf = (): Template => {\n let t = templates.get('leaf')\n if (!t) {\n // diamond in the xy plane, base at the origin, tip at +y; both faces\n const f = [0, 0, 0, -0.5, 0.4, 0, 0.5, 0.4, 0, 0, 1, 0]\n const pos: number[] = []\n const nor: number[] = []\n const uv: number[] = []\n const idx: number[] = []\n for (const side of [1, -1]) {\n const base = pos.length / 3\n for (let i = 0; i < 4; i++) {\n pos.push(f[i * 3], f[i * 3 + 1], f[i * 3 + 2])\n nor.push(0, 0, side)\n uv.push(f[i * 3] + 0.5, f[i * 3 + 1])\n }\n if (side === 1) idx.push(base, base + 2, base + 1, base + 1, base + 2, base + 3)\n else idx.push(base, base + 1, base + 2, base + 1, base + 3, base + 2)\n }\n // winding for the front face: counter clockwise seen from +z\n t = { pos: new Float32Array(pos), nor: new Float32Array(nor), uv: new Float32Array(uv), idx }\n templates.set('leaf', t)\n }\n return t\n }\n\n const m4 = new THREE.Matrix4()\n const mItem = new THREE.Matrix4()\n const mTotal = new THREE.Matrix4()\n const n3 = new THREE.Matrix3()\n const v = new THREE.Vector3()\n const quat = new THREE.Quaternion()\n const euler = new THREE.Euler()\n const scl = new THREE.Vector3()\n const color = new THREE.Color()\n\n /** Keys that share a material instance share the geometry too: the first key stands for all of them. */\n const canonical = new Map<MaterialKey, MaterialKey>()\n for (const k of MATERIAL_KEYS) {\n const first = MATERIAL_KEYS.find((o) => materials[o] === materials[k]) ?? k\n canonical.set(k, first)\n }\n const accOf = (requested: MaterialKey): Acc => {\n const key = canonical.get(requested) ?? requested\n let a = current.acc.get(key)\n if (!a) {\n a = { pos: [], nor: [], col: [], uv: [], idx: [] }\n current.acc.set(key, a)\n }\n return a\n }\n\n /**\n * Item transform (M.x, M.z, M.ry). Inside a part the coordinates are already relative to the pivot (the `HouseholdApi.part`\n * contract: the pack draws in the part frame), so nothing else is applied: the part group supplies pivot and `ry`.\n */\n const frame = (M: PropItem | undefined): ThreeNS.Matrix4 => {\n mItem.makeRotationY(M?.ry ?? 0)\n mItem.setPosition(M?.x ?? 0, 0, M?.z ?? 0)\n return mItem\n }\n\n const emit = (requested: MaterialKey, M: PropItem | undefined, local: ThreeNS.Matrix4, t: Template, hexColor: number, uv?: Uv): void => {\n const key: MaterialKey = requested in materials ? requested : 'plain'\n const a = accOf(key)\n const total = mTotal.copy(frame(M)).multiply(local)\n n3.getNormalMatrix(total)\n const base = a.pos.length / 3\n color.setHex(hexColor)\n const count = t.pos.length / 3\n const e = total.elements\n const nm = n3.elements\n const u = uv ?? IDENT_UV\n for (let i = 0; i < count; i++) {\n const x = t.pos[i * 3]\n const y = t.pos[i * 3 + 1]\n const z = t.pos[i * 3 + 2]\n a.pos.push(e[0] * x + e[4] * y + e[8] * z + e[12], e[1] * x + e[5] * y + e[9] * z + e[13], e[2] * x + e[6] * y + e[10] * z + e[14])\n const nx = t.nor[i * 3]\n const ny = t.nor[i * 3 + 1]\n const nz = t.nor[i * 3 + 2]\n v.set(nm[0] * nx + nm[3] * ny + nm[6] * nz, nm[1] * nx + nm[4] * ny + nm[7] * nz, nm[2] * nx + nm[5] * ny + nm[8] * nz).normalize()\n a.nor.push(v.x, v.y, v.z)\n a.col.push(color.r, color.g, color.b)\n a.uv.push(u.u0 + t.uv[i * 2] * (u.u1 - u.u0), u.v0 + t.uv[i * 2 + 1] * (u.v1 - u.v0))\n }\n for (let i = 0; i < t.idx.length; i++) a.idx.push(base + t.idx[i])\n }\n\n const compose = (x: number, y: number, z: number, rx: number, ry: number, rz: number, sx: number, sy: number, sz: number): ThreeNS.Matrix4 => {\n euler.set(rx, ry, rz, 'YXZ')\n quat.setFromEuler(euler)\n return m4.compose(v.set(x, y, z), quat, scl.set(sx, sy, sz))\n }\n\n const api: HouseholdApi = {\n box(M, material, x, y, z, w, h, d, col, ry, rx, rz) {\n emit(material as MaterialKey, M, compose(x, y + h / 2, z, rx, ry, rz, w, h, d), tBox(), col)\n },\n cylinder(M, material, x, y, z, r, h, col, rx, rz, shape) {\n const tilted = rx !== 0 || rz !== 0\n const cy = shape === 'sphere' ? y + h / 2 : tilted ? y : y + h / 2\n const sy = shape === 'sphere' ? h / 2 : h\n emit(material as MaterialKey, M, compose(x, cy, z, rx, 0, rz, r, sy, r), tCyl(shape), col)\n },\n leaf(M, x, y, z, w, h, col, ry, rx) {\n emit('plant', M, compose(x, y, z, rx, ry, 0, w, h, 1), tLeaf(), col)\n },\n plane(M, material, x, y, z, w, h, col, ry, rx, rz, uv) {\n emit(material as MaterialKey, M, compose(x, y, z, rx, ry, rz, w, h, 1), tPlane(), col, uv)\n },\n light(M, x, y, z, col, range) {\n const fr = frame(M)\n v.set(x, y, z).applyMatrix4(fr)\n current.lights.push({ x: v.x, y: v.y, z: v.z, color: col, range })\n },\n part(id, pivot, ry, draw) {\n let target = partTargets.get(id)\n if (!target) {\n target = { id, pivot: [pivot[0], pivot[1], pivot[2]], ry, acc: new Map(), lights: [] }\n partTargets.set(id, target)\n }\n stack.push(current)\n current = target\n try {\n draw()\n } finally {\n current = stack.pop() ?? root\n }\n },\n }\n\n const build = (target: Target, into: ThreeNS.Group, materialFor: MeshApiOptions['materialFor']): void => {\n for (const [key, a] of target.acc) {\n if (!a.idx.length) continue\n const g = new THREE.BufferGeometry()\n g.setAttribute('position', new THREE.Float32BufferAttribute(a.pos, 3))\n g.setAttribute('normal', new THREE.Float32BufferAttribute(a.nor, 3))\n g.setAttribute('color', new THREE.Float32BufferAttribute(a.col, 3))\n g.setAttribute('uv', new THREE.Float32BufferAttribute(a.uv, 2))\n g.setIndex(a.pos.length / 3 > 65535 ? new THREE.Uint32BufferAttribute(a.idx, 1) : new THREE.Uint16BufferAttribute(a.idx, 1))\n g.computeBoundingSphere()\n g.computeBoundingBox()\n const mesh = new THREE.Mesh(g, materialFor?.(key as MaterialKey, target.id) ?? materials[key as MaterialKey])\n mesh.name = target.id === null ? `static:${key}` : `part:${target.id}`\n if (target.id !== null) mesh.userData.part = target.id\n mesh.userData.material = key\n mesh.castShadow = shadows\n mesh.receiveShadow = shadows\n into.add(mesh)\n }\n for (const l of target.lights) {\n const light = new THREE.PointLight(l.color, 1, l.range)\n light.position.set(l.x, l.y, l.z)\n into.add(light)\n lightsOut.push(light)\n }\n }\n\n const lightsOut: ThreeNS.Light[] = []\n\n return {\n 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 group = new THREE.Group()\n group.name = 'interactable'\n const parts: Record<string, ThreeNS.Group> = {}\n build(root, group, materialFor)\n for (const [id, target] of partTargets) {\n const g = new THREE.Group()\n g.name = `part:${id}`\n g.userData.part = id\n g.position.set(target.pivot[0], target.pivot[1], target.pivot[2])\n g.rotation.y = target.ry\n g.updateMatrix()\n build(target, g, materialFor)\n rememberRest(g)\n group.add(g)\n parts[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 }\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 { 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: any\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, any>; 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 */\nexport function swayMaterial(THREE: ThreeLib, base: ThreeNS.Material, options: SwayOptions = {}): ThreeNS.Material & {\n userData: { sway: SwayHandle; depthMaterial: ThreeNS.MeshDepthMaterial; distanceMaterial: ThreeNS.MeshDistanceMaterial }\n} {\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 any\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 { Motion, World } from '@adatechnology/game-interactables'\nimport { createEffects, type Effects, type EffectsOptions } from './effects'\nimport { createCord, catenary } from './cord'\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}\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, ...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"],"mappings":";AA+DA,IAAM,QAAoB,CAAC,SAAS,SAAS,QAAQ,SAAS,OAAO;AACrE,IAAM,SAAmC,EAAE,OAAO,MAAM,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,OAAO,IAAI;AAuBxG,IAAM;AAAA;AAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAexB,IAAM;AAAA;AAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUxB,SAAS,SAAS,MAA4B;AAC5C,MAAI,IAAI,SAAS;AACjB,SAAO,MAAM;AACX,QAAK,IAAI,eAAgB;AACzB,QAAI,IAAI;AACR,QAAI,KAAK,KAAK,IAAK,MAAM,IAAK,IAAI,CAAC;AACnC,SAAK,IAAI,KAAK,KAAK,IAAK,MAAM,GAAI,IAAI,EAAE;AACxC,aAAS,IAAK,MAAM,QAAS,KAAK;AAAA,EACpC;AACF;AAGA,SAAS,WAAW,OAAiB,KAAiD;AACpF,QAAM,IAAI;AACV,MAAI;AACF,UAAM,SAAS,KAA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.ts","../src/merge.ts","../src/mirrors.ts","../src/screen.ts","../src/sway.ts","../src/adapter.ts"],"sourcesContent":["import type { ActiveEmitter, EmitterKind } from '@adatechnology/game-interactables'\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\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 = 'smoke' | 'steam' | 'fire' | 'water' | 'spark'\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 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 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 wide = size >= 0.1\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 = arc.r1 * Math.sqrt(rand())\n const sp = (wide ? 0.5 : 0.25) + rand() * 0.7\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.005, ez + Math.sin(a) * r, Math.cos(a) * sp, 0.9 + rand() * 1.3, 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 = arc.r1 * 1.4 * Math.sqrt(rand())\n spawn(pools.water, ex + Math.cos(a) * r, arc.stopY + 0.02, ez + Math.sin(a) * r, Math.cos(a) * 0.15, 0.18 + rand() * 0.15, Math.sin(a) * 0.15, 0.7 + rand() * 0.5, 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","import type { ThreeLib, ThreeNS, Vec3 } from './types'\n\n/**\n * Points of a hanging cord between `a` and `b` (n points including both ends, n >= 2). The deepest point sits `sag` meters below\n * the straight line between the ends, on a real catenary (y = a cosh(x/a)); when the ends differ in height the curve is\n * measured against the straight line between them.\n */\nexport function catenary(a: Vec3, b: Vec3, sag: number, n = 12): Vec3[] {\n const count = Math.max(2, Math.floor(n))\n const span = Math.hypot(b[0] - a[0], b[2] - a[2]) || Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2])\n const depth = Math.max(0, sag)\n const out: Vec3[] = []\n // Solve depth = c (cosh(span / 2c) - 1) for c by bisection (depth grows as c shrinks).\n let shape: (s: number) => number = () => 0\n if (depth > 1e-6 && span > 1e-6) {\n let lo = 1e-4\n let hi = span * 1000\n for (let i = 0; i < 80; i++) {\n const c = (lo + hi) / 2\n const d = c * (Math.cosh(span / (2 * c)) - 1)\n if (d > depth) lo = c\n else hi = c\n }\n const c = (lo + hi) / 2\n shape = (s) => c * (Math.cosh(((s - 0.5) * span) / c) - Math.cosh(span / (2 * c)))\n }\n for (let i = 0; i < count; i++) {\n const s = i / (count - 1)\n out.push([a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s + shape(s), a[2] + (b[2] - a[2]) * s])\n }\n return out\n}\n\n/** A thin tube through `points` (Catmull-Rom smoothed) for wires, cords and conduits. */\nexport function createCord(THREE: ThreeLib, points: readonly Vec3[], radius: number, material: ThreeNS.Material, radialSegments = 5): ThreeNS.Mesh {\n if (points.length < 2) throw new Error('createCord needs at least two points')\n const curve = new THREE.CatmullRomCurve3(points.map((p) => new THREE.Vector3(p[0], p[1], p[2])), false, 'centripetal')\n const segments = Math.max(4, (points.length - 1) * 4)\n const mesh = new THREE.Mesh(new THREE.TubeGeometry(curve, segments, radius, radialSegments, false), material)\n mesh.name = 'cord'\n mesh.castShadow = true\n return mesh\n}\n","import 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 { 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 /** 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\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). */\n lights: ThreeNS.Light[]\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\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 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 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(recorder.schema(), {\n colors: colorSpaceOf(THREE),\n materials: MATERIAL_KEYS,\n fallbackMaterial: 'plain',\n materialAlias,\n validate: false,\n key: false,\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 = new THREE.Group()\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 }\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'): any\n}\n","import { poseOf as enginePoseOf } from '@adatechnology/game-interactables'\nimport type { Motion, World } from '@adatechnology/game-interactables'\nimport type { ThreeLib, 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: { position: any; quaternion: any; scale: any; userData: Record<string, any> }): 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 { 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, any>; 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, any>; 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}\n\n/** Concatenates pieces (positions and normals moved by their matrices) into one geometry with the extra attributes. */\nfunction concat(THREE: ThreeLib, pieces: 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\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) })\n }\n }\n return map\n }\n const finishMesh = (name: string, key: string, geometry: ThreeNS.BufferGeometry, template: ThreeNS.Mesh, set: ReturnType<typeof patchedSet>, group: ThreeNS.Group): void => {\n const mesh = new THREE.Mesh(geometry, set.material)\n mesh.name = `${name}:${key}`\n mesh.userData.material = key\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, any>; 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, concat(THREE, 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, any>; 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, concat(THREE, 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 { 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: any\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, any>; 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 */\nexport function swayMaterial(THREE: ThreeLib, base: ThreeNS.Material, options: SwayOptions = {}): ThreeNS.Material & {\n userData: { sway: SwayHandle; depthMaterial: ThreeNS.MeshDepthMaterial; distanceMaterial: ThreeNS.MeshDistanceMaterial }\n} {\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 any\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 { Motion, World } from '@adatechnology/game-interactables'\nimport { createEffects, type Effects, type EffectsOptions } from './effects'\nimport { createCord, catenary } from './cord'\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}\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, ...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"],"mappings":";AA+DA,IAAM,QAAoB,CAAC,SAAS,SAAS,QAAQ,SAAS,OAAO;AACrE,IAAM,SAAmC,EAAE,OAAO,MAAM,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,OAAO,IAAI;AAuBxG,IAAM;AAAA;AAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAexB,IAAM;AAAA;AAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUxB,SAAS,SAAS,MAA4B;AAC5C,MAAI,I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