@react-three/fiber 10.0.0-canary.604355a → 10.0.0-canary.76d2134
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 +885 -1422
- package/dist/index.d.cts +309 -811
- package/dist/index.d.mts +309 -811
- package/dist/index.d.ts +309 -811
- package/dist/index.mjs +860 -1396
- package/dist/legacy.cjs +840 -1383
- package/dist/legacy.d.cts +310 -811
- package/dist/legacy.d.mts +310 -811
- package/dist/legacy.d.ts +310 -811
- package/dist/legacy.mjs +814 -1356
- package/dist/webgpu/index.cjs +1341 -1737
- package/dist/webgpu/index.d.cts +425 -825
- package/dist/webgpu/index.d.mts +425 -825
- package/dist/webgpu/index.d.ts +425 -825
- package/dist/webgpu/index.mjs +1310 -1709
- package/package.json +4 -3
- package/readme.md +2 -3
package/dist/legacy.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as three from 'three';
|
|
2
|
-
import { WebGLRenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene,
|
|
2
|
+
import { WebGLCubeRenderTarget, WebGLRenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGLRenderer } from 'three';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { useLayoutEffect, useRef, useMemo, useEffect, useContext, useImperativeHandle, useCallback, useState } from 'react';
|
|
@@ -11,8 +11,10 @@ import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
|
|
|
11
11
|
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
12
12
|
import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
13
13
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
14
|
-
import Tb, {
|
|
14
|
+
import Tb, { unstable_getCurrentPriorityLevel, unstable_IdlePriority, unstable_LowPriority, unstable_NormalPriority, unstable_UserBlockingPriority, unstable_ImmediatePriority, unstable_scheduleCallback } from 'scheduler';
|
|
15
15
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
16
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
17
|
+
export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
16
18
|
import { suspend, preload, clear } from 'suspend-react';
|
|
17
19
|
|
|
18
20
|
function _mergeNamespaces(n, m) {
|
|
@@ -40,9 +42,12 @@ const WebGPURenderer = class WebGPURenderer2 {
|
|
|
40
42
|
}
|
|
41
43
|
};
|
|
42
44
|
const RenderTarget = null;
|
|
45
|
+
const CubeRenderTarget = null;
|
|
43
46
|
|
|
44
47
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
45
48
|
__proto__: null,
|
|
49
|
+
CubeRenderTarget: CubeRenderTarget,
|
|
50
|
+
CubeRenderTargetCompat: WebGLCubeRenderTarget,
|
|
46
51
|
Inspector: Inspector,
|
|
47
52
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
48
53
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
@@ -148,7 +153,7 @@ function useEnvironment({
|
|
|
148
153
|
useLoader$1.clear(loader, multiFile ? [files] : files);
|
|
149
154
|
}
|
|
150
155
|
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
151
|
-
}, [files, renderer.domElement]);
|
|
156
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
152
157
|
const loaderResult = useLoader$1(
|
|
153
158
|
loader,
|
|
154
159
|
multiFile ? [files] : files,
|
|
@@ -320,15 +325,16 @@ function EnvironmentPortal({
|
|
|
320
325
|
preset = void 0,
|
|
321
326
|
extensions
|
|
322
327
|
}) {
|
|
323
|
-
const
|
|
328
|
+
const renderer = useThree$1((state) => state.renderer);
|
|
329
|
+
const isLegacy = useThree$1((state) => state.isLegacy);
|
|
324
330
|
const defaultScene = useThree$1((state) => state.scene);
|
|
325
331
|
const camera = React.useRef(null);
|
|
326
332
|
const [virtualScene] = React.useState(() => new Scene());
|
|
327
333
|
const fbo = React.useMemo(() => {
|
|
328
|
-
const fbo2 = new WebGLCubeRenderTarget(resolution);
|
|
334
|
+
const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
|
|
329
335
|
fbo2.texture.type = HalfFloatType;
|
|
330
336
|
return fbo2;
|
|
331
|
-
}, [resolution]);
|
|
337
|
+
}, [resolution, isLegacy]);
|
|
332
338
|
React.useEffect(() => {
|
|
333
339
|
return () => {
|
|
334
340
|
fbo.dispose();
|
|
@@ -336,10 +342,10 @@ function EnvironmentPortal({
|
|
|
336
342
|
}, [fbo]);
|
|
337
343
|
React.useLayoutEffect(() => {
|
|
338
344
|
if (frames === 1) {
|
|
339
|
-
const autoClear =
|
|
340
|
-
|
|
341
|
-
camera.current.update(
|
|
342
|
-
|
|
345
|
+
const autoClear = renderer.autoClear;
|
|
346
|
+
renderer.autoClear = true;
|
|
347
|
+
camera.current.update(renderer, virtualScene);
|
|
348
|
+
renderer.autoClear = autoClear;
|
|
343
349
|
}
|
|
344
350
|
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
345
351
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
@@ -348,14 +354,29 @@ function EnvironmentPortal({
|
|
|
348
354
|
environmentIntensity,
|
|
349
355
|
environmentRotation
|
|
350
356
|
});
|
|
351
|
-
}, [
|
|
357
|
+
}, [
|
|
358
|
+
children,
|
|
359
|
+
virtualScene,
|
|
360
|
+
fbo.texture,
|
|
361
|
+
scene,
|
|
362
|
+
defaultScene,
|
|
363
|
+
background,
|
|
364
|
+
frames,
|
|
365
|
+
renderer,
|
|
366
|
+
blur,
|
|
367
|
+
backgroundBlurriness,
|
|
368
|
+
backgroundIntensity,
|
|
369
|
+
backgroundRotation,
|
|
370
|
+
environmentIntensity,
|
|
371
|
+
environmentRotation
|
|
372
|
+
]);
|
|
352
373
|
let count = 1;
|
|
353
374
|
useFrame$1(() => {
|
|
354
375
|
if (frames === Infinity || count < frames) {
|
|
355
|
-
const autoClear =
|
|
356
|
-
|
|
357
|
-
camera.current.update(
|
|
358
|
-
|
|
376
|
+
const autoClear = renderer.autoClear;
|
|
377
|
+
renderer.autoClear = true;
|
|
378
|
+
camera.current.update(renderer, virtualScene);
|
|
379
|
+
renderer.autoClear = autoClear;
|
|
359
380
|
count++;
|
|
360
381
|
}
|
|
361
382
|
});
|
|
@@ -419,10 +440,9 @@ function Environment(props) {
|
|
|
419
440
|
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
420
441
|
}
|
|
421
442
|
|
|
422
|
-
var __defProp
|
|
423
|
-
var __defNormalProp
|
|
424
|
-
var __publicField
|
|
425
|
-
const act = React["act"];
|
|
443
|
+
var __defProp = Object.defineProperty;
|
|
444
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
445
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
426
446
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
427
447
|
function useMutableCallback(fn) {
|
|
428
448
|
const ref = React.useRef(fn);
|
|
@@ -453,7 +473,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
453
473
|
return _a = class extends React.Component {
|
|
454
474
|
constructor() {
|
|
455
475
|
super(...arguments);
|
|
456
|
-
__publicField
|
|
476
|
+
__publicField(this, "state", { error: false });
|
|
457
477
|
}
|
|
458
478
|
componentDidCatch(err) {
|
|
459
479
|
this.props.set(err);
|
|
@@ -461,7 +481,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
461
481
|
render() {
|
|
462
482
|
return this.state.error ? null : this.props.children;
|
|
463
483
|
}
|
|
464
|
-
}, __publicField
|
|
484
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
465
485
|
})();
|
|
466
486
|
|
|
467
487
|
const is = {
|
|
@@ -598,8 +618,7 @@ function prepare(target, root, type, props) {
|
|
|
598
618
|
object,
|
|
599
619
|
eventCount: 0,
|
|
600
620
|
handlers: {},
|
|
601
|
-
isHidden: false
|
|
602
|
-
deferredRefs: []
|
|
621
|
+
isHidden: false
|
|
603
622
|
};
|
|
604
623
|
if (object) object.__r3f = instance;
|
|
605
624
|
}
|
|
@@ -756,6 +775,17 @@ function unregisterVisibility(store, object) {
|
|
|
756
775
|
internal.visibilityRegistry.delete(object.uuid);
|
|
757
776
|
internal.occlusionCache.delete(object);
|
|
758
777
|
}
|
|
778
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
779
|
+
const { internal } = store.getState();
|
|
780
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
781
|
+
if (!entry) return false;
|
|
782
|
+
entry.handlers = handlers;
|
|
783
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
784
|
+
object.occlusionTest = true;
|
|
785
|
+
enableOcclusion(store);
|
|
786
|
+
}
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
759
789
|
function checkVisibility(state) {
|
|
760
790
|
const { internal, camera } = state;
|
|
761
791
|
const registry = internal.visibilityRegistry;
|
|
@@ -916,9 +946,9 @@ function diffProps(instance, newProps) {
|
|
|
916
946
|
const { root, key } = resolve(instance.object, prop);
|
|
917
947
|
if (root.constructor && root.constructor.length === 0) {
|
|
918
948
|
const ctor = getMemoizedPrototype(root);
|
|
919
|
-
if (!is.und(ctor)) changedProps[
|
|
949
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
920
950
|
} else {
|
|
921
|
-
changedProps[
|
|
951
|
+
changedProps[prop] = 0;
|
|
922
952
|
}
|
|
923
953
|
}
|
|
924
954
|
return changedProps;
|
|
@@ -943,10 +973,7 @@ function applyProps(object, props) {
|
|
|
943
973
|
continue;
|
|
944
974
|
}
|
|
945
975
|
if (value === void 0) continue;
|
|
946
|
-
if (isFromRef(value))
|
|
947
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
976
|
+
if (isFromRef(value)) continue;
|
|
950
977
|
if (isOnce(value)) {
|
|
951
978
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
952
979
|
if (instance) {
|
|
@@ -982,8 +1009,24 @@ function applyProps(object, props) {
|
|
|
982
1009
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
983
1010
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
984
1011
|
else target.set(value);
|
|
1012
|
+
} else if (root instanceof ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1013
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1014
|
+
const uniforms = root.uniforms;
|
|
1015
|
+
const nextUniforms = value;
|
|
1016
|
+
for (const name in nextUniforms) {
|
|
1017
|
+
const uniform = nextUniforms[name];
|
|
1018
|
+
const targetUniform = uniforms[name];
|
|
1019
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1020
|
+
else {
|
|
1021
|
+
const nextUniform = uniform instanceof Uniform ? uniform.clone() : new Uniform(uniform.value);
|
|
1022
|
+
uniforms[name] = nextUniform;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
985
1025
|
} else {
|
|
986
1026
|
root[key] = value;
|
|
1027
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1028
|
+
root.needsUpdate = true;
|
|
1029
|
+
}
|
|
987
1030
|
if (rootState && rootState.renderer?.outputColorSpace === SRGBColorSpace && colorMaps.includes(key) && isTexture(value) && root[key]?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
988
1031
|
root[key].format === RGBAFormat && root[key].type === UnsignedByteType) {
|
|
989
1032
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -997,6 +1040,9 @@ function applyProps(object, props) {
|
|
|
997
1040
|
if (instance.eventCount && object2.raycast !== null) {
|
|
998
1041
|
rootState.internal.interaction.push(object2);
|
|
999
1042
|
}
|
|
1043
|
+
}
|
|
1044
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1045
|
+
const object2 = instance.object;
|
|
1000
1046
|
const root = findInitialRoot(instance);
|
|
1001
1047
|
const visibilityHandlers = {
|
|
1002
1048
|
onFramed: instance.handlers.onFramed,
|
|
@@ -1004,7 +1050,9 @@ function applyProps(object, props) {
|
|
|
1004
1050
|
onVisible: instance.handlers.onVisible
|
|
1005
1051
|
};
|
|
1006
1052
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
1007
|
-
|
|
1053
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1054
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1055
|
+
}
|
|
1008
1056
|
} else {
|
|
1009
1057
|
unregisterVisibility(root, object2);
|
|
1010
1058
|
}
|
|
@@ -1017,38 +1065,95 @@ function applyProps(object, props) {
|
|
|
1017
1065
|
return object;
|
|
1018
1066
|
}
|
|
1019
1067
|
|
|
1068
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1069
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1070
|
+
function getPointerState(internal, pointerId) {
|
|
1071
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1072
|
+
if (!state) {
|
|
1073
|
+
state = {
|
|
1074
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1075
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1076
|
+
initialClick: [0, 0],
|
|
1077
|
+
initialHits: []
|
|
1078
|
+
};
|
|
1079
|
+
internal.pointerMap.set(pointerId, state);
|
|
1080
|
+
}
|
|
1081
|
+
return state;
|
|
1082
|
+
}
|
|
1083
|
+
function getPointerId(event) {
|
|
1084
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1085
|
+
}
|
|
1020
1086
|
function makeId(event) {
|
|
1021
1087
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1022
1088
|
}
|
|
1023
|
-
function releaseInternalPointerCapture(
|
|
1024
|
-
const
|
|
1089
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1090
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1091
|
+
if (!pointerState) return;
|
|
1092
|
+
const captureData = pointerState.captured.get(obj);
|
|
1025
1093
|
if (captureData) {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1094
|
+
pointerState.captured.delete(obj);
|
|
1095
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function swapInteractivity(store, object, newObject) {
|
|
1099
|
+
const { internal } = store.getState();
|
|
1100
|
+
for (let i = 0; i < internal.interaction.length; i++) {
|
|
1101
|
+
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
1102
|
+
}
|
|
1103
|
+
for (const pointerState of internal.pointerMap.values()) {
|
|
1104
|
+
for (let i = 0; i < pointerState.initialHits.length; i++) {
|
|
1105
|
+
if (pointerState.initialHits[i] === object) pointerState.initialHits[i] = newObject;
|
|
1106
|
+
}
|
|
1107
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1108
|
+
if (value.eventObject === object || value.object === object) {
|
|
1109
|
+
pointerState.hovered.delete(key);
|
|
1110
|
+
const next = {
|
|
1111
|
+
...value,
|
|
1112
|
+
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
1113
|
+
object: value.object === object ? newObject : value.object
|
|
1114
|
+
};
|
|
1115
|
+
pointerState.hovered.set(makeId(next), next);
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
const captureData = pointerState.captured.get(object);
|
|
1119
|
+
if (captureData) {
|
|
1120
|
+
pointerState.captured.delete(object);
|
|
1121
|
+
pointerState.captured.set(newObject, {
|
|
1122
|
+
...captureData,
|
|
1123
|
+
intersection: {
|
|
1124
|
+
...captureData.intersection,
|
|
1125
|
+
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
1126
|
+
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1030
1129
|
}
|
|
1031
1130
|
}
|
|
1131
|
+
unregisterVisibility(store, object);
|
|
1032
1132
|
}
|
|
1033
1133
|
function removeInteractivity(store, object) {
|
|
1034
1134
|
const { internal } = store.getState();
|
|
1035
1135
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1136
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1137
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1138
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1139
|
+
if (value.eventObject === object || value.object === object) {
|
|
1140
|
+
pointerState.hovered.delete(key);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
if (pointerState.captured.has(object)) {
|
|
1144
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1040
1145
|
}
|
|
1041
|
-
}
|
|
1042
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1043
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1044
|
-
});
|
|
1146
|
+
}
|
|
1045
1147
|
unregisterVisibility(store, object);
|
|
1046
1148
|
}
|
|
1047
1149
|
function createEvents(store) {
|
|
1048
|
-
function calculateDistance(event) {
|
|
1150
|
+
function calculateDistance(event, pointerId) {
|
|
1049
1151
|
const { internal } = store.getState();
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1152
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1153
|
+
if (!pointerState) return 0;
|
|
1154
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1155
|
+
const dx = event.offsetX - initialX;
|
|
1156
|
+
const dy = event.offsetY - initialY;
|
|
1052
1157
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1053
1158
|
}
|
|
1054
1159
|
function filterPointerEvents(objects) {
|
|
@@ -1084,6 +1189,15 @@ function createEvents(store) {
|
|
|
1084
1189
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1085
1190
|
}
|
|
1086
1191
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1192
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1193
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1194
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1195
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1196
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1197
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1198
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1087
1201
|
const aState = getRootState(a.object);
|
|
1088
1202
|
const bState = getRootState(b.object);
|
|
1089
1203
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1105,9 +1219,13 @@ function createEvents(store) {
|
|
|
1105
1219
|
eventObject = eventObject.parent;
|
|
1106
1220
|
}
|
|
1107
1221
|
}
|
|
1108
|
-
if ("pointerId" in event
|
|
1109
|
-
|
|
1110
|
-
|
|
1222
|
+
if ("pointerId" in event) {
|
|
1223
|
+
const pointerId = event.pointerId;
|
|
1224
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1225
|
+
if (pointerState?.captured.size) {
|
|
1226
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1227
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1228
|
+
}
|
|
1111
1229
|
}
|
|
1112
1230
|
}
|
|
1113
1231
|
return intersections;
|
|
@@ -1120,27 +1238,25 @@ function createEvents(store) {
|
|
|
1120
1238
|
if (state) {
|
|
1121
1239
|
const { raycaster, pointer, camera, internal } = state;
|
|
1122
1240
|
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1123
|
-
const hasPointerCapture = (id) =>
|
|
1241
|
+
const hasPointerCapture = (id) => {
|
|
1242
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1243
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1244
|
+
};
|
|
1124
1245
|
const setPointerCapture = (id) => {
|
|
1125
1246
|
const captureData = { intersection: hit, target: event.target };
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
} else {
|
|
1129
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1130
|
-
}
|
|
1247
|
+
const pointerState = getPointerState(internal, id);
|
|
1248
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1131
1249
|
event.target.setPointerCapture(id);
|
|
1132
1250
|
};
|
|
1133
1251
|
const releasePointerCapture = (id) => {
|
|
1134
|
-
|
|
1135
|
-
if (captures) {
|
|
1136
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1137
|
-
}
|
|
1252
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1138
1253
|
};
|
|
1139
1254
|
const extractEventProps = {};
|
|
1140
1255
|
for (const prop in event) {
|
|
1141
1256
|
const property = event[prop];
|
|
1142
1257
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1143
1258
|
}
|
|
1259
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1144
1260
|
const raycastEvent = {
|
|
1145
1261
|
...hit,
|
|
1146
1262
|
...extractEventProps,
|
|
@@ -1151,18 +1267,19 @@ function createEvents(store) {
|
|
|
1151
1267
|
unprojectedPoint,
|
|
1152
1268
|
ray: raycaster.ray,
|
|
1153
1269
|
camera,
|
|
1270
|
+
pointerId: eventPointerId,
|
|
1154
1271
|
// Hijack stopPropagation, which just sets a flag
|
|
1155
1272
|
stopPropagation() {
|
|
1156
|
-
const
|
|
1273
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1157
1274
|
if (
|
|
1158
1275
|
// ...if this pointer hasn't been captured
|
|
1159
|
-
!
|
|
1160
|
-
|
|
1276
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1277
|
+
pointerState.captured.has(hit.eventObject)
|
|
1161
1278
|
) {
|
|
1162
1279
|
raycastEvent.stopped = localState.stopped = true;
|
|
1163
|
-
if (
|
|
1280
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1164
1281
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1165
|
-
cancelPointer([...higher, hit]);
|
|
1282
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1166
1283
|
}
|
|
1167
1284
|
}
|
|
1168
1285
|
},
|
|
@@ -1178,15 +1295,18 @@ function createEvents(store) {
|
|
|
1178
1295
|
}
|
|
1179
1296
|
return intersections;
|
|
1180
1297
|
}
|
|
1181
|
-
function cancelPointer(intersections) {
|
|
1298
|
+
function cancelPointer(intersections, pointerId) {
|
|
1182
1299
|
const { internal } = store.getState();
|
|
1183
|
-
|
|
1300
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1301
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1302
|
+
if (!pointerState) return;
|
|
1303
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1184
1304
|
if (!intersections.length || !intersections.find(
|
|
1185
1305
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1186
1306
|
)) {
|
|
1187
1307
|
const eventObject = hoveredObj.eventObject;
|
|
1188
1308
|
const instance = eventObject.__r3f;
|
|
1189
|
-
|
|
1309
|
+
pointerState.hovered.delete(hoveredId);
|
|
1190
1310
|
if (instance?.eventCount) {
|
|
1191
1311
|
const handlers = instance.handlers;
|
|
1192
1312
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1215,41 +1335,118 @@ function createEvents(store) {
|
|
|
1215
1335
|
instance?.handlers.onDropMissed?.(event);
|
|
1216
1336
|
}
|
|
1217
1337
|
}
|
|
1338
|
+
function cleanupPointer(pointerId) {
|
|
1339
|
+
const { internal } = store.getState();
|
|
1340
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1341
|
+
if (pointerState) {
|
|
1342
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1343
|
+
const eventObject = hoveredObj.eventObject;
|
|
1344
|
+
const instance = eventObject.__r3f;
|
|
1345
|
+
if (instance?.eventCount) {
|
|
1346
|
+
const handlers = instance.handlers;
|
|
1347
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1348
|
+
handlers.onPointerOut?.(data);
|
|
1349
|
+
handlers.onPointerLeave?.(data);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
internal.pointerMap.delete(pointerId);
|
|
1353
|
+
}
|
|
1354
|
+
internal.pointerDirty.delete(pointerId);
|
|
1355
|
+
}
|
|
1356
|
+
function processDeferredPointer(event, pointerId) {
|
|
1357
|
+
const state = store.getState();
|
|
1358
|
+
const { internal } = state;
|
|
1359
|
+
if (!state.events.enabled) return;
|
|
1360
|
+
const filter = filterPointerEvents;
|
|
1361
|
+
const hits = intersect(event, filter);
|
|
1362
|
+
cancelPointer(hits, pointerId);
|
|
1363
|
+
function onIntersect(data) {
|
|
1364
|
+
const eventObject = data.eventObject;
|
|
1365
|
+
const instance = eventObject.__r3f;
|
|
1366
|
+
if (!instance?.eventCount) return;
|
|
1367
|
+
const handlers = instance.handlers;
|
|
1368
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1369
|
+
const id = makeId(data);
|
|
1370
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1371
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1372
|
+
if (!hoveredItem) {
|
|
1373
|
+
pointerState.hovered.set(id, data);
|
|
1374
|
+
handlers.onPointerOver?.(data);
|
|
1375
|
+
handlers.onPointerEnter?.(data);
|
|
1376
|
+
} else if (hoveredItem.stopped) {
|
|
1377
|
+
data.stopPropagation();
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
handlers.onPointerMove?.(data);
|
|
1381
|
+
}
|
|
1382
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1383
|
+
}
|
|
1218
1384
|
function handlePointer(name) {
|
|
1219
1385
|
switch (name) {
|
|
1220
1386
|
case "onPointerLeave":
|
|
1221
|
-
case "onPointerCancel":
|
|
1222
1387
|
case "onDragLeave":
|
|
1223
1388
|
return () => cancelPointer([]);
|
|
1389
|
+
// Global cancel of these events
|
|
1390
|
+
case "onPointerCancel":
|
|
1391
|
+
return (event) => {
|
|
1392
|
+
const pointerId = getPointerId(event);
|
|
1393
|
+
cleanupPointer(pointerId);
|
|
1394
|
+
};
|
|
1224
1395
|
case "onLostPointerCapture":
|
|
1225
1396
|
return (event) => {
|
|
1226
1397
|
const { internal } = store.getState();
|
|
1227
|
-
|
|
1398
|
+
const pointerId = getPointerId(event);
|
|
1399
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1400
|
+
if (pointerState?.captured.size) {
|
|
1228
1401
|
requestAnimationFrame(() => {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1402
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1403
|
+
if (pointerState2?.captured.size) {
|
|
1404
|
+
pointerState2.captured.clear();
|
|
1232
1405
|
}
|
|
1406
|
+
cancelPointer([], pointerId);
|
|
1233
1407
|
});
|
|
1234
1408
|
}
|
|
1235
1409
|
};
|
|
1236
1410
|
}
|
|
1237
1411
|
return function handleEvent(event) {
|
|
1238
1412
|
const state = store.getState();
|
|
1239
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1413
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1414
|
+
const pointerId = getPointerId(event);
|
|
1240
1415
|
internal.lastEvent.current = event;
|
|
1241
|
-
if (!
|
|
1416
|
+
if (!events.enabled) return;
|
|
1242
1417
|
const isPointerMove = name === "onPointerMove";
|
|
1243
1418
|
const isDragOver = name === "onDragOver";
|
|
1244
1419
|
const isDrop = name === "onDrop";
|
|
1245
1420
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1421
|
+
const isPointerDown = name === "onPointerDown";
|
|
1422
|
+
const isPointerUp = name === "onPointerUp";
|
|
1423
|
+
const isWheel = name === "onWheel";
|
|
1424
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1425
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1426
|
+
events.compute?.(event, state);
|
|
1427
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1431
|
+
events.compute?.(event, state);
|
|
1432
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1436
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1437
|
+
internal.pointerDirty.delete(pointerId);
|
|
1438
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1439
|
+
}
|
|
1246
1440
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1247
1441
|
const hits = intersect(event, filter);
|
|
1248
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1442
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1443
|
+
if (isPointerDown) {
|
|
1444
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1445
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1446
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1447
|
+
}
|
|
1448
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1449
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1253
1450
|
if (isClickEvent && !hits.length) {
|
|
1254
1451
|
if (delta <= 2) {
|
|
1255
1452
|
pointerMissed(event, internal.interaction);
|
|
@@ -1264,7 +1461,9 @@ function createEvents(store) {
|
|
|
1264
1461
|
dropMissed(event, internal.interaction);
|
|
1265
1462
|
if (onDropMissed) onDropMissed(event);
|
|
1266
1463
|
}
|
|
1267
|
-
if (isPointerMove || isDragOver)
|
|
1464
|
+
if (isPointerMove || isDragOver) {
|
|
1465
|
+
cancelPointer(hits, pointerId);
|
|
1466
|
+
}
|
|
1268
1467
|
function onIntersect(data) {
|
|
1269
1468
|
const eventObject = data.eventObject;
|
|
1270
1469
|
const instance = eventObject.__r3f;
|
|
@@ -1273,9 +1472,10 @@ function createEvents(store) {
|
|
|
1273
1472
|
if (isPointerMove) {
|
|
1274
1473
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1275
1474
|
const id = makeId(data);
|
|
1276
|
-
const
|
|
1475
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1476
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1277
1477
|
if (!hoveredItem) {
|
|
1278
|
-
|
|
1478
|
+
pointerState2.hovered.set(id, data);
|
|
1279
1479
|
handlers.onPointerOver?.(data);
|
|
1280
1480
|
handlers.onPointerEnter?.(data);
|
|
1281
1481
|
} else if (hoveredItem.stopped) {
|
|
@@ -1285,9 +1485,10 @@ function createEvents(store) {
|
|
|
1285
1485
|
handlers.onPointerMove?.(data);
|
|
1286
1486
|
} else if (isDragOver) {
|
|
1287
1487
|
const id = makeId(data);
|
|
1288
|
-
const
|
|
1488
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1489
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1289
1490
|
if (!hoveredItem) {
|
|
1290
|
-
|
|
1491
|
+
pointerState2.hovered.set(id, data);
|
|
1291
1492
|
handlers.onDragOverEnter?.(data);
|
|
1292
1493
|
} else if (hoveredItem.stopped) {
|
|
1293
1494
|
data.stopPropagation();
|
|
@@ -1298,18 +1499,18 @@ function createEvents(store) {
|
|
|
1298
1499
|
} else {
|
|
1299
1500
|
const handler = handlers[name];
|
|
1300
1501
|
if (handler) {
|
|
1301
|
-
if (!isClickEvent ||
|
|
1502
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1302
1503
|
pointerMissed(
|
|
1303
1504
|
event,
|
|
1304
|
-
internal.interaction.filter((object) => !
|
|
1505
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1305
1506
|
);
|
|
1306
1507
|
handler(data);
|
|
1307
1508
|
}
|
|
1308
1509
|
} else {
|
|
1309
|
-
if (isClickEvent &&
|
|
1510
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1310
1511
|
pointerMissed(
|
|
1311
1512
|
event,
|
|
1312
|
-
internal.interaction.filter((object) => !
|
|
1513
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1313
1514
|
);
|
|
1314
1515
|
}
|
|
1315
1516
|
}
|
|
@@ -1318,7 +1519,15 @@ function createEvents(store) {
|
|
|
1318
1519
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1319
1520
|
};
|
|
1320
1521
|
}
|
|
1321
|
-
|
|
1522
|
+
function flushDeferredPointers() {
|
|
1523
|
+
const { internal, events } = store.getState();
|
|
1524
|
+
if (!events.frameTimedRaycasts) return;
|
|
1525
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1526
|
+
processDeferredPointer(event, pointerId);
|
|
1527
|
+
}
|
|
1528
|
+
internal.pointerDirty.clear();
|
|
1529
|
+
}
|
|
1530
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1322
1531
|
}
|
|
1323
1532
|
const DOM_EVENTS = {
|
|
1324
1533
|
onClick: ["click", false],
|
|
@@ -1337,10 +1546,15 @@ const DOM_EVENTS = {
|
|
|
1337
1546
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1338
1547
|
};
|
|
1339
1548
|
function createPointerEvents(store) {
|
|
1340
|
-
const { handlePointer } = createEvents(store);
|
|
1549
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1550
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1551
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1341
1552
|
return {
|
|
1342
1553
|
priority: 1,
|
|
1343
1554
|
enabled: true,
|
|
1555
|
+
frameTimedRaycasts: true,
|
|
1556
|
+
alwaysFireOnScroll: true,
|
|
1557
|
+
updateOnFrame: false,
|
|
1344
1558
|
compute(event, state) {
|
|
1345
1559
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1346
1560
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1350,11 +1564,33 @@ function createPointerEvents(store) {
|
|
|
1350
1564
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1351
1565
|
{}
|
|
1352
1566
|
),
|
|
1353
|
-
update: () => {
|
|
1567
|
+
update: (pointerId) => {
|
|
1568
|
+
const { events, internal } = store.getState();
|
|
1569
|
+
if (!events.handlers) return;
|
|
1570
|
+
if (pointerId !== void 0) {
|
|
1571
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1572
|
+
if (event) {
|
|
1573
|
+
internal.pointerDirty.delete(pointerId);
|
|
1574
|
+
processDeferredPointer(event, pointerId);
|
|
1575
|
+
} else if (internal.lastEvent?.current) {
|
|
1576
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
flushDeferredPointers();
|
|
1580
|
+
if (internal.lastEvent?.current) {
|
|
1581
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
},
|
|
1585
|
+
flush: () => {
|
|
1354
1586
|
const { events, internal } = store.getState();
|
|
1355
|
-
|
|
1587
|
+
flushDeferredPointers();
|
|
1588
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1589
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1590
|
+
}
|
|
1356
1591
|
},
|
|
1357
1592
|
connect: (target) => {
|
|
1593
|
+
if (!target) return;
|
|
1358
1594
|
const { set, events } = store.getState();
|
|
1359
1595
|
events.disconnect?.();
|
|
1360
1596
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1378,6 +1614,33 @@ function createPointerEvents(store) {
|
|
|
1378
1614
|
}
|
|
1379
1615
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1380
1616
|
}
|
|
1617
|
+
},
|
|
1618
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1619
|
+
registerPointer: (config) => {
|
|
1620
|
+
const pointerId = nextXRPointerId++;
|
|
1621
|
+
xrPointers.set(pointerId, config);
|
|
1622
|
+
const { internal } = store.getState();
|
|
1623
|
+
getPointerState(internal, pointerId);
|
|
1624
|
+
return pointerId;
|
|
1625
|
+
},
|
|
1626
|
+
unregisterPointer: (pointerId) => {
|
|
1627
|
+
xrPointers.delete(pointerId);
|
|
1628
|
+
const { internal } = store.getState();
|
|
1629
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1630
|
+
if (pointerState) {
|
|
1631
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1632
|
+
const eventObject = hoveredObj.eventObject;
|
|
1633
|
+
const instance = eventObject.__r3f;
|
|
1634
|
+
if (instance?.eventCount) {
|
|
1635
|
+
const handlers = instance.handlers;
|
|
1636
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1637
|
+
handlers.onPointerOut?.(data);
|
|
1638
|
+
handlers.onPointerLeave?.(data);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
internal.pointerMap.delete(pointerId);
|
|
1642
|
+
}
|
|
1643
|
+
internal.pointerDirty.delete(pointerId);
|
|
1381
1644
|
}
|
|
1382
1645
|
};
|
|
1383
1646
|
}
|
|
@@ -1439,1036 +1702,11 @@ function notifyAlpha({ message, link }) {
|
|
|
1439
1702
|
}
|
|
1440
1703
|
}
|
|
1441
1704
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1447
|
-
constructor() {
|
|
1448
|
-
/** Ordered list of phase nodes */
|
|
1449
|
-
__publicField$1(this, "phases", []);
|
|
1450
|
-
/** Quick lookup by name */
|
|
1451
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1452
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1453
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1454
|
-
this.initializeDefaultPhases();
|
|
1455
|
-
}
|
|
1456
|
-
//* Initialization --------------------------------
|
|
1457
|
-
initializeDefaultPhases() {
|
|
1458
|
-
for (const name of DEFAULT_PHASES) {
|
|
1459
|
-
const node = { name, isAutoGenerated: false };
|
|
1460
|
-
this.phases.push(node);
|
|
1461
|
-
this.phaseMap.set(name, node);
|
|
1462
|
-
}
|
|
1463
|
-
this.invalidateCache();
|
|
1464
|
-
}
|
|
1465
|
-
//* Public API --------------------------------
|
|
1466
|
-
/**
|
|
1467
|
-
* Add a named phase to the graph
|
|
1468
|
-
* @param name - Phase name (must be unique)
|
|
1469
|
-
* @param options - Position options (before or after another phase)
|
|
1470
|
-
*/
|
|
1471
|
-
addPhase(name, options = {}) {
|
|
1472
|
-
if (this.phaseMap.has(name)) {
|
|
1473
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
const { before, after } = options;
|
|
1477
|
-
const node = { name, isAutoGenerated: false };
|
|
1478
|
-
let insertIndex = this.phases.length;
|
|
1479
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1480
|
-
if (targetIndex !== -1) {
|
|
1481
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1482
|
-
} else {
|
|
1483
|
-
const constraintType = before ? "before" : "after";
|
|
1484
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1485
|
-
}
|
|
1486
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1487
|
-
this.phaseMap.set(name, node);
|
|
1488
|
-
this.invalidateCache();
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Get ordered list of phase names
|
|
1492
|
-
*/
|
|
1493
|
-
getOrderedPhases() {
|
|
1494
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1495
|
-
return this.orderedNamesCache;
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Check if a phase exists
|
|
1499
|
-
*/
|
|
1500
|
-
hasPhase(name) {
|
|
1501
|
-
return this.phaseMap.has(name);
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* Get the index of a phase (-1 if not found)
|
|
1505
|
-
*/
|
|
1506
|
-
getPhaseIndex(name) {
|
|
1507
|
-
if (!name) return -1;
|
|
1508
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1509
|
-
}
|
|
1510
|
-
/**
|
|
1511
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1512
|
-
* Used for resolving before/after constraints.
|
|
1513
|
-
*
|
|
1514
|
-
* @param name - The phase name to ensure exists
|
|
1515
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1516
|
-
*/
|
|
1517
|
-
ensurePhase(name) {
|
|
1518
|
-
if (this.phaseMap.has(name)) return name;
|
|
1519
|
-
const node = { name, isAutoGenerated: true };
|
|
1520
|
-
this.phases.push(node);
|
|
1521
|
-
this.phaseMap.set(name, node);
|
|
1522
|
-
this.invalidateCache();
|
|
1523
|
-
return name;
|
|
1524
|
-
}
|
|
1525
|
-
/**
|
|
1526
|
-
* Resolve where a job with before/after constraints should go.
|
|
1527
|
-
* Creates auto-generated phases if needed.
|
|
1528
|
-
*
|
|
1529
|
-
* @param before - Phase(s) to run before
|
|
1530
|
-
* @param after - Phase(s) to run after
|
|
1531
|
-
* @returns The resolved phase name
|
|
1532
|
-
*/
|
|
1533
|
-
resolveConstraintPhase(before, after) {
|
|
1534
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1535
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1536
|
-
if (beforeArr.length > 0) {
|
|
1537
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1538
|
-
}
|
|
1539
|
-
if (afterArr.length > 0) {
|
|
1540
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1541
|
-
}
|
|
1542
|
-
return "update";
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1546
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1547
|
-
*
|
|
1548
|
-
* @param target - The target phase name to position relative to
|
|
1549
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1550
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1551
|
-
* @returns The auto-generated phase name
|
|
1552
|
-
*/
|
|
1553
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1554
|
-
const autoName = `${prefix}:${target}`;
|
|
1555
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1556
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1557
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1558
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1559
|
-
else this.phases.push(node);
|
|
1560
|
-
this.phaseMap.set(autoName, node);
|
|
1561
|
-
this.invalidateCache();
|
|
1562
|
-
return autoName;
|
|
1563
|
-
}
|
|
1564
|
-
// Internal --------------------------------
|
|
1565
|
-
invalidateCache() {
|
|
1566
|
-
this.orderedNamesCache = null;
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1571
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1572
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1573
|
-
for (const phase of orderedPhases) {
|
|
1574
|
-
buckets.set(phase, []);
|
|
1575
|
-
}
|
|
1576
|
-
for (const job of jobs.values()) {
|
|
1577
|
-
if (!job.enabled) continue;
|
|
1578
|
-
let bucket = buckets.get(job.phase);
|
|
1579
|
-
if (!bucket) {
|
|
1580
|
-
bucket = [];
|
|
1581
|
-
buckets.set(job.phase, bucket);
|
|
1582
|
-
}
|
|
1583
|
-
bucket.push(job);
|
|
1584
|
-
}
|
|
1585
|
-
const sortedBuckets = [];
|
|
1586
|
-
for (const phase of orderedPhases) {
|
|
1587
|
-
const bucket = buckets.get(phase);
|
|
1588
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1589
|
-
bucket.sort((a, b) => {
|
|
1590
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1591
|
-
return a.index - b.index;
|
|
1592
|
-
});
|
|
1593
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1594
|
-
}
|
|
1595
|
-
for (const [phase, bucket] of buckets) {
|
|
1596
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1597
|
-
bucket.sort((a, b) => {
|
|
1598
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1599
|
-
return a.index - b.index;
|
|
1600
|
-
});
|
|
1601
|
-
sortedBuckets.push(bucket);
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
return sortedBuckets.flat();
|
|
1605
|
-
}
|
|
1606
|
-
function hasCrossJobConstraints(bucket) {
|
|
1607
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1608
|
-
for (const job of bucket) {
|
|
1609
|
-
for (const ref of job.before) {
|
|
1610
|
-
if (jobIds.has(ref)) return true;
|
|
1611
|
-
}
|
|
1612
|
-
for (const ref of job.after) {
|
|
1613
|
-
if (jobIds.has(ref)) return true;
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
return false;
|
|
1617
|
-
}
|
|
1618
|
-
function topologicalSort(jobs) {
|
|
1619
|
-
const n = jobs.length;
|
|
1620
|
-
if (n <= 1) return jobs;
|
|
1621
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1622
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1623
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1624
|
-
for (const job of jobs) {
|
|
1625
|
-
jobMap.set(job.id, job);
|
|
1626
|
-
inDegree.set(job.id, 0);
|
|
1627
|
-
adjacency.set(job.id, []);
|
|
1628
|
-
}
|
|
1629
|
-
for (const job of jobs) {
|
|
1630
|
-
for (const ref of job.before) {
|
|
1631
|
-
if (jobMap.has(ref)) {
|
|
1632
|
-
adjacency.get(job.id).push(ref);
|
|
1633
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
for (const ref of job.after) {
|
|
1637
|
-
if (jobMap.has(ref)) {
|
|
1638
|
-
adjacency.get(ref).push(job.id);
|
|
1639
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
const queue = [];
|
|
1644
|
-
for (const job of jobs) {
|
|
1645
|
-
if (inDegree.get(job.id) === 0) {
|
|
1646
|
-
queue.push(job);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
queue.sort((a, b) => {
|
|
1650
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1651
|
-
return a.index - b.index;
|
|
1652
|
-
});
|
|
1653
|
-
const result = [];
|
|
1654
|
-
while (queue.length > 0) {
|
|
1655
|
-
const job = queue.shift();
|
|
1656
|
-
result.push(job);
|
|
1657
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1658
|
-
for (const neighborId of neighbors) {
|
|
1659
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1660
|
-
inDegree.set(neighborId, newDegree);
|
|
1661
|
-
if (newDegree === 0) {
|
|
1662
|
-
const neighbor = jobMap.get(neighborId);
|
|
1663
|
-
insertSorted(queue, neighbor);
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
if (result.length !== n) {
|
|
1668
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1669
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1670
|
-
for (const job of jobs) {
|
|
1671
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
return result;
|
|
1675
|
-
}
|
|
1676
|
-
function insertSorted(arr, job) {
|
|
1677
|
-
let i = 0;
|
|
1678
|
-
while (i < arr.length) {
|
|
1679
|
-
const cmp = arr[i];
|
|
1680
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1681
|
-
break;
|
|
1682
|
-
}
|
|
1683
|
-
i++;
|
|
1684
|
-
}
|
|
1685
|
-
arr.splice(i, 0, job);
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
function shouldRun(job, now) {
|
|
1689
|
-
if (!job.enabled) return false;
|
|
1690
|
-
if (!job.fps) return true;
|
|
1691
|
-
const minInterval = 1e3 / job.fps;
|
|
1692
|
-
const lastRun = job.lastRun ?? 0;
|
|
1693
|
-
const elapsed = now - lastRun;
|
|
1694
|
-
if (elapsed < minInterval) return false;
|
|
1695
|
-
if (job.drop) {
|
|
1696
|
-
job.lastRun = now;
|
|
1697
|
-
} else {
|
|
1698
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1699
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1700
|
-
if (job.lastRun < now - minInterval) {
|
|
1701
|
-
job.lastRun = now;
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
return true;
|
|
1705
|
-
}
|
|
1706
|
-
function resetJobTiming(job) {
|
|
1707
|
-
job.lastRun = void 0;
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
var __defProp = Object.defineProperty;
|
|
1711
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1712
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1713
|
-
const hmrData = (() => {
|
|
1714
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1715
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1716
|
-
try {
|
|
1717
|
-
return (0, eval)("import.meta.hot");
|
|
1718
|
-
} catch {
|
|
1719
|
-
return void 0;
|
|
1720
|
-
}
|
|
1721
|
-
})();
|
|
1722
|
-
const _Scheduler = class _Scheduler {
|
|
1723
|
-
//* Constructor ================================
|
|
1724
|
-
constructor() {
|
|
1725
|
-
//* Critical State ================================
|
|
1726
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1727
|
-
__publicField(this, "phaseGraph");
|
|
1728
|
-
__publicField(this, "loopState", {
|
|
1729
|
-
running: false,
|
|
1730
|
-
rafHandle: null,
|
|
1731
|
-
lastTime: null,
|
|
1732
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1733
|
-
frameCount: 0,
|
|
1734
|
-
elapsedTime: 0,
|
|
1735
|
-
createdAt: performance.now()
|
|
1736
|
-
});
|
|
1737
|
-
__publicField(this, "stoppedTime", 0);
|
|
1738
|
-
//* Private State ================================
|
|
1739
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1740
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1741
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1742
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1743
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1744
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1745
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1746
|
-
__publicField(this, "pendingFrames", 0);
|
|
1747
|
-
__publicField(this, "_frameloop", "always");
|
|
1748
|
-
//* Independent Mode & Error Handling State ================================
|
|
1749
|
-
__publicField(this, "_independent", false);
|
|
1750
|
-
__publicField(this, "errorHandler", null);
|
|
1751
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1752
|
-
//* Core Loop Execution Methods ================================
|
|
1753
|
-
/**
|
|
1754
|
-
* Main RAF loop callback.
|
|
1755
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1756
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1757
|
-
* @returns {void}
|
|
1758
|
-
* @private
|
|
1759
|
-
*/
|
|
1760
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1761
|
-
if (!this.loopState.running) return;
|
|
1762
|
-
this.executeFrame(timestamp);
|
|
1763
|
-
if (this._frameloop === "demand") {
|
|
1764
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1765
|
-
if (this.pendingFrames === 0) {
|
|
1766
|
-
this.notifyIdle(timestamp);
|
|
1767
|
-
return this.stop();
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1771
|
-
});
|
|
1772
|
-
this.phaseGraph = new PhaseGraph();
|
|
1773
|
-
}
|
|
1774
|
-
static get instance() {
|
|
1775
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1776
|
-
}
|
|
1777
|
-
static set instance(value) {
|
|
1778
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1782
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1783
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1784
|
-
*/
|
|
1785
|
-
static get() {
|
|
1786
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1787
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1788
|
-
}
|
|
1789
|
-
if (!_Scheduler.instance) {
|
|
1790
|
-
_Scheduler.instance = new _Scheduler();
|
|
1791
|
-
if (hmrData?.data) {
|
|
1792
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
return _Scheduler.instance;
|
|
1796
|
-
}
|
|
1797
|
-
/**
|
|
1798
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1799
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1800
|
-
* @returns {void}
|
|
1801
|
-
*/
|
|
1802
|
-
static reset() {
|
|
1803
|
-
if (_Scheduler.instance) {
|
|
1804
|
-
_Scheduler.instance.stop();
|
|
1805
|
-
_Scheduler.instance = null;
|
|
1806
|
-
}
|
|
1807
|
-
if (hmrData?.data) {
|
|
1808
|
-
hmrData.data.scheduler = null;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
//* Getters & Setters ================================
|
|
1812
|
-
get phases() {
|
|
1813
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1814
|
-
}
|
|
1815
|
-
get frameloop() {
|
|
1816
|
-
return this._frameloop;
|
|
1817
|
-
}
|
|
1818
|
-
set frameloop(mode) {
|
|
1819
|
-
if (this._frameloop === mode) return;
|
|
1820
|
-
const wasAlways = this._frameloop === "always";
|
|
1821
|
-
this._frameloop = mode;
|
|
1822
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1823
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1824
|
-
}
|
|
1825
|
-
get isRunning() {
|
|
1826
|
-
return this.loopState.running;
|
|
1827
|
-
}
|
|
1828
|
-
get isReady() {
|
|
1829
|
-
return this.roots.size > 0;
|
|
1830
|
-
}
|
|
1831
|
-
get independent() {
|
|
1832
|
-
return this._independent;
|
|
1833
|
-
}
|
|
1834
|
-
set independent(value) {
|
|
1835
|
-
this._independent = value;
|
|
1836
|
-
if (value) this.ensureDefaultRoot();
|
|
1837
|
-
}
|
|
1838
|
-
//* Root Management Methods ================================
|
|
1839
|
-
/**
|
|
1840
|
-
* Register a root (Canvas) with the scheduler.
|
|
1841
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1842
|
-
* @param {string} id - Unique identifier for this root
|
|
1843
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1844
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1845
|
-
*/
|
|
1846
|
-
registerRoot(id, options = {}) {
|
|
1847
|
-
if (this.roots.has(id)) {
|
|
1848
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1849
|
-
return () => this.unregisterRoot(id);
|
|
1850
|
-
}
|
|
1851
|
-
const entry = {
|
|
1852
|
-
id,
|
|
1853
|
-
getState: options.getState ?? (() => ({})),
|
|
1854
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1855
|
-
sortedJobs: [],
|
|
1856
|
-
needsRebuild: false
|
|
1857
|
-
};
|
|
1858
|
-
if (options.onError) {
|
|
1859
|
-
this.errorHandler = options.onError;
|
|
1860
|
-
}
|
|
1861
|
-
this.roots.set(id, entry);
|
|
1862
|
-
if (this.roots.size === 1) {
|
|
1863
|
-
this.notifyRootReady();
|
|
1864
|
-
if (this._frameloop === "always") this.start();
|
|
1865
|
-
}
|
|
1866
|
-
return () => this.unregisterRoot(id);
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
|
-
* Unregister a root from the scheduler.
|
|
1870
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1871
|
-
* The last root to unregister stops the RAF loop.
|
|
1872
|
-
* @param {string} id - The root ID to unregister
|
|
1873
|
-
* @returns {void}
|
|
1874
|
-
*/
|
|
1875
|
-
unregisterRoot(id) {
|
|
1876
|
-
const root = this.roots.get(id);
|
|
1877
|
-
if (!root) return;
|
|
1878
|
-
for (const jobId of root.jobs.keys()) {
|
|
1879
|
-
this.jobStateListeners.delete(jobId);
|
|
1880
|
-
}
|
|
1881
|
-
this.roots.delete(id);
|
|
1882
|
-
if (this.roots.size === 0) {
|
|
1883
|
-
this.stop();
|
|
1884
|
-
this.errorHandler = null;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Subscribe to be notified when a root becomes available.
|
|
1889
|
-
* Fires immediately if a root already exists.
|
|
1890
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1891
|
-
* @returns {() => void} Unsubscribe function
|
|
1892
|
-
*/
|
|
1893
|
-
onRootReady(callback) {
|
|
1894
|
-
if (this.roots.size > 0) {
|
|
1895
|
-
callback();
|
|
1896
|
-
return () => {
|
|
1897
|
-
};
|
|
1898
|
-
}
|
|
1899
|
-
this.rootReadyCallbacks.add(callback);
|
|
1900
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* Notify all registered root-ready callbacks.
|
|
1904
|
-
* Called when the first root registers.
|
|
1905
|
-
* @returns {void}
|
|
1906
|
-
* @private
|
|
1907
|
-
*/
|
|
1908
|
-
notifyRootReady() {
|
|
1909
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1910
|
-
try {
|
|
1911
|
-
cb();
|
|
1912
|
-
} catch (error) {
|
|
1913
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
this.rootReadyCallbacks.clear();
|
|
1917
|
-
}
|
|
1918
|
-
/**
|
|
1919
|
-
* Ensure a default root exists for independent mode.
|
|
1920
|
-
* Creates a minimal root with no state provider.
|
|
1921
|
-
* @returns {void}
|
|
1922
|
-
* @private
|
|
1923
|
-
*/
|
|
1924
|
-
ensureDefaultRoot() {
|
|
1925
|
-
if (!this.roots.has("__default__")) {
|
|
1926
|
-
this.registerRoot("__default__");
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
/**
|
|
1930
|
-
* Trigger error handling for job errors.
|
|
1931
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1932
|
-
* @param {Error} error - The error to handle
|
|
1933
|
-
* @returns {void}
|
|
1934
|
-
*/
|
|
1935
|
-
triggerError(error) {
|
|
1936
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1937
|
-
else console.error("[Scheduler]", error);
|
|
1938
|
-
}
|
|
1939
|
-
//* Phase Management Methods ================================
|
|
1940
|
-
/**
|
|
1941
|
-
* Add a named phase to the scheduler's execution order.
|
|
1942
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1943
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1944
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1945
|
-
* @returns {void}
|
|
1946
|
-
* @example
|
|
1947
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1948
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1949
|
-
*/
|
|
1950
|
-
addPhase(name, options) {
|
|
1951
|
-
this.phaseGraph.addPhase(name, options);
|
|
1952
|
-
for (const root of this.roots.values()) {
|
|
1953
|
-
root.needsRebuild = true;
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
/**
|
|
1957
|
-
* Check if a phase exists in the scheduler.
|
|
1958
|
-
* @param {string} name - The phase name to check
|
|
1959
|
-
* @returns {boolean} True if the phase exists
|
|
1960
|
-
*/
|
|
1961
|
-
hasPhase(name) {
|
|
1962
|
-
return this.phaseGraph.hasPhase(name);
|
|
1963
|
-
}
|
|
1964
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1965
|
-
/**
|
|
1966
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1967
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1968
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1969
|
-
* @param {string} id - Unique identifier for this global job
|
|
1970
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1971
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1972
|
-
* @deprecated Use useFrame with phases instead
|
|
1973
|
-
*/
|
|
1974
|
-
registerGlobal(phase, id, callback) {
|
|
1975
|
-
const job = { id, callback };
|
|
1976
|
-
if (phase === "before") {
|
|
1977
|
-
this.globalBeforeJobs.set(id, job);
|
|
1978
|
-
} else {
|
|
1979
|
-
this.globalAfterJobs.set(id, job);
|
|
1980
|
-
}
|
|
1981
|
-
return () => {
|
|
1982
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
1983
|
-
else this.globalAfterJobs.delete(id);
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
1987
|
-
/**
|
|
1988
|
-
* Register an idle callback that fires when the loop stops.
|
|
1989
|
-
* Used internally by deprecated addTail API.
|
|
1990
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
1991
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
1992
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
1993
|
-
*/
|
|
1994
|
-
onIdle(callback) {
|
|
1995
|
-
this.idleCallbacks.add(callback);
|
|
1996
|
-
return () => this.idleCallbacks.delete(callback);
|
|
1997
|
-
}
|
|
1998
|
-
/**
|
|
1999
|
-
* Notify all registered idle callbacks.
|
|
2000
|
-
* Called when the loop stops in demand mode.
|
|
2001
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2002
|
-
* @returns {void}
|
|
2003
|
-
* @private
|
|
2004
|
-
*/
|
|
2005
|
-
notifyIdle(timestamp) {
|
|
2006
|
-
for (const cb of this.idleCallbacks) {
|
|
2007
|
-
try {
|
|
2008
|
-
cb(timestamp);
|
|
2009
|
-
} catch (error) {
|
|
2010
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
//* Job Registration & Management Methods ================================
|
|
2015
|
-
/**
|
|
2016
|
-
* Register a job (frame callback) with a specific root.
|
|
2017
|
-
* This is the core registration method used by useFrame internally.
|
|
2018
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2019
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2020
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2021
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2022
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2023
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2024
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2025
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2026
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2027
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2028
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2029
|
-
*/
|
|
2030
|
-
register(callback, options = {}) {
|
|
2031
|
-
const rootId = options.rootId;
|
|
2032
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2033
|
-
if (!root) {
|
|
2034
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2035
|
-
return () => {
|
|
2036
|
-
};
|
|
2037
|
-
}
|
|
2038
|
-
const id = options.id ?? this.generateJobId();
|
|
2039
|
-
let phase = options.phase ?? "update";
|
|
2040
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2041
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2042
|
-
}
|
|
2043
|
-
const before = this.normalizeConstraints(options.before);
|
|
2044
|
-
const after = this.normalizeConstraints(options.after);
|
|
2045
|
-
const job = {
|
|
2046
|
-
id,
|
|
2047
|
-
callback,
|
|
2048
|
-
phase,
|
|
2049
|
-
before,
|
|
2050
|
-
after,
|
|
2051
|
-
priority: options.priority ?? 0,
|
|
2052
|
-
index: this.nextJobIndex++,
|
|
2053
|
-
fps: options.fps,
|
|
2054
|
-
drop: options.drop ?? true,
|
|
2055
|
-
enabled: options.enabled ?? true,
|
|
2056
|
-
system: options.system ?? false
|
|
2057
|
-
};
|
|
2058
|
-
if (root.jobs.has(id)) {
|
|
2059
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2060
|
-
}
|
|
2061
|
-
root.jobs.set(id, job);
|
|
2062
|
-
root.needsRebuild = true;
|
|
2063
|
-
return () => this.unregister(id, root.id);
|
|
2064
|
-
}
|
|
2065
|
-
/**
|
|
2066
|
-
* Unregister a job by its ID.
|
|
2067
|
-
* Searches all roots if rootId is not provided.
|
|
2068
|
-
* @param {string} id - The job ID to unregister
|
|
2069
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2070
|
-
* @returns {void}
|
|
2071
|
-
*/
|
|
2072
|
-
unregister(id, rootId) {
|
|
2073
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2074
|
-
if (root?.jobs.delete(id)) {
|
|
2075
|
-
root.needsRebuild = true;
|
|
2076
|
-
this.jobStateListeners.delete(id);
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* Update a job's options dynamically.
|
|
2081
|
-
* Searches all roots to find the job by ID.
|
|
2082
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2083
|
-
* @param {string} id - The job ID to update
|
|
2084
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2085
|
-
* @returns {void}
|
|
2086
|
-
*/
|
|
2087
|
-
updateJob(id, options) {
|
|
2088
|
-
let job;
|
|
2089
|
-
let root;
|
|
2090
|
-
for (const r of this.roots.values()) {
|
|
2091
|
-
job = r.jobs.get(id);
|
|
2092
|
-
if (job) {
|
|
2093
|
-
root = r;
|
|
2094
|
-
break;
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
if (!job || !root) return;
|
|
2098
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2099
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2100
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2101
|
-
if (options.enabled !== void 0) {
|
|
2102
|
-
const wasEnabled = job.enabled;
|
|
2103
|
-
job.enabled = options.enabled;
|
|
2104
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2105
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2106
|
-
}
|
|
2107
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2108
|
-
if (options.phase) job.phase = options.phase;
|
|
2109
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2110
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2111
|
-
root.needsRebuild = true;
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
//* Job State Management Methods ================================
|
|
2115
|
-
/**
|
|
2116
|
-
* Check if a job is currently paused (disabled).
|
|
2117
|
-
* @param {string} id - The job ID to check
|
|
2118
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2119
|
-
*/
|
|
2120
|
-
isJobPaused(id) {
|
|
2121
|
-
for (const root of this.roots.values()) {
|
|
2122
|
-
const job = root.jobs.get(id);
|
|
2123
|
-
if (job) return !job.enabled;
|
|
2124
|
-
}
|
|
2125
|
-
return false;
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
* Subscribe to state changes for a specific job.
|
|
2129
|
-
* Listener is called when job is paused or resumed.
|
|
2130
|
-
* @param {string} id - The job ID to subscribe to
|
|
2131
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2132
|
-
* @returns {() => void} Unsubscribe function
|
|
2133
|
-
*/
|
|
2134
|
-
subscribeJobState(id, listener) {
|
|
2135
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2136
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2137
|
-
}
|
|
2138
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2139
|
-
return () => {
|
|
2140
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2141
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2142
|
-
this.jobStateListeners.delete(id);
|
|
2143
|
-
}
|
|
2144
|
-
};
|
|
2145
|
-
}
|
|
2146
|
-
/**
|
|
2147
|
-
* Notify all listeners that a job's state has changed.
|
|
2148
|
-
* @param {string} id - The job ID that changed
|
|
2149
|
-
* @returns {void}
|
|
2150
|
-
* @private
|
|
2151
|
-
*/
|
|
2152
|
-
notifyJobStateChange(id) {
|
|
2153
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Pause a job by ID (sets enabled=false).
|
|
2157
|
-
* Notifies any subscribed state listeners.
|
|
2158
|
-
* @param {string} id - The job ID to pause
|
|
2159
|
-
* @returns {void}
|
|
2160
|
-
*/
|
|
2161
|
-
pauseJob(id) {
|
|
2162
|
-
this.updateJob(id, { enabled: false });
|
|
2163
|
-
this.notifyJobStateChange(id);
|
|
2164
|
-
}
|
|
2165
|
-
/**
|
|
2166
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2167
|
-
* Resets job timing to prevent frame accumulation.
|
|
2168
|
-
* Notifies any subscribed state listeners.
|
|
2169
|
-
* @param {string} id - The job ID to resume
|
|
2170
|
-
* @returns {void}
|
|
2171
|
-
*/
|
|
2172
|
-
resumeJob(id) {
|
|
2173
|
-
this.updateJob(id, { enabled: true });
|
|
2174
|
-
this.notifyJobStateChange(id);
|
|
2175
|
-
}
|
|
2176
|
-
//* Frame Loop Control Methods ================================
|
|
2177
|
-
/**
|
|
2178
|
-
* Start the requestAnimationFrame loop.
|
|
2179
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2180
|
-
* No-op if already running.
|
|
2181
|
-
* @returns {void}
|
|
2182
|
-
*/
|
|
2183
|
-
start() {
|
|
2184
|
-
if (this.loopState.running) return;
|
|
2185
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2186
|
-
let adjustedCreated = 0;
|
|
2187
|
-
if (this.stoppedTime > 0) {
|
|
2188
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2189
|
-
this.stoppedTime = 0;
|
|
2190
|
-
}
|
|
2191
|
-
Object.assign(this.loopState, {
|
|
2192
|
-
running: true,
|
|
2193
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2194
|
-
lastTime: performance.now(),
|
|
2195
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2196
|
-
frameCount: 0,
|
|
2197
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2198
|
-
});
|
|
2199
|
-
}
|
|
2200
|
-
/**
|
|
2201
|
-
* Stop the requestAnimationFrame loop.
|
|
2202
|
-
* Cancels any pending RAF callback.
|
|
2203
|
-
* No-op if not running.
|
|
2204
|
-
* @returns {void}
|
|
2205
|
-
*/
|
|
2206
|
-
stop() {
|
|
2207
|
-
if (!this.loopState.running) return;
|
|
2208
|
-
this.loopState.running = false;
|
|
2209
|
-
if (this.loopState.rafHandle !== null) {
|
|
2210
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2211
|
-
this.loopState.rafHandle = null;
|
|
2212
|
-
}
|
|
2213
|
-
this.stoppedTime = performance.now();
|
|
2214
|
-
}
|
|
2215
|
-
/**
|
|
2216
|
-
* Request frames to be rendered in demand mode.
|
|
2217
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2218
|
-
* No-op if frameloop is not 'demand'.
|
|
2219
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2220
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2221
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2222
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2223
|
-
* @returns {void}
|
|
2224
|
-
* @example
|
|
2225
|
-
* // Request a single frame render
|
|
2226
|
-
* scheduler.invalidate();
|
|
2227
|
-
*
|
|
2228
|
-
* @example
|
|
2229
|
-
* // Request 5 frames (e.g., for animations)
|
|
2230
|
-
* scheduler.invalidate(5);
|
|
2231
|
-
*
|
|
2232
|
-
* @example
|
|
2233
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2234
|
-
* scheduler.invalidate(3, false);
|
|
2235
|
-
*
|
|
2236
|
-
* @example
|
|
2237
|
-
* // Add 2 more frames to existing pending count
|
|
2238
|
-
* scheduler.invalidate(2, true);
|
|
2239
|
-
*/
|
|
2240
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2241
|
-
if (this._frameloop !== "demand") return;
|
|
2242
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2243
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2244
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2245
|
-
}
|
|
2246
|
-
/**
|
|
2247
|
-
* Reset timing state for deterministic testing.
|
|
2248
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2249
|
-
* @returns {void}
|
|
2250
|
-
*/
|
|
2251
|
-
resetTiming() {
|
|
2252
|
-
this.loopState.lastTime = null;
|
|
2253
|
-
this.loopState.frameCount = 0;
|
|
2254
|
-
this.loopState.elapsedTime = 0;
|
|
2255
|
-
this.loopState.createdAt = performance.now();
|
|
2256
|
-
}
|
|
2257
|
-
//* Manual Stepping Methods ================================
|
|
2258
|
-
/**
|
|
2259
|
-
* Manually execute a single frame for all roots.
|
|
2260
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2261
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2262
|
-
* @returns {void}
|
|
2263
|
-
* @example
|
|
2264
|
-
* // Manual control mode
|
|
2265
|
-
* scheduler.frameloop = 'never';
|
|
2266
|
-
* scheduler.step(); // Execute one frame
|
|
2267
|
-
*/
|
|
2268
|
-
step(timestamp) {
|
|
2269
|
-
const now = timestamp ?? performance.now();
|
|
2270
|
-
this.executeFrame(now);
|
|
2271
|
-
}
|
|
2272
|
-
/**
|
|
2273
|
-
* Manually execute a single job by its ID.
|
|
2274
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2275
|
-
* @param {string} id - The job ID to step
|
|
2276
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2277
|
-
* @returns {void}
|
|
2278
|
-
*/
|
|
2279
|
-
stepJob(id, timestamp) {
|
|
2280
|
-
let job;
|
|
2281
|
-
let root;
|
|
2282
|
-
for (const r of this.roots.values()) {
|
|
2283
|
-
job = r.jobs.get(id);
|
|
2284
|
-
if (job) {
|
|
2285
|
-
root = r;
|
|
2286
|
-
break;
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
if (!job || !root) {
|
|
2290
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2291
|
-
return;
|
|
2292
|
-
}
|
|
2293
|
-
const now = timestamp ?? performance.now();
|
|
2294
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2295
|
-
const delta = deltaMs / 1e3;
|
|
2296
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2297
|
-
const providedState = root.getState?.() ?? {};
|
|
2298
|
-
const frameState = {
|
|
2299
|
-
...providedState,
|
|
2300
|
-
time: now,
|
|
2301
|
-
delta,
|
|
2302
|
-
elapsed,
|
|
2303
|
-
frame: this.loopState.frameCount
|
|
2304
|
-
};
|
|
2305
|
-
try {
|
|
2306
|
-
job.callback(frameState, delta);
|
|
2307
|
-
} catch (error) {
|
|
2308
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2309
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Execute a single frame across all roots.
|
|
2314
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2315
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2316
|
-
* @returns {void}
|
|
2317
|
-
* @private
|
|
2318
|
-
*/
|
|
2319
|
-
executeFrame(timestamp) {
|
|
2320
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2321
|
-
const delta = deltaMs / 1e3;
|
|
2322
|
-
this.loopState.lastTime = timestamp;
|
|
2323
|
-
this.loopState.frameCount++;
|
|
2324
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2325
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2326
|
-
for (const root of this.roots.values()) {
|
|
2327
|
-
this.tickRoot(root, timestamp, delta);
|
|
2328
|
-
}
|
|
2329
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2330
|
-
}
|
|
2331
|
-
/**
|
|
2332
|
-
* Run all global jobs from a job map.
|
|
2333
|
-
* Catches and logs errors without stopping execution.
|
|
2334
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2335
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2336
|
-
* @returns {void}
|
|
2337
|
-
* @private
|
|
2338
|
-
*/
|
|
2339
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2340
|
-
for (const job of jobs.values()) {
|
|
2341
|
-
try {
|
|
2342
|
-
job.callback(timestamp);
|
|
2343
|
-
} catch (error) {
|
|
2344
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
/**
|
|
2349
|
-
* Execute all jobs for a single root in sorted order.
|
|
2350
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2351
|
-
* Errors are caught and propagated via triggerError.
|
|
2352
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2353
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2354
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2355
|
-
* @returns {void}
|
|
2356
|
-
* @private
|
|
2357
|
-
*/
|
|
2358
|
-
tickRoot(root, timestamp, delta) {
|
|
2359
|
-
if (root.needsRebuild) {
|
|
2360
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2361
|
-
root.needsRebuild = false;
|
|
2362
|
-
}
|
|
2363
|
-
const providedState = root.getState?.() ?? {};
|
|
2364
|
-
const frameState = {
|
|
2365
|
-
...providedState,
|
|
2366
|
-
time: timestamp,
|
|
2367
|
-
delta,
|
|
2368
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2369
|
-
// Convert ms to seconds
|
|
2370
|
-
frame: this.loopState.frameCount
|
|
2371
|
-
};
|
|
2372
|
-
for (const job of root.sortedJobs) {
|
|
2373
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2374
|
-
try {
|
|
2375
|
-
job.callback(frameState, delta);
|
|
2376
|
-
} catch (error) {
|
|
2377
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2378
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
//* Debug & Inspection Methods ================================
|
|
2383
|
-
/**
|
|
2384
|
-
* Get the total number of registered jobs across all roots.
|
|
2385
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2386
|
-
* @returns {number} Total job count
|
|
2387
|
-
*/
|
|
2388
|
-
getJobCount() {
|
|
2389
|
-
let count = 0;
|
|
2390
|
-
for (const root of this.roots.values()) {
|
|
2391
|
-
count += root.jobs.size;
|
|
2392
|
-
}
|
|
2393
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2394
|
-
}
|
|
2395
|
-
/**
|
|
2396
|
-
* Get all registered job IDs across all roots.
|
|
2397
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2398
|
-
* @returns {string[]} Array of all job IDs
|
|
2399
|
-
*/
|
|
2400
|
-
getJobIds() {
|
|
2401
|
-
const ids = [];
|
|
2402
|
-
for (const root of this.roots.values()) {
|
|
2403
|
-
ids.push(...root.jobs.keys());
|
|
2404
|
-
}
|
|
2405
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2406
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2407
|
-
return ids;
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* Get the number of registered roots (Canvas instances).
|
|
2411
|
-
* @returns {number} Number of registered roots
|
|
2412
|
-
*/
|
|
2413
|
-
getRootCount() {
|
|
2414
|
-
return this.roots.size;
|
|
2415
|
-
}
|
|
2416
|
-
/**
|
|
2417
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2418
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2419
|
-
*
|
|
2420
|
-
* @param phase The phase to check
|
|
2421
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2422
|
-
* @returns true if any user jobs exist in the phase
|
|
2423
|
-
*/
|
|
2424
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2425
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2426
|
-
return rootsToCheck.some((root) => {
|
|
2427
|
-
if (!root) return false;
|
|
2428
|
-
for (const job of root.jobs.values()) {
|
|
2429
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2430
|
-
}
|
|
2431
|
-
return false;
|
|
2432
|
-
});
|
|
2433
|
-
}
|
|
2434
|
-
//* Utility Methods ================================
|
|
2435
|
-
/**
|
|
2436
|
-
* Generate a unique root ID for automatic root registration.
|
|
2437
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2438
|
-
*/
|
|
2439
|
-
generateRootId() {
|
|
2440
|
-
return `root_${this.nextRootIndex++}`;
|
|
2441
|
-
}
|
|
2442
|
-
/**
|
|
2443
|
-
* Generate a unique job ID.
|
|
2444
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2445
|
-
* @private
|
|
2446
|
-
*/
|
|
2447
|
-
generateJobId() {
|
|
2448
|
-
return `job_${this.nextJobIndex}`;
|
|
2449
|
-
}
|
|
2450
|
-
/**
|
|
2451
|
-
* Normalize before/after constraints to a Set.
|
|
2452
|
-
* Handles undefined, single string, or array inputs.
|
|
2453
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2454
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2455
|
-
* @private
|
|
2456
|
-
*/
|
|
2457
|
-
normalizeConstraints(value) {
|
|
2458
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2459
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2460
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2461
|
-
}
|
|
2462
|
-
};
|
|
2463
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2464
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2465
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2466
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2467
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2468
|
-
let Scheduler = _Scheduler;
|
|
2469
|
-
const getScheduler = () => Scheduler.get();
|
|
2470
|
-
if (hmrData) {
|
|
2471
|
-
hmrData.accept?.();
|
|
1705
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1706
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1707
|
+
if (!stack) return false;
|
|
1708
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1709
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
2472
1710
|
}
|
|
2473
1711
|
|
|
2474
1712
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2508,7 +1746,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2508
1746
|
frustum: new Frustum(),
|
|
2509
1747
|
autoUpdateFrustum: true,
|
|
2510
1748
|
raycaster: null,
|
|
2511
|
-
events: {
|
|
1749
|
+
events: {
|
|
1750
|
+
priority: 1,
|
|
1751
|
+
enabled: true,
|
|
1752
|
+
connected: false,
|
|
1753
|
+
frameTimedRaycasts: true,
|
|
1754
|
+
alwaysFireOnScroll: true,
|
|
1755
|
+
updateOnFrame: false
|
|
1756
|
+
},
|
|
2512
1757
|
scene: null,
|
|
2513
1758
|
rootScene: null,
|
|
2514
1759
|
xr: null,
|
|
@@ -2596,14 +1841,18 @@ const createStore = (invalidate, advance) => {
|
|
|
2596
1841
|
}),
|
|
2597
1842
|
setFrameloop: (frameloop = "always") => {
|
|
2598
1843
|
set(() => ({ frameloop }));
|
|
1844
|
+
getScheduler().frameloop = frameloop;
|
|
2599
1845
|
},
|
|
2600
1846
|
setError: (error) => set(() => ({ error })),
|
|
2601
1847
|
error: null,
|
|
2602
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1848
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2603
1849
|
uniforms: {},
|
|
2604
1850
|
nodes: {},
|
|
1851
|
+
buffers: {},
|
|
1852
|
+
gpuStorage: {},
|
|
2605
1853
|
textures: /* @__PURE__ */ new Map(),
|
|
2606
|
-
|
|
1854
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1855
|
+
renderPipeline: null,
|
|
2607
1856
|
passes: {},
|
|
2608
1857
|
_hmrVersion: 0,
|
|
2609
1858
|
_sizeImperative: false,
|
|
@@ -2612,12 +1861,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2612
1861
|
internal: {
|
|
2613
1862
|
// Events
|
|
2614
1863
|
interaction: [],
|
|
2615
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2616
1864
|
subscribers: [],
|
|
1865
|
+
// Per-pointer state (new unified structure)
|
|
1866
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1867
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1868
|
+
lastEvent: React.createRef(),
|
|
1869
|
+
// Deprecated but kept for backwards compatibility
|
|
1870
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2617
1871
|
initialClick: [0, 0],
|
|
2618
1872
|
initialHits: [],
|
|
2619
1873
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2620
|
-
lastEvent: React.createRef(),
|
|
2621
1874
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2622
1875
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2623
1876
|
// Occlusion system (WebGPU only)
|
|
@@ -2656,8 +1909,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2656
1909
|
const currentState = rootStore.getState();
|
|
2657
1910
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2658
1911
|
const stack = new Error().stack || "";
|
|
2659
|
-
|
|
2660
|
-
if (!isInternalAccess) {
|
|
1912
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2661
1913
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2662
1914
|
notifyDepreciated({
|
|
2663
1915
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -2705,14 +1957,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2705
1957
|
oldSize = size;
|
|
2706
1958
|
oldDpr = viewport.dpr;
|
|
2707
1959
|
updateCamera(camera, size);
|
|
2708
|
-
if (canvasTarget) {
|
|
1960
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2709
1961
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2710
|
-
|
|
2711
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1962
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2712
1963
|
} else {
|
|
2713
1964
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2714
|
-
|
|
2715
|
-
|
|
1965
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1966
|
+
if (canvasTarget) {
|
|
1967
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1968
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1969
|
+
}
|
|
2716
1970
|
}
|
|
2717
1971
|
}
|
|
2718
1972
|
if (camera !== oldCamera) {
|
|
@@ -2768,19 +2022,25 @@ function loadingFn(extensions, onProgress) {
|
|
|
2768
2022
|
);
|
|
2769
2023
|
};
|
|
2770
2024
|
}
|
|
2771
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
2772
|
-
const
|
|
2025
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2026
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2027
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2773
2028
|
const fn = loadingFn(extensions, onProgress);
|
|
2774
|
-
const results =
|
|
2029
|
+
const results = cacheKeys.map(
|
|
2030
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2031
|
+
);
|
|
2775
2032
|
return Array.isArray(input) ? results : results[0];
|
|
2776
2033
|
}
|
|
2777
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
2778
|
-
const
|
|
2779
|
-
|
|
2034
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2035
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2036
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2037
|
+
cacheKeys.forEach(
|
|
2038
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2039
|
+
);
|
|
2780
2040
|
};
|
|
2781
|
-
useLoader.clear = function(loader, input) {
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2041
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2042
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2043
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
2784
2044
|
};
|
|
2785
2045
|
useLoader.loader = getLoader;
|
|
2786
2046
|
|
|
@@ -2856,20 +2116,14 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2856
2116
|
}
|
|
2857
2117
|
};
|
|
2858
2118
|
} else {
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
unregisterJob = registerOutside();
|
|
2868
|
-
});
|
|
2869
|
-
return () => {
|
|
2870
|
-
unsubReady();
|
|
2871
|
-
unregisterJob?.();
|
|
2872
|
-
};
|
|
2119
|
+
return scheduler.register(
|
|
2120
|
+
(state, delta) => {
|
|
2121
|
+
const frameState = state;
|
|
2122
|
+
if (!frameState.renderer) return;
|
|
2123
|
+
callbackRef.current?.(frameState, delta);
|
|
2124
|
+
},
|
|
2125
|
+
{ id, ...options }
|
|
2126
|
+
);
|
|
2873
2127
|
}
|
|
2874
2128
|
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2875
2129
|
const isPaused = React.useSyncExternalStore(
|
|
@@ -2960,18 +2214,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2960
2214
|
function useTexture(input, optionsOrOnLoad) {
|
|
2961
2215
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2962
2216
|
const store = useStore();
|
|
2963
|
-
const textureCache = useThree((state) => state.textures);
|
|
2964
2217
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2965
|
-
const { onLoad, cache =
|
|
2218
|
+
const { onLoad, cache = true } = options;
|
|
2966
2219
|
const onLoadRef = useRef(onLoad);
|
|
2967
2220
|
onLoadRef.current = onLoad;
|
|
2968
2221
|
const onLoadCalledForRef = useRef(null);
|
|
2969
2222
|
const urls = useMemo(() => getUrls(input), [input]);
|
|
2970
2223
|
const cachedResult = useMemo(() => {
|
|
2971
2224
|
if (!cache) return null;
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2225
|
+
const textures = store.getState().textures;
|
|
2226
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2227
|
+
return buildFromCache(input, textures);
|
|
2228
|
+
}, [cache, urls, input, store]);
|
|
2975
2229
|
const loadedTextures = useLoader(
|
|
2976
2230
|
TextureLoader,
|
|
2977
2231
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3015,8 +2269,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3015
2269
|
}, [input, loadedTextures, cachedResult]);
|
|
3016
2270
|
useEffect(() => {
|
|
3017
2271
|
if (!cache) return;
|
|
3018
|
-
if (cachedResult) return;
|
|
3019
|
-
const set = store.setState;
|
|
3020
2272
|
const urlTextureMap = [];
|
|
3021
2273
|
if (typeof input === "string") {
|
|
3022
2274
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3030,18 +2282,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3030
2282
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3031
2283
|
}
|
|
3032
2284
|
}
|
|
3033
|
-
|
|
3034
|
-
const
|
|
3035
|
-
let
|
|
2285
|
+
store.setState((state) => {
|
|
2286
|
+
const refs = new Map(state._textureRefs);
|
|
2287
|
+
let textures = state.textures;
|
|
2288
|
+
let added = false;
|
|
3036
2289
|
for (const [url, texture] of urlTextureMap) {
|
|
3037
|
-
if (!
|
|
3038
|
-
|
|
3039
|
-
|
|
2290
|
+
if (!textures.has(url)) {
|
|
2291
|
+
if (!added) {
|
|
2292
|
+
textures = new Map(textures);
|
|
2293
|
+
added = true;
|
|
2294
|
+
}
|
|
2295
|
+
textures.set(url, texture);
|
|
3040
2296
|
}
|
|
2297
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3041
2298
|
}
|
|
3042
|
-
return
|
|
2299
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2300
|
+
});
|
|
2301
|
+
return () => store.setState((state) => {
|
|
2302
|
+
const refs = new Map(state._textureRefs);
|
|
2303
|
+
for (const [url] of urlTextureMap) {
|
|
2304
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2305
|
+
if (next <= 0) refs.delete(url);
|
|
2306
|
+
else refs.set(url, next);
|
|
2307
|
+
}
|
|
2308
|
+
return { _textureRefs: refs };
|
|
3043
2309
|
});
|
|
3044
|
-
}, [cache, input, mappedTextures, store
|
|
2310
|
+
}, [cache, input, mappedTextures, store]);
|
|
3045
2311
|
return mappedTextures;
|
|
3046
2312
|
}
|
|
3047
2313
|
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
@@ -3057,96 +2323,63 @@ const Texture = ({
|
|
|
3057
2323
|
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
3058
2324
|
};
|
|
3059
2325
|
|
|
3060
|
-
function
|
|
3061
|
-
if (entry instanceof Texture$1) return entry;
|
|
3062
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof Texture$1) {
|
|
3063
|
-
return entry.value;
|
|
3064
|
-
}
|
|
3065
|
-
return null;
|
|
3066
|
-
}
|
|
3067
|
-
function useTextures() {
|
|
2326
|
+
function useTextures(selector) {
|
|
3068
2327
|
const store = useStore();
|
|
3069
|
-
|
|
3070
|
-
const set = store.setState;
|
|
2328
|
+
const registry = useMemo(() => {
|
|
3071
2329
|
const getState = store.getState;
|
|
3072
|
-
const
|
|
3073
|
-
|
|
3074
|
-
const newMap = new Map(state.textures);
|
|
3075
|
-
newMap.set(key, value);
|
|
3076
|
-
return { textures: newMap };
|
|
3077
|
-
});
|
|
3078
|
-
};
|
|
3079
|
-
const addMultiple = (items) => {
|
|
3080
|
-
set((state) => {
|
|
3081
|
-
const newMap = new Map(state.textures);
|
|
3082
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3083
|
-
for (const [key, value] of entries) {
|
|
3084
|
-
newMap.set(key, value);
|
|
3085
|
-
}
|
|
3086
|
-
return { textures: newMap };
|
|
3087
|
-
});
|
|
3088
|
-
};
|
|
3089
|
-
const remove = (key) => {
|
|
3090
|
-
set((state) => {
|
|
3091
|
-
const newMap = new Map(state.textures);
|
|
3092
|
-
newMap.delete(key);
|
|
3093
|
-
return { textures: newMap };
|
|
3094
|
-
});
|
|
3095
|
-
};
|
|
3096
|
-
const removeMultiple = (keys) => {
|
|
3097
|
-
set((state) => {
|
|
3098
|
-
const newMap = new Map(state.textures);
|
|
3099
|
-
for (const key of keys) newMap.delete(key);
|
|
3100
|
-
return { textures: newMap };
|
|
3101
|
-
});
|
|
3102
|
-
};
|
|
3103
|
-
const dispose = (key) => {
|
|
3104
|
-
const entry = getState().textures.get(key);
|
|
3105
|
-
if (entry) {
|
|
3106
|
-
const tex = getTextureValue(entry);
|
|
3107
|
-
tex?.dispose();
|
|
3108
|
-
}
|
|
3109
|
-
remove(key);
|
|
3110
|
-
};
|
|
3111
|
-
const disposeMultiple = (keys) => {
|
|
3112
|
-
const textures = getState().textures;
|
|
3113
|
-
for (const key of keys) {
|
|
3114
|
-
const entry = textures.get(key);
|
|
3115
|
-
if (entry) {
|
|
3116
|
-
const tex = getTextureValue(entry);
|
|
3117
|
-
tex?.dispose();
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
removeMultiple(keys);
|
|
3121
|
-
};
|
|
3122
|
-
const disposeAll = () => {
|
|
3123
|
-
const textures = getState().textures;
|
|
3124
|
-
for (const entry of textures.values()) {
|
|
3125
|
-
const tex = getTextureValue(entry);
|
|
3126
|
-
tex?.dispose();
|
|
3127
|
-
}
|
|
3128
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3129
|
-
};
|
|
2330
|
+
const setState = store.setState;
|
|
2331
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3130
2332
|
return {
|
|
3131
|
-
|
|
3132
|
-
get textures() {
|
|
2333
|
+
get all() {
|
|
3133
2334
|
return getState().textures;
|
|
3134
2335
|
},
|
|
3135
|
-
|
|
3136
|
-
|
|
2336
|
+
get(input) {
|
|
2337
|
+
if (typeof input === "string") return getOne(input);
|
|
2338
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2339
|
+
const out = {};
|
|
2340
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2341
|
+
return out;
|
|
2342
|
+
},
|
|
3137
2343
|
has: (key) => getState().textures.has(key),
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
2344
|
+
add(keyOrRecord, texture) {
|
|
2345
|
+
setState((state) => {
|
|
2346
|
+
const textures = new Map(state.textures);
|
|
2347
|
+
if (typeof keyOrRecord === "string") {
|
|
2348
|
+
textures.set(keyOrRecord, texture);
|
|
2349
|
+
} else {
|
|
2350
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2351
|
+
}
|
|
2352
|
+
return { textures };
|
|
2353
|
+
});
|
|
2354
|
+
},
|
|
2355
|
+
dispose(key, options) {
|
|
2356
|
+
const state = getState();
|
|
2357
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2358
|
+
if (refs > 0 && !options?.force) {
|
|
2359
|
+
console.warn(
|
|
2360
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2361
|
+
);
|
|
2362
|
+
return false;
|
|
2363
|
+
}
|
|
2364
|
+
state.textures.get(key)?.dispose();
|
|
2365
|
+
setState((s) => {
|
|
2366
|
+
const textures = new Map(s.textures);
|
|
2367
|
+
textures.delete(key);
|
|
2368
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2369
|
+
nextRefs.delete(key);
|
|
2370
|
+
return { textures, _textureRefs: nextRefs };
|
|
2371
|
+
});
|
|
2372
|
+
return true;
|
|
2373
|
+
},
|
|
2374
|
+
disposeAll() {
|
|
2375
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2376
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2377
|
+
}
|
|
3148
2378
|
};
|
|
3149
2379
|
}, [store]);
|
|
2380
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2381
|
+
const selected = useThree(subscribe);
|
|
2382
|
+
return selector ? selected : registry;
|
|
3150
2383
|
}
|
|
3151
2384
|
|
|
3152
2385
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3227,7 +2460,7 @@ function advance(timestamp) {
|
|
|
3227
2460
|
getScheduler().step(timestamp);
|
|
3228
2461
|
}
|
|
3229
2462
|
|
|
3230
|
-
const version = "10.0.0-alpha.
|
|
2463
|
+
const version = "10.0.0-alpha.3";
|
|
3231
2464
|
const packageData = {
|
|
3232
2465
|
version: version};
|
|
3233
2466
|
|
|
@@ -14483,7 +13716,7 @@ function n0() {
|
|
|
14483
13716
|
var t0 = n0();
|
|
14484
13717
|
const r0 = Xb(t0);
|
|
14485
13718
|
|
|
14486
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13719
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
14487
13720
|
|
|
14488
13721
|
function createReconciler(config) {
|
|
14489
13722
|
const reconciler2 = r0(config);
|
|
@@ -14648,7 +13881,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
14648
13881
|
}
|
|
14649
13882
|
}
|
|
14650
13883
|
const reconstructed = [];
|
|
14651
|
-
function
|
|
13884
|
+
function flushReconstructedInstances() {
|
|
13885
|
+
if (reconstructed.length === 0) return;
|
|
13886
|
+
try {
|
|
13887
|
+
swapReconstructedInstances();
|
|
13888
|
+
} finally {
|
|
13889
|
+
reconstructed.length = 0;
|
|
13890
|
+
}
|
|
13891
|
+
}
|
|
13892
|
+
function swapReconstructedInstances() {
|
|
14652
13893
|
for (const [instance] of reconstructed) {
|
|
14653
13894
|
const parent = instance.parent;
|
|
14654
13895
|
if (parent) {
|
|
@@ -14666,6 +13907,9 @@ function swapInstances() {
|
|
|
14666
13907
|
}
|
|
14667
13908
|
}
|
|
14668
13909
|
if (instance.isHidden) unhideInstance(instance);
|
|
13910
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13911
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13912
|
+
}
|
|
14669
13913
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14670
13914
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14671
13915
|
}
|
|
@@ -14674,10 +13918,16 @@ function swapInstances() {
|
|
|
14674
13918
|
const parent = instance.parent;
|
|
14675
13919
|
if (parent) {
|
|
14676
13920
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13921
|
+
const prevObject = instance.object;
|
|
14677
13922
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
14678
13923
|
instance.object.__r3f = instance;
|
|
14679
13924
|
setFiberRef(fiber, instance.object);
|
|
13925
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13926
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13927
|
+
}
|
|
14680
13928
|
delete instance.appliedOnce;
|
|
13929
|
+
instance.eventCount = 0;
|
|
13930
|
+
instance.handlers = {};
|
|
14681
13931
|
applyProps(instance.object, instance.props);
|
|
14682
13932
|
if (instance.props.attach) {
|
|
14683
13933
|
attach(parent, instance);
|
|
@@ -14694,14 +13944,114 @@ function swapInstances() {
|
|
|
14694
13944
|
invalidateInstance(instance);
|
|
14695
13945
|
}
|
|
14696
13946
|
}
|
|
14697
|
-
reconstructed.length = 0;
|
|
14698
13947
|
}
|
|
14699
13948
|
const handleTextInstance = () => {
|
|
14700
13949
|
};
|
|
14701
13950
|
const NO_CONTEXT = {};
|
|
14702
13951
|
let currentUpdatePriority = NoEventPriority;
|
|
14703
|
-
|
|
14704
|
-
|
|
13952
|
+
function getEventPriority(type) {
|
|
13953
|
+
switch (type) {
|
|
13954
|
+
case "beforetoggle":
|
|
13955
|
+
case "cancel":
|
|
13956
|
+
case "click":
|
|
13957
|
+
case "close":
|
|
13958
|
+
case "contextmenu":
|
|
13959
|
+
case "copy":
|
|
13960
|
+
case "cut":
|
|
13961
|
+
case "auxclick":
|
|
13962
|
+
case "dblclick":
|
|
13963
|
+
case "dragend":
|
|
13964
|
+
case "dragstart":
|
|
13965
|
+
case "drop":
|
|
13966
|
+
case "focusin":
|
|
13967
|
+
case "focusout":
|
|
13968
|
+
case "input":
|
|
13969
|
+
case "invalid":
|
|
13970
|
+
case "keydown":
|
|
13971
|
+
case "keypress":
|
|
13972
|
+
case "keyup":
|
|
13973
|
+
case "mousedown":
|
|
13974
|
+
case "mouseup":
|
|
13975
|
+
case "paste":
|
|
13976
|
+
case "pause":
|
|
13977
|
+
case "play":
|
|
13978
|
+
case "pointercancel":
|
|
13979
|
+
case "pointerdown":
|
|
13980
|
+
case "pointerup":
|
|
13981
|
+
case "ratechange":
|
|
13982
|
+
case "reset":
|
|
13983
|
+
case "resize":
|
|
13984
|
+
case "seeked":
|
|
13985
|
+
case "submit":
|
|
13986
|
+
case "touchcancel":
|
|
13987
|
+
case "touchend":
|
|
13988
|
+
case "touchstart":
|
|
13989
|
+
case "volumechange":
|
|
13990
|
+
case "change":
|
|
13991
|
+
case "selectionchange":
|
|
13992
|
+
case "compositionstart":
|
|
13993
|
+
case "compositionend":
|
|
13994
|
+
case "compositionupdate":
|
|
13995
|
+
case "beforeinput":
|
|
13996
|
+
case "blur":
|
|
13997
|
+
case "fullscreenchange":
|
|
13998
|
+
case "focus":
|
|
13999
|
+
case "hashchange":
|
|
14000
|
+
case "popstate":
|
|
14001
|
+
case "select":
|
|
14002
|
+
case "selectstart":
|
|
14003
|
+
return e;
|
|
14004
|
+
case "drag":
|
|
14005
|
+
case "dragenter":
|
|
14006
|
+
case "dragexit":
|
|
14007
|
+
case "dragleave":
|
|
14008
|
+
case "dragover":
|
|
14009
|
+
case "mousemove":
|
|
14010
|
+
case "mouseout":
|
|
14011
|
+
case "mouseover":
|
|
14012
|
+
case "pointermove":
|
|
14013
|
+
case "pointerout":
|
|
14014
|
+
case "pointerover":
|
|
14015
|
+
case "scroll":
|
|
14016
|
+
case "touchmove":
|
|
14017
|
+
case "wheel":
|
|
14018
|
+
case "mouseenter":
|
|
14019
|
+
case "mouseleave":
|
|
14020
|
+
case "pointerenter":
|
|
14021
|
+
case "pointerleave":
|
|
14022
|
+
return o;
|
|
14023
|
+
case "message": {
|
|
14024
|
+
switch (unstable_getCurrentPriorityLevel()) {
|
|
14025
|
+
case unstable_ImmediatePriority:
|
|
14026
|
+
return e;
|
|
14027
|
+
case unstable_UserBlockingPriority:
|
|
14028
|
+
return o;
|
|
14029
|
+
case unstable_NormalPriority:
|
|
14030
|
+
case unstable_LowPriority:
|
|
14031
|
+
return r;
|
|
14032
|
+
case unstable_IdlePriority:
|
|
14033
|
+
return i$1;
|
|
14034
|
+
default:
|
|
14035
|
+
return r;
|
|
14036
|
+
}
|
|
14037
|
+
}
|
|
14038
|
+
default:
|
|
14039
|
+
return r;
|
|
14040
|
+
}
|
|
14041
|
+
}
|
|
14042
|
+
function scheduleMicrotask(callback) {
|
|
14043
|
+
if (typeof queueMicrotask === "function") {
|
|
14044
|
+
queueMicrotask(callback);
|
|
14045
|
+
} else if (typeof Promise !== "undefined") {
|
|
14046
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
14047
|
+
setTimeout(() => {
|
|
14048
|
+
throw error;
|
|
14049
|
+
});
|
|
14050
|
+
});
|
|
14051
|
+
} else {
|
|
14052
|
+
setTimeout(callback);
|
|
14053
|
+
}
|
|
14054
|
+
}
|
|
14705
14055
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
14706
14056
|
isPrimaryRenderer: false,
|
|
14707
14057
|
warnsIfNotActing: false,
|
|
@@ -14740,16 +14090,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14740
14090
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
14741
14091
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
14742
14092
|
if (reconstruct) {
|
|
14743
|
-
reconstructed.push([instance,
|
|
14093
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
14744
14094
|
} else {
|
|
14745
14095
|
const changedProps = diffProps(instance, newProps);
|
|
14746
|
-
|
|
14747
|
-
|
|
14748
|
-
|
|
14749
|
-
|
|
14096
|
+
const attach2 = instance.props.attach;
|
|
14097
|
+
instance.props = getInstanceProps(newProps);
|
|
14098
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
14099
|
+
else delete instance.props.attach;
|
|
14100
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
14750
14101
|
}
|
|
14751
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14752
|
-
if (isTailSibling) swapInstances();
|
|
14753
14102
|
},
|
|
14754
14103
|
finalizeInitialChildren: (instance) => {
|
|
14755
14104
|
for (const prop in instance.props) {
|
|
@@ -14774,8 +14123,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14774
14123
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
14775
14124
|
return prepare(target, container, "", {});
|
|
14776
14125
|
},
|
|
14777
|
-
|
|
14778
|
-
|
|
14126
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
14127
|
+
// before layout effects run so refs point to the new objects
|
|
14128
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
14779
14129
|
shouldSetTextContent: () => false,
|
|
14780
14130
|
clearContainer: () => false,
|
|
14781
14131
|
hideInstance,
|
|
@@ -14783,6 +14133,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14783
14133
|
createTextInstance: handleTextInstance,
|
|
14784
14134
|
hideTextInstance: handleTextInstance,
|
|
14785
14135
|
unhideTextInstance: handleTextInstance,
|
|
14136
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
14137
|
+
supportsMicrotasks: true,
|
|
14138
|
+
scheduleMicrotask,
|
|
14786
14139
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
14787
14140
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
14788
14141
|
noTimeout: -1,
|
|
@@ -14823,28 +14176,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14823
14176
|
},
|
|
14824
14177
|
resolveUpdatePriority() {
|
|
14825
14178
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14826
|
-
|
|
14827
|
-
|
|
14828
|
-
|
|
14829
|
-
case "dblclick":
|
|
14830
|
-
case "dragenter":
|
|
14831
|
-
case "dragleave":
|
|
14832
|
-
case "drop":
|
|
14833
|
-
case "pointercancel":
|
|
14834
|
-
case "pointerdown":
|
|
14835
|
-
case "pointerup":
|
|
14836
|
-
return e;
|
|
14837
|
-
case "dragover":
|
|
14838
|
-
case "pointermove":
|
|
14839
|
-
case "pointerout":
|
|
14840
|
-
case "pointerover":
|
|
14841
|
-
case "pointerenter":
|
|
14842
|
-
case "pointerleave":
|
|
14843
|
-
case "wheel":
|
|
14844
|
-
return o;
|
|
14845
|
-
default:
|
|
14846
|
-
return r;
|
|
14847
|
-
}
|
|
14179
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14180
|
+
if (eventType === void 0) return r;
|
|
14181
|
+
return getEventPriority(eventType);
|
|
14848
14182
|
},
|
|
14849
14183
|
resetFormInstance() {
|
|
14850
14184
|
},
|
|
@@ -14893,11 +14227,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14893
14227
|
cloneMutableTextInstance(textInstance) {
|
|
14894
14228
|
return textInstance;
|
|
14895
14229
|
},
|
|
14230
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14231
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14232
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14233
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14234
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14235
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
14896
14236
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14897
|
-
throw new Error("Not implemented.");
|
|
14898
14237
|
},
|
|
14899
14238
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14900
|
-
throw new Error("Not implemented.");
|
|
14901
14239
|
},
|
|
14902
14240
|
// https://github.com/facebook/react/pull/32465
|
|
14903
14241
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14982,6 +14320,7 @@ function createRoot(canvas) {
|
|
|
14982
14320
|
const lastConfiguredProps = {};
|
|
14983
14321
|
let configured = false;
|
|
14984
14322
|
let pending = null;
|
|
14323
|
+
let rendererSetup = null;
|
|
14985
14324
|
return {
|
|
14986
14325
|
async configure(props = {}) {
|
|
14987
14326
|
let resolve;
|
|
@@ -14997,7 +14336,6 @@ function createRoot(canvas) {
|
|
|
14997
14336
|
events,
|
|
14998
14337
|
onCreated: onCreatedCallback,
|
|
14999
14338
|
shadows = false,
|
|
15000
|
-
textureColorSpace = SRGBColorSpace,
|
|
15001
14339
|
orthographic = false,
|
|
15002
14340
|
frameloop = "always",
|
|
15003
14341
|
dpr = [1, 2],
|
|
@@ -15012,7 +14350,8 @@ function createRoot(canvas) {
|
|
|
15012
14350
|
_sizeProps,
|
|
15013
14351
|
forceEven
|
|
15014
14352
|
} = props;
|
|
15015
|
-
const
|
|
14353
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
14354
|
+
let state = store.getState();
|
|
15016
14355
|
const defaultGLProps = {
|
|
15017
14356
|
canvas,
|
|
15018
14357
|
powerPreference: "high-performance",
|
|
@@ -15040,9 +14379,21 @@ function createRoot(canvas) {
|
|
|
15040
14379
|
);
|
|
15041
14380
|
}
|
|
15042
14381
|
if (!state.internal.actualRenderer) {
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
14382
|
+
if (!rendererSetup) {
|
|
14383
|
+
rendererSetup = (async () => {
|
|
14384
|
+
{
|
|
14385
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, WebGLRenderer);
|
|
14386
|
+
state.internal.actualRenderer = renderer;
|
|
14387
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14388
|
+
}
|
|
14389
|
+
})().catch((err) => {
|
|
14390
|
+
rendererSetup = null;
|
|
14391
|
+
throw err;
|
|
14392
|
+
});
|
|
14393
|
+
}
|
|
14394
|
+
await rendererSetup;
|
|
14395
|
+
state = store.getState();
|
|
14396
|
+
renderer = state.internal.actualRenderer;
|
|
15046
14397
|
}
|
|
15047
14398
|
let raycaster = state.raycaster;
|
|
15048
14399
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
@@ -15135,7 +14486,7 @@ function createRoot(canvas) {
|
|
|
15135
14486
|
lastConfiguredProps.performance = performance;
|
|
15136
14487
|
}
|
|
15137
14488
|
if (!state.xr) {
|
|
15138
|
-
const handleXRFrame = (timestamp,
|
|
14489
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15139
14490
|
const state2 = store.getState();
|
|
15140
14491
|
if (state2.frameloop === "never") return;
|
|
15141
14492
|
advance(timestamp);
|
|
@@ -15171,15 +14522,22 @@ function createRoot(canvas) {
|
|
|
15171
14522
|
const oldType = renderer.shadowMap.type;
|
|
15172
14523
|
renderer.shadowMap.enabled = !!shadows;
|
|
15173
14524
|
if (is.boo(shadows)) {
|
|
15174
|
-
renderer.shadowMap.type =
|
|
14525
|
+
renderer.shadowMap.type = PCFShadowMap;
|
|
15175
14526
|
} else if (is.str(shadows)) {
|
|
14527
|
+
if (shadows === "soft") {
|
|
14528
|
+
notifyDepreciated({
|
|
14529
|
+
heading: 'shadows="soft" is deprecated',
|
|
14530
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14531
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14532
|
+
});
|
|
14533
|
+
}
|
|
15176
14534
|
const types = {
|
|
15177
14535
|
basic: BasicShadowMap,
|
|
15178
14536
|
percentage: PCFShadowMap,
|
|
15179
|
-
soft:
|
|
14537
|
+
soft: PCFShadowMap,
|
|
15180
14538
|
variance: VSMShadowMap
|
|
15181
14539
|
};
|
|
15182
|
-
renderer.shadowMap.type = types[shadows] ??
|
|
14540
|
+
renderer.shadowMap.type = types[shadows] ?? PCFShadowMap;
|
|
15183
14541
|
} else if (is.obj(shadows)) {
|
|
15184
14542
|
Object.assign(renderer.shadowMap, shadows);
|
|
15185
14543
|
}
|
|
@@ -15195,13 +14553,24 @@ function createRoot(canvas) {
|
|
|
15195
14553
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15196
14554
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15197
14555
|
}
|
|
14556
|
+
const r3fProps = ["textureColorSpace"];
|
|
14557
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14558
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15198
14559
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15199
|
-
|
|
14560
|
+
const glProps = {};
|
|
14561
|
+
for (const key in glConfig) {
|
|
14562
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14563
|
+
}
|
|
14564
|
+
applyProps(renderer, glProps);
|
|
15200
14565
|
}
|
|
15201
14566
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15202
14567
|
const currentRenderer = state.renderer;
|
|
15203
14568
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15204
|
-
|
|
14569
|
+
const rendererProps = {};
|
|
14570
|
+
for (const key in rendererConfig) {
|
|
14571
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14572
|
+
}
|
|
14573
|
+
applyProps(currentRenderer, rendererProps);
|
|
15205
14574
|
}
|
|
15206
14575
|
}
|
|
15207
14576
|
const scheduler = getScheduler();
|
|
@@ -15227,6 +14596,18 @@ function createRoot(canvas) {
|
|
|
15227
14596
|
system: true
|
|
15228
14597
|
}
|
|
15229
14598
|
);
|
|
14599
|
+
const unregisterEventsFlush = scheduler.register(
|
|
14600
|
+
() => {
|
|
14601
|
+
const state2 = store.getState();
|
|
14602
|
+
state2.events.flush?.();
|
|
14603
|
+
},
|
|
14604
|
+
{
|
|
14605
|
+
id: `${newRootId}_events`,
|
|
14606
|
+
rootId: newRootId,
|
|
14607
|
+
phase: "input",
|
|
14608
|
+
system: true
|
|
14609
|
+
}
|
|
14610
|
+
);
|
|
15230
14611
|
const unregisterFrustum = scheduler.register(
|
|
15231
14612
|
() => {
|
|
15232
14613
|
const state2 = store.getState();
|
|
@@ -15237,7 +14618,7 @@ function createRoot(canvas) {
|
|
|
15237
14618
|
{
|
|
15238
14619
|
id: `${newRootId}_frustum`,
|
|
15239
14620
|
rootId: newRootId,
|
|
15240
|
-
|
|
14621
|
+
before: "render",
|
|
15241
14622
|
system: true
|
|
15242
14623
|
}
|
|
15243
14624
|
);
|
|
@@ -15249,7 +14630,7 @@ function createRoot(canvas) {
|
|
|
15249
14630
|
{
|
|
15250
14631
|
id: `${newRootId}_visibility`,
|
|
15251
14632
|
rootId: newRootId,
|
|
15252
|
-
|
|
14633
|
+
before: "render",
|
|
15253
14634
|
system: true,
|
|
15254
14635
|
after: `${newRootId}_frustum`
|
|
15255
14636
|
}
|
|
@@ -15261,7 +14642,7 @@ function createRoot(canvas) {
|
|
|
15261
14642
|
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
15262
14643
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15263
14644
|
try {
|
|
15264
|
-
if (state2.
|
|
14645
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15265
14646
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15266
14647
|
} catch (error) {
|
|
15267
14648
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15286,6 +14667,7 @@ function createRoot(canvas) {
|
|
|
15286
14667
|
unregisterRoot: () => {
|
|
15287
14668
|
unregisterRoot();
|
|
15288
14669
|
unregisterCanvasTarget();
|
|
14670
|
+
unregisterEventsFlush();
|
|
15289
14671
|
unregisterFrustum();
|
|
15290
14672
|
unregisterVisibility();
|
|
15291
14673
|
unregisterRender();
|
|
@@ -15361,7 +14743,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
15361
14743
|
dispose(state.scene);
|
|
15362
14744
|
_roots.delete(canvas);
|
|
15363
14745
|
if (callback) callback(canvas);
|
|
15364
|
-
} catch {
|
|
14746
|
+
} catch (error) {
|
|
14747
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
15365
14748
|
}
|
|
15366
14749
|
}, 500);
|
|
15367
14750
|
}
|
|
@@ -15424,6 +14807,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15424
14807
|
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
15425
14808
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15426
14809
|
}
|
|
14810
|
+
const set = injectState.set;
|
|
15427
14811
|
return {
|
|
15428
14812
|
// The intersect consists of the previous root state
|
|
15429
14813
|
...rootState,
|
|
@@ -15442,7 +14826,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15442
14826
|
size: resolvedSize,
|
|
15443
14827
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15444
14828
|
// Layers are allowed to override events
|
|
15445
|
-
setEvents: (events2) =>
|
|
14829
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15446
14830
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15447
14831
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15448
14832
|
};
|
|
@@ -15451,9 +14835,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15451
14835
|
const store = createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15452
14836
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15453
14837
|
onMutate(previousRoot.getState());
|
|
15454
|
-
previousRoot.subscribe(onMutate);
|
|
15455
14838
|
return store;
|
|
15456
14839
|
}, [previousRoot, container]);
|
|
14840
|
+
useIsomorphicLayoutEffect(() => {
|
|
14841
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14842
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14843
|
+
return unsubscribe;
|
|
14844
|
+
}, [previousRoot, usePortalStore]);
|
|
15457
14845
|
return (
|
|
15458
14846
|
// @ts-ignore, reconciler types are not maintained
|
|
15459
14847
|
/* @__PURE__ */ jsx(Fragment, { children: reconciler.createPortal(
|
|
@@ -15467,6 +14855,81 @@ function flushSync(fn) {
|
|
|
15467
14855
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15468
14856
|
}
|
|
15469
14857
|
|
|
14858
|
+
function parseBackground(background) {
|
|
14859
|
+
if (!background) return null;
|
|
14860
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14861
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14862
|
+
return {
|
|
14863
|
+
...rest,
|
|
14864
|
+
preset,
|
|
14865
|
+
files: envMap || files,
|
|
14866
|
+
backgroundFiles: backgroundMap,
|
|
14867
|
+
background: true
|
|
14868
|
+
};
|
|
14869
|
+
}
|
|
14870
|
+
if (typeof background === "number") {
|
|
14871
|
+
return { color: background, background: true };
|
|
14872
|
+
}
|
|
14873
|
+
if (typeof background === "string") {
|
|
14874
|
+
if (background in presetsObj) {
|
|
14875
|
+
return { preset: background, background: true };
|
|
14876
|
+
}
|
|
14877
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14878
|
+
return { files: background, background: true };
|
|
14879
|
+
}
|
|
14880
|
+
return { color: background, background: true };
|
|
14881
|
+
}
|
|
14882
|
+
if (background.isColor) {
|
|
14883
|
+
return { color: background, background: true };
|
|
14884
|
+
}
|
|
14885
|
+
return null;
|
|
14886
|
+
}
|
|
14887
|
+
|
|
14888
|
+
function parseRendererConfig(rendererProp) {
|
|
14889
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14890
|
+
if (isRendererConfig) {
|
|
14891
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14892
|
+
return {
|
|
14893
|
+
primaryCanvas: pc,
|
|
14894
|
+
scheduler: sc,
|
|
14895
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14896
|
+
};
|
|
14897
|
+
}
|
|
14898
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14899
|
+
}
|
|
14900
|
+
|
|
14901
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14902
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14903
|
+
function getKindRegistry(store, kind) {
|
|
14904
|
+
let registry = registries.get(store);
|
|
14905
|
+
if (!registry) {
|
|
14906
|
+
registry = {
|
|
14907
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14908
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14909
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14910
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14911
|
+
};
|
|
14912
|
+
registries.set(store, registry);
|
|
14913
|
+
}
|
|
14914
|
+
return registry[kind];
|
|
14915
|
+
}
|
|
14916
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14917
|
+
const registry = getKindRegistry(store, kind);
|
|
14918
|
+
{
|
|
14919
|
+
registry.valid.clear();
|
|
14920
|
+
registry.staged.clear();
|
|
14921
|
+
}
|
|
14922
|
+
}
|
|
14923
|
+
function invalidateAllResources(store) {
|
|
14924
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14925
|
+
}
|
|
14926
|
+
|
|
14927
|
+
function clearHmrCaches(store) {
|
|
14928
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14929
|
+
invalidateAllResources(primary);
|
|
14930
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14931
|
+
}
|
|
14932
|
+
|
|
15470
14933
|
function CanvasImpl({
|
|
15471
14934
|
ref,
|
|
15472
14935
|
children,
|
|
@@ -15487,6 +14950,8 @@ function CanvasImpl({
|
|
|
15487
14950
|
raycaster,
|
|
15488
14951
|
camera,
|
|
15489
14952
|
scene,
|
|
14953
|
+
autoUpdateFrustum,
|
|
14954
|
+
occlusion,
|
|
15490
14955
|
onPointerMissed,
|
|
15491
14956
|
onDragOverMissed,
|
|
15492
14957
|
onDropMissed,
|
|
@@ -15498,39 +14963,10 @@ function CanvasImpl({
|
|
|
15498
14963
|
forceEven,
|
|
15499
14964
|
...props
|
|
15500
14965
|
}) {
|
|
15501
|
-
const { primaryCanvas, scheduler,
|
|
15502
|
-
const renderer = Object.keys(rendererConfig).length > 0 ? rendererConfig : rendererProp;
|
|
14966
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15503
14967
|
React.useMemo(() => extend(THREE), []);
|
|
15504
14968
|
const Bridge = useBridge();
|
|
15505
|
-
const backgroundProps = React.useMemo(() =>
|
|
15506
|
-
if (!background) return null;
|
|
15507
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15508
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15509
|
-
return {
|
|
15510
|
-
...rest,
|
|
15511
|
-
preset,
|
|
15512
|
-
files: envMap || files,
|
|
15513
|
-
backgroundFiles: backgroundMap,
|
|
15514
|
-
background: true
|
|
15515
|
-
};
|
|
15516
|
-
}
|
|
15517
|
-
if (typeof background === "number") {
|
|
15518
|
-
return { color: background, background: true };
|
|
15519
|
-
}
|
|
15520
|
-
if (typeof background === "string") {
|
|
15521
|
-
if (background in presetsObj) {
|
|
15522
|
-
return { preset: background, background: true };
|
|
15523
|
-
}
|
|
15524
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15525
|
-
return { files: background, background: true };
|
|
15526
|
-
}
|
|
15527
|
-
return { color: background, background: true };
|
|
15528
|
-
}
|
|
15529
|
-
if (background.isColor) {
|
|
15530
|
-
return { color: background, background: true };
|
|
15531
|
-
}
|
|
15532
|
-
return null;
|
|
15533
|
-
}, [background]);
|
|
14969
|
+
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15534
14970
|
const hasInitialSizeRef = React.useRef(false);
|
|
15535
14971
|
const measureConfig = React.useMemo(() => {
|
|
15536
14972
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15572,6 +15008,7 @@ function CanvasImpl({
|
|
|
15572
15008
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15573
15009
|
const [block, setBlock] = React.useState(false);
|
|
15574
15010
|
const [error, setError] = React.useState(false);
|
|
15011
|
+
const [fallbackVisible, setFallbackVisible] = React.useState(false);
|
|
15575
15012
|
if (block) throw block;
|
|
15576
15013
|
if (error) throw error;
|
|
15577
15014
|
const root = React.useRef(null);
|
|
@@ -15579,6 +15016,7 @@ function CanvasImpl({
|
|
|
15579
15016
|
const unsubscribeErrorRef = React.useRef(null);
|
|
15580
15017
|
useIsomorphicLayoutEffect(() => {
|
|
15581
15018
|
effectActiveRef.current = true;
|
|
15019
|
+
if (fallbackVisible) return;
|
|
15582
15020
|
const canvas = canvasRef.current;
|
|
15583
15021
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15584
15022
|
if (!root.current) {
|
|
@@ -15599,7 +15037,7 @@ function CanvasImpl({
|
|
|
15599
15037
|
}
|
|
15600
15038
|
async function run() {
|
|
15601
15039
|
if (!effectActiveRef.current || !root.current) return;
|
|
15602
|
-
await root.current.configure({
|
|
15040
|
+
const configured = await root.current.configure({
|
|
15603
15041
|
id,
|
|
15604
15042
|
primaryCanvas,
|
|
15605
15043
|
scheduler,
|
|
@@ -15614,6 +15052,8 @@ function CanvasImpl({
|
|
|
15614
15052
|
performance,
|
|
15615
15053
|
raycaster,
|
|
15616
15054
|
camera,
|
|
15055
|
+
autoUpdateFrustum,
|
|
15056
|
+
occlusion,
|
|
15617
15057
|
size: effectiveSize,
|
|
15618
15058
|
// Store size props for reset functionality
|
|
15619
15059
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15638,8 +15078,20 @@ function CanvasImpl({
|
|
|
15638
15078
|
}
|
|
15639
15079
|
onCreated?.(state);
|
|
15640
15080
|
}
|
|
15641
|
-
})
|
|
15642
|
-
|
|
15081
|
+
}).then(
|
|
15082
|
+
() => true,
|
|
15083
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15084
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15085
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15086
|
+
(setupError) => {
|
|
15087
|
+
if (effectActiveRef.current) {
|
|
15088
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15089
|
+
else setError(setupError);
|
|
15090
|
+
}
|
|
15091
|
+
return false;
|
|
15092
|
+
}
|
|
15093
|
+
);
|
|
15094
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15643
15095
|
root.current.render(
|
|
15644
15096
|
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
15645
15097
|
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
@@ -15673,20 +15125,13 @@ function CanvasImpl({
|
|
|
15673
15125
|
const handleHMR = () => {
|
|
15674
15126
|
queueMicrotask(() => {
|
|
15675
15127
|
const rootEntry = _roots.get(canvas);
|
|
15676
|
-
if (rootEntry?.store)
|
|
15677
|
-
rootEntry.store.setState((state) => ({
|
|
15678
|
-
nodes: {},
|
|
15679
|
-
uniforms: {},
|
|
15680
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15681
|
-
}));
|
|
15682
|
-
}
|
|
15128
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15683
15129
|
});
|
|
15684
15130
|
};
|
|
15685
15131
|
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
15686
15132
|
const hot = import.meta.hot;
|
|
15687
15133
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15688
|
-
return () => hot.
|
|
15689
|
-
});
|
|
15134
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15690
15135
|
}
|
|
15691
15136
|
if (typeof module !== "undefined" && module.hot) {
|
|
15692
15137
|
const hot = module.hot;
|
|
@@ -15709,7 +15154,20 @@ function CanvasImpl({
|
|
|
15709
15154
|
...style
|
|
15710
15155
|
},
|
|
15711
15156
|
...props,
|
|
15712
|
-
children:
|
|
15157
|
+
children: fallbackVisible ? (
|
|
15158
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15159
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15160
|
+
fallback
|
|
15161
|
+
) : /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
15162
|
+
"canvas",
|
|
15163
|
+
{
|
|
15164
|
+
ref: canvasRef,
|
|
15165
|
+
id,
|
|
15166
|
+
className: "r3f-canvas",
|
|
15167
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
15168
|
+
children: fallback
|
|
15169
|
+
}
|
|
15170
|
+
) })
|
|
15713
15171
|
}
|
|
15714
15172
|
);
|
|
15715
15173
|
}
|
|
@@ -15719,4 +15177,4 @@ function Canvas(props) {
|
|
|
15719
15177
|
|
|
15720
15178
|
extend(THREE);
|
|
15721
15179
|
|
|
15722
|
-
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS,
|
|
15180
|
+
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, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, 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, reconciler, registerPrimary, removeInteractivity, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
|