@react-three/tsl 10.0.0-canary.d5cebb9 → 10.0.0-canary.d8aec34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +234 -99
- package/dist/index.d.cts +354 -105
- package/dist/index.d.mts +354 -105
- package/dist/index.d.ts +354 -105
- package/dist/index.mjs +235 -100
- package/package.json +2 -2
- package/readme.md +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RootState, useStore } from '@react-three/fiber/extension';
|
|
2
2
|
import * as three_webgpu from 'three/webgpu';
|
|
3
3
|
import { Node, StorageTexture, Storage3DTexture, StorageArrayTexture, Data3DTexture, RenderPipeline, Vector2, Vector3, Vector4, Color, Matrix2, Matrix3, Matrix4 } from 'three/webgpu';
|
|
4
|
+
import { Fn } from 'three/tsl';
|
|
4
5
|
|
|
5
6
|
//* Buffer Types (useBuffers) ========================================
|
|
6
7
|
|
|
@@ -57,6 +58,40 @@ type NodeRecord<T extends NodeLike = NodeLike> = Record<string, T>
|
|
|
57
58
|
*/
|
|
58
59
|
type NodeStore = Record<string, NodeLike | NodeRecord>
|
|
59
60
|
|
|
61
|
+
/** What `Fn()` returns (its members are what matters here, not its signature). */
|
|
62
|
+
type FnNodeLike = ReturnType<typeof Fn>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* What an unregistered node read is: `useNodes().wobble`, `useNodes('fx').blur`, a creator's
|
|
66
|
+
* `nodes.wobble`, `state.nodes.wobble` in `useFrame`.
|
|
67
|
+
*
|
|
68
|
+
* Why it is loose: the read goes through a string name, and TypeScript cannot know what the entry
|
|
69
|
+
* under that name holds: a float, a vec3, a texture sample, or an `Fn()` to call. three's types
|
|
70
|
+
* only give operator methods to a node whose node type is known, and only an `Fn()` can be called,
|
|
71
|
+
* so the broad `NodeLike` allowed neither and every read needed a cast.
|
|
72
|
+
*
|
|
73
|
+
* So this has every member that any of three's nodes or an `Fn()` has, each typed `any`, and can
|
|
74
|
+
* be called. `nodes.wobble.mul(2)`, `material.colorNode = nodes.wobble` and `nodes.rimLightFn()`
|
|
75
|
+
* compile, and a misspelt member is still an error. It is a deliberate simplification: results of
|
|
76
|
+
* its own methods and calls are `any`.
|
|
77
|
+
*
|
|
78
|
+
* A single `as` gives it an exact type: `nodes.wobble as Node<'vec3'>`, `nodes.fn as typeof fn`.
|
|
79
|
+
* For exact types without casts, register the nodes (`nodes` / `nodeScopes` in `Register`) or pass
|
|
80
|
+
* a schema to the reader: `useNodes<{ blur: Node<'vec4'> }>('fx')`, `nodes.scope<Schema>('fx')`.
|
|
81
|
+
*/
|
|
82
|
+
interface LooseNode extends TSLLooseMembers<Node<TSLNodeTypeName> | FnNodeLike> {
|
|
83
|
+
(...args: any[]): any
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A root entry of an unregistered node map: a node (its members) or a scope of nodes (any other
|
|
88
|
+
* name), since the type cannot tell which a name holds.
|
|
89
|
+
*/
|
|
90
|
+
type LooseNodeEntry = LooseNode & { readonly [name: string]: LooseNode }
|
|
91
|
+
|
|
92
|
+
/** An unregistered node map read: `state.nodes`, `useNodes()`. */
|
|
93
|
+
type LooseNodeStore = Record<string, LooseNodeEntry>
|
|
94
|
+
|
|
60
95
|
//* Storage Types (useGPUStorage) ========================================
|
|
61
96
|
|
|
62
97
|
/**
|
|
@@ -93,17 +128,23 @@ type StorageStore = Record<string, StorageLike | StorageRecord>
|
|
|
93
128
|
*/
|
|
94
129
|
interface TSLRootState {
|
|
95
130
|
/**
|
|
96
|
-
* TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms().
|
|
97
|
-
*
|
|
98
|
-
* needs no cast.
|
|
131
|
+
* TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms(). Each read is a
|
|
132
|
+
* `LooseUniformNode`, usable without casts, or typed by name once you register them (see
|
|
133
|
+
* `Register`), so `useFrame(({ uniforms }) => uniforms.uTime.value)` needs no cast either way.
|
|
99
134
|
*/
|
|
100
135
|
uniforms: AppUniforms
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
136
|
+
/**
|
|
137
|
+
* TSL nodes - root-level nodes + scoped sub-objects. Use useNodes(). Each read is a `LooseNode`,
|
|
138
|
+
* usable without casts, or typed by name once you register your nodes (see `Register`).
|
|
139
|
+
*/
|
|
140
|
+
nodes: AppNodes
|
|
141
|
+
/** Buffers - root-level buffers + scoped sub-objects. Use useBuffers(). Typed by name once registered */
|
|
142
|
+
buffers: AppBuffers
|
|
143
|
+
/**
|
|
144
|
+
* GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage().
|
|
145
|
+
* Typed by name once registered
|
|
146
|
+
*/
|
|
147
|
+
gpuStorage: AppGPUStorage
|
|
107
148
|
/** Internal: bumped by hot reloads and rebuilds to re-run creators */
|
|
108
149
|
_hmrVersion: number
|
|
109
150
|
/** The canvas's RenderPipeline, once useRenderPipeline created one. Per canvas, not shared. */
|
|
@@ -113,17 +154,11 @@ interface TSLRootState {
|
|
|
113
154
|
}
|
|
114
155
|
|
|
115
156
|
// Every fiber entry shares one core, and so one RootState: augmenting it through the root entry
|
|
116
|
-
// reaches /legacy
|
|
157
|
+
// reaches /legacy and /extension as well.
|
|
117
158
|
declare module '@react-three/fiber' {
|
|
118
159
|
interface RootState extends TSLRootState {}
|
|
119
160
|
}
|
|
120
161
|
|
|
121
|
-
// /webgpu exports WebGPURootState as RootState. Augmenting the base state it extends reaches both,
|
|
122
|
-
// and also the stores (useStore(), get(), primaryStore) typed with the base.
|
|
123
|
-
declare module '@react-three/fiber/webgpu' {
|
|
124
|
-
interface BaseRootState extends TSLRootState {}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
162
|
declare module '@react-three/fiber/extension' {
|
|
128
163
|
interface RootState extends TSLRootState {}
|
|
129
164
|
}
|
|
@@ -149,6 +184,16 @@ declare global {
|
|
|
149
184
|
/** Node type accepted by broad dynamic node-store readers. */
|
|
150
185
|
type TSLNodeType = three_webgpu.Node | CallableTSLNode
|
|
151
186
|
|
|
187
|
+
/**
|
|
188
|
+
* What TSL's constant constructors return: `int(1)`, `vec2(0, 1)`, `color('red')` and friends
|
|
189
|
+
* wrap a ConstNode in a VarNode. three's `uniform()` unwraps exactly this shape to
|
|
190
|
+
* `UniformNode<TNodeType, TValue>`, and so do the mappings below.
|
|
191
|
+
*/
|
|
192
|
+
type TSLConstNode<TNodeType, TValue> = three_webgpu.VarNode<
|
|
193
|
+
TNodeType,
|
|
194
|
+
three_webgpu.ConstNode<TNodeType, TValue>
|
|
195
|
+
>
|
|
196
|
+
|
|
152
197
|
/**
|
|
153
198
|
* Derive Three's shader node type from an existing node or a supported raw input.
|
|
154
199
|
* Existing InputNode generics take precedence over structural value normalization.
|
|
@@ -159,44 +204,48 @@ declare global {
|
|
|
159
204
|
? TNodeType
|
|
160
205
|
: T extends three_webgpu.InputNode<infer TNodeType, infer _TValue>
|
|
161
206
|
? TNodeType
|
|
162
|
-
: T extends
|
|
163
|
-
?
|
|
164
|
-
: T extends
|
|
165
|
-
? '
|
|
166
|
-
: T extends
|
|
167
|
-
? '
|
|
168
|
-
: T extends three_webgpu.
|
|
169
|
-
? '
|
|
170
|
-
: T extends three_webgpu.
|
|
171
|
-
? '
|
|
172
|
-
: T extends three_webgpu.
|
|
173
|
-
? '
|
|
174
|
-
: T extends three_webgpu.
|
|
175
|
-
? '
|
|
176
|
-
: T extends three_webgpu.
|
|
177
|
-
? '
|
|
178
|
-
: T extends three_webgpu.
|
|
179
|
-
? '
|
|
180
|
-
:
|
|
207
|
+
: T extends TSLConstNode<infer TNodeType, infer _TValue>
|
|
208
|
+
? TNodeType
|
|
209
|
+
: T extends number
|
|
210
|
+
? 'float'
|
|
211
|
+
: T extends boolean
|
|
212
|
+
? 'bool'
|
|
213
|
+
: T extends string | three_webgpu.Color | { r: number; g: number; b: number }
|
|
214
|
+
? 'color'
|
|
215
|
+
: T extends three_webgpu.Vector4 | { x: number; y: number; z: number; w: number }
|
|
216
|
+
? 'vec4'
|
|
217
|
+
: T extends three_webgpu.Vector3 | { x: number; y: number; z: number }
|
|
218
|
+
? 'vec3'
|
|
219
|
+
: T extends three_webgpu.Vector2 | { x: number; y: number }
|
|
220
|
+
? 'vec2'
|
|
221
|
+
: T extends three_webgpu.Matrix4
|
|
222
|
+
? 'mat4'
|
|
223
|
+
: T extends three_webgpu.Matrix3
|
|
224
|
+
? 'mat3'
|
|
225
|
+
: T extends three_webgpu.Matrix2
|
|
226
|
+
? 'mat2'
|
|
227
|
+
: unknown
|
|
181
228
|
|
|
182
229
|
/** Derive the normalized JavaScript value stored by a uniform node. */
|
|
183
230
|
type UniformNodeValue<T> = T extends three_webgpu.UniformNode<infer _TNodeType, infer TValue>
|
|
184
231
|
? TValue
|
|
185
232
|
: T extends three_webgpu.InputNode<infer _TNodeType, infer TValue>
|
|
186
233
|
? TValue
|
|
187
|
-
: T extends
|
|
188
|
-
?
|
|
189
|
-
: T extends
|
|
190
|
-
? three_webgpu.
|
|
191
|
-
: T extends { x: number; y: number; z: number }
|
|
192
|
-
? three_webgpu.
|
|
193
|
-
: T extends { x: number; y: number }
|
|
194
|
-
? three_webgpu.
|
|
195
|
-
: T extends number
|
|
196
|
-
?
|
|
197
|
-
: T extends
|
|
198
|
-
?
|
|
199
|
-
: T
|
|
234
|
+
: T extends TSLConstNode<infer _TNodeType, infer TValue>
|
|
235
|
+
? TValue
|
|
236
|
+
: T extends string | { r: number; g: number; b: number }
|
|
237
|
+
? three_webgpu.Color
|
|
238
|
+
: T extends { x: number; y: number; z: number; w: number }
|
|
239
|
+
? three_webgpu.Vector4
|
|
240
|
+
: T extends { x: number; y: number; z: number }
|
|
241
|
+
? three_webgpu.Vector3
|
|
242
|
+
: T extends { x: number; y: number }
|
|
243
|
+
? three_webgpu.Vector2
|
|
244
|
+
: T extends number
|
|
245
|
+
? number
|
|
246
|
+
: T extends boolean
|
|
247
|
+
? boolean
|
|
248
|
+
: T
|
|
200
249
|
|
|
201
250
|
/** Three's exact UniformNode with shader and value generics derived from an input. */
|
|
202
251
|
type UniformNodeFor<T> = three_webgpu.UniformNode<UniformNodeType<T>, UniformNodeValue<T>>
|
|
@@ -219,6 +268,69 @@ declare global {
|
|
|
219
268
|
*/
|
|
220
269
|
type UniformStore = Record<string, UniformNode | UniformRecord>
|
|
221
270
|
|
|
271
|
+
//* Loose reads ==============================
|
|
272
|
+
|
|
273
|
+
/** Every shader node type three's TSL declarations type separately. */
|
|
274
|
+
type TSLNodeTypeName =
|
|
275
|
+
| 'float'
|
|
276
|
+
| 'int'
|
|
277
|
+
| 'uint'
|
|
278
|
+
| 'bool'
|
|
279
|
+
| 'vec2'
|
|
280
|
+
| 'vec3'
|
|
281
|
+
| 'vec4'
|
|
282
|
+
| 'ivec2'
|
|
283
|
+
| 'ivec3'
|
|
284
|
+
| 'ivec4'
|
|
285
|
+
| 'uvec2'
|
|
286
|
+
| 'uvec3'
|
|
287
|
+
| 'uvec4'
|
|
288
|
+
| 'bvec2'
|
|
289
|
+
| 'bvec3'
|
|
290
|
+
| 'bvec4'
|
|
291
|
+
| 'color'
|
|
292
|
+
| 'mat2'
|
|
293
|
+
| 'mat3'
|
|
294
|
+
| 'mat4'
|
|
295
|
+
|
|
296
|
+
/** Every member of every constituent of `T`, each typed `any`. */
|
|
297
|
+
type TSLLooseMembers<T> = { [K in T extends unknown ? keyof T : never]: any }
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* What an unregistered uniform read is: `useUniforms().uTime`, `useUniforms('fx').blur`,
|
|
301
|
+
* `useUniform('uTime')`, a creator's `uniforms.uTime`, `state.uniforms.uTime` in `useFrame`.
|
|
302
|
+
*
|
|
303
|
+
* Why it is loose: the read goes through a string name, and TypeScript cannot know what a
|
|
304
|
+
* runtime entry under that name holds. three's types only give the operator methods (`.mul`,
|
|
305
|
+
* `.add`, swizzles, `.toVar()`, ...) to a node whose node type is known, so `UniformNode<unknown>`
|
|
306
|
+
* had none of them and every read needed a cast.
|
|
307
|
+
*
|
|
308
|
+
* So this has every member that any of three's uniform nodes has (float, vec3, color, mat4, ...),
|
|
309
|
+
* each typed `any`. Every operator, TSL function and material slot accepts it, and a misspelt member
|
|
310
|
+
* (`.valeu`) is still an error. It is a deliberate simplification: results of its own methods are
|
|
311
|
+
* `any`, and nothing checks that `cross()` gets a vec3.
|
|
312
|
+
*
|
|
313
|
+
* It converts to an exact type with a single `as`, since every member is `any`:
|
|
314
|
+
* `uniforms.uColor as UniformNode<'color', Color>`, or `as Node<'vec3'>`. A node typed as a float
|
|
315
|
+
* uniform would cover the operators with exact result types, but three's node types are not
|
|
316
|
+
* comparable to one another, so it could only be cast through `unknown`.
|
|
317
|
+
*
|
|
318
|
+
* Exact types without casts: register the uniforms (`Register` in `@react-three/tsl`, which also
|
|
319
|
+
* catches typos in the name), or pass a schema to the reader (`useUniforms<{ blur: number }>('fx')`,
|
|
320
|
+
* `useUniform<Color>('uColor')`, `uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')`).
|
|
321
|
+
*/
|
|
322
|
+
interface LooseUniformNode extends TSLLooseMembers<three_webgpu.UniformNode<TSLNodeTypeName, any>> {}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* A root entry of an unregistered uniform map: a uniform (its members) or a scope of uniforms (any
|
|
326
|
+
* other name), since the type cannot tell which a name holds. `uniforms.uTime.mul(2)` and
|
|
327
|
+
* `uniforms.player.uHealth` both read.
|
|
328
|
+
*/
|
|
329
|
+
type LooseUniformEntry = LooseUniformNode & { readonly [name: string]: LooseUniformNode }
|
|
330
|
+
|
|
331
|
+
/** An unregistered uniform map read: `state.uniforms`, `useUniforms()`. */
|
|
332
|
+
type LooseUniformStore = Record<string, LooseUniformEntry>
|
|
333
|
+
|
|
222
334
|
/**
|
|
223
335
|
* Helper to safely access a uniform node from the store.
|
|
224
336
|
* Use this when accessing state.uniforms to get proper typing.
|
|
@@ -300,13 +412,18 @@ declare global {
|
|
|
300
412
|
/**
|
|
301
413
|
* State passed to pipeline callbacks after the active pipeline has been created.
|
|
302
414
|
*
|
|
415
|
+
* The same state `useNodes` / `useLocalNodes` creators get: `uniforms`, `nodes`, `buffers`,
|
|
416
|
+
* `gpuStorage` and `textures` are the wrapped views, entries staged earlier in the render
|
|
417
|
+
* included. Reads through them are tracked, so a read resource that appears, is replaced or is
|
|
418
|
+
* removed re-runs the callbacks.
|
|
419
|
+
*
|
|
303
420
|
* `passes.scenePass` is required here: the hook installs the default scene pass before either
|
|
304
421
|
* callback runs, so callbacks can use it without a guard or a cast.
|
|
305
422
|
*
|
|
306
423
|
* `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
|
|
307
424
|
* the legacy renderer before either callback can run, so a callback never sees WebGL.
|
|
308
425
|
*/
|
|
309
|
-
type RenderPipelineCallbackState =
|
|
426
|
+
type RenderPipelineCallbackState = CreatorState & {
|
|
310
427
|
renderPipeline: ThreeRenderPipeline
|
|
311
428
|
passes: PassRecord & { scenePass: ScenePassNode }
|
|
312
429
|
renderer: three_webgpu.WebGPURenderer
|
|
@@ -317,7 +434,7 @@ declare global {
|
|
|
317
434
|
* What a callback may return to register entries into `state.passes`.
|
|
318
435
|
*
|
|
319
436
|
* `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
|
|
320
|
-
* created, and `rebuild()
|
|
437
|
+
* created, and `rebuild()`, `reset()` and unmount dispose that cached pass. A callback overwriting the
|
|
321
438
|
* store entry would leave the store pointing at a node the hook never disposes, and the hook
|
|
322
439
|
* disposing a pass nothing references. So returning it is a type error.
|
|
323
440
|
*/
|
|
@@ -329,15 +446,31 @@ declare global {
|
|
|
329
446
|
/** Main callback - runs second to configure outputNode, create effect passes */
|
|
330
447
|
type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
|
|
331
448
|
|
|
449
|
+
/** Options for a configuring useRenderPipeline call */
|
|
450
|
+
interface RenderPipelineOptions {
|
|
451
|
+
/**
|
|
452
|
+
* Keep the pipeline rendering after the component unmounts, until another component configures
|
|
453
|
+
* the canvas's pipeline, `reset()`, or the canvas unmounts. Off by default: an owner frees its
|
|
454
|
+
* pipeline and scene pass when it unmounts. A remount is a new owner with a new pipeline either way.
|
|
455
|
+
*/
|
|
456
|
+
persist?: boolean
|
|
457
|
+
}
|
|
458
|
+
|
|
332
459
|
/** The imperative half of useRenderPipeline's return value, present in every state */
|
|
333
460
|
interface UseRenderPipelineActions {
|
|
334
461
|
/** Current passes from state */
|
|
335
462
|
passes: PassRecord
|
|
336
|
-
/** Clear
|
|
463
|
+
/** Clear the passes record. From a reader, acts on the pipeline that is rendering. */
|
|
337
464
|
clearPasses: () => void
|
|
338
|
-
/**
|
|
465
|
+
/**
|
|
466
|
+
* Free the pipeline and its scene pass now. The previous owner takes over, or the canvas
|
|
467
|
+
* goes back to plain rendering. From a reader, acts on the pipeline that is rendering.
|
|
468
|
+
*/
|
|
339
469
|
reset: () => void
|
|
340
|
-
/**
|
|
470
|
+
/**
|
|
471
|
+
* Re-run setup/main callbacks with current closure values, against a fresh scene pass. From
|
|
472
|
+
* a reader, rebuilds the pipeline that is rendering.
|
|
473
|
+
*/
|
|
341
474
|
rebuild: () => void
|
|
342
475
|
}
|
|
343
476
|
|
|
@@ -357,9 +490,9 @@ declare global {
|
|
|
357
490
|
renderPipeline: ThreeRenderPipeline
|
|
358
491
|
}
|
|
359
492
|
| {
|
|
360
|
-
/** False until
|
|
493
|
+
/** False until a configuring call has created the pipeline */
|
|
361
494
|
isReady: false
|
|
362
|
-
/**
|
|
495
|
+
/** No owner yet, or torn down by reset() or the owner unmounting */
|
|
363
496
|
renderPipeline: null
|
|
364
497
|
}
|
|
365
498
|
)
|
|
@@ -381,13 +514,14 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
|
381
514
|
*
|
|
382
515
|
* @example
|
|
383
516
|
* ```tsx
|
|
384
|
-
* // With uniforms registered (see `Register` and the Typed
|
|
517
|
+
* // With uniforms registered (see `Register` and the Typed Resources guide), reads are typed by name
|
|
385
518
|
* useLocalNodes(({ uniforms }) => ({
|
|
386
519
|
* wobble: sin(uniforms.uTime.mul(2)),
|
|
387
520
|
* playerHealth: uniforms.scope('player').uHealth, // or uniforms.player.uHealth
|
|
388
521
|
* }), [])
|
|
389
522
|
*
|
|
390
|
-
* // Without registration
|
|
523
|
+
* // Without registration a read is loose: TSL takes it as is. A scope schema makes it exact.
|
|
524
|
+
* useLocalNodes(({ uniforms }) => ({ wobble: sin(uniforms.uTime.mul(2)) }), [])
|
|
391
525
|
* useLocalNodes(({ uniforms }) => {
|
|
392
526
|
* const player = uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')
|
|
393
527
|
* return { damage: player.uHealth.mul(2) }
|
|
@@ -400,16 +534,19 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
|
400
534
|
* Property access returns `T` (assumes leaf node).
|
|
401
535
|
* Use `.scope(key)` for nested object access.
|
|
402
536
|
*
|
|
537
|
+
* `TLeaf` is what a scope schema must hold (`scope<{ uHealth: UniformNode<'float', number> }>()`),
|
|
538
|
+
* `TRead` what a leaf reads as without one. They differ for uniforms and nodes, whose unregistered
|
|
539
|
+
* reads are the loose `LooseUniformNode` / `LooseNode` (see those types for why).
|
|
403
540
|
*/
|
|
404
|
-
type ScopedStoreMethods<TLeaf> = {
|
|
541
|
+
type ScopedStoreMethods<TLeaf, TRead extends TLeaf = TLeaf> = {
|
|
405
542
|
/** Access a nested scope by key. Returns empty wrapper if scope doesn't exist. */
|
|
406
|
-
scope<TScope extends Record<string, TLeaf> = Record<string,
|
|
543
|
+
scope<TScope extends Record<string, TLeaf> = Record<string, TRead>>(key: string): ScopedStoreType<TLeaf, TScope, TRead>;
|
|
407
544
|
/** Check if a key exists in the store */
|
|
408
545
|
has(key: string): boolean;
|
|
409
546
|
/** Get all keys in the store */
|
|
410
547
|
keys(): string[];
|
|
411
548
|
};
|
|
412
|
-
type ScopedStoreType<TLeaf, TEntries extends Record<string, TLeaf> = Record<string, TLeaf
|
|
549
|
+
type ScopedStoreType<TLeaf, TEntries extends Record<string, TLeaf> = Record<string, TLeaf>, TRead extends TLeaf = TLeaf> = Readonly<TEntries> & ScopedStoreMethods<TLeaf, TRead>;
|
|
413
550
|
interface ScopedStoreData<TLeaf> {
|
|
414
551
|
[key: string]: TLeaf | ScopedStoreData<TLeaf>;
|
|
415
552
|
}
|
|
@@ -426,18 +563,18 @@ declare function createScopedStore<TLeaf>(data: ScopedStoreData<TLeaf>, isLeaf:
|
|
|
426
563
|
type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStorage'> & {
|
|
427
564
|
/** Type-safe uniform access - property access returns UniformNode, typed by name when registered */
|
|
428
565
|
uniforms: CreatorUniforms;
|
|
429
|
-
/**
|
|
430
|
-
nodes:
|
|
431
|
-
/**
|
|
432
|
-
buffers:
|
|
433
|
-
/**
|
|
434
|
-
gpuStorage:
|
|
566
|
+
/** Node access: each read a `LooseNode` (callable, every operator), typed by name when registered */
|
|
567
|
+
nodes: CreatorNodes;
|
|
568
|
+
/** Buffer access: typed by name when registered, BufferLike (typed arrays, attributes, nodes) otherwise */
|
|
569
|
+
buffers: CreatorBuffers;
|
|
570
|
+
/** GPU storage access: typed by name when registered, StorageLike (storage textures, nodes) otherwise */
|
|
571
|
+
gpuStorage: CreatorGPUStorage;
|
|
435
572
|
};
|
|
436
573
|
|
|
437
574
|
/**
|
|
438
|
-
* @fileoverview Typed
|
|
575
|
+
* @fileoverview Typed TSL resources by registration (the TanStack Router `Register` pattern).
|
|
439
576
|
*
|
|
440
|
-
* Nothing registered: every type below falls back to
|
|
577
|
+
* Nothing registered: every type below falls back to loose reads (`LooseUniformNode`, `LooseNode`).
|
|
441
578
|
* Registered once, anywhere in the app:
|
|
442
579
|
*
|
|
443
580
|
* ```ts
|
|
@@ -457,14 +594,25 @@ type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStora
|
|
|
457
594
|
*
|
|
458
595
|
* then `useUniforms().uTime`, `useUniforms('player').uHealth`, `useUniform('uTime')`,
|
|
459
596
|
* `useFrame(({ uniforms }) => uniforms.uTime)`, `useThree((s) => s.uniforms.uTime)` and a creator's
|
|
460
|
-
* `({ uniforms }) => uniforms.uTime` are typed by name, with no generics.
|
|
597
|
+
* `({ uniforms }) => uniforms.uTime` are typed by name, with no generics. Nodes register the same
|
|
598
|
+
* way, by their node types: `nodes: { wobble: Node<'float'>; rimLight: typeof rimLightFn }` and
|
|
599
|
+
* `nodeScopes: { fx: { blur: Node<'vec4'> } }`, and so do buffers (`buffers` / `bufferScopes`) and
|
|
600
|
+
* GPU storage (`gpuStorage` / `gpuStorageScopes`). Docs: docs/webgpu/typed-resources.mdx.
|
|
601
|
+
*
|
|
602
|
+
* Unregistered reads are loose: `LooseUniformNode` / `LooseNode`, which every operator accepts and
|
|
603
|
+
* a single `as` makes exact (see those types for why).
|
|
461
604
|
*/
|
|
462
605
|
|
|
463
606
|
/**
|
|
464
|
-
* Augment this to type
|
|
607
|
+
* Augment this to type TSL resources by name. Recognised keys:
|
|
465
608
|
* - `uniforms`: the root-level uniform inputs (e.g. `typeof globalUniforms`)
|
|
466
|
-
* - `scopes`: named scopes and their inputs (e.g. `{ player: typeof playerUniforms }`)
|
|
467
|
-
* - `
|
|
609
|
+
* - `scopes`: named uniform scopes and their inputs (e.g. `{ player: typeof playerUniforms }`)
|
|
610
|
+
* - `nodes`: the root-level nodes by node type (e.g. `{ wobble: Node<'float'>; rim: typeof rimFn }`)
|
|
611
|
+
* - `nodeScopes`: named node scopes and their nodes (e.g. `{ fx: { blur: Node<'vec4'> } }`)
|
|
612
|
+
* - `buffers` / `bufferScopes`: buffers by name (e.g. `{ positions: StorageBufferNode<'vec3'> }`)
|
|
613
|
+
* - `gpuStorage` / `gpuStorageScopes`: GPU storage by name (e.g. `{ heightMap: StorageTexture }`)
|
|
614
|
+
* - `strict`: `false` makes unregistered root keys loose instead of errors (default: strict), for
|
|
615
|
+
* every resource family alike
|
|
468
616
|
*/
|
|
469
617
|
interface Register {
|
|
470
618
|
}
|
|
@@ -489,9 +637,11 @@ type TypedUniforms = UniformNodesFor<RegisteredUniforms> & {
|
|
|
489
637
|
};
|
|
490
638
|
/**
|
|
491
639
|
* What `state.uniforms` and `useUniforms()` are: the registered shape (strict by default, so a typo
|
|
492
|
-
* is an error), or
|
|
640
|
+
* is an error), or the loose `LooseUniformStore` when nothing is registered. With `strict: false`
|
|
641
|
+
* an unregistered root key reads loose too. A loose read is a `LooseUniformNode`: every operator and
|
|
642
|
+
* material slot accepts it, and a single `as` gives it an exact type (see that type for why).
|
|
493
643
|
*/
|
|
494
|
-
type AppUniforms = IsRegistered extends true ? IsStrict extends true ? TypedUniforms : TypedUniforms &
|
|
644
|
+
type AppUniforms = IsRegistered extends true ? IsStrict extends true ? TypedUniforms : TypedUniforms & LooseUniformStore : LooseUniformStore;
|
|
495
645
|
/** Creator input at root level: new keys are free, registered keys must keep their registered type. */
|
|
496
646
|
type RootUniformInput = Partial<RegisteredUniforms> & UniformInputRecord;
|
|
497
647
|
/** Creator input for scope `S`: checked against the registered scope, free for any other scope. */
|
|
@@ -501,13 +651,101 @@ type RegisteredScopeUniforms<S extends keyof RegisteredScopes> = UniformNodesFor
|
|
|
501
651
|
/** A registered root uniform's node. */
|
|
502
652
|
type RegisteredUniform<K extends keyof RegisteredUniforms> = UniformNodesFor<RegisteredUniforms>[K];
|
|
503
653
|
/**
|
|
504
|
-
* `uniforms` in a creator (`useNodes(({ uniforms }) => ...)`). Unregistered: any name
|
|
505
|
-
* `
|
|
654
|
+
* `uniforms` in a creator (`useNodes(({ uniforms }) => ...)`). Unregistered: any name reads as a
|
|
655
|
+
* `LooseUniformNode` (or, by dot access, a scope of them), and `.scope(name)` as a record of them
|
|
656
|
+
* unless given a schema. Registered: typed by name like `state.uniforms`, and `.scope(name)` is
|
|
506
657
|
* typed for registered scopes.
|
|
507
658
|
*/
|
|
508
659
|
type CreatorUniforms = IsRegistered extends true ? {
|
|
509
|
-
scope<S extends keyof RegisteredScopes & string>(key: S): ScopedStoreType<UniformNode, RegisteredScopeUniforms<S
|
|
510
|
-
} & Readonly<AppUniforms> & ScopedStoreMethods<UniformNode> : ScopedStoreType<UniformNode>;
|
|
660
|
+
scope<S extends keyof RegisteredScopes & string>(key: S): ScopedStoreType<UniformNode, RegisteredScopeUniforms<S>, LooseUniformNode>;
|
|
661
|
+
} & Readonly<AppUniforms> & ScopedStoreMethods<UniformNode, LooseUniformNode> : ScopedStoreType<UniformNode, LooseUniformStore, LooseUniformNode>;
|
|
662
|
+
/** The registered root-level nodes, or `{}` when none are registered. */
|
|
663
|
+
type RegisteredNodes = Register extends {
|
|
664
|
+
nodes: infer N extends NodeRecord;
|
|
665
|
+
} ? N : {};
|
|
666
|
+
/** The registered node scopes and their nodes, or `{}` when none are registered. */
|
|
667
|
+
type RegisteredNodeScopes = Register extends {
|
|
668
|
+
nodeScopes: infer S extends Record<string, NodeRecord>;
|
|
669
|
+
} ? S : {};
|
|
670
|
+
type IsNodesRegistered = Register extends {
|
|
671
|
+
nodes: any;
|
|
672
|
+
} | {
|
|
673
|
+
nodeScopes: any;
|
|
674
|
+
} ? true : false;
|
|
675
|
+
type TypedNodes = RegisteredNodes & RegisteredNodeScopes;
|
|
676
|
+
/**
|
|
677
|
+
* What `state.nodes` and `useNodes()` are: the registered shape (strict by default, so a typo is an
|
|
678
|
+
* error), or the loose `LooseNodeStore` when no nodes are registered. With `strict: false` an
|
|
679
|
+
* unregistered root key reads loose too.
|
|
680
|
+
*/
|
|
681
|
+
type AppNodes = IsNodesRegistered extends true ? IsStrict extends true ? TypedNodes : TypedNodes & LooseNodeStore : LooseNodeStore;
|
|
682
|
+
/** Creator output at root level: new keys are free, registered keys must keep their registered type. */
|
|
683
|
+
type RootNodeInput = Partial<RegisteredNodes> & NodeRecord;
|
|
684
|
+
/** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
|
|
685
|
+
type ScopeNodeInput<S extends string> = S extends keyof RegisteredNodeScopes ? Partial<RegisteredNodeScopes[S]> : unknown;
|
|
686
|
+
/**
|
|
687
|
+
* `nodes` in a creator. Unregistered: any name reads as a `LooseNode` (or, by dot access, a scope of
|
|
688
|
+
* them). Registered: typed by name like `state.nodes`, and `.scope(name)` is typed for registered
|
|
689
|
+
* scopes.
|
|
690
|
+
*/
|
|
691
|
+
type CreatorNodes = IsNodesRegistered extends true ? {
|
|
692
|
+
scope<S extends keyof RegisteredNodeScopes & string>(key: S): ScopedStoreType<NodeLike, RegisteredNodeScopes[S], LooseNode>;
|
|
693
|
+
} & Readonly<AppNodes> & ScopedStoreMethods<NodeLike, LooseNode> : ScopedStoreType<NodeLike, LooseNodeStore, LooseNode>;
|
|
694
|
+
/** A node reader's result for an explicit schema `T`, or loose nodes when none was given. */
|
|
695
|
+
type ReadNodes<T extends NodeRecord> = NodeRecord extends T ? Record<string, LooseNode> : T;
|
|
696
|
+
/** The registered root-level buffers, or `{}` when none are registered. */
|
|
697
|
+
type RegisteredBuffers = Register extends {
|
|
698
|
+
buffers: infer B extends BufferRecord;
|
|
699
|
+
} ? B : {};
|
|
700
|
+
/** The registered buffer scopes and their buffers, or `{}` when none are registered. */
|
|
701
|
+
type RegisteredBufferScopes = Register extends {
|
|
702
|
+
bufferScopes: infer S extends Record<string, BufferRecord>;
|
|
703
|
+
} ? S : {};
|
|
704
|
+
type IsBuffersRegistered = Register extends {
|
|
705
|
+
buffers: any;
|
|
706
|
+
} | {
|
|
707
|
+
bufferScopes: any;
|
|
708
|
+
} ? true : false;
|
|
709
|
+
type TypedBuffers = RegisteredBuffers & RegisteredBufferScopes;
|
|
710
|
+
/** What `state.buffers` and `useBuffers()` are: the registered shape, or `BufferStore` when none are. */
|
|
711
|
+
type AppBuffers = IsBuffersRegistered extends true ? IsStrict extends true ? TypedBuffers : TypedBuffers & BufferStore : BufferStore;
|
|
712
|
+
/** Creator output at root level: new keys are free, registered keys must keep their registered type. */
|
|
713
|
+
type RootBufferInput = Partial<RegisteredBuffers> & BufferRecord;
|
|
714
|
+
/** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
|
|
715
|
+
type ScopeBufferInput<S extends string> = S extends keyof RegisteredBufferScopes ? Partial<RegisteredBufferScopes[S]> : unknown;
|
|
716
|
+
/** `buffers` in a creator: typed by name when registered, `BufferLike` reads otherwise. */
|
|
717
|
+
type CreatorBuffers = IsBuffersRegistered extends true ? {
|
|
718
|
+
scope<S extends keyof RegisteredBufferScopes & string>(key: S): ScopedStoreType<BufferLike, RegisteredBufferScopes[S]>;
|
|
719
|
+
} & Readonly<AppBuffers> & ScopedStoreMethods<BufferLike> : ScopedStoreType<BufferLike>;
|
|
720
|
+
/** The registered root-level GPU storage, or `{}` when none is registered. */
|
|
721
|
+
type RegisteredGPUStorage = Register extends {
|
|
722
|
+
gpuStorage: infer G extends StorageRecord;
|
|
723
|
+
} ? G : {};
|
|
724
|
+
/** The registered GPU storage scopes and their entries, or `{}` when none are registered. */
|
|
725
|
+
type RegisteredGPUStorageScopes = Register extends {
|
|
726
|
+
gpuStorageScopes: infer S extends Record<string, StorageRecord>;
|
|
727
|
+
} ? S : {};
|
|
728
|
+
type IsGPUStorageRegistered = Register extends {
|
|
729
|
+
gpuStorage: any;
|
|
730
|
+
} | {
|
|
731
|
+
gpuStorageScopes: any;
|
|
732
|
+
} ? true : false;
|
|
733
|
+
type TypedGPUStorage = RegisteredGPUStorage & RegisteredGPUStorageScopes;
|
|
734
|
+
/** What `state.gpuStorage` and `useGPUStorage()` are: the registered shape, or `StorageStore`. */
|
|
735
|
+
type AppGPUStorage = IsGPUStorageRegistered extends true ? IsStrict extends true ? TypedGPUStorage : TypedGPUStorage & StorageStore : StorageStore;
|
|
736
|
+
/** Creator output at root level: new keys are free, registered keys must keep their registered type. */
|
|
737
|
+
type RootGPUStorageInput = Partial<RegisteredGPUStorage> & StorageRecord;
|
|
738
|
+
/** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
|
|
739
|
+
type ScopeGPUStorageInput<S extends string> = S extends keyof RegisteredGPUStorageScopes ? Partial<RegisteredGPUStorageScopes[S]> : unknown;
|
|
740
|
+
/** `gpuStorage` in a creator: typed by name when registered, `StorageLike` reads otherwise. */
|
|
741
|
+
type CreatorGPUStorage = IsGPUStorageRegistered extends true ? {
|
|
742
|
+
scope<S extends keyof RegisteredGPUStorageScopes & string>(key: S): ScopedStoreType<StorageLike, RegisteredGPUStorageScopes[S]>;
|
|
743
|
+
} & Readonly<AppGPUStorage> & ScopedStoreMethods<StorageLike> : ScopedStoreType<StorageLike>;
|
|
744
|
+
/**
|
|
745
|
+
* A reader's result for an explicit schema `T`, or loose uniforms when none was given (`T` is then
|
|
746
|
+
* its constraint, `UniformInputRecord`): `useUniforms<{ blur: number }>('fx')` vs `useUniforms('fx')`.
|
|
747
|
+
*/
|
|
748
|
+
type ReadUniforms<T extends UniformInputRecord> = UniformInputRecord extends T ? Record<string, LooseUniformNode> : UniformNodesFor<T>;
|
|
511
749
|
|
|
512
750
|
/** Uniforms that exist on every primary canvas from the start. See configureTSL. */
|
|
513
751
|
interface TSLConfig {
|
|
@@ -551,7 +789,7 @@ declare function useUniforms<T extends RootUniformInput>(uniforms: T): UniformsW
|
|
|
551
789
|
declare function useUniforms<T extends UniformInputRecord, S extends string>(uniforms: T & ScopeUniformInput<S>, scope: S): UniformsWithUtils<UniformNodesFor<T>>;
|
|
552
790
|
declare function useUniforms(): UniformsWithUtils<AppUniforms>;
|
|
553
791
|
declare function useUniforms<S extends keyof RegisteredScopes & string>(scope: S): UniformsWithUtils<RegisteredScopeUniforms<S>>;
|
|
554
|
-
declare function useUniforms<T extends UniformInputRecord>(scope?: string): UniformsWithUtils<
|
|
792
|
+
declare function useUniforms<T extends UniformInputRecord>(scope?: string): UniformsWithUtils<ReadUniforms<T>>;
|
|
555
793
|
/**
|
|
556
794
|
* Global rebuildUniforms function for HMR integration.
|
|
557
795
|
* Invalidates cached uniforms and increments _hmrVersion to trigger re-creation.
|
|
@@ -573,8 +811,10 @@ declare function rebuildAllUniforms(store: ReturnType<typeof useStore>, scope?:
|
|
|
573
811
|
* - UniformNode: existing uniforms (reused as-is)
|
|
574
812
|
*/
|
|
575
813
|
type UniformValue = number | boolean | string | Vector2 | Vector3 | Vector4 | Color | Matrix2 | Matrix3 | Matrix4 | Node | UniformNode;
|
|
814
|
+
/** `useUniform<T>(name)`'s result: exact for an explicit `T`, a `LooseUniformNode` without one. */
|
|
815
|
+
type ReadUniform<T extends UniformValue> = UniformValue extends T ? LooseUniformNode : UniformNodeFor<T>;
|
|
576
816
|
declare function useUniform<K extends keyof RegisteredUniforms & string>(name: K): RegisteredUniform<K>;
|
|
577
|
-
declare function useUniform<T extends UniformValue = UniformValue>(name: string):
|
|
817
|
+
declare function useUniform<T extends UniformValue = UniformValue>(name: string): ReadUniform<T>;
|
|
578
818
|
declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNodeFor<T>;
|
|
579
819
|
|
|
580
820
|
/**
|
|
@@ -604,12 +844,12 @@ type NodesWithUtils<T extends Record<string, unknown> = NodeRecord> = T & {
|
|
|
604
844
|
clearNodes: ClearNodesFn;
|
|
605
845
|
rebuildNodes: RebuildNodesFn;
|
|
606
846
|
};
|
|
607
|
-
declare function useNodes(): NodesWithUtils<
|
|
608
|
-
declare function useNodes(scope:
|
|
609
|
-
declare function useNodes<T extends NodeRecord>(scope?: string): NodesWithUtils<T
|
|
610
|
-
declare function useNodes<T extends
|
|
611
|
-
declare function useNodes<T extends NodeRecord>(creator:
|
|
612
|
-
declare function useNodes(creatorOrScope
|
|
847
|
+
declare function useNodes(): NodesWithUtils<AppNodes>;
|
|
848
|
+
declare function useNodes<S extends keyof RegisteredNodeScopes & string>(scope: S): NodesWithUtils<RegisteredNodeScopes[S]>;
|
|
849
|
+
declare function useNodes<T extends NodeRecord>(scope?: string): NodesWithUtils<ReadNodes<T>>;
|
|
850
|
+
declare function useNodes<T extends RootNodeInput>(creator: NodeCreator<T>): NodesWithUtils<T>;
|
|
851
|
+
declare function useNodes<T extends NodeRecord, S extends string>(creator: (state: CreatorState) => T & ScopeNodeInput<S>, scope: S): NodesWithUtils<T>;
|
|
852
|
+
declare function useNodes<S extends string | undefined>(creatorOrScope: NodeCreator<NodeRecord> | string | undefined, scope: S & (string extends S ? unknown : never)): NodesWithUtils<Record<string, unknown>>;
|
|
613
853
|
/**
|
|
614
854
|
* Global rebuildNodes function for HMR integration.
|
|
615
855
|
* Invalidates cached nodes and increments _hmrVersion to trigger re-creation.
|
|
@@ -680,8 +920,8 @@ type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
|
|
|
680
920
|
*
|
|
681
921
|
* @example
|
|
682
922
|
* ```tsx
|
|
683
|
-
* // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed when
|
|
684
|
-
* // app registers its uniforms (see `Register`)
|
|
923
|
+
* // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed by name when
|
|
924
|
+
* // the app registers its uniforms (see `Register`), and a loose node TSL accepts as is otherwise.
|
|
685
925
|
* const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
|
|
686
926
|
* wobble: sin(uniforms.uTime.mul(2)),
|
|
687
927
|
* uTime: uniforms.uTime, // can return uniforms too
|
|
@@ -692,10 +932,10 @@ type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
|
|
|
692
932
|
* result: pattern === 'noise' ? nodes.noise : nodes.stripes,
|
|
693
933
|
* }), [pattern])
|
|
694
934
|
*
|
|
695
|
-
* // An unregistered uniform
|
|
696
|
-
* const { colorNode } = useLocalNodes(({ uniforms }) => {
|
|
697
|
-
* const
|
|
698
|
-
* return { colorNode: mix(colorA, colorB,
|
|
935
|
+
* // An unregistered uniform works as is; one `as` gives its exact type where that matters
|
|
936
|
+
* const { colorNode, facing } = useLocalNodes(({ uniforms }) => {
|
|
937
|
+
* const uDir = uniforms.uDir as UniformNode<'vec3', Vector3> // cross() wants a vec3
|
|
938
|
+
* return { colorNode: mix(colorA, colorB, uniforms.myUniform), facing: cross(uDir, normalView) }
|
|
699
939
|
* }, [])
|
|
700
940
|
* ```
|
|
701
941
|
*/
|
|
@@ -726,11 +966,13 @@ type BuffersWithUtils<T extends BufferRecordType | BufferStore = BufferRecordTyp
|
|
|
726
966
|
rebuildBuffers: RebuildBuffersFn;
|
|
727
967
|
disposeBuffers: DisposeBuffersFn;
|
|
728
968
|
};
|
|
729
|
-
declare function useBuffers(): BuffersWithUtils<
|
|
969
|
+
declare function useBuffers(): BuffersWithUtils<AppBuffers>;
|
|
970
|
+
declare function useBuffers<S extends keyof RegisteredBufferScopes & string>(scope: S): BuffersWithUtils<RegisteredBufferScopes[S]>;
|
|
730
971
|
declare function useBuffers(scope: string): BuffersWithUtils<Record<string, BufferLike>>;
|
|
731
972
|
declare function useBuffers<T extends Record<string, BufferLike>>(scope?: string): BuffersWithUtils<T>;
|
|
732
|
-
declare function useBuffers<T extends
|
|
733
|
-
declare function useBuffers<T extends Record<string, BufferLike
|
|
973
|
+
declare function useBuffers<T extends RootBufferInput>(creator: BufferCreator<T>): BuffersWithUtils<T>;
|
|
974
|
+
declare function useBuffers<T extends Record<string, BufferLike>, S extends string>(creator: (state: CreatorState) => T & ScopeBufferInput<S>, scope: S): BuffersWithUtils<T>;
|
|
975
|
+
declare function useBuffers<S extends string | undefined>(creator: BufferCreator<BufferRecord>, scope: S & (string extends S ? unknown : never)): BuffersWithUtils<BufferRecord>;
|
|
734
976
|
/**
|
|
735
977
|
* Global rebuildBuffers function for HMR integration.
|
|
736
978
|
* Invalidates cached buffers and increments _hmrVersion to trigger re-creation.
|
|
@@ -768,11 +1010,13 @@ type StorageWithUtils<T extends StorageRecordType | StorageStore = StorageRecord
|
|
|
768
1010
|
rebuildStorage: RebuildStorageFn;
|
|
769
1011
|
disposeStorage: DisposeStorageFn;
|
|
770
1012
|
};
|
|
771
|
-
declare function useGPUStorage(): StorageWithUtils<
|
|
1013
|
+
declare function useGPUStorage(): StorageWithUtils<AppGPUStorage>;
|
|
1014
|
+
declare function useGPUStorage<S extends keyof RegisteredGPUStorageScopes & string>(scope: S): StorageWithUtils<RegisteredGPUStorageScopes[S]>;
|
|
772
1015
|
declare function useGPUStorage(scope: string): StorageWithUtils<Record<string, StorageLike>>;
|
|
773
1016
|
declare function useGPUStorage<T extends Record<string, StorageLike>>(scope?: string): StorageWithUtils<T>;
|
|
774
|
-
declare function useGPUStorage<T extends
|
|
775
|
-
declare function useGPUStorage<T extends Record<string, StorageLike
|
|
1017
|
+
declare function useGPUStorage<T extends RootGPUStorageInput>(creator: StorageCreator<T>): StorageWithUtils<T>;
|
|
1018
|
+
declare function useGPUStorage<T extends Record<string, StorageLike>, S extends string>(creator: (state: CreatorState) => T & ScopeGPUStorageInput<S>, scope: S): StorageWithUtils<T>;
|
|
1019
|
+
declare function useGPUStorage<S extends string | undefined>(creator: StorageCreator<StorageRecord>, scope: S & (string extends S ? unknown : never)): StorageWithUtils<StorageRecord>;
|
|
776
1020
|
/**
|
|
777
1021
|
* Global rebuildStorage function for HMR integration.
|
|
778
1022
|
* Invalidates cached storage and increments _hmrVersion to trigger re-creation.
|
|
@@ -790,11 +1034,15 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
790
1034
|
* Hook for managing WebGPU RenderPipeline with automatic scenePass setup.
|
|
791
1035
|
*
|
|
792
1036
|
* Features:
|
|
793
|
-
* -
|
|
794
|
-
*
|
|
795
|
-
* -
|
|
796
|
-
* -
|
|
797
|
-
* -
|
|
1037
|
+
* - A call with a callback owns the canvas's pipeline: it creates the pipeline and a default
|
|
1038
|
+
* scenePass (no MRT), and frees both when it unmounts (opt out with `persist`)
|
|
1039
|
+
* - A call without callbacks only reads: it never creates, keeps alive or frees the pipeline
|
|
1040
|
+
* - The most recently mounted owner renders; when it unmounts, the previous owner takes over again
|
|
1041
|
+
* - StrictMode and Fast Refresh remounts reuse the graph instead of rebuilding it
|
|
1042
|
+
* - Callbacks receive the same state as creators (`uniforms`, `nodes`, ... wrapped, including
|
|
1043
|
+
* entries staged earlier in the render), and their reads are tracked as in useLocalNodes: a read
|
|
1044
|
+
* resource that appears, is replaced or is removed re-runs them
|
|
1045
|
+
* - Callbacks re-run on a hot update (`_hmrVersion`), on scene/camera change and on rebuild()
|
|
798
1046
|
* - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
|
|
799
1047
|
* strand its render target (and MRT attachments) on the GPU
|
|
800
1048
|
* - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
|
|
@@ -802,6 +1050,7 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
802
1050
|
*
|
|
803
1051
|
* @param mainCB - Main callback to configure outputNode and create effect passes
|
|
804
1052
|
* @param setupCB - Optional setup callback to configure MRT on scenePass
|
|
1053
|
+
* @param options - `persist: true` keeps the pipeline after the component unmounts
|
|
805
1054
|
* @returns { passes, renderPipeline, clearPasses, reset, rebuild }
|
|
806
1055
|
*
|
|
807
1056
|
* @example
|
|
@@ -827,7 +1076,7 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
827
1076
|
* const { renderPipeline, passes } = useRenderPipeline()
|
|
828
1077
|
* ```
|
|
829
1078
|
*/
|
|
830
|
-
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
|
|
1079
|
+
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback, options?: RenderPipelineOptions): UseRenderPipelineReturn;
|
|
831
1080
|
|
|
832
1081
|
export { configureTSL, createScopedStore, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, useBuffers, useGPUStorage, useLocalNodes, useNodes, useRenderPipeline, useUniform, useUniforms };
|
|
833
|
-
export type { AppUniforms, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, CreatorState, DisposeBuffersFn, DisposeStorageFn, LocalNodeCreator, LocalNodeInstall, LocalNodeInstaller, NodeCreator, NodeLike, NodeRecord, NodeStore, NodesWithUtils, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, Register, RegisteredScopeUniforms, RegisteredScopes, RegisteredUniform, RegisteredUniforms, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RootUniformInput, ScopeUniformInput, ScopedStoreType, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, TSLConfig, TSLNode, TSLNodeLike, TSLRootState, UniformCreator, UniformValue, UniformsWithUtils };
|
|
1082
|
+
export type { AppBuffers, AppGPUStorage, AppNodes, AppUniforms, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, CreatorState, DisposeBuffersFn, DisposeStorageFn, FnNodeLike, LocalNodeCreator, LocalNodeInstall, LocalNodeInstaller, LooseNode, LooseNodeEntry, LooseNodeStore, NodeCreator, NodeLike, NodeRecord, NodeStore, NodesWithUtils, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, Register, RegisteredBufferScopes, RegisteredBuffers, RegisteredGPUStorage, RegisteredGPUStorageScopes, RegisteredNodeScopes, RegisteredNodes, RegisteredScopeUniforms, RegisteredScopes, RegisteredUniform, RegisteredUniforms, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RootBufferInput, RootGPUStorageInput, RootNodeInput, RootUniformInput, ScopeBufferInput, ScopeGPUStorageInput, ScopeNodeInput, ScopeUniformInput, ScopedStoreType, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, TSLConfig, TSLNode, TSLNodeLike, TSLRootState, UniformCreator, UniformValue, UniformsWithUtils };
|