@react-three/fiber 10.0.0-canary.d6fdf72 → 10.0.0-canary.f046a54
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 +230 -1195
- package/dist/index.d.cts +25 -720
- package/dist/index.d.mts +25 -720
- package/dist/index.d.ts +25 -720
- package/dist/index.mjs +203 -1167
- package/dist/legacy.cjs +185 -1150
- package/dist/legacy.d.cts +25 -720
- package/dist/legacy.d.mts +25 -720
- package/dist/legacy.d.ts +25 -720
- package/dist/legacy.mjs +158 -1122
- package/dist/webgpu/index.cjs +261 -1208
- package/dist/webgpu/index.d.cts +25 -720
- package/dist/webgpu/index.d.mts +25 -720
- package/dist/webgpu/index.d.ts +25 -720
- package/dist/webgpu/index.mjs +234 -1180
- package/package.json +2 -1
- package/readme.md +2 -2
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;
|
|
@@ -455,9 +456,9 @@ function Environment(props) {
|
|
|
455
456
|
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
457
|
}
|
|
457
458
|
|
|
458
|
-
var __defProp
|
|
459
|
-
var __defNormalProp
|
|
460
|
-
var __publicField
|
|
459
|
+
var __defProp = Object.defineProperty;
|
|
460
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
461
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
461
462
|
const act = React__namespace["act"];
|
|
462
463
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
463
464
|
function useMutableCallback(fn) {
|
|
@@ -489,7 +490,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
489
490
|
return _a = class extends React__namespace.Component {
|
|
490
491
|
constructor() {
|
|
491
492
|
super(...arguments);
|
|
492
|
-
__publicField
|
|
493
|
+
__publicField(this, "state", { error: false });
|
|
493
494
|
}
|
|
494
495
|
componentDidCatch(err) {
|
|
495
496
|
this.props.set(err);
|
|
@@ -497,7 +498,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
497
498
|
render() {
|
|
498
499
|
return this.state.error ? null : this.props.children;
|
|
499
500
|
}
|
|
500
|
-
}, __publicField
|
|
501
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
501
502
|
})();
|
|
502
503
|
|
|
503
504
|
const is = {
|
|
@@ -1018,6 +1019,19 @@ function applyProps(object, props) {
|
|
|
1018
1019
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1019
1020
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1020
1021
|
else target.set(value);
|
|
1022
|
+
} else if (root instanceof three.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1023
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1024
|
+
const uniforms = root.uniforms;
|
|
1025
|
+
const nextUniforms = value;
|
|
1026
|
+
for (const name in nextUniforms) {
|
|
1027
|
+
const uniform = nextUniforms[name];
|
|
1028
|
+
const targetUniform = uniforms[name];
|
|
1029
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1030
|
+
else {
|
|
1031
|
+
const nextUniform = uniform instanceof three.Uniform ? uniform.clone() : new three.Uniform(uniform.value);
|
|
1032
|
+
uniforms[name] = nextUniform;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1021
1035
|
} else {
|
|
1022
1036
|
root[key] = value;
|
|
1023
1037
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1657,1036 +1671,12 @@ function notifyAlpha({ message, link }) {
|
|
|
1657
1671
|
}
|
|
1658
1672
|
}
|
|
1659
1673
|
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
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?.();
|
|
1674
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1675
|
+
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1676
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1677
|
+
if (!stack) return false;
|
|
1678
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1679
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m)) || INTERNAL_FIBER_MARKERS.some((m) => caller.includes(m));
|
|
2690
1680
|
}
|
|
2691
1681
|
|
|
2692
1682
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2798,7 +1788,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2798
1788
|
size: newSize,
|
|
2799
1789
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2800
1790
|
}));
|
|
2801
|
-
getScheduler().invalidate();
|
|
1791
|
+
scheduler.getScheduler().invalidate();
|
|
2802
1792
|
}
|
|
2803
1793
|
}
|
|
2804
1794
|
return;
|
|
@@ -2813,7 +1803,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2813
1803
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2814
1804
|
_sizeImperative: true
|
|
2815
1805
|
}));
|
|
2816
|
-
getScheduler().invalidate();
|
|
1806
|
+
scheduler.getScheduler().invalidate();
|
|
2817
1807
|
},
|
|
2818
1808
|
setDpr: (dpr) => set((state2) => {
|
|
2819
1809
|
const resolved = calculateDpr(dpr);
|
|
@@ -2888,8 +1878,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2888
1878
|
const currentState = rootStore.getState();
|
|
2889
1879
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2890
1880
|
const stack = new Error().stack || "";
|
|
2891
|
-
|
|
2892
|
-
if (!isInternalAccess) {
|
|
1881
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2893
1882
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2894
1883
|
notifyDepreciated({
|
|
2895
1884
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -3002,26 +1991,32 @@ function loadingFn(extensions, onProgress) {
|
|
|
3002
1991
|
);
|
|
3003
1992
|
};
|
|
3004
1993
|
}
|
|
3005
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
3006
|
-
const
|
|
1994
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1995
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1996
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
3007
1997
|
const fn = loadingFn(extensions, onProgress);
|
|
3008
|
-
const results =
|
|
1998
|
+
const results = cacheKeys.map(
|
|
1999
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2000
|
+
);
|
|
3009
2001
|
return Array.isArray(input) ? results : results[0];
|
|
3010
2002
|
}
|
|
3011
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
3012
|
-
const
|
|
3013
|
-
|
|
2003
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2004
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2005
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2006
|
+
cacheKeys.forEach(
|
|
2007
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2008
|
+
);
|
|
3014
2009
|
};
|
|
3015
|
-
useLoader.clear = function(loader, input) {
|
|
3016
|
-
const
|
|
3017
|
-
|
|
2010
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2011
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2012
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
3018
2013
|
};
|
|
3019
2014
|
useLoader.loader = getLoader;
|
|
3020
2015
|
|
|
3021
2016
|
function useFrame(callback, priorityOrOptions) {
|
|
3022
2017
|
const store = React__namespace.useContext(context);
|
|
3023
2018
|
const isInsideCanvas = store !== null;
|
|
3024
|
-
const scheduler = getScheduler();
|
|
2019
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
3025
2020
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
3026
2021
|
id: priorityOrOptions.id,
|
|
3027
2022
|
phase: priorityOrOptions.phase,
|
|
@@ -3069,7 +2064,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3069
2064
|
};
|
|
3070
2065
|
callbackRef.current?.(mergedState, delta);
|
|
3071
2066
|
};
|
|
3072
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2067
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
3073
2068
|
id,
|
|
3074
2069
|
rootId,
|
|
3075
2070
|
...options
|
|
@@ -3090,37 +2085,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3090
2085
|
}
|
|
3091
2086
|
};
|
|
3092
2087
|
} else {
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
unregisterJob = registerOutside();
|
|
3102
|
-
});
|
|
3103
|
-
return () => {
|
|
3104
|
-
unsubReady();
|
|
3105
|
-
unregisterJob?.();
|
|
3106
|
-
};
|
|
2088
|
+
return scheduler$1.register(
|
|
2089
|
+
(state, delta) => {
|
|
2090
|
+
const frameState = state;
|
|
2091
|
+
if (!frameState.renderer) return;
|
|
2092
|
+
callbackRef.current?.(frameState, delta);
|
|
2093
|
+
},
|
|
2094
|
+
{ id, ...options }
|
|
2095
|
+
);
|
|
3107
2096
|
}
|
|
3108
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2097
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
3109
2098
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
3110
2099
|
// Subscribe function
|
|
3111
2100
|
React__namespace.useCallback(
|
|
3112
2101
|
(onStoreChange) => {
|
|
3113
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2102
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
3114
2103
|
},
|
|
3115
2104
|
[id]
|
|
3116
2105
|
),
|
|
3117
2106
|
// getSnapshot function
|
|
3118
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2107
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
3119
2108
|
// getServerSnapshot function (SSR)
|
|
3120
2109
|
React__namespace.useCallback(() => false, [])
|
|
3121
2110
|
);
|
|
3122
2111
|
const controls = React__namespace.useMemo(() => {
|
|
3123
|
-
const scheduler2 = getScheduler();
|
|
2112
|
+
const scheduler2 = scheduler.getScheduler();
|
|
3124
2113
|
return {
|
|
3125
2114
|
/** The job's unique ID */
|
|
3126
2115
|
id,
|
|
@@ -3135,7 +2124,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3135
2124
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3136
2125
|
*/
|
|
3137
2126
|
step: (timestamp) => {
|
|
3138
|
-
getScheduler().stepJob(id, timestamp);
|
|
2127
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
3139
2128
|
},
|
|
3140
2129
|
/**
|
|
3141
2130
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -3143,20 +2132,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3143
2132
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
3144
2133
|
*/
|
|
3145
2134
|
stepAll: (timestamp) => {
|
|
3146
|
-
getScheduler().step(timestamp);
|
|
2135
|
+
scheduler.getScheduler().step(timestamp);
|
|
3147
2136
|
},
|
|
3148
2137
|
/**
|
|
3149
2138
|
* Pause this job (set enabled=false).
|
|
3150
2139
|
* Job remains registered but won't run.
|
|
3151
2140
|
*/
|
|
3152
2141
|
pause: () => {
|
|
3153
|
-
getScheduler().pauseJob(id);
|
|
2142
|
+
scheduler.getScheduler().pauseJob(id);
|
|
3154
2143
|
},
|
|
3155
2144
|
/**
|
|
3156
2145
|
* Resume this job (set enabled=true).
|
|
3157
2146
|
*/
|
|
3158
2147
|
resume: () => {
|
|
3159
|
-
getScheduler().resumeJob(id);
|
|
2148
|
+
scheduler.getScheduler().resumeJob(id);
|
|
3160
2149
|
},
|
|
3161
2150
|
/**
|
|
3162
2151
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -3414,7 +2403,7 @@ function addEffect(callback) {
|
|
|
3414
2403
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3415
2404
|
});
|
|
3416
2405
|
const id = `legacy_effect_${effectId++}`;
|
|
3417
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2406
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3418
2407
|
}
|
|
3419
2408
|
function addAfterEffect(callback) {
|
|
3420
2409
|
notifyDepreciated({
|
|
@@ -3423,7 +2412,7 @@ function addAfterEffect(callback) {
|
|
|
3423
2412
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3424
2413
|
});
|
|
3425
2414
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3426
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2415
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3427
2416
|
}
|
|
3428
2417
|
function addTail(callback) {
|
|
3429
2418
|
notifyDepreciated({
|
|
@@ -3431,13 +2420,13 @@ function addTail(callback) {
|
|
|
3431
2420
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3432
2421
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3433
2422
|
});
|
|
3434
|
-
return getScheduler().onIdle(callback);
|
|
2423
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3435
2424
|
}
|
|
3436
2425
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3437
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2426
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3438
2427
|
}
|
|
3439
2428
|
function advance(timestamp) {
|
|
3440
|
-
getScheduler().step(timestamp);
|
|
2429
|
+
scheduler.getScheduler().step(timestamp);
|
|
3441
2430
|
}
|
|
3442
2431
|
|
|
3443
2432
|
const version = "10.0.0-alpha.2";
|
|
@@ -14879,6 +13868,7 @@ function swapInstances() {
|
|
|
14879
13868
|
}
|
|
14880
13869
|
}
|
|
14881
13870
|
if (instance.isHidden) unhideInstance(instance);
|
|
13871
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14882
13872
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14883
13873
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14884
13874
|
}
|
|
@@ -14891,6 +13881,8 @@ function swapInstances() {
|
|
|
14891
13881
|
instance.object.__r3f = instance;
|
|
14892
13882
|
setFiberRef(fiber, instance.object);
|
|
14893
13883
|
delete instance.appliedOnce;
|
|
13884
|
+
instance.eventCount = 0;
|
|
13885
|
+
instance.handlers = {};
|
|
14894
13886
|
applyProps(instance.object, instance.props);
|
|
14895
13887
|
if (instance.props.attach) {
|
|
14896
13888
|
attach(parent, instance);
|
|
@@ -15195,6 +14187,7 @@ function createRoot(canvas) {
|
|
|
15195
14187
|
const lastConfiguredProps = {};
|
|
15196
14188
|
let configured = false;
|
|
15197
14189
|
let pending = null;
|
|
14190
|
+
let rendererSetup = null;
|
|
15198
14191
|
return {
|
|
15199
14192
|
async configure(props = {}) {
|
|
15200
14193
|
let resolve;
|
|
@@ -15225,7 +14218,7 @@ function createRoot(canvas) {
|
|
|
15225
14218
|
forceEven
|
|
15226
14219
|
} = props;
|
|
15227
14220
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
|
|
15228
|
-
|
|
14221
|
+
let state = store.getState();
|
|
15229
14222
|
const defaultGLProps = {
|
|
15230
14223
|
canvas,
|
|
15231
14224
|
powerPreference: "high-performance",
|
|
@@ -15253,9 +14246,21 @@ function createRoot(canvas) {
|
|
|
15253
14246
|
);
|
|
15254
14247
|
}
|
|
15255
14248
|
if (!state.internal.actualRenderer) {
|
|
15256
|
-
|
|
15257
|
-
|
|
15258
|
-
|
|
14249
|
+
if (!rendererSetup) {
|
|
14250
|
+
rendererSetup = (async () => {
|
|
14251
|
+
{
|
|
14252
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
|
|
14253
|
+
state.internal.actualRenderer = renderer;
|
|
14254
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14255
|
+
}
|
|
14256
|
+
})().catch((err) => {
|
|
14257
|
+
rendererSetup = null;
|
|
14258
|
+
throw err;
|
|
14259
|
+
});
|
|
14260
|
+
}
|
|
14261
|
+
await rendererSetup;
|
|
14262
|
+
state = store.getState();
|
|
14263
|
+
renderer = state.internal.actualRenderer;
|
|
15259
14264
|
}
|
|
15260
14265
|
let raycaster = state.raycaster;
|
|
15261
14266
|
if (!raycaster) state.set({ raycaster: raycaster = new three.Raycaster() });
|
|
@@ -15435,15 +14440,15 @@ function createRoot(canvas) {
|
|
|
15435
14440
|
applyProps(currentRenderer, rendererProps);
|
|
15436
14441
|
}
|
|
15437
14442
|
}
|
|
15438
|
-
const scheduler = getScheduler();
|
|
14443
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15439
14444
|
const rootId = state.internal.rootId;
|
|
15440
14445
|
if (!rootId) {
|
|
15441
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15442
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14446
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14447
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15443
14448
|
getState: () => store.getState(),
|
|
15444
14449
|
onError: (err) => store.getState().setError(err)
|
|
15445
14450
|
});
|
|
15446
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14451
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15447
14452
|
() => {
|
|
15448
14453
|
const state2 = store.getState();
|
|
15449
14454
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15458,7 +14463,7 @@ function createRoot(canvas) {
|
|
|
15458
14463
|
system: true
|
|
15459
14464
|
}
|
|
15460
14465
|
);
|
|
15461
|
-
const unregisterEventsFlush = scheduler.register(
|
|
14466
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
15462
14467
|
() => {
|
|
15463
14468
|
const state2 = store.getState();
|
|
15464
14469
|
state2.events.flush?.();
|
|
@@ -15470,7 +14475,7 @@ function createRoot(canvas) {
|
|
|
15470
14475
|
system: true
|
|
15471
14476
|
}
|
|
15472
14477
|
);
|
|
15473
|
-
const unregisterFrustum = scheduler.register(
|
|
14478
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15474
14479
|
() => {
|
|
15475
14480
|
const state2 = store.getState();
|
|
15476
14481
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15480,11 +14485,11 @@ function createRoot(canvas) {
|
|
|
15480
14485
|
{
|
|
15481
14486
|
id: `${newRootId}_frustum`,
|
|
15482
14487
|
rootId: newRootId,
|
|
15483
|
-
|
|
14488
|
+
before: "render",
|
|
15484
14489
|
system: true
|
|
15485
14490
|
}
|
|
15486
14491
|
);
|
|
15487
|
-
const unregisterVisibility = scheduler.register(
|
|
14492
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15488
14493
|
() => {
|
|
15489
14494
|
const state2 = store.getState();
|
|
15490
14495
|
checkVisibility(state2);
|
|
@@ -15492,16 +14497,16 @@ function createRoot(canvas) {
|
|
|
15492
14497
|
{
|
|
15493
14498
|
id: `${newRootId}_visibility`,
|
|
15494
14499
|
rootId: newRootId,
|
|
15495
|
-
|
|
14500
|
+
before: "render",
|
|
15496
14501
|
system: true,
|
|
15497
14502
|
after: `${newRootId}_frustum`
|
|
15498
14503
|
}
|
|
15499
14504
|
);
|
|
15500
|
-
const unregisterRender = scheduler.register(
|
|
14505
|
+
const unregisterRender = scheduler$1.register(
|
|
15501
14506
|
() => {
|
|
15502
14507
|
const state2 = store.getState();
|
|
15503
14508
|
const renderer2 = state2.internal.actualRenderer;
|
|
15504
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14509
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15505
14510
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15506
14511
|
try {
|
|
15507
14512
|
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
@@ -15534,11 +14539,11 @@ function createRoot(canvas) {
|
|
|
15534
14539
|
unregisterVisibility();
|
|
15535
14540
|
unregisterRender();
|
|
15536
14541
|
},
|
|
15537
|
-
scheduler
|
|
14542
|
+
scheduler: scheduler$1
|
|
15538
14543
|
}
|
|
15539
14544
|
}));
|
|
15540
14545
|
}
|
|
15541
|
-
scheduler.frameloop = frameloop;
|
|
14546
|
+
scheduler$1.frameloop = frameloop;
|
|
15542
14547
|
onCreated = onCreatedCallback;
|
|
15543
14548
|
configured = true;
|
|
15544
14549
|
resolve();
|
|
@@ -15668,6 +14673,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15668
14673
|
viewport = rootState.viewport.getCurrentViewport(camera, new three.Vector3(), resolvedSize);
|
|
15669
14674
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15670
14675
|
}
|
|
14676
|
+
const set = injectState.set;
|
|
15671
14677
|
return {
|
|
15672
14678
|
// The intersect consists of the previous root state
|
|
15673
14679
|
...rootState,
|
|
@@ -15686,7 +14692,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15686
14692
|
size: resolvedSize,
|
|
15687
14693
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15688
14694
|
// Layers are allowed to override events
|
|
15689
|
-
setEvents: (events2) =>
|
|
14695
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15690
14696
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15691
14697
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15692
14698
|
};
|
|
@@ -15715,6 +14721,59 @@ function flushSync(fn) {
|
|
|
15715
14721
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15716
14722
|
}
|
|
15717
14723
|
|
|
14724
|
+
function parseBackground(background) {
|
|
14725
|
+
if (!background) return null;
|
|
14726
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14727
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14728
|
+
return {
|
|
14729
|
+
...rest,
|
|
14730
|
+
preset,
|
|
14731
|
+
files: envMap || files,
|
|
14732
|
+
backgroundFiles: backgroundMap,
|
|
14733
|
+
background: true
|
|
14734
|
+
};
|
|
14735
|
+
}
|
|
14736
|
+
if (typeof background === "number") {
|
|
14737
|
+
return { color: background, background: true };
|
|
14738
|
+
}
|
|
14739
|
+
if (typeof background === "string") {
|
|
14740
|
+
if (background in presetsObj) {
|
|
14741
|
+
return { preset: background, background: true };
|
|
14742
|
+
}
|
|
14743
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14744
|
+
return { files: background, background: true };
|
|
14745
|
+
}
|
|
14746
|
+
return { color: background, background: true };
|
|
14747
|
+
}
|
|
14748
|
+
if (background.isColor) {
|
|
14749
|
+
return { color: background, background: true };
|
|
14750
|
+
}
|
|
14751
|
+
return null;
|
|
14752
|
+
}
|
|
14753
|
+
|
|
14754
|
+
function parseRendererConfig(rendererProp) {
|
|
14755
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14756
|
+
if (isRendererConfig) {
|
|
14757
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14758
|
+
return {
|
|
14759
|
+
primaryCanvas: pc,
|
|
14760
|
+
scheduler: sc,
|
|
14761
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14762
|
+
};
|
|
14763
|
+
}
|
|
14764
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14765
|
+
}
|
|
14766
|
+
|
|
14767
|
+
function clearHmrCaches(store) {
|
|
14768
|
+
store.setState((state) => ({
|
|
14769
|
+
nodes: {},
|
|
14770
|
+
uniforms: {},
|
|
14771
|
+
buffers: {},
|
|
14772
|
+
gpuStorage: {},
|
|
14773
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14774
|
+
}));
|
|
14775
|
+
}
|
|
14776
|
+
|
|
15718
14777
|
function CanvasImpl({
|
|
15719
14778
|
ref,
|
|
15720
14779
|
children,
|
|
@@ -15735,6 +14794,8 @@ function CanvasImpl({
|
|
|
15735
14794
|
raycaster,
|
|
15736
14795
|
camera,
|
|
15737
14796
|
scene,
|
|
14797
|
+
autoUpdateFrustum,
|
|
14798
|
+
occlusion,
|
|
15738
14799
|
onPointerMissed,
|
|
15739
14800
|
onDragOverMissed,
|
|
15740
14801
|
onDropMissed,
|
|
@@ -15746,49 +14807,10 @@ function CanvasImpl({
|
|
|
15746
14807
|
forceEven,
|
|
15747
14808
|
...props
|
|
15748
14809
|
}) {
|
|
15749
|
-
const
|
|
15750
|
-
let primaryCanvas;
|
|
15751
|
-
let scheduler;
|
|
15752
|
-
let renderer;
|
|
15753
|
-
if (isRendererConfig) {
|
|
15754
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
15755
|
-
primaryCanvas = pc;
|
|
15756
|
-
scheduler = sc;
|
|
15757
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
15758
|
-
} else {
|
|
15759
|
-
renderer = rendererProp;
|
|
15760
|
-
}
|
|
14810
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15761
14811
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15762
14812
|
const Bridge = useBridge();
|
|
15763
|
-
const backgroundProps = React__namespace.useMemo(() =>
|
|
15764
|
-
if (!background) return null;
|
|
15765
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15766
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15767
|
-
return {
|
|
15768
|
-
...rest,
|
|
15769
|
-
preset,
|
|
15770
|
-
files: envMap || files,
|
|
15771
|
-
backgroundFiles: backgroundMap,
|
|
15772
|
-
background: true
|
|
15773
|
-
};
|
|
15774
|
-
}
|
|
15775
|
-
if (typeof background === "number") {
|
|
15776
|
-
return { color: background, background: true };
|
|
15777
|
-
}
|
|
15778
|
-
if (typeof background === "string") {
|
|
15779
|
-
if (background in presetsObj) {
|
|
15780
|
-
return { preset: background, background: true };
|
|
15781
|
-
}
|
|
15782
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15783
|
-
return { files: background, background: true };
|
|
15784
|
-
}
|
|
15785
|
-
return { color: background, background: true };
|
|
15786
|
-
}
|
|
15787
|
-
if (background.isColor) {
|
|
15788
|
-
return { color: background, background: true };
|
|
15789
|
-
}
|
|
15790
|
-
return null;
|
|
15791
|
-
}, [background]);
|
|
14813
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15792
14814
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15793
14815
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15794
14816
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15830,6 +14852,7 @@ function CanvasImpl({
|
|
|
15830
14852
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15831
14853
|
const [block, setBlock] = React__namespace.useState(false);
|
|
15832
14854
|
const [error, setError] = React__namespace.useState(false);
|
|
14855
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
15833
14856
|
if (block) throw block;
|
|
15834
14857
|
if (error) throw error;
|
|
15835
14858
|
const root = React__namespace.useRef(null);
|
|
@@ -15837,6 +14860,7 @@ function CanvasImpl({
|
|
|
15837
14860
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
15838
14861
|
useIsomorphicLayoutEffect(() => {
|
|
15839
14862
|
effectActiveRef.current = true;
|
|
14863
|
+
if (fallbackVisible) return;
|
|
15840
14864
|
const canvas = canvasRef.current;
|
|
15841
14865
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15842
14866
|
if (!root.current) {
|
|
@@ -15857,7 +14881,7 @@ function CanvasImpl({
|
|
|
15857
14881
|
}
|
|
15858
14882
|
async function run() {
|
|
15859
14883
|
if (!effectActiveRef.current || !root.current) return;
|
|
15860
|
-
await root.current.configure({
|
|
14884
|
+
const configured = await root.current.configure({
|
|
15861
14885
|
id,
|
|
15862
14886
|
primaryCanvas,
|
|
15863
14887
|
scheduler,
|
|
@@ -15872,6 +14896,8 @@ function CanvasImpl({
|
|
|
15872
14896
|
performance,
|
|
15873
14897
|
raycaster,
|
|
15874
14898
|
camera,
|
|
14899
|
+
autoUpdateFrustum,
|
|
14900
|
+
occlusion,
|
|
15875
14901
|
size: effectiveSize,
|
|
15876
14902
|
// Store size props for reset functionality
|
|
15877
14903
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15896,8 +14922,20 @@ function CanvasImpl({
|
|
|
15896
14922
|
}
|
|
15897
14923
|
onCreated?.(state);
|
|
15898
14924
|
}
|
|
15899
|
-
})
|
|
15900
|
-
|
|
14925
|
+
}).then(
|
|
14926
|
+
() => true,
|
|
14927
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
14928
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
14929
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
14930
|
+
(setupError) => {
|
|
14931
|
+
if (effectActiveRef.current) {
|
|
14932
|
+
if (fallback != null) setFallbackVisible(true);
|
|
14933
|
+
else setError(setupError);
|
|
14934
|
+
}
|
|
14935
|
+
return false;
|
|
14936
|
+
}
|
|
14937
|
+
);
|
|
14938
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15901
14939
|
root.current.render(
|
|
15902
14940
|
/* @__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: [
|
|
15903
14941
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -15931,14 +14969,7 @@ function CanvasImpl({
|
|
|
15931
14969
|
const handleHMR = () => {
|
|
15932
14970
|
queueMicrotask(() => {
|
|
15933
14971
|
const rootEntry = _roots.get(canvas);
|
|
15934
|
-
if (rootEntry?.store)
|
|
15935
|
-
console.log("[R3F] HMR detected \u2014 rebuilding nodes/uniforms");
|
|
15936
|
-
rootEntry.store.setState((state) => ({
|
|
15937
|
-
nodes: {},
|
|
15938
|
-
uniforms: {},
|
|
15939
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15940
|
-
}));
|
|
15941
|
-
}
|
|
14972
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15942
14973
|
});
|
|
15943
14974
|
};
|
|
15944
14975
|
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) {
|
|
@@ -15967,7 +14998,11 @@ function CanvasImpl({
|
|
|
15967
14998
|
...style
|
|
15968
14999
|
},
|
|
15969
15000
|
...props,
|
|
15970
|
-
children:
|
|
15001
|
+
children: fallbackVisible ? (
|
|
15002
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15003
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15004
|
+
fallback
|
|
15005
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
15971
15006
|
"canvas",
|
|
15972
15007
|
{
|
|
15973
15008
|
ref: canvasRef,
|
|
@@ -15986,6 +15021,8 @@ function Canvas(props) {
|
|
|
15986
15021
|
|
|
15987
15022
|
extend(THREE);
|
|
15988
15023
|
|
|
15024
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
15025
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
15989
15026
|
exports.Block = Block;
|
|
15990
15027
|
exports.Canvas = Canvas;
|
|
15991
15028
|
exports.Environment = Environment;
|
|
@@ -16001,7 +15038,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
16001
15038
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
16002
15039
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
16003
15040
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
16004
|
-
exports.Scheduler = Scheduler;
|
|
16005
15041
|
exports.Texture = Texture;
|
|
16006
15042
|
exports._roots = _roots;
|
|
16007
15043
|
exports.act = act;
|
|
@@ -16031,7 +15067,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
16031
15067
|
exports.getPrimary = getPrimary;
|
|
16032
15068
|
exports.getPrimaryIds = getPrimaryIds;
|
|
16033
15069
|
exports.getRootState = getRootState;
|
|
16034
|
-
exports.getScheduler = getScheduler;
|
|
16035
15070
|
exports.getUuidPrefix = getUuidPrefix;
|
|
16036
15071
|
exports.hasConstructor = hasConstructor;
|
|
16037
15072
|
exports.hasPrimary = hasPrimary;
|