@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/legacy.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js'
|
|
|
13
13
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
14
14
|
const Tb = require('scheduler');
|
|
15
15
|
const traditional = require('zustand/traditional');
|
|
16
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
16
17
|
const suspendReact = require('suspend-react');
|
|
17
18
|
|
|
18
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -61,9 +62,12 @@ const WebGPURenderer = class WebGPURenderer2 {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
const RenderTarget = null;
|
|
65
|
+
const CubeRenderTarget = null;
|
|
64
66
|
|
|
65
67
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
66
68
|
__proto__: null,
|
|
69
|
+
CubeRenderTarget: CubeRenderTarget,
|
|
70
|
+
CubeRenderTargetCompat: three.WebGLCubeRenderTarget,
|
|
67
71
|
Inspector: Inspector,
|
|
68
72
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
69
73
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
@@ -341,15 +345,16 @@ function EnvironmentPortal({
|
|
|
341
345
|
preset = void 0,
|
|
342
346
|
extensions
|
|
343
347
|
}) {
|
|
344
|
-
const
|
|
348
|
+
const renderer = fiber.useThree((state) => state.renderer);
|
|
349
|
+
const isLegacy = fiber.useThree((state) => state.isLegacy);
|
|
345
350
|
const defaultScene = fiber.useThree((state) => state.scene);
|
|
346
351
|
const camera = React__namespace.useRef(null);
|
|
347
352
|
const [virtualScene] = React__namespace.useState(() => new three.Scene());
|
|
348
353
|
const fbo = React__namespace.useMemo(() => {
|
|
349
|
-
const fbo2 = new three.WebGLCubeRenderTarget(resolution);
|
|
354
|
+
const fbo2 = isLegacy ? new three.WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
|
|
350
355
|
fbo2.texture.type = three.HalfFloatType;
|
|
351
356
|
return fbo2;
|
|
352
|
-
}, [resolution]);
|
|
357
|
+
}, [resolution, isLegacy]);
|
|
353
358
|
React__namespace.useEffect(() => {
|
|
354
359
|
return () => {
|
|
355
360
|
fbo.dispose();
|
|
@@ -357,10 +362,10 @@ function EnvironmentPortal({
|
|
|
357
362
|
}, [fbo]);
|
|
358
363
|
React__namespace.useLayoutEffect(() => {
|
|
359
364
|
if (frames === 1) {
|
|
360
|
-
const autoClear =
|
|
361
|
-
|
|
362
|
-
camera.current.update(
|
|
363
|
-
|
|
365
|
+
const autoClear = renderer.autoClear;
|
|
366
|
+
renderer.autoClear = true;
|
|
367
|
+
camera.current.update(renderer, virtualScene);
|
|
368
|
+
renderer.autoClear = autoClear;
|
|
364
369
|
}
|
|
365
370
|
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
366
371
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
@@ -377,7 +382,7 @@ function EnvironmentPortal({
|
|
|
377
382
|
defaultScene,
|
|
378
383
|
background,
|
|
379
384
|
frames,
|
|
380
|
-
|
|
385
|
+
renderer,
|
|
381
386
|
blur,
|
|
382
387
|
backgroundBlurriness,
|
|
383
388
|
backgroundIntensity,
|
|
@@ -388,10 +393,10 @@ function EnvironmentPortal({
|
|
|
388
393
|
let count = 1;
|
|
389
394
|
fiber.useFrame(() => {
|
|
390
395
|
if (frames === Infinity || count < frames) {
|
|
391
|
-
const autoClear =
|
|
392
|
-
|
|
393
|
-
camera.current.update(
|
|
394
|
-
|
|
396
|
+
const autoClear = renderer.autoClear;
|
|
397
|
+
renderer.autoClear = true;
|
|
398
|
+
camera.current.update(renderer, virtualScene);
|
|
399
|
+
renderer.autoClear = autoClear;
|
|
395
400
|
count++;
|
|
396
401
|
}
|
|
397
402
|
});
|
|
@@ -455,9 +460,9 @@ function Environment(props) {
|
|
|
455
460
|
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 });
|
|
456
461
|
}
|
|
457
462
|
|
|
458
|
-
var __defProp
|
|
459
|
-
var __defNormalProp
|
|
460
|
-
var __publicField
|
|
463
|
+
var __defProp = Object.defineProperty;
|
|
464
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
465
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
461
466
|
const act = React__namespace["act"];
|
|
462
467
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
463
468
|
function useMutableCallback(fn) {
|
|
@@ -489,7 +494,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
489
494
|
return _a = class extends React__namespace.Component {
|
|
490
495
|
constructor() {
|
|
491
496
|
super(...arguments);
|
|
492
|
-
__publicField
|
|
497
|
+
__publicField(this, "state", { error: false });
|
|
493
498
|
}
|
|
494
499
|
componentDidCatch(err) {
|
|
495
500
|
this.props.set(err);
|
|
@@ -497,7 +502,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
497
502
|
render() {
|
|
498
503
|
return this.state.error ? null : this.props.children;
|
|
499
504
|
}
|
|
500
|
-
}, __publicField
|
|
505
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
501
506
|
})();
|
|
502
507
|
|
|
503
508
|
const is = {
|
|
@@ -634,8 +639,7 @@ function prepare(target, root, type, props) {
|
|
|
634
639
|
object,
|
|
635
640
|
eventCount: 0,
|
|
636
641
|
handlers: {},
|
|
637
|
-
isHidden: false
|
|
638
|
-
deferredRefs: []
|
|
642
|
+
isHidden: false
|
|
639
643
|
};
|
|
640
644
|
if (object) object.__r3f = instance;
|
|
641
645
|
}
|
|
@@ -792,6 +796,17 @@ function unregisterVisibility(store, object) {
|
|
|
792
796
|
internal.visibilityRegistry.delete(object.uuid);
|
|
793
797
|
internal.occlusionCache.delete(object);
|
|
794
798
|
}
|
|
799
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
800
|
+
const { internal } = store.getState();
|
|
801
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
802
|
+
if (!entry) return false;
|
|
803
|
+
entry.handlers = handlers;
|
|
804
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
805
|
+
object.occlusionTest = true;
|
|
806
|
+
enableOcclusion(store);
|
|
807
|
+
}
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
795
810
|
function checkVisibility(state) {
|
|
796
811
|
const { internal, camera } = state;
|
|
797
812
|
const registry = internal.visibilityRegistry;
|
|
@@ -952,9 +967,9 @@ function diffProps(instance, newProps) {
|
|
|
952
967
|
const { root, key } = resolve(instance.object, prop);
|
|
953
968
|
if (root.constructor && root.constructor.length === 0) {
|
|
954
969
|
const ctor = getMemoizedPrototype(root);
|
|
955
|
-
if (!is.und(ctor)) changedProps[
|
|
970
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
956
971
|
} else {
|
|
957
|
-
changedProps[
|
|
972
|
+
changedProps[prop] = 0;
|
|
958
973
|
}
|
|
959
974
|
}
|
|
960
975
|
return changedProps;
|
|
@@ -979,10 +994,7 @@ function applyProps(object, props) {
|
|
|
979
994
|
continue;
|
|
980
995
|
}
|
|
981
996
|
if (value === void 0) continue;
|
|
982
|
-
if (isFromRef(value))
|
|
983
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
997
|
+
if (isFromRef(value)) continue;
|
|
986
998
|
if (isOnce(value)) {
|
|
987
999
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
988
1000
|
if (instance) {
|
|
@@ -1018,6 +1030,19 @@ function applyProps(object, props) {
|
|
|
1018
1030
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1019
1031
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1020
1032
|
else target.set(value);
|
|
1033
|
+
} else if (root instanceof three.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1034
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1035
|
+
const uniforms = root.uniforms;
|
|
1036
|
+
const nextUniforms = value;
|
|
1037
|
+
for (const name in nextUniforms) {
|
|
1038
|
+
const uniform = nextUniforms[name];
|
|
1039
|
+
const targetUniform = uniforms[name];
|
|
1040
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1041
|
+
else {
|
|
1042
|
+
const nextUniform = uniform instanceof three.Uniform ? uniform.clone() : new three.Uniform(uniform.value);
|
|
1043
|
+
uniforms[name] = nextUniform;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1021
1046
|
} else {
|
|
1022
1047
|
root[key] = value;
|
|
1023
1048
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1036,6 +1061,9 @@ function applyProps(object, props) {
|
|
|
1036
1061
|
if (instance.eventCount && object2.raycast !== null) {
|
|
1037
1062
|
rootState.internal.interaction.push(object2);
|
|
1038
1063
|
}
|
|
1064
|
+
}
|
|
1065
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1066
|
+
const object2 = instance.object;
|
|
1039
1067
|
const root = findInitialRoot(instance);
|
|
1040
1068
|
const visibilityHandlers = {
|
|
1041
1069
|
onFramed: instance.handlers.onFramed,
|
|
@@ -1043,7 +1071,9 @@ function applyProps(object, props) {
|
|
|
1043
1071
|
onVisible: instance.handlers.onVisible
|
|
1044
1072
|
};
|
|
1045
1073
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
1046
|
-
|
|
1074
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1075
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1076
|
+
}
|
|
1047
1077
|
} else {
|
|
1048
1078
|
unregisterVisibility(root, object2);
|
|
1049
1079
|
}
|
|
@@ -1571,6 +1601,7 @@ function createPointerEvents(store) {
|
|
|
1571
1601
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1572
1602
|
}
|
|
1573
1603
|
},
|
|
1604
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1574
1605
|
registerPointer: (config) => {
|
|
1575
1606
|
const pointerId = nextXRPointerId++;
|
|
1576
1607
|
xrPointers.set(pointerId, config);
|
|
@@ -1657,1036 +1688,11 @@ function notifyAlpha({ message, link }) {
|
|
|
1657
1688
|
}
|
|
1658
1689
|
}
|
|
1659
1690
|
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
constructor() {
|
|
1666
|
-
/** Ordered list of phase nodes */
|
|
1667
|
-
__publicField$1(this, "phases", []);
|
|
1668
|
-
/** Quick lookup by name */
|
|
1669
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1670
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1671
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1672
|
-
this.initializeDefaultPhases();
|
|
1673
|
-
}
|
|
1674
|
-
//* Initialization --------------------------------
|
|
1675
|
-
initializeDefaultPhases() {
|
|
1676
|
-
for (const name of DEFAULT_PHASES) {
|
|
1677
|
-
const node = { name, isAutoGenerated: false };
|
|
1678
|
-
this.phases.push(node);
|
|
1679
|
-
this.phaseMap.set(name, node);
|
|
1680
|
-
}
|
|
1681
|
-
this.invalidateCache();
|
|
1682
|
-
}
|
|
1683
|
-
//* Public API --------------------------------
|
|
1684
|
-
/**
|
|
1685
|
-
* Add a named phase to the graph
|
|
1686
|
-
* @param name - Phase name (must be unique)
|
|
1687
|
-
* @param options - Position options (before or after another phase)
|
|
1688
|
-
*/
|
|
1689
|
-
addPhase(name, options = {}) {
|
|
1690
|
-
if (this.phaseMap.has(name)) {
|
|
1691
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1692
|
-
return;
|
|
1693
|
-
}
|
|
1694
|
-
const { before, after } = options;
|
|
1695
|
-
const node = { name, isAutoGenerated: false };
|
|
1696
|
-
let insertIndex = this.phases.length;
|
|
1697
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1698
|
-
if (targetIndex !== -1) {
|
|
1699
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1700
|
-
} else {
|
|
1701
|
-
const constraintType = before ? "before" : "after";
|
|
1702
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1703
|
-
}
|
|
1704
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1705
|
-
this.phaseMap.set(name, node);
|
|
1706
|
-
this.invalidateCache();
|
|
1707
|
-
}
|
|
1708
|
-
/**
|
|
1709
|
-
* Get ordered list of phase names
|
|
1710
|
-
*/
|
|
1711
|
-
getOrderedPhases() {
|
|
1712
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1713
|
-
return this.orderedNamesCache;
|
|
1714
|
-
}
|
|
1715
|
-
/**
|
|
1716
|
-
* Check if a phase exists
|
|
1717
|
-
*/
|
|
1718
|
-
hasPhase(name) {
|
|
1719
|
-
return this.phaseMap.has(name);
|
|
1720
|
-
}
|
|
1721
|
-
/**
|
|
1722
|
-
* Get the index of a phase (-1 if not found)
|
|
1723
|
-
*/
|
|
1724
|
-
getPhaseIndex(name) {
|
|
1725
|
-
if (!name) return -1;
|
|
1726
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1730
|
-
* Used for resolving before/after constraints.
|
|
1731
|
-
*
|
|
1732
|
-
* @param name - The phase name to ensure exists
|
|
1733
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1734
|
-
*/
|
|
1735
|
-
ensurePhase(name) {
|
|
1736
|
-
if (this.phaseMap.has(name)) return name;
|
|
1737
|
-
const node = { name, isAutoGenerated: true };
|
|
1738
|
-
this.phases.push(node);
|
|
1739
|
-
this.phaseMap.set(name, node);
|
|
1740
|
-
this.invalidateCache();
|
|
1741
|
-
return name;
|
|
1742
|
-
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Resolve where a job with before/after constraints should go.
|
|
1745
|
-
* Creates auto-generated phases if needed.
|
|
1746
|
-
*
|
|
1747
|
-
* @param before - Phase(s) to run before
|
|
1748
|
-
* @param after - Phase(s) to run after
|
|
1749
|
-
* @returns The resolved phase name
|
|
1750
|
-
*/
|
|
1751
|
-
resolveConstraintPhase(before, after) {
|
|
1752
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1753
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1754
|
-
if (beforeArr.length > 0) {
|
|
1755
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1756
|
-
}
|
|
1757
|
-
if (afterArr.length > 0) {
|
|
1758
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1759
|
-
}
|
|
1760
|
-
return "update";
|
|
1761
|
-
}
|
|
1762
|
-
/**
|
|
1763
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1764
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1765
|
-
*
|
|
1766
|
-
* @param target - The target phase name to position relative to
|
|
1767
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1768
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1769
|
-
* @returns The auto-generated phase name
|
|
1770
|
-
*/
|
|
1771
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1772
|
-
const autoName = `${prefix}:${target}`;
|
|
1773
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1774
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1775
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1776
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1777
|
-
else this.phases.push(node);
|
|
1778
|
-
this.phaseMap.set(autoName, node);
|
|
1779
|
-
this.invalidateCache();
|
|
1780
|
-
return autoName;
|
|
1781
|
-
}
|
|
1782
|
-
// Internal --------------------------------
|
|
1783
|
-
invalidateCache() {
|
|
1784
|
-
this.orderedNamesCache = null;
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1789
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1790
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1791
|
-
for (const phase of orderedPhases) {
|
|
1792
|
-
buckets.set(phase, []);
|
|
1793
|
-
}
|
|
1794
|
-
for (const job of jobs.values()) {
|
|
1795
|
-
if (!job.enabled) continue;
|
|
1796
|
-
let bucket = buckets.get(job.phase);
|
|
1797
|
-
if (!bucket) {
|
|
1798
|
-
bucket = [];
|
|
1799
|
-
buckets.set(job.phase, bucket);
|
|
1800
|
-
}
|
|
1801
|
-
bucket.push(job);
|
|
1802
|
-
}
|
|
1803
|
-
const sortedBuckets = [];
|
|
1804
|
-
for (const phase of orderedPhases) {
|
|
1805
|
-
const bucket = buckets.get(phase);
|
|
1806
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1807
|
-
bucket.sort((a, b) => {
|
|
1808
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1809
|
-
return a.index - b.index;
|
|
1810
|
-
});
|
|
1811
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1812
|
-
}
|
|
1813
|
-
for (const [phase, bucket] of buckets) {
|
|
1814
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1815
|
-
bucket.sort((a, b) => {
|
|
1816
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1817
|
-
return a.index - b.index;
|
|
1818
|
-
});
|
|
1819
|
-
sortedBuckets.push(bucket);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
return sortedBuckets.flat();
|
|
1823
|
-
}
|
|
1824
|
-
function hasCrossJobConstraints(bucket) {
|
|
1825
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1826
|
-
for (const job of bucket) {
|
|
1827
|
-
for (const ref of job.before) {
|
|
1828
|
-
if (jobIds.has(ref)) return true;
|
|
1829
|
-
}
|
|
1830
|
-
for (const ref of job.after) {
|
|
1831
|
-
if (jobIds.has(ref)) return true;
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
return false;
|
|
1835
|
-
}
|
|
1836
|
-
function topologicalSort(jobs) {
|
|
1837
|
-
const n = jobs.length;
|
|
1838
|
-
if (n <= 1) return jobs;
|
|
1839
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1840
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1841
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1842
|
-
for (const job of jobs) {
|
|
1843
|
-
jobMap.set(job.id, job);
|
|
1844
|
-
inDegree.set(job.id, 0);
|
|
1845
|
-
adjacency.set(job.id, []);
|
|
1846
|
-
}
|
|
1847
|
-
for (const job of jobs) {
|
|
1848
|
-
for (const ref of job.before) {
|
|
1849
|
-
if (jobMap.has(ref)) {
|
|
1850
|
-
adjacency.get(job.id).push(ref);
|
|
1851
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
for (const ref of job.after) {
|
|
1855
|
-
if (jobMap.has(ref)) {
|
|
1856
|
-
adjacency.get(ref).push(job.id);
|
|
1857
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
const queue = [];
|
|
1862
|
-
for (const job of jobs) {
|
|
1863
|
-
if (inDegree.get(job.id) === 0) {
|
|
1864
|
-
queue.push(job);
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
queue.sort((a, b) => {
|
|
1868
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1869
|
-
return a.index - b.index;
|
|
1870
|
-
});
|
|
1871
|
-
const result = [];
|
|
1872
|
-
while (queue.length > 0) {
|
|
1873
|
-
const job = queue.shift();
|
|
1874
|
-
result.push(job);
|
|
1875
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1876
|
-
for (const neighborId of neighbors) {
|
|
1877
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1878
|
-
inDegree.set(neighborId, newDegree);
|
|
1879
|
-
if (newDegree === 0) {
|
|
1880
|
-
const neighbor = jobMap.get(neighborId);
|
|
1881
|
-
insertSorted(queue, neighbor);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
if (result.length !== n) {
|
|
1886
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1887
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1888
|
-
for (const job of jobs) {
|
|
1889
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
return result;
|
|
1893
|
-
}
|
|
1894
|
-
function insertSorted(arr, job) {
|
|
1895
|
-
let i = 0;
|
|
1896
|
-
while (i < arr.length) {
|
|
1897
|
-
const cmp = arr[i];
|
|
1898
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1899
|
-
break;
|
|
1900
|
-
}
|
|
1901
|
-
i++;
|
|
1902
|
-
}
|
|
1903
|
-
arr.splice(i, 0, job);
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
function shouldRun(job, now) {
|
|
1907
|
-
if (!job.enabled) return false;
|
|
1908
|
-
if (!job.fps) return true;
|
|
1909
|
-
const minInterval = 1e3 / job.fps;
|
|
1910
|
-
const lastRun = job.lastRun ?? 0;
|
|
1911
|
-
const elapsed = now - lastRun;
|
|
1912
|
-
if (elapsed < minInterval - 1) return false;
|
|
1913
|
-
if (job.drop) {
|
|
1914
|
-
job.lastRun = now;
|
|
1915
|
-
} else {
|
|
1916
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1917
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1918
|
-
if (job.lastRun < now - minInterval) {
|
|
1919
|
-
job.lastRun = now;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
return true;
|
|
1923
|
-
}
|
|
1924
|
-
function resetJobTiming(job) {
|
|
1925
|
-
job.lastRun = void 0;
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
var __defProp = Object.defineProperty;
|
|
1929
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1930
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1931
|
-
const hmrData = (() => {
|
|
1932
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1933
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1934
|
-
try {
|
|
1935
|
-
return (0, eval)("import.meta.hot");
|
|
1936
|
-
} catch {
|
|
1937
|
-
return void 0;
|
|
1938
|
-
}
|
|
1939
|
-
})();
|
|
1940
|
-
const _Scheduler = class _Scheduler {
|
|
1941
|
-
//* Constructor ================================
|
|
1942
|
-
constructor() {
|
|
1943
|
-
//* Critical State ================================
|
|
1944
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1945
|
-
__publicField(this, "phaseGraph");
|
|
1946
|
-
__publicField(this, "loopState", {
|
|
1947
|
-
running: false,
|
|
1948
|
-
rafHandle: null,
|
|
1949
|
-
lastTime: null,
|
|
1950
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1951
|
-
frameCount: 0,
|
|
1952
|
-
elapsedTime: 0,
|
|
1953
|
-
createdAt: performance.now()
|
|
1954
|
-
});
|
|
1955
|
-
__publicField(this, "stoppedTime", 0);
|
|
1956
|
-
//* Private State ================================
|
|
1957
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1958
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1959
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1960
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1961
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1962
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1963
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1964
|
-
__publicField(this, "pendingFrames", 0);
|
|
1965
|
-
__publicField(this, "_frameloop", "always");
|
|
1966
|
-
//* Independent Mode & Error Handling State ================================
|
|
1967
|
-
__publicField(this, "_independent", false);
|
|
1968
|
-
__publicField(this, "errorHandler", null);
|
|
1969
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1970
|
-
//* Core Loop Execution Methods ================================
|
|
1971
|
-
/**
|
|
1972
|
-
* Main RAF loop callback.
|
|
1973
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1974
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1975
|
-
* @returns {void}
|
|
1976
|
-
* @private
|
|
1977
|
-
*/
|
|
1978
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1979
|
-
if (!this.loopState.running) return;
|
|
1980
|
-
this.executeFrame(timestamp);
|
|
1981
|
-
if (this._frameloop === "demand") {
|
|
1982
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1983
|
-
if (this.pendingFrames === 0) {
|
|
1984
|
-
this.notifyIdle(timestamp);
|
|
1985
|
-
return this.stop();
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1989
|
-
});
|
|
1990
|
-
this.phaseGraph = new PhaseGraph();
|
|
1991
|
-
}
|
|
1992
|
-
static get instance() {
|
|
1993
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1994
|
-
}
|
|
1995
|
-
static set instance(value) {
|
|
1996
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1997
|
-
}
|
|
1998
|
-
/**
|
|
1999
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
2000
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
2001
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
2002
|
-
*/
|
|
2003
|
-
static get() {
|
|
2004
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
2005
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
2006
|
-
}
|
|
2007
|
-
if (!_Scheduler.instance) {
|
|
2008
|
-
_Scheduler.instance = new _Scheduler();
|
|
2009
|
-
if (hmrData?.data) {
|
|
2010
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
return _Scheduler.instance;
|
|
2014
|
-
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
2017
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
2018
|
-
* @returns {void}
|
|
2019
|
-
*/
|
|
2020
|
-
static reset() {
|
|
2021
|
-
if (_Scheduler.instance) {
|
|
2022
|
-
_Scheduler.instance.stop();
|
|
2023
|
-
_Scheduler.instance = null;
|
|
2024
|
-
}
|
|
2025
|
-
if (hmrData?.data) {
|
|
2026
|
-
hmrData.data.scheduler = null;
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
//* Getters & Setters ================================
|
|
2030
|
-
get phases() {
|
|
2031
|
-
return this.phaseGraph.getOrderedPhases();
|
|
2032
|
-
}
|
|
2033
|
-
get frameloop() {
|
|
2034
|
-
return this._frameloop;
|
|
2035
|
-
}
|
|
2036
|
-
set frameloop(mode) {
|
|
2037
|
-
if (this._frameloop === mode) return;
|
|
2038
|
-
const wasAlways = this._frameloop === "always";
|
|
2039
|
-
this._frameloop = mode;
|
|
2040
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
2041
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
2042
|
-
}
|
|
2043
|
-
get isRunning() {
|
|
2044
|
-
return this.loopState.running;
|
|
2045
|
-
}
|
|
2046
|
-
get isReady() {
|
|
2047
|
-
return this.roots.size > 0;
|
|
2048
|
-
}
|
|
2049
|
-
get independent() {
|
|
2050
|
-
return this._independent;
|
|
2051
|
-
}
|
|
2052
|
-
set independent(value) {
|
|
2053
|
-
this._independent = value;
|
|
2054
|
-
if (value) this.ensureDefaultRoot();
|
|
2055
|
-
}
|
|
2056
|
-
//* Root Management Methods ================================
|
|
2057
|
-
/**
|
|
2058
|
-
* Register a root (Canvas) with the scheduler.
|
|
2059
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
2060
|
-
* @param {string} id - Unique identifier for this root
|
|
2061
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
2062
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
2063
|
-
*/
|
|
2064
|
-
registerRoot(id, options = {}) {
|
|
2065
|
-
if (this.roots.has(id)) {
|
|
2066
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
2067
|
-
return () => this.unregisterRoot(id);
|
|
2068
|
-
}
|
|
2069
|
-
const entry = {
|
|
2070
|
-
id,
|
|
2071
|
-
getState: options.getState ?? (() => ({})),
|
|
2072
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
2073
|
-
sortedJobs: [],
|
|
2074
|
-
needsRebuild: false
|
|
2075
|
-
};
|
|
2076
|
-
if (options.onError) {
|
|
2077
|
-
this.errorHandler = options.onError;
|
|
2078
|
-
}
|
|
2079
|
-
this.roots.set(id, entry);
|
|
2080
|
-
if (this.roots.size === 1) {
|
|
2081
|
-
this.notifyRootReady();
|
|
2082
|
-
if (this._frameloop === "always") this.start();
|
|
2083
|
-
}
|
|
2084
|
-
return () => this.unregisterRoot(id);
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Unregister a root from the scheduler.
|
|
2088
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
2089
|
-
* The last root to unregister stops the RAF loop.
|
|
2090
|
-
* @param {string} id - The root ID to unregister
|
|
2091
|
-
* @returns {void}
|
|
2092
|
-
*/
|
|
2093
|
-
unregisterRoot(id) {
|
|
2094
|
-
const root = this.roots.get(id);
|
|
2095
|
-
if (!root) return;
|
|
2096
|
-
for (const jobId of root.jobs.keys()) {
|
|
2097
|
-
this.jobStateListeners.delete(jobId);
|
|
2098
|
-
}
|
|
2099
|
-
this.roots.delete(id);
|
|
2100
|
-
if (this.roots.size === 0) {
|
|
2101
|
-
this.stop();
|
|
2102
|
-
this.errorHandler = null;
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
/**
|
|
2106
|
-
* Subscribe to be notified when a root becomes available.
|
|
2107
|
-
* Fires immediately if a root already exists.
|
|
2108
|
-
* @param {() => void} callback - Function called when first root registers
|
|
2109
|
-
* @returns {() => void} Unsubscribe function
|
|
2110
|
-
*/
|
|
2111
|
-
onRootReady(callback) {
|
|
2112
|
-
if (this.roots.size > 0) {
|
|
2113
|
-
callback();
|
|
2114
|
-
return () => {
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
this.rootReadyCallbacks.add(callback);
|
|
2118
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
2119
|
-
}
|
|
2120
|
-
/**
|
|
2121
|
-
* Notify all registered root-ready callbacks.
|
|
2122
|
-
* Called when the first root registers.
|
|
2123
|
-
* @returns {void}
|
|
2124
|
-
* @private
|
|
2125
|
-
*/
|
|
2126
|
-
notifyRootReady() {
|
|
2127
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
2128
|
-
try {
|
|
2129
|
-
cb();
|
|
2130
|
-
} catch (error) {
|
|
2131
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
this.rootReadyCallbacks.clear();
|
|
2135
|
-
}
|
|
2136
|
-
/**
|
|
2137
|
-
* Ensure a default root exists for independent mode.
|
|
2138
|
-
* Creates a minimal root with no state provider.
|
|
2139
|
-
* @returns {void}
|
|
2140
|
-
* @private
|
|
2141
|
-
*/
|
|
2142
|
-
ensureDefaultRoot() {
|
|
2143
|
-
if (!this.roots.has("__default__")) {
|
|
2144
|
-
this.registerRoot("__default__");
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
/**
|
|
2148
|
-
* Trigger error handling for job errors.
|
|
2149
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
2150
|
-
* @param {Error} error - The error to handle
|
|
2151
|
-
* @returns {void}
|
|
2152
|
-
*/
|
|
2153
|
-
triggerError(error) {
|
|
2154
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
2155
|
-
else console.error("[Scheduler]", error);
|
|
2156
|
-
}
|
|
2157
|
-
//* Phase Management Methods ================================
|
|
2158
|
-
/**
|
|
2159
|
-
* Add a named phase to the scheduler's execution order.
|
|
2160
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
2161
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
2162
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
2163
|
-
* @returns {void}
|
|
2164
|
-
* @example
|
|
2165
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
2166
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
2167
|
-
*/
|
|
2168
|
-
addPhase(name, options) {
|
|
2169
|
-
this.phaseGraph.addPhase(name, options);
|
|
2170
|
-
for (const root of this.roots.values()) {
|
|
2171
|
-
root.needsRebuild = true;
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
/**
|
|
2175
|
-
* Check if a phase exists in the scheduler.
|
|
2176
|
-
* @param {string} name - The phase name to check
|
|
2177
|
-
* @returns {boolean} True if the phase exists
|
|
2178
|
-
*/
|
|
2179
|
-
hasPhase(name) {
|
|
2180
|
-
return this.phaseGraph.hasPhase(name);
|
|
2181
|
-
}
|
|
2182
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
2183
|
-
/**
|
|
2184
|
-
* Register a global job that runs once per frame (not per-root).
|
|
2185
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
2186
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
2187
|
-
* @param {string} id - Unique identifier for this global job
|
|
2188
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
2189
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
2190
|
-
* @deprecated Use useFrame with phases instead
|
|
2191
|
-
*/
|
|
2192
|
-
registerGlobal(phase, id, callback) {
|
|
2193
|
-
const job = { id, callback };
|
|
2194
|
-
if (phase === "before") {
|
|
2195
|
-
this.globalBeforeJobs.set(id, job);
|
|
2196
|
-
} else {
|
|
2197
|
-
this.globalAfterJobs.set(id, job);
|
|
2198
|
-
}
|
|
2199
|
-
return () => {
|
|
2200
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
2201
|
-
else this.globalAfterJobs.delete(id);
|
|
2202
|
-
};
|
|
2203
|
-
}
|
|
2204
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
2205
|
-
/**
|
|
2206
|
-
* Register an idle callback that fires when the loop stops.
|
|
2207
|
-
* Used internally by deprecated addTail API.
|
|
2208
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
2209
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
2210
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
2211
|
-
*/
|
|
2212
|
-
onIdle(callback) {
|
|
2213
|
-
this.idleCallbacks.add(callback);
|
|
2214
|
-
return () => this.idleCallbacks.delete(callback);
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* Notify all registered idle callbacks.
|
|
2218
|
-
* Called when the loop stops in demand mode.
|
|
2219
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2220
|
-
* @returns {void}
|
|
2221
|
-
* @private
|
|
2222
|
-
*/
|
|
2223
|
-
notifyIdle(timestamp) {
|
|
2224
|
-
for (const cb of this.idleCallbacks) {
|
|
2225
|
-
try {
|
|
2226
|
-
cb(timestamp);
|
|
2227
|
-
} catch (error) {
|
|
2228
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
//* Job Registration & Management Methods ================================
|
|
2233
|
-
/**
|
|
2234
|
-
* Register a job (frame callback) with a specific root.
|
|
2235
|
-
* This is the core registration method used by useFrame internally.
|
|
2236
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2237
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2238
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2239
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2240
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2241
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2242
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2243
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2244
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2245
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2246
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2247
|
-
*/
|
|
2248
|
-
register(callback, options = {}) {
|
|
2249
|
-
const rootId = options.rootId;
|
|
2250
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2251
|
-
if (!root) {
|
|
2252
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2253
|
-
return () => {
|
|
2254
|
-
};
|
|
2255
|
-
}
|
|
2256
|
-
const id = options.id ?? this.generateJobId();
|
|
2257
|
-
let phase = options.phase ?? "update";
|
|
2258
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2259
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2260
|
-
}
|
|
2261
|
-
const before = this.normalizeConstraints(options.before);
|
|
2262
|
-
const after = this.normalizeConstraints(options.after);
|
|
2263
|
-
const job = {
|
|
2264
|
-
id,
|
|
2265
|
-
callback,
|
|
2266
|
-
phase,
|
|
2267
|
-
before,
|
|
2268
|
-
after,
|
|
2269
|
-
priority: options.priority ?? 0,
|
|
2270
|
-
index: this.nextJobIndex++,
|
|
2271
|
-
fps: options.fps,
|
|
2272
|
-
drop: options.drop ?? true,
|
|
2273
|
-
enabled: options.enabled ?? true,
|
|
2274
|
-
system: options.system ?? false
|
|
2275
|
-
};
|
|
2276
|
-
if (root.jobs.has(id)) {
|
|
2277
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2278
|
-
}
|
|
2279
|
-
root.jobs.set(id, job);
|
|
2280
|
-
root.needsRebuild = true;
|
|
2281
|
-
return () => this.unregister(id, root.id);
|
|
2282
|
-
}
|
|
2283
|
-
/**
|
|
2284
|
-
* Unregister a job by its ID.
|
|
2285
|
-
* Searches all roots if rootId is not provided.
|
|
2286
|
-
* @param {string} id - The job ID to unregister
|
|
2287
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2288
|
-
* @returns {void}
|
|
2289
|
-
*/
|
|
2290
|
-
unregister(id, rootId) {
|
|
2291
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2292
|
-
if (root?.jobs.delete(id)) {
|
|
2293
|
-
root.needsRebuild = true;
|
|
2294
|
-
this.jobStateListeners.delete(id);
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
/**
|
|
2298
|
-
* Update a job's options dynamically.
|
|
2299
|
-
* Searches all roots to find the job by ID.
|
|
2300
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2301
|
-
* @param {string} id - The job ID to update
|
|
2302
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2303
|
-
* @returns {void}
|
|
2304
|
-
*/
|
|
2305
|
-
updateJob(id, options) {
|
|
2306
|
-
let job;
|
|
2307
|
-
let root;
|
|
2308
|
-
for (const r of this.roots.values()) {
|
|
2309
|
-
job = r.jobs.get(id);
|
|
2310
|
-
if (job) {
|
|
2311
|
-
root = r;
|
|
2312
|
-
break;
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
if (!job || !root) return;
|
|
2316
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2317
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2318
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2319
|
-
if (options.enabled !== void 0) {
|
|
2320
|
-
const wasEnabled = job.enabled;
|
|
2321
|
-
job.enabled = options.enabled;
|
|
2322
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2323
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2324
|
-
}
|
|
2325
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2326
|
-
if (options.phase) job.phase = options.phase;
|
|
2327
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2328
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2329
|
-
root.needsRebuild = true;
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
//* Job State Management Methods ================================
|
|
2333
|
-
/**
|
|
2334
|
-
* Check if a job is currently paused (disabled).
|
|
2335
|
-
* @param {string} id - The job ID to check
|
|
2336
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2337
|
-
*/
|
|
2338
|
-
isJobPaused(id) {
|
|
2339
|
-
for (const root of this.roots.values()) {
|
|
2340
|
-
const job = root.jobs.get(id);
|
|
2341
|
-
if (job) return !job.enabled;
|
|
2342
|
-
}
|
|
2343
|
-
return false;
|
|
2344
|
-
}
|
|
2345
|
-
/**
|
|
2346
|
-
* Subscribe to state changes for a specific job.
|
|
2347
|
-
* Listener is called when job is paused or resumed.
|
|
2348
|
-
* @param {string} id - The job ID to subscribe to
|
|
2349
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2350
|
-
* @returns {() => void} Unsubscribe function
|
|
2351
|
-
*/
|
|
2352
|
-
subscribeJobState(id, listener) {
|
|
2353
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2354
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2355
|
-
}
|
|
2356
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2357
|
-
return () => {
|
|
2358
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2359
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2360
|
-
this.jobStateListeners.delete(id);
|
|
2361
|
-
}
|
|
2362
|
-
};
|
|
2363
|
-
}
|
|
2364
|
-
/**
|
|
2365
|
-
* Notify all listeners that a job's state has changed.
|
|
2366
|
-
* @param {string} id - The job ID that changed
|
|
2367
|
-
* @returns {void}
|
|
2368
|
-
* @private
|
|
2369
|
-
*/
|
|
2370
|
-
notifyJobStateChange(id) {
|
|
2371
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2372
|
-
}
|
|
2373
|
-
/**
|
|
2374
|
-
* Pause a job by ID (sets enabled=false).
|
|
2375
|
-
* Notifies any subscribed state listeners.
|
|
2376
|
-
* @param {string} id - The job ID to pause
|
|
2377
|
-
* @returns {void}
|
|
2378
|
-
*/
|
|
2379
|
-
pauseJob(id) {
|
|
2380
|
-
this.updateJob(id, { enabled: false });
|
|
2381
|
-
this.notifyJobStateChange(id);
|
|
2382
|
-
}
|
|
2383
|
-
/**
|
|
2384
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2385
|
-
* Resets job timing to prevent frame accumulation.
|
|
2386
|
-
* Notifies any subscribed state listeners.
|
|
2387
|
-
* @param {string} id - The job ID to resume
|
|
2388
|
-
* @returns {void}
|
|
2389
|
-
*/
|
|
2390
|
-
resumeJob(id) {
|
|
2391
|
-
this.updateJob(id, { enabled: true });
|
|
2392
|
-
this.notifyJobStateChange(id);
|
|
2393
|
-
}
|
|
2394
|
-
//* Frame Loop Control Methods ================================
|
|
2395
|
-
/**
|
|
2396
|
-
* Start the requestAnimationFrame loop.
|
|
2397
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2398
|
-
* No-op if already running.
|
|
2399
|
-
* @returns {void}
|
|
2400
|
-
*/
|
|
2401
|
-
start() {
|
|
2402
|
-
if (this.loopState.running) return;
|
|
2403
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2404
|
-
let adjustedCreated = 0;
|
|
2405
|
-
if (this.stoppedTime > 0) {
|
|
2406
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2407
|
-
this.stoppedTime = 0;
|
|
2408
|
-
}
|
|
2409
|
-
Object.assign(this.loopState, {
|
|
2410
|
-
running: true,
|
|
2411
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2412
|
-
lastTime: performance.now(),
|
|
2413
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2414
|
-
frameCount: 0,
|
|
2415
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
/**
|
|
2419
|
-
* Stop the requestAnimationFrame loop.
|
|
2420
|
-
* Cancels any pending RAF callback.
|
|
2421
|
-
* No-op if not running.
|
|
2422
|
-
* @returns {void}
|
|
2423
|
-
*/
|
|
2424
|
-
stop() {
|
|
2425
|
-
if (!this.loopState.running) return;
|
|
2426
|
-
this.loopState.running = false;
|
|
2427
|
-
if (this.loopState.rafHandle !== null) {
|
|
2428
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2429
|
-
this.loopState.rafHandle = null;
|
|
2430
|
-
}
|
|
2431
|
-
this.stoppedTime = performance.now();
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Request frames to be rendered in demand mode.
|
|
2435
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2436
|
-
* No-op if frameloop is not 'demand'.
|
|
2437
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2438
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2439
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2440
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2441
|
-
* @returns {void}
|
|
2442
|
-
* @example
|
|
2443
|
-
* // Request a single frame render
|
|
2444
|
-
* scheduler.invalidate();
|
|
2445
|
-
*
|
|
2446
|
-
* @example
|
|
2447
|
-
* // Request 5 frames (e.g., for animations)
|
|
2448
|
-
* scheduler.invalidate(5);
|
|
2449
|
-
*
|
|
2450
|
-
* @example
|
|
2451
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2452
|
-
* scheduler.invalidate(3, false);
|
|
2453
|
-
*
|
|
2454
|
-
* @example
|
|
2455
|
-
* // Add 2 more frames to existing pending count
|
|
2456
|
-
* scheduler.invalidate(2, true);
|
|
2457
|
-
*/
|
|
2458
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2459
|
-
if (this._frameloop !== "demand") return;
|
|
2460
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2461
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2462
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2463
|
-
}
|
|
2464
|
-
/**
|
|
2465
|
-
* Reset timing state for deterministic testing.
|
|
2466
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2467
|
-
* @returns {void}
|
|
2468
|
-
*/
|
|
2469
|
-
resetTiming() {
|
|
2470
|
-
this.loopState.lastTime = null;
|
|
2471
|
-
this.loopState.frameCount = 0;
|
|
2472
|
-
this.loopState.elapsedTime = 0;
|
|
2473
|
-
this.loopState.createdAt = performance.now();
|
|
2474
|
-
}
|
|
2475
|
-
//* Manual Stepping Methods ================================
|
|
2476
|
-
/**
|
|
2477
|
-
* Manually execute a single frame for all roots.
|
|
2478
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2479
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2480
|
-
* @returns {void}
|
|
2481
|
-
* @example
|
|
2482
|
-
* // Manual control mode
|
|
2483
|
-
* scheduler.frameloop = 'never';
|
|
2484
|
-
* scheduler.step(); // Execute one frame
|
|
2485
|
-
*/
|
|
2486
|
-
step(timestamp) {
|
|
2487
|
-
const now = timestamp ?? performance.now();
|
|
2488
|
-
this.executeFrame(now);
|
|
2489
|
-
}
|
|
2490
|
-
/**
|
|
2491
|
-
* Manually execute a single job by its ID.
|
|
2492
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2493
|
-
* @param {string} id - The job ID to step
|
|
2494
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2495
|
-
* @returns {void}
|
|
2496
|
-
*/
|
|
2497
|
-
stepJob(id, timestamp) {
|
|
2498
|
-
let job;
|
|
2499
|
-
let root;
|
|
2500
|
-
for (const r of this.roots.values()) {
|
|
2501
|
-
job = r.jobs.get(id);
|
|
2502
|
-
if (job) {
|
|
2503
|
-
root = r;
|
|
2504
|
-
break;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
if (!job || !root) {
|
|
2508
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2509
|
-
return;
|
|
2510
|
-
}
|
|
2511
|
-
const now = timestamp ?? performance.now();
|
|
2512
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2513
|
-
const delta = deltaMs / 1e3;
|
|
2514
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2515
|
-
const providedState = root.getState?.() ?? {};
|
|
2516
|
-
const frameState = {
|
|
2517
|
-
...providedState,
|
|
2518
|
-
time: now,
|
|
2519
|
-
delta,
|
|
2520
|
-
elapsed,
|
|
2521
|
-
frame: this.loopState.frameCount
|
|
2522
|
-
};
|
|
2523
|
-
try {
|
|
2524
|
-
job.callback(frameState, delta);
|
|
2525
|
-
} catch (error) {
|
|
2526
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2527
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
/**
|
|
2531
|
-
* Execute a single frame across all roots.
|
|
2532
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2533
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2534
|
-
* @returns {void}
|
|
2535
|
-
* @private
|
|
2536
|
-
*/
|
|
2537
|
-
executeFrame(timestamp) {
|
|
2538
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2539
|
-
const delta = deltaMs / 1e3;
|
|
2540
|
-
this.loopState.lastTime = timestamp;
|
|
2541
|
-
this.loopState.frameCount++;
|
|
2542
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2543
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2544
|
-
for (const root of this.roots.values()) {
|
|
2545
|
-
this.tickRoot(root, timestamp, delta);
|
|
2546
|
-
}
|
|
2547
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2548
|
-
}
|
|
2549
|
-
/**
|
|
2550
|
-
* Run all global jobs from a job map.
|
|
2551
|
-
* Catches and logs errors without stopping execution.
|
|
2552
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2553
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2554
|
-
* @returns {void}
|
|
2555
|
-
* @private
|
|
2556
|
-
*/
|
|
2557
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2558
|
-
for (const job of jobs.values()) {
|
|
2559
|
-
try {
|
|
2560
|
-
job.callback(timestamp);
|
|
2561
|
-
} catch (error) {
|
|
2562
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
/**
|
|
2567
|
-
* Execute all jobs for a single root in sorted order.
|
|
2568
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2569
|
-
* Errors are caught and propagated via triggerError.
|
|
2570
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2571
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2572
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2573
|
-
* @returns {void}
|
|
2574
|
-
* @private
|
|
2575
|
-
*/
|
|
2576
|
-
tickRoot(root, timestamp, delta) {
|
|
2577
|
-
if (root.needsRebuild) {
|
|
2578
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2579
|
-
root.needsRebuild = false;
|
|
2580
|
-
}
|
|
2581
|
-
const providedState = root.getState?.() ?? {};
|
|
2582
|
-
const frameState = {
|
|
2583
|
-
...providedState,
|
|
2584
|
-
time: timestamp,
|
|
2585
|
-
delta,
|
|
2586
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2587
|
-
// Convert ms to seconds
|
|
2588
|
-
frame: this.loopState.frameCount
|
|
2589
|
-
};
|
|
2590
|
-
for (const job of root.sortedJobs) {
|
|
2591
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2592
|
-
try {
|
|
2593
|
-
job.callback(frameState, delta);
|
|
2594
|
-
} catch (error) {
|
|
2595
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2596
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
//* Debug & Inspection Methods ================================
|
|
2601
|
-
/**
|
|
2602
|
-
* Get the total number of registered jobs across all roots.
|
|
2603
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2604
|
-
* @returns {number} Total job count
|
|
2605
|
-
*/
|
|
2606
|
-
getJobCount() {
|
|
2607
|
-
let count = 0;
|
|
2608
|
-
for (const root of this.roots.values()) {
|
|
2609
|
-
count += root.jobs.size;
|
|
2610
|
-
}
|
|
2611
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2612
|
-
}
|
|
2613
|
-
/**
|
|
2614
|
-
* Get all registered job IDs across all roots.
|
|
2615
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2616
|
-
* @returns {string[]} Array of all job IDs
|
|
2617
|
-
*/
|
|
2618
|
-
getJobIds() {
|
|
2619
|
-
const ids = [];
|
|
2620
|
-
for (const root of this.roots.values()) {
|
|
2621
|
-
ids.push(...root.jobs.keys());
|
|
2622
|
-
}
|
|
2623
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2624
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2625
|
-
return ids;
|
|
2626
|
-
}
|
|
2627
|
-
/**
|
|
2628
|
-
* Get the number of registered roots (Canvas instances).
|
|
2629
|
-
* @returns {number} Number of registered roots
|
|
2630
|
-
*/
|
|
2631
|
-
getRootCount() {
|
|
2632
|
-
return this.roots.size;
|
|
2633
|
-
}
|
|
2634
|
-
/**
|
|
2635
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2636
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2637
|
-
*
|
|
2638
|
-
* @param phase The phase to check
|
|
2639
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2640
|
-
* @returns true if any user jobs exist in the phase
|
|
2641
|
-
*/
|
|
2642
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2643
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2644
|
-
return rootsToCheck.some((root) => {
|
|
2645
|
-
if (!root) return false;
|
|
2646
|
-
for (const job of root.jobs.values()) {
|
|
2647
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2648
|
-
}
|
|
2649
|
-
return false;
|
|
2650
|
-
});
|
|
2651
|
-
}
|
|
2652
|
-
//* Utility Methods ================================
|
|
2653
|
-
/**
|
|
2654
|
-
* Generate a unique root ID for automatic root registration.
|
|
2655
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2656
|
-
*/
|
|
2657
|
-
generateRootId() {
|
|
2658
|
-
return `root_${this.nextRootIndex++}`;
|
|
2659
|
-
}
|
|
2660
|
-
/**
|
|
2661
|
-
* Generate a unique job ID.
|
|
2662
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2663
|
-
* @private
|
|
2664
|
-
*/
|
|
2665
|
-
generateJobId() {
|
|
2666
|
-
return `job_${this.nextJobIndex}`;
|
|
2667
|
-
}
|
|
2668
|
-
/**
|
|
2669
|
-
* Normalize before/after constraints to a Set.
|
|
2670
|
-
* Handles undefined, single string, or array inputs.
|
|
2671
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2672
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2673
|
-
* @private
|
|
2674
|
-
*/
|
|
2675
|
-
normalizeConstraints(value) {
|
|
2676
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2677
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2678
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2679
|
-
}
|
|
2680
|
-
};
|
|
2681
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2682
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2683
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2684
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2685
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2686
|
-
let Scheduler = _Scheduler;
|
|
2687
|
-
const getScheduler = () => Scheduler.get();
|
|
2688
|
-
if (hmrData) {
|
|
2689
|
-
hmrData.accept?.();
|
|
1691
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1692
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1693
|
+
if (!stack) return false;
|
|
1694
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1695
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
2690
1696
|
}
|
|
2691
1697
|
|
|
2692
1698
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2798,7 +1804,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2798
1804
|
size: newSize,
|
|
2799
1805
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2800
1806
|
}));
|
|
2801
|
-
getScheduler().invalidate();
|
|
1807
|
+
scheduler.getScheduler().invalidate();
|
|
2802
1808
|
}
|
|
2803
1809
|
}
|
|
2804
1810
|
return;
|
|
@@ -2813,7 +1819,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2813
1819
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2814
1820
|
_sizeImperative: true
|
|
2815
1821
|
}));
|
|
2816
|
-
getScheduler().invalidate();
|
|
1822
|
+
scheduler.getScheduler().invalidate();
|
|
2817
1823
|
},
|
|
2818
1824
|
setDpr: (dpr) => set((state2) => {
|
|
2819
1825
|
const resolved = calculateDpr(dpr);
|
|
@@ -2821,6 +1827,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2821
1827
|
}),
|
|
2822
1828
|
setFrameloop: (frameloop = "always") => {
|
|
2823
1829
|
set(() => ({ frameloop }));
|
|
1830
|
+
scheduler.getScheduler().frameloop = frameloop;
|
|
2824
1831
|
},
|
|
2825
1832
|
setError: (error) => set(() => ({ error })),
|
|
2826
1833
|
error: null,
|
|
@@ -2830,6 +1837,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2830
1837
|
buffers: {},
|
|
2831
1838
|
gpuStorage: {},
|
|
2832
1839
|
textures: /* @__PURE__ */ new Map(),
|
|
1840
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
2833
1841
|
renderPipeline: null,
|
|
2834
1842
|
passes: {},
|
|
2835
1843
|
_hmrVersion: 0,
|
|
@@ -2887,8 +1895,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2887
1895
|
const currentState = rootStore.getState();
|
|
2888
1896
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2889
1897
|
const stack = new Error().stack || "";
|
|
2890
|
-
|
|
2891
|
-
if (!isInternalAccess) {
|
|
1898
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2892
1899
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2893
1900
|
notifyDepreciated({
|
|
2894
1901
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -3001,26 +2008,32 @@ function loadingFn(extensions, onProgress) {
|
|
|
3001
2008
|
);
|
|
3002
2009
|
};
|
|
3003
2010
|
}
|
|
3004
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
3005
|
-
const
|
|
2011
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2012
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2013
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
3006
2014
|
const fn = loadingFn(extensions, onProgress);
|
|
3007
|
-
const results =
|
|
2015
|
+
const results = cacheKeys.map(
|
|
2016
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2017
|
+
);
|
|
3008
2018
|
return Array.isArray(input) ? results : results[0];
|
|
3009
2019
|
}
|
|
3010
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
3011
|
-
const
|
|
3012
|
-
|
|
2020
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2021
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2022
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2023
|
+
cacheKeys.forEach(
|
|
2024
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2025
|
+
);
|
|
3013
2026
|
};
|
|
3014
|
-
useLoader.clear = function(loader, input) {
|
|
3015
|
-
const
|
|
3016
|
-
|
|
2027
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2028
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2029
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
3017
2030
|
};
|
|
3018
2031
|
useLoader.loader = getLoader;
|
|
3019
2032
|
|
|
3020
2033
|
function useFrame(callback, priorityOrOptions) {
|
|
3021
2034
|
const store = React__namespace.useContext(context);
|
|
3022
2035
|
const isInsideCanvas = store !== null;
|
|
3023
|
-
const scheduler = getScheduler();
|
|
2036
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
3024
2037
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
3025
2038
|
id: priorityOrOptions.id,
|
|
3026
2039
|
phase: priorityOrOptions.phase,
|
|
@@ -3068,7 +2081,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3068
2081
|
};
|
|
3069
2082
|
callbackRef.current?.(mergedState, delta);
|
|
3070
2083
|
};
|
|
3071
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2084
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
3072
2085
|
id,
|
|
3073
2086
|
rootId,
|
|
3074
2087
|
...options
|
|
@@ -3089,37 +2102,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3089
2102
|
}
|
|
3090
2103
|
};
|
|
3091
2104
|
} else {
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
unregisterJob = registerOutside();
|
|
3101
|
-
});
|
|
3102
|
-
return () => {
|
|
3103
|
-
unsubReady();
|
|
3104
|
-
unregisterJob?.();
|
|
3105
|
-
};
|
|
2105
|
+
return scheduler$1.register(
|
|
2106
|
+
(state, delta) => {
|
|
2107
|
+
const frameState = state;
|
|
2108
|
+
if (!frameState.renderer) return;
|
|
2109
|
+
callbackRef.current?.(frameState, delta);
|
|
2110
|
+
},
|
|
2111
|
+
{ id, ...options }
|
|
2112
|
+
);
|
|
3106
2113
|
}
|
|
3107
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2114
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
3108
2115
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
3109
2116
|
// Subscribe function
|
|
3110
2117
|
React__namespace.useCallback(
|
|
3111
2118
|
(onStoreChange) => {
|
|
3112
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2119
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
3113
2120
|
},
|
|
3114
2121
|
[id]
|
|
3115
2122
|
),
|
|
3116
2123
|
// getSnapshot function
|
|
3117
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2124
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
3118
2125
|
// getServerSnapshot function (SSR)
|
|
3119
2126
|
React__namespace.useCallback(() => false, [])
|
|
3120
2127
|
);
|
|
3121
2128
|
const controls = React__namespace.useMemo(() => {
|
|
3122
|
-
const scheduler2 = getScheduler();
|
|
2129
|
+
const scheduler2 = scheduler.getScheduler();
|
|
3123
2130
|
return {
|
|
3124
2131
|
/** The job's unique ID */
|
|
3125
2132
|
id,
|
|
@@ -3134,7 +2141,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3134
2141
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3135
2142
|
*/
|
|
3136
2143
|
step: (timestamp) => {
|
|
3137
|
-
getScheduler().stepJob(id, timestamp);
|
|
2144
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
3138
2145
|
},
|
|
3139
2146
|
/**
|
|
3140
2147
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -3142,20 +2149,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3142
2149
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3143
2150
|
*/
|
|
3144
2151
|
stepAll: (timestamp) => {
|
|
3145
|
-
getScheduler().step(timestamp);
|
|
2152
|
+
scheduler.getScheduler().step(timestamp);
|
|
3146
2153
|
},
|
|
3147
2154
|
/**
|
|
3148
2155
|
* Pause this job (set enabled=false).
|
|
3149
2156
|
* Job remains registered but won't run.
|
|
3150
2157
|
*/
|
|
3151
2158
|
pause: () => {
|
|
3152
|
-
getScheduler().pauseJob(id);
|
|
2159
|
+
scheduler.getScheduler().pauseJob(id);
|
|
3153
2160
|
},
|
|
3154
2161
|
/**
|
|
3155
2162
|
* Resume this job (set enabled=true).
|
|
3156
2163
|
*/
|
|
3157
2164
|
resume: () => {
|
|
3158
|
-
getScheduler().resumeJob(id);
|
|
2165
|
+
scheduler.getScheduler().resumeJob(id);
|
|
3159
2166
|
},
|
|
3160
2167
|
/**
|
|
3161
2168
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -3193,18 +2200,18 @@ function buildFromCache(input, textureCache) {
|
|
|
3193
2200
|
function useTexture(input, optionsOrOnLoad) {
|
|
3194
2201
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
3195
2202
|
const store = useStore();
|
|
3196
|
-
const textureCache = useThree((state) => state.textures);
|
|
3197
2203
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
3198
|
-
const { onLoad, cache =
|
|
2204
|
+
const { onLoad, cache = true } = options;
|
|
3199
2205
|
const onLoadRef = React.useRef(onLoad);
|
|
3200
2206
|
onLoadRef.current = onLoad;
|
|
3201
2207
|
const onLoadCalledForRef = React.useRef(null);
|
|
3202
2208
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
3203
2209
|
const cachedResult = React.useMemo(() => {
|
|
3204
2210
|
if (!cache) return null;
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
2211
|
+
const textures = store.getState().textures;
|
|
2212
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2213
|
+
return buildFromCache(input, textures);
|
|
2214
|
+
}, [cache, urls, input, store]);
|
|
3208
2215
|
const loadedTextures = useLoader(
|
|
3209
2216
|
three.TextureLoader,
|
|
3210
2217
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3248,8 +2255,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3248
2255
|
}, [input, loadedTextures, cachedResult]);
|
|
3249
2256
|
React.useEffect(() => {
|
|
3250
2257
|
if (!cache) return;
|
|
3251
|
-
if (cachedResult) return;
|
|
3252
|
-
const set = store.setState;
|
|
3253
2258
|
const urlTextureMap = [];
|
|
3254
2259
|
if (typeof input === "string") {
|
|
3255
2260
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3263,18 +2268,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3263
2268
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3264
2269
|
}
|
|
3265
2270
|
}
|
|
3266
|
-
|
|
3267
|
-
const
|
|
3268
|
-
let
|
|
2271
|
+
store.setState((state) => {
|
|
2272
|
+
const refs = new Map(state._textureRefs);
|
|
2273
|
+
let textures = state.textures;
|
|
2274
|
+
let added = false;
|
|
3269
2275
|
for (const [url, texture] of urlTextureMap) {
|
|
3270
|
-
if (!
|
|
3271
|
-
|
|
3272
|
-
|
|
2276
|
+
if (!textures.has(url)) {
|
|
2277
|
+
if (!added) {
|
|
2278
|
+
textures = new Map(textures);
|
|
2279
|
+
added = true;
|
|
2280
|
+
}
|
|
2281
|
+
textures.set(url, texture);
|
|
3273
2282
|
}
|
|
2283
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3274
2284
|
}
|
|
3275
|
-
return
|
|
2285
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2286
|
+
});
|
|
2287
|
+
return () => store.setState((state) => {
|
|
2288
|
+
const refs = new Map(state._textureRefs);
|
|
2289
|
+
for (const [url] of urlTextureMap) {
|
|
2290
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2291
|
+
if (next <= 0) refs.delete(url);
|
|
2292
|
+
else refs.set(url, next);
|
|
2293
|
+
}
|
|
2294
|
+
return { _textureRefs: refs };
|
|
3276
2295
|
});
|
|
3277
|
-
}, [cache, input, mappedTextures, store
|
|
2296
|
+
}, [cache, input, mappedTextures, store]);
|
|
3278
2297
|
return mappedTextures;
|
|
3279
2298
|
}
|
|
3280
2299
|
useTexture.preload = (url) => useLoader.preload(three.TextureLoader, url);
|
|
@@ -3290,96 +2309,63 @@ const Texture = ({
|
|
|
3290
2309
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
3291
2310
|
};
|
|
3292
2311
|
|
|
3293
|
-
function
|
|
3294
|
-
if (entry instanceof three.Texture) return entry;
|
|
3295
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof three.Texture) {
|
|
3296
|
-
return entry.value;
|
|
3297
|
-
}
|
|
3298
|
-
return null;
|
|
3299
|
-
}
|
|
3300
|
-
function useTextures() {
|
|
2312
|
+
function useTextures(selector) {
|
|
3301
2313
|
const store = useStore();
|
|
3302
|
-
|
|
3303
|
-
const set = store.setState;
|
|
2314
|
+
const registry = React.useMemo(() => {
|
|
3304
2315
|
const getState = store.getState;
|
|
3305
|
-
const
|
|
3306
|
-
|
|
3307
|
-
const newMap = new Map(state.textures);
|
|
3308
|
-
newMap.set(key, value);
|
|
3309
|
-
return { textures: newMap };
|
|
3310
|
-
});
|
|
3311
|
-
};
|
|
3312
|
-
const addMultiple = (items) => {
|
|
3313
|
-
set((state) => {
|
|
3314
|
-
const newMap = new Map(state.textures);
|
|
3315
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3316
|
-
for (const [key, value] of entries) {
|
|
3317
|
-
newMap.set(key, value);
|
|
3318
|
-
}
|
|
3319
|
-
return { textures: newMap };
|
|
3320
|
-
});
|
|
3321
|
-
};
|
|
3322
|
-
const remove = (key) => {
|
|
3323
|
-
set((state) => {
|
|
3324
|
-
const newMap = new Map(state.textures);
|
|
3325
|
-
newMap.delete(key);
|
|
3326
|
-
return { textures: newMap };
|
|
3327
|
-
});
|
|
3328
|
-
};
|
|
3329
|
-
const removeMultiple = (keys) => {
|
|
3330
|
-
set((state) => {
|
|
3331
|
-
const newMap = new Map(state.textures);
|
|
3332
|
-
for (const key of keys) newMap.delete(key);
|
|
3333
|
-
return { textures: newMap };
|
|
3334
|
-
});
|
|
3335
|
-
};
|
|
3336
|
-
const dispose = (key) => {
|
|
3337
|
-
const entry = getState().textures.get(key);
|
|
3338
|
-
if (entry) {
|
|
3339
|
-
const tex = getTextureValue(entry);
|
|
3340
|
-
tex?.dispose();
|
|
3341
|
-
}
|
|
3342
|
-
remove(key);
|
|
3343
|
-
};
|
|
3344
|
-
const disposeMultiple = (keys) => {
|
|
3345
|
-
const textures = getState().textures;
|
|
3346
|
-
for (const key of keys) {
|
|
3347
|
-
const entry = textures.get(key);
|
|
3348
|
-
if (entry) {
|
|
3349
|
-
const tex = getTextureValue(entry);
|
|
3350
|
-
tex?.dispose();
|
|
3351
|
-
}
|
|
3352
|
-
}
|
|
3353
|
-
removeMultiple(keys);
|
|
3354
|
-
};
|
|
3355
|
-
const disposeAll = () => {
|
|
3356
|
-
const textures = getState().textures;
|
|
3357
|
-
for (const entry of textures.values()) {
|
|
3358
|
-
const tex = getTextureValue(entry);
|
|
3359
|
-
tex?.dispose();
|
|
3360
|
-
}
|
|
3361
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3362
|
-
};
|
|
2316
|
+
const setState = store.setState;
|
|
2317
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3363
2318
|
return {
|
|
3364
|
-
|
|
3365
|
-
get textures() {
|
|
2319
|
+
get all() {
|
|
3366
2320
|
return getState().textures;
|
|
3367
2321
|
},
|
|
3368
|
-
|
|
3369
|
-
|
|
2322
|
+
get(input) {
|
|
2323
|
+
if (typeof input === "string") return getOne(input);
|
|
2324
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2325
|
+
const out = {};
|
|
2326
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2327
|
+
return out;
|
|
2328
|
+
},
|
|
3370
2329
|
has: (key) => getState().textures.has(key),
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
2330
|
+
add(keyOrRecord, texture) {
|
|
2331
|
+
setState((state) => {
|
|
2332
|
+
const textures = new Map(state.textures);
|
|
2333
|
+
if (typeof keyOrRecord === "string") {
|
|
2334
|
+
textures.set(keyOrRecord, texture);
|
|
2335
|
+
} else {
|
|
2336
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2337
|
+
}
|
|
2338
|
+
return { textures };
|
|
2339
|
+
});
|
|
2340
|
+
},
|
|
2341
|
+
dispose(key, options) {
|
|
2342
|
+
const state = getState();
|
|
2343
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2344
|
+
if (refs > 0 && !options?.force) {
|
|
2345
|
+
console.warn(
|
|
2346
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2347
|
+
);
|
|
2348
|
+
return false;
|
|
2349
|
+
}
|
|
2350
|
+
state.textures.get(key)?.dispose();
|
|
2351
|
+
setState((s) => {
|
|
2352
|
+
const textures = new Map(s.textures);
|
|
2353
|
+
textures.delete(key);
|
|
2354
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2355
|
+
nextRefs.delete(key);
|
|
2356
|
+
return { textures, _textureRefs: nextRefs };
|
|
2357
|
+
});
|
|
2358
|
+
return true;
|
|
2359
|
+
},
|
|
2360
|
+
disposeAll() {
|
|
2361
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2362
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2363
|
+
}
|
|
3381
2364
|
};
|
|
3382
2365
|
}, [store]);
|
|
2366
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2367
|
+
const selected = useThree(subscribe);
|
|
2368
|
+
return selector ? selected : registry;
|
|
3383
2369
|
}
|
|
3384
2370
|
|
|
3385
2371
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3434,7 +2420,7 @@ function addEffect(callback) {
|
|
|
3434
2420
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3435
2421
|
});
|
|
3436
2422
|
const id = `legacy_effect_${effectId++}`;
|
|
3437
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2423
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3438
2424
|
}
|
|
3439
2425
|
function addAfterEffect(callback) {
|
|
3440
2426
|
notifyDepreciated({
|
|
@@ -3443,7 +2429,7 @@ function addAfterEffect(callback) {
|
|
|
3443
2429
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3444
2430
|
});
|
|
3445
2431
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3446
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2432
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3447
2433
|
}
|
|
3448
2434
|
function addTail(callback) {
|
|
3449
2435
|
notifyDepreciated({
|
|
@@ -3451,16 +2437,16 @@ function addTail(callback) {
|
|
|
3451
2437
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3452
2438
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3453
2439
|
});
|
|
3454
|
-
return getScheduler().onIdle(callback);
|
|
2440
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3455
2441
|
}
|
|
3456
2442
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3457
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2443
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3458
2444
|
}
|
|
3459
2445
|
function advance(timestamp) {
|
|
3460
|
-
getScheduler().step(timestamp);
|
|
2446
|
+
scheduler.getScheduler().step(timestamp);
|
|
3461
2447
|
}
|
|
3462
2448
|
|
|
3463
|
-
const version = "10.0.0-alpha.
|
|
2449
|
+
const version = "10.0.0-alpha.3";
|
|
3464
2450
|
const packageData = {
|
|
3465
2451
|
version: version};
|
|
3466
2452
|
|
|
@@ -14716,7 +13702,7 @@ function n0() {
|
|
|
14716
13702
|
var t0 = n0();
|
|
14717
13703
|
const r0 = Xb(t0);
|
|
14718
13704
|
|
|
14719
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13705
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
14720
13706
|
|
|
14721
13707
|
function createReconciler(config) {
|
|
14722
13708
|
const reconciler2 = r0(config);
|
|
@@ -14881,7 +13867,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
14881
13867
|
}
|
|
14882
13868
|
}
|
|
14883
13869
|
const reconstructed = [];
|
|
14884
|
-
function
|
|
13870
|
+
function flushReconstructedInstances() {
|
|
13871
|
+
if (reconstructed.length === 0) return;
|
|
13872
|
+
try {
|
|
13873
|
+
swapReconstructedInstances();
|
|
13874
|
+
} finally {
|
|
13875
|
+
reconstructed.length = 0;
|
|
13876
|
+
}
|
|
13877
|
+
}
|
|
13878
|
+
function swapReconstructedInstances() {
|
|
14885
13879
|
for (const [instance] of reconstructed) {
|
|
14886
13880
|
const parent = instance.parent;
|
|
14887
13881
|
if (parent) {
|
|
@@ -14899,6 +13893,7 @@ function swapInstances() {
|
|
|
14899
13893
|
}
|
|
14900
13894
|
}
|
|
14901
13895
|
if (instance.isHidden) unhideInstance(instance);
|
|
13896
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14902
13897
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14903
13898
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14904
13899
|
}
|
|
@@ -14911,6 +13906,8 @@ function swapInstances() {
|
|
|
14911
13906
|
instance.object.__r3f = instance;
|
|
14912
13907
|
setFiberRef(fiber, instance.object);
|
|
14913
13908
|
delete instance.appliedOnce;
|
|
13909
|
+
instance.eventCount = 0;
|
|
13910
|
+
instance.handlers = {};
|
|
14914
13911
|
applyProps(instance.object, instance.props);
|
|
14915
13912
|
if (instance.props.attach) {
|
|
14916
13913
|
attach(parent, instance);
|
|
@@ -14927,14 +13924,114 @@ function swapInstances() {
|
|
|
14927
13924
|
invalidateInstance(instance);
|
|
14928
13925
|
}
|
|
14929
13926
|
}
|
|
14930
|
-
reconstructed.length = 0;
|
|
14931
13927
|
}
|
|
14932
13928
|
const handleTextInstance = () => {
|
|
14933
13929
|
};
|
|
14934
13930
|
const NO_CONTEXT = {};
|
|
14935
13931
|
let currentUpdatePriority = NoEventPriority;
|
|
14936
|
-
|
|
14937
|
-
|
|
13932
|
+
function getEventPriority(type) {
|
|
13933
|
+
switch (type) {
|
|
13934
|
+
case "beforetoggle":
|
|
13935
|
+
case "cancel":
|
|
13936
|
+
case "click":
|
|
13937
|
+
case "close":
|
|
13938
|
+
case "contextmenu":
|
|
13939
|
+
case "copy":
|
|
13940
|
+
case "cut":
|
|
13941
|
+
case "auxclick":
|
|
13942
|
+
case "dblclick":
|
|
13943
|
+
case "dragend":
|
|
13944
|
+
case "dragstart":
|
|
13945
|
+
case "drop":
|
|
13946
|
+
case "focusin":
|
|
13947
|
+
case "focusout":
|
|
13948
|
+
case "input":
|
|
13949
|
+
case "invalid":
|
|
13950
|
+
case "keydown":
|
|
13951
|
+
case "keypress":
|
|
13952
|
+
case "keyup":
|
|
13953
|
+
case "mousedown":
|
|
13954
|
+
case "mouseup":
|
|
13955
|
+
case "paste":
|
|
13956
|
+
case "pause":
|
|
13957
|
+
case "play":
|
|
13958
|
+
case "pointercancel":
|
|
13959
|
+
case "pointerdown":
|
|
13960
|
+
case "pointerup":
|
|
13961
|
+
case "ratechange":
|
|
13962
|
+
case "reset":
|
|
13963
|
+
case "resize":
|
|
13964
|
+
case "seeked":
|
|
13965
|
+
case "submit":
|
|
13966
|
+
case "touchcancel":
|
|
13967
|
+
case "touchend":
|
|
13968
|
+
case "touchstart":
|
|
13969
|
+
case "volumechange":
|
|
13970
|
+
case "change":
|
|
13971
|
+
case "selectionchange":
|
|
13972
|
+
case "compositionstart":
|
|
13973
|
+
case "compositionend":
|
|
13974
|
+
case "compositionupdate":
|
|
13975
|
+
case "beforeinput":
|
|
13976
|
+
case "blur":
|
|
13977
|
+
case "fullscreenchange":
|
|
13978
|
+
case "focus":
|
|
13979
|
+
case "hashchange":
|
|
13980
|
+
case "popstate":
|
|
13981
|
+
case "select":
|
|
13982
|
+
case "selectstart":
|
|
13983
|
+
return e;
|
|
13984
|
+
case "drag":
|
|
13985
|
+
case "dragenter":
|
|
13986
|
+
case "dragexit":
|
|
13987
|
+
case "dragleave":
|
|
13988
|
+
case "dragover":
|
|
13989
|
+
case "mousemove":
|
|
13990
|
+
case "mouseout":
|
|
13991
|
+
case "mouseover":
|
|
13992
|
+
case "pointermove":
|
|
13993
|
+
case "pointerout":
|
|
13994
|
+
case "pointerover":
|
|
13995
|
+
case "scroll":
|
|
13996
|
+
case "touchmove":
|
|
13997
|
+
case "wheel":
|
|
13998
|
+
case "mouseenter":
|
|
13999
|
+
case "mouseleave":
|
|
14000
|
+
case "pointerenter":
|
|
14001
|
+
case "pointerleave":
|
|
14002
|
+
return o;
|
|
14003
|
+
case "message": {
|
|
14004
|
+
switch (Tb.unstable_getCurrentPriorityLevel()) {
|
|
14005
|
+
case Tb.unstable_ImmediatePriority:
|
|
14006
|
+
return e;
|
|
14007
|
+
case Tb.unstable_UserBlockingPriority:
|
|
14008
|
+
return o;
|
|
14009
|
+
case Tb.unstable_NormalPriority:
|
|
14010
|
+
case Tb.unstable_LowPriority:
|
|
14011
|
+
return r;
|
|
14012
|
+
case Tb.unstable_IdlePriority:
|
|
14013
|
+
return i$1;
|
|
14014
|
+
default:
|
|
14015
|
+
return r;
|
|
14016
|
+
}
|
|
14017
|
+
}
|
|
14018
|
+
default:
|
|
14019
|
+
return r;
|
|
14020
|
+
}
|
|
14021
|
+
}
|
|
14022
|
+
function scheduleMicrotask(callback) {
|
|
14023
|
+
if (typeof queueMicrotask === "function") {
|
|
14024
|
+
queueMicrotask(callback);
|
|
14025
|
+
} else if (typeof Promise !== "undefined") {
|
|
14026
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
14027
|
+
setTimeout(() => {
|
|
14028
|
+
throw error;
|
|
14029
|
+
});
|
|
14030
|
+
});
|
|
14031
|
+
} else {
|
|
14032
|
+
setTimeout(callback);
|
|
14033
|
+
}
|
|
14034
|
+
}
|
|
14938
14035
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
14939
14036
|
isPrimaryRenderer: false,
|
|
14940
14037
|
warnsIfNotActing: false,
|
|
@@ -14973,16 +14070,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14973
14070
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
14974
14071
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
14975
14072
|
if (reconstruct) {
|
|
14976
|
-
reconstructed.push([instance,
|
|
14073
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
14977
14074
|
} else {
|
|
14978
14075
|
const changedProps = diffProps(instance, newProps);
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14076
|
+
const attach2 = instance.props.attach;
|
|
14077
|
+
instance.props = getInstanceProps(newProps);
|
|
14078
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
14079
|
+
else delete instance.props.attach;
|
|
14080
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
14983
14081
|
}
|
|
14984
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14985
|
-
if (isTailSibling) swapInstances();
|
|
14986
14082
|
},
|
|
14987
14083
|
finalizeInitialChildren: (instance) => {
|
|
14988
14084
|
for (const prop in instance.props) {
|
|
@@ -15007,8 +14103,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15007
14103
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
15008
14104
|
return prepare(target, container, "", {});
|
|
15009
14105
|
},
|
|
15010
|
-
|
|
15011
|
-
|
|
14106
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
14107
|
+
// before layout effects run so refs point to the new objects
|
|
14108
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
15012
14109
|
shouldSetTextContent: () => false,
|
|
15013
14110
|
clearContainer: () => false,
|
|
15014
14111
|
hideInstance,
|
|
@@ -15016,6 +14113,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15016
14113
|
createTextInstance: handleTextInstance,
|
|
15017
14114
|
hideTextInstance: handleTextInstance,
|
|
15018
14115
|
unhideTextInstance: handleTextInstance,
|
|
14116
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
14117
|
+
supportsMicrotasks: true,
|
|
14118
|
+
scheduleMicrotask,
|
|
15019
14119
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
15020
14120
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
15021
14121
|
noTimeout: -1,
|
|
@@ -15056,28 +14156,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15056
14156
|
},
|
|
15057
14157
|
resolveUpdatePriority() {
|
|
15058
14158
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
case "dblclick":
|
|
15063
|
-
case "dragenter":
|
|
15064
|
-
case "dragleave":
|
|
15065
|
-
case "drop":
|
|
15066
|
-
case "pointercancel":
|
|
15067
|
-
case "pointerdown":
|
|
15068
|
-
case "pointerup":
|
|
15069
|
-
return e;
|
|
15070
|
-
case "dragover":
|
|
15071
|
-
case "pointermove":
|
|
15072
|
-
case "pointerout":
|
|
15073
|
-
case "pointerover":
|
|
15074
|
-
case "pointerenter":
|
|
15075
|
-
case "pointerleave":
|
|
15076
|
-
case "wheel":
|
|
15077
|
-
return o;
|
|
15078
|
-
default:
|
|
15079
|
-
return r;
|
|
15080
|
-
}
|
|
14159
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14160
|
+
if (eventType === void 0) return r;
|
|
14161
|
+
return getEventPriority(eventType);
|
|
15081
14162
|
},
|
|
15082
14163
|
resetFormInstance() {
|
|
15083
14164
|
},
|
|
@@ -15126,11 +14207,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
15126
14207
|
cloneMutableTextInstance(textInstance) {
|
|
15127
14208
|
return textInstance;
|
|
15128
14209
|
},
|
|
14210
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14211
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14212
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14213
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14214
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14215
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
15129
14216
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
15130
|
-
throw new Error("Not implemented.");
|
|
15131
14217
|
},
|
|
15132
14218
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
15133
|
-
throw new Error("Not implemented.");
|
|
15134
14219
|
},
|
|
15135
14220
|
// https://github.com/facebook/react/pull/32465
|
|
15136
14221
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -15215,6 +14300,7 @@ function createRoot(canvas) {
|
|
|
15215
14300
|
const lastConfiguredProps = {};
|
|
15216
14301
|
let configured = false;
|
|
15217
14302
|
let pending = null;
|
|
14303
|
+
let rendererSetup = null;
|
|
15218
14304
|
return {
|
|
15219
14305
|
async configure(props = {}) {
|
|
15220
14306
|
let resolve;
|
|
@@ -15245,7 +14331,7 @@ function createRoot(canvas) {
|
|
|
15245
14331
|
forceEven
|
|
15246
14332
|
} = props;
|
|
15247
14333
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
|
|
15248
|
-
|
|
14334
|
+
let state = store.getState();
|
|
15249
14335
|
const defaultGLProps = {
|
|
15250
14336
|
canvas,
|
|
15251
14337
|
powerPreference: "high-performance",
|
|
@@ -15273,9 +14359,21 @@ function createRoot(canvas) {
|
|
|
15273
14359
|
);
|
|
15274
14360
|
}
|
|
15275
14361
|
if (!state.internal.actualRenderer) {
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
|
|
14362
|
+
if (!rendererSetup) {
|
|
14363
|
+
rendererSetup = (async () => {
|
|
14364
|
+
{
|
|
14365
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
|
|
14366
|
+
state.internal.actualRenderer = renderer;
|
|
14367
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14368
|
+
}
|
|
14369
|
+
})().catch((err) => {
|
|
14370
|
+
rendererSetup = null;
|
|
14371
|
+
throw err;
|
|
14372
|
+
});
|
|
14373
|
+
}
|
|
14374
|
+
await rendererSetup;
|
|
14375
|
+
state = store.getState();
|
|
14376
|
+
renderer = state.internal.actualRenderer;
|
|
15279
14377
|
}
|
|
15280
14378
|
let raycaster = state.raycaster;
|
|
15281
14379
|
if (!raycaster) state.set({ raycaster: raycaster = new three.Raycaster() });
|
|
@@ -15455,15 +14553,15 @@ function createRoot(canvas) {
|
|
|
15455
14553
|
applyProps(currentRenderer, rendererProps);
|
|
15456
14554
|
}
|
|
15457
14555
|
}
|
|
15458
|
-
const scheduler = getScheduler();
|
|
14556
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15459
14557
|
const rootId = state.internal.rootId;
|
|
15460
14558
|
if (!rootId) {
|
|
15461
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15462
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14559
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14560
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15463
14561
|
getState: () => store.getState(),
|
|
15464
14562
|
onError: (err) => store.getState().setError(err)
|
|
15465
14563
|
});
|
|
15466
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14564
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15467
14565
|
() => {
|
|
15468
14566
|
const state2 = store.getState();
|
|
15469
14567
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15478,7 +14576,7 @@ function createRoot(canvas) {
|
|
|
15478
14576
|
system: true
|
|
15479
14577
|
}
|
|
15480
14578
|
);
|
|
15481
|
-
const unregisterEventsFlush = scheduler.register(
|
|
14579
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
15482
14580
|
() => {
|
|
15483
14581
|
const state2 = store.getState();
|
|
15484
14582
|
state2.events.flush?.();
|
|
@@ -15490,7 +14588,7 @@ function createRoot(canvas) {
|
|
|
15490
14588
|
system: true
|
|
15491
14589
|
}
|
|
15492
14590
|
);
|
|
15493
|
-
const unregisterFrustum = scheduler.register(
|
|
14591
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15494
14592
|
() => {
|
|
15495
14593
|
const state2 = store.getState();
|
|
15496
14594
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15500,11 +14598,11 @@ function createRoot(canvas) {
|
|
|
15500
14598
|
{
|
|
15501
14599
|
id: `${newRootId}_frustum`,
|
|
15502
14600
|
rootId: newRootId,
|
|
15503
|
-
|
|
14601
|
+
before: "render",
|
|
15504
14602
|
system: true
|
|
15505
14603
|
}
|
|
15506
14604
|
);
|
|
15507
|
-
const unregisterVisibility = scheduler.register(
|
|
14605
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15508
14606
|
() => {
|
|
15509
14607
|
const state2 = store.getState();
|
|
15510
14608
|
checkVisibility(state2);
|
|
@@ -15512,16 +14610,16 @@ function createRoot(canvas) {
|
|
|
15512
14610
|
{
|
|
15513
14611
|
id: `${newRootId}_visibility`,
|
|
15514
14612
|
rootId: newRootId,
|
|
15515
|
-
|
|
14613
|
+
before: "render",
|
|
15516
14614
|
system: true,
|
|
15517
14615
|
after: `${newRootId}_frustum`
|
|
15518
14616
|
}
|
|
15519
14617
|
);
|
|
15520
|
-
const unregisterRender = scheduler.register(
|
|
14618
|
+
const unregisterRender = scheduler$1.register(
|
|
15521
14619
|
() => {
|
|
15522
14620
|
const state2 = store.getState();
|
|
15523
14621
|
const renderer2 = state2.internal.actualRenderer;
|
|
15524
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14622
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15525
14623
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15526
14624
|
try {
|
|
15527
14625
|
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
@@ -15554,11 +14652,11 @@ function createRoot(canvas) {
|
|
|
15554
14652
|
unregisterVisibility();
|
|
15555
14653
|
unregisterRender();
|
|
15556
14654
|
},
|
|
15557
|
-
scheduler
|
|
14655
|
+
scheduler: scheduler$1
|
|
15558
14656
|
}
|
|
15559
14657
|
}));
|
|
15560
14658
|
}
|
|
15561
|
-
scheduler.frameloop = frameloop;
|
|
14659
|
+
scheduler$1.frameloop = frameloop;
|
|
15562
14660
|
onCreated = onCreatedCallback;
|
|
15563
14661
|
configured = true;
|
|
15564
14662
|
resolve();
|
|
@@ -15625,7 +14723,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
15625
14723
|
dispose(state.scene);
|
|
15626
14724
|
_roots.delete(canvas);
|
|
15627
14725
|
if (callback) callback(canvas);
|
|
15628
|
-
} catch {
|
|
14726
|
+
} catch (error) {
|
|
14727
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
15629
14728
|
}
|
|
15630
14729
|
}, 500);
|
|
15631
14730
|
}
|
|
@@ -15688,6 +14787,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15688
14787
|
viewport = rootState.viewport.getCurrentViewport(camera, new three.Vector3(), resolvedSize);
|
|
15689
14788
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15690
14789
|
}
|
|
14790
|
+
const set = injectState.set;
|
|
15691
14791
|
return {
|
|
15692
14792
|
// The intersect consists of the previous root state
|
|
15693
14793
|
...rootState,
|
|
@@ -15706,7 +14806,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15706
14806
|
size: resolvedSize,
|
|
15707
14807
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15708
14808
|
// Layers are allowed to override events
|
|
15709
|
-
setEvents: (events2) =>
|
|
14809
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15710
14810
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15711
14811
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15712
14812
|
};
|
|
@@ -15735,6 +14835,81 @@ function flushSync(fn) {
|
|
|
15735
14835
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15736
14836
|
}
|
|
15737
14837
|
|
|
14838
|
+
function parseBackground(background) {
|
|
14839
|
+
if (!background) return null;
|
|
14840
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14841
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14842
|
+
return {
|
|
14843
|
+
...rest,
|
|
14844
|
+
preset,
|
|
14845
|
+
files: envMap || files,
|
|
14846
|
+
backgroundFiles: backgroundMap,
|
|
14847
|
+
background: true
|
|
14848
|
+
};
|
|
14849
|
+
}
|
|
14850
|
+
if (typeof background === "number") {
|
|
14851
|
+
return { color: background, background: true };
|
|
14852
|
+
}
|
|
14853
|
+
if (typeof background === "string") {
|
|
14854
|
+
if (background in presetsObj) {
|
|
14855
|
+
return { preset: background, background: true };
|
|
14856
|
+
}
|
|
14857
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14858
|
+
return { files: background, background: true };
|
|
14859
|
+
}
|
|
14860
|
+
return { color: background, background: true };
|
|
14861
|
+
}
|
|
14862
|
+
if (background.isColor) {
|
|
14863
|
+
return { color: background, background: true };
|
|
14864
|
+
}
|
|
14865
|
+
return null;
|
|
14866
|
+
}
|
|
14867
|
+
|
|
14868
|
+
function parseRendererConfig(rendererProp) {
|
|
14869
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14870
|
+
if (isRendererConfig) {
|
|
14871
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14872
|
+
return {
|
|
14873
|
+
primaryCanvas: pc,
|
|
14874
|
+
scheduler: sc,
|
|
14875
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14876
|
+
};
|
|
14877
|
+
}
|
|
14878
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14879
|
+
}
|
|
14880
|
+
|
|
14881
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14882
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14883
|
+
function getKindRegistry(store, kind) {
|
|
14884
|
+
let registry = registries.get(store);
|
|
14885
|
+
if (!registry) {
|
|
14886
|
+
registry = {
|
|
14887
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14888
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14889
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14890
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14891
|
+
};
|
|
14892
|
+
registries.set(store, registry);
|
|
14893
|
+
}
|
|
14894
|
+
return registry[kind];
|
|
14895
|
+
}
|
|
14896
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14897
|
+
const registry = getKindRegistry(store, kind);
|
|
14898
|
+
{
|
|
14899
|
+
registry.valid.clear();
|
|
14900
|
+
registry.staged.clear();
|
|
14901
|
+
}
|
|
14902
|
+
}
|
|
14903
|
+
function invalidateAllResources(store) {
|
|
14904
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14905
|
+
}
|
|
14906
|
+
|
|
14907
|
+
function clearHmrCaches(store) {
|
|
14908
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14909
|
+
invalidateAllResources(primary);
|
|
14910
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14911
|
+
}
|
|
14912
|
+
|
|
15738
14913
|
function CanvasImpl({
|
|
15739
14914
|
ref,
|
|
15740
14915
|
children,
|
|
@@ -15755,6 +14930,8 @@ function CanvasImpl({
|
|
|
15755
14930
|
raycaster,
|
|
15756
14931
|
camera,
|
|
15757
14932
|
scene,
|
|
14933
|
+
autoUpdateFrustum,
|
|
14934
|
+
occlusion,
|
|
15758
14935
|
onPointerMissed,
|
|
15759
14936
|
onDragOverMissed,
|
|
15760
14937
|
onDropMissed,
|
|
@@ -15766,49 +14943,10 @@ function CanvasImpl({
|
|
|
15766
14943
|
forceEven,
|
|
15767
14944
|
...props
|
|
15768
14945
|
}) {
|
|
15769
|
-
const
|
|
15770
|
-
let primaryCanvas;
|
|
15771
|
-
let scheduler;
|
|
15772
|
-
let renderer;
|
|
15773
|
-
if (isRendererConfig) {
|
|
15774
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
15775
|
-
primaryCanvas = pc;
|
|
15776
|
-
scheduler = sc;
|
|
15777
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
15778
|
-
} else {
|
|
15779
|
-
renderer = rendererProp;
|
|
15780
|
-
}
|
|
14946
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15781
14947
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15782
14948
|
const Bridge = useBridge();
|
|
15783
|
-
const backgroundProps = React__namespace.useMemo(() =>
|
|
15784
|
-
if (!background) return null;
|
|
15785
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15786
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15787
|
-
return {
|
|
15788
|
-
...rest,
|
|
15789
|
-
preset,
|
|
15790
|
-
files: envMap || files,
|
|
15791
|
-
backgroundFiles: backgroundMap,
|
|
15792
|
-
background: true
|
|
15793
|
-
};
|
|
15794
|
-
}
|
|
15795
|
-
if (typeof background === "number") {
|
|
15796
|
-
return { color: background, background: true };
|
|
15797
|
-
}
|
|
15798
|
-
if (typeof background === "string") {
|
|
15799
|
-
if (background in presetsObj) {
|
|
15800
|
-
return { preset: background, background: true };
|
|
15801
|
-
}
|
|
15802
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15803
|
-
return { files: background, background: true };
|
|
15804
|
-
}
|
|
15805
|
-
return { color: background, background: true };
|
|
15806
|
-
}
|
|
15807
|
-
if (background.isColor) {
|
|
15808
|
-
return { color: background, background: true };
|
|
15809
|
-
}
|
|
15810
|
-
return null;
|
|
15811
|
-
}, [background]);
|
|
14949
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15812
14950
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15813
14951
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15814
14952
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15850,6 +14988,7 @@ function CanvasImpl({
|
|
|
15850
14988
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15851
14989
|
const [block, setBlock] = React__namespace.useState(false);
|
|
15852
14990
|
const [error, setError] = React__namespace.useState(false);
|
|
14991
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
15853
14992
|
if (block) throw block;
|
|
15854
14993
|
if (error) throw error;
|
|
15855
14994
|
const root = React__namespace.useRef(null);
|
|
@@ -15857,6 +14996,7 @@ function CanvasImpl({
|
|
|
15857
14996
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
15858
14997
|
useIsomorphicLayoutEffect(() => {
|
|
15859
14998
|
effectActiveRef.current = true;
|
|
14999
|
+
if (fallbackVisible) return;
|
|
15860
15000
|
const canvas = canvasRef.current;
|
|
15861
15001
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15862
15002
|
if (!root.current) {
|
|
@@ -15877,7 +15017,7 @@ function CanvasImpl({
|
|
|
15877
15017
|
}
|
|
15878
15018
|
async function run() {
|
|
15879
15019
|
if (!effectActiveRef.current || !root.current) return;
|
|
15880
|
-
await root.current.configure({
|
|
15020
|
+
const configured = await root.current.configure({
|
|
15881
15021
|
id,
|
|
15882
15022
|
primaryCanvas,
|
|
15883
15023
|
scheduler,
|
|
@@ -15892,6 +15032,8 @@ function CanvasImpl({
|
|
|
15892
15032
|
performance,
|
|
15893
15033
|
raycaster,
|
|
15894
15034
|
camera,
|
|
15035
|
+
autoUpdateFrustum,
|
|
15036
|
+
occlusion,
|
|
15895
15037
|
size: effectiveSize,
|
|
15896
15038
|
// Store size props for reset functionality
|
|
15897
15039
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15916,8 +15058,20 @@ function CanvasImpl({
|
|
|
15916
15058
|
}
|
|
15917
15059
|
onCreated?.(state);
|
|
15918
15060
|
}
|
|
15919
|
-
})
|
|
15920
|
-
|
|
15061
|
+
}).then(
|
|
15062
|
+
() => true,
|
|
15063
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15064
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15065
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15066
|
+
(setupError) => {
|
|
15067
|
+
if (effectActiveRef.current) {
|
|
15068
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15069
|
+
else setError(setupError);
|
|
15070
|
+
}
|
|
15071
|
+
return false;
|
|
15072
|
+
}
|
|
15073
|
+
);
|
|
15074
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15921
15075
|
root.current.render(
|
|
15922
15076
|
/* @__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: [
|
|
15923
15077
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -15951,14 +15105,7 @@ function CanvasImpl({
|
|
|
15951
15105
|
const handleHMR = () => {
|
|
15952
15106
|
queueMicrotask(() => {
|
|
15953
15107
|
const rootEntry = _roots.get(canvas);
|
|
15954
|
-
if (rootEntry?.store)
|
|
15955
|
-
console.log("[R3F] HMR detected \u2014 rebuilding nodes/uniforms");
|
|
15956
|
-
rootEntry.store.setState((state) => ({
|
|
15957
|
-
nodes: {},
|
|
15958
|
-
uniforms: {},
|
|
15959
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15960
|
-
}));
|
|
15961
|
-
}
|
|
15108
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15962
15109
|
});
|
|
15963
15110
|
};
|
|
15964
15111
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('legacy.cjs', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
@@ -15987,7 +15134,11 @@ function CanvasImpl({
|
|
|
15987
15134
|
...style
|
|
15988
15135
|
},
|
|
15989
15136
|
...props,
|
|
15990
|
-
children:
|
|
15137
|
+
children: fallbackVisible ? (
|
|
15138
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15139
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15140
|
+
fallback
|
|
15141
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
15991
15142
|
"canvas",
|
|
15992
15143
|
{
|
|
15993
15144
|
ref: canvasRef,
|
|
@@ -16006,6 +15157,8 @@ function Canvas(props) {
|
|
|
16006
15157
|
|
|
16007
15158
|
extend(THREE);
|
|
16008
15159
|
|
|
15160
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
15161
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
16009
15162
|
exports.Block = Block;
|
|
16010
15163
|
exports.Canvas = Canvas;
|
|
16011
15164
|
exports.Environment = Environment;
|
|
@@ -16021,7 +15174,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
16021
15174
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
16022
15175
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
16023
15176
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
16024
|
-
exports.Scheduler = Scheduler;
|
|
16025
15177
|
exports.Texture = Texture;
|
|
16026
15178
|
exports._roots = _roots;
|
|
16027
15179
|
exports.act = act;
|
|
@@ -16051,7 +15203,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
16051
15203
|
exports.getPrimary = getPrimary;
|
|
16052
15204
|
exports.getPrimaryIds = getPrimaryIds;
|
|
16053
15205
|
exports.getRootState = getRootState;
|
|
16054
|
-
exports.getScheduler = getScheduler;
|
|
16055
15206
|
exports.getUuidPrefix = getUuidPrefix;
|
|
16056
15207
|
exports.hasConstructor = hasConstructor;
|
|
16057
15208
|
exports.hasPrimary = hasPrimary;
|