@adatechnology/game-render-three 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anderson Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # @adatechnology/game-render-three
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Owner of the GPU-facing state of a three.js game (spec 005, D4). In three, the program key of every lit material carries the number of
4
+ lights, the fog type, the tone mapping and more: change one in the middle of play and the whole scene recompiles. This package keeps those
5
+ numbers fixed after boot.
6
+
7
+ - `ThreeLib`: the one name of the three namespace (`typeof import('three')`); narrow it with `Pick<ThreeLib, ...>`.
8
+ - `createLightBudget(THREE, scene, sizes)`: creates every `PointLight`/`SpotLight`/`HemisphereLight` at boot and never adds, hides or
9
+ removes one. Clients ask for slots: `acquire` (short-lived: blast, rocket, flare), `addSource` (long-lived and competing by priority and
10
+ distance, `follow` an object), `lease` (fixed slots, the room lights of a house) and `leaseHemisphere` (the weather lightning).
11
+ Priority preemption with fades, shadow slots first, `seal()` / `check()` for the light counts, fog presence and type,
12
+ `scene.environment`, `toneMapping`, `outputColorSpace`, `shadowMap.type` and camera `far` against the neutral fog.
13
+ - `createProgramWarmup()`: `register(probe)`, `registerEffect`, `registerTexture`, `warmUp(renderer, scene, camera, { lights, fogStates, target })`
14
+ links every program once, uploads buffers, seals the budget; probe materials go to `anchors` and are never disposed (a program is freed
15
+ when its last material is disposed). `linkedSince(renderer)` counts `linkProgram` calls after the warmup: it must stay 0.
16
+ - `createFog(THREE, scene, { stable: true })`: `clear()` leaves a neutral linear fog (near 6.0e4, far 6.4e4) instead of `null`.
17
+ - `createGeometryPool()` / `createMaterialPool()`: keys, use counts, `retain`/`register`, `own` for per-frame materials, `trim` at load
18
+ points, and a development warning when a pooled resource is disposed directly.
19
+
20
+ ```ts
21
+ import * as THREE from 'three'
22
+ import { createLightBudget, createProgramWarmup, LIGHT_PRIORITY } from '@adatechnology/game-render-three'
23
+
24
+ const budget = createLightBudget(THREE, scene, { point: 16, pointShadows: 2, spot: 4 })
25
+ const warmup = createProgramWarmup(THREE)
26
+ warmup.warmUp(renderer, scene, camera, { lights: budget, fogStates: ['linear', 'exp2'] }) // behind the loading screen
27
+
28
+ const flash = budget.acquire({ owner: 'weapons.muzzle', priority: LIGHT_PRIORITY.muzzle, urgent: true, color: 0xffcc88, intensity: 4, distance: 12, position: [0, 1.5, 0] })
29
+ budget.present([camera.position.x, camera.position.y, camera.position.z], dtSeconds) // once per frame
30
+ flash?.release()
31
+ ```
32
+
33
+ `three` is a peer dependency (`^0.160.0`) and is never imported as a value: pass your `THREE`. The pools read three's internal
34
+ `renderer.properties.get(material).programs` (r160); `programKeysOf` isolates that read, a test checks it against the installed three, and
35
+ when it is missing the pools keep every material (more memory, no recompilation).
@@ -0,0 +1,440 @@
1
+ import * as three from 'three';
2
+ import { Group, Object3D, HemisphereLight, Scene, Camera, WebGLRenderTarget, Fog, FogExp2, Material, Texture, BufferGeometry, Mesh } from 'three';
3
+
4
+ /** The one name of the three.js namespace in the kit. Packages narrow it with Pick<ThreeLib, ...>. */
5
+ type ThreeLib = typeof three;
6
+
7
+ type LightKind = 'point' | 'spot';
8
+ type LinearRgb = readonly [number, number, number];
9
+ type FogState = 'none' | 'linear' | 'exp2';
10
+ type ThreeForLights = Pick<ThreeLib, 'Group' | 'PointLight' | 'SpotLight' | 'HemisphereLight' | 'Object3D' | 'Vector3' | 'Color' | 'LinearSRGBColorSpace'>;
11
+ /** What the budget reads of a renderer: a structural subset, so a fake works in Node. */
12
+ type RendererState = {
13
+ readonly toneMapping: number;
14
+ readonly outputColorSpace: string;
15
+ readonly shadowMap: {
16
+ readonly type: number;
17
+ };
18
+ };
19
+ interface LightBudgetOptions {
20
+ /** Point lights created at boot. Default 16. */
21
+ readonly point?: number;
22
+ /** Spot lights created at boot. Default 4. */
23
+ readonly spot?: number;
24
+ /** How many of the point lights cast shadows (cube maps). Default 2. Fixed for the life of the budget. */
25
+ readonly pointShadows?: number;
26
+ /** How many of the spot lights cast shadows. Default 0. */
27
+ readonly spotShadows?: number;
28
+ /** Shadow map size of the shadow slots. Default 512. */
29
+ readonly shadowMapSize?: number;
30
+ /** 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. */
31
+ readonly shadowSettings?: {
32
+ readonly bias?: number;
33
+ readonly normalBias?: number;
34
+ readonly near?: number;
35
+ };
36
+ /** Point slots only `urgent` requests may take while others are free. Default 2. */
37
+ readonly urgentReserve?: number;
38
+ /** Milliseconds a light fades out when a source loses its slot, and fades in when it gets one. Default 120. */
39
+ readonly fadeMs?: number;
40
+ /** A source keeps its slot until a challenger of the same priority is this much closer (0.15 = 15%). Default 0.15. */
41
+ readonly hysteresis?: number;
42
+ /** HemisphereLights created at boot for adapters that flash the sky; leased with `leaseHemisphere`. Default 0. */
43
+ readonly hemisphere?: number;
44
+ }
45
+ /** A light that lives as long as the request: a blast, a rocket in flight, a muzzle flash, a flare in the hand. */
46
+ interface LightRequest {
47
+ readonly owner: string;
48
+ readonly kind?: LightKind;
49
+ /** Higher wins a slot; see LIGHT_PRIORITY. */
50
+ readonly priority: number;
51
+ /** Hex (sRGB, like `new Color(hex)`) or linear RGB. */
52
+ readonly color: number | LinearRgb;
53
+ readonly intensity: number;
54
+ readonly distance: number;
55
+ readonly decay?: number;
56
+ readonly position: readonly [number, number, number];
57
+ /** Spot only. */
58
+ readonly target?: readonly [number, number, number];
59
+ readonly angle?: number;
60
+ readonly penumbra?: number;
61
+ /** Takes a slot at once: cuts the lowest victim instead of fading it, and may use the urgent reserve. */
62
+ readonly urgent?: boolean;
63
+ /** Called once when a higher priority took the slot; the handle is dead from then on. */
64
+ readonly onLost?: () => void;
65
+ }
66
+ type LightPatch = Partial<Pick<LightRequest, 'color' | 'intensity' | 'distance' | 'decay' | 'position' | 'target' | 'angle' | 'penumbra'>>;
67
+ interface LightHandle {
68
+ /** Index of this light among the scene's point (or spot) lights in the shader; stable while the handle lives. */
69
+ readonly slot: number;
70
+ readonly kind: LightKind;
71
+ readonly alive: boolean;
72
+ update(patch: LightPatch): void;
73
+ /** Gives the slot back; with fadeMs the light fades first. Idempotent. */
74
+ release(options?: {
75
+ readonly fadeMs?: number;
76
+ }): void;
77
+ }
78
+ /** 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. */
79
+ interface LightSource extends Omit<LightRequest, 'urgent' | 'onLost'> {
80
+ /** Wants a shadow slot; a shadow source competes for shadow slots only. */
81
+ readonly shadow?: boolean;
82
+ /**
83
+ * 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
84
+ * once per `present`; `position` is then an offset in its local space. A source whose `follow` left the scene counts as off.
85
+ */
86
+ readonly follow?: Object3D;
87
+ }
88
+ interface SourceHandle {
89
+ /** Slot now, or -1 while it has none (its light is not drawn). */
90
+ readonly slot: number;
91
+ update(patch: Partial<LightSource>): void;
92
+ remove(): void;
93
+ }
94
+ /** Slots a client keeps for itself for good: the room lights of a house (their masks are indexed by slot). */
95
+ interface LightLease {
96
+ readonly handles: readonly LightHandle[];
97
+ /** Redraws the shadow map of one leased slot (`handles[index]`), or of all of them, on the next render: the walls it shades changed. */
98
+ invalidateShadow(index?: number): void;
99
+ release(): void;
100
+ }
101
+ interface SealOptions {
102
+ /** Fog states the game will switch between at run time. Default: only the state at seal time. */
103
+ readonly fogStates?: readonly FogState[];
104
+ /** Cameras whose `far` must stay under the neutral fog's near (read at every `check`). */
105
+ readonly cameras?: readonly Camera[];
106
+ /** Where the game really draws; its colour space is part of the sealed state. */
107
+ readonly target?: WebGLRenderTarget | null;
108
+ }
109
+ interface LightCheck {
110
+ readonly ok: boolean;
111
+ readonly expected: string;
112
+ readonly actual: string;
113
+ /** Paths of PointLight/SpotLight found outside the budget's group. */
114
+ readonly strays: readonly string[];
115
+ }
116
+ interface LightBudgetStats {
117
+ readonly lit: number;
118
+ readonly free: number;
119
+ readonly leased: number;
120
+ readonly sources: number;
121
+ readonly sourcesWithoutSlot: number;
122
+ readonly preempted: number;
123
+ readonly refused: number;
124
+ }
125
+ interface LightBudget {
126
+ /** The group holding every light; first child of the scene. Never hidden, never removed while the budget lives. */
127
+ readonly group: Group;
128
+ readonly sizes: {
129
+ readonly point: number;
130
+ readonly spot: number;
131
+ readonly pointShadows: number;
132
+ readonly spotShadows: number;
133
+ };
134
+ acquire(request: LightRequest): LightHandle | null;
135
+ addSource(source: LightSource): SourceHandle;
136
+ /** Takes `point` slots (of which `shadows` shadow slots) for good. null when not enough unleased slots remain. */
137
+ lease(options: {
138
+ readonly owner: string;
139
+ readonly point: number;
140
+ readonly shadows?: number;
141
+ }): LightLease | null;
142
+ /** Takes one of the boot HemisphereLights for good. null when none is left. Its intensity starts at 0. */
143
+ leaseHemisphere(owner: string): HemisphereLight | null;
144
+ /** Once per frame, with the camera (or the player) as focus. `dtSeconds` is real time: fades do not stop in pause. */
145
+ present(focus: readonly [number, number, number], dtSeconds: number): void;
146
+ /** After this, any change in the program-key state of the scene is a bug and `check()` reports it. */
147
+ seal(renderer: RendererState, scene: Scene, options?: SealOptions): void;
148
+ check(renderer: RendererState, scene: Scene): LightCheck;
149
+ stats(): LightBudgetStats;
150
+ dispose(): void;
151
+ }
152
+ declare const LIGHT_PRIORITY: {
153
+ readonly blast: 900;
154
+ readonly rocket: 800;
155
+ readonly muzzle: 750;
156
+ readonly fire: 600;
157
+ readonly flare: 500;
158
+ readonly headlight: 400;
159
+ readonly weaponLight: 400;
160
+ readonly lamp: 200;
161
+ readonly street: 150;
162
+ };
163
+
164
+ declare function createLightBudget(THREE: ThreeForLights, scene: Object3D, options?: LightBudgetOptions): LightBudget;
165
+
166
+ /** For adapters that receive the budget as `unknown` through the host (the contract does not know three). */
167
+ declare function isLightBudget(value: unknown): value is LightBudget;
168
+
169
+ /** Both exact in half precision (multiples of 32 under 65 504), so the neutral fog survives a `mediump` fragment shader. */
170
+ declare const NEUTRAL_FOG_NEAR = 60000;
171
+ declare const NEUTRAL_FOG_FAR = 64000;
172
+ interface FogOptions {
173
+ /** `clear()` leaves a neutral linear Fog instead of `null`: the fog presence and type never change, so no program recompiles. */
174
+ readonly stable?: boolean;
175
+ /** Colour of the neutral fog. Default 0x000000. */
176
+ readonly color?: number;
177
+ }
178
+ interface FogController {
179
+ useLinear(color: number, near: number, far: number): Fog;
180
+ useExp2(color: number, density: number): FogExp2;
181
+ /** Back to no fog: the original fog (or `null`); when `stable`, the host's own linear fog or the neutral one, never `null`. */
182
+ clear(): void;
183
+ }
184
+ declare function isNeutralFog(fog: unknown): boolean;
185
+ /** Writes into the scene's existing fog object when its type matches, as the weather layer does, so nothing is reallocated per change. */
186
+ declare function createFog(THREE: Pick<ThreeLib, 'Fog' | 'FogExp2'>, scene: Scene, options?: FogOptions): FogController;
187
+
188
+ /** What `programKeysOf` reads of a renderer: `properties` is internal to three r160 and may be absent in another version. */
189
+ type PropertiesReader = {
190
+ readonly properties?: {
191
+ get(object: object): unknown;
192
+ };
193
+ };
194
+ /**
195
+ * Every program cache key three linked for `material` (one per state it was drawn in: fog type, shadow, light counts). Reads three's
196
+ * internal `properties.get(material).programs` Map (r160). `[]` for a material never drawn; `undefined` when this three does not have
197
+ * that internal, which sends the pools to their conservative mode.
198
+ */
199
+ declare function programKeysOf(renderer: PropertiesReader, material: Material): readonly string[] | undefined;
200
+
201
+ /** Materials kept alive and never disposed, one per program family: what keeps a program linked once its users are gone. */
202
+ interface MaterialAnchors {
203
+ /**
204
+ * 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).
205
+ * A material whose keys are all covered returns false and may be disposed. A material never drawn is not kept.
206
+ */
207
+ offer(material: Material): boolean;
208
+ readonly size: number;
209
+ /** Where program keys are read from. Until bound (or when three has no readable keys) every offered material is kept. */
210
+ bind(renderer: PropertiesReader): void;
211
+ }
212
+ declare function createMaterialAnchors(renderer?: PropertiesReader): MaterialAnchors;
213
+
214
+ /** What `warmUpProbes()` of the adapters already returns: a group to draw once. */
215
+ interface WarmupProbe {
216
+ readonly id: string;
217
+ /**
218
+ * The group to draw once. `materials` are handed to the warmup's anchor set and are **never** disposed (their programs stay linked);
219
+ * `dispose` frees only what is not a material (geometries of the probe meshes, the group).
220
+ */
221
+ build(): {
222
+ readonly group: Object3D;
223
+ readonly materials: readonly Material[];
224
+ dispose(): void;
225
+ };
226
+ }
227
+ /** An effect played once at load so its programs are linked and its buffers and textures reach the GPU before play. */
228
+ interface EffectWarmup {
229
+ readonly id: string;
230
+ /** Starts the effect where the camera sees it. */
231
+ play(): void;
232
+ /** Advances it; the warmup renders after each step. */
233
+ step(dtSeconds: number): void;
234
+ /** Stops and clears everything it left (world, log, sound), keeping the pools filled. */
235
+ stop(): void;
236
+ /** Frames to render. Default 3. */
237
+ readonly frames?: number;
238
+ /**
239
+ * Where the effect draws. Given, only that subtree (and the lights) is drawn while the effect plays: its programs and buffers are what the frames
240
+ * are for, and the rest of the scene was already drawn in every fog state. Without it the whole scene is drawn each frame.
241
+ */
242
+ readonly root?: () => Object3D | null | undefined;
243
+ }
244
+ interface WarmupOptions {
245
+ readonly lights?: LightBudget;
246
+ /** Fog states to warm; passed on to `lights.seal`. Default: the state of the scene. */
247
+ readonly fogStates?: readonly FogState[];
248
+ /** Where the game really draws: the program key carries the target's colour space and tone mapping. Default null (the canvas). */
249
+ readonly target?: WebGLRenderTarget | null;
250
+ /**
251
+ * Materials drawn once each, on a one-triangle mesh (a sprite, points or line for those materials): the registered materials of a `MaterialPool`
252
+ * (`registeredMaterials()`), so every program the pools were told about is drawn before play, not only linked. Never disposed or anchored here.
253
+ */
254
+ readonly materials?: readonly Material[];
255
+ }
256
+ interface WarmupReport {
257
+ readonly programs: number;
258
+ readonly geometries: number;
259
+ readonly textures: number;
260
+ readonly milliseconds: number;
261
+ readonly lightSignature: string;
262
+ /** `MAX_FRAGMENT_UNIFORM_VECTORS` of this GPU. */
263
+ readonly uniformVectors: number;
264
+ /** Anchors kept alive (one material per program family). */
265
+ readonly anchors: number;
266
+ }
267
+ type WarmupContext = {
268
+ readonly RGBA?: number;
269
+ readonly UNSIGNED_BYTE?: number;
270
+ readPixels?(x: number, y: number, width: number, height: number, format: number, type: number, pixels: Uint8Array): void;
271
+ getParameter(parameter: number): unknown;
272
+ readonly MAX_FRAGMENT_UNIFORM_VECTORS: number;
273
+ linkProgram(program: WebGLProgram): void;
274
+ };
275
+ /** What the warmup needs of a WebGLRenderer: structural, so a counting fake works in Node. */
276
+ type WarmupRenderer = RendererState & PropertiesReader & {
277
+ compile(scene: Object3D, camera: Camera): unknown;
278
+ render(scene: Object3D, camera: Camera): void;
279
+ setRenderTarget(target: WebGLRenderTarget | null): void;
280
+ initTexture(texture: Texture): void;
281
+ getContext(): WarmupContext;
282
+ readonly info: {
283
+ readonly programs?: ReadonlyArray<object> | null;
284
+ readonly memory: {
285
+ readonly geometries: number;
286
+ readonly textures: number;
287
+ };
288
+ };
289
+ };
290
+ interface ProgramWarmup {
291
+ register(probe: WarmupProbe): () => void;
292
+ registerEffect(effect: EffectWarmup): () => void;
293
+ registerTexture(texture: Texture): () => void;
294
+ /** Seals the budget and the scene state, then warms. */
295
+ warmUp(renderer: WarmupRenderer, scene: Scene, camera: Camera, options?: WarmupOptions): WarmupReport;
296
+ /** Calls to `gl.linkProgram` since warmUp: should stay 0. Counts the calls, not `info.programs.length`, which can hide a release and relink. */
297
+ linkedSince(renderer: WarmupRenderer): number;
298
+ /** The anchor set: materials that are never disposed while the warmup lives. Pools and probes hand theirs here. */
299
+ readonly anchors: MaterialAnchors;
300
+ }
301
+
302
+ declare function createProgramWarmup(THREE: Pick<ThreeLib, 'Group' | 'Sprite' | 'SpriteMaterial' | 'DataTexture' | 'Fog' | 'FogExp2' | 'Mesh' | 'Points' | 'LineSegments' | 'BufferGeometry' | 'BufferAttribute'>): ProgramWarmup;
303
+
304
+ /** The sprite probes the room builds by hand today: one sprite material with fog and one without. */
305
+ declare function spriteProbes(THREE: Pick<ThreeLib, 'Group' | 'Sprite' | 'SpriteMaterial' | 'DataTexture'>): WarmupProbe;
306
+
307
+ interface GeometryPool {
308
+ /** The geometry for `key`, built once with `build`. Counts one use. */
309
+ acquire(key: string, build: () => BufferGeometry): BufferGeometry;
310
+ release(geometry: BufferGeometry): void;
311
+ /** Never disposed while the pool lives (unit shapes, effect geometries warmed at load). */
312
+ retain(key: string): void;
313
+ /** Disposes unretained geometries with no use, oldest first, keeping at most `keep` idle ones. Only at load points, never in play. */
314
+ trim(keep?: number): number;
315
+ stats(): {
316
+ readonly entries: number;
317
+ readonly retained: number;
318
+ readonly inUse: number;
319
+ };
320
+ dispose(): void;
321
+ }
322
+ /** Builds a key from a kind and its numbers, rounded to `step`, so near-equal sizes share one geometry. */
323
+ declare function geometryKey(kind: string, params: readonly number[], step?: number): string;
324
+ declare function createGeometryPool(): GeometryPool;
325
+
326
+ interface MaterialPool {
327
+ /**
328
+ * The material for `key`, built once. Shared: callers must not change it. Per-instance variety goes into instance attributes, not
329
+ * into new materials.
330
+ */
331
+ acquire<TMaterial extends Material>(key: string, build: () => TMaterial): TMaterial;
332
+ release(material: Material): void;
333
+ /** Declares a variant that must never be disposed (its program stays linked). Effects register theirs at load. */
334
+ register<TMaterial extends Material>(key: string, build: () => TMaterial): TMaterial;
335
+ /**
336
+ * 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
337
+ * handed to the anchors, so disposing the others never frees the program.
338
+ */
339
+ own<TMaterial extends Material>(build: () => TMaterial): TMaterial;
340
+ /** The materials declared with `register`: the ones that must never be disposed and whose programs the warmup draws once. */
341
+ registeredMaterials?(): readonly Material[];
342
+ /** Disposes unregistered materials with no use, oldest first, keeping at most `keep` idle ones; a family's anchor is kept alive. */
343
+ trim(keep?: number): number;
344
+ stats(): {
345
+ readonly entries: number;
346
+ readonly registered: number;
347
+ readonly inUse: number;
348
+ readonly families: number;
349
+ };
350
+ /**
351
+ * The end of the pool: disposes every material it made, in use or not, registered or anchored (the guarantee that a program stays linked
352
+ * holds while the pool lives, not after it). The anchors object itself is not touched, and the pool is empty and usable again afterwards.
353
+ */
354
+ dispose(): void;
355
+ }
356
+ type MaterialPoolOptions = {
357
+ readonly anchors?: MaterialAnchors;
358
+ readonly renderer?: PropertiesReader;
359
+ };
360
+ /** Key from the material class and every parameter that changes its look, sorted, numbers rounded. */
361
+ declare function materialKey(type: string, params: Readonly<Record<string, unknown>>): string;
362
+ declare function createMaterialPool(options?: MaterialPoolOptions): MaterialPool;
363
+
364
+ /** The pools a host lends its adapters (`host.pools`): geometries and materials that outlive the effect that asked for them. */
365
+ interface RenderPools {
366
+ readonly geometries: GeometryPool;
367
+ readonly materials: MaterialPool;
368
+ }
369
+ /** For adapters that receive the pools as `unknown` through the host (the contract does not know three). */
370
+ declare function isRenderPools(value: unknown): value is RenderPools;
371
+
372
+ /** The part of a WebGL2 context the pacer reads; the renderer's `getContext()` satisfies it. */
373
+ type FramePacerContext = {
374
+ readonly SYNC_GPU_COMMANDS_COMPLETE: number;
375
+ readonly TIMEOUT_EXPIRED: number;
376
+ fenceSync(condition: number, flags: number): WebGLSync | null;
377
+ clientWaitSync(sync: WebGLSync, flags: number, timeout: number): number;
378
+ deleteSync(sync: WebGLSync | null): void;
379
+ flush(): void;
380
+ };
381
+ type FramePacerOptions = {
382
+ /** 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. */
383
+ readonly maxSkips?: number;
384
+ /** 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. */
385
+ readonly framesInFlight?: number;
386
+ };
387
+ type FramePacer = {
388
+ /** 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. */
389
+ ready(): boolean;
390
+ /** Fences the frame just drawn; call it right after the render. */
391
+ submitted(): void;
392
+ /** Draws held back so far. */
393
+ readonly skipped: number;
394
+ dispose(): void;
395
+ };
396
+ /**
397
+ * 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
398
+ * 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
399
+ * 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.
400
+ */
401
+ declare function createFramePacer(context: FramePacerContext | null, options?: FramePacerOptions): FramePacer;
402
+
403
+ /** The layer a batched mesh is moved to: no camera draws it, a raycaster that enables every layer still finds it. */
404
+ declare const BATCHED_LAYER = 30;
405
+ type StaticBatcherOptions = {
406
+ /** Which meshes may be batched (default every shown mesh with one material and no instancing, skinning or morphing). */
407
+ readonly include?: (mesh: Mesh) => boolean;
408
+ /** Milliseconds of merging per `update` (default all at once, in the call): batches are made a material at a time over the next frames. */
409
+ readonly budgetMs?: number;
410
+ /**
411
+ * 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
412
+ * wherever it goes, and only a new geometry, material, dent or hiding gives it its own draw back.
413
+ */
414
+ readonly followMeshes?: boolean;
415
+ };
416
+ type StaticBatcherStats = {
417
+ readonly batches: number;
418
+ readonly batched: number;
419
+ readonly released: number;
420
+ };
421
+ type StaticBatcher = {
422
+ /** The batch meshes, a child of the root. */
423
+ readonly group: Object3D;
424
+ /**
425
+ * Gives back to its own draw every batched mesh that changed since the batch was made (moved, dented, hidden, given another geometry or
426
+ * material); returns how many it released. Call it once per frame, before the render.
427
+ */
428
+ update(): number;
429
+ stats(): StaticBatcherStats;
430
+ /** Every mesh draws on its own again and the batches are disposed. */
431
+ dispose(): void;
432
+ };
433
+ /**
434
+ * 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
435
+ * 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
436
+ * camera's layer while batched.
437
+ */
438
+ declare function createStaticBatcher(THREE: ThreeLib, root: Object3D, options?: StaticBatcherOptions): StaticBatcher;
439
+
440
+ export { BATCHED_LAYER, type EffectWarmup, type FogController, type FogOptions, type FogState, type FramePacer, type FramePacerContext, type FramePacerOptions, type GeometryPool, LIGHT_PRIORITY, type LightBudget, type LightBudgetOptions, type LightBudgetStats, type LightCheck, type LightHandle, type LightKind, type LightLease, type LightPatch, type LightRequest, type LightSource, type LinearRgb, type MaterialAnchors, type MaterialPool, type MaterialPoolOptions, NEUTRAL_FOG_FAR, NEUTRAL_FOG_NEAR, type ProgramWarmup, type PropertiesReader, type RenderPools, type RendererState, type SealOptions, type SourceHandle, type StaticBatcher, type StaticBatcherOptions, type StaticBatcherStats, type ThreeForLights, type ThreeLib, type WarmupContext, type WarmupOptions, type WarmupProbe, type WarmupRenderer, type WarmupReport, createFog, createFramePacer, createGeometryPool, createLightBudget, createMaterialAnchors, createMaterialPool, createProgramWarmup, createStaticBatcher, geometryKey, isLightBudget, isNeutralFog, isRenderPools, materialKey, programKeysOf, spriteProbes };