@react-three/fiber 10.0.0-canary.dbbe704 → 10.0.0-canary.f046a54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +648 -1361
- package/dist/index.d.cts +249 -788
- package/dist/index.d.mts +249 -788
- package/dist/index.d.ts +249 -788
- package/dist/index.mjs +622 -1334
- package/dist/legacy.cjs +603 -1322
- package/dist/legacy.d.cts +249 -788
- package/dist/legacy.d.mts +249 -788
- package/dist/legacy.d.ts +249 -788
- package/dist/legacy.mjs +577 -1295
- package/dist/webgpu/index.cjs +1048 -1379
- package/dist/webgpu/index.d.cts +334 -801
- package/dist/webgpu/index.d.mts +334 -801
- package/dist/webgpu/index.d.ts +334 -801
- package/dist/webgpu/index.mjs +1017 -1351
- package/package.json +2 -1
- package/readme.md +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as webgpu from 'three/webgpu';
|
|
2
|
-
import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera,
|
|
2
|
+
import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer } from 'three/webgpu';
|
|
3
3
|
import { WebGLRenderTarget, WebGLRenderer } from 'three';
|
|
4
4
|
import { Inspector } from 'three/addons/inspector/Inspector.js';
|
|
5
5
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
@@ -15,6 +15,8 @@ import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
|
15
15
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
16
16
|
import Tb, { unstable_scheduleCallback, unstable_IdlePriority } from 'scheduler';
|
|
17
17
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
18
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
19
|
+
export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
18
20
|
import { suspend, preload, clear } from 'suspend-react';
|
|
19
21
|
|
|
20
22
|
function _mergeNamespaces(n, m) {
|
|
@@ -139,7 +141,7 @@ function useEnvironment({
|
|
|
139
141
|
useLoader$1.clear(loader, multiFile ? [files] : files);
|
|
140
142
|
}
|
|
141
143
|
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
142
|
-
}, [files, renderer.domElement]);
|
|
144
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
143
145
|
const loaderResult = useLoader$1(
|
|
144
146
|
loader,
|
|
145
147
|
multiFile ? [files] : files,
|
|
@@ -339,7 +341,22 @@ function EnvironmentPortal({
|
|
|
339
341
|
environmentIntensity,
|
|
340
342
|
environmentRotation
|
|
341
343
|
});
|
|
342
|
-
}, [
|
|
344
|
+
}, [
|
|
345
|
+
children,
|
|
346
|
+
virtualScene,
|
|
347
|
+
fbo.texture,
|
|
348
|
+
scene,
|
|
349
|
+
defaultScene,
|
|
350
|
+
background,
|
|
351
|
+
frames,
|
|
352
|
+
gl,
|
|
353
|
+
blur,
|
|
354
|
+
backgroundBlurriness,
|
|
355
|
+
backgroundIntensity,
|
|
356
|
+
backgroundRotation,
|
|
357
|
+
environmentIntensity,
|
|
358
|
+
environmentRotation
|
|
359
|
+
]);
|
|
343
360
|
let count = 1;
|
|
344
361
|
useFrame$1(() => {
|
|
345
362
|
if (frames === Infinity || count < frames) {
|
|
@@ -410,9 +427,9 @@ function Environment(props) {
|
|
|
410
427
|
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
411
428
|
}
|
|
412
429
|
|
|
413
|
-
var __defProp
|
|
414
|
-
var __defNormalProp
|
|
415
|
-
var __publicField
|
|
430
|
+
var __defProp = Object.defineProperty;
|
|
431
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
432
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
416
433
|
const act = React["act"];
|
|
417
434
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
418
435
|
function useMutableCallback(fn) {
|
|
@@ -444,7 +461,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
444
461
|
return _a = class extends React.Component {
|
|
445
462
|
constructor() {
|
|
446
463
|
super(...arguments);
|
|
447
|
-
__publicField
|
|
464
|
+
__publicField(this, "state", { error: false });
|
|
448
465
|
}
|
|
449
466
|
componentDidCatch(err) {
|
|
450
467
|
this.props.set(err);
|
|
@@ -452,7 +469,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
452
469
|
render() {
|
|
453
470
|
return this.state.error ? null : this.props.children;
|
|
454
471
|
}
|
|
455
|
-
}, __publicField
|
|
472
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
456
473
|
})();
|
|
457
474
|
|
|
458
475
|
const is = {
|
|
@@ -973,8 +990,24 @@ function applyProps(object, props) {
|
|
|
973
990
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
974
991
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
975
992
|
else target.set(value);
|
|
993
|
+
} else if (root instanceof ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
994
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
995
|
+
const uniforms = root.uniforms;
|
|
996
|
+
const nextUniforms = value;
|
|
997
|
+
for (const name in nextUniforms) {
|
|
998
|
+
const uniform = nextUniforms[name];
|
|
999
|
+
const targetUniform = uniforms[name];
|
|
1000
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1001
|
+
else {
|
|
1002
|
+
const nextUniform = uniform instanceof Uniform ? uniform.clone() : new Uniform(uniform.value);
|
|
1003
|
+
uniforms[name] = nextUniform;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
976
1006
|
} else {
|
|
977
1007
|
root[key] = value;
|
|
1008
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1009
|
+
root.needsUpdate = true;
|
|
1010
|
+
}
|
|
978
1011
|
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
|
|
979
1012
|
root[key].format === RGBAFormat && root[key].type === UnsignedByteType) {
|
|
980
1013
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -1008,38 +1041,60 @@ function applyProps(object, props) {
|
|
|
1008
1041
|
return object;
|
|
1009
1042
|
}
|
|
1010
1043
|
|
|
1044
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1045
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1046
|
+
function getPointerState(internal, pointerId) {
|
|
1047
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1048
|
+
if (!state) {
|
|
1049
|
+
state = {
|
|
1050
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1051
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1052
|
+
initialClick: [0, 0],
|
|
1053
|
+
initialHits: []
|
|
1054
|
+
};
|
|
1055
|
+
internal.pointerMap.set(pointerId, state);
|
|
1056
|
+
}
|
|
1057
|
+
return state;
|
|
1058
|
+
}
|
|
1059
|
+
function getPointerId(event) {
|
|
1060
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1061
|
+
}
|
|
1011
1062
|
function makeId(event) {
|
|
1012
1063
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1013
1064
|
}
|
|
1014
|
-
function releaseInternalPointerCapture(
|
|
1015
|
-
const
|
|
1065
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1066
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1067
|
+
if (!pointerState) return;
|
|
1068
|
+
const captureData = pointerState.captured.get(obj);
|
|
1016
1069
|
if (captureData) {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
capturedMap.delete(pointerId);
|
|
1020
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
1021
|
-
}
|
|
1070
|
+
pointerState.captured.delete(obj);
|
|
1071
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1022
1072
|
}
|
|
1023
1073
|
}
|
|
1024
1074
|
function removeInteractivity(store, object) {
|
|
1025
1075
|
const { internal } = store.getState();
|
|
1026
1076
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1077
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1078
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1079
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1080
|
+
if (value.eventObject === object || value.object === object) {
|
|
1081
|
+
pointerState.hovered.delete(key);
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
if (pointerState.captured.has(object)) {
|
|
1085
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1031
1086
|
}
|
|
1032
|
-
}
|
|
1033
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1034
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1035
|
-
});
|
|
1087
|
+
}
|
|
1036
1088
|
unregisterVisibility(store, object);
|
|
1037
1089
|
}
|
|
1038
1090
|
function createEvents(store) {
|
|
1039
|
-
function calculateDistance(event) {
|
|
1091
|
+
function calculateDistance(event, pointerId) {
|
|
1040
1092
|
const { internal } = store.getState();
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1093
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1094
|
+
if (!pointerState) return 0;
|
|
1095
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1096
|
+
const dx = event.offsetX - initialX;
|
|
1097
|
+
const dy = event.offsetY - initialY;
|
|
1043
1098
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1044
1099
|
}
|
|
1045
1100
|
function filterPointerEvents(objects) {
|
|
@@ -1075,6 +1130,15 @@ function createEvents(store) {
|
|
|
1075
1130
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1076
1131
|
}
|
|
1077
1132
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1133
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1134
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1135
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1136
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1137
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1138
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1139
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1078
1142
|
const aState = getRootState(a.object);
|
|
1079
1143
|
const bState = getRootState(b.object);
|
|
1080
1144
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1096,9 +1160,13 @@ function createEvents(store) {
|
|
|
1096
1160
|
eventObject = eventObject.parent;
|
|
1097
1161
|
}
|
|
1098
1162
|
}
|
|
1099
|
-
if ("pointerId" in event
|
|
1100
|
-
|
|
1101
|
-
|
|
1163
|
+
if ("pointerId" in event) {
|
|
1164
|
+
const pointerId = event.pointerId;
|
|
1165
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1166
|
+
if (pointerState?.captured.size) {
|
|
1167
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1168
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1169
|
+
}
|
|
1102
1170
|
}
|
|
1103
1171
|
}
|
|
1104
1172
|
return intersections;
|
|
@@ -1111,27 +1179,25 @@ function createEvents(store) {
|
|
|
1111
1179
|
if (state) {
|
|
1112
1180
|
const { raycaster, pointer, camera, internal } = state;
|
|
1113
1181
|
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1114
|
-
const hasPointerCapture = (id) =>
|
|
1182
|
+
const hasPointerCapture = (id) => {
|
|
1183
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1184
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1185
|
+
};
|
|
1115
1186
|
const setPointerCapture = (id) => {
|
|
1116
1187
|
const captureData = { intersection: hit, target: event.target };
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
} else {
|
|
1120
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1121
|
-
}
|
|
1188
|
+
const pointerState = getPointerState(internal, id);
|
|
1189
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1122
1190
|
event.target.setPointerCapture(id);
|
|
1123
1191
|
};
|
|
1124
1192
|
const releasePointerCapture = (id) => {
|
|
1125
|
-
|
|
1126
|
-
if (captures) {
|
|
1127
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1128
|
-
}
|
|
1193
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1129
1194
|
};
|
|
1130
1195
|
const extractEventProps = {};
|
|
1131
1196
|
for (const prop in event) {
|
|
1132
1197
|
const property = event[prop];
|
|
1133
1198
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1134
1199
|
}
|
|
1200
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1135
1201
|
const raycastEvent = {
|
|
1136
1202
|
...hit,
|
|
1137
1203
|
...extractEventProps,
|
|
@@ -1142,18 +1208,19 @@ function createEvents(store) {
|
|
|
1142
1208
|
unprojectedPoint,
|
|
1143
1209
|
ray: raycaster.ray,
|
|
1144
1210
|
camera,
|
|
1211
|
+
pointerId: eventPointerId,
|
|
1145
1212
|
// Hijack stopPropagation, which just sets a flag
|
|
1146
1213
|
stopPropagation() {
|
|
1147
|
-
const
|
|
1214
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1148
1215
|
if (
|
|
1149
1216
|
// ...if this pointer hasn't been captured
|
|
1150
|
-
!
|
|
1151
|
-
|
|
1217
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1218
|
+
pointerState.captured.has(hit.eventObject)
|
|
1152
1219
|
) {
|
|
1153
1220
|
raycastEvent.stopped = localState.stopped = true;
|
|
1154
|
-
if (
|
|
1221
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1155
1222
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1156
|
-
cancelPointer([...higher, hit]);
|
|
1223
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1157
1224
|
}
|
|
1158
1225
|
}
|
|
1159
1226
|
},
|
|
@@ -1169,15 +1236,18 @@ function createEvents(store) {
|
|
|
1169
1236
|
}
|
|
1170
1237
|
return intersections;
|
|
1171
1238
|
}
|
|
1172
|
-
function cancelPointer(intersections) {
|
|
1239
|
+
function cancelPointer(intersections, pointerId) {
|
|
1173
1240
|
const { internal } = store.getState();
|
|
1174
|
-
|
|
1241
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1242
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1243
|
+
if (!pointerState) return;
|
|
1244
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1175
1245
|
if (!intersections.length || !intersections.find(
|
|
1176
1246
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1177
1247
|
)) {
|
|
1178
1248
|
const eventObject = hoveredObj.eventObject;
|
|
1179
1249
|
const instance = eventObject.__r3f;
|
|
1180
|
-
|
|
1250
|
+
pointerState.hovered.delete(hoveredId);
|
|
1181
1251
|
if (instance?.eventCount) {
|
|
1182
1252
|
const handlers = instance.handlers;
|
|
1183
1253
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1206,41 +1276,118 @@ function createEvents(store) {
|
|
|
1206
1276
|
instance?.handlers.onDropMissed?.(event);
|
|
1207
1277
|
}
|
|
1208
1278
|
}
|
|
1279
|
+
function cleanupPointer(pointerId) {
|
|
1280
|
+
const { internal } = store.getState();
|
|
1281
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1282
|
+
if (pointerState) {
|
|
1283
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1284
|
+
const eventObject = hoveredObj.eventObject;
|
|
1285
|
+
const instance = eventObject.__r3f;
|
|
1286
|
+
if (instance?.eventCount) {
|
|
1287
|
+
const handlers = instance.handlers;
|
|
1288
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1289
|
+
handlers.onPointerOut?.(data);
|
|
1290
|
+
handlers.onPointerLeave?.(data);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
internal.pointerMap.delete(pointerId);
|
|
1294
|
+
}
|
|
1295
|
+
internal.pointerDirty.delete(pointerId);
|
|
1296
|
+
}
|
|
1297
|
+
function processDeferredPointer(event, pointerId) {
|
|
1298
|
+
const state = store.getState();
|
|
1299
|
+
const { internal } = state;
|
|
1300
|
+
if (!state.events.enabled) return;
|
|
1301
|
+
const filter = filterPointerEvents;
|
|
1302
|
+
const hits = intersect(event, filter);
|
|
1303
|
+
cancelPointer(hits, pointerId);
|
|
1304
|
+
function onIntersect(data) {
|
|
1305
|
+
const eventObject = data.eventObject;
|
|
1306
|
+
const instance = eventObject.__r3f;
|
|
1307
|
+
if (!instance?.eventCount) return;
|
|
1308
|
+
const handlers = instance.handlers;
|
|
1309
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1310
|
+
const id = makeId(data);
|
|
1311
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1312
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1313
|
+
if (!hoveredItem) {
|
|
1314
|
+
pointerState.hovered.set(id, data);
|
|
1315
|
+
handlers.onPointerOver?.(data);
|
|
1316
|
+
handlers.onPointerEnter?.(data);
|
|
1317
|
+
} else if (hoveredItem.stopped) {
|
|
1318
|
+
data.stopPropagation();
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
handlers.onPointerMove?.(data);
|
|
1322
|
+
}
|
|
1323
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1324
|
+
}
|
|
1209
1325
|
function handlePointer(name) {
|
|
1210
1326
|
switch (name) {
|
|
1211
1327
|
case "onPointerLeave":
|
|
1212
|
-
case "onPointerCancel":
|
|
1213
1328
|
case "onDragLeave":
|
|
1214
1329
|
return () => cancelPointer([]);
|
|
1330
|
+
// Global cancel of these events
|
|
1331
|
+
case "onPointerCancel":
|
|
1332
|
+
return (event) => {
|
|
1333
|
+
const pointerId = getPointerId(event);
|
|
1334
|
+
cleanupPointer(pointerId);
|
|
1335
|
+
};
|
|
1215
1336
|
case "onLostPointerCapture":
|
|
1216
1337
|
return (event) => {
|
|
1217
1338
|
const { internal } = store.getState();
|
|
1218
|
-
|
|
1339
|
+
const pointerId = getPointerId(event);
|
|
1340
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1341
|
+
if (pointerState?.captured.size) {
|
|
1219
1342
|
requestAnimationFrame(() => {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1343
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1344
|
+
if (pointerState2?.captured.size) {
|
|
1345
|
+
pointerState2.captured.clear();
|
|
1223
1346
|
}
|
|
1347
|
+
cancelPointer([], pointerId);
|
|
1224
1348
|
});
|
|
1225
1349
|
}
|
|
1226
1350
|
};
|
|
1227
1351
|
}
|
|
1228
1352
|
return function handleEvent(event) {
|
|
1229
1353
|
const state = store.getState();
|
|
1230
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1354
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1355
|
+
const pointerId = getPointerId(event);
|
|
1231
1356
|
internal.lastEvent.current = event;
|
|
1232
|
-
if (!
|
|
1357
|
+
if (!events.enabled) return;
|
|
1233
1358
|
const isPointerMove = name === "onPointerMove";
|
|
1234
1359
|
const isDragOver = name === "onDragOver";
|
|
1235
1360
|
const isDrop = name === "onDrop";
|
|
1236
1361
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1362
|
+
const isPointerDown = name === "onPointerDown";
|
|
1363
|
+
const isPointerUp = name === "onPointerUp";
|
|
1364
|
+
const isWheel = name === "onWheel";
|
|
1365
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1366
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1367
|
+
events.compute?.(event, state);
|
|
1368
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1372
|
+
events.compute?.(event, state);
|
|
1373
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1377
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1378
|
+
internal.pointerDirty.delete(pointerId);
|
|
1379
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1380
|
+
}
|
|
1237
1381
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1238
1382
|
const hits = intersect(event, filter);
|
|
1239
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1240
|
-
if (
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1383
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1384
|
+
if (isPointerDown) {
|
|
1385
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1386
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1387
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1388
|
+
}
|
|
1389
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1390
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1244
1391
|
if (isClickEvent && !hits.length) {
|
|
1245
1392
|
if (delta <= 2) {
|
|
1246
1393
|
pointerMissed(event, internal.interaction);
|
|
@@ -1255,7 +1402,9 @@ function createEvents(store) {
|
|
|
1255
1402
|
dropMissed(event, internal.interaction);
|
|
1256
1403
|
if (onDropMissed) onDropMissed(event);
|
|
1257
1404
|
}
|
|
1258
|
-
if (isPointerMove || isDragOver)
|
|
1405
|
+
if (isPointerMove || isDragOver) {
|
|
1406
|
+
cancelPointer(hits, pointerId);
|
|
1407
|
+
}
|
|
1259
1408
|
function onIntersect(data) {
|
|
1260
1409
|
const eventObject = data.eventObject;
|
|
1261
1410
|
const instance = eventObject.__r3f;
|
|
@@ -1264,9 +1413,10 @@ function createEvents(store) {
|
|
|
1264
1413
|
if (isPointerMove) {
|
|
1265
1414
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1266
1415
|
const id = makeId(data);
|
|
1267
|
-
const
|
|
1416
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1417
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1268
1418
|
if (!hoveredItem) {
|
|
1269
|
-
|
|
1419
|
+
pointerState2.hovered.set(id, data);
|
|
1270
1420
|
handlers.onPointerOver?.(data);
|
|
1271
1421
|
handlers.onPointerEnter?.(data);
|
|
1272
1422
|
} else if (hoveredItem.stopped) {
|
|
@@ -1276,9 +1426,10 @@ function createEvents(store) {
|
|
|
1276
1426
|
handlers.onPointerMove?.(data);
|
|
1277
1427
|
} else if (isDragOver) {
|
|
1278
1428
|
const id = makeId(data);
|
|
1279
|
-
const
|
|
1429
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1430
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1280
1431
|
if (!hoveredItem) {
|
|
1281
|
-
|
|
1432
|
+
pointerState2.hovered.set(id, data);
|
|
1282
1433
|
handlers.onDragOverEnter?.(data);
|
|
1283
1434
|
} else if (hoveredItem.stopped) {
|
|
1284
1435
|
data.stopPropagation();
|
|
@@ -1289,18 +1440,18 @@ function createEvents(store) {
|
|
|
1289
1440
|
} else {
|
|
1290
1441
|
const handler = handlers[name];
|
|
1291
1442
|
if (handler) {
|
|
1292
|
-
if (!isClickEvent ||
|
|
1443
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1293
1444
|
pointerMissed(
|
|
1294
1445
|
event,
|
|
1295
|
-
internal.interaction.filter((object) => !
|
|
1446
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1296
1447
|
);
|
|
1297
1448
|
handler(data);
|
|
1298
1449
|
}
|
|
1299
1450
|
} else {
|
|
1300
|
-
if (isClickEvent &&
|
|
1451
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1301
1452
|
pointerMissed(
|
|
1302
1453
|
event,
|
|
1303
|
-
internal.interaction.filter((object) => !
|
|
1454
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1304
1455
|
);
|
|
1305
1456
|
}
|
|
1306
1457
|
}
|
|
@@ -1309,7 +1460,15 @@ function createEvents(store) {
|
|
|
1309
1460
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1310
1461
|
};
|
|
1311
1462
|
}
|
|
1312
|
-
|
|
1463
|
+
function flushDeferredPointers() {
|
|
1464
|
+
const { internal, events } = store.getState();
|
|
1465
|
+
if (!events.frameTimedRaycasts) return;
|
|
1466
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1467
|
+
processDeferredPointer(event, pointerId);
|
|
1468
|
+
}
|
|
1469
|
+
internal.pointerDirty.clear();
|
|
1470
|
+
}
|
|
1471
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1313
1472
|
}
|
|
1314
1473
|
const DOM_EVENTS = {
|
|
1315
1474
|
onClick: ["click", false],
|
|
@@ -1328,10 +1487,15 @@ const DOM_EVENTS = {
|
|
|
1328
1487
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1329
1488
|
};
|
|
1330
1489
|
function createPointerEvents(store) {
|
|
1331
|
-
const { handlePointer } = createEvents(store);
|
|
1490
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1491
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1492
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1332
1493
|
return {
|
|
1333
1494
|
priority: 1,
|
|
1334
1495
|
enabled: true,
|
|
1496
|
+
frameTimedRaycasts: true,
|
|
1497
|
+
alwaysFireOnScroll: true,
|
|
1498
|
+
updateOnFrame: false,
|
|
1335
1499
|
compute(event, state) {
|
|
1336
1500
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1337
1501
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1341,11 +1505,33 @@ function createPointerEvents(store) {
|
|
|
1341
1505
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1342
1506
|
{}
|
|
1343
1507
|
),
|
|
1344
|
-
update: () => {
|
|
1508
|
+
update: (pointerId) => {
|
|
1345
1509
|
const { events, internal } = store.getState();
|
|
1346
|
-
if (
|
|
1510
|
+
if (!events.handlers) return;
|
|
1511
|
+
if (pointerId !== void 0) {
|
|
1512
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1513
|
+
if (event) {
|
|
1514
|
+
internal.pointerDirty.delete(pointerId);
|
|
1515
|
+
processDeferredPointer(event, pointerId);
|
|
1516
|
+
} else if (internal.lastEvent?.current) {
|
|
1517
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1518
|
+
}
|
|
1519
|
+
} else {
|
|
1520
|
+
flushDeferredPointers();
|
|
1521
|
+
if (internal.lastEvent?.current) {
|
|
1522
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
},
|
|
1526
|
+
flush: () => {
|
|
1527
|
+
const { events, internal } = store.getState();
|
|
1528
|
+
flushDeferredPointers();
|
|
1529
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1530
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1531
|
+
}
|
|
1347
1532
|
},
|
|
1348
1533
|
connect: (target) => {
|
|
1534
|
+
if (!target) return;
|
|
1349
1535
|
const { set, events } = store.getState();
|
|
1350
1536
|
events.disconnect?.();
|
|
1351
1537
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1369,6 +1555,32 @@ function createPointerEvents(store) {
|
|
|
1369
1555
|
}
|
|
1370
1556
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1371
1557
|
}
|
|
1558
|
+
},
|
|
1559
|
+
registerPointer: (config) => {
|
|
1560
|
+
const pointerId = nextXRPointerId++;
|
|
1561
|
+
xrPointers.set(pointerId, config);
|
|
1562
|
+
const { internal } = store.getState();
|
|
1563
|
+
getPointerState(internal, pointerId);
|
|
1564
|
+
return pointerId;
|
|
1565
|
+
},
|
|
1566
|
+
unregisterPointer: (pointerId) => {
|
|
1567
|
+
xrPointers.delete(pointerId);
|
|
1568
|
+
const { internal } = store.getState();
|
|
1569
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1570
|
+
if (pointerState) {
|
|
1571
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1572
|
+
const eventObject = hoveredObj.eventObject;
|
|
1573
|
+
const instance = eventObject.__r3f;
|
|
1574
|
+
if (instance?.eventCount) {
|
|
1575
|
+
const handlers = instance.handlers;
|
|
1576
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1577
|
+
handlers.onPointerOut?.(data);
|
|
1578
|
+
handlers.onPointerLeave?.(data);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
internal.pointerMap.delete(pointerId);
|
|
1582
|
+
}
|
|
1583
|
+
internal.pointerDirty.delete(pointerId);
|
|
1372
1584
|
}
|
|
1373
1585
|
};
|
|
1374
1586
|
}
|
|
@@ -1430,1036 +1642,12 @@ function notifyAlpha({ message, link }) {
|
|
|
1430
1642
|
}
|
|
1431
1643
|
}
|
|
1432
1644
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
/** Ordered list of phase nodes */
|
|
1440
|
-
__publicField$1(this, "phases", []);
|
|
1441
|
-
/** Quick lookup by name */
|
|
1442
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1443
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1444
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1445
|
-
this.initializeDefaultPhases();
|
|
1446
|
-
}
|
|
1447
|
-
//* Initialization --------------------------------
|
|
1448
|
-
initializeDefaultPhases() {
|
|
1449
|
-
for (const name of DEFAULT_PHASES) {
|
|
1450
|
-
const node = { name, isAutoGenerated: false };
|
|
1451
|
-
this.phases.push(node);
|
|
1452
|
-
this.phaseMap.set(name, node);
|
|
1453
|
-
}
|
|
1454
|
-
this.invalidateCache();
|
|
1455
|
-
}
|
|
1456
|
-
//* Public API --------------------------------
|
|
1457
|
-
/**
|
|
1458
|
-
* Add a named phase to the graph
|
|
1459
|
-
* @param name - Phase name (must be unique)
|
|
1460
|
-
* @param options - Position options (before or after another phase)
|
|
1461
|
-
*/
|
|
1462
|
-
addPhase(name, options = {}) {
|
|
1463
|
-
if (this.phaseMap.has(name)) {
|
|
1464
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1465
|
-
return;
|
|
1466
|
-
}
|
|
1467
|
-
const { before, after } = options;
|
|
1468
|
-
const node = { name, isAutoGenerated: false };
|
|
1469
|
-
let insertIndex = this.phases.length;
|
|
1470
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1471
|
-
if (targetIndex !== -1) {
|
|
1472
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1473
|
-
} else {
|
|
1474
|
-
const constraintType = before ? "before" : "after";
|
|
1475
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1476
|
-
}
|
|
1477
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1478
|
-
this.phaseMap.set(name, node);
|
|
1479
|
-
this.invalidateCache();
|
|
1480
|
-
}
|
|
1481
|
-
/**
|
|
1482
|
-
* Get ordered list of phase names
|
|
1483
|
-
*/
|
|
1484
|
-
getOrderedPhases() {
|
|
1485
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1486
|
-
return this.orderedNamesCache;
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Check if a phase exists
|
|
1490
|
-
*/
|
|
1491
|
-
hasPhase(name) {
|
|
1492
|
-
return this.phaseMap.has(name);
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Get the index of a phase (-1 if not found)
|
|
1496
|
-
*/
|
|
1497
|
-
getPhaseIndex(name) {
|
|
1498
|
-
if (!name) return -1;
|
|
1499
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1503
|
-
* Used for resolving before/after constraints.
|
|
1504
|
-
*
|
|
1505
|
-
* @param name - The phase name to ensure exists
|
|
1506
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1507
|
-
*/
|
|
1508
|
-
ensurePhase(name) {
|
|
1509
|
-
if (this.phaseMap.has(name)) return name;
|
|
1510
|
-
const node = { name, isAutoGenerated: true };
|
|
1511
|
-
this.phases.push(node);
|
|
1512
|
-
this.phaseMap.set(name, node);
|
|
1513
|
-
this.invalidateCache();
|
|
1514
|
-
return name;
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* Resolve where a job with before/after constraints should go.
|
|
1518
|
-
* Creates auto-generated phases if needed.
|
|
1519
|
-
*
|
|
1520
|
-
* @param before - Phase(s) to run before
|
|
1521
|
-
* @param after - Phase(s) to run after
|
|
1522
|
-
* @returns The resolved phase name
|
|
1523
|
-
*/
|
|
1524
|
-
resolveConstraintPhase(before, after) {
|
|
1525
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1526
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1527
|
-
if (beforeArr.length > 0) {
|
|
1528
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1529
|
-
}
|
|
1530
|
-
if (afterArr.length > 0) {
|
|
1531
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1532
|
-
}
|
|
1533
|
-
return "update";
|
|
1534
|
-
}
|
|
1535
|
-
/**
|
|
1536
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1537
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1538
|
-
*
|
|
1539
|
-
* @param target - The target phase name to position relative to
|
|
1540
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1541
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1542
|
-
* @returns The auto-generated phase name
|
|
1543
|
-
*/
|
|
1544
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1545
|
-
const autoName = `${prefix}:${target}`;
|
|
1546
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1547
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1548
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1549
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1550
|
-
else this.phases.push(node);
|
|
1551
|
-
this.phaseMap.set(autoName, node);
|
|
1552
|
-
this.invalidateCache();
|
|
1553
|
-
return autoName;
|
|
1554
|
-
}
|
|
1555
|
-
// Internal --------------------------------
|
|
1556
|
-
invalidateCache() {
|
|
1557
|
-
this.orderedNamesCache = null;
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1562
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1563
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1564
|
-
for (const phase of orderedPhases) {
|
|
1565
|
-
buckets.set(phase, []);
|
|
1566
|
-
}
|
|
1567
|
-
for (const job of jobs.values()) {
|
|
1568
|
-
if (!job.enabled) continue;
|
|
1569
|
-
let bucket = buckets.get(job.phase);
|
|
1570
|
-
if (!bucket) {
|
|
1571
|
-
bucket = [];
|
|
1572
|
-
buckets.set(job.phase, bucket);
|
|
1573
|
-
}
|
|
1574
|
-
bucket.push(job);
|
|
1575
|
-
}
|
|
1576
|
-
const sortedBuckets = [];
|
|
1577
|
-
for (const phase of orderedPhases) {
|
|
1578
|
-
const bucket = buckets.get(phase);
|
|
1579
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1580
|
-
bucket.sort((a, b) => {
|
|
1581
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1582
|
-
return a.index - b.index;
|
|
1583
|
-
});
|
|
1584
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1585
|
-
}
|
|
1586
|
-
for (const [phase, bucket] of buckets) {
|
|
1587
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1588
|
-
bucket.sort((a, b) => {
|
|
1589
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1590
|
-
return a.index - b.index;
|
|
1591
|
-
});
|
|
1592
|
-
sortedBuckets.push(bucket);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
return sortedBuckets.flat();
|
|
1596
|
-
}
|
|
1597
|
-
function hasCrossJobConstraints(bucket) {
|
|
1598
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1599
|
-
for (const job of bucket) {
|
|
1600
|
-
for (const ref of job.before) {
|
|
1601
|
-
if (jobIds.has(ref)) return true;
|
|
1602
|
-
}
|
|
1603
|
-
for (const ref of job.after) {
|
|
1604
|
-
if (jobIds.has(ref)) return true;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
return false;
|
|
1608
|
-
}
|
|
1609
|
-
function topologicalSort(jobs) {
|
|
1610
|
-
const n = jobs.length;
|
|
1611
|
-
if (n <= 1) return jobs;
|
|
1612
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1613
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1614
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1615
|
-
for (const job of jobs) {
|
|
1616
|
-
jobMap.set(job.id, job);
|
|
1617
|
-
inDegree.set(job.id, 0);
|
|
1618
|
-
adjacency.set(job.id, []);
|
|
1619
|
-
}
|
|
1620
|
-
for (const job of jobs) {
|
|
1621
|
-
for (const ref of job.before) {
|
|
1622
|
-
if (jobMap.has(ref)) {
|
|
1623
|
-
adjacency.get(job.id).push(ref);
|
|
1624
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
for (const ref of job.after) {
|
|
1628
|
-
if (jobMap.has(ref)) {
|
|
1629
|
-
adjacency.get(ref).push(job.id);
|
|
1630
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
const queue = [];
|
|
1635
|
-
for (const job of jobs) {
|
|
1636
|
-
if (inDegree.get(job.id) === 0) {
|
|
1637
|
-
queue.push(job);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
queue.sort((a, b) => {
|
|
1641
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1642
|
-
return a.index - b.index;
|
|
1643
|
-
});
|
|
1644
|
-
const result = [];
|
|
1645
|
-
while (queue.length > 0) {
|
|
1646
|
-
const job = queue.shift();
|
|
1647
|
-
result.push(job);
|
|
1648
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1649
|
-
for (const neighborId of neighbors) {
|
|
1650
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1651
|
-
inDegree.set(neighborId, newDegree);
|
|
1652
|
-
if (newDegree === 0) {
|
|
1653
|
-
const neighbor = jobMap.get(neighborId);
|
|
1654
|
-
insertSorted(queue, neighbor);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
if (result.length !== n) {
|
|
1659
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1660
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1661
|
-
for (const job of jobs) {
|
|
1662
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return result;
|
|
1666
|
-
}
|
|
1667
|
-
function insertSorted(arr, job) {
|
|
1668
|
-
let i = 0;
|
|
1669
|
-
while (i < arr.length) {
|
|
1670
|
-
const cmp = arr[i];
|
|
1671
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1672
|
-
break;
|
|
1673
|
-
}
|
|
1674
|
-
i++;
|
|
1675
|
-
}
|
|
1676
|
-
arr.splice(i, 0, job);
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
function shouldRun(job, now) {
|
|
1680
|
-
if (!job.enabled) return false;
|
|
1681
|
-
if (!job.fps) return true;
|
|
1682
|
-
const minInterval = 1e3 / job.fps;
|
|
1683
|
-
const lastRun = job.lastRun ?? 0;
|
|
1684
|
-
const elapsed = now - lastRun;
|
|
1685
|
-
if (elapsed < minInterval) return false;
|
|
1686
|
-
if (job.drop) {
|
|
1687
|
-
job.lastRun = now;
|
|
1688
|
-
} else {
|
|
1689
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1690
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1691
|
-
if (job.lastRun < now - minInterval) {
|
|
1692
|
-
job.lastRun = now;
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
return true;
|
|
1696
|
-
}
|
|
1697
|
-
function resetJobTiming(job) {
|
|
1698
|
-
job.lastRun = void 0;
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
var __defProp = Object.defineProperty;
|
|
1702
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1703
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1704
|
-
const hmrData = (() => {
|
|
1705
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1706
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1707
|
-
try {
|
|
1708
|
-
return (0, eval)("import.meta.hot");
|
|
1709
|
-
} catch {
|
|
1710
|
-
return void 0;
|
|
1711
|
-
}
|
|
1712
|
-
})();
|
|
1713
|
-
const _Scheduler = class _Scheduler {
|
|
1714
|
-
//* Constructor ================================
|
|
1715
|
-
constructor() {
|
|
1716
|
-
//* Critical State ================================
|
|
1717
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1718
|
-
__publicField(this, "phaseGraph");
|
|
1719
|
-
__publicField(this, "loopState", {
|
|
1720
|
-
running: false,
|
|
1721
|
-
rafHandle: null,
|
|
1722
|
-
lastTime: null,
|
|
1723
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1724
|
-
frameCount: 0,
|
|
1725
|
-
elapsedTime: 0,
|
|
1726
|
-
createdAt: performance.now()
|
|
1727
|
-
});
|
|
1728
|
-
__publicField(this, "stoppedTime", 0);
|
|
1729
|
-
//* Private State ================================
|
|
1730
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1731
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1732
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1733
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1734
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1735
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1736
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1737
|
-
__publicField(this, "pendingFrames", 0);
|
|
1738
|
-
__publicField(this, "_frameloop", "always");
|
|
1739
|
-
//* Independent Mode & Error Handling State ================================
|
|
1740
|
-
__publicField(this, "_independent", false);
|
|
1741
|
-
__publicField(this, "errorHandler", null);
|
|
1742
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1743
|
-
//* Core Loop Execution Methods ================================
|
|
1744
|
-
/**
|
|
1745
|
-
* Main RAF loop callback.
|
|
1746
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1747
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1748
|
-
* @returns {void}
|
|
1749
|
-
* @private
|
|
1750
|
-
*/
|
|
1751
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1752
|
-
if (!this.loopState.running) return;
|
|
1753
|
-
this.executeFrame(timestamp);
|
|
1754
|
-
if (this._frameloop === "demand") {
|
|
1755
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1756
|
-
if (this.pendingFrames === 0) {
|
|
1757
|
-
this.notifyIdle(timestamp);
|
|
1758
|
-
return this.stop();
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1762
|
-
});
|
|
1763
|
-
this.phaseGraph = new PhaseGraph();
|
|
1764
|
-
}
|
|
1765
|
-
static get instance() {
|
|
1766
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1767
|
-
}
|
|
1768
|
-
static set instance(value) {
|
|
1769
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1773
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1774
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1775
|
-
*/
|
|
1776
|
-
static get() {
|
|
1777
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1778
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1779
|
-
}
|
|
1780
|
-
if (!_Scheduler.instance) {
|
|
1781
|
-
_Scheduler.instance = new _Scheduler();
|
|
1782
|
-
if (hmrData?.data) {
|
|
1783
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
return _Scheduler.instance;
|
|
1787
|
-
}
|
|
1788
|
-
/**
|
|
1789
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1790
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1791
|
-
* @returns {void}
|
|
1792
|
-
*/
|
|
1793
|
-
static reset() {
|
|
1794
|
-
if (_Scheduler.instance) {
|
|
1795
|
-
_Scheduler.instance.stop();
|
|
1796
|
-
_Scheduler.instance = null;
|
|
1797
|
-
}
|
|
1798
|
-
if (hmrData?.data) {
|
|
1799
|
-
hmrData.data.scheduler = null;
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
//* Getters & Setters ================================
|
|
1803
|
-
get phases() {
|
|
1804
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1805
|
-
}
|
|
1806
|
-
get frameloop() {
|
|
1807
|
-
return this._frameloop;
|
|
1808
|
-
}
|
|
1809
|
-
set frameloop(mode) {
|
|
1810
|
-
if (this._frameloop === mode) return;
|
|
1811
|
-
const wasAlways = this._frameloop === "always";
|
|
1812
|
-
this._frameloop = mode;
|
|
1813
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1814
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1815
|
-
}
|
|
1816
|
-
get isRunning() {
|
|
1817
|
-
return this.loopState.running;
|
|
1818
|
-
}
|
|
1819
|
-
get isReady() {
|
|
1820
|
-
return this.roots.size > 0;
|
|
1821
|
-
}
|
|
1822
|
-
get independent() {
|
|
1823
|
-
return this._independent;
|
|
1824
|
-
}
|
|
1825
|
-
set independent(value) {
|
|
1826
|
-
this._independent = value;
|
|
1827
|
-
if (value) this.ensureDefaultRoot();
|
|
1828
|
-
}
|
|
1829
|
-
//* Root Management Methods ================================
|
|
1830
|
-
/**
|
|
1831
|
-
* Register a root (Canvas) with the scheduler.
|
|
1832
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1833
|
-
* @param {string} id - Unique identifier for this root
|
|
1834
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1835
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1836
|
-
*/
|
|
1837
|
-
registerRoot(id, options = {}) {
|
|
1838
|
-
if (this.roots.has(id)) {
|
|
1839
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1840
|
-
return () => this.unregisterRoot(id);
|
|
1841
|
-
}
|
|
1842
|
-
const entry = {
|
|
1843
|
-
id,
|
|
1844
|
-
getState: options.getState ?? (() => ({})),
|
|
1845
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1846
|
-
sortedJobs: [],
|
|
1847
|
-
needsRebuild: false
|
|
1848
|
-
};
|
|
1849
|
-
if (options.onError) {
|
|
1850
|
-
this.errorHandler = options.onError;
|
|
1851
|
-
}
|
|
1852
|
-
this.roots.set(id, entry);
|
|
1853
|
-
if (this.roots.size === 1) {
|
|
1854
|
-
this.notifyRootReady();
|
|
1855
|
-
if (this._frameloop === "always") this.start();
|
|
1856
|
-
}
|
|
1857
|
-
return () => this.unregisterRoot(id);
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
|
-
* Unregister a root from the scheduler.
|
|
1861
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1862
|
-
* The last root to unregister stops the RAF loop.
|
|
1863
|
-
* @param {string} id - The root ID to unregister
|
|
1864
|
-
* @returns {void}
|
|
1865
|
-
*/
|
|
1866
|
-
unregisterRoot(id) {
|
|
1867
|
-
const root = this.roots.get(id);
|
|
1868
|
-
if (!root) return;
|
|
1869
|
-
for (const jobId of root.jobs.keys()) {
|
|
1870
|
-
this.jobStateListeners.delete(jobId);
|
|
1871
|
-
}
|
|
1872
|
-
this.roots.delete(id);
|
|
1873
|
-
if (this.roots.size === 0) {
|
|
1874
|
-
this.stop();
|
|
1875
|
-
this.errorHandler = null;
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
/**
|
|
1879
|
-
* Subscribe to be notified when a root becomes available.
|
|
1880
|
-
* Fires immediately if a root already exists.
|
|
1881
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1882
|
-
* @returns {() => void} Unsubscribe function
|
|
1883
|
-
*/
|
|
1884
|
-
onRootReady(callback) {
|
|
1885
|
-
if (this.roots.size > 0) {
|
|
1886
|
-
callback();
|
|
1887
|
-
return () => {
|
|
1888
|
-
};
|
|
1889
|
-
}
|
|
1890
|
-
this.rootReadyCallbacks.add(callback);
|
|
1891
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1892
|
-
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Notify all registered root-ready callbacks.
|
|
1895
|
-
* Called when the first root registers.
|
|
1896
|
-
* @returns {void}
|
|
1897
|
-
* @private
|
|
1898
|
-
*/
|
|
1899
|
-
notifyRootReady() {
|
|
1900
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1901
|
-
try {
|
|
1902
|
-
cb();
|
|
1903
|
-
} catch (error) {
|
|
1904
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
this.rootReadyCallbacks.clear();
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Ensure a default root exists for independent mode.
|
|
1911
|
-
* Creates a minimal root with no state provider.
|
|
1912
|
-
* @returns {void}
|
|
1913
|
-
* @private
|
|
1914
|
-
*/
|
|
1915
|
-
ensureDefaultRoot() {
|
|
1916
|
-
if (!this.roots.has("__default__")) {
|
|
1917
|
-
this.registerRoot("__default__");
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
/**
|
|
1921
|
-
* Trigger error handling for job errors.
|
|
1922
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1923
|
-
* @param {Error} error - The error to handle
|
|
1924
|
-
* @returns {void}
|
|
1925
|
-
*/
|
|
1926
|
-
triggerError(error) {
|
|
1927
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1928
|
-
else console.error("[Scheduler]", error);
|
|
1929
|
-
}
|
|
1930
|
-
//* Phase Management Methods ================================
|
|
1931
|
-
/**
|
|
1932
|
-
* Add a named phase to the scheduler's execution order.
|
|
1933
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1934
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1935
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1936
|
-
* @returns {void}
|
|
1937
|
-
* @example
|
|
1938
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1939
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1940
|
-
*/
|
|
1941
|
-
addPhase(name, options) {
|
|
1942
|
-
this.phaseGraph.addPhase(name, options);
|
|
1943
|
-
for (const root of this.roots.values()) {
|
|
1944
|
-
root.needsRebuild = true;
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
/**
|
|
1948
|
-
* Check if a phase exists in the scheduler.
|
|
1949
|
-
* @param {string} name - The phase name to check
|
|
1950
|
-
* @returns {boolean} True if the phase exists
|
|
1951
|
-
*/
|
|
1952
|
-
hasPhase(name) {
|
|
1953
|
-
return this.phaseGraph.hasPhase(name);
|
|
1954
|
-
}
|
|
1955
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1956
|
-
/**
|
|
1957
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1958
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1959
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1960
|
-
* @param {string} id - Unique identifier for this global job
|
|
1961
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1962
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1963
|
-
* @deprecated Use useFrame with phases instead
|
|
1964
|
-
*/
|
|
1965
|
-
registerGlobal(phase, id, callback) {
|
|
1966
|
-
const job = { id, callback };
|
|
1967
|
-
if (phase === "before") {
|
|
1968
|
-
this.globalBeforeJobs.set(id, job);
|
|
1969
|
-
} else {
|
|
1970
|
-
this.globalAfterJobs.set(id, job);
|
|
1971
|
-
}
|
|
1972
|
-
return () => {
|
|
1973
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
1974
|
-
else this.globalAfterJobs.delete(id);
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
1978
|
-
/**
|
|
1979
|
-
* Register an idle callback that fires when the loop stops.
|
|
1980
|
-
* Used internally by deprecated addTail API.
|
|
1981
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
1982
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
1983
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
1984
|
-
*/
|
|
1985
|
-
onIdle(callback) {
|
|
1986
|
-
this.idleCallbacks.add(callback);
|
|
1987
|
-
return () => this.idleCallbacks.delete(callback);
|
|
1988
|
-
}
|
|
1989
|
-
/**
|
|
1990
|
-
* Notify all registered idle callbacks.
|
|
1991
|
-
* Called when the loop stops in demand mode.
|
|
1992
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
1993
|
-
* @returns {void}
|
|
1994
|
-
* @private
|
|
1995
|
-
*/
|
|
1996
|
-
notifyIdle(timestamp) {
|
|
1997
|
-
for (const cb of this.idleCallbacks) {
|
|
1998
|
-
try {
|
|
1999
|
-
cb(timestamp);
|
|
2000
|
-
} catch (error) {
|
|
2001
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
//* Job Registration & Management Methods ================================
|
|
2006
|
-
/**
|
|
2007
|
-
* Register a job (frame callback) with a specific root.
|
|
2008
|
-
* This is the core registration method used by useFrame internally.
|
|
2009
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2010
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2011
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2012
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2013
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2014
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2015
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2016
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2017
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2018
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2019
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2020
|
-
*/
|
|
2021
|
-
register(callback, options = {}) {
|
|
2022
|
-
const rootId = options.rootId;
|
|
2023
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2024
|
-
if (!root) {
|
|
2025
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2026
|
-
return () => {
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
const id = options.id ?? this.generateJobId();
|
|
2030
|
-
let phase = options.phase ?? "update";
|
|
2031
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2032
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2033
|
-
}
|
|
2034
|
-
const before = this.normalizeConstraints(options.before);
|
|
2035
|
-
const after = this.normalizeConstraints(options.after);
|
|
2036
|
-
const job = {
|
|
2037
|
-
id,
|
|
2038
|
-
callback,
|
|
2039
|
-
phase,
|
|
2040
|
-
before,
|
|
2041
|
-
after,
|
|
2042
|
-
priority: options.priority ?? 0,
|
|
2043
|
-
index: this.nextJobIndex++,
|
|
2044
|
-
fps: options.fps,
|
|
2045
|
-
drop: options.drop ?? true,
|
|
2046
|
-
enabled: options.enabled ?? true,
|
|
2047
|
-
system: options.system ?? false
|
|
2048
|
-
};
|
|
2049
|
-
if (root.jobs.has(id)) {
|
|
2050
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2051
|
-
}
|
|
2052
|
-
root.jobs.set(id, job);
|
|
2053
|
-
root.needsRebuild = true;
|
|
2054
|
-
return () => this.unregister(id, root.id);
|
|
2055
|
-
}
|
|
2056
|
-
/**
|
|
2057
|
-
* Unregister a job by its ID.
|
|
2058
|
-
* Searches all roots if rootId is not provided.
|
|
2059
|
-
* @param {string} id - The job ID to unregister
|
|
2060
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2061
|
-
* @returns {void}
|
|
2062
|
-
*/
|
|
2063
|
-
unregister(id, rootId) {
|
|
2064
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2065
|
-
if (root?.jobs.delete(id)) {
|
|
2066
|
-
root.needsRebuild = true;
|
|
2067
|
-
this.jobStateListeners.delete(id);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Update a job's options dynamically.
|
|
2072
|
-
* Searches all roots to find the job by ID.
|
|
2073
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2074
|
-
* @param {string} id - The job ID to update
|
|
2075
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2076
|
-
* @returns {void}
|
|
2077
|
-
*/
|
|
2078
|
-
updateJob(id, options) {
|
|
2079
|
-
let job;
|
|
2080
|
-
let root;
|
|
2081
|
-
for (const r of this.roots.values()) {
|
|
2082
|
-
job = r.jobs.get(id);
|
|
2083
|
-
if (job) {
|
|
2084
|
-
root = r;
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
if (!job || !root) return;
|
|
2089
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2090
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2091
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2092
|
-
if (options.enabled !== void 0) {
|
|
2093
|
-
const wasEnabled = job.enabled;
|
|
2094
|
-
job.enabled = options.enabled;
|
|
2095
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2096
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2097
|
-
}
|
|
2098
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2099
|
-
if (options.phase) job.phase = options.phase;
|
|
2100
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2101
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2102
|
-
root.needsRebuild = true;
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
//* Job State Management Methods ================================
|
|
2106
|
-
/**
|
|
2107
|
-
* Check if a job is currently paused (disabled).
|
|
2108
|
-
* @param {string} id - The job ID to check
|
|
2109
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2110
|
-
*/
|
|
2111
|
-
isJobPaused(id) {
|
|
2112
|
-
for (const root of this.roots.values()) {
|
|
2113
|
-
const job = root.jobs.get(id);
|
|
2114
|
-
if (job) return !job.enabled;
|
|
2115
|
-
}
|
|
2116
|
-
return false;
|
|
2117
|
-
}
|
|
2118
|
-
/**
|
|
2119
|
-
* Subscribe to state changes for a specific job.
|
|
2120
|
-
* Listener is called when job is paused or resumed.
|
|
2121
|
-
* @param {string} id - The job ID to subscribe to
|
|
2122
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2123
|
-
* @returns {() => void} Unsubscribe function
|
|
2124
|
-
*/
|
|
2125
|
-
subscribeJobState(id, listener) {
|
|
2126
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2127
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2128
|
-
}
|
|
2129
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2130
|
-
return () => {
|
|
2131
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2132
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2133
|
-
this.jobStateListeners.delete(id);
|
|
2134
|
-
}
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* Notify all listeners that a job's state has changed.
|
|
2139
|
-
* @param {string} id - The job ID that changed
|
|
2140
|
-
* @returns {void}
|
|
2141
|
-
* @private
|
|
2142
|
-
*/
|
|
2143
|
-
notifyJobStateChange(id) {
|
|
2144
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2145
|
-
}
|
|
2146
|
-
/**
|
|
2147
|
-
* Pause a job by ID (sets enabled=false).
|
|
2148
|
-
* Notifies any subscribed state listeners.
|
|
2149
|
-
* @param {string} id - The job ID to pause
|
|
2150
|
-
* @returns {void}
|
|
2151
|
-
*/
|
|
2152
|
-
pauseJob(id) {
|
|
2153
|
-
this.updateJob(id, { enabled: false });
|
|
2154
|
-
this.notifyJobStateChange(id);
|
|
2155
|
-
}
|
|
2156
|
-
/**
|
|
2157
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2158
|
-
* Resets job timing to prevent frame accumulation.
|
|
2159
|
-
* Notifies any subscribed state listeners.
|
|
2160
|
-
* @param {string} id - The job ID to resume
|
|
2161
|
-
* @returns {void}
|
|
2162
|
-
*/
|
|
2163
|
-
resumeJob(id) {
|
|
2164
|
-
this.updateJob(id, { enabled: true });
|
|
2165
|
-
this.notifyJobStateChange(id);
|
|
2166
|
-
}
|
|
2167
|
-
//* Frame Loop Control Methods ================================
|
|
2168
|
-
/**
|
|
2169
|
-
* Start the requestAnimationFrame loop.
|
|
2170
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2171
|
-
* No-op if already running.
|
|
2172
|
-
* @returns {void}
|
|
2173
|
-
*/
|
|
2174
|
-
start() {
|
|
2175
|
-
if (this.loopState.running) return;
|
|
2176
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2177
|
-
let adjustedCreated = 0;
|
|
2178
|
-
if (this.stoppedTime > 0) {
|
|
2179
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2180
|
-
this.stoppedTime = 0;
|
|
2181
|
-
}
|
|
2182
|
-
Object.assign(this.loopState, {
|
|
2183
|
-
running: true,
|
|
2184
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2185
|
-
lastTime: performance.now(),
|
|
2186
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2187
|
-
frameCount: 0,
|
|
2188
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2189
|
-
});
|
|
2190
|
-
}
|
|
2191
|
-
/**
|
|
2192
|
-
* Stop the requestAnimationFrame loop.
|
|
2193
|
-
* Cancels any pending RAF callback.
|
|
2194
|
-
* No-op if not running.
|
|
2195
|
-
* @returns {void}
|
|
2196
|
-
*/
|
|
2197
|
-
stop() {
|
|
2198
|
-
if (!this.loopState.running) return;
|
|
2199
|
-
this.loopState.running = false;
|
|
2200
|
-
if (this.loopState.rafHandle !== null) {
|
|
2201
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2202
|
-
this.loopState.rafHandle = null;
|
|
2203
|
-
}
|
|
2204
|
-
this.stoppedTime = performance.now();
|
|
2205
|
-
}
|
|
2206
|
-
/**
|
|
2207
|
-
* Request frames to be rendered in demand mode.
|
|
2208
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2209
|
-
* No-op if frameloop is not 'demand'.
|
|
2210
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2211
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2212
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2213
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2214
|
-
* @returns {void}
|
|
2215
|
-
* @example
|
|
2216
|
-
* // Request a single frame render
|
|
2217
|
-
* scheduler.invalidate();
|
|
2218
|
-
*
|
|
2219
|
-
* @example
|
|
2220
|
-
* // Request 5 frames (e.g., for animations)
|
|
2221
|
-
* scheduler.invalidate(5);
|
|
2222
|
-
*
|
|
2223
|
-
* @example
|
|
2224
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2225
|
-
* scheduler.invalidate(3, false);
|
|
2226
|
-
*
|
|
2227
|
-
* @example
|
|
2228
|
-
* // Add 2 more frames to existing pending count
|
|
2229
|
-
* scheduler.invalidate(2, true);
|
|
2230
|
-
*/
|
|
2231
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2232
|
-
if (this._frameloop !== "demand") return;
|
|
2233
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2234
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2235
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2236
|
-
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Reset timing state for deterministic testing.
|
|
2239
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2240
|
-
* @returns {void}
|
|
2241
|
-
*/
|
|
2242
|
-
resetTiming() {
|
|
2243
|
-
this.loopState.lastTime = null;
|
|
2244
|
-
this.loopState.frameCount = 0;
|
|
2245
|
-
this.loopState.elapsedTime = 0;
|
|
2246
|
-
this.loopState.createdAt = performance.now();
|
|
2247
|
-
}
|
|
2248
|
-
//* Manual Stepping Methods ================================
|
|
2249
|
-
/**
|
|
2250
|
-
* Manually execute a single frame for all roots.
|
|
2251
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2252
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2253
|
-
* @returns {void}
|
|
2254
|
-
* @example
|
|
2255
|
-
* // Manual control mode
|
|
2256
|
-
* scheduler.frameloop = 'never';
|
|
2257
|
-
* scheduler.step(); // Execute one frame
|
|
2258
|
-
*/
|
|
2259
|
-
step(timestamp) {
|
|
2260
|
-
const now = timestamp ?? performance.now();
|
|
2261
|
-
this.executeFrame(now);
|
|
2262
|
-
}
|
|
2263
|
-
/**
|
|
2264
|
-
* Manually execute a single job by its ID.
|
|
2265
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2266
|
-
* @param {string} id - The job ID to step
|
|
2267
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2268
|
-
* @returns {void}
|
|
2269
|
-
*/
|
|
2270
|
-
stepJob(id, timestamp) {
|
|
2271
|
-
let job;
|
|
2272
|
-
let root;
|
|
2273
|
-
for (const r of this.roots.values()) {
|
|
2274
|
-
job = r.jobs.get(id);
|
|
2275
|
-
if (job) {
|
|
2276
|
-
root = r;
|
|
2277
|
-
break;
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
if (!job || !root) {
|
|
2281
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2282
|
-
return;
|
|
2283
|
-
}
|
|
2284
|
-
const now = timestamp ?? performance.now();
|
|
2285
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2286
|
-
const delta = deltaMs / 1e3;
|
|
2287
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2288
|
-
const providedState = root.getState?.() ?? {};
|
|
2289
|
-
const frameState = {
|
|
2290
|
-
...providedState,
|
|
2291
|
-
time: now,
|
|
2292
|
-
delta,
|
|
2293
|
-
elapsed,
|
|
2294
|
-
frame: this.loopState.frameCount
|
|
2295
|
-
};
|
|
2296
|
-
try {
|
|
2297
|
-
job.callback(frameState, delta);
|
|
2298
|
-
} catch (error) {
|
|
2299
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2300
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
/**
|
|
2304
|
-
* Execute a single frame across all roots.
|
|
2305
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2306
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2307
|
-
* @returns {void}
|
|
2308
|
-
* @private
|
|
2309
|
-
*/
|
|
2310
|
-
executeFrame(timestamp) {
|
|
2311
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2312
|
-
const delta = deltaMs / 1e3;
|
|
2313
|
-
this.loopState.lastTime = timestamp;
|
|
2314
|
-
this.loopState.frameCount++;
|
|
2315
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2316
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2317
|
-
for (const root of this.roots.values()) {
|
|
2318
|
-
this.tickRoot(root, timestamp, delta);
|
|
2319
|
-
}
|
|
2320
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2321
|
-
}
|
|
2322
|
-
/**
|
|
2323
|
-
* Run all global jobs from a job map.
|
|
2324
|
-
* Catches and logs errors without stopping execution.
|
|
2325
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2326
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2327
|
-
* @returns {void}
|
|
2328
|
-
* @private
|
|
2329
|
-
*/
|
|
2330
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2331
|
-
for (const job of jobs.values()) {
|
|
2332
|
-
try {
|
|
2333
|
-
job.callback(timestamp);
|
|
2334
|
-
} catch (error) {
|
|
2335
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
/**
|
|
2340
|
-
* Execute all jobs for a single root in sorted order.
|
|
2341
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2342
|
-
* Errors are caught and propagated via triggerError.
|
|
2343
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2344
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2345
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2346
|
-
* @returns {void}
|
|
2347
|
-
* @private
|
|
2348
|
-
*/
|
|
2349
|
-
tickRoot(root, timestamp, delta) {
|
|
2350
|
-
if (root.needsRebuild) {
|
|
2351
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2352
|
-
root.needsRebuild = false;
|
|
2353
|
-
}
|
|
2354
|
-
const providedState = root.getState?.() ?? {};
|
|
2355
|
-
const frameState = {
|
|
2356
|
-
...providedState,
|
|
2357
|
-
time: timestamp,
|
|
2358
|
-
delta,
|
|
2359
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2360
|
-
// Convert ms to seconds
|
|
2361
|
-
frame: this.loopState.frameCount
|
|
2362
|
-
};
|
|
2363
|
-
for (const job of root.sortedJobs) {
|
|
2364
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2365
|
-
try {
|
|
2366
|
-
job.callback(frameState, delta);
|
|
2367
|
-
} catch (error) {
|
|
2368
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2369
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
//* Debug & Inspection Methods ================================
|
|
2374
|
-
/**
|
|
2375
|
-
* Get the total number of registered jobs across all roots.
|
|
2376
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2377
|
-
* @returns {number} Total job count
|
|
2378
|
-
*/
|
|
2379
|
-
getJobCount() {
|
|
2380
|
-
let count = 0;
|
|
2381
|
-
for (const root of this.roots.values()) {
|
|
2382
|
-
count += root.jobs.size;
|
|
2383
|
-
}
|
|
2384
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2385
|
-
}
|
|
2386
|
-
/**
|
|
2387
|
-
* Get all registered job IDs across all roots.
|
|
2388
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2389
|
-
* @returns {string[]} Array of all job IDs
|
|
2390
|
-
*/
|
|
2391
|
-
getJobIds() {
|
|
2392
|
-
const ids = [];
|
|
2393
|
-
for (const root of this.roots.values()) {
|
|
2394
|
-
ids.push(...root.jobs.keys());
|
|
2395
|
-
}
|
|
2396
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2397
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2398
|
-
return ids;
|
|
2399
|
-
}
|
|
2400
|
-
/**
|
|
2401
|
-
* Get the number of registered roots (Canvas instances).
|
|
2402
|
-
* @returns {number} Number of registered roots
|
|
2403
|
-
*/
|
|
2404
|
-
getRootCount() {
|
|
2405
|
-
return this.roots.size;
|
|
2406
|
-
}
|
|
2407
|
-
/**
|
|
2408
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2409
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2410
|
-
*
|
|
2411
|
-
* @param phase The phase to check
|
|
2412
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2413
|
-
* @returns true if any user jobs exist in the phase
|
|
2414
|
-
*/
|
|
2415
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2416
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2417
|
-
return rootsToCheck.some((root) => {
|
|
2418
|
-
if (!root) return false;
|
|
2419
|
-
for (const job of root.jobs.values()) {
|
|
2420
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2421
|
-
}
|
|
2422
|
-
return false;
|
|
2423
|
-
});
|
|
2424
|
-
}
|
|
2425
|
-
//* Utility Methods ================================
|
|
2426
|
-
/**
|
|
2427
|
-
* Generate a unique root ID for automatic root registration.
|
|
2428
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2429
|
-
*/
|
|
2430
|
-
generateRootId() {
|
|
2431
|
-
return `root_${this.nextRootIndex++}`;
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Generate a unique job ID.
|
|
2435
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2436
|
-
* @private
|
|
2437
|
-
*/
|
|
2438
|
-
generateJobId() {
|
|
2439
|
-
return `job_${this.nextJobIndex}`;
|
|
2440
|
-
}
|
|
2441
|
-
/**
|
|
2442
|
-
* Normalize before/after constraints to a Set.
|
|
2443
|
-
* Handles undefined, single string, or array inputs.
|
|
2444
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2445
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2446
|
-
* @private
|
|
2447
|
-
*/
|
|
2448
|
-
normalizeConstraints(value) {
|
|
2449
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2450
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2451
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2452
|
-
}
|
|
2453
|
-
};
|
|
2454
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2455
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2456
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2457
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2458
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2459
|
-
let Scheduler = _Scheduler;
|
|
2460
|
-
const getScheduler = () => Scheduler.get();
|
|
2461
|
-
if (hmrData) {
|
|
2462
|
-
hmrData.accept?.();
|
|
1645
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1646
|
+
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1647
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1648
|
+
if (!stack) return false;
|
|
1649
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1650
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m)) || INTERNAL_FIBER_MARKERS.some((m) => caller.includes(m));
|
|
2463
1651
|
}
|
|
2464
1652
|
|
|
2465
1653
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2499,7 +1687,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2499
1687
|
frustum: new Frustum(),
|
|
2500
1688
|
autoUpdateFrustum: true,
|
|
2501
1689
|
raycaster: null,
|
|
2502
|
-
events: {
|
|
1690
|
+
events: {
|
|
1691
|
+
priority: 1,
|
|
1692
|
+
enabled: true,
|
|
1693
|
+
connected: false,
|
|
1694
|
+
frameTimedRaycasts: true,
|
|
1695
|
+
alwaysFireOnScroll: true,
|
|
1696
|
+
updateOnFrame: false
|
|
1697
|
+
},
|
|
2503
1698
|
scene: null,
|
|
2504
1699
|
rootScene: null,
|
|
2505
1700
|
xr: null,
|
|
@@ -2590,11 +1785,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2590
1785
|
},
|
|
2591
1786
|
setError: (error) => set(() => ({ error })),
|
|
2592
1787
|
error: null,
|
|
2593
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1788
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2594
1789
|
uniforms: {},
|
|
2595
1790
|
nodes: {},
|
|
1791
|
+
buffers: {},
|
|
1792
|
+
gpuStorage: {},
|
|
2596
1793
|
textures: /* @__PURE__ */ new Map(),
|
|
2597
|
-
|
|
1794
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1795
|
+
renderPipeline: null,
|
|
2598
1796
|
passes: {},
|
|
2599
1797
|
_hmrVersion: 0,
|
|
2600
1798
|
_sizeImperative: false,
|
|
@@ -2603,12 +1801,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2603
1801
|
internal: {
|
|
2604
1802
|
// Events
|
|
2605
1803
|
interaction: [],
|
|
2606
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2607
1804
|
subscribers: [],
|
|
1805
|
+
// Per-pointer state (new unified structure)
|
|
1806
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1807
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1808
|
+
lastEvent: React.createRef(),
|
|
1809
|
+
// Deprecated but kept for backwards compatibility
|
|
1810
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2608
1811
|
initialClick: [0, 0],
|
|
2609
1812
|
initialHits: [],
|
|
2610
1813
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2611
|
-
lastEvent: React.createRef(),
|
|
2612
1814
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2613
1815
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2614
1816
|
// Occlusion system (WebGPU only)
|
|
@@ -2647,8 +1849,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2647
1849
|
const currentState = rootStore.getState();
|
|
2648
1850
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2649
1851
|
const stack = new Error().stack || "";
|
|
2650
|
-
|
|
2651
|
-
if (!isInternalAccess) {
|
|
1852
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2652
1853
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2653
1854
|
notifyDepreciated({
|
|
2654
1855
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -2696,14 +1897,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2696
1897
|
oldSize = size;
|
|
2697
1898
|
oldDpr = viewport.dpr;
|
|
2698
1899
|
updateCamera(camera, size);
|
|
2699
|
-
if (canvasTarget) {
|
|
1900
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2700
1901
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2701
|
-
|
|
2702
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1902
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2703
1903
|
} else {
|
|
2704
1904
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2705
|
-
|
|
2706
|
-
|
|
1905
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1906
|
+
if (canvasTarget) {
|
|
1907
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1908
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1909
|
+
}
|
|
2707
1910
|
}
|
|
2708
1911
|
}
|
|
2709
1912
|
if (camera !== oldCamera) {
|
|
@@ -2759,19 +1962,25 @@ function loadingFn(extensions, onProgress) {
|
|
|
2759
1962
|
);
|
|
2760
1963
|
};
|
|
2761
1964
|
}
|
|
2762
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
2763
|
-
const
|
|
1965
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1966
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1967
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2764
1968
|
const fn = loadingFn(extensions, onProgress);
|
|
2765
|
-
const results =
|
|
1969
|
+
const results = cacheKeys.map(
|
|
1970
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1971
|
+
);
|
|
2766
1972
|
return Array.isArray(input) ? results : results[0];
|
|
2767
1973
|
}
|
|
2768
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
2769
|
-
const
|
|
2770
|
-
|
|
1974
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1975
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1976
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1977
|
+
cacheKeys.forEach(
|
|
1978
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1979
|
+
);
|
|
2771
1980
|
};
|
|
2772
|
-
useLoader.clear = function(loader, input) {
|
|
2773
|
-
const
|
|
2774
|
-
|
|
1981
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1982
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1983
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
2775
1984
|
};
|
|
2776
1985
|
useLoader.loader = getLoader;
|
|
2777
1986
|
|
|
@@ -2847,20 +2056,14 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2847
2056
|
}
|
|
2848
2057
|
};
|
|
2849
2058
|
} else {
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
unregisterJob = registerOutside();
|
|
2859
|
-
});
|
|
2860
|
-
return () => {
|
|
2861
|
-
unsubReady();
|
|
2862
|
-
unregisterJob?.();
|
|
2863
|
-
};
|
|
2059
|
+
return scheduler.register(
|
|
2060
|
+
(state, delta) => {
|
|
2061
|
+
const frameState = state;
|
|
2062
|
+
if (!frameState.renderer) return;
|
|
2063
|
+
callbackRef.current?.(frameState, delta);
|
|
2064
|
+
},
|
|
2065
|
+
{ id, ...options }
|
|
2066
|
+
);
|
|
2864
2067
|
}
|
|
2865
2068
|
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2866
2069
|
const isPaused = React.useSyncExternalStore(
|
|
@@ -2951,18 +2154,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2951
2154
|
function useTexture(input, optionsOrOnLoad) {
|
|
2952
2155
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2953
2156
|
const store = useStore();
|
|
2954
|
-
const textureCache = useThree((state) => state.textures);
|
|
2955
2157
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2956
|
-
const { onLoad, cache =
|
|
2158
|
+
const { onLoad, cache = true } = options;
|
|
2957
2159
|
const onLoadRef = useRef(onLoad);
|
|
2958
2160
|
onLoadRef.current = onLoad;
|
|
2959
2161
|
const onLoadCalledForRef = useRef(null);
|
|
2960
2162
|
const urls = useMemo(() => getUrls(input), [input]);
|
|
2961
2163
|
const cachedResult = useMemo(() => {
|
|
2962
2164
|
if (!cache) return null;
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2165
|
+
const textures = store.getState().textures;
|
|
2166
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2167
|
+
return buildFromCache(input, textures);
|
|
2168
|
+
}, [cache, urls, input, store]);
|
|
2966
2169
|
const loadedTextures = useLoader(
|
|
2967
2170
|
TextureLoader,
|
|
2968
2171
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3006,8 +2209,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3006
2209
|
}, [input, loadedTextures, cachedResult]);
|
|
3007
2210
|
useEffect(() => {
|
|
3008
2211
|
if (!cache) return;
|
|
3009
|
-
if (cachedResult) return;
|
|
3010
|
-
const set = store.setState;
|
|
3011
2212
|
const urlTextureMap = [];
|
|
3012
2213
|
if (typeof input === "string") {
|
|
3013
2214
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3021,18 +2222,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3021
2222
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3022
2223
|
}
|
|
3023
2224
|
}
|
|
3024
|
-
|
|
3025
|
-
const
|
|
3026
|
-
let
|
|
2225
|
+
store.setState((state) => {
|
|
2226
|
+
const refs = new Map(state._textureRefs);
|
|
2227
|
+
let textures = state.textures;
|
|
2228
|
+
let added = false;
|
|
3027
2229
|
for (const [url, texture] of urlTextureMap) {
|
|
3028
|
-
if (!
|
|
3029
|
-
|
|
3030
|
-
|
|
2230
|
+
if (!textures.has(url)) {
|
|
2231
|
+
if (!added) {
|
|
2232
|
+
textures = new Map(textures);
|
|
2233
|
+
added = true;
|
|
2234
|
+
}
|
|
2235
|
+
textures.set(url, texture);
|
|
3031
2236
|
}
|
|
2237
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3032
2238
|
}
|
|
3033
|
-
return
|
|
2239
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
3034
2240
|
});
|
|
3035
|
-
|
|
2241
|
+
return () => store.setState((state) => {
|
|
2242
|
+
const refs = new Map(state._textureRefs);
|
|
2243
|
+
for (const [url] of urlTextureMap) {
|
|
2244
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2245
|
+
if (next <= 0) refs.delete(url);
|
|
2246
|
+
else refs.set(url, next);
|
|
2247
|
+
}
|
|
2248
|
+
return { _textureRefs: refs };
|
|
2249
|
+
});
|
|
2250
|
+
}, [cache, input, mappedTextures, store]);
|
|
3036
2251
|
return mappedTextures;
|
|
3037
2252
|
}
|
|
3038
2253
|
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
@@ -3048,96 +2263,63 @@ const Texture = ({
|
|
|
3048
2263
|
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
3049
2264
|
};
|
|
3050
2265
|
|
|
3051
|
-
function
|
|
3052
|
-
if (entry instanceof Texture$1) return entry;
|
|
3053
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof Texture$1) {
|
|
3054
|
-
return entry.value;
|
|
3055
|
-
}
|
|
3056
|
-
return null;
|
|
3057
|
-
}
|
|
3058
|
-
function useTextures() {
|
|
2266
|
+
function useTextures(selector) {
|
|
3059
2267
|
const store = useStore();
|
|
3060
|
-
|
|
3061
|
-
const set = store.setState;
|
|
2268
|
+
const registry = useMemo(() => {
|
|
3062
2269
|
const getState = store.getState;
|
|
3063
|
-
const
|
|
3064
|
-
|
|
3065
|
-
const newMap = new Map(state.textures);
|
|
3066
|
-
newMap.set(key, value);
|
|
3067
|
-
return { textures: newMap };
|
|
3068
|
-
});
|
|
3069
|
-
};
|
|
3070
|
-
const addMultiple = (items) => {
|
|
3071
|
-
set((state) => {
|
|
3072
|
-
const newMap = new Map(state.textures);
|
|
3073
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3074
|
-
for (const [key, value] of entries) {
|
|
3075
|
-
newMap.set(key, value);
|
|
3076
|
-
}
|
|
3077
|
-
return { textures: newMap };
|
|
3078
|
-
});
|
|
3079
|
-
};
|
|
3080
|
-
const remove = (key) => {
|
|
3081
|
-
set((state) => {
|
|
3082
|
-
const newMap = new Map(state.textures);
|
|
3083
|
-
newMap.delete(key);
|
|
3084
|
-
return { textures: newMap };
|
|
3085
|
-
});
|
|
3086
|
-
};
|
|
3087
|
-
const removeMultiple = (keys) => {
|
|
3088
|
-
set((state) => {
|
|
3089
|
-
const newMap = new Map(state.textures);
|
|
3090
|
-
for (const key of keys) newMap.delete(key);
|
|
3091
|
-
return { textures: newMap };
|
|
3092
|
-
});
|
|
3093
|
-
};
|
|
3094
|
-
const dispose = (key) => {
|
|
3095
|
-
const entry = getState().textures.get(key);
|
|
3096
|
-
if (entry) {
|
|
3097
|
-
const tex = getTextureValue(entry);
|
|
3098
|
-
tex?.dispose();
|
|
3099
|
-
}
|
|
3100
|
-
remove(key);
|
|
3101
|
-
};
|
|
3102
|
-
const disposeMultiple = (keys) => {
|
|
3103
|
-
const textures = getState().textures;
|
|
3104
|
-
for (const key of keys) {
|
|
3105
|
-
const entry = textures.get(key);
|
|
3106
|
-
if (entry) {
|
|
3107
|
-
const tex = getTextureValue(entry);
|
|
3108
|
-
tex?.dispose();
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
removeMultiple(keys);
|
|
3112
|
-
};
|
|
3113
|
-
const disposeAll = () => {
|
|
3114
|
-
const textures = getState().textures;
|
|
3115
|
-
for (const entry of textures.values()) {
|
|
3116
|
-
const tex = getTextureValue(entry);
|
|
3117
|
-
tex?.dispose();
|
|
3118
|
-
}
|
|
3119
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3120
|
-
};
|
|
2270
|
+
const setState = store.setState;
|
|
2271
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3121
2272
|
return {
|
|
3122
|
-
|
|
3123
|
-
get textures() {
|
|
2273
|
+
get all() {
|
|
3124
2274
|
return getState().textures;
|
|
3125
2275
|
},
|
|
3126
|
-
|
|
3127
|
-
|
|
2276
|
+
get(input) {
|
|
2277
|
+
if (typeof input === "string") return getOne(input);
|
|
2278
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2279
|
+
const out = {};
|
|
2280
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2281
|
+
return out;
|
|
2282
|
+
},
|
|
3128
2283
|
has: (key) => getState().textures.has(key),
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
2284
|
+
add(keyOrRecord, texture) {
|
|
2285
|
+
setState((state) => {
|
|
2286
|
+
const textures = new Map(state.textures);
|
|
2287
|
+
if (typeof keyOrRecord === "string") {
|
|
2288
|
+
textures.set(keyOrRecord, texture);
|
|
2289
|
+
} else {
|
|
2290
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2291
|
+
}
|
|
2292
|
+
return { textures };
|
|
2293
|
+
});
|
|
2294
|
+
},
|
|
2295
|
+
dispose(key, options) {
|
|
2296
|
+
const state = getState();
|
|
2297
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2298
|
+
if (refs > 0 && !options?.force) {
|
|
2299
|
+
console.warn(
|
|
2300
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2301
|
+
);
|
|
2302
|
+
return false;
|
|
2303
|
+
}
|
|
2304
|
+
state.textures.get(key)?.dispose();
|
|
2305
|
+
setState((s) => {
|
|
2306
|
+
const textures = new Map(s.textures);
|
|
2307
|
+
textures.delete(key);
|
|
2308
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2309
|
+
nextRefs.delete(key);
|
|
2310
|
+
return { textures, _textureRefs: nextRefs };
|
|
2311
|
+
});
|
|
2312
|
+
return true;
|
|
2313
|
+
},
|
|
2314
|
+
disposeAll() {
|
|
2315
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2316
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2317
|
+
}
|
|
3139
2318
|
};
|
|
3140
2319
|
}, [store]);
|
|
2320
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2321
|
+
const selected = useThree(subscribe);
|
|
2322
|
+
return selector ? selected : registry;
|
|
3141
2323
|
}
|
|
3142
2324
|
|
|
3143
2325
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -14659,6 +13841,7 @@ function swapInstances() {
|
|
|
14659
13841
|
}
|
|
14660
13842
|
}
|
|
14661
13843
|
if (instance.isHidden) unhideInstance(instance);
|
|
13844
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14662
13845
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14663
13846
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14664
13847
|
}
|
|
@@ -14671,6 +13854,8 @@ function swapInstances() {
|
|
|
14671
13854
|
instance.object.__r3f = instance;
|
|
14672
13855
|
setFiberRef(fiber, instance.object);
|
|
14673
13856
|
delete instance.appliedOnce;
|
|
13857
|
+
instance.eventCount = 0;
|
|
13858
|
+
instance.handlers = {};
|
|
14674
13859
|
applyProps(instance.object, instance.props);
|
|
14675
13860
|
if (instance.props.attach) {
|
|
14676
13861
|
attach(parent, instance);
|
|
@@ -14975,6 +14160,7 @@ function createRoot(canvas) {
|
|
|
14975
14160
|
const lastConfiguredProps = {};
|
|
14976
14161
|
let configured = false;
|
|
14977
14162
|
let pending = null;
|
|
14163
|
+
let rendererSetup = null;
|
|
14978
14164
|
return {
|
|
14979
14165
|
async configure(props = {}) {
|
|
14980
14166
|
let resolve;
|
|
@@ -14990,7 +14176,6 @@ function createRoot(canvas) {
|
|
|
14990
14176
|
events,
|
|
14991
14177
|
onCreated: onCreatedCallback,
|
|
14992
14178
|
shadows = false,
|
|
14993
|
-
textureColorSpace = SRGBColorSpace,
|
|
14994
14179
|
orthographic = false,
|
|
14995
14180
|
frameloop = "always",
|
|
14996
14181
|
dpr = [1, 2],
|
|
@@ -15005,7 +14190,8 @@ function createRoot(canvas) {
|
|
|
15005
14190
|
_sizeProps,
|
|
15006
14191
|
forceEven
|
|
15007
14192
|
} = props;
|
|
15008
|
-
const
|
|
14193
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
14194
|
+
let state = store.getState();
|
|
15009
14195
|
const defaultGLProps = {
|
|
15010
14196
|
canvas,
|
|
15011
14197
|
powerPreference: "high-performance",
|
|
@@ -15033,50 +14219,68 @@ function createRoot(canvas) {
|
|
|
15033
14219
|
"The `primaryCanvas` prop for multi-canvas rendering cannot be used with WebGL. Remove the `gl` prop or use WebGPU."
|
|
15034
14220
|
);
|
|
15035
14221
|
}
|
|
15036
|
-
if (
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
14222
|
+
if (!state.internal.actualRenderer) {
|
|
14223
|
+
if (!rendererSetup) {
|
|
14224
|
+
rendererSetup = (async () => {
|
|
14225
|
+
if (wantsGL) {
|
|
14226
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, WebGLRenderer);
|
|
14227
|
+
state.internal.actualRenderer = renderer;
|
|
14228
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14229
|
+
} else if (!wantsGL && primaryCanvas) {
|
|
14230
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14231
|
+
renderer = primary.renderer;
|
|
14232
|
+
state.internal.actualRenderer = renderer;
|
|
14233
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14234
|
+
primary.store.setState((prev) => ({
|
|
14235
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14236
|
+
}));
|
|
14237
|
+
state.set((prev) => ({
|
|
14238
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14239
|
+
renderer,
|
|
14240
|
+
primaryStore: primary.store,
|
|
14241
|
+
internal: {
|
|
14242
|
+
...prev.internal,
|
|
14243
|
+
canvasTarget,
|
|
14244
|
+
isMultiCanvas: true,
|
|
14245
|
+
isSecondary: true,
|
|
14246
|
+
targetId: primaryCanvas
|
|
14247
|
+
}
|
|
14248
|
+
}));
|
|
14249
|
+
} else if (!wantsGL) {
|
|
14250
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, WebGPURenderer);
|
|
14251
|
+
if (!renderer.hasInitialized?.()) {
|
|
14252
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14253
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14254
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14255
|
+
canvas.width = size2.width * pixelRatio;
|
|
14256
|
+
canvas.height = size2.height * pixelRatio;
|
|
14257
|
+
}
|
|
14258
|
+
await renderer.init();
|
|
14259
|
+
}
|
|
14260
|
+
const backend = renderer.backend;
|
|
14261
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14262
|
+
state.internal.actualRenderer = renderer;
|
|
14263
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14264
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14265
|
+
const canvasTarget = new CanvasTarget(canvas);
|
|
14266
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14267
|
+
state.set((prev) => ({
|
|
14268
|
+
internal: {
|
|
14269
|
+
...prev.internal,
|
|
14270
|
+
canvasTarget,
|
|
14271
|
+
unregisterPrimary
|
|
14272
|
+
}
|
|
14273
|
+
}));
|
|
14274
|
+
}
|
|
15077
14275
|
}
|
|
15078
|
-
}))
|
|
14276
|
+
})().catch((err) => {
|
|
14277
|
+
rendererSetup = null;
|
|
14278
|
+
throw err;
|
|
14279
|
+
});
|
|
15079
14280
|
}
|
|
14281
|
+
await rendererSetup;
|
|
14282
|
+
state = store.getState();
|
|
14283
|
+
renderer = state.internal.actualRenderer;
|
|
15080
14284
|
}
|
|
15081
14285
|
let raycaster = state.raycaster;
|
|
15082
14286
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
@@ -15169,7 +14373,7 @@ function createRoot(canvas) {
|
|
|
15169
14373
|
lastConfiguredProps.performance = performance;
|
|
15170
14374
|
}
|
|
15171
14375
|
if (!state.xr) {
|
|
15172
|
-
const handleXRFrame = (timestamp,
|
|
14376
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15173
14377
|
const state2 = store.getState();
|
|
15174
14378
|
if (state2.frameloop === "never") return;
|
|
15175
14379
|
advance(timestamp);
|
|
@@ -15205,15 +14409,22 @@ function createRoot(canvas) {
|
|
|
15205
14409
|
const oldType = renderer.shadowMap.type;
|
|
15206
14410
|
renderer.shadowMap.enabled = !!shadows;
|
|
15207
14411
|
if (is.boo(shadows)) {
|
|
15208
|
-
renderer.shadowMap.type =
|
|
14412
|
+
renderer.shadowMap.type = PCFShadowMap;
|
|
15209
14413
|
} else if (is.str(shadows)) {
|
|
14414
|
+
if (shadows === "soft") {
|
|
14415
|
+
notifyDepreciated({
|
|
14416
|
+
heading: 'shadows="soft" is deprecated',
|
|
14417
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14418
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14419
|
+
});
|
|
14420
|
+
}
|
|
15210
14421
|
const types = {
|
|
15211
14422
|
basic: BasicShadowMap,
|
|
15212
14423
|
percentage: PCFShadowMap,
|
|
15213
|
-
soft:
|
|
14424
|
+
soft: PCFShadowMap,
|
|
15214
14425
|
variance: VSMShadowMap
|
|
15215
14426
|
};
|
|
15216
|
-
renderer.shadowMap.type = types[shadows] ??
|
|
14427
|
+
renderer.shadowMap.type = types[shadows] ?? PCFShadowMap;
|
|
15217
14428
|
} else if (is.obj(shadows)) {
|
|
15218
14429
|
Object.assign(renderer.shadowMap, shadows);
|
|
15219
14430
|
}
|
|
@@ -15229,13 +14440,24 @@ function createRoot(canvas) {
|
|
|
15229
14440
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15230
14441
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15231
14442
|
}
|
|
14443
|
+
const r3fProps = ["textureColorSpace"];
|
|
14444
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14445
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15232
14446
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15233
|
-
|
|
14447
|
+
const glProps = {};
|
|
14448
|
+
for (const key in glConfig) {
|
|
14449
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14450
|
+
}
|
|
14451
|
+
applyProps(renderer, glProps);
|
|
15234
14452
|
}
|
|
15235
14453
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15236
14454
|
const currentRenderer = state.renderer;
|
|
15237
14455
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15238
|
-
|
|
14456
|
+
const rendererProps = {};
|
|
14457
|
+
for (const key in rendererConfig) {
|
|
14458
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14459
|
+
}
|
|
14460
|
+
applyProps(currentRenderer, rendererProps);
|
|
15239
14461
|
}
|
|
15240
14462
|
}
|
|
15241
14463
|
const scheduler = getScheduler();
|
|
@@ -15261,6 +14483,18 @@ function createRoot(canvas) {
|
|
|
15261
14483
|
system: true
|
|
15262
14484
|
}
|
|
15263
14485
|
);
|
|
14486
|
+
const unregisterEventsFlush = scheduler.register(
|
|
14487
|
+
() => {
|
|
14488
|
+
const state2 = store.getState();
|
|
14489
|
+
state2.events.flush?.();
|
|
14490
|
+
},
|
|
14491
|
+
{
|
|
14492
|
+
id: `${newRootId}_events`,
|
|
14493
|
+
rootId: newRootId,
|
|
14494
|
+
phase: "input",
|
|
14495
|
+
system: true
|
|
14496
|
+
}
|
|
14497
|
+
);
|
|
15264
14498
|
const unregisterFrustum = scheduler.register(
|
|
15265
14499
|
() => {
|
|
15266
14500
|
const state2 = store.getState();
|
|
@@ -15271,7 +14505,7 @@ function createRoot(canvas) {
|
|
|
15271
14505
|
{
|
|
15272
14506
|
id: `${newRootId}_frustum`,
|
|
15273
14507
|
rootId: newRootId,
|
|
15274
|
-
|
|
14508
|
+
before: "render",
|
|
15275
14509
|
system: true
|
|
15276
14510
|
}
|
|
15277
14511
|
);
|
|
@@ -15283,7 +14517,7 @@ function createRoot(canvas) {
|
|
|
15283
14517
|
{
|
|
15284
14518
|
id: `${newRootId}_visibility`,
|
|
15285
14519
|
rootId: newRootId,
|
|
15286
|
-
|
|
14520
|
+
before: "render",
|
|
15287
14521
|
system: true,
|
|
15288
14522
|
after: `${newRootId}_frustum`
|
|
15289
14523
|
}
|
|
@@ -15295,7 +14529,7 @@ function createRoot(canvas) {
|
|
|
15295
14529
|
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
15296
14530
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15297
14531
|
try {
|
|
15298
|
-
if (state2.
|
|
14532
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15299
14533
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15300
14534
|
} catch (error) {
|
|
15301
14535
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15320,6 +14554,7 @@ function createRoot(canvas) {
|
|
|
15320
14554
|
unregisterRoot: () => {
|
|
15321
14555
|
unregisterRoot();
|
|
15322
14556
|
unregisterCanvasTarget();
|
|
14557
|
+
unregisterEventsFlush();
|
|
15323
14558
|
unregisterFrustum();
|
|
15324
14559
|
unregisterVisibility();
|
|
15325
14560
|
unregisterRender();
|
|
@@ -15458,6 +14693,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15458
14693
|
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
15459
14694
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15460
14695
|
}
|
|
14696
|
+
const set = injectState.set;
|
|
15461
14697
|
return {
|
|
15462
14698
|
// The intersect consists of the previous root state
|
|
15463
14699
|
...rootState,
|
|
@@ -15476,7 +14712,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15476
14712
|
size: resolvedSize,
|
|
15477
14713
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15478
14714
|
// Layers are allowed to override events
|
|
15479
|
-
setEvents: (events2) =>
|
|
14715
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15480
14716
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15481
14717
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15482
14718
|
};
|
|
@@ -15485,9 +14721,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15485
14721
|
const store = createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15486
14722
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15487
14723
|
onMutate(previousRoot.getState());
|
|
15488
|
-
previousRoot.subscribe(onMutate);
|
|
15489
14724
|
return store;
|
|
15490
14725
|
}, [previousRoot, container]);
|
|
14726
|
+
useIsomorphicLayoutEffect(() => {
|
|
14727
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14728
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14729
|
+
return unsubscribe;
|
|
14730
|
+
}, [previousRoot, usePortalStore]);
|
|
15491
14731
|
return (
|
|
15492
14732
|
// @ts-ignore, reconciler types are not maintained
|
|
15493
14733
|
/* @__PURE__ */ jsx(Fragment, { children: reconciler.createPortal(
|
|
@@ -15501,6 +14741,59 @@ function flushSync(fn) {
|
|
|
15501
14741
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15502
14742
|
}
|
|
15503
14743
|
|
|
14744
|
+
function parseBackground(background) {
|
|
14745
|
+
if (!background) return null;
|
|
14746
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14747
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14748
|
+
return {
|
|
14749
|
+
...rest,
|
|
14750
|
+
preset,
|
|
14751
|
+
files: envMap || files,
|
|
14752
|
+
backgroundFiles: backgroundMap,
|
|
14753
|
+
background: true
|
|
14754
|
+
};
|
|
14755
|
+
}
|
|
14756
|
+
if (typeof background === "number") {
|
|
14757
|
+
return { color: background, background: true };
|
|
14758
|
+
}
|
|
14759
|
+
if (typeof background === "string") {
|
|
14760
|
+
if (background in presetsObj) {
|
|
14761
|
+
return { preset: background, background: true };
|
|
14762
|
+
}
|
|
14763
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14764
|
+
return { files: background, background: true };
|
|
14765
|
+
}
|
|
14766
|
+
return { color: background, background: true };
|
|
14767
|
+
}
|
|
14768
|
+
if (background.isColor) {
|
|
14769
|
+
return { color: background, background: true };
|
|
14770
|
+
}
|
|
14771
|
+
return null;
|
|
14772
|
+
}
|
|
14773
|
+
|
|
14774
|
+
function parseRendererConfig(rendererProp) {
|
|
14775
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14776
|
+
if (isRendererConfig) {
|
|
14777
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14778
|
+
return {
|
|
14779
|
+
primaryCanvas: pc,
|
|
14780
|
+
scheduler: sc,
|
|
14781
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14782
|
+
};
|
|
14783
|
+
}
|
|
14784
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14785
|
+
}
|
|
14786
|
+
|
|
14787
|
+
function clearHmrCaches(store) {
|
|
14788
|
+
store.setState((state) => ({
|
|
14789
|
+
nodes: {},
|
|
14790
|
+
uniforms: {},
|
|
14791
|
+
buffers: {},
|
|
14792
|
+
gpuStorage: {},
|
|
14793
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14794
|
+
}));
|
|
14795
|
+
}
|
|
14796
|
+
|
|
15504
14797
|
function CanvasImpl({
|
|
15505
14798
|
ref,
|
|
15506
14799
|
children,
|
|
@@ -15521,6 +14814,8 @@ function CanvasImpl({
|
|
|
15521
14814
|
raycaster,
|
|
15522
14815
|
camera,
|
|
15523
14816
|
scene,
|
|
14817
|
+
autoUpdateFrustum,
|
|
14818
|
+
occlusion,
|
|
15524
14819
|
onPointerMissed,
|
|
15525
14820
|
onDragOverMissed,
|
|
15526
14821
|
onDropMissed,
|
|
@@ -15532,39 +14827,10 @@ function CanvasImpl({
|
|
|
15532
14827
|
forceEven,
|
|
15533
14828
|
...props
|
|
15534
14829
|
}) {
|
|
15535
|
-
const { primaryCanvas, scheduler,
|
|
15536
|
-
const renderer = Object.keys(rendererConfig).length > 0 ? rendererConfig : rendererProp;
|
|
14830
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15537
14831
|
React.useMemo(() => extend(THREE), []);
|
|
15538
14832
|
const Bridge = useBridge();
|
|
15539
|
-
const backgroundProps = React.useMemo(() =>
|
|
15540
|
-
if (!background) return null;
|
|
15541
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15542
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15543
|
-
return {
|
|
15544
|
-
...rest,
|
|
15545
|
-
preset,
|
|
15546
|
-
files: envMap || files,
|
|
15547
|
-
backgroundFiles: backgroundMap,
|
|
15548
|
-
background: true
|
|
15549
|
-
};
|
|
15550
|
-
}
|
|
15551
|
-
if (typeof background === "number") {
|
|
15552
|
-
return { color: background, background: true };
|
|
15553
|
-
}
|
|
15554
|
-
if (typeof background === "string") {
|
|
15555
|
-
if (background in presetsObj) {
|
|
15556
|
-
return { preset: background, background: true };
|
|
15557
|
-
}
|
|
15558
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15559
|
-
return { files: background, background: true };
|
|
15560
|
-
}
|
|
15561
|
-
return { color: background, background: true };
|
|
15562
|
-
}
|
|
15563
|
-
if (background.isColor) {
|
|
15564
|
-
return { color: background, background: true };
|
|
15565
|
-
}
|
|
15566
|
-
return null;
|
|
15567
|
-
}, [background]);
|
|
14833
|
+
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15568
14834
|
const hasInitialSizeRef = React.useRef(false);
|
|
15569
14835
|
const measureConfig = React.useMemo(() => {
|
|
15570
14836
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15606,6 +14872,7 @@ function CanvasImpl({
|
|
|
15606
14872
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15607
14873
|
const [block, setBlock] = React.useState(false);
|
|
15608
14874
|
const [error, setError] = React.useState(false);
|
|
14875
|
+
const [fallbackVisible, setFallbackVisible] = React.useState(false);
|
|
15609
14876
|
if (block) throw block;
|
|
15610
14877
|
if (error) throw error;
|
|
15611
14878
|
const root = React.useRef(null);
|
|
@@ -15613,6 +14880,7 @@ function CanvasImpl({
|
|
|
15613
14880
|
const unsubscribeErrorRef = React.useRef(null);
|
|
15614
14881
|
useIsomorphicLayoutEffect(() => {
|
|
15615
14882
|
effectActiveRef.current = true;
|
|
14883
|
+
if (fallbackVisible) return;
|
|
15616
14884
|
const canvas = canvasRef.current;
|
|
15617
14885
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15618
14886
|
if (!root.current) {
|
|
@@ -15633,7 +14901,7 @@ function CanvasImpl({
|
|
|
15633
14901
|
}
|
|
15634
14902
|
async function run() {
|
|
15635
14903
|
if (!effectActiveRef.current || !root.current) return;
|
|
15636
|
-
await root.current.configure({
|
|
14904
|
+
const configured = await root.current.configure({
|
|
15637
14905
|
id,
|
|
15638
14906
|
primaryCanvas,
|
|
15639
14907
|
scheduler,
|
|
@@ -15648,6 +14916,8 @@ function CanvasImpl({
|
|
|
15648
14916
|
performance,
|
|
15649
14917
|
raycaster,
|
|
15650
14918
|
camera,
|
|
14919
|
+
autoUpdateFrustum,
|
|
14920
|
+
occlusion,
|
|
15651
14921
|
size: effectiveSize,
|
|
15652
14922
|
// Store size props for reset functionality
|
|
15653
14923
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15672,8 +14942,20 @@ function CanvasImpl({
|
|
|
15672
14942
|
}
|
|
15673
14943
|
onCreated?.(state);
|
|
15674
14944
|
}
|
|
15675
|
-
})
|
|
15676
|
-
|
|
14945
|
+
}).then(
|
|
14946
|
+
() => true,
|
|
14947
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
14948
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
14949
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
14950
|
+
(setupError) => {
|
|
14951
|
+
if (effectActiveRef.current) {
|
|
14952
|
+
if (fallback != null) setFallbackVisible(true);
|
|
14953
|
+
else setError(setupError);
|
|
14954
|
+
}
|
|
14955
|
+
return false;
|
|
14956
|
+
}
|
|
14957
|
+
);
|
|
14958
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15677
14959
|
root.current.render(
|
|
15678
14960
|
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
15679
14961
|
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
@@ -15707,20 +14989,13 @@ function CanvasImpl({
|
|
|
15707
14989
|
const handleHMR = () => {
|
|
15708
14990
|
queueMicrotask(() => {
|
|
15709
14991
|
const rootEntry = _roots.get(canvas);
|
|
15710
|
-
if (rootEntry?.store)
|
|
15711
|
-
rootEntry.store.setState((state) => ({
|
|
15712
|
-
nodes: {},
|
|
15713
|
-
uniforms: {},
|
|
15714
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15715
|
-
}));
|
|
15716
|
-
}
|
|
14992
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15717
14993
|
});
|
|
15718
14994
|
};
|
|
15719
14995
|
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
15720
14996
|
const hot = import.meta.hot;
|
|
15721
14997
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15722
|
-
return () => hot.
|
|
15723
|
-
});
|
|
14998
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15724
14999
|
}
|
|
15725
15000
|
if (typeof module !== "undefined" && module.hot) {
|
|
15726
15001
|
const hot = module.hot;
|
|
@@ -15743,7 +15018,20 @@ function CanvasImpl({
|
|
|
15743
15018
|
...style
|
|
15744
15019
|
},
|
|
15745
15020
|
...props,
|
|
15746
|
-
children:
|
|
15021
|
+
children: fallbackVisible ? (
|
|
15022
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15023
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15024
|
+
fallback
|
|
15025
|
+
) : /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
15026
|
+
"canvas",
|
|
15027
|
+
{
|
|
15028
|
+
ref: canvasRef,
|
|
15029
|
+
id,
|
|
15030
|
+
className: "r3f-canvas",
|
|
15031
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
15032
|
+
children: fallback
|
|
15033
|
+
}
|
|
15034
|
+
) })
|
|
15747
15035
|
}
|
|
15748
15036
|
);
|
|
15749
15037
|
}
|
|
@@ -15753,4 +15041,4 @@ function Canvas(props) {
|
|
|
15753
15041
|
|
|
15754
15042
|
extend(THREE);
|
|
15755
15043
|
|
|
15756
|
-
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS,
|
|
15044
|
+
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, 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, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
|