@adatechnology/game-render-three 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/index.d.ts +435 -0
- package/dist/index.js +1284 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lights/slots.ts","../src/lights/arbiter.ts","../src/fog.ts","../src/lights/scene-state.ts","../src/lights/budget.ts","../src/lights/types.ts","../src/lights/guard.ts","../src/program-key.ts","../src/pools/anchors.ts","../src/probes.ts","../src/warmup.ts","../src/pools/pooled.ts","../src/pools/geometry.ts","../src/pools/material.ts","../src/pools/render-pools.ts","../src/frame-pacer.ts","../src/static-batcher.ts"],"sourcesContent":["import type { Group, Object3D, PointLight, SpotLight } from 'three'\n\nimport type { LightKind, LightPatch, LinearRgb, ThreeForLights } from './types'\n\nconst PARKED_Y = -50\nconst DEFAULT_DECAY = 2\nconst DEFAULT_ANGLE = Math.PI / 3\nconst POSITION_EPSILON = 1e-6\n\nexport type Vec3 = [number, number, number]\n\nexport type LightValues = {\n color: number | LinearRgb\n intensity: number\n distance: number\n decay: number\n position: Vec3\n target: Vec3 | undefined\n angle: number\n penumbra: number\n}\n\n/** Whoever owns a slot: a request, a source or a lease. */\nexport interface Holder {\n readonly kind: 'request' | 'source' | 'lease'\n readonly owner: string\n readonly lightKind: LightKind\n priority: number\n urgent: boolean\n values: LightValues\n slot: Slot | null\n alive: boolean\n onLost: (() => void) | undefined\n /** Sources only. */\n follow: Object3D | undefined\n shadow: boolean\n wanted: boolean\n distance: number\n /** Sources only: `values` with the world position and direction of `follow` of this frame. */\n resolved: LightValues\n}\n\nexport interface Slot {\n readonly index: number\n readonly kind: LightKind\n readonly shadow: boolean\n readonly light: PointLight | SpotLight\n holder: Holder | null\n pending: Holder | null\n leased: boolean\n /** 0..1 multiplier on the holder's intensity. */\n fade: number\n fadeTarget: number\n fadeOutMs: number\n baseIntensity: number\n lastPosition: Vec3\n}\n\nexport function createValues(base: Partial<LightValues> & Pick<LightValues, 'color' | 'intensity' | 'distance' | 'position'>): LightValues {\n return {\n decay: DEFAULT_DECAY,\n target: undefined,\n angle: DEFAULT_ANGLE,\n penumbra: 0,\n ...base,\n position: [...base.position],\n }\n}\n\nexport function mergeValues(values: LightValues, patch: LightPatch): void {\n if (patch.color !== undefined) values.color = patch.color\n if (patch.intensity !== undefined) values.intensity = patch.intensity\n if (patch.distance !== undefined) values.distance = patch.distance\n if (patch.decay !== undefined) values.decay = patch.decay\n if (patch.position !== undefined) values.position = [...patch.position]\n if (patch.target !== undefined) values.target = [...patch.target]\n if (patch.angle !== undefined) values.angle = patch.angle\n if (patch.penumbra !== undefined) values.penumbra = patch.penumbra\n}\n\nexport type ShadowSettings = { readonly bias?: number; readonly normalBias?: number; readonly near?: number }\n\nexport function createSlots(THREE: ThreeForLights, group: Group, kind: LightKind, count: number, shadows: number, mapSize: number, settings: ShadowSettings = {}): Slot[] {\n const slots: Slot[] = []\n for (let index = 0; index < count; index++) {\n const light = kind === 'point' ? new THREE.PointLight(0xffffff, 0, 0, DEFAULT_DECAY) : new THREE.SpotLight(0xffffff, 0, 0, DEFAULT_ANGLE, 0, DEFAULT_DECAY)\n light.position.set(0, PARKED_Y, 0)\n light.layers.enableAll()\n const shadow = index < shadows\n if (shadow) {\n light.castShadow = true\n light.shadow.autoUpdate = false\n light.shadow.mapSize.set(mapSize, mapSize)\n if (settings.bias !== undefined) light.shadow.bias = settings.bias\n if (settings.normalBias !== undefined) light.shadow.normalBias = settings.normalBias\n if (settings.near !== undefined) light.shadow.camera.near = settings.near\n }\n group.add(light)\n if ('target' in light) group.add(light.target)\n slots.push({ index, kind, shadow, light, holder: null, pending: null, leased: false, fade: 0, fadeTarget: 0, fadeOutMs: 0, baseIntensity: 0, lastPosition: [0, PARKED_Y, 0] })\n }\n return slots\n}\n\nexport function isFree(slot: Slot): boolean {\n return !slot.leased && slot.holder === null && slot.pending === null\n}\n\nexport function applyIntensity(slot: Slot): void {\n slot.light.intensity = slot.baseIntensity * slot.fade\n}\n\nexport function markShadow(slot: Slot): void {\n if (slot.shadow) slot.light.shadow.needsUpdate = true\n}\n\nexport function writeLight(THREE: ThreeForLights, slot: Slot, values: LightValues): void {\n const { light } = slot\n if (typeof values.color === 'number') light.color.set(values.color)\n else light.color.setRGB(values.color[0], values.color[1], values.color[2], THREE.LinearSRGBColorSpace)\n light.distance = values.distance\n light.decay = values.decay\n const [x, y, z] = values.position\n light.position.set(x, y, z)\n if ('angle' in light) {\n light.angle = values.angle\n light.penumbra = values.penumbra\n const [tx, ty, tz] = values.target ?? [x, y - 1, z]\n light.target.position.set(tx, ty, tz)\n }\n const last = slot.lastPosition\n if (slot.shadow && (Math.abs(last[0] - x) > POSITION_EPSILON || Math.abs(last[1] - y) > POSITION_EPSILON || Math.abs(last[2] - z) > POSITION_EPSILON)) markShadow(slot)\n slot.lastPosition = [x, y, z]\n slot.baseIntensity = values.intensity\n applyIntensity(slot)\n}\n\n/** The holder's writes apply from now on; its light fades in (requests that cut a victim start at full). */\nexport function install(THREE: ThreeForLights, slot: Slot, holder: Holder, startAtFull: boolean): void {\n slot.holder = holder\n slot.pending = null\n slot.fade = startAtFull ? 1 : 0\n slot.fadeTarget = 1\n holder.slot = slot\n markShadow(slot)\n writeLight(THREE, slot, holder.values)\n}\n\n/** Drops the holder: the light keeps its last values and fades to 0 (at once with `fadeOutMs` 0). */\nexport function vacate(slot: Slot, fadeOutMs: number): void {\n slot.holder = null\n slot.fadeTarget = 0\n slot.fadeOutMs = fadeOutMs\n if (fadeOutMs <= 0) {\n slot.fade = 0\n applyIntensity(slot)\n }\n}\n\nexport function stepFade(slot: Slot, dtSeconds: number, fadeInMs: number): void {\n if (slot.fade < slot.fadeTarget) {\n slot.fade = fadeInMs <= 0 ? slot.fadeTarget : Math.min(slot.fadeTarget, slot.fade + (dtSeconds * 1000) / fadeInMs)\n } else if (slot.fade > slot.fadeTarget) {\n slot.fade = slot.fadeOutMs <= 0 ? slot.fadeTarget : Math.max(slot.fadeTarget, slot.fade - (dtSeconds * 1000) / slot.fadeOutMs)\n }\n applyIntensity(slot)\n}\n","import { type Holder, type Slot, install, isFree, stepFade, vacate } from './slots'\nimport type { LightKind, ThreeForLights } from './types'\n\nexport type ArbiterCore = {\n readonly THREE: ThreeForLights\n readonly slots: Record<LightKind, readonly Slot[]>\n readonly urgentReserve: number\n readonly fadeMs: number\n readonly hysteresis: number\n preempted: number\n refused: number\n}\n\n/** The slots requests and sources compete for: not leased, and shadow slots only on their own pass. */\nexport function poolOf(core: ArbiterCore, kind: LightKind, shadow: boolean): Slot[] {\n return core.slots[kind].filter((slot) => !slot.leased && slot.shadow === shadow)\n}\n\nfunction contribution(holder: Holder): number {\n return holder.values.intensity / Math.max(1, holder.distance) ** 2\n}\n\n/** Lowest priority first; on a tie, the smallest perceived contribution. */\nfunction isWeaker(a: Holder, b: Holder): boolean {\n if (a.priority !== b.priority) return a.priority < b.priority\n return contribution(a) < contribution(b)\n}\n\nfunction pickFree(slots: readonly Slot[]): Slot | undefined {\n let best: Slot | undefined\n for (const slot of slots) if (isFree(slot) && (best === undefined || slot.fade < best.fade)) best = slot\n return best\n}\n\n/** Gives a free slot to the holder: at once when its light is dark or the holder is urgent, else after the slot finishes fading out. */\nfunction place(core: ArbiterCore, slot: Slot, holder: Holder): void {\n holder.slot = slot\n if (slot.fade > 0 && !holder.urgent) {\n slot.pending = holder\n slot.fadeTarget = 0\n return\n }\n install(core.THREE, slot, holder, holder.kind === 'request')\n}\n\n/** Takes the slot from its holder; a request is told and dies, a source goes back to the queue. */\nfunction evict(core: ArbiterCore, slot: Slot, challenger: Holder, cut: boolean): void {\n const victim = slot.holder\n if (victim === null) return\n victim.slot = null\n if (victim.kind === 'request') {\n victim.alive = false\n victim.onLost?.()\n }\n core.preempted++\n vacate(slot, cut ? 0 : core.fadeMs)\n if (cut) {\n install(core.THREE, slot, challenger, true)\n return\n }\n slot.pending = challenger\n challenger.slot = slot\n}\n\nfunction weakestHolder(slots: readonly Slot[]): Slot | undefined {\n let weakest: Slot | undefined\n for (const slot of slots) {\n if (slot.holder === null || slot.pending !== null) continue\n if (weakest === undefined || isWeaker(slot.holder, weakest.holder as Holder)) weakest = slot\n }\n return weakest\n}\n\n/** Slots free to a holder that has no right to the urgent reserve. */\nfunction freeBeyondReserve(core: ArbiterCore, pool: readonly Slot[], reserve: number): Slot | undefined {\n const free = pool.filter(isFree)\n return free.length > reserve ? pickFree(pool) : undefined\n}\n\nexport function admitRequest(core: ArbiterCore, holder: Holder): boolean {\n const pool = poolOf(core, holder.lightKind, false)\n const reserve = holder.lightKind === 'point' ? core.urgentReserve : 0\n const free = holder.urgent ? pickFree(pool) : freeBeyondReserve(core, pool, reserve)\n if (free !== undefined) {\n place(core, free, holder)\n return true\n }\n const victim = weakestHolder(pool)\n if (victim === undefined || (victim.holder as Holder).priority >= holder.priority) {\n core.refused++\n return false\n }\n evict(core, victim, holder, holder.urgent)\n return true\n}\n\nfunction beats(challenger: Holder, incumbent: Holder, hysteresis: number): boolean {\n if (challenger.priority !== incumbent.priority) return challenger.priority > incumbent.priority\n return challenger.distance < incumbent.distance * (1 - hysteresis)\n}\n\nfunction bestFirst(a: Holder, b: Holder): number {\n return b.priority - a.priority || a.distance - b.distance\n}\n\n/** Hands the pool's slots to the wanted sources: best first, an incumbent only yields to a clearly better challenger. */\nexport function arbitrateSources(core: ArbiterCore, pool: readonly Slot[], sources: readonly Holder[], reserve: number): void {\n for (const slot of pool) {\n const holder = slot.holder\n if (slot.pending?.kind === 'source' && !slot.pending.wanted) {\n slot.pending.slot = null\n slot.pending = null\n }\n if (holder?.kind === 'source' && !holder.wanted) {\n holder.slot = null\n vacate(slot, core.fadeMs)\n }\n }\n const challengers = sources.filter((source) => source.wanted && source.slot === null).sort(bestFirst)\n for (const challenger of challengers) {\n const free = freeBeyondReserve(core, pool, reserve)\n if (free !== undefined) {\n place(core, free, challenger)\n continue\n }\n const incumbentSlots = pool.filter((slot) => slot.holder?.kind === 'source')\n let worst: Slot | undefined\n for (const slot of incumbentSlots) {\n if (slot.pending !== null) continue\n if (worst === undefined || bestFirst(slot.holder as Holder, worst.holder as Holder) > 0) worst = slot\n }\n if (worst === undefined || !beats(challenger, worst.holder as Holder, core.hysteresis)) break\n evict(core, worst, challenger, false)\n }\n}\n\nexport function stepSlots(core: ArbiterCore, dtSeconds: number): void {\n for (const kind of ['point', 'spot'] as const) {\n for (const slot of core.slots[kind]) {\n stepFade(slot, dtSeconds, core.fadeMs)\n if (slot.pending !== null && slot.fade <= 0) install(core.THREE, slot, slot.pending, false)\n }\n }\n}\n","import type { Fog, FogBase, FogExp2, Scene } from 'three'\n\nimport type { ThreeLib } from './three-lib'\n\n/** Both exact in half precision (multiples of 32 under 65 504), so the neutral fog survives a `mediump` fragment shader. */\nexport const NEUTRAL_FOG_NEAR = 6.0e4\nexport const NEUTRAL_FOG_FAR = 6.4e4\n\nexport interface FogOptions {\n /** `clear()` leaves a neutral linear Fog instead of `null`: the fog presence and type never change, so no program recompiles. */\n readonly stable?: boolean\n /** Colour of the neutral fog. Default 0x000000. */\n readonly color?: number\n}\n\nexport interface FogController {\n useLinear(color: number, near: number, far: number): Fog\n useExp2(color: number, density: number): FogExp2\n /** Back to no fog: the original fog (or `null`); when `stable`, the host's own linear fog or the neutral one, never `null`. */\n clear(): void\n}\n\nfunction isLinearFog(fog: FogBase | null): fog is Fog {\n return (fog as Partial<Fog> | null)?.isFog === true\n}\n\nfunction isExp2Fog(fog: FogBase | null): fog is FogExp2 {\n return (fog as Partial<FogExp2> | null)?.isFogExp2 === true\n}\n\nexport function isNeutralFog(fog: unknown): boolean {\n const candidate = fog as Partial<Fog> | null | undefined\n return candidate?.isFog === true && candidate.near === NEUTRAL_FOG_NEAR && candidate.far === NEUTRAL_FOG_FAR\n}\n\n/** Writes into the scene's existing fog object when its type matches, as the weather layer does, so nothing is reallocated per change. */\nexport function createFog(THREE: Pick<ThreeLib, 'Fog' | 'FogExp2'>, scene: Scene, options: FogOptions = {}): FogController {\n const original = scene.fog\n const hostLinear = isLinearFog(original) ? { color: original.color.getHex(), near: original.near, far: original.far } : undefined\n const resting = hostLinear ?? { color: options.color ?? 0, near: NEUTRAL_FOG_NEAR, far: NEUTRAL_FOG_FAR }\n return {\n useLinear(color, near, far) {\n const current = scene.fog\n if (isLinearFog(current)) {\n current.color.set(color)\n current.near = near\n current.far = far\n return current\n }\n const fog = new THREE.Fog(color, near, far)\n scene.fog = fog\n return fog\n },\n useExp2(color, density) {\n const current = scene.fog\n if (isExp2Fog(current)) {\n current.color.set(color)\n current.density = density\n return current\n }\n const fog = new THREE.FogExp2(color, density)\n scene.fog = fog\n return fog\n },\n clear() {\n if (options.stable !== true) {\n scene.fog = original\n return\n }\n const current = scene.fog\n if (isLinearFog(current)) {\n current.color.set(resting.color)\n current.near = resting.near\n current.far = resting.far\n return\n }\n scene.fog = new THREE.Fog(resting.color, resting.near, resting.far)\n },\n }\n}\n","import type { Object3D, Scene } from 'three'\n\nimport { NEUTRAL_FOG_NEAR } from '../fog'\nimport type { FogState, LightCheck, RendererState, SealOptions } from './types'\n\ntype Flags = Record<string, unknown>\ntype Counter = { count: number; shadows: number }\n\nconst LIGHT_FLAGS = [\n ['point', 'isPointLight'],\n ['spot', 'isSpotLight'],\n ['hemi', 'isHemisphereLight'],\n ['dir', 'isDirectionalLight'],\n ['ambient', 'isAmbientLight'],\n ['rect', 'isRectAreaLight'],\n] as const\n\n/** The visible lights the way the renderer collects them: they decide the shader's light counts. */\nexport function lightSignature(scene: Object3D): string {\n const counters: Record<string, Counter> = {}\n for (const [name] of LIGHT_FLAGS) counters[name] = { count: 0, shadows: 0 }\n scene.traverseVisible((object) => {\n const flags = object as unknown as Flags\n for (const [name, flag] of LIGHT_FLAGS) {\n if (flags[flag] !== true) continue\n const counter = counters[name] as Counter\n counter.count++\n if ((flags as { castShadow?: boolean }).castShadow === true) counter.shadows++\n }\n })\n return LIGHT_FLAGS.map(([name]) => `${name}:${(counters[name] as Counter).count}/${(counters[name] as Counter).shadows}`).join(' ')\n}\n\nexport function fogStateOf(scene: Scene): FogState {\n const fog = scene.fog as Flags | null\n if (fog === null) return 'none'\n return fog.isFogExp2 === true ? 'exp2' : 'linear'\n}\n\n/** Every PointLight/SpotLight under `scene` that is not under `group`, as a path of child indices. */\nexport function findStrays(scene: Object3D, group: Object3D): string[] {\n const strays: string[] = []\n const visit = (object: Object3D, path: string): void => {\n if (object === group) return\n const flags = object as unknown as Flags\n if (flags.isPointLight === true || flags.isSpotLight === true) strays.push(`${path}${object.name === '' ? object.type : object.name}`)\n object.children.forEach((child, index) => visit(child, `${path}${index}/`))\n }\n visit(scene, '')\n return strays\n}\n\nexport type Sealed = {\n readonly lights: string\n readonly environment: string\n readonly toneMapping: number\n readonly outputColorSpace: string\n readonly targetColorSpace: string\n readonly shadowMapType: number\n readonly fogStates: readonly FogState[]\n readonly cameras: SealOptions['cameras']\n readonly target: SealOptions['target']\n}\n\nfunction environmentOf(scene: Scene): string {\n return scene.environment === null ? 'none' : `texture:${scene.environment.mapping}`\n}\n\nfunction targetColorSpaceOf(target: SealOptions['target']): string {\n return target ? target.texture.colorSpace : 'canvas'\n}\n\nexport function captureSealed(renderer: RendererState, scene: Scene, options: SealOptions): Sealed {\n return {\n lights: lightSignature(scene),\n environment: environmentOf(scene),\n toneMapping: renderer.toneMapping,\n outputColorSpace: renderer.outputColorSpace,\n targetColorSpace: targetColorSpaceOf(options.target),\n shadowMapType: renderer.shadowMap.type,\n fogStates: options.fogStates ?? [fogStateOf(scene)],\n cameras: options.cameras,\n target: options.target,\n }\n}\n\ntype Described = {\n readonly lights: string\n readonly fog: string\n readonly environment: string\n readonly toneMapping: number\n readonly outputColorSpace: string\n readonly targetColorSpace: string\n readonly shadowMapType: number\n}\n\nfunction describe(state: Described): string {\n const { lights, fog, environment, toneMapping, outputColorSpace, targetColorSpace, shadowMapType } = state\n return `${lights} | fog:${fog} env:${environment} tone:${toneMapping} out:${outputColorSpace}/${targetColorSpace} shadow:${shadowMapType}`\n}\n\nfunction farBeyondNeutralFog(scene: Scene, sealed: Sealed): boolean {\n const fog = scene.fog as { isFog?: boolean; near?: number } | null\n if (fog?.isFog !== true || fog.near !== NEUTRAL_FOG_NEAR) return false\n return (sealed.cameras ?? []).some((camera) => ((camera as unknown as { far?: number }).far ?? 0) >= NEUTRAL_FOG_NEAR)\n}\n\nexport function checkSealed(sealed: Sealed | null, renderer: RendererState, scene: Scene, group: Object3D): LightCheck {\n const strays = findStrays(scene, group)\n const lights = lightSignature(scene)\n if (sealed === null) return { ok: strays.length === 0, expected: lights, actual: lights, strays }\n const fog = fogStateOf(scene)\n const fogAllowed = sealed.fogStates.includes(fog)\n const expected = describe({ ...sealed, fog: fogAllowed ? fog : sealed.fogStates.join('|') })\n const actual = describe({\n lights,\n fog,\n environment: environmentOf(scene),\n toneMapping: renderer.toneMapping,\n outputColorSpace: renderer.outputColorSpace,\n targetColorSpace: targetColorSpaceOf(sealed.target),\n shadowMapType: renderer.shadowMap.type,\n })\n const ok = strays.length === 0 && expected === actual && !farBeyondNeutralFog(scene, sealed)\n return { ok, expected, actual, strays }\n}\n","import type { HemisphereLight, Object3D, Scene } from 'three'\n\nimport { type ArbiterCore, admitRequest, arbitrateSources, poolOf, stepSlots } from './arbiter'\nimport { type Sealed, captureSealed, checkSealed } from './scene-state'\nimport { type Holder, type Slot, type Vec3, createSlots, createValues, isFree, markShadow, mergeValues, vacate, writeLight } from './slots'\nimport type {\n LightBudget,\n LightBudgetOptions,\n LightHandle,\n LightKind,\n LightLease,\n LightPatch,\n LightRequest,\n LightSource,\n RendererState,\n SourceHandle,\n ThreeForLights,\n} from './types'\n\nconst DEFAULTS = { point: 16, spot: 4, pointShadows: 2, spotShadows: 0, shadowMapSize: 512, urgentReserve: 2, fadeMs: 120, hysteresis: 0.15, hemisphere: 0 }\nconst ZERO: Vec3 = [0, 0, 0]\nconst ALL_LAYERS_MASK = -1\n\nfunction newHolder(kind: Holder['kind'], lightKind: LightKind, request: LightRequest | LightSource, urgent: boolean): Holder {\n return {\n kind,\n owner: request.owner,\n lightKind,\n priority: request.priority,\n urgent,\n values: createValues({ color: request.color, intensity: request.intensity, distance: request.distance, position: [...request.position], ...optional(request) }),\n slot: null,\n alive: true,\n onLost: undefined,\n follow: undefined,\n shadow: false,\n wanted: true,\n distance: 0,\n resolved: createValues({ color: request.color, intensity: 0, distance: 0, position: ZERO }),\n }\n}\n\nfunction optional(request: LightRequest | LightSource): Partial<Holder['values']> {\n const values: Partial<Holder['values']> = {}\n if (request.decay !== undefined) values.decay = request.decay\n if (request.target !== undefined) values.target = [...request.target]\n if (request.angle !== undefined) values.angle = request.angle\n if (request.penumbra !== undefined) values.penumbra = request.penumbra\n return values\n}\n\nfunction isAttached(object: Object3D, root: Object3D): boolean {\n for (let node: Object3D | null = object; node !== null; node = node.parent) if (node === root) return true\n return false\n}\n\nexport function createLightBudget(THREE: ThreeForLights, scene: Object3D, options: LightBudgetOptions = {}): LightBudget {\n const opts = { ...DEFAULTS, ...options }\n const pointShadows = Math.min(opts.pointShadows, opts.point)\n const spotShadows = Math.min(opts.spotShadows, opts.spot)\n const group = new THREE.Group()\n group.name = 'light-budget'\n const core: ArbiterCore = {\n THREE,\n slots: {\n point: createSlots(THREE, group, 'point', opts.point, pointShadows, opts.shadowMapSize, options.shadowSettings),\n spot: createSlots(THREE, group, 'spot', opts.spot, spotShadows, opts.shadowMapSize, options.shadowSettings),\n },\n urgentReserve: opts.urgentReserve,\n fadeMs: opts.fadeMs,\n hysteresis: opts.hysteresis,\n preempted: 0,\n refused: 0,\n }\n const hemispheres: HemisphereLight[] = []\n for (let index = 0; index < opts.hemisphere; index++) {\n const light = new THREE.HemisphereLight(0xffffff, 0xffffff, 0)\n light.layers.enableAll()\n group.add(light)\n hemispheres.push(light)\n }\n scene.add(group)\n scene.children.splice(scene.children.indexOf(group), 1)\n scene.children.unshift(group)\n\n const sources = new Set<Holder>()\n const world = new THREE.Vector3()\n const direction = new THREE.Vector3()\n let sealed: Sealed | null = null\n let leasedHemispheres = 0\n\n const allSlots = (): Slot[] => [...core.slots.point, ...core.slots.spot]\n\n function writeHolder(holder: Holder): void {\n if (holder.slot !== null && holder.slot.holder === holder) writeLight(THREE, holder.slot, holder.values)\n }\n\n function makeHandle(holder: Holder, release: ((fadeMs: number | undefined) => void) | null): LightHandle {\n return {\n get slot() {\n return holder.slot?.index ?? -1\n },\n kind: holder.lightKind,\n get alive() {\n return holder.alive\n },\n update(patch: LightPatch) {\n if (!holder.alive) return\n mergeValues(holder.values, patch)\n writeHolder(holder)\n },\n release(releaseOptions) {\n if (!holder.alive || release === null) return\n holder.alive = false\n release(releaseOptions?.fadeMs)\n },\n }\n }\n\n function dropHolder(holder: Holder, fadeMs: number): void {\n const slot = holder.slot\n holder.slot = null\n if (slot === null) return\n if (slot.pending === holder) slot.pending = null\n else if (slot.holder === holder) vacate(slot, fadeMs)\n }\n\n function resolveSource(holder: Holder, focus: readonly [number, number, number]): void {\n const { follow, values, resolved } = holder\n holder.wanted = values.intensity > 0\n if (follow === undefined) {\n holder.distance = Math.hypot(values.position[0] - focus[0], values.position[1] - focus[1], values.position[2] - focus[2])\n Object.assign(resolved, values)\n return\n }\n holder.wanted = holder.wanted && isAttached(follow, scene)\n if (!holder.wanted) return\n follow.getWorldPosition(world)\n const [ox, oy, oz] = values.position\n if (ox !== 0 || oy !== 0 || oz !== 0) world.set(ox, oy, oz).applyMatrix4(follow.matrixWorld)\n const axis = follow.matrixWorld.elements\n direction.set(-(axis[8] as number), -(axis[9] as number), -(axis[10] as number))\n holder.distance = Math.hypot(world.x - focus[0], world.y - focus[1], world.z - focus[2])\n Object.assign(resolved, values)\n resolved.position = [world.x, world.y, world.z]\n resolved.target = values.target ?? [world.x + direction.x, world.y + direction.y, world.z + direction.z]\n }\n\n return {\n group,\n sizes: { point: opts.point, spot: opts.spot, pointShadows, spotShadows },\n acquire(request) {\n const holder = newHolder('request', request.kind ?? 'point', request, request.urgent === true)\n holder.onLost = request.onLost\n if (!admitRequest(core, holder)) return null\n return makeHandle(holder, (fadeMs) => dropHolder(holder, fadeMs ?? opts.fadeMs))\n },\n addSource(source) {\n const holder = newHolder('source', source.kind ?? 'point', source, false)\n holder.follow = source.follow\n holder.shadow = source.shadow === true\n sources.add(holder)\n return {\n get slot() {\n return holder.slot !== null && holder.slot.holder === holder ? holder.slot.index : -1\n },\n update(patch: Partial<LightSource>) {\n mergeValues(holder.values, patch)\n if (patch.priority !== undefined) holder.priority = patch.priority\n if ('follow' in patch) holder.follow = patch.follow\n if (holder.follow === undefined) writeHolder(holder)\n },\n remove() {\n holder.alive = false\n holder.wanted = false\n sources.delete(holder)\n dropHolder(holder, opts.fadeMs)\n },\n } satisfies SourceHandle\n },\n lease({ owner, point, shadows = 0 }) {\n const shadowSlots = core.slots.point.filter((slot) => slot.shadow && isFree(slot))\n const plainSlots = core.slots.point.filter((slot) => !slot.shadow && isFree(slot))\n if (shadowSlots.length < shadows || plainSlots.length < point - shadows) return null\n const taken = [...shadowSlots.slice(0, shadows), ...plainSlots.slice(0, point - shadows)]\n const holders = taken.map((slot) => {\n const holder = newHolder('lease', 'point', { owner, priority: Number.POSITIVE_INFINITY, color: 0xffffff, intensity: 0, distance: 0, position: ZERO }, false)\n slot.leased = true\n slot.holder = holder\n slot.fade = 1\n slot.fadeTarget = 1\n holder.slot = slot\n markShadow(slot)\n return holder\n })\n const handles = holders.map((holder) => makeHandle(holder, null))\n return {\n handles,\n invalidateShadow(index) {\n for (const [at, holder] of holders.entries()) if ((index === undefined || index === at) && holder.slot !== null) markShadow(holder.slot)\n },\n release() {\n for (const holder of holders) {\n const slot = holder.slot\n holder.alive = false\n holder.slot = null\n if (slot === null) continue\n slot.leased = false\n slot.holder = null\n vacate(slot, 0)\n }\n },\n } satisfies LightLease\n },\n leaseHemisphere() {\n const light = hemispheres[leasedHemispheres]\n if (light === undefined) return null\n leasedHemispheres++\n return light\n },\n present(focus, dtSeconds) {\n for (const holder of sources) resolveSource(holder, focus)\n for (const kind of ['point', 'spot'] as const) {\n const reserve = kind === 'point' ? core.urgentReserve : 0\n const kindSources = [...sources].filter((holder) => holder.lightKind === kind)\n arbitrateSources(core, poolOf(core, kind, true), kindSources.filter((holder) => holder.shadow), 0)\n arbitrateSources(core, poolOf(core, kind, false), kindSources.filter((holder) => !holder.shadow), reserve)\n }\n stepSlots(core, dtSeconds)\n for (const holder of sources) if (holder.wanted && holder.slot?.holder === holder) writeLight(THREE, holder.slot, holder.resolved)\n },\n seal(renderer, scene, sealOptions = {}) {\n sealed = captureSealed(renderer, scene, sealOptions)\n },\n check(renderer: RendererState, checkedScene: Scene) {\n const result = checkSealed(sealed, renderer, checkedScene, group)\n const layersIntact = allSlots().every((slot) => slot.light.visible && slot.light.layers.mask === ALL_LAYERS_MASK)\n const isFirst = checkedScene.children[0] === group\n if (!layersIntact) return { ...result, ok: false, actual: `${result.actual} | budget lights hidden or off a layer` }\n return isFirst ? result : { ...result, ok: false, actual: `${result.actual} | budget group is not the first child of the scene` }\n },\n stats() {\n const slots = allSlots()\n return {\n lit: slots.filter((slot) => slot.light.intensity > 0).length,\n free: slots.filter(isFree).length,\n leased: slots.filter((slot) => slot.leased).length,\n sources: sources.size,\n sourcesWithoutSlot: [...sources].filter((holder) => holder.wanted && holder.slot === null).length,\n preempted: core.preempted,\n refused: core.refused,\n }\n },\n dispose() {\n group.removeFromParent()\n for (const slot of allSlots()) slot.light.dispose()\n sources.clear()\n },\n }\n}\n","import type { Camera, Group, HemisphereLight, Object3D, Scene, WebGLRenderTarget } from 'three'\n\nimport type { ThreeLib } from '../three-lib'\n\nexport type LightKind = 'point' | 'spot'\nexport type LinearRgb = readonly [number, number, number]\nexport type FogState = 'none' | 'linear' | 'exp2'\nexport type ThreeForLights = Pick<\n ThreeLib,\n 'Group' | 'PointLight' | 'SpotLight' | 'HemisphereLight' | 'Object3D' | 'Vector3' | 'Color' | 'LinearSRGBColorSpace'\n>\n/** What the budget reads of a renderer: a structural subset, so a fake works in Node. */\nexport type RendererState = {\n readonly toneMapping: number\n readonly outputColorSpace: string\n readonly shadowMap: { readonly type: number }\n}\n\nexport interface LightBudgetOptions {\n /** Point lights created at boot. Default 16. */\n readonly point?: number\n /** Spot lights created at boot. Default 4. */\n readonly spot?: number\n /** How many of the point lights cast shadows (cube maps). Default 2. Fixed for the life of the budget. */\n readonly pointShadows?: number\n /** How many of the spot lights cast shadows. Default 0. */\n readonly spotShadows?: number\n /** Shadow map size of the shadow slots. Default 512. */\n readonly shadowMapSize?: number\n /** Bias, normal bias and camera near plane of the shadow slots. Defaults: three.js's (0, 0, 0.5). The house's room lights use -0.0012, 0.05 and 0.12. */\n readonly shadowSettings?: { readonly bias?: number; readonly normalBias?: number; readonly near?: number }\n /** Point slots only `urgent` requests may take while others are free. Default 2. */\n readonly urgentReserve?: number\n /** Milliseconds a light fades out when a source loses its slot, and fades in when it gets one. Default 120. */\n readonly fadeMs?: number\n /** A source keeps its slot until a challenger of the same priority is this much closer (0.15 = 15%). Default 0.15. */\n readonly hysteresis?: number\n /** HemisphereLights created at boot for adapters that flash the sky; leased with `leaseHemisphere`. Default 0. */\n readonly hemisphere?: number\n}\n\n/** A light that lives as long as the request: a blast, a rocket in flight, a muzzle flash, a flare in the hand. */\nexport interface LightRequest {\n readonly owner: string\n readonly kind?: LightKind\n /** Higher wins a slot; see LIGHT_PRIORITY. */\n readonly priority: number\n /** Hex (sRGB, like `new Color(hex)`) or linear RGB. */\n readonly color: number | LinearRgb\n readonly intensity: number\n readonly distance: number\n readonly decay?: number\n readonly position: readonly [number, number, number]\n /** Spot only. */\n readonly target?: readonly [number, number, number]\n readonly angle?: number\n readonly penumbra?: number\n /** Takes a slot at once: cuts the lowest victim instead of fading it, and may use the urgent reserve. */\n readonly urgent?: boolean\n /** Called once when a higher priority took the slot; the handle is dead from then on. */\n readonly onLost?: () => void\n}\n\nexport type LightPatch = Partial<Pick<LightRequest, 'color' | 'intensity' | 'distance' | 'decay' | 'position' | 'target' | 'angle' | 'penumbra'>>\n\nexport interface LightHandle {\n /** Index of this light among the scene's point (or spot) lights in the shader; stable while the handle lives. */\n readonly slot: number\n readonly kind: LightKind\n readonly alive: boolean\n update(patch: LightPatch): void\n /** Gives the slot back; with fadeMs the light fades first. Idempotent. */\n release(options?: { readonly fadeMs?: number }): void\n}\n\n/** A light that exists in the world for a long time and competes for a slot every frame: a lamp, a street light, a headlight. */\nexport interface LightSource extends Omit<LightRequest, 'urgent' | 'onLost'> {\n /** Wants a shadow slot; a shadow source competes for shadow slots only. */\n readonly shadow?: boolean\n /**\n * The object the light sits on. Its world position (and, for a spot, its world -z as the direction when `target` is absent) is read\n * once per `present`; `position` is then an offset in its local space. A source whose `follow` left the scene counts as off.\n */\n readonly follow?: Object3D\n}\n\nexport interface SourceHandle {\n /** Slot now, or -1 while it has none (its light is not drawn). */\n readonly slot: number\n update(patch: Partial<LightSource>): void\n remove(): void\n}\n\n/** Slots a client keeps for itself for good: the room lights of a house (their masks are indexed by slot). */\nexport interface LightLease {\n readonly handles: readonly LightHandle[]\n /** Redraws the shadow map of one leased slot (`handles[index]`), or of all of them, on the next render: the walls it shades changed. */\n invalidateShadow(index?: number): void\n release(): void\n}\n\nexport interface SealOptions {\n /** Fog states the game will switch between at run time. Default: only the state at seal time. */\n readonly fogStates?: readonly FogState[]\n /** Cameras whose `far` must stay under the neutral fog's near (read at every `check`). */\n readonly cameras?: readonly Camera[]\n /** Where the game really draws; its colour space is part of the sealed state. */\n readonly target?: WebGLRenderTarget | null\n}\n\nexport interface LightCheck {\n readonly ok: boolean\n readonly expected: string\n readonly actual: string\n /** Paths of PointLight/SpotLight found outside the budget's group. */\n readonly strays: readonly string[]\n}\n\nexport interface LightBudgetStats {\n readonly lit: number\n readonly free: number\n readonly leased: number\n readonly sources: number\n readonly sourcesWithoutSlot: number\n readonly preempted: number\n readonly refused: number\n}\n\nexport interface LightBudget {\n /** The group holding every light; first child of the scene. Never hidden, never removed while the budget lives. */\n readonly group: Group\n readonly sizes: { readonly point: number; readonly spot: number; readonly pointShadows: number; readonly spotShadows: number }\n acquire(request: LightRequest): LightHandle | null\n addSource(source: LightSource): SourceHandle\n /** Takes `point` slots (of which `shadows` shadow slots) for good. null when not enough unleased slots remain. */\n lease(options: { readonly owner: string; readonly point: number; readonly shadows?: number }): LightLease | null\n /** Takes one of the boot HemisphereLights for good. null when none is left. Its intensity starts at 0. */\n leaseHemisphere(owner: string): HemisphereLight | null\n /** Once per frame, with the camera (or the player) as focus. `dtSeconds` is real time: fades do not stop in pause. */\n present(focus: readonly [number, number, number], dtSeconds: number): void\n /** After this, any change in the program-key state of the scene is a bug and `check()` reports it. */\n seal(renderer: RendererState, scene: Scene, options?: SealOptions): void\n check(renderer: RendererState, scene: Scene): LightCheck\n stats(): LightBudgetStats\n dispose(): void\n}\n\nexport const LIGHT_PRIORITY = {\n blast: 900,\n rocket: 800,\n muzzle: 750,\n fire: 600,\n flare: 500,\n headlight: 400,\n weaponLight: 400,\n lamp: 200,\n street: 150,\n} as const\n","import type { LightBudget } from './types'\n\n/** For adapters that receive the budget as `unknown` through the host (the contract does not know three). */\nexport function isLightBudget(value: unknown): value is LightBudget {\n const candidate = value as Partial<LightBudget> | null | undefined\n return typeof candidate === 'object' && candidate !== null && typeof candidate.acquire === 'function' && typeof candidate.addSource === 'function' && typeof candidate.lease === 'function' && typeof candidate.present === 'function'\n}\n","import type { Material } from 'three'\n\n/** What `programKeysOf` reads of a renderer: `properties` is internal to three r160 and may be absent in another version. */\nexport type PropertiesReader = { readonly properties?: { get(object: object): unknown } }\n\n/**\n * Every program cache key three linked for `material` (one per state it was drawn in: fog type, shadow, light counts). Reads three's\n * internal `properties.get(material).programs` Map (r160). `[]` for a material never drawn; `undefined` when this three does not have\n * that internal, which sends the pools to their conservative mode.\n */\nexport function programKeysOf(renderer: PropertiesReader, material: Material): readonly string[] | undefined {\n const properties = renderer.properties\n if (typeof properties?.get !== 'function') return undefined\n const programs = (properties.get(material) as { programs?: unknown } | undefined)?.programs\n if (programs === undefined) return []\n if (!(programs instanceof Map)) return undefined\n return [...programs.keys()].map(String)\n}\n","import type { Material } from 'three'\n\nimport { type PropertiesReader, programKeysOf } from '../program-key'\n\n/** Materials kept alive and never disposed, one per program family: what keeps a program linked once its users are gone. */\nexport interface MaterialAnchors {\n /**\n * Keeps `material` if any of its program keys has no anchor yet; returns true when it was kept (the caller must then not dispose it).\n * A material whose keys are all covered returns false and may be disposed. A material never drawn is not kept.\n */\n offer(material: Material): boolean\n readonly size: number\n /** Where program keys are read from. Until bound (or when three has no readable keys) every offered material is kept. */\n bind(renderer: PropertiesReader): void\n}\n\nexport function createMaterialAnchors(renderer?: PropertiesReader): MaterialAnchors {\n const anchors = new Set<Material>()\n let reader = renderer\n\n function coveredKeys(): Set<string> {\n const covered = new Set<string>()\n if (reader === undefined) return covered\n for (const anchor of anchors) for (const key of programKeysOf(reader, anchor) ?? []) covered.add(key)\n return covered\n }\n\n return {\n get size() {\n return anchors.size\n },\n bind(next) {\n reader = next\n },\n offer(material) {\n if (anchors.has(material)) return true\n const keys = reader === undefined ? undefined : programKeysOf(reader, material)\n if (keys === undefined) {\n anchors.add(material)\n return true\n }\n if (keys.length === 0) return false\n const covered = coveredKeys()\n if (keys.every((key) => covered.has(key))) return false\n anchors.add(material)\n return true\n },\n }\n}\n","import type { Object3D } from 'three'\n\nimport type { ThreeLib } from './three-lib'\nimport type { WarmupProbe } from './warmup-types'\n\n/** The sprite probes the room builds by hand today: one sprite material with fog and one without. */\nexport function spriteProbes(THREE: Pick<ThreeLib, 'Group' | 'Sprite' | 'SpriteMaterial' | 'DataTexture'>): WarmupProbe {\n return {\n id: 'sprite',\n build() {\n const group = new THREE.Group()\n const texture = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1)\n texture.needsUpdate = true\n const materials = [true, false].map((fog) => new THREE.SpriteMaterial({ map: texture, fog, transparent: true }))\n for (const material of materials) group.add(new THREE.Sprite(material))\n return { group, materials, dispose: () => texture.dispose() }\n },\n }\n}\n\nexport function hasMissingDistanceMaterial(root: Object3D): string | undefined {\n let found: string | undefined\n root.traverse((object) => {\n const mesh = object as { isInstancedMesh?: boolean; castShadow?: boolean; customDepthMaterial?: unknown; customDistanceMaterial?: unknown }\n if (found === undefined && mesh.isInstancedMesh === true && mesh.castShadow === true && mesh.customDepthMaterial && !mesh.customDistanceMaterial) found = object.name || object.type\n })\n return found\n}\n","import type { BufferGeometry, Camera, Material, Object3D, Scene } from 'three'\n\nimport { fogStateOf, lightSignature } from './lights/scene-state'\nimport type { FogState } from './lights/types'\nimport { createMaterialAnchors } from './pools/anchors'\nimport { hasMissingDistanceMaterial } from './probes'\nimport type { ThreeLib } from './three-lib'\nimport type { EffectWarmup, ProgramWarmup, WarmupContext, WarmupOptions, WarmupProbe, WarmupReport, WarmupRenderer } from './warmup-types'\n\nconst EFFECT_STEP_SECONDS = 1 / 50\nconst DEFAULT_EFFECT_FRAMES = 3\nconst WARM_FOG_DENSITY = 0.01\nconst WARM_FOG_FAR = 100\n\ntype LinkCounter = { count: number }\ntype BuiltProbe = { readonly probe: WarmupProbe; readonly built: ReturnType<WarmupProbe['build']> }\n\nfunction register<TItem>(items: Set<TItem>, item: TItem): () => void {\n items.add(item)\n return () => void items.delete(item)\n}\n\nfunction countLinks(context: WarmupContext, counters: WeakMap<WarmupContext, LinkCounter>): void {\n const existing = counters.get(context)\n if (existing !== undefined) {\n existing.count = 0\n return\n }\n const counter: LinkCounter = { count: 0 }\n counters.set(context, counter)\n const original = context.linkProgram.bind(context)\n context.linkProgram = (program) => {\n counter.count++\n original(program)\n }\n}\n\nfunction failedProgram(renderer: WarmupRenderer): string | undefined {\n for (const program of renderer.info.programs ?? []) {\n const diagnostics = (program as { diagnostics?: { runnable?: boolean; programLog?: string } }).diagnostics\n if (diagnostics?.runnable === false) return diagnostics.programLog ?? 'program failed to link'\n }\n return undefined\n}\n\nexport function createProgramWarmup(THREE: Pick<ThreeLib, 'Group' | 'Sprite' | 'SpriteMaterial' | 'DataTexture' | 'Fog' | 'FogExp2' | 'Mesh' | 'Points' | 'LineSegments' | 'BufferGeometry' | 'BufferAttribute'>): ProgramWarmup {\n const probes = new Set<WarmupProbe>()\n const effects = new Set<EffectWarmup>()\n const textures = new Set<Parameters<WarmupRenderer['initTexture']>[0]>()\n const anchors = createMaterialAnchors()\n const linkCounters = new WeakMap<WarmupContext, LinkCounter>()\n\n function setFog(scene: Scene, state: FogState): void {\n const color = scene.fog?.color.getHex() ?? 0\n if (state === 'none') scene.fog = null\n else if (state === 'linear' && (scene.fog as { isFog?: boolean } | null)?.isFog !== true) scene.fog = new THREE.Fog(color, 1, WARM_FOG_FAR)\n else if (state === 'exp2' && (scene.fog as { isFogExp2?: boolean } | null)?.isFogExp2 !== true) scene.fog = new THREE.FogExp2(color, WARM_FOG_DENSITY)\n }\n\n function draw(renderer: WarmupRenderer, scene: Scene, camera: Camera, target: WarmupOptions['target']): void {\n renderer.setRenderTarget(target ?? null)\n renderer.compile(scene, camera)\n renderer.render(scene, camera)\n }\n\n function playEffect(renderer: WarmupRenderer, scene: Scene, camera: Camera, effect: EffectWarmup, target: WarmupOptions['target']): void {\n effect.play()\n try {\n for (let frame = 0; frame < (effect.frames ?? DEFAULT_EFFECT_FRAMES); frame++) {\n effect.step(EFFECT_STEP_SECONDS)\n renderer.setRenderTarget(target ?? null)\n renderer.render(scene, camera)\n }\n } finally {\n effect.stop()\n }\n }\n\n /** One object per material, of the kind its program is for, each a single triangle: drawn once so that the program is used, not only linked. */\n function materialsProbe(materials: readonly Material[]): BuiltProbe {\n const geometry = new THREE.BufferGeometry()\n geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array([0, 0, 0, 0.001, 0, 0, 0, 0.001, 0]), 3))\n const group = new THREE.Group()\n for (const material of materials) group.add(drawableOf(material, geometry))\n return { probe: { id: 'materials', build: () => ({ group, materials: [], dispose: () => geometry.dispose() }) }, built: { group, materials: [], dispose: () => geometry.dispose() } }\n }\n\n function drawableOf(material: Material, geometry: BufferGeometry): Object3D {\n const flags = material as { isSpriteMaterial?: boolean; isPointsMaterial?: boolean; isLineBasicMaterial?: boolean }\n const object: Object3D =\n flags.isSpriteMaterial === true ? new THREE.Sprite(material as never)\n : flags.isPointsMaterial === true ? new THREE.Points(geometry, material)\n : flags.isLineBasicMaterial === true ? new THREE.LineSegments(geometry, material)\n : new THREE.Mesh(geometry, material)\n object.frustumCulled = false\n return object\n }\n\n function buildProbes(materials: readonly Material[] | undefined): BuiltProbe[] {\n const built = [...probes].map((probe) => ({ probe, built: probe.build() }))\n if (materials !== undefined && materials.length > 0) built.push(materialsProbe(materials))\n return built\n }\n\n function addProbes(scene: Scene, built: readonly BuiltProbe[]): void {\n for (const { probe, built: item } of built) {\n const missing = hasMissingDistanceMaterial(item.group)\n if (missing !== undefined) throw new Error(`warmup probe \"${probe.id}\": instanced mesh \"${missing}\" casts shadows with a customDepthMaterial but no customDistanceMaterial`)\n scene.add(item.group)\n }\n }\n\n function removeProbes(scene: Scene, built: readonly BuiltProbe[]): void {\n for (const { built: item } of built) {\n scene.remove(item.group)\n item.dispose()\n for (const material of item.materials) anchors.offer(material)\n }\n }\n\n function drawStates(renderer: WarmupRenderer, scene: Scene, camera: Camera, states: readonly FogState[], target: WarmupOptions['target']): void {\n for (const state of states) {\n setFog(scene, state)\n draw(renderer, scene, camera, target)\n }\n }\n\n /** Makes every instanced batch draw at least once: three skips an empty instanced batch, and a driver finishes a program's state on its first real draw (a 200 ms stall). Returns the undo. */\n function forceDraws(scene: Scene): () => void {\n const undo: Array<() => void> = []\n scene.traverse((object) => {\n const drawable = object as Object3D & { isInstancedMesh?: boolean; count?: number; geometry?: { isInstancedBufferGeometry?: boolean; instanceCount?: number } }\n const { geometry } = drawable\n if (geometry?.isInstancedBufferGeometry === true && geometry.instanceCount === 0) {\n geometry.instanceCount = 1\n undo.push(() => (geometry.instanceCount = 0))\n }\n if (drawable.isInstancedMesh === true && drawable.count === 0) {\n drawable.count = 1\n undo.push(() => (drawable.count = 0))\n }\n })\n return () => undo.forEach((restore) => restore())\n }\n\n return {\n anchors,\n register: (probe) => register(probes, probe),\n registerEffect: (effect) => register(effects, effect),\n registerTexture: (texture) => register(textures, texture),\n warmUp(renderer, scene, camera, options = {}): WarmupReport {\n const started = performance.now()\n const { lights, target } = options\n anchors.bind(renderer)\n const originalFog = scene.fog\n const states = options.fogStates ?? [fogStateOf(scene)]\n lights?.seal(renderer, scene, { fogStates: options.fogStates, cameras: [camera], target })\n scene.traverse((object) => {\n const light = object as { castShadow?: boolean; shadow?: { needsUpdate: boolean } }\n if (light.castShadow === true && light.shadow !== undefined) light.shadow.needsUpdate = true\n })\n const built = buildProbes(options.materials)\n let restoreDraws = (): void => undefined\n try {\n addProbes(scene, built)\n restoreDraws = forceDraws(scene)\n drawStates(renderer, scene, camera, states, target)\n scene.fog = originalFog\n for (const effect of effects) playEffect(renderer, scene, camera, effect, target)\n for (const texture of textures) renderer.initTexture(texture)\n } finally {\n restoreDraws()\n scene.fog = originalFog\n removeProbes(scene, built)\n }\n const context = renderer.getContext()\n const uniformVectors = Number(context.getParameter(context.MAX_FRAGMENT_UNIFORM_VECTORS))\n const failure = failedProgram(renderer)\n if (failure !== undefined) {\n throw new Error(`a shader program failed to link (MAX_FRAGMENT_UNIFORM_VECTORS ${uniformVectors}, lights: ${lightSignature(scene)}): ${failure}`)\n }\n countLinks(context, linkCounters)\n // the GPU process is still working through all of the above: wait here, at load, or the first upload of play stalls on it\n if (context.RGBA !== undefined && context.UNSIGNED_BYTE !== undefined) context.readPixels?.(0, 0, 1, 1, context.RGBA, context.UNSIGNED_BYTE, new Uint8Array(4))\n return {\n programs: renderer.info.programs?.length ?? 0,\n geometries: renderer.info.memory.geometries,\n textures: renderer.info.memory.textures,\n milliseconds: performance.now() - started,\n lightSignature: lightSignature(scene),\n uniformVectors,\n anchors: anchors.size,\n }\n },\n linkedSince(renderer) {\n return linkCounters.get(renderer.getContext())?.count ?? 0\n },\n }\n}\n","const POOLED = '__pooled'\n\ntype Disposable = { dispose(): void; userData: Record<string, unknown> }\n\nfunction isDevelopment(): boolean {\n return typeof process === 'undefined' || process.env.NODE_ENV !== 'production'\n}\n\n/** Marks a pool resource and, in development, warns when something disposes it directly instead of releasing it to the pool. */\nexport function markPooled(resource: Disposable, key: string, owner: string): { disposeForPool(): void } {\n resource.userData[POOLED] = key\n const original = resource.dispose.bind(resource)\n let fromPool = false\n if (isDevelopment()) {\n resource.dispose = () => {\n if (!fromPool) console.warn(`[game-render-three] ${owner} \"${key}\" was disposed directly; release it to its pool instead`)\n original()\n }\n }\n return {\n disposeForPool() {\n fromPool = true\n original()\n fromPool = false\n },\n }\n}\n\nexport function pooledKey(resource: { userData: Record<string, unknown> }): string | undefined {\n const key = resource.userData[POOLED]\n return typeof key === 'string' ? key : undefined\n}\n\n/** A number as a short stable string, rounded to `step`. */\nexport function roundedNumber(value: number, step: number): string {\n return String(Number((Math.round(value / step) * step).toFixed(6)))\n}\n","import type { BufferGeometry } from 'three'\n\nimport { markPooled, pooledKey, roundedNumber } from './pooled'\n\nexport interface GeometryPool {\n /** The geometry for `key`, built once with `build`. Counts one use. */\n acquire(key: string, build: () => BufferGeometry): BufferGeometry\n release(geometry: BufferGeometry): void\n /** Never disposed while the pool lives (unit shapes, effect geometries warmed at load). */\n retain(key: string): void\n /** Disposes unretained geometries with no use, oldest first, keeping at most `keep` idle ones. Only at load points, never in play. */\n trim(keep?: number): number\n stats(): { readonly entries: number; readonly retained: number; readonly inUse: number }\n dispose(): void\n}\n\ntype Entry = { geometry: BufferGeometry; uses: number; retained: boolean; idleSince: number; disposeForPool(): void }\n\nconst DEFAULT_KEY_STEP = 1e-3\n\n/** Builds a key from a kind and its numbers, rounded to `step`, so near-equal sizes share one geometry. */\nexport function geometryKey(kind: string, params: readonly number[], step: number = DEFAULT_KEY_STEP): string {\n return [kind, ...params.map((value) => roundedNumber(value, step))].join('|')\n}\n\nexport function createGeometryPool(): GeometryPool {\n const entries = new Map<string, Entry>()\n let clock = 0\n\n function disposeEntry(key: string, entry: Entry): void {\n entries.delete(key)\n entry.disposeForPool()\n }\n\n return {\n acquire(key, build) {\n let entry = entries.get(key)\n if (entry === undefined) {\n const geometry = build()\n entry = { geometry, uses: 0, retained: false, idleSince: 0, ...markPooled(geometry, key, 'geometry') }\n entries.set(key, entry)\n }\n entry.uses++\n return entry.geometry\n },\n release(geometry) {\n const key = pooledKey(geometry)\n const entry = key === undefined ? undefined : entries.get(key)\n if (entry === undefined || entry.uses === 0) return\n entry.uses--\n if (entry.uses === 0) entry.idleSince = ++clock\n },\n retain(key) {\n const entry = entries.get(key)\n if (entry !== undefined) entry.retained = true\n },\n trim(keep = 0) {\n const idle = [...entries].filter(([, entry]) => entry.uses === 0 && !entry.retained).sort((a, b) => a[1].idleSince - b[1].idleSince)\n const excess = idle.slice(0, Math.max(0, idle.length - keep))\n for (const [key, entry] of excess) disposeEntry(key, entry)\n return excess.length\n },\n stats() {\n const all = [...entries.values()]\n return { entries: all.length, retained: all.filter((entry) => entry.retained).length, inUse: all.filter((entry) => entry.uses > 0).length }\n },\n dispose() {\n for (const [key, entry] of [...entries]) disposeEntry(key, entry)\n },\n }\n}\n","import type { Material } from 'three'\n\nimport type { PropertiesReader } from '../program-key'\nimport { type MaterialAnchors, createMaterialAnchors } from './anchors'\nimport { markPooled, pooledKey, roundedNumber } from './pooled'\n\nexport interface MaterialPool {\n /**\n * The material for `key`, built once. Shared: callers must not change it. Per-instance variety goes into instance attributes, not\n * into new materials.\n */\n acquire<TMaterial extends Material>(key: string, build: () => TMaterial): TMaterial\n release(material: Material): void\n /** Declares a variant that must never be disposed (its program stays linked). Effects register theirs at load. */\n register<TMaterial extends Material>(key: string, build: () => TMaterial): TMaterial\n /**\n * A material the caller owns and changes per frame (a puff's opacity): not shared. On `release` the first one of its program family is\n * handed to the anchors, so disposing the others never frees the program.\n */\n own<TMaterial extends Material>(build: () => TMaterial): TMaterial\n /** The materials declared with `register`: the ones that must never be disposed and whose programs the warmup draws once. */\n registeredMaterials?(): readonly Material[]\n /** Disposes unregistered materials with no use, oldest first, keeping at most `keep` idle ones; a family's anchor is kept alive. */\n trim(keep?: number): number\n stats(): { readonly entries: number; readonly registered: number; readonly inUse: number; readonly families: number }\n /**\n * The end of the pool: disposes every material it made, in use or not, registered or anchored (the guarantee that a program stays linked\n * holds while the pool lives, not after it). The anchors object itself is not touched, and the pool is empty and usable again afterwards.\n */\n dispose(): void\n}\n\nexport type MaterialPoolOptions = { readonly anchors?: MaterialAnchors; readonly renderer?: PropertiesReader }\n\ntype Entry = { material: Material; uses: number; registered: boolean; idleSince: number; disposeForPool(): void }\n\nconst DEFAULT_KEY_STEP = 1e-3\n\n/** Key from the material class and every parameter that changes its look, sorted, numbers rounded. */\nexport function materialKey(type: string, params: Readonly<Record<string, unknown>>): string {\n const parts = Object.keys(params)\n .sort()\n .map((name) => {\n const value = params[name]\n return `${name}=${typeof value === 'number' ? roundedNumber(value, DEFAULT_KEY_STEP) : JSON.stringify(value)}`\n })\n return [type, ...parts].join('|')\n}\n\nexport function createMaterialPool(options: MaterialPoolOptions = {}): MaterialPool {\n const anchors = options.anchors ?? createMaterialAnchors()\n if (options.renderer !== undefined) anchors.bind(options.renderer)\n const entries = new Map<string, Entry>()\n const owned = new Map<Material, () => void>()\n let clock = 0\n\n function createEntry(key: string, material: Material, registered: boolean): Entry {\n const entry: Entry = { material, uses: 0, registered, idleSince: 0, ...markPooled(material, key, 'material') }\n entries.set(key, entry)\n return entry\n }\n\n /** Disposes the material unless it is the anchor of a program family. */\n function retire(material: Material, disposeForPool: () => void): boolean {\n if (anchors.offer(material)) return false\n disposeForPool()\n return true\n }\n\n return {\n acquire(key, build) {\n const entry = entries.get(key) ?? createEntry(key, build(), false)\n entry.uses++\n return entry.material as ReturnType<typeof build>\n },\n register(key, build) {\n const entry = entries.get(key) ?? createEntry(key, build(), true)\n entry.registered = true\n return entry.material as ReturnType<typeof build>\n },\n own(build) {\n const material = build()\n owned.set(material, markPooled(material, 'own', 'material').disposeForPool)\n return material\n },\n release(material) {\n const disposeOwned = owned.get(material)\n if (disposeOwned !== undefined) {\n owned.delete(material)\n retire(material, disposeOwned)\n return\n }\n const key = pooledKey(material)\n const entry = key === undefined ? undefined : entries.get(key)\n if (entry === undefined || entry.uses === 0) return\n entry.uses--\n if (entry.uses === 0) entry.idleSince = ++clock\n },\n trim(keep = 0) {\n const idle = [...entries].filter(([, entry]) => entry.uses === 0 && !entry.registered).sort((a, b) => a[1].idleSince - b[1].idleSince)\n let disposed = 0\n for (const [key, entry] of idle.slice(0, Math.max(0, idle.length - keep))) {\n entries.delete(key)\n if (retire(entry.material, entry.disposeForPool)) disposed++\n }\n return disposed\n },\n registeredMaterials() {\n return [...entries.values()].filter((entry) => entry.registered).map((entry) => entry.material)\n },\n stats() {\n const all = [...entries.values()]\n return {\n entries: all.length,\n registered: all.filter((entry) => entry.registered).length,\n inUse: all.filter((entry) => entry.uses > 0).length,\n families: anchors.size,\n }\n },\n dispose() {\n for (const entry of entries.values()) entry.disposeForPool()\n for (const disposeOwned of owned.values()) disposeOwned()\n entries.clear()\n owned.clear()\n },\n }\n}\n","import type { GeometryPool } from './geometry'\nimport type { MaterialPool } from './material'\n\n/** The pools a host lends its adapters (`host.pools`): geometries and materials that outlive the effect that asked for them. */\nexport interface RenderPools {\n readonly geometries: GeometryPool\n readonly materials: MaterialPool\n}\n\n/** For adapters that receive the pools as `unknown` through the host (the contract does not know three). */\nexport function isRenderPools(value: unknown): value is RenderPools {\n const candidate = value as Partial<RenderPools> | null | undefined\n return typeof candidate === 'object' && candidate !== null && typeof candidate.geometries?.acquire === 'function' && typeof candidate.materials?.acquire === 'function'\n}\n","/** The part of a WebGL2 context the pacer reads; the renderer's `getContext()` satisfies it. */\nexport type FramePacerContext = {\n readonly SYNC_GPU_COMMANDS_COMPLETE: number\n readonly TIMEOUT_EXPIRED: number\n fenceSync(condition: number, flags: number): WebGLSync | null\n clientWaitSync(sync: WebGLSync, flags: number, timeout: number): number\n deleteSync(sync: WebGLSync | null): void\n flush(): void\n}\n\nexport type FramePacerOptions = {\n /** Most frames in a row the pacer may hold back before it lets one through (default 3), so a stuck fence cannot freeze the picture. */\n readonly maxSkips?: number\n /** Frames the GPU may be behind before a draw is held back (default 2). The browser reports a fence only some 20 ms after the GPU finished it, so 1 would cap every GPU at one frame per report. */\n readonly framesInFlight?: number\n}\n\nexport type FramePacer = {\n /** True when fewer than `framesInFlight` drawn frames are unfinished: draw this frame. False: the GPU is too far behind, skip the draw and keep simulating. */\n ready(): boolean\n /** Fences the frame just drawn; call it right after the render. */\n submitted(): void\n /** Draws held back so far. */\n readonly skipped: number\n dispose(): void\n}\n\nconst DEFAULT_MAX_SKIPS = 3\nconst DEFAULT_FRAMES_IN_FLIGHT = 2\n\n/**\n * Keeps the GPU a few frames behind the CPU at most. A frame loop that draws as fast as it can (no vsync, as the perf runs do, or a slow GPU) fills the driver's queue and\n * then blocks in the compositor for the length of the whole queue: a run of 5 ms frames and a 150 ms one. Holding back the draw while the last frame is unfinished spends that\n * time on the next simulation step instead, and the longest frame is the GPU's own. A context without fences (WebGL1) is never held back.\n */\nexport function createFramePacer(context: FramePacerContext | null, options: FramePacerOptions = {}): FramePacer {\n const maxSkips = options.maxSkips ?? DEFAULT_MAX_SKIPS\n const framesInFlight = options.framesInFlight ?? DEFAULT_FRAMES_IN_FLIGHT\n const fences: WebGLSync[] = []\n let skippedInRow = 0\n let skipped = 0\n const dropOldest = (): void => {\n const oldest = fences.shift()\n if (oldest && context) context.deleteSync(oldest)\n }\n return {\n ready() {\n if (!context) return true\n while (fences.length > 0 && context.clientWaitSync(fences[0] as WebGLSync, 0, 0) !== context.TIMEOUT_EXPIRED) dropOldest()\n if (fences.length >= framesInFlight && skippedInRow < maxSkips) {\n skippedInRow++\n skipped++\n return false\n }\n skippedInRow = 0\n if (fences.length >= framesInFlight) dropOldest()\n return true\n },\n submitted() {\n if (!context || typeof context.fenceSync !== 'function') return\n const fence = context.fenceSync(context.SYNC_GPU_COMMANDS_COMPLETE, 0)\n if (fence) fences.push(fence)\n context.flush()\n },\n get skipped() {\n return skipped\n },\n dispose() {\n while (fences.length > 0) dropOldest()\n },\n }\n}\n","import type { Bone, BufferAttribute, BufferGeometry, Material, Matrix3, Matrix4, Mesh, Object3D, SkinnedMesh } from 'three'\n\nimport type { ThreeLib } from './three-lib'\n\n/** The layer a batched mesh is moved to: no camera draws it, a raycaster that enables every layer still finds it. */\nexport const BATCHED_LAYER = 30\n\nconst MATRIX_EPSILON = 1e-6\n\nexport type StaticBatcherOptions = {\n /** Which meshes may be batched (default every shown mesh with one material and no instancing, skinning or morphing). */\n readonly include?: (mesh: Mesh) => boolean\n /** Milliseconds of merging per `update` (default all at once, in the call): batches are made a material at a time over the next frames. */\n readonly budgetMs?: number\n /**\n * The meshes move on their own (a body posed bone by bone): each batch is skinned to its meshes, so a mesh carries its part of the batch\n * wherever it goes, and only a new geometry, material, dent or hiding gives it its own draw back.\n */\n readonly followMeshes?: boolean\n}\n\nexport type StaticBatcherStats = { readonly batches: number; readonly batched: number; readonly released: number }\n\nexport type StaticBatcher = {\n /** The batch meshes, a child of the root. */\n readonly group: Object3D\n /**\n * Gives back to its own draw every batched mesh that changed since the batch was made (moved, dented, hidden, given another geometry or\n * material); returns how many it released. Call it once per frame, before the render.\n */\n update(): number\n stats(): StaticBatcherStats\n /** Every mesh draws on its own again and the batches are disposed. */\n dispose(): void\n}\n\ntype Source = {\n readonly mesh: Mesh\n readonly geometry: BufferGeometry\n readonly material: Material\n readonly version: number\n readonly local: Matrix4\n /** The mesh's world matrix when last seen unchanged: equal again, nothing moved and the local check is skipped. */\n readonly world: Matrix4\n readonly mask: number\n readonly batch: Batch\n readonly start: number\n readonly count: number\n released: boolean\n}\n\ntype Batch = { readonly mesh: Mesh; live: number; readonly index: { array: ArrayLike<number> & { [n: number]: number }; needsUpdate: boolean } }\n\nconst ATTRIBUTES = ['position', 'normal', 'uv', 'color'] as const\n\n/** Visible all the way up to `root`; a mesh no longer under it (its model was rebuilt) is not shown. */\nconst isShown = (object: Object3D, root: Object3D): boolean => {\n for (let node: Object3D | null = object; node; node = node.parent) {\n if (node === root) return true\n if (!node.visible) return false\n }\n return false\n}\n\nconst isBatchable = (mesh: Mesh): boolean => {\n const flags = mesh as Mesh & { isInstancedMesh?: boolean; isSkinnedMesh?: boolean }\n if (flags.isInstancedMesh === true || flags.isSkinnedMesh === true || Array.isArray(mesh.material)) return false\n const geometry = mesh.geometry\n return geometry.attributes.position !== undefined && Object.keys(geometry.morphAttributes).length === 0\n}\n\nconst signatureOf = (mesh: Mesh): string => {\n const { attributes } = mesh.geometry\n const present = ATTRIBUTES.filter((name) => attributes[name] !== undefined).map((name) => `${name}${attributes[name]!.itemSize}`)\n return `${(mesh.material as Material).uuid}|${present.join(',')}|${mesh.castShadow ? 1 : 0}${mesh.receiveShadow ? 1 : 0}`\n}\n\nconst sameMatrix = (a: Matrix4, b: Matrix4): boolean => a.elements.every((value, index) => Math.abs(value - (b.elements[index] as number)) < MATRIX_EPSILON)\n\n/**\n * Draws the still, undamaged meshes of an object (a vehicle, a piece of furniture) as one batch per material, and gives each mesh its own draw\n * back the moment it changes. The meshes stay where they are: what hits, dents or cuts them works on them as before, they only leave the\n * camera's layer while batched.\n */\nexport function createStaticBatcher(THREE: ThreeLib, root: Object3D, options: StaticBatcherOptions = {}): StaticBatcher {\n const include = options.include ?? (() => true)\n const follow = options.followMeshes === true\n root.updateMatrixWorld(true)\n const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert()\n const groups = new Map<string, Mesh[]>()\n root.traverse((object) => {\n const mesh = object as Mesh\n if (!mesh.isMesh || !isShown(mesh, root) || !isBatchable(mesh) || !include(mesh)) return\n const key = signatureOf(mesh)\n groups.set(key, [...(groups.get(key) ?? []), mesh])\n })\n const group = new THREE.Group()\n group.name = 'static-batches'\n const sources: Source[] = []\n const pending = [...groups.values()].filter((meshes) => meshes.length >= 2)\n const mergeSome = (deadline: number): void => {\n while (pending.length > 0) {\n const meshes = pending.shift() as Mesh[]\n // a mesh that changed while it waited is left to draw on its own\n if (meshes.every((mesh) => isShown(mesh, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow }))\n if (performance.now() >= deadline) return\n }\n }\n if (options.budgetMs === undefined) mergeSome(Number.POSITIVE_INFINITY)\n root.add(group)\n const scratch = new THREE.Matrix4()\n let released = 0\n\n const release = (source: Source): void => {\n source.released = true\n source.mesh.layers.mask = source.mask\n const { index } = source.batch\n const first = index.array[source.start] as number\n for (let at = source.start; at < source.start + source.count; at++) index.array[at] = first\n index.needsUpdate = true\n // a batch whose meshes all draw on their own again is an empty draw: it leaves the screen\n if (--source.batch.live === 0) source.batch.mesh.visible = false\n released++\n }\n const hasChanged = (source: Source): boolean => {\n const { mesh } = source\n if (mesh.geometry !== source.geometry || mesh.material !== source.material || !isShown(mesh, root)) return true\n if ((mesh.geometry.attributes.position as BufferAttribute).version !== source.version) return true\n if (follow || sameMatrix(mesh.matrixWorld, source.world)) return false\n if (!sameMatrix(scratch.multiplyMatrices(inverse, mesh.matrixWorld), source.local)) return true\n // the whole object moved, the mesh did not move within it\n source.world.copy(mesh.matrixWorld)\n return false\n }\n\n return {\n group,\n update() {\n if (pending.length > 0) mergeSome(performance.now() + (options.budgetMs ?? Number.POSITIVE_INFINITY))\n const before = released\n inverse.copy(root.matrixWorld).invert()\n for (const source of sources) if (!source.released && hasChanged(source)) release(source)\n return released - before\n },\n stats: () => ({ batches: group.children.length, batched: sources.filter((source) => !source.released).length, released }),\n dispose() {\n for (const source of sources) if (!source.released) source.mesh.layers.mask = source.mask\n group.removeFromParent()\n for (const child of group.children) {\n ;(child as Mesh).geometry.dispose()\n ;(child as SkinnedMesh).skeleton?.dispose()\n }\n },\n }\n}\n\n/** Copies `attribute` into `target` at `offset` vertices: positions through `matrix`, normals through its normal matrix, the rest as they are. */\nfunction copyAttribute(name: string, attribute: BufferAttribute, target: Float32Array, offset: number, matrix: Matrix4, normalMatrix: Matrix3): void {\n const size = attribute.itemSize\n const source = attribute.array as ArrayLike<number>\n const flat = !(attribute as { isInterleavedBufferAttribute?: boolean }).isInterleavedBufferAttribute && source.length === attribute.count * size\n if (name !== 'position' && name !== 'normal') {\n if (flat) target.set(source as Float32Array, offset * size)\n else for (let at = 0; at < attribute.count; at++) for (let k = 0; k < size; k++) target[(offset + at) * size + k] = attribute.getComponent(at, k)\n return\n }\n const e = (name === 'position' ? matrix : normalMatrix).elements\n const isNormal = name === 'normal'\n for (let at = 0; at < attribute.count; at++) {\n const x = attribute.getX(at)\n const y = attribute.getY(at)\n const z = attribute.getZ(at)\n const out = (offset + at) * 3\n if (isNormal) {\n const nx = e[0]! * x + e[3]! * y + e[6]! * z\n const ny = e[1]! * x + e[4]! * y + e[7]! * z\n const nz = e[2]! * x + e[5]! * y + e[8]! * z\n const length = Math.hypot(nx, ny, nz) || 1\n target[out] = nx / length\n target[out + 1] = ny / length\n target[out + 2] = nz / length\n } else {\n target[out] = e[0]! * x + e[4]! * y + e[8]! * z + e[12]!\n target[out + 1] = e[1]! * x + e[5]! * y + e[9]! * z + e[13]!\n target[out + 2] = e[2]! * x + e[6]! * y + e[10]! * z + e[14]!\n }\n }\n}\n\ntype MergeGroupParams = { readonly meshes: readonly Mesh[]; readonly inverse: Matrix4; readonly group: Object3D; readonly follow: boolean }\n\n/** A skinned batch whose bone `n` is mesh `n` itself (no inverse, no bind offset): every vertex lands where its own mesh puts it. */\nfunction skinnedBatch(THREE: ThreeLib, merged: BufferGeometry, material: Material, meshes: readonly Mesh[]): Mesh {\n const vertices = (merged.attributes.position as BufferAttribute).count\n const skinIndex = new Uint16Array(vertices * 4)\n const skinWeight = new Float32Array(vertices * 4)\n let at = 0\n meshes.forEach((mesh, bone) => {\n for (let k = 0; k < (mesh.geometry.attributes.position as BufferAttribute).count; k++, at++) {\n skinIndex[at * 4] = bone\n skinWeight[at * 4] = 1\n }\n })\n merged.setAttribute('skinIndex', new THREE.BufferAttribute(skinIndex, 4))\n merged.setAttribute('skinWeight', new THREE.BufferAttribute(skinWeight, 4))\n const mesh = new THREE.SkinnedMesh(merged, material)\n const identities = meshes.map(() => new THREE.Matrix4())\n mesh.bind(new THREE.Skeleton(meshes as unknown as Bone[], identities), new THREE.Matrix4())\n // the parts move apart as the body is posed: the rest-pose bounds would cull the moved ones\n mesh.frustumCulled = false\n return mesh\n}\n\nfunction mergeGroup(THREE: ThreeLib, { meshes, inverse: rootInverse, group, follow }: MergeGroupParams): Source[] {\n const identity = new THREE.Matrix4()\n const inverse = follow ? identity : rootInverse\n const first = meshes[0] as Mesh\n const names = ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== undefined)\n const pieces = meshes.map((mesh) => {\n const local = new THREE.Matrix4().multiplyMatrices(inverse, mesh.matrixWorld)\n const vertices = (mesh.geometry.attributes.position as BufferAttribute).count\n const indexCount = mesh.geometry.index ? mesh.geometry.index.count : vertices\n return { mesh, local, vertices, indexCount }\n })\n const totalVertices = pieces.reduce((sum, piece) => sum + piece.vertices, 0)\n const totalIndices = pieces.reduce((sum, piece) => sum + piece.indexCount, 0)\n const merged = new THREE.BufferGeometry()\n const normalMatrix = new THREE.Matrix3()\n for (const name of names) {\n const size = first.geometry.attributes[name]!.itemSize\n const array = new Float32Array(totalVertices * size)\n let offset = 0\n for (const piece of pieces) {\n const matrix = follow ? identity : piece.local\n copyAttribute(name, piece.mesh.geometry.attributes[name] as BufferAttribute, array, offset, matrix, normalMatrix.getNormalMatrix(matrix))\n offset += piece.vertices\n }\n merged.setAttribute(name, new THREE.BufferAttribute(array, size))\n }\n const indexArray = totalVertices > 65535 ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices)\n const indexAttribute = new THREE.BufferAttribute(indexArray, 1)\n merged.setIndex(indexAttribute)\n const mesh = follow ? skinnedBatch(THREE, merged, first.material as Material, meshes) : new THREE.Mesh(merged, first.material)\n mesh.name = `batch:${(first.material as Material).name || (first.material as Material).type}`\n mesh.castShadow = first.castShadow\n mesh.receiveShadow = first.receiveShadow\n mesh.raycast = () => undefined\n merged.computeBoundingBox()\n merged.computeBoundingSphere()\n group.add(mesh)\n const batch: Batch = { mesh, live: pieces.length, index: indexAttribute as unknown as Batch['index'] }\n const sources: Source[] = []\n let vertexOffset = 0\n let indexOffset = 0\n for (const piece of pieces) {\n const index = piece.mesh.geometry.index\n if (index) for (let at = 0; at < piece.indexCount; at++) indexArray[indexOffset + at] = index.getX(at) + vertexOffset\n else for (let at = 0; at < piece.indexCount; at++) indexArray[indexOffset + at] = at + vertexOffset\n sources.push({\n mesh: piece.mesh,\n geometry: piece.mesh.geometry,\n material: piece.mesh.material as Material,\n version: (piece.mesh.geometry.attributes.position as BufferAttribute).version,\n local: piece.local,\n world: piece.mesh.matrixWorld.clone(),\n mask: piece.mesh.layers.mask,\n batch,\n start: indexOffset,\n count: piece.indexCount,\n released: false,\n })\n piece.mesh.layers.set(BATCHED_LAYER)\n vertexOffset += piece.vertices\n indexOffset += piece.indexCount\n }\n return sources\n}\n"],"mappings":";AAIA,IAAM,WAAW;AACjB,IAAM,gBAAgB;AACtB,IAAM,gBAAgB,KAAK,KAAK;AAChC,IAAM,mBAAmB;AAmDlB,SAAS,aAAa,MAA8G;AACzI,SAAO;AAAA,IACL,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV,GAAG;AAAA,IACH,UAAU,CAAC,GAAG,KAAK,QAAQ;AAAA,EAC7B;AACF;AAEO,SAAS,YAAY,QAAqB,OAAyB;AACxE,MAAI,MAAM,UAAU,OAAW,QAAO,QAAQ,MAAM;AACpD,MAAI,MAAM,cAAc,OAAW,QAAO,YAAY,MAAM;AAC5D,MAAI,MAAM,aAAa,OAAW,QAAO,WAAW,MAAM;AAC1D,MAAI,MAAM,UAAU,OAAW,QAAO,QAAQ,MAAM;AACpD,MAAI,MAAM,aAAa,OAAW,QAA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OAAO,QAAQ,OAAO,eAA4C;AACrG,QAAM,UAAoB,CAAC;AAC3B,MAAI,eAAe;AACnB,MAAI,cAAc;AAClB,aAAW,SAAS,QAAQ;AAC1B,UAAM,QAAQ,MAAM,KAAK,SAAS;AAClC,QAAI,MAAO,UAAS,KAAK,GAAG,KAAK,MAAM,YAAY,KAAM,YAAW,cAAc,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,QACpG,UAAS,KAAK,GAAG,KAAK,MAAM,YAAY,KAAM,YAAW,cAAc,EAAE,IAAI,KAAK;AACvF,YAAQ,KAAK;AAAA,MACX,MAAM,MAAM;AAAA,MACZ,UAAU,MAAM,KAAK;AAAA,MACrB,UAAU,MAAM,KAAK;AAAA,MACrB,SAAU,MAAM,KAAK,SAAS,WAAW,SAA6B;AAAA,MACtE,OAAO,MAAM;AAAA,MACb,OAAO,MAAM,KAAK,YAAY,MAAM;AAAA,MACpC,MAAM,MAAM,KAAK,OAAO;AAAA,MACxB;AAAA,MACA,OAAO;AAAA,MACP,OAAO,MAAM;AAAA,MACb,UAAU;AAAA,IACZ,CAAC;AACD,UAAM,KAAK,OAAO,IAAI,aAAa;AACnC,oBAAgB,MAAM;AACtB,mBAAe,MAAM;AAAA,EACvB;AACA,SAAO;AACT;","names":["scene","DEFAULT_KEY_STEP","mesh"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adatechnology/game-render-three",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Owner of the GPU-facing state of a three.js game: the one ThreeLib type, a LightBudget with a fixed number of lights (slots, priority, fades), a ProgramWarmup that links every shader program at load and keeps it linked, and geometry and material pools.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"three",
|
|
8
|
+
"threejs",
|
|
9
|
+
"game",
|
|
10
|
+
"lights",
|
|
11
|
+
"shader",
|
|
12
|
+
"warmup",
|
|
13
|
+
"pool"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Andersonfrfilho/adatechnology-game-kit.git",
|
|
18
|
+
"directory": "packages/game-render-three"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"three": "^0.160.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.10.7",
|
|
42
|
+
"@types/three": "^0.160.0",
|
|
43
|
+
"three": "^0.160.1",
|
|
44
|
+
"tsup": "^8.5.1",
|
|
45
|
+
"typescript": "^5.7.3",
|
|
46
|
+
"vitest": "^3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
6
53
|
}
|