@react-three/tsl 10.0.0-canary.490e4992
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/dist/index.cjs +935 -0
- package/dist/index.d.cts +777 -0
- package/dist/index.d.mts +777 -0
- package/dist/index.d.ts +777 -0
- package/dist/index.mjs +908 -0
- package/package.json +65 -0
- package/readme.md +53 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
import { RootState, useStore } from '@react-three/fiber/extension';
|
|
2
|
+
import * as three_webgpu from 'three/webgpu';
|
|
3
|
+
import { Node, StorageTexture, Storage3DTexture, StorageArrayTexture, Data3DTexture, RenderPipeline, Vector2, Vector3, Vector4, Color, Matrix2, Matrix3, Matrix4 } from 'three/webgpu';
|
|
4
|
+
|
|
5
|
+
//* Buffer Types (useBuffers) ========================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Buffer-like types for GPU compute and storage operations.
|
|
9
|
+
* Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const { positions, velocities } = useBuffers(() => ({
|
|
14
|
+
* positions: instancedArray(count, 'vec3'), // StorageBufferNode
|
|
15
|
+
* velocities: new Float32Array(count * 3), // TypedArray
|
|
16
|
+
* }), 'particles')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type BufferLike =
|
|
20
|
+
| Float32Array
|
|
21
|
+
| Uint32Array
|
|
22
|
+
| Int32Array
|
|
23
|
+
| Float64Array
|
|
24
|
+
| Uint8Array
|
|
25
|
+
| Int8Array
|
|
26
|
+
| Uint16Array
|
|
27
|
+
| Int16Array
|
|
28
|
+
| three_webgpu.BufferAttribute // Base class for all buffer attributes
|
|
29
|
+
| three_webgpu.InterleavedBufferAttribute
|
|
30
|
+
| Node // TSL buffer nodes (instancedArray, storage)
|
|
31
|
+
|
|
32
|
+
/** Flat record of buffer-like values (no nested scopes) */
|
|
33
|
+
type BufferRecord = Record<string, BufferLike>
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Buffer store that can contain both root-level buffers and scoped buffer objects.
|
|
37
|
+
* Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
|
|
38
|
+
*/
|
|
39
|
+
type BufferStore = Record<string, BufferLike | BufferRecord>
|
|
40
|
+
|
|
41
|
+
//* Node Types (useNodes) ========================================
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Every node representation `useNodes` accepts and `state.nodes` holds: three's real `Node`,
|
|
45
|
+
* the callable proxy `Fn()` returns, and the legacy structural shape (`uuid`/`nodeType`) older
|
|
46
|
+
* code passes through. Creators are constrained to this same type, so the shape a creator returns
|
|
47
|
+
* and the shape the store holds are one type by construction.
|
|
48
|
+
*/
|
|
49
|
+
type NodeLike = TSLNodeType | LegacyTSLNodeLike
|
|
50
|
+
|
|
51
|
+
/** Flat record of TSL nodes (no nested scopes) */
|
|
52
|
+
type NodeRecord<T extends NodeLike = NodeLike> = Record<string, T>
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Node store that can contain both root-level nodes and scoped node objects.
|
|
56
|
+
* Structure: { wobble: OperatorNode, fx: { blur: ShaderCallable } }
|
|
57
|
+
*/
|
|
58
|
+
type NodeStore = Record<string, NodeLike | NodeRecord>
|
|
59
|
+
|
|
60
|
+
//* Storage Types (useGPUStorage) ========================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* GPU storage types for texture-based storage operations.
|
|
64
|
+
* Includes Three.js storage textures and TSL storage texture nodes.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* const { heightMap } = useGPUStorage(() => ({
|
|
69
|
+
* heightMap: new StorageTexture(512, 512),
|
|
70
|
+
* }), 'terrain')
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
type StorageLike =
|
|
74
|
+
| StorageTexture // 2D GPU storage texture
|
|
75
|
+
| Storage3DTexture // 3D GPU storage texture (volumes, fluid grids)
|
|
76
|
+
| StorageArrayTexture // 2D-array GPU storage texture
|
|
77
|
+
| Data3DTexture // 3D texture (can be used as storage)
|
|
78
|
+
| Node // TSL storage texture nodes (storageTexture)
|
|
79
|
+
|
|
80
|
+
/** Flat record of storage-like values (no nested scopes) */
|
|
81
|
+
type StorageRecord = Record<string, StorageLike>
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Storage store that can contain both root-level storage and scoped storage objects.
|
|
85
|
+
* Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
|
|
86
|
+
*/
|
|
87
|
+
type StorageStore = Record<string, StorageLike | StorageRecord>
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The fields @react-three/tsl adds to RootState. Its root extension sets them up on every canvas;
|
|
91
|
+
* a secondary canvas holds its primary's map objects, and portals inherit them from their parent. So
|
|
92
|
+
* `state.uniforms` reads the same in useFrame, useThree, creators and handlers, on any canvas.
|
|
93
|
+
*/
|
|
94
|
+
interface TSLRootState {
|
|
95
|
+
/**
|
|
96
|
+
* TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms(). Typed by name
|
|
97
|
+
* once you register them (see `Register`), so `useFrame(({ uniforms }) => uniforms.uTime.value)`
|
|
98
|
+
* needs no cast.
|
|
99
|
+
*/
|
|
100
|
+
uniforms: AppUniforms
|
|
101
|
+
/** TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() */
|
|
102
|
+
nodes: NodeStore
|
|
103
|
+
/** Buffers - root-level buffers + scoped sub-objects. Use useBuffers() */
|
|
104
|
+
buffers: BufferStore
|
|
105
|
+
/** GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() */
|
|
106
|
+
gpuStorage: StorageStore
|
|
107
|
+
/** Internal: bumped by hot reloads and rebuilds to re-run creators */
|
|
108
|
+
_hmrVersion: number
|
|
109
|
+
/** The canvas's RenderPipeline, once useRenderPipeline created one. Per canvas, not shared. */
|
|
110
|
+
renderPipeline?: RenderPipeline | null
|
|
111
|
+
/** Pass nodes registered with useRenderPipeline */
|
|
112
|
+
passes?: PassRecord
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Each fiber entry bundles its own copy of RootState, so every entry the hooks can run under is
|
|
116
|
+
// augmented. The /legacy entry is not: it never has a WebGPU renderer.
|
|
117
|
+
declare module '@react-three/fiber' {
|
|
118
|
+
interface RootState extends TSLRootState {}
|
|
119
|
+
}
|
|
120
|
+
|
|
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
|
+
declare module '@react-three/fiber/extension' {
|
|
128
|
+
interface RootState extends TSLRootState {}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//* Global TSL Types ==============================
|
|
132
|
+
|
|
133
|
+
declare global {
|
|
134
|
+
/**
|
|
135
|
+
* Broad callable-node fallback for dynamic store readers.
|
|
136
|
+
* Creator hooks preserve the exact function signatures inferred from Three's `Fn`.
|
|
137
|
+
*/
|
|
138
|
+
type CallableTSLNode = ((...params: never[]) => unknown) & {
|
|
139
|
+
readonly shaderNode: unknown
|
|
140
|
+
readonly id: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Legacy structural node accepted when at least one historical marker exists. */
|
|
144
|
+
type LegacyTSLNodeLike = {
|
|
145
|
+
label?: ((label: string) => unknown) | string
|
|
146
|
+
setName?: (name: string) => unknown
|
|
147
|
+
} & ({ uuid: string | undefined; nodeType?: string | null } | { uuid?: string; nodeType: string | null | undefined })
|
|
148
|
+
|
|
149
|
+
/** Node type accepted by broad dynamic node-store readers. */
|
|
150
|
+
type TSLNodeType = three_webgpu.Node | CallableTSLNode
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Derive Three's shader node type from an existing node or a supported raw input.
|
|
154
|
+
* Existing InputNode generics take precedence over structural value normalization.
|
|
155
|
+
* Both generics must be inferred because Three's UniformNode intersects an unknown-typed
|
|
156
|
+
* InputNode base with its concrete InputNode specialization.
|
|
157
|
+
*/
|
|
158
|
+
type UniformNodeType<T> = T extends three_webgpu.UniformNode<infer TNodeType, infer _TValue>
|
|
159
|
+
? TNodeType
|
|
160
|
+
: T extends three_webgpu.InputNode<infer TNodeType, infer _TValue>
|
|
161
|
+
? TNodeType
|
|
162
|
+
: T extends number
|
|
163
|
+
? 'float'
|
|
164
|
+
: T extends boolean
|
|
165
|
+
? 'bool'
|
|
166
|
+
: T extends string | three_webgpu.Color | { r: number; g: number; b: number }
|
|
167
|
+
? 'color'
|
|
168
|
+
: T extends three_webgpu.Vector4 | { x: number; y: number; z: number; w: number }
|
|
169
|
+
? 'vec4'
|
|
170
|
+
: T extends three_webgpu.Vector3 | { x: number; y: number; z: number }
|
|
171
|
+
? 'vec3'
|
|
172
|
+
: T extends three_webgpu.Vector2 | { x: number; y: number }
|
|
173
|
+
? 'vec2'
|
|
174
|
+
: T extends three_webgpu.Matrix4
|
|
175
|
+
? 'mat4'
|
|
176
|
+
: T extends three_webgpu.Matrix3
|
|
177
|
+
? 'mat3'
|
|
178
|
+
: T extends three_webgpu.Matrix2
|
|
179
|
+
? 'mat2'
|
|
180
|
+
: unknown
|
|
181
|
+
|
|
182
|
+
/** Derive the normalized JavaScript value stored by a uniform node. */
|
|
183
|
+
type UniformNodeValue<T> = T extends three_webgpu.UniformNode<infer _TNodeType, infer TValue>
|
|
184
|
+
? TValue
|
|
185
|
+
: T extends three_webgpu.InputNode<infer _TNodeType, infer TValue>
|
|
186
|
+
? TValue
|
|
187
|
+
: T extends string | { r: number; g: number; b: number }
|
|
188
|
+
? three_webgpu.Color
|
|
189
|
+
: T extends { x: number; y: number; z: number; w: number }
|
|
190
|
+
? three_webgpu.Vector4
|
|
191
|
+
: T extends { x: number; y: number; z: number }
|
|
192
|
+
? three_webgpu.Vector3
|
|
193
|
+
: T extends { x: number; y: number }
|
|
194
|
+
? three_webgpu.Vector2
|
|
195
|
+
: T extends number
|
|
196
|
+
? number
|
|
197
|
+
: T extends boolean
|
|
198
|
+
? boolean
|
|
199
|
+
: T
|
|
200
|
+
|
|
201
|
+
/** Three's exact UniformNode with shader and value generics derived from an input. */
|
|
202
|
+
type UniformNodeFor<T> = three_webgpu.UniformNode<UniformNodeType<T>, UniformNodeValue<T>>
|
|
203
|
+
|
|
204
|
+
/** Preserve every input key while mapping values to exact Three uniform nodes. */
|
|
205
|
+
type UniformNodesFor<T extends UniformInputRecord> = {
|
|
206
|
+
[K in keyof T]: UniformNodeFor<T[K]>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Backward-compatible single-parameter uniform alias. */
|
|
210
|
+
type UniformNode<T = unknown> = UniformNodeFor<T>
|
|
211
|
+
|
|
212
|
+
/** Flat record of uniform nodes (no nested scopes) */
|
|
213
|
+
type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Uniform store that can contain both root-level uniforms and scoped uniform objects
|
|
217
|
+
* Used by state.uniforms which has structure like:
|
|
218
|
+
* { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
|
|
219
|
+
*/
|
|
220
|
+
type UniformStore = Record<string, UniformNode | UniformRecord>
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Helper to safely access a uniform node from the store.
|
|
224
|
+
* Use this when accessing state.uniforms to get proper typing.
|
|
225
|
+
* @example
|
|
226
|
+
* const uTime = uniforms.uTime as UniformNode<number>
|
|
227
|
+
* const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
|
|
228
|
+
*/
|
|
229
|
+
type GetUniform<T = unknown> = UniformNode<T>
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Acceptable input values for useUniforms - raw values that get converted to UniformNodes
|
|
233
|
+
* Supports:
|
|
234
|
+
* - Primitives: number, string (color), boolean
|
|
235
|
+
* - Three.js types: Color, Vector2/3/4, Matrix2/3/4
|
|
236
|
+
* - Plain objects: { x, y, z, w } converted to vectors
|
|
237
|
+
* - TSL nodes: color(), vec3(), float() for type casting
|
|
238
|
+
* - UniformNode: existing uniforms (reused as-is)
|
|
239
|
+
*/
|
|
240
|
+
type UniformValue =
|
|
241
|
+
| number
|
|
242
|
+
| string
|
|
243
|
+
| boolean
|
|
244
|
+
| three_webgpu.Color
|
|
245
|
+
| three_webgpu.Vector2
|
|
246
|
+
| three_webgpu.Vector3
|
|
247
|
+
| three_webgpu.Vector4
|
|
248
|
+
| three_webgpu.Matrix2
|
|
249
|
+
| three_webgpu.Matrix3
|
|
250
|
+
| three_webgpu.Matrix4
|
|
251
|
+
| { x: number; y: number }
|
|
252
|
+
| { x: number; y: number; z: number }
|
|
253
|
+
| { x: number; y: number; z: number; w: number }
|
|
254
|
+
| { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
|
|
255
|
+
| three_webgpu.Node // TSL nodes like color(), vec3(), float() for type casting
|
|
256
|
+
| UniformNode
|
|
257
|
+
|
|
258
|
+
/** Input record for useUniforms - accepts raw values or UniformNodes */
|
|
259
|
+
type UniformInputRecord = Record<string, UniformValue>
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
declare global {
|
|
263
|
+
/**
|
|
264
|
+
* three's own render pipeline type. Named here so the rest of R3F refers to three's shape
|
|
265
|
+
* rather than `any`. three r183 renamed `PostProcessing` to `RenderPipeline`; our peer floor
|
|
266
|
+
* is r185, so the new name is the only one.
|
|
267
|
+
*/
|
|
268
|
+
type ThreeRenderPipeline = three_webgpu.RenderPipeline
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
|
|
272
|
+
* `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
|
|
273
|
+
* `getTextureNode`, `setMRT` and `dispose` track the installed version.
|
|
274
|
+
*/
|
|
275
|
+
type ScenePassNode = three_webgpu.PassNode
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Pass record - stores TSL pass nodes for render pipeline.
|
|
279
|
+
*
|
|
280
|
+
* `scenePass` is the only key the library owns. It is optional here because this is also the
|
|
281
|
+
* shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
|
|
282
|
+
* or `clearPasses()`. Inside the callbacks it is always present; see
|
|
283
|
+
* {@link RenderPipelineCallbackState}.
|
|
284
|
+
*
|
|
285
|
+
* Every other key is user-registered, via a callback's return value. Those are TSL nodes of
|
|
286
|
+
* any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
|
|
287
|
+
* `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
|
|
288
|
+
* site when you need a member, e.g. `passes.velocity as TextureNode`.
|
|
289
|
+
*
|
|
290
|
+
* The index signature admits `undefined` because a key may simply not be registered, and
|
|
291
|
+
* because the optional `scenePass` must be assignable to it: under `skipLibCheck: false` an
|
|
292
|
+
* optional property whose type excludes `undefined` from the index signature is an error
|
|
293
|
+
* (TS2411) for every consumer compiling these declarations.
|
|
294
|
+
*/
|
|
295
|
+
interface PassRecord {
|
|
296
|
+
scenePass?: ScenePassNode
|
|
297
|
+
[key: string]: three_webgpu.Node | undefined
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* State passed to pipeline callbacks after the active pipeline has been created.
|
|
302
|
+
*
|
|
303
|
+
* `passes.scenePass` is required here: the hook installs the default scene pass before either
|
|
304
|
+
* callback runs, so callbacks can use it without a guard or a cast.
|
|
305
|
+
*
|
|
306
|
+
* `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
|
|
307
|
+
* the legacy renderer before either callback can run, so a callback never sees WebGL.
|
|
308
|
+
*/
|
|
309
|
+
type RenderPipelineCallbackState = RootState & {
|
|
310
|
+
renderPipeline: ThreeRenderPipeline
|
|
311
|
+
passes: PassRecord & { scenePass: ScenePassNode }
|
|
312
|
+
renderer: three_webgpu.WebGPURenderer
|
|
313
|
+
isLegacy: false
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* What a callback may return to register entries into `state.passes`.
|
|
318
|
+
*
|
|
319
|
+
* `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
|
|
320
|
+
* created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
|
|
321
|
+
* store entry would leave the store pointing at a node the hook never disposes, and the hook
|
|
322
|
+
* disposing a pass nothing references. So returning it is a type error.
|
|
323
|
+
*/
|
|
324
|
+
type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
|
|
325
|
+
|
|
326
|
+
/** Setup callback - runs first to configure MRT, create additional passes */
|
|
327
|
+
type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
|
|
328
|
+
|
|
329
|
+
/** Main callback - runs second to configure outputNode, create effect passes */
|
|
330
|
+
type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
|
|
331
|
+
|
|
332
|
+
/** The imperative half of useRenderPipeline's return value, present in every state */
|
|
333
|
+
interface UseRenderPipelineActions {
|
|
334
|
+
/** Current passes from state */
|
|
335
|
+
passes: PassRecord
|
|
336
|
+
/** Clear all passes from state */
|
|
337
|
+
clearPasses: () => void
|
|
338
|
+
/** Reset RenderPipeline entirely (clears PP + passes) */
|
|
339
|
+
reset: () => void
|
|
340
|
+
/** Re-run setup/main callbacks with current closure values */
|
|
341
|
+
rebuild: () => void
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Return type for useRenderPipeline hook, discriminated on `isReady`.
|
|
346
|
+
*
|
|
347
|
+
* `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
|
|
348
|
+
* callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
|
|
349
|
+
* `clearPasses()` empties the record while leaving the pipeline in place.
|
|
350
|
+
*/
|
|
351
|
+
type UseRenderPipelineReturn = UseRenderPipelineActions &
|
|
352
|
+
(
|
|
353
|
+
| {
|
|
354
|
+
/** True when RenderPipeline is configured and ready */
|
|
355
|
+
isReady: true
|
|
356
|
+
/** RenderPipeline instance */
|
|
357
|
+
renderPipeline: ThreeRenderPipeline
|
|
358
|
+
}
|
|
359
|
+
| {
|
|
360
|
+
/** False until the pipeline has been created */
|
|
361
|
+
isReady: false
|
|
362
|
+
/** Not initialized yet, or torn down by reset() */
|
|
363
|
+
renderPipeline: null
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Distinguishes a resource leaf from a nested resource scope. */
|
|
369
|
+
type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* ScopedStore - Type-safe wrapper for nested stores (uniforms, nodes)
|
|
373
|
+
*
|
|
374
|
+
* Provides TypeScript-friendly access to uniform/node stores where the runtime
|
|
375
|
+
* structure is `Record<string, T | Record<string, T>>` (leaf nodes or nested scopes).
|
|
376
|
+
*
|
|
377
|
+
* The wrapper uses a Proxy to:
|
|
378
|
+
* 1. Return `T` for property access (type assumption: assumes leaf node)
|
|
379
|
+
* 2. Provide `.scope(key)` method for explicit nested access
|
|
380
|
+
* 3. Support iteration methods: has(), keys(), Object.keys(), for...in
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```tsx
|
|
384
|
+
* useLocalNodes(({ uniforms }) => ({
|
|
385
|
+
* wobble: sin(uniforms.uTime.mul(2)), // No cast needed!
|
|
386
|
+
* playerHealth: uniforms.scope('player').uHealth // Explicit scope access
|
|
387
|
+
* }))
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Type-safe wrapper interface for accessing nested store data.
|
|
393
|
+
* Property access returns `T` (assumes leaf node).
|
|
394
|
+
* Use `.scope(key)` for nested object access.
|
|
395
|
+
*
|
|
396
|
+
*/
|
|
397
|
+
type ScopedStoreMethods<TLeaf> = {
|
|
398
|
+
/** Access a nested scope by key. Returns empty wrapper if scope doesn't exist. */
|
|
399
|
+
scope<TScope extends Record<string, TLeaf> = Record<string, TLeaf>>(key: string): ScopedStoreType<TLeaf, TScope>;
|
|
400
|
+
/** Check if a key exists in the store */
|
|
401
|
+
has(key: string): boolean;
|
|
402
|
+
/** Get all keys in the store */
|
|
403
|
+
keys(): string[];
|
|
404
|
+
};
|
|
405
|
+
type ScopedStoreType<TLeaf, TEntries extends Record<string, TLeaf> = Record<string, TLeaf>> = Readonly<TEntries> & ScopedStoreMethods<TLeaf>;
|
|
406
|
+
interface ScopedStoreData<TLeaf> {
|
|
407
|
+
[key: string]: TLeaf | ScopedStoreData<TLeaf>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Create a type-safe ScopedStore wrapper around store data.
|
|
411
|
+
* @param data - The raw store data (uniforms or nodes from RootState)
|
|
412
|
+
* @returns A ScopedStoreType wrapper with type-safe access
|
|
413
|
+
*/
|
|
414
|
+
declare function createScopedStore<TLeaf>(data: ScopedStoreData<TLeaf>, isLeaf: ResourceLeafGuard<TLeaf>): ScopedStoreType<TLeaf>;
|
|
415
|
+
/**
|
|
416
|
+
* State type passed to creator functions with ScopedStore wrappers.
|
|
417
|
+
* Provides type-safe access to uniforms, nodes, buffers, and gpuStorage without manual casting.
|
|
418
|
+
*/
|
|
419
|
+
type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStorage'> & {
|
|
420
|
+
/** Type-safe uniform access - property access returns UniformNode, typed by name when registered */
|
|
421
|
+
uniforms: CreatorUniforms;
|
|
422
|
+
/** Type-safe node access for real, callable, and legacy structural nodes */
|
|
423
|
+
nodes: ScopedStoreType<NodeLike>;
|
|
424
|
+
/** Type-safe buffer access - property access returns BufferLike (TypedArrays, BufferAttributes, TSL nodes) */
|
|
425
|
+
buffers: ScopedStoreType<BufferLike>;
|
|
426
|
+
/** Type-safe GPU storage access - property access returns StorageLike (StorageTexture, TSL nodes) */
|
|
427
|
+
gpuStorage: ScopedStoreType<StorageLike>;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @fileoverview Typed uniforms by registration (the TanStack Router `Register` pattern).
|
|
432
|
+
*
|
|
433
|
+
* Nothing registered: every type below falls back to the loose shapes the hooks have always had.
|
|
434
|
+
* Registered once, anywhere in the app:
|
|
435
|
+
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* export const globalUniforms = { uTime: 0, uColor: new Color('hotpink') }
|
|
438
|
+
* export const playerUniforms = { uHealth: 1 }
|
|
439
|
+
*
|
|
440
|
+
* declare module '@react-three/tsl' {
|
|
441
|
+
* interface Register {
|
|
442
|
+
* uniforms: typeof globalUniforms
|
|
443
|
+
* scopes: { player: typeof playerUniforms }
|
|
444
|
+
* // strict: false // unregistered root keys become loose instead of errors
|
|
445
|
+
* }
|
|
446
|
+
* }
|
|
447
|
+
*
|
|
448
|
+
* configureTSL({ uniforms: globalUniforms, scopes: { player: playerUniforms } })
|
|
449
|
+
* ```
|
|
450
|
+
*
|
|
451
|
+
* then `useUniforms().uTime`, `useUniforms('player').uHealth`, `useUniform('uTime')`,
|
|
452
|
+
* `useFrame(({ uniforms }) => uniforms.uTime)`, `useThree((s) => s.uniforms.uTime)` and a creator's
|
|
453
|
+
* `({ uniforms }) => uniforms.uTime` are typed by name, with no generics.
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Augment this to type uniforms by name. Recognised keys:
|
|
458
|
+
* - `uniforms`: the root-level uniform inputs (e.g. `typeof globalUniforms`)
|
|
459
|
+
* - `scopes`: named scopes and their inputs (e.g. `{ player: typeof playerUniforms }`)
|
|
460
|
+
* - `strict`: `false` makes unregistered root keys loose instead of errors (default: strict)
|
|
461
|
+
*/
|
|
462
|
+
interface Register {
|
|
463
|
+
}
|
|
464
|
+
/** The registered root-level uniform inputs, or `{}` when nothing is registered. */
|
|
465
|
+
type RegisteredUniforms = Register extends {
|
|
466
|
+
uniforms: infer U extends UniformInputRecord;
|
|
467
|
+
} ? U : {};
|
|
468
|
+
/** The registered scopes and their inputs, or `{}` when nothing is registered. */
|
|
469
|
+
type RegisteredScopes = Register extends {
|
|
470
|
+
scopes: infer S extends Record<string, UniformInputRecord>;
|
|
471
|
+
} ? S : {};
|
|
472
|
+
type IsRegistered = Register extends {
|
|
473
|
+
uniforms: any;
|
|
474
|
+
} | {
|
|
475
|
+
scopes: any;
|
|
476
|
+
} ? true : false;
|
|
477
|
+
type IsStrict = Register extends {
|
|
478
|
+
strict: false;
|
|
479
|
+
} ? false : true;
|
|
480
|
+
type TypedUniforms = UniformNodesFor<RegisteredUniforms> & {
|
|
481
|
+
[K in keyof RegisteredScopes]: UniformNodesFor<RegisteredScopes[K]>;
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* What `state.uniforms` and `useUniforms()` are: the registered shape (strict by default, so a typo
|
|
485
|
+
* is an error), or today's loose `UniformStore` when nothing is registered.
|
|
486
|
+
*/
|
|
487
|
+
type AppUniforms = IsRegistered extends true ? IsStrict extends true ? TypedUniforms : TypedUniforms & UniformStore : UniformStore;
|
|
488
|
+
/** Creator input at root level: new keys are free, registered keys must keep their registered type. */
|
|
489
|
+
type RootUniformInput = Partial<RegisteredUniforms> & UniformInputRecord;
|
|
490
|
+
/** Creator input for scope `S`: checked against the registered scope, free for any other scope. */
|
|
491
|
+
type ScopeUniformInput<S extends string> = S extends keyof RegisteredScopes ? Partial<RegisteredScopes[S]> : unknown;
|
|
492
|
+
/** A registered scope's uniform nodes. */
|
|
493
|
+
type RegisteredScopeUniforms<S extends keyof RegisteredScopes> = UniformNodesFor<RegisteredScopes[S]>;
|
|
494
|
+
/** A registered root uniform's node. */
|
|
495
|
+
type RegisteredUniform<K extends keyof RegisteredUniforms> = UniformNodesFor<RegisteredUniforms>[K];
|
|
496
|
+
/**
|
|
497
|
+
* `uniforms` in a creator (`useNodes(({ uniforms }) => ...)`). Unregistered: any name is a
|
|
498
|
+
* `UniformNode`, as before. Registered: typed by name like `state.uniforms`, and `.scope(name)` is
|
|
499
|
+
* typed for registered scopes.
|
|
500
|
+
*/
|
|
501
|
+
type CreatorUniforms = IsRegistered extends true ? {
|
|
502
|
+
scope<S extends keyof RegisteredScopes & string>(key: S): ScopedStoreType<UniformNode, RegisteredScopeUniforms<S>>;
|
|
503
|
+
} & Readonly<AppUniforms> & ScopedStoreMethods<UniformNode> : ScopedStoreType<UniformNode>;
|
|
504
|
+
|
|
505
|
+
/** Uniforms that exist on every primary canvas from the start. See configureTSL. */
|
|
506
|
+
interface TSLConfig {
|
|
507
|
+
/** Root-level uniform inputs, e.g. the object you registered as `Register['uniforms']` */
|
|
508
|
+
uniforms?: UniformInputRecord;
|
|
509
|
+
/** Scoped uniform inputs, e.g. the object you registered as `Register['scopes']` */
|
|
510
|
+
scopes?: Record<string, UniformInputRecord>;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Create uniforms on every primary canvas up front -- the runtime half of `Register`. Pass the same
|
|
514
|
+
* objects you registered, so the registered types are true before the first frame:
|
|
515
|
+
*
|
|
516
|
+
* ```ts
|
|
517
|
+
* configureTSL({ uniforms: globalUniforms, scopes: { player: playerUniforms } })
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* They land on the primary canvas's RootState, so `state.uniforms` has them on the primary, its
|
|
521
|
+
* secondaries and every portal. Applies to canvases already mounted and to every canvas mounted
|
|
522
|
+
* later. Calling it again adds to the configuration; uniforms that already exist are never
|
|
523
|
+
* replaced. Optional: without it, a uniform exists once some component creates it.
|
|
524
|
+
*/
|
|
525
|
+
declare function configureTSL(next: TSLConfig): void;
|
|
526
|
+
|
|
527
|
+
/** Creator function that returns uniform inputs (can be raw values or UniformNodes) */
|
|
528
|
+
type UniformCreator<T extends UniformInputRecord = UniformInputRecord> = (state: CreatorState) => T;
|
|
529
|
+
/** Function signature for removeUniforms util */
|
|
530
|
+
type RemoveUniformsFn = (names: string | string[], scope?: string) => void;
|
|
531
|
+
/** Function signature for clearUniforms util */
|
|
532
|
+
type ClearUniformsFn = (scope?: string) => void;
|
|
533
|
+
/** Function signature for rebuildUniforms util */
|
|
534
|
+
type RebuildUniformsFn = (scope?: string) => void;
|
|
535
|
+
/** Return type with utils included */
|
|
536
|
+
type UniformsWithUtils<T extends UniformRecord | UniformStore = UniformRecord> = T & {
|
|
537
|
+
removeUniforms: RemoveUniformsFn;
|
|
538
|
+
clearUniforms: ClearUniformsFn;
|
|
539
|
+
rebuildUniforms: RebuildUniformsFn;
|
|
540
|
+
};
|
|
541
|
+
declare function useUniforms<T extends RootUniformInput>(creator: UniformCreator<T>): UniformsWithUtils<UniformNodesFor<T>>;
|
|
542
|
+
declare function useUniforms<T extends UniformInputRecord, S extends string>(creator: (state: CreatorState) => T & ScopeUniformInput<S>, scope: S): UniformsWithUtils<UniformNodesFor<T>>;
|
|
543
|
+
declare function useUniforms<T extends RootUniformInput>(uniforms: T): UniformsWithUtils<UniformNodesFor<T>>;
|
|
544
|
+
declare function useUniforms<T extends UniformInputRecord, S extends string>(uniforms: T & ScopeUniformInput<S>, scope: S): UniformsWithUtils<UniformNodesFor<T>>;
|
|
545
|
+
declare function useUniforms(): UniformsWithUtils<AppUniforms>;
|
|
546
|
+
declare function useUniforms<S extends keyof RegisteredScopes & string>(scope: S): UniformsWithUtils<RegisteredScopeUniforms<S>>;
|
|
547
|
+
declare function useUniforms<T extends UniformInputRecord>(scope?: string): UniformsWithUtils<UniformNodesFor<T>>;
|
|
548
|
+
/**
|
|
549
|
+
* Global rebuildUniforms function for HMR integration.
|
|
550
|
+
* Invalidates cached uniforms and increments _hmrVersion to trigger re-creation.
|
|
551
|
+
* Call this when HMR is detected to refresh all uniform creators.
|
|
552
|
+
*
|
|
553
|
+
* Resolves to the primary store so shared TSL resources rebuild on the
|
|
554
|
+
* authoritative store.
|
|
555
|
+
*
|
|
556
|
+
* @param store - The R3F store (from useStore or context)
|
|
557
|
+
* @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
|
|
558
|
+
*/
|
|
559
|
+
declare function rebuildAllUniforms(store: ReturnType<typeof useStore>, scope?: string): void;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Supported uniform value types:
|
|
563
|
+
* - Raw values: number, boolean, Vector2, Vector3, Vector4, Color, Matrix2, Matrix3, Matrix4
|
|
564
|
+
* - String colors: '#ff0000', 'red', 'rgb(255,0,0)' (auto-converted to Color)
|
|
565
|
+
* - TSL nodes: color(), vec3(), float(), etc. (for type casting)
|
|
566
|
+
* - UniformNode: existing uniforms (reused as-is)
|
|
567
|
+
*/
|
|
568
|
+
type UniformValue = number | boolean | string | Vector2 | Vector3 | Vector4 | Color | Matrix2 | Matrix3 | Matrix4 | Node | UniformNode;
|
|
569
|
+
declare function useUniform<K extends keyof RegisteredUniforms & string>(name: K): RegisteredUniform<K>;
|
|
570
|
+
declare function useUniform<T extends UniformValue = UniformValue>(name: string): UniformNodeFor<T>;
|
|
571
|
+
declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNodeFor<T>;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Every node representation a creator may return. The definition lives with the store types as
|
|
575
|
+
* `NodeLike`, so the shape creators return and the shape `state.nodes` holds are one type by
|
|
576
|
+
* construction: three's real `Node`, the callable proxy `Fn()` returns, or the legacy structural
|
|
577
|
+
* `{ uuid, nodeType }` shape.
|
|
578
|
+
*/
|
|
579
|
+
type TSLNodeLike = NodeLike;
|
|
580
|
+
|
|
581
|
+
/** Backward-compatible alias covering every accepted node representation. */
|
|
582
|
+
type TSLNode = TSLNodeLike;
|
|
583
|
+
/**
|
|
584
|
+
* Creator function that returns a record of nodes.
|
|
585
|
+
* Exact creator return inference is preserved within the compatible node constraint.
|
|
586
|
+
*/
|
|
587
|
+
type NodeCreator<T extends Record<string, TSLNodeLike>> = (state: CreatorState) => T;
|
|
588
|
+
/** Function signature for removeNodes util */
|
|
589
|
+
type RemoveNodesFn = (names: string | string[], scope?: string) => void;
|
|
590
|
+
/** Function signature for clearNodes util */
|
|
591
|
+
type ClearNodesFn = (scope?: string) => void;
|
|
592
|
+
/** Function signature for rebuildNodes util */
|
|
593
|
+
type RebuildNodesFn = (scope?: string) => void;
|
|
594
|
+
/** Return type with utils included */
|
|
595
|
+
type NodesWithUtils<T extends Record<string, unknown> = NodeRecord> = T & {
|
|
596
|
+
removeNodes: RemoveNodesFn;
|
|
597
|
+
clearNodes: ClearNodesFn;
|
|
598
|
+
rebuildNodes: RebuildNodesFn;
|
|
599
|
+
};
|
|
600
|
+
declare function useNodes(): NodesWithUtils<NodeStore>;
|
|
601
|
+
declare function useNodes(scope: string): NodesWithUtils<NodeRecord>;
|
|
602
|
+
declare function useNodes<T extends NodeRecord>(scope?: string): NodesWithUtils<T>;
|
|
603
|
+
declare function useNodes<T extends NodeRecord>(creator: NodeCreator<T>): NodesWithUtils<T>;
|
|
604
|
+
declare function useNodes<T extends NodeRecord>(creator: NodeCreator<T>, scope: string): NodesWithUtils<T>;
|
|
605
|
+
declare function useNodes(creatorOrScope?: NodeCreator<NodeRecord> | string, scope?: string): NodesWithUtils<Record<string, unknown>>;
|
|
606
|
+
/**
|
|
607
|
+
* Global rebuildNodes function for HMR integration.
|
|
608
|
+
* Invalidates cached nodes and increments _hmrVersion to trigger re-creation.
|
|
609
|
+
* Call this when HMR is detected to refresh all node creators.
|
|
610
|
+
*
|
|
611
|
+
* Resolves to the primary store so shared TSL resources rebuild on the
|
|
612
|
+
* authoritative store.
|
|
613
|
+
*
|
|
614
|
+
* @param store - The R3F store (from useStore or context)
|
|
615
|
+
* @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
|
|
616
|
+
*/
|
|
617
|
+
declare function rebuildAllNodes(store: ReturnType<typeof useStore>, scope?: string): void;
|
|
618
|
+
|
|
619
|
+
/** Creator receives CreatorState with ScopedStore wrappers for type-safe access. Returns any record. */
|
|
620
|
+
type LocalNodeCreator<T extends Record<string, unknown>> = (state: CreatorState) => T;
|
|
621
|
+
/**
|
|
622
|
+
* Creates local values that rebuild when uniforms, nodes, or textures change.
|
|
623
|
+
*
|
|
624
|
+
* Unlike `useNodes`, this does NOT register to the global store.
|
|
625
|
+
* Use for component-specific nodes/values that depend on shared resources.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```tsx
|
|
629
|
+
* // Destructure what you need from state
|
|
630
|
+
* const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
|
|
631
|
+
* wobble: sin(uniforms.uTime.mul(2)),
|
|
632
|
+
* uTime: uniforms.uTime, // can return uniforms too
|
|
633
|
+
* }))
|
|
634
|
+
*
|
|
635
|
+
* // Or access anything else from RootState
|
|
636
|
+
* const { scaled } = useLocalNodes(({ camera, nodes }) => ({
|
|
637
|
+
* scaled: nodes.basePos.mul(camera.zoom),
|
|
638
|
+
* }))
|
|
639
|
+
*
|
|
640
|
+
* // Type-safe uniform access
|
|
641
|
+
* const { colorNode } = useLocalNodes(({ uniforms }) => {
|
|
642
|
+
* const uValue = uniforms.myUniform as UniformNode<number>
|
|
643
|
+
* return { colorNode: mix(colorA, colorB, uValue) }
|
|
644
|
+
* })
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function useLocalNodes<T extends Record<string, unknown>>(creator: LocalNodeCreator<T>): T;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* A record of buffer-like values - allows mixed types (TypedArrays, BufferAttributes, TSL nodes)
|
|
651
|
+
*/
|
|
652
|
+
type BufferRecordType<T extends BufferLike = BufferLike> = Record<string, T>;
|
|
653
|
+
/**
|
|
654
|
+
* Creator function that returns a record of buffers.
|
|
655
|
+
* Receives CreatorState with access to existing buffers, gpuStorage, uniforms, nodes, etc.
|
|
656
|
+
*/
|
|
657
|
+
type BufferCreator<T extends Record<string, BufferLike>> = (state: CreatorState) => T;
|
|
658
|
+
/** Function signature for removeBuffers util */
|
|
659
|
+
type RemoveBuffersFn = (names: string | string[], scope?: string) => void;
|
|
660
|
+
/** Function signature for clearBuffers util */
|
|
661
|
+
type ClearBuffersFn = (scope?: string) => void;
|
|
662
|
+
/** Function signature for rebuildBuffers util */
|
|
663
|
+
type RebuildBuffersFn = (scope?: string) => void;
|
|
664
|
+
/** Function signature for disposeBuffers util - releases GPU resources */
|
|
665
|
+
type DisposeBuffersFn = (names: string | string[], scope?: string) => void;
|
|
666
|
+
/** Return type with utils included */
|
|
667
|
+
type BuffersWithUtils<T extends BufferRecordType | BufferStore = BufferRecordType> = T & {
|
|
668
|
+
removeBuffers: RemoveBuffersFn;
|
|
669
|
+
clearBuffers: ClearBuffersFn;
|
|
670
|
+
rebuildBuffers: RebuildBuffersFn;
|
|
671
|
+
disposeBuffers: DisposeBuffersFn;
|
|
672
|
+
};
|
|
673
|
+
declare function useBuffers(): BuffersWithUtils<BufferStore>;
|
|
674
|
+
declare function useBuffers(scope: string): BuffersWithUtils<Record<string, BufferLike>>;
|
|
675
|
+
declare function useBuffers<T extends Record<string, BufferLike>>(scope?: string): BuffersWithUtils<T>;
|
|
676
|
+
declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>): BuffersWithUtils<T>;
|
|
677
|
+
declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>, scope: string): BuffersWithUtils<T>;
|
|
678
|
+
/**
|
|
679
|
+
* Global rebuildBuffers function for HMR integration.
|
|
680
|
+
* Invalidates cached buffers and increments _hmrVersion to trigger re-creation.
|
|
681
|
+
* Call this when HMR is detected to refresh all buffer creators.
|
|
682
|
+
*
|
|
683
|
+
* Resolves to the primary store so shared TSL resources rebuild on the
|
|
684
|
+
* authoritative store.
|
|
685
|
+
*
|
|
686
|
+
* @param store - The R3F store (from useStore or context)
|
|
687
|
+
* @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
|
|
688
|
+
*/
|
|
689
|
+
declare function rebuildAllBuffers(store: ReturnType<typeof useStore>, scope?: string): void;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* A record of storage-like values - allows mixed types (StorageTexture, Storage3DTexture, TSL nodes)
|
|
693
|
+
*/
|
|
694
|
+
type StorageRecordType<T extends StorageLike = StorageLike> = Record<string, T>;
|
|
695
|
+
/**
|
|
696
|
+
* Creator function that returns a record of GPU storage objects.
|
|
697
|
+
* Receives CreatorState with access to existing buffers, gpuStorage, uniforms, nodes, etc.
|
|
698
|
+
*/
|
|
699
|
+
type StorageCreator<T extends Record<string, StorageLike>> = (state: CreatorState) => T;
|
|
700
|
+
/** Function signature for removeStorage util */
|
|
701
|
+
type RemoveStorageFn = (names: string | string[], scope?: string) => void;
|
|
702
|
+
/** Function signature for clearStorage util */
|
|
703
|
+
type ClearStorageFn = (scope?: string) => void;
|
|
704
|
+
/** Function signature for rebuildStorage util */
|
|
705
|
+
type RebuildStorageFn = (scope?: string) => void;
|
|
706
|
+
/** Function signature for disposeStorage util - releases GPU resources */
|
|
707
|
+
type DisposeStorageFn = (names: string | string[], scope?: string) => void;
|
|
708
|
+
/** Return type with utils included */
|
|
709
|
+
type StorageWithUtils<T extends StorageRecordType | StorageStore = StorageRecordType> = T & {
|
|
710
|
+
removeStorage: RemoveStorageFn;
|
|
711
|
+
clearStorage: ClearStorageFn;
|
|
712
|
+
rebuildStorage: RebuildStorageFn;
|
|
713
|
+
disposeStorage: DisposeStorageFn;
|
|
714
|
+
};
|
|
715
|
+
declare function useGPUStorage(): StorageWithUtils<StorageStore>;
|
|
716
|
+
declare function useGPUStorage(scope: string): StorageWithUtils<Record<string, StorageLike>>;
|
|
717
|
+
declare function useGPUStorage<T extends Record<string, StorageLike>>(scope?: string): StorageWithUtils<T>;
|
|
718
|
+
declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>): StorageWithUtils<T>;
|
|
719
|
+
declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>, scope: string): StorageWithUtils<T>;
|
|
720
|
+
/**
|
|
721
|
+
* Global rebuildStorage function for HMR integration.
|
|
722
|
+
* Invalidates cached storage and increments _hmrVersion to trigger re-creation.
|
|
723
|
+
* Call this when HMR is detected to refresh all storage creators.
|
|
724
|
+
*
|
|
725
|
+
* Resolves to the primary store so shared TSL resources rebuild on the
|
|
726
|
+
* authoritative store.
|
|
727
|
+
*
|
|
728
|
+
* @param store - The R3F store (from useStore or context)
|
|
729
|
+
* @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
|
|
730
|
+
*/
|
|
731
|
+
declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: string): void;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Hook for managing WebGPU RenderPipeline with automatic scenePass setup.
|
|
735
|
+
*
|
|
736
|
+
* Features:
|
|
737
|
+
* - Creates RenderPipeline instance if not exists
|
|
738
|
+
* - Creates default scenePass (no MRT) automatically
|
|
739
|
+
* - Callbacks receive full RootState for flexibility
|
|
740
|
+
* - No auto-cleanup on unmount - use reset() for explicit cleanup
|
|
741
|
+
* - Scene/camera changes trigger scenePass recreation
|
|
742
|
+
* - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
|
|
743
|
+
* strand its render target (and MRT attachments) on the GPU
|
|
744
|
+
* - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
|
|
745
|
+
* recompiles instead of silently keeping the first compiled graph
|
|
746
|
+
*
|
|
747
|
+
* @param mainCB - Main callback to configure outputNode and create effect passes
|
|
748
|
+
* @param setupCB - Optional setup callback to configure MRT on scenePass
|
|
749
|
+
* @returns { passes, renderPipeline, clearPasses, reset, rebuild }
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```tsx
|
|
753
|
+
* // Simple effect
|
|
754
|
+
* useRenderPipeline(({ renderPipeline, passes }) => {
|
|
755
|
+
* renderPipeline.outputNode = bloom(passes.scenePass.getTextureNode())
|
|
756
|
+
* })
|
|
757
|
+
*
|
|
758
|
+
* // With MRT setup
|
|
759
|
+
* useRenderPipeline(
|
|
760
|
+
* ({ renderPipeline, passes }) => {
|
|
761
|
+
* const beauty = passes.scenePass.getTextureNode().toInspector('Color')
|
|
762
|
+
* const vel = passes.scenePass.getTextureNode('velocity')
|
|
763
|
+
* renderPipeline.outputNode = motionBlur(beauty, vel)
|
|
764
|
+
* },
|
|
765
|
+
* ({ passes }) => {
|
|
766
|
+
* passes.scenePass.setMRT(mrt({ output, velocity }))
|
|
767
|
+
* }
|
|
768
|
+
* )
|
|
769
|
+
*
|
|
770
|
+
* // Read-only access
|
|
771
|
+
* const { renderPipeline, passes } = useRenderPipeline()
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
774
|
+
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
|
|
775
|
+
|
|
776
|
+
export { configureTSL, createScopedStore, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, useBuffers, useGPUStorage, useLocalNodes, useNodes, useRenderPipeline, useUniform, useUniforms };
|
|
777
|
+
export type { AppUniforms, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, CreatorState, DisposeBuffersFn, DisposeStorageFn, LocalNodeCreator, 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 };
|