@react-three/fiber 10.0.0-alpha.1 → 10.0.0-canary.0706a92
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/LICENSE +21 -21
- package/dist/index.cjs +1364 -1446
- package/dist/index.d.cts +1888 -1702
- package/dist/index.d.mts +1888 -1702
- package/dist/index.d.ts +1888 -1702
- package/dist/index.mjs +1324 -1425
- package/dist/legacy.cjs +1321 -1428
- package/dist/legacy.d.cts +1889 -1703
- package/dist/legacy.d.mts +1889 -1703
- package/dist/legacy.d.ts +1889 -1703
- package/dist/legacy.mjs +1281 -1407
- package/dist/webgpu/index.cjs +2046 -1497
- package/dist/webgpu/index.d.cts +2163 -1725
- package/dist/webgpu/index.d.mts +2163 -1725
- package/dist/webgpu/index.d.ts +2163 -1725
- package/dist/webgpu/index.mjs +1999 -1476
- package/package.json +8 -5
- package/react-reconciler/constants.js +1 -9
- package/react-reconciler/index.js +4 -20
- package/readme.md +244 -318
package/dist/webgpu/index.cjs
CHANGED
|
@@ -6,13 +6,21 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
const React = require('react');
|
|
7
7
|
const useMeasure = require('react-use-measure');
|
|
8
8
|
const itsFine = require('its-fine');
|
|
9
|
+
const fiber = require('@react-three/fiber');
|
|
10
|
+
const GroundedSkybox_js = require('three/examples/jsm/objects/GroundedSkybox.js');
|
|
11
|
+
const HDRLoader_js = require('three/examples/jsm/loaders/HDRLoader.js');
|
|
12
|
+
const EXRLoader_js = require('three/examples/jsm/loaders/EXRLoader.js');
|
|
13
|
+
const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js');
|
|
14
|
+
const gainmapJs = require('@monogrid/gainmap-js');
|
|
9
15
|
const Tb = require('scheduler');
|
|
10
16
|
const traditional = require('zustand/traditional');
|
|
17
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
11
18
|
const suspendReact = require('suspend-react');
|
|
12
19
|
const lite = require('dequal/lite');
|
|
13
20
|
require('zustand/shallow');
|
|
14
21
|
const tsl = require('three/tsl');
|
|
15
22
|
|
|
23
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
24
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
17
25
|
|
|
18
26
|
function _interopNamespaceCompat(e) {
|
|
@@ -66,9 +74,392 @@ const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
|
66
74
|
WebGLRenderer: WebGLRenderer
|
|
67
75
|
}, [webgpu__namespace]);
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const primaryRegistry = /* @__PURE__ */ new Map();
|
|
78
|
+
const pendingSubscribers = /* @__PURE__ */ new Map();
|
|
79
|
+
function registerPrimary(id, renderer, store) {
|
|
80
|
+
if (primaryRegistry.has(id)) {
|
|
81
|
+
console.warn(`Canvas with id="${id}" already registered. Overwriting.`);
|
|
82
|
+
}
|
|
83
|
+
const entry = { renderer, store };
|
|
84
|
+
primaryRegistry.set(id, entry);
|
|
85
|
+
const subscribers = pendingSubscribers.get(id);
|
|
86
|
+
if (subscribers) {
|
|
87
|
+
subscribers.forEach((callback) => callback(entry));
|
|
88
|
+
pendingSubscribers.delete(id);
|
|
89
|
+
}
|
|
90
|
+
return () => {
|
|
91
|
+
const currentEntry = primaryRegistry.get(id);
|
|
92
|
+
if (currentEntry?.renderer === renderer) {
|
|
93
|
+
primaryRegistry.delete(id);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getPrimary(id) {
|
|
98
|
+
return primaryRegistry.get(id);
|
|
99
|
+
}
|
|
100
|
+
function waitForPrimary(id, timeout = 5e3) {
|
|
101
|
+
const existing = primaryRegistry.get(id);
|
|
102
|
+
if (existing) {
|
|
103
|
+
return Promise.resolve(existing);
|
|
104
|
+
}
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
const timeoutId = setTimeout(() => {
|
|
107
|
+
const subscribers = pendingSubscribers.get(id);
|
|
108
|
+
if (subscribers) {
|
|
109
|
+
const index = subscribers.indexOf(callback);
|
|
110
|
+
if (index !== -1) subscribers.splice(index, 1);
|
|
111
|
+
if (subscribers.length === 0) pendingSubscribers.delete(id);
|
|
112
|
+
}
|
|
113
|
+
reject(new Error(`Timeout waiting for canvas with id="${id}". Make sure a <Canvas id="${id}"> is mounted.`));
|
|
114
|
+
}, timeout);
|
|
115
|
+
const callback = (entry) => {
|
|
116
|
+
clearTimeout(timeoutId);
|
|
117
|
+
resolve(entry);
|
|
118
|
+
};
|
|
119
|
+
if (!pendingSubscribers.has(id)) {
|
|
120
|
+
pendingSubscribers.set(id, []);
|
|
121
|
+
}
|
|
122
|
+
pendingSubscribers.get(id).push(callback);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function hasPrimary(id) {
|
|
126
|
+
return primaryRegistry.has(id);
|
|
127
|
+
}
|
|
128
|
+
function unregisterPrimary(id) {
|
|
129
|
+
primaryRegistry.delete(id);
|
|
130
|
+
}
|
|
131
|
+
function getPrimaryIds() {
|
|
132
|
+
return Array.from(primaryRegistry.keys());
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const presetsObj = {
|
|
136
|
+
apartment: "lebombo_1k.hdr",
|
|
137
|
+
city: "potsdamer_platz_1k.hdr",
|
|
138
|
+
dawn: "kiara_1_dawn_1k.hdr",
|
|
139
|
+
forest: "forest_slope_1k.hdr",
|
|
140
|
+
lobby: "st_fagans_interior_1k.hdr",
|
|
141
|
+
night: "dikhololo_night_1k.hdr",
|
|
142
|
+
park: "rooitou_park_1k.hdr",
|
|
143
|
+
studio: "studio_small_03_1k.hdr",
|
|
144
|
+
sunset: "venice_sunset_1k.hdr",
|
|
145
|
+
warehouse: "empty_warehouse_01_1k.hdr"
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const CUBEMAP_ROOT = "https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/";
|
|
149
|
+
const isArray = (arr) => Array.isArray(arr);
|
|
150
|
+
const defaultFiles = ["/px.png", "/nx.png", "/py.png", "/ny.png", "/pz.png", "/nz.png"];
|
|
151
|
+
function useEnvironment({
|
|
152
|
+
files = defaultFiles,
|
|
153
|
+
path = "",
|
|
154
|
+
preset = void 0,
|
|
155
|
+
colorSpace = void 0,
|
|
156
|
+
extensions
|
|
157
|
+
} = {}) {
|
|
158
|
+
if (preset) {
|
|
159
|
+
validatePreset(preset);
|
|
160
|
+
files = presetsObj[preset];
|
|
161
|
+
path = CUBEMAP_ROOT;
|
|
162
|
+
}
|
|
163
|
+
const multiFile = isArray(files);
|
|
164
|
+
const { extension, isCubemap } = getExtension(files);
|
|
165
|
+
const loader = getLoader$1(extension);
|
|
166
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
167
|
+
const renderer = fiber.useThree((state) => state.renderer);
|
|
168
|
+
React.useLayoutEffect(() => {
|
|
169
|
+
if (extension !== "webp" && extension !== "jpg" && extension !== "jpeg") return;
|
|
170
|
+
function clearGainmapTexture() {
|
|
171
|
+
fiber.useLoader.clear(loader, multiFile ? [files] : files);
|
|
172
|
+
}
|
|
173
|
+
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
174
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
175
|
+
const loaderResult = fiber.useLoader(
|
|
176
|
+
loader,
|
|
177
|
+
multiFile ? [files] : files,
|
|
178
|
+
(loader2) => {
|
|
179
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
180
|
+
loader2.setRenderer?.(renderer);
|
|
181
|
+
}
|
|
182
|
+
loader2.setPath?.(path);
|
|
183
|
+
if (extensions) extensions(loader2);
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
let texture = multiFile ? (
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
loaderResult[0]
|
|
189
|
+
) : loaderResult;
|
|
190
|
+
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
191
|
+
texture = texture.renderTarget?.texture;
|
|
192
|
+
}
|
|
193
|
+
texture.mapping = isCubemap ? webgpu.CubeReflectionMapping : webgpu.EquirectangularReflectionMapping;
|
|
194
|
+
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
195
|
+
return texture;
|
|
196
|
+
}
|
|
197
|
+
const preloadDefaultOptions = {
|
|
198
|
+
files: defaultFiles,
|
|
199
|
+
path: "",
|
|
200
|
+
preset: void 0,
|
|
201
|
+
extensions: void 0
|
|
202
|
+
};
|
|
203
|
+
useEnvironment.preload = (preloadOptions) => {
|
|
204
|
+
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
205
|
+
let { files, path = "" } = options;
|
|
206
|
+
const { preset, extensions } = options;
|
|
207
|
+
if (preset) {
|
|
208
|
+
validatePreset(preset);
|
|
209
|
+
files = presetsObj[preset];
|
|
210
|
+
path = CUBEMAP_ROOT;
|
|
211
|
+
}
|
|
212
|
+
const { extension } = getExtension(files);
|
|
213
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
214
|
+
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
215
|
+
}
|
|
216
|
+
const loader = getLoader$1(extension);
|
|
217
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
218
|
+
fiber.useLoader.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
219
|
+
loader2.setPath?.(path);
|
|
220
|
+
if (extensions) extensions(loader2);
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
const clearDefaultOptins = {
|
|
224
|
+
files: defaultFiles,
|
|
225
|
+
preset: void 0
|
|
226
|
+
};
|
|
227
|
+
useEnvironment.clear = (clearOptions) => {
|
|
228
|
+
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
229
|
+
let { files } = options;
|
|
230
|
+
const { preset } = options;
|
|
231
|
+
if (preset) {
|
|
232
|
+
validatePreset(preset);
|
|
233
|
+
files = presetsObj[preset];
|
|
234
|
+
}
|
|
235
|
+
const { extension } = getExtension(files);
|
|
236
|
+
const loader = getLoader$1(extension);
|
|
237
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
238
|
+
fiber.useLoader.clear(loader, isArray(files) ? [files] : files);
|
|
239
|
+
};
|
|
240
|
+
function validatePreset(preset) {
|
|
241
|
+
if (!(preset in presetsObj)) throw new Error("Preset must be one of: " + Object.keys(presetsObj).join(", "));
|
|
242
|
+
}
|
|
243
|
+
function getExtension(files) {
|
|
244
|
+
const isCubemap = isArray(files) && files.length === 6;
|
|
245
|
+
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
246
|
+
const firstEntry = isArray(files) ? files[0] : files;
|
|
247
|
+
const extension = isCubemap ? "cube" : isGainmap ? "webp" : firstEntry.startsWith("data:application/exr") ? "exr" : firstEntry.startsWith("data:application/hdr") ? "hdr" : firstEntry.startsWith("data:image/jpeg") ? "jpg" : firstEntry.split(".").pop()?.split("?")?.shift()?.toLowerCase();
|
|
248
|
+
return { extension, isCubemap, isGainmap };
|
|
249
|
+
}
|
|
250
|
+
function getLoader$1(extension) {
|
|
251
|
+
const loader = extension === "cube" ? webgpu.CubeTextureLoader : extension === "hdr" ? HDRLoader_js.HDRLoader : extension === "exr" ? EXRLoader_js.EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader_js.UltraHDRLoader : extension === "webp" ? gainmapJs.GainMapLoader : null;
|
|
252
|
+
return loader;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const isRef$1 = (obj) => obj.current && obj.current.isScene;
|
|
256
|
+
const resolveScene = (scene) => isRef$1(scene) ? scene.current : scene;
|
|
257
|
+
function setEnvProps(background, scene, defaultScene, texture, sceneProps = {}) {
|
|
258
|
+
sceneProps = {
|
|
259
|
+
backgroundBlurriness: 0,
|
|
260
|
+
backgroundIntensity: 1,
|
|
261
|
+
backgroundRotation: [0, 0, 0],
|
|
262
|
+
environmentIntensity: 1,
|
|
263
|
+
environmentRotation: [0, 0, 0],
|
|
264
|
+
...sceneProps
|
|
265
|
+
};
|
|
266
|
+
const target = resolveScene(scene || defaultScene);
|
|
267
|
+
const oldbg = target.background;
|
|
268
|
+
const oldenv = target.environment;
|
|
269
|
+
const oldSceneProps = {
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
backgroundBlurriness: target.backgroundBlurriness,
|
|
272
|
+
// @ts-ignore
|
|
273
|
+
backgroundIntensity: target.backgroundIntensity,
|
|
274
|
+
// @ts-ignore
|
|
275
|
+
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
environmentIntensity: target.environmentIntensity,
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
280
|
+
};
|
|
281
|
+
if (background !== "only") target.environment = texture;
|
|
282
|
+
if (background) target.background = texture;
|
|
283
|
+
fiber.applyProps(target, sceneProps);
|
|
284
|
+
return () => {
|
|
285
|
+
if (background !== "only") target.environment = oldenv;
|
|
286
|
+
if (background) target.background = oldbg;
|
|
287
|
+
fiber.applyProps(target, oldSceneProps);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
291
|
+
const defaultScene = fiber.useThree((state) => state.scene);
|
|
292
|
+
React__namespace.useLayoutEffect(() => {
|
|
293
|
+
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
294
|
+
});
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
function EnvironmentCube({
|
|
298
|
+
background = false,
|
|
299
|
+
scene,
|
|
300
|
+
blur,
|
|
301
|
+
backgroundBlurriness,
|
|
302
|
+
backgroundIntensity,
|
|
303
|
+
backgroundRotation,
|
|
304
|
+
environmentIntensity,
|
|
305
|
+
environmentRotation,
|
|
306
|
+
...rest
|
|
307
|
+
}) {
|
|
308
|
+
const texture = useEnvironment(rest);
|
|
309
|
+
const defaultScene = fiber.useThree((state) => state.scene);
|
|
310
|
+
React__namespace.useLayoutEffect(() => {
|
|
311
|
+
return setEnvProps(background, scene, defaultScene, texture, {
|
|
312
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
313
|
+
backgroundIntensity,
|
|
314
|
+
backgroundRotation,
|
|
315
|
+
environmentIntensity,
|
|
316
|
+
environmentRotation
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
React__namespace.useEffect(() => {
|
|
320
|
+
return () => {
|
|
321
|
+
texture.dispose();
|
|
322
|
+
};
|
|
323
|
+
}, [texture]);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
function EnvironmentPortal({
|
|
327
|
+
children,
|
|
328
|
+
near = 0.1,
|
|
329
|
+
far = 1e3,
|
|
330
|
+
resolution = 256,
|
|
331
|
+
frames = 1,
|
|
332
|
+
map,
|
|
333
|
+
background = false,
|
|
334
|
+
blur,
|
|
335
|
+
backgroundBlurriness,
|
|
336
|
+
backgroundIntensity,
|
|
337
|
+
backgroundRotation,
|
|
338
|
+
environmentIntensity,
|
|
339
|
+
environmentRotation,
|
|
340
|
+
scene,
|
|
341
|
+
files,
|
|
342
|
+
path,
|
|
343
|
+
preset = void 0,
|
|
344
|
+
extensions
|
|
345
|
+
}) {
|
|
346
|
+
const gl = fiber.useThree((state) => state.gl);
|
|
347
|
+
const defaultScene = fiber.useThree((state) => state.scene);
|
|
348
|
+
const camera = React__namespace.useRef(null);
|
|
349
|
+
const [virtualScene] = React__namespace.useState(() => new webgpu.Scene());
|
|
350
|
+
const fbo = React__namespace.useMemo(() => {
|
|
351
|
+
const fbo2 = new webgpu.WebGLCubeRenderTarget(resolution);
|
|
352
|
+
fbo2.texture.type = webgpu.HalfFloatType;
|
|
353
|
+
return fbo2;
|
|
354
|
+
}, [resolution]);
|
|
355
|
+
React__namespace.useEffect(() => {
|
|
356
|
+
return () => {
|
|
357
|
+
fbo.dispose();
|
|
358
|
+
};
|
|
359
|
+
}, [fbo]);
|
|
360
|
+
React__namespace.useLayoutEffect(() => {
|
|
361
|
+
if (frames === 1) {
|
|
362
|
+
const autoClear = gl.autoClear;
|
|
363
|
+
gl.autoClear = true;
|
|
364
|
+
camera.current.update(gl, virtualScene);
|
|
365
|
+
gl.autoClear = autoClear;
|
|
366
|
+
}
|
|
367
|
+
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
368
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
369
|
+
backgroundIntensity,
|
|
370
|
+
backgroundRotation,
|
|
371
|
+
environmentIntensity,
|
|
372
|
+
environmentRotation
|
|
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
|
+
]);
|
|
390
|
+
let count = 1;
|
|
391
|
+
fiber.useFrame(() => {
|
|
392
|
+
if (frames === Infinity || count < frames) {
|
|
393
|
+
const autoClear = gl.autoClear;
|
|
394
|
+
gl.autoClear = true;
|
|
395
|
+
camera.current.update(gl, virtualScene);
|
|
396
|
+
gl.autoClear = autoClear;
|
|
397
|
+
count++;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(
|
|
401
|
+
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
402
|
+
children,
|
|
403
|
+
/* @__PURE__ */ jsxRuntime.jsx("cubeCamera", { ref: camera, args: [near, far, fbo] }),
|
|
404
|
+
files || preset ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { background: true, files, preset, path, extensions }) : map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { background: true, map, extensions }) : null
|
|
405
|
+
] }),
|
|
406
|
+
virtualScene
|
|
407
|
+
) });
|
|
408
|
+
}
|
|
409
|
+
function EnvironmentGround(props) {
|
|
410
|
+
const textureDefault = useEnvironment(props);
|
|
411
|
+
const texture = props.map || textureDefault;
|
|
412
|
+
React__namespace.useMemo(() => fiber.extend({ GroundProjectedEnvImpl: GroundedSkybox_js.GroundedSkybox }), []);
|
|
413
|
+
React__namespace.useEffect(() => {
|
|
414
|
+
return () => {
|
|
415
|
+
textureDefault.dispose();
|
|
416
|
+
};
|
|
417
|
+
}, [textureDefault]);
|
|
418
|
+
const height = props.ground?.height ?? 15;
|
|
419
|
+
const radius = props.ground?.radius ?? 60;
|
|
420
|
+
const scale = props.ground?.scale ?? 1e3;
|
|
421
|
+
const args = React__namespace.useMemo(
|
|
422
|
+
() => [texture, height, radius],
|
|
423
|
+
[texture, height, radius]
|
|
424
|
+
);
|
|
425
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
426
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props, map: texture }),
|
|
427
|
+
/* @__PURE__ */ jsxRuntime.jsx("groundProjectedEnvImpl", { args, scale })
|
|
428
|
+
] });
|
|
429
|
+
}
|
|
430
|
+
function EnvironmentColor({ color, scene }) {
|
|
431
|
+
const defaultScene = fiber.useThree((state) => state.scene);
|
|
432
|
+
React__namespace.useLayoutEffect(() => {
|
|
433
|
+
if (color === void 0) return;
|
|
434
|
+
const target = resolveScene(scene || defaultScene);
|
|
435
|
+
const oldBg = target.background;
|
|
436
|
+
target.background = new webgpu.Color(color);
|
|
437
|
+
return () => {
|
|
438
|
+
target.background = oldBg;
|
|
439
|
+
};
|
|
440
|
+
});
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
function EnvironmentDualSource(props) {
|
|
444
|
+
const { backgroundFiles, ...envProps } = props;
|
|
445
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
446
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...envProps, background: false }),
|
|
447
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props, files: backgroundFiles, background: "only" })
|
|
448
|
+
] });
|
|
449
|
+
}
|
|
450
|
+
function Environment(props) {
|
|
451
|
+
if (props.color && !props.files && !props.preset && !props.map) {
|
|
452
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentColor, { ...props });
|
|
453
|
+
}
|
|
454
|
+
if (props.backgroundFiles && props.backgroundFiles !== props.files) {
|
|
455
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentDualSource, { ...props });
|
|
456
|
+
}
|
|
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 });
|
|
458
|
+
}
|
|
459
|
+
|
|
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);
|
|
72
463
|
const act = React__namespace["act"];
|
|
73
464
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
74
465
|
function useMutableCallback(fn) {
|
|
@@ -100,7 +491,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
100
491
|
return _a = class extends React__namespace.Component {
|
|
101
492
|
constructor() {
|
|
102
493
|
super(...arguments);
|
|
103
|
-
__publicField$
|
|
494
|
+
__publicField$1(this, "state", { error: false });
|
|
104
495
|
}
|
|
105
496
|
componentDidCatch(err) {
|
|
106
497
|
this.props.set(err);
|
|
@@ -108,7 +499,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
108
499
|
render() {
|
|
109
500
|
return this.state.error ? null : this.props.children;
|
|
110
501
|
}
|
|
111
|
-
}, __publicField$
|
|
502
|
+
}, __publicField$1(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
112
503
|
})();
|
|
113
504
|
|
|
114
505
|
const is = {
|
|
@@ -294,7 +685,7 @@ function createOcclusionObserverNode(store, uniform) {
|
|
|
294
685
|
let occlusionSetupPromise = null;
|
|
295
686
|
function enableOcclusion(store) {
|
|
296
687
|
const state = store.getState();
|
|
297
|
-
const { internal, renderer
|
|
688
|
+
const { internal, renderer } = state;
|
|
298
689
|
if (internal.occlusionEnabled || occlusionSetupPromise) return;
|
|
299
690
|
const hasOcclusionSupport = typeof renderer?.isOccluded === "function";
|
|
300
691
|
if (!hasOcclusionSupport) {
|
|
@@ -402,6 +793,17 @@ function unregisterVisibility(store, object) {
|
|
|
402
793
|
internal.visibilityRegistry.delete(object.uuid);
|
|
403
794
|
internal.occlusionCache.delete(object);
|
|
404
795
|
}
|
|
796
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
797
|
+
const { internal } = store.getState();
|
|
798
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
799
|
+
if (!entry) return false;
|
|
800
|
+
entry.handlers = handlers;
|
|
801
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
802
|
+
object.occlusionTest = true;
|
|
803
|
+
enableOcclusion(store);
|
|
804
|
+
}
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
405
807
|
function checkVisibility(state) {
|
|
406
808
|
const { internal, camera } = state;
|
|
407
809
|
const registry = internal.visibilityRegistry;
|
|
@@ -457,6 +859,22 @@ function hasVisibilityHandlers(handlers) {
|
|
|
457
859
|
return !!(handlers.onFramed || handlers.onOccluded || handlers.onVisible);
|
|
458
860
|
}
|
|
459
861
|
|
|
862
|
+
const FROM_REF = Symbol.for("@react-three/fiber.fromRef");
|
|
863
|
+
function fromRef(ref) {
|
|
864
|
+
return { [FROM_REF]: ref };
|
|
865
|
+
}
|
|
866
|
+
function isFromRef(value) {
|
|
867
|
+
return value !== null && typeof value === "object" && FROM_REF in value;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
const ONCE = Symbol.for("@react-three/fiber.once");
|
|
871
|
+
function once(...args) {
|
|
872
|
+
return { [ONCE]: args.length ? args : true };
|
|
873
|
+
}
|
|
874
|
+
function isOnce(value) {
|
|
875
|
+
return value !== null && typeof value === "object" && ONCE in value;
|
|
876
|
+
}
|
|
877
|
+
|
|
460
878
|
const RESERVED_PROPS = [
|
|
461
879
|
"children",
|
|
462
880
|
"key",
|
|
@@ -527,7 +945,7 @@ function getMemoizedPrototype(root) {
|
|
|
527
945
|
ctor = new root.constructor();
|
|
528
946
|
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
529
947
|
}
|
|
530
|
-
} catch
|
|
948
|
+
} catch {
|
|
531
949
|
}
|
|
532
950
|
return ctor;
|
|
533
951
|
}
|
|
@@ -558,7 +976,7 @@ function applyProps(object, props) {
|
|
|
558
976
|
const rootState = instance && findInitialRoot(instance).getState();
|
|
559
977
|
const prevHandlers = instance?.eventCount;
|
|
560
978
|
for (const prop in props) {
|
|
561
|
-
|
|
979
|
+
const value = props[prop];
|
|
562
980
|
if (RESERVED_PROPS.includes(prop)) continue;
|
|
563
981
|
if (instance && EVENT_REGEX.test(prop)) {
|
|
564
982
|
if (typeof value === "function") instance.handlers[prop] = value;
|
|
@@ -573,6 +991,22 @@ function applyProps(object, props) {
|
|
|
573
991
|
continue;
|
|
574
992
|
}
|
|
575
993
|
if (value === void 0) continue;
|
|
994
|
+
if (isFromRef(value)) continue;
|
|
995
|
+
if (isOnce(value)) {
|
|
996
|
+
if (instance?.appliedOnce?.has(prop)) continue;
|
|
997
|
+
if (instance) {
|
|
998
|
+
instance.appliedOnce ?? (instance.appliedOnce = /* @__PURE__ */ new Set());
|
|
999
|
+
instance.appliedOnce.add(prop);
|
|
1000
|
+
}
|
|
1001
|
+
const { root: targetRoot, key: targetKey } = resolve(object, prop);
|
|
1002
|
+
const args = value[ONCE];
|
|
1003
|
+
if (typeof targetRoot[targetKey] === "function") {
|
|
1004
|
+
targetRoot[targetKey](...args === true ? [] : args);
|
|
1005
|
+
} else if (args !== true && args.length > 0) {
|
|
1006
|
+
targetRoot[targetKey] = args[0];
|
|
1007
|
+
}
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
576
1010
|
let { root, key, target } = resolve(object, prop);
|
|
577
1011
|
if (target === void 0 && (typeof root !== "object" || root === null)) {
|
|
578
1012
|
throw Error(`R3F: Cannot set "${prop}". Ensure it is an object before setting "${key}".`);
|
|
@@ -593,9 +1027,25 @@ function applyProps(object, props) {
|
|
|
593
1027
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
594
1028
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
595
1029
|
else target.set(value);
|
|
1030
|
+
} else if (root instanceof webgpu.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
1031
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
1032
|
+
const uniforms = root.uniforms;
|
|
1033
|
+
const nextUniforms = value;
|
|
1034
|
+
for (const name in nextUniforms) {
|
|
1035
|
+
const uniform = nextUniforms[name];
|
|
1036
|
+
const targetUniform = uniforms[name];
|
|
1037
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
1038
|
+
else {
|
|
1039
|
+
const nextUniform = uniform instanceof webgpu.Uniform ? uniform.clone() : new webgpu.Uniform(uniform.value);
|
|
1040
|
+
uniforms[name] = nextUniform;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
596
1043
|
} else {
|
|
597
1044
|
root[key] = value;
|
|
598
|
-
if (
|
|
1045
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1046
|
+
root.needsUpdate = true;
|
|
1047
|
+
}
|
|
1048
|
+
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
|
|
599
1049
|
root[key].format === webgpu.RGBAFormat && root[key].type === webgpu.UnsignedByteType) {
|
|
600
1050
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
601
1051
|
}
|
|
@@ -608,6 +1058,9 @@ function applyProps(object, props) {
|
|
|
608
1058
|
if (instance.eventCount && object2.raycast !== null) {
|
|
609
1059
|
rootState.internal.interaction.push(object2);
|
|
610
1060
|
}
|
|
1061
|
+
}
|
|
1062
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
1063
|
+
const object2 = instance.object;
|
|
611
1064
|
const root = findInitialRoot(instance);
|
|
612
1065
|
const visibilityHandlers = {
|
|
613
1066
|
onFramed: instance.handlers.onFramed,
|
|
@@ -615,7 +1068,9 @@ function applyProps(object, props) {
|
|
|
615
1068
|
onVisible: instance.handlers.onVisible
|
|
616
1069
|
};
|
|
617
1070
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
618
|
-
|
|
1071
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
1072
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
1073
|
+
}
|
|
619
1074
|
} else {
|
|
620
1075
|
unregisterVisibility(root, object2);
|
|
621
1076
|
}
|
|
@@ -628,38 +1083,60 @@ function applyProps(object, props) {
|
|
|
628
1083
|
return object;
|
|
629
1084
|
}
|
|
630
1085
|
|
|
1086
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1087
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1088
|
+
function getPointerState(internal, pointerId) {
|
|
1089
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1090
|
+
if (!state) {
|
|
1091
|
+
state = {
|
|
1092
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1093
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1094
|
+
initialClick: [0, 0],
|
|
1095
|
+
initialHits: []
|
|
1096
|
+
};
|
|
1097
|
+
internal.pointerMap.set(pointerId, state);
|
|
1098
|
+
}
|
|
1099
|
+
return state;
|
|
1100
|
+
}
|
|
1101
|
+
function getPointerId(event) {
|
|
1102
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1103
|
+
}
|
|
631
1104
|
function makeId(event) {
|
|
632
1105
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
633
1106
|
}
|
|
634
|
-
function releaseInternalPointerCapture(
|
|
635
|
-
const
|
|
1107
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1108
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1109
|
+
if (!pointerState) return;
|
|
1110
|
+
const captureData = pointerState.captured.get(obj);
|
|
636
1111
|
if (captureData) {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
capturedMap.delete(pointerId);
|
|
640
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
641
|
-
}
|
|
1112
|
+
pointerState.captured.delete(obj);
|
|
1113
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
642
1114
|
}
|
|
643
1115
|
}
|
|
644
1116
|
function removeInteractivity(store, object) {
|
|
645
1117
|
const { internal } = store.getState();
|
|
646
1118
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
1119
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1120
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1121
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1122
|
+
if (value.eventObject === object || value.object === object) {
|
|
1123
|
+
pointerState.hovered.delete(key);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
if (pointerState.captured.has(object)) {
|
|
1127
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
651
1128
|
}
|
|
652
|
-
}
|
|
653
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
654
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
655
|
-
});
|
|
1129
|
+
}
|
|
656
1130
|
unregisterVisibility(store, object);
|
|
657
1131
|
}
|
|
658
1132
|
function createEvents(store) {
|
|
659
|
-
function calculateDistance(event) {
|
|
1133
|
+
function calculateDistance(event, pointerId) {
|
|
660
1134
|
const { internal } = store.getState();
|
|
661
|
-
const
|
|
662
|
-
|
|
1135
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1136
|
+
if (!pointerState) return 0;
|
|
1137
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1138
|
+
const dx = event.offsetX - initialX;
|
|
1139
|
+
const dy = event.offsetY - initialY;
|
|
663
1140
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
664
1141
|
}
|
|
665
1142
|
function filterPointerEvents(objects) {
|
|
@@ -695,6 +1172,15 @@ function createEvents(store) {
|
|
|
695
1172
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
696
1173
|
}
|
|
697
1174
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1175
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1176
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1177
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1178
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1179
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1180
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1181
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
698
1184
|
const aState = getRootState(a.object);
|
|
699
1185
|
const bState = getRootState(b.object);
|
|
700
1186
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -710,14 +1196,19 @@ function createEvents(store) {
|
|
|
710
1196
|
for (const hit of hits) {
|
|
711
1197
|
let eventObject = hit.object;
|
|
712
1198
|
while (eventObject) {
|
|
713
|
-
if (eventObject.__r3f?.eventCount)
|
|
1199
|
+
if (eventObject.__r3f?.eventCount) {
|
|
714
1200
|
intersections.push({ ...hit, eventObject });
|
|
1201
|
+
}
|
|
715
1202
|
eventObject = eventObject.parent;
|
|
716
1203
|
}
|
|
717
1204
|
}
|
|
718
|
-
if ("pointerId" in event
|
|
719
|
-
|
|
720
|
-
|
|
1205
|
+
if ("pointerId" in event) {
|
|
1206
|
+
const pointerId = event.pointerId;
|
|
1207
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1208
|
+
if (pointerState?.captured.size) {
|
|
1209
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1210
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1211
|
+
}
|
|
721
1212
|
}
|
|
722
1213
|
}
|
|
723
1214
|
return intersections;
|
|
@@ -730,28 +1221,26 @@ function createEvents(store) {
|
|
|
730
1221
|
if (state) {
|
|
731
1222
|
const { raycaster, pointer, camera, internal } = state;
|
|
732
1223
|
const unprojectedPoint = new webgpu.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
733
|
-
const hasPointerCapture = (id) =>
|
|
1224
|
+
const hasPointerCapture = (id) => {
|
|
1225
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1226
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1227
|
+
};
|
|
734
1228
|
const setPointerCapture = (id) => {
|
|
735
1229
|
const captureData = { intersection: hit, target: event.target };
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
} else {
|
|
739
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
740
|
-
}
|
|
1230
|
+
const pointerState = getPointerState(internal, id);
|
|
1231
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
741
1232
|
event.target.setPointerCapture(id);
|
|
742
1233
|
};
|
|
743
1234
|
const releasePointerCapture = (id) => {
|
|
744
|
-
|
|
745
|
-
if (captures) {
|
|
746
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
747
|
-
}
|
|
1235
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
748
1236
|
};
|
|
749
|
-
|
|
750
|
-
for (
|
|
751
|
-
|
|
1237
|
+
const extractEventProps = {};
|
|
1238
|
+
for (const prop in event) {
|
|
1239
|
+
const property = event[prop];
|
|
752
1240
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
753
1241
|
}
|
|
754
|
-
|
|
1242
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1243
|
+
const raycastEvent = {
|
|
755
1244
|
...hit,
|
|
756
1245
|
...extractEventProps,
|
|
757
1246
|
pointer,
|
|
@@ -761,18 +1250,19 @@ function createEvents(store) {
|
|
|
761
1250
|
unprojectedPoint,
|
|
762
1251
|
ray: raycaster.ray,
|
|
763
1252
|
camera,
|
|
1253
|
+
pointerId: eventPointerId,
|
|
764
1254
|
// Hijack stopPropagation, which just sets a flag
|
|
765
1255
|
stopPropagation() {
|
|
766
|
-
const
|
|
1256
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
767
1257
|
if (
|
|
768
1258
|
// ...if this pointer hasn't been captured
|
|
769
|
-
!
|
|
770
|
-
|
|
1259
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1260
|
+
pointerState.captured.has(hit.eventObject)
|
|
771
1261
|
) {
|
|
772
1262
|
raycastEvent.stopped = localState.stopped = true;
|
|
773
|
-
if (
|
|
1263
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
774
1264
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
775
|
-
cancelPointer([...higher, hit]);
|
|
1265
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
776
1266
|
}
|
|
777
1267
|
}
|
|
778
1268
|
},
|
|
@@ -788,15 +1278,18 @@ function createEvents(store) {
|
|
|
788
1278
|
}
|
|
789
1279
|
return intersections;
|
|
790
1280
|
}
|
|
791
|
-
function cancelPointer(intersections) {
|
|
1281
|
+
function cancelPointer(intersections, pointerId) {
|
|
792
1282
|
const { internal } = store.getState();
|
|
793
|
-
|
|
1283
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1284
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1285
|
+
if (!pointerState) return;
|
|
1286
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
794
1287
|
if (!intersections.length || !intersections.find(
|
|
795
1288
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
796
1289
|
)) {
|
|
797
1290
|
const eventObject = hoveredObj.eventObject;
|
|
798
1291
|
const instance = eventObject.__r3f;
|
|
799
|
-
|
|
1292
|
+
pointerState.hovered.delete(hoveredId);
|
|
800
1293
|
if (instance?.eventCount) {
|
|
801
1294
|
const handlers = instance.handlers;
|
|
802
1295
|
const data = { ...hoveredObj, intersections };
|
|
@@ -825,41 +1318,118 @@ function createEvents(store) {
|
|
|
825
1318
|
instance?.handlers.onDropMissed?.(event);
|
|
826
1319
|
}
|
|
827
1320
|
}
|
|
1321
|
+
function cleanupPointer(pointerId) {
|
|
1322
|
+
const { internal } = store.getState();
|
|
1323
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1324
|
+
if (pointerState) {
|
|
1325
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1326
|
+
const eventObject = hoveredObj.eventObject;
|
|
1327
|
+
const instance = eventObject.__r3f;
|
|
1328
|
+
if (instance?.eventCount) {
|
|
1329
|
+
const handlers = instance.handlers;
|
|
1330
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1331
|
+
handlers.onPointerOut?.(data);
|
|
1332
|
+
handlers.onPointerLeave?.(data);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
internal.pointerMap.delete(pointerId);
|
|
1336
|
+
}
|
|
1337
|
+
internal.pointerDirty.delete(pointerId);
|
|
1338
|
+
}
|
|
1339
|
+
function processDeferredPointer(event, pointerId) {
|
|
1340
|
+
const state = store.getState();
|
|
1341
|
+
const { internal } = state;
|
|
1342
|
+
if (!state.events.enabled) return;
|
|
1343
|
+
const filter = filterPointerEvents;
|
|
1344
|
+
const hits = intersect(event, filter);
|
|
1345
|
+
cancelPointer(hits, pointerId);
|
|
1346
|
+
function onIntersect(data) {
|
|
1347
|
+
const eventObject = data.eventObject;
|
|
1348
|
+
const instance = eventObject.__r3f;
|
|
1349
|
+
if (!instance?.eventCount) return;
|
|
1350
|
+
const handlers = instance.handlers;
|
|
1351
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1352
|
+
const id = makeId(data);
|
|
1353
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1354
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1355
|
+
if (!hoveredItem) {
|
|
1356
|
+
pointerState.hovered.set(id, data);
|
|
1357
|
+
handlers.onPointerOver?.(data);
|
|
1358
|
+
handlers.onPointerEnter?.(data);
|
|
1359
|
+
} else if (hoveredItem.stopped) {
|
|
1360
|
+
data.stopPropagation();
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
handlers.onPointerMove?.(data);
|
|
1364
|
+
}
|
|
1365
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1366
|
+
}
|
|
828
1367
|
function handlePointer(name) {
|
|
829
1368
|
switch (name) {
|
|
830
1369
|
case "onPointerLeave":
|
|
831
|
-
case "onPointerCancel":
|
|
832
1370
|
case "onDragLeave":
|
|
833
1371
|
return () => cancelPointer([]);
|
|
1372
|
+
// Global cancel of these events
|
|
1373
|
+
case "onPointerCancel":
|
|
1374
|
+
return (event) => {
|
|
1375
|
+
const pointerId = getPointerId(event);
|
|
1376
|
+
cleanupPointer(pointerId);
|
|
1377
|
+
};
|
|
834
1378
|
case "onLostPointerCapture":
|
|
835
1379
|
return (event) => {
|
|
836
1380
|
const { internal } = store.getState();
|
|
837
|
-
|
|
1381
|
+
const pointerId = getPointerId(event);
|
|
1382
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1383
|
+
if (pointerState?.captured.size) {
|
|
838
1384
|
requestAnimationFrame(() => {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1385
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1386
|
+
if (pointerState2?.captured.size) {
|
|
1387
|
+
pointerState2.captured.clear();
|
|
842
1388
|
}
|
|
1389
|
+
cancelPointer([], pointerId);
|
|
843
1390
|
});
|
|
844
1391
|
}
|
|
845
1392
|
};
|
|
846
1393
|
}
|
|
847
1394
|
return function handleEvent(event) {
|
|
848
1395
|
const state = store.getState();
|
|
849
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1396
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1397
|
+
const pointerId = getPointerId(event);
|
|
850
1398
|
internal.lastEvent.current = event;
|
|
851
|
-
if (!
|
|
1399
|
+
if (!events.enabled) return;
|
|
852
1400
|
const isPointerMove = name === "onPointerMove";
|
|
853
1401
|
const isDragOver = name === "onDragOver";
|
|
854
1402
|
const isDrop = name === "onDrop";
|
|
855
1403
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1404
|
+
const isPointerDown = name === "onPointerDown";
|
|
1405
|
+
const isPointerUp = name === "onPointerUp";
|
|
1406
|
+
const isWheel = name === "onWheel";
|
|
1407
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1408
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1409
|
+
events.compute?.(event, state);
|
|
1410
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1414
|
+
events.compute?.(event, state);
|
|
1415
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1419
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1420
|
+
internal.pointerDirty.delete(pointerId);
|
|
1421
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1422
|
+
}
|
|
856
1423
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
857
1424
|
const hits = intersect(event, filter);
|
|
858
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
859
|
-
if (
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1425
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1426
|
+
if (isPointerDown) {
|
|
1427
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1428
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1429
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1430
|
+
}
|
|
1431
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1432
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
863
1433
|
if (isClickEvent && !hits.length) {
|
|
864
1434
|
if (delta <= 2) {
|
|
865
1435
|
pointerMissed(event, internal.interaction);
|
|
@@ -874,7 +1444,9 @@ function createEvents(store) {
|
|
|
874
1444
|
dropMissed(event, internal.interaction);
|
|
875
1445
|
if (onDropMissed) onDropMissed(event);
|
|
876
1446
|
}
|
|
877
|
-
if (isPointerMove || isDragOver)
|
|
1447
|
+
if (isPointerMove || isDragOver) {
|
|
1448
|
+
cancelPointer(hits, pointerId);
|
|
1449
|
+
}
|
|
878
1450
|
function onIntersect(data) {
|
|
879
1451
|
const eventObject = data.eventObject;
|
|
880
1452
|
const instance = eventObject.__r3f;
|
|
@@ -883,9 +1455,10 @@ function createEvents(store) {
|
|
|
883
1455
|
if (isPointerMove) {
|
|
884
1456
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
885
1457
|
const id = makeId(data);
|
|
886
|
-
const
|
|
1458
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1459
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
887
1460
|
if (!hoveredItem) {
|
|
888
|
-
|
|
1461
|
+
pointerState2.hovered.set(id, data);
|
|
889
1462
|
handlers.onPointerOver?.(data);
|
|
890
1463
|
handlers.onPointerEnter?.(data);
|
|
891
1464
|
} else if (hoveredItem.stopped) {
|
|
@@ -895,9 +1468,10 @@ function createEvents(store) {
|
|
|
895
1468
|
handlers.onPointerMove?.(data);
|
|
896
1469
|
} else if (isDragOver) {
|
|
897
1470
|
const id = makeId(data);
|
|
898
|
-
const
|
|
1471
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1472
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
899
1473
|
if (!hoveredItem) {
|
|
900
|
-
|
|
1474
|
+
pointerState2.hovered.set(id, data);
|
|
901
1475
|
handlers.onDragOverEnter?.(data);
|
|
902
1476
|
} else if (hoveredItem.stopped) {
|
|
903
1477
|
data.stopPropagation();
|
|
@@ -908,18 +1482,18 @@ function createEvents(store) {
|
|
|
908
1482
|
} else {
|
|
909
1483
|
const handler = handlers[name];
|
|
910
1484
|
if (handler) {
|
|
911
|
-
if (!isClickEvent ||
|
|
1485
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
912
1486
|
pointerMissed(
|
|
913
1487
|
event,
|
|
914
|
-
internal.interaction.filter((object) => !
|
|
1488
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
915
1489
|
);
|
|
916
1490
|
handler(data);
|
|
917
1491
|
}
|
|
918
1492
|
} else {
|
|
919
|
-
if (isClickEvent &&
|
|
1493
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
920
1494
|
pointerMissed(
|
|
921
1495
|
event,
|
|
922
|
-
internal.interaction.filter((object) => !
|
|
1496
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
923
1497
|
);
|
|
924
1498
|
}
|
|
925
1499
|
}
|
|
@@ -928,7 +1502,15 @@ function createEvents(store) {
|
|
|
928
1502
|
handleIntersects(hits, event, delta, onIntersect);
|
|
929
1503
|
};
|
|
930
1504
|
}
|
|
931
|
-
|
|
1505
|
+
function flushDeferredPointers() {
|
|
1506
|
+
const { internal, events } = store.getState();
|
|
1507
|
+
if (!events.frameTimedRaycasts) return;
|
|
1508
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1509
|
+
processDeferredPointer(event, pointerId);
|
|
1510
|
+
}
|
|
1511
|
+
internal.pointerDirty.clear();
|
|
1512
|
+
}
|
|
1513
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
932
1514
|
}
|
|
933
1515
|
const DOM_EVENTS = {
|
|
934
1516
|
onClick: ["click", false],
|
|
@@ -947,11 +1529,16 @@ const DOM_EVENTS = {
|
|
|
947
1529
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
948
1530
|
};
|
|
949
1531
|
function createPointerEvents(store) {
|
|
950
|
-
const { handlePointer } = createEvents(store);
|
|
1532
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1533
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1534
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
951
1535
|
return {
|
|
952
1536
|
priority: 1,
|
|
953
1537
|
enabled: true,
|
|
954
|
-
|
|
1538
|
+
frameTimedRaycasts: true,
|
|
1539
|
+
alwaysFireOnScroll: true,
|
|
1540
|
+
updateOnFrame: false,
|
|
1541
|
+
compute(event, state) {
|
|
955
1542
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
956
1543
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
957
1544
|
},
|
|
@@ -960,11 +1547,33 @@ function createPointerEvents(store) {
|
|
|
960
1547
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
961
1548
|
{}
|
|
962
1549
|
),
|
|
963
|
-
update: () => {
|
|
1550
|
+
update: (pointerId) => {
|
|
1551
|
+
const { events, internal } = store.getState();
|
|
1552
|
+
if (!events.handlers) return;
|
|
1553
|
+
if (pointerId !== void 0) {
|
|
1554
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1555
|
+
if (event) {
|
|
1556
|
+
internal.pointerDirty.delete(pointerId);
|
|
1557
|
+
processDeferredPointer(event, pointerId);
|
|
1558
|
+
} else if (internal.lastEvent?.current) {
|
|
1559
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1560
|
+
}
|
|
1561
|
+
} else {
|
|
1562
|
+
flushDeferredPointers();
|
|
1563
|
+
if (internal.lastEvent?.current) {
|
|
1564
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
},
|
|
1568
|
+
flush: () => {
|
|
964
1569
|
const { events, internal } = store.getState();
|
|
965
|
-
|
|
1570
|
+
flushDeferredPointers();
|
|
1571
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1572
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1573
|
+
}
|
|
966
1574
|
},
|
|
967
1575
|
connect: (target) => {
|
|
1576
|
+
if (!target) return;
|
|
968
1577
|
const { set, events } = store.getState();
|
|
969
1578
|
events.disconnect?.();
|
|
970
1579
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -988,6 +1597,33 @@ function createPointerEvents(store) {
|
|
|
988
1597
|
}
|
|
989
1598
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
990
1599
|
}
|
|
1600
|
+
},
|
|
1601
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1602
|
+
registerPointer: (config) => {
|
|
1603
|
+
const pointerId = nextXRPointerId++;
|
|
1604
|
+
xrPointers.set(pointerId, config);
|
|
1605
|
+
const { internal } = store.getState();
|
|
1606
|
+
getPointerState(internal, pointerId);
|
|
1607
|
+
return pointerId;
|
|
1608
|
+
},
|
|
1609
|
+
unregisterPointer: (pointerId) => {
|
|
1610
|
+
xrPointers.delete(pointerId);
|
|
1611
|
+
const { internal } = store.getState();
|
|
1612
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1613
|
+
if (pointerState) {
|
|
1614
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1615
|
+
const eventObject = hoveredObj.eventObject;
|
|
1616
|
+
const instance = eventObject.__r3f;
|
|
1617
|
+
if (instance?.eventCount) {
|
|
1618
|
+
const handlers = instance.handlers;
|
|
1619
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1620
|
+
handlers.onPointerOut?.(data);
|
|
1621
|
+
handlers.onPointerLeave?.(data);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
internal.pointerMap.delete(pointerId);
|
|
1625
|
+
}
|
|
1626
|
+
internal.pointerDirty.delete(pointerId);
|
|
991
1627
|
}
|
|
992
1628
|
};
|
|
993
1629
|
}
|
|
@@ -1049,6 +1685,14 @@ function notifyAlpha({ message, link }) {
|
|
|
1049
1685
|
}
|
|
1050
1686
|
}
|
|
1051
1687
|
|
|
1688
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
1689
|
+
const INTERNAL_FIBER_MARKERS = ["packages/fiber/src", "packages/fiber/dist", "@react-three/fiber", "@react-three_fiber"];
|
|
1690
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
1691
|
+
if (!stack) return false;
|
|
1692
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
1693
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m)) || INTERNAL_FIBER_MARKERS.some((m) => caller.includes(m));
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1052
1696
|
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
1053
1697
|
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
1054
1698
|
const createStore = (invalidate, advance) => {
|
|
@@ -1078,23 +1722,29 @@ const createStore = (invalidate, advance) => {
|
|
|
1078
1722
|
set,
|
|
1079
1723
|
get,
|
|
1080
1724
|
// Mock objects that have to be configured
|
|
1725
|
+
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
1726
|
+
primaryStore: null,
|
|
1081
1727
|
gl: null,
|
|
1082
1728
|
renderer: null,
|
|
1083
1729
|
camera: null,
|
|
1084
1730
|
frustum: new webgpu.Frustum(),
|
|
1085
1731
|
autoUpdateFrustum: true,
|
|
1086
1732
|
raycaster: null,
|
|
1087
|
-
events: {
|
|
1733
|
+
events: {
|
|
1734
|
+
priority: 1,
|
|
1735
|
+
enabled: true,
|
|
1736
|
+
connected: false,
|
|
1737
|
+
frameTimedRaycasts: true,
|
|
1738
|
+
alwaysFireOnScroll: true,
|
|
1739
|
+
updateOnFrame: false
|
|
1740
|
+
},
|
|
1088
1741
|
scene: null,
|
|
1089
1742
|
rootScene: null,
|
|
1090
1743
|
xr: null,
|
|
1091
1744
|
inspector: null,
|
|
1092
1745
|
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
1093
1746
|
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
1094
|
-
|
|
1095
|
-
linear: false,
|
|
1096
|
-
flat: false,
|
|
1097
|
-
textureColorSpace: "srgb",
|
|
1747
|
+
textureColorSpace: webgpu.SRGBColorSpace,
|
|
1098
1748
|
isLegacy: false,
|
|
1099
1749
|
webGPUSupported: false,
|
|
1100
1750
|
isNative: false,
|
|
@@ -1134,10 +1784,40 @@ const createStore = (invalidate, advance) => {
|
|
|
1134
1784
|
getCurrentViewport
|
|
1135
1785
|
},
|
|
1136
1786
|
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
1137
|
-
setSize: (width, height, top
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1140
|
-
|
|
1787
|
+
setSize: (width, height, top, left) => {
|
|
1788
|
+
const state2 = get();
|
|
1789
|
+
if (width === void 0) {
|
|
1790
|
+
set({ _sizeImperative: false });
|
|
1791
|
+
if (state2._sizeProps) {
|
|
1792
|
+
const { width: propW, height: propH } = state2._sizeProps;
|
|
1793
|
+
if (propW !== void 0 || propH !== void 0) {
|
|
1794
|
+
const currentSize = state2.size;
|
|
1795
|
+
const newSize = {
|
|
1796
|
+
width: propW ?? currentSize.width,
|
|
1797
|
+
height: propH ?? currentSize.height,
|
|
1798
|
+
top: currentSize.top,
|
|
1799
|
+
left: currentSize.left
|
|
1800
|
+
};
|
|
1801
|
+
set((s) => ({
|
|
1802
|
+
size: newSize,
|
|
1803
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1804
|
+
}));
|
|
1805
|
+
scheduler.getScheduler().invalidate();
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
const w = width;
|
|
1811
|
+
const h = height ?? width;
|
|
1812
|
+
const t = top ?? state2.size.top;
|
|
1813
|
+
const l = left ?? state2.size.left;
|
|
1814
|
+
const size = { width: w, height: h, top: t, left: l };
|
|
1815
|
+
set((s) => ({
|
|
1816
|
+
size,
|
|
1817
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1818
|
+
_sizeImperative: true
|
|
1819
|
+
}));
|
|
1820
|
+
scheduler.getScheduler().invalidate();
|
|
1141
1821
|
},
|
|
1142
1822
|
setDpr: (dpr) => set((state2) => {
|
|
1143
1823
|
const resolved = calculateDpr(dpr);
|
|
@@ -1145,25 +1825,36 @@ const createStore = (invalidate, advance) => {
|
|
|
1145
1825
|
}),
|
|
1146
1826
|
setFrameloop: (frameloop = "always") => {
|
|
1147
1827
|
set(() => ({ frameloop }));
|
|
1828
|
+
scheduler.getScheduler().frameloop = frameloop;
|
|
1148
1829
|
},
|
|
1149
1830
|
setError: (error) => set(() => ({ error })),
|
|
1150
1831
|
error: null,
|
|
1151
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1832
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1152
1833
|
uniforms: {},
|
|
1153
1834
|
nodes: {},
|
|
1835
|
+
buffers: {},
|
|
1836
|
+
gpuStorage: {},
|
|
1154
1837
|
textures: /* @__PURE__ */ new Map(),
|
|
1155
|
-
|
|
1838
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1839
|
+
renderPipeline: null,
|
|
1156
1840
|
passes: {},
|
|
1841
|
+
_hmrVersion: 0,
|
|
1842
|
+
_sizeImperative: false,
|
|
1843
|
+
_sizeProps: null,
|
|
1157
1844
|
previousRoot: void 0,
|
|
1158
1845
|
internal: {
|
|
1159
1846
|
// Events
|
|
1160
1847
|
interaction: [],
|
|
1161
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1162
1848
|
subscribers: [],
|
|
1849
|
+
// Per-pointer state (new unified structure)
|
|
1850
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1851
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1852
|
+
lastEvent: React__namespace.createRef(),
|
|
1853
|
+
// Deprecated but kept for backwards compatibility
|
|
1854
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1163
1855
|
initialClick: [0, 0],
|
|
1164
1856
|
initialHits: [],
|
|
1165
1857
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
1166
|
-
lastEvent: React__namespace.createRef(),
|
|
1167
1858
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1168
1859
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1169
1860
|
// Occlusion system (WebGPU only)
|
|
@@ -1202,8 +1893,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1202
1893
|
const currentState = rootStore.getState();
|
|
1203
1894
|
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1204
1895
|
const stack = new Error().stack || "";
|
|
1205
|
-
|
|
1206
|
-
if (!isInternalAccess) {
|
|
1896
|
+
if (!isInternalRendererAccess(stack)) {
|
|
1207
1897
|
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1208
1898
|
notifyDepreciated({
|
|
1209
1899
|
heading: "Accessing state.gl in WebGPU mode",
|
|
@@ -1246,13 +1936,22 @@ const createStore = (invalidate, advance) => {
|
|
|
1246
1936
|
rootStore.subscribe(() => {
|
|
1247
1937
|
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1248
1938
|
const actualRenderer = internal.actualRenderer;
|
|
1939
|
+
const canvasTarget = internal.canvasTarget;
|
|
1249
1940
|
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1250
1941
|
oldSize = size;
|
|
1251
1942
|
oldDpr = viewport.dpr;
|
|
1252
1943
|
updateCamera(camera, size);
|
|
1253
|
-
if (
|
|
1254
|
-
|
|
1255
|
-
|
|
1944
|
+
if (internal.isSecondary && canvasTarget) {
|
|
1945
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1946
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1947
|
+
} else {
|
|
1948
|
+
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1949
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1950
|
+
if (canvasTarget) {
|
|
1951
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1952
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1256
1955
|
}
|
|
1257
1956
|
if (camera !== oldCamera) {
|
|
1258
1957
|
oldCamera = camera;
|
|
@@ -1307,1092 +2006,67 @@ function loadingFn(extensions, onProgress) {
|
|
|
1307
2006
|
);
|
|
1308
2007
|
};
|
|
1309
2008
|
}
|
|
1310
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
1311
|
-
const
|
|
2009
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2010
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2011
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1312
2012
|
const fn = loadingFn(extensions, onProgress);
|
|
1313
|
-
const results =
|
|
2013
|
+
const results = cacheKeys.map(
|
|
2014
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2015
|
+
);
|
|
1314
2016
|
return Array.isArray(input) ? results : results[0];
|
|
1315
2017
|
}
|
|
1316
|
-
useLoader.preload = function(loader, input, extensions, onProgress) {
|
|
1317
|
-
const
|
|
1318
|
-
|
|
2018
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2019
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
2020
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2021
|
+
cacheKeys.forEach(
|
|
2022
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2023
|
+
);
|
|
1319
2024
|
};
|
|
1320
|
-
useLoader.clear = function(loader, input) {
|
|
1321
|
-
const
|
|
1322
|
-
|
|
2025
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
2026
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2027
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
1323
2028
|
};
|
|
1324
2029
|
useLoader.loader = getLoader;
|
|
1325
2030
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
else {
|
|
1366
|
-
const constraintType = before ? "before" : "after";
|
|
1367
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1368
|
-
}
|
|
1369
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1370
|
-
this.phaseMap.set(name, node);
|
|
1371
|
-
this.invalidateCache();
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Get ordered list of phase names
|
|
1375
|
-
*/
|
|
1376
|
-
getOrderedPhases() {
|
|
1377
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1378
|
-
return this.orderedNamesCache;
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Check if a phase exists
|
|
1382
|
-
*/
|
|
1383
|
-
hasPhase(name) {
|
|
1384
|
-
return this.phaseMap.has(name);
|
|
1385
|
-
}
|
|
1386
|
-
/**
|
|
1387
|
-
* Get the index of a phase (-1 if not found)
|
|
1388
|
-
*/
|
|
1389
|
-
getPhaseIndex(name) {
|
|
1390
|
-
if (!name) return -1;
|
|
1391
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1395
|
-
* Used for resolving before/after constraints.
|
|
1396
|
-
*
|
|
1397
|
-
* @param name - The phase name to ensure exists
|
|
1398
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1399
|
-
*/
|
|
1400
|
-
ensurePhase(name) {
|
|
1401
|
-
if (this.phaseMap.has(name)) return name;
|
|
1402
|
-
const node = { name, isAutoGenerated: true };
|
|
1403
|
-
this.phases.push(node);
|
|
1404
|
-
this.phaseMap.set(name, node);
|
|
1405
|
-
this.invalidateCache();
|
|
1406
|
-
return name;
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Resolve where a job with before/after constraints should go.
|
|
1410
|
-
* Creates auto-generated phases if needed.
|
|
1411
|
-
*
|
|
1412
|
-
* @param before - Phase(s) to run before
|
|
1413
|
-
* @param after - Phase(s) to run after
|
|
1414
|
-
* @returns The resolved phase name
|
|
1415
|
-
*/
|
|
1416
|
-
resolveConstraintPhase(before, after) {
|
|
1417
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1418
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1419
|
-
if (beforeArr.length > 0) {
|
|
1420
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1421
|
-
}
|
|
1422
|
-
if (afterArr.length > 0) {
|
|
1423
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1424
|
-
}
|
|
1425
|
-
return "update";
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1429
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1430
|
-
*
|
|
1431
|
-
* @param target - The target phase name to position relative to
|
|
1432
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1433
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1434
|
-
* @returns The auto-generated phase name
|
|
1435
|
-
*/
|
|
1436
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1437
|
-
const autoName = `${prefix}:${target}`;
|
|
1438
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1439
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1440
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1441
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1442
|
-
else this.phases.push(node);
|
|
1443
|
-
this.phaseMap.set(autoName, node);
|
|
1444
|
-
this.invalidateCache();
|
|
1445
|
-
return autoName;
|
|
1446
|
-
}
|
|
1447
|
-
// Internal --------------------------------
|
|
1448
|
-
invalidateCache() {
|
|
1449
|
-
this.orderedNamesCache = null;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1454
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1455
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1456
|
-
for (const phase of orderedPhases) {
|
|
1457
|
-
buckets.set(phase, []);
|
|
1458
|
-
}
|
|
1459
|
-
for (const job of jobs.values()) {
|
|
1460
|
-
if (!job.enabled) continue;
|
|
1461
|
-
let bucket = buckets.get(job.phase);
|
|
1462
|
-
if (!bucket) {
|
|
1463
|
-
bucket = [];
|
|
1464
|
-
buckets.set(job.phase, bucket);
|
|
1465
|
-
}
|
|
1466
|
-
bucket.push(job);
|
|
1467
|
-
}
|
|
1468
|
-
const sortedBuckets = [];
|
|
1469
|
-
for (const phase of orderedPhases) {
|
|
1470
|
-
const bucket = buckets.get(phase);
|
|
1471
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1472
|
-
bucket.sort((a, b) => {
|
|
1473
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1474
|
-
return a.index - b.index;
|
|
1475
|
-
});
|
|
1476
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1477
|
-
}
|
|
1478
|
-
for (const [phase, bucket] of buckets) {
|
|
1479
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1480
|
-
bucket.sort((a, b) => {
|
|
1481
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1482
|
-
return a.index - b.index;
|
|
1483
|
-
});
|
|
1484
|
-
sortedBuckets.push(bucket);
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
return sortedBuckets.flat();
|
|
1488
|
-
}
|
|
1489
|
-
function hasCrossJobConstraints(bucket) {
|
|
1490
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1491
|
-
for (const job of bucket) {
|
|
1492
|
-
for (const ref of job.before) {
|
|
1493
|
-
if (jobIds.has(ref)) return true;
|
|
1494
|
-
}
|
|
1495
|
-
for (const ref of job.after) {
|
|
1496
|
-
if (jobIds.has(ref)) return true;
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
return false;
|
|
1500
|
-
}
|
|
1501
|
-
function topologicalSort(jobs) {
|
|
1502
|
-
const n = jobs.length;
|
|
1503
|
-
if (n <= 1) return jobs;
|
|
1504
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1505
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1506
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1507
|
-
for (const job of jobs) {
|
|
1508
|
-
jobMap.set(job.id, job);
|
|
1509
|
-
inDegree.set(job.id, 0);
|
|
1510
|
-
adjacency.set(job.id, []);
|
|
1511
|
-
}
|
|
1512
|
-
for (const job of jobs) {
|
|
1513
|
-
for (const ref of job.before) {
|
|
1514
|
-
if (jobMap.has(ref)) {
|
|
1515
|
-
adjacency.get(job.id).push(ref);
|
|
1516
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
for (const ref of job.after) {
|
|
1520
|
-
if (jobMap.has(ref)) {
|
|
1521
|
-
adjacency.get(ref).push(job.id);
|
|
1522
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
const queue = [];
|
|
1527
|
-
for (const job of jobs) {
|
|
1528
|
-
if (inDegree.get(job.id) === 0) {
|
|
1529
|
-
queue.push(job);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
queue.sort((a, b) => {
|
|
1533
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1534
|
-
return a.index - b.index;
|
|
1535
|
-
});
|
|
1536
|
-
const result = [];
|
|
1537
|
-
while (queue.length > 0) {
|
|
1538
|
-
const job = queue.shift();
|
|
1539
|
-
result.push(job);
|
|
1540
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1541
|
-
for (const neighborId of neighbors) {
|
|
1542
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1543
|
-
inDegree.set(neighborId, newDegree);
|
|
1544
|
-
if (newDegree === 0) {
|
|
1545
|
-
const neighbor = jobMap.get(neighborId);
|
|
1546
|
-
insertSorted(queue, neighbor);
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
if (result.length !== n) {
|
|
1551
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1552
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1553
|
-
for (const job of jobs) {
|
|
1554
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
return result;
|
|
1558
|
-
}
|
|
1559
|
-
function insertSorted(arr, job) {
|
|
1560
|
-
let i = 0;
|
|
1561
|
-
while (i < arr.length) {
|
|
1562
|
-
const cmp = arr[i];
|
|
1563
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1564
|
-
break;
|
|
1565
|
-
}
|
|
1566
|
-
i++;
|
|
1567
|
-
}
|
|
1568
|
-
arr.splice(i, 0, job);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
function shouldRun(job, now) {
|
|
1572
|
-
if (!job.enabled) return false;
|
|
1573
|
-
if (!job.fps) return true;
|
|
1574
|
-
const minInterval = 1e3 / job.fps;
|
|
1575
|
-
const lastRun = job.lastRun ?? 0;
|
|
1576
|
-
const elapsed = now - lastRun;
|
|
1577
|
-
if (elapsed < minInterval) return false;
|
|
1578
|
-
if (job.drop) {
|
|
1579
|
-
job.lastRun = now;
|
|
1580
|
-
} else {
|
|
1581
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1582
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1583
|
-
if (job.lastRun < now - minInterval) {
|
|
1584
|
-
job.lastRun = now;
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
return true;
|
|
1588
|
-
}
|
|
1589
|
-
function resetJobTiming(job) {
|
|
1590
|
-
job.lastRun = void 0;
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
var __defProp = Object.defineProperty;
|
|
1594
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1595
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1596
|
-
const hmrData = (() => {
|
|
1597
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1598
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1599
|
-
try {
|
|
1600
|
-
return (0, eval)("import.meta.hot");
|
|
1601
|
-
} catch {
|
|
1602
|
-
return void 0;
|
|
1603
|
-
}
|
|
1604
|
-
})();
|
|
1605
|
-
const _Scheduler = class _Scheduler {
|
|
1606
|
-
//* Constructor ================================
|
|
1607
|
-
constructor() {
|
|
1608
|
-
//* Critical State ================================
|
|
1609
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1610
|
-
__publicField(this, "phaseGraph");
|
|
1611
|
-
__publicField(this, "loopState", {
|
|
1612
|
-
running: false,
|
|
1613
|
-
rafHandle: null,
|
|
1614
|
-
lastTime: null,
|
|
1615
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1616
|
-
frameCount: 0,
|
|
1617
|
-
elapsedTime: 0,
|
|
1618
|
-
createdAt: performance.now()
|
|
1619
|
-
});
|
|
1620
|
-
__publicField(this, "stoppedTime", 0);
|
|
1621
|
-
//* Private State ================================
|
|
1622
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1623
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1624
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1625
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1626
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1627
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1628
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1629
|
-
__publicField(this, "pendingFrames", 0);
|
|
1630
|
-
__publicField(this, "_frameloop", "always");
|
|
1631
|
-
//* Independent Mode & Error Handling State ================================
|
|
1632
|
-
__publicField(this, "_independent", false);
|
|
1633
|
-
__publicField(this, "errorHandler", null);
|
|
1634
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1635
|
-
//* Core Loop Execution Methods ================================
|
|
1636
|
-
/**
|
|
1637
|
-
* Main RAF loop callback.
|
|
1638
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1639
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1640
|
-
* @returns {void}
|
|
1641
|
-
* @private
|
|
1642
|
-
*/
|
|
1643
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1644
|
-
if (!this.loopState.running) return;
|
|
1645
|
-
this.executeFrame(timestamp);
|
|
1646
|
-
if (this._frameloop === "demand") {
|
|
1647
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1648
|
-
if (this.pendingFrames === 0) {
|
|
1649
|
-
this.notifyIdle(timestamp);
|
|
1650
|
-
return this.stop();
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1654
|
-
});
|
|
1655
|
-
this.phaseGraph = new PhaseGraph();
|
|
1656
|
-
}
|
|
1657
|
-
static get instance() {
|
|
1658
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1659
|
-
}
|
|
1660
|
-
static set instance(value) {
|
|
1661
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1665
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1666
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1667
|
-
*/
|
|
1668
|
-
static get() {
|
|
1669
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1670
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1671
|
-
}
|
|
1672
|
-
if (!_Scheduler.instance) {
|
|
1673
|
-
_Scheduler.instance = new _Scheduler();
|
|
1674
|
-
if (hmrData?.data) {
|
|
1675
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
return _Scheduler.instance;
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1682
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1683
|
-
* @returns {void}
|
|
1684
|
-
*/
|
|
1685
|
-
static reset() {
|
|
1686
|
-
if (_Scheduler.instance) {
|
|
1687
|
-
_Scheduler.instance.stop();
|
|
1688
|
-
_Scheduler.instance = null;
|
|
1689
|
-
}
|
|
1690
|
-
if (hmrData?.data) {
|
|
1691
|
-
hmrData.data.scheduler = null;
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
//* Getters & Setters ================================
|
|
1695
|
-
get phases() {
|
|
1696
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1697
|
-
}
|
|
1698
|
-
get frameloop() {
|
|
1699
|
-
return this._frameloop;
|
|
1700
|
-
}
|
|
1701
|
-
set frameloop(mode) {
|
|
1702
|
-
if (this._frameloop === mode) return;
|
|
1703
|
-
const wasAlways = this._frameloop === "always";
|
|
1704
|
-
this._frameloop = mode;
|
|
1705
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1706
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1707
|
-
}
|
|
1708
|
-
get isRunning() {
|
|
1709
|
-
return this.loopState.running;
|
|
1710
|
-
}
|
|
1711
|
-
get isReady() {
|
|
1712
|
-
return this.roots.size > 0;
|
|
1713
|
-
}
|
|
1714
|
-
get independent() {
|
|
1715
|
-
return this._independent;
|
|
1716
|
-
}
|
|
1717
|
-
set independent(value) {
|
|
1718
|
-
this._independent = value;
|
|
1719
|
-
if (value) this.ensureDefaultRoot();
|
|
1720
|
-
}
|
|
1721
|
-
//* Root Management Methods ================================
|
|
1722
|
-
/**
|
|
1723
|
-
* Register a root (Canvas) with the scheduler.
|
|
1724
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1725
|
-
* @param {string} id - Unique identifier for this root
|
|
1726
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1727
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1728
|
-
*/
|
|
1729
|
-
registerRoot(id, options = {}) {
|
|
1730
|
-
if (this.roots.has(id)) {
|
|
1731
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1732
|
-
return () => this.unregisterRoot(id);
|
|
1733
|
-
}
|
|
1734
|
-
const entry = {
|
|
1735
|
-
id,
|
|
1736
|
-
getState: options.getState ?? (() => ({})),
|
|
1737
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1738
|
-
sortedJobs: [],
|
|
1739
|
-
needsRebuild: false
|
|
1740
|
-
};
|
|
1741
|
-
if (options.onError) {
|
|
1742
|
-
this.errorHandler = options.onError;
|
|
1743
|
-
}
|
|
1744
|
-
this.roots.set(id, entry);
|
|
1745
|
-
if (this.roots.size === 1) {
|
|
1746
|
-
this.notifyRootReady();
|
|
1747
|
-
if (this._frameloop === "always") this.start();
|
|
1748
|
-
}
|
|
1749
|
-
return () => this.unregisterRoot(id);
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Unregister a root from the scheduler.
|
|
1753
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1754
|
-
* The last root to unregister stops the RAF loop.
|
|
1755
|
-
* @param {string} id - The root ID to unregister
|
|
1756
|
-
* @returns {void}
|
|
1757
|
-
*/
|
|
1758
|
-
unregisterRoot(id) {
|
|
1759
|
-
const root = this.roots.get(id);
|
|
1760
|
-
if (!root) return;
|
|
1761
|
-
for (const jobId of root.jobs.keys()) {
|
|
1762
|
-
this.jobStateListeners.delete(jobId);
|
|
1763
|
-
}
|
|
1764
|
-
this.roots.delete(id);
|
|
1765
|
-
if (this.roots.size === 0) {
|
|
1766
|
-
this.stop();
|
|
1767
|
-
this.errorHandler = null;
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
/**
|
|
1771
|
-
* Subscribe to be notified when a root becomes available.
|
|
1772
|
-
* Fires immediately if a root already exists.
|
|
1773
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1774
|
-
* @returns {() => void} Unsubscribe function
|
|
1775
|
-
*/
|
|
1776
|
-
onRootReady(callback) {
|
|
1777
|
-
if (this.roots.size > 0) {
|
|
1778
|
-
callback();
|
|
1779
|
-
return () => {
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
this.rootReadyCallbacks.add(callback);
|
|
1783
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Notify all registered root-ready callbacks.
|
|
1787
|
-
* Called when the first root registers.
|
|
1788
|
-
* @returns {void}
|
|
1789
|
-
* @private
|
|
1790
|
-
*/
|
|
1791
|
-
notifyRootReady() {
|
|
1792
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1793
|
-
try {
|
|
1794
|
-
cb();
|
|
1795
|
-
} catch (error) {
|
|
1796
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
this.rootReadyCallbacks.clear();
|
|
1800
|
-
}
|
|
1801
|
-
/**
|
|
1802
|
-
* Ensure a default root exists for independent mode.
|
|
1803
|
-
* Creates a minimal root with no state provider.
|
|
1804
|
-
* @returns {void}
|
|
1805
|
-
* @private
|
|
1806
|
-
*/
|
|
1807
|
-
ensureDefaultRoot() {
|
|
1808
|
-
if (!this.roots.has("__default__")) {
|
|
1809
|
-
this.registerRoot("__default__");
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
/**
|
|
1813
|
-
* Trigger error handling for job errors.
|
|
1814
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1815
|
-
* @param {Error} error - The error to handle
|
|
1816
|
-
* @returns {void}
|
|
1817
|
-
*/
|
|
1818
|
-
triggerError(error) {
|
|
1819
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1820
|
-
else console.error("[Scheduler]", error);
|
|
1821
|
-
}
|
|
1822
|
-
//* Phase Management Methods ================================
|
|
1823
|
-
/**
|
|
1824
|
-
* Add a named phase to the scheduler's execution order.
|
|
1825
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1826
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1827
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1828
|
-
* @returns {void}
|
|
1829
|
-
* @example
|
|
1830
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1831
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1832
|
-
*/
|
|
1833
|
-
addPhase(name, options) {
|
|
1834
|
-
this.phaseGraph.addPhase(name, options);
|
|
1835
|
-
for (const root of this.roots.values()) {
|
|
1836
|
-
root.needsRebuild = true;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Check if a phase exists in the scheduler.
|
|
1841
|
-
* @param {string} name - The phase name to check
|
|
1842
|
-
* @returns {boolean} True if the phase exists
|
|
1843
|
-
*/
|
|
1844
|
-
hasPhase(name) {
|
|
1845
|
-
return this.phaseGraph.hasPhase(name);
|
|
1846
|
-
}
|
|
1847
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1848
|
-
/**
|
|
1849
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1850
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1851
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1852
|
-
* @param {string} id - Unique identifier for this global job
|
|
1853
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1854
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1855
|
-
* @deprecated Use useFrame with phases instead
|
|
1856
|
-
*/
|
|
1857
|
-
registerGlobal(phase, id, callback) {
|
|
1858
|
-
const job = { id, callback };
|
|
1859
|
-
if (phase === "before") {
|
|
1860
|
-
this.globalBeforeJobs.set(id, job);
|
|
1861
|
-
} else {
|
|
1862
|
-
this.globalAfterJobs.set(id, job);
|
|
1863
|
-
}
|
|
1864
|
-
return () => {
|
|
1865
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
1866
|
-
else this.globalAfterJobs.delete(id);
|
|
1867
|
-
};
|
|
1868
|
-
}
|
|
1869
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
1870
|
-
/**
|
|
1871
|
-
* Register an idle callback that fires when the loop stops.
|
|
1872
|
-
* Used internally by deprecated addTail API.
|
|
1873
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
1874
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
1875
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
1876
|
-
*/
|
|
1877
|
-
onIdle(callback) {
|
|
1878
|
-
this.idleCallbacks.add(callback);
|
|
1879
|
-
return () => this.idleCallbacks.delete(callback);
|
|
1880
|
-
}
|
|
1881
|
-
/**
|
|
1882
|
-
* Notify all registered idle callbacks.
|
|
1883
|
-
* Called when the loop stops in demand mode.
|
|
1884
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
1885
|
-
* @returns {void}
|
|
1886
|
-
* @private
|
|
1887
|
-
*/
|
|
1888
|
-
notifyIdle(timestamp) {
|
|
1889
|
-
for (const cb of this.idleCallbacks) {
|
|
1890
|
-
try {
|
|
1891
|
-
cb(timestamp);
|
|
1892
|
-
} catch (error) {
|
|
1893
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
//* Job Registration & Management Methods ================================
|
|
1898
|
-
/**
|
|
1899
|
-
* Register a job (frame callback) with a specific root.
|
|
1900
|
-
* This is the core registration method used by useFrame internally.
|
|
1901
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
1902
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
1903
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
1904
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
1905
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
1906
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
1907
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
1908
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
1909
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
1910
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
1911
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
1912
|
-
*/
|
|
1913
|
-
register(callback, options = {}) {
|
|
1914
|
-
const rootId = options.rootId;
|
|
1915
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
1916
|
-
if (!root) {
|
|
1917
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
1918
|
-
return () => {
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
const id = options.id ?? this.generateJobId();
|
|
1922
|
-
let phase = options.phase ?? "update";
|
|
1923
|
-
if (!options.phase && (options.before || options.after)) {
|
|
1924
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
1925
|
-
}
|
|
1926
|
-
const before = this.normalizeConstraints(options.before);
|
|
1927
|
-
const after = this.normalizeConstraints(options.after);
|
|
1928
|
-
const job = {
|
|
1929
|
-
id,
|
|
1930
|
-
callback,
|
|
1931
|
-
phase,
|
|
1932
|
-
before,
|
|
1933
|
-
after,
|
|
1934
|
-
priority: options.priority ?? 0,
|
|
1935
|
-
index: this.nextJobIndex++,
|
|
1936
|
-
fps: options.fps,
|
|
1937
|
-
drop: options.drop ?? true,
|
|
1938
|
-
enabled: options.enabled ?? true,
|
|
1939
|
-
system: options.system ?? false
|
|
1940
|
-
};
|
|
1941
|
-
if (root.jobs.has(id)) {
|
|
1942
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
1943
|
-
}
|
|
1944
|
-
root.jobs.set(id, job);
|
|
1945
|
-
root.needsRebuild = true;
|
|
1946
|
-
return () => this.unregister(id, root.id);
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Unregister a job by its ID.
|
|
1950
|
-
* Searches all roots if rootId is not provided.
|
|
1951
|
-
* @param {string} id - The job ID to unregister
|
|
1952
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
1953
|
-
* @returns {void}
|
|
1954
|
-
*/
|
|
1955
|
-
unregister(id, rootId) {
|
|
1956
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
1957
|
-
if (root?.jobs.delete(id)) {
|
|
1958
|
-
root.needsRebuild = true;
|
|
1959
|
-
this.jobStateListeners.delete(id);
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
/**
|
|
1963
|
-
* Update a job's options dynamically.
|
|
1964
|
-
* Searches all roots to find the job by ID.
|
|
1965
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
1966
|
-
* @param {string} id - The job ID to update
|
|
1967
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
1968
|
-
* @returns {void}
|
|
1969
|
-
*/
|
|
1970
|
-
updateJob(id, options) {
|
|
1971
|
-
let job;
|
|
1972
|
-
let root;
|
|
1973
|
-
for (const r of this.roots.values()) {
|
|
1974
|
-
job = r.jobs.get(id);
|
|
1975
|
-
if (job) {
|
|
1976
|
-
root = r;
|
|
1977
|
-
break;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
if (!job || !root) return;
|
|
1981
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
1982
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
1983
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
1984
|
-
if (options.enabled !== void 0) {
|
|
1985
|
-
const wasEnabled = job.enabled;
|
|
1986
|
-
job.enabled = options.enabled;
|
|
1987
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
1988
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
1989
|
-
}
|
|
1990
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
1991
|
-
if (options.phase) job.phase = options.phase;
|
|
1992
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
1993
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
1994
|
-
root.needsRebuild = true;
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
//* Job State Management Methods ================================
|
|
1998
|
-
/**
|
|
1999
|
-
* Check if a job is currently paused (disabled).
|
|
2000
|
-
* @param {string} id - The job ID to check
|
|
2001
|
-
* @returns {boolean} True if the job exists and is paused
|
|
2002
|
-
*/
|
|
2003
|
-
isJobPaused(id) {
|
|
2004
|
-
for (const root of this.roots.values()) {
|
|
2005
|
-
const job = root.jobs.get(id);
|
|
2006
|
-
if (job) return !job.enabled;
|
|
2007
|
-
}
|
|
2008
|
-
return false;
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Subscribe to state changes for a specific job.
|
|
2012
|
-
* Listener is called when job is paused or resumed.
|
|
2013
|
-
* @param {string} id - The job ID to subscribe to
|
|
2014
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
2015
|
-
* @returns {() => void} Unsubscribe function
|
|
2016
|
-
*/
|
|
2017
|
-
subscribeJobState(id, listener) {
|
|
2018
|
-
if (!this.jobStateListeners.has(id)) {
|
|
2019
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
2020
|
-
}
|
|
2021
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2022
|
-
return () => {
|
|
2023
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2024
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2025
|
-
this.jobStateListeners.delete(id);
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* Notify all listeners that a job's state has changed.
|
|
2031
|
-
* @param {string} id - The job ID that changed
|
|
2032
|
-
* @returns {void}
|
|
2033
|
-
* @private
|
|
2034
|
-
*/
|
|
2035
|
-
notifyJobStateChange(id) {
|
|
2036
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* Pause a job by ID (sets enabled=false).
|
|
2040
|
-
* Notifies any subscribed state listeners.
|
|
2041
|
-
* @param {string} id - The job ID to pause
|
|
2042
|
-
* @returns {void}
|
|
2043
|
-
*/
|
|
2044
|
-
pauseJob(id) {
|
|
2045
|
-
this.updateJob(id, { enabled: false });
|
|
2046
|
-
this.notifyJobStateChange(id);
|
|
2047
|
-
}
|
|
2048
|
-
/**
|
|
2049
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2050
|
-
* Resets job timing to prevent frame accumulation.
|
|
2051
|
-
* Notifies any subscribed state listeners.
|
|
2052
|
-
* @param {string} id - The job ID to resume
|
|
2053
|
-
* @returns {void}
|
|
2054
|
-
*/
|
|
2055
|
-
resumeJob(id) {
|
|
2056
|
-
this.updateJob(id, { enabled: true });
|
|
2057
|
-
this.notifyJobStateChange(id);
|
|
2058
|
-
}
|
|
2059
|
-
//* Frame Loop Control Methods ================================
|
|
2060
|
-
/**
|
|
2061
|
-
* Start the requestAnimationFrame loop.
|
|
2062
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2063
|
-
* No-op if already running.
|
|
2064
|
-
* @returns {void}
|
|
2065
|
-
*/
|
|
2066
|
-
start() {
|
|
2067
|
-
if (this.loopState.running) return;
|
|
2068
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2069
|
-
let adjustedCreated = 0;
|
|
2070
|
-
if (this.stoppedTime > 0) {
|
|
2071
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2072
|
-
this.stoppedTime = 0;
|
|
2073
|
-
}
|
|
2074
|
-
Object.assign(this.loopState, {
|
|
2075
|
-
running: true,
|
|
2076
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2077
|
-
lastTime: performance.now(),
|
|
2078
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2079
|
-
frameCount: 0,
|
|
2080
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
/**
|
|
2084
|
-
* Stop the requestAnimationFrame loop.
|
|
2085
|
-
* Cancels any pending RAF callback.
|
|
2086
|
-
* No-op if not running.
|
|
2087
|
-
* @returns {void}
|
|
2088
|
-
*/
|
|
2089
|
-
stop() {
|
|
2090
|
-
if (!this.loopState.running) return;
|
|
2091
|
-
this.loopState.running = false;
|
|
2092
|
-
if (this.loopState.rafHandle !== null) {
|
|
2093
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2094
|
-
this.loopState.rafHandle = null;
|
|
2095
|
-
}
|
|
2096
|
-
this.stoppedTime = performance.now();
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Request frames to be rendered in demand mode.
|
|
2100
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2101
|
-
* No-op if frameloop is not 'demand'.
|
|
2102
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2103
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2104
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2105
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2106
|
-
* @returns {void}
|
|
2107
|
-
* @example
|
|
2108
|
-
* // Request a single frame render
|
|
2109
|
-
* scheduler.invalidate();
|
|
2110
|
-
*
|
|
2111
|
-
* @example
|
|
2112
|
-
* // Request 5 frames (e.g., for animations)
|
|
2113
|
-
* scheduler.invalidate(5);
|
|
2114
|
-
*
|
|
2115
|
-
* @example
|
|
2116
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2117
|
-
* scheduler.invalidate(3, false);
|
|
2118
|
-
*
|
|
2119
|
-
* @example
|
|
2120
|
-
* // Add 2 more frames to existing pending count
|
|
2121
|
-
* scheduler.invalidate(2, true);
|
|
2122
|
-
*/
|
|
2123
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2124
|
-
if (this._frameloop !== "demand") return;
|
|
2125
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2126
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2127
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2128
|
-
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Reset timing state for deterministic testing.
|
|
2131
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2132
|
-
* @returns {void}
|
|
2133
|
-
*/
|
|
2134
|
-
resetTiming() {
|
|
2135
|
-
this.loopState.lastTime = null;
|
|
2136
|
-
this.loopState.frameCount = 0;
|
|
2137
|
-
this.loopState.elapsedTime = 0;
|
|
2138
|
-
this.loopState.createdAt = performance.now();
|
|
2139
|
-
}
|
|
2140
|
-
//* Manual Stepping Methods ================================
|
|
2141
|
-
/**
|
|
2142
|
-
* Manually execute a single frame for all roots.
|
|
2143
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2144
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2145
|
-
* @returns {void}
|
|
2146
|
-
* @example
|
|
2147
|
-
* // Manual control mode
|
|
2148
|
-
* scheduler.frameloop = 'never';
|
|
2149
|
-
* scheduler.step(); // Execute one frame
|
|
2150
|
-
*/
|
|
2151
|
-
step(timestamp) {
|
|
2152
|
-
const now = timestamp ?? performance.now();
|
|
2153
|
-
this.executeFrame(now);
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Manually execute a single job by its ID.
|
|
2157
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2158
|
-
* @param {string} id - The job ID to step
|
|
2159
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2160
|
-
* @returns {void}
|
|
2161
|
-
*/
|
|
2162
|
-
stepJob(id, timestamp) {
|
|
2163
|
-
let job;
|
|
2164
|
-
let root;
|
|
2165
|
-
for (const r of this.roots.values()) {
|
|
2166
|
-
job = r.jobs.get(id);
|
|
2167
|
-
if (job) {
|
|
2168
|
-
root = r;
|
|
2169
|
-
break;
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
if (!job || !root) {
|
|
2173
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2174
|
-
return;
|
|
2175
|
-
}
|
|
2176
|
-
const now = timestamp ?? performance.now();
|
|
2177
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2178
|
-
const delta = deltaMs / 1e3;
|
|
2179
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2180
|
-
const providedState = root.getState?.() ?? {};
|
|
2181
|
-
const frameState = {
|
|
2182
|
-
...providedState,
|
|
2183
|
-
time: now,
|
|
2184
|
-
delta,
|
|
2185
|
-
elapsed,
|
|
2186
|
-
frame: this.loopState.frameCount
|
|
2187
|
-
};
|
|
2188
|
-
try {
|
|
2189
|
-
job.callback(frameState, delta);
|
|
2190
|
-
} catch (error) {
|
|
2191
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2192
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
/**
|
|
2196
|
-
* Execute a single frame across all roots.
|
|
2197
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2198
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2199
|
-
* @returns {void}
|
|
2200
|
-
* @private
|
|
2201
|
-
*/
|
|
2202
|
-
executeFrame(timestamp) {
|
|
2203
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2204
|
-
const delta = deltaMs / 1e3;
|
|
2205
|
-
this.loopState.lastTime = timestamp;
|
|
2206
|
-
this.loopState.frameCount++;
|
|
2207
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2208
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2209
|
-
for (const root of this.roots.values()) {
|
|
2210
|
-
this.tickRoot(root, timestamp, delta);
|
|
2211
|
-
}
|
|
2212
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Run all global jobs from a job map.
|
|
2216
|
-
* Catches and logs errors without stopping execution.
|
|
2217
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2218
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2219
|
-
* @returns {void}
|
|
2220
|
-
* @private
|
|
2221
|
-
*/
|
|
2222
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2223
|
-
for (const job of jobs.values()) {
|
|
2224
|
-
try {
|
|
2225
|
-
job.callback(timestamp);
|
|
2226
|
-
} catch (error) {
|
|
2227
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
/**
|
|
2232
|
-
* Execute all jobs for a single root in sorted order.
|
|
2233
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2234
|
-
* Errors are caught and propagated via triggerError.
|
|
2235
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2236
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2237
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2238
|
-
* @returns {void}
|
|
2239
|
-
* @private
|
|
2240
|
-
*/
|
|
2241
|
-
tickRoot(root, timestamp, delta) {
|
|
2242
|
-
if (root.needsRebuild) {
|
|
2243
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2244
|
-
root.needsRebuild = false;
|
|
2245
|
-
}
|
|
2246
|
-
const providedState = root.getState?.() ?? {};
|
|
2247
|
-
const frameState = {
|
|
2248
|
-
...providedState,
|
|
2249
|
-
time: timestamp,
|
|
2250
|
-
delta,
|
|
2251
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2252
|
-
// Convert ms to seconds
|
|
2253
|
-
frame: this.loopState.frameCount
|
|
2254
|
-
};
|
|
2255
|
-
for (const job of root.sortedJobs) {
|
|
2256
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2257
|
-
try {
|
|
2258
|
-
job.callback(frameState, delta);
|
|
2259
|
-
} catch (error) {
|
|
2260
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2261
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
//* Debug & Inspection Methods ================================
|
|
2266
|
-
/**
|
|
2267
|
-
* Get the total number of registered jobs across all roots.
|
|
2268
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2269
|
-
* @returns {number} Total job count
|
|
2270
|
-
*/
|
|
2271
|
-
getJobCount() {
|
|
2272
|
-
let count = 0;
|
|
2273
|
-
for (const root of this.roots.values()) {
|
|
2274
|
-
count += root.jobs.size;
|
|
2275
|
-
}
|
|
2276
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2277
|
-
}
|
|
2278
|
-
/**
|
|
2279
|
-
* Get all registered job IDs across all roots.
|
|
2280
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2281
|
-
* @returns {string[]} Array of all job IDs
|
|
2282
|
-
*/
|
|
2283
|
-
getJobIds() {
|
|
2284
|
-
const ids = [];
|
|
2285
|
-
for (const root of this.roots.values()) {
|
|
2286
|
-
ids.push(...root.jobs.keys());
|
|
2287
|
-
}
|
|
2288
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2289
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2290
|
-
return ids;
|
|
2291
|
-
}
|
|
2292
|
-
/**
|
|
2293
|
-
* Get the number of registered roots (Canvas instances).
|
|
2294
|
-
* @returns {number} Number of registered roots
|
|
2295
|
-
*/
|
|
2296
|
-
getRootCount() {
|
|
2297
|
-
return this.roots.size;
|
|
2298
|
-
}
|
|
2299
|
-
/**
|
|
2300
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2301
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2302
|
-
*
|
|
2303
|
-
* @param phase The phase to check
|
|
2304
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2305
|
-
* @returns true if any user jobs exist in the phase
|
|
2306
|
-
*/
|
|
2307
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2308
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2309
|
-
return rootsToCheck.some((root) => {
|
|
2310
|
-
if (!root) return false;
|
|
2311
|
-
for (const job of root.jobs.values()) {
|
|
2312
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2313
|
-
}
|
|
2314
|
-
return false;
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
//* Utility Methods ================================
|
|
2318
|
-
/**
|
|
2319
|
-
* Generate a unique root ID for automatic root registration.
|
|
2320
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2321
|
-
*/
|
|
2322
|
-
generateRootId() {
|
|
2323
|
-
return `root_${this.nextRootIndex++}`;
|
|
2324
|
-
}
|
|
2325
|
-
/**
|
|
2326
|
-
* Generate a unique job ID.
|
|
2327
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2328
|
-
* @private
|
|
2329
|
-
*/
|
|
2330
|
-
generateJobId() {
|
|
2331
|
-
return `job_${this.nextJobIndex}`;
|
|
2332
|
-
}
|
|
2333
|
-
/**
|
|
2334
|
-
* Normalize before/after constraints to a Set.
|
|
2335
|
-
* Handles undefined, single string, or array inputs.
|
|
2336
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2337
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2338
|
-
* @private
|
|
2339
|
-
*/
|
|
2340
|
-
normalizeConstraints(value) {
|
|
2341
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2342
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2343
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2344
|
-
}
|
|
2345
|
-
};
|
|
2346
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2347
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2348
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2349
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2350
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2351
|
-
let Scheduler = _Scheduler;
|
|
2352
|
-
const getScheduler = () => Scheduler.get();
|
|
2353
|
-
if (hmrData) {
|
|
2354
|
-
hmrData.accept?.();
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
function useFrame(callback, priorityOrOptions) {
|
|
2358
|
-
const store = React__namespace.useContext(context);
|
|
2359
|
-
const isInsideCanvas = store !== null;
|
|
2360
|
-
const scheduler = getScheduler();
|
|
2361
|
-
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2362
|
-
id: priorityOrOptions.id,
|
|
2363
|
-
phase: priorityOrOptions.phase,
|
|
2364
|
-
priority: priorityOrOptions.priority,
|
|
2365
|
-
fps: priorityOrOptions.fps,
|
|
2366
|
-
drop: priorityOrOptions.drop,
|
|
2367
|
-
enabled: priorityOrOptions.enabled,
|
|
2368
|
-
before: priorityOrOptions.before,
|
|
2369
|
-
after: priorityOrOptions.after
|
|
2370
|
-
}) : "";
|
|
2371
|
-
const options = React__namespace.useMemo(() => {
|
|
2372
|
-
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
2373
|
-
}, [optionsKey]);
|
|
2374
|
-
const reactId = React__namespace.useId();
|
|
2375
|
-
const id = options.id ?? reactId;
|
|
2376
|
-
const callbackRef = useMutableCallback(callback);
|
|
2377
|
-
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
2378
|
-
useIsomorphicLayoutEffect(() => {
|
|
2379
|
-
if (!callback) return;
|
|
2380
|
-
if (isInsideCanvas) {
|
|
2381
|
-
const state = store.getState();
|
|
2382
|
-
const rootId = state.internal.rootId;
|
|
2383
|
-
if (isLegacyPriority) {
|
|
2384
|
-
state.internal.priority++;
|
|
2385
|
-
let parentRoot = state.previousRoot;
|
|
2386
|
-
while (parentRoot) {
|
|
2387
|
-
const parentState = parentRoot.getState();
|
|
2388
|
-
if (parentState?.internal) parentState.internal.priority++;
|
|
2389
|
-
parentRoot = parentState?.previousRoot;
|
|
2390
|
-
}
|
|
2391
|
-
notifyDepreciated({
|
|
2392
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
2393
|
-
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within update phase, use: useFrame(callback, { priority: number })',
|
|
2394
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2395
|
-
});
|
|
2031
|
+
function useFrame(callback, priorityOrOptions) {
|
|
2032
|
+
const store = React__namespace.useContext(context);
|
|
2033
|
+
const isInsideCanvas = store !== null;
|
|
2034
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
2035
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2036
|
+
id: priorityOrOptions.id,
|
|
2037
|
+
phase: priorityOrOptions.phase,
|
|
2038
|
+
priority: priorityOrOptions.priority,
|
|
2039
|
+
fps: priorityOrOptions.fps,
|
|
2040
|
+
drop: priorityOrOptions.drop,
|
|
2041
|
+
enabled: priorityOrOptions.enabled,
|
|
2042
|
+
before: priorityOrOptions.before,
|
|
2043
|
+
after: priorityOrOptions.after
|
|
2044
|
+
}) : "";
|
|
2045
|
+
const options = React__namespace.useMemo(() => {
|
|
2046
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
2047
|
+
}, [optionsKey]);
|
|
2048
|
+
const reactId = React__namespace.useId();
|
|
2049
|
+
const id = options.id ?? reactId;
|
|
2050
|
+
const callbackRef = useMutableCallback(callback);
|
|
2051
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
2052
|
+
useIsomorphicLayoutEffect(() => {
|
|
2053
|
+
if (!callback) return;
|
|
2054
|
+
if (isInsideCanvas) {
|
|
2055
|
+
const state = store.getState();
|
|
2056
|
+
const rootId = state.internal.rootId;
|
|
2057
|
+
if (isLegacyPriority) {
|
|
2058
|
+
state.internal.priority++;
|
|
2059
|
+
let parentRoot = state.previousRoot;
|
|
2060
|
+
while (parentRoot) {
|
|
2061
|
+
const parentState = parentRoot.getState();
|
|
2062
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
2063
|
+
parentRoot = parentState?.previousRoot;
|
|
2064
|
+
}
|
|
2065
|
+
notifyDepreciated({
|
|
2066
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
2067
|
+
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within update phase, use: useFrame(callback, { priority: number })',
|
|
2068
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2069
|
+
});
|
|
2396
2070
|
}
|
|
2397
2071
|
const wrappedCallback = (frameState, delta) => {
|
|
2398
2072
|
const localState = store.getState();
|
|
@@ -2405,7 +2079,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2405
2079
|
};
|
|
2406
2080
|
callbackRef.current?.(mergedState, delta);
|
|
2407
2081
|
};
|
|
2408
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2082
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2409
2083
|
id,
|
|
2410
2084
|
rootId,
|
|
2411
2085
|
...options
|
|
@@ -2426,37 +2100,31 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2426
2100
|
}
|
|
2427
2101
|
};
|
|
2428
2102
|
} else {
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
unregisterJob = registerOutside();
|
|
2438
|
-
});
|
|
2439
|
-
return () => {
|
|
2440
|
-
unsubReady();
|
|
2441
|
-
unregisterJob?.();
|
|
2442
|
-
};
|
|
2103
|
+
return scheduler$1.register(
|
|
2104
|
+
(state, delta) => {
|
|
2105
|
+
const frameState = state;
|
|
2106
|
+
if (!frameState.renderer) return;
|
|
2107
|
+
callbackRef.current?.(frameState, delta);
|
|
2108
|
+
},
|
|
2109
|
+
{ id, ...options }
|
|
2110
|
+
);
|
|
2443
2111
|
}
|
|
2444
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2112
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2445
2113
|
const isPaused = React__namespace.useSyncExternalStore(
|
|
2446
2114
|
// Subscribe function
|
|
2447
2115
|
React__namespace.useCallback(
|
|
2448
2116
|
(onStoreChange) => {
|
|
2449
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2117
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2450
2118
|
},
|
|
2451
2119
|
[id]
|
|
2452
2120
|
),
|
|
2453
2121
|
// getSnapshot function
|
|
2454
|
-
React__namespace.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2122
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2455
2123
|
// getServerSnapshot function (SSR)
|
|
2456
2124
|
React__namespace.useCallback(() => false, [])
|
|
2457
2125
|
);
|
|
2458
2126
|
const controls = React__namespace.useMemo(() => {
|
|
2459
|
-
const scheduler2 = getScheduler();
|
|
2127
|
+
const scheduler2 = scheduler.getScheduler();
|
|
2460
2128
|
return {
|
|
2461
2129
|
/** The job's unique ID */
|
|
2462
2130
|
id,
|
|
@@ -2471,7 +2139,7 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2471
2139
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2472
2140
|
*/
|
|
2473
2141
|
step: (timestamp) => {
|
|
2474
|
-
getScheduler().stepJob(id, timestamp);
|
|
2142
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
2475
2143
|
},
|
|
2476
2144
|
/**
|
|
2477
2145
|
* Manually step ALL jobs in the scheduler.
|
|
@@ -2479,20 +2147,20 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2479
2147
|
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2480
2148
|
*/
|
|
2481
2149
|
stepAll: (timestamp) => {
|
|
2482
|
-
getScheduler().step(timestamp);
|
|
2150
|
+
scheduler.getScheduler().step(timestamp);
|
|
2483
2151
|
},
|
|
2484
2152
|
/**
|
|
2485
2153
|
* Pause this job (set enabled=false).
|
|
2486
2154
|
* Job remains registered but won't run.
|
|
2487
2155
|
*/
|
|
2488
2156
|
pause: () => {
|
|
2489
|
-
getScheduler().pauseJob(id);
|
|
2157
|
+
scheduler.getScheduler().pauseJob(id);
|
|
2490
2158
|
},
|
|
2491
2159
|
/**
|
|
2492
2160
|
* Resume this job (set enabled=true).
|
|
2493
2161
|
*/
|
|
2494
2162
|
resume: () => {
|
|
2495
|
-
getScheduler().resumeJob(id);
|
|
2163
|
+
scheduler.getScheduler().resumeJob(id);
|
|
2496
2164
|
},
|
|
2497
2165
|
/**
|
|
2498
2166
|
* Reactive paused state - automatically updates when pause/resume is called.
|
|
@@ -2530,22 +2198,29 @@ function buildFromCache(input, textureCache) {
|
|
|
2530
2198
|
function useTexture(input, optionsOrOnLoad) {
|
|
2531
2199
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2532
2200
|
const store = useStore();
|
|
2533
|
-
const textureCache = useThree((state) => state.textures);
|
|
2534
2201
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2535
|
-
const { onLoad, cache =
|
|
2202
|
+
const { onLoad, cache = true } = options;
|
|
2203
|
+
const onLoadRef = React.useRef(onLoad);
|
|
2204
|
+
onLoadRef.current = onLoad;
|
|
2205
|
+
const onLoadCalledForRef = React.useRef(null);
|
|
2536
2206
|
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2537
2207
|
const cachedResult = React.useMemo(() => {
|
|
2538
2208
|
if (!cache) return null;
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2209
|
+
const textures = store.getState().textures;
|
|
2210
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2211
|
+
return buildFromCache(input, textures);
|
|
2212
|
+
}, [cache, urls, input, store]);
|
|
2542
2213
|
const loadedTextures = useLoader(
|
|
2543
2214
|
webgpu.TextureLoader,
|
|
2544
2215
|
IsObject(input) ? Object.values(input) : input
|
|
2545
2216
|
);
|
|
2217
|
+
const inputKey = urls.join("\0");
|
|
2546
2218
|
React.useLayoutEffect(() => {
|
|
2547
|
-
if (
|
|
2548
|
-
|
|
2219
|
+
if (cachedResult) return;
|
|
2220
|
+
if (onLoadCalledForRef.current === inputKey) return;
|
|
2221
|
+
onLoadCalledForRef.current = inputKey;
|
|
2222
|
+
onLoadRef.current?.(loadedTextures);
|
|
2223
|
+
}, [cachedResult, loadedTextures, inputKey]);
|
|
2549
2224
|
React.useEffect(() => {
|
|
2550
2225
|
if (cachedResult) return;
|
|
2551
2226
|
if ("initTexture" in renderer) {
|
|
@@ -2578,8 +2253,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
2578
2253
|
}, [input, loadedTextures, cachedResult]);
|
|
2579
2254
|
React.useEffect(() => {
|
|
2580
2255
|
if (!cache) return;
|
|
2581
|
-
if (cachedResult) return;
|
|
2582
|
-
const set = store.setState;
|
|
2583
2256
|
const urlTextureMap = [];
|
|
2584
2257
|
if (typeof input === "string") {
|
|
2585
2258
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -2593,18 +2266,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
2593
2266
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
2594
2267
|
}
|
|
2595
2268
|
}
|
|
2596
|
-
|
|
2597
|
-
const
|
|
2598
|
-
let
|
|
2269
|
+
store.setState((state) => {
|
|
2270
|
+
const refs = new Map(state._textureRefs);
|
|
2271
|
+
let textures = state.textures;
|
|
2272
|
+
let added = false;
|
|
2599
2273
|
for (const [url, texture] of urlTextureMap) {
|
|
2600
|
-
if (!
|
|
2601
|
-
|
|
2602
|
-
|
|
2274
|
+
if (!textures.has(url)) {
|
|
2275
|
+
if (!added) {
|
|
2276
|
+
textures = new Map(textures);
|
|
2277
|
+
added = true;
|
|
2278
|
+
}
|
|
2279
|
+
textures.set(url, texture);
|
|
2603
2280
|
}
|
|
2281
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2604
2282
|
}
|
|
2605
|
-
return
|
|
2283
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2284
|
+
});
|
|
2285
|
+
return () => store.setState((state) => {
|
|
2286
|
+
const refs = new Map(state._textureRefs);
|
|
2287
|
+
for (const [url] of urlTextureMap) {
|
|
2288
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2289
|
+
if (next <= 0) refs.delete(url);
|
|
2290
|
+
else refs.set(url, next);
|
|
2291
|
+
}
|
|
2292
|
+
return { _textureRefs: refs };
|
|
2606
2293
|
});
|
|
2607
|
-
}, [cache, input, mappedTextures, store
|
|
2294
|
+
}, [cache, input, mappedTextures, store]);
|
|
2608
2295
|
return mappedTextures;
|
|
2609
2296
|
}
|
|
2610
2297
|
useTexture.preload = (url) => useLoader.preload(webgpu.TextureLoader, url);
|
|
@@ -2620,106 +2307,90 @@ const Texture = ({
|
|
|
2620
2307
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
2621
2308
|
};
|
|
2622
2309
|
|
|
2623
|
-
function
|
|
2624
|
-
if (entry instanceof webgpu.Texture) return entry;
|
|
2625
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof webgpu.Texture) {
|
|
2626
|
-
return entry.value;
|
|
2627
|
-
}
|
|
2628
|
-
return null;
|
|
2629
|
-
}
|
|
2630
|
-
function useTextures() {
|
|
2310
|
+
function useTextures(selector) {
|
|
2631
2311
|
const store = useStore();
|
|
2632
|
-
|
|
2633
|
-
const set = store.setState;
|
|
2312
|
+
const registry = React.useMemo(() => {
|
|
2634
2313
|
const getState = store.getState;
|
|
2635
|
-
const
|
|
2636
|
-
|
|
2637
|
-
const newMap = new Map(state.textures);
|
|
2638
|
-
newMap.set(key, value);
|
|
2639
|
-
return { textures: newMap };
|
|
2640
|
-
});
|
|
2641
|
-
};
|
|
2642
|
-
const addMultiple = (items) => {
|
|
2643
|
-
set((state) => {
|
|
2644
|
-
const newMap = new Map(state.textures);
|
|
2645
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
2646
|
-
for (const [key, value] of entries) {
|
|
2647
|
-
newMap.set(key, value);
|
|
2648
|
-
}
|
|
2649
|
-
return { textures: newMap };
|
|
2650
|
-
});
|
|
2651
|
-
};
|
|
2652
|
-
const remove = (key) => {
|
|
2653
|
-
set((state) => {
|
|
2654
|
-
const newMap = new Map(state.textures);
|
|
2655
|
-
newMap.delete(key);
|
|
2656
|
-
return { textures: newMap };
|
|
2657
|
-
});
|
|
2658
|
-
};
|
|
2659
|
-
const removeMultiple = (keys) => {
|
|
2660
|
-
set((state) => {
|
|
2661
|
-
const newMap = new Map(state.textures);
|
|
2662
|
-
for (const key of keys) newMap.delete(key);
|
|
2663
|
-
return { textures: newMap };
|
|
2664
|
-
});
|
|
2665
|
-
};
|
|
2666
|
-
const dispose = (key) => {
|
|
2667
|
-
const entry = getState().textures.get(key);
|
|
2668
|
-
if (entry) {
|
|
2669
|
-
const tex = getTextureValue(entry);
|
|
2670
|
-
tex?.dispose();
|
|
2671
|
-
}
|
|
2672
|
-
remove(key);
|
|
2673
|
-
};
|
|
2674
|
-
const disposeMultiple = (keys) => {
|
|
2675
|
-
const textures = getState().textures;
|
|
2676
|
-
for (const key of keys) {
|
|
2677
|
-
const entry = textures.get(key);
|
|
2678
|
-
if (entry) {
|
|
2679
|
-
const tex = getTextureValue(entry);
|
|
2680
|
-
tex?.dispose();
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
removeMultiple(keys);
|
|
2684
|
-
};
|
|
2685
|
-
const disposeAll = () => {
|
|
2686
|
-
const textures = getState().textures;
|
|
2687
|
-
for (const entry of textures.values()) {
|
|
2688
|
-
const tex = getTextureValue(entry);
|
|
2689
|
-
tex?.dispose();
|
|
2690
|
-
}
|
|
2691
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
2692
|
-
};
|
|
2314
|
+
const setState = store.setState;
|
|
2315
|
+
const getOne = (key) => getState().textures.get(key);
|
|
2693
2316
|
return {
|
|
2694
|
-
|
|
2695
|
-
get textures() {
|
|
2317
|
+
get all() {
|
|
2696
2318
|
return getState().textures;
|
|
2697
2319
|
},
|
|
2698
|
-
|
|
2699
|
-
|
|
2320
|
+
get(input) {
|
|
2321
|
+
if (typeof input === "string") return getOne(input);
|
|
2322
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2323
|
+
const out = {};
|
|
2324
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2325
|
+
return out;
|
|
2326
|
+
},
|
|
2700
2327
|
has: (key) => getState().textures.has(key),
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2328
|
+
add(keyOrRecord, texture) {
|
|
2329
|
+
setState((state) => {
|
|
2330
|
+
const textures = new Map(state.textures);
|
|
2331
|
+
if (typeof keyOrRecord === "string") {
|
|
2332
|
+
textures.set(keyOrRecord, texture);
|
|
2333
|
+
} else {
|
|
2334
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2335
|
+
}
|
|
2336
|
+
return { textures };
|
|
2337
|
+
});
|
|
2338
|
+
},
|
|
2339
|
+
dispose(key, options) {
|
|
2340
|
+
const state = getState();
|
|
2341
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2342
|
+
if (refs > 0 && !options?.force) {
|
|
2343
|
+
console.warn(
|
|
2344
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2345
|
+
);
|
|
2346
|
+
return false;
|
|
2347
|
+
}
|
|
2348
|
+
state.textures.get(key)?.dispose();
|
|
2349
|
+
setState((s) => {
|
|
2350
|
+
const textures = new Map(s.textures);
|
|
2351
|
+
textures.delete(key);
|
|
2352
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2353
|
+
nextRefs.delete(key);
|
|
2354
|
+
return { textures, _textureRefs: nextRefs };
|
|
2355
|
+
});
|
|
2356
|
+
return true;
|
|
2357
|
+
},
|
|
2358
|
+
disposeAll() {
|
|
2359
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2360
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2361
|
+
}
|
|
2711
2362
|
};
|
|
2712
2363
|
}, [store]);
|
|
2364
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2365
|
+
const selected = useThree(subscribe);
|
|
2366
|
+
return selector ? selected : registry;
|
|
2713
2367
|
}
|
|
2714
2368
|
|
|
2715
|
-
function useRenderTarget(
|
|
2369
|
+
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2716
2370
|
const isLegacy = useThree((s) => s.isLegacy);
|
|
2717
2371
|
const size = useThree((s) => s.size);
|
|
2372
|
+
let width;
|
|
2373
|
+
let height;
|
|
2374
|
+
let opts;
|
|
2375
|
+
if (typeof widthOrOptions === "object") {
|
|
2376
|
+
opts = widthOrOptions;
|
|
2377
|
+
} else if (typeof widthOrOptions === "number") {
|
|
2378
|
+
width = widthOrOptions;
|
|
2379
|
+
if (typeof heightOrOptions === "object") {
|
|
2380
|
+
height = widthOrOptions;
|
|
2381
|
+
opts = heightOrOptions;
|
|
2382
|
+
} else if (typeof heightOrOptions === "number") {
|
|
2383
|
+
height = heightOrOptions;
|
|
2384
|
+
opts = options;
|
|
2385
|
+
} else {
|
|
2386
|
+
height = widthOrOptions;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2718
2389
|
return React.useMemo(() => {
|
|
2719
2390
|
const w = width ?? size.width;
|
|
2720
2391
|
const h = height ?? size.height;
|
|
2721
|
-
return new webgpu.RenderTarget(w, h,
|
|
2722
|
-
}, [width, height, size.width, size.height,
|
|
2392
|
+
return new webgpu.RenderTarget(w, h, opts);
|
|
2393
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2723
2394
|
}
|
|
2724
2395
|
|
|
2725
2396
|
function useStore() {
|
|
@@ -2747,7 +2418,7 @@ function addEffect(callback) {
|
|
|
2747
2418
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2748
2419
|
});
|
|
2749
2420
|
const id = `legacy_effect_${effectId++}`;
|
|
2750
|
-
return getScheduler().registerGlobal("before", id, callback);
|
|
2421
|
+
return scheduler.getScheduler().registerGlobal("before", id, callback);
|
|
2751
2422
|
}
|
|
2752
2423
|
function addAfterEffect(callback) {
|
|
2753
2424
|
notifyDepreciated({
|
|
@@ -2756,7 +2427,7 @@ function addAfterEffect(callback) {
|
|
|
2756
2427
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2757
2428
|
});
|
|
2758
2429
|
const id = `legacy_afterEffect_${effectId++}`;
|
|
2759
|
-
return getScheduler().registerGlobal("after", id, callback);
|
|
2430
|
+
return scheduler.getScheduler().registerGlobal("after", id, callback);
|
|
2760
2431
|
}
|
|
2761
2432
|
function addTail(callback) {
|
|
2762
2433
|
notifyDepreciated({
|
|
@@ -2764,33 +2435,23 @@ function addTail(callback) {
|
|
|
2764
2435
|
body: "Use scheduler.onIdle(callback) instead.\naddTail will be removed in a future version.",
|
|
2765
2436
|
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2766
2437
|
});
|
|
2767
|
-
return getScheduler().onIdle(callback);
|
|
2438
|
+
return scheduler.getScheduler().onIdle(callback);
|
|
2768
2439
|
}
|
|
2769
2440
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
2770
|
-
getScheduler().invalidate(frames, stackFrames);
|
|
2441
|
+
scheduler.getScheduler().invalidate(frames, stackFrames);
|
|
2771
2442
|
}
|
|
2772
|
-
function advance(timestamp
|
|
2773
|
-
getScheduler().step(timestamp);
|
|
2443
|
+
function advance(timestamp) {
|
|
2444
|
+
scheduler.getScheduler().step(timestamp);
|
|
2774
2445
|
}
|
|
2775
2446
|
|
|
2776
|
-
const version = "10.0.0-alpha.
|
|
2447
|
+
const version = "10.0.0-alpha.3";
|
|
2777
2448
|
const packageData = {
|
|
2778
2449
|
version: version};
|
|
2779
2450
|
|
|
2780
2451
|
function Xb(Tt) {
|
|
2781
2452
|
return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
|
|
2782
2453
|
}
|
|
2783
|
-
var Rm = { exports: {} }, Og = { exports: {} };
|
|
2784
|
-
/**
|
|
2785
|
-
* @license React
|
|
2786
|
-
* react-reconciler.production.js
|
|
2787
|
-
*
|
|
2788
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2789
|
-
*
|
|
2790
|
-
* This source code is licensed under the MIT license found in the
|
|
2791
|
-
* LICENSE file in the root directory of this source tree.
|
|
2792
|
-
*/
|
|
2793
|
-
var _b;
|
|
2454
|
+
var Rm = { exports: {} }, Og = { exports: {} }, _b;
|
|
2794
2455
|
function Kb() {
|
|
2795
2456
|
return _b || (_b = 1, (function(Tt) {
|
|
2796
2457
|
Tt.exports = function(m) {
|
|
@@ -3862,7 +3523,6 @@ Error generating stack: ` + l.message + `
|
|
|
3862
3523
|
if (J === cl || J === jc) throw J;
|
|
3863
3524
|
var Ge = Yn(29, J, null, P.mode);
|
|
3864
3525
|
return Ge.lanes = H, Ge.return = P, Ge;
|
|
3865
|
-
} finally {
|
|
3866
3526
|
}
|
|
3867
3527
|
};
|
|
3868
3528
|
}
|
|
@@ -4516,7 +4176,6 @@ Error generating stack: ` + l.message + `
|
|
|
4516
4176
|
var h = r.lastRenderedState, y = d(h, a);
|
|
4517
4177
|
if (c.hasEagerState = true, c.eagerState = y, jn(y, h)) return go(t, r, c, 0), Ne === null && Bn(), false;
|
|
4518
4178
|
} catch {
|
|
4519
|
-
} finally {
|
|
4520
4179
|
}
|
|
4521
4180
|
if (a = yo(t, r, c, l), a !== null) return nt(a, t, l), ns(a, r, l), true;
|
|
4522
4181
|
}
|
|
@@ -6937,10 +6596,7 @@ Error generating stack: ` + l.message + `
|
|
|
6937
6596
|
function vr(t, r) {
|
|
6938
6597
|
Sf(t, r), (t = t.alternate) && Sf(t, r);
|
|
6939
6598
|
}
|
|
6940
|
-
var ie = {}, Fm = React__default, tt = Tb__default, Lt = Object.assign, hc = Symbol.for("react.element"), zs = Symbol.for("react.transitional.element"), sa = Symbol.for("react.portal"), $a = Symbol.for("react.fragment"), kf = Symbol.for("react.strict_mode"), Cs = Symbol.for("react.profiler"), mc = Symbol.for("react.consumer"), Io = Symbol.for("react.context"), Zi = Symbol.for("react.forward_ref"), Va = Symbol.for("react.suspense"), Te = Symbol.for("react.suspense_list"), wf = Symbol.for("react.memo"), ua = Symbol.for("react.lazy");
|
|
6941
|
-
var gc = Symbol.for("react.activity");
|
|
6942
|
-
var $r = Symbol.for("react.memo_cache_sentinel");
|
|
6943
|
-
var Pf = Symbol.iterator, xf = Symbol.for("react.client.reference"), ca = Array.isArray, M = Fm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Yp = m.rendererVersion, zf = m.rendererPackageName, Cf = m.extraDevToolsConfig, Ts = m.getPublicInstance, Hm = m.getRootHostContext, Xp = m.getChildHostContext, Am = m.prepareForCommit, _s = m.resetAfterCommit, Vr = m.createInstance;
|
|
6599
|
+
var ie = {}, Fm = React__default, tt = Tb__default, Lt = Object.assign, hc = Symbol.for("react.element"), zs = Symbol.for("react.transitional.element"), sa = Symbol.for("react.portal"), $a = Symbol.for("react.fragment"), kf = Symbol.for("react.strict_mode"), Cs = Symbol.for("react.profiler"), mc = Symbol.for("react.consumer"), Io = Symbol.for("react.context"), Zi = Symbol.for("react.forward_ref"), Va = Symbol.for("react.suspense"), Te = Symbol.for("react.suspense_list"), wf = Symbol.for("react.memo"), ua = Symbol.for("react.lazy"), gc = Symbol.for("react.activity"), $r = Symbol.for("react.memo_cache_sentinel"), Pf = Symbol.iterator, xf = Symbol.for("react.client.reference"), ca = Array.isArray, M = Fm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Yp = m.rendererVersion, zf = m.rendererPackageName, Cf = m.extraDevToolsConfig, Ts = m.getPublicInstance, Hm = m.getRootHostContext, Xp = m.getChildHostContext, Am = m.prepareForCommit, _s = m.resetAfterCommit, Vr = m.createInstance;
|
|
6944
6600
|
m.cloneMutableInstance;
|
|
6945
6601
|
var yc = m.appendInitialChild, Kp = m.finalizeInitialChildren, Rs = m.shouldSetTextContent, bc = m.createTextInstance;
|
|
6946
6602
|
m.cloneMutableTextInstance;
|
|
@@ -7309,17 +6965,7 @@ No matching component was found for:
|
|
|
7309
6965
|
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true });
|
|
7310
6966
|
})(Og)), Og.exports;
|
|
7311
6967
|
}
|
|
7312
|
-
var Mg = { exports: {} };
|
|
7313
|
-
/**
|
|
7314
|
-
* @license React
|
|
7315
|
-
* react-reconciler.development.js
|
|
7316
|
-
*
|
|
7317
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7318
|
-
*
|
|
7319
|
-
* This source code is licensed under the MIT license found in the
|
|
7320
|
-
* LICENSE file in the root directory of this source tree.
|
|
7321
|
-
*/
|
|
7322
|
-
var Rb;
|
|
6968
|
+
var Mg = { exports: {} }, Rb;
|
|
7323
6969
|
function e0() {
|
|
7324
6970
|
return Rb || (Rb = 1, (function(Tt) {
|
|
7325
6971
|
process.env.NODE_ENV !== "production" && (Tt.exports = function(m) {
|
|
@@ -13086,10 +12732,7 @@ Check the render method of %s.`, G(di) || "Unknown")), i = zo(n), i.payload = {
|
|
|
13086
12732
|
function Ic() {
|
|
13087
12733
|
return di;
|
|
13088
12734
|
}
|
|
13089
|
-
var le = {}, qm = React__default, St = Tb__default, ze = Object.assign, Uh = Symbol.for("react.element"), Ho = Symbol.for("react.transitional.element"), Ao = Symbol.for("react.portal"), ol = Symbol.for("react.fragment"), Lc = Symbol.for("react.strict_mode"), Uf = Symbol.for("react.profiler"), ei = Symbol.for("react.consumer"), on = Symbol.for("react.context"), jn = Symbol.for("react.forward_ref"), Nc = Symbol.for("react.suspense"), Bf = Symbol.for("react.suspense_list"), al = Symbol.for("react.memo"), kt = Symbol.for("react.lazy");
|
|
13090
|
-
var Ds = Symbol.for("react.activity");
|
|
13091
|
-
var Bh = Symbol.for("react.memo_cache_sentinel");
|
|
13092
|
-
var ni = Symbol.iterator, il = Symbol.for("react.client.reference"), fn = Array.isArray, x = qm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Jt = m.rendererVersion, Zt = m.rendererPackageName, jo = m.extraDevToolsConfig, ot = m.getPublicInstance, Zr = m.getRootHostContext, Dn = m.getChildHostContext, Ws = m.prepareForCommit, pa = m.resetAfterCommit, Fc = m.createInstance;
|
|
12735
|
+
var le = {}, qm = React__default, St = Tb__default, ze = Object.assign, Uh = Symbol.for("react.element"), Ho = Symbol.for("react.transitional.element"), Ao = Symbol.for("react.portal"), ol = Symbol.for("react.fragment"), Lc = Symbol.for("react.strict_mode"), Uf = Symbol.for("react.profiler"), ei = Symbol.for("react.consumer"), on = Symbol.for("react.context"), jn = Symbol.for("react.forward_ref"), Nc = Symbol.for("react.suspense"), Bf = Symbol.for("react.suspense_list"), al = Symbol.for("react.memo"), kt = Symbol.for("react.lazy"), Ds = Symbol.for("react.activity"), Bh = Symbol.for("react.memo_cache_sentinel"), ni = Symbol.iterator, il = Symbol.for("react.client.reference"), fn = Array.isArray, x = qm.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Jt = m.rendererVersion, Zt = m.rendererPackageName, jo = m.extraDevToolsConfig, ot = m.getPublicInstance, Zr = m.getRootHostContext, Dn = m.getChildHostContext, Ws = m.prepareForCommit, pa = m.resetAfterCommit, Fc = m.createInstance;
|
|
13093
12736
|
m.cloneMutableInstance;
|
|
13094
12737
|
var bn = m.appendInitialChild, Ue = m.finalizeInitialChildren, ue = m.shouldSetTextContent, Do = m.createTextInstance;
|
|
13095
12738
|
m.cloneMutableTextInstance;
|
|
@@ -14057,15 +13700,6 @@ function n0() {
|
|
|
14057
13700
|
var t0 = n0();
|
|
14058
13701
|
const r0 = Xb(t0);
|
|
14059
13702
|
|
|
14060
|
-
/**
|
|
14061
|
-
* @license React
|
|
14062
|
-
* react-reconciler-constants.production.js
|
|
14063
|
-
*
|
|
14064
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14065
|
-
*
|
|
14066
|
-
* This source code is licensed under the MIT license found in the
|
|
14067
|
-
* LICENSE file in the root directory of this source tree.
|
|
14068
|
-
*/
|
|
14069
13703
|
const t = 1, o = 8, r = 32, e = 2;
|
|
14070
13704
|
|
|
14071
13705
|
function createReconciler(config) {
|
|
@@ -14092,10 +13726,11 @@ function extend(objects) {
|
|
|
14092
13726
|
function validateInstance(type, props) {
|
|
14093
13727
|
const name = toPascalCase(type);
|
|
14094
13728
|
const target = catalogue[name];
|
|
14095
|
-
if (type !== "primitive" && !target)
|
|
13729
|
+
if (type !== "primitive" && !target) {
|
|
14096
13730
|
throw new Error(
|
|
14097
13731
|
`R3F: ${name} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`
|
|
14098
13732
|
);
|
|
13733
|
+
}
|
|
14099
13734
|
if (type === "primitive" && !props.object) throw new Error(`R3F: Primitives without 'object' are invalid!`);
|
|
14100
13735
|
if (props.args !== void 0 && !Array.isArray(props.args)) throw new Error("R3F: The args prop must be an array!");
|
|
14101
13736
|
}
|
|
@@ -14248,6 +13883,7 @@ function swapInstances() {
|
|
|
14248
13883
|
}
|
|
14249
13884
|
}
|
|
14250
13885
|
if (instance.isHidden) unhideInstance(instance);
|
|
13886
|
+
if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
|
|
14251
13887
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
14252
13888
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
14253
13889
|
}
|
|
@@ -14259,6 +13895,9 @@ function swapInstances() {
|
|
|
14259
13895
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
14260
13896
|
instance.object.__r3f = instance;
|
|
14261
13897
|
setFiberRef(fiber, instance.object);
|
|
13898
|
+
delete instance.appliedOnce;
|
|
13899
|
+
instance.eventCount = 0;
|
|
13900
|
+
instance.handlers = {};
|
|
14262
13901
|
applyProps(instance.object, instance.props);
|
|
14263
13902
|
if (instance.props.attach) {
|
|
14264
13903
|
attach(parent, instance);
|
|
@@ -14332,8 +13971,22 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14332
13971
|
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14333
13972
|
if (isTailSibling) swapInstances();
|
|
14334
13973
|
},
|
|
14335
|
-
finalizeInitialChildren: () =>
|
|
14336
|
-
|
|
13974
|
+
finalizeInitialChildren: (instance) => {
|
|
13975
|
+
for (const prop in instance.props) {
|
|
13976
|
+
if (isFromRef(instance.props[prop])) return true;
|
|
13977
|
+
}
|
|
13978
|
+
return false;
|
|
13979
|
+
},
|
|
13980
|
+
commitMount(instance) {
|
|
13981
|
+
const resolved = {};
|
|
13982
|
+
for (const prop in instance.props) {
|
|
13983
|
+
const value = instance.props[prop];
|
|
13984
|
+
if (isFromRef(value)) {
|
|
13985
|
+
const ref = value[FROM_REF];
|
|
13986
|
+
if (ref.current != null) resolved[prop] = ref.current;
|
|
13987
|
+
}
|
|
13988
|
+
}
|
|
13989
|
+
if (Object.keys(resolved).length) applyProps(instance.object, resolved);
|
|
14337
13990
|
},
|
|
14338
13991
|
getPublicInstance: (instance) => instance?.object,
|
|
14339
13992
|
prepareForCommit: () => null,
|
|
@@ -14460,11 +14113,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14460
14113
|
cloneMutableTextInstance(textInstance) {
|
|
14461
14114
|
return textInstance;
|
|
14462
14115
|
},
|
|
14116
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14117
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14118
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14119
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14120
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14121
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
14463
14122
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14464
|
-
throw new Error("Not implemented.");
|
|
14465
14123
|
},
|
|
14466
14124
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14467
|
-
throw new Error("Not implemented.");
|
|
14468
14125
|
},
|
|
14469
14126
|
// https://github.com/facebook/react/pull/32465
|
|
14470
14127
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14546,14 +14203,18 @@ function createRoot(canvas) {
|
|
|
14546
14203
|
if (!prevRoot) _roots.set(canvas, { fiber, store });
|
|
14547
14204
|
let onCreated;
|
|
14548
14205
|
let lastCamera;
|
|
14549
|
-
|
|
14206
|
+
const lastConfiguredProps = {};
|
|
14550
14207
|
let configured = false;
|
|
14551
14208
|
let pending = null;
|
|
14209
|
+
let rendererSetup = null;
|
|
14552
14210
|
return {
|
|
14553
14211
|
async configure(props = {}) {
|
|
14554
14212
|
let resolve;
|
|
14555
14213
|
pending = new Promise((_resolve) => resolve = _resolve);
|
|
14556
|
-
|
|
14214
|
+
const {
|
|
14215
|
+
id: canvasId,
|
|
14216
|
+
primaryCanvas,
|
|
14217
|
+
scheduler: schedulerConfig,
|
|
14557
14218
|
gl: glConfig,
|
|
14558
14219
|
renderer: rendererConfig,
|
|
14559
14220
|
size: propsSize,
|
|
@@ -14561,10 +14222,6 @@ function createRoot(canvas) {
|
|
|
14561
14222
|
events,
|
|
14562
14223
|
onCreated: onCreatedCallback,
|
|
14563
14224
|
shadows = false,
|
|
14564
|
-
linear = false,
|
|
14565
|
-
flat = false,
|
|
14566
|
-
textureColorSpace = webgpu.SRGBColorSpace,
|
|
14567
|
-
legacy = false,
|
|
14568
14225
|
orthographic = false,
|
|
14569
14226
|
frameloop = "always",
|
|
14570
14227
|
dpr = [1, 2],
|
|
@@ -14575,11 +14232,15 @@ function createRoot(canvas) {
|
|
|
14575
14232
|
onDragOverMissed,
|
|
14576
14233
|
onDropMissed,
|
|
14577
14234
|
autoUpdateFrustum = true,
|
|
14578
|
-
occlusion = false
|
|
14235
|
+
occlusion = false,
|
|
14236
|
+
_sizeProps,
|
|
14237
|
+
forceEven
|
|
14579
14238
|
} = props;
|
|
14239
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || webgpu.SRGBColorSpace;
|
|
14580
14240
|
let state = store.getState();
|
|
14581
14241
|
const defaultGPUProps = {
|
|
14582
|
-
canvas
|
|
14242
|
+
canvas,
|
|
14243
|
+
antialias: true
|
|
14583
14244
|
};
|
|
14584
14245
|
if (glConfig && !R3F_BUILD_LEGACY) {
|
|
14585
14246
|
throw new Error(
|
|
@@ -14591,21 +14252,72 @@ function createRoot(canvas) {
|
|
|
14591
14252
|
}
|
|
14592
14253
|
let renderer = state.internal.actualRenderer;
|
|
14593
14254
|
if (!state.internal.actualRenderer) {
|
|
14594
|
-
|
|
14595
|
-
|
|
14596
|
-
|
|
14255
|
+
if (!rendererSetup) {
|
|
14256
|
+
rendererSetup = (async () => {
|
|
14257
|
+
if (primaryCanvas) {
|
|
14258
|
+
const primary = await waitForPrimary(primaryCanvas);
|
|
14259
|
+
renderer = primary.renderer;
|
|
14260
|
+
state.internal.actualRenderer = renderer;
|
|
14261
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14262
|
+
primary.store.setState((prev) => ({
|
|
14263
|
+
internal: { ...prev.internal, isMultiCanvas: true }
|
|
14264
|
+
}));
|
|
14265
|
+
state.set((prev) => ({
|
|
14266
|
+
webGPUSupported: primary.store.getState().webGPUSupported,
|
|
14267
|
+
renderer,
|
|
14268
|
+
primaryStore: primary.store,
|
|
14269
|
+
internal: {
|
|
14270
|
+
...prev.internal,
|
|
14271
|
+
canvasTarget,
|
|
14272
|
+
isMultiCanvas: true,
|
|
14273
|
+
isSecondary: true,
|
|
14274
|
+
targetId: primaryCanvas
|
|
14275
|
+
}
|
|
14276
|
+
}));
|
|
14277
|
+
} else {
|
|
14278
|
+
renderer = await resolveRenderer(rendererConfig, defaultGPUProps, webgpu.WebGPURenderer);
|
|
14279
|
+
if (!renderer.hasInitialized?.()) {
|
|
14280
|
+
const size2 = computeInitialSize(canvas, propsSize);
|
|
14281
|
+
if (size2.width > 0 && size2.height > 0) {
|
|
14282
|
+
const pixelRatio = calculateDpr(dpr);
|
|
14283
|
+
canvas.width = size2.width * pixelRatio;
|
|
14284
|
+
canvas.height = size2.height * pixelRatio;
|
|
14285
|
+
}
|
|
14286
|
+
await renderer.init();
|
|
14287
|
+
}
|
|
14288
|
+
const backend = renderer.backend;
|
|
14289
|
+
const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
|
|
14290
|
+
state.internal.actualRenderer = renderer;
|
|
14291
|
+
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14292
|
+
if (canvasId && !state.internal.isSecondary) {
|
|
14293
|
+
const canvasTarget = new webgpu.CanvasTarget(canvas);
|
|
14294
|
+
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14295
|
+
state.set((prev) => ({
|
|
14296
|
+
internal: {
|
|
14297
|
+
...prev.internal,
|
|
14298
|
+
canvasTarget,
|
|
14299
|
+
unregisterPrimary
|
|
14300
|
+
}
|
|
14301
|
+
}));
|
|
14302
|
+
}
|
|
14303
|
+
}
|
|
14304
|
+
})().catch((err) => {
|
|
14305
|
+
rendererSetup = null;
|
|
14306
|
+
throw err;
|
|
14307
|
+
});
|
|
14597
14308
|
}
|
|
14598
|
-
|
|
14599
|
-
|
|
14600
|
-
state.internal.actualRenderer
|
|
14601
|
-
state.set({ webGPUSupported: isWebGPUBackend, renderer });
|
|
14309
|
+
await rendererSetup;
|
|
14310
|
+
state = store.getState();
|
|
14311
|
+
renderer = state.internal.actualRenderer;
|
|
14602
14312
|
}
|
|
14603
14313
|
let raycaster = state.raycaster;
|
|
14604
14314
|
if (!raycaster) state.set({ raycaster: raycaster = new webgpu.Raycaster() });
|
|
14605
14315
|
const { params, ...options } = raycastOptions || {};
|
|
14606
14316
|
if (!is.equ(options, raycaster, shallowLoose)) applyProps(raycaster, { ...options });
|
|
14607
|
-
if (!is.equ(params, raycaster.params, shallowLoose))
|
|
14317
|
+
if (!is.equ(params, raycaster.params, shallowLoose)) {
|
|
14608
14318
|
applyProps(raycaster, { params: { ...raycaster.params, ...params } });
|
|
14319
|
+
}
|
|
14320
|
+
let tempCamera = state.camera;
|
|
14609
14321
|
if (!state.camera || state.camera === lastCamera && !is.equ(lastCamera, cameraOptions, shallowLoose)) {
|
|
14610
14322
|
lastCamera = cameraOptions;
|
|
14611
14323
|
const isCamera = cameraOptions?.isCamera;
|
|
@@ -14625,6 +14337,7 @@ function createRoot(canvas) {
|
|
|
14625
14337
|
if (!state.camera && !cameraOptions?.rotation) camera.lookAt(0, 0, 0);
|
|
14626
14338
|
}
|
|
14627
14339
|
state.set({ camera });
|
|
14340
|
+
tempCamera = camera;
|
|
14628
14341
|
raycaster.camera = camera;
|
|
14629
14342
|
}
|
|
14630
14343
|
if (!state.scene) {
|
|
@@ -14642,7 +14355,7 @@ function createRoot(canvas) {
|
|
|
14642
14355
|
rootScene: scene,
|
|
14643
14356
|
internal: { ...prev.internal, container: scene }
|
|
14644
14357
|
}));
|
|
14645
|
-
const camera =
|
|
14358
|
+
const camera = tempCamera;
|
|
14646
14359
|
if (camera && !camera.parent) scene.add(camera);
|
|
14647
14360
|
}
|
|
14648
14361
|
if (events && !state.events.handlers) {
|
|
@@ -14656,9 +14369,17 @@ function createRoot(canvas) {
|
|
|
14656
14369
|
wasEnabled = enabled;
|
|
14657
14370
|
});
|
|
14658
14371
|
}
|
|
14372
|
+
if (_sizeProps !== void 0) {
|
|
14373
|
+
state.set({ _sizeProps });
|
|
14374
|
+
}
|
|
14375
|
+
if (forceEven !== void 0 && state.internal.forceEven !== forceEven) {
|
|
14376
|
+
state.set((prev) => ({ internal: { ...prev.internal, forceEven } }));
|
|
14377
|
+
}
|
|
14659
14378
|
const size = computeInitialSize(canvas, propsSize);
|
|
14660
|
-
if (!is.equ(size, state.size, shallowLoose)) {
|
|
14379
|
+
if (!state._sizeImperative && !is.equ(size, state.size, shallowLoose)) {
|
|
14380
|
+
const wasImperative = state._sizeImperative;
|
|
14661
14381
|
state.setSize(size.width, size.height, size.top, size.left);
|
|
14382
|
+
if (!wasImperative) state.set({ _sizeImperative: false });
|
|
14662
14383
|
}
|
|
14663
14384
|
if (dpr !== void 0 && !is.equ(dpr, lastConfiguredProps.dpr, shallowLoose)) {
|
|
14664
14385
|
state.setDpr(dpr);
|
|
@@ -14680,10 +14401,10 @@ function createRoot(canvas) {
|
|
|
14680
14401
|
lastConfiguredProps.performance = performance;
|
|
14681
14402
|
}
|
|
14682
14403
|
if (!state.xr) {
|
|
14683
|
-
const handleXRFrame = (timestamp,
|
|
14404
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
14684
14405
|
const state2 = store.getState();
|
|
14685
14406
|
if (state2.frameloop === "never") return;
|
|
14686
|
-
advance(timestamp
|
|
14407
|
+
advance(timestamp);
|
|
14687
14408
|
};
|
|
14688
14409
|
const actualRenderer = state.internal.actualRenderer;
|
|
14689
14410
|
const handleSessionChange = () => {
|
|
@@ -14695,16 +14416,16 @@ function createRoot(canvas) {
|
|
|
14695
14416
|
};
|
|
14696
14417
|
const xr = {
|
|
14697
14418
|
connect() {
|
|
14698
|
-
const { gl, renderer: renderer2
|
|
14699
|
-
const
|
|
14700
|
-
|
|
14701
|
-
|
|
14419
|
+
const { gl, renderer: renderer2 } = store.getState();
|
|
14420
|
+
const xrManager = (renderer2 || gl).xr;
|
|
14421
|
+
xrManager.addEventListener("sessionstart", handleSessionChange);
|
|
14422
|
+
xrManager.addEventListener("sessionend", handleSessionChange);
|
|
14702
14423
|
},
|
|
14703
14424
|
disconnect() {
|
|
14704
|
-
const { gl, renderer: renderer2
|
|
14705
|
-
const
|
|
14706
|
-
|
|
14707
|
-
|
|
14425
|
+
const { gl, renderer: renderer2 } = store.getState();
|
|
14426
|
+
const xrManager = (renderer2 || gl).xr;
|
|
14427
|
+
xrManager.removeEventListener("sessionstart", handleSessionChange);
|
|
14428
|
+
xrManager.removeEventListener("sessionend", handleSessionChange);
|
|
14708
14429
|
}
|
|
14709
14430
|
};
|
|
14710
14431
|
if (typeof renderer.xr?.addEventListener === "function") xr.connect();
|
|
@@ -14716,42 +14437,93 @@ function createRoot(canvas) {
|
|
|
14716
14437
|
const oldType = renderer.shadowMap.type;
|
|
14717
14438
|
renderer.shadowMap.enabled = !!shadows;
|
|
14718
14439
|
if (is.boo(shadows)) {
|
|
14719
|
-
renderer.shadowMap.type = webgpu.
|
|
14440
|
+
renderer.shadowMap.type = webgpu.PCFShadowMap;
|
|
14720
14441
|
} else if (is.str(shadows)) {
|
|
14442
|
+
if (shadows === "soft") {
|
|
14443
|
+
notifyDepreciated({
|
|
14444
|
+
heading: 'shadows="soft" is deprecated',
|
|
14445
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14446
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14447
|
+
});
|
|
14448
|
+
}
|
|
14721
14449
|
const types = {
|
|
14722
14450
|
basic: webgpu.BasicShadowMap,
|
|
14723
14451
|
percentage: webgpu.PCFShadowMap,
|
|
14724
|
-
soft: webgpu.
|
|
14452
|
+
soft: webgpu.PCFShadowMap,
|
|
14725
14453
|
variance: webgpu.VSMShadowMap
|
|
14726
14454
|
};
|
|
14727
|
-
renderer.shadowMap.type = types[shadows] ?? webgpu.
|
|
14455
|
+
renderer.shadowMap.type = types[shadows] ?? webgpu.PCFShadowMap;
|
|
14728
14456
|
} else if (is.obj(shadows)) {
|
|
14729
14457
|
Object.assign(renderer.shadowMap, shadows);
|
|
14730
14458
|
}
|
|
14731
|
-
if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type)
|
|
14459
|
+
if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type) {
|
|
14732
14460
|
renderer.shadowMap.needsUpdate = true;
|
|
14461
|
+
}
|
|
14462
|
+
}
|
|
14463
|
+
if (!configured) {
|
|
14464
|
+
renderer.outputColorSpace = webgpu.SRGBColorSpace;
|
|
14465
|
+
renderer.toneMapping = webgpu.ACESFilmicToneMapping;
|
|
14733
14466
|
}
|
|
14734
14467
|
if (textureColorSpace !== lastConfiguredProps.textureColorSpace) {
|
|
14735
14468
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
14736
14469
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
14737
14470
|
}
|
|
14738
|
-
|
|
14739
|
-
|
|
14471
|
+
const r3fProps = ["textureColorSpace"];
|
|
14472
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14473
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
14474
|
+
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
14475
|
+
const glProps = {};
|
|
14476
|
+
for (const key in glConfig) {
|
|
14477
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14478
|
+
}
|
|
14479
|
+
applyProps(renderer, glProps);
|
|
14480
|
+
}
|
|
14740
14481
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
14741
14482
|
const currentRenderer = state.renderer;
|
|
14742
14483
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
14743
|
-
|
|
14484
|
+
const rendererProps = {};
|
|
14485
|
+
for (const key in rendererConfig) {
|
|
14486
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14487
|
+
}
|
|
14488
|
+
applyProps(currentRenderer, rendererProps);
|
|
14744
14489
|
}
|
|
14745
14490
|
}
|
|
14746
|
-
const scheduler = getScheduler();
|
|
14491
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
14747
14492
|
const rootId = state.internal.rootId;
|
|
14748
14493
|
if (!rootId) {
|
|
14749
|
-
const newRootId = scheduler.generateRootId();
|
|
14750
|
-
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14494
|
+
const newRootId = canvasId || scheduler$1.generateRootId();
|
|
14495
|
+
const unregisterRoot = scheduler$1.registerRoot(newRootId, {
|
|
14751
14496
|
getState: () => store.getState(),
|
|
14752
14497
|
onError: (err) => store.getState().setError(err)
|
|
14753
14498
|
});
|
|
14754
|
-
const
|
|
14499
|
+
const unregisterCanvasTarget = scheduler$1.register(
|
|
14500
|
+
() => {
|
|
14501
|
+
const state2 = store.getState();
|
|
14502
|
+
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
14503
|
+
const renderer2 = state2.internal.actualRenderer;
|
|
14504
|
+
renderer2.setCanvasTarget(state2.internal.canvasTarget);
|
|
14505
|
+
}
|
|
14506
|
+
},
|
|
14507
|
+
{
|
|
14508
|
+
id: `${newRootId}_canvasTarget`,
|
|
14509
|
+
rootId: newRootId,
|
|
14510
|
+
phase: "start",
|
|
14511
|
+
system: true
|
|
14512
|
+
}
|
|
14513
|
+
);
|
|
14514
|
+
const unregisterEventsFlush = scheduler$1.register(
|
|
14515
|
+
() => {
|
|
14516
|
+
const state2 = store.getState();
|
|
14517
|
+
state2.events.flush?.();
|
|
14518
|
+
},
|
|
14519
|
+
{
|
|
14520
|
+
id: `${newRootId}_events`,
|
|
14521
|
+
rootId: newRootId,
|
|
14522
|
+
phase: "input",
|
|
14523
|
+
system: true
|
|
14524
|
+
}
|
|
14525
|
+
);
|
|
14526
|
+
const unregisterFrustum = scheduler$1.register(
|
|
14755
14527
|
() => {
|
|
14756
14528
|
const state2 = store.getState();
|
|
14757
14529
|
if (state2.autoUpdateFrustum && state2.camera) {
|
|
@@ -14761,11 +14533,11 @@ function createRoot(canvas) {
|
|
|
14761
14533
|
{
|
|
14762
14534
|
id: `${newRootId}_frustum`,
|
|
14763
14535
|
rootId: newRootId,
|
|
14764
|
-
|
|
14536
|
+
before: "render",
|
|
14765
14537
|
system: true
|
|
14766
14538
|
}
|
|
14767
14539
|
);
|
|
14768
|
-
const unregisterVisibility = scheduler.register(
|
|
14540
|
+
const unregisterVisibility = scheduler$1.register(
|
|
14769
14541
|
() => {
|
|
14770
14542
|
const state2 = store.getState();
|
|
14771
14543
|
checkVisibility(state2);
|
|
@@ -14773,30 +14545,34 @@ function createRoot(canvas) {
|
|
|
14773
14545
|
{
|
|
14774
14546
|
id: `${newRootId}_visibility`,
|
|
14775
14547
|
rootId: newRootId,
|
|
14776
|
-
|
|
14548
|
+
before: "render",
|
|
14777
14549
|
system: true,
|
|
14778
14550
|
after: `${newRootId}_frustum`
|
|
14779
14551
|
}
|
|
14780
14552
|
);
|
|
14781
|
-
const unregisterRender = scheduler.register(
|
|
14553
|
+
const unregisterRender = scheduler$1.register(
|
|
14782
14554
|
() => {
|
|
14783
14555
|
const state2 = store.getState();
|
|
14784
14556
|
const renderer2 = state2.internal.actualRenderer;
|
|
14785
|
-
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14557
|
+
const userHandlesRender = scheduler$1.hasUserJobsInPhase("render", newRootId);
|
|
14786
14558
|
if (userHandlesRender || state2.internal.priority) return;
|
|
14787
14559
|
try {
|
|
14788
|
-
if (state2.
|
|
14560
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
14789
14561
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
14790
14562
|
} catch (error) {
|
|
14791
14563
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
14792
14564
|
}
|
|
14793
14565
|
},
|
|
14794
14566
|
{
|
|
14795
|
-
|
|
14567
|
+
// Use canvas ID directly as job ID if available, otherwise use generated rootId
|
|
14568
|
+
id: canvasId || `${newRootId}_render`,
|
|
14796
14569
|
rootId: newRootId,
|
|
14797
14570
|
phase: "render",
|
|
14798
|
-
system: true
|
|
14571
|
+
system: true,
|
|
14799
14572
|
// Internal flag: this is a system job, not user-controlled
|
|
14573
|
+
// Apply scheduler config for render ordering and rate limiting
|
|
14574
|
+
...schedulerConfig?.after && { after: schedulerConfig.after },
|
|
14575
|
+
...schedulerConfig?.fps && { fps: schedulerConfig.fps }
|
|
14800
14576
|
}
|
|
14801
14577
|
);
|
|
14802
14578
|
state.set((state2) => ({
|
|
@@ -14805,15 +14581,17 @@ function createRoot(canvas) {
|
|
|
14805
14581
|
rootId: newRootId,
|
|
14806
14582
|
unregisterRoot: () => {
|
|
14807
14583
|
unregisterRoot();
|
|
14584
|
+
unregisterCanvasTarget();
|
|
14585
|
+
unregisterEventsFlush();
|
|
14808
14586
|
unregisterFrustum();
|
|
14809
14587
|
unregisterVisibility();
|
|
14810
14588
|
unregisterRender();
|
|
14811
14589
|
},
|
|
14812
|
-
scheduler
|
|
14590
|
+
scheduler: scheduler$1
|
|
14813
14591
|
}
|
|
14814
14592
|
}));
|
|
14815
14593
|
}
|
|
14816
|
-
scheduler.frameloop = frameloop;
|
|
14594
|
+
scheduler$1.frameloop = frameloop;
|
|
14817
14595
|
onCreated = onCreatedCallback;
|
|
14818
14596
|
configured = true;
|
|
14819
14597
|
resolve();
|
|
@@ -14863,15 +14641,24 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14863
14641
|
const renderer = state.internal.actualRenderer;
|
|
14864
14642
|
const unregisterRoot = state.internal.unregisterRoot;
|
|
14865
14643
|
if (unregisterRoot) unregisterRoot();
|
|
14644
|
+
const unregisterPrimary = state.internal.unregisterPrimary;
|
|
14645
|
+
if (unregisterPrimary) unregisterPrimary();
|
|
14646
|
+
const canvasTarget = state.internal.canvasTarget;
|
|
14647
|
+
if (canvasTarget?.dispose) canvasTarget.dispose();
|
|
14866
14648
|
state.events.disconnect?.();
|
|
14867
14649
|
cleanupHelperGroup(root.store);
|
|
14868
|
-
renderer
|
|
14869
|
-
|
|
14870
|
-
|
|
14650
|
+
if (state.isLegacy && renderer) {
|
|
14651
|
+
;
|
|
14652
|
+
renderer.renderLists?.dispose?.();
|
|
14653
|
+
renderer.forceContextLoss?.();
|
|
14654
|
+
}
|
|
14655
|
+
if (!state.internal.isSecondary) {
|
|
14656
|
+
if (renderer?.xr) state.xr.disconnect();
|
|
14657
|
+
}
|
|
14871
14658
|
dispose(state.scene);
|
|
14872
14659
|
_roots.delete(canvas);
|
|
14873
14660
|
if (callback) callback(canvas);
|
|
14874
|
-
} catch
|
|
14661
|
+
} catch {
|
|
14875
14662
|
}
|
|
14876
14663
|
}, 500);
|
|
14877
14664
|
}
|
|
@@ -14879,36 +14666,34 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14879
14666
|
}
|
|
14880
14667
|
}
|
|
14881
14668
|
function createPortal(children, container, state) {
|
|
14882
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14669
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Portal, { children, container, state });
|
|
14883
14670
|
}
|
|
14884
|
-
function
|
|
14671
|
+
function Portal({ children, container, state }) {
|
|
14885
14672
|
const isRef = React.useCallback((obj) => obj && "current" in obj, []);
|
|
14886
|
-
const [resolvedContainer,
|
|
14673
|
+
const [resolvedContainer, _setResolvedContainer] = React.useState(() => {
|
|
14887
14674
|
if (isRef(container)) return container.current ?? null;
|
|
14888
14675
|
return container;
|
|
14889
14676
|
});
|
|
14677
|
+
const setResolvedContainer = React.useCallback(
|
|
14678
|
+
(newContainer) => {
|
|
14679
|
+
if (!newContainer || newContainer === resolvedContainer) return;
|
|
14680
|
+
_setResolvedContainer(isRef(newContainer) ? newContainer.current : newContainer);
|
|
14681
|
+
},
|
|
14682
|
+
[resolvedContainer, _setResolvedContainer, isRef]
|
|
14683
|
+
);
|
|
14890
14684
|
React.useMemo(() => {
|
|
14891
|
-
if (isRef(container)) {
|
|
14892
|
-
|
|
14893
|
-
|
|
14894
|
-
|
|
14895
|
-
const updated = container.current;
|
|
14896
|
-
if (updated && updated !== resolvedContainer) {
|
|
14897
|
-
setResolvedContainer(updated);
|
|
14898
|
-
}
|
|
14899
|
-
});
|
|
14900
|
-
} else if (current !== resolvedContainer) {
|
|
14901
|
-
setResolvedContainer(current);
|
|
14902
|
-
}
|
|
14903
|
-
} else if (container !== resolvedContainer) {
|
|
14904
|
-
setResolvedContainer(container);
|
|
14685
|
+
if (isRef(container) && !container.current) {
|
|
14686
|
+
return queueMicrotask(() => {
|
|
14687
|
+
setResolvedContainer(container.current);
|
|
14688
|
+
});
|
|
14905
14689
|
}
|
|
14906
|
-
|
|
14690
|
+
setResolvedContainer(container);
|
|
14691
|
+
}, [container, isRef, setResolvedContainer]);
|
|
14907
14692
|
if (!resolvedContainer) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
14908
14693
|
const portalKey = resolvedContainer.uuid ?? `portal-${resolvedContainer.id ?? "unknown"}`;
|
|
14909
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14694
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PortalInner, { children, container: resolvedContainer, state }, portalKey);
|
|
14910
14695
|
}
|
|
14911
|
-
function
|
|
14696
|
+
function PortalInner({ state = {}, children, container }) {
|
|
14912
14697
|
const { events, size, injectScene = true, ...rest } = state;
|
|
14913
14698
|
const previousRoot = useStore();
|
|
14914
14699
|
const [raycaster] = React.useState(() => new webgpu.Raycaster());
|
|
@@ -14929,12 +14714,14 @@ function Portal({ state = {}, children, container }) {
|
|
|
14929
14714
|
};
|
|
14930
14715
|
}, [portalScene, container, injectScene]);
|
|
14931
14716
|
const inject = useMutableCallback((rootState, injectState) => {
|
|
14717
|
+
const resolvedSize = { ...rootState.size, ...injectState.size, ...size };
|
|
14932
14718
|
let viewport = void 0;
|
|
14933
|
-
if (injectState.camera && size) {
|
|
14719
|
+
if (injectState.camera && (size || injectState.size)) {
|
|
14934
14720
|
const camera = injectState.camera;
|
|
14935
|
-
viewport = rootState.viewport.getCurrentViewport(camera, new webgpu.Vector3(),
|
|
14936
|
-
if (camera !== rootState.camera) updateCamera(camera,
|
|
14721
|
+
viewport = rootState.viewport.getCurrentViewport(camera, new webgpu.Vector3(), resolvedSize);
|
|
14722
|
+
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14937
14723
|
}
|
|
14724
|
+
const set = injectState.set;
|
|
14938
14725
|
return {
|
|
14939
14726
|
// The intersect consists of the previous root state
|
|
14940
14727
|
...rootState,
|
|
@@ -14950,10 +14737,10 @@ function Portal({ state = {}, children, container }) {
|
|
|
14950
14737
|
previousRoot,
|
|
14951
14738
|
// Events, size and viewport can be overridden by the inject layer
|
|
14952
14739
|
events: { ...rootState.events, ...injectState.events, ...events },
|
|
14953
|
-
size:
|
|
14740
|
+
size: resolvedSize,
|
|
14954
14741
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14955
14742
|
// Layers are allowed to override events
|
|
14956
|
-
setEvents: (events2) =>
|
|
14743
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
14957
14744
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
14958
14745
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
14959
14746
|
};
|
|
@@ -14962,9 +14749,13 @@ function Portal({ state = {}, children, container }) {
|
|
|
14962
14749
|
const store = traditional.createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
14963
14750
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
14964
14751
|
onMutate(previousRoot.getState());
|
|
14965
|
-
previousRoot.subscribe(onMutate);
|
|
14966
14752
|
return store;
|
|
14967
14753
|
}, [previousRoot, container]);
|
|
14754
|
+
useIsomorphicLayoutEffect(() => {
|
|
14755
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14756
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14757
|
+
return unsubscribe;
|
|
14758
|
+
}, [previousRoot, usePortalStore]);
|
|
14968
14759
|
return (
|
|
14969
14760
|
// @ts-ignore, reconciler types are not maintained
|
|
14970
14761
|
/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: reconciler.createPortal(
|
|
@@ -14978,21 +14769,72 @@ function flushSync(fn) {
|
|
|
14978
14769
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14979
14770
|
}
|
|
14980
14771
|
|
|
14772
|
+
function parseBackground(background) {
|
|
14773
|
+
if (!background) return null;
|
|
14774
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14775
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14776
|
+
return {
|
|
14777
|
+
...rest,
|
|
14778
|
+
preset,
|
|
14779
|
+
files: envMap || files,
|
|
14780
|
+
backgroundFiles: backgroundMap,
|
|
14781
|
+
background: true
|
|
14782
|
+
};
|
|
14783
|
+
}
|
|
14784
|
+
if (typeof background === "number") {
|
|
14785
|
+
return { color: background, background: true };
|
|
14786
|
+
}
|
|
14787
|
+
if (typeof background === "string") {
|
|
14788
|
+
if (background in presetsObj) {
|
|
14789
|
+
return { preset: background, background: true };
|
|
14790
|
+
}
|
|
14791
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14792
|
+
return { files: background, background: true };
|
|
14793
|
+
}
|
|
14794
|
+
return { color: background, background: true };
|
|
14795
|
+
}
|
|
14796
|
+
if (background.isColor) {
|
|
14797
|
+
return { color: background, background: true };
|
|
14798
|
+
}
|
|
14799
|
+
return null;
|
|
14800
|
+
}
|
|
14801
|
+
|
|
14802
|
+
function parseRendererConfig(rendererProp) {
|
|
14803
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14804
|
+
if (isRendererConfig) {
|
|
14805
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14806
|
+
return {
|
|
14807
|
+
primaryCanvas: pc,
|
|
14808
|
+
scheduler: sc,
|
|
14809
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14810
|
+
};
|
|
14811
|
+
}
|
|
14812
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14813
|
+
}
|
|
14814
|
+
|
|
14815
|
+
function clearHmrCaches(store) {
|
|
14816
|
+
store.setState((state) => ({
|
|
14817
|
+
nodes: {},
|
|
14818
|
+
uniforms: {},
|
|
14819
|
+
buffers: {},
|
|
14820
|
+
gpuStorage: {},
|
|
14821
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14822
|
+
}));
|
|
14823
|
+
}
|
|
14824
|
+
|
|
14981
14825
|
function CanvasImpl({
|
|
14982
14826
|
ref,
|
|
14983
14827
|
children,
|
|
14984
14828
|
fallback,
|
|
14985
14829
|
resize,
|
|
14986
14830
|
style,
|
|
14831
|
+
id,
|
|
14987
14832
|
gl,
|
|
14988
|
-
renderer,
|
|
14833
|
+
renderer: rendererProp,
|
|
14989
14834
|
events = createPointerEvents,
|
|
14990
14835
|
eventSource,
|
|
14991
14836
|
eventPrefix,
|
|
14992
14837
|
shadows,
|
|
14993
|
-
linear,
|
|
14994
|
-
flat,
|
|
14995
|
-
legacy,
|
|
14996
14838
|
orthographic,
|
|
14997
14839
|
frameloop,
|
|
14998
14840
|
dpr,
|
|
@@ -15000,14 +14842,23 @@ function CanvasImpl({
|
|
|
15000
14842
|
raycaster,
|
|
15001
14843
|
camera,
|
|
15002
14844
|
scene,
|
|
14845
|
+
autoUpdateFrustum,
|
|
14846
|
+
occlusion,
|
|
15003
14847
|
onPointerMissed,
|
|
15004
14848
|
onDragOverMissed,
|
|
15005
14849
|
onDropMissed,
|
|
15006
14850
|
onCreated,
|
|
14851
|
+
hmr,
|
|
14852
|
+
width,
|
|
14853
|
+
height,
|
|
14854
|
+
background,
|
|
14855
|
+
forceEven,
|
|
15007
14856
|
...props
|
|
15008
14857
|
}) {
|
|
14858
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
15009
14859
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
15010
14860
|
const Bridge = useBridge();
|
|
14861
|
+
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
15011
14862
|
const hasInitialSizeRef = React__namespace.useRef(false);
|
|
15012
14863
|
const measureConfig = React__namespace.useMemo(() => {
|
|
15013
14864
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15024,7 +14875,21 @@ function CanvasImpl({
|
|
|
15024
14875
|
};
|
|
15025
14876
|
}, [resize, hasInitialSizeRef.current]);
|
|
15026
14877
|
const [containerRef, containerRect] = useMeasure__default(measureConfig);
|
|
15027
|
-
|
|
14878
|
+
const effectiveSize = React__namespace.useMemo(() => {
|
|
14879
|
+
let w = width ?? containerRect.width;
|
|
14880
|
+
let h = height ?? containerRect.height;
|
|
14881
|
+
if (forceEven) {
|
|
14882
|
+
w = Math.ceil(w / 2) * 2;
|
|
14883
|
+
h = Math.ceil(h / 2) * 2;
|
|
14884
|
+
}
|
|
14885
|
+
return {
|
|
14886
|
+
width: w,
|
|
14887
|
+
height: h,
|
|
14888
|
+
top: containerRect.top,
|
|
14889
|
+
left: containerRect.left
|
|
14890
|
+
};
|
|
14891
|
+
}, [width, height, containerRect, forceEven]);
|
|
14892
|
+
if (!hasInitialSizeRef.current && effectiveSize.width > 0 && effectiveSize.height > 0) {
|
|
15028
14893
|
hasInitialSizeRef.current = true;
|
|
15029
14894
|
}
|
|
15030
14895
|
const canvasRef = React__namespace.useRef(null);
|
|
@@ -15035,6 +14900,7 @@ function CanvasImpl({
|
|
|
15035
14900
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
15036
14901
|
const [block, setBlock] = React__namespace.useState(false);
|
|
15037
14902
|
const [error, setError] = React__namespace.useState(false);
|
|
14903
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
15038
14904
|
if (block) throw block;
|
|
15039
14905
|
if (error) throw error;
|
|
15040
14906
|
const root = React__namespace.useRef(null);
|
|
@@ -15042,8 +14908,9 @@ function CanvasImpl({
|
|
|
15042
14908
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
15043
14909
|
useIsomorphicLayoutEffect(() => {
|
|
15044
14910
|
effectActiveRef.current = true;
|
|
14911
|
+
if (fallbackVisible) return;
|
|
15045
14912
|
const canvas = canvasRef.current;
|
|
15046
|
-
if (
|
|
14913
|
+
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15047
14914
|
if (!root.current) {
|
|
15048
14915
|
root.current = createRoot(canvas);
|
|
15049
14916
|
notifyAlpha({
|
|
@@ -15062,22 +14929,27 @@ function CanvasImpl({
|
|
|
15062
14929
|
}
|
|
15063
14930
|
async function run() {
|
|
15064
14931
|
if (!effectActiveRef.current || !root.current) return;
|
|
15065
|
-
await root.current.configure({
|
|
14932
|
+
const configured = await root.current.configure({
|
|
14933
|
+
id,
|
|
14934
|
+
primaryCanvas,
|
|
14935
|
+
scheduler,
|
|
15066
14936
|
gl,
|
|
15067
14937
|
renderer,
|
|
15068
14938
|
scene,
|
|
15069
14939
|
events,
|
|
15070
14940
|
shadows,
|
|
15071
|
-
linear,
|
|
15072
|
-
flat,
|
|
15073
|
-
legacy,
|
|
15074
14941
|
orthographic,
|
|
15075
14942
|
frameloop,
|
|
15076
14943
|
dpr,
|
|
15077
14944
|
performance,
|
|
15078
14945
|
raycaster,
|
|
15079
14946
|
camera,
|
|
15080
|
-
|
|
14947
|
+
autoUpdateFrustum,
|
|
14948
|
+
occlusion,
|
|
14949
|
+
size: effectiveSize,
|
|
14950
|
+
// Store size props for reset functionality
|
|
14951
|
+
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
14952
|
+
forceEven,
|
|
15081
14953
|
// Pass mutable reference to onPointerMissed so it's free to update
|
|
15082
14954
|
onPointerMissed: (...args) => handlePointerMissed.current?.(...args),
|
|
15083
14955
|
onDragOverMissed: (...args) => handleDragOverMissed.current?.(...args),
|
|
@@ -15098,10 +14970,25 @@ function CanvasImpl({
|
|
|
15098
14970
|
}
|
|
15099
14971
|
onCreated?.(state);
|
|
15100
14972
|
}
|
|
15101
|
-
})
|
|
15102
|
-
|
|
14973
|
+
}).then(
|
|
14974
|
+
() => true,
|
|
14975
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
14976
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
14977
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
14978
|
+
(setupError) => {
|
|
14979
|
+
if (effectActiveRef.current) {
|
|
14980
|
+
if (fallback != null) setFallbackVisible(true);
|
|
14981
|
+
else setError(setupError);
|
|
14982
|
+
}
|
|
14983
|
+
return false;
|
|
14984
|
+
}
|
|
14985
|
+
);
|
|
14986
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
15103
14987
|
root.current.render(
|
|
15104
|
-
/* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.
|
|
14988
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Block, { set: setBlock }), children: [
|
|
14989
|
+
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
14990
|
+
children ?? null
|
|
14991
|
+
] }) }) })
|
|
15105
14992
|
);
|
|
15106
14993
|
}
|
|
15107
14994
|
run();
|
|
@@ -15122,7 +15009,29 @@ function CanvasImpl({
|
|
|
15122
15009
|
root.current = null;
|
|
15123
15010
|
};
|
|
15124
15011
|
}
|
|
15125
|
-
}, []);
|
|
15012
|
+
}, []);
|
|
15013
|
+
React__namespace.useEffect(() => {
|
|
15014
|
+
if (hmr === false) return;
|
|
15015
|
+
const canvas = canvasRef.current;
|
|
15016
|
+
if (!canvas) return;
|
|
15017
|
+
const handleHMR = () => {
|
|
15018
|
+
queueMicrotask(() => {
|
|
15019
|
+
const rootEntry = _roots.get(canvas);
|
|
15020
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
15021
|
+
});
|
|
15022
|
+
};
|
|
15023
|
+
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) {
|
|
15024
|
+
const hot = undefined;
|
|
15025
|
+
hot.on("vite:afterUpdate", handleHMR);
|
|
15026
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
15027
|
+
}
|
|
15028
|
+
if (typeof module !== "undefined" && module.hot) {
|
|
15029
|
+
const hot = module.hot;
|
|
15030
|
+
hot.addStatusHandler((status) => {
|
|
15031
|
+
if (status === "idle") handleHMR();
|
|
15032
|
+
});
|
|
15033
|
+
}
|
|
15034
|
+
}, [hmr]);
|
|
15126
15035
|
const pointerEvents = eventSource ? "none" : "auto";
|
|
15127
15036
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
15128
15037
|
"div",
|
|
@@ -15137,7 +15046,20 @@ function CanvasImpl({
|
|
|
15137
15046
|
...style
|
|
15138
15047
|
},
|
|
15139
15048
|
...props,
|
|
15140
|
-
children:
|
|
15049
|
+
children: fallbackVisible ? (
|
|
15050
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15051
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15052
|
+
fallback
|
|
15053
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
15054
|
+
"canvas",
|
|
15055
|
+
{
|
|
15056
|
+
ref: canvasRef,
|
|
15057
|
+
id,
|
|
15058
|
+
className: "r3f-canvas",
|
|
15059
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
15060
|
+
children: fallback
|
|
15061
|
+
}
|
|
15062
|
+
) })
|
|
15141
15063
|
}
|
|
15142
15064
|
);
|
|
15143
15065
|
}
|
|
@@ -15145,6 +15067,114 @@ function Canvas(props) {
|
|
|
15145
15067
|
return /* @__PURE__ */ jsxRuntime.jsx(itsFine.FiberProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(CanvasImpl, { ...props }) });
|
|
15146
15068
|
}
|
|
15147
15069
|
|
|
15070
|
+
var __defProp = Object.defineProperty;
|
|
15071
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15072
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15073
|
+
var _a;
|
|
15074
|
+
const INTERNAL_DATA = Symbol("ScopedStore.data");
|
|
15075
|
+
_a = INTERNAL_DATA;
|
|
15076
|
+
const _ScopedStore = class _ScopedStore {
|
|
15077
|
+
constructor(data) {
|
|
15078
|
+
__publicField(this, _a);
|
|
15079
|
+
this[INTERNAL_DATA] = data;
|
|
15080
|
+
return new Proxy(this, {
|
|
15081
|
+
get(target, prop, receiver) {
|
|
15082
|
+
if (typeof prop === "string") {
|
|
15083
|
+
if (prop === "scope" || prop === "has" || prop === "keys") {
|
|
15084
|
+
return Reflect.get(target, prop, receiver);
|
|
15085
|
+
}
|
|
15086
|
+
return target[INTERNAL_DATA][prop];
|
|
15087
|
+
}
|
|
15088
|
+
return Reflect.get(target, prop, receiver);
|
|
15089
|
+
},
|
|
15090
|
+
has(target, prop) {
|
|
15091
|
+
return typeof prop === "string" ? prop in target[INTERNAL_DATA] : Reflect.has(target, prop);
|
|
15092
|
+
},
|
|
15093
|
+
ownKeys(target) {
|
|
15094
|
+
return Reflect.ownKeys(target[INTERNAL_DATA]);
|
|
15095
|
+
},
|
|
15096
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
15097
|
+
if (typeof prop === "string" && prop in target[INTERNAL_DATA]) {
|
|
15098
|
+
return {
|
|
15099
|
+
configurable: true,
|
|
15100
|
+
enumerable: true,
|
|
15101
|
+
value: target[INTERNAL_DATA][prop]
|
|
15102
|
+
};
|
|
15103
|
+
}
|
|
15104
|
+
return void 0;
|
|
15105
|
+
}
|
|
15106
|
+
});
|
|
15107
|
+
}
|
|
15108
|
+
/**
|
|
15109
|
+
* Access a nested scope by key.
|
|
15110
|
+
* If the key doesn't exist or isn't a scope object, returns an empty ScopedStore.
|
|
15111
|
+
*/
|
|
15112
|
+
scope(key) {
|
|
15113
|
+
const data = this[INTERNAL_DATA][key];
|
|
15114
|
+
return new _ScopedStore(
|
|
15115
|
+
data && typeof data === "object" ? data : {}
|
|
15116
|
+
);
|
|
15117
|
+
}
|
|
15118
|
+
/**
|
|
15119
|
+
* Check if a key exists in the store.
|
|
15120
|
+
*/
|
|
15121
|
+
has(key) {
|
|
15122
|
+
return key in this[INTERNAL_DATA];
|
|
15123
|
+
}
|
|
15124
|
+
/**
|
|
15125
|
+
* Get all keys in the store.
|
|
15126
|
+
*/
|
|
15127
|
+
keys() {
|
|
15128
|
+
return Object.keys(this[INTERNAL_DATA]);
|
|
15129
|
+
}
|
|
15130
|
+
};
|
|
15131
|
+
let ScopedStore = _ScopedStore;
|
|
15132
|
+
function createScopedStore(data) {
|
|
15133
|
+
return new ScopedStore(data);
|
|
15134
|
+
}
|
|
15135
|
+
function createLazyCreatorState(state) {
|
|
15136
|
+
let _uniforms = null;
|
|
15137
|
+
let _nodes = null;
|
|
15138
|
+
let _buffers = null;
|
|
15139
|
+
let _gpuStorage = null;
|
|
15140
|
+
return Object.create(state, {
|
|
15141
|
+
uniforms: {
|
|
15142
|
+
get() {
|
|
15143
|
+
return _uniforms ?? (_uniforms = createScopedStore(state.uniforms));
|
|
15144
|
+
}
|
|
15145
|
+
},
|
|
15146
|
+
nodes: {
|
|
15147
|
+
get() {
|
|
15148
|
+
return _nodes ?? (_nodes = createScopedStore(state.nodes));
|
|
15149
|
+
}
|
|
15150
|
+
},
|
|
15151
|
+
buffers: {
|
|
15152
|
+
get() {
|
|
15153
|
+
return _buffers ?? (_buffers = createScopedStore(state.buffers));
|
|
15154
|
+
}
|
|
15155
|
+
},
|
|
15156
|
+
gpuStorage: {
|
|
15157
|
+
get() {
|
|
15158
|
+
return _gpuStorage ?? (_gpuStorage = createScopedStore(state.gpuStorage));
|
|
15159
|
+
}
|
|
15160
|
+
}
|
|
15161
|
+
});
|
|
15162
|
+
}
|
|
15163
|
+
|
|
15164
|
+
function resolvePrimary(local) {
|
|
15165
|
+
return local.getState().primaryStore ?? local;
|
|
15166
|
+
}
|
|
15167
|
+
function usePrimaryStore() {
|
|
15168
|
+
const local = useStore();
|
|
15169
|
+
const primary = local.getState().primaryStore;
|
|
15170
|
+
return React.useMemo(() => primary ?? local, [primary, local]);
|
|
15171
|
+
}
|
|
15172
|
+
function usePrimaryThree(selector = (state) => state, equalityFn) {
|
|
15173
|
+
const local = useStore();
|
|
15174
|
+
const primary = resolvePrimary(local);
|
|
15175
|
+
return primary(selector, equalityFn);
|
|
15176
|
+
}
|
|
15177
|
+
|
|
15148
15178
|
function addTexture(set, key, value) {
|
|
15149
15179
|
set((state) => {
|
|
15150
15180
|
const newMap = new Map(state.textures);
|
|
@@ -15184,6 +15214,27 @@ function createTextureOperations(set) {
|
|
|
15184
15214
|
removeMultiple: (keys) => removeTextures(set, keys)
|
|
15185
15215
|
};
|
|
15186
15216
|
}
|
|
15217
|
+
function extractTSLValue(value) {
|
|
15218
|
+
if (value === null || value === void 0) return value;
|
|
15219
|
+
if (typeof value !== "object") return value;
|
|
15220
|
+
const node = value;
|
|
15221
|
+
if (!node.isNode) return value;
|
|
15222
|
+
if (node.isConstNode) {
|
|
15223
|
+
return node.value;
|
|
15224
|
+
}
|
|
15225
|
+
if ("value" in node) {
|
|
15226
|
+
let extractedValue = node.value;
|
|
15227
|
+
if (typeof node.traverse === "function") {
|
|
15228
|
+
node.traverse((n) => {
|
|
15229
|
+
if (n.isConstNode) {
|
|
15230
|
+
extractedValue = n.value;
|
|
15231
|
+
}
|
|
15232
|
+
});
|
|
15233
|
+
}
|
|
15234
|
+
return extractedValue;
|
|
15235
|
+
}
|
|
15236
|
+
return value;
|
|
15237
|
+
}
|
|
15187
15238
|
function vectorize(inObject) {
|
|
15188
15239
|
if (inObject === null || inObject === void 0) return inObject;
|
|
15189
15240
|
if (typeof inObject === "string") {
|
|
@@ -15196,9 +15247,16 @@ function vectorize(inObject) {
|
|
|
15196
15247
|
}
|
|
15197
15248
|
if (typeof inObject !== "object") return inObject;
|
|
15198
15249
|
const obj = inObject;
|
|
15250
|
+
if (obj.isNode) {
|
|
15251
|
+
return extractTSLValue(inObject);
|
|
15252
|
+
}
|
|
15199
15253
|
if (obj.isVector2 || obj.isVector3 || obj.isVector4) return inObject;
|
|
15200
15254
|
if (obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15201
15255
|
if (obj.isColor || obj.isEuler || obj.isQuaternion || obj.isSpherical) return inObject;
|
|
15256
|
+
if ("r" in obj && "g" in obj && "b" in obj && typeof obj.r === "number" && typeof obj.g === "number" && typeof obj.b === "number") {
|
|
15257
|
+
const scale = obj.r > 1 || obj.g > 1 || obj.b > 1 ? 1 / 255 : 1;
|
|
15258
|
+
return new webgpu.Color(obj.r * scale, obj.g * scale, obj.b * scale);
|
|
15259
|
+
}
|
|
15202
15260
|
if ("x" in obj && "y" in obj && typeof obj.x === "number" && typeof obj.y === "number") {
|
|
15203
15261
|
if ("w" in obj && typeof obj.w === "number" && "z" in obj && typeof obj.z === "number") {
|
|
15204
15262
|
return new webgpu.Vector4(obj.x, obj.y, obj.z, obj.w);
|
|
@@ -15222,7 +15280,7 @@ function useCompareMemoize(value, deep) {
|
|
|
15222
15280
|
|
|
15223
15281
|
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15224
15282
|
function useUniforms(creatorOrScope, scope) {
|
|
15225
|
-
const store =
|
|
15283
|
+
const store = usePrimaryStore();
|
|
15226
15284
|
const removeUniforms2 = React.useCallback(
|
|
15227
15285
|
(names, targetScope) => {
|
|
15228
15286
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -15258,21 +15316,55 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
15258
15316
|
},
|
|
15259
15317
|
[store]
|
|
15260
15318
|
);
|
|
15319
|
+
const rebuildUniforms = React.useCallback(
|
|
15320
|
+
(targetScope) => {
|
|
15321
|
+
store.setState((state) => {
|
|
15322
|
+
let newUniforms = {};
|
|
15323
|
+
if (targetScope && targetScope !== "root") {
|
|
15324
|
+
const { [targetScope]: _, ...rest } = state.uniforms;
|
|
15325
|
+
newUniforms = rest;
|
|
15326
|
+
} else if (targetScope === "root") {
|
|
15327
|
+
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15328
|
+
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
15329
|
+
}
|
|
15330
|
+
}
|
|
15331
|
+
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
15332
|
+
});
|
|
15333
|
+
},
|
|
15334
|
+
[store]
|
|
15335
|
+
);
|
|
15261
15336
|
const inputForMemoization = React.useMemo(() => {
|
|
15262
|
-
|
|
15337
|
+
let raw = creatorOrScope;
|
|
15338
|
+
if (is.fun(creatorOrScope)) {
|
|
15339
|
+
const wrappedState = createLazyCreatorState(store.getState());
|
|
15340
|
+
raw = creatorOrScope(wrappedState);
|
|
15341
|
+
}
|
|
15342
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
15343
|
+
const normalized = {};
|
|
15344
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
15345
|
+
normalized[key] = vectorize(value);
|
|
15346
|
+
}
|
|
15347
|
+
return normalized;
|
|
15348
|
+
}
|
|
15349
|
+
return raw;
|
|
15263
15350
|
}, [creatorOrScope, store]);
|
|
15264
15351
|
const memoizedInput = useCompareMemoize(inputForMemoization);
|
|
15352
|
+
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
15353
|
+
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15354
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15355
|
+
const readerDep = isReader ? storeUniforms : null;
|
|
15356
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15265
15357
|
const uniforms = React.useMemo(() => {
|
|
15266
|
-
const state = store.getState();
|
|
15267
|
-
const set = store.setState;
|
|
15268
15358
|
if (memoizedInput === void 0) {
|
|
15269
|
-
return
|
|
15359
|
+
return storeUniforms;
|
|
15270
15360
|
}
|
|
15271
15361
|
if (typeof memoizedInput === "string") {
|
|
15272
|
-
const scopeData =
|
|
15362
|
+
const scopeData = storeUniforms[memoizedInput];
|
|
15273
15363
|
if (scopeData && !isUniformNode$1(scopeData)) return scopeData;
|
|
15274
15364
|
return {};
|
|
15275
15365
|
}
|
|
15366
|
+
const state = store.getState();
|
|
15367
|
+
const set = store.setState;
|
|
15276
15368
|
if (typeof memoizedInput !== "object" || memoizedInput === null) {
|
|
15277
15369
|
throw new Error("Invalid uniform input");
|
|
15278
15370
|
}
|
|
@@ -15316,8 +15408,23 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
15316
15408
|
}
|
|
15317
15409
|
}
|
|
15318
15410
|
return result;
|
|
15319
|
-
}, [store, memoizedInput, scope]);
|
|
15320
|
-
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms };
|
|
15411
|
+
}, [store, memoizedInput, scope, readerDep, creatorDep]);
|
|
15412
|
+
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
15413
|
+
}
|
|
15414
|
+
function rebuildAllUniforms(store, scope) {
|
|
15415
|
+
store = store.getState().primaryStore ?? store;
|
|
15416
|
+
store.setState((state) => {
|
|
15417
|
+
let newUniforms = {};
|
|
15418
|
+
if (scope && scope !== "root") {
|
|
15419
|
+
const { [scope]: _, ...rest } = state.uniforms;
|
|
15420
|
+
newUniforms = rest;
|
|
15421
|
+
} else if (scope === "root") {
|
|
15422
|
+
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15423
|
+
if (!isUniformNode$1(value)) newUniforms[key] = value;
|
|
15424
|
+
}
|
|
15425
|
+
}
|
|
15426
|
+
return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
|
|
15427
|
+
});
|
|
15321
15428
|
}
|
|
15322
15429
|
function removeUniforms(set, names, scope) {
|
|
15323
15430
|
set((state) => {
|
|
@@ -15382,15 +15489,17 @@ function isSameThreeType(a, b) {
|
|
|
15382
15489
|
}
|
|
15383
15490
|
|
|
15384
15491
|
const isUniformNode = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15492
|
+
const isTSLNode$1 = (value) => value !== null && typeof value === "object" && "uuid" in value && "nodeType" in value;
|
|
15385
15493
|
function useUniform(name, value) {
|
|
15386
15494
|
const store = useStore();
|
|
15495
|
+
const hmrVersion = useThree((s) => s._hmrVersion);
|
|
15387
15496
|
return React.useMemo(() => {
|
|
15388
15497
|
const state = store.getState();
|
|
15389
15498
|
const set = store.setState;
|
|
15390
15499
|
const existing = state.uniforms[name];
|
|
15391
15500
|
if (existing && isUniformNode(existing)) {
|
|
15392
|
-
if (value !== void 0) {
|
|
15393
|
-
existing.value = value;
|
|
15501
|
+
if (value !== void 0 && !isTSLNode$1(value) && !isUniformNode(value)) {
|
|
15502
|
+
existing.value = typeof value === "string" ? new webgpu.Color(value) : value;
|
|
15394
15503
|
}
|
|
15395
15504
|
return existing;
|
|
15396
15505
|
}
|
|
@@ -15399,7 +15508,24 @@ function useUniform(name, value) {
|
|
|
15399
15508
|
`[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
|
|
15400
15509
|
);
|
|
15401
15510
|
}
|
|
15402
|
-
|
|
15511
|
+
if (isUniformNode(value)) {
|
|
15512
|
+
const node2 = value;
|
|
15513
|
+
if (typeof node2.setName === "function") {
|
|
15514
|
+
node2.setName(name);
|
|
15515
|
+
}
|
|
15516
|
+
set((s) => ({
|
|
15517
|
+
uniforms: { ...s.uniforms, [name]: node2 }
|
|
15518
|
+
}));
|
|
15519
|
+
return node2;
|
|
15520
|
+
}
|
|
15521
|
+
let node;
|
|
15522
|
+
if (isTSLNode$1(value)) {
|
|
15523
|
+
node = tsl.uniform(value);
|
|
15524
|
+
} else if (typeof value === "string") {
|
|
15525
|
+
node = tsl.uniform(new webgpu.Color(value));
|
|
15526
|
+
} else {
|
|
15527
|
+
node = tsl.uniform(value);
|
|
15528
|
+
}
|
|
15403
15529
|
if (typeof node.setName === "function") {
|
|
15404
15530
|
node.setName(name);
|
|
15405
15531
|
}
|
|
@@ -15410,12 +15536,12 @@ function useUniform(name, value) {
|
|
|
15410
15536
|
}
|
|
15411
15537
|
}));
|
|
15412
15538
|
return node;
|
|
15413
|
-
}, [store, name]);
|
|
15539
|
+
}, [store, name, hmrVersion]);
|
|
15414
15540
|
}
|
|
15415
15541
|
|
|
15416
15542
|
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
15417
15543
|
function useNodes(creatorOrScope, scope) {
|
|
15418
|
-
const store =
|
|
15544
|
+
const store = usePrimaryStore();
|
|
15419
15545
|
const removeNodes2 = React.useCallback(
|
|
15420
15546
|
(names, targetScope) => {
|
|
15421
15547
|
const nameArray = Array.isArray(names) ? names : [names];
|
|
@@ -15451,19 +15577,46 @@ function useNodes(creatorOrScope, scope) {
|
|
|
15451
15577
|
},
|
|
15452
15578
|
[store]
|
|
15453
15579
|
);
|
|
15580
|
+
const rebuildNodes = React.useCallback(
|
|
15581
|
+
(targetScope) => {
|
|
15582
|
+
store.setState((state) => {
|
|
15583
|
+
let newNodes = state.nodes;
|
|
15584
|
+
if (targetScope && targetScope !== "root") {
|
|
15585
|
+
const { [targetScope]: _, ...rest } = state.nodes;
|
|
15586
|
+
newNodes = rest;
|
|
15587
|
+
} else if (targetScope === "root") {
|
|
15588
|
+
newNodes = {};
|
|
15589
|
+
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15590
|
+
if (!isTSLNode(value)) newNodes[key] = value;
|
|
15591
|
+
}
|
|
15592
|
+
} else {
|
|
15593
|
+
newNodes = {};
|
|
15594
|
+
}
|
|
15595
|
+
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
15596
|
+
});
|
|
15597
|
+
},
|
|
15598
|
+
[store]
|
|
15599
|
+
);
|
|
15600
|
+
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15601
|
+
const storeNodes = usePrimaryThree((s) => s.nodes);
|
|
15602
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15603
|
+
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
15604
|
+
const readerDep = isReader ? storeNodes : null;
|
|
15605
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15454
15606
|
const nodes = React.useMemo(() => {
|
|
15455
|
-
const state = store.getState();
|
|
15456
|
-
const set = store.setState;
|
|
15457
15607
|
if (creatorOrScope === void 0) {
|
|
15458
|
-
return
|
|
15608
|
+
return storeNodes;
|
|
15459
15609
|
}
|
|
15460
15610
|
if (typeof creatorOrScope === "string") {
|
|
15461
|
-
const scopeData =
|
|
15611
|
+
const scopeData = storeNodes[creatorOrScope];
|
|
15462
15612
|
if (scopeData && !isTSLNode(scopeData)) return scopeData;
|
|
15463
15613
|
return {};
|
|
15464
15614
|
}
|
|
15615
|
+
const state = store.getState();
|
|
15616
|
+
const set = store.setState;
|
|
15465
15617
|
const creator = creatorOrScope;
|
|
15466
|
-
const
|
|
15618
|
+
const wrappedState = createLazyCreatorState(state);
|
|
15619
|
+
const created = creator(wrappedState);
|
|
15467
15620
|
const result = {};
|
|
15468
15621
|
let hasNewNodes = false;
|
|
15469
15622
|
if (scope) {
|
|
@@ -15472,7 +15625,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
15472
15625
|
if (currentScope[name]) {
|
|
15473
15626
|
result[name] = currentScope[name];
|
|
15474
15627
|
} else {
|
|
15475
|
-
|
|
15628
|
+
node.setName?.(`${scope}.${name}`);
|
|
15476
15629
|
result[name] = node;
|
|
15477
15630
|
hasNewNodes = true;
|
|
15478
15631
|
}
|
|
@@ -15492,7 +15645,7 @@ function useNodes(creatorOrScope, scope) {
|
|
|
15492
15645
|
if (existing && isTSLNode(existing)) {
|
|
15493
15646
|
result[name] = existing;
|
|
15494
15647
|
} else {
|
|
15495
|
-
|
|
15648
|
+
node.setName?.(name);
|
|
15496
15649
|
result[name] = node;
|
|
15497
15650
|
hasNewNodes = true;
|
|
15498
15651
|
}
|
|
@@ -15501,8 +15654,26 @@ function useNodes(creatorOrScope, scope) {
|
|
|
15501
15654
|
set((s) => ({ nodes: { ...s.nodes, ...result } }));
|
|
15502
15655
|
}
|
|
15503
15656
|
return result;
|
|
15504
|
-
}, [store,
|
|
15505
|
-
return { ...nodes, removeNodes: removeNodes2, clearNodes };
|
|
15657
|
+
}, [store, scopeDep, readerDep, creatorDep]);
|
|
15658
|
+
return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
|
|
15659
|
+
}
|
|
15660
|
+
function rebuildAllNodes(store, scope) {
|
|
15661
|
+
store = store.getState().primaryStore ?? store;
|
|
15662
|
+
store.setState((state) => {
|
|
15663
|
+
let newNodes = state.nodes;
|
|
15664
|
+
if (scope && scope !== "root") {
|
|
15665
|
+
const { [scope]: _, ...rest } = state.nodes;
|
|
15666
|
+
newNodes = rest;
|
|
15667
|
+
} else if (scope === "root") {
|
|
15668
|
+
newNodes = {};
|
|
15669
|
+
for (const [key, value] of Object.entries(state.nodes)) {
|
|
15670
|
+
if (!isTSLNode(value)) newNodes[key] = value;
|
|
15671
|
+
}
|
|
15672
|
+
} else {
|
|
15673
|
+
newNodes = {};
|
|
15674
|
+
}
|
|
15675
|
+
return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
|
|
15676
|
+
});
|
|
15506
15677
|
}
|
|
15507
15678
|
function removeNodes(set, names, scope) {
|
|
15508
15679
|
set((state) => {
|
|
@@ -15532,17 +15703,365 @@ function clearRootNodes(set) {
|
|
|
15532
15703
|
});
|
|
15533
15704
|
}
|
|
15534
15705
|
function useLocalNodes(creator) {
|
|
15535
|
-
const store =
|
|
15536
|
-
const uniforms =
|
|
15537
|
-
const nodes =
|
|
15538
|
-
const textures =
|
|
15706
|
+
const store = usePrimaryStore();
|
|
15707
|
+
const uniforms = usePrimaryThree((s) => s.uniforms);
|
|
15708
|
+
const nodes = usePrimaryThree((s) => s.nodes);
|
|
15709
|
+
const textures = usePrimaryThree((s) => s.textures);
|
|
15710
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15539
15711
|
return React.useMemo(() => {
|
|
15712
|
+
const wrappedState = createLazyCreatorState(store.getState());
|
|
15713
|
+
return creator(wrappedState);
|
|
15714
|
+
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
15715
|
+
}
|
|
15716
|
+
|
|
15717
|
+
const isBufferLike = (value) => {
|
|
15718
|
+
if (value === null || typeof value !== "object") return false;
|
|
15719
|
+
if (ArrayBuffer.isView(value)) return true;
|
|
15720
|
+
if ("isBufferAttribute" in value) return true;
|
|
15721
|
+
if ("uuid" in value || "nodeType" in value) return true;
|
|
15722
|
+
return false;
|
|
15723
|
+
};
|
|
15724
|
+
const disposeBuffer = (buffer) => {
|
|
15725
|
+
if (buffer === null || typeof buffer !== "object") return;
|
|
15726
|
+
if ("dispose" in buffer && typeof buffer.dispose === "function") {
|
|
15727
|
+
buffer.dispose();
|
|
15728
|
+
}
|
|
15729
|
+
};
|
|
15730
|
+
function useBuffers(creatorOrScope, scope) {
|
|
15731
|
+
const store = usePrimaryStore();
|
|
15732
|
+
const removeBuffers = React.useCallback(
|
|
15733
|
+
(names, targetScope) => {
|
|
15734
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15735
|
+
store.setState((state) => {
|
|
15736
|
+
if (targetScope) {
|
|
15737
|
+
const currentScope = { ...state.buffers[targetScope] };
|
|
15738
|
+
for (const name of nameArray) delete currentScope[name];
|
|
15739
|
+
return { buffers: { ...state.buffers, [targetScope]: currentScope } };
|
|
15740
|
+
}
|
|
15741
|
+
const buffers2 = { ...state.buffers };
|
|
15742
|
+
for (const name of nameArray) if (isBufferLike(buffers2[name])) delete buffers2[name];
|
|
15743
|
+
return { buffers: buffers2 };
|
|
15744
|
+
});
|
|
15745
|
+
},
|
|
15746
|
+
[store]
|
|
15747
|
+
);
|
|
15748
|
+
const clearBuffers = React.useCallback(
|
|
15749
|
+
(targetScope) => {
|
|
15750
|
+
store.setState((state) => {
|
|
15751
|
+
if (targetScope && targetScope !== "root") {
|
|
15752
|
+
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15753
|
+
return { buffers: rest };
|
|
15754
|
+
}
|
|
15755
|
+
if (targetScope === "root") {
|
|
15756
|
+
const buffers2 = {};
|
|
15757
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15758
|
+
if (!isBufferLike(value)) buffers2[key] = value;
|
|
15759
|
+
}
|
|
15760
|
+
return { buffers: buffers2 };
|
|
15761
|
+
}
|
|
15762
|
+
return { buffers: {} };
|
|
15763
|
+
});
|
|
15764
|
+
},
|
|
15765
|
+
[store]
|
|
15766
|
+
);
|
|
15767
|
+
const rebuildBuffers = React.useCallback(
|
|
15768
|
+
(targetScope) => {
|
|
15769
|
+
store.setState((state) => {
|
|
15770
|
+
let newBuffers = state.buffers;
|
|
15771
|
+
if (targetScope && targetScope !== "root") {
|
|
15772
|
+
const { [targetScope]: _, ...rest } = state.buffers;
|
|
15773
|
+
newBuffers = rest;
|
|
15774
|
+
} else if (targetScope === "root") {
|
|
15775
|
+
newBuffers = {};
|
|
15776
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15777
|
+
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15778
|
+
}
|
|
15779
|
+
} else {
|
|
15780
|
+
newBuffers = {};
|
|
15781
|
+
}
|
|
15782
|
+
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15783
|
+
});
|
|
15784
|
+
},
|
|
15785
|
+
[store]
|
|
15786
|
+
);
|
|
15787
|
+
const disposeBuffers = React.useCallback(
|
|
15788
|
+
(names, targetScope) => {
|
|
15789
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15790
|
+
const state = store.getState();
|
|
15791
|
+
for (const name of nameArray) {
|
|
15792
|
+
const buffer = targetScope ? state.buffers[targetScope]?.[name] : state.buffers[name];
|
|
15793
|
+
if (buffer && isBufferLike(buffer)) {
|
|
15794
|
+
disposeBuffer(buffer);
|
|
15795
|
+
}
|
|
15796
|
+
}
|
|
15797
|
+
removeBuffers(names, targetScope);
|
|
15798
|
+
},
|
|
15799
|
+
[store, removeBuffers]
|
|
15800
|
+
);
|
|
15801
|
+
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15802
|
+
const storeBuffers = usePrimaryThree((s) => s.buffers);
|
|
15803
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15804
|
+
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
15805
|
+
const readerDep = isReader ? storeBuffers : null;
|
|
15806
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15807
|
+
const buffers = React.useMemo(() => {
|
|
15808
|
+
if (creatorOrScope === void 0) {
|
|
15809
|
+
return storeBuffers;
|
|
15810
|
+
}
|
|
15811
|
+
if (typeof creatorOrScope === "string") {
|
|
15812
|
+
const scopeData = storeBuffers[creatorOrScope];
|
|
15813
|
+
if (scopeData && !isBufferLike(scopeData)) return scopeData;
|
|
15814
|
+
return {};
|
|
15815
|
+
}
|
|
15816
|
+
const state = store.getState();
|
|
15817
|
+
const set = store.setState;
|
|
15818
|
+
const creator = creatorOrScope;
|
|
15819
|
+
const wrappedState = createLazyCreatorState(state);
|
|
15820
|
+
const created = creator(wrappedState);
|
|
15821
|
+
const result = {};
|
|
15822
|
+
let hasNewBuffers = false;
|
|
15823
|
+
if (scope) {
|
|
15824
|
+
const currentScope = state.buffers[scope] ?? {};
|
|
15825
|
+
for (const [name, buffer] of Object.entries(created)) {
|
|
15826
|
+
if (currentScope[name]) {
|
|
15827
|
+
result[name] = currentScope[name];
|
|
15828
|
+
} else {
|
|
15829
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15830
|
+
buffer.setName(`${scope}.${name}`);
|
|
15831
|
+
}
|
|
15832
|
+
result[name] = buffer;
|
|
15833
|
+
hasNewBuffers = true;
|
|
15834
|
+
}
|
|
15835
|
+
}
|
|
15836
|
+
if (hasNewBuffers) {
|
|
15837
|
+
set((s) => ({
|
|
15838
|
+
buffers: {
|
|
15839
|
+
...s.buffers,
|
|
15840
|
+
[scope]: { ...s.buffers[scope], ...result }
|
|
15841
|
+
}
|
|
15842
|
+
}));
|
|
15843
|
+
}
|
|
15844
|
+
return result;
|
|
15845
|
+
}
|
|
15846
|
+
for (const [name, buffer] of Object.entries(created)) {
|
|
15847
|
+
const existing = state.buffers[name];
|
|
15848
|
+
if (existing && isBufferLike(existing)) {
|
|
15849
|
+
result[name] = existing;
|
|
15850
|
+
} else {
|
|
15851
|
+
if ("setName" in buffer && typeof buffer.setName === "function") {
|
|
15852
|
+
buffer.setName(name);
|
|
15853
|
+
}
|
|
15854
|
+
result[name] = buffer;
|
|
15855
|
+
hasNewBuffers = true;
|
|
15856
|
+
}
|
|
15857
|
+
}
|
|
15858
|
+
if (hasNewBuffers) {
|
|
15859
|
+
set((s) => ({ buffers: { ...s.buffers, ...result } }));
|
|
15860
|
+
}
|
|
15861
|
+
return result;
|
|
15862
|
+
}, [store, scopeDep, readerDep, creatorDep]);
|
|
15863
|
+
return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
|
|
15864
|
+
}
|
|
15865
|
+
function rebuildAllBuffers(store, scope) {
|
|
15866
|
+
store = store.getState().primaryStore ?? store;
|
|
15867
|
+
store.setState((state) => {
|
|
15868
|
+
let newBuffers = state.buffers;
|
|
15869
|
+
if (scope && scope !== "root") {
|
|
15870
|
+
const { [scope]: _, ...rest } = state.buffers;
|
|
15871
|
+
newBuffers = rest;
|
|
15872
|
+
} else if (scope === "root") {
|
|
15873
|
+
newBuffers = {};
|
|
15874
|
+
for (const [key, value] of Object.entries(state.buffers)) {
|
|
15875
|
+
if (!isBufferLike(value)) newBuffers[key] = value;
|
|
15876
|
+
}
|
|
15877
|
+
} else {
|
|
15878
|
+
newBuffers = {};
|
|
15879
|
+
}
|
|
15880
|
+
return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
|
|
15881
|
+
});
|
|
15882
|
+
}
|
|
15883
|
+
|
|
15884
|
+
const isStorageLike = (value) => {
|
|
15885
|
+
if (value === null || typeof value !== "object") return false;
|
|
15886
|
+
if ("isTexture" in value) return true;
|
|
15887
|
+
if ("isData3DTexture" in value) return true;
|
|
15888
|
+
if ("uuid" in value || "nodeType" in value) return true;
|
|
15889
|
+
return false;
|
|
15890
|
+
};
|
|
15891
|
+
const disposeStorage = (storage) => {
|
|
15892
|
+
if (storage === null || typeof storage !== "object") return;
|
|
15893
|
+
if ("dispose" in storage && typeof storage.dispose === "function") {
|
|
15894
|
+
storage.dispose();
|
|
15895
|
+
}
|
|
15896
|
+
};
|
|
15897
|
+
function useGPUStorage(creatorOrScope, scope) {
|
|
15898
|
+
const store = usePrimaryStore();
|
|
15899
|
+
const removeStorage = React.useCallback(
|
|
15900
|
+
(names, targetScope) => {
|
|
15901
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15902
|
+
store.setState((state) => {
|
|
15903
|
+
if (targetScope) {
|
|
15904
|
+
const currentScope = { ...state.gpuStorage[targetScope] };
|
|
15905
|
+
for (const name of nameArray) delete currentScope[name];
|
|
15906
|
+
return { gpuStorage: { ...state.gpuStorage, [targetScope]: currentScope } };
|
|
15907
|
+
}
|
|
15908
|
+
const gpuStorage2 = { ...state.gpuStorage };
|
|
15909
|
+
for (const name of nameArray) if (isStorageLike(gpuStorage2[name])) delete gpuStorage2[name];
|
|
15910
|
+
return { gpuStorage: gpuStorage2 };
|
|
15911
|
+
});
|
|
15912
|
+
},
|
|
15913
|
+
[store]
|
|
15914
|
+
);
|
|
15915
|
+
const clearStorage = React.useCallback(
|
|
15916
|
+
(targetScope) => {
|
|
15917
|
+
store.setState((state) => {
|
|
15918
|
+
if (targetScope && targetScope !== "root") {
|
|
15919
|
+
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15920
|
+
return { gpuStorage: rest };
|
|
15921
|
+
}
|
|
15922
|
+
if (targetScope === "root") {
|
|
15923
|
+
const gpuStorage2 = {};
|
|
15924
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15925
|
+
if (!isStorageLike(value)) gpuStorage2[key] = value;
|
|
15926
|
+
}
|
|
15927
|
+
return { gpuStorage: gpuStorage2 };
|
|
15928
|
+
}
|
|
15929
|
+
return { gpuStorage: {} };
|
|
15930
|
+
});
|
|
15931
|
+
},
|
|
15932
|
+
[store]
|
|
15933
|
+
);
|
|
15934
|
+
const rebuildStorage = React.useCallback(
|
|
15935
|
+
(targetScope) => {
|
|
15936
|
+
store.setState((state) => {
|
|
15937
|
+
let newStorage = state.gpuStorage;
|
|
15938
|
+
if (targetScope && targetScope !== "root") {
|
|
15939
|
+
const { [targetScope]: _, ...rest } = state.gpuStorage;
|
|
15940
|
+
newStorage = rest;
|
|
15941
|
+
} else if (targetScope === "root") {
|
|
15942
|
+
newStorage = {};
|
|
15943
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
15944
|
+
if (!isStorageLike(value)) newStorage[key] = value;
|
|
15945
|
+
}
|
|
15946
|
+
} else {
|
|
15947
|
+
newStorage = {};
|
|
15948
|
+
}
|
|
15949
|
+
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
15950
|
+
});
|
|
15951
|
+
},
|
|
15952
|
+
[store]
|
|
15953
|
+
);
|
|
15954
|
+
const disposeStorageFn = React.useCallback(
|
|
15955
|
+
(names, targetScope) => {
|
|
15956
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
15957
|
+
const state = store.getState();
|
|
15958
|
+
for (const name of nameArray) {
|
|
15959
|
+
const storage = targetScope ? state.gpuStorage[targetScope]?.[name] : state.gpuStorage[name];
|
|
15960
|
+
if (storage && isStorageLike(storage)) {
|
|
15961
|
+
disposeStorage(storage);
|
|
15962
|
+
}
|
|
15963
|
+
}
|
|
15964
|
+
removeStorage(names, targetScope);
|
|
15965
|
+
},
|
|
15966
|
+
[store, removeStorage]
|
|
15967
|
+
);
|
|
15968
|
+
const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
|
|
15969
|
+
const storeStorage = usePrimaryThree((s) => s.gpuStorage);
|
|
15970
|
+
const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
|
|
15971
|
+
const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
|
|
15972
|
+
const readerDep = isReader ? storeStorage : null;
|
|
15973
|
+
const creatorDep = isReader ? null : hmrVersion;
|
|
15974
|
+
const gpuStorage = React.useMemo(() => {
|
|
15975
|
+
if (creatorOrScope === void 0) {
|
|
15976
|
+
return storeStorage;
|
|
15977
|
+
}
|
|
15978
|
+
if (typeof creatorOrScope === "string") {
|
|
15979
|
+
const scopeData = storeStorage[creatorOrScope];
|
|
15980
|
+
if (scopeData && !isStorageLike(scopeData)) return scopeData;
|
|
15981
|
+
return {};
|
|
15982
|
+
}
|
|
15540
15983
|
const state = store.getState();
|
|
15541
|
-
|
|
15542
|
-
|
|
15984
|
+
const set = store.setState;
|
|
15985
|
+
const creator = creatorOrScope;
|
|
15986
|
+
const wrappedState = createLazyCreatorState(state);
|
|
15987
|
+
const created = creator(wrappedState);
|
|
15988
|
+
const result = {};
|
|
15989
|
+
let hasNewStorage = false;
|
|
15990
|
+
if (scope) {
|
|
15991
|
+
const currentScope = state.gpuStorage[scope] ?? {};
|
|
15992
|
+
for (const [name, storage] of Object.entries(created)) {
|
|
15993
|
+
if (currentScope[name]) {
|
|
15994
|
+
result[name] = currentScope[name];
|
|
15995
|
+
} else {
|
|
15996
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
15997
|
+
storage.setName(`${scope}.${name}`);
|
|
15998
|
+
}
|
|
15999
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
16000
|
+
storage.name = `${scope}.${name}`;
|
|
16001
|
+
}
|
|
16002
|
+
result[name] = storage;
|
|
16003
|
+
hasNewStorage = true;
|
|
16004
|
+
}
|
|
16005
|
+
}
|
|
16006
|
+
if (hasNewStorage) {
|
|
16007
|
+
set((s) => ({
|
|
16008
|
+
gpuStorage: {
|
|
16009
|
+
...s.gpuStorage,
|
|
16010
|
+
[scope]: { ...s.gpuStorage[scope], ...result }
|
|
16011
|
+
}
|
|
16012
|
+
}));
|
|
16013
|
+
}
|
|
16014
|
+
return result;
|
|
16015
|
+
}
|
|
16016
|
+
for (const [name, storage] of Object.entries(created)) {
|
|
16017
|
+
const existing = state.gpuStorage[name];
|
|
16018
|
+
if (existing && isStorageLike(existing)) {
|
|
16019
|
+
result[name] = existing;
|
|
16020
|
+
} else {
|
|
16021
|
+
if ("setName" in storage && typeof storage.setName === "function") {
|
|
16022
|
+
storage.setName(name);
|
|
16023
|
+
}
|
|
16024
|
+
if ("name" in storage && typeof storage.name === "string") {
|
|
16025
|
+
storage.name = name;
|
|
16026
|
+
}
|
|
16027
|
+
result[name] = storage;
|
|
16028
|
+
hasNewStorage = true;
|
|
16029
|
+
}
|
|
16030
|
+
}
|
|
16031
|
+
if (hasNewStorage) {
|
|
16032
|
+
set((s) => ({ gpuStorage: { ...s.gpuStorage, ...result } }));
|
|
16033
|
+
}
|
|
16034
|
+
return result;
|
|
16035
|
+
}, [store, scopeDep, readerDep, creatorDep]);
|
|
16036
|
+
return {
|
|
16037
|
+
...gpuStorage,
|
|
16038
|
+
removeStorage,
|
|
16039
|
+
clearStorage,
|
|
16040
|
+
rebuildStorage,
|
|
16041
|
+
disposeStorage: disposeStorageFn
|
|
16042
|
+
};
|
|
16043
|
+
}
|
|
16044
|
+
function rebuildAllStorage(store, scope) {
|
|
16045
|
+
store = store.getState().primaryStore ?? store;
|
|
16046
|
+
store.setState((state) => {
|
|
16047
|
+
let newStorage = state.gpuStorage;
|
|
16048
|
+
if (scope && scope !== "root") {
|
|
16049
|
+
const { [scope]: _, ...rest } = state.gpuStorage;
|
|
16050
|
+
newStorage = rest;
|
|
16051
|
+
} else if (scope === "root") {
|
|
16052
|
+
newStorage = {};
|
|
16053
|
+
for (const [key, value] of Object.entries(state.gpuStorage)) {
|
|
16054
|
+
if (!isStorageLike(value)) newStorage[key] = value;
|
|
16055
|
+
}
|
|
16056
|
+
} else {
|
|
16057
|
+
newStorage = {};
|
|
16058
|
+
}
|
|
16059
|
+
return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
|
|
16060
|
+
});
|
|
15543
16061
|
}
|
|
15544
16062
|
|
|
15545
|
-
|
|
16063
|
+
const RenderPipelineCtor = webgpu.RenderPipeline ?? webgpu.PostProcessing;
|
|
16064
|
+
function useRenderPipeline(mainCB, setupCB) {
|
|
15546
16065
|
const store = useStore();
|
|
15547
16066
|
const { scene, camera, renderer, isLegacy } = useThree();
|
|
15548
16067
|
const callbacksRanRef = React.useRef(false);
|
|
@@ -15552,12 +16071,16 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
15552
16071
|
mainCBRef.current = mainCB;
|
|
15553
16072
|
setupCBRef.current = setupCB;
|
|
15554
16073
|
const [rebuildVersion, setRebuildVersion] = React.useState(0);
|
|
16074
|
+
React.useEffect(() => {
|
|
16075
|
+
callbacksRanRef.current = false;
|
|
16076
|
+
scenePassCacheRef.current = null;
|
|
16077
|
+
}, []);
|
|
15555
16078
|
const clearPasses = React.useCallback(() => {
|
|
15556
16079
|
store.setState({ passes: {} });
|
|
15557
16080
|
}, [store]);
|
|
15558
16081
|
const reset = React.useCallback(() => {
|
|
15559
16082
|
store.setState({
|
|
15560
|
-
|
|
16083
|
+
renderPipeline: null,
|
|
15561
16084
|
passes: {}
|
|
15562
16085
|
});
|
|
15563
16086
|
callbacksRanRef.current = false;
|
|
@@ -15570,18 +16093,18 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
15570
16093
|
}, []);
|
|
15571
16094
|
React.useLayoutEffect(() => {
|
|
15572
16095
|
if (isLegacy) {
|
|
15573
|
-
throw new Error("
|
|
16096
|
+
throw new Error("useRenderPipeline is only available with WebGPU renderer. Set renderer prop on Canvas.");
|
|
15574
16097
|
}
|
|
15575
16098
|
if (!renderer || !scene || !camera) return;
|
|
15576
16099
|
const state = store.getState();
|
|
15577
16100
|
const set = store.setState;
|
|
15578
16101
|
try {
|
|
15579
|
-
let
|
|
16102
|
+
let pipeline = state.renderPipeline;
|
|
15580
16103
|
let currentPasses = { ...state.passes };
|
|
15581
|
-
let
|
|
15582
|
-
if (!
|
|
15583
|
-
|
|
15584
|
-
|
|
16104
|
+
let justCreatedPipeline = false;
|
|
16105
|
+
if (!pipeline) {
|
|
16106
|
+
pipeline = new RenderPipelineCtor(renderer);
|
|
16107
|
+
justCreatedPipeline = true;
|
|
15585
16108
|
}
|
|
15586
16109
|
const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
15587
16110
|
let scenePass;
|
|
@@ -15592,9 +16115,9 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
15592
16115
|
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
15593
16116
|
}
|
|
15594
16117
|
currentPasses.scenePass = scenePass;
|
|
15595
|
-
if (!
|
|
15596
|
-
set({
|
|
15597
|
-
const shouldRunCallbacks =
|
|
16118
|
+
if (!pipeline.outputNode || justCreatedPipeline) pipeline.outputNode = scenePass;
|
|
16119
|
+
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
16120
|
+
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
15598
16121
|
if (shouldRunCallbacks) {
|
|
15599
16122
|
if (setupCBRef.current) {
|
|
15600
16123
|
const freshState = store.getState();
|
|
@@ -15615,33 +16138,41 @@ function usePostProcessing(mainCB, setupCB) {
|
|
|
15615
16138
|
callbacksRanRef.current = true;
|
|
15616
16139
|
}
|
|
15617
16140
|
} catch (error) {
|
|
15618
|
-
console.error("[
|
|
16141
|
+
console.error("[useRenderPipeline] Setup error:", error);
|
|
15619
16142
|
}
|
|
15620
16143
|
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
15621
16144
|
const passes = useThree((s) => s.passes);
|
|
15622
|
-
const
|
|
16145
|
+
const renderPipeline = useThree((s) => s.renderPipeline);
|
|
15623
16146
|
return {
|
|
15624
16147
|
passes,
|
|
15625
|
-
|
|
16148
|
+
renderPipeline,
|
|
15626
16149
|
clearPasses,
|
|
15627
16150
|
reset,
|
|
15628
16151
|
rebuild,
|
|
15629
|
-
// isReady indicates if
|
|
15630
|
-
isReady:
|
|
16152
|
+
// isReady indicates if RenderPipeline is configured and ready for rendering
|
|
16153
|
+
isReady: renderPipeline !== null
|
|
15631
16154
|
};
|
|
15632
16155
|
}
|
|
15633
16156
|
|
|
15634
16157
|
extend(THREE);
|
|
15635
16158
|
|
|
16159
|
+
exports.Scheduler = scheduler.Scheduler;
|
|
16160
|
+
exports.getScheduler = scheduler.getScheduler;
|
|
15636
16161
|
exports.Block = Block;
|
|
15637
16162
|
exports.Canvas = Canvas;
|
|
16163
|
+
exports.Environment = Environment;
|
|
16164
|
+
exports.EnvironmentCube = EnvironmentCube;
|
|
16165
|
+
exports.EnvironmentMap = EnvironmentMap;
|
|
16166
|
+
exports.EnvironmentPortal = EnvironmentPortal;
|
|
15638
16167
|
exports.ErrorBoundary = ErrorBoundary;
|
|
16168
|
+
exports.FROM_REF = FROM_REF;
|
|
15639
16169
|
exports.IsObject = IsObject;
|
|
16170
|
+
exports.ONCE = ONCE;
|
|
16171
|
+
exports.Portal = Portal;
|
|
15640
16172
|
exports.R3F_BUILD_LEGACY = R3F_BUILD_LEGACY;
|
|
15641
16173
|
exports.R3F_BUILD_WEBGPU = R3F_BUILD_WEBGPU;
|
|
15642
16174
|
exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
15643
16175
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
15644
|
-
exports.Scheduler = Scheduler;
|
|
15645
16176
|
exports.Texture = Texture;
|
|
15646
16177
|
exports._roots = _roots;
|
|
15647
16178
|
exports.act = act;
|
|
@@ -15662,6 +16193,7 @@ exports.createEvents = createEvents;
|
|
|
15662
16193
|
exports.createPointerEvents = createPointerEvents;
|
|
15663
16194
|
exports.createPortal = createPortal;
|
|
15664
16195
|
exports.createRoot = createRoot;
|
|
16196
|
+
exports.createScopedStore = createScopedStore;
|
|
15665
16197
|
exports.createStore = createStore;
|
|
15666
16198
|
exports.createTextureOperations = createTextureOperations;
|
|
15667
16199
|
exports.detach = detach;
|
|
@@ -15671,33 +16203,49 @@ exports.events = createPointerEvents;
|
|
|
15671
16203
|
exports.extend = extend;
|
|
15672
16204
|
exports.findInitialRoot = findInitialRoot;
|
|
15673
16205
|
exports.flushSync = flushSync;
|
|
16206
|
+
exports.fromRef = fromRef;
|
|
15674
16207
|
exports.getInstanceProps = getInstanceProps;
|
|
16208
|
+
exports.getPrimary = getPrimary;
|
|
16209
|
+
exports.getPrimaryIds = getPrimaryIds;
|
|
15675
16210
|
exports.getRootState = getRootState;
|
|
15676
|
-
exports.getScheduler = getScheduler;
|
|
15677
16211
|
exports.getUuidPrefix = getUuidPrefix;
|
|
15678
16212
|
exports.hasConstructor = hasConstructor;
|
|
16213
|
+
exports.hasPrimary = hasPrimary;
|
|
15679
16214
|
exports.invalidate = invalidate;
|
|
15680
16215
|
exports.invalidateInstance = invalidateInstance;
|
|
15681
16216
|
exports.is = is;
|
|
15682
16217
|
exports.isColorRepresentation = isColorRepresentation;
|
|
15683
16218
|
exports.isCopyable = isCopyable;
|
|
16219
|
+
exports.isFromRef = isFromRef;
|
|
15684
16220
|
exports.isObject3D = isObject3D;
|
|
16221
|
+
exports.isOnce = isOnce;
|
|
15685
16222
|
exports.isOrthographicCamera = isOrthographicCamera;
|
|
15686
16223
|
exports.isRef = isRef;
|
|
15687
16224
|
exports.isRenderer = isRenderer;
|
|
15688
16225
|
exports.isTexture = isTexture;
|
|
15689
16226
|
exports.isVectorLike = isVectorLike;
|
|
16227
|
+
exports.once = once;
|
|
15690
16228
|
exports.prepare = prepare;
|
|
16229
|
+
exports.presetsObj = presetsObj;
|
|
16230
|
+
exports.rebuildAllBuffers = rebuildAllBuffers;
|
|
16231
|
+
exports.rebuildAllNodes = rebuildAllNodes;
|
|
16232
|
+
exports.rebuildAllStorage = rebuildAllStorage;
|
|
16233
|
+
exports.rebuildAllUniforms = rebuildAllUniforms;
|
|
15691
16234
|
exports.reconciler = reconciler;
|
|
16235
|
+
exports.registerPrimary = registerPrimary;
|
|
15692
16236
|
exports.removeInteractivity = removeInteractivity;
|
|
15693
16237
|
exports.removeNodes = removeNodes;
|
|
15694
16238
|
exports.removeUniforms = removeUniforms;
|
|
15695
16239
|
exports.resolve = resolve;
|
|
15696
16240
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
16241
|
+
exports.unregisterPrimary = unregisterPrimary;
|
|
15697
16242
|
exports.updateCamera = updateCamera;
|
|
15698
16243
|
exports.updateFrustum = updateFrustum;
|
|
15699
16244
|
exports.useBridge = useBridge;
|
|
16245
|
+
exports.useBuffers = useBuffers;
|
|
16246
|
+
exports.useEnvironment = useEnvironment;
|
|
15700
16247
|
exports.useFrame = useFrame;
|
|
16248
|
+
exports.useGPUStorage = useGPUStorage;
|
|
15701
16249
|
exports.useGraph = useGraph;
|
|
15702
16250
|
exports.useInstanceHandle = useInstanceHandle;
|
|
15703
16251
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
@@ -15705,7 +16253,7 @@ exports.useLoader = useLoader;
|
|
|
15705
16253
|
exports.useLocalNodes = useLocalNodes;
|
|
15706
16254
|
exports.useMutableCallback = useMutableCallback;
|
|
15707
16255
|
exports.useNodes = useNodes;
|
|
15708
|
-
exports.
|
|
16256
|
+
exports.useRenderPipeline = useRenderPipeline;
|
|
15709
16257
|
exports.useRenderTarget = useRenderTarget;
|
|
15710
16258
|
exports.useStore = useStore;
|
|
15711
16259
|
exports.useTexture = useTexture;
|
|
@@ -15713,3 +16261,4 @@ exports.useTextures = useTextures;
|
|
|
15713
16261
|
exports.useThree = useThree;
|
|
15714
16262
|
exports.useUniform = useUniform;
|
|
15715
16263
|
exports.useUniforms = useUniforms;
|
|
16264
|
+
exports.waitForPrimary = waitForPrimary;
|