@react-three/tsl 10.0.0-canary.d202062 → 10.0.0-canary.d46ab63
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 +26 -33
- package/dist/index.d.cts +314 -85
- package/dist/index.d.mts +314 -85
- package/dist/index.d.ts +314 -85
- package/dist/index.mjs +26 -33
- package/package.json +2 -2
- package/readme.md +1 -1
package/dist/index.mjs
CHANGED
|
@@ -58,6 +58,13 @@ function withStagedOverlay(store, kind, committed) {
|
|
|
58
58
|
}
|
|
59
59
|
return view;
|
|
60
60
|
}
|
|
61
|
+
function readWithStaged(store, kind, committed, scope, isLeaf) {
|
|
62
|
+
if (scope === void 0) return withStagedOverlay(store, kind, committed);
|
|
63
|
+
const scopeData = committed[scope];
|
|
64
|
+
const current = scopeData && typeof scopeData === "object" && !isLeaf(scopeData) ? scopeData : {};
|
|
65
|
+
const staged = scope === ROOT_SCOPE ? void 0 : peekStaged(store, kind, scope);
|
|
66
|
+
return staged ? { ...current, ...staged } : current;
|
|
67
|
+
}
|
|
61
68
|
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
62
69
|
const registry = getKindRegistry(store, kind);
|
|
63
70
|
const staged = registry.staged.get(scopeKey);
|
|
@@ -162,6 +169,10 @@ function extractTSLValue(value) {
|
|
|
162
169
|
if (node.isConstNode) {
|
|
163
170
|
return node.value;
|
|
164
171
|
}
|
|
172
|
+
if (node.isVarNode && node.node) {
|
|
173
|
+
const inner = extractTSLValue(node.node);
|
|
174
|
+
return inner === node.node ? value : inner;
|
|
175
|
+
}
|
|
165
176
|
if ("value" in node) {
|
|
166
177
|
let extractedValue = node.value;
|
|
167
178
|
if (typeof node.traverse === "function") {
|
|
@@ -685,8 +696,9 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
685
696
|
input: memoizedInput,
|
|
686
697
|
create: () => {
|
|
687
698
|
if (isReader) return {};
|
|
688
|
-
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null)
|
|
699
|
+
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null) {
|
|
689
700
|
throw new Error("Invalid uniform input");
|
|
701
|
+
}
|
|
690
702
|
return processedInput.candidates;
|
|
691
703
|
},
|
|
692
704
|
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
@@ -704,13 +716,7 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
704
716
|
if (!equals) existing.value = newVal;
|
|
705
717
|
}
|
|
706
718
|
});
|
|
707
|
-
|
|
708
|
-
if (memoizedInput === void 0) {
|
|
709
|
-
uniforms = storeUniforms;
|
|
710
|
-
} else if (typeof memoizedInput === "string") {
|
|
711
|
-
const scopeData = storeUniforms[memoizedInput];
|
|
712
|
-
uniforms = scopeData && !isUniformNode(scopeData) ? scopeData : {};
|
|
713
|
-
}
|
|
719
|
+
const uniforms = isReader ? readWithStaged(store, "uniforms", storeUniforms, memoizedInput, isUniformNode) : created;
|
|
714
720
|
return { ...uniforms, removeUniforms, clearUniforms, rebuildUniforms };
|
|
715
721
|
}
|
|
716
722
|
function rebuildAllUniforms(store, scope) {
|
|
@@ -744,18 +750,20 @@ function isSameThreeType(a, b) {
|
|
|
744
750
|
const uniformOf = uniform;
|
|
745
751
|
function useUniform(name, value) {
|
|
746
752
|
const store = usePrimaryStore();
|
|
753
|
+
const memoizedInput = useCompareMemoize(value === void 0 ? name : { [name]: normalizeValue(value) });
|
|
747
754
|
const registered = useScopedResource({
|
|
748
755
|
store,
|
|
749
756
|
kind: "uniforms",
|
|
750
757
|
scope: void 0,
|
|
751
758
|
isLeaf: isUniformNode,
|
|
752
|
-
input:
|
|
759
|
+
input: memoizedInput,
|
|
753
760
|
create: () => value === void 0 ? {} : { [name]: value },
|
|
754
761
|
prepare: createNamedUniform,
|
|
755
762
|
reconcile: (existing2) => {
|
|
756
|
-
if (value
|
|
757
|
-
|
|
758
|
-
|
|
763
|
+
if (value === void 0 || isUniformNode(value)) return;
|
|
764
|
+
const next = normalizeValue(value);
|
|
765
|
+
if (isTSLNode(next)) return;
|
|
766
|
+
existing2.value = next;
|
|
759
767
|
}
|
|
760
768
|
});
|
|
761
769
|
if (registered[name]) return registered[name];
|
|
@@ -765,6 +773,9 @@ function useUniform(name, value) {
|
|
|
765
773
|
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
766
774
|
);
|
|
767
775
|
}
|
|
776
|
+
function normalizeValue(value) {
|
|
777
|
+
return typeof value === "string" ? new Color(value) : vectorize(value);
|
|
778
|
+
}
|
|
768
779
|
function createNamedUniform(name, value) {
|
|
769
780
|
let node;
|
|
770
781
|
if (isUniformNode(value)) {
|
|
@@ -822,13 +833,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
822
833
|
return node;
|
|
823
834
|
}
|
|
824
835
|
});
|
|
825
|
-
|
|
826
|
-
if (creatorOrScope === void 0) {
|
|
827
|
-
nodes = storeNodes;
|
|
828
|
-
} else if (typeof creatorOrScope === "string") {
|
|
829
|
-
const scopeData = storeNodes[creatorOrScope];
|
|
830
|
-
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
831
|
-
}
|
|
836
|
+
const nodes = isReader ? readWithStaged(store, "nodes", storeNodes, creatorOrScope, isTSLNode) : created;
|
|
832
837
|
return { ...nodes, removeNodes, clearNodes, rebuildNodes };
|
|
833
838
|
}
|
|
834
839
|
function rebuildAllNodes(store, scope) {
|
|
@@ -983,13 +988,7 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
983
988
|
return buffer;
|
|
984
989
|
}
|
|
985
990
|
});
|
|
986
|
-
|
|
987
|
-
if (creatorOrScope === void 0) {
|
|
988
|
-
buffers = storeBuffers;
|
|
989
|
-
} else if (typeof creatorOrScope === "string") {
|
|
990
|
-
const scopeData = storeBuffers[creatorOrScope];
|
|
991
|
-
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
992
|
-
}
|
|
991
|
+
const buffers = isReader ? readWithStaged(store, "buffers", storeBuffers, creatorOrScope, isBufferLike) : created;
|
|
993
992
|
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
994
993
|
}
|
|
995
994
|
function rebuildAllBuffers(store, scope) {
|
|
@@ -1053,13 +1052,7 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
1053
1052
|
return storage;
|
|
1054
1053
|
}
|
|
1055
1054
|
});
|
|
1056
|
-
|
|
1057
|
-
if (creatorOrScope === void 0) {
|
|
1058
|
-
gpuStorage = storeStorage;
|
|
1059
|
-
} else if (typeof creatorOrScope === "string") {
|
|
1060
|
-
const scopeData = storeStorage[creatorOrScope];
|
|
1061
|
-
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
1062
|
-
}
|
|
1055
|
+
const gpuStorage = isReader ? readWithStaged(store, "gpuStorage", storeStorage, creatorOrScope, isStorageLike) : created;
|
|
1063
1056
|
return {
|
|
1064
1057
|
...gpuStorage,
|
|
1065
1058
|
removeStorage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/tsl",
|
|
3
|
-
"version": "10.0.0-canary.
|
|
3
|
+
"version": "10.0.0-canary.d46ab63",
|
|
4
4
|
"description": "TSL resource hooks for react-three-fiber: uniforms, nodes, buffers, GPU storage and render pipelines on WebGPU",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/three": "^0.185.0",
|
|
57
57
|
"@webgpu/types": "^0.1.64",
|
|
58
58
|
"three": ">=0.185.0",
|
|
59
|
-
"@react-three/fiber": "10.0.0-canary.
|
|
59
|
+
"@react-three/fiber": "10.0.0-canary.d46ab63"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "unbuild",
|
package/readme.md
CHANGED
|
@@ -46,7 +46,7 @@ export const App = () => (
|
|
|
46
46
|
| `useBuffers`, `useGPUStorage` | Buffers and storage textures for compute |
|
|
47
47
|
| `useRenderPipeline` | Post-processing with three's `RenderPipeline` (scene pass, MRT, output node) |
|
|
48
48
|
|
|
49
|
-
Resources belong to the renderer: a primary
|
|
49
|
+
Resources belong to the renderer: a `<Canvas primary>`, the canvases sharing its renderer (every other WebGPU canvas, or `share="id"`) and every portal inside them share one set. They live on the primary canvas's `RootState` (`state.uniforms`, `state.nodes`, `state.buffers`, `state.gpuStorage`); secondaries hold the same objects and portals inherit them from their parent (a portal's scene and camera stay its own), so `state.uniforms` reads the same everywhere.
|
|
50
50
|
|
|
51
51
|
Works under any Canvas that runs the WebGPU renderer: `@react-three/fiber` with the `renderer` prop, or `@react-three/fiber/webgpu`. It reaches fiber only through the three-free `@react-three/fiber/extension` entry, so it adds no renderer and no second copy of fiber to your bundle.
|
|
52
52
|
|