@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/webgpu/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as webgpu from 'three/webgpu';
|
|
2
|
-
import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, Vector4, PostProcessing } from 'three/webgpu';
|
|
2
|
+
import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, Vector4, PostProcessing } from 'three/webgpu';
|
|
3
3
|
import { Inspector } from 'three/addons/inspector/Inspector.js';
|
|
4
4
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
@@ -14,6 +14,8 @@ import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
|
14
14
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
15
15
|
import Tb, { unstable_scheduleCallback, unstable_IdlePriority } from 'scheduler';
|
|
16
16
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
17
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
18
|
+
export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
17
19
|
import { suspend, preload, clear } from 'suspend-react';
|
|
18
20
|
import { dequal } from 'dequal/lite';
|
|
19
21
|
import 'zustand/shallow';
|
|
@@ -435,9 +437,9 @@ function Environment(props) {
|
|
|
435
437
|
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
var __defProp$
|
|
439
|
-
var __defNormalProp$
|
|
440
|
-
var __publicField$
|
|
440
|
+
var __defProp$1 = Object.defineProperty;
|
|
441
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
442
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
441
443
|
const act = React["act"];
|
|
442
444
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
443
445
|
function useMutableCallback(fn) {
|
|
@@ -469,7 +471,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
469
471
|
return _a = class extends React.Component {
|
|
470
472
|
constructor() {
|
|
471
473
|
super(...arguments);
|
|
472
|
-
__publicField$
|
|
474
|
+
__publicField$1(this, "state", { error: false });
|
|
473
475
|
}
|
|
474
476
|
componentDidCatch(err) {
|
|
475
477
|
this.props.set(err);
|
|
@@ -477,7 +479,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
477
479
|
render() {
|
|
478
480
|
return this.state.error ? null : this.props.children;
|
|
479
481
|
}
|
|
480
|
-
}, __publicField$
|
|
482
|
+
}, __publicField$1(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
481
483
|
})();
|
|
482
484
|
|
|
483
485
|
const is = {
|
|
@@ -998,6 +1000,19 @@ function applyProps(object, props) {
|
|
|
998
1000
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
999
1001
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1000
1002
|
else target.set(value);
|
|
1003
|
+
} else if (root instanceof ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1004
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1005
|
+
const uniforms = root.uniforms;
|
|
1006
|
+
const nextUniforms = value;
|
|
1007
|
+
for (const name in nextUniforms) {
|
|
1008
|
+
const uniform = nextUniforms[name];
|
|
1009
|
+
const targetUniform = uniforms[name];
|
|
1010
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1011
|
+
else {
|
|
1012
|
+
const nextUniform = uniform instanceof Uniform ? uniform.clone() : new Uniform(uniform.value);
|
|
1013
|
+
uniforms[name] = nextUniform;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1001
1016
|
} else {
|
|
1002
1017
|
root[key] = value;
|
|
1003
1018
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1637,1036 +1652,12 @@ function notifyAlpha({ message, link }) {
|
|
|
1637
1652
|
}
|
|
1638
1653
|
}
|
|
1639
1654
|
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
/** Ordered list of phase nodes */
|
|
1647
|
-
__publicField$2(this, "phases", []);
|
|
1648
|
-
/** Quick lookup by name */
|
|
1649
|
-
__publicField$2(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1650
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1651
|
-
__publicField$2(this, "orderedNamesCache", null);
|
|
1652
|
-
this.initializeDefaultPhases();
|
|
1653
|
-
}
|
|
1654
|
-
//* Initialization --------------------------------
|
|
1655
|
-
initializeDefaultPhases() {
|
|
1656
|
-
for (const name of DEFAULT_PHASES) {
|
|
1657
|
-
const node = { name, isAutoGenerated: false };
|
|
1658
|
-
this.phases.push(node);
|
|
1659
|
-
this.phaseMap.set(name, node);
|
|
1660
|
-
}
|
|
1661
|
-
this.invalidateCache();
|
|
1662
|
-
}
|
|
1663
|
-
//* Public API --------------------------------
|
|
1664
|
-
/**
|
|
1665
|
-
* Add a named phase to the graph
|
|
1666
|
-
* @param name - Phase name (must be unique)
|
|
1667
|
-
* @param options - Position options (before or after another phase)
|
|
1668
|
-
*/
|
|
1669
|
-
addPhase(name, options = {}) {
|
|
1670
|
-
if (this.phaseMap.has(name)) {
|
|
1671
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1672
|
-
return;
|
|
1673
|
-
}
|
|
1674
|
-
const { before, after } = options;
|
|
1675
|
-
const node = { name, isAutoGenerated: false };
|
|
1676
|
-
let insertIndex = this.phases.length;
|
|
1677
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1678
|
-
if (targetIndex !== -1) {
|
|
1679
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1680
|
-
} else {
|
|
1681
|
-
const constraintType = before ? "before" : "after";
|
|
1682
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1683
|
-
}
|
|
1684
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1685
|
-
this.phaseMap.set(name, node);
|
|
1686
|
-
this.invalidateCache();
|
|
1687
|
-
}
|
|
1688
|
-
/**
|
|
1689
|
-
* Get ordered list of phase names
|
|
1690
|
-
*/
|
|
1691
|
-
getOrderedPhases() {
|
|
1692
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1693
|
-
return this.orderedNamesCache;
|
|
1694
|
-
}
|
|
1695
|
-
/**
|
|
1696
|
-
* Check if a phase exists
|
|
1697
|
-
*/
|
|
1698
|
-
hasPhase(name) {
|
|
1699
|
-
return this.phaseMap.has(name);
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* Get the index of a phase (-1 if not found)
|
|
1703
|
-
*/
|
|
1704
|
-
getPhaseIndex(name) {
|
|
1705
|
-
if (!name) return -1;
|
|
1706
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1707
|
-
}
|
|
1708
|
-
/**
|
|
1709
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1710
|
-
* Used for resolving before/after constraints.
|
|
1711
|
-
*
|
|
1712
|
-
* @param name - The phase name to ensure exists
|
|
1713
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1714
|
-
*/
|
|
1715
|
-
ensurePhase(name) {
|
|
1716
|
-
if (this.phaseMap.has(name)) return name;
|
|
1717
|
-
const node = { name, isAutoGenerated: true };
|
|
1718
|
-
this.phases.push(node);
|
|
1719
|
-
this.phaseMap.set(name, node);
|
|
1720
|
-
this.invalidateCache();
|
|
1721
|
-
return name;
|
|
1722
|
-
}
|
|
1723
|
-
/**
|
|
1724
|
-
* Resolve where a job with before/after constraints should go.
|
|
1725
|
-
* Creates auto-generated phases if needed.
|
|
1726
|
-
*
|
|
1727
|
-
* @param before - Phase(s) to run before
|
|
1728
|
-
* @param after - Phase(s) to run after
|
|
1729
|
-
* @returns The resolved phase name
|
|
1730
|
-
*/
|
|
1731
|
-
resolveConstraintPhase(before, after) {
|
|
1732
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1733
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1734
|
-
if (beforeArr.length > 0) {
|
|
1735
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1736
|
-
}
|
|
1737
|
-
if (afterArr.length > 0) {
|
|
1738
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1739
|
-
}
|
|
1740
|
-
return "update";
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1744
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1745
|
-
*
|
|
1746
|
-
* @param target - The target phase name to position relative to
|
|
1747
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1748
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1749
|
-
* @returns The auto-generated phase name
|
|
1750
|
-
*/
|
|
1751
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1752
|
-
const autoName = `${prefix}:${target}`;
|
|
1753
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1754
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1755
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1756
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1757
|
-
else this.phases.push(node);
|
|
1758
|
-
this.phaseMap.set(autoName, node);
|
|
1759
|
-
this.invalidateCache();
|
|
1760
|
-
return autoName;
|
|
1761
|
-
}
|
|
1762
|
-
// Internal --------------------------------
|
|
1763
|
-
invalidateCache() {
|
|
1764
|
-
this.orderedNamesCache = null;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1769
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1770
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1771
|
-
for (const phase of orderedPhases) {
|
|
1772
|
-
buckets.set(phase, []);
|
|
1773
|
-
}
|
|
1774
|
-
for (const job of jobs.values()) {
|
|
1775
|
-
if (!job.enabled) continue;
|
|
1776
|
-
let bucket = buckets.get(job.phase);
|
|
1777
|
-
if (!bucket) {
|
|
1778
|
-
bucket = [];
|
|
1779
|
-
buckets.set(job.phase, bucket);
|
|
1780
|
-
}
|
|
1781
|
-
bucket.push(job);
|
|
1782
|
-
}
|
|
1783
|
-
const sortedBuckets = [];
|
|
1784
|
-
for (const phase of orderedPhases) {
|
|
1785
|
-
const bucket = buckets.get(phase);
|
|
1786
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1787
|
-
bucket.sort((a, b) => {
|
|
1788
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1789
|
-
return a.index - b.index;
|
|
1790
|
-
});
|
|
1791
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1792
|
-
}
|
|
1793
|
-
for (const [phase, bucket] of buckets) {
|
|
1794
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1795
|
-
bucket.sort((a, b) => {
|
|
1796
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1797
|
-
return a.index - b.index;
|
|
1798
|
-
});
|
|
1799
|
-
sortedBuckets.push(bucket);
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
return sortedBuckets.flat();
|
|
1803
|
-
}
|
|
1804
|
-
function hasCrossJobConstraints(bucket) {
|
|
1805
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1806
|
-
for (const job of bucket) {
|
|
1807
|
-
for (const ref of job.before) {
|
|
1808
|
-
if (jobIds.has(ref)) return true;
|
|
1809
|
-
}
|
|
1810
|
-
for (const ref of job.after) {
|
|
1811
|
-
if (jobIds.has(ref)) return true;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
return false;
|
|
1815
|
-
}
|
|
1816
|
-
function topologicalSort(jobs) {
|
|
1817
|
-
const n = jobs.length;
|
|
1818
|
-
if (n <= 1) return jobs;
|
|
1819
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1820
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1821
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1822
|
-
for (const job of jobs) {
|
|
1823
|
-
jobMap.set(job.id, job);
|
|
1824
|
-
inDegree.set(job.id, 0);
|
|
1825
|
-
adjacency.set(job.id, []);
|
|
1826
|
-
}
|
|
1827
|
-
for (const job of jobs) {
|
|
1828
|
-
for (const ref of job.before) {
|
|
1829
|
-
if (jobMap.has(ref)) {
|
|
1830
|
-
adjacency.get(job.id).push(ref);
|
|
1831
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
for (const ref of job.after) {
|
|
1835
|
-
if (jobMap.has(ref)) {
|
|
1836
|
-
adjacency.get(ref).push(job.id);
|
|
1837
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
const queue = [];
|
|
1842
|
-
for (const job of jobs) {
|
|
1843
|
-
if (inDegree.get(job.id) === 0) {
|
|
1844
|
-
queue.push(job);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
queue.sort((a, b) => {
|
|
1848
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1849
|
-
return a.index - b.index;
|
|
1850
|
-
});
|
|
1851
|
-
const result = [];
|
|
1852
|
-
while (queue.length > 0) {
|
|
1853
|
-
const job = queue.shift();
|
|
1854
|
-
result.push(job);
|
|
1855
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1856
|
-
for (const neighborId of neighbors) {
|
|
1857
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1858
|
-
inDegree.set(neighborId, newDegree);
|
|
1859
|
-
if (newDegree === 0) {
|
|
1860
|
-
const neighbor = jobMap.get(neighborId);
|
|
1861
|
-
insertSorted(queue, neighbor);
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
if (result.length !== n) {
|
|
1866
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1867
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1868
|
-
for (const job of jobs) {
|
|
1869
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
return result;
|
|
1873
|
-
}
|
|
1874
|
-
function insertSorted(arr, job) {
|
|
1875
|
-
let i = 0;
|
|
1876
|
-
while (i < arr.length) {
|
|
1877
|
-
const cmp = arr[i];
|
|
1878
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1879
|
-
break;
|
|
1880
|
-
}
|
|
1881
|
-
i++;
|
|
1882
|
-
}
|
|
1883
|
-
arr.splice(i, 0, job);
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
function shouldRun(job, now) {
|
|
1887
|
-
if (!job.enabled) return false;
|
|
1888
|
-
if (!job.fps) return true;
|
|
1889
|
-
const minInterval = 1e3 / job.fps;
|
|
1890
|
-
const lastRun = job.lastRun ?? 0;
|
|
1891
|
-
const elapsed = now - lastRun;
|
|
1892
|
-
if (elapsed < minInterval - 1) return false;
|
|
1893
|
-
if (job.drop) {
|
|
1894
|
-
job.lastRun = now;
|
|
1895
|
-
} else {
|
|
1896
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1897
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1898
|
-
if (job.lastRun < now - minInterval) {
|
|
1899
|
-
job.lastRun = now;
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
return true;
|
|
1903
|
-
}
|
|
1904
|
-
function resetJobTiming(job) {
|
|
1905
|
-
job.lastRun = void 0;
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
var __defProp$1 = Object.defineProperty;
|
|
1909
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1910
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1911
|
-
const hmrData = (() => {
|
|
1912
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1913
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1914
|
-
try {
|
|
1915
|
-
return (0, eval)("import.meta.hot");
|
|
1916
|
-
} catch {
|
|
1917
|
-
return void 0;
|
|
1918
|
-
}
|
|
1919
|
-
})();
|
|
1920
|
-
const _Scheduler = class _Scheduler {
|
|
1921
|
-
//* Constructor ================================
|
|
1922
|
-
constructor() {
|
|
1923
|
-
//* Critical State ================================
|
|
1924
|
-
__publicField$1(this, "roots", /* @__PURE__ */ new Map());
|
|
1925
|
-
__publicField$1(this, "phaseGraph");
|
|
1926
|
-
__publicField$1(this, "loopState", {
|
|
1927
|
-
running: false,
|
|
1928
|
-
rafHandle: null,
|
|
1929
|
-
lastTime: null,
|
|
1930
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1931
|
-
frameCount: 0,
|
|
1932
|
-
elapsedTime: 0,
|
|
1933
|
-
createdAt: performance.now()
|
|
1934
|
-
});
|
|
1935
|
-
__publicField$1(this, "stoppedTime", 0);
|
|
1936
|
-
//* Private State ================================
|
|
1937
|
-
__publicField$1(this, "nextRootIndex", 0);
|
|
1938
|
-
__publicField$1(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1939
|
-
__publicField$1(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1940
|
-
__publicField$1(this, "nextGlobalIndex", 0);
|
|
1941
|
-
__publicField$1(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1942
|
-
__publicField$1(this, "nextJobIndex", 0);
|
|
1943
|
-
__publicField$1(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1944
|
-
__publicField$1(this, "pendingFrames", 0);
|
|
1945
|
-
__publicField$1(this, "_frameloop", "always");
|
|
1946
|
-
//* Independent Mode & Error Handling State ================================
|
|
1947
|
-
__publicField$1(this, "_independent", false);
|
|
1948
|
-
__publicField$1(this, "errorHandler", null);
|
|
1949
|
-
__publicField$1(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1950
|
-
//* Core Loop Execution Methods ================================
|
|
1951
|
-
/**
|
|
1952
|
-
* Main RAF loop callback.
|
|
1953
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1954
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1955
|
-
* @returns {void}
|
|
1956
|
-
* @private
|
|
1957
|
-
*/
|
|
1958
|
-
__publicField$1(this, "loop", (timestamp) => {
|
|
1959
|
-
if (!this.loopState.running) return;
|
|
1960
|
-
this.executeFrame(timestamp);
|
|
1961
|
-
if (this._frameloop === "demand") {
|
|
1962
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1963
|
-
if (this.pendingFrames === 0) {
|
|
1964
|
-
this.notifyIdle(timestamp);
|
|
1965
|
-
return this.stop();
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1969
|
-
});
|
|
1970
|
-
this.phaseGraph = new PhaseGraph();
|
|
1971
|
-
}
|
|
1972
|
-
static get instance() {
|
|
1973
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1974
|
-
}
|
|
1975
|
-
static set instance(value) {
|
|
1976
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1977
|
-
}
|
|
1978
|
-
/**
|
|
1979
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1980
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1981
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1982
|
-
*/
|
|
1983
|
-
static get() {
|
|
1984
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1985
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1986
|
-
}
|
|
1987
|
-
if (!_Scheduler.instance) {
|
|
1988
|
-
_Scheduler.instance = new _Scheduler();
|
|
1989
|
-
if (hmrData?.data) {
|
|
1990
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
return _Scheduler.instance;
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1997
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1998
|
-
* @returns {void}
|
|
1999
|
-
*/
|
|
2000
|
-
static reset() {
|
|
2001
|
-
if (_Scheduler.instance) {
|
|
2002
|
-
_Scheduler.instance.stop();
|
|
2003
|
-
_Scheduler.instance = null;
|
|
2004
|
-
}
|
|
2005
|
-
if (hmrData?.data) {
|
|
2006
|
-
hmrData.data.scheduler = null;
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
//* Getters & Setters ================================
|
|
2010
|
-
get phases() {
|
|
2011
|
-
return this.phaseGraph.getOrderedPhases();
|
|
2012
|
-
}
|
|
2013
|
-
get frameloop() {
|
|
2014
|
-
return this._frameloop;
|
|
2015
|
-
}
|
|
2016
|
-
set frameloop(mode) {
|
|
2017
|
-
if (this._frameloop === mode) return;
|
|
2018
|
-
const wasAlways = this._frameloop === "always";
|
|
2019
|
-
this._frameloop = mode;
|
|
2020
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
2021
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
2022
|
-
}
|
|
2023
|
-
get isRunning() {
|
|
2024
|
-
return this.loopState.running;
|
|
2025
|
-
}
|
|
2026
|
-
get isReady() {
|
|
2027
|
-
return this.roots.size > 0;
|
|
2028
|
-
}
|
|
2029
|
-
get independent() {
|
|
2030
|
-
return this._independent;
|
|
2031
|
-
}
|
|
2032
|
-
set independent(value) {
|
|
2033
|
-
this._independent = value;
|
|
2034
|
-
if (value) this.ensureDefaultRoot();
|
|
2035
|
-
}
|
|
2036
|
-
//* Root Management Methods ================================
|
|
2037
|
-
/**
|
|
2038
|
-
* Register a root (Canvas) with the scheduler.
|
|
2039
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
2040
|
-
* @param {string} id - Unique identifier for this root
|
|
2041
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
2042
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
2043
|
-
*/
|
|
2044
|
-
registerRoot(id, options = {}) {
|
|
2045
|
-
if (this.roots.has(id)) {
|
|
2046
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
2047
|
-
return () => this.unregisterRoot(id);
|
|
2048
|
-
}
|
|
2049
|
-
const entry = {
|
|
2050
|
-
id,
|
|
2051
|
-
getState: options.getState ?? (() => ({})),
|
|
2052
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
2053
|
-
sortedJobs: [],
|
|
2054
|
-
needsRebuild: false
|
|
2055
|
-
};
|
|
2056
|
-
if (options.onError) {
|
|
2057
|
-
this.errorHandler = options.onError;
|
|
2058
|
-
}
|
|
2059
|
-
this.roots.set(id, entry);
|
|
2060
|
-
if (this.roots.size === 1) {
|
|
2061
|
-
this.notifyRootReady();
|
|
2062
|
-
if (this._frameloop === "always") this.start();
|
|
2063
|
-
}
|
|
2064
|
-
return () => this.unregisterRoot(id);
|
|
2065
|
-
}
|
|
2066
|
-
/**
|
|
2067
|
-
* Unregister a root from the scheduler.
|
|
2068
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
2069
|
-
* The last root to unregister stops the RAF loop.
|
|
2070
|
-
* @param {string} id - The root ID to unregister
|
|
2071
|
-
* @returns {void}
|
|
2072
|
-
*/
|
|
2073
|
-
unregisterRoot(id) {
|
|
2074
|
-
const root = this.roots.get(id);
|
|
2075
|
-
if (!root) return;
|
|
2076
|
-
for (const jobId of root.jobs.keys()) {
|
|
2077
|
-
this.jobStateListeners.delete(jobId);
|
|
2078
|
-
}
|
|
2079
|
-
this.roots.delete(id);
|
|
2080
|
-
if (this.roots.size === 0) {
|
|
2081
|
-
this.stop();
|
|
2082
|
-
this.errorHandler = null;
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
/**
|
|
2086
|
-
* Subscribe to be notified when a root becomes available.
|
|
2087
|
-
* Fires immediately if a root already exists.
|
|
2088
|
-
* @param {() => void} callback - Function called when first root registers
|
|
2089
|
-
* @returns {() => void} Unsubscribe function
|
|
2090
|
-
*/
|
|
2091
|
-
onRootReady(callback) {
|
|
2092
|
-
if (this.roots.size > 0) {
|
|
2093
|
-
callback();
|
|
2094
|
-
return () => {
|
|
2095
|
-
};
|
|
2096
|
-
}
|
|
2097
|
-
this.rootReadyCallbacks.add(callback);
|
|
2098
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* Notify all registered root-ready callbacks.
|
|
2102
|
-
* Called when the first root registers.
|
|
2103
|
-
* @returns {void}
|
|
2104
|
-
* @private
|
|
2105
|
-
*/
|
|
2106
|
-
notifyRootReady() {
|
|
2107
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
2108
|
-
try {
|
|
2109
|
-
cb();
|
|
2110
|
-
} catch (error) {
|
|
2111
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
this.rootReadyCallbacks.clear();
|
|
2115
|
-
}
|
|
2116
|
-
/**
|
|
2117
|
-
* Ensure a default root exists for independent mode.
|
|
2118
|
-
* Creates a minimal root with no state provider.
|
|
2119
|
-
* @returns {void}
|
|
2120
|
-
* @private
|
|
2121
|
-
*/
|
|
2122
|
-
ensureDefaultRoot() {
|
|
2123
|
-
if (!this.roots.has("__default__")) {
|
|
2124
|
-
this.registerRoot("__default__");
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
* Trigger error handling for job errors.
|
|
2129
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
2130
|
-
* @param {Error} error - The error to handle
|
|
2131
|
-
* @returns {void}
|
|
2132
|
-
*/
|
|
2133
|
-
triggerError(error) {
|
|
2134
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
2135
|
-
else console.error("[Scheduler]", error);
|
|
2136
|
-
}
|
|
2137
|
-
//* Phase Management Methods ================================
|
|
2138
|
-
/**
|
|
2139
|
-
* Add a named phase to the scheduler's execution order.
|
|
2140
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
2141
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
2142
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
2143
|
-
* @returns {void}
|
|
2144
|
-
* @example
|
|
2145
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
2146
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
2147
|
-
*/
|
|
2148
|
-
addPhase(name, options) {
|
|
2149
|
-
this.phaseGraph.addPhase(name, options);
|
|
2150
|
-
for (const root of this.roots.values()) {
|
|
2151
|
-
root.needsRebuild = true;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
/**
|
|
2155
|
-
* Check if a phase exists in the scheduler.
|
|
2156
|
-
* @param {string} name - The phase name to check
|
|
2157
|
-
* @returns {boolean} True if the phase exists
|
|
2158
|
-
*/
|
|
2159
|
-
hasPhase(name) {
|
|
2160
|
-
return this.phaseGraph.hasPhase(name);
|
|
2161
|
-
}
|
|
2162
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
2163
|
-
/**
|
|
2164
|
-
* Register a global job that runs once per frame (not per-root).
|
|
2165
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
2166
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
2167
|
-
* @param {string} id - Unique identifier for this global job
|
|
2168
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
2169
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
2170
|
-
* @deprecated Use useFrame with phases instead
|
|
2171
|
-
*/
|
|
2172
|
-
registerGlobal(phase, id, callback) {
|
|
2173
|
-
const job = { id, callback };
|
|
2174
|
-
if (phase === "before") {
|
|
2175
|
-
this.globalBeforeJobs.set(id, job);
|
|
2176
|
-
} else {
|
|
2177
|
-
this.globalAfterJobs.set(id, job);
|
|
2178
|
-
}
|
|
2179
|
-
return () => {
|
|
2180
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
2181
|
-
else this.globalAfterJobs.delete(id);
|
|
2182
|
-
};
|
|
2183
|
-
}
|
|
2184
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
2185
|
-
/**
|
|
2186
|
-
* Register an idle callback that fires when the loop stops.
|
|
2187
|
-
* Used internally by deprecated addTail API.
|
|
2188
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
2189
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
2190
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
2191
|
-
*/
|
|
2192
|
-
onIdle(callback) {
|
|
2193
|
-
this.idleCallbacks.add(callback);
|
|
2194
|
-
return () => this.idleCallbacks.delete(callback);
|
|
2195
|
-
}
|
|
2196
|
-
/**
|
|
2197
|
-
* Notify all registered idle callbacks.
|
|
2198
|
-
* Called when the loop stops in demand mode.
|
|
2199
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2200
|
-
* @returns {void}
|
|
2201
|
-
* @private
|
|
2202
|
-
*/
|
|
2203
|
-
notifyIdle(timestamp) {
|
|
2204
|
-
for (const cb of this.idleCallbacks) {
|
|
2205
|
-
try {
|
|
2206
|
-
cb(timestamp);
|
|
2207
|
-
} catch (error) {
|
|
2208
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
//* Job Registration & Management Methods ================================
|
|
2213
|
-
/**
|
|
2214
|
-
* Register a job (frame callback) with a specific root.
|
|
2215
|
-
* This is the core registration method used by useFrame internally.
|
|
2216
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2217
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2218
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2219
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2220
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2221
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2222
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2223
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2224
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2225
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2226
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2227
|
-
*/
|
|
2228
|
-
register(callback, options = {}) {
|
|
2229
|
-
const rootId = options.rootId;
|
|
2230
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2231
|
-
if (!root) {
|
|
2232
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2233
|
-
return () => {
|
|
2234
|
-
};
|
|
2235
|
-
}
|
|
2236
|
-
const id = options.id ?? this.generateJobId();
|
|
2237
|
-
let phase = options.phase ?? "update";
|
|
2238
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2239
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2240
|
-
}
|
|
2241
|
-
const before = this.normalizeConstraints(options.before);
|
|
2242
|
-
const after = this.normalizeConstraints(options.after);
|
|
2243
|
-
const job = {
|
|
2244
|
-
id,
|
|
2245
|
-
callback,
|
|
2246
|
-
phase,
|
|
2247
|
-
before,
|
|
2248
|
-
after,
|
|
2249
|
-
priority: options.priority ?? 0,
|
|
2250
|
-
index: this.nextJobIndex++,
|
|
2251
|
-
fps: options.fps,
|
|
2252
|
-
drop: options.drop ?? true,
|
|
2253
|
-
enabled: options.enabled ?? true,
|
|
2254
|
-
system: options.system ?? false
|
|
2255
|
-
};
|
|
2256
|
-
if (root.jobs.has(id)) {
|
|
2257
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2258
|
-
}
|
|
2259
|
-
root.jobs.set(id, job);
|
|
2260
|
-
root.needsRebuild = true;
|
|
2261
|
-
return () => this.unregister(id, root.id);
|
|
2262
|
-
}
|
|
2263
|
-
/**
|
|
2264
|
-
* Unregister a job by its ID.
|
|
2265
|
-
* Searches all roots if rootId is not provided.
|
|
2266
|
-
* @param {string} id - The job ID to unregister
|
|
2267
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2268
|
-
* @returns {void}
|
|
2269
|
-
*/
|
|
2270
|
-
unregister(id, rootId) {
|
|
2271
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2272
|
-
if (root?.jobs.delete(id)) {
|
|
2273
|
-
root.needsRebuild = true;
|
|
2274
|
-
this.jobStateListeners.delete(id);
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
/**
|
|
2278
|
-
* Update a job's options dynamically.
|
|
2279
|
-
* Searches all roots to find the job by ID.
|
|
2280
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2281
|
-
* @param {string} id - The job ID to update
|
|
2282
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2283
|
-
* @returns {void}
|
|
2284
|
-
*/
|
|
2285
|
-
updateJob(id, options) {
|
|
2286
|
-
let job;
|
|
2287
|
-
let root;
|
|
2288
|
-
for (const r of this.roots.values()) {
|
|
2289
|
-
job = r.jobs.get(id);
|
|
2290
|
-
if (job) {
|
|
2291
|
-
root = r;
|
|
2292
|
-
break;
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
if (!job || !root) return;
|
|
2296
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2297
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2298
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2299
|
-
if (options.enabled !== void 0) {
|
|
2300
|
-
const wasEnabled = job.enabled;
|
|
2301
|
-
job.enabled = options.enabled;
|
|
2302
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2303
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2304
|
-
}
|
|
2305
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2306
|
-
if (options.phase) job.phase = options.phase;
|
|
2307
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2308
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2309
|
-
root.needsRebuild = true;
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
//* Job State Management Methods ================================
|
|
2313
|
-
/**
|
|
2314
|
-
* Check if a job is currently paused (disabled).
|
|
2315
|
-
* @param {string} id - The job ID to check
|
|
2316
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2317
|
-
*/
|
|
2318
|
-
isJobPaused(id) {
|
|
2319
|
-
for (const root of this.roots.values()) {
|
|
2320
|
-
const job = root.jobs.get(id);
|
|
2321
|
-
if (job) return !job.enabled;
|
|
2322
|
-
}
|
|
2323
|
-
return false;
|
|
2324
|
-
}
|
|
2325
|
-
/**
|
|
2326
|
-
* Subscribe to state changes for a specific job.
|
|
2327
|
-
* Listener is called when job is paused or resumed.
|
|
2328
|
-
* @param {string} id - The job ID to subscribe to
|
|
2329
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2330
|
-
* @returns {() => void} Unsubscribe function
|
|
2331
|
-
*/
|
|
2332
|
-
subscribeJobState(id, listener) {
|
|
2333
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2334
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2335
|
-
}
|
|
2336
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2337
|
-
return () => {
|
|
2338
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2339
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2340
|
-
this.jobStateListeners.delete(id);
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Notify all listeners that a job's state has changed.
|
|
2346
|
-
* @param {string} id - The job ID that changed
|
|
2347
|
-
* @returns {void}
|
|
2348
|
-
* @private
|
|
2349
|
-
*/
|
|
2350
|
-
notifyJobStateChange(id) {
|
|
2351
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2352
|
-
}
|
|
2353
|
-
/**
|
|
2354
|
-
* Pause a job by ID (sets enabled=false).
|
|
2355
|
-
* Notifies any subscribed state listeners.
|
|
2356
|
-
* @param {string} id - The job ID to pause
|
|
2357
|
-
* @returns {void}
|
|
2358
|
-
*/
|
|
2359
|
-
pauseJob(id) {
|
|
2360
|
-
this.updateJob(id, { enabled: false });
|
|
2361
|
-
this.notifyJobStateChange(id);
|
|
2362
|
-
}
|
|
2363
|
-
/**
|
|
2364
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2365
|
-
* Resets job timing to prevent frame accumulation.
|
|
2366
|
-
* Notifies any subscribed state listeners.
|
|
2367
|
-
* @param {string} id - The job ID to resume
|
|
2368
|
-
* @returns {void}
|
|
2369
|
-
*/
|
|
2370
|
-
resumeJob(id) {
|
|
2371
|
-
this.updateJob(id, { enabled: true });
|
|
2372
|
-
this.notifyJobStateChange(id);
|
|
2373
|
-
}
|
|
2374
|
-
//* Frame Loop Control Methods ================================
|
|
2375
|
-
/**
|
|
2376
|
-
* Start the requestAnimationFrame loop.
|
|
2377
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2378
|
-
* No-op if already running.
|
|
2379
|
-
* @returns {void}
|
|
2380
|
-
*/
|
|
2381
|
-
start() {
|
|
2382
|
-
if (this.loopState.running) return;
|
|
2383
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2384
|
-
let adjustedCreated = 0;
|
|
2385
|
-
if (this.stoppedTime > 0) {
|
|
2386
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2387
|
-
this.stoppedTime = 0;
|
|
2388
|
-
}
|
|
2389
|
-
Object.assign(this.loopState, {
|
|
2390
|
-
running: true,
|
|
2391
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2392
|
-
lastTime: performance.now(),
|
|
2393
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2394
|
-
frameCount: 0,
|
|
2395
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2396
|
-
});
|
|
2397
|
-
}
|
|
2398
|
-
/**
|
|
2399
|
-
* Stop the requestAnimationFrame loop.
|
|
2400
|
-
* Cancels any pending RAF callback.
|
|
2401
|
-
* No-op if not running.
|
|
2402
|
-
* @returns {void}
|
|
2403
|
-
*/
|
|
2404
|
-
stop() {
|
|
2405
|
-
if (!this.loopState.running) return;
|
|
2406
|
-
this.loopState.running = false;
|
|
2407
|
-
if (this.loopState.rafHandle !== null) {
|
|
2408
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2409
|
-
this.loopState.rafHandle = null;
|
|
2410
|
-
}
|
|
2411
|
-
this.stoppedTime = performance.now();
|
|
2412
|
-
}
|
|
2413
|
-
/**
|
|
2414
|
-
* Request frames to be rendered in demand mode.
|
|
2415
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2416
|
-
* No-op if frameloop is not 'demand'.
|
|
2417
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2418
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2419
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2420
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2421
|
-
* @returns {void}
|
|
2422
|
-
* @example
|
|
2423
|
-
* // Request a single frame render
|
|
2424
|
-
* scheduler.invalidate();
|
|
2425
|
-
*
|
|
2426
|
-
* @example
|
|
2427
|
-
* // Request 5 frames (e.g., for animations)
|
|
2428
|
-
* scheduler.invalidate(5);
|
|
2429
|
-
*
|
|
2430
|
-
* @example
|
|
2431
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2432
|
-
* scheduler.invalidate(3, false);
|
|
2433
|
-
*
|
|
2434
|
-
* @example
|
|
2435
|
-
* // Add 2 more frames to existing pending count
|
|
2436
|
-
* scheduler.invalidate(2, true);
|
|
2437
|
-
*/
|
|
2438
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2439
|
-
if (this._frameloop !== "demand") return;
|
|
2440
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2441
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2442
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2443
|
-
}
|
|
2444
|
-
/**
|
|
2445
|
-
* Reset timing state for deterministic testing.
|
|
2446
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2447
|
-
* @returns {void}
|
|
2448
|
-
*/
|
|
2449
|
-
resetTiming() {
|
|
2450
|
-
this.loopState.lastTime = null;
|
|
2451
|
-
this.loopState.frameCount = 0;
|
|
2452
|
-
this.loopState.elapsedTime = 0;
|
|
2453
|
-
this.loopState.createdAt = performance.now();
|
|
2454
|
-
}
|
|
2455
|
-
//* Manual Stepping Methods ================================
|
|
2456
|
-
/**
|
|
2457
|
-
* Manually execute a single frame for all roots.
|
|
2458
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2459
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2460
|
-
* @returns {void}
|
|
2461
|
-
* @example
|
|
2462
|
-
* // Manual control mode
|
|
2463
|
-
* scheduler.frameloop = 'never';
|
|
2464
|
-
* scheduler.step(); // Execute one frame
|
|
2465
|
-
*/
|
|
2466
|
-
step(timestamp) {
|
|
2467
|
-
const now = timestamp ?? performance.now();
|
|
2468
|
-
this.executeFrame(now);
|
|
2469
|
-
}
|
|
2470
|
-
/**
|
|
2471
|
-
* Manually execute a single job by its ID.
|
|
2472
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2473
|
-
* @param {string} id - The job ID to step
|
|
2474
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2475
|
-
* @returns {void}
|
|
2476
|
-
*/
|
|
2477
|
-
stepJob(id, timestamp) {
|
|
2478
|
-
let job;
|
|
2479
|
-
let root;
|
|
2480
|
-
for (const r of this.roots.values()) {
|
|
2481
|
-
job = r.jobs.get(id);
|
|
2482
|
-
if (job) {
|
|
2483
|
-
root = r;
|
|
2484
|
-
break;
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
if (!job || !root) {
|
|
2488
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2489
|
-
return;
|
|
2490
|
-
}
|
|
2491
|
-
const now = timestamp ?? performance.now();
|
|
2492
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2493
|
-
const delta = deltaMs / 1e3;
|
|
2494
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2495
|
-
const providedState = root.getState?.() ?? {};
|
|
2496
|
-
const frameState = {
|
|
2497
|
-
...providedState,
|
|
2498
|
-
time: now,
|
|
2499
|
-
delta,
|
|
2500
|
-
elapsed,
|
|
2501
|
-
frame: this.loopState.frameCount
|
|
2502
|
-
};
|
|
2503
|
-
try {
|
|
2504
|
-
job.callback(frameState, delta);
|
|
2505
|
-
} catch (error) {
|
|
2506
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2507
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
/**
|
|
2511
|
-
* Execute a single frame across all roots.
|
|
2512
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2513
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2514
|
-
* @returns {void}
|
|
2515
|
-
* @private
|
|
2516
|
-
*/
|
|
2517
|
-
executeFrame(timestamp) {
|
|
2518
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2519
|
-
const delta = deltaMs / 1e3;
|
|
2520
|
-
this.loopState.lastTime = timestamp;
|
|
2521
|
-
this.loopState.frameCount++;
|
|
2522
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2523
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2524
|
-
for (const root of this.roots.values()) {
|
|
2525
|
-
this.tickRoot(root, timestamp, delta);
|
|
2526
|
-
}
|
|
2527
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2528
|
-
}
|
|
2529
|
-
/**
|
|
2530
|
-
* Run all global jobs from a job map.
|
|
2531
|
-
* Catches and logs errors without stopping execution.
|
|
2532
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2533
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2534
|
-
* @returns {void}
|
|
2535
|
-
* @private
|
|
2536
|
-
*/
|
|
2537
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2538
|
-
for (const job of jobs.values()) {
|
|
2539
|
-
try {
|
|
2540
|
-
job.callback(timestamp);
|
|
2541
|
-
} catch (error) {
|
|
2542
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
/**
|
|
2547
|
-
* Execute all jobs for a single root in sorted order.
|
|
2548
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2549
|
-
* Errors are caught and propagated via triggerError.
|
|
2550
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2551
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2552
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2553
|
-
* @returns {void}
|
|
2554
|
-
* @private
|
|
2555
|
-
*/
|
|
2556
|
-
tickRoot(root, timestamp, delta) {
|
|
2557
|
-
if (root.needsRebuild) {
|
|
2558
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2559
|
-
root.needsRebuild = false;
|
|
2560
|
-
}
|
|
2561
|
-
const providedState = root.getState?.() ?? {};
|
|
2562
|
-
const frameState = {
|
|
2563
|
-
...providedState,
|
|
2564
|
-
time: timestamp,
|
|
2565
|
-
delta,
|
|
2566
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2567
|
-
// Convert ms to seconds
|
|
2568
|
-
frame: this.loopState.frameCount
|
|
2569
|
-
};
|
|
2570
|
-
for (const job of root.sortedJobs) {
|
|
2571
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2572
|
-
try {
|
|
2573
|
-
job.callback(frameState, delta);
|
|
2574
|
-
} catch (error) {
|
|
2575
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2576
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
}
|
|
2580
|
-
//* Debug & Inspection Methods ================================
|
|
2581
|
-
/**
|
|
2582
|
-
* Get the total number of registered jobs across all roots.
|
|
2583
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2584
|
-
* @returns {number} Total job count
|
|
2585
|
-
*/
|
|
2586
|
-
getJobCount() {
|
|
2587
|
-
let count = 0;
|
|
2588
|
-
for (const root of this.roots.values()) {
|
|
2589
|
-
count += root.jobs.size;
|
|
2590
|
-
}
|
|
2591
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2592
|
-
}
|
|
2593
|
-
/**
|
|
2594
|
-
* Get all registered job IDs across all roots.
|
|
2595
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2596
|
-
* @returns {string[]} Array of all job IDs
|
|
2597
|
-
*/
|
|
2598
|
-
getJobIds() {
|
|
2599
|
-
const ids = [];
|
|
2600
|
-
for (const root of this.roots.values()) {
|
|
2601
|
-
ids.push(...root.jobs.keys());
|
|
2602
|
-
}
|
|
2603
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2604
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2605
|
-
return ids;
|
|
2606
|
-
}
|
|
2607
|
-
/**
|
|
2608
|
-
* Get the number of registered roots (Canvas instances).
|
|
2609
|
-
* @returns {number} Number of registered roots
|
|
2610
|
-
*/
|
|
2611
|
-
getRootCount() {
|
|
2612
|
-
return this.roots.size;
|
|
2613
|
-
}
|
|
2614
|
-
/**
|
|
2615
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2616
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2617
|
-
*
|
|
2618
|
-
* @param phase The phase to check
|
|
2619
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2620
|
-
* @returns true if any user jobs exist in the phase
|
|
2621
|
-
*/
|
|
2622
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2623
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2624
|
-
return rootsToCheck.some((root) => {
|
|
2625
|
-
if (!root) return false;
|
|
2626
|
-
for (const job of root.jobs.values()) {
|
|
2627
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2628
|
-
}
|
|
2629
|
-
return false;
|
|
2630
|
-
});
|
|
2631
|
-
}
|
|
2632
|
-
//* Utility Methods ================================
|
|
2633
|
-
/**
|
|
2634
|
-
* Generate a unique root ID for automatic root registration.
|
|
2635
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2636
|
-
*/
|
|
2637
|
-
generateRootId() {
|
|
2638
|
-
return `root_${this.nextRootIndex++}`;
|
|
2639
|
-
}
|
|
2640
|
-
/**
|
|
2641
|
-
* Generate a unique job ID.
|
|
2642
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2643
|
-
* @private
|
|
2644
|
-
*/
|
|
2645
|
-
generateJobId() {
|
|
2646
|
-
return `job_${this.nextJobIndex}`;
|
|
2647
|
-
}
|
|
2648
|
-
/**
|
|
2649
|
-
* Normalize before/after constraints to a Set.
|
|
2650
|
-
* Handles undefined, single string, or array inputs.
|
|
2651
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2652
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2653
|
-
* @private
|
|
2654
|
-
*/
|
|
2655
|
-
normalizeConstraints(value) {
|
|
2656
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2657
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2658
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2659
|
-
}
|
|
2660
|
-
};
|
|
2661
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2662
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2663
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2664
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2665
|
-
__publicField$1(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2666
|
-
let Scheduler = _Scheduler;
|
|
2667
|
-
const getScheduler = () => Scheduler.get();
|
|
2668
|
-
if (hmrData) {
|
|
2669
|
-
hmrData.accept?.();
|
|
1655
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1656
|
+
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1657
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1658
|
+
if (!stack) return false;
|
|
1659
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1660
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m)) || INTERNAL_FIBER_MARKERS.some((m) => caller.includes(m));
|
|
2670
1661
|
}
|
|
2671
1662
|
|
|
2672
1663
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2868,8 +1859,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2868
1859
|
const currentState = rootStore.getState();
|
|
2869
1860
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2870
1861
|
const stack = new Error().stack || "";
|
|
2871
|
-
|
|
2872
|
-
if (!isInternalAccess) {
|
|
1862
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2873
1863
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2874
1864
|
notifyDepreciated({
|
|
2875
1865
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -2982,19 +1972,25 @@ function loadingFn(extensions, onProgress) {
|
|
|
2982
1972
|
);
|
|
2983
1973
|
};
|
|
2984
1974
|
}
|
|
2985
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
2986
|
-
const
|
|
1975
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1976
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1977
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2987
1978
|
const fn = loadingFn(extensions, onProgress);
|
|
2988
|
-
const results =
|
|
1979
|
+
const results = cacheKeys.map(
|
|
1980
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1981
|
+
);
|
|
2989
1982
|
return Array.isArray(input) ? results : results[0];
|
|
2990
1983
|
}
|
|
2991
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
2992
|
-
const
|
|
2993
|
-
|
|
1984
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1985
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1986
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1987
|
+
cacheKeys.forEach(
|
|
1988
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1989
|
+
);
|
|
2994
1990
|
};
|
|
2995
|
-
useLoader.clear = function(loader, input) {
|
|
2996
|
-
const
|
|
2997
|
-
|
|
1991
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1992
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1993
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
2998
1994
|
};
|
|
2999
1995
|
useLoader.loader = getLoader;
|
|
3000
1996
|
|
|
@@ -3070,20 +2066,14 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
3070
2066
|
}
|
|
3071
2067
|
};
|
|
3072
2068
|
} else {
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
unregisterJob = registerOutside();
|
|
3082
|
-
});
|
|
3083
|
-
return () => {
|
|
3084
|
-
unsubReady();
|
|
3085
|
-
unregisterJob?.();
|
|
3086
|
-
};
|
|
2069
|
+
return scheduler.register(
|
|
2070
|
+
(state, delta) => {
|
|
2071
|
+
const frameState = state;
|
|
2072
|
+
if (!frameState.renderer) return;
|
|
2073
|
+
callbackRef.current?.(frameState, delta);
|
|
2074
|
+
},
|
|
2075
|
+
{ id, ...options }
|
|
2076
|
+
);
|
|
3087
2077
|
}
|
|
3088
2078
|
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
3089
2079
|
const isPaused = React.useSyncExternalStore(
|
|
@@ -14859,6 +13849,7 @@ function swapInstances() {
|
|
|
14859
13849
|
}
|
|
14860
13850
|
}
|
|
14861
13851
|
if (instance.isHidden) unhideInstance(instance);
|
|
13852
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14862
13853
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14863
13854
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14864
13855
|
}
|
|
@@ -14871,6 +13862,8 @@ function swapInstances() {
|
|
|
14871
13862
|
instance.object.__r3f = instance;
|
|
14872
13863
|
setFiberRef(fiber, instance.object);
|
|
14873
13864
|
delete instance.appliedOnce;
|
|
13865
|
+
instance.eventCount = 0;
|
|
13866
|
+
instance.handlers = {};
|
|
14874
13867
|
applyProps(instance.object, instance.props);
|
|
14875
13868
|
if (instance.props.attach) {
|
|
14876
13869
|
attach(parent, instance);
|
|
@@ -15175,6 +14168,7 @@ function createRoot(canvas) {
|
|
|
15175
14168
|
const lastConfiguredProps = {};
|
|
15176
14169
|
let configured = false;
|
|
15177
14170
|
let pending = null;
|
|
14171
|
+
let rendererSetup = null;
|
|
15178
14172
|
return {
|
|
15179
14173
|
async configure(props = {}) {
|
|
15180
14174
|
let resolve;
|
|
@@ -15205,7 +14199,7 @@ function createRoot(canvas) {
|
|
|
15205
14199
|
forceEven
|
|
15206
14200
|
} = props;
|
|
15207
14201
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
15208
|
-
|
|
14202
|
+
let state = store.getState();
|
|
15209
14203
|
const defaultGPUProps = {
|
|
15210
14204
|
canvas,
|
|
15211
14205
|
antialias: true
|
|
@@ -15219,52 +14213,64 @@ function createRoot(canvas) {
|
|
|
15219
14213
|
throw new Error("Cannot use both gl and renderer props at the same time");
|
|
15220
14214
|
}
|
|
15221
14215
|
let renderer = state.internal.actualRenderer;
|
|
15222
|
-
if (
|
|
15223
|
-
|
|
15224
|
-
|
|
15225
|
-
|
|
15226
|
-
|
|
15227
|
-
|
|
15228
|
-
|
|
15229
|
-
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15236
|
-
|
|
15237
|
-
|
|
15238
|
-
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
|
|
15243
|
-
|
|
15244
|
-
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
|
|
15250
|
-
|
|
15251
|
-
|
|
15252
|
-
|
|
15253
|
-
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
|
|
15257
|
-
|
|
15258
|
-
|
|
15259
|
-
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
|
|
15263
|
-
|
|
15264
|
-
|
|
14216
|
+
if (!state.internal.actualRenderer) {
|
|
14217
|
+
if (!rendererSetup) {
|
|
14218
|
+
rendererSetup = (async () => {
|
|
14219
|
+
if (primaryCanvas) {
|
|
14220
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14221
|
+
renderer = primary.renderer;
|
|
14222
|
+
state.internal.actualRenderer = renderer;
|
|
14223
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14224
|
+
primary.store.setState((prev) => ({
|
|
14225
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14226
|
+
}));
|
|
14227
|
+
state.set((prev) => ({
|
|
14228
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14229
|
+
renderer,
|
|
14230
|
+
primaryStore: primary.store,
|
|
14231
|
+
internal: {
|
|
14232
|
+
...prev.internal,
|
|
14233
|
+
canvasTarget,
|
|
14234
|
+
isMultiCanvas: true,
|
|
14235
|
+
isSecondary: true,
|
|
14236
|
+
targetId: primaryCanvas
|
|
14237
|
+
}
|
|
14238
|
+
}));
|
|
14239
|
+
} else {
|
|
14240
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, WebGPURenderer);
|
|
14241
|
+
if (!renderer.hasInitialized?.()) {
|
|
14242
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14243
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14244
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14245
|
+
canvas.width = size2.width * pixelRatio;
|
|
14246
|
+
canvas.height = size2.height * pixelRatio;
|
|
14247
|
+
}
|
|
14248
|
+
await renderer.init();
|
|
14249
|
+
}
|
|
14250
|
+
const backend = renderer.backend;
|
|
14251
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14252
|
+
state.internal.actualRenderer = renderer;
|
|
14253
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14254
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14255
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14256
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14257
|
+
state.set((prev) => ({
|
|
14258
|
+
internal: {
|
|
14259
|
+
...prev.internal,
|
|
14260
|
+
canvasTarget,
|
|
14261
|
+
unregisterPrimary
|
|
14262
|
+
}
|
|
14263
|
+
}));
|
|
14264
|
+
}
|
|
15265
14265
|
}
|
|
15266
|
-
}))
|
|
14266
|
+
})().catch((err) => {
|
|
14267
|
+
rendererSetup = null;
|
|
14268
|
+
throw err;
|
|
14269
|
+
});
|
|
15267
14270
|
}
|
|
14271
|
+
await rendererSetup;
|
|
14272
|
+
state = store.getState();
|
|
14273
|
+
renderer = state.internal.actualRenderer;
|
|
15268
14274
|
}
|
|
15269
14275
|
let raycaster = state.raycaster;
|
|
15270
14276
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
@@ -15489,7 +14495,7 @@ function createRoot(canvas) {
|
|
|
15489
14495
|
{
|
|
15490
14496
|
id: `${newRootId}_frustum`,
|
|
15491
14497
|
rootId: newRootId,
|
|
15492
|
-
|
|
14498
|
+
before: "render",
|
|
15493
14499
|
system: true
|
|
15494
14500
|
}
|
|
15495
14501
|
);
|
|
@@ -15501,7 +14507,7 @@ function createRoot(canvas) {
|
|
|
15501
14507
|
{
|
|
15502
14508
|
id: `${newRootId}_visibility`,
|
|
15503
14509
|
rootId: newRootId,
|
|
15504
|
-
|
|
14510
|
+
before: "render",
|
|
15505
14511
|
system: true,
|
|
15506
14512
|
after: `${newRootId}_frustum`
|
|
15507
14513
|
}
|
|
@@ -15677,6 +14683,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15677
14683
|
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
15678
14684
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15679
14685
|
}
|
|
14686
|
+
const set = injectState.set;
|
|
15680
14687
|
return {
|
|
15681
14688
|
// The intersect consists of the previous root state
|
|
15682
14689
|
...rootState,
|
|
@@ -15695,7 +14702,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15695
14702
|
size: resolvedSize,
|
|
15696
14703
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15697
14704
|
// Layers are allowed to override events
|
|
15698
|
-
setEvents: (events2) =>
|
|
14705
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15699
14706
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15700
14707
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15701
14708
|
};
|
|
@@ -15724,6 +14731,59 @@ function flushSync(fn) {
|
|
|
15724
14731
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15725
14732
|
}
|
|
15726
14733
|
|
|
14734
|
+
function parseBackground(background) {
|
|
14735
|
+
if (!background) return null;
|
|
14736
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14737
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14738
|
+
return {
|
|
14739
|
+
...rest,
|
|
14740
|
+
preset,
|
|
14741
|
+
files: envMap || files,
|
|
14742
|
+
backgroundFiles: backgroundMap,
|
|
14743
|
+
background: true
|
|
14744
|
+
};
|
|
14745
|
+
}
|
|
14746
|
+
if (typeof background === "number") {
|
|
14747
|
+
return { color: background, background: true };
|
|
14748
|
+
}
|
|
14749
|
+
if (typeof background === "string") {
|
|
14750
|
+
if (background in presetsObj) {
|
|
14751
|
+
return { preset: background, background: true };
|
|
14752
|
+
}
|
|
14753
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14754
|
+
return { files: background, background: true };
|
|
14755
|
+
}
|
|
14756
|
+
return { color: background, background: true };
|
|
14757
|
+
}
|
|
14758
|
+
if (background.isColor) {
|
|
14759
|
+
return { color: background, background: true };
|
|
14760
|
+
}
|
|
14761
|
+
return null;
|
|
14762
|
+
}
|
|
14763
|
+
|
|
14764
|
+
function parseRendererConfig(rendererProp) {
|
|
14765
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14766
|
+
if (isRendererConfig) {
|
|
14767
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14768
|
+
return {
|
|
14769
|
+
primaryCanvas: pc,
|
|
14770
|
+
scheduler: sc,
|
|
14771
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14772
|
+
};
|
|
14773
|
+
}
|
|
14774
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14775
|
+
}
|
|
14776
|
+
|
|
14777
|
+
function clearHmrCaches(store) {
|
|
14778
|
+
store.setState((state) => ({
|
|
14779
|
+
nodes: {},
|
|
14780
|
+
uniforms: {},
|
|
14781
|
+
buffers: {},
|
|
14782
|
+
gpuStorage: {},
|
|
14783
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14784
|
+
}));
|
|
14785
|
+
}
|
|
14786
|
+
|
|
15727
14787
|
function CanvasImpl({
|
|
15728
14788
|
ref,
|
|
15729
14789
|
children,
|
|
@@ -15744,6 +14804,8 @@ function CanvasImpl({
|
|
|
15744
14804
|
raycaster,
|
|
15745
14805
|
camera,
|
|
15746
14806
|
scene,
|
|
14807
|
+
autoUpdateFrustum,
|
|
14808
|
+
occlusion,
|
|
15747
14809
|
onPointerMissed,
|
|
15748
14810
|
onDragOverMissed,
|
|
15749
14811
|
onDropMissed,
|
|
@@ -15755,49 +14817,10 @@ function CanvasImpl({
|
|
|
15755
14817
|
forceEven,
|
|
15756
14818
|
...props
|
|
15757
14819
|
}) {
|
|
15758
|
-
const
|
|
15759
|
-
let primaryCanvas;
|
|
15760
|
-
let scheduler;
|
|
15761
|
-
let renderer;
|
|
15762
|
-
if (isRendererConfig) {
|
|
15763
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
15764
|
-
primaryCanvas = pc;
|
|
15765
|
-
scheduler = sc;
|
|
15766
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
15767
|
-
} else {
|
|
15768
|
-
renderer = rendererProp;
|
|
15769
|
-
}
|
|
14820
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15770
14821
|
React.useMemo(() => extend(THREE), []);
|
|
15771
14822
|
const Bridge = useBridge();
|
|
15772
|
-
const backgroundProps = React.useMemo(() =>
|
|
15773
|
-
if (!background) return null;
|
|
15774
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15775
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15776
|
-
return {
|
|
15777
|
-
...rest,
|
|
15778
|
-
preset,
|
|
15779
|
-
files: envMap || files,
|
|
15780
|
-
backgroundFiles: backgroundMap,
|
|
15781
|
-
background: true
|
|
15782
|
-
};
|
|
15783
|
-
}
|
|
15784
|
-
if (typeof background === "number") {
|
|
15785
|
-
return { color: background, background: true };
|
|
15786
|
-
}
|
|
15787
|
-
if (typeof background === "string") {
|
|
15788
|
-
if (background in presetsObj) {
|
|
15789
|
-
return { preset: background, background: true };
|
|
15790
|
-
}
|
|
15791
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15792
|
-
return { files: background, background: true };
|
|
15793
|
-
}
|
|
15794
|
-
return { color: background, background: true };
|
|
15795
|
-
}
|
|
15796
|
-
if (background.isColor) {
|
|
15797
|
-
return { color: background, background: true };
|
|
15798
|
-
}
|
|
15799
|
-
return null;
|
|
15800
|
-
}, [background]);
|
|
14823
|
+
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15801
14824
|
const hasInitialSizeRef = React.useRef(false);
|
|
15802
14825
|
const measureConfig = React.useMemo(() => {
|
|
15803
14826
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15839,6 +14862,7 @@ function CanvasImpl({
|
|
|
15839
14862
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15840
14863
|
const [block, setBlock] = React.useState(false);
|
|
15841
14864
|
const [error, setError] = React.useState(false);
|
|
14865
|
+
const [fallbackVisible, setFallbackVisible] = React.useState(false);
|
|
15842
14866
|
if (block) throw block;
|
|
15843
14867
|
if (error) throw error;
|
|
15844
14868
|
const root = React.useRef(null);
|
|
@@ -15846,6 +14870,7 @@ function CanvasImpl({
|
|
|
15846
14870
|
const unsubscribeErrorRef = React.useRef(null);
|
|
15847
14871
|
useIsomorphicLayoutEffect(() => {
|
|
15848
14872
|
effectActiveRef.current = true;
|
|
14873
|
+
if (fallbackVisible) return;
|
|
15849
14874
|
const canvas = canvasRef.current;
|
|
15850
14875
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15851
14876
|
if (!root.current) {
|
|
@@ -15866,7 +14891,7 @@ function CanvasImpl({
|
|
|
15866
14891
|
}
|
|
15867
14892
|
async function run() {
|
|
15868
14893
|
if (!effectActiveRef.current || !root.current) return;
|
|
15869
|
-
await root.current.configure({
|
|
14894
|
+
const configured = await root.current.configure({
|
|
15870
14895
|
id,
|
|
15871
14896
|
primaryCanvas,
|
|
15872
14897
|
scheduler,
|
|
@@ -15881,6 +14906,8 @@ function CanvasImpl({
|
|
|
15881
14906
|
performance,
|
|
15882
14907
|
raycaster,
|
|
15883
14908
|
camera,
|
|
14909
|
+
autoUpdateFrustum,
|
|
14910
|
+
occlusion,
|
|
15884
14911
|
size: effectiveSize,
|
|
15885
14912
|
// Store size props for reset functionality
|
|
15886
14913
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15905,8 +14932,20 @@ function CanvasImpl({
|
|
|
15905
14932
|
}
|
|
15906
14933
|
onCreated?.(state);
|
|
15907
14934
|
}
|
|
15908
|
-
})
|
|
15909
|
-
|
|
14935
|
+
}).then(
|
|
14936
|
+
() => true,
|
|
14937
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
14938
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
14939
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
14940
|
+
(setupError) => {
|
|
14941
|
+
if (effectActiveRef.current) {
|
|
14942
|
+
if (fallback != null) setFallbackVisible(true);
|
|
14943
|
+
else setError(setupError);
|
|
14944
|
+
}
|
|
14945
|
+
return false;
|
|
14946
|
+
}
|
|
14947
|
+
);
|
|
14948
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15910
14949
|
root.current.render(
|
|
15911
14950
|
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
15912
14951
|
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
@@ -15940,14 +14979,7 @@ function CanvasImpl({
|
|
|
15940
14979
|
const handleHMR = () => {
|
|
15941
14980
|
queueMicrotask(() => {
|
|
15942
14981
|
const rootEntry = _roots.get(canvas);
|
|
15943
|
-
if (rootEntry?.store)
|
|
15944
|
-
console.log("[R3F] HMR detected \u2014 rebuilding nodes/uniforms");
|
|
15945
|
-
rootEntry.store.setState((state) => ({
|
|
15946
|
-
nodes: {},
|
|
15947
|
-
uniforms: {},
|
|
15948
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15949
|
-
}));
|
|
15950
|
-
}
|
|
14982
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15951
14983
|
});
|
|
15952
14984
|
};
|
|
15953
14985
|
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
@@ -15976,7 +15008,11 @@ function CanvasImpl({
|
|
|
15976
15008
|
...style
|
|
15977
15009
|
},
|
|
15978
15010
|
...props,
|
|
15979
|
-
children:
|
|
15011
|
+
children: fallbackVisible ? (
|
|
15012
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15013
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15014
|
+
fallback
|
|
15015
|
+
) : /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
15980
15016
|
"canvas",
|
|
15981
15017
|
{
|
|
15982
15018
|
ref: canvasRef,
|
|
@@ -16087,6 +15123,20 @@ function createLazyCreatorState(state) {
|
|
|
16087
15123
|
});
|
|
16088
15124
|
}
|
|
16089
15125
|
|
|
15126
|
+
function resolvePrimary(local) {
|
|
15127
|
+
return local.getState().primaryStore ?? local;
|
|
15128
|
+
}
|
|
15129
|
+
function usePrimaryStore() {
|
|
15130
|
+
const local = useStore();
|
|
15131
|
+
const primary = local.getState().primaryStore;
|
|
15132
|
+
return useMemo(() => primary ?? local, [primary, local]);
|
|
15133
|
+
}
|
|
15134
|
+
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15135
|
+
const local = useStore();
|
|
15136
|
+
const primary = resolvePrimary(local);
|
|
15137
|
+
return primary(selector, equalityFn);
|
|
15138
|
+
}
|
|
15139
|
+
|
|
16090
15140
|
function addTexture(set, key, value) {
|
|
16091
15141
|
set((state) => {
|
|
16092
15142
|
const newMap = new Map(state.textures);
|
|
@@ -16192,7 +15242,7 @@ function useCompareMemoize(value, deep) {
|
|
|
16192
15242
|
|
|
16193
15243
|
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
16194
15244
|
function useUniforms(creatorOrScope, scope) {
|
|
16195
|
-
const store =
|
|
15245
|
+
const store = usePrimaryStore();
|
|
16196
15246
|
const removeUniforms2 = useCallback(
|
|
16197
15247
|
(names, targetScope) => {
|
|
16198
15248
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16262,8 +15312,8 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
16262
15312
|
}, [creatorOrScope, store]);
|
|
16263
15313
|
const memoizedInput = useCompareMemoize(inputForMemoization);
|
|
16264
15314
|
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
16265
|
-
const storeUniforms =
|
|
16266
|
-
const hmrVersion =
|
|
15315
|
+
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15316
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16267
15317
|
const readerDep = isReader ? storeUniforms : null;
|
|
16268
15318
|
const creatorDep = isReader ? null : hmrVersion;
|
|
16269
15319
|
const uniforms = useMemo(() => {
|
|
@@ -16324,6 +15374,7 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
16324
15374
|
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
16325
15375
|
}
|
|
16326
15376
|
function rebuildAllUniforms(store, scope) {
|
|
15377
|
+
store = store.getState().primaryStore ?? store;
|
|
16327
15378
|
store.setState((state) => {
|
|
16328
15379
|
let newUniforms = {};
|
|
16329
15380
|
if (scope && scope !== "root") {
|
|
@@ -16452,7 +15503,7 @@ function useUniform(name, value) {
|
|
|
16452
15503
|
|
|
16453
15504
|
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
16454
15505
|
function useNodes(creatorOrScope, scope) {
|
|
16455
|
-
const store =
|
|
15506
|
+
const store = usePrimaryStore();
|
|
16456
15507
|
const removeNodes2 = useCallback(
|
|
16457
15508
|
(names, targetScope) => {
|
|
16458
15509
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16509,8 +15560,8 @@ function useNodes(creatorOrScope, scope) {
|
|
|
16509
15560
|
[store]
|
|
16510
15561
|
);
|
|
16511
15562
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16512
|
-
const storeNodes =
|
|
16513
|
-
const hmrVersion =
|
|
15563
|
+
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15564
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16514
15565
|
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
16515
15566
|
const readerDep = isReader ? storeNodes : null;
|
|
16516
15567
|
const creatorDep = isReader ? null : hmrVersion;
|
|
@@ -16569,6 +15620,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
16569
15620
|
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
16570
15621
|
}
|
|
16571
15622
|
function rebuildAllNodes(store, scope) {
|
|
15623
|
+
store = store.getState().primaryStore ?? store;
|
|
16572
15624
|
store.setState((state) => {
|
|
16573
15625
|
let newNodes = state.nodes;
|
|
16574
15626
|
if (scope && scope !== "root") {
|
|
@@ -16613,11 +15665,11 @@ function clearRootNodes(set) {
|
|
|
16613
15665
|
});
|
|
16614
15666
|
}
|
|
16615
15667
|
function useLocalNodes(creator) {
|
|
16616
|
-
const store =
|
|
16617
|
-
const uniforms =
|
|
16618
|
-
const nodes =
|
|
16619
|
-
const textures =
|
|
16620
|
-
const hmrVersion =
|
|
15668
|
+
const store = usePrimaryStore();
|
|
15669
|
+
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15670
|
+
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15671
|
+
const textures = usePrimaryThree((s) => s.textures);
|
|
15672
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16621
15673
|
return useMemo(() => {
|
|
16622
15674
|
const wrappedState = createLazyCreatorState(store.getState());
|
|
16623
15675
|
return creator(wrappedState);
|
|
@@ -16638,7 +15690,7 @@ const disposeBuffer = (buffer) => {
|
|
|
16638
15690
|
}
|
|
16639
15691
|
};
|
|
16640
15692
|
function useBuffers(creatorOrScope, scope) {
|
|
16641
|
-
const store =
|
|
15693
|
+
const store = usePrimaryStore();
|
|
16642
15694
|
const removeBuffers = useCallback(
|
|
16643
15695
|
(names, targetScope) => {
|
|
16644
15696
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16709,8 +15761,8 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
16709
15761
|
[store, removeBuffers]
|
|
16710
15762
|
);
|
|
16711
15763
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16712
|
-
const storeBuffers =
|
|
16713
|
-
const hmrVersion =
|
|
15764
|
+
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15765
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16714
15766
|
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
16715
15767
|
const readerDep = isReader ? storeBuffers : null;
|
|
16716
15768
|
const creatorDep = isReader ? null : hmrVersion;
|
|
@@ -16773,6 +15825,7 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
16773
15825
|
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
16774
15826
|
}
|
|
16775
15827
|
function rebuildAllBuffers(store, scope) {
|
|
15828
|
+
store = store.getState().primaryStore ?? store;
|
|
16776
15829
|
store.setState((state) => {
|
|
16777
15830
|
let newBuffers = state.buffers;
|
|
16778
15831
|
if (scope && scope !== "root") {
|
|
@@ -16804,7 +15857,7 @@ const disposeStorage = (storage) => {
|
|
|
16804
15857
|
}
|
|
16805
15858
|
};
|
|
16806
15859
|
function useGPUStorage(creatorOrScope, scope) {
|
|
16807
|
-
const store =
|
|
15860
|
+
const store = usePrimaryStore();
|
|
16808
15861
|
const removeStorage = useCallback(
|
|
16809
15862
|
(names, targetScope) => {
|
|
16810
15863
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16875,8 +15928,8 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
16875
15928
|
[store, removeStorage]
|
|
16876
15929
|
);
|
|
16877
15930
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16878
|
-
const storeStorage =
|
|
16879
|
-
const hmrVersion =
|
|
15931
|
+
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
15932
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16880
15933
|
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
16881
15934
|
const readerDep = isReader ? storeStorage : null;
|
|
16882
15935
|
const creatorDep = isReader ? null : hmrVersion;
|
|
@@ -16951,6 +16004,7 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
16951
16004
|
};
|
|
16952
16005
|
}
|
|
16953
16006
|
function rebuildAllStorage(store, scope) {
|
|
16007
|
+
store = store.getState().primaryStore ?? store;
|
|
16954
16008
|
store.setState((state) => {
|
|
16955
16009
|
let newStorage = state.gpuStorage;
|
|
16956
16010
|
if (scope && scope !== "root") {
|
|
@@ -17063,4 +16117,4 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
17063
16117
|
|
|
17064
16118
|
extend(THREE);
|
|
17065
16119
|
|
|
17066
|
-
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS,
|
|
16120
|
+
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };
|