@react-three/tsl 10.0.0-canary.490e4992 → 10.0.0-canary.590ca48
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 +318 -27
- package/dist/index.d.cts +76 -20
- package/dist/index.d.mts +76 -20
- package/dist/index.d.ts +76 -20
- package/dist/index.mjs +320 -29
- package/package.json +3 -3
- package/readme.md +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -112,8 +112,8 @@ interface TSLRootState {
|
|
|
112
112
|
passes?: PassRecord
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
//
|
|
115
|
+
// Every fiber entry shares one core, and so one RootState: augmenting it through the root entry
|
|
116
|
+
// reaches /legacy, /webgpu and /extension as well.
|
|
117
117
|
declare module '@react-three/fiber' {
|
|
118
118
|
interface RootState extends TSLRootState {}
|
|
119
119
|
}
|
|
@@ -381,10 +381,17 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
|
381
381
|
*
|
|
382
382
|
* @example
|
|
383
383
|
* ```tsx
|
|
384
|
+
* // With uniforms registered (see `Register` and the Typed Uniforms guide), reads are typed by name
|
|
384
385
|
* useLocalNodes(({ uniforms }) => ({
|
|
385
|
-
* wobble: sin(uniforms.uTime.mul(2)),
|
|
386
|
-
* playerHealth: uniforms.scope('player').uHealth //
|
|
387
|
-
* }))
|
|
386
|
+
* wobble: sin(uniforms.uTime.mul(2)),
|
|
387
|
+
* playerHealth: uniforms.scope('player').uHealth, // or uniforms.player.uHealth
|
|
388
|
+
* }), [])
|
|
389
|
+
*
|
|
390
|
+
* // Without registration, give a scope its schema
|
|
391
|
+
* useLocalNodes(({ uniforms }) => {
|
|
392
|
+
* const player = uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')
|
|
393
|
+
* return { damage: player.uHealth.mul(2) }
|
|
394
|
+
* }, [])
|
|
388
395
|
* ```
|
|
389
396
|
*/
|
|
390
397
|
|
|
@@ -619,32 +626,81 @@ declare function rebuildAllNodes(store: ReturnType<typeof useStore>, scope?: str
|
|
|
619
626
|
/** Creator receives CreatorState with ScopedStore wrappers for type-safe access. Returns any record. */
|
|
620
627
|
type LocalNodeCreator<T extends Record<string, unknown>> = (state: CreatorState) => T;
|
|
621
628
|
/**
|
|
622
|
-
*
|
|
629
|
+
* The install step an install-form creator returns: it runs after commit (as a layout effect) and
|
|
630
|
+
* may return a cleanup, which runs before the next install and on unmount.
|
|
631
|
+
*/
|
|
632
|
+
type LocalNodeInstall = () => void | (() => void);
|
|
633
|
+
/** A creator that builds during render and returns an install step instead of a record. */
|
|
634
|
+
type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
|
|
635
|
+
/**
|
|
636
|
+
* Creates component-local values from the rendering context and the shared TSL resources.
|
|
637
|
+
*
|
|
638
|
+
* Unlike `useNodes`, this does NOT register to the global store — nothing is published during
|
|
639
|
+
* render or commit. The creator runs in the render phase and is pure computation.
|
|
640
|
+
*
|
|
641
|
+
* **When the creator re-runs** is controlled by the optional `deps` array, mirroring `useMemo`:
|
|
642
|
+
*
|
|
643
|
+
* | Call | Ordinary component renders |
|
|
644
|
+
* | -------------------------------- | ----------------------------------------------------------- |
|
|
645
|
+
* | `useLocalNodes(creator)` | Re-evaluate every render, even with a `useCallback` creator |
|
|
646
|
+
* | `useLocalNodes(creator, [])` | Reuse the result |
|
|
647
|
+
* | `useLocalNodes(creator, [a, b])` | Reuse until a declared dependency changes by `Object.is` |
|
|
648
|
+
*
|
|
649
|
+
* Independently of `deps`, three things re-run the creator: a change to a shared resource the
|
|
650
|
+
* creator READ (replaced, removed, or appearing where it read nothing), a change of the owning
|
|
651
|
+
* (primary) store, and an HMR / `rebuild*` invalidation. Registrations the creator did not read
|
|
652
|
+
* change nothing, and writing `.value` on a uniform it read is not a change. `[]` therefore means
|
|
653
|
+
* "no JavaScript construction inputs", not "never rebuild". Whenever it re-runs, the creator from
|
|
654
|
+
* the CURRENT render is used; creator identity itself is never a rebuild trigger once an array is
|
|
655
|
+
* supplied.
|
|
623
656
|
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
657
|
+
* Only reads the creator makes before it returns are tracked. Inside `Fn(() => …)` the body runs
|
|
658
|
+
* later, while three builds the shader, so read the resource in the creator and close over it.
|
|
659
|
+
*
|
|
660
|
+
* `[]` is the normal case. A value that changes (a color prop, a slider) belongs in a uniform: the
|
|
661
|
+
* graph references the `UniformNode`, so updating its `.value` needs no rebuild and must not be a
|
|
662
|
+
* dependency. Declare only inputs that decide the graph's structure and cannot be uniforms: which
|
|
663
|
+
* node to use, a loop count, whether a branch exists.
|
|
664
|
+
*
|
|
665
|
+
* **Install form.** To put a node onto a Three object (`scene.fogNode`, `scene.backgroundNode`),
|
|
666
|
+
* return a function instead of a record. The creator still builds during render; the returned
|
|
667
|
+
* function runs after commit and may return a cleanup, which runs before the next install and on
|
|
668
|
+
* unmount. Mutating a Three object inside the creator itself is unsafe: React can discard a
|
|
669
|
+
* render, and StrictMode renders twice. The hook returns nothing in this form.
|
|
670
|
+
*
|
|
671
|
+
* ```tsx
|
|
672
|
+
* useLocalNodes(({ scene, uniforms }) => {
|
|
673
|
+
* const fogNode = fog(uniforms.fogColor, rangeFogFactor(uniforms.near, uniforms.far))
|
|
674
|
+
* return () => {
|
|
675
|
+
* scene.fogNode = fogNode
|
|
676
|
+
* return () => { scene.fogNode = null }
|
|
677
|
+
* }
|
|
678
|
+
* }, [])
|
|
679
|
+
* ```
|
|
626
680
|
*
|
|
627
681
|
* @example
|
|
628
682
|
* ```tsx
|
|
629
|
-
* //
|
|
683
|
+
* // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed when the
|
|
684
|
+
* // app registers its uniforms (see `Register`); otherwise give a scope its schema or cast.
|
|
630
685
|
* const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
|
|
631
686
|
* wobble: sin(uniforms.uTime.mul(2)),
|
|
632
|
-
* uTime: uniforms.uTime,
|
|
633
|
-
* }))
|
|
687
|
+
* uTime: uniforms.uTime, // can return uniforms too
|
|
688
|
+
* }), [])
|
|
634
689
|
*
|
|
635
|
-
* //
|
|
636
|
-
* const {
|
|
637
|
-
*
|
|
638
|
-
* }))
|
|
690
|
+
* // `pattern` picks which node the graph is built from: a structural input.
|
|
691
|
+
* const { result } = useLocalNodes(({ nodes }) => ({
|
|
692
|
+
* result: pattern === 'noise' ? nodes.noise : nodes.stripes,
|
|
693
|
+
* }), [pattern])
|
|
639
694
|
*
|
|
640
|
-
* //
|
|
695
|
+
* // An unregistered uniform, cast to its type
|
|
641
696
|
* const { colorNode } = useLocalNodes(({ uniforms }) => {
|
|
642
|
-
* const uValue = uniforms.myUniform as UniformNode<number>
|
|
697
|
+
* const uValue = uniforms.myUniform as UniformNode<'float', number>
|
|
643
698
|
* return { colorNode: mix(colorA, colorB, uValue) }
|
|
644
|
-
* })
|
|
699
|
+
* }, [])
|
|
645
700
|
* ```
|
|
646
701
|
*/
|
|
647
|
-
declare function useLocalNodes
|
|
702
|
+
declare function useLocalNodes(creator: LocalNodeInstaller, deps?: React.DependencyList): void;
|
|
703
|
+
declare function useLocalNodes<T extends Record<string, unknown>>(creator: LocalNodeCreator<T>, deps?: React.DependencyList): T;
|
|
648
704
|
|
|
649
705
|
/**
|
|
650
706
|
* A record of buffer-like values - allows mixed types (TypedArrays, BufferAttributes, TSL nodes)
|
|
@@ -774,4 +830,4 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
774
830
|
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
|
|
775
831
|
|
|
776
832
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -112,8 +112,8 @@ interface TSLRootState {
|
|
|
112
112
|
passes?: PassRecord
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
//
|
|
115
|
+
// Every fiber entry shares one core, and so one RootState: augmenting it through the root entry
|
|
116
|
+
// reaches /legacy, /webgpu and /extension as well.
|
|
117
117
|
declare module '@react-three/fiber' {
|
|
118
118
|
interface RootState extends TSLRootState {}
|
|
119
119
|
}
|
|
@@ -381,10 +381,17 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
|
|
|
381
381
|
*
|
|
382
382
|
* @example
|
|
383
383
|
* ```tsx
|
|
384
|
+
* // With uniforms registered (see `Register` and the Typed Uniforms guide), reads are typed by name
|
|
384
385
|
* useLocalNodes(({ uniforms }) => ({
|
|
385
|
-
* wobble: sin(uniforms.uTime.mul(2)),
|
|
386
|
-
* playerHealth: uniforms.scope('player').uHealth //
|
|
387
|
-
* }))
|
|
386
|
+
* wobble: sin(uniforms.uTime.mul(2)),
|
|
387
|
+
* playerHealth: uniforms.scope('player').uHealth, // or uniforms.player.uHealth
|
|
388
|
+
* }), [])
|
|
389
|
+
*
|
|
390
|
+
* // Without registration, give a scope its schema
|
|
391
|
+
* useLocalNodes(({ uniforms }) => {
|
|
392
|
+
* const player = uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')
|
|
393
|
+
* return { damage: player.uHealth.mul(2) }
|
|
394
|
+
* }, [])
|
|
388
395
|
* ```
|
|
389
396
|
*/
|
|
390
397
|
|
|
@@ -619,32 +626,81 @@ declare function rebuildAllNodes(store: ReturnType<typeof useStore>, scope?: str
|
|
|
619
626
|
/** Creator receives CreatorState with ScopedStore wrappers for type-safe access. Returns any record. */
|
|
620
627
|
type LocalNodeCreator<T extends Record<string, unknown>> = (state: CreatorState) => T;
|
|
621
628
|
/**
|
|
622
|
-
*
|
|
629
|
+
* The install step an install-form creator returns: it runs after commit (as a layout effect) and
|
|
630
|
+
* may return a cleanup, which runs before the next install and on unmount.
|
|
631
|
+
*/
|
|
632
|
+
type LocalNodeInstall = () => void | (() => void);
|
|
633
|
+
/** A creator that builds during render and returns an install step instead of a record. */
|
|
634
|
+
type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
|
|
635
|
+
/**
|
|
636
|
+
* Creates component-local values from the rendering context and the shared TSL resources.
|
|
637
|
+
*
|
|
638
|
+
* Unlike `useNodes`, this does NOT register to the global store — nothing is published during
|
|
639
|
+
* render or commit. The creator runs in the render phase and is pure computation.
|
|
640
|
+
*
|
|
641
|
+
* **When the creator re-runs** is controlled by the optional `deps` array, mirroring `useMemo`:
|
|
642
|
+
*
|
|
643
|
+
* | Call | Ordinary component renders |
|
|
644
|
+
* | -------------------------------- | ----------------------------------------------------------- |
|
|
645
|
+
* | `useLocalNodes(creator)` | Re-evaluate every render, even with a `useCallback` creator |
|
|
646
|
+
* | `useLocalNodes(creator, [])` | Reuse the result |
|
|
647
|
+
* | `useLocalNodes(creator, [a, b])` | Reuse until a declared dependency changes by `Object.is` |
|
|
648
|
+
*
|
|
649
|
+
* Independently of `deps`, three things re-run the creator: a change to a shared resource the
|
|
650
|
+
* creator READ (replaced, removed, or appearing where it read nothing), a change of the owning
|
|
651
|
+
* (primary) store, and an HMR / `rebuild*` invalidation. Registrations the creator did not read
|
|
652
|
+
* change nothing, and writing `.value` on a uniform it read is not a change. `[]` therefore means
|
|
653
|
+
* "no JavaScript construction inputs", not "never rebuild". Whenever it re-runs, the creator from
|
|
654
|
+
* the CURRENT render is used; creator identity itself is never a rebuild trigger once an array is
|
|
655
|
+
* supplied.
|
|
623
656
|
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
657
|
+
* Only reads the creator makes before it returns are tracked. Inside `Fn(() => …)` the body runs
|
|
658
|
+
* later, while three builds the shader, so read the resource in the creator and close over it.
|
|
659
|
+
*
|
|
660
|
+
* `[]` is the normal case. A value that changes (a color prop, a slider) belongs in a uniform: the
|
|
661
|
+
* graph references the `UniformNode`, so updating its `.value` needs no rebuild and must not be a
|
|
662
|
+
* dependency. Declare only inputs that decide the graph's structure and cannot be uniforms: which
|
|
663
|
+
* node to use, a loop count, whether a branch exists.
|
|
664
|
+
*
|
|
665
|
+
* **Install form.** To put a node onto a Three object (`scene.fogNode`, `scene.backgroundNode`),
|
|
666
|
+
* return a function instead of a record. The creator still builds during render; the returned
|
|
667
|
+
* function runs after commit and may return a cleanup, which runs before the next install and on
|
|
668
|
+
* unmount. Mutating a Three object inside the creator itself is unsafe: React can discard a
|
|
669
|
+
* render, and StrictMode renders twice. The hook returns nothing in this form.
|
|
670
|
+
*
|
|
671
|
+
* ```tsx
|
|
672
|
+
* useLocalNodes(({ scene, uniforms }) => {
|
|
673
|
+
* const fogNode = fog(uniforms.fogColor, rangeFogFactor(uniforms.near, uniforms.far))
|
|
674
|
+
* return () => {
|
|
675
|
+
* scene.fogNode = fogNode
|
|
676
|
+
* return () => { scene.fogNode = null }
|
|
677
|
+
* }
|
|
678
|
+
* }, [])
|
|
679
|
+
* ```
|
|
626
680
|
*
|
|
627
681
|
* @example
|
|
628
682
|
* ```tsx
|
|
629
|
-
* //
|
|
683
|
+
* // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed when the
|
|
684
|
+
* // app registers its uniforms (see `Register`); otherwise give a scope its schema or cast.
|
|
630
685
|
* const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
|
|
631
686
|
* wobble: sin(uniforms.uTime.mul(2)),
|
|
632
|
-
* uTime: uniforms.uTime,
|
|
633
|
-
* }))
|
|
687
|
+
* uTime: uniforms.uTime, // can return uniforms too
|
|
688
|
+
* }), [])
|
|
634
689
|
*
|
|
635
|
-
* //
|
|
636
|
-
* const {
|
|
637
|
-
*
|
|
638
|
-
* }))
|
|
690
|
+
* // `pattern` picks which node the graph is built from: a structural input.
|
|
691
|
+
* const { result } = useLocalNodes(({ nodes }) => ({
|
|
692
|
+
* result: pattern === 'noise' ? nodes.noise : nodes.stripes,
|
|
693
|
+
* }), [pattern])
|
|
639
694
|
*
|
|
640
|
-
* //
|
|
695
|
+
* // An unregistered uniform, cast to its type
|
|
641
696
|
* const { colorNode } = useLocalNodes(({ uniforms }) => {
|
|
642
|
-
* const uValue = uniforms.myUniform as UniformNode<number>
|
|
697
|
+
* const uValue = uniforms.myUniform as UniformNode<'float', number>
|
|
643
698
|
* return { colorNode: mix(colorA, colorB, uValue) }
|
|
644
|
-
* })
|
|
699
|
+
* }, [])
|
|
645
700
|
* ```
|
|
646
701
|
*/
|
|
647
|
-
declare function useLocalNodes
|
|
702
|
+
declare function useLocalNodes(creator: LocalNodeInstaller, deps?: React.DependencyList): void;
|
|
703
|
+
declare function useLocalNodes<T extends Record<string, unknown>>(creator: LocalNodeCreator<T>, deps?: React.DependencyList): T;
|
|
648
704
|
|
|
649
705
|
/**
|
|
650
706
|
* A record of buffer-like values - allows mixed types (TypedArrays, BufferAttributes, TSL nodes)
|
|
@@ -774,4 +830,4 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
|
|
|
774
830
|
declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
|
|
775
831
|
|
|
776
832
|
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 };
|
|
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 };
|