@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/legacy.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js'
|
|
|
13
13
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
14
14
|
const Tb = require('scheduler');
|
|
15
15
|
const traditional = require('zustand/traditional');
|
|
16
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
16
17
|
const suspendReact = require('suspend-react');
|
|
17
18
|
|
|
18
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -169,7 +170,7 @@ function useEnvironment({
|
|
|
169
170
|
fiber.useLoader.clear(loader, multiFile ? [files] : files);
|
|
170
171
|
}
|
|
171
172
|
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
172
|
-
}, [files, renderer.domElement]);
|
|
173
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
173
174
|
const loaderResult = fiber.useLoader(
|
|
174
175
|
loader,
|
|
175
176
|
multiFile ? [files] : files,
|
|
@@ -369,7 +370,22 @@ function EnvironmentPortal({
|
|
|
369
370
|
environmentIntensity,
|
|
370
371
|
environmentRotation
|
|
371
372
|
});
|
|
372
|
-
}, [
|
|
373
|
+
}, [
|
|
374
|
+
children,
|
|
375
|
+
virtualScene,
|
|
376
|
+
fbo.texture,
|
|
377
|
+
scene,
|
|
378
|
+
defaultScene,
|
|
379
|
+
background,
|
|
380
|
+
frames,
|
|
381
|
+
gl,
|
|
382
|
+
blur,
|
|
383
|
+
backgroundBlurriness,
|
|
384
|
+
backgroundIntensity,
|
|
385
|
+
backgroundRotation,
|
|
386
|
+
environmentIntensity,
|
|
387
|
+
environmentRotation
|
|
388
|
+
]);
|
|
373
389
|
let count = 1;
|
|
374
390
|
fiber.useFrame(() => {
|
|
375
391
|
if (frames === Infinity || count < frames) {
|
|
@@ -440,9 +456,9 @@ function Environment(props) {
|
|
|
440
456
|
return props.ground ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props });
|
|
441
457
|
}
|
|
442
458
|
|
|
443
|
-
var __defProp
|
|
444
|
-
var __defNormalProp
|
|
445
|
-
var __publicField
|
|
459
|
+
var __defProp = Object.defineProperty;
|
|
460
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
461
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
446
462
|
const act = React__namespace["act"];
|
|
447
463
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
448
464
|
function useMutableCallback(fn) {
|
|
@@ -474,7 +490,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
474
490
|
return _a = class extends React__namespace.Component {
|
|
475
491
|
constructor() {
|
|
476
492
|
super(...arguments);
|
|
477
|
-
__publicField
|
|
493
|
+
__publicField(this, "state", { error: false });
|
|
478
494
|
}
|
|
479
495
|
componentDidCatch(err) {
|
|
480
496
|
this.props.set(err);
|
|
@@ -482,7 +498,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
482
498
|
render() {
|
|
483
499
|
return this.state.error ? null : this.props.children;
|
|
484
500
|
}
|
|
485
|
-
}, __publicField
|
|
501
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
486
502
|
})();
|
|
487
503
|
|
|
488
504
|
const is = {
|
|
@@ -1003,8 +1019,24 @@ function applyProps(object, props) {
|
|
|
1003
1019
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1004
1020
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1005
1021
|
else target.set(value);
|
|
1022
|
+
} else if (root instanceof three.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1023
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1024
|
+
const uniforms = root.uniforms;
|
|
1025
|
+
const nextUniforms = value;
|
|
1026
|
+
for (const name in nextUniforms) {
|
|
1027
|
+
const uniform = nextUniforms[name];
|
|
1028
|
+
const targetUniform = uniforms[name];
|
|
1029
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1030
|
+
else {
|
|
1031
|
+
const nextUniform = uniform instanceof three.Uniform ? uniform.clone() : new three.Uniform(uniform.value);
|
|
1032
|
+
uniforms[name] = nextUniform;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1006
1035
|
} else {
|
|
1007
1036
|
root[key] = value;
|
|
1037
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1038
|
+
root.needsUpdate = true;
|
|
1039
|
+
}
|
|
1008
1040
|
if (rootState && rootState.renderer?.outputColorSpace === three.SRGBColorSpace && colorMaps.includes(key) && isTexture(value) && root[key]?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
1009
1041
|
root[key].format === three.RGBAFormat && root[key].type === three.UnsignedByteType) {
|
|
1010
1042
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -1038,38 +1070,60 @@ function applyProps(object, props) {
|
|
|
1038
1070
|
return object;
|
|
1039
1071
|
}
|
|
1040
1072
|
|
|
1073
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1074
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1075
|
+
function getPointerState(internal, pointerId) {
|
|
1076
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1077
|
+
if (!state) {
|
|
1078
|
+
state = {
|
|
1079
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1080
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1081
|
+
initialClick: [0, 0],
|
|
1082
|
+
initialHits: []
|
|
1083
|
+
};
|
|
1084
|
+
internal.pointerMap.set(pointerId, state);
|
|
1085
|
+
}
|
|
1086
|
+
return state;
|
|
1087
|
+
}
|
|
1088
|
+
function getPointerId(event) {
|
|
1089
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1090
|
+
}
|
|
1041
1091
|
function makeId(event) {
|
|
1042
1092
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1043
1093
|
}
|
|
1044
|
-
function releaseInternalPointerCapture(
|
|
1045
|
-
const
|
|
1094
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1095
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1096
|
+
if (!pointerState) return;
|
|
1097
|
+
const captureData = pointerState.captured.get(obj);
|
|
1046
1098
|
if (captureData) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
capturedMap.delete(pointerId);
|
|
1050
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
1051
|
-
}
|
|
1099
|
+
pointerState.captured.delete(obj);
|
|
1100
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1052
1101
|
}
|
|
1053
1102
|
}
|
|
1054
1103
|
function removeInteractivity(store, object) {
|
|
1055
1104
|
const { internal } = store.getState();
|
|
1056
1105
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1106
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1107
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1108
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1109
|
+
if (value.eventObject === object || value.object === object) {
|
|
1110
|
+
pointerState.hovered.delete(key);
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
if (pointerState.captured.has(object)) {
|
|
1114
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1061
1115
|
}
|
|
1062
|
-
}
|
|
1063
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1064
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1065
|
-
});
|
|
1116
|
+
}
|
|
1066
1117
|
unregisterVisibility(store, object);
|
|
1067
1118
|
}
|
|
1068
1119
|
function createEvents(store) {
|
|
1069
|
-
function calculateDistance(event) {
|
|
1120
|
+
function calculateDistance(event, pointerId) {
|
|
1070
1121
|
const { internal } = store.getState();
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1122
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1123
|
+
if (!pointerState) return 0;
|
|
1124
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1125
|
+
const dx = event.offsetX - initialX;
|
|
1126
|
+
const dy = event.offsetY - initialY;
|
|
1073
1127
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1074
1128
|
}
|
|
1075
1129
|
function filterPointerEvents(objects) {
|
|
@@ -1105,6 +1159,15 @@ function createEvents(store) {
|
|
|
1105
1159
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1106
1160
|
}
|
|
1107
1161
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1162
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1163
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1164
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1165
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1166
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1167
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1168
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1108
1171
|
const aState = getRootState(a.object);
|
|
1109
1172
|
const bState = getRootState(b.object);
|
|
1110
1173
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1126,9 +1189,13 @@ function createEvents(store) {
|
|
|
1126
1189
|
eventObject = eventObject.parent;
|
|
1127
1190
|
}
|
|
1128
1191
|
}
|
|
1129
|
-
if ("pointerId" in event
|
|
1130
|
-
|
|
1131
|
-
|
|
1192
|
+
if ("pointerId" in event) {
|
|
1193
|
+
const pointerId = event.pointerId;
|
|
1194
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1195
|
+
if (pointerState?.captured.size) {
|
|
1196
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1197
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1198
|
+
}
|
|
1132
1199
|
}
|
|
1133
1200
|
}
|
|
1134
1201
|
return intersections;
|
|
@@ -1141,27 +1208,25 @@ function createEvents(store) {
|
|
|
1141
1208
|
if (state) {
|
|
1142
1209
|
const { raycaster, pointer, camera, internal } = state;
|
|
1143
1210
|
const unprojectedPoint = new three.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1144
|
-
const hasPointerCapture = (id) =>
|
|
1211
|
+
const hasPointerCapture = (id) => {
|
|
1212
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1213
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1214
|
+
};
|
|
1145
1215
|
const setPointerCapture = (id) => {
|
|
1146
1216
|
const captureData = { intersection: hit, target: event.target };
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
} else {
|
|
1150
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1151
|
-
}
|
|
1217
|
+
const pointerState = getPointerState(internal, id);
|
|
1218
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1152
1219
|
event.target.setPointerCapture(id);
|
|
1153
1220
|
};
|
|
1154
1221
|
const releasePointerCapture = (id) => {
|
|
1155
|
-
|
|
1156
|
-
if (captures) {
|
|
1157
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1158
|
-
}
|
|
1222
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1159
1223
|
};
|
|
1160
1224
|
const extractEventProps = {};
|
|
1161
1225
|
for (const prop in event) {
|
|
1162
1226
|
const property = event[prop];
|
|
1163
1227
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1164
1228
|
}
|
|
1229
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1165
1230
|
const raycastEvent = {
|
|
1166
1231
|
...hit,
|
|
1167
1232
|
...extractEventProps,
|
|
@@ -1172,18 +1237,19 @@ function createEvents(store) {
|
|
|
1172
1237
|
unprojectedPoint,
|
|
1173
1238
|
ray: raycaster.ray,
|
|
1174
1239
|
camera,
|
|
1240
|
+
pointerId: eventPointerId,
|
|
1175
1241
|
// Hijack stopPropagation, which just sets a flag
|
|
1176
1242
|
stopPropagation() {
|
|
1177
|
-
const
|
|
1243
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1178
1244
|
if (
|
|
1179
1245
|
// ...if this pointer hasn't been captured
|
|
1180
|
-
!
|
|
1181
|
-
|
|
1246
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1247
|
+
pointerState.captured.has(hit.eventObject)
|
|
1182
1248
|
) {
|
|
1183
1249
|
raycastEvent.stopped = localState.stopped = true;
|
|
1184
|
-
if (
|
|
1250
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1185
1251
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1186
|
-
cancelPointer([...higher, hit]);
|
|
1252
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1187
1253
|
}
|
|
1188
1254
|
}
|
|
1189
1255
|
},
|
|
@@ -1199,15 +1265,18 @@ function createEvents(store) {
|
|
|
1199
1265
|
}
|
|
1200
1266
|
return intersections;
|
|
1201
1267
|
}
|
|
1202
|
-
function cancelPointer(intersections) {
|
|
1268
|
+
function cancelPointer(intersections, pointerId) {
|
|
1203
1269
|
const { internal } = store.getState();
|
|
1204
|
-
|
|
1270
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1271
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1272
|
+
if (!pointerState) return;
|
|
1273
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1205
1274
|
if (!intersections.length || !intersections.find(
|
|
1206
1275
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1207
1276
|
)) {
|
|
1208
1277
|
const eventObject = hoveredObj.eventObject;
|
|
1209
1278
|
const instance = eventObject.__r3f;
|
|
1210
|
-
|
|
1279
|
+
pointerState.hovered.delete(hoveredId);
|
|
1211
1280
|
if (instance?.eventCount) {
|
|
1212
1281
|
const handlers = instance.handlers;
|
|
1213
1282
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1236,41 +1305,118 @@ function createEvents(store) {
|
|
|
1236
1305
|
instance?.handlers.onDropMissed?.(event);
|
|
1237
1306
|
}
|
|
1238
1307
|
}
|
|
1308
|
+
function cleanupPointer(pointerId) {
|
|
1309
|
+
const { internal } = store.getState();
|
|
1310
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1311
|
+
if (pointerState) {
|
|
1312
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1313
|
+
const eventObject = hoveredObj.eventObject;
|
|
1314
|
+
const instance = eventObject.__r3f;
|
|
1315
|
+
if (instance?.eventCount) {
|
|
1316
|
+
const handlers = instance.handlers;
|
|
1317
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1318
|
+
handlers.onPointerOut?.(data);
|
|
1319
|
+
handlers.onPointerLeave?.(data);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
internal.pointerMap.delete(pointerId);
|
|
1323
|
+
}
|
|
1324
|
+
internal.pointerDirty.delete(pointerId);
|
|
1325
|
+
}
|
|
1326
|
+
function processDeferredPointer(event, pointerId) {
|
|
1327
|
+
const state = store.getState();
|
|
1328
|
+
const { internal } = state;
|
|
1329
|
+
if (!state.events.enabled) return;
|
|
1330
|
+
const filter = filterPointerEvents;
|
|
1331
|
+
const hits = intersect(event, filter);
|
|
1332
|
+
cancelPointer(hits, pointerId);
|
|
1333
|
+
function onIntersect(data) {
|
|
1334
|
+
const eventObject = data.eventObject;
|
|
1335
|
+
const instance = eventObject.__r3f;
|
|
1336
|
+
if (!instance?.eventCount) return;
|
|
1337
|
+
const handlers = instance.handlers;
|
|
1338
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1339
|
+
const id = makeId(data);
|
|
1340
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1341
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1342
|
+
if (!hoveredItem) {
|
|
1343
|
+
pointerState.hovered.set(id, data);
|
|
1344
|
+
handlers.onPointerOver?.(data);
|
|
1345
|
+
handlers.onPointerEnter?.(data);
|
|
1346
|
+
} else if (hoveredItem.stopped) {
|
|
1347
|
+
data.stopPropagation();
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
handlers.onPointerMove?.(data);
|
|
1351
|
+
}
|
|
1352
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1353
|
+
}
|
|
1239
1354
|
function handlePointer(name) {
|
|
1240
1355
|
switch (name) {
|
|
1241
1356
|
case "onPointerLeave":
|
|
1242
|
-
case "onPointerCancel":
|
|
1243
1357
|
case "onDragLeave":
|
|
1244
1358
|
return () => cancelPointer([]);
|
|
1359
|
+
// Global cancel of these events
|
|
1360
|
+
case "onPointerCancel":
|
|
1361
|
+
return (event) => {
|
|
1362
|
+
const pointerId = getPointerId(event);
|
|
1363
|
+
cleanupPointer(pointerId);
|
|
1364
|
+
};
|
|
1245
1365
|
case "onLostPointerCapture":
|
|
1246
1366
|
return (event) => {
|
|
1247
1367
|
const { internal } = store.getState();
|
|
1248
|
-
|
|
1368
|
+
const pointerId = getPointerId(event);
|
|
1369
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1370
|
+
if (pointerState?.captured.size) {
|
|
1249
1371
|
requestAnimationFrame(() => {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1372
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1373
|
+
if (pointerState2?.captured.size) {
|
|
1374
|
+
pointerState2.captured.clear();
|
|
1253
1375
|
}
|
|
1376
|
+
cancelPointer([], pointerId);
|
|
1254
1377
|
});
|
|
1255
1378
|
}
|
|
1256
1379
|
};
|
|
1257
1380
|
}
|
|
1258
1381
|
return function handleEvent(event) {
|
|
1259
1382
|
const state = store.getState();
|
|
1260
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1383
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1384
|
+
const pointerId = getPointerId(event);
|
|
1261
1385
|
internal.lastEvent.current = event;
|
|
1262
|
-
if (!
|
|
1386
|
+
if (!events.enabled) return;
|
|
1263
1387
|
const isPointerMove = name === "onPointerMove";
|
|
1264
1388
|
const isDragOver = name === "onDragOver";
|
|
1265
1389
|
const isDrop = name === "onDrop";
|
|
1266
1390
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1391
|
+
const isPointerDown = name === "onPointerDown";
|
|
1392
|
+
const isPointerUp = name === "onPointerUp";
|
|
1393
|
+
const isWheel = name === "onWheel";
|
|
1394
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1395
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1396
|
+
events.compute?.(event, state);
|
|
1397
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1401
|
+
events.compute?.(event, state);
|
|
1402
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1406
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1407
|
+
internal.pointerDirty.delete(pointerId);
|
|
1408
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1409
|
+
}
|
|
1267
1410
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1268
1411
|
const hits = intersect(event, filter);
|
|
1269
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1270
|
-
if (
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1412
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1413
|
+
if (isPointerDown) {
|
|
1414
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1415
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1416
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1417
|
+
}
|
|
1418
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1419
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1274
1420
|
if (isClickEvent && !hits.length) {
|
|
1275
1421
|
if (delta <= 2) {
|
|
1276
1422
|
pointerMissed(event, internal.interaction);
|
|
@@ -1285,7 +1431,9 @@ function createEvents(store) {
|
|
|
1285
1431
|
dropMissed(event, internal.interaction);
|
|
1286
1432
|
if (onDropMissed) onDropMissed(event);
|
|
1287
1433
|
}
|
|
1288
|
-
if (isPointerMove || isDragOver)
|
|
1434
|
+
if (isPointerMove || isDragOver) {
|
|
1435
|
+
cancelPointer(hits, pointerId);
|
|
1436
|
+
}
|
|
1289
1437
|
function onIntersect(data) {
|
|
1290
1438
|
const eventObject = data.eventObject;
|
|
1291
1439
|
const instance = eventObject.__r3f;
|
|
@@ -1294,9 +1442,10 @@ function createEvents(store) {
|
|
|
1294
1442
|
if (isPointerMove) {
|
|
1295
1443
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1296
1444
|
const id = makeId(data);
|
|
1297
|
-
const
|
|
1445
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1446
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1298
1447
|
if (!hoveredItem) {
|
|
1299
|
-
|
|
1448
|
+
pointerState2.hovered.set(id, data);
|
|
1300
1449
|
handlers.onPointerOver?.(data);
|
|
1301
1450
|
handlers.onPointerEnter?.(data);
|
|
1302
1451
|
} else if (hoveredItem.stopped) {
|
|
@@ -1306,9 +1455,10 @@ function createEvents(store) {
|
|
|
1306
1455
|
handlers.onPointerMove?.(data);
|
|
1307
1456
|
} else if (isDragOver) {
|
|
1308
1457
|
const id = makeId(data);
|
|
1309
|
-
const
|
|
1458
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1459
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1310
1460
|
if (!hoveredItem) {
|
|
1311
|
-
|
|
1461
|
+
pointerState2.hovered.set(id, data);
|
|
1312
1462
|
handlers.onDragOverEnter?.(data);
|
|
1313
1463
|
} else if (hoveredItem.stopped) {
|
|
1314
1464
|
data.stopPropagation();
|
|
@@ -1319,18 +1469,18 @@ function createEvents(store) {
|
|
|
1319
1469
|
} else {
|
|
1320
1470
|
const handler = handlers[name];
|
|
1321
1471
|
if (handler) {
|
|
1322
|
-
if (!isClickEvent ||
|
|
1472
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1323
1473
|
pointerMissed(
|
|
1324
1474
|
event,
|
|
1325
|
-
internal.interaction.filter((object) => !
|
|
1475
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1326
1476
|
);
|
|
1327
1477
|
handler(data);
|
|
1328
1478
|
}
|
|
1329
1479
|
} else {
|
|
1330
|
-
if (isClickEvent &&
|
|
1480
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1331
1481
|
pointerMissed(
|
|
1332
1482
|
event,
|
|
1333
|
-
internal.interaction.filter((object) => !
|
|
1483
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1334
1484
|
);
|
|
1335
1485
|
}
|
|
1336
1486
|
}
|
|
@@ -1339,7 +1489,15 @@ function createEvents(store) {
|
|
|
1339
1489
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1340
1490
|
};
|
|
1341
1491
|
}
|
|
1342
|
-
|
|
1492
|
+
function flushDeferredPointers() {
|
|
1493
|
+
const { internal, events } = store.getState();
|
|
1494
|
+
if (!events.frameTimedRaycasts) return;
|
|
1495
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1496
|
+
processDeferredPointer(event, pointerId);
|
|
1497
|
+
}
|
|
1498
|
+
internal.pointerDirty.clear();
|
|
1499
|
+
}
|
|
1500
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1343
1501
|
}
|
|
1344
1502
|
const DOM_EVENTS = {
|
|
1345
1503
|
onClick: ["click", false],
|
|
@@ -1358,10 +1516,15 @@ const DOM_EVENTS = {
|
|
|
1358
1516
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1359
1517
|
};
|
|
1360
1518
|
function createPointerEvents(store) {
|
|
1361
|
-
const { handlePointer } = createEvents(store);
|
|
1519
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1520
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1521
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1362
1522
|
return {
|
|
1363
1523
|
priority: 1,
|
|
1364
1524
|
enabled: true,
|
|
1525
|
+
frameTimedRaycasts: true,
|
|
1526
|
+
alwaysFireOnScroll: true,
|
|
1527
|
+
updateOnFrame: false,
|
|
1365
1528
|
compute(event, state) {
|
|
1366
1529
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1367
1530
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1371,11 +1534,33 @@ function createPointerEvents(store) {
|
|
|
1371
1534
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1372
1535
|
{}
|
|
1373
1536
|
),
|
|
1374
|
-
update: () => {
|
|
1537
|
+
update: (pointerId) => {
|
|
1538
|
+
const { events, internal } = store.getState();
|
|
1539
|
+
if (!events.handlers) return;
|
|
1540
|
+
if (pointerId !== void 0) {
|
|
1541
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1542
|
+
if (event) {
|
|
1543
|
+
internal.pointerDirty.delete(pointerId);
|
|
1544
|
+
processDeferredPointer(event, pointerId);
|
|
1545
|
+
} else if (internal.lastEvent?.current) {
|
|
1546
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1547
|
+
}
|
|
1548
|
+
} else {
|
|
1549
|
+
flushDeferredPointers();
|
|
1550
|
+
if (internal.lastEvent?.current) {
|
|
1551
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1555
|
+
flush: () => {
|
|
1375
1556
|
const { events, internal } = store.getState();
|
|
1376
|
-
|
|
1557
|
+
flushDeferredPointers();
|
|
1558
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1559
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1560
|
+
}
|
|
1377
1561
|
},
|
|
1378
1562
|
connect: (target) => {
|
|
1563
|
+
if (!target) return;
|
|
1379
1564
|
const { set, events } = store.getState();
|
|
1380
1565
|
events.disconnect?.();
|
|
1381
1566
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1399,6 +1584,32 @@ function createPointerEvents(store) {
|
|
|
1399
1584
|
}
|
|
1400
1585
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1401
1586
|
}
|
|
1587
|
+
},
|
|
1588
|
+
registerPointer: (config) => {
|
|
1589
|
+
const pointerId = nextXRPointerId++;
|
|
1590
|
+
xrPointers.set(pointerId, config);
|
|
1591
|
+
const { internal } = store.getState();
|
|
1592
|
+
getPointerState(internal, pointerId);
|
|
1593
|
+
return pointerId;
|
|
1594
|
+
},
|
|
1595
|
+
unregisterPointer: (pointerId) => {
|
|
1596
|
+
xrPointers.delete(pointerId);
|
|
1597
|
+
const { internal } = store.getState();
|
|
1598
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1599
|
+
if (pointerState) {
|
|
1600
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1601
|
+
const eventObject = hoveredObj.eventObject;
|
|
1602
|
+
const instance = eventObject.__r3f;
|
|
1603
|
+
if (instance?.eventCount) {
|
|
1604
|
+
const handlers = instance.handlers;
|
|
1605
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1606
|
+
handlers.onPointerOut?.(data);
|
|
1607
|
+
handlers.onPointerLeave?.(data);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
internal.pointerMap.delete(pointerId);
|
|
1611
|
+
}
|
|
1612
|
+
internal.pointerDirty.delete(pointerId);
|
|
1402
1613
|
}
|
|
1403
1614
|
};
|
|
1404
1615
|
}
|
|
@@ -1460,1036 +1671,12 @@ function notifyAlpha({ message, link }) {
|
|
|
1460
1671
|
}
|
|
1461
1672
|
}
|
|
1462
1673
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
/** Ordered list of phase nodes */
|
|
1470
|
-
__publicField$1(this, "phases", []);
|
|
1471
|
-
/** Quick lookup by name */
|
|
1472
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1473
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1474
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1475
|
-
this.initializeDefaultPhases();
|
|
1476
|
-
}
|
|
1477
|
-
//* Initialization --------------------------------
|
|
1478
|
-
initializeDefaultPhases() {
|
|
1479
|
-
for (const name of DEFAULT_PHASES) {
|
|
1480
|
-
const node = { name, isAutoGenerated: false };
|
|
1481
|
-
this.phases.push(node);
|
|
1482
|
-
this.phaseMap.set(name, node);
|
|
1483
|
-
}
|
|
1484
|
-
this.invalidateCache();
|
|
1485
|
-
}
|
|
1486
|
-
//* Public API --------------------------------
|
|
1487
|
-
/**
|
|
1488
|
-
* Add a named phase to the graph
|
|
1489
|
-
* @param name - Phase name (must be unique)
|
|
1490
|
-
* @param options - Position options (before or after another phase)
|
|
1491
|
-
*/
|
|
1492
|
-
addPhase(name, options = {}) {
|
|
1493
|
-
if (this.phaseMap.has(name)) {
|
|
1494
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1495
|
-
return;
|
|
1496
|
-
}
|
|
1497
|
-
const { before, after } = options;
|
|
1498
|
-
const node = { name, isAutoGenerated: false };
|
|
1499
|
-
let insertIndex = this.phases.length;
|
|
1500
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1501
|
-
if (targetIndex !== -1) {
|
|
1502
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1503
|
-
} else {
|
|
1504
|
-
const constraintType = before ? "before" : "after";
|
|
1505
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1506
|
-
}
|
|
1507
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1508
|
-
this.phaseMap.set(name, node);
|
|
1509
|
-
this.invalidateCache();
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Get ordered list of phase names
|
|
1513
|
-
*/
|
|
1514
|
-
getOrderedPhases() {
|
|
1515
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1516
|
-
return this.orderedNamesCache;
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Check if a phase exists
|
|
1520
|
-
*/
|
|
1521
|
-
hasPhase(name) {
|
|
1522
|
-
return this.phaseMap.has(name);
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Get the index of a phase (-1 if not found)
|
|
1526
|
-
*/
|
|
1527
|
-
getPhaseIndex(name) {
|
|
1528
|
-
if (!name) return -1;
|
|
1529
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1533
|
-
* Used for resolving before/after constraints.
|
|
1534
|
-
*
|
|
1535
|
-
* @param name - The phase name to ensure exists
|
|
1536
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1537
|
-
*/
|
|
1538
|
-
ensurePhase(name) {
|
|
1539
|
-
if (this.phaseMap.has(name)) return name;
|
|
1540
|
-
const node = { name, isAutoGenerated: true };
|
|
1541
|
-
this.phases.push(node);
|
|
1542
|
-
this.phaseMap.set(name, node);
|
|
1543
|
-
this.invalidateCache();
|
|
1544
|
-
return name;
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Resolve where a job with before/after constraints should go.
|
|
1548
|
-
* Creates auto-generated phases if needed.
|
|
1549
|
-
*
|
|
1550
|
-
* @param before - Phase(s) to run before
|
|
1551
|
-
* @param after - Phase(s) to run after
|
|
1552
|
-
* @returns The resolved phase name
|
|
1553
|
-
*/
|
|
1554
|
-
resolveConstraintPhase(before, after) {
|
|
1555
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1556
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1557
|
-
if (beforeArr.length > 0) {
|
|
1558
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1559
|
-
}
|
|
1560
|
-
if (afterArr.length > 0) {
|
|
1561
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1562
|
-
}
|
|
1563
|
-
return "update";
|
|
1564
|
-
}
|
|
1565
|
-
/**
|
|
1566
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1567
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1568
|
-
*
|
|
1569
|
-
* @param target - The target phase name to position relative to
|
|
1570
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1571
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1572
|
-
* @returns The auto-generated phase name
|
|
1573
|
-
*/
|
|
1574
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1575
|
-
const autoName = `${prefix}:${target}`;
|
|
1576
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1577
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1578
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1579
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1580
|
-
else this.phases.push(node);
|
|
1581
|
-
this.phaseMap.set(autoName, node);
|
|
1582
|
-
this.invalidateCache();
|
|
1583
|
-
return autoName;
|
|
1584
|
-
}
|
|
1585
|
-
// Internal --------------------------------
|
|
1586
|
-
invalidateCache() {
|
|
1587
|
-
this.orderedNamesCache = null;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1592
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1593
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1594
|
-
for (const phase of orderedPhases) {
|
|
1595
|
-
buckets.set(phase, []);
|
|
1596
|
-
}
|
|
1597
|
-
for (const job of jobs.values()) {
|
|
1598
|
-
if (!job.enabled) continue;
|
|
1599
|
-
let bucket = buckets.get(job.phase);
|
|
1600
|
-
if (!bucket) {
|
|
1601
|
-
bucket = [];
|
|
1602
|
-
buckets.set(job.phase, bucket);
|
|
1603
|
-
}
|
|
1604
|
-
bucket.push(job);
|
|
1605
|
-
}
|
|
1606
|
-
const sortedBuckets = [];
|
|
1607
|
-
for (const phase of orderedPhases) {
|
|
1608
|
-
const bucket = buckets.get(phase);
|
|
1609
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1610
|
-
bucket.sort((a, b) => {
|
|
1611
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1612
|
-
return a.index - b.index;
|
|
1613
|
-
});
|
|
1614
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1615
|
-
}
|
|
1616
|
-
for (const [phase, bucket] of buckets) {
|
|
1617
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1618
|
-
bucket.sort((a, b) => {
|
|
1619
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1620
|
-
return a.index - b.index;
|
|
1621
|
-
});
|
|
1622
|
-
sortedBuckets.push(bucket);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
return sortedBuckets.flat();
|
|
1626
|
-
}
|
|
1627
|
-
function hasCrossJobConstraints(bucket) {
|
|
1628
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1629
|
-
for (const job of bucket) {
|
|
1630
|
-
for (const ref of job.before) {
|
|
1631
|
-
if (jobIds.has(ref)) return true;
|
|
1632
|
-
}
|
|
1633
|
-
for (const ref of job.after) {
|
|
1634
|
-
if (jobIds.has(ref)) return true;
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
return false;
|
|
1638
|
-
}
|
|
1639
|
-
function topologicalSort(jobs) {
|
|
1640
|
-
const n = jobs.length;
|
|
1641
|
-
if (n <= 1) return jobs;
|
|
1642
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1643
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1644
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1645
|
-
for (const job of jobs) {
|
|
1646
|
-
jobMap.set(job.id, job);
|
|
1647
|
-
inDegree.set(job.id, 0);
|
|
1648
|
-
adjacency.set(job.id, []);
|
|
1649
|
-
}
|
|
1650
|
-
for (const job of jobs) {
|
|
1651
|
-
for (const ref of job.before) {
|
|
1652
|
-
if (jobMap.has(ref)) {
|
|
1653
|
-
adjacency.get(job.id).push(ref);
|
|
1654
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
for (const ref of job.after) {
|
|
1658
|
-
if (jobMap.has(ref)) {
|
|
1659
|
-
adjacency.get(ref).push(job.id);
|
|
1660
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
const queue = [];
|
|
1665
|
-
for (const job of jobs) {
|
|
1666
|
-
if (inDegree.get(job.id) === 0) {
|
|
1667
|
-
queue.push(job);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
queue.sort((a, b) => {
|
|
1671
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1672
|
-
return a.index - b.index;
|
|
1673
|
-
});
|
|
1674
|
-
const result = [];
|
|
1675
|
-
while (queue.length > 0) {
|
|
1676
|
-
const job = queue.shift();
|
|
1677
|
-
result.push(job);
|
|
1678
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1679
|
-
for (const neighborId of neighbors) {
|
|
1680
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1681
|
-
inDegree.set(neighborId, newDegree);
|
|
1682
|
-
if (newDegree === 0) {
|
|
1683
|
-
const neighbor = jobMap.get(neighborId);
|
|
1684
|
-
insertSorted(queue, neighbor);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
if (result.length !== n) {
|
|
1689
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1690
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1691
|
-
for (const job of jobs) {
|
|
1692
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
return result;
|
|
1696
|
-
}
|
|
1697
|
-
function insertSorted(arr, job) {
|
|
1698
|
-
let i = 0;
|
|
1699
|
-
while (i < arr.length) {
|
|
1700
|
-
const cmp = arr[i];
|
|
1701
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1702
|
-
break;
|
|
1703
|
-
}
|
|
1704
|
-
i++;
|
|
1705
|
-
}
|
|
1706
|
-
arr.splice(i, 0, job);
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
function shouldRun(job, now) {
|
|
1710
|
-
if (!job.enabled) return false;
|
|
1711
|
-
if (!job.fps) return true;
|
|
1712
|
-
const minInterval = 1e3 / job.fps;
|
|
1713
|
-
const lastRun = job.lastRun ?? 0;
|
|
1714
|
-
const elapsed = now - lastRun;
|
|
1715
|
-
if (elapsed < minInterval) return false;
|
|
1716
|
-
if (job.drop) {
|
|
1717
|
-
job.lastRun = now;
|
|
1718
|
-
} else {
|
|
1719
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1720
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1721
|
-
if (job.lastRun < now - minInterval) {
|
|
1722
|
-
job.lastRun = now;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
return true;
|
|
1726
|
-
}
|
|
1727
|
-
function resetJobTiming(job) {
|
|
1728
|
-
job.lastRun = void 0;
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
var __defProp = Object.defineProperty;
|
|
1732
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1733
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1734
|
-
const hmrData = (() => {
|
|
1735
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1736
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1737
|
-
try {
|
|
1738
|
-
return (0, eval)("import.meta.hot");
|
|
1739
|
-
} catch {
|
|
1740
|
-
return void 0;
|
|
1741
|
-
}
|
|
1742
|
-
})();
|
|
1743
|
-
const _Scheduler = class _Scheduler {
|
|
1744
|
-
//* Constructor ================================
|
|
1745
|
-
constructor() {
|
|
1746
|
-
//* Critical State ================================
|
|
1747
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1748
|
-
__publicField(this, "phaseGraph");
|
|
1749
|
-
__publicField(this, "loopState", {
|
|
1750
|
-
running: false,
|
|
1751
|
-
rafHandle: null,
|
|
1752
|
-
lastTime: null,
|
|
1753
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1754
|
-
frameCount: 0,
|
|
1755
|
-
elapsedTime: 0,
|
|
1756
|
-
createdAt: performance.now()
|
|
1757
|
-
});
|
|
1758
|
-
__publicField(this, "stoppedTime", 0);
|
|
1759
|
-
//* Private State ================================
|
|
1760
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1761
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1762
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1763
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1764
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1765
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1766
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1767
|
-
__publicField(this, "pendingFrames", 0);
|
|
1768
|
-
__publicField(this, "_frameloop", "always");
|
|
1769
|
-
//* Independent Mode & Error Handling State ================================
|
|
1770
|
-
__publicField(this, "_independent", false);
|
|
1771
|
-
__publicField(this, "errorHandler", null);
|
|
1772
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1773
|
-
//* Core Loop Execution Methods ================================
|
|
1774
|
-
/**
|
|
1775
|
-
* Main RAF loop callback.
|
|
1776
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1777
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1778
|
-
* @returns {void}
|
|
1779
|
-
* @private
|
|
1780
|
-
*/
|
|
1781
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1782
|
-
if (!this.loopState.running) return;
|
|
1783
|
-
this.executeFrame(timestamp);
|
|
1784
|
-
if (this._frameloop === "demand") {
|
|
1785
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1786
|
-
if (this.pendingFrames === 0) {
|
|
1787
|
-
this.notifyIdle(timestamp);
|
|
1788
|
-
return this.stop();
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1792
|
-
});
|
|
1793
|
-
this.phaseGraph = new PhaseGraph();
|
|
1794
|
-
}
|
|
1795
|
-
static get instance() {
|
|
1796
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1797
|
-
}
|
|
1798
|
-
static set instance(value) {
|
|
1799
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1800
|
-
}
|
|
1801
|
-
/**
|
|
1802
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1803
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1804
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1805
|
-
*/
|
|
1806
|
-
static get() {
|
|
1807
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1808
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1809
|
-
}
|
|
1810
|
-
if (!_Scheduler.instance) {
|
|
1811
|
-
_Scheduler.instance = new _Scheduler();
|
|
1812
|
-
if (hmrData?.data) {
|
|
1813
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
return _Scheduler.instance;
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1820
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1821
|
-
* @returns {void}
|
|
1822
|
-
*/
|
|
1823
|
-
static reset() {
|
|
1824
|
-
if (_Scheduler.instance) {
|
|
1825
|
-
_Scheduler.instance.stop();
|
|
1826
|
-
_Scheduler.instance = null;
|
|
1827
|
-
}
|
|
1828
|
-
if (hmrData?.data) {
|
|
1829
|
-
hmrData.data.scheduler = null;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
//* Getters & Setters ================================
|
|
1833
|
-
get phases() {
|
|
1834
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1835
|
-
}
|
|
1836
|
-
get frameloop() {
|
|
1837
|
-
return this._frameloop;
|
|
1838
|
-
}
|
|
1839
|
-
set frameloop(mode) {
|
|
1840
|
-
if (this._frameloop === mode) return;
|
|
1841
|
-
const wasAlways = this._frameloop === "always";
|
|
1842
|
-
this._frameloop = mode;
|
|
1843
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1844
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1845
|
-
}
|
|
1846
|
-
get isRunning() {
|
|
1847
|
-
return this.loopState.running;
|
|
1848
|
-
}
|
|
1849
|
-
get isReady() {
|
|
1850
|
-
return this.roots.size > 0;
|
|
1851
|
-
}
|
|
1852
|
-
get independent() {
|
|
1853
|
-
return this._independent;
|
|
1854
|
-
}
|
|
1855
|
-
set independent(value) {
|
|
1856
|
-
this._independent = value;
|
|
1857
|
-
if (value) this.ensureDefaultRoot();
|
|
1858
|
-
}
|
|
1859
|
-
//* Root Management Methods ================================
|
|
1860
|
-
/**
|
|
1861
|
-
* Register a root (Canvas) with the scheduler.
|
|
1862
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1863
|
-
* @param {string} id - Unique identifier for this root
|
|
1864
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1865
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1866
|
-
*/
|
|
1867
|
-
registerRoot(id, options = {}) {
|
|
1868
|
-
if (this.roots.has(id)) {
|
|
1869
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1870
|
-
return () => this.unregisterRoot(id);
|
|
1871
|
-
}
|
|
1872
|
-
const entry = {
|
|
1873
|
-
id,
|
|
1874
|
-
getState: options.getState ?? (() => ({})),
|
|
1875
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1876
|
-
sortedJobs: [],
|
|
1877
|
-
needsRebuild: false
|
|
1878
|
-
};
|
|
1879
|
-
if (options.onError) {
|
|
1880
|
-
this.errorHandler = options.onError;
|
|
1881
|
-
}
|
|
1882
|
-
this.roots.set(id, entry);
|
|
1883
|
-
if (this.roots.size === 1) {
|
|
1884
|
-
this.notifyRootReady();
|
|
1885
|
-
if (this._frameloop === "always") this.start();
|
|
1886
|
-
}
|
|
1887
|
-
return () => this.unregisterRoot(id);
|
|
1888
|
-
}
|
|
1889
|
-
/**
|
|
1890
|
-
* Unregister a root from the scheduler.
|
|
1891
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1892
|
-
* The last root to unregister stops the RAF loop.
|
|
1893
|
-
* @param {string} id - The root ID to unregister
|
|
1894
|
-
* @returns {void}
|
|
1895
|
-
*/
|
|
1896
|
-
unregisterRoot(id) {
|
|
1897
|
-
const root = this.roots.get(id);
|
|
1898
|
-
if (!root) return;
|
|
1899
|
-
for (const jobId of root.jobs.keys()) {
|
|
1900
|
-
this.jobStateListeners.delete(jobId);
|
|
1901
|
-
}
|
|
1902
|
-
this.roots.delete(id);
|
|
1903
|
-
if (this.roots.size === 0) {
|
|
1904
|
-
this.stop();
|
|
1905
|
-
this.errorHandler = null;
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
/**
|
|
1909
|
-
* Subscribe to be notified when a root becomes available.
|
|
1910
|
-
* Fires immediately if a root already exists.
|
|
1911
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1912
|
-
* @returns {() => void} Unsubscribe function
|
|
1913
|
-
*/
|
|
1914
|
-
onRootReady(callback) {
|
|
1915
|
-
if (this.roots.size > 0) {
|
|
1916
|
-
callback();
|
|
1917
|
-
return () => {
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1920
|
-
this.rootReadyCallbacks.add(callback);
|
|
1921
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Notify all registered root-ready callbacks.
|
|
1925
|
-
* Called when the first root registers.
|
|
1926
|
-
* @returns {void}
|
|
1927
|
-
* @private
|
|
1928
|
-
*/
|
|
1929
|
-
notifyRootReady() {
|
|
1930
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1931
|
-
try {
|
|
1932
|
-
cb();
|
|
1933
|
-
} catch (error) {
|
|
1934
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
this.rootReadyCallbacks.clear();
|
|
1938
|
-
}
|
|
1939
|
-
/**
|
|
1940
|
-
* Ensure a default root exists for independent mode.
|
|
1941
|
-
* Creates a minimal root with no state provider.
|
|
1942
|
-
* @returns {void}
|
|
1943
|
-
* @private
|
|
1944
|
-
*/
|
|
1945
|
-
ensureDefaultRoot() {
|
|
1946
|
-
if (!this.roots.has("__default__")) {
|
|
1947
|
-
this.registerRoot("__default__");
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
|
-
/**
|
|
1951
|
-
* Trigger error handling for job errors.
|
|
1952
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1953
|
-
* @param {Error} error - The error to handle
|
|
1954
|
-
* @returns {void}
|
|
1955
|
-
*/
|
|
1956
|
-
triggerError(error) {
|
|
1957
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1958
|
-
else console.error("[Scheduler]", error);
|
|
1959
|
-
}
|
|
1960
|
-
//* Phase Management Methods ================================
|
|
1961
|
-
/**
|
|
1962
|
-
* Add a named phase to the scheduler's execution order.
|
|
1963
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1964
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1965
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1966
|
-
* @returns {void}
|
|
1967
|
-
* @example
|
|
1968
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1969
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1970
|
-
*/
|
|
1971
|
-
addPhase(name, options) {
|
|
1972
|
-
this.phaseGraph.addPhase(name, options);
|
|
1973
|
-
for (const root of this.roots.values()) {
|
|
1974
|
-
root.needsRebuild = true;
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
/**
|
|
1978
|
-
* Check if a phase exists in the scheduler.
|
|
1979
|
-
* @param {string} name - The phase name to check
|
|
1980
|
-
* @returns {boolean} True if the phase exists
|
|
1981
|
-
*/
|
|
1982
|
-
hasPhase(name) {
|
|
1983
|
-
return this.phaseGraph.hasPhase(name);
|
|
1984
|
-
}
|
|
1985
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1986
|
-
/**
|
|
1987
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1988
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1989
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1990
|
-
* @param {string} id - Unique identifier for this global job
|
|
1991
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1992
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1993
|
-
* @deprecated Use useFrame with phases instead
|
|
1994
|
-
*/
|
|
1995
|
-
registerGlobal(phase, id, callback) {
|
|
1996
|
-
const job = { id, callback };
|
|
1997
|
-
if (phase === "before") {
|
|
1998
|
-
this.globalBeforeJobs.set(id, job);
|
|
1999
|
-
} else {
|
|
2000
|
-
this.globalAfterJobs.set(id, job);
|
|
2001
|
-
}
|
|
2002
|
-
return () => {
|
|
2003
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
2004
|
-
else this.globalAfterJobs.delete(id);
|
|
2005
|
-
};
|
|
2006
|
-
}
|
|
2007
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
2008
|
-
/**
|
|
2009
|
-
* Register an idle callback that fires when the loop stops.
|
|
2010
|
-
* Used internally by deprecated addTail API.
|
|
2011
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
2012
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
2013
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
2014
|
-
*/
|
|
2015
|
-
onIdle(callback) {
|
|
2016
|
-
this.idleCallbacks.add(callback);
|
|
2017
|
-
return () => this.idleCallbacks.delete(callback);
|
|
2018
|
-
}
|
|
2019
|
-
/**
|
|
2020
|
-
* Notify all registered idle callbacks.
|
|
2021
|
-
* Called when the loop stops in demand mode.
|
|
2022
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2023
|
-
* @returns {void}
|
|
2024
|
-
* @private
|
|
2025
|
-
*/
|
|
2026
|
-
notifyIdle(timestamp) {
|
|
2027
|
-
for (const cb of this.idleCallbacks) {
|
|
2028
|
-
try {
|
|
2029
|
-
cb(timestamp);
|
|
2030
|
-
} catch (error) {
|
|
2031
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
//* Job Registration & Management Methods ================================
|
|
2036
|
-
/**
|
|
2037
|
-
* Register a job (frame callback) with a specific root.
|
|
2038
|
-
* This is the core registration method used by useFrame internally.
|
|
2039
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2040
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2041
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2042
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2043
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2044
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2045
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2046
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2047
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2048
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2049
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2050
|
-
*/
|
|
2051
|
-
register(callback, options = {}) {
|
|
2052
|
-
const rootId = options.rootId;
|
|
2053
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2054
|
-
if (!root) {
|
|
2055
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2056
|
-
return () => {
|
|
2057
|
-
};
|
|
2058
|
-
}
|
|
2059
|
-
const id = options.id ?? this.generateJobId();
|
|
2060
|
-
let phase = options.phase ?? "update";
|
|
2061
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2062
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2063
|
-
}
|
|
2064
|
-
const before = this.normalizeConstraints(options.before);
|
|
2065
|
-
const after = this.normalizeConstraints(options.after);
|
|
2066
|
-
const job = {
|
|
2067
|
-
id,
|
|
2068
|
-
callback,
|
|
2069
|
-
phase,
|
|
2070
|
-
before,
|
|
2071
|
-
after,
|
|
2072
|
-
priority: options.priority ?? 0,
|
|
2073
|
-
index: this.nextJobIndex++,
|
|
2074
|
-
fps: options.fps,
|
|
2075
|
-
drop: options.drop ?? true,
|
|
2076
|
-
enabled: options.enabled ?? true,
|
|
2077
|
-
system: options.system ?? false
|
|
2078
|
-
};
|
|
2079
|
-
if (root.jobs.has(id)) {
|
|
2080
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2081
|
-
}
|
|
2082
|
-
root.jobs.set(id, job);
|
|
2083
|
-
root.needsRebuild = true;
|
|
2084
|
-
return () => this.unregister(id, root.id);
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Unregister a job by its ID.
|
|
2088
|
-
* Searches all roots if rootId is not provided.
|
|
2089
|
-
* @param {string} id - The job ID to unregister
|
|
2090
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2091
|
-
* @returns {void}
|
|
2092
|
-
*/
|
|
2093
|
-
unregister(id, rootId) {
|
|
2094
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2095
|
-
if (root?.jobs.delete(id)) {
|
|
2096
|
-
root.needsRebuild = true;
|
|
2097
|
-
this.jobStateListeners.delete(id);
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* Update a job's options dynamically.
|
|
2102
|
-
* Searches all roots to find the job by ID.
|
|
2103
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2104
|
-
* @param {string} id - The job ID to update
|
|
2105
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2106
|
-
* @returns {void}
|
|
2107
|
-
*/
|
|
2108
|
-
updateJob(id, options) {
|
|
2109
|
-
let job;
|
|
2110
|
-
let root;
|
|
2111
|
-
for (const r of this.roots.values()) {
|
|
2112
|
-
job = r.jobs.get(id);
|
|
2113
|
-
if (job) {
|
|
2114
|
-
root = r;
|
|
2115
|
-
break;
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
if (!job || !root) return;
|
|
2119
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2120
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2121
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2122
|
-
if (options.enabled !== void 0) {
|
|
2123
|
-
const wasEnabled = job.enabled;
|
|
2124
|
-
job.enabled = options.enabled;
|
|
2125
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2126
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2127
|
-
}
|
|
2128
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2129
|
-
if (options.phase) job.phase = options.phase;
|
|
2130
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2131
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2132
|
-
root.needsRebuild = true;
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
//* Job State Management Methods ================================
|
|
2136
|
-
/**
|
|
2137
|
-
* Check if a job is currently paused (disabled).
|
|
2138
|
-
* @param {string} id - The job ID to check
|
|
2139
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2140
|
-
*/
|
|
2141
|
-
isJobPaused(id) {
|
|
2142
|
-
for (const root of this.roots.values()) {
|
|
2143
|
-
const job = root.jobs.get(id);
|
|
2144
|
-
if (job) return !job.enabled;
|
|
2145
|
-
}
|
|
2146
|
-
return false;
|
|
2147
|
-
}
|
|
2148
|
-
/**
|
|
2149
|
-
* Subscribe to state changes for a specific job.
|
|
2150
|
-
* Listener is called when job is paused or resumed.
|
|
2151
|
-
* @param {string} id - The job ID to subscribe to
|
|
2152
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2153
|
-
* @returns {() => void} Unsubscribe function
|
|
2154
|
-
*/
|
|
2155
|
-
subscribeJobState(id, listener) {
|
|
2156
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2157
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2158
|
-
}
|
|
2159
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2160
|
-
return () => {
|
|
2161
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2162
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2163
|
-
this.jobStateListeners.delete(id);
|
|
2164
|
-
}
|
|
2165
|
-
};
|
|
2166
|
-
}
|
|
2167
|
-
/**
|
|
2168
|
-
* Notify all listeners that a job's state has changed.
|
|
2169
|
-
* @param {string} id - The job ID that changed
|
|
2170
|
-
* @returns {void}
|
|
2171
|
-
* @private
|
|
2172
|
-
*/
|
|
2173
|
-
notifyJobStateChange(id) {
|
|
2174
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2175
|
-
}
|
|
2176
|
-
/**
|
|
2177
|
-
* Pause a job by ID (sets enabled=false).
|
|
2178
|
-
* Notifies any subscribed state listeners.
|
|
2179
|
-
* @param {string} id - The job ID to pause
|
|
2180
|
-
* @returns {void}
|
|
2181
|
-
*/
|
|
2182
|
-
pauseJob(id) {
|
|
2183
|
-
this.updateJob(id, { enabled: false });
|
|
2184
|
-
this.notifyJobStateChange(id);
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2188
|
-
* Resets job timing to prevent frame accumulation.
|
|
2189
|
-
* Notifies any subscribed state listeners.
|
|
2190
|
-
* @param {string} id - The job ID to resume
|
|
2191
|
-
* @returns {void}
|
|
2192
|
-
*/
|
|
2193
|
-
resumeJob(id) {
|
|
2194
|
-
this.updateJob(id, { enabled: true });
|
|
2195
|
-
this.notifyJobStateChange(id);
|
|
2196
|
-
}
|
|
2197
|
-
//* Frame Loop Control Methods ================================
|
|
2198
|
-
/**
|
|
2199
|
-
* Start the requestAnimationFrame loop.
|
|
2200
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2201
|
-
* No-op if already running.
|
|
2202
|
-
* @returns {void}
|
|
2203
|
-
*/
|
|
2204
|
-
start() {
|
|
2205
|
-
if (this.loopState.running) return;
|
|
2206
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2207
|
-
let adjustedCreated = 0;
|
|
2208
|
-
if (this.stoppedTime > 0) {
|
|
2209
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2210
|
-
this.stoppedTime = 0;
|
|
2211
|
-
}
|
|
2212
|
-
Object.assign(this.loopState, {
|
|
2213
|
-
running: true,
|
|
2214
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2215
|
-
lastTime: performance.now(),
|
|
2216
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2217
|
-
frameCount: 0,
|
|
2218
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2219
|
-
});
|
|
2220
|
-
}
|
|
2221
|
-
/**
|
|
2222
|
-
* Stop the requestAnimationFrame loop.
|
|
2223
|
-
* Cancels any pending RAF callback.
|
|
2224
|
-
* No-op if not running.
|
|
2225
|
-
* @returns {void}
|
|
2226
|
-
*/
|
|
2227
|
-
stop() {
|
|
2228
|
-
if (!this.loopState.running) return;
|
|
2229
|
-
this.loopState.running = false;
|
|
2230
|
-
if (this.loopState.rafHandle !== null) {
|
|
2231
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2232
|
-
this.loopState.rafHandle = null;
|
|
2233
|
-
}
|
|
2234
|
-
this.stoppedTime = performance.now();
|
|
2235
|
-
}
|
|
2236
|
-
/**
|
|
2237
|
-
* Request frames to be rendered in demand mode.
|
|
2238
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2239
|
-
* No-op if frameloop is not 'demand'.
|
|
2240
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2241
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2242
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2243
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2244
|
-
* @returns {void}
|
|
2245
|
-
* @example
|
|
2246
|
-
* // Request a single frame render
|
|
2247
|
-
* scheduler.invalidate();
|
|
2248
|
-
*
|
|
2249
|
-
* @example
|
|
2250
|
-
* // Request 5 frames (e.g., for animations)
|
|
2251
|
-
* scheduler.invalidate(5);
|
|
2252
|
-
*
|
|
2253
|
-
* @example
|
|
2254
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2255
|
-
* scheduler.invalidate(3, false);
|
|
2256
|
-
*
|
|
2257
|
-
* @example
|
|
2258
|
-
* // Add 2 more frames to existing pending count
|
|
2259
|
-
* scheduler.invalidate(2, true);
|
|
2260
|
-
*/
|
|
2261
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2262
|
-
if (this._frameloop !== "demand") return;
|
|
2263
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2264
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2265
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2266
|
-
}
|
|
2267
|
-
/**
|
|
2268
|
-
* Reset timing state for deterministic testing.
|
|
2269
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2270
|
-
* @returns {void}
|
|
2271
|
-
*/
|
|
2272
|
-
resetTiming() {
|
|
2273
|
-
this.loopState.lastTime = null;
|
|
2274
|
-
this.loopState.frameCount = 0;
|
|
2275
|
-
this.loopState.elapsedTime = 0;
|
|
2276
|
-
this.loopState.createdAt = performance.now();
|
|
2277
|
-
}
|
|
2278
|
-
//* Manual Stepping Methods ================================
|
|
2279
|
-
/**
|
|
2280
|
-
* Manually execute a single frame for all roots.
|
|
2281
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2282
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2283
|
-
* @returns {void}
|
|
2284
|
-
* @example
|
|
2285
|
-
* // Manual control mode
|
|
2286
|
-
* scheduler.frameloop = 'never';
|
|
2287
|
-
* scheduler.step(); // Execute one frame
|
|
2288
|
-
*/
|
|
2289
|
-
step(timestamp) {
|
|
2290
|
-
const now = timestamp ?? performance.now();
|
|
2291
|
-
this.executeFrame(now);
|
|
2292
|
-
}
|
|
2293
|
-
/**
|
|
2294
|
-
* Manually execute a single job by its ID.
|
|
2295
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2296
|
-
* @param {string} id - The job ID to step
|
|
2297
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2298
|
-
* @returns {void}
|
|
2299
|
-
*/
|
|
2300
|
-
stepJob(id, timestamp) {
|
|
2301
|
-
let job;
|
|
2302
|
-
let root;
|
|
2303
|
-
for (const r of this.roots.values()) {
|
|
2304
|
-
job = r.jobs.get(id);
|
|
2305
|
-
if (job) {
|
|
2306
|
-
root = r;
|
|
2307
|
-
break;
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
if (!job || !root) {
|
|
2311
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2312
|
-
return;
|
|
2313
|
-
}
|
|
2314
|
-
const now = timestamp ?? performance.now();
|
|
2315
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2316
|
-
const delta = deltaMs / 1e3;
|
|
2317
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2318
|
-
const providedState = root.getState?.() ?? {};
|
|
2319
|
-
const frameState = {
|
|
2320
|
-
...providedState,
|
|
2321
|
-
time: now,
|
|
2322
|
-
delta,
|
|
2323
|
-
elapsed,
|
|
2324
|
-
frame: this.loopState.frameCount
|
|
2325
|
-
};
|
|
2326
|
-
try {
|
|
2327
|
-
job.callback(frameState, delta);
|
|
2328
|
-
} catch (error) {
|
|
2329
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2330
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
/**
|
|
2334
|
-
* Execute a single frame across all roots.
|
|
2335
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2336
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2337
|
-
* @returns {void}
|
|
2338
|
-
* @private
|
|
2339
|
-
*/
|
|
2340
|
-
executeFrame(timestamp) {
|
|
2341
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2342
|
-
const delta = deltaMs / 1e3;
|
|
2343
|
-
this.loopState.lastTime = timestamp;
|
|
2344
|
-
this.loopState.frameCount++;
|
|
2345
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2346
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2347
|
-
for (const root of this.roots.values()) {
|
|
2348
|
-
this.tickRoot(root, timestamp, delta);
|
|
2349
|
-
}
|
|
2350
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2351
|
-
}
|
|
2352
|
-
/**
|
|
2353
|
-
* Run all global jobs from a job map.
|
|
2354
|
-
* Catches and logs errors without stopping execution.
|
|
2355
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2356
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2357
|
-
* @returns {void}
|
|
2358
|
-
* @private
|
|
2359
|
-
*/
|
|
2360
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2361
|
-
for (const job of jobs.values()) {
|
|
2362
|
-
try {
|
|
2363
|
-
job.callback(timestamp);
|
|
2364
|
-
} catch (error) {
|
|
2365
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
/**
|
|
2370
|
-
* Execute all jobs for a single root in sorted order.
|
|
2371
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2372
|
-
* Errors are caught and propagated via triggerError.
|
|
2373
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2374
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2375
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2376
|
-
* @returns {void}
|
|
2377
|
-
* @private
|
|
2378
|
-
*/
|
|
2379
|
-
tickRoot(root, timestamp, delta) {
|
|
2380
|
-
if (root.needsRebuild) {
|
|
2381
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2382
|
-
root.needsRebuild = false;
|
|
2383
|
-
}
|
|
2384
|
-
const providedState = root.getState?.() ?? {};
|
|
2385
|
-
const frameState = {
|
|
2386
|
-
...providedState,
|
|
2387
|
-
time: timestamp,
|
|
2388
|
-
delta,
|
|
2389
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2390
|
-
// Convert ms to seconds
|
|
2391
|
-
frame: this.loopState.frameCount
|
|
2392
|
-
};
|
|
2393
|
-
for (const job of root.sortedJobs) {
|
|
2394
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2395
|
-
try {
|
|
2396
|
-
job.callback(frameState, delta);
|
|
2397
|
-
} catch (error) {
|
|
2398
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2399
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
}
|
|
2403
|
-
//* Debug & Inspection Methods ================================
|
|
2404
|
-
/**
|
|
2405
|
-
* Get the total number of registered jobs across all roots.
|
|
2406
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2407
|
-
* @returns {number} Total job count
|
|
2408
|
-
*/
|
|
2409
|
-
getJobCount() {
|
|
2410
|
-
let count = 0;
|
|
2411
|
-
for (const root of this.roots.values()) {
|
|
2412
|
-
count += root.jobs.size;
|
|
2413
|
-
}
|
|
2414
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2415
|
-
}
|
|
2416
|
-
/**
|
|
2417
|
-
* Get all registered job IDs across all roots.
|
|
2418
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2419
|
-
* @returns {string[]} Array of all job IDs
|
|
2420
|
-
*/
|
|
2421
|
-
getJobIds() {
|
|
2422
|
-
const ids = [];
|
|
2423
|
-
for (const root of this.roots.values()) {
|
|
2424
|
-
ids.push(...root.jobs.keys());
|
|
2425
|
-
}
|
|
2426
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2427
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2428
|
-
return ids;
|
|
2429
|
-
}
|
|
2430
|
-
/**
|
|
2431
|
-
* Get the number of registered roots (Canvas instances).
|
|
2432
|
-
* @returns {number} Number of registered roots
|
|
2433
|
-
*/
|
|
2434
|
-
getRootCount() {
|
|
2435
|
-
return this.roots.size;
|
|
2436
|
-
}
|
|
2437
|
-
/**
|
|
2438
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2439
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2440
|
-
*
|
|
2441
|
-
* @param phase The phase to check
|
|
2442
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2443
|
-
* @returns true if any user jobs exist in the phase
|
|
2444
|
-
*/
|
|
2445
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2446
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2447
|
-
return rootsToCheck.some((root) => {
|
|
2448
|
-
if (!root) return false;
|
|
2449
|
-
for (const job of root.jobs.values()) {
|
|
2450
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2451
|
-
}
|
|
2452
|
-
return false;
|
|
2453
|
-
});
|
|
2454
|
-
}
|
|
2455
|
-
//* Utility Methods ================================
|
|
2456
|
-
/**
|
|
2457
|
-
* Generate a unique root ID for automatic root registration.
|
|
2458
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2459
|
-
*/
|
|
2460
|
-
generateRootId() {
|
|
2461
|
-
return `root_${this.nextRootIndex++}`;
|
|
2462
|
-
}
|
|
2463
|
-
/**
|
|
2464
|
-
* Generate a unique job ID.
|
|
2465
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2466
|
-
* @private
|
|
2467
|
-
*/
|
|
2468
|
-
generateJobId() {
|
|
2469
|
-
return `job_${this.nextJobIndex}`;
|
|
2470
|
-
}
|
|
2471
|
-
/**
|
|
2472
|
-
* Normalize before/after constraints to a Set.
|
|
2473
|
-
* Handles undefined, single string, or array inputs.
|
|
2474
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2475
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2476
|
-
* @private
|
|
2477
|
-
*/
|
|
2478
|
-
normalizeConstraints(value) {
|
|
2479
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2480
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2481
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2482
|
-
}
|
|
2483
|
-
};
|
|
2484
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2485
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2486
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2487
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2488
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2489
|
-
let Scheduler = _Scheduler;
|
|
2490
|
-
const getScheduler = () => Scheduler.get();
|
|
2491
|
-
if (hmrData) {
|
|
2492
|
-
hmrData.accept?.();
|
|
1674
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1675
|
+
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1676
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1677
|
+
if (!stack) return false;
|
|
1678
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1679
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m)) || INTERNAL_FIBER_MARKERS.some((m) => caller.includes(m));
|
|
2493
1680
|
}
|
|
2494
1681
|
|
|
2495
1682
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
@@ -2529,7 +1716,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2529
1716
|
frustum: new three.Frustum(),
|
|
2530
1717
|
autoUpdateFrustum: true,
|
|
2531
1718
|
raycaster: null,
|
|
2532
|
-
events: {
|
|
1719
|
+
events: {
|
|
1720
|
+
priority: 1,
|
|
1721
|
+
enabled: true,
|
|
1722
|
+
connected: false,
|
|
1723
|
+
frameTimedRaycasts: true,
|
|
1724
|
+
alwaysFireOnScroll: true,
|
|
1725
|
+
updateOnFrame: false
|
|
1726
|
+
},
|
|
2533
1727
|
scene: null,
|
|
2534
1728
|
rootScene: null,
|
|
2535
1729
|
xr: null,
|
|
@@ -2594,7 +1788,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2594
1788
|
size: newSize,
|
|
2595
1789
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2596
1790
|
}));
|
|
2597
|
-
getScheduler().invalidate();
|
|
1791
|
+
scheduler.getScheduler().invalidate();
|
|
2598
1792
|
}
|
|
2599
1793
|
}
|
|
2600
1794
|
return;
|
|
@@ -2609,7 +1803,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2609
1803
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2610
1804
|
_sizeImperative: true
|
|
2611
1805
|
}));
|
|
2612
|
-
getScheduler().invalidate();
|
|
1806
|
+
scheduler.getScheduler().invalidate();
|
|
2613
1807
|
},
|
|
2614
1808
|
setDpr: (dpr) => set((state2) => {
|
|
2615
1809
|
const resolved = calculateDpr(dpr);
|
|
@@ -2620,11 +1814,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2620
1814
|
},
|
|
2621
1815
|
setError: (error) => set(() => ({ error })),
|
|
2622
1816
|
error: null,
|
|
2623
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1817
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2624
1818
|
uniforms: {},
|
|
2625
1819
|
nodes: {},
|
|
1820
|
+
buffers: {},
|
|
1821
|
+
gpuStorage: {},
|
|
2626
1822
|
textures: /* @__PURE__ */ new Map(),
|
|
2627
|
-
|
|
1823
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1824
|
+
renderPipeline: null,
|
|
2628
1825
|
passes: {},
|
|
2629
1826
|
_hmrVersion: 0,
|
|
2630
1827
|
_sizeImperative: false,
|
|
@@ -2633,12 +1830,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2633
1830
|
internal: {
|
|
2634
1831
|
// Events
|
|
2635
1832
|
interaction: [],
|
|
2636
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2637
1833
|
subscribers: [],
|
|
1834
|
+
// Per-pointer state (new unified structure)
|
|
1835
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1836
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1837
|
+
lastEvent: React__namespace.createRef(),
|
|
1838
|
+
// Deprecated but kept for backwards compatibility
|
|
1839
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2638
1840
|
initialClick: [0, 0],
|
|
2639
1841
|
initialHits: [],
|
|
2640
1842
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2641
|
-
lastEvent: React__namespace.createRef(),
|
|
2642
1843
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2643
1844
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2644
1845
|
// Occlusion system (WebGPU only)
|
|
@@ -2677,8 +1878,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2677
1878
|
const currentState = rootStore.getState();
|
|
2678
1879
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
2679
1880
|
const stack = new Error().stack || "";
|
|
2680
|
-
|
|
2681
|
-
if (!isInternalAccess) {
|
|
1881
|
+
if (!isInternalRendererAccess(stack)) {
|
|
2682
1882
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
2683
1883
|
notifyDepreciated({
|
|
2684
1884
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -2726,14 +1926,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2726
1926
|
oldSize = size;
|
|
2727
1927
|
oldDpr = viewport.dpr;
|
|
2728
1928
|
updateCamera(camera, size);
|
|
2729
|
-
if (canvasTarget) {
|
|
1929
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2730
1930
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2731
|
-
|
|
2732
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1931
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2733
1932
|
} else {
|
|
2734
1933
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2735
|
-
|
|
2736
|
-
|
|
1934
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1935
|
+
if (canvasTarget) {
|
|
1936
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1937
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1938
|
+
}
|
|
2737
1939
|
}
|
|
2738
1940
|
}
|
|
2739
1941
|
if (camera !== oldCamera) {
|
|
@@ -2789,26 +1991,32 @@ function loadingFn(extensions, onProgress) {
|
|
|
2789
1991
|
);
|
|
2790
1992
|
};
|
|
2791
1993
|
}
|
|
2792
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
2793
|
-
const
|
|
1994
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1995
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1996
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2794
1997
|
const fn = loadingFn(extensions, onProgress);
|
|
2795
|
-
const results =
|
|
1998
|
+
const results = cacheKeys.map(
|
|
1999
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2000
|
+
);
|
|
2796
2001
|
return Array.isArray(input) ? results : results[0];
|
|
2797
2002
|
}
|
|
2798
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
2799
|
-
const
|
|
2800
|
-
|
|
2003
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2004
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2005
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2006
|
+
cacheKeys.forEach(
|
|
2007
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2008
|
+
);
|
|
2801
2009
|
};
|
|
2802
|
-
useLoader.clear = function(loader, input) {
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2010
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2011
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2012
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
2805
2013
|
};
|
|
2806
2014
|
useLoader.loader = getLoader;
|
|
2807
2015
|
|
|
2808
2016
|
function useFrame(callback, priorityOrOptions) {
|
|
2809
2017
|
const store = React__namespace.useContext(context);
|
|
2810
2018
|
const isInsideCanvas = store !== null;
|
|
2811
|
-
const scheduler = getScheduler();
|
|
2019
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
2812
2020
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2813
2021
|
id: priorityOrOptions.id,
|
|
2814
2022
|
phase: priorityOrOptions.phase,
|
|
@@ -2856,7 +2064,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2856
2064
|
};
|
|
2857
2065
|
callbackRef.current?.(mergedState, delta);
|
|
2858
2066
|
};
|
|
2859
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2067
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2860
2068
|
id,
|
|
2861
2069
|
rootId,
|
|
2862
2070
|
...options
|
|
@@ -2877,37 +2085,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2877
2085
|
}
|
|
2878
2086
|
};
|
|
2879
2087
|
} else {
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
unregisterJob = registerOutside();
|
|
2889
|
-
});
|
|
2890
|
-
return () => {
|
|
2891
|
-
unsubReady();
|
|
2892
|
-
unregisterJob?.();
|
|
2893
|
-
};
|
|
2088
|
+
return scheduler$1.register(
|
|
2089
|
+
(state, delta) => {
|
|
2090
|
+
const frameState = state;
|
|
2091
|
+
if (!frameState.renderer) return;
|
|
2092
|
+
callbackRef.current?.(frameState, delta);
|
|
2093
|
+
},
|
|
2094
|
+
{ id, ...options }
|
|
2095
|
+
);
|
|
2894
2096
|
}
|
|
2895
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2097
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2896
2098
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
2897
2099
|
// Subscribe function
|
|
2898
2100
|
React__namespace.useCallback(
|
|
2899
2101
|
(onStoreChange) => {
|
|
2900
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2102
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2901
2103
|
},
|
|
2902
2104
|
[id]
|
|
2903
2105
|
),
|
|
2904
2106
|
// getSnapshot function
|
|
2905
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2107
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2906
2108
|
// getServerSnapshot function (SSR)
|
|
2907
2109
|
React__namespace.useCallback(() => false, [])
|
|
2908
2110
|
);
|
|
2909
2111
|
const controls = React__namespace.useMemo(() => {
|
|
2910
|
-
const scheduler2 = getScheduler();
|
|
2112
|
+
const scheduler2 = scheduler.getScheduler();
|
|
2911
2113
|
return {
|
|
2912
2114
|
/** The job's unique ID */
|
|
2913
2115
|
id,
|
|
@@ -2922,7 +2124,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2922
2124
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2923
2125
|
*/
|
|
2924
2126
|
step: (timestamp) => {
|
|
2925
|
-
getScheduler().stepJob(id, timestamp);
|
|
2127
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
2926
2128
|
},
|
|
2927
2129
|
/**
|
|
2928
2130
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -2930,20 +2132,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2930
2132
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2931
2133
|
*/
|
|
2932
2134
|
stepAll: (timestamp) => {
|
|
2933
|
-
getScheduler().step(timestamp);
|
|
2135
|
+
scheduler.getScheduler().step(timestamp);
|
|
2934
2136
|
},
|
|
2935
2137
|
/**
|
|
2936
2138
|
* Pause this job (set enabled=false).
|
|
2937
2139
|
* Job remains registered but won't run.
|
|
2938
2140
|
*/
|
|
2939
2141
|
pause: () => {
|
|
2940
|
-
getScheduler().pauseJob(id);
|
|
2142
|
+
scheduler.getScheduler().pauseJob(id);
|
|
2941
2143
|
},
|
|
2942
2144
|
/**
|
|
2943
2145
|
* Resume this job (set enabled=true).
|
|
2944
2146
|
*/
|
|
2945
2147
|
resume: () => {
|
|
2946
|
-
getScheduler().resumeJob(id);
|
|
2148
|
+
scheduler.getScheduler().resumeJob(id);
|
|
2947
2149
|
},
|
|
2948
2150
|
/**
|
|
2949
2151
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -2981,18 +2183,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2981
2183
|
function useTexture(input, optionsOrOnLoad) {
|
|
2982
2184
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2983
2185
|
const store = useStore();
|
|
2984
|
-
const textureCache = useThree((state) => state.textures);
|
|
2985
2186
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2986
|
-
const { onLoad, cache =
|
|
2187
|
+
const { onLoad, cache = true } = options;
|
|
2987
2188
|
const onLoadRef = React.useRef(onLoad);
|
|
2988
2189
|
onLoadRef.current = onLoad;
|
|
2989
2190
|
const onLoadCalledForRef = React.useRef(null);
|
|
2990
2191
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2991
2192
|
const cachedResult = React.useMemo(() => {
|
|
2992
2193
|
if (!cache) return null;
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2194
|
+
const textures = store.getState().textures;
|
|
2195
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2196
|
+
return buildFromCache(input, textures);
|
|
2197
|
+
}, [cache, urls, input, store]);
|
|
2996
2198
|
const loadedTextures = useLoader(
|
|
2997
2199
|
three.TextureLoader,
|
|
2998
2200
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3036,8 +2238,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3036
2238
|
}, [input, loadedTextures, cachedResult]);
|
|
3037
2239
|
React.useEffect(() => {
|
|
3038
2240
|
if (!cache) return;
|
|
3039
|
-
if (cachedResult) return;
|
|
3040
|
-
const set = store.setState;
|
|
3041
2241
|
const urlTextureMap = [];
|
|
3042
2242
|
if (typeof input === "string") {
|
|
3043
2243
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3051,18 +2251,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3051
2251
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3052
2252
|
}
|
|
3053
2253
|
}
|
|
3054
|
-
|
|
3055
|
-
const
|
|
3056
|
-
let
|
|
2254
|
+
store.setState((state) => {
|
|
2255
|
+
const refs = new Map(state._textureRefs);
|
|
2256
|
+
let textures = state.textures;
|
|
2257
|
+
let added = false;
|
|
3057
2258
|
for (const [url, texture] of urlTextureMap) {
|
|
3058
|
-
if (!
|
|
3059
|
-
|
|
3060
|
-
|
|
2259
|
+
if (!textures.has(url)) {
|
|
2260
|
+
if (!added) {
|
|
2261
|
+
textures = new Map(textures);
|
|
2262
|
+
added = true;
|
|
2263
|
+
}
|
|
2264
|
+
textures.set(url, texture);
|
|
3061
2265
|
}
|
|
2266
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3062
2267
|
}
|
|
3063
|
-
return
|
|
2268
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2269
|
+
});
|
|
2270
|
+
return () => store.setState((state) => {
|
|
2271
|
+
const refs = new Map(state._textureRefs);
|
|
2272
|
+
for (const [url] of urlTextureMap) {
|
|
2273
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2274
|
+
if (next <= 0) refs.delete(url);
|
|
2275
|
+
else refs.set(url, next);
|
|
2276
|
+
}
|
|
2277
|
+
return { _textureRefs: refs };
|
|
3064
2278
|
});
|
|
3065
|
-
}, [cache, input, mappedTextures, store
|
|
2279
|
+
}, [cache, input, mappedTextures, store]);
|
|
3066
2280
|
return mappedTextures;
|
|
3067
2281
|
}
|
|
3068
2282
|
useTexture.preload = (url) => useLoader.preload(three.TextureLoader, url);
|
|
@@ -3078,96 +2292,63 @@ const Texture = ({
|
|
|
3078
2292
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
3079
2293
|
};
|
|
3080
2294
|
|
|
3081
|
-
function
|
|
3082
|
-
if (entry instanceof three.Texture) return entry;
|
|
3083
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof three.Texture) {
|
|
3084
|
-
return entry.value;
|
|
3085
|
-
}
|
|
3086
|
-
return null;
|
|
3087
|
-
}
|
|
3088
|
-
function useTextures() {
|
|
2295
|
+
function useTextures(selector) {
|
|
3089
2296
|
const store = useStore();
|
|
3090
|
-
|
|
3091
|
-
const set = store.setState;
|
|
2297
|
+
const registry = React.useMemo(() => {
|
|
3092
2298
|
const getState = store.getState;
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
const newMap = new Map(state.textures);
|
|
3096
|
-
newMap.set(key, value);
|
|
3097
|
-
return { textures: newMap };
|
|
3098
|
-
});
|
|
3099
|
-
};
|
|
3100
|
-
const addMultiple = (items) => {
|
|
3101
|
-
set((state) => {
|
|
3102
|
-
const newMap = new Map(state.textures);
|
|
3103
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3104
|
-
for (const [key, value] of entries) {
|
|
3105
|
-
newMap.set(key, value);
|
|
3106
|
-
}
|
|
3107
|
-
return { textures: newMap };
|
|
3108
|
-
});
|
|
3109
|
-
};
|
|
3110
|
-
const remove = (key) => {
|
|
3111
|
-
set((state) => {
|
|
3112
|
-
const newMap = new Map(state.textures);
|
|
3113
|
-
newMap.delete(key);
|
|
3114
|
-
return { textures: newMap };
|
|
3115
|
-
});
|
|
3116
|
-
};
|
|
3117
|
-
const removeMultiple = (keys) => {
|
|
3118
|
-
set((state) => {
|
|
3119
|
-
const newMap = new Map(state.textures);
|
|
3120
|
-
for (const key of keys) newMap.delete(key);
|
|
3121
|
-
return { textures: newMap };
|
|
3122
|
-
});
|
|
3123
|
-
};
|
|
3124
|
-
const dispose = (key) => {
|
|
3125
|
-
const entry = getState().textures.get(key);
|
|
3126
|
-
if (entry) {
|
|
3127
|
-
const tex = getTextureValue(entry);
|
|
3128
|
-
tex?.dispose();
|
|
3129
|
-
}
|
|
3130
|
-
remove(key);
|
|
3131
|
-
};
|
|
3132
|
-
const disposeMultiple = (keys) => {
|
|
3133
|
-
const textures = getState().textures;
|
|
3134
|
-
for (const key of keys) {
|
|
3135
|
-
const entry = textures.get(key);
|
|
3136
|
-
if (entry) {
|
|
3137
|
-
const tex = getTextureValue(entry);
|
|
3138
|
-
tex?.dispose();
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
removeMultiple(keys);
|
|
3142
|
-
};
|
|
3143
|
-
const disposeAll = () => {
|
|
3144
|
-
const textures = getState().textures;
|
|
3145
|
-
for (const entry of textures.values()) {
|
|
3146
|
-
const tex = getTextureValue(entry);
|
|
3147
|
-
tex?.dispose();
|
|
3148
|
-
}
|
|
3149
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3150
|
-
};
|
|
2299
|
+
const setState = store.setState;
|
|
2300
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3151
2301
|
return {
|
|
3152
|
-
|
|
3153
|
-
get textures() {
|
|
2302
|
+
get all() {
|
|
3154
2303
|
return getState().textures;
|
|
3155
2304
|
},
|
|
3156
|
-
|
|
3157
|
-
|
|
2305
|
+
get(input) {
|
|
2306
|
+
if (typeof input === "string") return getOne(input);
|
|
2307
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2308
|
+
const out = {};
|
|
2309
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2310
|
+
return out;
|
|
2311
|
+
},
|
|
3158
2312
|
has: (key) => getState().textures.has(key),
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
2313
|
+
add(keyOrRecord, texture) {
|
|
2314
|
+
setState((state) => {
|
|
2315
|
+
const textures = new Map(state.textures);
|
|
2316
|
+
if (typeof keyOrRecord === "string") {
|
|
2317
|
+
textures.set(keyOrRecord, texture);
|
|
2318
|
+
} else {
|
|
2319
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2320
|
+
}
|
|
2321
|
+
return { textures };
|
|
2322
|
+
});
|
|
2323
|
+
},
|
|
2324
|
+
dispose(key, options) {
|
|
2325
|
+
const state = getState();
|
|
2326
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2327
|
+
if (refs > 0 && !options?.force) {
|
|
2328
|
+
console.warn(
|
|
2329
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2330
|
+
);
|
|
2331
|
+
return false;
|
|
2332
|
+
}
|
|
2333
|
+
state.textures.get(key)?.dispose();
|
|
2334
|
+
setState((s) => {
|
|
2335
|
+
const textures = new Map(s.textures);
|
|
2336
|
+
textures.delete(key);
|
|
2337
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2338
|
+
nextRefs.delete(key);
|
|
2339
|
+
return { textures, _textureRefs: nextRefs };
|
|
2340
|
+
});
|
|
2341
|
+
return true;
|
|
2342
|
+
},
|
|
2343
|
+
disposeAll() {
|
|
2344
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2345
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2346
|
+
}
|
|
3169
2347
|
};
|
|
3170
2348
|
}, [store]);
|
|
2349
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2350
|
+
const selected = useThree(subscribe);
|
|
2351
|
+
return selector ? selected : registry;
|
|
3171
2352
|
}
|
|
3172
2353
|
|
|
3173
2354
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3222,7 +2403,7 @@ function addEffect(callback) {
|
|
|
3222
2403
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3223
2404
|
});
|
|
3224
2405
|
const id = `legacy_effect_${effectId++}`;
|
|
3225
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2406
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3226
2407
|
}
|
|
3227
2408
|
function addAfterEffect(callback) {
|
|
3228
2409
|
notifyDepreciated({
|
|
@@ -3231,7 +2412,7 @@ function addAfterEffect(callback) {
|
|
|
3231
2412
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3232
2413
|
});
|
|
3233
2414
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3234
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2415
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3235
2416
|
}
|
|
3236
2417
|
function addTail(callback) {
|
|
3237
2418
|
notifyDepreciated({
|
|
@@ -3239,13 +2420,13 @@ function addTail(callback) {
|
|
|
3239
2420
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3240
2421
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3241
2422
|
});
|
|
3242
|
-
return getScheduler().onIdle(callback);
|
|
2423
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3243
2424
|
}
|
|
3244
2425
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3245
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2426
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3246
2427
|
}
|
|
3247
2428
|
function advance(timestamp) {
|
|
3248
|
-
getScheduler().step(timestamp);
|
|
2429
|
+
scheduler.getScheduler().step(timestamp);
|
|
3249
2430
|
}
|
|
3250
2431
|
|
|
3251
2432
|
const version = "10.0.0-alpha.2";
|
|
@@ -14687,6 +13868,7 @@ function swapInstances() {
|
|
|
14687
13868
|
}
|
|
14688
13869
|
}
|
|
14689
13870
|
if (instance.isHidden) unhideInstance(instance);
|
|
13871
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14690
13872
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14691
13873
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14692
13874
|
}
|
|
@@ -14699,6 +13881,8 @@ function swapInstances() {
|
|
|
14699
13881
|
instance.object.__r3f = instance;
|
|
14700
13882
|
setFiberRef(fiber, instance.object);
|
|
14701
13883
|
delete instance.appliedOnce;
|
|
13884
|
+
instance.eventCount = 0;
|
|
13885
|
+
instance.handlers = {};
|
|
14702
13886
|
applyProps(instance.object, instance.props);
|
|
14703
13887
|
if (instance.props.attach) {
|
|
14704
13888
|
attach(parent, instance);
|
|
@@ -15003,6 +14187,7 @@ function createRoot(canvas) {
|
|
|
15003
14187
|
const lastConfiguredProps = {};
|
|
15004
14188
|
let configured = false;
|
|
15005
14189
|
let pending = null;
|
|
14190
|
+
let rendererSetup = null;
|
|
15006
14191
|
return {
|
|
15007
14192
|
async configure(props = {}) {
|
|
15008
14193
|
let resolve;
|
|
@@ -15018,7 +14203,6 @@ function createRoot(canvas) {
|
|
|
15018
14203
|
events,
|
|
15019
14204
|
onCreated: onCreatedCallback,
|
|
15020
14205
|
shadows = false,
|
|
15021
|
-
textureColorSpace = three.SRGBColorSpace,
|
|
15022
14206
|
orthographic = false,
|
|
15023
14207
|
frameloop = "always",
|
|
15024
14208
|
dpr = [1, 2],
|
|
@@ -15033,7 +14217,8 @@ function createRoot(canvas) {
|
|
|
15033
14217
|
_sizeProps,
|
|
15034
14218
|
forceEven
|
|
15035
14219
|
} = props;
|
|
15036
|
-
const
|
|
14220
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
|
|
14221
|
+
let state = store.getState();
|
|
15037
14222
|
const defaultGLProps = {
|
|
15038
14223
|
canvas,
|
|
15039
14224
|
powerPreference: "high-performance",
|
|
@@ -15061,9 +14246,21 @@ function createRoot(canvas) {
|
|
|
15061
14246
|
);
|
|
15062
14247
|
}
|
|
15063
14248
|
if (!state.internal.actualRenderer) {
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
14249
|
+
if (!rendererSetup) {
|
|
14250
|
+
rendererSetup = (async () => {
|
|
14251
|
+
{
|
|
14252
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
|
|
14253
|
+
state.internal.actualRenderer = renderer;
|
|
14254
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14255
|
+
}
|
|
14256
|
+
})().catch((err) => {
|
|
14257
|
+
rendererSetup = null;
|
|
14258
|
+
throw err;
|
|
14259
|
+
});
|
|
14260
|
+
}
|
|
14261
|
+
await rendererSetup;
|
|
14262
|
+
state = store.getState();
|
|
14263
|
+
renderer = state.internal.actualRenderer;
|
|
15067
14264
|
}
|
|
15068
14265
|
let raycaster = state.raycaster;
|
|
15069
14266
|
if (!raycaster) state.set({ raycaster: raycaster = new three.Raycaster() });
|
|
@@ -15156,7 +14353,7 @@ function createRoot(canvas) {
|
|
|
15156
14353
|
lastConfiguredProps.performance = performance;
|
|
15157
14354
|
}
|
|
15158
14355
|
if (!state.xr) {
|
|
15159
|
-
const handleXRFrame = (timestamp,
|
|
14356
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15160
14357
|
const state2 = store.getState();
|
|
15161
14358
|
if (state2.frameloop === "never") return;
|
|
15162
14359
|
advance(timestamp);
|
|
@@ -15192,15 +14389,22 @@ function createRoot(canvas) {
|
|
|
15192
14389
|
const oldType = renderer.shadowMap.type;
|
|
15193
14390
|
renderer.shadowMap.enabled = !!shadows;
|
|
15194
14391
|
if (is.boo(shadows)) {
|
|
15195
|
-
renderer.shadowMap.type = three.
|
|
14392
|
+
renderer.shadowMap.type = three.PCFShadowMap;
|
|
15196
14393
|
} else if (is.str(shadows)) {
|
|
14394
|
+
if (shadows === "soft") {
|
|
14395
|
+
notifyDepreciated({
|
|
14396
|
+
heading: 'shadows="soft" is deprecated',
|
|
14397
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14398
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14399
|
+
});
|
|
14400
|
+
}
|
|
15197
14401
|
const types = {
|
|
15198
14402
|
basic: three.BasicShadowMap,
|
|
15199
14403
|
percentage: three.PCFShadowMap,
|
|
15200
|
-
soft: three.
|
|
14404
|
+
soft: three.PCFShadowMap,
|
|
15201
14405
|
variance: three.VSMShadowMap
|
|
15202
14406
|
};
|
|
15203
|
-
renderer.shadowMap.type = types[shadows] ?? three.
|
|
14407
|
+
renderer.shadowMap.type = types[shadows] ?? three.PCFShadowMap;
|
|
15204
14408
|
} else if (is.obj(shadows)) {
|
|
15205
14409
|
Object.assign(renderer.shadowMap, shadows);
|
|
15206
14410
|
}
|
|
@@ -15216,24 +14420,35 @@ function createRoot(canvas) {
|
|
|
15216
14420
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15217
14421
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15218
14422
|
}
|
|
14423
|
+
const r3fProps = ["textureColorSpace"];
|
|
14424
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14425
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15219
14426
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15220
|
-
|
|
14427
|
+
const glProps = {};
|
|
14428
|
+
for (const key in glConfig) {
|
|
14429
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14430
|
+
}
|
|
14431
|
+
applyProps(renderer, glProps);
|
|
15221
14432
|
}
|
|
15222
14433
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15223
14434
|
const currentRenderer = state.renderer;
|
|
15224
14435
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15225
|
-
|
|
14436
|
+
const rendererProps = {};
|
|
14437
|
+
for (const key in rendererConfig) {
|
|
14438
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14439
|
+
}
|
|
14440
|
+
applyProps(currentRenderer, rendererProps);
|
|
15226
14441
|
}
|
|
15227
14442
|
}
|
|
15228
|
-
const scheduler = getScheduler();
|
|
14443
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15229
14444
|
const rootId = state.internal.rootId;
|
|
15230
14445
|
if (!rootId) {
|
|
15231
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15232
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14446
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14447
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15233
14448
|
getState: () => store.getState(),
|
|
15234
14449
|
onError: (err) => store.getState().setError(err)
|
|
15235
14450
|
});
|
|
15236
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14451
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15237
14452
|
() => {
|
|
15238
14453
|
const state2 = store.getState();
|
|
15239
14454
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15248,7 +14463,19 @@ function createRoot(canvas) {
|
|
|
15248
14463
|
system: true
|
|
15249
14464
|
}
|
|
15250
14465
|
);
|
|
15251
|
-
const
|
|
14466
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
14467
|
+
() => {
|
|
14468
|
+
const state2 = store.getState();
|
|
14469
|
+
state2.events.flush?.();
|
|
14470
|
+
},
|
|
14471
|
+
{
|
|
14472
|
+
id: `${newRootId}_events`,
|
|
14473
|
+
rootId: newRootId,
|
|
14474
|
+
phase: "input",
|
|
14475
|
+
system: true
|
|
14476
|
+
}
|
|
14477
|
+
);
|
|
14478
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15252
14479
|
() => {
|
|
15253
14480
|
const state2 = store.getState();
|
|
15254
14481
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15258,11 +14485,11 @@ function createRoot(canvas) {
|
|
|
15258
14485
|
{
|
|
15259
14486
|
id: `${newRootId}_frustum`,
|
|
15260
14487
|
rootId: newRootId,
|
|
15261
|
-
|
|
14488
|
+
before: "render",
|
|
15262
14489
|
system: true
|
|
15263
14490
|
}
|
|
15264
14491
|
);
|
|
15265
|
-
const unregisterVisibility = scheduler.register(
|
|
14492
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15266
14493
|
() => {
|
|
15267
14494
|
const state2 = store.getState();
|
|
15268
14495
|
checkVisibility(state2);
|
|
@@ -15270,19 +14497,19 @@ function createRoot(canvas) {
|
|
|
15270
14497
|
{
|
|
15271
14498
|
id: `${newRootId}_visibility`,
|
|
15272
14499
|
rootId: newRootId,
|
|
15273
|
-
|
|
14500
|
+
before: "render",
|
|
15274
14501
|
system: true,
|
|
15275
14502
|
after: `${newRootId}_frustum`
|
|
15276
14503
|
}
|
|
15277
14504
|
);
|
|
15278
|
-
const unregisterRender = scheduler.register(
|
|
14505
|
+
const unregisterRender = scheduler$1.register(
|
|
15279
14506
|
() => {
|
|
15280
14507
|
const state2 = store.getState();
|
|
15281
14508
|
const renderer2 = state2.internal.actualRenderer;
|
|
15282
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14509
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15283
14510
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15284
14511
|
try {
|
|
15285
|
-
if (state2.
|
|
14512
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15286
14513
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15287
14514
|
} catch (error) {
|
|
15288
14515
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15307,15 +14534,16 @@ function createRoot(canvas) {
|
|
|
15307
14534
|
unregisterRoot: () => {
|
|
15308
14535
|
unregisterRoot();
|
|
15309
14536
|
unregisterCanvasTarget();
|
|
14537
|
+
unregisterEventsFlush();
|
|
15310
14538
|
unregisterFrustum();
|
|
15311
14539
|
unregisterVisibility();
|
|
15312
14540
|
unregisterRender();
|
|
15313
14541
|
},
|
|
15314
|
-
scheduler
|
|
14542
|
+
scheduler: scheduler$1
|
|
15315
14543
|
}
|
|
15316
14544
|
}));
|
|
15317
14545
|
}
|
|
15318
|
-
scheduler.frameloop = frameloop;
|
|
14546
|
+
scheduler$1.frameloop = frameloop;
|
|
15319
14547
|
onCreated = onCreatedCallback;
|
|
15320
14548
|
configured = true;
|
|
15321
14549
|
resolve();
|
|
@@ -15445,6 +14673,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15445
14673
|
viewport = rootState.viewport.getCurrentViewport(camera, new three.Vector3(), resolvedSize);
|
|
15446
14674
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
15447
14675
|
}
|
|
14676
|
+
const set = injectState.set;
|
|
15448
14677
|
return {
|
|
15449
14678
|
// The intersect consists of the previous root state
|
|
15450
14679
|
...rootState,
|
|
@@ -15463,7 +14692,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15463
14692
|
size: resolvedSize,
|
|
15464
14693
|
viewport: { ...rootState.viewport, ...viewport },
|
|
15465
14694
|
// Layers are allowed to override events
|
|
15466
|
-
setEvents: (events2) =>
|
|
14695
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
15467
14696
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
15468
14697
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
15469
14698
|
};
|
|
@@ -15472,9 +14701,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15472
14701
|
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15473
14702
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15474
14703
|
onMutate(previousRoot.getState());
|
|
15475
|
-
previousRoot.subscribe(onMutate);
|
|
15476
14704
|
return store;
|
|
15477
14705
|
}, [previousRoot, container]);
|
|
14706
|
+
useIsomorphicLayoutEffect(() => {
|
|
14707
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14708
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14709
|
+
return unsubscribe;
|
|
14710
|
+
}, [previousRoot, usePortalStore]);
|
|
15478
14711
|
return (
|
|
15479
14712
|
// @ts-ignore, reconciler types are not maintained
|
|
15480
14713
|
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
@@ -15488,6 +14721,59 @@ function flushSync(fn) {
|
|
|
15488
14721
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15489
14722
|
}
|
|
15490
14723
|
|
|
14724
|
+
function parseBackground(background) {
|
|
14725
|
+
if (!background) return null;
|
|
14726
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14727
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14728
|
+
return {
|
|
14729
|
+
...rest,
|
|
14730
|
+
preset,
|
|
14731
|
+
files: envMap || files,
|
|
14732
|
+
backgroundFiles: backgroundMap,
|
|
14733
|
+
background: true
|
|
14734
|
+
};
|
|
14735
|
+
}
|
|
14736
|
+
if (typeof background === "number") {
|
|
14737
|
+
return { color: background, background: true };
|
|
14738
|
+
}
|
|
14739
|
+
if (typeof background === "string") {
|
|
14740
|
+
if (background in presetsObj) {
|
|
14741
|
+
return { preset: background, background: true };
|
|
14742
|
+
}
|
|
14743
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14744
|
+
return { files: background, background: true };
|
|
14745
|
+
}
|
|
14746
|
+
return { color: background, background: true };
|
|
14747
|
+
}
|
|
14748
|
+
if (background.isColor) {
|
|
14749
|
+
return { color: background, background: true };
|
|
14750
|
+
}
|
|
14751
|
+
return null;
|
|
14752
|
+
}
|
|
14753
|
+
|
|
14754
|
+
function parseRendererConfig(rendererProp) {
|
|
14755
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14756
|
+
if (isRendererConfig) {
|
|
14757
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14758
|
+
return {
|
|
14759
|
+
primaryCanvas: pc,
|
|
14760
|
+
scheduler: sc,
|
|
14761
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14762
|
+
};
|
|
14763
|
+
}
|
|
14764
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14765
|
+
}
|
|
14766
|
+
|
|
14767
|
+
function clearHmrCaches(store) {
|
|
14768
|
+
store.setState((state) => ({
|
|
14769
|
+
nodes: {},
|
|
14770
|
+
uniforms: {},
|
|
14771
|
+
buffers: {},
|
|
14772
|
+
gpuStorage: {},
|
|
14773
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14774
|
+
}));
|
|
14775
|
+
}
|
|
14776
|
+
|
|
15491
14777
|
function CanvasImpl({
|
|
15492
14778
|
ref,
|
|
15493
14779
|
children,
|
|
@@ -15508,6 +14794,8 @@ function CanvasImpl({
|
|
|
15508
14794
|
raycaster,
|
|
15509
14795
|
camera,
|
|
15510
14796
|
scene,
|
|
14797
|
+
autoUpdateFrustum,
|
|
14798
|
+
occlusion,
|
|
15511
14799
|
onPointerMissed,
|
|
15512
14800
|
onDragOverMissed,
|
|
15513
14801
|
onDropMissed,
|
|
@@ -15519,39 +14807,10 @@ function CanvasImpl({
|
|
|
15519
14807
|
forceEven,
|
|
15520
14808
|
...props
|
|
15521
14809
|
}) {
|
|
15522
|
-
const { primaryCanvas, scheduler,
|
|
15523
|
-
const renderer = Object.keys(rendererConfig).length > 0 ? rendererConfig : rendererProp;
|
|
14810
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15524
14811
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15525
14812
|
const Bridge = useBridge();
|
|
15526
|
-
const backgroundProps = React__namespace.useMemo(() =>
|
|
15527
|
-
if (!background) return null;
|
|
15528
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15529
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15530
|
-
return {
|
|
15531
|
-
...rest,
|
|
15532
|
-
preset,
|
|
15533
|
-
files: envMap || files,
|
|
15534
|
-
backgroundFiles: backgroundMap,
|
|
15535
|
-
background: true
|
|
15536
|
-
};
|
|
15537
|
-
}
|
|
15538
|
-
if (typeof background === "number") {
|
|
15539
|
-
return { color: background, background: true };
|
|
15540
|
-
}
|
|
15541
|
-
if (typeof background === "string") {
|
|
15542
|
-
if (background in presetsObj) {
|
|
15543
|
-
return { preset: background, background: true };
|
|
15544
|
-
}
|
|
15545
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15546
|
-
return { files: background, background: true };
|
|
15547
|
-
}
|
|
15548
|
-
return { color: background, background: true };
|
|
15549
|
-
}
|
|
15550
|
-
if (background.isColor) {
|
|
15551
|
-
return { color: background, background: true };
|
|
15552
|
-
}
|
|
15553
|
-
return null;
|
|
15554
|
-
}, [background]);
|
|
14813
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15555
14814
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15556
14815
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15557
14816
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15593,6 +14852,7 @@ function CanvasImpl({
|
|
|
15593
14852
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15594
14853
|
const [block, setBlock] = React__namespace.useState(false);
|
|
15595
14854
|
const [error, setError] = React__namespace.useState(false);
|
|
14855
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
15596
14856
|
if (block) throw block;
|
|
15597
14857
|
if (error) throw error;
|
|
15598
14858
|
const root = React__namespace.useRef(null);
|
|
@@ -15600,6 +14860,7 @@ function CanvasImpl({
|
|
|
15600
14860
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
15601
14861
|
useIsomorphicLayoutEffect(() => {
|
|
15602
14862
|
effectActiveRef.current = true;
|
|
14863
|
+
if (fallbackVisible) return;
|
|
15603
14864
|
const canvas = canvasRef.current;
|
|
15604
14865
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15605
14866
|
if (!root.current) {
|
|
@@ -15620,7 +14881,7 @@ function CanvasImpl({
|
|
|
15620
14881
|
}
|
|
15621
14882
|
async function run() {
|
|
15622
14883
|
if (!effectActiveRef.current || !root.current) return;
|
|
15623
|
-
await root.current.configure({
|
|
14884
|
+
const configured = await root.current.configure({
|
|
15624
14885
|
id,
|
|
15625
14886
|
primaryCanvas,
|
|
15626
14887
|
scheduler,
|
|
@@ -15635,6 +14896,8 @@ function CanvasImpl({
|
|
|
15635
14896
|
performance,
|
|
15636
14897
|
raycaster,
|
|
15637
14898
|
camera,
|
|
14899
|
+
autoUpdateFrustum,
|
|
14900
|
+
occlusion,
|
|
15638
14901
|
size: effectiveSize,
|
|
15639
14902
|
// Store size props for reset functionality
|
|
15640
14903
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15659,8 +14922,20 @@ function CanvasImpl({
|
|
|
15659
14922
|
}
|
|
15660
14923
|
onCreated?.(state);
|
|
15661
14924
|
}
|
|
15662
|
-
})
|
|
15663
|
-
|
|
14925
|
+
}).then(
|
|
14926
|
+
() => true,
|
|
14927
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
14928
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
14929
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
14930
|
+
(setupError) => {
|
|
14931
|
+
if (effectActiveRef.current) {
|
|
14932
|
+
if (fallback != null) setFallbackVisible(true);
|
|
14933
|
+
else setError(setupError);
|
|
14934
|
+
}
|
|
14935
|
+
return false;
|
|
14936
|
+
}
|
|
14937
|
+
);
|
|
14938
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15664
14939
|
root.current.render(
|
|
15665
14940
|
/* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Block, { set: setBlock }), children: [
|
|
15666
14941
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -15694,20 +14969,13 @@ function CanvasImpl({
|
|
|
15694
14969
|
const handleHMR = () => {
|
|
15695
14970
|
queueMicrotask(() => {
|
|
15696
14971
|
const rootEntry = _roots.get(canvas);
|
|
15697
|
-
if (rootEntry?.store)
|
|
15698
|
-
rootEntry.store.setState((state) => ({
|
|
15699
|
-
nodes: {},
|
|
15700
|
-
uniforms: {},
|
|
15701
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15702
|
-
}));
|
|
15703
|
-
}
|
|
14972
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15704
14973
|
});
|
|
15705
14974
|
};
|
|
15706
14975
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('legacy.cjs', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
15707
14976
|
const hot = undefined;
|
|
15708
14977
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15709
|
-
return () => hot.
|
|
15710
|
-
});
|
|
14978
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15711
14979
|
}
|
|
15712
14980
|
if (typeof module !== "undefined" && module.hot) {
|
|
15713
14981
|
const hot = module.hot;
|
|
@@ -15730,7 +14998,20 @@ function CanvasImpl({
|
|
|
15730
14998
|
...style
|
|
15731
14999
|
},
|
|
15732
15000
|
...props,
|
|
15733
|
-
children:
|
|
15001
|
+
children: fallbackVisible ? (
|
|
15002
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15003
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15004
|
+
fallback
|
|
15005
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
15006
|
+
"canvas",
|
|
15007
|
+
{
|
|
15008
|
+
ref: canvasRef,
|
|
15009
|
+
id,
|
|
15010
|
+
className: "r3f-canvas",
|
|
15011
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
15012
|
+
children: fallback
|
|
15013
|
+
}
|
|
15014
|
+
) })
|
|
15734
15015
|
}
|
|
15735
15016
|
);
|
|
15736
15017
|
}
|
|
@@ -15740,6 +15021,8 @@ function Canvas(props) {
|
|
|
15740
15021
|
|
|
15741
15022
|
extend(THREE);
|
|
15742
15023
|
|
|
15024
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
15025
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
15743
15026
|
exports.Block = Block;
|
|
15744
15027
|
exports.Canvas = Canvas;
|
|
15745
15028
|
exports.Environment = Environment;
|
|
@@ -15755,7 +15038,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
15755
15038
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
15756
15039
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
15757
15040
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
15758
|
-
exports.Scheduler = Scheduler;
|
|
15759
15041
|
exports.Texture = Texture;
|
|
15760
15042
|
exports._roots = _roots;
|
|
15761
15043
|
exports.act = act;
|
|
@@ -15785,7 +15067,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
15785
15067
|
exports.getPrimary = getPrimary;
|
|
15786
15068
|
exports.getPrimaryIds = getPrimaryIds;
|
|
15787
15069
|
exports.getRootState = getRootState;
|
|
15788
|
-
exports.getScheduler = getScheduler;
|
|
15789
15070
|
exports.getUuidPrefix = getUuidPrefix;
|
|
15790
15071
|
exports.hasConstructor = hasConstructor;
|
|
15791
15072
|
exports.hasPrimary = hasPrimary;
|