@react-three/fiber 10.0.0-canary.2b511a5 → 10.0.0-canary.2c50459
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 +529 -1305
- package/dist/index.d.cts +246 -785
- package/dist/index.d.mts +246 -785
- package/dist/index.d.ts +246 -785
- package/dist/index.mjs +503 -1278
- package/dist/legacy.cjs +523 -1305
- package/dist/legacy.d.cts +246 -785
- package/dist/legacy.d.mts +246 -785
- package/dist/legacy.d.ts +246 -785
- package/dist/legacy.mjs +497 -1278
- package/dist/webgpu/index.cjs +937 -1331
- package/dist/webgpu/index.d.cts +331 -798
- package/dist/webgpu/index.d.mts +331 -798
- package/dist/webgpu/index.d.ts +331 -798
- package/dist/webgpu/index.mjs +906 -1303
- 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 = {
|
|
@@ -1005,6 +1021,9 @@ function applyProps(object, props) {
|
|
|
1005
1021
|
else target.set(value);
|
|
1006
1022
|
} else {
|
|
1007
1023
|
root[key] = value;
|
|
1024
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1025
|
+
root.needsUpdate = true;
|
|
1026
|
+
}
|
|
1008
1027
|
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
1028
|
root[key].format === three.RGBAFormat && root[key].type === three.UnsignedByteType) {
|
|
1010
1029
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -1038,38 +1057,60 @@ function applyProps(object, props) {
|
|
|
1038
1057
|
return object;
|
|
1039
1058
|
}
|
|
1040
1059
|
|
|
1060
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1061
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1062
|
+
function getPointerState(internal, pointerId) {
|
|
1063
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1064
|
+
if (!state) {
|
|
1065
|
+
state = {
|
|
1066
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1067
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1068
|
+
initialClick: [0, 0],
|
|
1069
|
+
initialHits: []
|
|
1070
|
+
};
|
|
1071
|
+
internal.pointerMap.set(pointerId, state);
|
|
1072
|
+
}
|
|
1073
|
+
return state;
|
|
1074
|
+
}
|
|
1075
|
+
function getPointerId(event) {
|
|
1076
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1077
|
+
}
|
|
1041
1078
|
function makeId(event) {
|
|
1042
1079
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1043
1080
|
}
|
|
1044
|
-
function releaseInternalPointerCapture(
|
|
1045
|
-
const
|
|
1081
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1082
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1083
|
+
if (!pointerState) return;
|
|
1084
|
+
const captureData = pointerState.captured.get(obj);
|
|
1046
1085
|
if (captureData) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
capturedMap.delete(pointerId);
|
|
1050
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
1051
|
-
}
|
|
1086
|
+
pointerState.captured.delete(obj);
|
|
1087
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1052
1088
|
}
|
|
1053
1089
|
}
|
|
1054
1090
|
function removeInteractivity(store, object) {
|
|
1055
1091
|
const { internal } = store.getState();
|
|
1056
1092
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1093
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1094
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1095
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1096
|
+
if (value.eventObject === object || value.object === object) {
|
|
1097
|
+
pointerState.hovered.delete(key);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
if (pointerState.captured.has(object)) {
|
|
1101
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1061
1102
|
}
|
|
1062
|
-
}
|
|
1063
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1064
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1065
|
-
});
|
|
1103
|
+
}
|
|
1066
1104
|
unregisterVisibility(store, object);
|
|
1067
1105
|
}
|
|
1068
1106
|
function createEvents(store) {
|
|
1069
|
-
function calculateDistance(event) {
|
|
1107
|
+
function calculateDistance(event, pointerId) {
|
|
1070
1108
|
const { internal } = store.getState();
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1109
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1110
|
+
if (!pointerState) return 0;
|
|
1111
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1112
|
+
const dx = event.offsetX - initialX;
|
|
1113
|
+
const dy = event.offsetY - initialY;
|
|
1073
1114
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1074
1115
|
}
|
|
1075
1116
|
function filterPointerEvents(objects) {
|
|
@@ -1105,6 +1146,15 @@ function createEvents(store) {
|
|
|
1105
1146
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1106
1147
|
}
|
|
1107
1148
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1149
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1150
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1151
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1152
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1153
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1154
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1155
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1108
1158
|
const aState = getRootState(a.object);
|
|
1109
1159
|
const bState = getRootState(b.object);
|
|
1110
1160
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1126,9 +1176,13 @@ function createEvents(store) {
|
|
|
1126
1176
|
eventObject = eventObject.parent;
|
|
1127
1177
|
}
|
|
1128
1178
|
}
|
|
1129
|
-
if ("pointerId" in event
|
|
1130
|
-
|
|
1131
|
-
|
|
1179
|
+
if ("pointerId" in event) {
|
|
1180
|
+
const pointerId = event.pointerId;
|
|
1181
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1182
|
+
if (pointerState?.captured.size) {
|
|
1183
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1184
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1185
|
+
}
|
|
1132
1186
|
}
|
|
1133
1187
|
}
|
|
1134
1188
|
return intersections;
|
|
@@ -1141,27 +1195,25 @@ function createEvents(store) {
|
|
|
1141
1195
|
if (state) {
|
|
1142
1196
|
const { raycaster, pointer, camera, internal } = state;
|
|
1143
1197
|
const unprojectedPoint = new three.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1144
|
-
const hasPointerCapture = (id) =>
|
|
1198
|
+
const hasPointerCapture = (id) => {
|
|
1199
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1200
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1201
|
+
};
|
|
1145
1202
|
const setPointerCapture = (id) => {
|
|
1146
1203
|
const captureData = { intersection: hit, target: event.target };
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
} else {
|
|
1150
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1151
|
-
}
|
|
1204
|
+
const pointerState = getPointerState(internal, id);
|
|
1205
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1152
1206
|
event.target.setPointerCapture(id);
|
|
1153
1207
|
};
|
|
1154
1208
|
const releasePointerCapture = (id) => {
|
|
1155
|
-
|
|
1156
|
-
if (captures) {
|
|
1157
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1158
|
-
}
|
|
1209
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1159
1210
|
};
|
|
1160
1211
|
const extractEventProps = {};
|
|
1161
1212
|
for (const prop in event) {
|
|
1162
1213
|
const property = event[prop];
|
|
1163
1214
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1164
1215
|
}
|
|
1216
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1165
1217
|
const raycastEvent = {
|
|
1166
1218
|
...hit,
|
|
1167
1219
|
...extractEventProps,
|
|
@@ -1172,18 +1224,19 @@ function createEvents(store) {
|
|
|
1172
1224
|
unprojectedPoint,
|
|
1173
1225
|
ray: raycaster.ray,
|
|
1174
1226
|
camera,
|
|
1227
|
+
pointerId: eventPointerId,
|
|
1175
1228
|
// Hijack stopPropagation, which just sets a flag
|
|
1176
1229
|
stopPropagation() {
|
|
1177
|
-
const
|
|
1230
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1178
1231
|
if (
|
|
1179
1232
|
// ...if this pointer hasn't been captured
|
|
1180
|
-
!
|
|
1181
|
-
|
|
1233
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1234
|
+
pointerState.captured.has(hit.eventObject)
|
|
1182
1235
|
) {
|
|
1183
1236
|
raycastEvent.stopped = localState.stopped = true;
|
|
1184
|
-
if (
|
|
1237
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1185
1238
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1186
|
-
cancelPointer([...higher, hit]);
|
|
1239
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1187
1240
|
}
|
|
1188
1241
|
}
|
|
1189
1242
|
},
|
|
@@ -1199,15 +1252,18 @@ function createEvents(store) {
|
|
|
1199
1252
|
}
|
|
1200
1253
|
return intersections;
|
|
1201
1254
|
}
|
|
1202
|
-
function cancelPointer(intersections) {
|
|
1255
|
+
function cancelPointer(intersections, pointerId) {
|
|
1203
1256
|
const { internal } = store.getState();
|
|
1204
|
-
|
|
1257
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1258
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1259
|
+
if (!pointerState) return;
|
|
1260
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1205
1261
|
if (!intersections.length || !intersections.find(
|
|
1206
1262
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1207
1263
|
)) {
|
|
1208
1264
|
const eventObject = hoveredObj.eventObject;
|
|
1209
1265
|
const instance = eventObject.__r3f;
|
|
1210
|
-
|
|
1266
|
+
pointerState.hovered.delete(hoveredId);
|
|
1211
1267
|
if (instance?.eventCount) {
|
|
1212
1268
|
const handlers = instance.handlers;
|
|
1213
1269
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1236,41 +1292,118 @@ function createEvents(store) {
|
|
|
1236
1292
|
instance?.handlers.onDropMissed?.(event);
|
|
1237
1293
|
}
|
|
1238
1294
|
}
|
|
1295
|
+
function cleanupPointer(pointerId) {
|
|
1296
|
+
const { internal } = store.getState();
|
|
1297
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1298
|
+
if (pointerState) {
|
|
1299
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1300
|
+
const eventObject = hoveredObj.eventObject;
|
|
1301
|
+
const instance = eventObject.__r3f;
|
|
1302
|
+
if (instance?.eventCount) {
|
|
1303
|
+
const handlers = instance.handlers;
|
|
1304
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1305
|
+
handlers.onPointerOut?.(data);
|
|
1306
|
+
handlers.onPointerLeave?.(data);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
internal.pointerMap.delete(pointerId);
|
|
1310
|
+
}
|
|
1311
|
+
internal.pointerDirty.delete(pointerId);
|
|
1312
|
+
}
|
|
1313
|
+
function processDeferredPointer(event, pointerId) {
|
|
1314
|
+
const state = store.getState();
|
|
1315
|
+
const { internal } = state;
|
|
1316
|
+
if (!state.events.enabled) return;
|
|
1317
|
+
const filter = filterPointerEvents;
|
|
1318
|
+
const hits = intersect(event, filter);
|
|
1319
|
+
cancelPointer(hits, pointerId);
|
|
1320
|
+
function onIntersect(data) {
|
|
1321
|
+
const eventObject = data.eventObject;
|
|
1322
|
+
const instance = eventObject.__r3f;
|
|
1323
|
+
if (!instance?.eventCount) return;
|
|
1324
|
+
const handlers = instance.handlers;
|
|
1325
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1326
|
+
const id = makeId(data);
|
|
1327
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1328
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1329
|
+
if (!hoveredItem) {
|
|
1330
|
+
pointerState.hovered.set(id, data);
|
|
1331
|
+
handlers.onPointerOver?.(data);
|
|
1332
|
+
handlers.onPointerEnter?.(data);
|
|
1333
|
+
} else if (hoveredItem.stopped) {
|
|
1334
|
+
data.stopPropagation();
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
handlers.onPointerMove?.(data);
|
|
1338
|
+
}
|
|
1339
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1340
|
+
}
|
|
1239
1341
|
function handlePointer(name) {
|
|
1240
1342
|
switch (name) {
|
|
1241
1343
|
case "onPointerLeave":
|
|
1242
|
-
case "onPointerCancel":
|
|
1243
1344
|
case "onDragLeave":
|
|
1244
1345
|
return () => cancelPointer([]);
|
|
1346
|
+
// Global cancel of these events
|
|
1347
|
+
case "onPointerCancel":
|
|
1348
|
+
return (event) => {
|
|
1349
|
+
const pointerId = getPointerId(event);
|
|
1350
|
+
cleanupPointer(pointerId);
|
|
1351
|
+
};
|
|
1245
1352
|
case "onLostPointerCapture":
|
|
1246
1353
|
return (event) => {
|
|
1247
1354
|
const { internal } = store.getState();
|
|
1248
|
-
|
|
1355
|
+
const pointerId = getPointerId(event);
|
|
1356
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1357
|
+
if (pointerState?.captured.size) {
|
|
1249
1358
|
requestAnimationFrame(() => {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1359
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1360
|
+
if (pointerState2?.captured.size) {
|
|
1361
|
+
pointerState2.captured.clear();
|
|
1253
1362
|
}
|
|
1363
|
+
cancelPointer([], pointerId);
|
|
1254
1364
|
});
|
|
1255
1365
|
}
|
|
1256
1366
|
};
|
|
1257
1367
|
}
|
|
1258
1368
|
return function handleEvent(event) {
|
|
1259
1369
|
const state = store.getState();
|
|
1260
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1370
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1371
|
+
const pointerId = getPointerId(event);
|
|
1261
1372
|
internal.lastEvent.current = event;
|
|
1262
|
-
if (!
|
|
1373
|
+
if (!events.enabled) return;
|
|
1263
1374
|
const isPointerMove = name === "onPointerMove";
|
|
1264
1375
|
const isDragOver = name === "onDragOver";
|
|
1265
1376
|
const isDrop = name === "onDrop";
|
|
1266
1377
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1378
|
+
const isPointerDown = name === "onPointerDown";
|
|
1379
|
+
const isPointerUp = name === "onPointerUp";
|
|
1380
|
+
const isWheel = name === "onWheel";
|
|
1381
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1382
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1383
|
+
events.compute?.(event, state);
|
|
1384
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1388
|
+
events.compute?.(event, state);
|
|
1389
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1393
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1394
|
+
internal.pointerDirty.delete(pointerId);
|
|
1395
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1396
|
+
}
|
|
1267
1397
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1268
1398
|
const hits = intersect(event, filter);
|
|
1269
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1270
|
-
if (
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1399
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1400
|
+
if (isPointerDown) {
|
|
1401
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1402
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1403
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1404
|
+
}
|
|
1405
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1406
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1274
1407
|
if (isClickEvent && !hits.length) {
|
|
1275
1408
|
if (delta <= 2) {
|
|
1276
1409
|
pointerMissed(event, internal.interaction);
|
|
@@ -1285,7 +1418,9 @@ function createEvents(store) {
|
|
|
1285
1418
|
dropMissed(event, internal.interaction);
|
|
1286
1419
|
if (onDropMissed) onDropMissed(event);
|
|
1287
1420
|
}
|
|
1288
|
-
if (isPointerMove || isDragOver)
|
|
1421
|
+
if (isPointerMove || isDragOver) {
|
|
1422
|
+
cancelPointer(hits, pointerId);
|
|
1423
|
+
}
|
|
1289
1424
|
function onIntersect(data) {
|
|
1290
1425
|
const eventObject = data.eventObject;
|
|
1291
1426
|
const instance = eventObject.__r3f;
|
|
@@ -1294,9 +1429,10 @@ function createEvents(store) {
|
|
|
1294
1429
|
if (isPointerMove) {
|
|
1295
1430
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1296
1431
|
const id = makeId(data);
|
|
1297
|
-
const
|
|
1432
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1433
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1298
1434
|
if (!hoveredItem) {
|
|
1299
|
-
|
|
1435
|
+
pointerState2.hovered.set(id, data);
|
|
1300
1436
|
handlers.onPointerOver?.(data);
|
|
1301
1437
|
handlers.onPointerEnter?.(data);
|
|
1302
1438
|
} else if (hoveredItem.stopped) {
|
|
@@ -1306,9 +1442,10 @@ function createEvents(store) {
|
|
|
1306
1442
|
handlers.onPointerMove?.(data);
|
|
1307
1443
|
} else if (isDragOver) {
|
|
1308
1444
|
const id = makeId(data);
|
|
1309
|
-
const
|
|
1445
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1446
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1310
1447
|
if (!hoveredItem) {
|
|
1311
|
-
|
|
1448
|
+
pointerState2.hovered.set(id, data);
|
|
1312
1449
|
handlers.onDragOverEnter?.(data);
|
|
1313
1450
|
} else if (hoveredItem.stopped) {
|
|
1314
1451
|
data.stopPropagation();
|
|
@@ -1319,18 +1456,18 @@ function createEvents(store) {
|
|
|
1319
1456
|
} else {
|
|
1320
1457
|
const handler = handlers[name];
|
|
1321
1458
|
if (handler) {
|
|
1322
|
-
if (!isClickEvent ||
|
|
1459
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1323
1460
|
pointerMissed(
|
|
1324
1461
|
event,
|
|
1325
|
-
internal.interaction.filter((object) => !
|
|
1462
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1326
1463
|
);
|
|
1327
1464
|
handler(data);
|
|
1328
1465
|
}
|
|
1329
1466
|
} else {
|
|
1330
|
-
if (isClickEvent &&
|
|
1467
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1331
1468
|
pointerMissed(
|
|
1332
1469
|
event,
|
|
1333
|
-
internal.interaction.filter((object) => !
|
|
1470
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1334
1471
|
);
|
|
1335
1472
|
}
|
|
1336
1473
|
}
|
|
@@ -1339,7 +1476,15 @@ function createEvents(store) {
|
|
|
1339
1476
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1340
1477
|
};
|
|
1341
1478
|
}
|
|
1342
|
-
|
|
1479
|
+
function flushDeferredPointers() {
|
|
1480
|
+
const { internal, events } = store.getState();
|
|
1481
|
+
if (!events.frameTimedRaycasts) return;
|
|
1482
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1483
|
+
processDeferredPointer(event, pointerId);
|
|
1484
|
+
}
|
|
1485
|
+
internal.pointerDirty.clear();
|
|
1486
|
+
}
|
|
1487
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1343
1488
|
}
|
|
1344
1489
|
const DOM_EVENTS = {
|
|
1345
1490
|
onClick: ["click", false],
|
|
@@ -1358,10 +1503,15 @@ const DOM_EVENTS = {
|
|
|
1358
1503
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1359
1504
|
};
|
|
1360
1505
|
function createPointerEvents(store) {
|
|
1361
|
-
const { handlePointer } = createEvents(store);
|
|
1506
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1507
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1508
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1362
1509
|
return {
|
|
1363
1510
|
priority: 1,
|
|
1364
1511
|
enabled: true,
|
|
1512
|
+
frameTimedRaycasts: true,
|
|
1513
|
+
alwaysFireOnScroll: true,
|
|
1514
|
+
updateOnFrame: false,
|
|
1365
1515
|
compute(event, state) {
|
|
1366
1516
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1367
1517
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1371,11 +1521,33 @@ function createPointerEvents(store) {
|
|
|
1371
1521
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1372
1522
|
{}
|
|
1373
1523
|
),
|
|
1374
|
-
update: () => {
|
|
1524
|
+
update: (pointerId) => {
|
|
1375
1525
|
const { events, internal } = store.getState();
|
|
1376
|
-
if (
|
|
1526
|
+
if (!events.handlers) return;
|
|
1527
|
+
if (pointerId !== void 0) {
|
|
1528
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1529
|
+
if (event) {
|
|
1530
|
+
internal.pointerDirty.delete(pointerId);
|
|
1531
|
+
processDeferredPointer(event, pointerId);
|
|
1532
|
+
} else if (internal.lastEvent?.current) {
|
|
1533
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1534
|
+
}
|
|
1535
|
+
} else {
|
|
1536
|
+
flushDeferredPointers();
|
|
1537
|
+
if (internal.lastEvent?.current) {
|
|
1538
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
},
|
|
1542
|
+
flush: () => {
|
|
1543
|
+
const { events, internal } = store.getState();
|
|
1544
|
+
flushDeferredPointers();
|
|
1545
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1546
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1547
|
+
}
|
|
1377
1548
|
},
|
|
1378
1549
|
connect: (target) => {
|
|
1550
|
+
if (!target) return;
|
|
1379
1551
|
const { set, events } = store.getState();
|
|
1380
1552
|
events.disconnect?.();
|
|
1381
1553
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1399,6 +1571,32 @@ function createPointerEvents(store) {
|
|
|
1399
1571
|
}
|
|
1400
1572
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1401
1573
|
}
|
|
1574
|
+
},
|
|
1575
|
+
registerPointer: (config) => {
|
|
1576
|
+
const pointerId = nextXRPointerId++;
|
|
1577
|
+
xrPointers.set(pointerId, config);
|
|
1578
|
+
const { internal } = store.getState();
|
|
1579
|
+
getPointerState(internal, pointerId);
|
|
1580
|
+
return pointerId;
|
|
1581
|
+
},
|
|
1582
|
+
unregisterPointer: (pointerId) => {
|
|
1583
|
+
xrPointers.delete(pointerId);
|
|
1584
|
+
const { internal } = store.getState();
|
|
1585
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1586
|
+
if (pointerState) {
|
|
1587
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1588
|
+
const eventObject = hoveredObj.eventObject;
|
|
1589
|
+
const instance = eventObject.__r3f;
|
|
1590
|
+
if (instance?.eventCount) {
|
|
1591
|
+
const handlers = instance.handlers;
|
|
1592
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1593
|
+
handlers.onPointerOut?.(data);
|
|
1594
|
+
handlers.onPointerLeave?.(data);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
internal.pointerMap.delete(pointerId);
|
|
1598
|
+
}
|
|
1599
|
+
internal.pointerDirty.delete(pointerId);
|
|
1402
1600
|
}
|
|
1403
1601
|
};
|
|
1404
1602
|
}
|
|
@@ -1460,1038 +1658,6 @@ function notifyAlpha({ message, link }) {
|
|
|
1460
1658
|
}
|
|
1461
1659
|
}
|
|
1462
1660
|
|
|
1463
|
-
var __defProp$1 = Object.defineProperty;
|
|
1464
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1465
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1466
|
-
const DEFAULT_PHASES = ["start", "input", "physics", "update", "render", "finish"];
|
|
1467
|
-
class PhaseGraph {
|
|
1468
|
-
constructor() {
|
|
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?.();
|
|
2493
|
-
}
|
|
2494
|
-
|
|
2495
1661
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
2496
1662
|
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
2497
1663
|
const createStore = (invalidate, advance) => {
|
|
@@ -2529,7 +1695,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2529
1695
|
frustum: new three.Frustum(),
|
|
2530
1696
|
autoUpdateFrustum: true,
|
|
2531
1697
|
raycaster: null,
|
|
2532
|
-
events: {
|
|
1698
|
+
events: {
|
|
1699
|
+
priority: 1,
|
|
1700
|
+
enabled: true,
|
|
1701
|
+
connected: false,
|
|
1702
|
+
frameTimedRaycasts: true,
|
|
1703
|
+
alwaysFireOnScroll: true,
|
|
1704
|
+
updateOnFrame: false
|
|
1705
|
+
},
|
|
2533
1706
|
scene: null,
|
|
2534
1707
|
rootScene: null,
|
|
2535
1708
|
xr: null,
|
|
@@ -2594,7 +1767,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2594
1767
|
size: newSize,
|
|
2595
1768
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2596
1769
|
}));
|
|
2597
|
-
getScheduler().invalidate();
|
|
1770
|
+
scheduler.getScheduler().invalidate();
|
|
2598
1771
|
}
|
|
2599
1772
|
}
|
|
2600
1773
|
return;
|
|
@@ -2609,7 +1782,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2609
1782
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2610
1783
|
_sizeImperative: true
|
|
2611
1784
|
}));
|
|
2612
|
-
getScheduler().invalidate();
|
|
1785
|
+
scheduler.getScheduler().invalidate();
|
|
2613
1786
|
},
|
|
2614
1787
|
setDpr: (dpr) => set((state2) => {
|
|
2615
1788
|
const resolved = calculateDpr(dpr);
|
|
@@ -2620,11 +1793,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2620
1793
|
},
|
|
2621
1794
|
setError: (error) => set(() => ({ error })),
|
|
2622
1795
|
error: null,
|
|
2623
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1796
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2624
1797
|
uniforms: {},
|
|
2625
1798
|
nodes: {},
|
|
1799
|
+
buffers: {},
|
|
1800
|
+
gpuStorage: {},
|
|
2626
1801
|
textures: /* @__PURE__ */ new Map(),
|
|
2627
|
-
|
|
1802
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1803
|
+
renderPipeline: null,
|
|
2628
1804
|
passes: {},
|
|
2629
1805
|
_hmrVersion: 0,
|
|
2630
1806
|
_sizeImperative: false,
|
|
@@ -2633,12 +1809,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2633
1809
|
internal: {
|
|
2634
1810
|
// Events
|
|
2635
1811
|
interaction: [],
|
|
2636
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2637
1812
|
subscribers: [],
|
|
1813
|
+
// Per-pointer state (new unified structure)
|
|
1814
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1815
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1816
|
+
lastEvent: React__namespace.createRef(),
|
|
1817
|
+
// Deprecated but kept for backwards compatibility
|
|
1818
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2638
1819
|
initialClick: [0, 0],
|
|
2639
1820
|
initialHits: [],
|
|
2640
1821
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2641
|
-
lastEvent: React__namespace.createRef(),
|
|
2642
1822
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2643
1823
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2644
1824
|
// Occlusion system (WebGPU only)
|
|
@@ -2726,14 +1906,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2726
1906
|
oldSize = size;
|
|
2727
1907
|
oldDpr = viewport.dpr;
|
|
2728
1908
|
updateCamera(camera, size);
|
|
2729
|
-
if (canvasTarget) {
|
|
1909
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2730
1910
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2731
|
-
|
|
2732
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1911
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2733
1912
|
} else {
|
|
2734
1913
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2735
|
-
|
|
2736
|
-
|
|
1914
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1915
|
+
if (canvasTarget) {
|
|
1916
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1917
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1918
|
+
}
|
|
2737
1919
|
}
|
|
2738
1920
|
}
|
|
2739
1921
|
if (camera !== oldCamera) {
|
|
@@ -2808,7 +1990,7 @@ useLoader.loader = getLoader;
|
|
|
2808
1990
|
function useFrame(callback, priorityOrOptions) {
|
|
2809
1991
|
const store = React__namespace.useContext(context);
|
|
2810
1992
|
const isInsideCanvas = store !== null;
|
|
2811
|
-
const scheduler = getScheduler();
|
|
1993
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
2812
1994
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2813
1995
|
id: priorityOrOptions.id,
|
|
2814
1996
|
phase: priorityOrOptions.phase,
|
|
@@ -2856,7 +2038,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2856
2038
|
};
|
|
2857
2039
|
callbackRef.current?.(mergedState, delta);
|
|
2858
2040
|
};
|
|
2859
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2041
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2860
2042
|
id,
|
|
2861
2043
|
rootId,
|
|
2862
2044
|
...options
|
|
@@ -2877,37 +2059,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2877
2059
|
}
|
|
2878
2060
|
};
|
|
2879
2061
|
} else {
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
unregisterJob = registerOutside();
|
|
2889
|
-
});
|
|
2890
|
-
return () => {
|
|
2891
|
-
unsubReady();
|
|
2892
|
-
unregisterJob?.();
|
|
2893
|
-
};
|
|
2062
|
+
return scheduler$1.register(
|
|
2063
|
+
(state, delta) => {
|
|
2064
|
+
const frameState = state;
|
|
2065
|
+
if (!frameState.renderer) return;
|
|
2066
|
+
callbackRef.current?.(frameState, delta);
|
|
2067
|
+
},
|
|
2068
|
+
{ id, ...options }
|
|
2069
|
+
);
|
|
2894
2070
|
}
|
|
2895
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2071
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2896
2072
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
2897
2073
|
// Subscribe function
|
|
2898
2074
|
React__namespace.useCallback(
|
|
2899
2075
|
(onStoreChange) => {
|
|
2900
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2076
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2901
2077
|
},
|
|
2902
2078
|
[id]
|
|
2903
2079
|
),
|
|
2904
2080
|
// getSnapshot function
|
|
2905
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2081
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2906
2082
|
// getServerSnapshot function (SSR)
|
|
2907
2083
|
React__namespace.useCallback(() => false, [])
|
|
2908
2084
|
);
|
|
2909
2085
|
const controls = React__namespace.useMemo(() => {
|
|
2910
|
-
const scheduler2 = getScheduler();
|
|
2086
|
+
const scheduler2 = scheduler.getScheduler();
|
|
2911
2087
|
return {
|
|
2912
2088
|
/** The job's unique ID */
|
|
2913
2089
|
id,
|
|
@@ -2922,7 +2098,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2922
2098
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2923
2099
|
*/
|
|
2924
2100
|
step: (timestamp) => {
|
|
2925
|
-
getScheduler().stepJob(id, timestamp);
|
|
2101
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
2926
2102
|
},
|
|
2927
2103
|
/**
|
|
2928
2104
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -2930,20 +2106,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2930
2106
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2931
2107
|
*/
|
|
2932
2108
|
stepAll: (timestamp) => {
|
|
2933
|
-
getScheduler().step(timestamp);
|
|
2109
|
+
scheduler.getScheduler().step(timestamp);
|
|
2934
2110
|
},
|
|
2935
2111
|
/**
|
|
2936
2112
|
* Pause this job (set enabled=false).
|
|
2937
2113
|
* Job remains registered but won't run.
|
|
2938
2114
|
*/
|
|
2939
2115
|
pause: () => {
|
|
2940
|
-
getScheduler().pauseJob(id);
|
|
2116
|
+
scheduler.getScheduler().pauseJob(id);
|
|
2941
2117
|
},
|
|
2942
2118
|
/**
|
|
2943
2119
|
* Resume this job (set enabled=true).
|
|
2944
2120
|
*/
|
|
2945
2121
|
resume: () => {
|
|
2946
|
-
getScheduler().resumeJob(id);
|
|
2122
|
+
scheduler.getScheduler().resumeJob(id);
|
|
2947
2123
|
},
|
|
2948
2124
|
/**
|
|
2949
2125
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -2981,18 +2157,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2981
2157
|
function useTexture(input, optionsOrOnLoad) {
|
|
2982
2158
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2983
2159
|
const store = useStore();
|
|
2984
|
-
const textureCache = useThree((state) => state.textures);
|
|
2985
2160
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2986
|
-
const { onLoad, cache =
|
|
2161
|
+
const { onLoad, cache = true } = options;
|
|
2987
2162
|
const onLoadRef = React.useRef(onLoad);
|
|
2988
2163
|
onLoadRef.current = onLoad;
|
|
2989
2164
|
const onLoadCalledForRef = React.useRef(null);
|
|
2990
2165
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2991
2166
|
const cachedResult = React.useMemo(() => {
|
|
2992
2167
|
if (!cache) return null;
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2168
|
+
const textures = store.getState().textures;
|
|
2169
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2170
|
+
return buildFromCache(input, textures);
|
|
2171
|
+
}, [cache, urls, input, store]);
|
|
2996
2172
|
const loadedTextures = useLoader(
|
|
2997
2173
|
three.TextureLoader,
|
|
2998
2174
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3036,8 +2212,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3036
2212
|
}, [input, loadedTextures, cachedResult]);
|
|
3037
2213
|
React.useEffect(() => {
|
|
3038
2214
|
if (!cache) return;
|
|
3039
|
-
if (cachedResult) return;
|
|
3040
|
-
const set = store.setState;
|
|
3041
2215
|
const urlTextureMap = [];
|
|
3042
2216
|
if (typeof input === "string") {
|
|
3043
2217
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3051,18 +2225,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3051
2225
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3052
2226
|
}
|
|
3053
2227
|
}
|
|
3054
|
-
|
|
3055
|
-
const
|
|
3056
|
-
let
|
|
2228
|
+
store.setState((state) => {
|
|
2229
|
+
const refs = new Map(state._textureRefs);
|
|
2230
|
+
let textures = state.textures;
|
|
2231
|
+
let added = false;
|
|
3057
2232
|
for (const [url, texture] of urlTextureMap) {
|
|
3058
|
-
if (!
|
|
3059
|
-
|
|
3060
|
-
|
|
2233
|
+
if (!textures.has(url)) {
|
|
2234
|
+
if (!added) {
|
|
2235
|
+
textures = new Map(textures);
|
|
2236
|
+
added = true;
|
|
2237
|
+
}
|
|
2238
|
+
textures.set(url, texture);
|
|
3061
2239
|
}
|
|
2240
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3062
2241
|
}
|
|
3063
|
-
return
|
|
2242
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2243
|
+
});
|
|
2244
|
+
return () => store.setState((state) => {
|
|
2245
|
+
const refs = new Map(state._textureRefs);
|
|
2246
|
+
for (const [url] of urlTextureMap) {
|
|
2247
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2248
|
+
if (next <= 0) refs.delete(url);
|
|
2249
|
+
else refs.set(url, next);
|
|
2250
|
+
}
|
|
2251
|
+
return { _textureRefs: refs };
|
|
3064
2252
|
});
|
|
3065
|
-
}, [cache, input, mappedTextures, store
|
|
2253
|
+
}, [cache, input, mappedTextures, store]);
|
|
3066
2254
|
return mappedTextures;
|
|
3067
2255
|
}
|
|
3068
2256
|
useTexture.preload = (url) => useLoader.preload(three.TextureLoader, url);
|
|
@@ -3078,96 +2266,63 @@ const Texture = ({
|
|
|
3078
2266
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
3079
2267
|
};
|
|
3080
2268
|
|
|
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() {
|
|
2269
|
+
function useTextures(selector) {
|
|
3089
2270
|
const store = useStore();
|
|
3090
|
-
|
|
3091
|
-
const set = store.setState;
|
|
2271
|
+
const registry = React.useMemo(() => {
|
|
3092
2272
|
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
|
-
};
|
|
2273
|
+
const setState = store.setState;
|
|
2274
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3151
2275
|
return {
|
|
3152
|
-
|
|
3153
|
-
get textures() {
|
|
2276
|
+
get all() {
|
|
3154
2277
|
return getState().textures;
|
|
3155
2278
|
},
|
|
3156
|
-
|
|
3157
|
-
|
|
2279
|
+
get(input) {
|
|
2280
|
+
if (typeof input === "string") return getOne(input);
|
|
2281
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2282
|
+
const out = {};
|
|
2283
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2284
|
+
return out;
|
|
2285
|
+
},
|
|
3158
2286
|
has: (key) => getState().textures.has(key),
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
2287
|
+
add(keyOrRecord, texture) {
|
|
2288
|
+
setState((state) => {
|
|
2289
|
+
const textures = new Map(state.textures);
|
|
2290
|
+
if (typeof keyOrRecord === "string") {
|
|
2291
|
+
textures.set(keyOrRecord, texture);
|
|
2292
|
+
} else {
|
|
2293
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2294
|
+
}
|
|
2295
|
+
return { textures };
|
|
2296
|
+
});
|
|
2297
|
+
},
|
|
2298
|
+
dispose(key, options) {
|
|
2299
|
+
const state = getState();
|
|
2300
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2301
|
+
if (refs > 0 && !options?.force) {
|
|
2302
|
+
console.warn(
|
|
2303
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2304
|
+
);
|
|
2305
|
+
return false;
|
|
2306
|
+
}
|
|
2307
|
+
state.textures.get(key)?.dispose();
|
|
2308
|
+
setState((s) => {
|
|
2309
|
+
const textures = new Map(s.textures);
|
|
2310
|
+
textures.delete(key);
|
|
2311
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2312
|
+
nextRefs.delete(key);
|
|
2313
|
+
return { textures, _textureRefs: nextRefs };
|
|
2314
|
+
});
|
|
2315
|
+
return true;
|
|
2316
|
+
},
|
|
2317
|
+
disposeAll() {
|
|
2318
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2319
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2320
|
+
}
|
|
3169
2321
|
};
|
|
3170
2322
|
}, [store]);
|
|
2323
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2324
|
+
const selected = useThree(subscribe);
|
|
2325
|
+
return selector ? selected : registry;
|
|
3171
2326
|
}
|
|
3172
2327
|
|
|
3173
2328
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3222,7 +2377,7 @@ function addEffect(callback) {
|
|
|
3222
2377
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3223
2378
|
});
|
|
3224
2379
|
const id = `legacy_effect_${effectId++}`;
|
|
3225
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2380
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3226
2381
|
}
|
|
3227
2382
|
function addAfterEffect(callback) {
|
|
3228
2383
|
notifyDepreciated({
|
|
@@ -3231,7 +2386,7 @@ function addAfterEffect(callback) {
|
|
|
3231
2386
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3232
2387
|
});
|
|
3233
2388
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3234
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2389
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3235
2390
|
}
|
|
3236
2391
|
function addTail(callback) {
|
|
3237
2392
|
notifyDepreciated({
|
|
@@ -3239,13 +2394,13 @@ function addTail(callback) {
|
|
|
3239
2394
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3240
2395
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3241
2396
|
});
|
|
3242
|
-
return getScheduler().onIdle(callback);
|
|
2397
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3243
2398
|
}
|
|
3244
2399
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3245
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2400
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3246
2401
|
}
|
|
3247
2402
|
function advance(timestamp) {
|
|
3248
|
-
getScheduler().step(timestamp);
|
|
2403
|
+
scheduler.getScheduler().step(timestamp);
|
|
3249
2404
|
}
|
|
3250
2405
|
|
|
3251
2406
|
const version = "10.0.0-alpha.2";
|
|
@@ -15018,7 +14173,6 @@ function createRoot(canvas) {
|
|
|
15018
14173
|
events,
|
|
15019
14174
|
onCreated: onCreatedCallback,
|
|
15020
14175
|
shadows = false,
|
|
15021
|
-
textureColorSpace = three.SRGBColorSpace,
|
|
15022
14176
|
orthographic = false,
|
|
15023
14177
|
frameloop = "always",
|
|
15024
14178
|
dpr = [1, 2],
|
|
@@ -15033,6 +14187,7 @@ function createRoot(canvas) {
|
|
|
15033
14187
|
_sizeProps,
|
|
15034
14188
|
forceEven
|
|
15035
14189
|
} = props;
|
|
14190
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
|
|
15036
14191
|
const state = store.getState();
|
|
15037
14192
|
const defaultGLProps = {
|
|
15038
14193
|
canvas,
|
|
@@ -15156,7 +14311,7 @@ function createRoot(canvas) {
|
|
|
15156
14311
|
lastConfiguredProps.performance = performance;
|
|
15157
14312
|
}
|
|
15158
14313
|
if (!state.xr) {
|
|
15159
|
-
const handleXRFrame = (timestamp,
|
|
14314
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15160
14315
|
const state2 = store.getState();
|
|
15161
14316
|
if (state2.frameloop === "never") return;
|
|
15162
14317
|
advance(timestamp);
|
|
@@ -15192,15 +14347,22 @@ function createRoot(canvas) {
|
|
|
15192
14347
|
const oldType = renderer.shadowMap.type;
|
|
15193
14348
|
renderer.shadowMap.enabled = !!shadows;
|
|
15194
14349
|
if (is.boo(shadows)) {
|
|
15195
|
-
renderer.shadowMap.type = three.
|
|
14350
|
+
renderer.shadowMap.type = three.PCFShadowMap;
|
|
15196
14351
|
} else if (is.str(shadows)) {
|
|
14352
|
+
if (shadows === "soft") {
|
|
14353
|
+
notifyDepreciated({
|
|
14354
|
+
heading: 'shadows="soft" is deprecated',
|
|
14355
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14356
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14357
|
+
});
|
|
14358
|
+
}
|
|
15197
14359
|
const types = {
|
|
15198
14360
|
basic: three.BasicShadowMap,
|
|
15199
14361
|
percentage: three.PCFShadowMap,
|
|
15200
|
-
soft: three.
|
|
14362
|
+
soft: three.PCFShadowMap,
|
|
15201
14363
|
variance: three.VSMShadowMap
|
|
15202
14364
|
};
|
|
15203
|
-
renderer.shadowMap.type = types[shadows] ?? three.
|
|
14365
|
+
renderer.shadowMap.type = types[shadows] ?? three.PCFShadowMap;
|
|
15204
14366
|
} else if (is.obj(shadows)) {
|
|
15205
14367
|
Object.assign(renderer.shadowMap, shadows);
|
|
15206
14368
|
}
|
|
@@ -15216,24 +14378,35 @@ function createRoot(canvas) {
|
|
|
15216
14378
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15217
14379
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15218
14380
|
}
|
|
14381
|
+
const r3fProps = ["textureColorSpace"];
|
|
14382
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14383
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15219
14384
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15220
|
-
|
|
14385
|
+
const glProps = {};
|
|
14386
|
+
for (const key in glConfig) {
|
|
14387
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14388
|
+
}
|
|
14389
|
+
applyProps(renderer, glProps);
|
|
15221
14390
|
}
|
|
15222
14391
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15223
14392
|
const currentRenderer = state.renderer;
|
|
15224
14393
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15225
|
-
|
|
14394
|
+
const rendererProps = {};
|
|
14395
|
+
for (const key in rendererConfig) {
|
|
14396
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14397
|
+
}
|
|
14398
|
+
applyProps(currentRenderer, rendererProps);
|
|
15226
14399
|
}
|
|
15227
14400
|
}
|
|
15228
|
-
const scheduler = getScheduler();
|
|
14401
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15229
14402
|
const rootId = state.internal.rootId;
|
|
15230
14403
|
if (!rootId) {
|
|
15231
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15232
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14404
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14405
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15233
14406
|
getState: () => store.getState(),
|
|
15234
14407
|
onError: (err) => store.getState().setError(err)
|
|
15235
14408
|
});
|
|
15236
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14409
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15237
14410
|
() => {
|
|
15238
14411
|
const state2 = store.getState();
|
|
15239
14412
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15248,7 +14421,19 @@ function createRoot(canvas) {
|
|
|
15248
14421
|
system: true
|
|
15249
14422
|
}
|
|
15250
14423
|
);
|
|
15251
|
-
const
|
|
14424
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
14425
|
+
() => {
|
|
14426
|
+
const state2 = store.getState();
|
|
14427
|
+
state2.events.flush?.();
|
|
14428
|
+
},
|
|
14429
|
+
{
|
|
14430
|
+
id: `${newRootId}_events`,
|
|
14431
|
+
rootId: newRootId,
|
|
14432
|
+
phase: "input",
|
|
14433
|
+
system: true
|
|
14434
|
+
}
|
|
14435
|
+
);
|
|
14436
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15252
14437
|
() => {
|
|
15253
14438
|
const state2 = store.getState();
|
|
15254
14439
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15258,11 +14443,11 @@ function createRoot(canvas) {
|
|
|
15258
14443
|
{
|
|
15259
14444
|
id: `${newRootId}_frustum`,
|
|
15260
14445
|
rootId: newRootId,
|
|
15261
|
-
|
|
14446
|
+
before: "render",
|
|
15262
14447
|
system: true
|
|
15263
14448
|
}
|
|
15264
14449
|
);
|
|
15265
|
-
const unregisterVisibility = scheduler.register(
|
|
14450
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15266
14451
|
() => {
|
|
15267
14452
|
const state2 = store.getState();
|
|
15268
14453
|
checkVisibility(state2);
|
|
@@ -15270,19 +14455,19 @@ function createRoot(canvas) {
|
|
|
15270
14455
|
{
|
|
15271
14456
|
id: `${newRootId}_visibility`,
|
|
15272
14457
|
rootId: newRootId,
|
|
15273
|
-
|
|
14458
|
+
before: "render",
|
|
15274
14459
|
system: true,
|
|
15275
14460
|
after: `${newRootId}_frustum`
|
|
15276
14461
|
}
|
|
15277
14462
|
);
|
|
15278
|
-
const unregisterRender = scheduler.register(
|
|
14463
|
+
const unregisterRender = scheduler$1.register(
|
|
15279
14464
|
() => {
|
|
15280
14465
|
const state2 = store.getState();
|
|
15281
14466
|
const renderer2 = state2.internal.actualRenderer;
|
|
15282
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14467
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15283
14468
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15284
14469
|
try {
|
|
15285
|
-
if (state2.
|
|
14470
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15286
14471
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15287
14472
|
} catch (error) {
|
|
15288
14473
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15307,15 +14492,16 @@ function createRoot(canvas) {
|
|
|
15307
14492
|
unregisterRoot: () => {
|
|
15308
14493
|
unregisterRoot();
|
|
15309
14494
|
unregisterCanvasTarget();
|
|
14495
|
+
unregisterEventsFlush();
|
|
15310
14496
|
unregisterFrustum();
|
|
15311
14497
|
unregisterVisibility();
|
|
15312
14498
|
unregisterRender();
|
|
15313
14499
|
},
|
|
15314
|
-
scheduler
|
|
14500
|
+
scheduler: scheduler$1
|
|
15315
14501
|
}
|
|
15316
14502
|
}));
|
|
15317
14503
|
}
|
|
15318
|
-
scheduler.frameloop = frameloop;
|
|
14504
|
+
scheduler$1.frameloop = frameloop;
|
|
15319
14505
|
onCreated = onCreatedCallback;
|
|
15320
14506
|
configured = true;
|
|
15321
14507
|
resolve();
|
|
@@ -15472,9 +14658,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15472
14658
|
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15473
14659
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15474
14660
|
onMutate(previousRoot.getState());
|
|
15475
|
-
previousRoot.subscribe(onMutate);
|
|
15476
14661
|
return store;
|
|
15477
14662
|
}, [previousRoot, container]);
|
|
14663
|
+
useIsomorphicLayoutEffect(() => {
|
|
14664
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14665
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14666
|
+
return unsubscribe;
|
|
14667
|
+
}, [previousRoot, usePortalStore]);
|
|
15478
14668
|
return (
|
|
15479
14669
|
// @ts-ignore, reconciler types are not maintained
|
|
15480
14670
|
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
@@ -15488,6 +14678,46 @@ function flushSync(fn) {
|
|
|
15488
14678
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15489
14679
|
}
|
|
15490
14680
|
|
|
14681
|
+
function parseBackground(background) {
|
|
14682
|
+
if (!background) return null;
|
|
14683
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14684
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14685
|
+
return {
|
|
14686
|
+
...rest,
|
|
14687
|
+
preset,
|
|
14688
|
+
files: envMap || files,
|
|
14689
|
+
backgroundFiles: backgroundMap,
|
|
14690
|
+
background: true
|
|
14691
|
+
};
|
|
14692
|
+
}
|
|
14693
|
+
if (typeof background === "number") {
|
|
14694
|
+
return { color: background, background: true };
|
|
14695
|
+
}
|
|
14696
|
+
if (typeof background === "string") {
|
|
14697
|
+
if (background in presetsObj) {
|
|
14698
|
+
return { preset: background, background: true };
|
|
14699
|
+
}
|
|
14700
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14701
|
+
return { files: background, background: true };
|
|
14702
|
+
}
|
|
14703
|
+
return { color: background, background: true };
|
|
14704
|
+
}
|
|
14705
|
+
if (background.isColor) {
|
|
14706
|
+
return { color: background, background: true };
|
|
14707
|
+
}
|
|
14708
|
+
return null;
|
|
14709
|
+
}
|
|
14710
|
+
|
|
14711
|
+
function clearHmrCaches(store) {
|
|
14712
|
+
store.setState((state) => ({
|
|
14713
|
+
nodes: {},
|
|
14714
|
+
uniforms: {},
|
|
14715
|
+
buffers: {},
|
|
14716
|
+
gpuStorage: {},
|
|
14717
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14718
|
+
}));
|
|
14719
|
+
}
|
|
14720
|
+
|
|
15491
14721
|
function CanvasImpl({
|
|
15492
14722
|
ref,
|
|
15493
14723
|
children,
|
|
@@ -15508,6 +14738,8 @@ function CanvasImpl({
|
|
|
15508
14738
|
raycaster,
|
|
15509
14739
|
camera,
|
|
15510
14740
|
scene,
|
|
14741
|
+
autoUpdateFrustum,
|
|
14742
|
+
occlusion,
|
|
15511
14743
|
onPointerMissed,
|
|
15512
14744
|
onDragOverMissed,
|
|
15513
14745
|
onDropMissed,
|
|
@@ -15519,39 +14751,21 @@ function CanvasImpl({
|
|
|
15519
14751
|
forceEven,
|
|
15520
14752
|
...props
|
|
15521
14753
|
}) {
|
|
15522
|
-
const
|
|
15523
|
-
|
|
14754
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14755
|
+
let primaryCanvas;
|
|
14756
|
+
let scheduler;
|
|
14757
|
+
let renderer;
|
|
14758
|
+
if (isRendererConfig) {
|
|
14759
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14760
|
+
primaryCanvas = pc;
|
|
14761
|
+
scheduler = sc;
|
|
14762
|
+
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
14763
|
+
} else {
|
|
14764
|
+
renderer = rendererProp;
|
|
14765
|
+
}
|
|
15524
14766
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15525
14767
|
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]);
|
|
14768
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15555
14769
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15556
14770
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15557
14771
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15635,6 +14849,8 @@ function CanvasImpl({
|
|
|
15635
14849
|
performance,
|
|
15636
14850
|
raycaster,
|
|
15637
14851
|
camera,
|
|
14852
|
+
autoUpdateFrustum,
|
|
14853
|
+
occlusion,
|
|
15638
14854
|
size: effectiveSize,
|
|
15639
14855
|
// Store size props for reset functionality
|
|
15640
14856
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15694,20 +14910,13 @@ function CanvasImpl({
|
|
|
15694
14910
|
const handleHMR = () => {
|
|
15695
14911
|
queueMicrotask(() => {
|
|
15696
14912
|
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
|
-
}
|
|
14913
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15704
14914
|
});
|
|
15705
14915
|
};
|
|
15706
14916
|
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
14917
|
const hot = undefined;
|
|
15708
14918
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15709
|
-
return () => hot.
|
|
15710
|
-
});
|
|
14919
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15711
14920
|
}
|
|
15712
14921
|
if (typeof module !== "undefined" && module.hot) {
|
|
15713
14922
|
const hot = module.hot;
|
|
@@ -15730,7 +14939,16 @@ function CanvasImpl({
|
|
|
15730
14939
|
...style
|
|
15731
14940
|
},
|
|
15732
14941
|
...props,
|
|
15733
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14942
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14943
|
+
"canvas",
|
|
14944
|
+
{
|
|
14945
|
+
ref: canvasRef,
|
|
14946
|
+
id,
|
|
14947
|
+
className: "r3f-canvas",
|
|
14948
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
14949
|
+
children: fallback
|
|
14950
|
+
}
|
|
14951
|
+
) })
|
|
15734
14952
|
}
|
|
15735
14953
|
);
|
|
15736
14954
|
}
|
|
@@ -15740,6 +14958,8 @@ function Canvas(props) {
|
|
|
15740
14958
|
|
|
15741
14959
|
extend(THREE);
|
|
15742
14960
|
|
|
14961
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
14962
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
15743
14963
|
exports.Block = Block;
|
|
15744
14964
|
exports.Canvas = Canvas;
|
|
15745
14965
|
exports.Environment = Environment;
|
|
@@ -15755,7 +14975,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
15755
14975
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
15756
14976
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
15757
14977
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
15758
|
-
exports.Scheduler = Scheduler;
|
|
15759
14978
|
exports.Texture = Texture;
|
|
15760
14979
|
exports._roots = _roots;
|
|
15761
14980
|
exports.act = act;
|
|
@@ -15785,7 +15004,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
15785
15004
|
exports.getPrimary = getPrimary;
|
|
15786
15005
|
exports.getPrimaryIds = getPrimaryIds;
|
|
15787
15006
|
exports.getRootState = getRootState;
|
|
15788
|
-
exports.getScheduler = getScheduler;
|
|
15789
15007
|
exports.getUuidPrefix = getUuidPrefix;
|
|
15790
15008
|
exports.hasConstructor = hasConstructor;
|
|
15791
15009
|
exports.hasPrimary = hasPrimary;
|