@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/webgpu/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js'
|
|
|
14
14
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
15
15
|
const Tb = require('scheduler');
|
|
16
16
|
const traditional = require('zustand/traditional');
|
|
17
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
17
18
|
const suspendReact = require('suspend-react');
|
|
18
19
|
const lite = require('dequal/lite');
|
|
19
20
|
require('zustand/shallow');
|
|
@@ -170,7 +171,7 @@ function useEnvironment({
|
|
|
170
171
|
fiber.useLoader.clear(loader, multiFile ? [files] : files);
|
|
171
172
|
}
|
|
172
173
|
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
173
|
-
}, [files, renderer.domElement]);
|
|
174
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
174
175
|
const loaderResult = fiber.useLoader(
|
|
175
176
|
loader,
|
|
176
177
|
multiFile ? [files] : files,
|
|
@@ -370,7 +371,22 @@ function EnvironmentPortal({
|
|
|
370
371
|
environmentIntensity,
|
|
371
372
|
environmentRotation
|
|
372
373
|
});
|
|
373
|
-
}, [
|
|
374
|
+
}, [
|
|
375
|
+
children,
|
|
376
|
+
virtualScene,
|
|
377
|
+
fbo.texture,
|
|
378
|
+
scene,
|
|
379
|
+
defaultScene,
|
|
380
|
+
background,
|
|
381
|
+
frames,
|
|
382
|
+
gl,
|
|
383
|
+
blur,
|
|
384
|
+
backgroundBlurriness,
|
|
385
|
+
backgroundIntensity,
|
|
386
|
+
backgroundRotation,
|
|
387
|
+
environmentIntensity,
|
|
388
|
+
environmentRotation
|
|
389
|
+
]);
|
|
374
390
|
let count = 1;
|
|
375
391
|
fiber.useFrame(() => {
|
|
376
392
|
if (frames === Infinity || count < frames) {
|
|
@@ -441,9 +457,9 @@ function Environment(props) {
|
|
|
441
457
|
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 });
|
|
442
458
|
}
|
|
443
459
|
|
|
444
|
-
var __defProp$
|
|
445
|
-
var __defNormalProp$
|
|
446
|
-
var __publicField$
|
|
460
|
+
var __defProp$1 = Object.defineProperty;
|
|
461
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
462
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
447
463
|
const act = React__namespace["act"];
|
|
448
464
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
449
465
|
function useMutableCallback(fn) {
|
|
@@ -475,7 +491,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
475
491
|
return _a = class extends React__namespace.Component {
|
|
476
492
|
constructor() {
|
|
477
493
|
super(...arguments);
|
|
478
|
-
__publicField$
|
|
494
|
+
__publicField$1(this, "state", { error: false });
|
|
479
495
|
}
|
|
480
496
|
componentDidCatch(err) {
|
|
481
497
|
this.props.set(err);
|
|
@@ -483,7 +499,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
483
499
|
render() {
|
|
484
500
|
return this.state.error ? null : this.props.children;
|
|
485
501
|
}
|
|
486
|
-
}, __publicField$
|
|
502
|
+
}, __publicField$1(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
487
503
|
})();
|
|
488
504
|
|
|
489
505
|
const is = {
|
|
@@ -1006,6 +1022,9 @@ function applyProps(object, props) {
|
|
|
1006
1022
|
else target.set(value);
|
|
1007
1023
|
} else {
|
|
1008
1024
|
root[key] = value;
|
|
1025
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1026
|
+
root.needsUpdate = true;
|
|
1027
|
+
}
|
|
1009
1028
|
if (rootState && rootState.renderer?.outputColorSpace === webgpu.SRGBColorSpace && colorMaps.includes(key) && isTexture(value) && root[key]?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
1010
1029
|
root[key].format === webgpu.RGBAFormat && root[key].type === webgpu.UnsignedByteType) {
|
|
1011
1030
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
@@ -1039,38 +1058,60 @@ function applyProps(object, props) {
|
|
|
1039
1058
|
return object;
|
|
1040
1059
|
}
|
|
1041
1060
|
|
|
1061
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1062
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1063
|
+
function getPointerState(internal, pointerId) {
|
|
1064
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1065
|
+
if (!state) {
|
|
1066
|
+
state = {
|
|
1067
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1068
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1069
|
+
initialClick: [0, 0],
|
|
1070
|
+
initialHits: []
|
|
1071
|
+
};
|
|
1072
|
+
internal.pointerMap.set(pointerId, state);
|
|
1073
|
+
}
|
|
1074
|
+
return state;
|
|
1075
|
+
}
|
|
1076
|
+
function getPointerId(event) {
|
|
1077
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1078
|
+
}
|
|
1042
1079
|
function makeId(event) {
|
|
1043
1080
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1044
1081
|
}
|
|
1045
|
-
function releaseInternalPointerCapture(
|
|
1046
|
-
const
|
|
1082
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1083
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1084
|
+
if (!pointerState) return;
|
|
1085
|
+
const captureData = pointerState.captured.get(obj);
|
|
1047
1086
|
if (captureData) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
capturedMap.delete(pointerId);
|
|
1051
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
1052
|
-
}
|
|
1087
|
+
pointerState.captured.delete(obj);
|
|
1088
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1053
1089
|
}
|
|
1054
1090
|
}
|
|
1055
1091
|
function removeInteractivity(store, object) {
|
|
1056
1092
|
const { internal } = store.getState();
|
|
1057
1093
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1094
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1095
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1096
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1097
|
+
if (value.eventObject === object || value.object === object) {
|
|
1098
|
+
pointerState.hovered.delete(key);
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
if (pointerState.captured.has(object)) {
|
|
1102
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1062
1103
|
}
|
|
1063
|
-
}
|
|
1064
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1065
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1066
|
-
});
|
|
1104
|
+
}
|
|
1067
1105
|
unregisterVisibility(store, object);
|
|
1068
1106
|
}
|
|
1069
1107
|
function createEvents(store) {
|
|
1070
|
-
function calculateDistance(event) {
|
|
1108
|
+
function calculateDistance(event, pointerId) {
|
|
1071
1109
|
const { internal } = store.getState();
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1110
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1111
|
+
if (!pointerState) return 0;
|
|
1112
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1113
|
+
const dx = event.offsetX - initialX;
|
|
1114
|
+
const dy = event.offsetY - initialY;
|
|
1074
1115
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
1075
1116
|
}
|
|
1076
1117
|
function filterPointerEvents(objects) {
|
|
@@ -1106,6 +1147,15 @@ function createEvents(store) {
|
|
|
1106
1147
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1107
1148
|
}
|
|
1108
1149
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1150
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1151
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1152
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1153
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1154
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1155
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1156
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1109
1159
|
const aState = getRootState(a.object);
|
|
1110
1160
|
const bState = getRootState(b.object);
|
|
1111
1161
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -1127,9 +1177,13 @@ function createEvents(store) {
|
|
|
1127
1177
|
eventObject = eventObject.parent;
|
|
1128
1178
|
}
|
|
1129
1179
|
}
|
|
1130
|
-
if ("pointerId" in event
|
|
1131
|
-
|
|
1132
|
-
|
|
1180
|
+
if ("pointerId" in event) {
|
|
1181
|
+
const pointerId = event.pointerId;
|
|
1182
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1183
|
+
if (pointerState?.captured.size) {
|
|
1184
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1185
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1186
|
+
}
|
|
1133
1187
|
}
|
|
1134
1188
|
}
|
|
1135
1189
|
return intersections;
|
|
@@ -1142,27 +1196,25 @@ function createEvents(store) {
|
|
|
1142
1196
|
if (state) {
|
|
1143
1197
|
const { raycaster, pointer, camera, internal } = state;
|
|
1144
1198
|
const unprojectedPoint = new webgpu.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1145
|
-
const hasPointerCapture = (id) =>
|
|
1199
|
+
const hasPointerCapture = (id) => {
|
|
1200
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1201
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1202
|
+
};
|
|
1146
1203
|
const setPointerCapture = (id) => {
|
|
1147
1204
|
const captureData = { intersection: hit, target: event.target };
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
} else {
|
|
1151
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
1152
|
-
}
|
|
1205
|
+
const pointerState = getPointerState(internal, id);
|
|
1206
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
1153
1207
|
event.target.setPointerCapture(id);
|
|
1154
1208
|
};
|
|
1155
1209
|
const releasePointerCapture = (id) => {
|
|
1156
|
-
|
|
1157
|
-
if (captures) {
|
|
1158
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1159
|
-
}
|
|
1210
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1160
1211
|
};
|
|
1161
1212
|
const extractEventProps = {};
|
|
1162
1213
|
for (const prop in event) {
|
|
1163
1214
|
const property = event[prop];
|
|
1164
1215
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1165
1216
|
}
|
|
1217
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1166
1218
|
const raycastEvent = {
|
|
1167
1219
|
...hit,
|
|
1168
1220
|
...extractEventProps,
|
|
@@ -1173,18 +1225,19 @@ function createEvents(store) {
|
|
|
1173
1225
|
unprojectedPoint,
|
|
1174
1226
|
ray: raycaster.ray,
|
|
1175
1227
|
camera,
|
|
1228
|
+
pointerId: eventPointerId,
|
|
1176
1229
|
// Hijack stopPropagation, which just sets a flag
|
|
1177
1230
|
stopPropagation() {
|
|
1178
|
-
const
|
|
1231
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1179
1232
|
if (
|
|
1180
1233
|
// ...if this pointer hasn't been captured
|
|
1181
|
-
!
|
|
1182
|
-
|
|
1234
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1235
|
+
pointerState.captured.has(hit.eventObject)
|
|
1183
1236
|
) {
|
|
1184
1237
|
raycastEvent.stopped = localState.stopped = true;
|
|
1185
|
-
if (
|
|
1238
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1186
1239
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1187
|
-
cancelPointer([...higher, hit]);
|
|
1240
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
1188
1241
|
}
|
|
1189
1242
|
}
|
|
1190
1243
|
},
|
|
@@ -1200,15 +1253,18 @@ function createEvents(store) {
|
|
|
1200
1253
|
}
|
|
1201
1254
|
return intersections;
|
|
1202
1255
|
}
|
|
1203
|
-
function cancelPointer(intersections) {
|
|
1256
|
+
function cancelPointer(intersections, pointerId) {
|
|
1204
1257
|
const { internal } = store.getState();
|
|
1205
|
-
|
|
1258
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1259
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1260
|
+
if (!pointerState) return;
|
|
1261
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
1206
1262
|
if (!intersections.length || !intersections.find(
|
|
1207
1263
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
1208
1264
|
)) {
|
|
1209
1265
|
const eventObject = hoveredObj.eventObject;
|
|
1210
1266
|
const instance = eventObject.__r3f;
|
|
1211
|
-
|
|
1267
|
+
pointerState.hovered.delete(hoveredId);
|
|
1212
1268
|
if (instance?.eventCount) {
|
|
1213
1269
|
const handlers = instance.handlers;
|
|
1214
1270
|
const data = { ...hoveredObj, intersections };
|
|
@@ -1237,41 +1293,118 @@ function createEvents(store) {
|
|
|
1237
1293
|
instance?.handlers.onDropMissed?.(event);
|
|
1238
1294
|
}
|
|
1239
1295
|
}
|
|
1296
|
+
function cleanupPointer(pointerId) {
|
|
1297
|
+
const { internal } = store.getState();
|
|
1298
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1299
|
+
if (pointerState) {
|
|
1300
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1301
|
+
const eventObject = hoveredObj.eventObject;
|
|
1302
|
+
const instance = eventObject.__r3f;
|
|
1303
|
+
if (instance?.eventCount) {
|
|
1304
|
+
const handlers = instance.handlers;
|
|
1305
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1306
|
+
handlers.onPointerOut?.(data);
|
|
1307
|
+
handlers.onPointerLeave?.(data);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
internal.pointerMap.delete(pointerId);
|
|
1311
|
+
}
|
|
1312
|
+
internal.pointerDirty.delete(pointerId);
|
|
1313
|
+
}
|
|
1314
|
+
function processDeferredPointer(event, pointerId) {
|
|
1315
|
+
const state = store.getState();
|
|
1316
|
+
const { internal } = state;
|
|
1317
|
+
if (!state.events.enabled) return;
|
|
1318
|
+
const filter = filterPointerEvents;
|
|
1319
|
+
const hits = intersect(event, filter);
|
|
1320
|
+
cancelPointer(hits, pointerId);
|
|
1321
|
+
function onIntersect(data) {
|
|
1322
|
+
const eventObject = data.eventObject;
|
|
1323
|
+
const instance = eventObject.__r3f;
|
|
1324
|
+
if (!instance?.eventCount) return;
|
|
1325
|
+
const handlers = instance.handlers;
|
|
1326
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1327
|
+
const id = makeId(data);
|
|
1328
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1329
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1330
|
+
if (!hoveredItem) {
|
|
1331
|
+
pointerState.hovered.set(id, data);
|
|
1332
|
+
handlers.onPointerOver?.(data);
|
|
1333
|
+
handlers.onPointerEnter?.(data);
|
|
1334
|
+
} else if (hoveredItem.stopped) {
|
|
1335
|
+
data.stopPropagation();
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
handlers.onPointerMove?.(data);
|
|
1339
|
+
}
|
|
1340
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1341
|
+
}
|
|
1240
1342
|
function handlePointer(name) {
|
|
1241
1343
|
switch (name) {
|
|
1242
1344
|
case "onPointerLeave":
|
|
1243
|
-
case "onPointerCancel":
|
|
1244
1345
|
case "onDragLeave":
|
|
1245
1346
|
return () => cancelPointer([]);
|
|
1347
|
+
// Global cancel of these events
|
|
1348
|
+
case "onPointerCancel":
|
|
1349
|
+
return (event) => {
|
|
1350
|
+
const pointerId = getPointerId(event);
|
|
1351
|
+
cleanupPointer(pointerId);
|
|
1352
|
+
};
|
|
1246
1353
|
case "onLostPointerCapture":
|
|
1247
1354
|
return (event) => {
|
|
1248
1355
|
const { internal } = store.getState();
|
|
1249
|
-
|
|
1356
|
+
const pointerId = getPointerId(event);
|
|
1357
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1358
|
+
if (pointerState?.captured.size) {
|
|
1250
1359
|
requestAnimationFrame(() => {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1360
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1361
|
+
if (pointerState2?.captured.size) {
|
|
1362
|
+
pointerState2.captured.clear();
|
|
1254
1363
|
}
|
|
1364
|
+
cancelPointer([], pointerId);
|
|
1255
1365
|
});
|
|
1256
1366
|
}
|
|
1257
1367
|
};
|
|
1258
1368
|
}
|
|
1259
1369
|
return function handleEvent(event) {
|
|
1260
1370
|
const state = store.getState();
|
|
1261
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1371
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1372
|
+
const pointerId = getPointerId(event);
|
|
1262
1373
|
internal.lastEvent.current = event;
|
|
1263
|
-
if (!
|
|
1374
|
+
if (!events.enabled) return;
|
|
1264
1375
|
const isPointerMove = name === "onPointerMove";
|
|
1265
1376
|
const isDragOver = name === "onDragOver";
|
|
1266
1377
|
const isDrop = name === "onDrop";
|
|
1267
1378
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1379
|
+
const isPointerDown = name === "onPointerDown";
|
|
1380
|
+
const isPointerUp = name === "onPointerUp";
|
|
1381
|
+
const isWheel = name === "onWheel";
|
|
1382
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1383
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1384
|
+
events.compute?.(event, state);
|
|
1385
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1389
|
+
events.compute?.(event, state);
|
|
1390
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1394
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1395
|
+
internal.pointerDirty.delete(pointerId);
|
|
1396
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1397
|
+
}
|
|
1268
1398
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1269
1399
|
const hits = intersect(event, filter);
|
|
1270
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1271
|
-
if (
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1400
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1401
|
+
if (isPointerDown) {
|
|
1402
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1403
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1404
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1405
|
+
}
|
|
1406
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1407
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
1275
1408
|
if (isClickEvent && !hits.length) {
|
|
1276
1409
|
if (delta <= 2) {
|
|
1277
1410
|
pointerMissed(event, internal.interaction);
|
|
@@ -1286,7 +1419,9 @@ function createEvents(store) {
|
|
|
1286
1419
|
dropMissed(event, internal.interaction);
|
|
1287
1420
|
if (onDropMissed) onDropMissed(event);
|
|
1288
1421
|
}
|
|
1289
|
-
if (isPointerMove || isDragOver)
|
|
1422
|
+
if (isPointerMove || isDragOver) {
|
|
1423
|
+
cancelPointer(hits, pointerId);
|
|
1424
|
+
}
|
|
1290
1425
|
function onIntersect(data) {
|
|
1291
1426
|
const eventObject = data.eventObject;
|
|
1292
1427
|
const instance = eventObject.__r3f;
|
|
@@ -1295,9 +1430,10 @@ function createEvents(store) {
|
|
|
1295
1430
|
if (isPointerMove) {
|
|
1296
1431
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1297
1432
|
const id = makeId(data);
|
|
1298
|
-
const
|
|
1433
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1434
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1299
1435
|
if (!hoveredItem) {
|
|
1300
|
-
|
|
1436
|
+
pointerState2.hovered.set(id, data);
|
|
1301
1437
|
handlers.onPointerOver?.(data);
|
|
1302
1438
|
handlers.onPointerEnter?.(data);
|
|
1303
1439
|
} else if (hoveredItem.stopped) {
|
|
@@ -1307,9 +1443,10 @@ function createEvents(store) {
|
|
|
1307
1443
|
handlers.onPointerMove?.(data);
|
|
1308
1444
|
} else if (isDragOver) {
|
|
1309
1445
|
const id = makeId(data);
|
|
1310
|
-
const
|
|
1446
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1447
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
1311
1448
|
if (!hoveredItem) {
|
|
1312
|
-
|
|
1449
|
+
pointerState2.hovered.set(id, data);
|
|
1313
1450
|
handlers.onDragOverEnter?.(data);
|
|
1314
1451
|
} else if (hoveredItem.stopped) {
|
|
1315
1452
|
data.stopPropagation();
|
|
@@ -1320,18 +1457,18 @@ function createEvents(store) {
|
|
|
1320
1457
|
} else {
|
|
1321
1458
|
const handler = handlers[name];
|
|
1322
1459
|
if (handler) {
|
|
1323
|
-
if (!isClickEvent ||
|
|
1460
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1324
1461
|
pointerMissed(
|
|
1325
1462
|
event,
|
|
1326
|
-
internal.interaction.filter((object) => !
|
|
1463
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1327
1464
|
);
|
|
1328
1465
|
handler(data);
|
|
1329
1466
|
}
|
|
1330
1467
|
} else {
|
|
1331
|
-
if (isClickEvent &&
|
|
1468
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1332
1469
|
pointerMissed(
|
|
1333
1470
|
event,
|
|
1334
|
-
internal.interaction.filter((object) => !
|
|
1471
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1335
1472
|
);
|
|
1336
1473
|
}
|
|
1337
1474
|
}
|
|
@@ -1340,7 +1477,15 @@ function createEvents(store) {
|
|
|
1340
1477
|
handleIntersects(hits, event, delta, onIntersect);
|
|
1341
1478
|
};
|
|
1342
1479
|
}
|
|
1343
|
-
|
|
1480
|
+
function flushDeferredPointers() {
|
|
1481
|
+
const { internal, events } = store.getState();
|
|
1482
|
+
if (!events.frameTimedRaycasts) return;
|
|
1483
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1484
|
+
processDeferredPointer(event, pointerId);
|
|
1485
|
+
}
|
|
1486
|
+
internal.pointerDirty.clear();
|
|
1487
|
+
}
|
|
1488
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1344
1489
|
}
|
|
1345
1490
|
const DOM_EVENTS = {
|
|
1346
1491
|
onClick: ["click", false],
|
|
@@ -1359,10 +1504,15 @@ const DOM_EVENTS = {
|
|
|
1359
1504
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
1360
1505
|
};
|
|
1361
1506
|
function createPointerEvents(store) {
|
|
1362
|
-
const { handlePointer } = createEvents(store);
|
|
1507
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1508
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1509
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
1363
1510
|
return {
|
|
1364
1511
|
priority: 1,
|
|
1365
1512
|
enabled: true,
|
|
1513
|
+
frameTimedRaycasts: true,
|
|
1514
|
+
alwaysFireOnScroll: true,
|
|
1515
|
+
updateOnFrame: false,
|
|
1366
1516
|
compute(event, state) {
|
|
1367
1517
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1368
1518
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
@@ -1372,11 +1522,33 @@ function createPointerEvents(store) {
|
|
|
1372
1522
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1373
1523
|
{}
|
|
1374
1524
|
),
|
|
1375
|
-
update: () => {
|
|
1525
|
+
update: (pointerId) => {
|
|
1376
1526
|
const { events, internal } = store.getState();
|
|
1377
|
-
if (
|
|
1527
|
+
if (!events.handlers) return;
|
|
1528
|
+
if (pointerId !== void 0) {
|
|
1529
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1530
|
+
if (event) {
|
|
1531
|
+
internal.pointerDirty.delete(pointerId);
|
|
1532
|
+
processDeferredPointer(event, pointerId);
|
|
1533
|
+
} else if (internal.lastEvent?.current) {
|
|
1534
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1535
|
+
}
|
|
1536
|
+
} else {
|
|
1537
|
+
flushDeferredPointers();
|
|
1538
|
+
if (internal.lastEvent?.current) {
|
|
1539
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
},
|
|
1543
|
+
flush: () => {
|
|
1544
|
+
const { events, internal } = store.getState();
|
|
1545
|
+
flushDeferredPointers();
|
|
1546
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1547
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1548
|
+
}
|
|
1378
1549
|
},
|
|
1379
1550
|
connect: (target) => {
|
|
1551
|
+
if (!target) return;
|
|
1380
1552
|
const { set, events } = store.getState();
|
|
1381
1553
|
events.disconnect?.();
|
|
1382
1554
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -1400,6 +1572,32 @@ function createPointerEvents(store) {
|
|
|
1400
1572
|
}
|
|
1401
1573
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1402
1574
|
}
|
|
1575
|
+
},
|
|
1576
|
+
registerPointer: (config) => {
|
|
1577
|
+
const pointerId = nextXRPointerId++;
|
|
1578
|
+
xrPointers.set(pointerId, config);
|
|
1579
|
+
const { internal } = store.getState();
|
|
1580
|
+
getPointerState(internal, pointerId);
|
|
1581
|
+
return pointerId;
|
|
1582
|
+
},
|
|
1583
|
+
unregisterPointer: (pointerId) => {
|
|
1584
|
+
xrPointers.delete(pointerId);
|
|
1585
|
+
const { internal } = store.getState();
|
|
1586
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1587
|
+
if (pointerState) {
|
|
1588
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1589
|
+
const eventObject = hoveredObj.eventObject;
|
|
1590
|
+
const instance = eventObject.__r3f;
|
|
1591
|
+
if (instance?.eventCount) {
|
|
1592
|
+
const handlers = instance.handlers;
|
|
1593
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1594
|
+
handlers.onPointerOut?.(data);
|
|
1595
|
+
handlers.onPointerLeave?.(data);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
internal.pointerMap.delete(pointerId);
|
|
1599
|
+
}
|
|
1600
|
+
internal.pointerDirty.delete(pointerId);
|
|
1403
1601
|
}
|
|
1404
1602
|
};
|
|
1405
1603
|
}
|
|
@@ -1461,1038 +1659,6 @@ function notifyAlpha({ message, link }) {
|
|
|
1461
1659
|
}
|
|
1462
1660
|
}
|
|
1463
1661
|
|
|
1464
|
-
var __defProp$2 = Object.defineProperty;
|
|
1465
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1466
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1467
|
-
const DEFAULT_PHASES = ["start", "input", "physics", "update", "render", "finish"];
|
|
1468
|
-
class PhaseGraph {
|
|
1469
|
-
constructor() {
|
|
1470
|
-
/** Ordered list of phase nodes */
|
|
1471
|
-
__publicField$2(this, "phases", []);
|
|
1472
|
-
/** Quick lookup by name */
|
|
1473
|
-
__publicField$2(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1474
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1475
|
-
__publicField$2(this, "orderedNamesCache", null);
|
|
1476
|
-
this.initializeDefaultPhases();
|
|
1477
|
-
}
|
|
1478
|
-
//* Initialization --------------------------------
|
|
1479
|
-
initializeDefaultPhases() {
|
|
1480
|
-
for (const name of DEFAULT_PHASES) {
|
|
1481
|
-
const node = { name, isAutoGenerated: false };
|
|
1482
|
-
this.phases.push(node);
|
|
1483
|
-
this.phaseMap.set(name, node);
|
|
1484
|
-
}
|
|
1485
|
-
this.invalidateCache();
|
|
1486
|
-
}
|
|
1487
|
-
//* Public API --------------------------------
|
|
1488
|
-
/**
|
|
1489
|
-
* Add a named phase to the graph
|
|
1490
|
-
* @param name - Phase name (must be unique)
|
|
1491
|
-
* @param options - Position options (before or after another phase)
|
|
1492
|
-
*/
|
|
1493
|
-
addPhase(name, options = {}) {
|
|
1494
|
-
if (this.phaseMap.has(name)) {
|
|
1495
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1496
|
-
return;
|
|
1497
|
-
}
|
|
1498
|
-
const { before, after } = options;
|
|
1499
|
-
const node = { name, isAutoGenerated: false };
|
|
1500
|
-
let insertIndex = this.phases.length;
|
|
1501
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1502
|
-
if (targetIndex !== -1) {
|
|
1503
|
-
insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1504
|
-
} else {
|
|
1505
|
-
const constraintType = before ? "before" : "after";
|
|
1506
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1507
|
-
}
|
|
1508
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1509
|
-
this.phaseMap.set(name, node);
|
|
1510
|
-
this.invalidateCache();
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Get ordered list of phase names
|
|
1514
|
-
*/
|
|
1515
|
-
getOrderedPhases() {
|
|
1516
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1517
|
-
return this.orderedNamesCache;
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Check if a phase exists
|
|
1521
|
-
*/
|
|
1522
|
-
hasPhase(name) {
|
|
1523
|
-
return this.phaseMap.has(name);
|
|
1524
|
-
}
|
|
1525
|
-
/**
|
|
1526
|
-
* Get the index of a phase (-1 if not found)
|
|
1527
|
-
*/
|
|
1528
|
-
getPhaseIndex(name) {
|
|
1529
|
-
if (!name) return -1;
|
|
1530
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1534
|
-
* Used for resolving before/after constraints.
|
|
1535
|
-
*
|
|
1536
|
-
* @param name - The phase name to ensure exists
|
|
1537
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1538
|
-
*/
|
|
1539
|
-
ensurePhase(name) {
|
|
1540
|
-
if (this.phaseMap.has(name)) return name;
|
|
1541
|
-
const node = { name, isAutoGenerated: true };
|
|
1542
|
-
this.phases.push(node);
|
|
1543
|
-
this.phaseMap.set(name, node);
|
|
1544
|
-
this.invalidateCache();
|
|
1545
|
-
return name;
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Resolve where a job with before/after constraints should go.
|
|
1549
|
-
* Creates auto-generated phases if needed.
|
|
1550
|
-
*
|
|
1551
|
-
* @param before - Phase(s) to run before
|
|
1552
|
-
* @param after - Phase(s) to run after
|
|
1553
|
-
* @returns The resolved phase name
|
|
1554
|
-
*/
|
|
1555
|
-
resolveConstraintPhase(before, after) {
|
|
1556
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1557
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1558
|
-
if (beforeArr.length > 0) {
|
|
1559
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1560
|
-
}
|
|
1561
|
-
if (afterArr.length > 0) {
|
|
1562
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1563
|
-
}
|
|
1564
|
-
return "update";
|
|
1565
|
-
}
|
|
1566
|
-
/**
|
|
1567
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1568
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1569
|
-
*
|
|
1570
|
-
* @param target - The target phase name to position relative to
|
|
1571
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1572
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1573
|
-
* @returns The auto-generated phase name
|
|
1574
|
-
*/
|
|
1575
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1576
|
-
const autoName = `${prefix}:${target}`;
|
|
1577
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1578
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1579
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1580
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1581
|
-
else this.phases.push(node);
|
|
1582
|
-
this.phaseMap.set(autoName, node);
|
|
1583
|
-
this.invalidateCache();
|
|
1584
|
-
return autoName;
|
|
1585
|
-
}
|
|
1586
|
-
// Internal --------------------------------
|
|
1587
|
-
invalidateCache() {
|
|
1588
|
-
this.orderedNamesCache = null;
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1593
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1594
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1595
|
-
for (const phase of orderedPhases) {
|
|
1596
|
-
buckets.set(phase, []);
|
|
1597
|
-
}
|
|
1598
|
-
for (const job of jobs.values()) {
|
|
1599
|
-
if (!job.enabled) continue;
|
|
1600
|
-
let bucket = buckets.get(job.phase);
|
|
1601
|
-
if (!bucket) {
|
|
1602
|
-
bucket = [];
|
|
1603
|
-
buckets.set(job.phase, bucket);
|
|
1604
|
-
}
|
|
1605
|
-
bucket.push(job);
|
|
1606
|
-
}
|
|
1607
|
-
const sortedBuckets = [];
|
|
1608
|
-
for (const phase of orderedPhases) {
|
|
1609
|
-
const bucket = buckets.get(phase);
|
|
1610
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1611
|
-
bucket.sort((a, b) => {
|
|
1612
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1613
|
-
return a.index - b.index;
|
|
1614
|
-
});
|
|
1615
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1616
|
-
}
|
|
1617
|
-
for (const [phase, bucket] of buckets) {
|
|
1618
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1619
|
-
bucket.sort((a, b) => {
|
|
1620
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1621
|
-
return a.index - b.index;
|
|
1622
|
-
});
|
|
1623
|
-
sortedBuckets.push(bucket);
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
return sortedBuckets.flat();
|
|
1627
|
-
}
|
|
1628
|
-
function hasCrossJobConstraints(bucket) {
|
|
1629
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1630
|
-
for (const job of bucket) {
|
|
1631
|
-
for (const ref of job.before) {
|
|
1632
|
-
if (jobIds.has(ref)) return true;
|
|
1633
|
-
}
|
|
1634
|
-
for (const ref of job.after) {
|
|
1635
|
-
if (jobIds.has(ref)) return true;
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
return false;
|
|
1639
|
-
}
|
|
1640
|
-
function topologicalSort(jobs) {
|
|
1641
|
-
const n = jobs.length;
|
|
1642
|
-
if (n <= 1) return jobs;
|
|
1643
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1644
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1645
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1646
|
-
for (const job of jobs) {
|
|
1647
|
-
jobMap.set(job.id, job);
|
|
1648
|
-
inDegree.set(job.id, 0);
|
|
1649
|
-
adjacency.set(job.id, []);
|
|
1650
|
-
}
|
|
1651
|
-
for (const job of jobs) {
|
|
1652
|
-
for (const ref of job.before) {
|
|
1653
|
-
if (jobMap.has(ref)) {
|
|
1654
|
-
adjacency.get(job.id).push(ref);
|
|
1655
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
for (const ref of job.after) {
|
|
1659
|
-
if (jobMap.has(ref)) {
|
|
1660
|
-
adjacency.get(ref).push(job.id);
|
|
1661
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
const queue = [];
|
|
1666
|
-
for (const job of jobs) {
|
|
1667
|
-
if (inDegree.get(job.id) === 0) {
|
|
1668
|
-
queue.push(job);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
queue.sort((a, b) => {
|
|
1672
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1673
|
-
return a.index - b.index;
|
|
1674
|
-
});
|
|
1675
|
-
const result = [];
|
|
1676
|
-
while (queue.length > 0) {
|
|
1677
|
-
const job = queue.shift();
|
|
1678
|
-
result.push(job);
|
|
1679
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1680
|
-
for (const neighborId of neighbors) {
|
|
1681
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1682
|
-
inDegree.set(neighborId, newDegree);
|
|
1683
|
-
if (newDegree === 0) {
|
|
1684
|
-
const neighbor = jobMap.get(neighborId);
|
|
1685
|
-
insertSorted(queue, neighbor);
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
if (result.length !== n) {
|
|
1690
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1691
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1692
|
-
for (const job of jobs) {
|
|
1693
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
return result;
|
|
1697
|
-
}
|
|
1698
|
-
function insertSorted(arr, job) {
|
|
1699
|
-
let i = 0;
|
|
1700
|
-
while (i < arr.length) {
|
|
1701
|
-
const cmp = arr[i];
|
|
1702
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1703
|
-
break;
|
|
1704
|
-
}
|
|
1705
|
-
i++;
|
|
1706
|
-
}
|
|
1707
|
-
arr.splice(i, 0, job);
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
function shouldRun(job, now) {
|
|
1711
|
-
if (!job.enabled) return false;
|
|
1712
|
-
if (!job.fps) return true;
|
|
1713
|
-
const minInterval = 1e3 / job.fps;
|
|
1714
|
-
const lastRun = job.lastRun ?? 0;
|
|
1715
|
-
const elapsed = now - lastRun;
|
|
1716
|
-
if (elapsed < minInterval) return false;
|
|
1717
|
-
if (job.drop) {
|
|
1718
|
-
job.lastRun = now;
|
|
1719
|
-
} else {
|
|
1720
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1721
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1722
|
-
if (job.lastRun < now - minInterval) {
|
|
1723
|
-
job.lastRun = now;
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
return true;
|
|
1727
|
-
}
|
|
1728
|
-
function resetJobTiming(job) {
|
|
1729
|
-
job.lastRun = void 0;
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
var __defProp$1 = Object.defineProperty;
|
|
1733
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1734
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1735
|
-
const hmrData = (() => {
|
|
1736
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1737
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1738
|
-
try {
|
|
1739
|
-
return (0, eval)("import.meta.hot");
|
|
1740
|
-
} catch {
|
|
1741
|
-
return void 0;
|
|
1742
|
-
}
|
|
1743
|
-
})();
|
|
1744
|
-
const _Scheduler = class _Scheduler {
|
|
1745
|
-
//* Constructor ================================
|
|
1746
|
-
constructor() {
|
|
1747
|
-
//* Critical State ================================
|
|
1748
|
-
__publicField$1(this, "roots", /* @__PURE__ */ new Map());
|
|
1749
|
-
__publicField$1(this, "phaseGraph");
|
|
1750
|
-
__publicField$1(this, "loopState", {
|
|
1751
|
-
running: false,
|
|
1752
|
-
rafHandle: null,
|
|
1753
|
-
lastTime: null,
|
|
1754
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1755
|
-
frameCount: 0,
|
|
1756
|
-
elapsedTime: 0,
|
|
1757
|
-
createdAt: performance.now()
|
|
1758
|
-
});
|
|
1759
|
-
__publicField$1(this, "stoppedTime", 0);
|
|
1760
|
-
//* Private State ================================
|
|
1761
|
-
__publicField$1(this, "nextRootIndex", 0);
|
|
1762
|
-
__publicField$1(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1763
|
-
__publicField$1(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1764
|
-
__publicField$1(this, "nextGlobalIndex", 0);
|
|
1765
|
-
__publicField$1(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1766
|
-
__publicField$1(this, "nextJobIndex", 0);
|
|
1767
|
-
__publicField$1(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1768
|
-
__publicField$1(this, "pendingFrames", 0);
|
|
1769
|
-
__publicField$1(this, "_frameloop", "always");
|
|
1770
|
-
//* Independent Mode & Error Handling State ================================
|
|
1771
|
-
__publicField$1(this, "_independent", false);
|
|
1772
|
-
__publicField$1(this, "errorHandler", null);
|
|
1773
|
-
__publicField$1(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1774
|
-
//* Core Loop Execution Methods ================================
|
|
1775
|
-
/**
|
|
1776
|
-
* Main RAF loop callback.
|
|
1777
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1778
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1779
|
-
* @returns {void}
|
|
1780
|
-
* @private
|
|
1781
|
-
*/
|
|
1782
|
-
__publicField$1(this, "loop", (timestamp) => {
|
|
1783
|
-
if (!this.loopState.running) return;
|
|
1784
|
-
this.executeFrame(timestamp);
|
|
1785
|
-
if (this._frameloop === "demand") {
|
|
1786
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1787
|
-
if (this.pendingFrames === 0) {
|
|
1788
|
-
this.notifyIdle(timestamp);
|
|
1789
|
-
return this.stop();
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1793
|
-
});
|
|
1794
|
-
this.phaseGraph = new PhaseGraph();
|
|
1795
|
-
}
|
|
1796
|
-
static get instance() {
|
|
1797
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1798
|
-
}
|
|
1799
|
-
static set instance(value) {
|
|
1800
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1801
|
-
}
|
|
1802
|
-
/**
|
|
1803
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1804
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1805
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1806
|
-
*/
|
|
1807
|
-
static get() {
|
|
1808
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1809
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1810
|
-
}
|
|
1811
|
-
if (!_Scheduler.instance) {
|
|
1812
|
-
_Scheduler.instance = new _Scheduler();
|
|
1813
|
-
if (hmrData?.data) {
|
|
1814
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
return _Scheduler.instance;
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1821
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1822
|
-
* @returns {void}
|
|
1823
|
-
*/
|
|
1824
|
-
static reset() {
|
|
1825
|
-
if (_Scheduler.instance) {
|
|
1826
|
-
_Scheduler.instance.stop();
|
|
1827
|
-
_Scheduler.instance = null;
|
|
1828
|
-
}
|
|
1829
|
-
if (hmrData?.data) {
|
|
1830
|
-
hmrData.data.scheduler = null;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
//* Getters & Setters ================================
|
|
1834
|
-
get phases() {
|
|
1835
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1836
|
-
}
|
|
1837
|
-
get frameloop() {
|
|
1838
|
-
return this._frameloop;
|
|
1839
|
-
}
|
|
1840
|
-
set frameloop(mode) {
|
|
1841
|
-
if (this._frameloop === mode) return;
|
|
1842
|
-
const wasAlways = this._frameloop === "always";
|
|
1843
|
-
this._frameloop = mode;
|
|
1844
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1845
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1846
|
-
}
|
|
1847
|
-
get isRunning() {
|
|
1848
|
-
return this.loopState.running;
|
|
1849
|
-
}
|
|
1850
|
-
get isReady() {
|
|
1851
|
-
return this.roots.size > 0;
|
|
1852
|
-
}
|
|
1853
|
-
get independent() {
|
|
1854
|
-
return this._independent;
|
|
1855
|
-
}
|
|
1856
|
-
set independent(value) {
|
|
1857
|
-
this._independent = value;
|
|
1858
|
-
if (value) this.ensureDefaultRoot();
|
|
1859
|
-
}
|
|
1860
|
-
//* Root Management Methods ================================
|
|
1861
|
-
/**
|
|
1862
|
-
* Register a root (Canvas) with the scheduler.
|
|
1863
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1864
|
-
* @param {string} id - Unique identifier for this root
|
|
1865
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1866
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1867
|
-
*/
|
|
1868
|
-
registerRoot(id, options = {}) {
|
|
1869
|
-
if (this.roots.has(id)) {
|
|
1870
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1871
|
-
return () => this.unregisterRoot(id);
|
|
1872
|
-
}
|
|
1873
|
-
const entry = {
|
|
1874
|
-
id,
|
|
1875
|
-
getState: options.getState ?? (() => ({})),
|
|
1876
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1877
|
-
sortedJobs: [],
|
|
1878
|
-
needsRebuild: false
|
|
1879
|
-
};
|
|
1880
|
-
if (options.onError) {
|
|
1881
|
-
this.errorHandler = options.onError;
|
|
1882
|
-
}
|
|
1883
|
-
this.roots.set(id, entry);
|
|
1884
|
-
if (this.roots.size === 1) {
|
|
1885
|
-
this.notifyRootReady();
|
|
1886
|
-
if (this._frameloop === "always") this.start();
|
|
1887
|
-
}
|
|
1888
|
-
return () => this.unregisterRoot(id);
|
|
1889
|
-
}
|
|
1890
|
-
/**
|
|
1891
|
-
* Unregister a root from the scheduler.
|
|
1892
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1893
|
-
* The last root to unregister stops the RAF loop.
|
|
1894
|
-
* @param {string} id - The root ID to unregister
|
|
1895
|
-
* @returns {void}
|
|
1896
|
-
*/
|
|
1897
|
-
unregisterRoot(id) {
|
|
1898
|
-
const root = this.roots.get(id);
|
|
1899
|
-
if (!root) return;
|
|
1900
|
-
for (const jobId of root.jobs.keys()) {
|
|
1901
|
-
this.jobStateListeners.delete(jobId);
|
|
1902
|
-
}
|
|
1903
|
-
this.roots.delete(id);
|
|
1904
|
-
if (this.roots.size === 0) {
|
|
1905
|
-
this.stop();
|
|
1906
|
-
this.errorHandler = null;
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Subscribe to be notified when a root becomes available.
|
|
1911
|
-
* Fires immediately if a root already exists.
|
|
1912
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1913
|
-
* @returns {() => void} Unsubscribe function
|
|
1914
|
-
*/
|
|
1915
|
-
onRootReady(callback) {
|
|
1916
|
-
if (this.roots.size > 0) {
|
|
1917
|
-
callback();
|
|
1918
|
-
return () => {
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
this.rootReadyCallbacks.add(callback);
|
|
1922
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1923
|
-
}
|
|
1924
|
-
/**
|
|
1925
|
-
* Notify all registered root-ready callbacks.
|
|
1926
|
-
* Called when the first root registers.
|
|
1927
|
-
* @returns {void}
|
|
1928
|
-
* @private
|
|
1929
|
-
*/
|
|
1930
|
-
notifyRootReady() {
|
|
1931
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1932
|
-
try {
|
|
1933
|
-
cb();
|
|
1934
|
-
} catch (error) {
|
|
1935
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
this.rootReadyCallbacks.clear();
|
|
1939
|
-
}
|
|
1940
|
-
/**
|
|
1941
|
-
* Ensure a default root exists for independent mode.
|
|
1942
|
-
* Creates a minimal root with no state provider.
|
|
1943
|
-
* @returns {void}
|
|
1944
|
-
* @private
|
|
1945
|
-
*/
|
|
1946
|
-
ensureDefaultRoot() {
|
|
1947
|
-
if (!this.roots.has("__default__")) {
|
|
1948
|
-
this.registerRoot("__default__");
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
/**
|
|
1952
|
-
* Trigger error handling for job errors.
|
|
1953
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1954
|
-
* @param {Error} error - The error to handle
|
|
1955
|
-
* @returns {void}
|
|
1956
|
-
*/
|
|
1957
|
-
triggerError(error) {
|
|
1958
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1959
|
-
else console.error("[Scheduler]", error);
|
|
1960
|
-
}
|
|
1961
|
-
//* Phase Management Methods ================================
|
|
1962
|
-
/**
|
|
1963
|
-
* Add a named phase to the scheduler's execution order.
|
|
1964
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1965
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1966
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1967
|
-
* @returns {void}
|
|
1968
|
-
* @example
|
|
1969
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1970
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1971
|
-
*/
|
|
1972
|
-
addPhase(name, options) {
|
|
1973
|
-
this.phaseGraph.addPhase(name, options);
|
|
1974
|
-
for (const root of this.roots.values()) {
|
|
1975
|
-
root.needsRebuild = true;
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
/**
|
|
1979
|
-
* Check if a phase exists in the scheduler.
|
|
1980
|
-
* @param {string} name - The phase name to check
|
|
1981
|
-
* @returns {boolean} True if the phase exists
|
|
1982
|
-
*/
|
|
1983
|
-
hasPhase(name) {
|
|
1984
|
-
return this.phaseGraph.hasPhase(name);
|
|
1985
|
-
}
|
|
1986
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1987
|
-
/**
|
|
1988
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1989
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1990
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1991
|
-
* @param {string} id - Unique identifier for this global job
|
|
1992
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1993
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1994
|
-
* @deprecated Use useFrame with phases instead
|
|
1995
|
-
*/
|
|
1996
|
-
registerGlobal(phase, id, callback) {
|
|
1997
|
-
const job = { id, callback };
|
|
1998
|
-
if (phase === "before") {
|
|
1999
|
-
this.globalBeforeJobs.set(id, job);
|
|
2000
|
-
} else {
|
|
2001
|
-
this.globalAfterJobs.set(id, job);
|
|
2002
|
-
}
|
|
2003
|
-
return () => {
|
|
2004
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
2005
|
-
else this.globalAfterJobs.delete(id);
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
2009
|
-
/**
|
|
2010
|
-
* Register an idle callback that fires when the loop stops.
|
|
2011
|
-
* Used internally by deprecated addTail API.
|
|
2012
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
2013
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
2014
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
2015
|
-
*/
|
|
2016
|
-
onIdle(callback) {
|
|
2017
|
-
this.idleCallbacks.add(callback);
|
|
2018
|
-
return () => this.idleCallbacks.delete(callback);
|
|
2019
|
-
}
|
|
2020
|
-
/**
|
|
2021
|
-
* Notify all registered idle callbacks.
|
|
2022
|
-
* Called when the loop stops in demand mode.
|
|
2023
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
2024
|
-
* @returns {void}
|
|
2025
|
-
* @private
|
|
2026
|
-
*/
|
|
2027
|
-
notifyIdle(timestamp) {
|
|
2028
|
-
for (const cb of this.idleCallbacks) {
|
|
2029
|
-
try {
|
|
2030
|
-
cb(timestamp);
|
|
2031
|
-
} catch (error) {
|
|
2032
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
//* Job Registration & Management Methods ================================
|
|
2037
|
-
/**
|
|
2038
|
-
* Register a job (frame callback) with a specific root.
|
|
2039
|
-
* This is the core registration method used by useFrame internally.
|
|
2040
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
2041
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
2042
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
2043
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
2044
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
2045
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
2046
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
2047
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
2048
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
2049
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
2050
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
2051
|
-
*/
|
|
2052
|
-
register(callback, options = {}) {
|
|
2053
|
-
const rootId = options.rootId;
|
|
2054
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
2055
|
-
if (!root) {
|
|
2056
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
2057
|
-
return () => {
|
|
2058
|
-
};
|
|
2059
|
-
}
|
|
2060
|
-
const id = options.id ?? this.generateJobId();
|
|
2061
|
-
let phase = options.phase ?? "update";
|
|
2062
|
-
if (!options.phase && (options.before || options.after)) {
|
|
2063
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
2064
|
-
}
|
|
2065
|
-
const before = this.normalizeConstraints(options.before);
|
|
2066
|
-
const after = this.normalizeConstraints(options.after);
|
|
2067
|
-
const job = {
|
|
2068
|
-
id,
|
|
2069
|
-
callback,
|
|
2070
|
-
phase,
|
|
2071
|
-
before,
|
|
2072
|
-
after,
|
|
2073
|
-
priority: options.priority ?? 0,
|
|
2074
|
-
index: this.nextJobIndex++,
|
|
2075
|
-
fps: options.fps,
|
|
2076
|
-
drop: options.drop ?? true,
|
|
2077
|
-
enabled: options.enabled ?? true,
|
|
2078
|
-
system: options.system ?? false
|
|
2079
|
-
};
|
|
2080
|
-
if (root.jobs.has(id)) {
|
|
2081
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
2082
|
-
}
|
|
2083
|
-
root.jobs.set(id, job);
|
|
2084
|
-
root.needsRebuild = true;
|
|
2085
|
-
return () => this.unregister(id, root.id);
|
|
2086
|
-
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Unregister a job by its ID.
|
|
2089
|
-
* Searches all roots if rootId is not provided.
|
|
2090
|
-
* @param {string} id - The job ID to unregister
|
|
2091
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
2092
|
-
* @returns {void}
|
|
2093
|
-
*/
|
|
2094
|
-
unregister(id, rootId) {
|
|
2095
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
2096
|
-
if (root?.jobs.delete(id)) {
|
|
2097
|
-
root.needsRebuild = true;
|
|
2098
|
-
this.jobStateListeners.delete(id);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
/**
|
|
2102
|
-
* Update a job's options dynamically.
|
|
2103
|
-
* Searches all roots to find the job by ID.
|
|
2104
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
2105
|
-
* @param {string} id - The job ID to update
|
|
2106
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
2107
|
-
* @returns {void}
|
|
2108
|
-
*/
|
|
2109
|
-
updateJob(id, options) {
|
|
2110
|
-
let job;
|
|
2111
|
-
let root;
|
|
2112
|
-
for (const r of this.roots.values()) {
|
|
2113
|
-
job = r.jobs.get(id);
|
|
2114
|
-
if (job) {
|
|
2115
|
-
root = r;
|
|
2116
|
-
break;
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
if (!job || !root) return;
|
|
2120
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
2121
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
2122
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
2123
|
-
if (options.enabled !== void 0) {
|
|
2124
|
-
const wasEnabled = job.enabled;
|
|
2125
|
-
job.enabled = options.enabled;
|
|
2126
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
2127
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
2128
|
-
}
|
|
2129
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
2130
|
-
if (options.phase) job.phase = options.phase;
|
|
2131
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
2132
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
2133
|
-
root.needsRebuild = true;
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
//* Job State Management Methods ================================
|
|
2137
|
-
/**
|
|
2138
|
-
* Check if a job is currently paused (disabled).
|
|
2139
|
-
* @param {string} id - The job ID to check
|
|
2140
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2141
|
-
*/
|
|
2142
|
-
isJobPaused(id) {
|
|
2143
|
-
for (const root of this.roots.values()) {
|
|
2144
|
-
const job = root.jobs.get(id);
|
|
2145
|
-
if (job) return !job.enabled;
|
|
2146
|
-
}
|
|
2147
|
-
return false;
|
|
2148
|
-
}
|
|
2149
|
-
/**
|
|
2150
|
-
* Subscribe to state changes for a specific job.
|
|
2151
|
-
* Listener is called when job is paused or resumed.
|
|
2152
|
-
* @param {string} id - The job ID to subscribe to
|
|
2153
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2154
|
-
* @returns {() => void} Unsubscribe function
|
|
2155
|
-
*/
|
|
2156
|
-
subscribeJobState(id, listener) {
|
|
2157
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2158
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2159
|
-
}
|
|
2160
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2161
|
-
return () => {
|
|
2162
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2163
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2164
|
-
this.jobStateListeners.delete(id);
|
|
2165
|
-
}
|
|
2166
|
-
};
|
|
2167
|
-
}
|
|
2168
|
-
/**
|
|
2169
|
-
* Notify all listeners that a job's state has changed.
|
|
2170
|
-
* @param {string} id - The job ID that changed
|
|
2171
|
-
* @returns {void}
|
|
2172
|
-
* @private
|
|
2173
|
-
*/
|
|
2174
|
-
notifyJobStateChange(id) {
|
|
2175
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2176
|
-
}
|
|
2177
|
-
/**
|
|
2178
|
-
* Pause a job by ID (sets enabled=false).
|
|
2179
|
-
* Notifies any subscribed state listeners.
|
|
2180
|
-
* @param {string} id - The job ID to pause
|
|
2181
|
-
* @returns {void}
|
|
2182
|
-
*/
|
|
2183
|
-
pauseJob(id) {
|
|
2184
|
-
this.updateJob(id, { enabled: false });
|
|
2185
|
-
this.notifyJobStateChange(id);
|
|
2186
|
-
}
|
|
2187
|
-
/**
|
|
2188
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2189
|
-
* Resets job timing to prevent frame accumulation.
|
|
2190
|
-
* Notifies any subscribed state listeners.
|
|
2191
|
-
* @param {string} id - The job ID to resume
|
|
2192
|
-
* @returns {void}
|
|
2193
|
-
*/
|
|
2194
|
-
resumeJob(id) {
|
|
2195
|
-
this.updateJob(id, { enabled: true });
|
|
2196
|
-
this.notifyJobStateChange(id);
|
|
2197
|
-
}
|
|
2198
|
-
//* Frame Loop Control Methods ================================
|
|
2199
|
-
/**
|
|
2200
|
-
* Start the requestAnimationFrame loop.
|
|
2201
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2202
|
-
* No-op if already running.
|
|
2203
|
-
* @returns {void}
|
|
2204
|
-
*/
|
|
2205
|
-
start() {
|
|
2206
|
-
if (this.loopState.running) return;
|
|
2207
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2208
|
-
let adjustedCreated = 0;
|
|
2209
|
-
if (this.stoppedTime > 0) {
|
|
2210
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2211
|
-
this.stoppedTime = 0;
|
|
2212
|
-
}
|
|
2213
|
-
Object.assign(this.loopState, {
|
|
2214
|
-
running: true,
|
|
2215
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2216
|
-
lastTime: performance.now(),
|
|
2217
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2218
|
-
frameCount: 0,
|
|
2219
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Stop the requestAnimationFrame loop.
|
|
2224
|
-
* Cancels any pending RAF callback.
|
|
2225
|
-
* No-op if not running.
|
|
2226
|
-
* @returns {void}
|
|
2227
|
-
*/
|
|
2228
|
-
stop() {
|
|
2229
|
-
if (!this.loopState.running) return;
|
|
2230
|
-
this.loopState.running = false;
|
|
2231
|
-
if (this.loopState.rafHandle !== null) {
|
|
2232
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2233
|
-
this.loopState.rafHandle = null;
|
|
2234
|
-
}
|
|
2235
|
-
this.stoppedTime = performance.now();
|
|
2236
|
-
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Request frames to be rendered in demand mode.
|
|
2239
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2240
|
-
* No-op if frameloop is not 'demand'.
|
|
2241
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2242
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2243
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2244
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2245
|
-
* @returns {void}
|
|
2246
|
-
* @example
|
|
2247
|
-
* // Request a single frame render
|
|
2248
|
-
* scheduler.invalidate();
|
|
2249
|
-
*
|
|
2250
|
-
* @example
|
|
2251
|
-
* // Request 5 frames (e.g., for animations)
|
|
2252
|
-
* scheduler.invalidate(5);
|
|
2253
|
-
*
|
|
2254
|
-
* @example
|
|
2255
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2256
|
-
* scheduler.invalidate(3, false);
|
|
2257
|
-
*
|
|
2258
|
-
* @example
|
|
2259
|
-
* // Add 2 more frames to existing pending count
|
|
2260
|
-
* scheduler.invalidate(2, true);
|
|
2261
|
-
*/
|
|
2262
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2263
|
-
if (this._frameloop !== "demand") return;
|
|
2264
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2265
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2266
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2267
|
-
}
|
|
2268
|
-
/**
|
|
2269
|
-
* Reset timing state for deterministic testing.
|
|
2270
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2271
|
-
* @returns {void}
|
|
2272
|
-
*/
|
|
2273
|
-
resetTiming() {
|
|
2274
|
-
this.loopState.lastTime = null;
|
|
2275
|
-
this.loopState.frameCount = 0;
|
|
2276
|
-
this.loopState.elapsedTime = 0;
|
|
2277
|
-
this.loopState.createdAt = performance.now();
|
|
2278
|
-
}
|
|
2279
|
-
//* Manual Stepping Methods ================================
|
|
2280
|
-
/**
|
|
2281
|
-
* Manually execute a single frame for all roots.
|
|
2282
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2283
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2284
|
-
* @returns {void}
|
|
2285
|
-
* @example
|
|
2286
|
-
* // Manual control mode
|
|
2287
|
-
* scheduler.frameloop = 'never';
|
|
2288
|
-
* scheduler.step(); // Execute one frame
|
|
2289
|
-
*/
|
|
2290
|
-
step(timestamp) {
|
|
2291
|
-
const now = timestamp ?? performance.now();
|
|
2292
|
-
this.executeFrame(now);
|
|
2293
|
-
}
|
|
2294
|
-
/**
|
|
2295
|
-
* Manually execute a single job by its ID.
|
|
2296
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2297
|
-
* @param {string} id - The job ID to step
|
|
2298
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2299
|
-
* @returns {void}
|
|
2300
|
-
*/
|
|
2301
|
-
stepJob(id, timestamp) {
|
|
2302
|
-
let job;
|
|
2303
|
-
let root;
|
|
2304
|
-
for (const r of this.roots.values()) {
|
|
2305
|
-
job = r.jobs.get(id);
|
|
2306
|
-
if (job) {
|
|
2307
|
-
root = r;
|
|
2308
|
-
break;
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
if (!job || !root) {
|
|
2312
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2313
|
-
return;
|
|
2314
|
-
}
|
|
2315
|
-
const now = timestamp ?? performance.now();
|
|
2316
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2317
|
-
const delta = deltaMs / 1e3;
|
|
2318
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2319
|
-
const providedState = root.getState?.() ?? {};
|
|
2320
|
-
const frameState = {
|
|
2321
|
-
...providedState,
|
|
2322
|
-
time: now,
|
|
2323
|
-
delta,
|
|
2324
|
-
elapsed,
|
|
2325
|
-
frame: this.loopState.frameCount
|
|
2326
|
-
};
|
|
2327
|
-
try {
|
|
2328
|
-
job.callback(frameState, delta);
|
|
2329
|
-
} catch (error) {
|
|
2330
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2331
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
/**
|
|
2335
|
-
* Execute a single frame across all roots.
|
|
2336
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2337
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2338
|
-
* @returns {void}
|
|
2339
|
-
* @private
|
|
2340
|
-
*/
|
|
2341
|
-
executeFrame(timestamp) {
|
|
2342
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2343
|
-
const delta = deltaMs / 1e3;
|
|
2344
|
-
this.loopState.lastTime = timestamp;
|
|
2345
|
-
this.loopState.frameCount++;
|
|
2346
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2347
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2348
|
-
for (const root of this.roots.values()) {
|
|
2349
|
-
this.tickRoot(root, timestamp, delta);
|
|
2350
|
-
}
|
|
2351
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2352
|
-
}
|
|
2353
|
-
/**
|
|
2354
|
-
* Run all global jobs from a job map.
|
|
2355
|
-
* Catches and logs errors without stopping execution.
|
|
2356
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2357
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2358
|
-
* @returns {void}
|
|
2359
|
-
* @private
|
|
2360
|
-
*/
|
|
2361
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2362
|
-
for (const job of jobs.values()) {
|
|
2363
|
-
try {
|
|
2364
|
-
job.callback(timestamp);
|
|
2365
|
-
} catch (error) {
|
|
2366
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
/**
|
|
2371
|
-
* Execute all jobs for a single root in sorted order.
|
|
2372
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2373
|
-
* Errors are caught and propagated via triggerError.
|
|
2374
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2375
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2376
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2377
|
-
* @returns {void}
|
|
2378
|
-
* @private
|
|
2379
|
-
*/
|
|
2380
|
-
tickRoot(root, timestamp, delta) {
|
|
2381
|
-
if (root.needsRebuild) {
|
|
2382
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2383
|
-
root.needsRebuild = false;
|
|
2384
|
-
}
|
|
2385
|
-
const providedState = root.getState?.() ?? {};
|
|
2386
|
-
const frameState = {
|
|
2387
|
-
...providedState,
|
|
2388
|
-
time: timestamp,
|
|
2389
|
-
delta,
|
|
2390
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2391
|
-
// Convert ms to seconds
|
|
2392
|
-
frame: this.loopState.frameCount
|
|
2393
|
-
};
|
|
2394
|
-
for (const job of root.sortedJobs) {
|
|
2395
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2396
|
-
try {
|
|
2397
|
-
job.callback(frameState, delta);
|
|
2398
|
-
} catch (error) {
|
|
2399
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2400
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2401
|
-
}
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
//* Debug & Inspection Methods ================================
|
|
2405
|
-
/**
|
|
2406
|
-
* Get the total number of registered jobs across all roots.
|
|
2407
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2408
|
-
* @returns {number} Total job count
|
|
2409
|
-
*/
|
|
2410
|
-
getJobCount() {
|
|
2411
|
-
let count = 0;
|
|
2412
|
-
for (const root of this.roots.values()) {
|
|
2413
|
-
count += root.jobs.size;
|
|
2414
|
-
}
|
|
2415
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2416
|
-
}
|
|
2417
|
-
/**
|
|
2418
|
-
* Get all registered job IDs across all roots.
|
|
2419
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2420
|
-
* @returns {string[]} Array of all job IDs
|
|
2421
|
-
*/
|
|
2422
|
-
getJobIds() {
|
|
2423
|
-
const ids = [];
|
|
2424
|
-
for (const root of this.roots.values()) {
|
|
2425
|
-
ids.push(...root.jobs.keys());
|
|
2426
|
-
}
|
|
2427
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2428
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2429
|
-
return ids;
|
|
2430
|
-
}
|
|
2431
|
-
/**
|
|
2432
|
-
* Get the number of registered roots (Canvas instances).
|
|
2433
|
-
* @returns {number} Number of registered roots
|
|
2434
|
-
*/
|
|
2435
|
-
getRootCount() {
|
|
2436
|
-
return this.roots.size;
|
|
2437
|
-
}
|
|
2438
|
-
/**
|
|
2439
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2440
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2441
|
-
*
|
|
2442
|
-
* @param phase The phase to check
|
|
2443
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2444
|
-
* @returns true if any user jobs exist in the phase
|
|
2445
|
-
*/
|
|
2446
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2447
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2448
|
-
return rootsToCheck.some((root) => {
|
|
2449
|
-
if (!root) return false;
|
|
2450
|
-
for (const job of root.jobs.values()) {
|
|
2451
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2452
|
-
}
|
|
2453
|
-
return false;
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
//* Utility Methods ================================
|
|
2457
|
-
/**
|
|
2458
|
-
* Generate a unique root ID for automatic root registration.
|
|
2459
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2460
|
-
*/
|
|
2461
|
-
generateRootId() {
|
|
2462
|
-
return `root_${this.nextRootIndex++}`;
|
|
2463
|
-
}
|
|
2464
|
-
/**
|
|
2465
|
-
* Generate a unique job ID.
|
|
2466
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2467
|
-
* @private
|
|
2468
|
-
*/
|
|
2469
|
-
generateJobId() {
|
|
2470
|
-
return `job_${this.nextJobIndex}`;
|
|
2471
|
-
}
|
|
2472
|
-
/**
|
|
2473
|
-
* Normalize before/after constraints to a Set.
|
|
2474
|
-
* Handles undefined, single string, or array inputs.
|
|
2475
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2476
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2477
|
-
* @private
|
|
2478
|
-
*/
|
|
2479
|
-
normalizeConstraints(value) {
|
|
2480
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2481
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2482
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2483
|
-
}
|
|
2484
|
-
};
|
|
2485
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2486
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2487
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2488
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2489
|
-
__publicField$1(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2490
|
-
let Scheduler = _Scheduler;
|
|
2491
|
-
const getScheduler = () => Scheduler.get();
|
|
2492
|
-
if (hmrData) {
|
|
2493
|
-
hmrData.accept?.();
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
1662
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
2497
1663
|
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
2498
1664
|
const createStore = (invalidate, advance) => {
|
|
@@ -2530,7 +1696,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2530
1696
|
frustum: new webgpu.Frustum(),
|
|
2531
1697
|
autoUpdateFrustum: true,
|
|
2532
1698
|
raycaster: null,
|
|
2533
|
-
events: {
|
|
1699
|
+
events: {
|
|
1700
|
+
priority: 1,
|
|
1701
|
+
enabled: true,
|
|
1702
|
+
connected: false,
|
|
1703
|
+
frameTimedRaycasts: true,
|
|
1704
|
+
alwaysFireOnScroll: true,
|
|
1705
|
+
updateOnFrame: false
|
|
1706
|
+
},
|
|
2534
1707
|
scene: null,
|
|
2535
1708
|
rootScene: null,
|
|
2536
1709
|
xr: null,
|
|
@@ -2595,7 +1768,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2595
1768
|
size: newSize,
|
|
2596
1769
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
2597
1770
|
}));
|
|
2598
|
-
getScheduler().invalidate();
|
|
1771
|
+
scheduler.getScheduler().invalidate();
|
|
2599
1772
|
}
|
|
2600
1773
|
}
|
|
2601
1774
|
return;
|
|
@@ -2610,7 +1783,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2610
1783
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
2611
1784
|
_sizeImperative: true
|
|
2612
1785
|
}));
|
|
2613
|
-
getScheduler().invalidate();
|
|
1786
|
+
scheduler.getScheduler().invalidate();
|
|
2614
1787
|
},
|
|
2615
1788
|
setDpr: (dpr) => set((state2) => {
|
|
2616
1789
|
const resolved = calculateDpr(dpr);
|
|
@@ -2621,11 +1794,14 @@ const createStore = (invalidate, advance) => {
|
|
|
2621
1794
|
},
|
|
2622
1795
|
setError: (error) => set(() => ({ error })),
|
|
2623
1796
|
error: null,
|
|
2624
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1797
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
2625
1798
|
uniforms: {},
|
|
2626
1799
|
nodes: {},
|
|
1800
|
+
buffers: {},
|
|
1801
|
+
gpuStorage: {},
|
|
2627
1802
|
textures: /* @__PURE__ */ new Map(),
|
|
2628
|
-
|
|
1803
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1804
|
+
renderPipeline: null,
|
|
2629
1805
|
passes: {},
|
|
2630
1806
|
_hmrVersion: 0,
|
|
2631
1807
|
_sizeImperative: false,
|
|
@@ -2634,12 +1810,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2634
1810
|
internal: {
|
|
2635
1811
|
// Events
|
|
2636
1812
|
interaction: [],
|
|
2637
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
2638
1813
|
subscribers: [],
|
|
1814
|
+
// Per-pointer state (new unified structure)
|
|
1815
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1816
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1817
|
+
lastEvent: React__namespace.createRef(),
|
|
1818
|
+
// Deprecated but kept for backwards compatibility
|
|
1819
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
2639
1820
|
initialClick: [0, 0],
|
|
2640
1821
|
initialHits: [],
|
|
2641
1822
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
2642
|
-
lastEvent: React__namespace.createRef(),
|
|
2643
1823
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
2644
1824
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
2645
1825
|
// Occlusion system (WebGPU only)
|
|
@@ -2727,14 +1907,16 @@ const createStore = (invalidate, advance) => {
|
|
|
2727
1907
|
oldSize = size;
|
|
2728
1908
|
oldDpr = viewport.dpr;
|
|
2729
1909
|
updateCamera(camera, size);
|
|
2730
|
-
if (canvasTarget) {
|
|
1910
|
+
if (internal.isSecondary && canvasTarget) {
|
|
2731
1911
|
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
2732
|
-
|
|
2733
|
-
canvasTarget.setSize(size.width, size.height, updateStyle);
|
|
1912
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
2734
1913
|
} else {
|
|
2735
1914
|
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
2736
|
-
|
|
2737
|
-
|
|
1915
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1916
|
+
if (canvasTarget) {
|
|
1917
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1918
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1919
|
+
}
|
|
2738
1920
|
}
|
|
2739
1921
|
}
|
|
2740
1922
|
if (camera !== oldCamera) {
|
|
@@ -2809,7 +1991,7 @@ useLoader.loader = getLoader;
|
|
|
2809
1991
|
function useFrame(callback, priorityOrOptions) {
|
|
2810
1992
|
const store = React__namespace.useContext(context);
|
|
2811
1993
|
const isInsideCanvas = store !== null;
|
|
2812
|
-
const scheduler = getScheduler();
|
|
1994
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
2813
1995
|
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2814
1996
|
id: priorityOrOptions.id,
|
|
2815
1997
|
phase: priorityOrOptions.phase,
|
|
@@ -2857,7 +2039,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2857
2039
|
};
|
|
2858
2040
|
callbackRef.current?.(mergedState, delta);
|
|
2859
2041
|
};
|
|
2860
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2042
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2861
2043
|
id,
|
|
2862
2044
|
rootId,
|
|
2863
2045
|
...options
|
|
@@ -2878,37 +2060,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2878
2060
|
}
|
|
2879
2061
|
};
|
|
2880
2062
|
} else {
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
unregisterJob = registerOutside();
|
|
2890
|
-
});
|
|
2891
|
-
return () => {
|
|
2892
|
-
unsubReady();
|
|
2893
|
-
unregisterJob?.();
|
|
2894
|
-
};
|
|
2063
|
+
return scheduler$1.register(
|
|
2064
|
+
(state, delta) => {
|
|
2065
|
+
const frameState = state;
|
|
2066
|
+
if (!frameState.renderer) return;
|
|
2067
|
+
callbackRef.current?.(frameState, delta);
|
|
2068
|
+
},
|
|
2069
|
+
{ id, ...options }
|
|
2070
|
+
);
|
|
2895
2071
|
}
|
|
2896
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2072
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2897
2073
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
2898
2074
|
// Subscribe function
|
|
2899
2075
|
React__namespace.useCallback(
|
|
2900
2076
|
(onStoreChange) => {
|
|
2901
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2077
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2902
2078
|
},
|
|
2903
2079
|
[id]
|
|
2904
2080
|
),
|
|
2905
2081
|
// getSnapshot function
|
|
2906
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2082
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2907
2083
|
// getServerSnapshot function (SSR)
|
|
2908
2084
|
React__namespace.useCallback(() => false, [])
|
|
2909
2085
|
);
|
|
2910
2086
|
const controls = React__namespace.useMemo(() => {
|
|
2911
|
-
const scheduler2 = getScheduler();
|
|
2087
|
+
const scheduler2 = scheduler.getScheduler();
|
|
2912
2088
|
return {
|
|
2913
2089
|
/** The job's unique ID */
|
|
2914
2090
|
id,
|
|
@@ -2923,7 +2099,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2923
2099
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2924
2100
|
*/
|
|
2925
2101
|
step: (timestamp) => {
|
|
2926
|
-
getScheduler().stepJob(id, timestamp);
|
|
2102
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
2927
2103
|
},
|
|
2928
2104
|
/**
|
|
2929
2105
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -2931,20 +2107,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2931
2107
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2932
2108
|
*/
|
|
2933
2109
|
stepAll: (timestamp) => {
|
|
2934
|
-
getScheduler().step(timestamp);
|
|
2110
|
+
scheduler.getScheduler().step(timestamp);
|
|
2935
2111
|
},
|
|
2936
2112
|
/**
|
|
2937
2113
|
* Pause this job (set enabled=false).
|
|
2938
2114
|
* Job remains registered but won't run.
|
|
2939
2115
|
*/
|
|
2940
2116
|
pause: () => {
|
|
2941
|
-
getScheduler().pauseJob(id);
|
|
2117
|
+
scheduler.getScheduler().pauseJob(id);
|
|
2942
2118
|
},
|
|
2943
2119
|
/**
|
|
2944
2120
|
* Resume this job (set enabled=true).
|
|
2945
2121
|
*/
|
|
2946
2122
|
resume: () => {
|
|
2947
|
-
getScheduler().resumeJob(id);
|
|
2123
|
+
scheduler.getScheduler().resumeJob(id);
|
|
2948
2124
|
},
|
|
2949
2125
|
/**
|
|
2950
2126
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -2982,18 +2158,18 @@ function buildFromCache(input, textureCache) {
|
|
|
2982
2158
|
function useTexture(input, optionsOrOnLoad) {
|
|
2983
2159
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2984
2160
|
const store = useStore();
|
|
2985
|
-
const textureCache = useThree((state) => state.textures);
|
|
2986
2161
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2987
|
-
const { onLoad, cache =
|
|
2162
|
+
const { onLoad, cache = true } = options;
|
|
2988
2163
|
const onLoadRef = React.useRef(onLoad);
|
|
2989
2164
|
onLoadRef.current = onLoad;
|
|
2990
2165
|
const onLoadCalledForRef = React.useRef(null);
|
|
2991
2166
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2992
2167
|
const cachedResult = React.useMemo(() => {
|
|
2993
2168
|
if (!cache) return null;
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2169
|
+
const textures = store.getState().textures;
|
|
2170
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2171
|
+
return buildFromCache(input, textures);
|
|
2172
|
+
}, [cache, urls, input, store]);
|
|
2997
2173
|
const loadedTextures = useLoader(
|
|
2998
2174
|
webgpu.TextureLoader,
|
|
2999
2175
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3037,8 +2213,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3037
2213
|
}, [input, loadedTextures, cachedResult]);
|
|
3038
2214
|
React.useEffect(() => {
|
|
3039
2215
|
if (!cache) return;
|
|
3040
|
-
if (cachedResult) return;
|
|
3041
|
-
const set = store.setState;
|
|
3042
2216
|
const urlTextureMap = [];
|
|
3043
2217
|
if (typeof input === "string") {
|
|
3044
2218
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3052,18 +2226,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3052
2226
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3053
2227
|
}
|
|
3054
2228
|
}
|
|
3055
|
-
|
|
3056
|
-
const
|
|
3057
|
-
let
|
|
2229
|
+
store.setState((state) => {
|
|
2230
|
+
const refs = new Map(state._textureRefs);
|
|
2231
|
+
let textures = state.textures;
|
|
2232
|
+
let added = false;
|
|
3058
2233
|
for (const [url, texture] of urlTextureMap) {
|
|
3059
|
-
if (!
|
|
3060
|
-
|
|
3061
|
-
|
|
2234
|
+
if (!textures.has(url)) {
|
|
2235
|
+
if (!added) {
|
|
2236
|
+
textures = new Map(textures);
|
|
2237
|
+
added = true;
|
|
2238
|
+
}
|
|
2239
|
+
textures.set(url, texture);
|
|
3062
2240
|
}
|
|
2241
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3063
2242
|
}
|
|
3064
|
-
return
|
|
2243
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
3065
2244
|
});
|
|
3066
|
-
|
|
2245
|
+
return () => store.setState((state) => {
|
|
2246
|
+
const refs = new Map(state._textureRefs);
|
|
2247
|
+
for (const [url] of urlTextureMap) {
|
|
2248
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2249
|
+
if (next <= 0) refs.delete(url);
|
|
2250
|
+
else refs.set(url, next);
|
|
2251
|
+
}
|
|
2252
|
+
return { _textureRefs: refs };
|
|
2253
|
+
});
|
|
2254
|
+
}, [cache, input, mappedTextures, store]);
|
|
3067
2255
|
return mappedTextures;
|
|
3068
2256
|
}
|
|
3069
2257
|
useTexture.preload = (url) => useLoader.preload(webgpu.TextureLoader, url);
|
|
@@ -3077,98 +2265,65 @@ const Texture = ({
|
|
|
3077
2265
|
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
3078
2266
|
const ret = useTexture(input, options);
|
|
3079
2267
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
3080
|
-
};
|
|
3081
|
-
|
|
3082
|
-
function
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
}
|
|
3089
|
-
function useTextures() {
|
|
3090
|
-
const store = useStore();
|
|
3091
|
-
return React.useMemo(() => {
|
|
3092
|
-
const set = store.setState;
|
|
3093
|
-
const getState = store.getState;
|
|
3094
|
-
const add = (key, value) => {
|
|
3095
|
-
set((state) => {
|
|
3096
|
-
const newMap = new Map(state.textures);
|
|
3097
|
-
newMap.set(key, value);
|
|
3098
|
-
return { textures: newMap };
|
|
3099
|
-
});
|
|
3100
|
-
};
|
|
3101
|
-
const addMultiple = (items) => {
|
|
3102
|
-
set((state) => {
|
|
3103
|
-
const newMap = new Map(state.textures);
|
|
3104
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3105
|
-
for (const [key, value] of entries) {
|
|
3106
|
-
newMap.set(key, value);
|
|
3107
|
-
}
|
|
3108
|
-
return { textures: newMap };
|
|
3109
|
-
});
|
|
3110
|
-
};
|
|
3111
|
-
const remove = (key) => {
|
|
3112
|
-
set((state) => {
|
|
3113
|
-
const newMap = new Map(state.textures);
|
|
3114
|
-
newMap.delete(key);
|
|
3115
|
-
return { textures: newMap };
|
|
3116
|
-
});
|
|
3117
|
-
};
|
|
3118
|
-
const removeMultiple = (keys) => {
|
|
3119
|
-
set((state) => {
|
|
3120
|
-
const newMap = new Map(state.textures);
|
|
3121
|
-
for (const key of keys) newMap.delete(key);
|
|
3122
|
-
return { textures: newMap };
|
|
3123
|
-
});
|
|
3124
|
-
};
|
|
3125
|
-
const dispose = (key) => {
|
|
3126
|
-
const entry = getState().textures.get(key);
|
|
3127
|
-
if (entry) {
|
|
3128
|
-
const tex = getTextureValue(entry);
|
|
3129
|
-
tex?.dispose();
|
|
3130
|
-
}
|
|
3131
|
-
remove(key);
|
|
3132
|
-
};
|
|
3133
|
-
const disposeMultiple = (keys) => {
|
|
3134
|
-
const textures = getState().textures;
|
|
3135
|
-
for (const key of keys) {
|
|
3136
|
-
const entry = textures.get(key);
|
|
3137
|
-
if (entry) {
|
|
3138
|
-
const tex = getTextureValue(entry);
|
|
3139
|
-
tex?.dispose();
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
removeMultiple(keys);
|
|
3143
|
-
};
|
|
3144
|
-
const disposeAll = () => {
|
|
3145
|
-
const textures = getState().textures;
|
|
3146
|
-
for (const entry of textures.values()) {
|
|
3147
|
-
const tex = getTextureValue(entry);
|
|
3148
|
-
tex?.dispose();
|
|
3149
|
-
}
|
|
3150
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3151
|
-
};
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2270
|
+
function useTextures(selector) {
|
|
2271
|
+
const store = useStore();
|
|
2272
|
+
const registry = React.useMemo(() => {
|
|
2273
|
+
const getState = store.getState;
|
|
2274
|
+
const setState = store.setState;
|
|
2275
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3152
2276
|
return {
|
|
3153
|
-
|
|
3154
|
-
get textures() {
|
|
2277
|
+
get all() {
|
|
3155
2278
|
return getState().textures;
|
|
3156
2279
|
},
|
|
3157
|
-
|
|
3158
|
-
|
|
2280
|
+
get(input) {
|
|
2281
|
+
if (typeof input === "string") return getOne(input);
|
|
2282
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2283
|
+
const out = {};
|
|
2284
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2285
|
+
return out;
|
|
2286
|
+
},
|
|
3159
2287
|
has: (key) => getState().textures.has(key),
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
2288
|
+
add(keyOrRecord, texture) {
|
|
2289
|
+
setState((state) => {
|
|
2290
|
+
const textures = new Map(state.textures);
|
|
2291
|
+
if (typeof keyOrRecord === "string") {
|
|
2292
|
+
textures.set(keyOrRecord, texture);
|
|
2293
|
+
} else {
|
|
2294
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2295
|
+
}
|
|
2296
|
+
return { textures };
|
|
2297
|
+
});
|
|
2298
|
+
},
|
|
2299
|
+
dispose(key, options) {
|
|
2300
|
+
const state = getState();
|
|
2301
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2302
|
+
if (refs > 0 && !options?.force) {
|
|
2303
|
+
console.warn(
|
|
2304
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2305
|
+
);
|
|
2306
|
+
return false;
|
|
2307
|
+
}
|
|
2308
|
+
state.textures.get(key)?.dispose();
|
|
2309
|
+
setState((s) => {
|
|
2310
|
+
const textures = new Map(s.textures);
|
|
2311
|
+
textures.delete(key);
|
|
2312
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2313
|
+
nextRefs.delete(key);
|
|
2314
|
+
return { textures, _textureRefs: nextRefs };
|
|
2315
|
+
});
|
|
2316
|
+
return true;
|
|
2317
|
+
},
|
|
2318
|
+
disposeAll() {
|
|
2319
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2320
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2321
|
+
}
|
|
3170
2322
|
};
|
|
3171
2323
|
}, [store]);
|
|
2324
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2325
|
+
const selected = useThree(subscribe);
|
|
2326
|
+
return selector ? selected : registry;
|
|
3172
2327
|
}
|
|
3173
2328
|
|
|
3174
2329
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
@@ -3223,7 +2378,7 @@ function addEffect(callback) {
|
|
|
3223
2378
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3224
2379
|
});
|
|
3225
2380
|
const id = `legacy_effect_${effectId++}`;
|
|
3226
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2381
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
3227
2382
|
}
|
|
3228
2383
|
function addAfterEffect(callback) {
|
|
3229
2384
|
notifyDepreciated({
|
|
@@ -3232,7 +2387,7 @@ function addAfterEffect(callback) {
|
|
|
3232
2387
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3233
2388
|
});
|
|
3234
2389
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
3235
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2390
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
3236
2391
|
}
|
|
3237
2392
|
function addTail(callback) {
|
|
3238
2393
|
notifyDepreciated({
|
|
@@ -3240,13 +2395,13 @@ function addTail(callback) {
|
|
|
3240
2395
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
3241
2396
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
3242
2397
|
});
|
|
3243
|
-
return getScheduler().onIdle(callback);
|
|
2398
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
3244
2399
|
}
|
|
3245
2400
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
3246
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2401
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
3247
2402
|
}
|
|
3248
2403
|
function advance(timestamp) {
|
|
3249
|
-
getScheduler().step(timestamp);
|
|
2404
|
+
scheduler.getScheduler().step(timestamp);
|
|
3250
2405
|
}
|
|
3251
2406
|
|
|
3252
2407
|
const version = "10.0.0-alpha.2";
|
|
@@ -15019,7 +14174,6 @@ function createRoot(canvas) {
|
|
|
15019
14174
|
events,
|
|
15020
14175
|
onCreated: onCreatedCallback,
|
|
15021
14176
|
shadows = false,
|
|
15022
|
-
textureColorSpace = webgpu.SRGBColorSpace,
|
|
15023
14177
|
orthographic = false,
|
|
15024
14178
|
frameloop = "always",
|
|
15025
14179
|
dpr = [1, 2],
|
|
@@ -15034,6 +14188,7 @@ function createRoot(canvas) {
|
|
|
15034
14188
|
_sizeProps,
|
|
15035
14189
|
forceEven
|
|
15036
14190
|
} = props;
|
|
14191
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || webgpu.SRGBColorSpace;
|
|
15037
14192
|
const state = store.getState();
|
|
15038
14193
|
const defaultGPUProps = {
|
|
15039
14194
|
canvas,
|
|
@@ -15071,6 +14226,12 @@ function createRoot(canvas) {
|
|
|
15071
14226
|
} else if (!state.internal.actualRenderer) {
|
|
15072
14227
|
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, webgpu.WebGPURenderer);
|
|
15073
14228
|
if (!renderer.hasInitialized?.()) {
|
|
14229
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14230
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14231
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14232
|
+
canvas.width = size2.width * pixelRatio;
|
|
14233
|
+
canvas.height = size2.height * pixelRatio;
|
|
14234
|
+
}
|
|
15074
14235
|
await renderer.init();
|
|
15075
14236
|
}
|
|
15076
14237
|
const backend = renderer.backend;
|
|
@@ -15180,7 +14341,7 @@ function createRoot(canvas) {
|
|
|
15180
14341
|
lastConfiguredProps.performance = performance;
|
|
15181
14342
|
}
|
|
15182
14343
|
if (!state.xr) {
|
|
15183
|
-
const handleXRFrame = (timestamp,
|
|
14344
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
15184
14345
|
const state2 = store.getState();
|
|
15185
14346
|
if (state2.frameloop === "never") return;
|
|
15186
14347
|
advance(timestamp);
|
|
@@ -15216,15 +14377,22 @@ function createRoot(canvas) {
|
|
|
15216
14377
|
const oldType = renderer.shadowMap.type;
|
|
15217
14378
|
renderer.shadowMap.enabled = !!shadows;
|
|
15218
14379
|
if (is.boo(shadows)) {
|
|
15219
|
-
renderer.shadowMap.type = webgpu.
|
|
14380
|
+
renderer.shadowMap.type = webgpu.PCFShadowMap;
|
|
15220
14381
|
} else if (is.str(shadows)) {
|
|
14382
|
+
if (shadows === "soft") {
|
|
14383
|
+
notifyDepreciated({
|
|
14384
|
+
heading: 'shadows="soft" is deprecated',
|
|
14385
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14386
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14387
|
+
});
|
|
14388
|
+
}
|
|
15221
14389
|
const types = {
|
|
15222
14390
|
basic: webgpu.BasicShadowMap,
|
|
15223
14391
|
percentage: webgpu.PCFShadowMap,
|
|
15224
|
-
soft: webgpu.
|
|
14392
|
+
soft: webgpu.PCFShadowMap,
|
|
15225
14393
|
variance: webgpu.VSMShadowMap
|
|
15226
14394
|
};
|
|
15227
|
-
renderer.shadowMap.type = types[shadows] ?? webgpu.
|
|
14395
|
+
renderer.shadowMap.type = types[shadows] ?? webgpu.PCFShadowMap;
|
|
15228
14396
|
} else if (is.obj(shadows)) {
|
|
15229
14397
|
Object.assign(renderer.shadowMap, shadows);
|
|
15230
14398
|
}
|
|
@@ -15240,24 +14408,35 @@ function createRoot(canvas) {
|
|
|
15240
14408
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
15241
14409
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
15242
14410
|
}
|
|
14411
|
+
const r3fProps = ["textureColorSpace"];
|
|
14412
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14413
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
15243
14414
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
15244
|
-
|
|
14415
|
+
const glProps = {};
|
|
14416
|
+
for (const key in glConfig) {
|
|
14417
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14418
|
+
}
|
|
14419
|
+
applyProps(renderer, glProps);
|
|
15245
14420
|
}
|
|
15246
14421
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
15247
14422
|
const currentRenderer = state.renderer;
|
|
15248
14423
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
15249
|
-
|
|
14424
|
+
const rendererProps = {};
|
|
14425
|
+
for (const key in rendererConfig) {
|
|
14426
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14427
|
+
}
|
|
14428
|
+
applyProps(currentRenderer, rendererProps);
|
|
15250
14429
|
}
|
|
15251
14430
|
}
|
|
15252
|
-
const scheduler = getScheduler();
|
|
14431
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
15253
14432
|
const rootId = state.internal.rootId;
|
|
15254
14433
|
if (!rootId) {
|
|
15255
|
-
const newRootId = canvasId || scheduler.generateRootId();
|
|
15256
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14434
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14435
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
15257
14436
|
getState: () => store.getState(),
|
|
15258
14437
|
onError: (err) => store.getState().setError(err)
|
|
15259
14438
|
});
|
|
15260
|
-
const unregisterCanvasTarget = scheduler.register(
|
|
14439
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
15261
14440
|
() => {
|
|
15262
14441
|
const state2 = store.getState();
|
|
15263
14442
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
@@ -15272,7 +14451,19 @@ function createRoot(canvas) {
|
|
|
15272
14451
|
system: true
|
|
15273
14452
|
}
|
|
15274
14453
|
);
|
|
15275
|
-
const
|
|
14454
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
14455
|
+
() => {
|
|
14456
|
+
const state2 = store.getState();
|
|
14457
|
+
state2.events.flush?.();
|
|
14458
|
+
},
|
|
14459
|
+
{
|
|
14460
|
+
id: `${newRootId}_events`,
|
|
14461
|
+
rootId: newRootId,
|
|
14462
|
+
phase: "input",
|
|
14463
|
+
system: true
|
|
14464
|
+
}
|
|
14465
|
+
);
|
|
14466
|
+
const unregisterFrustum = scheduler$1.register(
|
|
15276
14467
|
() => {
|
|
15277
14468
|
const state2 = store.getState();
|
|
15278
14469
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -15282,11 +14473,11 @@ function createRoot(canvas) {
|
|
|
15282
14473
|
{
|
|
15283
14474
|
id: `${newRootId}_frustum`,
|
|
15284
14475
|
rootId: newRootId,
|
|
15285
|
-
|
|
14476
|
+
before: "render",
|
|
15286
14477
|
system: true
|
|
15287
14478
|
}
|
|
15288
14479
|
);
|
|
15289
|
-
const unregisterVisibility = scheduler.register(
|
|
14480
|
+
const unregisterVisibility = scheduler$1.register(
|
|
15290
14481
|
() => {
|
|
15291
14482
|
const state2 = store.getState();
|
|
15292
14483
|
checkVisibility(state2);
|
|
@@ -15294,19 +14485,19 @@ function createRoot(canvas) {
|
|
|
15294
14485
|
{
|
|
15295
14486
|
id: `${newRootId}_visibility`,
|
|
15296
14487
|
rootId: newRootId,
|
|
15297
|
-
|
|
14488
|
+
before: "render",
|
|
15298
14489
|
system: true,
|
|
15299
14490
|
after: `${newRootId}_frustum`
|
|
15300
14491
|
}
|
|
15301
14492
|
);
|
|
15302
|
-
const unregisterRender = scheduler.register(
|
|
14493
|
+
const unregisterRender = scheduler$1.register(
|
|
15303
14494
|
() => {
|
|
15304
14495
|
const state2 = store.getState();
|
|
15305
14496
|
const renderer2 = state2.internal.actualRenderer;
|
|
15306
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14497
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
15307
14498
|
if (userHandlesRender || state2.internal.priority) return;
|
|
15308
14499
|
try {
|
|
15309
|
-
if (state2.
|
|
14500
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
15310
14501
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
15311
14502
|
} catch (error) {
|
|
15312
14503
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -15331,15 +14522,16 @@ function createRoot(canvas) {
|
|
|
15331
14522
|
unregisterRoot: () => {
|
|
15332
14523
|
unregisterRoot();
|
|
15333
14524
|
unregisterCanvasTarget();
|
|
14525
|
+
unregisterEventsFlush();
|
|
15334
14526
|
unregisterFrustum();
|
|
15335
14527
|
unregisterVisibility();
|
|
15336
14528
|
unregisterRender();
|
|
15337
14529
|
},
|
|
15338
|
-
scheduler
|
|
14530
|
+
scheduler: scheduler$1
|
|
15339
14531
|
}
|
|
15340
14532
|
}));
|
|
15341
14533
|
}
|
|
15342
|
-
scheduler.frameloop = frameloop;
|
|
14534
|
+
scheduler$1.frameloop = frameloop;
|
|
15343
14535
|
onCreated = onCreatedCallback;
|
|
15344
14536
|
configured = true;
|
|
15345
14537
|
resolve();
|
|
@@ -15496,9 +14688,13 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
15496
14688
|
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
15497
14689
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
15498
14690
|
onMutate(previousRoot.getState());
|
|
15499
|
-
previousRoot.subscribe(onMutate);
|
|
15500
14691
|
return store;
|
|
15501
14692
|
}, [previousRoot, container]);
|
|
14693
|
+
useIsomorphicLayoutEffect(() => {
|
|
14694
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14695
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14696
|
+
return unsubscribe;
|
|
14697
|
+
}, [previousRoot, usePortalStore]);
|
|
15502
14698
|
return (
|
|
15503
14699
|
// @ts-ignore, reconciler types are not maintained
|
|
15504
14700
|
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
@@ -15512,6 +14708,46 @@ function flushSync(fn) {
|
|
|
15512
14708
|
return reconciler.flushSyncFromReconciler(fn);
|
|
15513
14709
|
}
|
|
15514
14710
|
|
|
14711
|
+
function parseBackground(background) {
|
|
14712
|
+
if (!background) return null;
|
|
14713
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14714
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14715
|
+
return {
|
|
14716
|
+
...rest,
|
|
14717
|
+
preset,
|
|
14718
|
+
files: envMap || files,
|
|
14719
|
+
backgroundFiles: backgroundMap,
|
|
14720
|
+
background: true
|
|
14721
|
+
};
|
|
14722
|
+
}
|
|
14723
|
+
if (typeof background === "number") {
|
|
14724
|
+
return { color: background, background: true };
|
|
14725
|
+
}
|
|
14726
|
+
if (typeof background === "string") {
|
|
14727
|
+
if (background in presetsObj) {
|
|
14728
|
+
return { preset: background, background: true };
|
|
14729
|
+
}
|
|
14730
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14731
|
+
return { files: background, background: true };
|
|
14732
|
+
}
|
|
14733
|
+
return { color: background, background: true };
|
|
14734
|
+
}
|
|
14735
|
+
if (background.isColor) {
|
|
14736
|
+
return { color: background, background: true };
|
|
14737
|
+
}
|
|
14738
|
+
return null;
|
|
14739
|
+
}
|
|
14740
|
+
|
|
14741
|
+
function clearHmrCaches(store) {
|
|
14742
|
+
store.setState((state) => ({
|
|
14743
|
+
nodes: {},
|
|
14744
|
+
uniforms: {},
|
|
14745
|
+
buffers: {},
|
|
14746
|
+
gpuStorage: {},
|
|
14747
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14748
|
+
}));
|
|
14749
|
+
}
|
|
14750
|
+
|
|
15515
14751
|
function CanvasImpl({
|
|
15516
14752
|
ref,
|
|
15517
14753
|
children,
|
|
@@ -15532,6 +14768,8 @@ function CanvasImpl({
|
|
|
15532
14768
|
raycaster,
|
|
15533
14769
|
camera,
|
|
15534
14770
|
scene,
|
|
14771
|
+
autoUpdateFrustum,
|
|
14772
|
+
occlusion,
|
|
15535
14773
|
onPointerMissed,
|
|
15536
14774
|
onDragOverMissed,
|
|
15537
14775
|
onDropMissed,
|
|
@@ -15543,39 +14781,21 @@ function CanvasImpl({
|
|
|
15543
14781
|
forceEven,
|
|
15544
14782
|
...props
|
|
15545
14783
|
}) {
|
|
15546
|
-
const
|
|
15547
|
-
|
|
14784
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14785
|
+
let primaryCanvas;
|
|
14786
|
+
let scheduler;
|
|
14787
|
+
let renderer;
|
|
14788
|
+
if (isRendererConfig) {
|
|
14789
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14790
|
+
primaryCanvas = pc;
|
|
14791
|
+
scheduler = sc;
|
|
14792
|
+
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
14793
|
+
} else {
|
|
14794
|
+
renderer = rendererProp;
|
|
14795
|
+
}
|
|
15548
14796
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15549
14797
|
const Bridge = useBridge();
|
|
15550
|
-
const backgroundProps = React__namespace.useMemo(() =>
|
|
15551
|
-
if (!background) return null;
|
|
15552
|
-
if (typeof background === "object" && !background.isColor) {
|
|
15553
|
-
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
15554
|
-
return {
|
|
15555
|
-
...rest,
|
|
15556
|
-
preset,
|
|
15557
|
-
files: envMap || files,
|
|
15558
|
-
backgroundFiles: backgroundMap,
|
|
15559
|
-
background: true
|
|
15560
|
-
};
|
|
15561
|
-
}
|
|
15562
|
-
if (typeof background === "number") {
|
|
15563
|
-
return { color: background, background: true };
|
|
15564
|
-
}
|
|
15565
|
-
if (typeof background === "string") {
|
|
15566
|
-
if (background in presetsObj) {
|
|
15567
|
-
return { preset: background, background: true };
|
|
15568
|
-
}
|
|
15569
|
-
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
15570
|
-
return { files: background, background: true };
|
|
15571
|
-
}
|
|
15572
|
-
return { color: background, background: true };
|
|
15573
|
-
}
|
|
15574
|
-
if (background.isColor) {
|
|
15575
|
-
return { color: background, background: true };
|
|
15576
|
-
}
|
|
15577
|
-
return null;
|
|
15578
|
-
}, [background]);
|
|
14798
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15579
14799
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15580
14800
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15581
14801
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15659,6 +14879,8 @@ function CanvasImpl({
|
|
|
15659
14879
|
performance,
|
|
15660
14880
|
raycaster,
|
|
15661
14881
|
camera,
|
|
14882
|
+
autoUpdateFrustum,
|
|
14883
|
+
occlusion,
|
|
15662
14884
|
size: effectiveSize,
|
|
15663
14885
|
// Store size props for reset functionality
|
|
15664
14886
|
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
@@ -15718,20 +14940,13 @@ function CanvasImpl({
|
|
|
15718
14940
|
const handleHMR = () => {
|
|
15719
14941
|
queueMicrotask(() => {
|
|
15720
14942
|
const rootEntry = _roots.get(canvas);
|
|
15721
|
-
if (rootEntry?.store)
|
|
15722
|
-
rootEntry.store.setState((state) => ({
|
|
15723
|
-
nodes: {},
|
|
15724
|
-
uniforms: {},
|
|
15725
|
-
_hmrVersion: state._hmrVersion + 1
|
|
15726
|
-
}));
|
|
15727
|
-
}
|
|
14943
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15728
14944
|
});
|
|
15729
14945
|
};
|
|
15730
14946
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
15731
14947
|
const hot = undefined;
|
|
15732
14948
|
hot.on("vite:afterUpdate", handleHMR);
|
|
15733
|
-
return () => hot.
|
|
15734
|
-
});
|
|
14949
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15735
14950
|
}
|
|
15736
14951
|
if (typeof module !== "undefined" && module.hot) {
|
|
15737
14952
|
const hot = module.hot;
|
|
@@ -15754,7 +14969,16 @@ function CanvasImpl({
|
|
|
15754
14969
|
...style
|
|
15755
14970
|
},
|
|
15756
14971
|
...props,
|
|
15757
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14972
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14973
|
+
"canvas",
|
|
14974
|
+
{
|
|
14975
|
+
ref: canvasRef,
|
|
14976
|
+
id,
|
|
14977
|
+
className: "r3f-canvas",
|
|
14978
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
14979
|
+
children: fallback
|
|
14980
|
+
}
|
|
14981
|
+
) })
|
|
15758
14982
|
}
|
|
15759
14983
|
);
|
|
15760
14984
|
}
|
|
@@ -15830,6 +15054,8 @@ function createScopedStore(data) {
|
|
|
15830
15054
|
function createLazyCreatorState(state) {
|
|
15831
15055
|
let _uniforms = null;
|
|
15832
15056
|
let _nodes = null;
|
|
15057
|
+
let _buffers = null;
|
|
15058
|
+
let _gpuStorage = null;
|
|
15833
15059
|
return Object.create(state, {
|
|
15834
15060
|
uniforms: {
|
|
15835
15061
|
get() {
|
|
@@ -15840,10 +15066,34 @@ function createLazyCreatorState(state) {
|
|
|
15840
15066
|
get() {
|
|
15841
15067
|
return _nodes ?? (_nodes = createScopedStore(state.nodes));
|
|
15842
15068
|
}
|
|
15069
|
+
},
|
|
15070
|
+
buffers: {
|
|
15071
|
+
get() {
|
|
15072
|
+
return _buffers ?? (_buffers = createScopedStore(state.buffers));
|
|
15073
|
+
}
|
|
15074
|
+
},
|
|
15075
|
+
gpuStorage: {
|
|
15076
|
+
get() {
|
|
15077
|
+
return _gpuStorage ?? (_gpuStorage = createScopedStore(state.gpuStorage));
|
|
15078
|
+
}
|
|
15843
15079
|
}
|
|
15844
15080
|
});
|
|
15845
15081
|
}
|
|
15846
15082
|
|
|
15083
|
+
function resolvePrimary(local) {
|
|
15084
|
+
return local.getState().primaryStore ?? local;
|
|
15085
|
+
}
|
|
15086
|
+
function usePrimaryStore() {
|
|
15087
|
+
const local = useStore();
|
|
15088
|
+
const primary = local.getState().primaryStore;
|
|
15089
|
+
return React.useMemo(() => primary ?? local, [primary, local]);
|
|
15090
|
+
}
|
|
15091
|
+
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15092
|
+
const local = useStore();
|
|
15093
|
+
const primary = resolvePrimary(local);
|
|
15094
|
+
return primary(selector, equalityFn);
|
|
15095
|
+
}
|
|
15096
|
+
|
|
15847
15097
|
function addTexture(set, key, value) {
|
|
15848
15098
|
set((state) => {
|
|
15849
15099
|
const newMap = new Map(state.textures);
|
|
@@ -15922,6 +15172,10 @@ function vectorize(inObject) {
|
|
|
15922
15172
|
if (obj.isVector2 || obj.isVector3 || obj.isVector4) return inObject;
|
|
15923
15173
|
if (obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15924
15174
|
if (obj.isColor || obj.isEuler || obj.isQuaternion || obj.isSpherical) return inObject;
|
|
15175
|
+
if ("r" in obj && "g" in obj && "b" in obj && typeof obj.r === "number" && typeof obj.g === "number" && typeof obj.b === "number") {
|
|
15176
|
+
const scale = obj.r > 1 || obj.g > 1 || obj.b > 1 ? 1 / 255 : 1;
|
|
15177
|
+
return new webgpu.Color(obj.r * scale, obj.g * scale, obj.b * scale);
|
|
15178
|
+
}
|
|
15925
15179
|
if ("x" in obj && "y" in obj && typeof obj.x === "number" && typeof obj.y === "number") {
|
|
15926
15180
|
if ("w" in obj && typeof obj.w === "number" && "z" in obj && typeof obj.z === "number") {
|
|
15927
15181
|
return new webgpu.Vector4(obj.x, obj.y, obj.z, obj.w);
|
|
@@ -15945,7 +15199,7 @@ function useCompareMemoize(value, deep) {
|
|
|
15945
15199
|
|
|
15946
15200
|
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15947
15201
|
function useUniforms(creatorOrScope, scope) {
|
|
15948
|
-
const store =
|
|
15202
|
+
const store = usePrimaryStore();
|
|
15949
15203
|
const removeUniforms2 = React.useCallback(
|
|
15950
15204
|
(names, targetScope) => {
|
|
15951
15205
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16015,8 +15269,8 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
16015
15269
|
}, [creatorOrScope, store]);
|
|
16016
15270
|
const memoizedInput = useCompareMemoize(inputForMemoization);
|
|
16017
15271
|
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
16018
|
-
const storeUniforms =
|
|
16019
|
-
const hmrVersion =
|
|
15272
|
+
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15273
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16020
15274
|
const readerDep = isReader ? storeUniforms : null;
|
|
16021
15275
|
const creatorDep = isReader ? null : hmrVersion;
|
|
16022
15276
|
const uniforms = React.useMemo(() => {
|
|
@@ -16077,6 +15331,7 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
16077
15331
|
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
16078
15332
|
}
|
|
16079
15333
|
function rebuildAllUniforms(store, scope) {
|
|
15334
|
+
store = store.getState().primaryStore ?? store;
|
|
16080
15335
|
store.setState((state) => {
|
|
16081
15336
|
let newUniforms = {};
|
|
16082
15337
|
if (scope && scope !== "root") {
|
|
@@ -16205,7 +15460,7 @@ function useUniform(name, value) {
|
|
|
16205
15460
|
|
|
16206
15461
|
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
16207
15462
|
function useNodes(creatorOrScope, scope) {
|
|
16208
|
-
const store =
|
|
15463
|
+
const store = usePrimaryStore();
|
|
16209
15464
|
const removeNodes2 = React.useCallback(
|
|
16210
15465
|
(names, targetScope) => {
|
|
16211
15466
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -16262,8 +15517,8 @@ function useNodes(creatorOrScope, scope) {
|
|
|
16262
15517
|
[store]
|
|
16263
15518
|
);
|
|
16264
15519
|
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
16265
|
-
const storeNodes =
|
|
16266
|
-
const hmrVersion =
|
|
15520
|
+
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15521
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16267
15522
|
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
16268
15523
|
const readerDep = isReader ? storeNodes : null;
|
|
16269
15524
|
const creatorDep = isReader ? null : hmrVersion;
|
|
@@ -16322,6 +15577,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
16322
15577
|
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
16323
15578
|
}
|
|
16324
15579
|
function rebuildAllNodes(store, scope) {
|
|
15580
|
+
store = store.getState().primaryStore ?? store;
|
|
16325
15581
|
store.setState((state) => {
|
|
16326
15582
|
let newNodes = state.nodes;
|
|
16327
15583
|
if (scope && scope !== "root") {
|
|
@@ -16366,18 +15622,364 @@ function clearRootNodes(set) {
|
|
|
16366
15622
|
});
|
|
16367
15623
|
}
|
|
16368
15624
|
function useLocalNodes(creator) {
|
|
16369
|
-
const store =
|
|
16370
|
-
const uniforms =
|
|
16371
|
-
const nodes =
|
|
16372
|
-
const textures =
|
|
16373
|
-
const hmrVersion =
|
|
15625
|
+
const store = usePrimaryStore();
|
|
15626
|
+
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15627
|
+
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15628
|
+
const textures = usePrimaryThree((s) => s.textures);
|
|
15629
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
16374
15630
|
return React.useMemo(() => {
|
|
16375
15631
|
const wrappedState = createLazyCreatorState(store.getState());
|
|
16376
15632
|
return creator(wrappedState);
|
|
16377
15633
|
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
16378
15634
|
}
|
|
16379
15635
|
|
|
16380
|
-
|
|
15636
|
+
const isBufferLike = (value) => {
|
|
15637
|
+
if (value === null || typeof value !== "object") return false;
|
|
15638
|
+
if (ArrayBuffer.isView(value)) return true;
|
|
15639
|
+
if ("isBufferAttribute" in value) return true;
|
|
15640
|
+
if ("uuid" in value || "nodeType" in value) return true;
|
|
15641
|
+
return false;
|
|
15642
|
+
};
|
|
15643
|
+
const disposeBuffer = (buffer) => {
|
|
15644
|
+
if (buffer === null || typeof buffer !== "object") return;
|
|
15645
|
+
if ("dispose" in buffer && typeof buffer.dispose === "function") {
|
|
15646
|
+
buffer.dispose();
|
|
15647
|
+
}
|
|
15648
|
+
};
|
|
15649
|
+
function useBuffers(creatorOrScope, scope) {
|
|
15650
|
+
const store = usePrimaryStore();
|
|
15651
|
+
const removeBuffers = React.useCallback(
|
|
15652
|
+
(names, targetScope) => {
|
|
15653
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15654
|
+
store.setState((state) => {
|
|
15655
|
+
if (targetScope) {
|
|
15656
|
+
const currentScope = { ...state.buffers[targetScope] };
|
|
15657
|
+
for (const name of nameArray) delete currentScope[name];
|
|
15658
|
+
return { buffers: { ...state.buffers, [targetScope]: currentScope } };
|
|
15659
|
+
}
|
|
15660
|
+
const buffers2 = { ...state.buffers };
|
|
15661
|
+
for (const name of nameArray) if (isBufferLike(buffers2[name])) delete buffers2[name];
|
|
15662
|
+
return { buffers: buffers2 };
|
|
15663
|
+
});
|
|
15664
|
+
},
|
|
15665
|
+
[store]
|
|
15666
|
+
);
|
|
15667
|
+
const clearBuffers = React.useCallback(
|
|
15668
|
+
(targetScope) => {
|
|
15669
|
+
store.setState((state) => {
|
|
15670
|
+
if (targetScope && targetScope !== "root") {
|
|
15671
|
+
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15672
|
+
return { buffers: rest };
|
|
15673
|
+
}
|
|
15674
|
+
if (targetScope === "root") {
|
|
15675
|
+
const buffers2 = {};
|
|
15676
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15677
|
+
if (!isBufferLike(value)) buffers2[key] = value;
|
|
15678
|
+
}
|
|
15679
|
+
return { buffers: buffers2 };
|
|
15680
|
+
}
|
|
15681
|
+
return { buffers: {} };
|
|
15682
|
+
});
|
|
15683
|
+
},
|
|
15684
|
+
[store]
|
|
15685
|
+
);
|
|
15686
|
+
const rebuildBuffers = React.useCallback(
|
|
15687
|
+
(targetScope) => {
|
|
15688
|
+
store.setState((state) => {
|
|
15689
|
+
let newBuffers = state.buffers;
|
|
15690
|
+
if (targetScope && targetScope !== "root") {
|
|
15691
|
+
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15692
|
+
newBuffers = rest;
|
|
15693
|
+
} else if (targetScope === "root") {
|
|
15694
|
+
newBuffers = {};
|
|
15695
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15696
|
+
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15697
|
+
}
|
|
15698
|
+
} else {
|
|
15699
|
+
newBuffers = {};
|
|
15700
|
+
}
|
|
15701
|
+
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15702
|
+
});
|
|
15703
|
+
},
|
|
15704
|
+
[store]
|
|
15705
|
+
);
|
|
15706
|
+
const disposeBuffers = React.useCallback(
|
|
15707
|
+
(names, targetScope) => {
|
|
15708
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15709
|
+
const state = store.getState();
|
|
15710
|
+
for (const name of nameArray) {
|
|
15711
|
+
const buffer = targetScope ? state.buffers[targetScope]?.[name] : state.buffers[name];
|
|
15712
|
+
if (buffer && isBufferLike(buffer)) {
|
|
15713
|
+
disposeBuffer(buffer);
|
|
15714
|
+
}
|
|
15715
|
+
}
|
|
15716
|
+
removeBuffers(names, targetScope);
|
|
15717
|
+
},
|
|
15718
|
+
[store, removeBuffers]
|
|
15719
|
+
);
|
|
15720
|
+
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15721
|
+
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15722
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15723
|
+
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
15724
|
+
const readerDep = isReader ? storeBuffers : null;
|
|
15725
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15726
|
+
const buffers = React.useMemo(() => {
|
|
15727
|
+
if (creatorOrScope === void 0) {
|
|
15728
|
+
return storeBuffers;
|
|
15729
|
+
}
|
|
15730
|
+
if (typeof creatorOrScope === "string") {
|
|
15731
|
+
const scopeData = storeBuffers[creatorOrScope];
|
|
15732
|
+
if (scopeData && !isBufferLike(scopeData)) return scopeData;
|
|
15733
|
+
return {};
|
|
15734
|
+
}
|
|
15735
|
+
const state = store.getState();
|
|
15736
|
+
const set = store.setState;
|
|
15737
|
+
const creator = creatorOrScope;
|
|
15738
|
+
const wrappedState = createLazyCreatorState(state);
|
|
15739
|
+
const created = creator(wrappedState);
|
|
15740
|
+
const result = {};
|
|
15741
|
+
let hasNewBuffers = false;
|
|
15742
|
+
if (scope) {
|
|
15743
|
+
const currentScope = state.buffers[scope] ?? {};
|
|
15744
|
+
for (const [name, buffer] of Object.entries(created)) {
|
|
15745
|
+
if (currentScope[name]) {
|
|
15746
|
+
result[name] = currentScope[name];
|
|
15747
|
+
} else {
|
|
15748
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15749
|
+
buffer.setName(`${scope}.${name}`);
|
|
15750
|
+
}
|
|
15751
|
+
result[name] = buffer;
|
|
15752
|
+
hasNewBuffers = true;
|
|
15753
|
+
}
|
|
15754
|
+
}
|
|
15755
|
+
if (hasNewBuffers) {
|
|
15756
|
+
set((s) => ({
|
|
15757
|
+
buffers: {
|
|
15758
|
+
...s.buffers,
|
|
15759
|
+
[scope]: { ...s.buffers[scope], ...result }
|
|
15760
|
+
}
|
|
15761
|
+
}));
|
|
15762
|
+
}
|
|
15763
|
+
return result;
|
|
15764
|
+
}
|
|
15765
|
+
for (const [name, buffer] of Object.entries(created)) {
|
|
15766
|
+
const existing = state.buffers[name];
|
|
15767
|
+
if (existing && isBufferLike(existing)) {
|
|
15768
|
+
result[name] = existing;
|
|
15769
|
+
} else {
|
|
15770
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15771
|
+
buffer.setName(name);
|
|
15772
|
+
}
|
|
15773
|
+
result[name] = buffer;
|
|
15774
|
+
hasNewBuffers = true;
|
|
15775
|
+
}
|
|
15776
|
+
}
|
|
15777
|
+
if (hasNewBuffers) {
|
|
15778
|
+
set((s) => ({ buffers: { ...s.buffers, ...result } }));
|
|
15779
|
+
}
|
|
15780
|
+
return result;
|
|
15781
|
+
}, [store, scopeDep, readerDep, creatorDep]);
|
|
15782
|
+
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
15783
|
+
}
|
|
15784
|
+
function rebuildAllBuffers(store, scope) {
|
|
15785
|
+
store = store.getState().primaryStore ?? store;
|
|
15786
|
+
store.setState((state) => {
|
|
15787
|
+
let newBuffers = state.buffers;
|
|
15788
|
+
if (scope && scope !== "root") {
|
|
15789
|
+
const { [scope]: _, ...rest } = state.buffers;
|
|
15790
|
+
newBuffers = rest;
|
|
15791
|
+
} else if (scope === "root") {
|
|
15792
|
+
newBuffers = {};
|
|
15793
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15794
|
+
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15795
|
+
}
|
|
15796
|
+
} else {
|
|
15797
|
+
newBuffers = {};
|
|
15798
|
+
}
|
|
15799
|
+
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15800
|
+
});
|
|
15801
|
+
}
|
|
15802
|
+
|
|
15803
|
+
const isStorageLike = (value) => {
|
|
15804
|
+
if (value === null || typeof value !== "object") return false;
|
|
15805
|
+
if ("isTexture" in value) return true;
|
|
15806
|
+
if ("isData3DTexture" in value) return true;
|
|
15807
|
+
if ("uuid" in value || "nodeType" in value) return true;
|
|
15808
|
+
return false;
|
|
15809
|
+
};
|
|
15810
|
+
const disposeStorage = (storage) => {
|
|
15811
|
+
if (storage === null || typeof storage !== "object") return;
|
|
15812
|
+
if ("dispose" in storage && typeof storage.dispose === "function") {
|
|
15813
|
+
storage.dispose();
|
|
15814
|
+
}
|
|
15815
|
+
};
|
|
15816
|
+
function useGPUStorage(creatorOrScope, scope) {
|
|
15817
|
+
const store = usePrimaryStore();
|
|
15818
|
+
const removeStorage = React.useCallback(
|
|
15819
|
+
(names, targetScope) => {
|
|
15820
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15821
|
+
store.setState((state) => {
|
|
15822
|
+
if (targetScope) {
|
|
15823
|
+
const currentScope = { ...state.gpuStorage[targetScope] };
|
|
15824
|
+
for (const name of nameArray) delete currentScope[name];
|
|
15825
|
+
return { gpuStorage: { ...state.gpuStorage, [targetScope]: currentScope } };
|
|
15826
|
+
}
|
|
15827
|
+
const gpuStorage2 = { ...state.gpuStorage };
|
|
15828
|
+
for (const name of nameArray) if (isStorageLike(gpuStorage2[name])) delete gpuStorage2[name];
|
|
15829
|
+
return { gpuStorage: gpuStorage2 };
|
|
15830
|
+
});
|
|
15831
|
+
},
|
|
15832
|
+
[store]
|
|
15833
|
+
);
|
|
15834
|
+
const clearStorage = React.useCallback(
|
|
15835
|
+
(targetScope) => {
|
|
15836
|
+
store.setState((state) => {
|
|
15837
|
+
if (targetScope && targetScope !== "root") {
|
|
15838
|
+
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15839
|
+
return { gpuStorage: rest };
|
|
15840
|
+
}
|
|
15841
|
+
if (targetScope === "root") {
|
|
15842
|
+
const gpuStorage2 = {};
|
|
15843
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15844
|
+
if (!isStorageLike(value)) gpuStorage2[key] = value;
|
|
15845
|
+
}
|
|
15846
|
+
return { gpuStorage: gpuStorage2 };
|
|
15847
|
+
}
|
|
15848
|
+
return { gpuStorage: {} };
|
|
15849
|
+
});
|
|
15850
|
+
},
|
|
15851
|
+
[store]
|
|
15852
|
+
);
|
|
15853
|
+
const rebuildStorage = React.useCallback(
|
|
15854
|
+
(targetScope) => {
|
|
15855
|
+
store.setState((state) => {
|
|
15856
|
+
let newStorage = state.gpuStorage;
|
|
15857
|
+
if (targetScope && targetScope !== "root") {
|
|
15858
|
+
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15859
|
+
newStorage = rest;
|
|
15860
|
+
} else if (targetScope === "root") {
|
|
15861
|
+
newStorage = {};
|
|
15862
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15863
|
+
if (!isStorageLike(value)) newStorage[key] = value;
|
|
15864
|
+
}
|
|
15865
|
+
} else {
|
|
15866
|
+
newStorage = {};
|
|
15867
|
+
}
|
|
15868
|
+
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
15869
|
+
});
|
|
15870
|
+
},
|
|
15871
|
+
[store]
|
|
15872
|
+
);
|
|
15873
|
+
const disposeStorageFn = React.useCallback(
|
|
15874
|
+
(names, targetScope) => {
|
|
15875
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15876
|
+
const state = store.getState();
|
|
15877
|
+
for (const name of nameArray) {
|
|
15878
|
+
const storage = targetScope ? state.gpuStorage[targetScope]?.[name] : state.gpuStorage[name];
|
|
15879
|
+
if (storage && isStorageLike(storage)) {
|
|
15880
|
+
disposeStorage(storage);
|
|
15881
|
+
}
|
|
15882
|
+
}
|
|
15883
|
+
removeStorage(names, targetScope);
|
|
15884
|
+
},
|
|
15885
|
+
[store, removeStorage]
|
|
15886
|
+
);
|
|
15887
|
+
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15888
|
+
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
15889
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15890
|
+
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
15891
|
+
const readerDep = isReader ? storeStorage : null;
|
|
15892
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15893
|
+
const gpuStorage = React.useMemo(() => {
|
|
15894
|
+
if (creatorOrScope === void 0) {
|
|
15895
|
+
return storeStorage;
|
|
15896
|
+
}
|
|
15897
|
+
if (typeof creatorOrScope === "string") {
|
|
15898
|
+
const scopeData = storeStorage[creatorOrScope];
|
|
15899
|
+
if (scopeData && !isStorageLike(scopeData)) return scopeData;
|
|
15900
|
+
return {};
|
|
15901
|
+
}
|
|
15902
|
+
const state = store.getState();
|
|
15903
|
+
const set = store.setState;
|
|
15904
|
+
const creator = creatorOrScope;
|
|
15905
|
+
const wrappedState = createLazyCreatorState(state);
|
|
15906
|
+
const created = creator(wrappedState);
|
|
15907
|
+
const result = {};
|
|
15908
|
+
let hasNewStorage = false;
|
|
15909
|
+
if (scope) {
|
|
15910
|
+
const currentScope = state.gpuStorage[scope] ?? {};
|
|
15911
|
+
for (const [name, storage] of Object.entries(created)) {
|
|
15912
|
+
if (currentScope[name]) {
|
|
15913
|
+
result[name] = currentScope[name];
|
|
15914
|
+
} else {
|
|
15915
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15916
|
+
storage.setName(`${scope}.${name}`);
|
|
15917
|
+
}
|
|
15918
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
15919
|
+
storage.name = `${scope}.${name}`;
|
|
15920
|
+
}
|
|
15921
|
+
result[name] = storage;
|
|
15922
|
+
hasNewStorage = true;
|
|
15923
|
+
}
|
|
15924
|
+
}
|
|
15925
|
+
if (hasNewStorage) {
|
|
15926
|
+
set((s) => ({
|
|
15927
|
+
gpuStorage: {
|
|
15928
|
+
...s.gpuStorage,
|
|
15929
|
+
[scope]: { ...s.gpuStorage[scope], ...result }
|
|
15930
|
+
}
|
|
15931
|
+
}));
|
|
15932
|
+
}
|
|
15933
|
+
return result;
|
|
15934
|
+
}
|
|
15935
|
+
for (const [name, storage] of Object.entries(created)) {
|
|
15936
|
+
const existing = state.gpuStorage[name];
|
|
15937
|
+
if (existing && isStorageLike(existing)) {
|
|
15938
|
+
result[name] = existing;
|
|
15939
|
+
} else {
|
|
15940
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15941
|
+
storage.setName(name);
|
|
15942
|
+
}
|
|
15943
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
15944
|
+
storage.name = name;
|
|
15945
|
+
}
|
|
15946
|
+
result[name] = storage;
|
|
15947
|
+
hasNewStorage = true;
|
|
15948
|
+
}
|
|
15949
|
+
}
|
|
15950
|
+
if (hasNewStorage) {
|
|
15951
|
+
set((s) => ({ gpuStorage: { ...s.gpuStorage, ...result } }));
|
|
15952
|
+
}
|
|
15953
|
+
return result;
|
|
15954
|
+
}, [store, scopeDep, readerDep, creatorDep]);
|
|
15955
|
+
return {
|
|
15956
|
+
...gpuStorage,
|
|
15957
|
+
removeStorage,
|
|
15958
|
+
clearStorage,
|
|
15959
|
+
rebuildStorage,
|
|
15960
|
+
disposeStorage: disposeStorageFn
|
|
15961
|
+
};
|
|
15962
|
+
}
|
|
15963
|
+
function rebuildAllStorage(store, scope) {
|
|
15964
|
+
store = store.getState().primaryStore ?? store;
|
|
15965
|
+
store.setState((state) => {
|
|
15966
|
+
let newStorage = state.gpuStorage;
|
|
15967
|
+
if (scope && scope !== "root") {
|
|
15968
|
+
const { [scope]: _, ...rest } = state.gpuStorage;
|
|
15969
|
+
newStorage = rest;
|
|
15970
|
+
} else if (scope === "root") {
|
|
15971
|
+
newStorage = {};
|
|
15972
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15973
|
+
if (!isStorageLike(value)) newStorage[key] = value;
|
|
15974
|
+
}
|
|
15975
|
+
} else {
|
|
15976
|
+
newStorage = {};
|
|
15977
|
+
}
|
|
15978
|
+
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
15979
|
+
});
|
|
15980
|
+
}
|
|
15981
|
+
|
|
15982
|
+
function useRenderPipeline(mainCB, setupCB) {
|
|
16381
15983
|
const store = useStore();
|
|
16382
15984
|
const { scene, camera, renderer, isLegacy } = useThree();
|
|
16383
15985
|
const callbacksRanRef = React.useRef(false);
|
|
@@ -16396,7 +15998,7 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
16396
15998
|
}, [store]);
|
|
16397
15999
|
const reset = React.useCallback(() => {
|
|
16398
16000
|
store.setState({
|
|
16399
|
-
|
|
16001
|
+
renderPipeline: null,
|
|
16400
16002
|
passes: {}
|
|
16401
16003
|
});
|
|
16402
16004
|
callbacksRanRef.current = false;
|
|
@@ -16409,13 +16011,13 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
16409
16011
|
}, []);
|
|
16410
16012
|
React.useLayoutEffect(() => {
|
|
16411
16013
|
if (isLegacy) {
|
|
16412
|
-
throw new Error("
|
|
16014
|
+
throw new Error("useRenderPipeline is only available with WebGPU renderer. Set renderer prop on Canvas.");
|
|
16413
16015
|
}
|
|
16414
16016
|
if (!renderer || !scene || !camera) return;
|
|
16415
16017
|
const state = store.getState();
|
|
16416
16018
|
const set = store.setState;
|
|
16417
16019
|
try {
|
|
16418
|
-
let pp = state.
|
|
16020
|
+
let pp = state.renderPipeline;
|
|
16419
16021
|
let currentPasses = { ...state.passes };
|
|
16420
16022
|
let justCreatedPP = false;
|
|
16421
16023
|
if (!pp) {
|
|
@@ -16432,7 +16034,7 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
16432
16034
|
}
|
|
16433
16035
|
currentPasses.scenePass = scenePass;
|
|
16434
16036
|
if (!pp.outputNode || justCreatedPP) pp.outputNode = scenePass;
|
|
16435
|
-
set({
|
|
16037
|
+
set({ renderPipeline: pp, passes: currentPasses });
|
|
16436
16038
|
const shouldRunCallbacks = justCreatedPP || !callbacksRanRef.current || !cacheValid;
|
|
16437
16039
|
if (shouldRunCallbacks) {
|
|
16438
16040
|
if (setupCBRef.current) {
|
|
@@ -16454,24 +16056,26 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
16454
16056
|
callbacksRanRef.current = true;
|
|
16455
16057
|
}
|
|
16456
16058
|
} catch (error) {
|
|
16457
|
-
console.error("[
|
|
16059
|
+
console.error("[useRenderPipeline] Setup error:", error);
|
|
16458
16060
|
}
|
|
16459
16061
|
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
16460
16062
|
const passes = useThree((s) => s.passes);
|
|
16461
|
-
const
|
|
16063
|
+
const renderPipeline = useThree((s) => s.renderPipeline);
|
|
16462
16064
|
return {
|
|
16463
16065
|
passes,
|
|
16464
|
-
|
|
16066
|
+
renderPipeline,
|
|
16465
16067
|
clearPasses,
|
|
16466
16068
|
reset,
|
|
16467
16069
|
rebuild,
|
|
16468
|
-
// isReady indicates if
|
|
16469
|
-
isReady:
|
|
16070
|
+
// isReady indicates if RenderPipeline is configured and ready for rendering
|
|
16071
|
+
isReady: renderPipeline !== null
|
|
16470
16072
|
};
|
|
16471
16073
|
}
|
|
16472
16074
|
|
|
16473
16075
|
extend(THREE);
|
|
16474
16076
|
|
|
16077
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
16078
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
16475
16079
|
exports.Block = Block;
|
|
16476
16080
|
exports.Canvas = Canvas;
|
|
16477
16081
|
exports.Environment = Environment;
|
|
@@ -16487,7 +16091,6 @@ exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
|
16487
16091
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
16488
16092
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
16489
16093
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
16490
|
-
exports.Scheduler = Scheduler;
|
|
16491
16094
|
exports.Texture = Texture;
|
|
16492
16095
|
exports._roots = _roots;
|
|
16493
16096
|
exports.act = act;
|
|
@@ -16523,7 +16126,6 @@ exports.getInstanceProps = getInstanceProps;
|
|
|
16523
16126
|
exports.getPrimary = getPrimary;
|
|
16524
16127
|
exports.getPrimaryIds = getPrimaryIds;
|
|
16525
16128
|
exports.getRootState = getRootState;
|
|
16526
|
-
exports.getScheduler = getScheduler;
|
|
16527
16129
|
exports.getUuidPrefix = getUuidPrefix;
|
|
16528
16130
|
exports.hasConstructor = hasConstructor;
|
|
16529
16131
|
exports.hasPrimary = hasPrimary;
|
|
@@ -16543,7 +16145,9 @@ exports.isVectorLike = isVectorLike;
|
|
|
16543
16145
|
exports.once = once;
|
|
16544
16146
|
exports.prepare = prepare;
|
|
16545
16147
|
exports.presetsObj = presetsObj;
|
|
16148
|
+
exports.rebuildAllBuffers = rebuildAllBuffers;
|
|
16546
16149
|
exports.rebuildAllNodes = rebuildAllNodes;
|
|
16150
|
+
exports.rebuildAllStorage = rebuildAllStorage;
|
|
16547
16151
|
exports.rebuildAllUniforms = rebuildAllUniforms;
|
|
16548
16152
|
exports.reconciler = reconciler;
|
|
16549
16153
|
exports.registerPrimary = registerPrimary;
|
|
@@ -16556,8 +16160,10 @@ exports.unregisterPrimary = unregisterPrimary;
|
|
|
16556
16160
|
exports.updateCamera = updateCamera;
|
|
16557
16161
|
exports.updateFrustum = updateFrustum;
|
|
16558
16162
|
exports.useBridge = useBridge;
|
|
16163
|
+
exports.useBuffers = useBuffers;
|
|
16559
16164
|
exports.useEnvironment = useEnvironment;
|
|
16560
16165
|
exports.useFrame = useFrame;
|
|
16166
|
+
exports.useGPUStorage = useGPUStorage;
|
|
16561
16167
|
exports.useGraph = useGraph;
|
|
16562
16168
|
exports.useInstanceHandle = useInstanceHandle;
|
|
16563
16169
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
@@ -16565,7 +16171,7 @@ exports.useLoader = useLoader;
|
|
|
16565
16171
|
exports.useLocalNodes = useLocalNodes;
|
|
16566
16172
|
exports.useMutableCallback = useMutableCallback;
|
|
16567
16173
|
exports.useNodes = useNodes;
|
|
16568
|
-
exports.
|
|
16174
|
+
exports.useRenderPipeline = useRenderPipeline;
|
|
16569
16175
|
exports.useRenderTarget = useRenderTarget;
|
|
16570
16176
|
exports.useStore = useStore;
|
|
16571
16177
|
exports.useTexture = useTexture;
|