@react-three/tsl 10.0.0-canary.bf4b0be → 10.0.0-canary.d458ee7
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 +331 -31
- package/dist/index.d.cts +120 -50
- package/dist/index.d.mts +120 -50
- package/dist/index.d.ts +120 -50
- package/dist/index.mjs +333 -33
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -149,6 +149,16 @@ declare global {
|
|
|
149
149
|
/** Node type accepted by broad dynamic node-store readers. */
|
|
150
150
|
type TSLNodeType = three_webgpu.Node | CallableTSLNode
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* What TSL's constant constructors return: `int(1)`, `vec2(0, 1)`, `color('red')` and friends
|
|
154
|
+
* wrap a ConstNode in a VarNode. three's `uniform()` unwraps exactly this shape to
|
|
155
|
+
* `UniformNode<TNodeType, TValue>`, and so do the mappings below.
|
|
156
|
+
*/
|
|
157
|
+
type TSLConstNode<TNodeType, TValue> = three_webgpu.VarNode<
|
|
158
|
+
TNodeType,
|
|
159
|
+
three_webgpu.ConstNode<TNodeType, TValue>
|
|
160
|
+
>
|
|
161
|
+
|
|
152
162
|
/**
|
|
153
163
|
* Derive Three's shader node type from an existing node or a supported raw input.
|
|
154
164
|
* Existing InputNode generics take precedence over structural value normalization.
|
|
@@ -159,44 +169,48 @@ declare global {
|
|
|
159
169
|
? TNodeType
|
|
160
170
|
: T extends three_webgpu.InputNode<infer TNodeType, infer _TValue>
|
|
161
171
|
? 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
|
-
:
|
|
172
|
+
: T extends TSLConstNode<infer TNodeType, infer _TValue>
|
|
173
|
+
? TNodeType
|
|
174
|
+
: T extends number
|
|
175
|
+
? 'float'
|
|
176
|
+
: T extends boolean
|
|
177
|
+
? 'bool'
|
|
178
|
+
: T extends string | three_webgpu.Color | { r: number; g: number; b: number }
|
|
179
|
+
? 'color'
|
|
180
|
+
: T extends three_webgpu.Vector4 | { x: number; y: number; z: number; w: number }
|
|
181
|
+
? 'vec4'
|
|
182
|
+
: T extends three_webgpu.Vector3 | { x: number; y: number; z: number }
|
|
183
|
+
? 'vec3'
|
|
184
|
+
: T extends three_webgpu.Vector2 | { x: number; y: number }
|
|
185
|
+
? 'vec2'
|
|
186
|
+
: T extends three_webgpu.Matrix4
|
|
187
|
+
? 'mat4'
|
|
188
|
+
: T extends three_webgpu.Matrix3
|
|
189
|
+
? 'mat3'
|
|
190
|
+
: T extends three_webgpu.Matrix2
|
|
191
|
+
? 'mat2'
|
|
192
|
+
: unknown
|
|
181
193
|
|
|
182
194
|
/** Derive the normalized JavaScript value stored by a uniform node. */
|
|
183
195
|
type UniformNodeValue<T> = T extends three_webgpu.UniformNode<infer _TNodeType, infer TValue>
|
|
184
196
|
? TValue
|
|
185
197
|
: T extends three_webgpu.InputNode<infer _TNodeType, infer TValue>
|
|
186
198
|
? 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
|
|
199
|
+
: T extends TSLConstNode<infer _TNodeType, infer TValue>
|
|
200
|
+
? TValue
|
|
201
|
+
: T extends string | { r: number; g: number; b: number }
|
|
202
|
+
? three_webgpu.Color
|
|
203
|
+
: T extends { x: number; y: number; z: number; w: number }
|
|
204
|
+
? three_webgpu.Vector4
|
|
205
|
+
: T extends { x: number; y: number; z: number }
|
|
206
|
+
? three_webgpu.Vector3
|
|
207
|
+
: T extends { x: number; y: number }
|
|
208
|
+
? three_webgpu.Vector2
|
|
209
|
+
: T extends number
|
|
210
|
+
? number
|
|
211
|
+
: T extends boolean
|
|
212
|
+
? boolean
|
|
213
|
+
: T
|
|
200
214
|
|
|
201
215
|
/** Three's exact UniformNode with shader and value generics derived from an input. */
|
|
202
216
|
type UniformNodeFor<T> = three_webgpu.UniformNode<UniformNodeType<T>, UniformNodeValue<T>>
|
|
@@ -381,10 +395,17 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
|
381
395
|
*
|
|
382
396
|
* @example
|
|
383
397
|
* ```tsx
|
|
398
|
+
* // With uniforms registered (see `Register` and the Typed Uniforms guide), reads are typed by name
|
|
384
399
|
* useLocalNodes(({ uniforms }) => ({
|
|
385
|
-
* wobble: sin(uniforms.uTime.mul(2)),
|
|
386
|
-
* playerHealth: uniforms.scope('player').uHealth //
|
|
387
|
-
* }))
|
|
400
|
+
* wobble: sin(uniforms.uTime.mul(2)),
|
|
401
|
+
* playerHealth: uniforms.scope('player').uHealth, // or uniforms.player.uHealth
|
|
402
|
+
* }), [])
|
|
403
|
+
*
|
|
404
|
+
* // Without registration, give a scope its schema
|
|
405
|
+
* useLocalNodes(({ uniforms }) => {
|
|
406
|
+
* const player = uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')
|
|
407
|
+
* return { damage: player.uHealth.mul(2) }
|
|
408
|
+
* }, [])
|
|
388
409
|
* ```
|
|
389
410
|
*/
|
|
390
411
|
|
|
@@ -619,32 +640,81 @@ declare function rebuildAllNodes(store: ReturnType<typeof useStore>, scope?: str
|
|
|
619
640
|
/** Creator receives CreatorState with ScopedStore wrappers for type-safe access. Returns any record. */
|
|
620
641
|
type LocalNodeCreator<T extends Record<string, unknown>> = (state: CreatorState) => T;
|
|
621
642
|
/**
|
|
622
|
-
*
|
|
643
|
+
* The install step an install-form creator returns: it runs after commit (as a layout effect) and
|
|
644
|
+
* may return a cleanup, which runs before the next install and on unmount.
|
|
645
|
+
*/
|
|
646
|
+
type LocalNodeInstall = () => void | (() => void);
|
|
647
|
+
/** A creator that builds during render and returns an install step instead of a record. */
|
|
648
|
+
type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
|
|
649
|
+
/**
|
|
650
|
+
* Creates component-local values from the rendering context and the shared TSL resources.
|
|
651
|
+
*
|
|
652
|
+
* Unlike `useNodes`, this does NOT register to the global store — nothing is published during
|
|
653
|
+
* render or commit. The creator runs in the render phase and is pure computation.
|
|
654
|
+
*
|
|
655
|
+
* **When the creator re-runs** is controlled by the optional `deps` array, mirroring `useMemo`:
|
|
623
656
|
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
657
|
+
* | Call | Ordinary component renders |
|
|
658
|
+
* | -------------------------------- | ----------------------------------------------------------- |
|
|
659
|
+
* | `useLocalNodes(creator)` | Re-evaluate every render, even with a `useCallback` creator |
|
|
660
|
+
* | `useLocalNodes(creator, [])` | Reuse the result |
|
|
661
|
+
* | `useLocalNodes(creator, [a, b])` | Reuse until a declared dependency changes by `Object.is` |
|
|
662
|
+
*
|
|
663
|
+
* Independently of `deps`, three things re-run the creator: a change to a shared resource the
|
|
664
|
+
* creator READ (replaced, removed, or appearing where it read nothing), a change of the owning
|
|
665
|
+
* (primary) store, and an HMR / `rebuild*` invalidation. Registrations the creator did not read
|
|
666
|
+
* change nothing, and writing `.value` on a uniform it read is not a change. `[]` therefore means
|
|
667
|
+
* "no JavaScript construction inputs", not "never rebuild". Whenever it re-runs, the creator from
|
|
668
|
+
* the CURRENT render is used; creator identity itself is never a rebuild trigger once an array is
|
|
669
|
+
* supplied.
|
|
670
|
+
*
|
|
671
|
+
* Only reads the creator makes before it returns are tracked. Inside `Fn(() => …)` the body runs
|
|
672
|
+
* later, while three builds the shader, so read the resource in the creator and close over it.
|
|
673
|
+
*
|
|
674
|
+
* `[]` is the normal case. A value that changes (a color prop, a slider) belongs in a uniform: the
|
|
675
|
+
* graph references the `UniformNode`, so updating its `.value` needs no rebuild and must not be a
|
|
676
|
+
* dependency. Declare only inputs that decide the graph's structure and cannot be uniforms: which
|
|
677
|
+
* node to use, a loop count, whether a branch exists.
|
|
678
|
+
*
|
|
679
|
+
* **Install form.** To put a node onto a Three object (`scene.fogNode`, `scene.backgroundNode`),
|
|
680
|
+
* return a function instead of a record. The creator still builds during render; the returned
|
|
681
|
+
* function runs after commit and may return a cleanup, which runs before the next install and on
|
|
682
|
+
* unmount. Mutating a Three object inside the creator itself is unsafe: React can discard a
|
|
683
|
+
* render, and StrictMode renders twice. The hook returns nothing in this form.
|
|
684
|
+
*
|
|
685
|
+
* ```tsx
|
|
686
|
+
* useLocalNodes(({ scene, uniforms }) => {
|
|
687
|
+
* const fogNode = fog(uniforms.fogColor, rangeFogFactor(uniforms.near, uniforms.far))
|
|
688
|
+
* return () => {
|
|
689
|
+
* scene.fogNode = fogNode
|
|
690
|
+
* return () => { scene.fogNode = null }
|
|
691
|
+
* }
|
|
692
|
+
* }, [])
|
|
693
|
+
* ```
|
|
626
694
|
*
|
|
627
695
|
* @example
|
|
628
696
|
* ```tsx
|
|
629
|
-
* //
|
|
697
|
+
* // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed when the
|
|
698
|
+
* // app registers its uniforms (see `Register`); otherwise give a scope its schema or cast.
|
|
630
699
|
* const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
|
|
631
700
|
* wobble: sin(uniforms.uTime.mul(2)),
|
|
632
|
-
* uTime: uniforms.uTime,
|
|
633
|
-
* }))
|
|
701
|
+
* uTime: uniforms.uTime, // can return uniforms too
|
|
702
|
+
* }), [])
|
|
634
703
|
*
|
|
635
|
-
* //
|
|
636
|
-
* const {
|
|
637
|
-
*
|
|
638
|
-
* }))
|
|
704
|
+
* // `pattern` picks which node the graph is built from: a structural input.
|
|
705
|
+
* const { result } = useLocalNodes(({ nodes }) => ({
|
|
706
|
+
* result: pattern === 'noise' ? nodes.noise : nodes.stripes,
|
|
707
|
+
* }), [pattern])
|
|
639
708
|
*
|
|
640
|
-
* //
|
|
709
|
+
* // An unregistered uniform, cast to its type
|
|
641
710
|
* const { colorNode } = useLocalNodes(({ uniforms }) => {
|
|
642
|
-
* const uValue = uniforms.myUniform as UniformNode<number>
|
|
711
|
+
* const uValue = uniforms.myUniform as UniformNode<'float', number>
|
|
643
712
|
* return { colorNode: mix(colorA, colorB, uValue) }
|
|
644
|
-
* })
|
|
713
|
+
* }, [])
|
|
645
714
|
* ```
|
|
646
715
|
*/
|
|
647
|
-
declare function useLocalNodes
|
|
716
|
+
declare function useLocalNodes(creator: LocalNodeInstaller, deps?: React.DependencyList): void;
|
|
717
|
+
declare function useLocalNodes<T extends Record<string, unknown>>(creator: LocalNodeCreator<T>, deps?: React.DependencyList): T;
|
|
648
718
|
|
|
649
719
|
/**
|
|
650
720
|
* A record of buffer-like values - allows mixed types (TypedArrays, BufferAttributes, TSL nodes)
|
|
@@ -774,4 +844,4 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
774
844
|
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
|
|
775
845
|
|
|
776
846
|
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 };
|
|
847
|
+
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 };
|