@react-three/fiber 10.0.0-canary.1b98c17 → 10.0.0-canary.1be335a
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 +504 -1353
- package/dist/index.d.cts +151 -795
- package/dist/index.d.mts +151 -795
- package/dist/index.d.ts +151 -795
- package/dist/index.mjs +479 -1327
- package/dist/legacy.cjs +459 -1308
- package/dist/legacy.d.cts +151 -794
- package/dist/legacy.d.mts +151 -794
- package/dist/legacy.d.ts +151 -794
- package/dist/legacy.mjs +433 -1281
- package/dist/webgpu/index.cjs +1024 -2096
- package/dist/webgpu/index.d.cts +184 -798
- package/dist/webgpu/index.d.mts +184 -798
- package/dist/webgpu/index.d.ts +184 -798
- package/dist/webgpu/index.mjs +1000 -2071
- package/package.json +4 -3
- package/readme.md +2 -3
package/dist/webgpu/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js'
|
|
|
14
14
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
15
15
|
const Tb = require('scheduler');
|
|
16
16
|
const traditional = require('zustand/traditional');
|
|
17
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
17
18
|
const suspendReact = require('suspend-react');
|
|
18
19
|
const lite = require('dequal/lite');
|
|
19
20
|
require('zustand/shallow');
|
|
@@ -62,13 +63,16 @@ const WebGLRenderer = class WebGLRenderer2 {
|
|
|
62
63
|
}
|
|
63
64
|
};
|
|
64
65
|
const WebGLRenderTarget = null;
|
|
66
|
+
const WebGLCubeRenderTarget = null;
|
|
65
67
|
|
|
66
68
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
67
69
|
__proto__: null,
|
|
70
|
+
CubeRenderTargetCompat: webgpu.CubeRenderTarget,
|
|
68
71
|
Inspector: Inspector_js.Inspector,
|
|
69
72
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
70
73
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
71
74
|
RenderTargetCompat: webgpu.RenderTarget,
|
|
75
|
+
WebGLCubeRenderTarget: WebGLCubeRenderTarget,
|
|
72
76
|
WebGLRenderTarget: WebGLRenderTarget,
|
|
73
77
|
WebGLRenderer: WebGLRenderer
|
|
74
78
|
}, [webgpu__namespace]);
|
|
@@ -342,15 +346,16 @@ function EnvironmentPortal({
|
|
|
342
346
|
preset = void 0,
|
|
343
347
|
extensions
|
|
344
348
|
}) {
|
|
345
|
-
const
|
|
349
|
+
const renderer = fiber.useThree((state) => state.renderer);
|
|
350
|
+
const isLegacy = fiber.useThree((state) => state.isLegacy);
|
|
346
351
|
const defaultScene = fiber.useThree((state) => state.scene);
|
|
347
352
|
const camera = React__namespace.useRef(null);
|
|
348
353
|
const [virtualScene] = React__namespace.useState(() => new webgpu.Scene());
|
|
349
354
|
const fbo = React__namespace.useMemo(() => {
|
|
350
|
-
const fbo2 = new webgpu.
|
|
355
|
+
const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new webgpu.CubeRenderTarget(resolution);
|
|
351
356
|
fbo2.texture.type = webgpu.HalfFloatType;
|
|
352
357
|
return fbo2;
|
|
353
|
-
}, [resolution]);
|
|
358
|
+
}, [resolution, isLegacy]);
|
|
354
359
|
React__namespace.useEffect(() => {
|
|
355
360
|
return () => {
|
|
356
361
|
fbo.dispose();
|
|
@@ -358,10 +363,10 @@ function EnvironmentPortal({
|
|
|
358
363
|
}, [fbo]);
|
|
359
364
|
React__namespace.useLayoutEffect(() => {
|
|
360
365
|
if (frames === 1) {
|
|
361
|
-
const autoClear =
|
|
362
|
-
|
|
363
|
-
camera.current.update(
|
|
364
|
-
|
|
366
|
+
const autoClear = renderer.autoClear;
|
|
367
|
+
renderer.autoClear = true;
|
|
368
|
+
camera.current.update(renderer, virtualScene);
|
|
369
|
+
renderer.autoClear = autoClear;
|
|
365
370
|
}
|
|
366
371
|
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
367
372
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
@@ -378,7 +383,7 @@ function EnvironmentPortal({
|
|
|
378
383
|
defaultScene,
|
|
379
384
|
background,
|
|
380
385
|
frames,
|
|
381
|
-
|
|
386
|
+
renderer,
|
|
382
387
|
blur,
|
|
383
388
|
backgroundBlurriness,
|
|
384
389
|
backgroundIntensity,
|
|
@@ -389,10 +394,10 @@ function EnvironmentPortal({
|
|
|
389
394
|
let count = 1;
|
|
390
395
|
fiber.useFrame(() => {
|
|
391
396
|
if (frames === Infinity || count < frames) {
|
|
392
|
-
const autoClear =
|
|
393
|
-
|
|
394
|
-
camera.current.update(
|
|
395
|
-
|
|
397
|
+
const autoClear = renderer.autoClear;
|
|
398
|
+
renderer.autoClear = true;
|
|
399
|
+
camera.current.update(renderer, virtualScene);
|
|
400
|
+
renderer.autoClear = autoClear;
|
|
396
401
|
count++;
|
|
397
402
|
}
|
|
398
403
|
});
|
|
@@ -456,9 +461,9 @@ function Environment(props) {
|
|
|
456
461
|
return props.ground ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props });
|
|
457
462
|
}
|
|
458
463
|
|
|
459
|
-
var __defProp$
|
|
460
|
-
var __defNormalProp$
|
|
461
|
-
var __publicField$
|
|
464
|
+
var __defProp$1 = Object.defineProperty;
|
|
465
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
466
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
462
467
|
const act = React__namespace["act"];
|
|
463
468
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
464
469
|
function useMutableCallback(fn) {
|
|
@@ -490,7 +495,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
490
495
|
return _a = class extends React__namespace.Component {
|
|
491
496
|
constructor() {
|
|
492
497
|
super(...arguments);
|
|
493
|
-
__publicField$
|
|
498
|
+
__publicField$1(this, "state", { error: false });
|
|
494
499
|
}
|
|
495
500
|
componentDidCatch(err) {
|
|
496
501
|
this.props.set(err);
|
|
@@ -498,7 +503,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
498
503
|
render() {
|
|
499
504
|
return this.state.error ? null : this.props.children;
|
|
500
505
|
}
|
|
501
|
-
}, __publicField$
|
|
506
|
+
}, __publicField$1(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
502
507
|
})();
|
|
503
508
|
|
|
504
509
|
const is = {
|
|
@@ -635,8 +640,7 @@ function prepare(target, root, type, props) {
|
|
|
635
640
|
object,
|
|
636
641
|
eventCount: 0,
|
|
637
642
|
handlers: {},
|
|
638
|
-
isHidden: false
|
|
639
|
-
deferredRefs: []
|
|
643
|
+
isHidden: false
|
|
640
644
|
};
|
|
641
645
|
if (object) object.__r3f = instance;
|
|
642
646
|
}
|
|
@@ -793,6 +797,17 @@ function unregisterVisibility(store, object) {
|
|
|
793
797
|
internal.visibilityRegistry.delete(object.uuid);
|
|
794
798
|
internal.occlusionCache.delete(object);
|
|
795
799
|
}
|
|
800
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
801
|
+
const { internal } = store.getState();
|
|
802
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
803
|
+
if (!entry) return false;
|
|
804
|
+
entry.handlers = handlers;
|
|
805
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
806
|
+
object.occlusionTest = true;
|
|
807
|
+
enableOcclusion(store);
|
|
808
|
+
}
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
796
811
|
function checkVisibility(state) {
|
|
797
812
|
const { internal, camera } = state;
|
|
798
813
|
const registry = internal.visibilityRegistry;
|
|
@@ -953,9 +968,9 @@ function diffProps(instance, newProps) {
|
|
|
953
968
|
const { root, key } = resolve(instance.object, prop);
|
|
954
969
|
if (root.constructor && root.constructor.length === 0) {
|
|
955
970
|
const ctor = getMemoizedPrototype(root);
|
|
956
|
-
if (!is.und(ctor)) changedProps[
|
|
971
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
957
972
|
} else {
|
|
958
|
-
changedProps[
|
|
973
|
+
changedProps[prop] = 0;
|
|
959
974
|
}
|
|
960
975
|
}
|
|
961
976
|
return changedProps;
|
|
@@ -980,10 +995,7 @@ function applyProps(object, props) {
|
|
|
980
995
|
continue;
|
|
981
996
|
}
|
|
982
997
|
if (value === void 0) continue;
|
|
983
|
-
if (isFromRef(value))
|
|
984
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
998
|
+
if (isFromRef(value)) continue;
|
|
987
999
|
if (isOnce(value)) {
|
|
988
1000
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
989
1001
|
if (instance) {
|
|
@@ -1019,6 +1031,19 @@ function applyProps(object, props) {
|
|
|
1019
1031
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1020
1032
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1021
1033
|
else target.set(value);
|
|
1034
|
+
} else if (root instanceof webgpu.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1035
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1036
|
+
const uniforms = root.uniforms;
|
|
1037
|
+
const nextUniforms = value;
|
|
1038
|
+
for (const name in nextUniforms) {
|
|
1039
|
+
const uniform = nextUniforms[name];
|
|
1040
|
+
const targetUniform = uniforms[name];
|
|
1041
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1042
|
+
else {
|
|
1043
|
+
const nextUniform = uniform instanceof webgpu.Uniform ? uniform.clone() : new webgpu.Uniform(uniform.value);
|
|
1044
|
+
uniforms[name] = nextUniform;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1022
1047
|
} else {
|
|
1023
1048
|
root[key] = value;
|
|
1024
1049
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1037,6 +1062,9 @@ function applyProps(object, props) {
|
|
|
1037
1062
|
if (instance.eventCount && object2.raycast !== null) {
|
|
1038
1063
|
rootState.internal.interaction.push(object2);
|
|
1039
1064
|
}
|
|
1065
|
+
}
|
|
1066
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1067
|
+
const object2 = instance.object;
|
|
1040
1068
|
const root = findInitialRoot(instance);
|
|
1041
1069
|
const visibilityHandlers = {
|
|
1042
1070
|
onFramed: instance.handlers.onFramed,
|
|
@@ -1044,7 +1072,9 @@ function applyProps(object, props) {
|
|
|
1044
1072
|
onVisible: instance.handlers.onVisible
|
|
1045
1073
|
};
|
|
1046
1074
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
1047
|
-
|
|
1075
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1076
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1077
|
+
}
|
|
1048
1078
|
} else {
|
|
1049
1079
|
unregisterVisibility(root, object2);
|
|
1050
1080
|
}
|
|
@@ -1572,6 +1602,7 @@ function createPointerEvents(store) {
|
|
|
1572
1602
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1573
1603
|
}
|
|
1574
1604
|
},
|
|
1605
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1575
1606
|
registerPointer: (config) => {
|
|
1576
1607
|
const pointerId = nextXRPointerId++;
|
|
1577
1608
|
xrPointers.set(pointerId, config);
|
|
@@ -1658,1229 +1689,206 @@ function notifyAlpha({ message, link }) {
|
|
|
1658
1689
|
}
|
|
1659
1690
|
}
|
|
1660
1691
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
constructor() {
|
|
1667
|
-
/** Ordered list of phase nodes */
|
|
1668
|
-
__publicField$2(this, "phases", []);
|
|
1669
|
-
/** Quick lookup by name */
|
|
1670
|
-
__publicField$2(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1671
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1672
|
-
__publicField$2(this, "orderedNamesCache", null);
|
|
1673
|
-
this.initializeDefaultPhases();
|
|
1674
|
-
}
|
|
1675
|
-
//* Initialization --------------------------------
|
|
1676
|
-
initializeDefaultPhases() {
|
|
1677
|
-
for (const name of DEFAULT_PHASES) {
|
|
1678
|
-
const node = { name, isAutoGenerated: false };
|
|
1679
|
-
this.phases.push(node);
|
|
1680
|
-
this.phaseMap.set(name, node);
|
|
1681
|
-
}
|
|
1682
|
-
this.invalidateCache();
|
|
1683
|
-
}
|
|
1684
|
-
//* Public API --------------------------------
|
|
1685
|
-
/**
|
|
1686
|
-
* Add a named phase to the graph
|
|
1687
|
-
* @param name - Phase name (must be unique)
|
|
1688
|
-
* @param options - Position options (before or after another phase)
|
|
1689
|
-
*/
|
|
1690
|
-
addPhase(name, options = {}) {
|
|
1691
|
-
if (this.phaseMap.has(name)) {
|
|
1692
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
const { before, after } = options;
|
|
1696
|
-
const node = { name, isAutoGenerated: false };
|
|
1697
|
-
let insertIndex = this.phases.length;
|
|
1698
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1699
|
-
if (targetIndex !== -1) {
|
|
1700
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1701
|
-
} else {
|
|
1702
|
-
const constraintType = before ? "before" : "after";
|
|
1703
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1704
|
-
}
|
|
1705
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1706
|
-
this.phaseMap.set(name, node);
|
|
1707
|
-
this.invalidateCache();
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Get ordered list of phase names
|
|
1711
|
-
*/
|
|
1712
|
-
getOrderedPhases() {
|
|
1713
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1714
|
-
return this.orderedNamesCache;
|
|
1715
|
-
}
|
|
1716
|
-
/**
|
|
1717
|
-
* Check if a phase exists
|
|
1718
|
-
*/
|
|
1719
|
-
hasPhase(name) {
|
|
1720
|
-
return this.phaseMap.has(name);
|
|
1721
|
-
}
|
|
1722
|
-
/**
|
|
1723
|
-
* Get the index of a phase (-1 if not found)
|
|
1724
|
-
*/
|
|
1725
|
-
getPhaseIndex(name) {
|
|
1726
|
-
if (!name) return -1;
|
|
1727
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1728
|
-
}
|
|
1729
|
-
/**
|
|
1730
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1731
|
-
* Used for resolving before/after constraints.
|
|
1732
|
-
*
|
|
1733
|
-
* @param name - The phase name to ensure exists
|
|
1734
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1735
|
-
*/
|
|
1736
|
-
ensurePhase(name) {
|
|
1737
|
-
if (this.phaseMap.has(name)) return name;
|
|
1738
|
-
const node = { name, isAutoGenerated: true };
|
|
1739
|
-
this.phases.push(node);
|
|
1740
|
-
this.phaseMap.set(name, node);
|
|
1741
|
-
this.invalidateCache();
|
|
1742
|
-
return name;
|
|
1743
|
-
}
|
|
1744
|
-
/**
|
|
1745
|
-
* Resolve where a job with before/after constraints should go.
|
|
1746
|
-
* Creates auto-generated phases if needed.
|
|
1747
|
-
*
|
|
1748
|
-
* @param before - Phase(s) to run before
|
|
1749
|
-
* @param after - Phase(s) to run after
|
|
1750
|
-
* @returns The resolved phase name
|
|
1751
|
-
*/
|
|
1752
|
-
resolveConstraintPhase(before, after) {
|
|
1753
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1754
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1755
|
-
if (beforeArr.length > 0) {
|
|
1756
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1757
|
-
}
|
|
1758
|
-
if (afterArr.length > 0) {
|
|
1759
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1760
|
-
}
|
|
1761
|
-
return "update";
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1765
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1766
|
-
*
|
|
1767
|
-
* @param target - The target phase name to position relative to
|
|
1768
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1769
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1770
|
-
* @returns The auto-generated phase name
|
|
1771
|
-
*/
|
|
1772
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1773
|
-
const autoName = `${prefix}:${target}`;
|
|
1774
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1775
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1776
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1777
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1778
|
-
else this.phases.push(node);
|
|
1779
|
-
this.phaseMap.set(autoName, node);
|
|
1780
|
-
this.invalidateCache();
|
|
1781
|
-
return autoName;
|
|
1782
|
-
}
|
|
1783
|
-
// Internal --------------------------------
|
|
1784
|
-
invalidateCache() {
|
|
1785
|
-
this.orderedNamesCache = null;
|
|
1786
|
-
}
|
|
1692
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1693
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1694
|
+
if (!stack) return false;
|
|
1695
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1696
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
1787
1697
|
}
|
|
1788
1698
|
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1810
|
-
return a.index - b.index;
|
|
1811
|
-
});
|
|
1812
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1813
|
-
}
|
|
1814
|
-
for (const [phase, bucket] of buckets) {
|
|
1815
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1816
|
-
bucket.sort((a, b) => {
|
|
1817
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1818
|
-
return a.index - b.index;
|
|
1819
|
-
});
|
|
1820
|
-
sortedBuckets.push(bucket);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
return sortedBuckets.flat();
|
|
1824
|
-
}
|
|
1825
|
-
function hasCrossJobConstraints(bucket) {
|
|
1826
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1827
|
-
for (const job of bucket) {
|
|
1828
|
-
for (const ref of job.before) {
|
|
1829
|
-
if (jobIds.has(ref)) return true;
|
|
1830
|
-
}
|
|
1831
|
-
for (const ref of job.after) {
|
|
1832
|
-
if (jobIds.has(ref)) return true;
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
return false;
|
|
1836
|
-
}
|
|
1837
|
-
function topologicalSort(jobs) {
|
|
1838
|
-
const n = jobs.length;
|
|
1839
|
-
if (n <= 1) return jobs;
|
|
1840
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1841
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1842
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1843
|
-
for (const job of jobs) {
|
|
1844
|
-
jobMap.set(job.id, job);
|
|
1845
|
-
inDegree.set(job.id, 0);
|
|
1846
|
-
adjacency.set(job.id, []);
|
|
1847
|
-
}
|
|
1848
|
-
for (const job of jobs) {
|
|
1849
|
-
for (const ref of job.before) {
|
|
1850
|
-
if (jobMap.has(ref)) {
|
|
1851
|
-
adjacency.get(job.id).push(ref);
|
|
1852
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1699
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
1700
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
1701
|
+
const createStore = (invalidate, advance) => {
|
|
1702
|
+
const rootStore = traditional.createWithEqualityFn((set, get) => {
|
|
1703
|
+
const position = new webgpu.Vector3();
|
|
1704
|
+
const defaultTarget = new webgpu.Vector3();
|
|
1705
|
+
const tempTarget = new webgpu.Vector3();
|
|
1706
|
+
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
1707
|
+
const { width, height, top, left } = size;
|
|
1708
|
+
const aspect = width / height;
|
|
1709
|
+
if (target.isVector3) tempTarget.copy(target);
|
|
1710
|
+
else tempTarget.set(...target);
|
|
1711
|
+
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
1712
|
+
if (isOrthographicCamera(camera)) {
|
|
1713
|
+
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
1714
|
+
} else {
|
|
1715
|
+
const fov = camera.fov * Math.PI / 180;
|
|
1716
|
+
const h = 2 * Math.tan(fov / 2) * distance;
|
|
1717
|
+
const w = h * (width / height);
|
|
1718
|
+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1853
1719
|
}
|
|
1854
1720
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1721
|
+
let performanceTimeout = void 0;
|
|
1722
|
+
const setPerformanceCurrent = (current) => set((state2) => ({ performance: { ...state2.performance, current } }));
|
|
1723
|
+
const pointer = new webgpu.Vector2();
|
|
1724
|
+
const rootState = {
|
|
1725
|
+
set,
|
|
1726
|
+
get,
|
|
1727
|
+
// Mock objects that have to be configured
|
|
1728
|
+
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
1729
|
+
primaryStore: null,
|
|
1730
|
+
gl: null,
|
|
1731
|
+
renderer: null,
|
|
1732
|
+
camera: null,
|
|
1733
|
+
frustum: new webgpu.Frustum(),
|
|
1734
|
+
autoUpdateFrustum: true,
|
|
1735
|
+
raycaster: null,
|
|
1736
|
+
events: {
|
|
1737
|
+
priority: 1,
|
|
1738
|
+
enabled: true,
|
|
1739
|
+
connected: false,
|
|
1740
|
+
frameTimedRaycasts: true,
|
|
1741
|
+
alwaysFireOnScroll: true,
|
|
1742
|
+
updateOnFrame: false
|
|
1743
|
+
},
|
|
1744
|
+
scene: null,
|
|
1745
|
+
rootScene: null,
|
|
1746
|
+
xr: null,
|
|
1747
|
+
inspector: null,
|
|
1748
|
+
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
1749
|
+
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
1750
|
+
textureColorSpace: webgpu.SRGBColorSpace,
|
|
1751
|
+
isLegacy: false,
|
|
1752
|
+
webGPUSupported: false,
|
|
1753
|
+
isNative: false,
|
|
1754
|
+
controls: null,
|
|
1755
|
+
pointer,
|
|
1756
|
+
mouse: pointer,
|
|
1757
|
+
frameloop: "always",
|
|
1758
|
+
onPointerMissed: void 0,
|
|
1759
|
+
onDragOverMissed: void 0,
|
|
1760
|
+
onDropMissed: void 0,
|
|
1761
|
+
performance: {
|
|
1762
|
+
current: 1,
|
|
1763
|
+
min: 0.5,
|
|
1764
|
+
max: 1,
|
|
1765
|
+
debounce: 200,
|
|
1766
|
+
regress: () => {
|
|
1767
|
+
const state2 = get();
|
|
1768
|
+
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
1769
|
+
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
1770
|
+
performanceTimeout = setTimeout(
|
|
1771
|
+
() => setPerformanceCurrent(get().performance.max),
|
|
1772
|
+
state2.performance.debounce
|
|
1773
|
+
);
|
|
1774
|
+
}
|
|
1775
|
+
},
|
|
1776
|
+
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
1777
|
+
viewport: {
|
|
1778
|
+
initialDpr: 0,
|
|
1779
|
+
dpr: 0,
|
|
1780
|
+
width: 0,
|
|
1781
|
+
height: 0,
|
|
1782
|
+
top: 0,
|
|
1783
|
+
left: 0,
|
|
1784
|
+
aspect: 0,
|
|
1785
|
+
distance: 0,
|
|
1786
|
+
factor: 0,
|
|
1787
|
+
getCurrentViewport
|
|
1788
|
+
},
|
|
1789
|
+
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
1790
|
+
setSize: (width, height, top, left) => {
|
|
1791
|
+
const state2 = get();
|
|
1792
|
+
if (width === void 0) {
|
|
1793
|
+
set({ _sizeImperative: false });
|
|
1794
|
+
if (state2._sizeProps) {
|
|
1795
|
+
const { width: propW, height: propH } = state2._sizeProps;
|
|
1796
|
+
if (propW !== void 0 || propH !== void 0) {
|
|
1797
|
+
const currentSize = state2.size;
|
|
1798
|
+
const newSize = {
|
|
1799
|
+
width: propW ?? currentSize.width,
|
|
1800
|
+
height: propH ?? currentSize.height,
|
|
1801
|
+
top: currentSize.top,
|
|
1802
|
+
left: currentSize.left
|
|
1803
|
+
};
|
|
1804
|
+
set((s) => ({
|
|
1805
|
+
size: newSize,
|
|
1806
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1807
|
+
}));
|
|
1808
|
+
scheduler.getScheduler().invalidate();
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const w = width;
|
|
1814
|
+
const h = height ?? width;
|
|
1815
|
+
const t = top ?? state2.size.top;
|
|
1816
|
+
const l = left ?? state2.size.left;
|
|
1817
|
+
const size = { width: w, height: h, top: t, left: l };
|
|
1818
|
+
set((s) => ({
|
|
1819
|
+
size,
|
|
1820
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1821
|
+
_sizeImperative: true
|
|
1822
|
+
}));
|
|
1823
|
+
scheduler.getScheduler().invalidate();
|
|
1824
|
+
},
|
|
1825
|
+
setDpr: (dpr) => set((state2) => {
|
|
1826
|
+
const resolved = calculateDpr(dpr);
|
|
1827
|
+
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
1828
|
+
}),
|
|
1829
|
+
setFrameloop: (frameloop = "always") => {
|
|
1830
|
+
set(() => ({ frameloop }));
|
|
1831
|
+
scheduler.getScheduler().frameloop = frameloop;
|
|
1832
|
+
},
|
|
1833
|
+
setError: (error) => set(() => ({ error })),
|
|
1834
|
+
error: null,
|
|
1835
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1836
|
+
uniforms: {},
|
|
1837
|
+
nodes: {},
|
|
1838
|
+
buffers: {},
|
|
1839
|
+
gpuStorage: {},
|
|
1840
|
+
textures: /* @__PURE__ */ new Map(),
|
|
1841
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1842
|
+
renderPipeline: null,
|
|
1843
|
+
passes: {},
|
|
1844
|
+
_hmrVersion: 0,
|
|
1845
|
+
_sizeImperative: false,
|
|
1846
|
+
_sizeProps: null,
|
|
1847
|
+
previousRoot: void 0,
|
|
1848
|
+
internal: {
|
|
1849
|
+
// Events
|
|
1850
|
+
interaction: [],
|
|
1851
|
+
subscribers: [],
|
|
1852
|
+
// Per-pointer state (new unified structure)
|
|
1853
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1854
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1855
|
+
lastEvent: React__namespace.createRef(),
|
|
1856
|
+
// Deprecated but kept for backwards compatibility
|
|
1857
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1858
|
+
initialClick: [0, 0],
|
|
1859
|
+
initialHits: [],
|
|
1860
|
+
capturedMap: /* @__PURE__ */ new Map(),
|
|
1861
|
+
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1862
|
+
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1863
|
+
// Occlusion system (WebGPU only)
|
|
1864
|
+
occlusionEnabled: false,
|
|
1865
|
+
occlusionObserver: null,
|
|
1866
|
+
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1867
|
+
helperGroup: null,
|
|
1868
|
+
// Updates
|
|
1869
|
+
active: false,
|
|
1870
|
+
frames: 0,
|
|
1871
|
+
priority: 0,
|
|
1872
|
+
subscribe: (ref, priority, store) => {
|
|
1873
|
+
const internal = get().internal;
|
|
1874
|
+
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1875
|
+
internal.subscribers.push({ ref, priority, store });
|
|
1876
|
+
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1877
|
+
return () => {
|
|
1878
|
+
const internal2 = get().internal;
|
|
1879
|
+
if (internal2?.subscribers) {
|
|
1880
|
+
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1881
|
+
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1884
|
+
},
|
|
1885
|
+
// Renderer Storage (single source of truth)
|
|
1886
|
+
actualRenderer: null,
|
|
1887
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1888
|
+
scheduler: null
|
|
1859
1889
|
}
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
const queue = [];
|
|
1863
|
-
for (const job of jobs) {
|
|
1864
|
-
if (inDegree.get(job.id) === 0) {
|
|
1865
|
-
queue.push(job);
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
queue.sort((a, b) => {
|
|
1869
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1870
|
-
return a.index - b.index;
|
|
1871
|
-
});
|
|
1872
|
-
const result = [];
|
|
1873
|
-
while (queue.length > 0) {
|
|
1874
|
-
const job = queue.shift();
|
|
1875
|
-
result.push(job);
|
|
1876
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1877
|
-
for (const neighborId of neighbors) {
|
|
1878
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1879
|
-
inDegree.set(neighborId, newDegree);
|
|
1880
|
-
if (newDegree === 0) {
|
|
1881
|
-
const neighbor = jobMap.get(neighborId);
|
|
1882
|
-
insertSorted(queue, neighbor);
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
if (result.length !== n) {
|
|
1887
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1888
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1889
|
-
for (const job of jobs) {
|
|
1890
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
return result;
|
|
1894
|
-
}
|
|
1895
|
-
function insertSorted(arr, job) {
|
|
1896
|
-
let i = 0;
|
|
1897
|
-
while (i < arr.length) {
|
|
1898
|
-
const cmp = arr[i];
|
|
1899
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1900
|
-
break;
|
|
1901
|
-
}
|
|
1902
|
-
i++;
|
|
1903
|
-
}
|
|
1904
|
-
arr.splice(i, 0, job);
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
function shouldRun(job, now) {
|
|
1908
|
-
if (!job.enabled) return false;
|
|
1909
|
-
if (!job.fps) return true;
|
|
1910
|
-
const minInterval = 1e3 / job.fps;
|
|
1911
|
-
const lastRun = job.lastRun ?? 0;
|
|
1912
|
-
const elapsed = now - lastRun;
|
|
1913
|
-
if (elapsed < minInterval - 1) return false;
|
|
1914
|
-
if (job.drop) {
|
|
1915
|
-
job.lastRun = now;
|
|
1916
|
-
} else {
|
|
1917
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1918
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1919
|
-
if (job.lastRun < now - minInterval) {
|
|
1920
|
-
job.lastRun = now;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
return true;
|
|
1924
|
-
}
|
|
1925
|
-
function resetJobTiming(job) {
|
|
1926
|
-
job.lastRun = void 0;
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
var __defProp$1 = Object.defineProperty;
|
|
1930
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1931
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1932
|
-
const hmrData = (() => {
|
|
1933
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1934
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1935
|
-
try {
|
|
1936
|
-
return (0, eval)("import.meta.hot");
|
|
1937
|
-
} catch {
|
|
1938
|
-
return void 0;
|
|
1939
|
-
}
|
|
1940
|
-
})();
|
|
1941
|
-
const _Scheduler = class _Scheduler {
|
|
1942
|
-
//* Constructor ================================
|
|
1943
|
-
constructor() {
|
|
1944
|
-
//* Critical State ================================
|
|
1945
|
-
__publicField$1(this, "roots", /* @__PURE__ */ new Map());
|
|
1946
|
-
__publicField$1(this, "phaseGraph");
|
|
1947
|
-
__publicField$1(this, "loopState", {
|
|
1948
|
-
running: false,
|
|
1949
|
-
rafHandle: null,
|
|
1950
|
-
lastTime: null,
|
|
1951
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1952
|
-
frameCount: 0,
|
|
1953
|
-
elapsedTime: 0,
|
|
1954
|
-
createdAt: performance.now()
|
|
1955
|
-
});
|
|
1956
|
-
__publicField$1(this, "stoppedTime", 0);
|
|
1957
|
-
//* Private State ================================
|
|
1958
|
-
__publicField$1(this, "nextRootIndex", 0);
|
|
1959
|
-
__publicField$1(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1960
|
-
__publicField$1(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1961
|
-
__publicField$1(this, "nextGlobalIndex", 0);
|
|
1962
|
-
__publicField$1(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1963
|
-
__publicField$1(this, "nextJobIndex", 0);
|
|
1964
|
-
__publicField$1(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1965
|
-
__publicField$1(this, "pendingFrames", 0);
|
|
1966
|
-
__publicField$1(this, "_frameloop", "always");
|
|
1967
|
-
//* Independent Mode & Error Handling State ================================
|
|
1968
|
-
__publicField$1(this, "_independent", false);
|
|
1969
|
-
__publicField$1(this, "errorHandler", null);
|
|
1970
|
-
__publicField$1(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1971
|
-
//* Core Loop Execution Methods ================================
|
|
1972
|
-
/**
|
|
1973
|
-
* Main RAF loop callback.
|
|
1974
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1975
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1976
|
-
* @returns {void}
|
|
1977
|
-
* @private
|
|
1978
|
-
*/
|
|
1979
|
-
__publicField$1(this, "loop", (timestamp) => {
|
|
1980
|
-
if (!this.loopState.running) return;
|
|
1981
|
-
this.executeFrame(timestamp);
|
|
1982
|
-
if (this._frameloop === "demand") {
|
|
1983
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1984
|
-
if (this.pendingFrames === 0) {
|
|
1985
|
-
this.notifyIdle(timestamp);
|
|
1986
|
-
return this.stop();
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1990
|
-
});
|
|
1991
|
-
this.phaseGraph = new PhaseGraph();
|
|
1992
|
-
}
|
|
1993
|
-
static get instance() {
|
|
1994
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1995
|
-
}
|
|
1996
|
-
static set instance(value) {
|
|
1997
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
2001
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
2002
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
2003
|
-
*/
|
|
2004
|
-
static get() {
|
|
2005
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
2006
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
2007
|
-
}
|
|
2008
|
-
if (!_Scheduler.instance) {
|
|
2009
|
-
_Scheduler.instance = new _Scheduler();
|
|
2010
|
-
if (hmrData?.data) {
|
|
2011
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
return _Scheduler.instance;
|
|
2015
|
-
}
|
|
2016
|
-
/**
|
|
2017
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
2018
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
2019
|
-
* @returns {void}
|
|
2020
|
-
*/
|
|
2021
|
-
static reset() {
|
|
2022
|
-
if (_Scheduler.instance) {
|
|
2023
|
-
_Scheduler.instance.stop();
|
|
2024
|
-
_Scheduler.instance = null;
|
|
2025
|
-
}
|
|
2026
|
-
if (hmrData?.data) {
|
|
2027
|
-
hmrData.data.scheduler = null;
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
//* Getters & Setters ================================
|
|
2031
|
-
get phases() {
|
|
2032
|
-
return this.phaseGraph.getOrderedPhases();
|
|
2033
|
-
}
|
|
2034
|
-
get frameloop() {
|
|
2035
|
-
return this._frameloop;
|
|
2036
|
-
}
|
|
2037
|
-
set frameloop(mode) {
|
|
2038
|
-
if (this._frameloop === mode) return;
|
|
2039
|
-
const wasAlways = this._frameloop === "always";
|
|
2040
|
-
this._frameloop = mode;
|
|
2041
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
2042
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
2043
|
-
}
|
|
2044
|
-
get isRunning() {
|
|
2045
|
-
return this.loopState.running;
|
|
2046
|
-
}
|
|
2047
|
-
get isReady() {
|
|
2048
|
-
return this.roots.size > 0;
|
|
2049
|
-
}
|
|
2050
|
-
get independent() {
|
|
2051
|
-
return this._independent;
|
|
2052
|
-
}
|
|
2053
|
-
set independent(value) {
|
|
2054
|
-
this._independent = value;
|
|
2055
|
-
if (value) this.ensureDefaultRoot();
|
|
2056
|
-
}
|
|
2057
|
-
//* Root Management Methods ================================
|
|
2058
|
-
/**
|
|
2059
|
-
* Register a root (Canvas) with the scheduler.
|
|
2060
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
2061
|
-
* @param {string} id - Unique identifier for this root
|
|
2062
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
2063
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
2064
|
-
*/
|
|
2065
|
-
registerRoot(id, options = {}) {
|
|
2066
|
-
if (this.roots.has(id)) {
|
|
2067
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
2068
|
-
return () => this.unregisterRoot(id);
|
|
2069
|
-
}
|
|
2070
|
-
const entry = {
|
|
2071
|
-
id,
|
|
2072
|
-
getState: options.getState ?? (() => ({})),
|
|
2073
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
2074
|
-
sortedJobs: [],
|
|
2075
|
-
needsRebuild: false
|
|
2076
|
-
};
|
|
2077
|
-
if (options.onError) {
|
|
2078
|
-
this.errorHandler = options.onError;
|
|
2079
|
-
}
|
|
2080
|
-
this.roots.set(id, entry);
|
|
2081
|
-
if (this.roots.size === 1) {
|
|
2082
|
-
this.notifyRootReady();
|
|
2083
|
-
if (this._frameloop === "always") this.start();
|
|
2084
|
-
}
|
|
2085
|
-
return () => this.unregisterRoot(id);
|
|
2086
|
-
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Unregister a root from the scheduler.
|
|
2089
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
2090
|
-
* The last root to unregister stops the RAF loop.
|
|
2091
|
-
* @param {string} id - The root ID to unregister
|
|
2092
|
-
* @returns {void}
|
|
2093
|
-
*/
|
|
2094
|
-
unregisterRoot(id) {
|
|
2095
|
-
const root = this.roots.get(id);
|
|
2096
|
-
if (!root) return;
|
|
2097
|
-
for (const jobId of root.jobs.keys()) {
|
|
2098
|
-
this.jobStateListeners.delete(jobId);
|
|
2099
|
-
}
|
|
2100
|
-
this.roots.delete(id);
|
|
2101
|
-
if (this.roots.size === 0) {
|
|
2102
|
-
this.stop();
|
|
2103
|
-
this.errorHandler = null;
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
/**
|
|
2107
|
-
* Subscribe to be notified when a root becomes available.
|
|
2108
|
-
* Fires immediately if a root already exists.
|
|
2109
|
-
* @param {() => void} callback - Function called when first root registers
|
|
2110
|
-
* @returns {() => void} Unsubscribe function
|
|
2111
|
-
*/
|
|
2112
|
-
onRootReady(callback) {
|
|
2113
|
-
if (this.roots.size > 0) {
|
|
2114
|
-
callback();
|
|
2115
|
-
return () => {
|
|
2116
|
-
};
|
|
2117
|
-
}
|
|
2118
|
-
this.rootReadyCallbacks.add(callback);
|
|
2119
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
2120
|
-
}
|
|
2121
|
-
/**
|
|
2122
|
-
* Notify all registered root-ready callbacks.
|
|
2123
|
-
* Called when the first root registers.
|
|
2124
|
-
* @returns {void}
|
|
2125
|
-
* @private
|
|
2126
|
-
*/
|
|
2127
|
-
notifyRootReady() {
|
|
2128
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
2129
|
-
try {
|
|
2130
|
-
cb();
|
|
2131
|
-
} catch (error) {
|
|
2132
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
this.rootReadyCallbacks.clear();
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* Ensure a default root exists for independent mode.
|
|
2139
|
-
* Creates a minimal root with no state provider.
|
|
2140
|
-
* @returns {void}
|
|
2141
|
-
* @private
|
|
2142
|
-
*/
|
|
2143
|
-
ensureDefaultRoot() {
|
|
2144
|
-
if (!this.roots.has("__default__")) {
|
|
2145
|
-
this.registerRoot("__default__");
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
/**
|
|
2149
|
-
* Trigger error handling for job errors.
|
|
2150
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
2151
|
-
* @param {Error} error - The error to handle
|
|
2152
|
-
* @returns {void}
|
|
2153
|
-
*/
|
|
2154
|
-
triggerError(error) {
|
|
2155
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
2156
|
-
else console.error("[Scheduler]", error);
|
|
2157
|
-
}
|
|
2158
|
-
//* Phase Management Methods ================================
|
|
2159
|
-
/**
|
|
2160
|
-
* Add a named phase to the scheduler's execution order.
|
|
2161
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
2162
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
2163
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
2164
|
-
* @returns {void}
|
|
2165
|
-
* @example
|
|
2166
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
2167
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
2168
|
-
*/
|
|
2169
|
-
addPhase(name, options) {
|
|
2170
|
-
this.phaseGraph.addPhase(name, options);
|
|
2171
|
-
for (const root of this.roots.values()) {
|
|
2172
|
-
root.needsRebuild = true;
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
/**
|
|
2176
|
-
* Check if a phase exists in the scheduler.
|
|
2177
|
-
* @param {string} name - The phase name to check
|
|
2178
|
-
* @returns {boolean} True if the phase exists
|
|
2179
|
-
*/
|
|
2180
|
-
hasPhase(name) {
|
|
2181
|
-
return this.phaseGraph.hasPhase(name);
|
|
2182
|
-
}
|
|
2183
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
2184
|
-
/**
|
|
2185
|
-
* Register a global job that runs once per frame (not per-root).
|
|
2186
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
2187
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
2188
|
-
* @param {string} id - Unique identifier for this global job
|
|
2189
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
2190
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
2191
|
-
* @deprecated Use useFrame with phases instead
|
|
2192
|
-
*/
|
|
2193
|
-
registerGlobal(phase, id, callback) {
|
|
2194
|
-
const job = { id, callback };
|
|
2195
|
-
if (phase === "before") {
|
|
2196
|
-
this.globalBeforeJobs.set(id, job);
|
|
2197
|
-
} else {
|
|
2198
|
-
this.globalAfterJobs.set(id, job);
|
|
2199
|
-
}
|
|
2200
|
-
return () => {
|
|
2201
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
2202
|
-
else this.globalAfterJobs.delete(id);
|
|
2203
|
-
};
|
|
2204
|
-
}
|
|
2205
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
2206
|
-
/**
|
|
2207
|
-
* Register an idle callback that fires when the loop stops.
|
|
2208
|
-
* Used internally by deprecated addTail API.
|
|
2209
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
2210
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
2211
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
2212
|
-
*/
|
|
2213
|
-
onIdle(callback) {
|
|
2214
|
-
this.idleCallbacks.add(callback);
|
|
2215
|
-
return () => this.idleCallbacks.delete(callback);
|
|
2216
|
-
}
|
|
2217
|
-
/**
|
|
2218
|
-
* Notify all registered idle callbacks.
|
|
2219
|
-
* Called when the loop stops in demand mode.
|
|
2220
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2221
|
-
* @returns {void}
|
|
2222
|
-
* @private
|
|
2223
|
-
*/
|
|
2224
|
-
notifyIdle(timestamp) {
|
|
2225
|
-
for (const cb of this.idleCallbacks) {
|
|
2226
|
-
try {
|
|
2227
|
-
cb(timestamp);
|
|
2228
|
-
} catch (error) {
|
|
2229
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
//* Job Registration & Management Methods ================================
|
|
2234
|
-
/**
|
|
2235
|
-
* Register a job (frame callback) with a specific root.
|
|
2236
|
-
* This is the core registration method used by useFrame internally.
|
|
2237
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2238
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2239
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2240
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2241
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2242
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2243
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2244
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2245
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2246
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2247
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2248
|
-
*/
|
|
2249
|
-
register(callback, options = {}) {
|
|
2250
|
-
const rootId = options.rootId;
|
|
2251
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2252
|
-
if (!root) {
|
|
2253
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2254
|
-
return () => {
|
|
2255
|
-
};
|
|
2256
|
-
}
|
|
2257
|
-
const id = options.id ?? this.generateJobId();
|
|
2258
|
-
let phase = options.phase ?? "update";
|
|
2259
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2260
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2261
|
-
}
|
|
2262
|
-
const before = this.normalizeConstraints(options.before);
|
|
2263
|
-
const after = this.normalizeConstraints(options.after);
|
|
2264
|
-
const job = {
|
|
2265
|
-
id,
|
|
2266
|
-
callback,
|
|
2267
|
-
phase,
|
|
2268
|
-
before,
|
|
2269
|
-
after,
|
|
2270
|
-
priority: options.priority ?? 0,
|
|
2271
|
-
index: this.nextJobIndex++,
|
|
2272
|
-
fps: options.fps,
|
|
2273
|
-
drop: options.drop ?? true,
|
|
2274
|
-
enabled: options.enabled ?? true,
|
|
2275
|
-
system: options.system ?? false
|
|
2276
|
-
};
|
|
2277
|
-
if (root.jobs.has(id)) {
|
|
2278
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2279
|
-
}
|
|
2280
|
-
root.jobs.set(id, job);
|
|
2281
|
-
root.needsRebuild = true;
|
|
2282
|
-
return () => this.unregister(id, root.id);
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Unregister a job by its ID.
|
|
2286
|
-
* Searches all roots if rootId is not provided.
|
|
2287
|
-
* @param {string} id - The job ID to unregister
|
|
2288
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2289
|
-
* @returns {void}
|
|
2290
|
-
*/
|
|
2291
|
-
unregister(id, rootId) {
|
|
2292
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2293
|
-
if (root?.jobs.delete(id)) {
|
|
2294
|
-
root.needsRebuild = true;
|
|
2295
|
-
this.jobStateListeners.delete(id);
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
/**
|
|
2299
|
-
* Update a job's options dynamically.
|
|
2300
|
-
* Searches all roots to find the job by ID.
|
|
2301
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2302
|
-
* @param {string} id - The job ID to update
|
|
2303
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2304
|
-
* @returns {void}
|
|
2305
|
-
*/
|
|
2306
|
-
updateJob(id, options) {
|
|
2307
|
-
let job;
|
|
2308
|
-
let root;
|
|
2309
|
-
for (const r of this.roots.values()) {
|
|
2310
|
-
job = r.jobs.get(id);
|
|
2311
|
-
if (job) {
|
|
2312
|
-
root = r;
|
|
2313
|
-
break;
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2316
|
-
if (!job || !root) return;
|
|
2317
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2318
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2319
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2320
|
-
if (options.enabled !== void 0) {
|
|
2321
|
-
const wasEnabled = job.enabled;
|
|
2322
|
-
job.enabled = options.enabled;
|
|
2323
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2324
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2325
|
-
}
|
|
2326
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2327
|
-
if (options.phase) job.phase = options.phase;
|
|
2328
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2329
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2330
|
-
root.needsRebuild = true;
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
//* Job State Management Methods ================================
|
|
2334
|
-
/**
|
|
2335
|
-
* Check if a job is currently paused (disabled).
|
|
2336
|
-
* @param {string} id - The job ID to check
|
|
2337
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2338
|
-
*/
|
|
2339
|
-
isJobPaused(id) {
|
|
2340
|
-
for (const root of this.roots.values()) {
|
|
2341
|
-
const job = root.jobs.get(id);
|
|
2342
|
-
if (job) return !job.enabled;
|
|
2343
|
-
}
|
|
2344
|
-
return false;
|
|
2345
|
-
}
|
|
2346
|
-
/**
|
|
2347
|
-
* Subscribe to state changes for a specific job.
|
|
2348
|
-
* Listener is called when job is paused or resumed.
|
|
2349
|
-
* @param {string} id - The job ID to subscribe to
|
|
2350
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2351
|
-
* @returns {() => void} Unsubscribe function
|
|
2352
|
-
*/
|
|
2353
|
-
subscribeJobState(id, listener) {
|
|
2354
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2355
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2356
|
-
}
|
|
2357
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2358
|
-
return () => {
|
|
2359
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2360
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2361
|
-
this.jobStateListeners.delete(id);
|
|
2362
|
-
}
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2365
|
-
/**
|
|
2366
|
-
* Notify all listeners that a job's state has changed.
|
|
2367
|
-
* @param {string} id - The job ID that changed
|
|
2368
|
-
* @returns {void}
|
|
2369
|
-
* @private
|
|
2370
|
-
*/
|
|
2371
|
-
notifyJobStateChange(id) {
|
|
2372
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2373
|
-
}
|
|
2374
|
-
/**
|
|
2375
|
-
* Pause a job by ID (sets enabled=false).
|
|
2376
|
-
* Notifies any subscribed state listeners.
|
|
2377
|
-
* @param {string} id - The job ID to pause
|
|
2378
|
-
* @returns {void}
|
|
2379
|
-
*/
|
|
2380
|
-
pauseJob(id) {
|
|
2381
|
-
this.updateJob(id, { enabled: false });
|
|
2382
|
-
this.notifyJobStateChange(id);
|
|
2383
|
-
}
|
|
2384
|
-
/**
|
|
2385
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2386
|
-
* Resets job timing to prevent frame accumulation.
|
|
2387
|
-
* Notifies any subscribed state listeners.
|
|
2388
|
-
* @param {string} id - The job ID to resume
|
|
2389
|
-
* @returns {void}
|
|
2390
|
-
*/
|
|
2391
|
-
resumeJob(id) {
|
|
2392
|
-
this.updateJob(id, { enabled: true });
|
|
2393
|
-
this.notifyJobStateChange(id);
|
|
2394
|
-
}
|
|
2395
|
-
//* Frame Loop Control Methods ================================
|
|
2396
|
-
/**
|
|
2397
|
-
* Start the requestAnimationFrame loop.
|
|
2398
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2399
|
-
* No-op if already running.
|
|
2400
|
-
* @returns {void}
|
|
2401
|
-
*/
|
|
2402
|
-
start() {
|
|
2403
|
-
if (this.loopState.running) return;
|
|
2404
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2405
|
-
let adjustedCreated = 0;
|
|
2406
|
-
if (this.stoppedTime > 0) {
|
|
2407
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2408
|
-
this.stoppedTime = 0;
|
|
2409
|
-
}
|
|
2410
|
-
Object.assign(this.loopState, {
|
|
2411
|
-
running: true,
|
|
2412
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2413
|
-
lastTime: performance.now(),
|
|
2414
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2415
|
-
frameCount: 0,
|
|
2416
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2417
|
-
});
|
|
2418
|
-
}
|
|
2419
|
-
/**
|
|
2420
|
-
* Stop the requestAnimationFrame loop.
|
|
2421
|
-
* Cancels any pending RAF callback.
|
|
2422
|
-
* No-op if not running.
|
|
2423
|
-
* @returns {void}
|
|
2424
|
-
*/
|
|
2425
|
-
stop() {
|
|
2426
|
-
if (!this.loopState.running) return;
|
|
2427
|
-
this.loopState.running = false;
|
|
2428
|
-
if (this.loopState.rafHandle !== null) {
|
|
2429
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2430
|
-
this.loopState.rafHandle = null;
|
|
2431
|
-
}
|
|
2432
|
-
this.stoppedTime = performance.now();
|
|
2433
|
-
}
|
|
2434
|
-
/**
|
|
2435
|
-
* Request frames to be rendered in demand mode.
|
|
2436
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2437
|
-
* No-op if frameloop is not 'demand'.
|
|
2438
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2439
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2440
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2441
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2442
|
-
* @returns {void}
|
|
2443
|
-
* @example
|
|
2444
|
-
* // Request a single frame render
|
|
2445
|
-
* scheduler.invalidate();
|
|
2446
|
-
*
|
|
2447
|
-
* @example
|
|
2448
|
-
* // Request 5 frames (e.g., for animations)
|
|
2449
|
-
* scheduler.invalidate(5);
|
|
2450
|
-
*
|
|
2451
|
-
* @example
|
|
2452
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2453
|
-
* scheduler.invalidate(3, false);
|
|
2454
|
-
*
|
|
2455
|
-
* @example
|
|
2456
|
-
* // Add 2 more frames to existing pending count
|
|
2457
|
-
* scheduler.invalidate(2, true);
|
|
2458
|
-
*/
|
|
2459
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2460
|
-
if (this._frameloop !== "demand") return;
|
|
2461
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2462
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2463
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2464
|
-
}
|
|
2465
|
-
/**
|
|
2466
|
-
* Reset timing state for deterministic testing.
|
|
2467
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2468
|
-
* @returns {void}
|
|
2469
|
-
*/
|
|
2470
|
-
resetTiming() {
|
|
2471
|
-
this.loopState.lastTime = null;
|
|
2472
|
-
this.loopState.frameCount = 0;
|
|
2473
|
-
this.loopState.elapsedTime = 0;
|
|
2474
|
-
this.loopState.createdAt = performance.now();
|
|
2475
|
-
}
|
|
2476
|
-
//* Manual Stepping Methods ================================
|
|
2477
|
-
/**
|
|
2478
|
-
* Manually execute a single frame for all roots.
|
|
2479
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2480
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2481
|
-
* @returns {void}
|
|
2482
|
-
* @example
|
|
2483
|
-
* // Manual control mode
|
|
2484
|
-
* scheduler.frameloop = 'never';
|
|
2485
|
-
* scheduler.step(); // Execute one frame
|
|
2486
|
-
*/
|
|
2487
|
-
step(timestamp) {
|
|
2488
|
-
const now = timestamp ?? performance.now();
|
|
2489
|
-
this.executeFrame(now);
|
|
2490
|
-
}
|
|
2491
|
-
/**
|
|
2492
|
-
* Manually execute a single job by its ID.
|
|
2493
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2494
|
-
* @param {string} id - The job ID to step
|
|
2495
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2496
|
-
* @returns {void}
|
|
2497
|
-
*/
|
|
2498
|
-
stepJob(id, timestamp) {
|
|
2499
|
-
let job;
|
|
2500
|
-
let root;
|
|
2501
|
-
for (const r of this.roots.values()) {
|
|
2502
|
-
job = r.jobs.get(id);
|
|
2503
|
-
if (job) {
|
|
2504
|
-
root = r;
|
|
2505
|
-
break;
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
if (!job || !root) {
|
|
2509
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2510
|
-
return;
|
|
2511
|
-
}
|
|
2512
|
-
const now = timestamp ?? performance.now();
|
|
2513
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2514
|
-
const delta = deltaMs / 1e3;
|
|
2515
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2516
|
-
const providedState = root.getState?.() ?? {};
|
|
2517
|
-
const frameState = {
|
|
2518
|
-
...providedState,
|
|
2519
|
-
time: now,
|
|
2520
|
-
delta,
|
|
2521
|
-
elapsed,
|
|
2522
|
-
frame: this.loopState.frameCount
|
|
2523
|
-
};
|
|
2524
|
-
try {
|
|
2525
|
-
job.callback(frameState, delta);
|
|
2526
|
-
} catch (error) {
|
|
2527
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2528
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
/**
|
|
2532
|
-
* Execute a single frame across all roots.
|
|
2533
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2534
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2535
|
-
* @returns {void}
|
|
2536
|
-
* @private
|
|
2537
|
-
*/
|
|
2538
|
-
executeFrame(timestamp) {
|
|
2539
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2540
|
-
const delta = deltaMs / 1e3;
|
|
2541
|
-
this.loopState.lastTime = timestamp;
|
|
2542
|
-
this.loopState.frameCount++;
|
|
2543
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2544
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2545
|
-
for (const root of this.roots.values()) {
|
|
2546
|
-
this.tickRoot(root, timestamp, delta);
|
|
2547
|
-
}
|
|
2548
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2549
|
-
}
|
|
2550
|
-
/**
|
|
2551
|
-
* Run all global jobs from a job map.
|
|
2552
|
-
* Catches and logs errors without stopping execution.
|
|
2553
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2554
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2555
|
-
* @returns {void}
|
|
2556
|
-
* @private
|
|
2557
|
-
*/
|
|
2558
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2559
|
-
for (const job of jobs.values()) {
|
|
2560
|
-
try {
|
|
2561
|
-
job.callback(timestamp);
|
|
2562
|
-
} catch (error) {
|
|
2563
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
/**
|
|
2568
|
-
* Execute all jobs for a single root in sorted order.
|
|
2569
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2570
|
-
* Errors are caught and propagated via triggerError.
|
|
2571
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2572
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2573
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2574
|
-
* @returns {void}
|
|
2575
|
-
* @private
|
|
2576
|
-
*/
|
|
2577
|
-
tickRoot(root, timestamp, delta) {
|
|
2578
|
-
if (root.needsRebuild) {
|
|
2579
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2580
|
-
root.needsRebuild = false;
|
|
2581
|
-
}
|
|
2582
|
-
const providedState = root.getState?.() ?? {};
|
|
2583
|
-
const frameState = {
|
|
2584
|
-
...providedState,
|
|
2585
|
-
time: timestamp,
|
|
2586
|
-
delta,
|
|
2587
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2588
|
-
// Convert ms to seconds
|
|
2589
|
-
frame: this.loopState.frameCount
|
|
2590
|
-
};
|
|
2591
|
-
for (const job of root.sortedJobs) {
|
|
2592
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2593
|
-
try {
|
|
2594
|
-
job.callback(frameState, delta);
|
|
2595
|
-
} catch (error) {
|
|
2596
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2597
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
//* Debug & Inspection Methods ================================
|
|
2602
|
-
/**
|
|
2603
|
-
* Get the total number of registered jobs across all roots.
|
|
2604
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2605
|
-
* @returns {number} Total job count
|
|
2606
|
-
*/
|
|
2607
|
-
getJobCount() {
|
|
2608
|
-
let count = 0;
|
|
2609
|
-
for (const root of this.roots.values()) {
|
|
2610
|
-
count += root.jobs.size;
|
|
2611
|
-
}
|
|
2612
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2613
|
-
}
|
|
2614
|
-
/**
|
|
2615
|
-
* Get all registered job IDs across all roots.
|
|
2616
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2617
|
-
* @returns {string[]} Array of all job IDs
|
|
2618
|
-
*/
|
|
2619
|
-
getJobIds() {
|
|
2620
|
-
const ids = [];
|
|
2621
|
-
for (const root of this.roots.values()) {
|
|
2622
|
-
ids.push(...root.jobs.keys());
|
|
2623
|
-
}
|
|
2624
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2625
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2626
|
-
return ids;
|
|
2627
|
-
}
|
|
2628
|
-
/**
|
|
2629
|
-
* Get the number of registered roots (Canvas instances).
|
|
2630
|
-
* @returns {number} Number of registered roots
|
|
2631
|
-
*/
|
|
2632
|
-
getRootCount() {
|
|
2633
|
-
return this.roots.size;
|
|
2634
|
-
}
|
|
2635
|
-
/**
|
|
2636
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2637
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2638
|
-
*
|
|
2639
|
-
* @param phase The phase to check
|
|
2640
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2641
|
-
* @returns true if any user jobs exist in the phase
|
|
2642
|
-
*/
|
|
2643
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2644
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2645
|
-
return rootsToCheck.some((root) => {
|
|
2646
|
-
if (!root) return false;
|
|
2647
|
-
for (const job of root.jobs.values()) {
|
|
2648
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2649
|
-
}
|
|
2650
|
-
return false;
|
|
2651
|
-
});
|
|
2652
|
-
}
|
|
2653
|
-
//* Utility Methods ================================
|
|
2654
|
-
/**
|
|
2655
|
-
* Generate a unique root ID for automatic root registration.
|
|
2656
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2657
|
-
*/
|
|
2658
|
-
generateRootId() {
|
|
2659
|
-
return `root_${this.nextRootIndex++}`;
|
|
2660
|
-
}
|
|
2661
|
-
/**
|
|
2662
|
-
* Generate a unique job ID.
|
|
2663
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2664
|
-
* @private
|
|
2665
|
-
*/
|
|
2666
|
-
generateJobId() {
|
|
2667
|
-
return `job_${this.nextJobIndex}`;
|
|
2668
|
-
}
|
|
2669
|
-
/**
|
|
2670
|
-
* Normalize before/after constraints to a Set.
|
|
2671
|
-
* Handles undefined, single string, or array inputs.
|
|
2672
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2673
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2674
|
-
* @private
|
|
2675
|
-
*/
|
|
2676
|
-
normalizeConstraints(value) {
|
|
2677
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2678
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2679
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2683
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2684
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2685
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2686
|
-
__publicField$1(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2687
|
-
let Scheduler = _Scheduler;
|
|
2688
|
-
const getScheduler = () => Scheduler.get();
|
|
2689
|
-
if (hmrData) {
|
|
2690
|
-
hmrData.accept?.();
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
2694
|
-
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
2695
|
-
const createStore = (invalidate, advance) => {
|
|
2696
|
-
const rootStore = traditional.createWithEqualityFn((set, get) => {
|
|
2697
|
-
const position = new webgpu.Vector3();
|
|
2698
|
-
const defaultTarget = new webgpu.Vector3();
|
|
2699
|
-
const tempTarget = new webgpu.Vector3();
|
|
2700
|
-
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
2701
|
-
const { width, height, top, left } = size;
|
|
2702
|
-
const aspect = width / height;
|
|
2703
|
-
if (target.isVector3) tempTarget.copy(target);
|
|
2704
|
-
else tempTarget.set(...target);
|
|
2705
|
-
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
2706
|
-
if (isOrthographicCamera(camera)) {
|
|
2707
|
-
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
2708
|
-
} else {
|
|
2709
|
-
const fov = camera.fov * Math.PI / 180;
|
|
2710
|
-
const h = 2 * Math.tan(fov / 2) * distance;
|
|
2711
|
-
const w = h * (width / height);
|
|
2712
|
-
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
let performanceTimeout = void 0;
|
|
2716
|
-
const setPerformanceCurrent = (current) => set((state2) => ({ performance: { ...state2.performance, current } }));
|
|
2717
|
-
const pointer = new webgpu.Vector2();
|
|
2718
|
-
const rootState = {
|
|
2719
|
-
set,
|
|
2720
|
-
get,
|
|
2721
|
-
// Mock objects that have to be configured
|
|
2722
|
-
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
2723
|
-
primaryStore: null,
|
|
2724
|
-
gl: null,
|
|
2725
|
-
renderer: null,
|
|
2726
|
-
camera: null,
|
|
2727
|
-
frustum: new webgpu.Frustum(),
|
|
2728
|
-
autoUpdateFrustum: true,
|
|
2729
|
-
raycaster: null,
|
|
2730
|
-
events: {
|
|
2731
|
-
priority: 1,
|
|
2732
|
-
enabled: true,
|
|
2733
|
-
connected: false,
|
|
2734
|
-
frameTimedRaycasts: true,
|
|
2735
|
-
alwaysFireOnScroll: true,
|
|
2736
|
-
updateOnFrame: false
|
|
2737
|
-
},
|
|
2738
|
-
scene: null,
|
|
2739
|
-
rootScene: null,
|
|
2740
|
-
xr: null,
|
|
2741
|
-
inspector: null,
|
|
2742
|
-
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
2743
|
-
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
2744
|
-
textureColorSpace: webgpu.SRGBColorSpace,
|
|
2745
|
-
isLegacy: false,
|
|
2746
|
-
webGPUSupported: false,
|
|
2747
|
-
isNative: false,
|
|
2748
|
-
controls: null,
|
|
2749
|
-
pointer,
|
|
2750
|
-
mouse: pointer,
|
|
2751
|
-
frameloop: "always",
|
|
2752
|
-
onPointerMissed: void 0,
|
|
2753
|
-
onDragOverMissed: void 0,
|
|
2754
|
-
onDropMissed: void 0,
|
|
2755
|
-
performance: {
|
|
2756
|
-
current: 1,
|
|
2757
|
-
min: 0.5,
|
|
2758
|
-
max: 1,
|
|
2759
|
-
debounce: 200,
|
|
2760
|
-
regress: () => {
|
|
2761
|
-
const state2 = get();
|
|
2762
|
-
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
2763
|
-
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
2764
|
-
performanceTimeout = setTimeout(
|
|
2765
|
-
() => setPerformanceCurrent(get().performance.max),
|
|
2766
|
-
state2.performance.debounce
|
|
2767
|
-
);
|
|
2768
|
-
}
|
|
2769
|
-
},
|
|
2770
|
-
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
2771
|
-
viewport: {
|
|
2772
|
-
initialDpr: 0,
|
|
2773
|
-
dpr: 0,
|
|
2774
|
-
width: 0,
|
|
2775
|
-
height: 0,
|
|
2776
|
-
top: 0,
|
|
2777
|
-
left: 0,
|
|
2778
|
-
aspect: 0,
|
|
2779
|
-
distance: 0,
|
|
2780
|
-
factor: 0,
|
|
2781
|
-
getCurrentViewport
|
|
2782
|
-
},
|
|
2783
|
-
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
2784
|
-
setSize: (width, height, top, left) => {
|
|
2785
|
-
const state2 = get();
|
|
2786
|
-
if (width === void 0) {
|
|
2787
|
-
set({ _sizeImperative: false });
|
|
2788
|
-
if (state2._sizeProps) {
|
|
2789
|
-
const { width: propW, height: propH } = state2._sizeProps;
|
|
2790
|
-
if (propW !== void 0 || propH !== void 0) {
|
|
2791
|
-
const currentSize = state2.size;
|
|
2792
|
-
const newSize = {
|
|
2793
|
-
width: propW ?? currentSize.width,
|
|
2794
|
-
height: propH ?? currentSize.height,
|
|
2795
|
-
top: currentSize.top,
|
|
2796
|
-
left: currentSize.left
|
|
2797
|
-
};
|
|
2798
|
-
set((s) => ({
|
|
2799
|
-
size: newSize,
|
|
2800
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2801
|
-
}));
|
|
2802
|
-
getScheduler().invalidate();
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
return;
|
|
2806
|
-
}
|
|
2807
|
-
const w = width;
|
|
2808
|
-
const h = height ?? width;
|
|
2809
|
-
const t = top ?? state2.size.top;
|
|
2810
|
-
const l = left ?? state2.size.left;
|
|
2811
|
-
const size = { width: w, height: h, top: t, left: l };
|
|
2812
|
-
set((s) => ({
|
|
2813
|
-
size,
|
|
2814
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2815
|
-
_sizeImperative: true
|
|
2816
|
-
}));
|
|
2817
|
-
getScheduler().invalidate();
|
|
2818
|
-
},
|
|
2819
|
-
setDpr: (dpr) => set((state2) => {
|
|
2820
|
-
const resolved = calculateDpr(dpr);
|
|
2821
|
-
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
2822
|
-
}),
|
|
2823
|
-
setFrameloop: (frameloop = "always") => {
|
|
2824
|
-
set(() => ({ frameloop }));
|
|
2825
|
-
},
|
|
2826
|
-
setError: (error) => set(() => ({ error })),
|
|
2827
|
-
error: null,
|
|
2828
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2829
|
-
uniforms: {},
|
|
2830
|
-
nodes: {},
|
|
2831
|
-
buffers: {},
|
|
2832
|
-
gpuStorage: {},
|
|
2833
|
-
textures: /* @__PURE__ */ new Map(),
|
|
2834
|
-
renderPipeline: null,
|
|
2835
|
-
passes: {},
|
|
2836
|
-
_hmrVersion: 0,
|
|
2837
|
-
_sizeImperative: false,
|
|
2838
|
-
_sizeProps: null,
|
|
2839
|
-
previousRoot: void 0,
|
|
2840
|
-
internal: {
|
|
2841
|
-
// Events
|
|
2842
|
-
interaction: [],
|
|
2843
|
-
subscribers: [],
|
|
2844
|
-
// Per-pointer state (new unified structure)
|
|
2845
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
2846
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
2847
|
-
lastEvent: React__namespace.createRef(),
|
|
2848
|
-
// Deprecated but kept for backwards compatibility
|
|
2849
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2850
|
-
initialClick: [0, 0],
|
|
2851
|
-
initialHits: [],
|
|
2852
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
2853
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2854
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2855
|
-
// Occlusion system (WebGPU only)
|
|
2856
|
-
occlusionEnabled: false,
|
|
2857
|
-
occlusionObserver: null,
|
|
2858
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
2859
|
-
helperGroup: null,
|
|
2860
|
-
// Updates
|
|
2861
|
-
active: false,
|
|
2862
|
-
frames: 0,
|
|
2863
|
-
priority: 0,
|
|
2864
|
-
subscribe: (ref, priority, store) => {
|
|
2865
|
-
const internal = get().internal;
|
|
2866
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
2867
|
-
internal.subscribers.push({ ref, priority, store });
|
|
2868
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
2869
|
-
return () => {
|
|
2870
|
-
const internal2 = get().internal;
|
|
2871
|
-
if (internal2?.subscribers) {
|
|
2872
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
2873
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
2874
|
-
}
|
|
2875
|
-
};
|
|
2876
|
-
},
|
|
2877
|
-
// Renderer Storage (single source of truth)
|
|
2878
|
-
actualRenderer: null,
|
|
2879
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
2880
|
-
scheduler: null
|
|
2881
|
-
}
|
|
2882
|
-
};
|
|
2883
|
-
return rootState;
|
|
1890
|
+
};
|
|
1891
|
+
return rootState;
|
|
2884
1892
|
});
|
|
2885
1893
|
const state = rootStore.getState();
|
|
2886
1894
|
Object.defineProperty(state, "gl", {
|
|
@@ -2888,8 +1896,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2888
1896
|
const currentState = rootStore.getState();
|
|
2889
1897
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2890
1898
|
const stack = new Error().stack || "";
|
|
2891
|
-
|
|
2892
|
-
if (!isInternalAccess) {
|
|
1899
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2893
1900
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2894
1901
|
notifyDepreciated({
|
|
2895
1902
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -3002,26 +2009,32 @@ function loadingFn(extensions, onProgress) {
|
|
|
3002
2009
|
);
|
|
3003
2010
|
};
|
|
3004
2011
|
}
|
|
3005
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
3006
|
-
const
|
|
2012
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2013
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2014
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
3007
2015
|
const fn = loadingFn(extensions, onProgress);
|
|
3008
|
-
const results =
|
|
2016
|
+
const results = cacheKeys.map(
|
|
2017
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2018
|
+
);
|
|
3009
2019
|
return Array.isArray(input) ? results : results[0];
|
|
3010
2020
|
}
|
|
3011
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
3012
|
-
const
|
|
3013
|
-
|
|
2021
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2022
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2023
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2024
|
+
cacheKeys.forEach(
|
|
2025
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2026
|
+
);
|
|
3014
2027
|
};
|
|
3015
|
-
useLoader.clear = function(loader, input) {
|
|
3016
|
-
const
|
|
3017
|
-
|
|
2028
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2029
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2030
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
3018
2031
|
};
|
|
3019
2032
|
useLoader.loader = getLoader;
|
|
3020
2033
|
|
|
3021
2034
|
function useFrame(callback, priorityOrOptions) {
|
|
3022
2035
|
const store = React__namespace.useContext(context);
|
|
3023
2036
|
const isInsideCanvas = store !== null;
|
|
3024
|
-
const scheduler = getScheduler();
|
|
2037
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
3025
2038
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
3026
2039
|
id: priorityOrOptions.id,
|
|
3027
2040
|
phase: priorityOrOptions.phase,
|
|
@@ -3069,7 +2082,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3069
2082
|
};
|
|
3070
2083
|
callbackRef.current?.(mergedState, delta);
|
|
3071
2084
|
};
|
|
3072
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2085
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
3073
2086
|
id,
|
|
3074
2087
|
rootId,
|
|
3075
2088
|
...options
|
|
@@ -3090,37 +2103,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3090
2103
|
}
|
|
3091
2104
|
};
|
|
3092
2105
|
} else {
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
unregisterJob = registerOutside();
|
|
3102
|
-
});
|
|
3103
|
-
return () => {
|
|
3104
|
-
unsubReady();
|
|
3105
|
-
unregisterJob?.();
|
|
3106
|
-
};
|
|
2106
|
+
return scheduler$1.register(
|
|
2107
|
+
(state, delta) => {
|
|
2108
|
+
const frameState = state;
|
|
2109
|
+
if (!frameState.renderer) return;
|
|
2110
|
+
callbackRef.current?.(frameState, delta);
|
|
2111
|
+
},
|
|
2112
|
+
{ id, ...options }
|
|
2113
|
+
);
|
|
3107
2114
|
}
|
|
3108
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2115
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
3109
2116
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
3110
2117
|
// Subscribe function
|
|
3111
2118
|
React__namespace.useCallback(
|
|
3112
2119
|
(onStoreChange) => {
|
|
3113
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2120
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
3114
2121
|
},
|
|
3115
2122
|
[id]
|
|
3116
2123
|
),
|
|
3117
2124
|
// getSnapshot function
|
|
3118
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2125
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
3119
2126
|
// getServerSnapshot function (SSR)
|
|
3120
2127
|
React__namespace.useCallback(() => false, [])
|
|
3121
2128
|
);
|
|
3122
2129
|
const controls = React__namespace.useMemo(() => {
|
|
3123
|
-
const scheduler2 = getScheduler();
|
|
2130
|
+
const scheduler2 = scheduler.getScheduler();
|
|
3124
2131
|
return {
|
|
3125
2132
|
/** The job's unique ID */
|
|
3126
2133
|
id,
|
|
@@ -3135,7 +2142,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3135
2142
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3136
2143
|
*/
|
|
3137
2144
|
step: (timestamp) => {
|
|
3138
|
-
getScheduler().stepJob(id, timestamp);
|
|
2145
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
3139
2146
|
},
|
|
3140
2147
|
/**
|
|
3141
2148
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -3143,20 +2150,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3143
2150
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3144
2151
|
*/
|
|
3145
2152
|
stepAll: (timestamp) => {
|
|
3146
|
-
getScheduler().step(timestamp);
|
|
2153
|
+
scheduler.getScheduler().step(timestamp);
|
|
3147
2154
|
},
|
|
3148
2155
|
/**
|
|
3149
2156
|
* Pause this job (set enabled=false).
|
|
3150
2157
|
* Job remains registered but won't run.
|
|
3151
2158
|
*/
|
|
3152
2159
|
pause: () => {
|
|
3153
|
-
getScheduler().pauseJob(id);
|
|
2160
|
+
scheduler.getScheduler().pauseJob(id);
|
|
3154
2161
|
},
|
|
3155
2162
|
/**
|
|
3156
2163
|
* Resume this job (set enabled=true).
|
|
3157
2164
|
*/
|
|
3158
2165
|
resume: () => {
|
|
3159
|
-
getScheduler().resumeJob(id);
|
|
2166
|
+
scheduler.getScheduler().resumeJob(id);
|
|
3160
2167
|
},
|
|
3161
2168
|
/**
|
|
3162
2169
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -3194,18 +2201,18 @@ function buildFromCache(input, textureCache) {
|
|
|
3194
2201
|
function useTexture(input, optionsOrOnLoad) {
|
|
3195
2202
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
3196
2203
|
const store = useStore();
|
|
3197
|
-
const textureCache = useThree((state) => state.textures);
|
|
3198
2204
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
3199
|
-
const { onLoad, cache =
|
|
2205
|
+
const { onLoad, cache = true } = options;
|
|
3200
2206
|
const onLoadRef = React.useRef(onLoad);
|
|
3201
2207
|
onLoadRef.current = onLoad;
|
|
3202
2208
|
const onLoadCalledForRef = React.useRef(null);
|
|
3203
2209
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
3204
2210
|
const cachedResult = React.useMemo(() => {
|
|
3205
2211
|
if (!cache) return null;
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
2212
|
+
const textures = store.getState().textures;
|
|
2213
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2214
|
+
return buildFromCache(input, textures);
|
|
2215
|
+
}, [cache, urls, input, store]);
|
|
3209
2216
|
const loadedTextures = useLoader(
|
|
3210
2217
|
webgpu.TextureLoader,
|
|
3211
2218
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3249,8 +2256,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3249
2256
|
}, [input, loadedTextures, cachedResult]);
|
|
3250
2257
|
React.useEffect(() => {
|
|
3251
2258
|
if (!cache) return;
|
|
3252
|
-
if (cachedResult) return;
|
|
3253
|
-
const set = store.setState;
|
|
3254
2259
|
const urlTextureMap = [];
|
|
3255
2260
|
if (typeof input === "string") {
|
|
3256
2261
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3264,18 +2269,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3264
2269
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3265
2270
|
}
|
|
3266
2271
|
}
|
|
3267
|
-
|
|
3268
|
-
const
|
|
3269
|
-
let
|
|
2272
|
+
store.setState((state) => {
|
|
2273
|
+
const refs = new Map(state._textureRefs);
|
|
2274
|
+
let textures = state.textures;
|
|
2275
|
+
let added = false;
|
|
3270
2276
|
for (const [url, texture] of urlTextureMap) {
|
|
3271
|
-
if (!
|
|
3272
|
-
|
|
3273
|
-
|
|
2277
|
+
if (!textures.has(url)) {
|
|
2278
|
+
if (!added) {
|
|
2279
|
+
textures = new Map(textures);
|
|
2280
|
+
added = true;
|
|
2281
|
+
}
|
|
2282
|
+
textures.set(url, texture);
|
|
3274
2283
|
}
|
|
2284
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3275
2285
|
}
|
|
3276
|
-
return
|
|
2286
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
3277
2287
|
});
|
|
3278
|
-
|
|
2288
|
+
return () => store.setState((state) => {
|
|
2289
|
+
const refs = new Map(state._textureRefs);
|
|
2290
|
+
for (const [url] of urlTextureMap) {
|
|
2291
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2292
|
+
if (next <= 0) refs.delete(url);
|
|
2293
|
+
else refs.set(url, next);
|
|
2294
|
+
}
|
|
2295
|
+
return { _textureRefs: refs };
|
|
2296
|
+
});
|
|
2297
|
+
}, [cache, input, mappedTextures, store]);
|
|
3279
2298
|
return mappedTextures;
|
|
3280
2299
|
}
|
|
3281
2300
|
useTexture.preload = (url) => useLoader.preload(webgpu.TextureLoader, url);
|
|
@@ -3291,96 +2310,63 @@ const Texture = ({
|
|
|
3291
2310
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
3292
2311
|
};
|
|
3293
2312
|
|
|
3294
|
-
function
|
|
3295
|
-
if (entry instanceof webgpu.Texture) return entry;
|
|
3296
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof webgpu.Texture) {
|
|
3297
|
-
return entry.value;
|
|
3298
|
-
}
|
|
3299
|
-
return null;
|
|
3300
|
-
}
|
|
3301
|
-
function useTextures() {
|
|
2313
|
+
function useTextures(selector) {
|
|
3302
2314
|
const store = useStore();
|
|
3303
|
-
|
|
3304
|
-
const set = store.setState;
|
|
2315
|
+
const registry = React.useMemo(() => {
|
|
3305
2316
|
const getState = store.getState;
|
|
3306
|
-
const
|
|
3307
|
-
|
|
3308
|
-
const newMap = new Map(state.textures);
|
|
3309
|
-
newMap.set(key, value);
|
|
3310
|
-
return { textures: newMap };
|
|
3311
|
-
});
|
|
3312
|
-
};
|
|
3313
|
-
const addMultiple = (items) => {
|
|
3314
|
-
set((state) => {
|
|
3315
|
-
const newMap = new Map(state.textures);
|
|
3316
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3317
|
-
for (const [key, value] of entries) {
|
|
3318
|
-
newMap.set(key, value);
|
|
3319
|
-
}
|
|
3320
|
-
return { textures: newMap };
|
|
3321
|
-
});
|
|
3322
|
-
};
|
|
3323
|
-
const remove = (key) => {
|
|
3324
|
-
set((state) => {
|
|
3325
|
-
const newMap = new Map(state.textures);
|
|
3326
|
-
newMap.delete(key);
|
|
3327
|
-
return { textures: newMap };
|
|
3328
|
-
});
|
|
3329
|
-
};
|
|
3330
|
-
const removeMultiple = (keys) => {
|
|
3331
|
-
set((state) => {
|
|
3332
|
-
const newMap = new Map(state.textures);
|
|
3333
|
-
for (const key of keys) newMap.delete(key);
|
|
3334
|
-
return { textures: newMap };
|
|
3335
|
-
});
|
|
3336
|
-
};
|
|
3337
|
-
const dispose = (key) => {
|
|
3338
|
-
const entry = getState().textures.get(key);
|
|
3339
|
-
if (entry) {
|
|
3340
|
-
const tex = getTextureValue(entry);
|
|
3341
|
-
tex?.dispose();
|
|
3342
|
-
}
|
|
3343
|
-
remove(key);
|
|
3344
|
-
};
|
|
3345
|
-
const disposeMultiple = (keys) => {
|
|
3346
|
-
const textures = getState().textures;
|
|
3347
|
-
for (const key of keys) {
|
|
3348
|
-
const entry = textures.get(key);
|
|
3349
|
-
if (entry) {
|
|
3350
|
-
const tex = getTextureValue(entry);
|
|
3351
|
-
tex?.dispose();
|
|
3352
|
-
}
|
|
3353
|
-
}
|
|
3354
|
-
removeMultiple(keys);
|
|
3355
|
-
};
|
|
3356
|
-
const disposeAll = () => {
|
|
3357
|
-
const textures = getState().textures;
|
|
3358
|
-
for (const entry of textures.values()) {
|
|
3359
|
-
const tex = getTextureValue(entry);
|
|
3360
|
-
tex?.dispose();
|
|
3361
|
-
}
|
|
3362
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3363
|
-
};
|
|
2317
|
+
const setState = store.setState;
|
|
2318
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3364
2319
|
return {
|
|
3365
|
-
|
|
3366
|
-
get textures() {
|
|
2320
|
+
get all() {
|
|
3367
2321
|
return getState().textures;
|
|
3368
2322
|
},
|
|
3369
|
-
|
|
3370
|
-
|
|
2323
|
+
get(input) {
|
|
2324
|
+
if (typeof input === "string") return getOne(input);
|
|
2325
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2326
|
+
const out = {};
|
|
2327
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2328
|
+
return out;
|
|
2329
|
+
},
|
|
3371
2330
|
has: (key) => getState().textures.has(key),
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
2331
|
+
add(keyOrRecord, texture) {
|
|
2332
|
+
setState((state) => {
|
|
2333
|
+
const textures = new Map(state.textures);
|
|
2334
|
+
if (typeof keyOrRecord === "string") {
|
|
2335
|
+
textures.set(keyOrRecord, texture);
|
|
2336
|
+
} else {
|
|
2337
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2338
|
+
}
|
|
2339
|
+
return { textures };
|
|
2340
|
+
});
|
|
2341
|
+
},
|
|
2342
|
+
dispose(key, options) {
|
|
2343
|
+
const state = getState();
|
|
2344
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2345
|
+
if (refs > 0 && !options?.force) {
|
|
2346
|
+
console.warn(
|
|
2347
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2348
|
+
);
|
|
2349
|
+
return false;
|
|
2350
|
+
}
|
|
2351
|
+
state.textures.get(key)?.dispose();
|
|
2352
|
+
setState((s) => {
|
|
2353
|
+
const textures = new Map(s.textures);
|
|
2354
|
+
textures.delete(key);
|
|
2355
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2356
|
+
nextRefs.delete(key);
|
|
2357
|
+
return { textures, _textureRefs: nextRefs };
|
|
2358
|
+
});
|
|
2359
|
+
return true;
|
|
2360
|
+
},
|
|
2361
|
+
disposeAll() {
|
|
2362
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2363
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2364
|
+
}
|
|
3382
2365
|
};
|
|
3383
2366
|
}, [store]);
|
|
2367
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2368
|
+
const selected = useThree(subscribe);
|
|
2369
|
+
return selector ? selected : registry;
|
|
3384
2370
|
}
|
|
3385
2371
|
|
|
3386
2372
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3435,7 +2421,7 @@ function addEffect(callback) {
|
|
|
3435
2421
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3436
2422
|
});
|
|
3437
2423
|
const id = `legacy_effect_${effectId++}`;
|
|
3438
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2424
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3439
2425
|
}
|
|
3440
2426
|
function addAfterEffect(callback) {
|
|
3441
2427
|
notifyDepreciated({
|
|
@@ -3444,7 +2430,7 @@ function addAfterEffect(callback) {
|
|
|
3444
2430
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3445
2431
|
});
|
|
3446
2432
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3447
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2433
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3448
2434
|
}
|
|
3449
2435
|
function addTail(callback) {
|
|
3450
2436
|
notifyDepreciated({
|
|
@@ -3452,16 +2438,16 @@ function addTail(callback) {
|
|
|
3452
2438
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3453
2439
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3454
2440
|
});
|
|
3455
|
-
return getScheduler().onIdle(callback);
|
|
2441
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3456
2442
|
}
|
|
3457
2443
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3458
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2444
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3459
2445
|
}
|
|
3460
2446
|
function advance(timestamp) {
|
|
3461
|
-
getScheduler().step(timestamp);
|
|
2447
|
+
scheduler.getScheduler().step(timestamp);
|
|
3462
2448
|
}
|
|
3463
2449
|
|
|
3464
|
-
const version = "10.0.0-alpha.
|
|
2450
|
+
const version = "10.0.0-alpha.3";
|
|
3465
2451
|
const packageData = {
|
|
3466
2452
|
version: version};
|
|
3467
2453
|
|
|
@@ -14717,7 +13703,7 @@ function n0() {
|
|
|
14717
13703
|
var t0 = n0();
|
|
14718
13704
|
const r0 = Xb(t0);
|
|
14719
13705
|
|
|
14720
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13706
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
14721
13707
|
|
|
14722
13708
|
function createReconciler(config) {
|
|
14723
13709
|
const reconciler2 = r0(config);
|
|
@@ -14882,7 +13868,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
14882
13868
|
}
|
|
14883
13869
|
}
|
|
14884
13870
|
const reconstructed = [];
|
|
14885
|
-
function
|
|
13871
|
+
function flushReconstructedInstances() {
|
|
13872
|
+
if (reconstructed.length === 0) return;
|
|
13873
|
+
try {
|
|
13874
|
+
swapReconstructedInstances();
|
|
13875
|
+
} finally {
|
|
13876
|
+
reconstructed.length = 0;
|
|
13877
|
+
}
|
|
13878
|
+
}
|
|
13879
|
+
function swapReconstructedInstances() {
|
|
14886
13880
|
for (const [instance] of reconstructed) {
|
|
14887
13881
|
const parent = instance.parent;
|
|
14888
13882
|
if (parent) {
|
|
@@ -14900,6 +13894,7 @@ function swapInstances() {
|
|
|
14900
13894
|
}
|
|
14901
13895
|
}
|
|
14902
13896
|
if (instance.isHidden) unhideInstance(instance);
|
|
13897
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14903
13898
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14904
13899
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14905
13900
|
}
|
|
@@ -14912,6 +13907,8 @@ function swapInstances() {
|
|
|
14912
13907
|
instance.object.__r3f = instance;
|
|
14913
13908
|
setFiberRef(fiber, instance.object);
|
|
14914
13909
|
delete instance.appliedOnce;
|
|
13910
|
+
instance.eventCount = 0;
|
|
13911
|
+
instance.handlers = {};
|
|
14915
13912
|
applyProps(instance.object, instance.props);
|
|
14916
13913
|
if (instance.props.attach) {
|
|
14917
13914
|
attach(parent, instance);
|
|
@@ -14928,14 +13925,114 @@ function swapInstances() {
|
|
|
14928
13925
|
invalidateInstance(instance);
|
|
14929
13926
|
}
|
|
14930
13927
|
}
|
|
14931
|
-
reconstructed.length = 0;
|
|
14932
13928
|
}
|
|
14933
13929
|
const handleTextInstance = () => {
|
|
14934
13930
|
};
|
|
14935
13931
|
const NO_CONTEXT = {};
|
|
14936
13932
|
let currentUpdatePriority = NoEventPriority;
|
|
14937
|
-
|
|
14938
|
-
|
|
13933
|
+
function getEventPriority(type) {
|
|
13934
|
+
switch (type) {
|
|
13935
|
+
case "beforetoggle":
|
|
13936
|
+
case "cancel":
|
|
13937
|
+
case "click":
|
|
13938
|
+
case "close":
|
|
13939
|
+
case "contextmenu":
|
|
13940
|
+
case "copy":
|
|
13941
|
+
case "cut":
|
|
13942
|
+
case "auxclick":
|
|
13943
|
+
case "dblclick":
|
|
13944
|
+
case "dragend":
|
|
13945
|
+
case "dragstart":
|
|
13946
|
+
case "drop":
|
|
13947
|
+
case "focusin":
|
|
13948
|
+
case "focusout":
|
|
13949
|
+
case "input":
|
|
13950
|
+
case "invalid":
|
|
13951
|
+
case "keydown":
|
|
13952
|
+
case "keypress":
|
|
13953
|
+
case "keyup":
|
|
13954
|
+
case "mousedown":
|
|
13955
|
+
case "mouseup":
|
|
13956
|
+
case "paste":
|
|
13957
|
+
case "pause":
|
|
13958
|
+
case "play":
|
|
13959
|
+
case "pointercancel":
|
|
13960
|
+
case "pointerdown":
|
|
13961
|
+
case "pointerup":
|
|
13962
|
+
case "ratechange":
|
|
13963
|
+
case "reset":
|
|
13964
|
+
case "resize":
|
|
13965
|
+
case "seeked":
|
|
13966
|
+
case "submit":
|
|
13967
|
+
case "touchcancel":
|
|
13968
|
+
case "touchend":
|
|
13969
|
+
case "touchstart":
|
|
13970
|
+
case "volumechange":
|
|
13971
|
+
case "change":
|
|
13972
|
+
case "selectionchange":
|
|
13973
|
+
case "compositionstart":
|
|
13974
|
+
case "compositionend":
|
|
13975
|
+
case "compositionupdate":
|
|
13976
|
+
case "beforeinput":
|
|
13977
|
+
case "blur":
|
|
13978
|
+
case "fullscreenchange":
|
|
13979
|
+
case "focus":
|
|
13980
|
+
case "hashchange":
|
|
13981
|
+
case "popstate":
|
|
13982
|
+
case "select":
|
|
13983
|
+
case "selectstart":
|
|
13984
|
+
return e;
|
|
13985
|
+
case "drag":
|
|
13986
|
+
case "dragenter":
|
|
13987
|
+
case "dragexit":
|
|
13988
|
+
case "dragleave":
|
|
13989
|
+
case "dragover":
|
|
13990
|
+
case "mousemove":
|
|
13991
|
+
case "mouseout":
|
|
13992
|
+
case "mouseover":
|
|
13993
|
+
case "pointermove":
|
|
13994
|
+
case "pointerout":
|
|
13995
|
+
case "pointerover":
|
|
13996
|
+
case "scroll":
|
|
13997
|
+
case "touchmove":
|
|
13998
|
+
case "wheel":
|
|
13999
|
+
case "mouseenter":
|
|
14000
|
+
case "mouseleave":
|
|
14001
|
+
case "pointerenter":
|
|
14002
|
+
case "pointerleave":
|
|
14003
|
+
return o;
|
|
14004
|
+
case "message": {
|
|
14005
|
+
switch (Tb.unstable_getCurrentPriorityLevel()) {
|
|
14006
|
+
case Tb.unstable_ImmediatePriority:
|
|
14007
|
+
return e;
|
|
14008
|
+
case Tb.unstable_UserBlockingPriority:
|
|
14009
|
+
return o;
|
|
14010
|
+
case Tb.unstable_NormalPriority:
|
|
14011
|
+
case Tb.unstable_LowPriority:
|
|
14012
|
+
return r;
|
|
14013
|
+
case Tb.unstable_IdlePriority:
|
|
14014
|
+
return i$1;
|
|
14015
|
+
default:
|
|
14016
|
+
return r;
|
|
14017
|
+
}
|
|
14018
|
+
}
|
|
14019
|
+
default:
|
|
14020
|
+
return r;
|
|
14021
|
+
}
|
|
14022
|
+
}
|
|
14023
|
+
function scheduleMicrotask(callback) {
|
|
14024
|
+
if (typeof queueMicrotask === "function") {
|
|
14025
|
+
queueMicrotask(callback);
|
|
14026
|
+
} else if (typeof Promise !== "undefined") {
|
|
14027
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
14028
|
+
setTimeout(() => {
|
|
14029
|
+
throw error;
|
|
14030
|
+
});
|
|
14031
|
+
});
|
|
14032
|
+
} else {
|
|
14033
|
+
setTimeout(callback);
|
|
14034
|
+
}
|
|
14035
|
+
}
|
|
14939
14036
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
14940
14037
|
isPrimaryRenderer: false,
|
|
14941
14038
|
warnsIfNotActing: false,
|
|
@@ -14974,16 +14071,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14974
14071
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
14975
14072
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
14976
14073
|
if (reconstruct) {
|
|
14977
|
-
reconstructed.push([instance,
|
|
14074
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
14978
14075
|
} else {
|
|
14979
14076
|
const changedProps = diffProps(instance, newProps);
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14983
|
-
|
|
14077
|
+
const attach2 = instance.props.attach;
|
|
14078
|
+
instance.props = getInstanceProps(newProps);
|
|
14079
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
14080
|
+
else delete instance.props.attach;
|
|
14081
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
14984
14082
|
}
|
|
14985
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14986
|
-
if (isTailSibling) swapInstances();
|
|
14987
14083
|
},
|
|
14988
14084
|
finalizeInitialChildren: (instance) => {
|
|
14989
14085
|
for (const prop in instance.props) {
|
|
@@ -15008,8 +14104,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15008
14104
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
15009
14105
|
return prepare(target, container, "", {});
|
|
15010
14106
|
},
|
|
15011
|
-
|
|
15012
|
-
|
|
14107
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
14108
|
+
// before layout effects run so refs point to the new objects
|
|
14109
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
15013
14110
|
shouldSetTextContent: () => false,
|
|
15014
14111
|
clearContainer: () => false,
|
|
15015
14112
|
hideInstance,
|
|
@@ -15017,6 +14114,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15017
14114
|
createTextInstance: handleTextInstance,
|
|
15018
14115
|
hideTextInstance: handleTextInstance,
|
|
15019
14116
|
unhideTextInstance: handleTextInstance,
|
|
14117
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
14118
|
+
supportsMicrotasks: true,
|
|
14119
|
+
scheduleMicrotask,
|
|
15020
14120
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
15021
14121
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
15022
14122
|
noTimeout: -1,
|
|
@@ -15057,28 +14157,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15057
14157
|
},
|
|
15058
14158
|
resolveUpdatePriority() {
|
|
15059
14159
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
case "dblclick":
|
|
15064
|
-
case "dragenter":
|
|
15065
|
-
case "dragleave":
|
|
15066
|
-
case "drop":
|
|
15067
|
-
case "pointercancel":
|
|
15068
|
-
case "pointerdown":
|
|
15069
|
-
case "pointerup":
|
|
15070
|
-
return e;
|
|
15071
|
-
case "dragover":
|
|
15072
|
-
case "pointermove":
|
|
15073
|
-
case "pointerout":
|
|
15074
|
-
case "pointerover":
|
|
15075
|
-
case "pointerenter":
|
|
15076
|
-
case "pointerleave":
|
|
15077
|
-
case "wheel":
|
|
15078
|
-
return o;
|
|
15079
|
-
default:
|
|
15080
|
-
return r;
|
|
15081
|
-
}
|
|
14160
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14161
|
+
if (eventType === void 0) return r;
|
|
14162
|
+
return getEventPriority(eventType);
|
|
15082
14163
|
},
|
|
15083
14164
|
resetFormInstance() {
|
|
15084
14165
|
},
|
|
@@ -15127,11 +14208,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15127
14208
|
cloneMutableTextInstance(textInstance) {
|
|
15128
14209
|
return textInstance;
|
|
15129
14210
|
},
|
|
14211
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14212
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14213
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14214
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14215
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14216
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
15130
14217
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
15131
|
-
throw new Error("Not implemented.");
|
|
15132
14218
|
},
|
|
15133
14219
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
15134
|
-
throw new Error("Not implemented.");
|
|
15135
14220
|
},
|
|
15136
14221
|
// https://github.com/facebook/react/pull/32465
|
|
15137
14222
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -15216,6 +14301,7 @@ function createRoot(canvas) {
|
|
|
15216
14301
|
const lastConfiguredProps = {};
|
|
15217
14302
|
let configured = false;
|
|
15218
14303
|
let pending = null;
|
|
14304
|
+
let rendererSetup = null;
|
|
15219
14305
|
return {
|
|
15220
14306
|
async configure(props = {}) {
|
|
15221
14307
|
let resolve;
|
|
@@ -15246,7 +14332,7 @@ function createRoot(canvas) {
|
|
|
15246
14332
|
forceEven
|
|
15247
14333
|
} = props;
|
|
15248
14334
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || webgpu.SRGBColorSpace;
|
|
15249
|
-
|
|
14335
|
+
let state = store.getState();
|
|
15250
14336
|
const defaultGPUProps = {
|
|
15251
14337
|
canvas,
|
|
15252
14338
|
antialias: true
|
|
@@ -15260,52 +14346,64 @@ function createRoot(canvas) {
|
|
|
15260
14346
|
throw new Error("Cannot use both gl and renderer props at the same time");
|
|
15261
14347
|
}
|
|
15262
14348
|
let renderer = state.internal.actualRenderer;
|
|
15263
|
-
if (
|
|
15264
|
-
|
|
15265
|
-
|
|
15266
|
-
|
|
15267
|
-
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
|
|
15279
|
-
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
|
|
15283
|
-
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
|
|
15287
|
-
|
|
15288
|
-
|
|
15289
|
-
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
|
|
15305
|
-
|
|
14349
|
+
if (!state.internal.actualRenderer) {
|
|
14350
|
+
if (!rendererSetup) {
|
|
14351
|
+
rendererSetup = (async () => {
|
|
14352
|
+
if (primaryCanvas) {
|
|
14353
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14354
|
+
renderer = primary.renderer;
|
|
14355
|
+
state.internal.actualRenderer = renderer;
|
|
14356
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14357
|
+
primary.store.setState((prev) => ({
|
|
14358
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14359
|
+
}));
|
|
14360
|
+
state.set((prev) => ({
|
|
14361
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14362
|
+
renderer,
|
|
14363
|
+
primaryStore: primary.store,
|
|
14364
|
+
internal: {
|
|
14365
|
+
...prev.internal,
|
|
14366
|
+
canvasTarget,
|
|
14367
|
+
isMultiCanvas: true,
|
|
14368
|
+
isSecondary: true,
|
|
14369
|
+
targetId: primaryCanvas
|
|
14370
|
+
}
|
|
14371
|
+
}));
|
|
14372
|
+
} else {
|
|
14373
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, webgpu.WebGPURenderer);
|
|
14374
|
+
if (!renderer.hasInitialized?.()) {
|
|
14375
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14376
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14377
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14378
|
+
canvas.width = size2.width * pixelRatio;
|
|
14379
|
+
canvas.height = size2.height * pixelRatio;
|
|
14380
|
+
}
|
|
14381
|
+
await renderer.init();
|
|
14382
|
+
}
|
|
14383
|
+
const backend = renderer.backend;
|
|
14384
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14385
|
+
state.internal.actualRenderer = renderer;
|
|
14386
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14387
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14388
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14389
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14390
|
+
state.set((prev) => ({
|
|
14391
|
+
internal: {
|
|
14392
|
+
...prev.internal,
|
|
14393
|
+
canvasTarget,
|
|
14394
|
+
unregisterPrimary
|
|
14395
|
+
}
|
|
14396
|
+
}));
|
|
14397
|
+
}
|
|
15306
14398
|
}
|
|
15307
|
-
}))
|
|
14399
|
+
})().catch((err) => {
|
|
14400
|
+
rendererSetup = null;
|
|
14401
|
+
throw err;
|
|
14402
|
+
});
|
|
15308
14403
|
}
|
|
14404
|
+
await rendererSetup;
|
|
14405
|
+
state = store.getState();
|
|
14406
|
+
renderer = state.internal.actualRenderer;
|
|
15309
14407
|
}
|
|
15310
14408
|
let raycaster = state.raycaster;
|
|
15311
14409
|
if (!raycaster) state.set({ raycaster: raycaster = new webgpu.Raycaster() });
|
|
@@ -15485,15 +14583,15 @@ function createRoot(canvas) {
|
|
|
15485
14583
|
applyProps(currentRenderer, rendererProps);
|
|
15486
14584
|
}
|
|
15487
14585
|
}
|
|
15488
|
-
const scheduler = getScheduler();
|
|
14586
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15489
14587
|
const rootId = state.internal.rootId;
|
|
15490
14588
|
if (!rootId) {
|
|
15491
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15492
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14589
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14590
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15493
14591
|
getState: () => store.getState(),
|
|
15494
14592
|
onError: (err) => store.getState().setError(err)
|
|
15495
14593
|
});
|
|
15496
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14594
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15497
14595
|
() => {
|
|
15498
14596
|
const state2 = store.getState();
|
|
15499
14597
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15508,7 +14606,7 @@ function createRoot(canvas) {
|
|
|
15508
14606
|
system: true
|
|
15509
14607
|
}
|
|
15510
14608
|
);
|
|
15511
|
-
const unregisterEventsFlush = scheduler.register(
|
|
14609
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
15512
14610
|
() => {
|
|
15513
14611
|
const state2 = store.getState();
|
|
15514
14612
|
state2.events.flush?.();
|
|
@@ -15520,7 +14618,7 @@ function createRoot(canvas) {
|
|
|
15520
14618
|
system: true
|
|
15521
14619
|
}
|
|
15522
14620
|
);
|
|
15523
|
-
const unregisterFrustum = scheduler.register(
|
|
14621
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15524
14622
|
() => {
|
|
15525
14623
|
const state2 = store.getState();
|
|
15526
14624
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15530,11 +14628,11 @@ function createRoot(canvas) {
|
|
|
15530
14628
|
{
|
|
15531
14629
|
id: `${newRootId}_frustum`,
|
|
15532
14630
|
rootId: newRootId,
|
|
15533
|
-
|
|
14631
|
+
before: "render",
|
|
15534
14632
|
system: true
|
|
15535
14633
|
}
|
|
15536
14634
|
);
|
|
15537
|
-
const unregisterVisibility = scheduler.register(
|
|
14635
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15538
14636
|
() => {
|
|
15539
14637
|
const state2 = store.getState();
|
|
15540
14638
|
checkVisibility(state2);
|
|
@@ -15542,16 +14640,16 @@ function createRoot(canvas) {
|
|
|
15542
14640
|
{
|
|
15543
14641
|
id: `${newRootId}_visibility`,
|
|
15544
14642
|
rootId: newRootId,
|
|
15545
|
-
|
|
14643
|
+
before: "render",
|
|
15546
14644
|
system: true,
|
|
15547
14645
|
after: `${newRootId}_frustum`
|
|
15548
14646
|
}
|
|
15549
14647
|
);
|
|
15550
|
-
const unregisterRender = scheduler.register(
|
|
14648
|
+
const unregisterRender = scheduler$1.register(
|
|
15551
14649
|
() => {
|
|
15552
14650
|
const state2 = store.getState();
|
|
15553
14651
|
const renderer2 = state2.internal.actualRenderer;
|
|
15554
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14652
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15555
14653
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15556
14654
|
try {
|
|
15557
14655
|
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
@@ -15584,11 +14682,11 @@ function createRoot(canvas) {
|
|
|
15584
14682
|
unregisterVisibility();
|
|
15585
14683
|
unregisterRender();
|
|
15586
14684
|
},
|
|
15587
|
-
scheduler
|
|
14685
|
+
scheduler: scheduler$1
|
|
15588
14686
|
}
|
|
15589
14687
|
}));
|
|
15590
14688
|
}
|
|
15591
|
-
scheduler.frameloop = frameloop;
|
|
14689
|
+
scheduler$1.frameloop = frameloop;
|
|
15592
14690
|
onCreated = onCreatedCallback;
|
|
15593
14691
|
configured = true;
|
|
15594
14692
|
resolve();
|
|
@@ -15655,7 +14753,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
15655
14753
|
dispose(state.scene);
|
|
15656
14754
|
_roots.delete(canvas);
|
|
15657
14755
|
if (callback) callback(canvas);
|
|
15658
|
-
} catch {
|
|
14756
|
+
} catch (error) {
|
|
14757
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
15659
14758
|
}
|
|
15660
14759
|
}, 500);
|
|
15661
14760
|
}
|
|
@@ -15718,6 +14817,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15718
14817
|
viewport = rootState.viewport.getCurrentViewport(camera, new webgpu.Vector3(), resolvedSize);
|
|
15719
14818
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15720
14819
|
}
|
|
14820
|
+
const set = injectState.set;
|
|
15721
14821
|
return {
|
|
15722
14822
|
// The intersect consists of the previous root state
|
|
15723
14823
|
...rootState,
|
|
@@ -15736,33 +14836,205 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15736
14836
|
size: resolvedSize,
|
|
15737
14837
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15738
14838
|
// Layers are allowed to override events
|
|
15739
|
-
setEvents: (events2) =>
|
|
14839
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15740
14840
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15741
14841
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15742
14842
|
};
|
|
15743
14843
|
});
|
|
15744
|
-
const usePortalStore = React.useMemo(() => {
|
|
15745
|
-
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15746
|
-
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15747
|
-
onMutate(previousRoot.getState());
|
|
15748
|
-
return store;
|
|
15749
|
-
}, [previousRoot, container]);
|
|
15750
|
-
useIsomorphicLayoutEffect(() => {
|
|
15751
|
-
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
15752
|
-
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
15753
|
-
return unsubscribe;
|
|
15754
|
-
}, [previousRoot, usePortalStore]);
|
|
15755
|
-
return (
|
|
15756
|
-
// @ts-ignore, reconciler types are not maintained
|
|
15757
|
-
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
15758
|
-
/* @__PURE__ */ jsxRuntime.jsx(context.Provider, { value: usePortalStore, children }),
|
|
15759
|
-
usePortalStore,
|
|
15760
|
-
null
|
|
15761
|
-
) })
|
|
15762
|
-
);
|
|
14844
|
+
const usePortalStore = React.useMemo(() => {
|
|
14845
|
+
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
14846
|
+
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
14847
|
+
onMutate(previousRoot.getState());
|
|
14848
|
+
return store;
|
|
14849
|
+
}, [previousRoot, container]);
|
|
14850
|
+
useIsomorphicLayoutEffect(() => {
|
|
14851
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14852
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14853
|
+
return unsubscribe;
|
|
14854
|
+
}, [previousRoot, usePortalStore]);
|
|
14855
|
+
return (
|
|
14856
|
+
// @ts-ignore, reconciler types are not maintained
|
|
14857
|
+
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
14858
|
+
/* @__PURE__ */ jsxRuntime.jsx(context.Provider, { value: usePortalStore, children }),
|
|
14859
|
+
usePortalStore,
|
|
14860
|
+
null
|
|
14861
|
+
) })
|
|
14862
|
+
);
|
|
14863
|
+
}
|
|
14864
|
+
function flushSync(fn) {
|
|
14865
|
+
return reconciler.flushSyncFromReconciler(fn);
|
|
14866
|
+
}
|
|
14867
|
+
|
|
14868
|
+
function parseBackground(background) {
|
|
14869
|
+
if (!background) return null;
|
|
14870
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14871
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14872
|
+
return {
|
|
14873
|
+
...rest,
|
|
14874
|
+
preset,
|
|
14875
|
+
files: envMap || files,
|
|
14876
|
+
backgroundFiles: backgroundMap,
|
|
14877
|
+
background: true
|
|
14878
|
+
};
|
|
14879
|
+
}
|
|
14880
|
+
if (typeof background === "number") {
|
|
14881
|
+
return { color: background, background: true };
|
|
14882
|
+
}
|
|
14883
|
+
if (typeof background === "string") {
|
|
14884
|
+
if (background in presetsObj) {
|
|
14885
|
+
return { preset: background, background: true };
|
|
14886
|
+
}
|
|
14887
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14888
|
+
return { files: background, background: true };
|
|
14889
|
+
}
|
|
14890
|
+
return { color: background, background: true };
|
|
14891
|
+
}
|
|
14892
|
+
if (background.isColor) {
|
|
14893
|
+
return { color: background, background: true };
|
|
14894
|
+
}
|
|
14895
|
+
return null;
|
|
14896
|
+
}
|
|
14897
|
+
|
|
14898
|
+
function parseRendererConfig(rendererProp) {
|
|
14899
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14900
|
+
if (isRendererConfig) {
|
|
14901
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14902
|
+
return {
|
|
14903
|
+
primaryCanvas: pc,
|
|
14904
|
+
scheduler: sc,
|
|
14905
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14906
|
+
};
|
|
14907
|
+
}
|
|
14908
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14909
|
+
}
|
|
14910
|
+
|
|
14911
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14912
|
+
const ROOT_SCOPE = "";
|
|
14913
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14914
|
+
function getKindRegistry(store, kind) {
|
|
14915
|
+
let registry = registries.get(store);
|
|
14916
|
+
if (!registry) {
|
|
14917
|
+
registry = {
|
|
14918
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14919
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14920
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14921
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14922
|
+
};
|
|
14923
|
+
registries.set(store, registry);
|
|
14924
|
+
}
|
|
14925
|
+
return registry[kind];
|
|
14926
|
+
}
|
|
14927
|
+
function resolvePrimary$1(store) {
|
|
14928
|
+
return store.getState().primaryStore ?? store;
|
|
14929
|
+
}
|
|
14930
|
+
function isScopeValid(store, kind, scopeKey) {
|
|
14931
|
+
return getKindRegistry(store, kind).valid.has(scopeKey);
|
|
14932
|
+
}
|
|
14933
|
+
function peekStaged(store, kind, scopeKey) {
|
|
14934
|
+
return getKindRegistry(store, kind).staged.get(scopeKey);
|
|
14935
|
+
}
|
|
14936
|
+
function stageEntries(store, kind, scopeKey, entries) {
|
|
14937
|
+
const { staged } = getKindRegistry(store, kind);
|
|
14938
|
+
const current = staged.get(scopeKey);
|
|
14939
|
+
if (current) Object.assign(current, entries);
|
|
14940
|
+
else staged.set(scopeKey, { ...entries });
|
|
14941
|
+
}
|
|
14942
|
+
function readCommittedScope(map, scopeKey, isLeaf) {
|
|
14943
|
+
if (scopeKey === ROOT_SCOPE) {
|
|
14944
|
+
const leaves = {};
|
|
14945
|
+
for (const [key, value] of Object.entries(map)) if (isLeaf(value)) leaves[key] = value;
|
|
14946
|
+
return leaves;
|
|
14947
|
+
}
|
|
14948
|
+
const scopeData = map[scopeKey];
|
|
14949
|
+
if (scopeData && typeof scopeData === "object" && !isLeaf(scopeData)) return scopeData;
|
|
14950
|
+
return {};
|
|
14951
|
+
}
|
|
14952
|
+
function withStagedOverlay(store, kind, committed) {
|
|
14953
|
+
const { staged } = getKindRegistry(store, kind);
|
|
14954
|
+
if (staged.size === 0) return committed;
|
|
14955
|
+
const view = { ...committed };
|
|
14956
|
+
for (const [scopeKey, entries] of staged) {
|
|
14957
|
+
if (scopeKey === ROOT_SCOPE) Object.assign(view, entries);
|
|
14958
|
+
else view[scopeKey] = { ...view[scopeKey], ...entries };
|
|
14959
|
+
}
|
|
14960
|
+
return view;
|
|
14961
|
+
}
|
|
14962
|
+
function flushStagedScope(store, kind, scopeKey, isLeaf) {
|
|
14963
|
+
const registry = getKindRegistry(store, kind);
|
|
14964
|
+
const staged = registry.staged.get(scopeKey);
|
|
14965
|
+
if (!staged) return;
|
|
14966
|
+
registry.staged.delete(scopeKey);
|
|
14967
|
+
const replace = !registry.valid.has(scopeKey);
|
|
14968
|
+
store.setState((state) => {
|
|
14969
|
+
const map = state[kind];
|
|
14970
|
+
if (scopeKey === ROOT_SCOPE) {
|
|
14971
|
+
if (!replace) return { [kind]: { ...map, ...staged } };
|
|
14972
|
+
const next = {};
|
|
14973
|
+
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
14974
|
+
return { [kind]: { ...next, ...staged } };
|
|
14975
|
+
}
|
|
14976
|
+
const current = replace ? {} : map[scopeKey] ?? {};
|
|
14977
|
+
return { [kind]: { ...map, [scopeKey]: { ...current, ...staged } } };
|
|
14978
|
+
});
|
|
14979
|
+
registry.valid.add(scopeKey);
|
|
14980
|
+
}
|
|
14981
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14982
|
+
const registry = getKindRegistry(store, kind);
|
|
14983
|
+
if (scopeKey === void 0) {
|
|
14984
|
+
registry.valid.clear();
|
|
14985
|
+
registry.staged.clear();
|
|
14986
|
+
} else {
|
|
14987
|
+
registry.valid.delete(scopeKey);
|
|
14988
|
+
registry.staged.delete(scopeKey);
|
|
14989
|
+
}
|
|
14990
|
+
}
|
|
14991
|
+
function rebuildResource(store, kind, userScope) {
|
|
14992
|
+
const primary = resolvePrimary$1(store);
|
|
14993
|
+
invalidateResource(primary, kind, userScope === "root" ? ROOT_SCOPE : userScope);
|
|
14994
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14995
|
+
}
|
|
14996
|
+
function invalidateAllResources(store) {
|
|
14997
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14998
|
+
}
|
|
14999
|
+
function removeResourceEntries(store, kind, names, scope, isLeaf) {
|
|
15000
|
+
const staged = peekStaged(store, kind, scope ?? ROOT_SCOPE);
|
|
15001
|
+
if (staged) for (const name of names) delete staged[name];
|
|
15002
|
+
store.setState((state) => {
|
|
15003
|
+
const map = state[kind];
|
|
15004
|
+
if (scope) {
|
|
15005
|
+
const currentScope = { ...map[scope] };
|
|
15006
|
+
for (const name of names) delete currentScope[name];
|
|
15007
|
+
return { [kind]: { ...map, [scope]: currentScope } };
|
|
15008
|
+
}
|
|
15009
|
+
const next = { ...map };
|
|
15010
|
+
for (const name of names) if (isLeaf(next[name])) delete next[name];
|
|
15011
|
+
return { [kind]: next };
|
|
15012
|
+
});
|
|
15763
15013
|
}
|
|
15764
|
-
function
|
|
15765
|
-
|
|
15014
|
+
function clearResourceEntries(store, kind, scope, isLeaf) {
|
|
15015
|
+
const registry = getKindRegistry(store, kind);
|
|
15016
|
+
if (scope && scope !== "root") registry.staged.delete(scope);
|
|
15017
|
+
else if (scope === "root") registry.staged.delete(ROOT_SCOPE);
|
|
15018
|
+
else registry.staged.clear();
|
|
15019
|
+
store.setState((state) => {
|
|
15020
|
+
const map = state[kind];
|
|
15021
|
+
if (scope && scope !== "root") {
|
|
15022
|
+
const { [scope]: _, ...rest } = map;
|
|
15023
|
+
return { [kind]: rest };
|
|
15024
|
+
}
|
|
15025
|
+
if (scope === "root") {
|
|
15026
|
+
const next = {};
|
|
15027
|
+
for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
|
|
15028
|
+
return { [kind]: next };
|
|
15029
|
+
}
|
|
15030
|
+
return { [kind]: {} };
|
|
15031
|
+
});
|
|
15032
|
+
}
|
|
15033
|
+
|
|
15034
|
+
function clearHmrCaches(store) {
|
|
15035
|
+
const primary = store.getState().primaryStore ?? store;
|
|
15036
|
+
invalidateAllResources(primary);
|
|
15037
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
15766
15038
|
}
|
|
15767
15039
|
|
|
15768
15040
|
function CanvasImpl({
|
|
@@ -15785,6 +15057,8 @@ function CanvasImpl({
|
|
|
15785
15057
|
raycaster,
|
|
15786
15058
|
camera,
|
|
15787
15059
|
scene,
|
|
15060
|
+
autoUpdateFrustum,
|
|
15061
|
+
occlusion,
|
|
15788
15062
|
onPointerMissed,
|
|
15789
15063
|
onDragOverMissed,
|
|
15790
15064
|
onDropMissed,
|
|
@@ -15796,49 +15070,10 @@ function CanvasImpl({
|
|
|
15796
15070
|
forceEven,
|
|
15797
15071
|
...props
|
|
15798
15072
|
}) {
|
|
15799
|
-
const
|
|
15800
|
-
let primaryCanvas;
|
|
15801
|
-
let scheduler;
|
|
15802
|
-
let renderer;
|
|
15803
|
-
if (isRendererConfig) {
|
|
15804
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
15805
|
-
primaryCanvas = pc;
|
|
15806
|
-
scheduler = sc;
|
|
15807
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
15808
|
-
} else {
|
|
15809
|
-
renderer = rendererProp;
|
|
15810
|
-
}
|
|
15073
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15811
15074
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15812
15075
|
const Bridge = useBridge();
|
|
15813
|
-
const backgroundProps = React__namespace.useMemo(() =>
|
|
15814
|
-
if (!background) return null;
|
|
15815
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15816
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15817
|
-
return {
|
|
15818
|
-
...rest,
|
|
15819
|
-
preset,
|
|
15820
|
-
files: envMap || files,
|
|
15821
|
-
backgroundFiles: backgroundMap,
|
|
15822
|
-
background: true
|
|
15823
|
-
};
|
|
15824
|
-
}
|
|
15825
|
-
if (typeof background === "number") {
|
|
15826
|
-
return { color: background, background: true };
|
|
15827
|
-
}
|
|
15828
|
-
if (typeof background === "string") {
|
|
15829
|
-
if (background in presetsObj) {
|
|
15830
|
-
return { preset: background, background: true };
|
|
15831
|
-
}
|
|
15832
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15833
|
-
return { files: background, background: true };
|
|
15834
|
-
}
|
|
15835
|
-
return { color: background, background: true };
|
|
15836
|
-
}
|
|
15837
|
-
if (background.isColor) {
|
|
15838
|
-
return { color: background, background: true };
|
|
15839
|
-
}
|
|
15840
|
-
return null;
|
|
15841
|
-
}, [background]);
|
|
15076
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15842
15077
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15843
15078
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15844
15079
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15880,6 +15115,7 @@ function CanvasImpl({
|
|
|
15880
15115
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15881
15116
|
const [block, setBlock] = React__namespace.useState(false);
|
|
15882
15117
|
const [error, setError] = React__namespace.useState(false);
|
|
15118
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
15883
15119
|
if (block) throw block;
|
|
15884
15120
|
if (error) throw error;
|
|
15885
15121
|
const root = React__namespace.useRef(null);
|
|
@@ -15887,6 +15123,7 @@ function CanvasImpl({
|
|
|
15887
15123
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
15888
15124
|
useIsomorphicLayoutEffect(() => {
|
|
15889
15125
|
effectActiveRef.current = true;
|
|
15126
|
+
if (fallbackVisible) return;
|
|
15890
15127
|
const canvas = canvasRef.current;
|
|
15891
15128
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15892
15129
|
if (!root.current) {
|
|
@@ -15907,7 +15144,7 @@ function CanvasImpl({
|
|
|
15907
15144
|
}
|
|
15908
15145
|
async function run() {
|
|
15909
15146
|
if (!effectActiveRef.current || !root.current) return;
|
|
15910
|
-
await root.current.configure({
|
|
15147
|
+
const configured = await root.current.configure({
|
|
15911
15148
|
id,
|
|
15912
15149
|
primaryCanvas,
|
|
15913
15150
|
scheduler,
|
|
@@ -15922,6 +15159,8 @@ function CanvasImpl({
|
|
|
15922
15159
|
performance,
|
|
15923
15160
|
raycaster,
|
|
15924
15161
|
camera,
|
|
15162
|
+
autoUpdateFrustum,
|
|
15163
|
+
occlusion,
|
|
15925
15164
|
size: effectiveSize,
|
|
15926
15165
|
// Store size props for reset functionality
|
|
15927
15166
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15946,8 +15185,20 @@ function CanvasImpl({
|
|
|
15946
15185
|
}
|
|
15947
15186
|
onCreated?.(state);
|
|
15948
15187
|
}
|
|
15949
|
-
})
|
|
15950
|
-
|
|
15188
|
+
}).then(
|
|
15189
|
+
() => true,
|
|
15190
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15191
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15192
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15193
|
+
(setupError) => {
|
|
15194
|
+
if (effectActiveRef.current) {
|
|
15195
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15196
|
+
else setError(setupError);
|
|
15197
|
+
}
|
|
15198
|
+
return false;
|
|
15199
|
+
}
|
|
15200
|
+
);
|
|
15201
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15951
15202
|
root.current.render(
|
|
15952
15203
|
/* @__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: [
|
|
15953
15204
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -15981,14 +15232,7 @@ function CanvasImpl({
|
|
|
15981
15232
|
const handleHMR = () => {
|
|
15982
15233
|
queueMicrotask(() => {
|
|
15983
15234
|
const rootEntry = _roots.get(canvas);
|
|
15984
|
-
if (rootEntry?.store)
|
|
15985
|
-
console.log("[R3F] HMR detected \u2014 rebuilding nodes/uniforms");
|
|
15986
|
-
rootEntry.store.setState((state) => ({
|
|
15987
|
-
nodes: {},
|
|
15988
|
-
uniforms: {},
|
|
15989
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15990
|
-
}));
|
|
15991
|
-
}
|
|
15235
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15992
15236
|
});
|
|
15993
15237
|
};
|
|
15994
15238
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
@@ -16017,7 +15261,11 @@ function CanvasImpl({
|
|
|
16017
15261
|
...style
|
|
16018
15262
|
},
|
|
16019
15263
|
...props,
|
|
16020
|
-
children:
|
|
15264
|
+
children: fallbackVisible ? (
|
|
15265
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15266
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15267
|
+
fallback
|
|
15268
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
16021
15269
|
"canvas",
|
|
16022
15270
|
{
|
|
16023
15271
|
ref: canvasRef,
|
|
@@ -16099,35 +15347,50 @@ let ScopedStore = _ScopedStore;
|
|
|
16099
15347
|
function createScopedStore(data) {
|
|
16100
15348
|
return new ScopedStore(data);
|
|
16101
15349
|
}
|
|
16102
|
-
function createLazyCreatorState(state) {
|
|
15350
|
+
function createLazyCreatorState(state, store) {
|
|
16103
15351
|
let _uniforms = null;
|
|
16104
15352
|
let _nodes = null;
|
|
16105
15353
|
let _buffers = null;
|
|
16106
15354
|
let _gpuStorage = null;
|
|
15355
|
+
const view = (kind) => store ? withStagedOverlay(store, kind, state[kind]) : state[kind];
|
|
16107
15356
|
return Object.create(state, {
|
|
16108
15357
|
uniforms: {
|
|
16109
15358
|
get() {
|
|
16110
|
-
return _uniforms ?? (_uniforms = createScopedStore(
|
|
15359
|
+
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms")));
|
|
16111
15360
|
}
|
|
16112
15361
|
},
|
|
16113
15362
|
nodes: {
|
|
16114
15363
|
get() {
|
|
16115
|
-
return _nodes ?? (_nodes = createScopedStore(
|
|
15364
|
+
return _nodes ?? (_nodes = createScopedStore(view("nodes")));
|
|
16116
15365
|
}
|
|
16117
15366
|
},
|
|
16118
15367
|
buffers: {
|
|
16119
15368
|
get() {
|
|
16120
|
-
return _buffers ?? (_buffers = createScopedStore(
|
|
15369
|
+
return _buffers ?? (_buffers = createScopedStore(view("buffers")));
|
|
16121
15370
|
}
|
|
16122
15371
|
},
|
|
16123
15372
|
gpuStorage: {
|
|
16124
15373
|
get() {
|
|
16125
|
-
return _gpuStorage ?? (_gpuStorage = createScopedStore(
|
|
15374
|
+
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage")));
|
|
16126
15375
|
}
|
|
16127
15376
|
}
|
|
16128
15377
|
});
|
|
16129
15378
|
}
|
|
16130
15379
|
|
|
15380
|
+
function resolvePrimary(local) {
|
|
15381
|
+
return local.getState().primaryStore ?? local;
|
|
15382
|
+
}
|
|
15383
|
+
function usePrimaryStore() {
|
|
15384
|
+
const local = useStore();
|
|
15385
|
+
const primary = local.getState().primaryStore;
|
|
15386
|
+
return React.useMemo(() => primary ?? local, [primary, local]);
|
|
15387
|
+
}
|
|
15388
|
+
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15389
|
+
const local = useStore();
|
|
15390
|
+
const primary = resolvePrimary(local);
|
|
15391
|
+
return primary(selector, equalityFn);
|
|
15392
|
+
}
|
|
15393
|
+
|
|
16131
15394
|
function addTexture(set, key, value) {
|
|
16132
15395
|
set((state) => {
|
|
16133
15396
|
const newMap = new Map(state.textures);
|
|
@@ -16231,65 +15494,56 @@ function useCompareMemoize(value, deep) {
|
|
|
16231
15494
|
return ref.current;
|
|
16232
15495
|
}
|
|
16233
15496
|
|
|
15497
|
+
function useScopedResource(options) {
|
|
15498
|
+
const { store, kind, scope, isLeaf, create, prepare, reconcile, input } = options;
|
|
15499
|
+
const scopeKey = scope ?? ROOT_SCOPE;
|
|
15500
|
+
const version = store((s) => s._hmrVersion);
|
|
15501
|
+
const entries = React.useMemo(() => {
|
|
15502
|
+
const staged = peekStaged(store, kind, scopeKey);
|
|
15503
|
+
const reusable = isScopeValid(store, kind, scopeKey);
|
|
15504
|
+
const map = store.getState()[kind];
|
|
15505
|
+
const committed = reusable ? readCommittedScope(map, scopeKey, isLeaf) : void 0;
|
|
15506
|
+
const result = {};
|
|
15507
|
+
let fresh = null;
|
|
15508
|
+
for (const [name, candidate] of Object.entries(create())) {
|
|
15509
|
+
const existing = staged?.[name] ?? committed?.[name];
|
|
15510
|
+
if (existing !== void 0) {
|
|
15511
|
+
result[name] = existing;
|
|
15512
|
+
reconcile?.(existing, candidate);
|
|
15513
|
+
} else {
|
|
15514
|
+
const value = prepare ? prepare(name, candidate) : candidate;
|
|
15515
|
+
result[name] = value;
|
|
15516
|
+
(fresh ?? (fresh = {}))[name] = value;
|
|
15517
|
+
}
|
|
15518
|
+
}
|
|
15519
|
+
if (fresh) stageEntries(store, kind, scopeKey, fresh);
|
|
15520
|
+
return result;
|
|
15521
|
+
}, [store, kind, scopeKey, version, input]);
|
|
15522
|
+
useIsomorphicLayoutEffect(() => {
|
|
15523
|
+
flushStagedScope(store, kind, scopeKey, isLeaf);
|
|
15524
|
+
});
|
|
15525
|
+
return entries;
|
|
15526
|
+
}
|
|
15527
|
+
|
|
16234
15528
|
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
16235
15529
|
function useUniforms(creatorOrScope, scope) {
|
|
16236
|
-
const store =
|
|
15530
|
+
const store = usePrimaryStore();
|
|
16237
15531
|
const removeUniforms2 = React.useCallback(
|
|
16238
|
-
(names, targetScope) =>
|
|
16239
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16240
|
-
store.setState((state) => {
|
|
16241
|
-
if (targetScope) {
|
|
16242
|
-
const currentScope = { ...state.uniforms[targetScope] };
|
|
16243
|
-
for (const name of nameArray) delete currentScope[name];
|
|
16244
|
-
return { uniforms: { ...state.uniforms, [targetScope]: currentScope } };
|
|
16245
|
-
}
|
|
16246
|
-
const uniforms2 = { ...state.uniforms };
|
|
16247
|
-
for (const name of nameArray) if (isUniformNode$1(uniforms2[name])) delete uniforms2[name];
|
|
16248
|
-
return { uniforms: uniforms2 };
|
|
16249
|
-
});
|
|
16250
|
-
},
|
|
15532
|
+
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode$1),
|
|
16251
15533
|
[store]
|
|
16252
15534
|
);
|
|
16253
15535
|
const clearUniforms = React.useCallback(
|
|
16254
|
-
(targetScope) =>
|
|
16255
|
-
store.setState((state) => {
|
|
16256
|
-
if (targetScope && targetScope !== "root") {
|
|
16257
|
-
const { [targetScope]: _, ...rest } = state.uniforms;
|
|
16258
|
-
return { uniforms: rest };
|
|
16259
|
-
}
|
|
16260
|
-
if (targetScope === "root") {
|
|
16261
|
-
const uniforms2 = {};
|
|
16262
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
16263
|
-
if (!isUniformNode$1(value)) uniforms2[key] = value;
|
|
16264
|
-
}
|
|
16265
|
-
return { uniforms: uniforms2 };
|
|
16266
|
-
}
|
|
16267
|
-
return { uniforms: {} };
|
|
16268
|
-
});
|
|
16269
|
-
},
|
|
15536
|
+
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode$1),
|
|
16270
15537
|
[store]
|
|
16271
15538
|
);
|
|
16272
15539
|
const rebuildUniforms = React.useCallback(
|
|
16273
|
-
(targetScope) =>
|
|
16274
|
-
store.setState((state) => {
|
|
16275
|
-
let newUniforms = {};
|
|
16276
|
-
if (targetScope && targetScope !== "root") {
|
|
16277
|
-
const { [targetScope]: _, ...rest } = state.uniforms;
|
|
16278
|
-
newUniforms = rest;
|
|
16279
|
-
} else if (targetScope === "root") {
|
|
16280
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
16281
|
-
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
16282
|
-
}
|
|
16283
|
-
}
|
|
16284
|
-
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
16285
|
-
});
|
|
16286
|
-
},
|
|
15540
|
+
(targetScope) => rebuildResource(store, "uniforms", targetScope),
|
|
16287
15541
|
[store]
|
|
16288
15542
|
);
|
|
16289
15543
|
const inputForMemoization = React.useMemo(() => {
|
|
16290
15544
|
let raw = creatorOrScope;
|
|
16291
15545
|
if (is.fun(creatorOrScope)) {
|
|
16292
|
-
const wrappedState = createLazyCreatorState(store.getState());
|
|
15546
|
+
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
16293
15547
|
raw = creatorOrScope(wrappedState);
|
|
16294
15548
|
}
|
|
16295
15549
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
@@ -16303,80 +15557,44 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
16303
15557
|
}, [creatorOrScope, store]);
|
|
16304
15558
|
const memoizedInput = useCompareMemoize(inputForMemoization);
|
|
16305
15559
|
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
16306
|
-
const storeUniforms =
|
|
16307
|
-
const
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
16314
|
-
|
|
16315
|
-
|
|
16316
|
-
|
|
16317
|
-
|
|
16318
|
-
|
|
16319
|
-
|
|
16320
|
-
|
|
16321
|
-
|
|
16322
|
-
|
|
16323
|
-
|
|
16324
|
-
|
|
16325
|
-
|
|
16326
|
-
|
|
16327
|
-
|
|
16328
|
-
if (scope) {
|
|
16329
|
-
if (!state.uniforms[scope]) state.uniforms[scope] = {};
|
|
16330
|
-
targetRecord = state.uniforms[scope];
|
|
16331
|
-
}
|
|
16332
|
-
for (const [name, node] of Object.entries(created)) {
|
|
16333
|
-
if (targetRecord[name]) {
|
|
16334
|
-
result[name] = targetRecord[name];
|
|
16335
|
-
const existingVal = result[name].value;
|
|
16336
|
-
const newVal = vectorize(node);
|
|
16337
|
-
let equals = newVal === existingVal;
|
|
16338
|
-
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
16339
|
-
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
16340
|
-
equals = vectorEquals(existingVal, newVal);
|
|
16341
|
-
} else if (isSameThreeType(existingVal, newVal)) {
|
|
16342
|
-
equals = existingVal.equals(newVal);
|
|
16343
|
-
}
|
|
15560
|
+
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15561
|
+
const created = useScopedResource({
|
|
15562
|
+
store,
|
|
15563
|
+
kind: "uniforms",
|
|
15564
|
+
scope: isReader ? void 0 : scope,
|
|
15565
|
+
isLeaf: isUniformNode$1,
|
|
15566
|
+
input: memoizedInput,
|
|
15567
|
+
create: () => {
|
|
15568
|
+
if (isReader) return {};
|
|
15569
|
+
if (typeof memoizedInput !== "object" || memoizedInput === null) throw new Error("Invalid uniform input");
|
|
15570
|
+
return memoizedInput;
|
|
15571
|
+
},
|
|
15572
|
+
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
15573
|
+
reconcile: (existing, candidate) => {
|
|
15574
|
+
const existingVal = existing.value;
|
|
15575
|
+
const newVal = vectorize(candidate);
|
|
15576
|
+
let equals = newVal === existingVal;
|
|
15577
|
+
if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
|
|
15578
|
+
if (isThreeVector(existingVal) && isThreeVector(newVal)) {
|
|
15579
|
+
equals = vectorEquals(existingVal, newVal);
|
|
15580
|
+
} else if (isSameThreeType(existingVal, newVal)) {
|
|
15581
|
+
equals = existingVal.equals(newVal);
|
|
16344
15582
|
}
|
|
16345
|
-
if (!equals) result[name].value = newVal;
|
|
16346
|
-
} else {
|
|
16347
|
-
result[name] = createUniform(name, node, scope);
|
|
16348
|
-
hasNewUniforms = true;
|
|
16349
|
-
}
|
|
16350
|
-
}
|
|
16351
|
-
if (hasNewUniforms) {
|
|
16352
|
-
if (scope) {
|
|
16353
|
-
set((s) => ({
|
|
16354
|
-
uniforms: {
|
|
16355
|
-
...s.uniforms,
|
|
16356
|
-
[scope]: { ...s.uniforms[scope], ...result }
|
|
16357
|
-
}
|
|
16358
|
-
}));
|
|
16359
|
-
} else {
|
|
16360
|
-
set((s) => ({ uniforms: { ...s.uniforms, ...result } }));
|
|
16361
15583
|
}
|
|
15584
|
+
if (!equals) existing.value = newVal;
|
|
16362
15585
|
}
|
|
16363
|
-
|
|
16364
|
-
|
|
15586
|
+
});
|
|
15587
|
+
let uniforms = created;
|
|
15588
|
+
if (memoizedInput === void 0) {
|
|
15589
|
+
uniforms = storeUniforms;
|
|
15590
|
+
} else if (typeof memoizedInput === "string") {
|
|
15591
|
+
const scopeData = storeUniforms[memoizedInput];
|
|
15592
|
+
uniforms = scopeData && !isUniformNode$1(scopeData) ? scopeData : {};
|
|
15593
|
+
}
|
|
16365
15594
|
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
16366
15595
|
}
|
|
16367
15596
|
function rebuildAllUniforms(store, scope) {
|
|
16368
|
-
store
|
|
16369
|
-
let newUniforms = {};
|
|
16370
|
-
if (scope && scope !== "root") {
|
|
16371
|
-
const { [scope]: _, ...rest } = state.uniforms;
|
|
16372
|
-
newUniforms = rest;
|
|
16373
|
-
} else if (scope === "root") {
|
|
16374
|
-
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
16375
|
-
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
16376
|
-
}
|
|
16377
|
-
}
|
|
16378
|
-
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
16379
|
-
});
|
|
15597
|
+
rebuildResource(store, "uniforms", scope);
|
|
16380
15598
|
}
|
|
16381
15599
|
function removeUniforms(set, names, scope) {
|
|
16382
15600
|
set((state) => {
|
|
@@ -16440,191 +15658,91 @@ function isSameThreeType(a, b) {
|
|
|
16440
15658
|
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;
|
|
16441
15659
|
}
|
|
16442
15660
|
|
|
15661
|
+
const uniformOf = tsl.uniform;
|
|
16443
15662
|
const isUniformNode = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
16444
15663
|
const isTSLNode$1 = (value) => value !== null && typeof value === "object" && "uuid" in value && "nodeType" in value;
|
|
16445
15664
|
function useUniform(name, value) {
|
|
16446
15665
|
const store = useStore();
|
|
16447
|
-
const
|
|
16448
|
-
|
|
16449
|
-
|
|
16450
|
-
|
|
16451
|
-
|
|
16452
|
-
|
|
15666
|
+
const registered = useScopedResource({
|
|
15667
|
+
store,
|
|
15668
|
+
kind: "uniforms",
|
|
15669
|
+
scope: void 0,
|
|
15670
|
+
isLeaf: isUniformNode,
|
|
15671
|
+
input: name,
|
|
15672
|
+
create: () => value === void 0 ? {} : { [name]: value },
|
|
15673
|
+
prepare: createNamedUniform,
|
|
15674
|
+
reconcile: (existing2) => {
|
|
16453
15675
|
if (value !== void 0 && !isTSLNode$1(value) && !isUniformNode(value)) {
|
|
16454
|
-
|
|
15676
|
+
existing2.value = typeof value === "string" ? new webgpu.Color(value) : value;
|
|
16455
15677
|
}
|
|
16456
|
-
return existing;
|
|
16457
|
-
}
|
|
16458
|
-
if (value === void 0) {
|
|
16459
|
-
throw new Error(
|
|
16460
|
-
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
16461
|
-
);
|
|
16462
|
-
}
|
|
16463
|
-
if (isUniformNode(value)) {
|
|
16464
|
-
const node2 = value;
|
|
16465
|
-
if (typeof node2.setName === "function") {
|
|
16466
|
-
node2.setName(name);
|
|
16467
|
-
}
|
|
16468
|
-
set((s) => ({
|
|
16469
|
-
uniforms: { ...s.uniforms, [name]: node2 }
|
|
16470
|
-
}));
|
|
16471
|
-
return node2;
|
|
16472
|
-
}
|
|
16473
|
-
let node;
|
|
16474
|
-
if (isTSLNode$1(value)) {
|
|
16475
|
-
node = tsl.uniform(value);
|
|
16476
|
-
} else if (typeof value === "string") {
|
|
16477
|
-
node = tsl.uniform(new webgpu.Color(value));
|
|
16478
|
-
} else {
|
|
16479
|
-
node = tsl.uniform(value);
|
|
16480
|
-
}
|
|
16481
|
-
if (typeof node.setName === "function") {
|
|
16482
|
-
node.setName(name);
|
|
16483
15678
|
}
|
|
16484
|
-
|
|
16485
|
-
|
|
16486
|
-
|
|
16487
|
-
|
|
16488
|
-
|
|
16489
|
-
})
|
|
16490
|
-
|
|
16491
|
-
|
|
15679
|
+
});
|
|
15680
|
+
if (registered[name]) return registered[name];
|
|
15681
|
+
const existing = peekStaged(store, "uniforms", ROOT_SCOPE)?.[name] ?? store.getState().uniforms[name];
|
|
15682
|
+
if (existing && isUniformNode(existing)) return existing;
|
|
15683
|
+
throw new Error(
|
|
15684
|
+
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15685
|
+
);
|
|
15686
|
+
}
|
|
15687
|
+
function createNamedUniform(name, value) {
|
|
15688
|
+
let node;
|
|
15689
|
+
if (isUniformNode(value)) {
|
|
15690
|
+
node = value;
|
|
15691
|
+
} else if (isTSLNode$1(value)) {
|
|
15692
|
+
node = uniformOf(value);
|
|
15693
|
+
} else if (typeof value === "string") {
|
|
15694
|
+
node = tsl.uniform(new webgpu.Color(value));
|
|
15695
|
+
} else {
|
|
15696
|
+
node = uniformOf(value);
|
|
15697
|
+
}
|
|
15698
|
+
if (typeof node.setName === "function") {
|
|
15699
|
+
node.setName(name);
|
|
15700
|
+
}
|
|
15701
|
+
return node;
|
|
16492
15702
|
}
|
|
16493
15703
|
|
|
16494
15704
|
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
16495
15705
|
function useNodes(creatorOrScope, scope) {
|
|
16496
|
-
const store =
|
|
15706
|
+
const store = usePrimaryStore();
|
|
16497
15707
|
const removeNodes2 = React.useCallback(
|
|
16498
|
-
(names, targetScope) =>
|
|
16499
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16500
|
-
store.setState((state) => {
|
|
16501
|
-
if (targetScope) {
|
|
16502
|
-
const currentScope = { ...state.nodes[targetScope] };
|
|
16503
|
-
for (const name of nameArray) delete currentScope[name];
|
|
16504
|
-
return { nodes: { ...state.nodes, [targetScope]: currentScope } };
|
|
16505
|
-
}
|
|
16506
|
-
const nodes2 = { ...state.nodes };
|
|
16507
|
-
for (const name of nameArray) if (isTSLNode(nodes2[name])) delete nodes2[name];
|
|
16508
|
-
return { nodes: nodes2 };
|
|
16509
|
-
});
|
|
16510
|
-
},
|
|
15708
|
+
(names, targetScope) => removeResourceEntries(store, "nodes", Array.isArray(names) ? names : [names], targetScope, isTSLNode),
|
|
16511
15709
|
[store]
|
|
16512
15710
|
);
|
|
16513
15711
|
const clearNodes = React.useCallback(
|
|
16514
|
-
(targetScope) =>
|
|
16515
|
-
store.setState((state) => {
|
|
16516
|
-
if (targetScope && targetScope !== "root") {
|
|
16517
|
-
const { [targetScope]: _, ...rest } = state.nodes;
|
|
16518
|
-
return { nodes: rest };
|
|
16519
|
-
}
|
|
16520
|
-
if (targetScope === "root") {
|
|
16521
|
-
const nodes2 = {};
|
|
16522
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
16523
|
-
if (!isTSLNode(value)) nodes2[key] = value;
|
|
16524
|
-
}
|
|
16525
|
-
return { nodes: nodes2 };
|
|
16526
|
-
}
|
|
16527
|
-
return { nodes: {} };
|
|
16528
|
-
});
|
|
16529
|
-
},
|
|
15712
|
+
(targetScope) => clearResourceEntries(store, "nodes", targetScope, isTSLNode),
|
|
16530
15713
|
[store]
|
|
16531
15714
|
);
|
|
16532
15715
|
const rebuildNodes = React.useCallback(
|
|
16533
|
-
(targetScope) =>
|
|
16534
|
-
store.setState((state) => {
|
|
16535
|
-
let newNodes = state.nodes;
|
|
16536
|
-
if (targetScope && targetScope !== "root") {
|
|
16537
|
-
const { [targetScope]: _, ...rest } = state.nodes;
|
|
16538
|
-
newNodes = rest;
|
|
16539
|
-
} else if (targetScope === "root") {
|
|
16540
|
-
newNodes = {};
|
|
16541
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
16542
|
-
if (!isTSLNode(value)) newNodes[key] = value;
|
|
16543
|
-
}
|
|
16544
|
-
} else {
|
|
16545
|
-
newNodes = {};
|
|
16546
|
-
}
|
|
16547
|
-
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
16548
|
-
});
|
|
16549
|
-
},
|
|
15716
|
+
(targetScope) => rebuildResource(store, "nodes", targetScope),
|
|
16550
15717
|
[store]
|
|
16551
15718
|
);
|
|
16552
15719
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16553
|
-
const storeNodes =
|
|
16554
|
-
const
|
|
16555
|
-
|
|
16556
|
-
|
|
16557
|
-
|
|
16558
|
-
|
|
16559
|
-
|
|
16560
|
-
return
|
|
16561
|
-
|
|
16562
|
-
|
|
16563
|
-
|
|
16564
|
-
|
|
16565
|
-
return
|
|
16566
|
-
}
|
|
16567
|
-
const state = store.getState();
|
|
16568
|
-
const set = store.setState;
|
|
16569
|
-
const creator = creatorOrScope;
|
|
16570
|
-
const wrappedState = createLazyCreatorState(state);
|
|
16571
|
-
const created = creator(wrappedState);
|
|
16572
|
-
const result = {};
|
|
16573
|
-
let hasNewNodes = false;
|
|
16574
|
-
if (scope) {
|
|
16575
|
-
const currentScope = state.nodes[scope] ?? {};
|
|
16576
|
-
for (const [name, node] of Object.entries(created)) {
|
|
16577
|
-
if (currentScope[name]) {
|
|
16578
|
-
result[name] = currentScope[name];
|
|
16579
|
-
} else {
|
|
16580
|
-
node.setName?.(`${scope}.${name}`);
|
|
16581
|
-
result[name] = node;
|
|
16582
|
-
hasNewNodes = true;
|
|
16583
|
-
}
|
|
16584
|
-
}
|
|
16585
|
-
if (hasNewNodes) {
|
|
16586
|
-
set((s) => ({
|
|
16587
|
-
nodes: {
|
|
16588
|
-
...s.nodes,
|
|
16589
|
-
[scope]: { ...s.nodes[scope], ...result }
|
|
16590
|
-
}
|
|
16591
|
-
}));
|
|
16592
|
-
}
|
|
16593
|
-
return result;
|
|
16594
|
-
}
|
|
16595
|
-
for (const [name, node] of Object.entries(created)) {
|
|
16596
|
-
const existing = state.nodes[name];
|
|
16597
|
-
if (existing && isTSLNode(existing)) {
|
|
16598
|
-
result[name] = existing;
|
|
16599
|
-
} else {
|
|
16600
|
-
node.setName?.(name);
|
|
16601
|
-
result[name] = node;
|
|
16602
|
-
hasNewNodes = true;
|
|
16603
|
-
}
|
|
16604
|
-
}
|
|
16605
|
-
if (hasNewNodes) {
|
|
16606
|
-
set((s) => ({ nodes: { ...s.nodes, ...result } }));
|
|
15720
|
+
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15721
|
+
const created = useScopedResource({
|
|
15722
|
+
store,
|
|
15723
|
+
kind: "nodes",
|
|
15724
|
+
scope: isReader ? void 0 : scope,
|
|
15725
|
+
isLeaf: isTSLNode,
|
|
15726
|
+
create: () => {
|
|
15727
|
+
if (isReader) return {};
|
|
15728
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15729
|
+
},
|
|
15730
|
+
prepare: (name, node) => {
|
|
15731
|
+
node.setName?.(scope ? `${scope}.${name}` : name);
|
|
15732
|
+
return node;
|
|
16607
15733
|
}
|
|
16608
|
-
|
|
16609
|
-
|
|
15734
|
+
});
|
|
15735
|
+
let nodes = created;
|
|
15736
|
+
if (creatorOrScope === void 0) {
|
|
15737
|
+
nodes = storeNodes;
|
|
15738
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15739
|
+
const scopeData = storeNodes[creatorOrScope];
|
|
15740
|
+
nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
|
|
15741
|
+
}
|
|
16610
15742
|
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
16611
15743
|
}
|
|
16612
15744
|
function rebuildAllNodes(store, scope) {
|
|
16613
|
-
store
|
|
16614
|
-
let newNodes = state.nodes;
|
|
16615
|
-
if (scope && scope !== "root") {
|
|
16616
|
-
const { [scope]: _, ...rest } = state.nodes;
|
|
16617
|
-
newNodes = rest;
|
|
16618
|
-
} else if (scope === "root") {
|
|
16619
|
-
newNodes = {};
|
|
16620
|
-
for (const [key, value] of Object.entries(state.nodes)) {
|
|
16621
|
-
if (!isTSLNode(value)) newNodes[key] = value;
|
|
16622
|
-
}
|
|
16623
|
-
} else {
|
|
16624
|
-
newNodes = {};
|
|
16625
|
-
}
|
|
16626
|
-
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
16627
|
-
});
|
|
15745
|
+
rebuildResource(store, "nodes", scope);
|
|
16628
15746
|
}
|
|
16629
15747
|
function removeNodes(set, names, scope) {
|
|
16630
15748
|
set((state) => {
|
|
@@ -16654,13 +15772,13 @@ function clearRootNodes(set) {
|
|
|
16654
15772
|
});
|
|
16655
15773
|
}
|
|
16656
15774
|
function useLocalNodes(creator) {
|
|
16657
|
-
const store =
|
|
16658
|
-
const uniforms =
|
|
16659
|
-
const nodes =
|
|
16660
|
-
const textures =
|
|
16661
|
-
const hmrVersion =
|
|
15775
|
+
const store = usePrimaryStore();
|
|
15776
|
+
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15777
|
+
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15778
|
+
const textures = usePrimaryThree((s) => s.textures);
|
|
15779
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16662
15780
|
return React.useMemo(() => {
|
|
16663
|
-
const wrappedState = createLazyCreatorState(store.getState());
|
|
15781
|
+
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
16664
15782
|
return creator(wrappedState);
|
|
16665
15783
|
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
16666
15784
|
}
|
|
@@ -16679,60 +15797,17 @@ const disposeBuffer = (buffer) => {
|
|
|
16679
15797
|
}
|
|
16680
15798
|
};
|
|
16681
15799
|
function useBuffers(creatorOrScope, scope) {
|
|
16682
|
-
const store =
|
|
15800
|
+
const store = usePrimaryStore();
|
|
16683
15801
|
const removeBuffers = React.useCallback(
|
|
16684
|
-
(names, targetScope) =>
|
|
16685
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16686
|
-
store.setState((state) => {
|
|
16687
|
-
if (targetScope) {
|
|
16688
|
-
const currentScope = { ...state.buffers[targetScope] };
|
|
16689
|
-
for (const name of nameArray) delete currentScope[name];
|
|
16690
|
-
return { buffers: { ...state.buffers, [targetScope]: currentScope } };
|
|
16691
|
-
}
|
|
16692
|
-
const buffers2 = { ...state.buffers };
|
|
16693
|
-
for (const name of nameArray) if (isBufferLike(buffers2[name])) delete buffers2[name];
|
|
16694
|
-
return { buffers: buffers2 };
|
|
16695
|
-
});
|
|
16696
|
-
},
|
|
15802
|
+
(names, targetScope) => removeResourceEntries(store, "buffers", Array.isArray(names) ? names : [names], targetScope, isBufferLike),
|
|
16697
15803
|
[store]
|
|
16698
15804
|
);
|
|
16699
15805
|
const clearBuffers = React.useCallback(
|
|
16700
|
-
(targetScope) =>
|
|
16701
|
-
store.setState((state) => {
|
|
16702
|
-
if (targetScope && targetScope !== "root") {
|
|
16703
|
-
const { [targetScope]: _, ...rest } = state.buffers;
|
|
16704
|
-
return { buffers: rest };
|
|
16705
|
-
}
|
|
16706
|
-
if (targetScope === "root") {
|
|
16707
|
-
const buffers2 = {};
|
|
16708
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
16709
|
-
if (!isBufferLike(value)) buffers2[key] = value;
|
|
16710
|
-
}
|
|
16711
|
-
return { buffers: buffers2 };
|
|
16712
|
-
}
|
|
16713
|
-
return { buffers: {} };
|
|
16714
|
-
});
|
|
16715
|
-
},
|
|
15806
|
+
(targetScope) => clearResourceEntries(store, "buffers", targetScope, isBufferLike),
|
|
16716
15807
|
[store]
|
|
16717
15808
|
);
|
|
16718
15809
|
const rebuildBuffers = React.useCallback(
|
|
16719
|
-
(targetScope) =>
|
|
16720
|
-
store.setState((state) => {
|
|
16721
|
-
let newBuffers = state.buffers;
|
|
16722
|
-
if (targetScope && targetScope !== "root") {
|
|
16723
|
-
const { [targetScope]: _, ...rest } = state.buffers;
|
|
16724
|
-
newBuffers = rest;
|
|
16725
|
-
} else if (targetScope === "root") {
|
|
16726
|
-
newBuffers = {};
|
|
16727
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
16728
|
-
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
16729
|
-
}
|
|
16730
|
-
} else {
|
|
16731
|
-
newBuffers = {};
|
|
16732
|
-
}
|
|
16733
|
-
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
16734
|
-
});
|
|
16735
|
-
},
|
|
15810
|
+
(targetScope) => rebuildResource(store, "buffers", targetScope),
|
|
16736
15811
|
[store]
|
|
16737
15812
|
);
|
|
16738
15813
|
const disposeBuffers = React.useCallback(
|
|
@@ -16750,85 +15825,34 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
16750
15825
|
[store, removeBuffers]
|
|
16751
15826
|
);
|
|
16752
15827
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16753
|
-
const storeBuffers =
|
|
16754
|
-
const
|
|
16755
|
-
|
|
16756
|
-
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
return
|
|
16761
|
-
|
|
16762
|
-
|
|
16763
|
-
|
|
16764
|
-
if (
|
|
16765
|
-
|
|
16766
|
-
}
|
|
16767
|
-
const state = store.getState();
|
|
16768
|
-
const set = store.setState;
|
|
16769
|
-
const creator = creatorOrScope;
|
|
16770
|
-
const wrappedState = createLazyCreatorState(state);
|
|
16771
|
-
const created = creator(wrappedState);
|
|
16772
|
-
const result = {};
|
|
16773
|
-
let hasNewBuffers = false;
|
|
16774
|
-
if (scope) {
|
|
16775
|
-
const currentScope = state.buffers[scope] ?? {};
|
|
16776
|
-
for (const [name, buffer] of Object.entries(created)) {
|
|
16777
|
-
if (currentScope[name]) {
|
|
16778
|
-
result[name] = currentScope[name];
|
|
16779
|
-
} else {
|
|
16780
|
-
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
16781
|
-
buffer.setName(`${scope}.${name}`);
|
|
16782
|
-
}
|
|
16783
|
-
result[name] = buffer;
|
|
16784
|
-
hasNewBuffers = true;
|
|
16785
|
-
}
|
|
16786
|
-
}
|
|
16787
|
-
if (hasNewBuffers) {
|
|
16788
|
-
set((s) => ({
|
|
16789
|
-
buffers: {
|
|
16790
|
-
...s.buffers,
|
|
16791
|
-
[scope]: { ...s.buffers[scope], ...result }
|
|
16792
|
-
}
|
|
16793
|
-
}));
|
|
16794
|
-
}
|
|
16795
|
-
return result;
|
|
16796
|
-
}
|
|
16797
|
-
for (const [name, buffer] of Object.entries(created)) {
|
|
16798
|
-
const existing = state.buffers[name];
|
|
16799
|
-
if (existing && isBufferLike(existing)) {
|
|
16800
|
-
result[name] = existing;
|
|
16801
|
-
} else {
|
|
16802
|
-
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
16803
|
-
buffer.setName(name);
|
|
16804
|
-
}
|
|
16805
|
-
result[name] = buffer;
|
|
16806
|
-
hasNewBuffers = true;
|
|
15828
|
+
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15829
|
+
const created = useScopedResource({
|
|
15830
|
+
store,
|
|
15831
|
+
kind: "buffers",
|
|
15832
|
+
scope: isReader ? void 0 : scope,
|
|
15833
|
+
isLeaf: isBufferLike,
|
|
15834
|
+
create: () => {
|
|
15835
|
+
if (isReader) return {};
|
|
15836
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15837
|
+
},
|
|
15838
|
+
prepare: (name, buffer) => {
|
|
15839
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15840
|
+
buffer.setName(scope ? `${scope}.${name}` : name);
|
|
16807
15841
|
}
|
|
15842
|
+
return buffer;
|
|
16808
15843
|
}
|
|
16809
|
-
|
|
16810
|
-
|
|
16811
|
-
|
|
16812
|
-
|
|
16813
|
-
}
|
|
15844
|
+
});
|
|
15845
|
+
let buffers = created;
|
|
15846
|
+
if (creatorOrScope === void 0) {
|
|
15847
|
+
buffers = storeBuffers;
|
|
15848
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15849
|
+
const scopeData = storeBuffers[creatorOrScope];
|
|
15850
|
+
buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
|
|
15851
|
+
}
|
|
16814
15852
|
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
16815
15853
|
}
|
|
16816
15854
|
function rebuildAllBuffers(store, scope) {
|
|
16817
|
-
store
|
|
16818
|
-
let newBuffers = state.buffers;
|
|
16819
|
-
if (scope && scope !== "root") {
|
|
16820
|
-
const { [scope]: _, ...rest } = state.buffers;
|
|
16821
|
-
newBuffers = rest;
|
|
16822
|
-
} else if (scope === "root") {
|
|
16823
|
-
newBuffers = {};
|
|
16824
|
-
for (const [key, value] of Object.entries(state.buffers)) {
|
|
16825
|
-
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
16826
|
-
}
|
|
16827
|
-
} else {
|
|
16828
|
-
newBuffers = {};
|
|
16829
|
-
}
|
|
16830
|
-
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
16831
|
-
});
|
|
15855
|
+
rebuildResource(store, "buffers", scope);
|
|
16832
15856
|
}
|
|
16833
15857
|
|
|
16834
15858
|
const isStorageLike = (value) => {
|
|
@@ -16845,60 +15869,17 @@ const disposeStorage = (storage) => {
|
|
|
16845
15869
|
}
|
|
16846
15870
|
};
|
|
16847
15871
|
function useGPUStorage(creatorOrScope, scope) {
|
|
16848
|
-
const store =
|
|
15872
|
+
const store = usePrimaryStore();
|
|
16849
15873
|
const removeStorage = React.useCallback(
|
|
16850
|
-
(names, targetScope) =>
|
|
16851
|
-
const nameArray = Array.isArray(names) ? names : [names];
|
|
16852
|
-
store.setState((state) => {
|
|
16853
|
-
if (targetScope) {
|
|
16854
|
-
const currentScope = { ...state.gpuStorage[targetScope] };
|
|
16855
|
-
for (const name of nameArray) delete currentScope[name];
|
|
16856
|
-
return { gpuStorage: { ...state.gpuStorage, [targetScope]: currentScope } };
|
|
16857
|
-
}
|
|
16858
|
-
const gpuStorage2 = { ...state.gpuStorage };
|
|
16859
|
-
for (const name of nameArray) if (isStorageLike(gpuStorage2[name])) delete gpuStorage2[name];
|
|
16860
|
-
return { gpuStorage: gpuStorage2 };
|
|
16861
|
-
});
|
|
16862
|
-
},
|
|
15874
|
+
(names, targetScope) => removeResourceEntries(store, "gpuStorage", Array.isArray(names) ? names : [names], targetScope, isStorageLike),
|
|
16863
15875
|
[store]
|
|
16864
15876
|
);
|
|
16865
15877
|
const clearStorage = React.useCallback(
|
|
16866
|
-
(targetScope) =>
|
|
16867
|
-
store.setState((state) => {
|
|
16868
|
-
if (targetScope && targetScope !== "root") {
|
|
16869
|
-
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
16870
|
-
return { gpuStorage: rest };
|
|
16871
|
-
}
|
|
16872
|
-
if (targetScope === "root") {
|
|
16873
|
-
const gpuStorage2 = {};
|
|
16874
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
16875
|
-
if (!isStorageLike(value)) gpuStorage2[key] = value;
|
|
16876
|
-
}
|
|
16877
|
-
return { gpuStorage: gpuStorage2 };
|
|
16878
|
-
}
|
|
16879
|
-
return { gpuStorage: {} };
|
|
16880
|
-
});
|
|
16881
|
-
},
|
|
15878
|
+
(targetScope) => clearResourceEntries(store, "gpuStorage", targetScope, isStorageLike),
|
|
16882
15879
|
[store]
|
|
16883
15880
|
);
|
|
16884
15881
|
const rebuildStorage = React.useCallback(
|
|
16885
|
-
(targetScope) =>
|
|
16886
|
-
store.setState((state) => {
|
|
16887
|
-
let newStorage = state.gpuStorage;
|
|
16888
|
-
if (targetScope && targetScope !== "root") {
|
|
16889
|
-
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
16890
|
-
newStorage = rest;
|
|
16891
|
-
} else if (targetScope === "root") {
|
|
16892
|
-
newStorage = {};
|
|
16893
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
16894
|
-
if (!isStorageLike(value)) newStorage[key] = value;
|
|
16895
|
-
}
|
|
16896
|
-
} else {
|
|
16897
|
-
newStorage = {};
|
|
16898
|
-
}
|
|
16899
|
-
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
16900
|
-
});
|
|
16901
|
-
},
|
|
15882
|
+
(targetScope) => rebuildResource(store, "gpuStorage", targetScope),
|
|
16902
15883
|
[store]
|
|
16903
15884
|
);
|
|
16904
15885
|
const disposeStorageFn = React.useCallback(
|
|
@@ -16916,73 +15897,34 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
16916
15897
|
[store, removeStorage]
|
|
16917
15898
|
);
|
|
16918
15899
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16919
|
-
const storeStorage =
|
|
16920
|
-
const
|
|
16921
|
-
|
|
16922
|
-
|
|
16923
|
-
|
|
16924
|
-
|
|
16925
|
-
|
|
16926
|
-
return
|
|
16927
|
-
|
|
16928
|
-
|
|
16929
|
-
|
|
16930
|
-
|
|
16931
|
-
|
|
16932
|
-
|
|
16933
|
-
const state = store.getState();
|
|
16934
|
-
const set = store.setState;
|
|
16935
|
-
const creator = creatorOrScope;
|
|
16936
|
-
const wrappedState = createLazyCreatorState(state);
|
|
16937
|
-
const created = creator(wrappedState);
|
|
16938
|
-
const result = {};
|
|
16939
|
-
let hasNewStorage = false;
|
|
16940
|
-
if (scope) {
|
|
16941
|
-
const currentScope = state.gpuStorage[scope] ?? {};
|
|
16942
|
-
for (const [name, storage] of Object.entries(created)) {
|
|
16943
|
-
if (currentScope[name]) {
|
|
16944
|
-
result[name] = currentScope[name];
|
|
16945
|
-
} else {
|
|
16946
|
-
if ("setName" in storage && typeof storage.setName === "function") {
|
|
16947
|
-
storage.setName(`${scope}.${name}`);
|
|
16948
|
-
}
|
|
16949
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
16950
|
-
storage.name = `${scope}.${name}`;
|
|
16951
|
-
}
|
|
16952
|
-
result[name] = storage;
|
|
16953
|
-
hasNewStorage = true;
|
|
16954
|
-
}
|
|
16955
|
-
}
|
|
16956
|
-
if (hasNewStorage) {
|
|
16957
|
-
set((s) => ({
|
|
16958
|
-
gpuStorage: {
|
|
16959
|
-
...s.gpuStorage,
|
|
16960
|
-
[scope]: { ...s.gpuStorage[scope], ...result }
|
|
16961
|
-
}
|
|
16962
|
-
}));
|
|
15900
|
+
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
15901
|
+
const created = useScopedResource({
|
|
15902
|
+
store,
|
|
15903
|
+
kind: "gpuStorage",
|
|
15904
|
+
scope: isReader ? void 0 : scope,
|
|
15905
|
+
isLeaf: isStorageLike,
|
|
15906
|
+
create: () => {
|
|
15907
|
+
if (isReader) return {};
|
|
15908
|
+
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15909
|
+
},
|
|
15910
|
+
prepare: (name, storage) => {
|
|
15911
|
+
const label = scope ? `${scope}.${name}` : name;
|
|
15912
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15913
|
+
storage.setName(label);
|
|
16963
15914
|
}
|
|
16964
|
-
|
|
16965
|
-
|
|
16966
|
-
for (const [name, storage] of Object.entries(created)) {
|
|
16967
|
-
const existing = state.gpuStorage[name];
|
|
16968
|
-
if (existing && isStorageLike(existing)) {
|
|
16969
|
-
result[name] = existing;
|
|
16970
|
-
} else {
|
|
16971
|
-
if ("setName" in storage && typeof storage.setName === "function") {
|
|
16972
|
-
storage.setName(name);
|
|
16973
|
-
}
|
|
16974
|
-
if ("name" in storage && typeof storage.name === "string") {
|
|
16975
|
-
storage.name = name;
|
|
16976
|
-
}
|
|
16977
|
-
result[name] = storage;
|
|
16978
|
-
hasNewStorage = true;
|
|
15915
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
15916
|
+
storage.name = label;
|
|
16979
15917
|
}
|
|
15918
|
+
return storage;
|
|
16980
15919
|
}
|
|
16981
|
-
|
|
16982
|
-
|
|
16983
|
-
|
|
16984
|
-
|
|
16985
|
-
}
|
|
15920
|
+
});
|
|
15921
|
+
let gpuStorage = created;
|
|
15922
|
+
if (creatorOrScope === void 0) {
|
|
15923
|
+
gpuStorage = storeStorage;
|
|
15924
|
+
} else if (typeof creatorOrScope === "string") {
|
|
15925
|
+
const scopeData = storeStorage[creatorOrScope];
|
|
15926
|
+
gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
|
|
15927
|
+
}
|
|
16986
15928
|
return {
|
|
16987
15929
|
...gpuStorage,
|
|
16988
15930
|
removeStorage,
|
|
@@ -16992,21 +15934,7 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
16992
15934
|
};
|
|
16993
15935
|
}
|
|
16994
15936
|
function rebuildAllStorage(store, scope) {
|
|
16995
|
-
store
|
|
16996
|
-
let newStorage = state.gpuStorage;
|
|
16997
|
-
if (scope && scope !== "root") {
|
|
16998
|
-
const { [scope]: _, ...rest } = state.gpuStorage;
|
|
16999
|
-
newStorage = rest;
|
|
17000
|
-
} else if (scope === "root") {
|
|
17001
|
-
newStorage = {};
|
|
17002
|
-
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
17003
|
-
if (!isStorageLike(value)) newStorage[key] = value;
|
|
17004
|
-
}
|
|
17005
|
-
} else {
|
|
17006
|
-
newStorage = {};
|
|
17007
|
-
}
|
|
17008
|
-
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
17009
|
-
});
|
|
15937
|
+
rebuildResource(store, "gpuStorage", scope);
|
|
17010
15938
|
}
|
|
17011
15939
|
|
|
17012
15940
|
function useRenderPipeline(mainCB, setupCB) {
|
|
@@ -17047,12 +15975,12 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
17047
15975
|
const state = store.getState();
|
|
17048
15976
|
const set = store.setState;
|
|
17049
15977
|
try {
|
|
17050
|
-
let
|
|
15978
|
+
let pipeline = state.renderPipeline;
|
|
17051
15979
|
let currentPasses = { ...state.passes };
|
|
17052
|
-
let
|
|
17053
|
-
if (!
|
|
17054
|
-
|
|
17055
|
-
|
|
15980
|
+
let justCreatedPipeline = false;
|
|
15981
|
+
if (!pipeline) {
|
|
15982
|
+
pipeline = new webgpu.RenderPipeline(renderer);
|
|
15983
|
+
justCreatedPipeline = true;
|
|
17056
15984
|
}
|
|
17057
15985
|
const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
17058
15986
|
let scenePass;
|
|
@@ -17063,9 +15991,9 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
17063
15991
|
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
17064
15992
|
}
|
|
17065
15993
|
currentPasses.scenePass = scenePass;
|
|
17066
|
-
if (!
|
|
17067
|
-
set({ renderPipeline:
|
|
17068
|
-
const shouldRunCallbacks =
|
|
15994
|
+
if (!pipeline.outputNode || justCreatedPipeline) pipeline.outputNode = scenePass;
|
|
15995
|
+
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
15996
|
+
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
17069
15997
|
if (shouldRunCallbacks) {
|
|
17070
15998
|
if (setupCBRef.current) {
|
|
17071
15999
|
const freshState = store.getState();
|
|
@@ -17086,7 +16014,7 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
17086
16014
|
callbacksRanRef.current = true;
|
|
17087
16015
|
}
|
|
17088
16016
|
} catch (error) {
|
|
17089
|
-
console.
|
|
16017
|
+
console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
|
|
17090
16018
|
}
|
|
17091
16019
|
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
17092
16020
|
const passes = useThree((s) => s.passes);
|
|
@@ -17104,6 +16032,8 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
17104
16032
|
|
|
17105
16033
|
extend(THREE);
|
|
17106
16034
|
|
|
16035
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
16036
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
17107
16037
|
exports.Block = Block;
|
|
17108
16038
|
exports.Canvas = Canvas;
|
|
17109
16039
|
exports.Environment = Environment;
|
|
@@ -17119,7 +16049,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
17119
16049
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
17120
16050
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
17121
16051
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
17122
|
-
exports.Scheduler = Scheduler;
|
|
17123
16052
|
exports.Texture = Texture;
|
|
17124
16053
|
exports._roots = _roots;
|
|
17125
16054
|
exports.act = act;
|
|
@@ -17155,7 +16084,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
17155
16084
|
exports.getPrimary = getPrimary;
|
|
17156
16085
|
exports.getPrimaryIds = getPrimaryIds;
|
|
17157
16086
|
exports.getRootState = getRootState;
|
|
17158
|
-
exports.getScheduler = getScheduler;
|
|
17159
16087
|
exports.getUuidPrefix = getUuidPrefix;
|
|
17160
16088
|
exports.hasConstructor = hasConstructor;
|
|
17161
16089
|
exports.hasPrimary = hasPrimary;
|