@react-three/fiber 10.0.0-canary.5c62eb9 → 10.0.0-canary.60e7a38
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 +365 -135
- package/dist/index.d.cts +68 -31
- package/dist/index.d.mts +68 -31
- package/dist/index.d.ts +68 -31
- package/dist/index.mjs +368 -138
- package/dist/legacy.cjs +320 -90
- package/dist/legacy.d.cts +68 -30
- package/dist/legacy.d.mts +68 -30
- package/dist/legacy.d.ts +68 -30
- package/dist/legacy.mjs +322 -92
- package/dist/webgpu/index.cjs +652 -663
- package/dist/webgpu/index.d.cts +102 -35
- package/dist/webgpu/index.d.mts +102 -35
- package/dist/webgpu/index.d.ts +102 -35
- package/dist/webgpu/index.mjs +655 -666
- package/package.json +3 -3
- package/readme.md +0 -1
package/dist/webgpu/index.cjs
CHANGED
|
@@ -63,13 +63,16 @@ const WebGLRenderer = class WebGLRenderer2 {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
const WebGLRenderTarget = null;
|
|
66
|
+
const WebGLCubeRenderTarget = null;
|
|
66
67
|
|
|
67
68
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
68
69
|
__proto__: null,
|
|
70
|
+
CubeRenderTargetCompat: webgpu.CubeRenderTarget,
|
|
69
71
|
Inspector: Inspector_js.Inspector,
|
|
70
72
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
71
73
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
72
74
|
RenderTargetCompat: webgpu.RenderTarget,
|
|
75
|
+
WebGLCubeRenderTarget: WebGLCubeRenderTarget,
|
|
73
76
|
WebGLRenderTarget: WebGLRenderTarget,
|
|
74
77
|
WebGLRenderer: WebGLRenderer
|
|
75
78
|
}, [webgpu__namespace]);
|
|
@@ -343,15 +346,16 @@ function EnvironmentPortal({
|
|
|
343
346
|
preset = void 0,
|
|
344
347
|
extensions
|
|
345
348
|
}) {
|
|
346
|
-
const
|
|
349
|
+
const renderer = fiber.useThree((state) => state.renderer);
|
|
350
|
+
const isLegacy = fiber.useThree((state) => state.isLegacy);
|
|
347
351
|
const defaultScene = fiber.useThree((state) => state.scene);
|
|
348
352
|
const camera = React__namespace.useRef(null);
|
|
349
353
|
const [virtualScene] = React__namespace.useState(() => new webgpu.Scene());
|
|
350
354
|
const fbo = React__namespace.useMemo(() => {
|
|
351
|
-
const fbo2 = new webgpu.
|
|
355
|
+
const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new webgpu.CubeRenderTarget(resolution);
|
|
352
356
|
fbo2.texture.type = webgpu.HalfFloatType;
|
|
353
357
|
return fbo2;
|
|
354
|
-
}, [resolution]);
|
|
358
|
+
}, [resolution, isLegacy]);
|
|
355
359
|
React__namespace.useEffect(() => {
|
|
356
360
|
return () => {
|
|
357
361
|
fbo.dispose();
|
|
@@ -359,10 +363,10 @@ function EnvironmentPortal({
|
|
|
359
363
|
}, [fbo]);
|
|
360
364
|
React__namespace.useLayoutEffect(() => {
|
|
361
365
|
if (frames === 1) {
|
|
362
|
-
const autoClear =
|
|
363
|
-
|
|
364
|
-
camera.current.update(
|
|
365
|
-
|
|
366
|
+
const autoClear = renderer.autoClear;
|
|
367
|
+
renderer.autoClear = true;
|
|
368
|
+
camera.current.update(renderer, virtualScene);
|
|
369
|
+
renderer.autoClear = autoClear;
|
|
366
370
|
}
|
|
367
371
|
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
368
372
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
@@ -379,7 +383,7 @@ function EnvironmentPortal({
|
|
|
379
383
|
defaultScene,
|
|
380
384
|
background,
|
|
381
385
|
frames,
|
|
382
|
-
|
|
386
|
+
renderer,
|
|
383
387
|
blur,
|
|
384
388
|
backgroundBlurriness,
|
|
385
389
|
backgroundIntensity,
|
|
@@ -390,10 +394,10 @@ function EnvironmentPortal({
|
|
|
390
394
|
let count = 1;
|
|
391
395
|
fiber.useFrame(() => {
|
|
392
396
|
if (frames === Infinity || count < frames) {
|
|
393
|
-
const autoClear =
|
|
394
|
-
|
|
395
|
-
camera.current.update(
|
|
396
|
-
|
|
397
|
+
const autoClear = renderer.autoClear;
|
|
398
|
+
renderer.autoClear = true;
|
|
399
|
+
camera.current.update(renderer, virtualScene);
|
|
400
|
+
renderer.autoClear = autoClear;
|
|
397
401
|
count++;
|
|
398
402
|
}
|
|
399
403
|
});
|
|
@@ -460,7 +464,6 @@ function Environment(props) {
|
|
|
460
464
|
var __defProp$1 = Object.defineProperty;
|
|
461
465
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
462
466
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
463
|
-
const act = React__namespace["act"];
|
|
464
467
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
465
468
|
function useMutableCallback(fn) {
|
|
466
469
|
const ref = React__namespace.useRef(fn);
|
|
@@ -636,8 +639,7 @@ function prepare(target, root, type, props) {
|
|
|
636
639
|
object,
|
|
637
640
|
eventCount: 0,
|
|
638
641
|
handlers: {},
|
|
639
|
-
isHidden: false
|
|
640
|
-
deferredRefs: []
|
|
642
|
+
isHidden: false
|
|
641
643
|
};
|
|
642
644
|
if (object) object.__r3f = instance;
|
|
643
645
|
}
|
|
@@ -794,6 +796,17 @@ function unregisterVisibility(store, object) {
|
|
|
794
796
|
internal.visibilityRegistry.delete(object.uuid);
|
|
795
797
|
internal.occlusionCache.delete(object);
|
|
796
798
|
}
|
|
799
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
800
|
+
const { internal } = store.getState();
|
|
801
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
802
|
+
if (!entry) return false;
|
|
803
|
+
entry.handlers = handlers;
|
|
804
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
805
|
+
object.occlusionTest = true;
|
|
806
|
+
enableOcclusion(store);
|
|
807
|
+
}
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
797
810
|
function checkVisibility(state) {
|
|
798
811
|
const { internal, camera } = state;
|
|
799
812
|
const registry = internal.visibilityRegistry;
|
|
@@ -954,9 +967,9 @@ function diffProps(instance, newProps) {
|
|
|
954
967
|
const { root, key } = resolve(instance.object, prop);
|
|
955
968
|
if (root.constructor && root.constructor.length === 0) {
|
|
956
969
|
const ctor = getMemoizedPrototype(root);
|
|
957
|
-
if (!is.und(ctor)) changedProps[
|
|
970
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
958
971
|
} else {
|
|
959
|
-
changedProps[
|
|
972
|
+
changedProps[prop] = 0;
|
|
960
973
|
}
|
|
961
974
|
}
|
|
962
975
|
return changedProps;
|
|
@@ -981,10 +994,7 @@ function applyProps(object, props) {
|
|
|
981
994
|
continue;
|
|
982
995
|
}
|
|
983
996
|
if (value === void 0) continue;
|
|
984
|
-
if (isFromRef(value))
|
|
985
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
986
|
-
continue;
|
|
987
|
-
}
|
|
997
|
+
if (isFromRef(value)) continue;
|
|
988
998
|
if (isOnce(value)) {
|
|
989
999
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
990
1000
|
if (instance) {
|
|
@@ -1020,6 +1030,19 @@ function applyProps(object, props) {
|
|
|
1020
1030
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1021
1031
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1022
1032
|
else target.set(value);
|
|
1033
|
+
} else if (root instanceof webgpu.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1034
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1035
|
+
const uniforms = root.uniforms;
|
|
1036
|
+
const nextUniforms = value;
|
|
1037
|
+
for (const name in nextUniforms) {
|
|
1038
|
+
const uniform = nextUniforms[name];
|
|
1039
|
+
const targetUniform = uniforms[name];
|
|
1040
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1041
|
+
else {
|
|
1042
|
+
const nextUniform = uniform instanceof webgpu.Uniform ? uniform.clone() : new webgpu.Uniform(uniform.value);
|
|
1043
|
+
uniforms[name] = nextUniform;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1023
1046
|
} else {
|
|
1024
1047
|
root[key] = value;
|
|
1025
1048
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1038,6 +1061,9 @@ function applyProps(object, props) {
|
|
|
1038
1061
|
if (instance.eventCount && object2.raycast !== null) {
|
|
1039
1062
|
rootState.internal.interaction.push(object2);
|
|
1040
1063
|
}
|
|
1064
|
+
}
|
|
1065
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1066
|
+
const object2 = instance.object;
|
|
1041
1067
|
const root = findInitialRoot(instance);
|
|
1042
1068
|
const visibilityHandlers = {
|
|
1043
1069
|
onFramed: instance.handlers.onFramed,
|
|
@@ -1045,7 +1071,9 @@ function applyProps(object, props) {
|
|
|
1045
1071
|
onVisible: instance.handlers.onVisible
|
|
1046
1072
|
};
|
|
1047
1073
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
1048
|
-
|
|
1074
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1075
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1076
|
+
}
|
|
1049
1077
|
} else {
|
|
1050
1078
|
unregisterVisibility(root, object2);
|
|
1051
1079
|
}
|
|
@@ -1088,6 +1116,41 @@ function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
|
1088
1116
|
captureData.target.releasePointerCapture(pointerId);
|
|
1089
1117
|
}
|
|
1090
1118
|
}
|
|
1119
|
+
function swapInteractivity(store, object, newObject) {
|
|
1120
|
+
const { internal } = store.getState();
|
|
1121
|
+
for (let i = 0; i < internal.interaction.length; i++) {
|
|
1122
|
+
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
1123
|
+
}
|
|
1124
|
+
for (const pointerState of internal.pointerMap.values()) {
|
|
1125
|
+
for (let i = 0; i < pointerState.initialHits.length; i++) {
|
|
1126
|
+
if (pointerState.initialHits[i] === object) pointerState.initialHits[i] = newObject;
|
|
1127
|
+
}
|
|
1128
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1129
|
+
if (value.eventObject === object || value.object === object) {
|
|
1130
|
+
pointerState.hovered.delete(key);
|
|
1131
|
+
const next = {
|
|
1132
|
+
...value,
|
|
1133
|
+
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
1134
|
+
object: value.object === object ? newObject : value.object
|
|
1135
|
+
};
|
|
1136
|
+
pointerState.hovered.set(makeId(next), next);
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
const captureData = pointerState.captured.get(object);
|
|
1140
|
+
if (captureData) {
|
|
1141
|
+
pointerState.captured.delete(object);
|
|
1142
|
+
pointerState.captured.set(newObject, {
|
|
1143
|
+
...captureData,
|
|
1144
|
+
intersection: {
|
|
1145
|
+
...captureData.intersection,
|
|
1146
|
+
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
1147
|
+
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
unregisterVisibility(store, object);
|
|
1153
|
+
}
|
|
1091
1154
|
function removeInteractivity(store, object) {
|
|
1092
1155
|
const { internal } = store.getState();
|
|
1093
1156
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
@@ -1573,6 +1636,7 @@ function createPointerEvents(store) {
|
|
|
1573
1636
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1574
1637
|
}
|
|
1575
1638
|
},
|
|
1639
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1576
1640
|
registerPointer: (config) => {
|
|
1577
1641
|
const pointerId = nextXRPointerId++;
|
|
1578
1642
|
xrPointers.set(pointerId, config);
|
|
@@ -1660,11 +1724,10 @@ function notifyAlpha({ message, link }) {
|
|
|
1660
1724
|
}
|
|
1661
1725
|
|
|
1662
1726
|
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1663
|
-
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1664
1727
|
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1665
1728
|
if (!stack) return false;
|
|
1666
1729
|
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1667
|
-
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m))
|
|
1730
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
1668
1731
|
}
|
|
1669
1732
|
|
|
1670
1733
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -1799,6 +1862,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1799
1862
|
}),
|
|
1800
1863
|
setFrameloop: (frameloop = "always") => {
|
|
1801
1864
|
set(() => ({ frameloop }));
|
|
1865
|
+
scheduler.getScheduler().frameloop = frameloop;
|
|
1802
1866
|
},
|
|
1803
1867
|
setError: (error) => set(() => ({ error })),
|
|
1804
1868
|
error: null,
|
|
@@ -1979,19 +2043,25 @@ function loadingFn(extensions, onProgress) {
|
|
|
1979
2043
|
);
|
|
1980
2044
|
};
|
|
1981
2045
|
}
|
|
1982
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
1983
|
-
const
|
|
2046
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2047
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2048
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1984
2049
|
const fn = loadingFn(extensions, onProgress);
|
|
1985
|
-
const results =
|
|
2050
|
+
const results = cacheKeys.map(
|
|
2051
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2052
|
+
);
|
|
1986
2053
|
return Array.isArray(input) ? results : results[0];
|
|
1987
2054
|
}
|
|
1988
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
1989
|
-
const
|
|
1990
|
-
|
|
2055
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2056
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2057
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2058
|
+
cacheKeys.forEach(
|
|
2059
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2060
|
+
);
|
|
1991
2061
|
};
|
|
1992
|
-
useLoader.clear = function(loader, input) {
|
|
1993
|
-
const
|
|
1994
|
-
|
|
2062
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2063
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2064
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
1995
2065
|
};
|
|
1996
2066
|
useLoader.loader = getLoader;
|
|
1997
2067
|
|
|
@@ -2411,7 +2481,7 @@ function advance(timestamp) {
|
|
|
2411
2481
|
scheduler.getScheduler().step(timestamp);
|
|
2412
2482
|
}
|
|
2413
2483
|
|
|
2414
|
-
const version = "10.0.0-alpha.
|
|
2484
|
+
const version = "10.0.0-alpha.3";
|
|
2415
2485
|
const packageData = {
|
|
2416
2486
|
version: version};
|
|
2417
2487
|
|
|
@@ -13667,7 +13737,7 @@ function n0() {
|
|
|
13667
13737
|
var t0 = n0();
|
|
13668
13738
|
const r0 = Xb(t0);
|
|
13669
13739
|
|
|
13670
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13740
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
13671
13741
|
|
|
13672
13742
|
function createReconciler(config) {
|
|
13673
13743
|
const reconciler2 = r0(config);
|
|
@@ -13832,7 +13902,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
13832
13902
|
}
|
|
13833
13903
|
}
|
|
13834
13904
|
const reconstructed = [];
|
|
13835
|
-
function
|
|
13905
|
+
function flushReconstructedInstances() {
|
|
13906
|
+
if (reconstructed.length === 0) return;
|
|
13907
|
+
try {
|
|
13908
|
+
swapReconstructedInstances();
|
|
13909
|
+
} finally {
|
|
13910
|
+
reconstructed.length = 0;
|
|
13911
|
+
}
|
|
13912
|
+
}
|
|
13913
|
+
function swapReconstructedInstances() {
|
|
13836
13914
|
for (const [instance] of reconstructed) {
|
|
13837
13915
|
const parent = instance.parent;
|
|
13838
13916
|
if (parent) {
|
|
@@ -13850,6 +13928,9 @@ function swapInstances() {
|
|
|
13850
13928
|
}
|
|
13851
13929
|
}
|
|
13852
13930
|
if (instance.isHidden) unhideInstance(instance);
|
|
13931
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13932
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13933
|
+
}
|
|
13853
13934
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
13854
13935
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
13855
13936
|
}
|
|
@@ -13858,10 +13939,16 @@ function swapInstances() {
|
|
|
13858
13939
|
const parent = instance.parent;
|
|
13859
13940
|
if (parent) {
|
|
13860
13941
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13942
|
+
const prevObject = instance.object;
|
|
13861
13943
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
13862
13944
|
instance.object.__r3f = instance;
|
|
13863
13945
|
setFiberRef(fiber, instance.object);
|
|
13946
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13947
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13948
|
+
}
|
|
13864
13949
|
delete instance.appliedOnce;
|
|
13950
|
+
instance.eventCount = 0;
|
|
13951
|
+
instance.handlers = {};
|
|
13865
13952
|
applyProps(instance.object, instance.props);
|
|
13866
13953
|
if (instance.props.attach) {
|
|
13867
13954
|
attach(parent, instance);
|
|
@@ -13878,14 +13965,114 @@ function swapInstances() {
|
|
|
13878
13965
|
invalidateInstance(instance);
|
|
13879
13966
|
}
|
|
13880
13967
|
}
|
|
13881
|
-
reconstructed.length = 0;
|
|
13882
13968
|
}
|
|
13883
13969
|
const handleTextInstance = () => {
|
|
13884
13970
|
};
|
|
13885
13971
|
const NO_CONTEXT = {};
|
|
13886
13972
|
let currentUpdatePriority = NoEventPriority;
|
|
13887
|
-
|
|
13888
|
-
|
|
13973
|
+
function getEventPriority(type) {
|
|
13974
|
+
switch (type) {
|
|
13975
|
+
case "beforetoggle":
|
|
13976
|
+
case "cancel":
|
|
13977
|
+
case "click":
|
|
13978
|
+
case "close":
|
|
13979
|
+
case "contextmenu":
|
|
13980
|
+
case "copy":
|
|
13981
|
+
case "cut":
|
|
13982
|
+
case "auxclick":
|
|
13983
|
+
case "dblclick":
|
|
13984
|
+
case "dragend":
|
|
13985
|
+
case "dragstart":
|
|
13986
|
+
case "drop":
|
|
13987
|
+
case "focusin":
|
|
13988
|
+
case "focusout":
|
|
13989
|
+
case "input":
|
|
13990
|
+
case "invalid":
|
|
13991
|
+
case "keydown":
|
|
13992
|
+
case "keypress":
|
|
13993
|
+
case "keyup":
|
|
13994
|
+
case "mousedown":
|
|
13995
|
+
case "mouseup":
|
|
13996
|
+
case "paste":
|
|
13997
|
+
case "pause":
|
|
13998
|
+
case "play":
|
|
13999
|
+
case "pointercancel":
|
|
14000
|
+
case "pointerdown":
|
|
14001
|
+
case "pointerup":
|
|
14002
|
+
case "ratechange":
|
|
14003
|
+
case "reset":
|
|
14004
|
+
case "resize":
|
|
14005
|
+
case "seeked":
|
|
14006
|
+
case "submit":
|
|
14007
|
+
case "touchcancel":
|
|
14008
|
+
case "touchend":
|
|
14009
|
+
case "touchstart":
|
|
14010
|
+
case "volumechange":
|
|
14011
|
+
case "change":
|
|
14012
|
+
case "selectionchange":
|
|
14013
|
+
case "compositionstart":
|
|
14014
|
+
case "compositionend":
|
|
14015
|
+
case "compositionupdate":
|
|
14016
|
+
case "beforeinput":
|
|
14017
|
+
case "blur":
|
|
14018
|
+
case "fullscreenchange":
|
|
14019
|
+
case "focus":
|
|
14020
|
+
case "hashchange":
|
|
14021
|
+
case "popstate":
|
|
14022
|
+
case "select":
|
|
14023
|
+
case "selectstart":
|
|
14024
|
+
return e;
|
|
14025
|
+
case "drag":
|
|
14026
|
+
case "dragenter":
|
|
14027
|
+
case "dragexit":
|
|
14028
|
+
case "dragleave":
|
|
14029
|
+
case "dragover":
|
|
14030
|
+
case "mousemove":
|
|
14031
|
+
case "mouseout":
|
|
14032
|
+
case "mouseover":
|
|
14033
|
+
case "pointermove":
|
|
14034
|
+
case "pointerout":
|
|
14035
|
+
case "pointerover":
|
|
14036
|
+
case "scroll":
|
|
14037
|
+
case "touchmove":
|
|
14038
|
+
case "wheel":
|
|
14039
|
+
case "mouseenter":
|
|
14040
|
+
case "mouseleave":
|
|
14041
|
+
case "pointerenter":
|
|
14042
|
+
case "pointerleave":
|
|
14043
|
+
return o;
|
|
14044
|
+
case "message": {
|
|
14045
|
+
switch (Tb.unstable_getCurrentPriorityLevel()) {
|
|
14046
|
+
case Tb.unstable_ImmediatePriority:
|
|
14047
|
+
return e;
|
|
14048
|
+
case Tb.unstable_UserBlockingPriority:
|
|
14049
|
+
return o;
|
|
14050
|
+
case Tb.unstable_NormalPriority:
|
|
14051
|
+
case Tb.unstable_LowPriority:
|
|
14052
|
+
return r;
|
|
14053
|
+
case Tb.unstable_IdlePriority:
|
|
14054
|
+
return i$1;
|
|
14055
|
+
default:
|
|
14056
|
+
return r;
|
|
14057
|
+
}
|
|
14058
|
+
}
|
|
14059
|
+
default:
|
|
14060
|
+
return r;
|
|
14061
|
+
}
|
|
14062
|
+
}
|
|
14063
|
+
function scheduleMicrotask(callback) {
|
|
14064
|
+
if (typeof queueMicrotask === "function") {
|
|
14065
|
+
queueMicrotask(callback);
|
|
14066
|
+
} else if (typeof Promise !== "undefined") {
|
|
14067
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
14068
|
+
setTimeout(() => {
|
|
14069
|
+
throw error;
|
|
14070
|
+
});
|
|
14071
|
+
});
|
|
14072
|
+
} else {
|
|
14073
|
+
setTimeout(callback);
|
|
14074
|
+
}
|
|
14075
|
+
}
|
|
13889
14076
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
13890
14077
|
isPrimaryRenderer: false,
|
|
13891
14078
|
warnsIfNotActing: false,
|
|
@@ -13924,16 +14111,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13924
14111
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
13925
14112
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
13926
14113
|
if (reconstruct) {
|
|
13927
|
-
reconstructed.push([instance,
|
|
14114
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
13928
14115
|
} else {
|
|
13929
14116
|
const changedProps = diffProps(instance, newProps);
|
|
13930
|
-
|
|
13931
|
-
|
|
13932
|
-
|
|
13933
|
-
|
|
14117
|
+
const attach2 = instance.props.attach;
|
|
14118
|
+
instance.props = getInstanceProps(newProps);
|
|
14119
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
14120
|
+
else delete instance.props.attach;
|
|
14121
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
13934
14122
|
}
|
|
13935
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
13936
|
-
if (isTailSibling) swapInstances();
|
|
13937
14123
|
},
|
|
13938
14124
|
finalizeInitialChildren: (instance) => {
|
|
13939
14125
|
for (const prop in instance.props) {
|
|
@@ -13958,8 +14144,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13958
14144
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
13959
14145
|
return prepare(target, container, "", {});
|
|
13960
14146
|
},
|
|
13961
|
-
|
|
13962
|
-
|
|
14147
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
14148
|
+
// before layout effects run so refs point to the new objects
|
|
14149
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
13963
14150
|
shouldSetTextContent: () => false,
|
|
13964
14151
|
clearContainer: () => false,
|
|
13965
14152
|
hideInstance,
|
|
@@ -13967,6 +14154,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13967
14154
|
createTextInstance: handleTextInstance,
|
|
13968
14155
|
hideTextInstance: handleTextInstance,
|
|
13969
14156
|
unhideTextInstance: handleTextInstance,
|
|
14157
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
14158
|
+
supportsMicrotasks: true,
|
|
14159
|
+
scheduleMicrotask,
|
|
13970
14160
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
13971
14161
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
13972
14162
|
noTimeout: -1,
|
|
@@ -14007,28 +14197,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14007
14197
|
},
|
|
14008
14198
|
resolveUpdatePriority() {
|
|
14009
14199
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14010
|
-
|
|
14011
|
-
|
|
14012
|
-
|
|
14013
|
-
case "dblclick":
|
|
14014
|
-
case "dragenter":
|
|
14015
|
-
case "dragleave":
|
|
14016
|
-
case "drop":
|
|
14017
|
-
case "pointercancel":
|
|
14018
|
-
case "pointerdown":
|
|
14019
|
-
case "pointerup":
|
|
14020
|
-
return e;
|
|
14021
|
-
case "dragover":
|
|
14022
|
-
case "pointermove":
|
|
14023
|
-
case "pointerout":
|
|
14024
|
-
case "pointerover":
|
|
14025
|
-
case "pointerenter":
|
|
14026
|
-
case "pointerleave":
|
|
14027
|
-
case "wheel":
|
|
14028
|
-
return o;
|
|
14029
|
-
default:
|
|
14030
|
-
return r;
|
|
14031
|
-
}
|
|
14200
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14201
|
+
if (eventType === void 0) return r;
|
|
14202
|
+
return getEventPriority(eventType);
|
|
14032
14203
|
},
|
|
14033
14204
|
resetFormInstance() {
|
|
14034
14205
|
},
|
|
@@ -14077,11 +14248,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14077
14248
|
cloneMutableTextInstance(textInstance) {
|
|
14078
14249
|
return textInstance;
|
|
14079
14250
|
},
|
|
14251
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14252
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14253
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14254
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14255
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14256
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
14080
14257
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14081
|
-
throw new Error("Not implemented.");
|
|
14082
14258
|
},
|
|
14083
14259
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14084
|
-
throw new Error("Not implemented.");
|
|
14085
14260
|
},
|
|
14086
14261
|
// https://github.com/facebook/react/pull/32465
|
|
14087
14262
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14166,6 +14341,7 @@ function createRoot(canvas) {
|
|
|
14166
14341
|
const lastConfiguredProps = {};
|
|
14167
14342
|
let configured = false;
|
|
14168
14343
|
let pending = null;
|
|
14344
|
+
let rendererSetup = null;
|
|
14169
14345
|
return {
|
|
14170
14346
|
async configure(props = {}) {
|
|
14171
14347
|
let resolve;
|
|
@@ -14196,7 +14372,7 @@ function createRoot(canvas) {
|
|
|
14196
14372
|
forceEven
|
|
14197
14373
|
} = props;
|
|
14198
14374
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || webgpu.SRGBColorSpace;
|
|
14199
|
-
|
|
14375
|
+
let state = store.getState();
|
|
14200
14376
|
const defaultGPUProps = {
|
|
14201
14377
|
canvas,
|
|
14202
14378
|
antialias: true
|
|
@@ -14210,52 +14386,64 @@ function createRoot(canvas) {
|
|
|
14210
14386
|
throw new Error("Cannot use both gl and renderer props at the same time");
|
|
14211
14387
|
}
|
|
14212
14388
|
let renderer = state.internal.actualRenderer;
|
|
14213
|
-
if (
|
|
14214
|
-
|
|
14215
|
-
|
|
14216
|
-
|
|
14217
|
-
|
|
14218
|
-
|
|
14219
|
-
|
|
14220
|
-
|
|
14221
|
-
|
|
14222
|
-
|
|
14223
|
-
|
|
14224
|
-
|
|
14225
|
-
|
|
14226
|
-
|
|
14227
|
-
|
|
14228
|
-
|
|
14229
|
-
|
|
14230
|
-
|
|
14231
|
-
|
|
14232
|
-
|
|
14233
|
-
|
|
14234
|
-
|
|
14235
|
-
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
|
|
14242
|
-
|
|
14243
|
-
|
|
14244
|
-
|
|
14245
|
-
|
|
14246
|
-
|
|
14247
|
-
|
|
14248
|
-
|
|
14249
|
-
|
|
14250
|
-
|
|
14251
|
-
|
|
14252
|
-
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14389
|
+
if (!state.internal.actualRenderer) {
|
|
14390
|
+
if (!rendererSetup) {
|
|
14391
|
+
rendererSetup = (async () => {
|
|
14392
|
+
if (primaryCanvas) {
|
|
14393
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14394
|
+
renderer = primary.renderer;
|
|
14395
|
+
state.internal.actualRenderer = renderer;
|
|
14396
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14397
|
+
primary.store.setState((prev) => ({
|
|
14398
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14399
|
+
}));
|
|
14400
|
+
state.set((prev) => ({
|
|
14401
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14402
|
+
renderer,
|
|
14403
|
+
primaryStore: primary.store,
|
|
14404
|
+
internal: {
|
|
14405
|
+
...prev.internal,
|
|
14406
|
+
canvasTarget,
|
|
14407
|
+
isMultiCanvas: true,
|
|
14408
|
+
isSecondary: true,
|
|
14409
|
+
targetId: primaryCanvas
|
|
14410
|
+
}
|
|
14411
|
+
}));
|
|
14412
|
+
} else {
|
|
14413
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, webgpu.WebGPURenderer);
|
|
14414
|
+
if (!renderer.hasInitialized?.()) {
|
|
14415
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14416
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14417
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14418
|
+
canvas.width = size2.width * pixelRatio;
|
|
14419
|
+
canvas.height = size2.height * pixelRatio;
|
|
14420
|
+
}
|
|
14421
|
+
await renderer.init();
|
|
14422
|
+
}
|
|
14423
|
+
const backend = renderer.backend;
|
|
14424
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14425
|
+
state.internal.actualRenderer = renderer;
|
|
14426
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14427
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14428
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14429
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14430
|
+
state.set((prev) => ({
|
|
14431
|
+
internal: {
|
|
14432
|
+
...prev.internal,
|
|
14433
|
+
canvasTarget,
|
|
14434
|
+
unregisterPrimary
|
|
14435
|
+
}
|
|
14436
|
+
}));
|
|
14437
|
+
}
|
|
14256
14438
|
}
|
|
14257
|
-
}))
|
|
14439
|
+
})().catch((err) => {
|
|
14440
|
+
rendererSetup = null;
|
|
14441
|
+
throw err;
|
|
14442
|
+
});
|
|
14258
14443
|
}
|
|
14444
|
+
await rendererSetup;
|
|
14445
|
+
state = store.getState();
|
|
14446
|
+
renderer = state.internal.actualRenderer;
|
|
14259
14447
|
}
|
|
14260
14448
|
let raycaster = state.raycaster;
|
|
14261
14449
|
if (!raycaster) state.set({ raycaster: raycaster = new webgpu.Raycaster() });
|
|
@@ -14605,7 +14793,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14605
14793
|
dispose(state.scene);
|
|
14606
14794
|
_roots.delete(canvas);
|
|
14607
14795
|
if (callback) callback(canvas);
|
|
14608
|
-
} catch {
|
|
14796
|
+
} catch (error) {
|
|
14797
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
14609
14798
|
}
|
|
14610
14799
|
}, 500);
|
|
14611
14800
|
}
|
|
@@ -14668,6 +14857,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14668
14857
|
viewport = rootState.viewport.getCurrentViewport(camera, new webgpu.Vector3(), resolvedSize);
|
|
14669
14858
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14670
14859
|
}
|
|
14860
|
+
const set = injectState.set;
|
|
14671
14861
|
return {
|
|
14672
14862
|
// The intersect consists of the previous root state
|
|
14673
14863
|
...rootState,
|
|
@@ -14686,7 +14876,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14686
14876
|
size: resolvedSize,
|
|
14687
14877
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14688
14878
|
// Layers are allowed to override events
|
|
14689
|
-
setEvents: (events2) =>
|
|
14879
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
14690
14880
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
14691
14881
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
14692
14882
|
};
|
|
@@ -14758,14 +14948,133 @@ function parseRendererConfig(rendererProp) {
|
|
|
14758
14948
|
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14759
14949
|
}
|
|
14760
14950
|
|
|
14951
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14952
|
+
const ROOT_SCOPE = "";
|
|
14953
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14954
|
+
function getKindRegistry(store, kind) {
|
|
14955
|
+
let registry = registries.get(store);
|
|
14956
|
+
if (!registry) {
|
|
14957
|
+
registry = {
|
|
14958
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14959
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14960
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14961
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14962
|
+
};
|
|
14963
|
+
registries.set(store, registry);
|
|
14964
|
+
}
|
|
14965
|
+
return registry[kind];
|
|
14966
|
+
}
|
|
14967
|
+
function resolvePrimary$1(store) {
|
|
14968
|
+
return store.getState().primaryStore ?? store;
|
|
14969
|
+
}
|
|
14970
|
+
function isScopeValid(store, kind, scopeKey) {
|
|
14971
|
+
return getKindRegistry(store, kind).valid.has(scopeKey);
|
|
14972
|
+
}
|
|
14973
|
+
function peekStaged(store, kind, scopeKey) {
|
|
14974
|
+
return getKindRegistry(store, kind).staged.get(scopeKey);
|
|
14975
|
+
}
|
|
14976
|
+
function stageEntries(store, kind, scopeKey, entries) {
|
|
14977
|
+
const { staged } = getKindRegistry(store, kind);
|
|
14978
|
+
const current = staged.get(scopeKey);
|
|
14979
|
+
if (current) Object.assign(current, entries);
|
|
14980
|
+
else staged.set(scopeKey, { ...entries });
|
|
14981
|
+
}
|
|
14982
|
+
function readCommittedScope(map, scopeKey, isLeaf) {
|
|
14983
|
+
if (scopeKey === ROOT_SCOPE) {
|
|
14984
|
+
const leaves = {};
|
|
14985
|
+
for (const [key, value] of Object.entries(map)) if (isLeaf(value)) leaves[key] = value;
|
|
14986
|
+
return leaves;
|
|
14987
|
+
}
|
|
14988
|
+
const scopeData = map[scopeKey];
|
|
14989
|
+
if (scopeData && typeof scopeData === "object" && !isLeaf(scopeData)) return scopeData;
|
|
14990
|
+
return {};
|
|
14991
|
+
}
|
|
14992
|
+
function withStagedOverlay(store, kind, committed) {
|
|
14993
|
+
const { staged } = getKindRegistry(store, kind);
|
|
14994
|
+
if (staged.size === 0) return committed;
|
|
14995
|
+
const view = { ...committed };
|
|
14996
|
+
for (const [scopeKey, entries] of staged) {
|
|
14997
|
+
if (scopeKey === ROOT_SCOPE) Object.assign(view, entries);
|
|
14998
|
+
else view[scopeKey] = { ...view[scopeKey], ...entries };
|
|
14999
|
+
}
|
|
15000
|
+
return view;
|
|
15001
|
+
}
|
|
15002
|
+
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
15003
|
+
const registry = getKindRegistry(store, kind);
|
|
15004
|
+
const staged = registry.staged.get(scopeKey);
|
|
15005
|
+
if (!staged) return;
|
|
15006
|
+
registry.staged.delete(scopeKey);
|
|
15007
|
+
const replace = !registry.valid.has(scopeKey);
|
|
15008
|
+
store.setState((state) => {
|
|
15009
|
+
const map = state[kind];
|
|
15010
|
+
if (scopeKey === ROOT_SCOPE) {
|
|
15011
|
+
if (!replace) return { [kind]: { ...map, ...staged } };
|
|
15012
|
+
const next = {};
|
|
15013
|
+
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15014
|
+
return { [kind]: { ...next, ...staged } };
|
|
15015
|
+
}
|
|
15016
|
+
const current = replace ? {} : map[scopeKey] ?? {};
|
|
15017
|
+
return { [kind]: { ...map, [scopeKey]: { ...current, ...staged } } };
|
|
15018
|
+
});
|
|
15019
|
+
registry.valid.add(scopeKey);
|
|
15020
|
+
}
|
|
15021
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
15022
|
+
const registry = getKindRegistry(store, kind);
|
|
15023
|
+
if (scopeKey === void 0) {
|
|
15024
|
+
registry.valid.clear();
|
|
15025
|
+
registry.staged.clear();
|
|
15026
|
+
} else {
|
|
15027
|
+
registry.valid.delete(scopeKey);
|
|
15028
|
+
registry.staged.delete(scopeKey);
|
|
15029
|
+
}
|
|
15030
|
+
}
|
|
15031
|
+
function rebuildResource(store, kind, userScope) {
|
|
15032
|
+
const primary = resolvePrimary$1(store);
|
|
15033
|
+
invalidateResource(primary, kind, userScope === "root" ? ROOT_SCOPE : userScope);
|
|
15034
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15035
|
+
}
|
|
15036
|
+
function invalidateAllResources(store) {
|
|
15037
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
15038
|
+
}
|
|
15039
|
+
function removeResourceEntries(store, kind, names, scope, isLeaf) {
|
|
15040
|
+
const staged = peekStaged(store, kind, scope ?? ROOT_SCOPE);
|
|
15041
|
+
if (staged) for (const name of names) delete staged[name];
|
|
15042
|
+
store.setState((state) => {
|
|
15043
|
+
const map = state[kind];
|
|
15044
|
+
if (scope) {
|
|
15045
|
+
const currentScope = { ...map[scope] };
|
|
15046
|
+
for (const name of names) delete currentScope[name];
|
|
15047
|
+
return { [kind]: { ...map, [scope]: currentScope } };
|
|
15048
|
+
}
|
|
15049
|
+
const next = { ...map };
|
|
15050
|
+
for (const name of names) if (isLeaf(next[name])) delete next[name];
|
|
15051
|
+
return { [kind]: next };
|
|
15052
|
+
});
|
|
15053
|
+
}
|
|
15054
|
+
function clearResourceEntries(store, kind, scope, isLeaf) {
|
|
15055
|
+
const registry = getKindRegistry(store, kind);
|
|
15056
|
+
if (scope && scope !== "root") registry.staged.delete(scope);
|
|
15057
|
+
else if (scope === "root") registry.staged.delete(ROOT_SCOPE);
|
|
15058
|
+
else registry.staged.clear();
|
|
15059
|
+
store.setState((state) => {
|
|
15060
|
+
const map = state[kind];
|
|
15061
|
+
if (scope && scope !== "root") {
|
|
15062
|
+
const { [scope]: _, ...rest } = map;
|
|
15063
|
+
return { [kind]: rest };
|
|
15064
|
+
}
|
|
15065
|
+
if (scope === "root") {
|
|
15066
|
+
const next = {};
|
|
15067
|
+
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15068
|
+
return { [kind]: next };
|
|
15069
|
+
}
|
|
15070
|
+
return { [kind]: {} };
|
|
15071
|
+
});
|
|
15072
|
+
}
|
|
15073
|
+
|
|
14761
15074
|
function clearHmrCaches(store) {
|
|
14762
|
-
store.
|
|
14763
|
-
|
|
14764
|
-
|
|
14765
|
-
buffers: {},
|
|
14766
|
-
gpuStorage: {},
|
|
14767
|
-
_hmrVersion: state._hmrVersion + 1
|
|
14768
|
-
}));
|
|
15075
|
+
const primary = store.getState().primaryStore ?? store;
|
|
15076
|
+
invalidateAllResources(primary);
|
|
15077
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14769
15078
|
}
|
|
14770
15079
|
|
|
14771
15080
|
function CanvasImpl({
|
|
@@ -14846,6 +15155,7 @@ function CanvasImpl({
|
|
|
14846
15155
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
14847
15156
|
const [block, setBlock] = React__namespace.useState(false);
|
|
14848
15157
|
const [error, setError] = React__namespace.useState(false);
|
|
15158
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
14849
15159
|
if (block) throw block;
|
|
14850
15160
|
if (error) throw error;
|
|
14851
15161
|
const root = React__namespace.useRef(null);
|
|
@@ -14853,6 +15163,7 @@ function CanvasImpl({
|
|
|
14853
15163
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
14854
15164
|
useIsomorphicLayoutEffect(() => {
|
|
14855
15165
|
effectActiveRef.current = true;
|
|
15166
|
+
if (fallbackVisible) return;
|
|
14856
15167
|
const canvas = canvasRef.current;
|
|
14857
15168
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
14858
15169
|
if (!root.current) {
|
|
@@ -14873,7 +15184,7 @@ function CanvasImpl({
|
|
|
14873
15184
|
}
|
|
14874
15185
|
async function run() {
|
|
14875
15186
|
if (!effectActiveRef.current || !root.current) return;
|
|
14876
|
-
await root.current.configure({
|
|
15187
|
+
const configured = await root.current.configure({
|
|
14877
15188
|
id,
|
|
14878
15189
|
primaryCanvas,
|
|
14879
15190
|
scheduler,
|
|
@@ -14914,8 +15225,20 @@ function CanvasImpl({
|
|
|
14914
15225
|
}
|
|
14915
15226
|
onCreated?.(state);
|
|
14916
15227
|
}
|
|
14917
|
-
})
|
|
14918
|
-
|
|
15228
|
+
}).then(
|
|
15229
|
+
() => true,
|
|
15230
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15231
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15232
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15233
|
+
(setupError) => {
|
|
15234
|
+
if (effectActiveRef.current) {
|
|
15235
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15236
|
+
else setError(setupError);
|
|
15237
|
+
}
|
|
15238
|
+
return false;
|
|
15239
|
+
}
|
|
15240
|
+
);
|
|
15241
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
14919
15242
|
root.current.render(
|
|
14920
15243
|
/* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Block, { set: setBlock }), children: [
|
|
14921
15244
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -14978,7 +15301,11 @@ function CanvasImpl({
|
|
|
14978
15301
|
...style
|
|
14979
15302
|
},
|
|
14980
15303
|
...props,
|
|
14981
|
-
children:
|
|
15304
|
+
children: fallbackVisible ? (
|
|
15305
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15306
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15307
|
+
fallback
|
|
15308
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14982
15309
|
"canvas",
|
|
14983
15310
|
{
|
|
14984
15311
|
ref: canvasRef,
|
|
@@ -15060,30 +15387,31 @@ let ScopedStore = _ScopedStore;
|
|
|
15060
15387
|
function createScopedStore(data) {
|
|
15061
15388
|
return new ScopedStore(data);
|
|
15062
15389
|
}
|
|
15063
|
-
function createLazyCreatorState(state) {
|
|
15390
|
+
function createLazyCreatorState(state, store) {
|
|
15064
15391
|
let _uniforms = null;
|
|
15065
15392
|
let _nodes = null;
|
|
15066
15393
|
let _buffers = null;
|
|
15067
15394
|
let _gpuStorage = null;
|
|
15395
|
+
const view = (kind) => store ? withStagedOverlay(store, kind, state[kind]) : state[kind];
|
|
15068
15396
|
return Object.create(state, {
|
|
15069
15397
|
uniforms: {
|
|
15070
15398
|
get() {
|
|
15071
|
-
return _uniforms ?? (_uniforms = createScopedStore(
|
|
15399
|
+
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms")));
|
|
15072
15400
|
}
|
|
15073
15401
|
},
|
|
15074
15402
|
nodes: {
|
|
15075
15403
|
get() {
|
|
15076
|
-
return _nodes ?? (_nodes = createScopedStore(
|
|
15404
|
+
return _nodes ?? (_nodes = createScopedStore(view("nodes")));
|
|
15077
15405
|
}
|
|
15078
15406
|
},
|
|
15079
15407
|
buffers: {
|
|
15080
15408
|
get() {
|
|
15081
|
-
return _buffers ?? (_buffers = createScopedStore(
|
|
15409
|
+
return _buffers ?? (_buffers = createScopedStore(view("buffers")));
|
|
15082
15410
|
}
|
|
15083
15411
|
},
|
|
15084
15412
|
gpuStorage: {
|
|
15085
15413
|
get() {
|
|
15086
|
-
return _gpuStorage ?? (_gpuStorage = createScopedStore(
|
|
15414
|
+
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage")));
|
|
15087
15415
|
}
|
|
15088
15416
|
}
|
|
15089
15417
|
});
|
|
@@ -15206,65 +15534,56 @@ function useCompareMemoize(value, deep) {
|
|
|
15206
15534
|
return ref.current;
|
|
15207
15535
|
}
|
|
15208
15536
|
|
|
15537
|
+
function useScopedResource(options) {
|
|
15538
|
+
const { store, kind, scope, isLeaf, create, prepare, reconcile, input } = options;
|
|
15539
|
+
const scopeKey = scope ?? ROOT_SCOPE;
|
|
15540
|
+
const version = store((s) => s._hmrVersion);
|
|
15541
|
+
const entries = React.useMemo(() => {
|
|
15542
|
+
const staged = peekStaged(store, kind, scopeKey);
|
|
15543
|
+
const reusable = isScopeValid(store, kind, scopeKey);
|
|
15544
|
+
const map = store.getState()[kind];
|
|
15545
|
+
const committed = reusable ? readCommittedScope(map, scopeKey, isLeaf) : void 0;
|
|
15546
|
+
const result = {};
|
|
15547
|
+
let fresh = null;
|
|
15548
|
+
for (const [name, candidate] of Object.entries(create())) {
|
|
15549
|
+
const existing = staged?.[name] ?? committed?.[name];
|
|
15550
|
+
if (existing !== void 0) {
|
|
15551
|
+
result[name] = existing;
|
|
15552
|
+
reconcile?.(existing, candidate);
|
|
15553
|
+
} else {
|
|
15554
|
+
const value = prepare ? prepare(name, candidate) : candidate;
|
|
15555
|
+
result[name] = value;
|
|
15556
|
+
(fresh ?? (fresh = {}))[name] = value;
|
|
15557
|
+
}
|
|
15558
|
+
}
|
|
15559
|
+
if (fresh) stageEntries(store, kind, scopeKey, fresh);
|
|
15560
|
+
return result;
|
|
15561
|
+
}, [store, kind, scopeKey, version, input]);
|
|
15562
|
+
useIsomorphicLayoutEffect(() => {
|
|
15563
|
+
flushStagedScope(store, kind, scopeKey, isLeaf);
|
|
15564
|
+
});
|
|
15565
|
+
return entries;
|
|
15566
|
+
}
|
|
15567
|
+
|
|
15209
15568
|
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15210
15569
|
function useUniforms(creatorOrScope, scope) {
|
|
15211
15570
|
const store = usePrimaryStore();
|
|
15212
15571
|
const removeUniforms2 = React.useCallback(
|
|
15213
|
-
(names, targetScope) =>
|
|
15214
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15215
|
-
store.setState((state) => {
|
|
15216
|
-
if (targetScope) {
|
|
15217
|
-
const currentScope = { ...state.uniforms[targetScope] };
|
|
15218
|
-
for (const name of nameArray) delete currentScope[name];
|
|
15219
|
-
return { uniforms: { ...state.uniforms, [targetScope]: currentScope } };
|
|
15220
|
-
}
|
|
15221
|
-
const uniforms2 = { ...state.uniforms };
|
|
15222
|
-
for (const name of nameArray) if (isUniformNode$1(uniforms2[name])) delete uniforms2[name];
|
|
15223
|
-
return { uniforms: uniforms2 };
|
|
15224
|
-
});
|
|
15225
|
-
},
|
|
15572
|
+
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode$1),
|
|
15226
15573
|
[store]
|
|
15227
15574
|
);
|
|
15228
15575
|
const clearUniforms = React.useCallback(
|
|
15229
|
-
(targetScope) =>
|
|
15230
|
-
store.setState((state) => {
|
|
15231
|
-
if (targetScope && targetScope !== "root") {
|
|
15232
|
-
const { [targetScope]: _, ...rest } = state.uniforms;
|
|
15233
|
-
return { uniforms: rest };
|
|
15234
|
-
}
|
|
15235
|
-
if (targetScope === "root") {
|
|
15236
|
-
const uniforms2 = {};
|
|
15237
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15238
|
-
if (!isUniformNode$1(value)) uniforms2[key] = value;
|
|
15239
|
-
}
|
|
15240
|
-
return { uniforms: uniforms2 };
|
|
15241
|
-
}
|
|
15242
|
-
return { uniforms: {} };
|
|
15243
|
-
});
|
|
15244
|
-
},
|
|
15576
|
+
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode$1),
|
|
15245
15577
|
[store]
|
|
15246
15578
|
);
|
|
15247
15579
|
const rebuildUniforms = React.useCallback(
|
|
15248
|
-
(targetScope) =>
|
|
15249
|
-
store.setState((state) => {
|
|
15250
|
-
let newUniforms = {};
|
|
15251
|
-
if (targetScope && targetScope !== "root") {
|
|
15252
|
-
const { [targetScope]: _, ...rest } = state.uniforms;
|
|
15253
|
-
newUniforms = rest;
|
|
15254
|
-
} else if (targetScope === "root") {
|
|
15255
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15256
|
-
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
15257
|
-
}
|
|
15258
|
-
}
|
|
15259
|
-
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
15260
|
-
});
|
|
15261
|
-
},
|
|
15580
|
+
(targetScope) => rebuildResource(store, "uniforms", targetScope),
|
|
15262
15581
|
[store]
|
|
15263
15582
|
);
|
|
15264
15583
|
const inputForMemoization = React.useMemo(() => {
|
|
15265
15584
|
let raw = creatorOrScope;
|
|
15266
15585
|
if (is.fun(creatorOrScope)) {
|
|
15267
|
-
const wrappedState = createLazyCreatorState(store.getState());
|
|
15586
|
+
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15268
15587
|
raw = creatorOrScope(wrappedState);
|
|
15269
15588
|
}
|
|
15270
15589
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
@@ -15279,80 +15598,43 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
15279
15598
|
const memoizedInput = useCompareMemoize(inputForMemoization);
|
|
15280
15599
|
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
15281
15600
|
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15282
|
-
const
|
|
15283
|
-
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
|
|
15287
|
-
|
|
15288
|
-
|
|
15289
|
-
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
if (!state.uniforms[scope]) state.uniforms[scope] = {};
|
|
15305
|
-
targetRecord = state.uniforms[scope];
|
|
15306
|
-
}
|
|
15307
|
-
for (const [name, node] of Object.entries(created)) {
|
|
15308
|
-
if (targetRecord[name]) {
|
|
15309
|
-
result[name] = targetRecord[name];
|
|
15310
|
-
const existingVal = result[name].value;
|
|
15311
|
-
const newVal = vectorize(node);
|
|
15312
|
-
let equals = newVal === existingVal;
|
|
15313
|
-
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
15314
|
-
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
15315
|
-
equals = vectorEquals(existingVal, newVal);
|
|
15316
|
-
} else if (isSameThreeType(existingVal, newVal)) {
|
|
15317
|
-
equals = existingVal.equals(newVal);
|
|
15318
|
-
}
|
|
15319
|
-
}
|
|
15320
|
-
if (!equals) result[name].value = newVal;
|
|
15321
|
-
} else {
|
|
15322
|
-
result[name] = createUniform(name, node, scope);
|
|
15323
|
-
hasNewUniforms = true;
|
|
15324
|
-
}
|
|
15325
|
-
}
|
|
15326
|
-
if (hasNewUniforms) {
|
|
15327
|
-
if (scope) {
|
|
15328
|
-
set((s) => ({
|
|
15329
|
-
uniforms: {
|
|
15330
|
-
...s.uniforms,
|
|
15331
|
-
[scope]: { ...s.uniforms[scope], ...result }
|
|
15332
|
-
}
|
|
15333
|
-
}));
|
|
15334
|
-
} else {
|
|
15335
|
-
set((s) => ({ uniforms: { ...s.uniforms, ...result } }));
|
|
15601
|
+
const created = useScopedResource({
|
|
15602
|
+
store,
|
|
15603
|
+
kind: "uniforms",
|
|
15604
|
+
scope: isReader ? void 0 : scope,
|
|
15605
|
+
isLeaf: isUniformNode$1,
|
|
15606
|
+
input: memoizedInput,
|
|
15607
|
+
create: () => {
|
|
15608
|
+
if (isReader) return {};
|
|
15609
|
+
if (typeof memoizedInput !== "object" || memoizedInput === null) throw new Error("Invalid uniform input");
|
|
15610
|
+
return memoizedInput;
|
|
15611
|
+
},
|
|
15612
|
+
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
15613
|
+
reconcile: (existing, candidate) => {
|
|
15614
|
+
const existingVal = existing.value;
|
|
15615
|
+
const newVal = vectorize(candidate);
|
|
15616
|
+
let equals = newVal === existingVal;
|
|
15617
|
+
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
15618
|
+
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
15619
|
+
equals = vectorEquals(existingVal, newVal);
|
|
15620
|
+
} else if (isSameThreeType(existingVal, newVal)) {
|
|
15621
|
+
equals = existingVal.equals(newVal);
|
|
15622
|
+
}
|
|
15336
15623
|
}
|
|
15624
|
+
if (!equals) existing.value = newVal;
|
|
15337
15625
|
}
|
|
15338
|
-
|
|
15339
|
-
|
|
15626
|
+
});
|
|
15627
|
+
let uniforms = created;
|
|
15628
|
+
if (memoizedInput === void 0) {
|
|
15629
|
+
uniforms = storeUniforms;
|
|
15630
|
+
} else if (typeof memoizedInput === "string") {
|
|
15631
|
+
const scopeData = storeUniforms[memoizedInput];
|
|
15632
|
+
uniforms = scopeData && !isUniformNode$1(scopeData) ? scopeData : {};
|
|
15633
|
+
}
|
|
15340
15634
|
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
15341
15635
|
}
|
|
15342
15636
|
function rebuildAllUniforms(store, scope) {
|
|
15343
|
-
store
|
|
15344
|
-
store.setState((state) => {
|
|
15345
|
-
let newUniforms = {};
|
|
15346
|
-
if (scope && scope !== "root") {
|
|
15347
|
-
const { [scope]: _, ...rest } = state.uniforms;
|
|
15348
|
-
newUniforms = rest;
|
|
15349
|
-
} else if (scope === "root") {
|
|
15350
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15351
|
-
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
15352
|
-
}
|
|
15353
|
-
}
|
|
15354
|
-
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
15355
|
-
});
|
|
15637
|
+
rebuildResource(store, "uniforms", scope);
|
|
15356
15638
|
}
|
|
15357
15639
|
function removeUniforms(set, names, scope) {
|
|
15358
15640
|
set((state) => {
|
|
@@ -15416,192 +15698,91 @@ function isSameThreeType(a, b) {
|
|
|
15416
15698
|
return obj_a.isColor && obj_b.isColor || obj_a.isMatrix3 && obj_b.isMatrix3 || obj_a.isMatrix4 && obj_b.isMatrix4 || obj_a.isEuler && obj_b.isEuler || obj_a.isQuaternion && obj_b.isQuaternion;
|
|
15417
15699
|
}
|
|
15418
15700
|
|
|
15701
|
+
const uniformOf = tsl.uniform;
|
|
15419
15702
|
const isUniformNode = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15420
15703
|
const isTSLNode$1 = (value) => value !== null && typeof value === "object" && "uuid" in value && "nodeType" in value;
|
|
15421
15704
|
function useUniform(name, value) {
|
|
15422
15705
|
const store = useStore();
|
|
15423
|
-
const
|
|
15424
|
-
|
|
15425
|
-
|
|
15426
|
-
|
|
15427
|
-
|
|
15428
|
-
|
|
15706
|
+
const registered = useScopedResource({
|
|
15707
|
+
store,
|
|
15708
|
+
kind: "uniforms",
|
|
15709
|
+
scope: void 0,
|
|
15710
|
+
isLeaf: isUniformNode,
|
|
15711
|
+
input: name,
|
|
15712
|
+
create: () => value === void 0 ? {} : { [name]: value },
|
|
15713
|
+
prepare: createNamedUniform,
|
|
15714
|
+
reconcile: (existing2) => {
|
|
15429
15715
|
if (value !== void 0 && !isTSLNode$1(value) && !isUniformNode(value)) {
|
|
15430
|
-
|
|
15716
|
+
existing2.value = typeof value === "string" ? new webgpu.Color(value) : value;
|
|
15431
15717
|
}
|
|
15432
|
-
return existing;
|
|
15433
|
-
}
|
|
15434
|
-
if (value === void 0) {
|
|
15435
|
-
throw new Error(
|
|
15436
|
-
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15437
|
-
);
|
|
15438
|
-
}
|
|
15439
|
-
if (isUniformNode(value)) {
|
|
15440
|
-
const node2 = value;
|
|
15441
|
-
if (typeof node2.setName === "function") {
|
|
15442
|
-
node2.setName(name);
|
|
15443
|
-
}
|
|
15444
|
-
set((s) => ({
|
|
15445
|
-
uniforms: { ...s.uniforms, [name]: node2 }
|
|
15446
|
-
}));
|
|
15447
|
-
return node2;
|
|
15448
|
-
}
|
|
15449
|
-
let node;
|
|
15450
|
-
if (isTSLNode$1(value)) {
|
|
15451
|
-
node = tsl.uniform(value);
|
|
15452
|
-
} else if (typeof value === "string") {
|
|
15453
|
-
node = tsl.uniform(new webgpu.Color(value));
|
|
15454
|
-
} else {
|
|
15455
|
-
node = tsl.uniform(value);
|
|
15456
15718
|
}
|
|
15457
|
-
|
|
15458
|
-
|
|
15459
|
-
|
|
15460
|
-
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
|
|
15464
|
-
|
|
15465
|
-
|
|
15466
|
-
|
|
15467
|
-
|
|
15719
|
+
});
|
|
15720
|
+
if (registered[name]) return registered[name];
|
|
15721
|
+
const existing = peekStaged(store, "uniforms", ROOT_SCOPE)?.[name] ?? store.getState().uniforms[name];
|
|
15722
|
+
if (existing && isUniformNode(existing)) return existing;
|
|
15723
|
+
throw new Error(
|
|
15724
|
+
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15725
|
+
);
|
|
15726
|
+
}
|
|
15727
|
+
function createNamedUniform(name, value) {
|
|
15728
|
+
let node;
|
|
15729
|
+
if (isUniformNode(value)) {
|
|
15730
|
+
node = value;
|
|
15731
|
+
} else if (isTSLNode$1(value)) {
|
|
15732
|
+
node = uniformOf(value);
|
|
15733
|
+
} else if (typeof value === "string") {
|
|
15734
|
+
node = tsl.uniform(new webgpu.Color(value));
|
|
15735
|
+
} else {
|
|
15736
|
+
node = uniformOf(value);
|
|
15737
|
+
}
|
|
15738
|
+
if (typeof node.setName === "function") {
|
|
15739
|
+
node.setName(name);
|
|
15740
|
+
}
|
|
15741
|
+
return node;
|
|
15468
15742
|
}
|
|
15469
15743
|
|
|
15470
15744
|
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
15471
15745
|
function useNodes(creatorOrScope, scope) {
|
|
15472
15746
|
const store = usePrimaryStore();
|
|
15473
15747
|
const removeNodes2 = React.useCallback(
|
|
15474
|
-
(names, targetScope) =>
|
|
15475
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15476
|
-
store.setState((state) => {
|
|
15477
|
-
if (targetScope) {
|
|
15478
|
-
const currentScope = { ...state.nodes[targetScope] };
|
|
15479
|
-
for (const name of nameArray) delete currentScope[name];
|
|
15480
|
-
return { nodes: { ...state.nodes, [targetScope]: currentScope } };
|
|
15481
|
-
}
|
|
15482
|
-
const nodes2 = { ...state.nodes };
|
|
15483
|
-
for (const name of nameArray) if (isTSLNode(nodes2[name])) delete nodes2[name];
|
|
15484
|
-
return { nodes: nodes2 };
|
|
15485
|
-
});
|
|
15486
|
-
},
|
|
15748
|
+
(names, targetScope) => removeResourceEntries(store, "nodes", Array.isArray(names) ? names : [names], targetScope, isTSLNode),
|
|
15487
15749
|
[store]
|
|
15488
15750
|
);
|
|
15489
15751
|
const clearNodes = React.useCallback(
|
|
15490
|
-
(targetScope) =>
|
|
15491
|
-
store.setState((state) => {
|
|
15492
|
-
if (targetScope && targetScope !== "root") {
|
|
15493
|
-
const { [targetScope]: _, ...rest } = state.nodes;
|
|
15494
|
-
return { nodes: rest };
|
|
15495
|
-
}
|
|
15496
|
-
if (targetScope === "root") {
|
|
15497
|
-
const nodes2 = {};
|
|
15498
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15499
|
-
if (!isTSLNode(value)) nodes2[key] = value;
|
|
15500
|
-
}
|
|
15501
|
-
return { nodes: nodes2 };
|
|
15502
|
-
}
|
|
15503
|
-
return { nodes: {} };
|
|
15504
|
-
});
|
|
15505
|
-
},
|
|
15752
|
+
(targetScope) => clearResourceEntries(store, "nodes", targetScope, isTSLNode),
|
|
15506
15753
|
[store]
|
|
15507
15754
|
);
|
|
15508
15755
|
const rebuildNodes = React.useCallback(
|
|
15509
|
-
(targetScope) =>
|
|
15510
|
-
store.setState((state) => {
|
|
15511
|
-
let newNodes = state.nodes;
|
|
15512
|
-
if (targetScope && targetScope !== "root") {
|
|
15513
|
-
const { [targetScope]: _, ...rest } = state.nodes;
|
|
15514
|
-
newNodes = rest;
|
|
15515
|
-
} else if (targetScope === "root") {
|
|
15516
|
-
newNodes = {};
|
|
15517
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15518
|
-
if (!isTSLNode(value)) newNodes[key] = value;
|
|
15519
|
-
}
|
|
15520
|
-
} else {
|
|
15521
|
-
newNodes = {};
|
|
15522
|
-
}
|
|
15523
|
-
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
15524
|
-
});
|
|
15525
|
-
},
|
|
15756
|
+
(targetScope) => rebuildResource(store, "nodes", targetScope),
|
|
15526
15757
|
[store]
|
|
15527
15758
|
);
|
|
15528
15759
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15529
15760
|
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15530
|
-
const
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
return
|
|
15537
|
-
|
|
15538
|
-
|
|
15539
|
-
|
|
15540
|
-
|
|
15541
|
-
return
|
|
15542
|
-
}
|
|
15543
|
-
const state = store.getState();
|
|
15544
|
-
const set = store.setState;
|
|
15545
|
-
const creator = creatorOrScope;
|
|
15546
|
-
const wrappedState = createLazyCreatorState(state);
|
|
15547
|
-
const created = creator(wrappedState);
|
|
15548
|
-
const result = {};
|
|
15549
|
-
let hasNewNodes = false;
|
|
15550
|
-
if (scope) {
|
|
15551
|
-
const currentScope = state.nodes[scope] ?? {};
|
|
15552
|
-
for (const [name, node] of Object.entries(created)) {
|
|
15553
|
-
if (currentScope[name]) {
|
|
15554
|
-
result[name] = currentScope[name];
|
|
15555
|
-
} else {
|
|
15556
|
-
node.setName?.(`${scope}.${name}`);
|
|
15557
|
-
result[name] = node;
|
|
15558
|
-
hasNewNodes = true;
|
|
15559
|
-
}
|
|
15560
|
-
}
|
|
15561
|
-
if (hasNewNodes) {
|
|
15562
|
-
set((s) => ({
|
|
15563
|
-
nodes: {
|
|
15564
|
-
...s.nodes,
|
|
15565
|
-
[scope]: { ...s.nodes[scope], ...result }
|
|
15566
|
-
}
|
|
15567
|
-
}));
|
|
15568
|
-
}
|
|
15569
|
-
return result;
|
|
15570
|
-
}
|
|
15571
|
-
for (const [name, node] of Object.entries(created)) {
|
|
15572
|
-
const existing = state.nodes[name];
|
|
15573
|
-
if (existing && isTSLNode(existing)) {
|
|
15574
|
-
result[name] = existing;
|
|
15575
|
-
} else {
|
|
15576
|
-
node.setName?.(name);
|
|
15577
|
-
result[name] = node;
|
|
15578
|
-
hasNewNodes = true;
|
|
15579
|
-
}
|
|
15580
|
-
}
|
|
15581
|
-
if (hasNewNodes) {
|
|
15582
|
-
set((s) => ({ nodes: { ...s.nodes, ...result } }));
|
|
15761
|
+
const created = useScopedResource({
|
|
15762
|
+
store,
|
|
15763
|
+
kind: "nodes",
|
|
15764
|
+
scope: isReader ? void 0 : scope,
|
|
15765
|
+
isLeaf: isTSLNode,
|
|
15766
|
+
create: () => {
|
|
15767
|
+
if (isReader) return {};
|
|
15768
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15769
|
+
},
|
|
15770
|
+
prepare: (name, node) => {
|
|
15771
|
+
node.setName?.(scope ? `${scope}.${name}` : name);
|
|
15772
|
+
return node;
|
|
15583
15773
|
}
|
|
15584
|
-
|
|
15585
|
-
|
|
15774
|
+
});
|
|
15775
|
+
let nodes = created;
|
|
15776
|
+
if (creatorOrScope === void 0) {
|
|
15777
|
+
nodes = storeNodes;
|
|
15778
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15779
|
+
const scopeData = storeNodes[creatorOrScope];
|
|
15780
|
+
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
15781
|
+
}
|
|
15586
15782
|
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
15587
15783
|
}
|
|
15588
15784
|
function rebuildAllNodes(store, scope) {
|
|
15589
|
-
store
|
|
15590
|
-
store.setState((state) => {
|
|
15591
|
-
let newNodes = state.nodes;
|
|
15592
|
-
if (scope && scope !== "root") {
|
|
15593
|
-
const { [scope]: _, ...rest } = state.nodes;
|
|
15594
|
-
newNodes = rest;
|
|
15595
|
-
} else if (scope === "root") {
|
|
15596
|
-
newNodes = {};
|
|
15597
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15598
|
-
if (!isTSLNode(value)) newNodes[key] = value;
|
|
15599
|
-
}
|
|
15600
|
-
} else {
|
|
15601
|
-
newNodes = {};
|
|
15602
|
-
}
|
|
15603
|
-
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
15604
|
-
});
|
|
15785
|
+
rebuildResource(store, "nodes", scope);
|
|
15605
15786
|
}
|
|
15606
15787
|
function removeNodes(set, names, scope) {
|
|
15607
15788
|
set((state) => {
|
|
@@ -15637,7 +15818,7 @@ function useLocalNodes(creator) {
|
|
|
15637
15818
|
const textures = usePrimaryThree((s) => s.textures);
|
|
15638
15819
|
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15639
15820
|
return React.useMemo(() => {
|
|
15640
|
-
const wrappedState = createLazyCreatorState(store.getState());
|
|
15821
|
+
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
15641
15822
|
return creator(wrappedState);
|
|
15642
15823
|
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
15643
15824
|
}
|
|
@@ -15658,58 +15839,15 @@ const disposeBuffer = (buffer) => {
|
|
|
15658
15839
|
function useBuffers(creatorOrScope, scope) {
|
|
15659
15840
|
const store = usePrimaryStore();
|
|
15660
15841
|
const removeBuffers = React.useCallback(
|
|
15661
|
-
(names, targetScope) =>
|
|
15662
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15663
|
-
store.setState((state) => {
|
|
15664
|
-
if (targetScope) {
|
|
15665
|
-
const currentScope = { ...state.buffers[targetScope] };
|
|
15666
|
-
for (const name of nameArray) delete currentScope[name];
|
|
15667
|
-
return { buffers: { ...state.buffers, [targetScope]: currentScope } };
|
|
15668
|
-
}
|
|
15669
|
-
const buffers2 = { ...state.buffers };
|
|
15670
|
-
for (const name of nameArray) if (isBufferLike(buffers2[name])) delete buffers2[name];
|
|
15671
|
-
return { buffers: buffers2 };
|
|
15672
|
-
});
|
|
15673
|
-
},
|
|
15842
|
+
(names, targetScope) => removeResourceEntries(store, "buffers", Array.isArray(names) ? names : [names], targetScope, isBufferLike),
|
|
15674
15843
|
[store]
|
|
15675
15844
|
);
|
|
15676
15845
|
const clearBuffers = React.useCallback(
|
|
15677
|
-
(targetScope) =>
|
|
15678
|
-
store.setState((state) => {
|
|
15679
|
-
if (targetScope && targetScope !== "root") {
|
|
15680
|
-
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15681
|
-
return { buffers: rest };
|
|
15682
|
-
}
|
|
15683
|
-
if (targetScope === "root") {
|
|
15684
|
-
const buffers2 = {};
|
|
15685
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15686
|
-
if (!isBufferLike(value)) buffers2[key] = value;
|
|
15687
|
-
}
|
|
15688
|
-
return { buffers: buffers2 };
|
|
15689
|
-
}
|
|
15690
|
-
return { buffers: {} };
|
|
15691
|
-
});
|
|
15692
|
-
},
|
|
15846
|
+
(targetScope) => clearResourceEntries(store, "buffers", targetScope, isBufferLike),
|
|
15693
15847
|
[store]
|
|
15694
15848
|
);
|
|
15695
15849
|
const rebuildBuffers = React.useCallback(
|
|
15696
|
-
(targetScope) =>
|
|
15697
|
-
store.setState((state) => {
|
|
15698
|
-
let newBuffers = state.buffers;
|
|
15699
|
-
if (targetScope && targetScope !== "root") {
|
|
15700
|
-
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15701
|
-
newBuffers = rest;
|
|
15702
|
-
} else if (targetScope === "root") {
|
|
15703
|
-
newBuffers = {};
|
|
15704
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15705
|
-
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15706
|
-
}
|
|
15707
|
-
} else {
|
|
15708
|
-
newBuffers = {};
|
|
15709
|
-
}
|
|
15710
|
-
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15711
|
-
});
|
|
15712
|
-
},
|
|
15850
|
+
(targetScope) => rebuildResource(store, "buffers", targetScope),
|
|
15713
15851
|
[store]
|
|
15714
15852
|
);
|
|
15715
15853
|
const disposeBuffers = React.useCallback(
|
|
@@ -15728,85 +15866,33 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
15728
15866
|
);
|
|
15729
15867
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15730
15868
|
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15731
|
-
const
|
|
15732
|
-
|
|
15733
|
-
|
|
15734
|
-
|
|
15735
|
-
|
|
15736
|
-
|
|
15737
|
-
return
|
|
15738
|
-
|
|
15739
|
-
|
|
15740
|
-
|
|
15741
|
-
if (
|
|
15742
|
-
|
|
15743
|
-
}
|
|
15744
|
-
const state = store.getState();
|
|
15745
|
-
const set = store.setState;
|
|
15746
|
-
const creator = creatorOrScope;
|
|
15747
|
-
const wrappedState = createLazyCreatorState(state);
|
|
15748
|
-
const created = creator(wrappedState);
|
|
15749
|
-
const result = {};
|
|
15750
|
-
let hasNewBuffers = false;
|
|
15751
|
-
if (scope) {
|
|
15752
|
-
const currentScope = state.buffers[scope] ?? {};
|
|
15753
|
-
for (const [name, buffer] of Object.entries(created)) {
|
|
15754
|
-
if (currentScope[name]) {
|
|
15755
|
-
result[name] = currentScope[name];
|
|
15756
|
-
} else {
|
|
15757
|
-
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15758
|
-
buffer.setName(`${scope}.${name}`);
|
|
15759
|
-
}
|
|
15760
|
-
result[name] = buffer;
|
|
15761
|
-
hasNewBuffers = true;
|
|
15762
|
-
}
|
|
15763
|
-
}
|
|
15764
|
-
if (hasNewBuffers) {
|
|
15765
|
-
set((s) => ({
|
|
15766
|
-
buffers: {
|
|
15767
|
-
...s.buffers,
|
|
15768
|
-
[scope]: { ...s.buffers[scope], ...result }
|
|
15769
|
-
}
|
|
15770
|
-
}));
|
|
15771
|
-
}
|
|
15772
|
-
return result;
|
|
15773
|
-
}
|
|
15774
|
-
for (const [name, buffer] of Object.entries(created)) {
|
|
15775
|
-
const existing = state.buffers[name];
|
|
15776
|
-
if (existing && isBufferLike(existing)) {
|
|
15777
|
-
result[name] = existing;
|
|
15778
|
-
} else {
|
|
15779
|
-
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15780
|
-
buffer.setName(name);
|
|
15781
|
-
}
|
|
15782
|
-
result[name] = buffer;
|
|
15783
|
-
hasNewBuffers = true;
|
|
15869
|
+
const created = useScopedResource({
|
|
15870
|
+
store,
|
|
15871
|
+
kind: "buffers",
|
|
15872
|
+
scope: isReader ? void 0 : scope,
|
|
15873
|
+
isLeaf: isBufferLike,
|
|
15874
|
+
create: () => {
|
|
15875
|
+
if (isReader) return {};
|
|
15876
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15877
|
+
},
|
|
15878
|
+
prepare: (name, buffer) => {
|
|
15879
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15880
|
+
buffer.setName(scope ? `${scope}.${name}` : name);
|
|
15784
15881
|
}
|
|
15882
|
+
return buffer;
|
|
15785
15883
|
}
|
|
15786
|
-
|
|
15787
|
-
|
|
15788
|
-
|
|
15789
|
-
|
|
15790
|
-
}
|
|
15884
|
+
});
|
|
15885
|
+
let buffers = created;
|
|
15886
|
+
if (creatorOrScope === void 0) {
|
|
15887
|
+
buffers = storeBuffers;
|
|
15888
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15889
|
+
const scopeData = storeBuffers[creatorOrScope];
|
|
15890
|
+
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
15891
|
+
}
|
|
15791
15892
|
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
15792
15893
|
}
|
|
15793
15894
|
function rebuildAllBuffers(store, scope) {
|
|
15794
|
-
store
|
|
15795
|
-
store.setState((state) => {
|
|
15796
|
-
let newBuffers = state.buffers;
|
|
15797
|
-
if (scope && scope !== "root") {
|
|
15798
|
-
const { [scope]: _, ...rest } = state.buffers;
|
|
15799
|
-
newBuffers = rest;
|
|
15800
|
-
} else if (scope === "root") {
|
|
15801
|
-
newBuffers = {};
|
|
15802
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15803
|
-
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15804
|
-
}
|
|
15805
|
-
} else {
|
|
15806
|
-
newBuffers = {};
|
|
15807
|
-
}
|
|
15808
|
-
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15809
|
-
});
|
|
15895
|
+
rebuildResource(store, "buffers", scope);
|
|
15810
15896
|
}
|
|
15811
15897
|
|
|
15812
15898
|
const isStorageLike = (value) => {
|
|
@@ -15825,58 +15911,15 @@ const disposeStorage = (storage) => {
|
|
|
15825
15911
|
function useGPUStorage(creatorOrScope, scope) {
|
|
15826
15912
|
const store = usePrimaryStore();
|
|
15827
15913
|
const removeStorage = React.useCallback(
|
|
15828
|
-
(names, targetScope) =>
|
|
15829
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
15830
|
-
store.setState((state) => {
|
|
15831
|
-
if (targetScope) {
|
|
15832
|
-
const currentScope = { ...state.gpuStorage[targetScope] };
|
|
15833
|
-
for (const name of nameArray) delete currentScope[name];
|
|
15834
|
-
return { gpuStorage: { ...state.gpuStorage, [targetScope]: currentScope } };
|
|
15835
|
-
}
|
|
15836
|
-
const gpuStorage2 = { ...state.gpuStorage };
|
|
15837
|
-
for (const name of nameArray) if (isStorageLike(gpuStorage2[name])) delete gpuStorage2[name];
|
|
15838
|
-
return { gpuStorage: gpuStorage2 };
|
|
15839
|
-
});
|
|
15840
|
-
},
|
|
15914
|
+
(names, targetScope) => removeResourceEntries(store, "gpuStorage", Array.isArray(names) ? names : [names], targetScope, isStorageLike),
|
|
15841
15915
|
[store]
|
|
15842
15916
|
);
|
|
15843
15917
|
const clearStorage = React.useCallback(
|
|
15844
|
-
(targetScope) =>
|
|
15845
|
-
store.setState((state) => {
|
|
15846
|
-
if (targetScope && targetScope !== "root") {
|
|
15847
|
-
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15848
|
-
return { gpuStorage: rest };
|
|
15849
|
-
}
|
|
15850
|
-
if (targetScope === "root") {
|
|
15851
|
-
const gpuStorage2 = {};
|
|
15852
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15853
|
-
if (!isStorageLike(value)) gpuStorage2[key] = value;
|
|
15854
|
-
}
|
|
15855
|
-
return { gpuStorage: gpuStorage2 };
|
|
15856
|
-
}
|
|
15857
|
-
return { gpuStorage: {} };
|
|
15858
|
-
});
|
|
15859
|
-
},
|
|
15918
|
+
(targetScope) => clearResourceEntries(store, "gpuStorage", targetScope, isStorageLike),
|
|
15860
15919
|
[store]
|
|
15861
15920
|
);
|
|
15862
15921
|
const rebuildStorage = React.useCallback(
|
|
15863
|
-
(targetScope) =>
|
|
15864
|
-
store.setState((state) => {
|
|
15865
|
-
let newStorage = state.gpuStorage;
|
|
15866
|
-
if (targetScope && targetScope !== "root") {
|
|
15867
|
-
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15868
|
-
newStorage = rest;
|
|
15869
|
-
} else if (targetScope === "root") {
|
|
15870
|
-
newStorage = {};
|
|
15871
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15872
|
-
if (!isStorageLike(value)) newStorage[key] = value;
|
|
15873
|
-
}
|
|
15874
|
-
} else {
|
|
15875
|
-
newStorage = {};
|
|
15876
|
-
}
|
|
15877
|
-
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
15878
|
-
});
|
|
15879
|
-
},
|
|
15922
|
+
(targetScope) => rebuildResource(store, "gpuStorage", targetScope),
|
|
15880
15923
|
[store]
|
|
15881
15924
|
);
|
|
15882
15925
|
const disposeStorageFn = React.useCallback(
|
|
@@ -15895,72 +15938,33 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
15895
15938
|
);
|
|
15896
15939
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15897
15940
|
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
15898
|
-
const
|
|
15899
|
-
|
|
15900
|
-
|
|
15901
|
-
|
|
15902
|
-
|
|
15903
|
-
|
|
15904
|
-
return
|
|
15905
|
-
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
const state = store.getState();
|
|
15912
|
-
const set = store.setState;
|
|
15913
|
-
const creator = creatorOrScope;
|
|
15914
|
-
const wrappedState = createLazyCreatorState(state);
|
|
15915
|
-
const created = creator(wrappedState);
|
|
15916
|
-
const result = {};
|
|
15917
|
-
let hasNewStorage = false;
|
|
15918
|
-
if (scope) {
|
|
15919
|
-
const currentScope = state.gpuStorage[scope] ?? {};
|
|
15920
|
-
for (const [name, storage] of Object.entries(created)) {
|
|
15921
|
-
if (currentScope[name]) {
|
|
15922
|
-
result[name] = currentScope[name];
|
|
15923
|
-
} else {
|
|
15924
|
-
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15925
|
-
storage.setName(`${scope}.${name}`);
|
|
15926
|
-
}
|
|
15927
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
15928
|
-
storage.name = `${scope}.${name}`;
|
|
15929
|
-
}
|
|
15930
|
-
result[name] = storage;
|
|
15931
|
-
hasNewStorage = true;
|
|
15932
|
-
}
|
|
15933
|
-
}
|
|
15934
|
-
if (hasNewStorage) {
|
|
15935
|
-
set((s) => ({
|
|
15936
|
-
gpuStorage: {
|
|
15937
|
-
...s.gpuStorage,
|
|
15938
|
-
[scope]: { ...s.gpuStorage[scope], ...result }
|
|
15939
|
-
}
|
|
15940
|
-
}));
|
|
15941
|
+
const created = useScopedResource({
|
|
15942
|
+
store,
|
|
15943
|
+
kind: "gpuStorage",
|
|
15944
|
+
scope: isReader ? void 0 : scope,
|
|
15945
|
+
isLeaf: isStorageLike,
|
|
15946
|
+
create: () => {
|
|
15947
|
+
if (isReader) return {};
|
|
15948
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15949
|
+
},
|
|
15950
|
+
prepare: (name, storage) => {
|
|
15951
|
+
const label = scope ? `${scope}.${name}` : name;
|
|
15952
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15953
|
+
storage.setName(label);
|
|
15941
15954
|
}
|
|
15942
|
-
|
|
15943
|
-
|
|
15944
|
-
for (const [name, storage] of Object.entries(created)) {
|
|
15945
|
-
const existing = state.gpuStorage[name];
|
|
15946
|
-
if (existing && isStorageLike(existing)) {
|
|
15947
|
-
result[name] = existing;
|
|
15948
|
-
} else {
|
|
15949
|
-
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15950
|
-
storage.setName(name);
|
|
15951
|
-
}
|
|
15952
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
15953
|
-
storage.name = name;
|
|
15954
|
-
}
|
|
15955
|
-
result[name] = storage;
|
|
15956
|
-
hasNewStorage = true;
|
|
15955
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
15956
|
+
storage.name = label;
|
|
15957
15957
|
}
|
|
15958
|
+
return storage;
|
|
15958
15959
|
}
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
}
|
|
15960
|
+
});
|
|
15961
|
+
let gpuStorage = created;
|
|
15962
|
+
if (creatorOrScope === void 0) {
|
|
15963
|
+
gpuStorage = storeStorage;
|
|
15964
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15965
|
+
const scopeData = storeStorage[creatorOrScope];
|
|
15966
|
+
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
15967
|
+
}
|
|
15964
15968
|
return {
|
|
15965
15969
|
...gpuStorage,
|
|
15966
15970
|
removeStorage,
|
|
@@ -15970,22 +15974,7 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
15970
15974
|
};
|
|
15971
15975
|
}
|
|
15972
15976
|
function rebuildAllStorage(store, scope) {
|
|
15973
|
-
store
|
|
15974
|
-
store.setState((state) => {
|
|
15975
|
-
let newStorage = state.gpuStorage;
|
|
15976
|
-
if (scope && scope !== "root") {
|
|
15977
|
-
const { [scope]: _, ...rest } = state.gpuStorage;
|
|
15978
|
-
newStorage = rest;
|
|
15979
|
-
} else if (scope === "root") {
|
|
15980
|
-
newStorage = {};
|
|
15981
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15982
|
-
if (!isStorageLike(value)) newStorage[key] = value;
|
|
15983
|
-
}
|
|
15984
|
-
} else {
|
|
15985
|
-
newStorage = {};
|
|
15986
|
-
}
|
|
15987
|
-
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
15988
|
-
});
|
|
15977
|
+
rebuildResource(store, "gpuStorage", scope);
|
|
15989
15978
|
}
|
|
15990
15979
|
|
|
15991
15980
|
function useRenderPipeline(mainCB, setupCB) {
|
|
@@ -16026,12 +16015,12 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16026
16015
|
const state = store.getState();
|
|
16027
16016
|
const set = store.setState;
|
|
16028
16017
|
try {
|
|
16029
|
-
let
|
|
16018
|
+
let pipeline = state.renderPipeline;
|
|
16030
16019
|
let currentPasses = { ...state.passes };
|
|
16031
|
-
let
|
|
16032
|
-
if (!
|
|
16033
|
-
|
|
16034
|
-
|
|
16020
|
+
let justCreatedPipeline = false;
|
|
16021
|
+
if (!pipeline) {
|
|
16022
|
+
pipeline = new webgpu.RenderPipeline(renderer);
|
|
16023
|
+
justCreatedPipeline = true;
|
|
16035
16024
|
}
|
|
16036
16025
|
const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
16037
16026
|
let scenePass;
|
|
@@ -16042,9 +16031,9 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16042
16031
|
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
16043
16032
|
}
|
|
16044
16033
|
currentPasses.scenePass = scenePass;
|
|
16045
|
-
if (!
|
|
16046
|
-
set({ renderPipeline:
|
|
16047
|
-
const shouldRunCallbacks =
|
|
16034
|
+
if (!pipeline.outputNode || justCreatedPipeline) pipeline.outputNode = scenePass;
|
|
16035
|
+
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
16036
|
+
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
16048
16037
|
if (shouldRunCallbacks) {
|
|
16049
16038
|
if (setupCBRef.current) {
|
|
16050
16039
|
const freshState = store.getState();
|
|
@@ -16065,7 +16054,7 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16065
16054
|
callbacksRanRef.current = true;
|
|
16066
16055
|
}
|
|
16067
16056
|
} catch (error) {
|
|
16068
|
-
console.
|
|
16057
|
+
console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
|
|
16069
16058
|
}
|
|
16070
16059
|
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
16071
16060
|
const passes = useThree((s) => s.passes);
|
|
@@ -16102,7 +16091,6 @@ exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
|
16102
16091
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
16103
16092
|
exports.Texture = Texture;
|
|
16104
16093
|
exports._roots = _roots;
|
|
16105
|
-
exports.act = act;
|
|
16106
16094
|
exports.addAfterEffect = addAfterEffect;
|
|
16107
16095
|
exports.addEffect = addEffect;
|
|
16108
16096
|
exports.addTail = addTail;
|
|
@@ -16164,6 +16152,7 @@ exports.removeInteractivity = removeInteractivity;
|
|
|
16164
16152
|
exports.removeNodes = removeNodes;
|
|
16165
16153
|
exports.removeUniforms = removeUniforms;
|
|
16166
16154
|
exports.resolve = resolve;
|
|
16155
|
+
exports.swapInteractivity = swapInteractivity;
|
|
16167
16156
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
16168
16157
|
exports.unregisterPrimary = unregisterPrimary;
|
|
16169
16158
|
exports.updateCamera = updateCamera;
|