@react-three/tsl 10.0.0-canary.e3891fb → 10.0.0-canary.e78793c
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 +3 -3
- package/readme.md +1 -1
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,13 @@ function withStagedOverlay(store, kind, committed) {
|
|
|
73
73
|
}
|
|
74
74
|
return view;
|
|
75
75
|
}
|
|
76
|
+
function readWithStaged(store, kind, committed, scope, isLeaf) {
|
|
77
|
+
if (scope === void 0) return withStagedOverlay(store, kind, committed);
|
|
78
|
+
const scopeData = committed[scope];
|
|
79
|
+
const current = scopeData && typeof scopeData === "object" && !isLeaf(scopeData) ? scopeData : {};
|
|
80
|
+
const staged = scope === ROOT_SCOPE ? void 0 : peekStaged(store, kind, scope);
|
|
81
|
+
return staged ? { ...current, ...staged } : current;
|
|
82
|
+
}
|
|
76
83
|
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
77
84
|
const registry = getKindRegistry(store, kind);
|
|
78
85
|
const staged = registry.staged.get(scopeKey);
|
|
@@ -177,6 +184,10 @@ function extractTSLValue(value) {
|
|
|
177
184
|
if (node.isConstNode) {
|
|
178
185
|
return node.value;
|
|
179
186
|
}
|
|
187
|
+
if (node.isVarNode && node.node) {
|
|
188
|
+
const inner = extractTSLValue(node.node);
|
|
189
|
+
return inner === node.node ? value : inner;
|
|
190
|
+
}
|
|
180
191
|
if ("value" in node) {
|
|
181
192
|
let extractedValue = node.value;
|
|
182
193
|
if (typeof node.traverse === "function") {
|
|
@@ -700,8 +711,9 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
700
711
|
input: memoizedInput,
|
|
701
712
|
create: () => {
|
|
702
713
|
if (isReader) return {};
|
|
703
|
-
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null)
|
|
714
|
+
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null) {
|
|
704
715
|
throw new Error("Invalid uniform input");
|
|
716
|
+
}
|
|
705
717
|
return processedInput.candidates;
|
|
706
718
|
},
|
|
707
719
|
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
@@ -719,13 +731,7 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
719
731
|
if (!equals) existing.value = newVal;
|
|
720
732
|
}
|
|
721
733
|
});
|
|
722
|
-
|
|
723
|
-
if (memoizedInput === void 0) {
|
|
724
|
-
uniforms = storeUniforms;
|
|
725
|
-
} else if (typeof memoizedInput === "string") {
|
|
726
|
-
const scopeData = storeUniforms[memoizedInput];
|
|
727
|
-
uniforms = scopeData && !isUniformNode(scopeData) ? scopeData : {};
|
|
728
|
-
}
|
|
734
|
+
const uniforms = isReader ? readWithStaged(store, "uniforms", storeUniforms, memoizedInput, isUniformNode) : created;
|
|
729
735
|
return { ...uniforms, removeUniforms, clearUniforms, rebuildUniforms };
|
|
730
736
|
}
|
|
731
737
|
function rebuildAllUniforms(store, scope) {
|
|
@@ -759,18 +765,20 @@ function isSameThreeType(a, b) {
|
|
|
759
765
|
const uniformOf = tsl.uniform;
|
|
760
766
|
function useUniform(name, value) {
|
|
761
767
|
const store = usePrimaryStore();
|
|
768
|
+
const memoizedInput = useCompareMemoize(value === void 0 ? name : { [name]: normalizeValue(value) });
|
|
762
769
|
const registered = useScopedResource({
|
|
763
770
|
store,
|
|
764
771
|
kind: "uniforms",
|
|
765
772
|
scope: void 0,
|
|
766
773
|
isLeaf: isUniformNode,
|
|
767
|
-
input:
|
|
774
|
+
input: memoizedInput,
|
|
768
775
|
create: () => value === void 0 ? {} : { [name]: value },
|
|
769
776
|
prepare: createNamedUniform,
|
|
770
777
|
reconcile: (existing2) => {
|
|
771
|
-
if (value
|
|
772
|
-
|
|
773
|
-
|
|
778
|
+
if (value === void 0 || isUniformNode(value)) return;
|
|
779
|
+
const next = normalizeValue(value);
|
|
780
|
+
if (isTSLNode(next)) return;
|
|
781
|
+
existing2.value = next;
|
|
774
782
|
}
|
|
775
783
|
});
|
|
776
784
|
if (registered[name]) return registered[name];
|
|
@@ -780,6 +788,9 @@ function useUniform(name, value) {
|
|
|
780
788
|
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
781
789
|
);
|
|
782
790
|
}
|
|
791
|
+
function normalizeValue(value) {
|
|
792
|
+
return typeof value === "string" ? new THREE.Color(value) : vectorize(value);
|
|
793
|
+
}
|
|
783
794
|
function createNamedUniform(name, value) {
|
|
784
795
|
let node;
|
|
785
796
|
if (isUniformNode(value)) {
|
|
@@ -837,13 +848,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
837
848
|
return node;
|
|
838
849
|
}
|
|
839
850
|
});
|
|
840
|
-
|
|
841
|
-
if (creatorOrScope === void 0) {
|
|
842
|
-
nodes = storeNodes;
|
|
843
|
-
} else if (typeof creatorOrScope === "string") {
|
|
844
|
-
const scopeData = storeNodes[creatorOrScope];
|
|
845
|
-
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
846
|
-
}
|
|
851
|
+
const nodes = isReader ? readWithStaged(store, "nodes", storeNodes, creatorOrScope, isTSLNode) : created;
|
|
847
852
|
return { ...nodes, removeNodes, clearNodes, rebuildNodes };
|
|
848
853
|
}
|
|
849
854
|
function rebuildAllNodes(store, scope) {
|
|
@@ -998,13 +1003,7 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
998
1003
|
return buffer;
|
|
999
1004
|
}
|
|
1000
1005
|
});
|
|
1001
|
-
|
|
1002
|
-
if (creatorOrScope === void 0) {
|
|
1003
|
-
buffers = storeBuffers;
|
|
1004
|
-
} else if (typeof creatorOrScope === "string") {
|
|
1005
|
-
const scopeData = storeBuffers[creatorOrScope];
|
|
1006
|
-
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
1007
|
-
}
|
|
1006
|
+
const buffers = isReader ? readWithStaged(store, "buffers", storeBuffers, creatorOrScope, isBufferLike) : created;
|
|
1008
1007
|
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
1009
1008
|
}
|
|
1010
1009
|
function rebuildAllBuffers(store, scope) {
|
|
@@ -1068,13 +1067,7 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
1068
1067
|
return storage;
|
|
1069
1068
|
}
|
|
1070
1069
|
});
|
|
1071
|
-
|
|
1072
|
-
if (creatorOrScope === void 0) {
|
|
1073
|
-
gpuStorage = storeStorage;
|
|
1074
|
-
} else if (typeof creatorOrScope === "string") {
|
|
1075
|
-
const scopeData = storeStorage[creatorOrScope];
|
|
1076
|
-
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
1077
|
-
}
|
|
1070
|
+
const gpuStorage = isReader ? readWithStaged(store, "gpuStorage", storeStorage, creatorOrScope, isStorageLike) : created;
|
|
1078
1071
|
return {
|
|
1079
1072
|
...gpuStorage,
|
|
1080
1073
|
removeStorage,
|