@react-three/fiber 10.0.0-alpha.1 → 10.0.0-canary.164c7be
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 +1256 -1419
- package/dist/index.d.cts +1887 -1699
- package/dist/index.d.mts +1887 -1699
- package/dist/index.d.ts +1887 -1699
- package/dist/index.mjs +1216 -1398
- package/dist/legacy.cjs +1222 -1410
- package/dist/legacy.d.cts +1888 -1700
- package/dist/legacy.d.mts +1888 -1700
- package/dist/legacy.d.ts +1888 -1700
- package/dist/legacy.mjs +1182 -1389
- package/dist/webgpu/index.cjs +1937 -1470
- package/dist/webgpu/index.d.cts +2145 -1722
- package/dist/webgpu/index.d.mts +2145 -1722
- package/dist/webgpu/index.d.ts +2145 -1722
- package/dist/webgpu/index.mjs +1890 -1449
- 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/legacy.mjs
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import * as three from 'three';
|
|
2
|
-
import { WebGLRenderTarget, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1,
|
|
3
|
-
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { WebGLRenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGLRenderer } from 'three';
|
|
3
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import React__default, {
|
|
5
|
+
import React__default, { useLayoutEffect, useRef, useMemo, useEffect, useContext, useImperativeHandle, useCallback, useState } from 'react';
|
|
6
6
|
import useMeasure from 'react-use-measure';
|
|
7
7
|
import { useFiber, useContextBridge, traverseFiber, FiberProvider } from 'its-fine';
|
|
8
|
+
import { useThree as useThree$1, useLoader as useLoader$1, useFrame as useFrame$1, createPortal as createPortal$1, applyProps as applyProps$1, extend as extend$1 } from '@react-three/fiber';
|
|
9
|
+
import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
|
|
10
|
+
import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
|
|
11
|
+
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
12
|
+
import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
13
|
+
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
8
14
|
import Tb, { unstable_scheduleCallback, unstable_IdlePriority } from 'scheduler';
|
|
9
15
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
16
|
+
import { getScheduler } from '@pmndrs/scheduler';
|
|
17
|
+
export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
10
18
|
import { suspend, preload, clear } from 'suspend-react';
|
|
11
19
|
|
|
12
20
|
function _mergeNamespaces(n, m) {
|
|
@@ -45,9 +53,392 @@ const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
|
45
53
|
WebGPURenderer: WebGPURenderer
|
|
46
54
|
}, [three]);
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
const primaryRegistry = /* @__PURE__ */ new Map();
|
|
57
|
+
const pendingSubscribers = /* @__PURE__ */ new Map();
|
|
58
|
+
function registerPrimary(id, renderer, store) {
|
|
59
|
+
if (primaryRegistry.has(id)) {
|
|
60
|
+
console.warn(`Canvas with id="${id}" already registered. Overwriting.`);
|
|
61
|
+
}
|
|
62
|
+
const entry = { renderer, store };
|
|
63
|
+
primaryRegistry.set(id, entry);
|
|
64
|
+
const subscribers = pendingSubscribers.get(id);
|
|
65
|
+
if (subscribers) {
|
|
66
|
+
subscribers.forEach((callback) => callback(entry));
|
|
67
|
+
pendingSubscribers.delete(id);
|
|
68
|
+
}
|
|
69
|
+
return () => {
|
|
70
|
+
const currentEntry = primaryRegistry.get(id);
|
|
71
|
+
if (currentEntry?.renderer === renderer) {
|
|
72
|
+
primaryRegistry.delete(id);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getPrimary(id) {
|
|
77
|
+
return primaryRegistry.get(id);
|
|
78
|
+
}
|
|
79
|
+
function waitForPrimary(id, timeout = 5e3) {
|
|
80
|
+
const existing = primaryRegistry.get(id);
|
|
81
|
+
if (existing) {
|
|
82
|
+
return Promise.resolve(existing);
|
|
83
|
+
}
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const timeoutId = setTimeout(() => {
|
|
86
|
+
const subscribers = pendingSubscribers.get(id);
|
|
87
|
+
if (subscribers) {
|
|
88
|
+
const index = subscribers.indexOf(callback);
|
|
89
|
+
if (index !== -1) subscribers.splice(index, 1);
|
|
90
|
+
if (subscribers.length === 0) pendingSubscribers.delete(id);
|
|
91
|
+
}
|
|
92
|
+
reject(new Error(`Timeout waiting for canvas with id="${id}". Make sure a <Canvas id="${id}"> is mounted.`));
|
|
93
|
+
}, timeout);
|
|
94
|
+
const callback = (entry) => {
|
|
95
|
+
clearTimeout(timeoutId);
|
|
96
|
+
resolve(entry);
|
|
97
|
+
};
|
|
98
|
+
if (!pendingSubscribers.has(id)) {
|
|
99
|
+
pendingSubscribers.set(id, []);
|
|
100
|
+
}
|
|
101
|
+
pendingSubscribers.get(id).push(callback);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function hasPrimary(id) {
|
|
105
|
+
return primaryRegistry.has(id);
|
|
106
|
+
}
|
|
107
|
+
function unregisterPrimary(id) {
|
|
108
|
+
primaryRegistry.delete(id);
|
|
109
|
+
}
|
|
110
|
+
function getPrimaryIds() {
|
|
111
|
+
return Array.from(primaryRegistry.keys());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const presetsObj = {
|
|
115
|
+
apartment: "lebombo_1k.hdr",
|
|
116
|
+
city: "potsdamer_platz_1k.hdr",
|
|
117
|
+
dawn: "kiara_1_dawn_1k.hdr",
|
|
118
|
+
forest: "forest_slope_1k.hdr",
|
|
119
|
+
lobby: "st_fagans_interior_1k.hdr",
|
|
120
|
+
night: "dikhololo_night_1k.hdr",
|
|
121
|
+
park: "rooitou_park_1k.hdr",
|
|
122
|
+
studio: "studio_small_03_1k.hdr",
|
|
123
|
+
sunset: "venice_sunset_1k.hdr",
|
|
124
|
+
warehouse: "empty_warehouse_01_1k.hdr"
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const CUBEMAP_ROOT = "https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/";
|
|
128
|
+
const isArray = (arr) => Array.isArray(arr);
|
|
129
|
+
const defaultFiles = ["/px.png", "/nx.png", "/py.png", "/ny.png", "/pz.png", "/nz.png"];
|
|
130
|
+
function useEnvironment({
|
|
131
|
+
files = defaultFiles,
|
|
132
|
+
path = "",
|
|
133
|
+
preset = void 0,
|
|
134
|
+
colorSpace = void 0,
|
|
135
|
+
extensions
|
|
136
|
+
} = {}) {
|
|
137
|
+
if (preset) {
|
|
138
|
+
validatePreset(preset);
|
|
139
|
+
files = presetsObj[preset];
|
|
140
|
+
path = CUBEMAP_ROOT;
|
|
141
|
+
}
|
|
142
|
+
const multiFile = isArray(files);
|
|
143
|
+
const { extension, isCubemap } = getExtension(files);
|
|
144
|
+
const loader = getLoader$1(extension);
|
|
145
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
146
|
+
const renderer = useThree$1((state) => state.renderer);
|
|
147
|
+
useLayoutEffect(() => {
|
|
148
|
+
if (extension !== "webp" && extension !== "jpg" && extension !== "jpeg") return;
|
|
149
|
+
function clearGainmapTexture() {
|
|
150
|
+
useLoader$1.clear(loader, multiFile ? [files] : files);
|
|
151
|
+
}
|
|
152
|
+
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
153
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
154
|
+
const loaderResult = useLoader$1(
|
|
155
|
+
loader,
|
|
156
|
+
multiFile ? [files] : files,
|
|
157
|
+
(loader2) => {
|
|
158
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
159
|
+
loader2.setRenderer?.(renderer);
|
|
160
|
+
}
|
|
161
|
+
loader2.setPath?.(path);
|
|
162
|
+
if (extensions) extensions(loader2);
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
let texture = multiFile ? (
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
loaderResult[0]
|
|
168
|
+
) : loaderResult;
|
|
169
|
+
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
170
|
+
texture = texture.renderTarget?.texture;
|
|
171
|
+
}
|
|
172
|
+
texture.mapping = isCubemap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
173
|
+
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
174
|
+
return texture;
|
|
175
|
+
}
|
|
176
|
+
const preloadDefaultOptions = {
|
|
177
|
+
files: defaultFiles,
|
|
178
|
+
path: "",
|
|
179
|
+
preset: void 0,
|
|
180
|
+
extensions: void 0
|
|
181
|
+
};
|
|
182
|
+
useEnvironment.preload = (preloadOptions) => {
|
|
183
|
+
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
184
|
+
let { files, path = "" } = options;
|
|
185
|
+
const { preset, extensions } = options;
|
|
186
|
+
if (preset) {
|
|
187
|
+
validatePreset(preset);
|
|
188
|
+
files = presetsObj[preset];
|
|
189
|
+
path = CUBEMAP_ROOT;
|
|
190
|
+
}
|
|
191
|
+
const { extension } = getExtension(files);
|
|
192
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
193
|
+
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
194
|
+
}
|
|
195
|
+
const loader = getLoader$1(extension);
|
|
196
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
197
|
+
useLoader$1.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
198
|
+
loader2.setPath?.(path);
|
|
199
|
+
if (extensions) extensions(loader2);
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
const clearDefaultOptins = {
|
|
203
|
+
files: defaultFiles,
|
|
204
|
+
preset: void 0
|
|
205
|
+
};
|
|
206
|
+
useEnvironment.clear = (clearOptions) => {
|
|
207
|
+
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
208
|
+
let { files } = options;
|
|
209
|
+
const { preset } = options;
|
|
210
|
+
if (preset) {
|
|
211
|
+
validatePreset(preset);
|
|
212
|
+
files = presetsObj[preset];
|
|
213
|
+
}
|
|
214
|
+
const { extension } = getExtension(files);
|
|
215
|
+
const loader = getLoader$1(extension);
|
|
216
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
217
|
+
useLoader$1.clear(loader, isArray(files) ? [files] : files);
|
|
218
|
+
};
|
|
219
|
+
function validatePreset(preset) {
|
|
220
|
+
if (!(preset in presetsObj)) throw new Error("Preset must be one of: " + Object.keys(presetsObj).join(", "));
|
|
221
|
+
}
|
|
222
|
+
function getExtension(files) {
|
|
223
|
+
const isCubemap = isArray(files) && files.length === 6;
|
|
224
|
+
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
225
|
+
const firstEntry = isArray(files) ? files[0] : files;
|
|
226
|
+
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();
|
|
227
|
+
return { extension, isCubemap, isGainmap };
|
|
228
|
+
}
|
|
229
|
+
function getLoader$1(extension) {
|
|
230
|
+
const loader = extension === "cube" ? CubeTextureLoader : extension === "hdr" ? HDRLoader : extension === "exr" ? EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader : extension === "webp" ? GainMapLoader : null;
|
|
231
|
+
return loader;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const isRef$1 = (obj) => obj.current && obj.current.isScene;
|
|
235
|
+
const resolveScene = (scene) => isRef$1(scene) ? scene.current : scene;
|
|
236
|
+
function setEnvProps(background, scene, defaultScene, texture, sceneProps = {}) {
|
|
237
|
+
sceneProps = {
|
|
238
|
+
backgroundBlurriness: 0,
|
|
239
|
+
backgroundIntensity: 1,
|
|
240
|
+
backgroundRotation: [0, 0, 0],
|
|
241
|
+
environmentIntensity: 1,
|
|
242
|
+
environmentRotation: [0, 0, 0],
|
|
243
|
+
...sceneProps
|
|
244
|
+
};
|
|
245
|
+
const target = resolveScene(scene || defaultScene);
|
|
246
|
+
const oldbg = target.background;
|
|
247
|
+
const oldenv = target.environment;
|
|
248
|
+
const oldSceneProps = {
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
backgroundBlurriness: target.backgroundBlurriness,
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
backgroundIntensity: target.backgroundIntensity,
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
environmentIntensity: target.environmentIntensity,
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
259
|
+
};
|
|
260
|
+
if (background !== "only") target.environment = texture;
|
|
261
|
+
if (background) target.background = texture;
|
|
262
|
+
applyProps$1(target, sceneProps);
|
|
263
|
+
return () => {
|
|
264
|
+
if (background !== "only") target.environment = oldenv;
|
|
265
|
+
if (background) target.background = oldbg;
|
|
266
|
+
applyProps$1(target, oldSceneProps);
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
270
|
+
const defaultScene = useThree$1((state) => state.scene);
|
|
271
|
+
React.useLayoutEffect(() => {
|
|
272
|
+
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
273
|
+
});
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
function EnvironmentCube({
|
|
277
|
+
background = false,
|
|
278
|
+
scene,
|
|
279
|
+
blur,
|
|
280
|
+
backgroundBlurriness,
|
|
281
|
+
backgroundIntensity,
|
|
282
|
+
backgroundRotation,
|
|
283
|
+
environmentIntensity,
|
|
284
|
+
environmentRotation,
|
|
285
|
+
...rest
|
|
286
|
+
}) {
|
|
287
|
+
const texture = useEnvironment(rest);
|
|
288
|
+
const defaultScene = useThree$1((state) => state.scene);
|
|
289
|
+
React.useLayoutEffect(() => {
|
|
290
|
+
return setEnvProps(background, scene, defaultScene, texture, {
|
|
291
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
292
|
+
backgroundIntensity,
|
|
293
|
+
backgroundRotation,
|
|
294
|
+
environmentIntensity,
|
|
295
|
+
environmentRotation
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
React.useEffect(() => {
|
|
299
|
+
return () => {
|
|
300
|
+
texture.dispose();
|
|
301
|
+
};
|
|
302
|
+
}, [texture]);
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
function EnvironmentPortal({
|
|
306
|
+
children,
|
|
307
|
+
near = 0.1,
|
|
308
|
+
far = 1e3,
|
|
309
|
+
resolution = 256,
|
|
310
|
+
frames = 1,
|
|
311
|
+
map,
|
|
312
|
+
background = false,
|
|
313
|
+
blur,
|
|
314
|
+
backgroundBlurriness,
|
|
315
|
+
backgroundIntensity,
|
|
316
|
+
backgroundRotation,
|
|
317
|
+
environmentIntensity,
|
|
318
|
+
environmentRotation,
|
|
319
|
+
scene,
|
|
320
|
+
files,
|
|
321
|
+
path,
|
|
322
|
+
preset = void 0,
|
|
323
|
+
extensions
|
|
324
|
+
}) {
|
|
325
|
+
const gl = useThree$1((state) => state.gl);
|
|
326
|
+
const defaultScene = useThree$1((state) => state.scene);
|
|
327
|
+
const camera = React.useRef(null);
|
|
328
|
+
const [virtualScene] = React.useState(() => new Scene());
|
|
329
|
+
const fbo = React.useMemo(() => {
|
|
330
|
+
const fbo2 = new WebGLCubeRenderTarget(resolution);
|
|
331
|
+
fbo2.texture.type = HalfFloatType;
|
|
332
|
+
return fbo2;
|
|
333
|
+
}, [resolution]);
|
|
334
|
+
React.useEffect(() => {
|
|
335
|
+
return () => {
|
|
336
|
+
fbo.dispose();
|
|
337
|
+
};
|
|
338
|
+
}, [fbo]);
|
|
339
|
+
React.useLayoutEffect(() => {
|
|
340
|
+
if (frames === 1) {
|
|
341
|
+
const autoClear = gl.autoClear;
|
|
342
|
+
gl.autoClear = true;
|
|
343
|
+
camera.current.update(gl, virtualScene);
|
|
344
|
+
gl.autoClear = autoClear;
|
|
345
|
+
}
|
|
346
|
+
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
347
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
348
|
+
backgroundIntensity,
|
|
349
|
+
backgroundRotation,
|
|
350
|
+
environmentIntensity,
|
|
351
|
+
environmentRotation
|
|
352
|
+
});
|
|
353
|
+
}, [
|
|
354
|
+
children,
|
|
355
|
+
virtualScene,
|
|
356
|
+
fbo.texture,
|
|
357
|
+
scene,
|
|
358
|
+
defaultScene,
|
|
359
|
+
background,
|
|
360
|
+
frames,
|
|
361
|
+
gl,
|
|
362
|
+
blur,
|
|
363
|
+
backgroundBlurriness,
|
|
364
|
+
backgroundIntensity,
|
|
365
|
+
backgroundRotation,
|
|
366
|
+
environmentIntensity,
|
|
367
|
+
environmentRotation
|
|
368
|
+
]);
|
|
369
|
+
let count = 1;
|
|
370
|
+
useFrame$1(() => {
|
|
371
|
+
if (frames === Infinity || count < frames) {
|
|
372
|
+
const autoClear = gl.autoClear;
|
|
373
|
+
gl.autoClear = true;
|
|
374
|
+
camera.current.update(gl, virtualScene);
|
|
375
|
+
gl.autoClear = autoClear;
|
|
376
|
+
count++;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal$1(
|
|
380
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
381
|
+
children,
|
|
382
|
+
/* @__PURE__ */ jsx("cubeCamera", { ref: camera, args: [near, far, fbo] }),
|
|
383
|
+
files || preset ? /* @__PURE__ */ jsx(EnvironmentCube, { background: true, files, preset, path, extensions }) : map ? /* @__PURE__ */ jsx(EnvironmentMap, { background: true, map, extensions }) : null
|
|
384
|
+
] }),
|
|
385
|
+
virtualScene
|
|
386
|
+
) });
|
|
387
|
+
}
|
|
388
|
+
function EnvironmentGround(props) {
|
|
389
|
+
const textureDefault = useEnvironment(props);
|
|
390
|
+
const texture = props.map || textureDefault;
|
|
391
|
+
React.useMemo(() => extend$1({ GroundProjectedEnvImpl: GroundedSkybox }), []);
|
|
392
|
+
React.useEffect(() => {
|
|
393
|
+
return () => {
|
|
394
|
+
textureDefault.dispose();
|
|
395
|
+
};
|
|
396
|
+
}, [textureDefault]);
|
|
397
|
+
const height = props.ground?.height ?? 15;
|
|
398
|
+
const radius = props.ground?.radius ?? 60;
|
|
399
|
+
const scale = props.ground?.scale ?? 1e3;
|
|
400
|
+
const args = React.useMemo(
|
|
401
|
+
() => [texture, height, radius],
|
|
402
|
+
[texture, height, radius]
|
|
403
|
+
);
|
|
404
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
405
|
+
/* @__PURE__ */ jsx(EnvironmentMap, { ...props, map: texture }),
|
|
406
|
+
/* @__PURE__ */ jsx("groundProjectedEnvImpl", { args, scale })
|
|
407
|
+
] });
|
|
408
|
+
}
|
|
409
|
+
function EnvironmentColor({ color, scene }) {
|
|
410
|
+
const defaultScene = useThree$1((state) => state.scene);
|
|
411
|
+
React.useLayoutEffect(() => {
|
|
412
|
+
if (color === void 0) return;
|
|
413
|
+
const target = resolveScene(scene || defaultScene);
|
|
414
|
+
const oldBg = target.background;
|
|
415
|
+
target.background = new Color(color);
|
|
416
|
+
return () => {
|
|
417
|
+
target.background = oldBg;
|
|
418
|
+
};
|
|
419
|
+
});
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
function EnvironmentDualSource(props) {
|
|
423
|
+
const { backgroundFiles, ...envProps } = props;
|
|
424
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
425
|
+
/* @__PURE__ */ jsx(EnvironmentCube, { ...envProps, background: false }),
|
|
426
|
+
/* @__PURE__ */ jsx(EnvironmentCube, { ...props, files: backgroundFiles, background: "only" })
|
|
427
|
+
] });
|
|
428
|
+
}
|
|
429
|
+
function Environment(props) {
|
|
430
|
+
if (props.color && !props.files && !props.preset && !props.map) {
|
|
431
|
+
return /* @__PURE__ */ jsx(EnvironmentColor, { ...props });
|
|
432
|
+
}
|
|
433
|
+
if (props.backgroundFiles && props.backgroundFiles !== props.files) {
|
|
434
|
+
return /* @__PURE__ */ jsx(EnvironmentDualSource, { ...props });
|
|
435
|
+
}
|
|
436
|
+
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
var __defProp = Object.defineProperty;
|
|
440
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
441
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
51
442
|
const act = React["act"];
|
|
52
443
|
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
53
444
|
function useMutableCallback(fn) {
|
|
@@ -79,7 +470,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
79
470
|
return _a = class extends React.Component {
|
|
80
471
|
constructor() {
|
|
81
472
|
super(...arguments);
|
|
82
|
-
__publicField
|
|
473
|
+
__publicField(this, "state", { error: false });
|
|
83
474
|
}
|
|
84
475
|
componentDidCatch(err) {
|
|
85
476
|
this.props.set(err);
|
|
@@ -87,7 +478,7 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
|
87
478
|
render() {
|
|
88
479
|
return this.state.error ? null : this.props.children;
|
|
89
480
|
}
|
|
90
|
-
}, __publicField
|
|
481
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
91
482
|
})();
|
|
92
483
|
|
|
93
484
|
const is = {
|
|
@@ -224,7 +615,8 @@ function prepare(target, root, type, props) {
|
|
|
224
615
|
object,
|
|
225
616
|
eventCount: 0,
|
|
226
617
|
handlers: {},
|
|
227
|
-
isHidden: false
|
|
618
|
+
isHidden: false,
|
|
619
|
+
deferredRefs: []
|
|
228
620
|
};
|
|
229
621
|
if (object) object.__r3f = instance;
|
|
230
622
|
}
|
|
@@ -273,7 +665,7 @@ function createOcclusionObserverNode(store, uniform) {
|
|
|
273
665
|
let occlusionSetupPromise = null;
|
|
274
666
|
function enableOcclusion(store) {
|
|
275
667
|
const state = store.getState();
|
|
276
|
-
const { internal, renderer
|
|
668
|
+
const { internal, renderer } = state;
|
|
277
669
|
if (internal.occlusionEnabled || occlusionSetupPromise) return;
|
|
278
670
|
const hasOcclusionSupport = typeof renderer?.isOccluded === "function";
|
|
279
671
|
if (!hasOcclusionSupport) {
|
|
@@ -436,6 +828,22 @@ function hasVisibilityHandlers(handlers) {
|
|
|
436
828
|
return !!(handlers.onFramed || handlers.onOccluded || handlers.onVisible);
|
|
437
829
|
}
|
|
438
830
|
|
|
831
|
+
const FROM_REF = Symbol.for("@react-three/fiber.fromRef");
|
|
832
|
+
function fromRef(ref) {
|
|
833
|
+
return { [FROM_REF]: ref };
|
|
834
|
+
}
|
|
835
|
+
function isFromRef(value) {
|
|
836
|
+
return value !== null && typeof value === "object" && FROM_REF in value;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const ONCE = Symbol.for("@react-three/fiber.once");
|
|
840
|
+
function once(...args) {
|
|
841
|
+
return { [ONCE]: args.length ? args : true };
|
|
842
|
+
}
|
|
843
|
+
function isOnce(value) {
|
|
844
|
+
return value !== null && typeof value === "object" && ONCE in value;
|
|
845
|
+
}
|
|
846
|
+
|
|
439
847
|
const RESERVED_PROPS = [
|
|
440
848
|
"children",
|
|
441
849
|
"key",
|
|
@@ -506,7 +914,7 @@ function getMemoizedPrototype(root) {
|
|
|
506
914
|
ctor = new root.constructor();
|
|
507
915
|
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
508
916
|
}
|
|
509
|
-
} catch
|
|
917
|
+
} catch {
|
|
510
918
|
}
|
|
511
919
|
return ctor;
|
|
512
920
|
}
|
|
@@ -537,7 +945,7 @@ function applyProps(object, props) {
|
|
|
537
945
|
const rootState = instance && findInitialRoot(instance).getState();
|
|
538
946
|
const prevHandlers = instance?.eventCount;
|
|
539
947
|
for (const prop in props) {
|
|
540
|
-
|
|
948
|
+
const value = props[prop];
|
|
541
949
|
if (RESERVED_PROPS.includes(prop)) continue;
|
|
542
950
|
if (instance && EVENT_REGEX.test(prop)) {
|
|
543
951
|
if (typeof value === "function") instance.handlers[prop] = value;
|
|
@@ -552,6 +960,25 @@ function applyProps(object, props) {
|
|
|
552
960
|
continue;
|
|
553
961
|
}
|
|
554
962
|
if (value === void 0) continue;
|
|
963
|
+
if (isFromRef(value)) {
|
|
964
|
+
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (isOnce(value)) {
|
|
968
|
+
if (instance?.appliedOnce?.has(prop)) continue;
|
|
969
|
+
if (instance) {
|
|
970
|
+
instance.appliedOnce ?? (instance.appliedOnce = /* @__PURE__ */ new Set());
|
|
971
|
+
instance.appliedOnce.add(prop);
|
|
972
|
+
}
|
|
973
|
+
const { root: targetRoot, key: targetKey } = resolve(object, prop);
|
|
974
|
+
const args = value[ONCE];
|
|
975
|
+
if (typeof targetRoot[targetKey] === "function") {
|
|
976
|
+
targetRoot[targetKey](...args === true ? [] : args);
|
|
977
|
+
} else if (args !== true && args.length > 0) {
|
|
978
|
+
targetRoot[targetKey] = args[0];
|
|
979
|
+
}
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
555
982
|
let { root, key, target } = resolve(object, prop);
|
|
556
983
|
if (target === void 0 && (typeof root !== "object" || root === null)) {
|
|
557
984
|
throw Error(`R3F: Cannot set "${prop}". Ensure it is an object before setting "${key}".`);
|
|
@@ -574,7 +1001,10 @@ function applyProps(object, props) {
|
|
|
574
1001
|
else target.set(value);
|
|
575
1002
|
} else {
|
|
576
1003
|
root[key] = value;
|
|
577
|
-
if (
|
|
1004
|
+
if (key.endsWith("Node") && root.isMaterial) {
|
|
1005
|
+
root.needsUpdate = true;
|
|
1006
|
+
}
|
|
1007
|
+
if (rootState && rootState.renderer?.outputColorSpace === SRGBColorSpace && colorMaps.includes(key) && isTexture(value) && root[key]?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
578
1008
|
root[key].format === RGBAFormat && root[key].type === UnsignedByteType) {
|
|
579
1009
|
root[key].colorSpace = rootState.textureColorSpace;
|
|
580
1010
|
}
|
|
@@ -607,38 +1037,60 @@ function applyProps(object, props) {
|
|
|
607
1037
|
return object;
|
|
608
1038
|
}
|
|
609
1039
|
|
|
1040
|
+
const DEFAULT_POINTER_ID = 0;
|
|
1041
|
+
const XR_POINTER_ID_START = 1e3;
|
|
1042
|
+
function getPointerState(internal, pointerId) {
|
|
1043
|
+
let state = internal.pointerMap.get(pointerId);
|
|
1044
|
+
if (!state) {
|
|
1045
|
+
state = {
|
|
1046
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1047
|
+
captured: /* @__PURE__ */ new Map(),
|
|
1048
|
+
initialClick: [0, 0],
|
|
1049
|
+
initialHits: []
|
|
1050
|
+
};
|
|
1051
|
+
internal.pointerMap.set(pointerId, state);
|
|
1052
|
+
}
|
|
1053
|
+
return state;
|
|
1054
|
+
}
|
|
1055
|
+
function getPointerId(event) {
|
|
1056
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
1057
|
+
}
|
|
610
1058
|
function makeId(event) {
|
|
611
1059
|
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
612
1060
|
}
|
|
613
|
-
function releaseInternalPointerCapture(
|
|
614
|
-
const
|
|
1061
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1062
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1063
|
+
if (!pointerState) return;
|
|
1064
|
+
const captureData = pointerState.captured.get(obj);
|
|
615
1065
|
if (captureData) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
capturedMap.delete(pointerId);
|
|
619
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
620
|
-
}
|
|
1066
|
+
pointerState.captured.delete(obj);
|
|
1067
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
621
1068
|
}
|
|
622
1069
|
}
|
|
623
1070
|
function removeInteractivity(store, object) {
|
|
624
1071
|
const { internal } = store.getState();
|
|
625
1072
|
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
1073
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
1074
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
1075
|
+
pointerState.hovered.forEach((value, key) => {
|
|
1076
|
+
if (value.eventObject === object || value.object === object) {
|
|
1077
|
+
pointerState.hovered.delete(key);
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
if (pointerState.captured.has(object)) {
|
|
1081
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
630
1082
|
}
|
|
631
|
-
}
|
|
632
|
-
internal.capturedMap.forEach((captures, pointerId) => {
|
|
633
|
-
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
634
|
-
});
|
|
1083
|
+
}
|
|
635
1084
|
unregisterVisibility(store, object);
|
|
636
1085
|
}
|
|
637
1086
|
function createEvents(store) {
|
|
638
|
-
function calculateDistance(event) {
|
|
1087
|
+
function calculateDistance(event, pointerId) {
|
|
639
1088
|
const { internal } = store.getState();
|
|
640
|
-
const
|
|
641
|
-
|
|
1089
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1090
|
+
if (!pointerState) return 0;
|
|
1091
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
1092
|
+
const dx = event.offsetX - initialX;
|
|
1093
|
+
const dy = event.offsetY - initialY;
|
|
642
1094
|
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
643
1095
|
}
|
|
644
1096
|
function filterPointerEvents(objects) {
|
|
@@ -674,6 +1126,15 @@ function createEvents(store) {
|
|
|
674
1126
|
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
675
1127
|
}
|
|
676
1128
|
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1129
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1130
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1131
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1132
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1133
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1134
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
1135
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
677
1138
|
const aState = getRootState(a.object);
|
|
678
1139
|
const bState = getRootState(b.object);
|
|
679
1140
|
const aPriority = aState?.events?.priority ?? 1;
|
|
@@ -689,14 +1150,19 @@ function createEvents(store) {
|
|
|
689
1150
|
for (const hit of hits) {
|
|
690
1151
|
let eventObject = hit.object;
|
|
691
1152
|
while (eventObject) {
|
|
692
|
-
if (eventObject.__r3f?.eventCount)
|
|
1153
|
+
if (eventObject.__r3f?.eventCount) {
|
|
693
1154
|
intersections.push({ ...hit, eventObject });
|
|
1155
|
+
}
|
|
694
1156
|
eventObject = eventObject.parent;
|
|
695
1157
|
}
|
|
696
1158
|
}
|
|
697
|
-
if ("pointerId" in event
|
|
698
|
-
|
|
699
|
-
|
|
1159
|
+
if ("pointerId" in event) {
|
|
1160
|
+
const pointerId = event.pointerId;
|
|
1161
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
1162
|
+
if (pointerState?.captured.size) {
|
|
1163
|
+
for (const captureData of pointerState.captured.values()) {
|
|
1164
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
1165
|
+
}
|
|
700
1166
|
}
|
|
701
1167
|
}
|
|
702
1168
|
return intersections;
|
|
@@ -709,28 +1175,26 @@ function createEvents(store) {
|
|
|
709
1175
|
if (state) {
|
|
710
1176
|
const { raycaster, pointer, camera, internal } = state;
|
|
711
1177
|
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
712
|
-
const hasPointerCapture = (id) =>
|
|
1178
|
+
const hasPointerCapture = (id) => {
|
|
1179
|
+
const pointerState = internal.pointerMap.get(id);
|
|
1180
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
1181
|
+
};
|
|
713
1182
|
const setPointerCapture = (id) => {
|
|
714
1183
|
const captureData = { intersection: hit, target: event.target };
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
} else {
|
|
718
|
-
internal.capturedMap.set(id, /* @__PURE__ */ new Map([[hit.eventObject, captureData]]));
|
|
719
|
-
}
|
|
1184
|
+
const pointerState = getPointerState(internal, id);
|
|
1185
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
720
1186
|
event.target.setPointerCapture(id);
|
|
721
1187
|
};
|
|
722
1188
|
const releasePointerCapture = (id) => {
|
|
723
|
-
|
|
724
|
-
if (captures) {
|
|
725
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
726
|
-
}
|
|
1189
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
727
1190
|
};
|
|
728
|
-
|
|
729
|
-
for (
|
|
730
|
-
|
|
1191
|
+
const extractEventProps = {};
|
|
1192
|
+
for (const prop in event) {
|
|
1193
|
+
const property = event[prop];
|
|
731
1194
|
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
732
1195
|
}
|
|
733
|
-
|
|
1196
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1197
|
+
const raycastEvent = {
|
|
734
1198
|
...hit,
|
|
735
1199
|
...extractEventProps,
|
|
736
1200
|
pointer,
|
|
@@ -740,18 +1204,19 @@ function createEvents(store) {
|
|
|
740
1204
|
unprojectedPoint,
|
|
741
1205
|
ray: raycaster.ray,
|
|
742
1206
|
camera,
|
|
1207
|
+
pointerId: eventPointerId,
|
|
743
1208
|
// Hijack stopPropagation, which just sets a flag
|
|
744
1209
|
stopPropagation() {
|
|
745
|
-
const
|
|
1210
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
746
1211
|
if (
|
|
747
1212
|
// ...if this pointer hasn't been captured
|
|
748
|
-
!
|
|
749
|
-
|
|
1213
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1214
|
+
pointerState.captured.has(hit.eventObject)
|
|
750
1215
|
) {
|
|
751
1216
|
raycastEvent.stopped = localState.stopped = true;
|
|
752
|
-
if (
|
|
1217
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
753
1218
|
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
754
|
-
cancelPointer([...higher, hit]);
|
|
1219
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
755
1220
|
}
|
|
756
1221
|
}
|
|
757
1222
|
},
|
|
@@ -767,15 +1232,18 @@ function createEvents(store) {
|
|
|
767
1232
|
}
|
|
768
1233
|
return intersections;
|
|
769
1234
|
}
|
|
770
|
-
function cancelPointer(intersections) {
|
|
1235
|
+
function cancelPointer(intersections, pointerId) {
|
|
771
1236
|
const { internal } = store.getState();
|
|
772
|
-
|
|
1237
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
1238
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
1239
|
+
if (!pointerState) return;
|
|
1240
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
773
1241
|
if (!intersections.length || !intersections.find(
|
|
774
1242
|
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
775
1243
|
)) {
|
|
776
1244
|
const eventObject = hoveredObj.eventObject;
|
|
777
1245
|
const instance = eventObject.__r3f;
|
|
778
|
-
|
|
1246
|
+
pointerState.hovered.delete(hoveredId);
|
|
779
1247
|
if (instance?.eventCount) {
|
|
780
1248
|
const handlers = instance.handlers;
|
|
781
1249
|
const data = { ...hoveredObj, intersections };
|
|
@@ -804,41 +1272,118 @@ function createEvents(store) {
|
|
|
804
1272
|
instance?.handlers.onDropMissed?.(event);
|
|
805
1273
|
}
|
|
806
1274
|
}
|
|
1275
|
+
function cleanupPointer(pointerId) {
|
|
1276
|
+
const { internal } = store.getState();
|
|
1277
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1278
|
+
if (pointerState) {
|
|
1279
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1280
|
+
const eventObject = hoveredObj.eventObject;
|
|
1281
|
+
const instance = eventObject.__r3f;
|
|
1282
|
+
if (instance?.eventCount) {
|
|
1283
|
+
const handlers = instance.handlers;
|
|
1284
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1285
|
+
handlers.onPointerOut?.(data);
|
|
1286
|
+
handlers.onPointerLeave?.(data);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
internal.pointerMap.delete(pointerId);
|
|
1290
|
+
}
|
|
1291
|
+
internal.pointerDirty.delete(pointerId);
|
|
1292
|
+
}
|
|
1293
|
+
function processDeferredPointer(event, pointerId) {
|
|
1294
|
+
const state = store.getState();
|
|
1295
|
+
const { internal } = state;
|
|
1296
|
+
if (!state.events.enabled) return;
|
|
1297
|
+
const filter = filterPointerEvents;
|
|
1298
|
+
const hits = intersect(event, filter);
|
|
1299
|
+
cancelPointer(hits, pointerId);
|
|
1300
|
+
function onIntersect(data) {
|
|
1301
|
+
const eventObject = data.eventObject;
|
|
1302
|
+
const instance = eventObject.__r3f;
|
|
1303
|
+
if (!instance?.eventCount) return;
|
|
1304
|
+
const handlers = instance.handlers;
|
|
1305
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1306
|
+
const id = makeId(data);
|
|
1307
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
1308
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
1309
|
+
if (!hoveredItem) {
|
|
1310
|
+
pointerState.hovered.set(id, data);
|
|
1311
|
+
handlers.onPointerOver?.(data);
|
|
1312
|
+
handlers.onPointerEnter?.(data);
|
|
1313
|
+
} else if (hoveredItem.stopped) {
|
|
1314
|
+
data.stopPropagation();
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
handlers.onPointerMove?.(data);
|
|
1318
|
+
}
|
|
1319
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
1320
|
+
}
|
|
807
1321
|
function handlePointer(name) {
|
|
808
1322
|
switch (name) {
|
|
809
1323
|
case "onPointerLeave":
|
|
810
|
-
case "onPointerCancel":
|
|
811
1324
|
case "onDragLeave":
|
|
812
1325
|
return () => cancelPointer([]);
|
|
1326
|
+
// Global cancel of these events
|
|
1327
|
+
case "onPointerCancel":
|
|
1328
|
+
return (event) => {
|
|
1329
|
+
const pointerId = getPointerId(event);
|
|
1330
|
+
cleanupPointer(pointerId);
|
|
1331
|
+
};
|
|
813
1332
|
case "onLostPointerCapture":
|
|
814
1333
|
return (event) => {
|
|
815
1334
|
const { internal } = store.getState();
|
|
816
|
-
|
|
1335
|
+
const pointerId = getPointerId(event);
|
|
1336
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1337
|
+
if (pointerState?.captured.size) {
|
|
817
1338
|
requestAnimationFrame(() => {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1339
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1340
|
+
if (pointerState2?.captured.size) {
|
|
1341
|
+
pointerState2.captured.clear();
|
|
821
1342
|
}
|
|
1343
|
+
cancelPointer([], pointerId);
|
|
822
1344
|
});
|
|
823
1345
|
}
|
|
824
1346
|
};
|
|
825
1347
|
}
|
|
826
1348
|
return function handleEvent(event) {
|
|
827
1349
|
const state = store.getState();
|
|
828
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal } = state;
|
|
1350
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1351
|
+
const pointerId = getPointerId(event);
|
|
829
1352
|
internal.lastEvent.current = event;
|
|
830
|
-
if (!
|
|
1353
|
+
if (!events.enabled) return;
|
|
831
1354
|
const isPointerMove = name === "onPointerMove";
|
|
832
1355
|
const isDragOver = name === "onDragOver";
|
|
833
1356
|
const isDrop = name === "onDrop";
|
|
834
1357
|
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1358
|
+
const isPointerDown = name === "onPointerDown";
|
|
1359
|
+
const isPointerUp = name === "onPointerUp";
|
|
1360
|
+
const isWheel = name === "onWheel";
|
|
1361
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1362
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
1363
|
+
events.compute?.(event, state);
|
|
1364
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1368
|
+
events.compute?.(event, state);
|
|
1369
|
+
internal.pointerDirty.set(pointerId, event);
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1373
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1374
|
+
internal.pointerDirty.delete(pointerId);
|
|
1375
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
1376
|
+
}
|
|
835
1377
|
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
836
1378
|
const hits = intersect(event, filter);
|
|
837
|
-
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
838
|
-
if (
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1379
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1380
|
+
if (isPointerDown) {
|
|
1381
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1382
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1383
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1384
|
+
}
|
|
1385
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1386
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
842
1387
|
if (isClickEvent && !hits.length) {
|
|
843
1388
|
if (delta <= 2) {
|
|
844
1389
|
pointerMissed(event, internal.interaction);
|
|
@@ -853,7 +1398,9 @@ function createEvents(store) {
|
|
|
853
1398
|
dropMissed(event, internal.interaction);
|
|
854
1399
|
if (onDropMissed) onDropMissed(event);
|
|
855
1400
|
}
|
|
856
|
-
if (isPointerMove || isDragOver)
|
|
1401
|
+
if (isPointerMove || isDragOver) {
|
|
1402
|
+
cancelPointer(hits, pointerId);
|
|
1403
|
+
}
|
|
857
1404
|
function onIntersect(data) {
|
|
858
1405
|
const eventObject = data.eventObject;
|
|
859
1406
|
const instance = eventObject.__r3f;
|
|
@@ -862,9 +1409,10 @@ function createEvents(store) {
|
|
|
862
1409
|
if (isPointerMove) {
|
|
863
1410
|
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
864
1411
|
const id = makeId(data);
|
|
865
|
-
const
|
|
1412
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1413
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
866
1414
|
if (!hoveredItem) {
|
|
867
|
-
|
|
1415
|
+
pointerState2.hovered.set(id, data);
|
|
868
1416
|
handlers.onPointerOver?.(data);
|
|
869
1417
|
handlers.onPointerEnter?.(data);
|
|
870
1418
|
} else if (hoveredItem.stopped) {
|
|
@@ -874,9 +1422,10 @@ function createEvents(store) {
|
|
|
874
1422
|
handlers.onPointerMove?.(data);
|
|
875
1423
|
} else if (isDragOver) {
|
|
876
1424
|
const id = makeId(data);
|
|
877
|
-
const
|
|
1425
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
1426
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
878
1427
|
if (!hoveredItem) {
|
|
879
|
-
|
|
1428
|
+
pointerState2.hovered.set(id, data);
|
|
880
1429
|
handlers.onDragOverEnter?.(data);
|
|
881
1430
|
} else if (hoveredItem.stopped) {
|
|
882
1431
|
data.stopPropagation();
|
|
@@ -887,18 +1436,18 @@ function createEvents(store) {
|
|
|
887
1436
|
} else {
|
|
888
1437
|
const handler = handlers[name];
|
|
889
1438
|
if (handler) {
|
|
890
|
-
if (!isClickEvent ||
|
|
1439
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
891
1440
|
pointerMissed(
|
|
892
1441
|
event,
|
|
893
|
-
internal.interaction.filter((object) => !
|
|
1442
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
894
1443
|
);
|
|
895
1444
|
handler(data);
|
|
896
1445
|
}
|
|
897
1446
|
} else {
|
|
898
|
-
if (isClickEvent &&
|
|
1447
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
899
1448
|
pointerMissed(
|
|
900
1449
|
event,
|
|
901
|
-
internal.interaction.filter((object) => !
|
|
1450
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
902
1451
|
);
|
|
903
1452
|
}
|
|
904
1453
|
}
|
|
@@ -907,7 +1456,15 @@ function createEvents(store) {
|
|
|
907
1456
|
handleIntersects(hits, event, delta, onIntersect);
|
|
908
1457
|
};
|
|
909
1458
|
}
|
|
910
|
-
|
|
1459
|
+
function flushDeferredPointers() {
|
|
1460
|
+
const { internal, events } = store.getState();
|
|
1461
|
+
if (!events.frameTimedRaycasts) return;
|
|
1462
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
1463
|
+
processDeferredPointer(event, pointerId);
|
|
1464
|
+
}
|
|
1465
|
+
internal.pointerDirty.clear();
|
|
1466
|
+
}
|
|
1467
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
911
1468
|
}
|
|
912
1469
|
const DOM_EVENTS = {
|
|
913
1470
|
onClick: ["click", false],
|
|
@@ -926,11 +1483,16 @@ const DOM_EVENTS = {
|
|
|
926
1483
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
927
1484
|
};
|
|
928
1485
|
function createPointerEvents(store) {
|
|
929
|
-
const { handlePointer } = createEvents(store);
|
|
1486
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1487
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1488
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
930
1489
|
return {
|
|
931
1490
|
priority: 1,
|
|
932
1491
|
enabled: true,
|
|
933
|
-
|
|
1492
|
+
frameTimedRaycasts: true,
|
|
1493
|
+
alwaysFireOnScroll: true,
|
|
1494
|
+
updateOnFrame: false,
|
|
1495
|
+
compute(event, state) {
|
|
934
1496
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
935
1497
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
936
1498
|
},
|
|
@@ -939,11 +1501,33 @@ function createPointerEvents(store) {
|
|
|
939
1501
|
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
940
1502
|
{}
|
|
941
1503
|
),
|
|
942
|
-
update: () => {
|
|
1504
|
+
update: (pointerId) => {
|
|
943
1505
|
const { events, internal } = store.getState();
|
|
944
|
-
if (
|
|
1506
|
+
if (!events.handlers) return;
|
|
1507
|
+
if (pointerId !== void 0) {
|
|
1508
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
1509
|
+
if (event) {
|
|
1510
|
+
internal.pointerDirty.delete(pointerId);
|
|
1511
|
+
processDeferredPointer(event, pointerId);
|
|
1512
|
+
} else if (internal.lastEvent?.current) {
|
|
1513
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1514
|
+
}
|
|
1515
|
+
} else {
|
|
1516
|
+
flushDeferredPointers();
|
|
1517
|
+
if (internal.lastEvent?.current) {
|
|
1518
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
},
|
|
1522
|
+
flush: () => {
|
|
1523
|
+
const { events, internal } = store.getState();
|
|
1524
|
+
flushDeferredPointers();
|
|
1525
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1526
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1527
|
+
}
|
|
945
1528
|
},
|
|
946
1529
|
connect: (target) => {
|
|
1530
|
+
if (!target) return;
|
|
947
1531
|
const { set, events } = store.getState();
|
|
948
1532
|
events.disconnect?.();
|
|
949
1533
|
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
@@ -967,6 +1551,32 @@ function createPointerEvents(store) {
|
|
|
967
1551
|
}
|
|
968
1552
|
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
969
1553
|
}
|
|
1554
|
+
},
|
|
1555
|
+
registerPointer: (config) => {
|
|
1556
|
+
const pointerId = nextXRPointerId++;
|
|
1557
|
+
xrPointers.set(pointerId, config);
|
|
1558
|
+
const { internal } = store.getState();
|
|
1559
|
+
getPointerState(internal, pointerId);
|
|
1560
|
+
return pointerId;
|
|
1561
|
+
},
|
|
1562
|
+
unregisterPointer: (pointerId) => {
|
|
1563
|
+
xrPointers.delete(pointerId);
|
|
1564
|
+
const { internal } = store.getState();
|
|
1565
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
1566
|
+
if (pointerState) {
|
|
1567
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1568
|
+
const eventObject = hoveredObj.eventObject;
|
|
1569
|
+
const instance = eventObject.__r3f;
|
|
1570
|
+
if (instance?.eventCount) {
|
|
1571
|
+
const handlers = instance.handlers;
|
|
1572
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
1573
|
+
handlers.onPointerOut?.(data);
|
|
1574
|
+
handlers.onPointerLeave?.(data);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
internal.pointerMap.delete(pointerId);
|
|
1578
|
+
}
|
|
1579
|
+
internal.pointerDirty.delete(pointerId);
|
|
970
1580
|
}
|
|
971
1581
|
};
|
|
972
1582
|
}
|
|
@@ -1057,23 +1667,29 @@ const createStore = (invalidate, advance) => {
|
|
|
1057
1667
|
set,
|
|
1058
1668
|
get,
|
|
1059
1669
|
// Mock objects that have to be configured
|
|
1670
|
+
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
1671
|
+
primaryStore: null,
|
|
1060
1672
|
gl: null,
|
|
1061
1673
|
renderer: null,
|
|
1062
1674
|
camera: null,
|
|
1063
1675
|
frustum: new Frustum(),
|
|
1064
1676
|
autoUpdateFrustum: true,
|
|
1065
1677
|
raycaster: null,
|
|
1066
|
-
events: {
|
|
1678
|
+
events: {
|
|
1679
|
+
priority: 1,
|
|
1680
|
+
enabled: true,
|
|
1681
|
+
connected: false,
|
|
1682
|
+
frameTimedRaycasts: true,
|
|
1683
|
+
alwaysFireOnScroll: true,
|
|
1684
|
+
updateOnFrame: false
|
|
1685
|
+
},
|
|
1067
1686
|
scene: null,
|
|
1068
1687
|
rootScene: null,
|
|
1069
1688
|
xr: null,
|
|
1070
1689
|
inspector: null,
|
|
1071
1690
|
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
1072
1691
|
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
1073
|
-
|
|
1074
|
-
linear: false,
|
|
1075
|
-
flat: false,
|
|
1076
|
-
textureColorSpace: "srgb",
|
|
1692
|
+
textureColorSpace: SRGBColorSpace,
|
|
1077
1693
|
isLegacy: false,
|
|
1078
1694
|
webGPUSupported: false,
|
|
1079
1695
|
isNative: false,
|
|
@@ -1113,10 +1729,40 @@ const createStore = (invalidate, advance) => {
|
|
|
1113
1729
|
getCurrentViewport
|
|
1114
1730
|
},
|
|
1115
1731
|
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
1116
|
-
setSize: (width, height, top
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1732
|
+
setSize: (width, height, top, left) => {
|
|
1733
|
+
const state2 = get();
|
|
1734
|
+
if (width === void 0) {
|
|
1735
|
+
set({ _sizeImperative: false });
|
|
1736
|
+
if (state2._sizeProps) {
|
|
1737
|
+
const { width: propW, height: propH } = state2._sizeProps;
|
|
1738
|
+
if (propW !== void 0 || propH !== void 0) {
|
|
1739
|
+
const currentSize = state2.size;
|
|
1740
|
+
const newSize = {
|
|
1741
|
+
width: propW ?? currentSize.width,
|
|
1742
|
+
height: propH ?? currentSize.height,
|
|
1743
|
+
top: currentSize.top,
|
|
1744
|
+
left: currentSize.left
|
|
1745
|
+
};
|
|
1746
|
+
set((s) => ({
|
|
1747
|
+
size: newSize,
|
|
1748
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1749
|
+
}));
|
|
1750
|
+
getScheduler().invalidate();
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
const w = width;
|
|
1756
|
+
const h = height ?? width;
|
|
1757
|
+
const t = top ?? state2.size.top;
|
|
1758
|
+
const l = left ?? state2.size.left;
|
|
1759
|
+
const size = { width: w, height: h, top: t, left: l };
|
|
1760
|
+
set((s) => ({
|
|
1761
|
+
size,
|
|
1762
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1763
|
+
_sizeImperative: true
|
|
1764
|
+
}));
|
|
1765
|
+
getScheduler().invalidate();
|
|
1120
1766
|
},
|
|
1121
1767
|
setDpr: (dpr) => set((state2) => {
|
|
1122
1768
|
const resolved = calculateDpr(dpr);
|
|
@@ -1127,22 +1773,32 @@ const createStore = (invalidate, advance) => {
|
|
|
1127
1773
|
},
|
|
1128
1774
|
setError: (error) => set(() => ({ error })),
|
|
1129
1775
|
error: null,
|
|
1130
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useTextures,
|
|
1776
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1131
1777
|
uniforms: {},
|
|
1132
1778
|
nodes: {},
|
|
1779
|
+
buffers: {},
|
|
1780
|
+
gpuStorage: {},
|
|
1133
1781
|
textures: /* @__PURE__ */ new Map(),
|
|
1134
|
-
|
|
1782
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1783
|
+
renderPipeline: null,
|
|
1135
1784
|
passes: {},
|
|
1785
|
+
_hmrVersion: 0,
|
|
1786
|
+
_sizeImperative: false,
|
|
1787
|
+
_sizeProps: null,
|
|
1136
1788
|
previousRoot: void 0,
|
|
1137
1789
|
internal: {
|
|
1138
1790
|
// Events
|
|
1139
1791
|
interaction: [],
|
|
1140
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1141
1792
|
subscribers: [],
|
|
1793
|
+
// Per-pointer state (new unified structure)
|
|
1794
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
1795
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1796
|
+
lastEvent: React.createRef(),
|
|
1797
|
+
// Deprecated but kept for backwards compatibility
|
|
1798
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
1142
1799
|
initialClick: [0, 0],
|
|
1143
1800
|
initialHits: [],
|
|
1144
1801
|
capturedMap: /* @__PURE__ */ new Map(),
|
|
1145
|
-
lastEvent: React.createRef(),
|
|
1146
1802
|
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1147
1803
|
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1148
1804
|
// Occlusion system (WebGPU only)
|
|
@@ -1225,13 +1881,22 @@ const createStore = (invalidate, advance) => {
|
|
|
1225
1881
|
rootStore.subscribe(() => {
|
|
1226
1882
|
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1227
1883
|
const actualRenderer = internal.actualRenderer;
|
|
1884
|
+
const canvasTarget = internal.canvasTarget;
|
|
1228
1885
|
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1229
1886
|
oldSize = size;
|
|
1230
1887
|
oldDpr = viewport.dpr;
|
|
1231
1888
|
updateCamera(camera, size);
|
|
1232
|
-
if (
|
|
1233
|
-
|
|
1234
|
-
|
|
1889
|
+
if (internal.isSecondary && canvasTarget) {
|
|
1890
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1891
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1892
|
+
} else {
|
|
1893
|
+
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1894
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1895
|
+
if (canvasTarget) {
|
|
1896
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1897
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1235
1900
|
}
|
|
1236
1901
|
if (camera !== oldCamera) {
|
|
1237
1902
|
oldCamera = camera;
|
|
@@ -1302,1037 +1967,6 @@ useLoader.clear = function(loader, input) {
|
|
|
1302
1967
|
};
|
|
1303
1968
|
useLoader.loader = getLoader;
|
|
1304
1969
|
|
|
1305
|
-
var __defProp$1 = Object.defineProperty;
|
|
1306
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1307
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1308
|
-
const DEFAULT_PHASES = ["start", "input", "physics", "update", "render", "finish"];
|
|
1309
|
-
class PhaseGraph {
|
|
1310
|
-
constructor() {
|
|
1311
|
-
/** Ordered list of phase nodes */
|
|
1312
|
-
__publicField$1(this, "phases", []);
|
|
1313
|
-
/** Quick lookup by name */
|
|
1314
|
-
__publicField$1(this, "phaseMap", /* @__PURE__ */ new Map());
|
|
1315
|
-
/** Cached ordered names (invalidated on changes) */
|
|
1316
|
-
__publicField$1(this, "orderedNamesCache", null);
|
|
1317
|
-
this.initializeDefaultPhases();
|
|
1318
|
-
}
|
|
1319
|
-
//* Initialization --------------------------------
|
|
1320
|
-
initializeDefaultPhases() {
|
|
1321
|
-
for (const name of DEFAULT_PHASES) {
|
|
1322
|
-
const node = { name, isAutoGenerated: false };
|
|
1323
|
-
this.phases.push(node);
|
|
1324
|
-
this.phaseMap.set(name, node);
|
|
1325
|
-
}
|
|
1326
|
-
this.invalidateCache();
|
|
1327
|
-
}
|
|
1328
|
-
//* Public API --------------------------------
|
|
1329
|
-
/**
|
|
1330
|
-
* Add a named phase to the graph
|
|
1331
|
-
* @param name - Phase name (must be unique)
|
|
1332
|
-
* @param options - Position options (before or after another phase)
|
|
1333
|
-
*/
|
|
1334
|
-
addPhase(name, options = {}) {
|
|
1335
|
-
if (this.phaseMap.has(name)) {
|
|
1336
|
-
console.warn(`[useFrame] Phase "${name}" already exists`);
|
|
1337
|
-
return;
|
|
1338
|
-
}
|
|
1339
|
-
const { before, after } = options;
|
|
1340
|
-
const node = { name, isAutoGenerated: false };
|
|
1341
|
-
let insertIndex = this.phases.length;
|
|
1342
|
-
const targetIndex = this.getPhaseIndex(before ?? after);
|
|
1343
|
-
if (targetIndex !== -1) insertIndex = before ? targetIndex : targetIndex + 1;
|
|
1344
|
-
else {
|
|
1345
|
-
const constraintType = before ? "before" : "after";
|
|
1346
|
-
console.warn(`[useFrame] Phase "${before ?? after}" not found for '${constraintType}' constraint`);
|
|
1347
|
-
}
|
|
1348
|
-
this.phases.splice(insertIndex, 0, node);
|
|
1349
|
-
this.phaseMap.set(name, node);
|
|
1350
|
-
this.invalidateCache();
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Get ordered list of phase names
|
|
1354
|
-
*/
|
|
1355
|
-
getOrderedPhases() {
|
|
1356
|
-
if (this.orderedNamesCache === null) this.orderedNamesCache = this.phases.map((p) => p.name);
|
|
1357
|
-
return this.orderedNamesCache;
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* Check if a phase exists
|
|
1361
|
-
*/
|
|
1362
|
-
hasPhase(name) {
|
|
1363
|
-
return this.phaseMap.has(name);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Get the index of a phase (-1 if not found)
|
|
1367
|
-
*/
|
|
1368
|
-
getPhaseIndex(name) {
|
|
1369
|
-
if (!name) return -1;
|
|
1370
|
-
return this.phases.findIndex((p) => p.name === name);
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* Ensure a phase exists, creating an auto-generated one if needed.
|
|
1374
|
-
* Used for resolving before/after constraints.
|
|
1375
|
-
*
|
|
1376
|
-
* @param name - The phase name to ensure exists
|
|
1377
|
-
* @returns The phase name (may be auto-generated like 'before:render')
|
|
1378
|
-
*/
|
|
1379
|
-
ensurePhase(name) {
|
|
1380
|
-
if (this.phaseMap.has(name)) return name;
|
|
1381
|
-
const node = { name, isAutoGenerated: true };
|
|
1382
|
-
this.phases.push(node);
|
|
1383
|
-
this.phaseMap.set(name, node);
|
|
1384
|
-
this.invalidateCache();
|
|
1385
|
-
return name;
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Resolve where a job with before/after constraints should go.
|
|
1389
|
-
* Creates auto-generated phases if needed.
|
|
1390
|
-
*
|
|
1391
|
-
* @param before - Phase(s) to run before
|
|
1392
|
-
* @param after - Phase(s) to run after
|
|
1393
|
-
* @returns The resolved phase name
|
|
1394
|
-
*/
|
|
1395
|
-
resolveConstraintPhase(before, after) {
|
|
1396
|
-
const beforeArr = before ? Array.isArray(before) ? before : [before] : [];
|
|
1397
|
-
const afterArr = after ? Array.isArray(after) ? after : [after] : [];
|
|
1398
|
-
if (beforeArr.length > 0) {
|
|
1399
|
-
return this.ensureAutoPhase(beforeArr[0], "before", 0);
|
|
1400
|
-
}
|
|
1401
|
-
if (afterArr.length > 0) {
|
|
1402
|
-
return this.ensureAutoPhase(afterArr[0], "after", 1);
|
|
1403
|
-
}
|
|
1404
|
-
return "update";
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Ensure an auto-generated phase exists relative to a target phase.
|
|
1408
|
-
* Creates the phase if it doesn't exist, inserting it at the correct position.
|
|
1409
|
-
*
|
|
1410
|
-
* @param target - The target phase name to position relative to
|
|
1411
|
-
* @param prefix - Prefix for auto-generated phase name ('before' or 'after')
|
|
1412
|
-
* @param offset - Insertion offset (0 for before, 1 for after)
|
|
1413
|
-
* @returns The auto-generated phase name
|
|
1414
|
-
*/
|
|
1415
|
-
ensureAutoPhase(target, prefix, offset) {
|
|
1416
|
-
const autoName = `${prefix}:${target}`;
|
|
1417
|
-
if (this.phaseMap.has(autoName)) return autoName;
|
|
1418
|
-
const node = { name: autoName, isAutoGenerated: true };
|
|
1419
|
-
const targetIndex = this.getPhaseIndex(target);
|
|
1420
|
-
if (targetIndex !== -1) this.phases.splice(targetIndex + offset, 0, node);
|
|
1421
|
-
else this.phases.push(node);
|
|
1422
|
-
this.phaseMap.set(autoName, node);
|
|
1423
|
-
this.invalidateCache();
|
|
1424
|
-
return autoName;
|
|
1425
|
-
}
|
|
1426
|
-
// Internal --------------------------------
|
|
1427
|
-
invalidateCache() {
|
|
1428
|
-
this.orderedNamesCache = null;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
function rebuildSortedJobs(jobs, phaseGraph) {
|
|
1433
|
-
const orderedPhases = phaseGraph.getOrderedPhases();
|
|
1434
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1435
|
-
for (const phase of orderedPhases) {
|
|
1436
|
-
buckets.set(phase, []);
|
|
1437
|
-
}
|
|
1438
|
-
for (const job of jobs.values()) {
|
|
1439
|
-
if (!job.enabled) continue;
|
|
1440
|
-
let bucket = buckets.get(job.phase);
|
|
1441
|
-
if (!bucket) {
|
|
1442
|
-
bucket = [];
|
|
1443
|
-
buckets.set(job.phase, bucket);
|
|
1444
|
-
}
|
|
1445
|
-
bucket.push(job);
|
|
1446
|
-
}
|
|
1447
|
-
const sortedBuckets = [];
|
|
1448
|
-
for (const phase of orderedPhases) {
|
|
1449
|
-
const bucket = buckets.get(phase);
|
|
1450
|
-
if (!bucket || bucket.length === 0) continue;
|
|
1451
|
-
bucket.sort((a, b) => {
|
|
1452
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1453
|
-
return a.index - b.index;
|
|
1454
|
-
});
|
|
1455
|
-
sortedBuckets.push(hasCrossJobConstraints(bucket) ? topologicalSort(bucket) : bucket);
|
|
1456
|
-
}
|
|
1457
|
-
for (const [phase, bucket] of buckets) {
|
|
1458
|
-
if (!orderedPhases.includes(phase) && bucket.length > 0) {
|
|
1459
|
-
bucket.sort((a, b) => {
|
|
1460
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1461
|
-
return a.index - b.index;
|
|
1462
|
-
});
|
|
1463
|
-
sortedBuckets.push(bucket);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
return sortedBuckets.flat();
|
|
1467
|
-
}
|
|
1468
|
-
function hasCrossJobConstraints(bucket) {
|
|
1469
|
-
const jobIds = new Set(bucket.map((j) => j.id));
|
|
1470
|
-
for (const job of bucket) {
|
|
1471
|
-
for (const ref of job.before) {
|
|
1472
|
-
if (jobIds.has(ref)) return true;
|
|
1473
|
-
}
|
|
1474
|
-
for (const ref of job.after) {
|
|
1475
|
-
if (jobIds.has(ref)) return true;
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
return false;
|
|
1479
|
-
}
|
|
1480
|
-
function topologicalSort(jobs) {
|
|
1481
|
-
const n = jobs.length;
|
|
1482
|
-
if (n <= 1) return jobs;
|
|
1483
|
-
const jobMap = /* @__PURE__ */ new Map();
|
|
1484
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
1485
|
-
const adjacency = /* @__PURE__ */ new Map();
|
|
1486
|
-
for (const job of jobs) {
|
|
1487
|
-
jobMap.set(job.id, job);
|
|
1488
|
-
inDegree.set(job.id, 0);
|
|
1489
|
-
adjacency.set(job.id, []);
|
|
1490
|
-
}
|
|
1491
|
-
for (const job of jobs) {
|
|
1492
|
-
for (const ref of job.before) {
|
|
1493
|
-
if (jobMap.has(ref)) {
|
|
1494
|
-
adjacency.get(job.id).push(ref);
|
|
1495
|
-
inDegree.set(ref, inDegree.get(ref) + 1);
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
for (const ref of job.after) {
|
|
1499
|
-
if (jobMap.has(ref)) {
|
|
1500
|
-
adjacency.get(ref).push(job.id);
|
|
1501
|
-
inDegree.set(job.id, inDegree.get(job.id) + 1);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
const queue = [];
|
|
1506
|
-
for (const job of jobs) {
|
|
1507
|
-
if (inDegree.get(job.id) === 0) {
|
|
1508
|
-
queue.push(job);
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
queue.sort((a, b) => {
|
|
1512
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
1513
|
-
return a.index - b.index;
|
|
1514
|
-
});
|
|
1515
|
-
const result = [];
|
|
1516
|
-
while (queue.length > 0) {
|
|
1517
|
-
const job = queue.shift();
|
|
1518
|
-
result.push(job);
|
|
1519
|
-
const neighbors = adjacency.get(job.id) || [];
|
|
1520
|
-
for (const neighborId of neighbors) {
|
|
1521
|
-
const newDegree = inDegree.get(neighborId) - 1;
|
|
1522
|
-
inDegree.set(neighborId, newDegree);
|
|
1523
|
-
if (newDegree === 0) {
|
|
1524
|
-
const neighbor = jobMap.get(neighborId);
|
|
1525
|
-
insertSorted(queue, neighbor);
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
if (result.length !== n) {
|
|
1530
|
-
console.warn("[useFrame] Circular dependency detected in job constraints");
|
|
1531
|
-
const resultIds = new Set(result.map((j) => j.id));
|
|
1532
|
-
for (const job of jobs) {
|
|
1533
|
-
if (!resultIds.has(job.id)) result.push(job);
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
return result;
|
|
1537
|
-
}
|
|
1538
|
-
function insertSorted(arr, job) {
|
|
1539
|
-
let i = 0;
|
|
1540
|
-
while (i < arr.length) {
|
|
1541
|
-
const cmp = arr[i];
|
|
1542
|
-
if (job.priority > cmp.priority || job.priority === cmp.priority && job.index < cmp.index) {
|
|
1543
|
-
break;
|
|
1544
|
-
}
|
|
1545
|
-
i++;
|
|
1546
|
-
}
|
|
1547
|
-
arr.splice(i, 0, job);
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
function shouldRun(job, now) {
|
|
1551
|
-
if (!job.enabled) return false;
|
|
1552
|
-
if (!job.fps) return true;
|
|
1553
|
-
const minInterval = 1e3 / job.fps;
|
|
1554
|
-
const lastRun = job.lastRun ?? 0;
|
|
1555
|
-
const elapsed = now - lastRun;
|
|
1556
|
-
if (elapsed < minInterval) return false;
|
|
1557
|
-
if (job.drop) {
|
|
1558
|
-
job.lastRun = now;
|
|
1559
|
-
} else {
|
|
1560
|
-
const steps = Math.floor(elapsed / minInterval);
|
|
1561
|
-
job.lastRun = lastRun + steps * minInterval;
|
|
1562
|
-
if (job.lastRun < now - minInterval) {
|
|
1563
|
-
job.lastRun = now;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
return true;
|
|
1567
|
-
}
|
|
1568
|
-
function resetJobTiming(job) {
|
|
1569
|
-
job.lastRun = void 0;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
var __defProp = Object.defineProperty;
|
|
1573
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1574
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1575
|
-
const hmrData = (() => {
|
|
1576
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return void 0;
|
|
1577
|
-
if (typeof import_meta_hot !== "undefined") return import_meta_hot;
|
|
1578
|
-
try {
|
|
1579
|
-
return (0, eval)("import.meta.hot");
|
|
1580
|
-
} catch {
|
|
1581
|
-
return void 0;
|
|
1582
|
-
}
|
|
1583
|
-
})();
|
|
1584
|
-
const _Scheduler = class _Scheduler {
|
|
1585
|
-
//* Constructor ================================
|
|
1586
|
-
constructor() {
|
|
1587
|
-
//* Critical State ================================
|
|
1588
|
-
__publicField(this, "roots", /* @__PURE__ */ new Map());
|
|
1589
|
-
__publicField(this, "phaseGraph");
|
|
1590
|
-
__publicField(this, "loopState", {
|
|
1591
|
-
running: false,
|
|
1592
|
-
rafHandle: null,
|
|
1593
|
-
lastTime: null,
|
|
1594
|
-
// null = uninitialized, 0+ = valid timestamp
|
|
1595
|
-
frameCount: 0,
|
|
1596
|
-
elapsedTime: 0,
|
|
1597
|
-
createdAt: performance.now()
|
|
1598
|
-
});
|
|
1599
|
-
__publicField(this, "stoppedTime", 0);
|
|
1600
|
-
//* Private State ================================
|
|
1601
|
-
__publicField(this, "nextRootIndex", 0);
|
|
1602
|
-
__publicField(this, "globalBeforeJobs", /* @__PURE__ */ new Map());
|
|
1603
|
-
__publicField(this, "globalAfterJobs", /* @__PURE__ */ new Map());
|
|
1604
|
-
__publicField(this, "nextGlobalIndex", 0);
|
|
1605
|
-
__publicField(this, "idleCallbacks", /* @__PURE__ */ new Set());
|
|
1606
|
-
__publicField(this, "nextJobIndex", 0);
|
|
1607
|
-
__publicField(this, "jobStateListeners", /* @__PURE__ */ new Map());
|
|
1608
|
-
__publicField(this, "pendingFrames", 0);
|
|
1609
|
-
__publicField(this, "_frameloop", "always");
|
|
1610
|
-
//* Independent Mode & Error Handling State ================================
|
|
1611
|
-
__publicField(this, "_independent", false);
|
|
1612
|
-
__publicField(this, "errorHandler", null);
|
|
1613
|
-
__publicField(this, "rootReadyCallbacks", /* @__PURE__ */ new Set());
|
|
1614
|
-
//* Core Loop Execution Methods ================================
|
|
1615
|
-
/**
|
|
1616
|
-
* Main RAF loop callback.
|
|
1617
|
-
* Executes frame, handles demand mode, and schedules next frame.
|
|
1618
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
1619
|
-
* @returns {void}
|
|
1620
|
-
* @private
|
|
1621
|
-
*/
|
|
1622
|
-
__publicField(this, "loop", (timestamp) => {
|
|
1623
|
-
if (!this.loopState.running) return;
|
|
1624
|
-
this.executeFrame(timestamp);
|
|
1625
|
-
if (this._frameloop === "demand") {
|
|
1626
|
-
this.pendingFrames = Math.max(0, this.pendingFrames - 1);
|
|
1627
|
-
if (this.pendingFrames === 0) {
|
|
1628
|
-
this.notifyIdle(timestamp);
|
|
1629
|
-
return this.stop();
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
this.loopState.rafHandle = requestAnimationFrame(this.loop);
|
|
1633
|
-
});
|
|
1634
|
-
this.phaseGraph = new PhaseGraph();
|
|
1635
|
-
}
|
|
1636
|
-
static get instance() {
|
|
1637
|
-
return globalThis[_Scheduler.INSTANCE_KEY] ?? null;
|
|
1638
|
-
}
|
|
1639
|
-
static set instance(value) {
|
|
1640
|
-
globalThis[_Scheduler.INSTANCE_KEY] = value;
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Get the global scheduler instance (creates if doesn't exist).
|
|
1644
|
-
* Uses HMR data to preserve instance across hot reloads.
|
|
1645
|
-
* @returns {Scheduler} The singleton scheduler instance
|
|
1646
|
-
*/
|
|
1647
|
-
static get() {
|
|
1648
|
-
if (!_Scheduler.instance && hmrData?.data?.scheduler) {
|
|
1649
|
-
_Scheduler.instance = hmrData.data.scheduler;
|
|
1650
|
-
}
|
|
1651
|
-
if (!_Scheduler.instance) {
|
|
1652
|
-
_Scheduler.instance = new _Scheduler();
|
|
1653
|
-
if (hmrData?.data) {
|
|
1654
|
-
hmrData.data.scheduler = _Scheduler.instance;
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
return _Scheduler.instance;
|
|
1658
|
-
}
|
|
1659
|
-
/**
|
|
1660
|
-
* Reset the singleton instance. Stops the loop and clears all state.
|
|
1661
|
-
* Primarily used for testing to ensure clean state between tests.
|
|
1662
|
-
* @returns {void}
|
|
1663
|
-
*/
|
|
1664
|
-
static reset() {
|
|
1665
|
-
if (_Scheduler.instance) {
|
|
1666
|
-
_Scheduler.instance.stop();
|
|
1667
|
-
_Scheduler.instance = null;
|
|
1668
|
-
}
|
|
1669
|
-
if (hmrData?.data) {
|
|
1670
|
-
hmrData.data.scheduler = null;
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
//* Getters & Setters ================================
|
|
1674
|
-
get phases() {
|
|
1675
|
-
return this.phaseGraph.getOrderedPhases();
|
|
1676
|
-
}
|
|
1677
|
-
get frameloop() {
|
|
1678
|
-
return this._frameloop;
|
|
1679
|
-
}
|
|
1680
|
-
set frameloop(mode) {
|
|
1681
|
-
if (this._frameloop === mode) return;
|
|
1682
|
-
const wasAlways = this._frameloop === "always";
|
|
1683
|
-
this._frameloop = mode;
|
|
1684
|
-
if (mode === "always" && !this.loopState.running && this.roots.size > 0) this.start();
|
|
1685
|
-
else if (mode !== "always" && wasAlways) this.stop();
|
|
1686
|
-
}
|
|
1687
|
-
get isRunning() {
|
|
1688
|
-
return this.loopState.running;
|
|
1689
|
-
}
|
|
1690
|
-
get isReady() {
|
|
1691
|
-
return this.roots.size > 0;
|
|
1692
|
-
}
|
|
1693
|
-
get independent() {
|
|
1694
|
-
return this._independent;
|
|
1695
|
-
}
|
|
1696
|
-
set independent(value) {
|
|
1697
|
-
this._independent = value;
|
|
1698
|
-
if (value) this.ensureDefaultRoot();
|
|
1699
|
-
}
|
|
1700
|
-
//* Root Management Methods ================================
|
|
1701
|
-
/**
|
|
1702
|
-
* Register a root (Canvas) with the scheduler.
|
|
1703
|
-
* The first root to register starts the RAF loop (if frameloop='always').
|
|
1704
|
-
* @param {string} id - Unique identifier for this root
|
|
1705
|
-
* @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
|
|
1706
|
-
* @returns {() => void} Unsubscribe function to remove this root
|
|
1707
|
-
*/
|
|
1708
|
-
registerRoot(id, options = {}) {
|
|
1709
|
-
if (this.roots.has(id)) {
|
|
1710
|
-
console.warn(`[Scheduler] Root "${id}" already registered`);
|
|
1711
|
-
return () => this.unregisterRoot(id);
|
|
1712
|
-
}
|
|
1713
|
-
const entry = {
|
|
1714
|
-
id,
|
|
1715
|
-
getState: options.getState ?? (() => ({})),
|
|
1716
|
-
jobs: /* @__PURE__ */ new Map(),
|
|
1717
|
-
sortedJobs: [],
|
|
1718
|
-
needsRebuild: false
|
|
1719
|
-
};
|
|
1720
|
-
if (options.onError) {
|
|
1721
|
-
this.errorHandler = options.onError;
|
|
1722
|
-
}
|
|
1723
|
-
this.roots.set(id, entry);
|
|
1724
|
-
if (this.roots.size === 1) {
|
|
1725
|
-
this.notifyRootReady();
|
|
1726
|
-
if (this._frameloop === "always") this.start();
|
|
1727
|
-
}
|
|
1728
|
-
return () => this.unregisterRoot(id);
|
|
1729
|
-
}
|
|
1730
|
-
/**
|
|
1731
|
-
* Unregister a root from the scheduler.
|
|
1732
|
-
* Cleans up all job state listeners for this root's jobs.
|
|
1733
|
-
* The last root to unregister stops the RAF loop.
|
|
1734
|
-
* @param {string} id - The root ID to unregister
|
|
1735
|
-
* @returns {void}
|
|
1736
|
-
*/
|
|
1737
|
-
unregisterRoot(id) {
|
|
1738
|
-
const root = this.roots.get(id);
|
|
1739
|
-
if (!root) return;
|
|
1740
|
-
for (const jobId of root.jobs.keys()) {
|
|
1741
|
-
this.jobStateListeners.delete(jobId);
|
|
1742
|
-
}
|
|
1743
|
-
this.roots.delete(id);
|
|
1744
|
-
if (this.roots.size === 0) {
|
|
1745
|
-
this.stop();
|
|
1746
|
-
this.errorHandler = null;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
/**
|
|
1750
|
-
* Subscribe to be notified when a root becomes available.
|
|
1751
|
-
* Fires immediately if a root already exists.
|
|
1752
|
-
* @param {() => void} callback - Function called when first root registers
|
|
1753
|
-
* @returns {() => void} Unsubscribe function
|
|
1754
|
-
*/
|
|
1755
|
-
onRootReady(callback) {
|
|
1756
|
-
if (this.roots.size > 0) {
|
|
1757
|
-
callback();
|
|
1758
|
-
return () => {
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
this.rootReadyCallbacks.add(callback);
|
|
1762
|
-
return () => this.rootReadyCallbacks.delete(callback);
|
|
1763
|
-
}
|
|
1764
|
-
/**
|
|
1765
|
-
* Notify all registered root-ready callbacks.
|
|
1766
|
-
* Called when the first root registers.
|
|
1767
|
-
* @returns {void}
|
|
1768
|
-
* @private
|
|
1769
|
-
*/
|
|
1770
|
-
notifyRootReady() {
|
|
1771
|
-
for (const cb of this.rootReadyCallbacks) {
|
|
1772
|
-
try {
|
|
1773
|
-
cb();
|
|
1774
|
-
} catch (error) {
|
|
1775
|
-
console.error("[Scheduler] Error in root-ready callback:", error);
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
this.rootReadyCallbacks.clear();
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Ensure a default root exists for independent mode.
|
|
1782
|
-
* Creates a minimal root with no state provider.
|
|
1783
|
-
* @returns {void}
|
|
1784
|
-
* @private
|
|
1785
|
-
*/
|
|
1786
|
-
ensureDefaultRoot() {
|
|
1787
|
-
if (!this.roots.has("__default__")) {
|
|
1788
|
-
this.registerRoot("__default__");
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
/**
|
|
1792
|
-
* Trigger error handling for job errors.
|
|
1793
|
-
* Uses the bound error handler if available, otherwise logs to console.
|
|
1794
|
-
* @param {Error} error - The error to handle
|
|
1795
|
-
* @returns {void}
|
|
1796
|
-
*/
|
|
1797
|
-
triggerError(error) {
|
|
1798
|
-
if (this.errorHandler) this.errorHandler(error);
|
|
1799
|
-
else console.error("[Scheduler]", error);
|
|
1800
|
-
}
|
|
1801
|
-
//* Phase Management Methods ================================
|
|
1802
|
-
/**
|
|
1803
|
-
* Add a named phase to the scheduler's execution order.
|
|
1804
|
-
* Marks all roots for rebuild to incorporate the new phase.
|
|
1805
|
-
* @param {string} name - The phase name (e.g., 'physics', 'postprocess')
|
|
1806
|
-
* @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
|
|
1807
|
-
* @returns {void}
|
|
1808
|
-
* @example
|
|
1809
|
-
* scheduler.addPhase('physics', { before: 'update' });
|
|
1810
|
-
* scheduler.addPhase('postprocess', { after: 'render' });
|
|
1811
|
-
*/
|
|
1812
|
-
addPhase(name, options) {
|
|
1813
|
-
this.phaseGraph.addPhase(name, options);
|
|
1814
|
-
for (const root of this.roots.values()) {
|
|
1815
|
-
root.needsRebuild = true;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Check if a phase exists in the scheduler.
|
|
1820
|
-
* @param {string} name - The phase name to check
|
|
1821
|
-
* @returns {boolean} True if the phase exists
|
|
1822
|
-
*/
|
|
1823
|
-
hasPhase(name) {
|
|
1824
|
-
return this.phaseGraph.hasPhase(name);
|
|
1825
|
-
}
|
|
1826
|
-
//* Global Job Registration Methods (Deprecated APIs) ================================
|
|
1827
|
-
/**
|
|
1828
|
-
* Register a global job that runs once per frame (not per-root).
|
|
1829
|
-
* Used internally by deprecated addEffect/addAfterEffect APIs.
|
|
1830
|
-
* @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
|
|
1831
|
-
* @param {string} id - Unique identifier for this global job
|
|
1832
|
-
* @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
|
|
1833
|
-
* @returns {() => void} Unsubscribe function to remove this global job
|
|
1834
|
-
* @deprecated Use useFrame with phases instead
|
|
1835
|
-
*/
|
|
1836
|
-
registerGlobal(phase, id, callback) {
|
|
1837
|
-
const job = { id, callback };
|
|
1838
|
-
if (phase === "before") {
|
|
1839
|
-
this.globalBeforeJobs.set(id, job);
|
|
1840
|
-
} else {
|
|
1841
|
-
this.globalAfterJobs.set(id, job);
|
|
1842
|
-
}
|
|
1843
|
-
return () => {
|
|
1844
|
-
if (phase === "before") this.globalBeforeJobs.delete(id);
|
|
1845
|
-
else this.globalAfterJobs.delete(id);
|
|
1846
|
-
};
|
|
1847
|
-
}
|
|
1848
|
-
//* Idle Callback Methods (Deprecated API) ================================
|
|
1849
|
-
/**
|
|
1850
|
-
* Register an idle callback that fires when the loop stops.
|
|
1851
|
-
* Used internally by deprecated addTail API.
|
|
1852
|
-
* @param {(timestamp: number) => void} callback - Function called when loop becomes idle
|
|
1853
|
-
* @returns {() => void} Unsubscribe function to remove this idle callback
|
|
1854
|
-
* @deprecated Use demand mode with invalidate() instead
|
|
1855
|
-
*/
|
|
1856
|
-
onIdle(callback) {
|
|
1857
|
-
this.idleCallbacks.add(callback);
|
|
1858
|
-
return () => this.idleCallbacks.delete(callback);
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Notify all registered idle callbacks.
|
|
1862
|
-
* Called when the loop stops in demand mode.
|
|
1863
|
-
* @param {number} timestamp - The RAF timestamp when idle occurred
|
|
1864
|
-
* @returns {void}
|
|
1865
|
-
* @private
|
|
1866
|
-
*/
|
|
1867
|
-
notifyIdle(timestamp) {
|
|
1868
|
-
for (const cb of this.idleCallbacks) {
|
|
1869
|
-
try {
|
|
1870
|
-
cb(timestamp);
|
|
1871
|
-
} catch (error) {
|
|
1872
|
-
console.error("[Scheduler] Error in idle callback:", error);
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
//* Job Registration & Management Methods ================================
|
|
1877
|
-
/**
|
|
1878
|
-
* Register a job (frame callback) with a specific root.
|
|
1879
|
-
* This is the core registration method used by useFrame internally.
|
|
1880
|
-
* @param {FrameNextCallback} callback - The function to call each frame
|
|
1881
|
-
* @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
|
|
1882
|
-
* @param {string} [options.rootId] - Target root ID (defaults to first registered root)
|
|
1883
|
-
* @param {string} [options.id] - Unique job ID (auto-generated if not provided)
|
|
1884
|
-
* @param {string} [options.phase] - Execution phase (defaults to 'update')
|
|
1885
|
-
* @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
|
|
1886
|
-
* @param {number} [options.fps] - FPS throttle limit
|
|
1887
|
-
* @param {boolean} [options.drop] - Drop frames when behind (default true)
|
|
1888
|
-
* @param {boolean} [options.enabled] - Whether job is active (default true)
|
|
1889
|
-
* @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
|
|
1890
|
-
* @returns {() => void} Unsubscribe function to remove this job
|
|
1891
|
-
*/
|
|
1892
|
-
register(callback, options = {}) {
|
|
1893
|
-
const rootId = options.rootId;
|
|
1894
|
-
const root = rootId ? this.roots.get(rootId) : this.roots.values().next().value;
|
|
1895
|
-
if (!root) {
|
|
1896
|
-
console.warn("[Scheduler] No root registered. Is this inside a Canvas?");
|
|
1897
|
-
return () => {
|
|
1898
|
-
};
|
|
1899
|
-
}
|
|
1900
|
-
const id = options.id ?? this.generateJobId();
|
|
1901
|
-
let phase = options.phase ?? "update";
|
|
1902
|
-
if (!options.phase && (options.before || options.after)) {
|
|
1903
|
-
phase = this.phaseGraph.resolveConstraintPhase(options.before, options.after);
|
|
1904
|
-
}
|
|
1905
|
-
const before = this.normalizeConstraints(options.before);
|
|
1906
|
-
const after = this.normalizeConstraints(options.after);
|
|
1907
|
-
const job = {
|
|
1908
|
-
id,
|
|
1909
|
-
callback,
|
|
1910
|
-
phase,
|
|
1911
|
-
before,
|
|
1912
|
-
after,
|
|
1913
|
-
priority: options.priority ?? 0,
|
|
1914
|
-
index: this.nextJobIndex++,
|
|
1915
|
-
fps: options.fps,
|
|
1916
|
-
drop: options.drop ?? true,
|
|
1917
|
-
enabled: options.enabled ?? true,
|
|
1918
|
-
system: options.system ?? false
|
|
1919
|
-
};
|
|
1920
|
-
if (root.jobs.has(id)) {
|
|
1921
|
-
console.warn(`[useFrame] Job with id "${id}" already exists, replacing`);
|
|
1922
|
-
}
|
|
1923
|
-
root.jobs.set(id, job);
|
|
1924
|
-
root.needsRebuild = true;
|
|
1925
|
-
return () => this.unregister(id, root.id);
|
|
1926
|
-
}
|
|
1927
|
-
/**
|
|
1928
|
-
* Unregister a job by its ID.
|
|
1929
|
-
* Searches all roots if rootId is not provided.
|
|
1930
|
-
* @param {string} id - The job ID to unregister
|
|
1931
|
-
* @param {string} [rootId] - Optional root ID to search (searches all if not provided)
|
|
1932
|
-
* @returns {void}
|
|
1933
|
-
*/
|
|
1934
|
-
unregister(id, rootId) {
|
|
1935
|
-
const root = rootId ? this.roots.get(rootId) : Array.from(this.roots.values()).find((r) => r.jobs.has(id));
|
|
1936
|
-
if (root?.jobs.delete(id)) {
|
|
1937
|
-
root.needsRebuild = true;
|
|
1938
|
-
this.jobStateListeners.delete(id);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Update a job's options dynamically.
|
|
1943
|
-
* Searches all roots to find the job by ID.
|
|
1944
|
-
* Phase/constraint changes trigger a rebuild of the sorted job list.
|
|
1945
|
-
* @param {string} id - The job ID to update
|
|
1946
|
-
* @param {Partial<JobOptions>} options - The options to update
|
|
1947
|
-
* @returns {void}
|
|
1948
|
-
*/
|
|
1949
|
-
updateJob(id, options) {
|
|
1950
|
-
let job;
|
|
1951
|
-
let root;
|
|
1952
|
-
for (const r of this.roots.values()) {
|
|
1953
|
-
job = r.jobs.get(id);
|
|
1954
|
-
if (job) {
|
|
1955
|
-
root = r;
|
|
1956
|
-
break;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
if (!job || !root) return;
|
|
1960
|
-
if (options.priority !== void 0) job.priority = options.priority;
|
|
1961
|
-
if (options.fps !== void 0) job.fps = options.fps;
|
|
1962
|
-
if (options.drop !== void 0) job.drop = options.drop;
|
|
1963
|
-
if (options.enabled !== void 0) {
|
|
1964
|
-
const wasEnabled = job.enabled;
|
|
1965
|
-
job.enabled = options.enabled;
|
|
1966
|
-
if (!wasEnabled && job.enabled) resetJobTiming(job);
|
|
1967
|
-
if (wasEnabled !== job.enabled) root.needsRebuild = true;
|
|
1968
|
-
}
|
|
1969
|
-
if (options.phase !== void 0 || options.before !== void 0 || options.after !== void 0) {
|
|
1970
|
-
if (options.phase) job.phase = options.phase;
|
|
1971
|
-
if (options.before !== void 0) job.before = this.normalizeConstraints(options.before);
|
|
1972
|
-
if (options.after !== void 0) job.after = this.normalizeConstraints(options.after);
|
|
1973
|
-
root.needsRebuild = true;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
//* Job State Management Methods ================================
|
|
1977
|
-
/**
|
|
1978
|
-
* Check if a job is currently paused (disabled).
|
|
1979
|
-
* @param {string} id - The job ID to check
|
|
1980
|
-
* @returns {boolean} True if the job exists and is paused
|
|
1981
|
-
*/
|
|
1982
|
-
isJobPaused(id) {
|
|
1983
|
-
for (const root of this.roots.values()) {
|
|
1984
|
-
const job = root.jobs.get(id);
|
|
1985
|
-
if (job) return !job.enabled;
|
|
1986
|
-
}
|
|
1987
|
-
return false;
|
|
1988
|
-
}
|
|
1989
|
-
/**
|
|
1990
|
-
* Subscribe to state changes for a specific job.
|
|
1991
|
-
* Listener is called when job is paused or resumed.
|
|
1992
|
-
* @param {string} id - The job ID to subscribe to
|
|
1993
|
-
* @param {() => void} listener - Callback invoked on state changes
|
|
1994
|
-
* @returns {() => void} Unsubscribe function
|
|
1995
|
-
*/
|
|
1996
|
-
subscribeJobState(id, listener) {
|
|
1997
|
-
if (!this.jobStateListeners.has(id)) {
|
|
1998
|
-
this.jobStateListeners.set(id, /* @__PURE__ */ new Set());
|
|
1999
|
-
}
|
|
2000
|
-
this.jobStateListeners.get(id).add(listener);
|
|
2001
|
-
return () => {
|
|
2002
|
-
this.jobStateListeners.get(id)?.delete(listener);
|
|
2003
|
-
if (this.jobStateListeners.get(id)?.size === 0) {
|
|
2004
|
-
this.jobStateListeners.delete(id);
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
/**
|
|
2009
|
-
* Notify all listeners that a job's state has changed.
|
|
2010
|
-
* @param {string} id - The job ID that changed
|
|
2011
|
-
* @returns {void}
|
|
2012
|
-
* @private
|
|
2013
|
-
*/
|
|
2014
|
-
notifyJobStateChange(id) {
|
|
2015
|
-
this.jobStateListeners.get(id)?.forEach((listener) => listener());
|
|
2016
|
-
}
|
|
2017
|
-
/**
|
|
2018
|
-
* Pause a job by ID (sets enabled=false).
|
|
2019
|
-
* Notifies any subscribed state listeners.
|
|
2020
|
-
* @param {string} id - The job ID to pause
|
|
2021
|
-
* @returns {void}
|
|
2022
|
-
*/
|
|
2023
|
-
pauseJob(id) {
|
|
2024
|
-
this.updateJob(id, { enabled: false });
|
|
2025
|
-
this.notifyJobStateChange(id);
|
|
2026
|
-
}
|
|
2027
|
-
/**
|
|
2028
|
-
* Resume a paused job by ID (sets enabled=true).
|
|
2029
|
-
* Resets job timing to prevent frame accumulation.
|
|
2030
|
-
* Notifies any subscribed state listeners.
|
|
2031
|
-
* @param {string} id - The job ID to resume
|
|
2032
|
-
* @returns {void}
|
|
2033
|
-
*/
|
|
2034
|
-
resumeJob(id) {
|
|
2035
|
-
this.updateJob(id, { enabled: true });
|
|
2036
|
-
this.notifyJobStateChange(id);
|
|
2037
|
-
}
|
|
2038
|
-
//* Frame Loop Control Methods ================================
|
|
2039
|
-
/**
|
|
2040
|
-
* Start the requestAnimationFrame loop.
|
|
2041
|
-
* Resets timing state (elapsedTime, frameCount) on start.
|
|
2042
|
-
* No-op if already running.
|
|
2043
|
-
* @returns {void}
|
|
2044
|
-
*/
|
|
2045
|
-
start() {
|
|
2046
|
-
if (this.loopState.running) return;
|
|
2047
|
-
const { elapsedTime, createdAt } = this.loopState;
|
|
2048
|
-
let adjustedCreated = 0;
|
|
2049
|
-
if (this.stoppedTime > 0) {
|
|
2050
|
-
adjustedCreated = createdAt - (performance.now() - this.stoppedTime);
|
|
2051
|
-
this.stoppedTime = 0;
|
|
2052
|
-
}
|
|
2053
|
-
Object.assign(this.loopState, {
|
|
2054
|
-
running: true,
|
|
2055
|
-
elapsedTime: elapsedTime ?? 0,
|
|
2056
|
-
lastTime: performance.now(),
|
|
2057
|
-
createdAt: adjustedCreated > 0 ? adjustedCreated : performance.now(),
|
|
2058
|
-
frameCount: 0,
|
|
2059
|
-
rafHandle: requestAnimationFrame(this.loop)
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
/**
|
|
2063
|
-
* Stop the requestAnimationFrame loop.
|
|
2064
|
-
* Cancels any pending RAF callback.
|
|
2065
|
-
* No-op if not running.
|
|
2066
|
-
* @returns {void}
|
|
2067
|
-
*/
|
|
2068
|
-
stop() {
|
|
2069
|
-
if (!this.loopState.running) return;
|
|
2070
|
-
this.loopState.running = false;
|
|
2071
|
-
if (this.loopState.rafHandle !== null) {
|
|
2072
|
-
cancelAnimationFrame(this.loopState.rafHandle);
|
|
2073
|
-
this.loopState.rafHandle = null;
|
|
2074
|
-
}
|
|
2075
|
-
this.stoppedTime = performance.now();
|
|
2076
|
-
}
|
|
2077
|
-
/**
|
|
2078
|
-
* Request frames to be rendered in demand mode.
|
|
2079
|
-
* Accumulates pending frames (capped at 60) and starts the loop if not running.
|
|
2080
|
-
* No-op if frameloop is not 'demand'.
|
|
2081
|
-
* @param {number} [frames=1] - Number of frames to request
|
|
2082
|
-
* @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
|
|
2083
|
-
* - `false` (default): Sets pending frames to the specified value (replaces existing count)
|
|
2084
|
-
* - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
|
|
2085
|
-
* @returns {void}
|
|
2086
|
-
* @example
|
|
2087
|
-
* // Request a single frame render
|
|
2088
|
-
* scheduler.invalidate();
|
|
2089
|
-
*
|
|
2090
|
-
* @example
|
|
2091
|
-
* // Request 5 frames (e.g., for animations)
|
|
2092
|
-
* scheduler.invalidate(5);
|
|
2093
|
-
*
|
|
2094
|
-
* @example
|
|
2095
|
-
* // Set pending frames to exactly 3 (don't stack with existing)
|
|
2096
|
-
* scheduler.invalidate(3, false);
|
|
2097
|
-
*
|
|
2098
|
-
* @example
|
|
2099
|
-
* // Add 2 more frames to existing pending count
|
|
2100
|
-
* scheduler.invalidate(2, true);
|
|
2101
|
-
*/
|
|
2102
|
-
invalidate(frames = 1, stackFrames = false) {
|
|
2103
|
-
if (this._frameloop !== "demand") return;
|
|
2104
|
-
const baseFrames = stackFrames ? this.pendingFrames : 0;
|
|
2105
|
-
this.pendingFrames = Math.min(60, baseFrames + frames);
|
|
2106
|
-
if (!this.loopState.running && this.pendingFrames > 0) this.start();
|
|
2107
|
-
}
|
|
2108
|
-
/**
|
|
2109
|
-
* Reset timing state for deterministic testing.
|
|
2110
|
-
* Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
|
|
2111
|
-
* @returns {void}
|
|
2112
|
-
*/
|
|
2113
|
-
resetTiming() {
|
|
2114
|
-
this.loopState.lastTime = null;
|
|
2115
|
-
this.loopState.frameCount = 0;
|
|
2116
|
-
this.loopState.elapsedTime = 0;
|
|
2117
|
-
this.loopState.createdAt = performance.now();
|
|
2118
|
-
}
|
|
2119
|
-
//* Manual Stepping Methods ================================
|
|
2120
|
-
/**
|
|
2121
|
-
* Manually execute a single frame for all roots.
|
|
2122
|
-
* Useful for frameloop='never' mode or testing scenarios.
|
|
2123
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2124
|
-
* @returns {void}
|
|
2125
|
-
* @example
|
|
2126
|
-
* // Manual control mode
|
|
2127
|
-
* scheduler.frameloop = 'never';
|
|
2128
|
-
* scheduler.step(); // Execute one frame
|
|
2129
|
-
*/
|
|
2130
|
-
step(timestamp) {
|
|
2131
|
-
const now = timestamp ?? performance.now();
|
|
2132
|
-
this.executeFrame(now);
|
|
2133
|
-
}
|
|
2134
|
-
/**
|
|
2135
|
-
* Manually execute a single job by its ID.
|
|
2136
|
-
* Useful for testing individual job callbacks in isolation.
|
|
2137
|
-
* @param {string} id - The job ID to step
|
|
2138
|
-
* @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
|
|
2139
|
-
* @returns {void}
|
|
2140
|
-
*/
|
|
2141
|
-
stepJob(id, timestamp) {
|
|
2142
|
-
let job;
|
|
2143
|
-
let root;
|
|
2144
|
-
for (const r of this.roots.values()) {
|
|
2145
|
-
job = r.jobs.get(id);
|
|
2146
|
-
if (job) {
|
|
2147
|
-
root = r;
|
|
2148
|
-
break;
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
if (!job || !root) {
|
|
2152
|
-
console.warn(`[Scheduler] Job "${id}" not found`);
|
|
2153
|
-
return;
|
|
2154
|
-
}
|
|
2155
|
-
const now = timestamp ?? performance.now();
|
|
2156
|
-
const deltaMs = this.loopState.lastTime !== null ? now - this.loopState.lastTime : 0;
|
|
2157
|
-
const delta = deltaMs / 1e3;
|
|
2158
|
-
const elapsed = now - this.loopState.createdAt;
|
|
2159
|
-
const providedState = root.getState?.() ?? {};
|
|
2160
|
-
const frameState = {
|
|
2161
|
-
...providedState,
|
|
2162
|
-
time: now,
|
|
2163
|
-
delta,
|
|
2164
|
-
elapsed,
|
|
2165
|
-
frame: this.loopState.frameCount
|
|
2166
|
-
};
|
|
2167
|
-
try {
|
|
2168
|
-
job.callback(frameState, delta);
|
|
2169
|
-
} catch (error) {
|
|
2170
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2171
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
/**
|
|
2175
|
-
* Execute a single frame across all roots.
|
|
2176
|
-
* Order: globalBefore → each root's jobs → globalAfter
|
|
2177
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2178
|
-
* @returns {void}
|
|
2179
|
-
* @private
|
|
2180
|
-
*/
|
|
2181
|
-
executeFrame(timestamp) {
|
|
2182
|
-
const deltaMs = this.loopState.lastTime !== null ? timestamp - this.loopState.lastTime : 0;
|
|
2183
|
-
const delta = deltaMs / 1e3;
|
|
2184
|
-
this.loopState.lastTime = timestamp;
|
|
2185
|
-
this.loopState.frameCount++;
|
|
2186
|
-
this.loopState.elapsedTime += deltaMs;
|
|
2187
|
-
this.runGlobalJobs(this.globalBeforeJobs, timestamp);
|
|
2188
|
-
for (const root of this.roots.values()) {
|
|
2189
|
-
this.tickRoot(root, timestamp, delta);
|
|
2190
|
-
}
|
|
2191
|
-
this.runGlobalJobs(this.globalAfterJobs, timestamp);
|
|
2192
|
-
}
|
|
2193
|
-
/**
|
|
2194
|
-
* Run all global jobs from a job map.
|
|
2195
|
-
* Catches and logs errors without stopping execution.
|
|
2196
|
-
* @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
|
|
2197
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2198
|
-
* @returns {void}
|
|
2199
|
-
* @private
|
|
2200
|
-
*/
|
|
2201
|
-
runGlobalJobs(jobs, timestamp) {
|
|
2202
|
-
for (const job of jobs.values()) {
|
|
2203
|
-
try {
|
|
2204
|
-
job.callback(timestamp);
|
|
2205
|
-
} catch (error) {
|
|
2206
|
-
console.error(`[Scheduler] Error in global job "${job.id}":`, error);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Execute all jobs for a single root in sorted order.
|
|
2212
|
-
* Rebuilds sorted job list if needed, then dispatches each job.
|
|
2213
|
-
* Errors are caught and propagated via triggerError.
|
|
2214
|
-
* @param {RootEntry} root - The root entry to tick
|
|
2215
|
-
* @param {number} timestamp - RAF timestamp in milliseconds
|
|
2216
|
-
* @param {number} delta - Time since last frame in seconds
|
|
2217
|
-
* @returns {void}
|
|
2218
|
-
* @private
|
|
2219
|
-
*/
|
|
2220
|
-
tickRoot(root, timestamp, delta) {
|
|
2221
|
-
if (root.needsRebuild) {
|
|
2222
|
-
root.sortedJobs = rebuildSortedJobs(root.jobs, this.phaseGraph);
|
|
2223
|
-
root.needsRebuild = false;
|
|
2224
|
-
}
|
|
2225
|
-
const providedState = root.getState?.() ?? {};
|
|
2226
|
-
const frameState = {
|
|
2227
|
-
...providedState,
|
|
2228
|
-
time: timestamp,
|
|
2229
|
-
delta,
|
|
2230
|
-
elapsed: this.loopState.elapsedTime / 1e3,
|
|
2231
|
-
// Convert ms to seconds
|
|
2232
|
-
frame: this.loopState.frameCount
|
|
2233
|
-
};
|
|
2234
|
-
for (const job of root.sortedJobs) {
|
|
2235
|
-
if (!shouldRun(job, timestamp)) continue;
|
|
2236
|
-
try {
|
|
2237
|
-
job.callback(frameState, delta);
|
|
2238
|
-
} catch (error) {
|
|
2239
|
-
console.error(`[Scheduler] Error in job "${job.id}":`, error);
|
|
2240
|
-
this.triggerError(error instanceof Error ? error : new Error(String(error)));
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
//* Debug & Inspection Methods ================================
|
|
2245
|
-
/**
|
|
2246
|
-
* Get the total number of registered jobs across all roots.
|
|
2247
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2248
|
-
* @returns {number} Total job count
|
|
2249
|
-
*/
|
|
2250
|
-
getJobCount() {
|
|
2251
|
-
let count = 0;
|
|
2252
|
-
for (const root of this.roots.values()) {
|
|
2253
|
-
count += root.jobs.size;
|
|
2254
|
-
}
|
|
2255
|
-
return count + this.globalBeforeJobs.size + this.globalAfterJobs.size;
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Get all registered job IDs across all roots.
|
|
2259
|
-
* Includes both per-root jobs and global before/after jobs.
|
|
2260
|
-
* @returns {string[]} Array of all job IDs
|
|
2261
|
-
*/
|
|
2262
|
-
getJobIds() {
|
|
2263
|
-
const ids = [];
|
|
2264
|
-
for (const root of this.roots.values()) {
|
|
2265
|
-
ids.push(...root.jobs.keys());
|
|
2266
|
-
}
|
|
2267
|
-
ids.push(...this.globalBeforeJobs.keys());
|
|
2268
|
-
ids.push(...this.globalAfterJobs.keys());
|
|
2269
|
-
return ids;
|
|
2270
|
-
}
|
|
2271
|
-
/**
|
|
2272
|
-
* Get the number of registered roots (Canvas instances).
|
|
2273
|
-
* @returns {number} Number of registered roots
|
|
2274
|
-
*/
|
|
2275
|
-
getRootCount() {
|
|
2276
|
-
return this.roots.size;
|
|
2277
|
-
}
|
|
2278
|
-
/**
|
|
2279
|
-
* Check if any user (non-system) jobs are registered in a specific phase.
|
|
2280
|
-
* Used by the default render job to know if a user has taken over rendering.
|
|
2281
|
-
*
|
|
2282
|
-
* @param phase The phase to check
|
|
2283
|
-
* @param rootId Optional root ID to check (checks all roots if not provided)
|
|
2284
|
-
* @returns true if any user jobs exist in the phase
|
|
2285
|
-
*/
|
|
2286
|
-
hasUserJobsInPhase(phase, rootId) {
|
|
2287
|
-
const rootsToCheck = rootId ? [this.roots.get(rootId)].filter(Boolean) : Array.from(this.roots.values());
|
|
2288
|
-
return rootsToCheck.some((root) => {
|
|
2289
|
-
if (!root) return false;
|
|
2290
|
-
for (const job of root.jobs.values()) {
|
|
2291
|
-
if (job.phase === phase && !job.system && job.enabled) return true;
|
|
2292
|
-
}
|
|
2293
|
-
return false;
|
|
2294
|
-
});
|
|
2295
|
-
}
|
|
2296
|
-
//* Utility Methods ================================
|
|
2297
|
-
/**
|
|
2298
|
-
* Generate a unique root ID for automatic root registration.
|
|
2299
|
-
* @returns {string} A unique root ID in the format 'root_N'
|
|
2300
|
-
*/
|
|
2301
|
-
generateRootId() {
|
|
2302
|
-
return `root_${this.nextRootIndex++}`;
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Generate a unique job ID.
|
|
2306
|
-
* @returns {string} A unique job ID in the format 'job_N'
|
|
2307
|
-
* @private
|
|
2308
|
-
*/
|
|
2309
|
-
generateJobId() {
|
|
2310
|
-
return `job_${this.nextJobIndex}`;
|
|
2311
|
-
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Normalize before/after constraints to a Set.
|
|
2314
|
-
* Handles undefined, single string, or array inputs.
|
|
2315
|
-
* @param {string | string[] | undefined} value - The constraint value(s)
|
|
2316
|
-
* @returns {Set<string>} Normalized Set of constraint strings
|
|
2317
|
-
* @private
|
|
2318
|
-
*/
|
|
2319
|
-
normalizeConstraints(value) {
|
|
2320
|
-
if (!value) return /* @__PURE__ */ new Set();
|
|
2321
|
-
if (Array.isArray(value)) return new Set(value);
|
|
2322
|
-
return /* @__PURE__ */ new Set([value]);
|
|
2323
|
-
}
|
|
2324
|
-
};
|
|
2325
|
-
//* Static State & Methods (Singleton Usage) ================================
|
|
2326
|
-
//* Cross-Bundle Singleton Key ==============================
|
|
2327
|
-
// Use Symbol.for() to ensure scheduler is shared across bundle boundaries
|
|
2328
|
-
// This prevents issues when mixing imports from @react-three/fiber and @react-three/fiber/webgpu
|
|
2329
|
-
__publicField(_Scheduler, "INSTANCE_KEY", Symbol.for("@react-three/fiber.scheduler"));
|
|
2330
|
-
let Scheduler = _Scheduler;
|
|
2331
|
-
const getScheduler = () => Scheduler.get();
|
|
2332
|
-
if (hmrData) {
|
|
2333
|
-
hmrData.accept?.();
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
1970
|
function useFrame(callback, priorityOrOptions) {
|
|
2337
1971
|
const store = React.useContext(context);
|
|
2338
1972
|
const isInsideCanvas = store !== null;
|
|
@@ -2405,20 +2039,14 @@ function useFrame(callback, priorityOrOptions) {
|
|
|
2405
2039
|
}
|
|
2406
2040
|
};
|
|
2407
2041
|
} else {
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
unregisterJob = registerOutside();
|
|
2417
|
-
});
|
|
2418
|
-
return () => {
|
|
2419
|
-
unsubReady();
|
|
2420
|
-
unregisterJob?.();
|
|
2421
|
-
};
|
|
2042
|
+
return scheduler.register(
|
|
2043
|
+
(state, delta) => {
|
|
2044
|
+
const frameState = state;
|
|
2045
|
+
if (!frameState.renderer) return;
|
|
2046
|
+
callbackRef.current?.(frameState, delta);
|
|
2047
|
+
},
|
|
2048
|
+
{ id, ...options }
|
|
2049
|
+
);
|
|
2422
2050
|
}
|
|
2423
2051
|
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2424
2052
|
const isPaused = React.useSyncExternalStore(
|
|
@@ -2509,22 +2137,29 @@ function buildFromCache(input, textureCache) {
|
|
|
2509
2137
|
function useTexture(input, optionsOrOnLoad) {
|
|
2510
2138
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2511
2139
|
const store = useStore();
|
|
2512
|
-
const textureCache = useThree((state) => state.textures);
|
|
2513
2140
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2514
|
-
const { onLoad, cache =
|
|
2141
|
+
const { onLoad, cache = true } = options;
|
|
2142
|
+
const onLoadRef = useRef(onLoad);
|
|
2143
|
+
onLoadRef.current = onLoad;
|
|
2144
|
+
const onLoadCalledForRef = useRef(null);
|
|
2515
2145
|
const urls = useMemo(() => getUrls(input), [input]);
|
|
2516
2146
|
const cachedResult = useMemo(() => {
|
|
2517
2147
|
if (!cache) return null;
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2148
|
+
const textures = store.getState().textures;
|
|
2149
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
2150
|
+
return buildFromCache(input, textures);
|
|
2151
|
+
}, [cache, urls, input, store]);
|
|
2521
2152
|
const loadedTextures = useLoader(
|
|
2522
2153
|
TextureLoader,
|
|
2523
2154
|
IsObject(input) ? Object.values(input) : input
|
|
2524
2155
|
);
|
|
2156
|
+
const inputKey = urls.join("\0");
|
|
2525
2157
|
useLayoutEffect(() => {
|
|
2526
|
-
if (
|
|
2527
|
-
|
|
2158
|
+
if (cachedResult) return;
|
|
2159
|
+
if (onLoadCalledForRef.current === inputKey) return;
|
|
2160
|
+
onLoadCalledForRef.current = inputKey;
|
|
2161
|
+
onLoadRef.current?.(loadedTextures);
|
|
2162
|
+
}, [cachedResult, loadedTextures, inputKey]);
|
|
2528
2163
|
useEffect(() => {
|
|
2529
2164
|
if (cachedResult) return;
|
|
2530
2165
|
if ("initTexture" in renderer) {
|
|
@@ -2557,8 +2192,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
2557
2192
|
}, [input, loadedTextures, cachedResult]);
|
|
2558
2193
|
useEffect(() => {
|
|
2559
2194
|
if (!cache) return;
|
|
2560
|
-
if (cachedResult) return;
|
|
2561
|
-
const set = store.setState;
|
|
2562
2195
|
const urlTextureMap = [];
|
|
2563
2196
|
if (typeof input === "string") {
|
|
2564
2197
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -2572,18 +2205,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
2572
2205
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
2573
2206
|
}
|
|
2574
2207
|
}
|
|
2575
|
-
|
|
2576
|
-
const
|
|
2577
|
-
let
|
|
2208
|
+
store.setState((state) => {
|
|
2209
|
+
const refs = new Map(state._textureRefs);
|
|
2210
|
+
let textures = state.textures;
|
|
2211
|
+
let added = false;
|
|
2578
2212
|
for (const [url, texture] of urlTextureMap) {
|
|
2579
|
-
if (!
|
|
2580
|
-
|
|
2581
|
-
|
|
2213
|
+
if (!textures.has(url)) {
|
|
2214
|
+
if (!added) {
|
|
2215
|
+
textures = new Map(textures);
|
|
2216
|
+
added = true;
|
|
2217
|
+
}
|
|
2218
|
+
textures.set(url, texture);
|
|
2582
2219
|
}
|
|
2220
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2583
2221
|
}
|
|
2584
|
-
return
|
|
2222
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2223
|
+
});
|
|
2224
|
+
return () => store.setState((state) => {
|
|
2225
|
+
const refs = new Map(state._textureRefs);
|
|
2226
|
+
for (const [url] of urlTextureMap) {
|
|
2227
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
2228
|
+
if (next <= 0) refs.delete(url);
|
|
2229
|
+
else refs.set(url, next);
|
|
2230
|
+
}
|
|
2231
|
+
return { _textureRefs: refs };
|
|
2585
2232
|
});
|
|
2586
|
-
}, [cache, input, mappedTextures, store
|
|
2233
|
+
}, [cache, input, mappedTextures, store]);
|
|
2587
2234
|
return mappedTextures;
|
|
2588
2235
|
}
|
|
2589
2236
|
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
@@ -2599,106 +2246,90 @@ const Texture = ({
|
|
|
2599
2246
|
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
2600
2247
|
};
|
|
2601
2248
|
|
|
2602
|
-
function
|
|
2603
|
-
if (entry instanceof Texture$1) return entry;
|
|
2604
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof Texture$1) {
|
|
2605
|
-
return entry.value;
|
|
2606
|
-
}
|
|
2607
|
-
return null;
|
|
2608
|
-
}
|
|
2609
|
-
function useTextures() {
|
|
2249
|
+
function useTextures(selector) {
|
|
2610
2250
|
const store = useStore();
|
|
2611
|
-
|
|
2612
|
-
const set = store.setState;
|
|
2251
|
+
const registry = useMemo(() => {
|
|
2613
2252
|
const getState = store.getState;
|
|
2614
|
-
const
|
|
2615
|
-
|
|
2616
|
-
const newMap = new Map(state.textures);
|
|
2617
|
-
newMap.set(key, value);
|
|
2618
|
-
return { textures: newMap };
|
|
2619
|
-
});
|
|
2620
|
-
};
|
|
2621
|
-
const addMultiple = (items) => {
|
|
2622
|
-
set((state) => {
|
|
2623
|
-
const newMap = new Map(state.textures);
|
|
2624
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
2625
|
-
for (const [key, value] of entries) {
|
|
2626
|
-
newMap.set(key, value);
|
|
2627
|
-
}
|
|
2628
|
-
return { textures: newMap };
|
|
2629
|
-
});
|
|
2630
|
-
};
|
|
2631
|
-
const remove = (key) => {
|
|
2632
|
-
set((state) => {
|
|
2633
|
-
const newMap = new Map(state.textures);
|
|
2634
|
-
newMap.delete(key);
|
|
2635
|
-
return { textures: newMap };
|
|
2636
|
-
});
|
|
2637
|
-
};
|
|
2638
|
-
const removeMultiple = (keys) => {
|
|
2639
|
-
set((state) => {
|
|
2640
|
-
const newMap = new Map(state.textures);
|
|
2641
|
-
for (const key of keys) newMap.delete(key);
|
|
2642
|
-
return { textures: newMap };
|
|
2643
|
-
});
|
|
2644
|
-
};
|
|
2645
|
-
const dispose = (key) => {
|
|
2646
|
-
const entry = getState().textures.get(key);
|
|
2647
|
-
if (entry) {
|
|
2648
|
-
const tex = getTextureValue(entry);
|
|
2649
|
-
tex?.dispose();
|
|
2650
|
-
}
|
|
2651
|
-
remove(key);
|
|
2652
|
-
};
|
|
2653
|
-
const disposeMultiple = (keys) => {
|
|
2654
|
-
const textures = getState().textures;
|
|
2655
|
-
for (const key of keys) {
|
|
2656
|
-
const entry = textures.get(key);
|
|
2657
|
-
if (entry) {
|
|
2658
|
-
const tex = getTextureValue(entry);
|
|
2659
|
-
tex?.dispose();
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
removeMultiple(keys);
|
|
2663
|
-
};
|
|
2664
|
-
const disposeAll = () => {
|
|
2665
|
-
const textures = getState().textures;
|
|
2666
|
-
for (const entry of textures.values()) {
|
|
2667
|
-
const tex = getTextureValue(entry);
|
|
2668
|
-
tex?.dispose();
|
|
2669
|
-
}
|
|
2670
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
2671
|
-
};
|
|
2253
|
+
const setState = store.setState;
|
|
2254
|
+
const getOne = (key) => getState().textures.get(key);
|
|
2672
2255
|
return {
|
|
2673
|
-
|
|
2674
|
-
get textures() {
|
|
2256
|
+
get all() {
|
|
2675
2257
|
return getState().textures;
|
|
2676
2258
|
},
|
|
2677
|
-
|
|
2678
|
-
|
|
2259
|
+
get(input) {
|
|
2260
|
+
if (typeof input === "string") return getOne(input);
|
|
2261
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
2262
|
+
const out = {};
|
|
2263
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
2264
|
+
return out;
|
|
2265
|
+
},
|
|
2679
2266
|
has: (key) => getState().textures.has(key),
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2267
|
+
add(keyOrRecord, texture) {
|
|
2268
|
+
setState((state) => {
|
|
2269
|
+
const textures = new Map(state.textures);
|
|
2270
|
+
if (typeof keyOrRecord === "string") {
|
|
2271
|
+
textures.set(keyOrRecord, texture);
|
|
2272
|
+
} else {
|
|
2273
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2274
|
+
}
|
|
2275
|
+
return { textures };
|
|
2276
|
+
});
|
|
2277
|
+
},
|
|
2278
|
+
dispose(key, options) {
|
|
2279
|
+
const state = getState();
|
|
2280
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
2281
|
+
if (refs > 0 && !options?.force) {
|
|
2282
|
+
console.warn(
|
|
2283
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2284
|
+
);
|
|
2285
|
+
return false;
|
|
2286
|
+
}
|
|
2287
|
+
state.textures.get(key)?.dispose();
|
|
2288
|
+
setState((s) => {
|
|
2289
|
+
const textures = new Map(s.textures);
|
|
2290
|
+
textures.delete(key);
|
|
2291
|
+
const nextRefs = new Map(s._textureRefs);
|
|
2292
|
+
nextRefs.delete(key);
|
|
2293
|
+
return { textures, _textureRefs: nextRefs };
|
|
2294
|
+
});
|
|
2295
|
+
return true;
|
|
2296
|
+
},
|
|
2297
|
+
disposeAll() {
|
|
2298
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
2299
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2300
|
+
}
|
|
2690
2301
|
};
|
|
2691
2302
|
}, [store]);
|
|
2303
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2304
|
+
const selected = useThree(subscribe);
|
|
2305
|
+
return selector ? selected : registry;
|
|
2692
2306
|
}
|
|
2693
2307
|
|
|
2694
|
-
function useRenderTarget(
|
|
2308
|
+
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2695
2309
|
const isLegacy = useThree((s) => s.isLegacy);
|
|
2696
2310
|
const size = useThree((s) => s.size);
|
|
2311
|
+
let width;
|
|
2312
|
+
let height;
|
|
2313
|
+
let opts;
|
|
2314
|
+
if (typeof widthOrOptions === "object") {
|
|
2315
|
+
opts = widthOrOptions;
|
|
2316
|
+
} else if (typeof widthOrOptions === "number") {
|
|
2317
|
+
width = widthOrOptions;
|
|
2318
|
+
if (typeof heightOrOptions === "object") {
|
|
2319
|
+
height = widthOrOptions;
|
|
2320
|
+
opts = heightOrOptions;
|
|
2321
|
+
} else if (typeof heightOrOptions === "number") {
|
|
2322
|
+
height = heightOrOptions;
|
|
2323
|
+
opts = options;
|
|
2324
|
+
} else {
|
|
2325
|
+
height = widthOrOptions;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2697
2328
|
return useMemo(() => {
|
|
2698
2329
|
const w = width ?? size.width;
|
|
2699
2330
|
const h = height ?? size.height;
|
|
2700
|
-
return new WebGLRenderTarget(w, h,
|
|
2701
|
-
}, [width, height, size.width, size.height,
|
|
2331
|
+
return new WebGLRenderTarget(w, h, opts);
|
|
2332
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2702
2333
|
}
|
|
2703
2334
|
|
|
2704
2335
|
function useStore() {
|
|
@@ -2748,28 +2379,18 @@ function addTail(callback) {
|
|
|
2748
2379
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
2749
2380
|
getScheduler().invalidate(frames, stackFrames);
|
|
2750
2381
|
}
|
|
2751
|
-
function advance(timestamp
|
|
2382
|
+
function advance(timestamp) {
|
|
2752
2383
|
getScheduler().step(timestamp);
|
|
2753
2384
|
}
|
|
2754
2385
|
|
|
2755
|
-
const version = "10.0.0-alpha.
|
|
2386
|
+
const version = "10.0.0-alpha.2";
|
|
2756
2387
|
const packageData = {
|
|
2757
2388
|
version: version};
|
|
2758
2389
|
|
|
2759
2390
|
function Xb(Tt) {
|
|
2760
2391
|
return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
|
|
2761
2392
|
}
|
|
2762
|
-
var Rm = { exports: {} }, Og = { exports: {} };
|
|
2763
|
-
/**
|
|
2764
|
-
* @license React
|
|
2765
|
-
* react-reconciler.production.js
|
|
2766
|
-
*
|
|
2767
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2768
|
-
*
|
|
2769
|
-
* This source code is licensed under the MIT license found in the
|
|
2770
|
-
* LICENSE file in the root directory of this source tree.
|
|
2771
|
-
*/
|
|
2772
|
-
var _b;
|
|
2393
|
+
var Rm = { exports: {} }, Og = { exports: {} }, _b;
|
|
2773
2394
|
function Kb() {
|
|
2774
2395
|
return _b || (_b = 1, (function(Tt) {
|
|
2775
2396
|
Tt.exports = function(m) {
|
|
@@ -3841,7 +3462,6 @@ Error generating stack: ` + l.message + `
|
|
|
3841
3462
|
if (J === cl || J === jc) throw J;
|
|
3842
3463
|
var Ge = Yn(29, J, null, P.mode);
|
|
3843
3464
|
return Ge.lanes = H, Ge.return = P, Ge;
|
|
3844
|
-
} finally {
|
|
3845
3465
|
}
|
|
3846
3466
|
};
|
|
3847
3467
|
}
|
|
@@ -4495,7 +4115,6 @@ Error generating stack: ` + l.message + `
|
|
|
4495
4115
|
var h = r.lastRenderedState, y = d(h, a);
|
|
4496
4116
|
if (c.hasEagerState = true, c.eagerState = y, jn(y, h)) return go(t, r, c, 0), Ne === null && Bn(), false;
|
|
4497
4117
|
} catch {
|
|
4498
|
-
} finally {
|
|
4499
4118
|
}
|
|
4500
4119
|
if (a = yo(t, r, c, l), a !== null) return nt(a, t, l), ns(a, r, l), true;
|
|
4501
4120
|
}
|
|
@@ -6916,10 +6535,7 @@ Error generating stack: ` + l.message + `
|
|
|
6916
6535
|
function vr(t, r) {
|
|
6917
6536
|
Sf(t, r), (t = t.alternate) && Sf(t, r);
|
|
6918
6537
|
}
|
|
6919
|
-
var ie = {}, Fm = React__default, tt = Tb, 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");
|
|
6920
|
-
var gc = Symbol.for("react.activity");
|
|
6921
|
-
var $r = Symbol.for("react.memo_cache_sentinel");
|
|
6922
|
-
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;
|
|
6538
|
+
var ie = {}, Fm = React__default, tt = Tb, 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;
|
|
6923
6539
|
m.cloneMutableInstance;
|
|
6924
6540
|
var yc = m.appendInitialChild, Kp = m.finalizeInitialChildren, Rs = m.shouldSetTextContent, bc = m.createTextInstance;
|
|
6925
6541
|
m.cloneMutableTextInstance;
|
|
@@ -7288,17 +6904,7 @@ No matching component was found for:
|
|
|
7288
6904
|
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true });
|
|
7289
6905
|
})(Og)), Og.exports;
|
|
7290
6906
|
}
|
|
7291
|
-
var Mg = { exports: {} };
|
|
7292
|
-
/**
|
|
7293
|
-
* @license React
|
|
7294
|
-
* react-reconciler.development.js
|
|
7295
|
-
*
|
|
7296
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7297
|
-
*
|
|
7298
|
-
* This source code is licensed under the MIT license found in the
|
|
7299
|
-
* LICENSE file in the root directory of this source tree.
|
|
7300
|
-
*/
|
|
7301
|
-
var Rb;
|
|
6907
|
+
var Mg = { exports: {} }, Rb;
|
|
7302
6908
|
function e0() {
|
|
7303
6909
|
return Rb || (Rb = 1, (function(Tt) {
|
|
7304
6910
|
process.env.NODE_ENV !== "production" && (Tt.exports = function(m) {
|
|
@@ -13065,10 +12671,7 @@ Check the render method of %s.`, G(di) || "Unknown")), i = zo(n), i.payload = {
|
|
|
13065
12671
|
function Ic() {
|
|
13066
12672
|
return di;
|
|
13067
12673
|
}
|
|
13068
|
-
var le = {}, qm = React__default, St = Tb, 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");
|
|
13069
|
-
var Ds = Symbol.for("react.activity");
|
|
13070
|
-
var Bh = Symbol.for("react.memo_cache_sentinel");
|
|
13071
|
-
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;
|
|
12674
|
+
var le = {}, qm = React__default, St = Tb, 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;
|
|
13072
12675
|
m.cloneMutableInstance;
|
|
13073
12676
|
var bn = m.appendInitialChild, Ue = m.finalizeInitialChildren, ue = m.shouldSetTextContent, Do = m.createTextInstance;
|
|
13074
12677
|
m.cloneMutableTextInstance;
|
|
@@ -14036,15 +13639,6 @@ function n0() {
|
|
|
14036
13639
|
var t0 = n0();
|
|
14037
13640
|
const r0 = Xb(t0);
|
|
14038
13641
|
|
|
14039
|
-
/**
|
|
14040
|
-
* @license React
|
|
14041
|
-
* react-reconciler-constants.production.js
|
|
14042
|
-
*
|
|
14043
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14044
|
-
*
|
|
14045
|
-
* This source code is licensed under the MIT license found in the
|
|
14046
|
-
* LICENSE file in the root directory of this source tree.
|
|
14047
|
-
*/
|
|
14048
13642
|
const t = 1, o = 8, r = 32, e = 2;
|
|
14049
13643
|
|
|
14050
13644
|
function createReconciler(config) {
|
|
@@ -14071,10 +13665,11 @@ function extend(objects) {
|
|
|
14071
13665
|
function validateInstance(type, props) {
|
|
14072
13666
|
const name = toPascalCase(type);
|
|
14073
13667
|
const target = catalogue[name];
|
|
14074
|
-
if (type !== "primitive" && !target)
|
|
13668
|
+
if (type !== "primitive" && !target) {
|
|
14075
13669
|
throw new Error(
|
|
14076
13670
|
`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`
|
|
14077
13671
|
);
|
|
13672
|
+
}
|
|
14078
13673
|
if (type === "primitive" && !props.object) throw new Error(`R3F: Primitives without 'object' are invalid!`);
|
|
14079
13674
|
if (props.args !== void 0 && !Array.isArray(props.args)) throw new Error("R3F: The args prop must be an array!");
|
|
14080
13675
|
}
|
|
@@ -14238,6 +13833,7 @@ function swapInstances() {
|
|
|
14238
13833
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
14239
13834
|
instance.object.__r3f = instance;
|
|
14240
13835
|
setFiberRef(fiber, instance.object);
|
|
13836
|
+
delete instance.appliedOnce;
|
|
14241
13837
|
applyProps(instance.object, instance.props);
|
|
14242
13838
|
if (instance.props.attach) {
|
|
14243
13839
|
attach(parent, instance);
|
|
@@ -14311,8 +13907,22 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14311
13907
|
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
14312
13908
|
if (isTailSibling) swapInstances();
|
|
14313
13909
|
},
|
|
14314
|
-
finalizeInitialChildren: () =>
|
|
14315
|
-
|
|
13910
|
+
finalizeInitialChildren: (instance) => {
|
|
13911
|
+
for (const prop in instance.props) {
|
|
13912
|
+
if (isFromRef(instance.props[prop])) return true;
|
|
13913
|
+
}
|
|
13914
|
+
return false;
|
|
13915
|
+
},
|
|
13916
|
+
commitMount(instance) {
|
|
13917
|
+
const resolved = {};
|
|
13918
|
+
for (const prop in instance.props) {
|
|
13919
|
+
const value = instance.props[prop];
|
|
13920
|
+
if (isFromRef(value)) {
|
|
13921
|
+
const ref = value[FROM_REF];
|
|
13922
|
+
if (ref.current != null) resolved[prop] = ref.current;
|
|
13923
|
+
}
|
|
13924
|
+
}
|
|
13925
|
+
if (Object.keys(resolved).length) applyProps(instance.object, resolved);
|
|
14316
13926
|
},
|
|
14317
13927
|
getPublicInstance: (instance) => instance?.object,
|
|
14318
13928
|
prepareForCommit: () => null,
|
|
@@ -14525,14 +14135,17 @@ function createRoot(canvas) {
|
|
|
14525
14135
|
if (!prevRoot) _roots.set(canvas, { fiber, store });
|
|
14526
14136
|
let onCreated;
|
|
14527
14137
|
let lastCamera;
|
|
14528
|
-
|
|
14138
|
+
const lastConfiguredProps = {};
|
|
14529
14139
|
let configured = false;
|
|
14530
14140
|
let pending = null;
|
|
14531
14141
|
return {
|
|
14532
14142
|
async configure(props = {}) {
|
|
14533
14143
|
let resolve;
|
|
14534
14144
|
pending = new Promise((_resolve) => resolve = _resolve);
|
|
14535
|
-
|
|
14145
|
+
const {
|
|
14146
|
+
id: canvasId,
|
|
14147
|
+
primaryCanvas,
|
|
14148
|
+
scheduler: schedulerConfig,
|
|
14536
14149
|
gl: glConfig,
|
|
14537
14150
|
renderer: rendererConfig,
|
|
14538
14151
|
size: propsSize,
|
|
@@ -14540,10 +14153,6 @@ function createRoot(canvas) {
|
|
|
14540
14153
|
events,
|
|
14541
14154
|
onCreated: onCreatedCallback,
|
|
14542
14155
|
shadows = false,
|
|
14543
|
-
linear = false,
|
|
14544
|
-
flat = false,
|
|
14545
|
-
textureColorSpace = SRGBColorSpace,
|
|
14546
|
-
legacy = false,
|
|
14547
14156
|
orthographic = false,
|
|
14548
14157
|
frameloop = "always",
|
|
14549
14158
|
dpr = [1, 2],
|
|
@@ -14554,9 +14163,12 @@ function createRoot(canvas) {
|
|
|
14554
14163
|
onDragOverMissed,
|
|
14555
14164
|
onDropMissed,
|
|
14556
14165
|
autoUpdateFrustum = true,
|
|
14557
|
-
occlusion = false
|
|
14166
|
+
occlusion = false,
|
|
14167
|
+
_sizeProps,
|
|
14168
|
+
forceEven
|
|
14558
14169
|
} = props;
|
|
14559
|
-
|
|
14170
|
+
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
14171
|
+
const state = store.getState();
|
|
14560
14172
|
const defaultGLProps = {
|
|
14561
14173
|
canvas,
|
|
14562
14174
|
powerPreference: "high-performance",
|
|
@@ -14568,22 +14180,34 @@ function createRoot(canvas) {
|
|
|
14568
14180
|
"WebGPURenderer (renderer prop) is not available in this build. Use @react-three/fiber or @react-three/fiber/webgpu instead."
|
|
14569
14181
|
);
|
|
14570
14182
|
}
|
|
14571
|
-
(state.isLegacy || glConfig || !R3F_BUILD_WEBGPU);
|
|
14183
|
+
const wantsGL = (state.isLegacy || glConfig || !R3F_BUILD_WEBGPU);
|
|
14572
14184
|
if (glConfig && rendererConfig) {
|
|
14573
14185
|
throw new Error("Cannot use both gl and renderer props at the same time");
|
|
14574
14186
|
}
|
|
14575
14187
|
let renderer = state.internal.actualRenderer;
|
|
14188
|
+
if (primaryCanvas && !R3F_BUILD_WEBGPU) {
|
|
14189
|
+
throw new Error(
|
|
14190
|
+
"The `primaryCanvas` prop for multi-canvas rendering is only available with WebGPU. Use @react-three/fiber/webgpu instead."
|
|
14191
|
+
);
|
|
14192
|
+
}
|
|
14193
|
+
if (primaryCanvas && wantsGL) {
|
|
14194
|
+
throw new Error(
|
|
14195
|
+
"The `primaryCanvas` prop for multi-canvas rendering cannot be used with WebGL. Remove the `gl` prop or use WebGPU."
|
|
14196
|
+
);
|
|
14197
|
+
}
|
|
14576
14198
|
if (!state.internal.actualRenderer) {
|
|
14577
14199
|
renderer = await resolveRenderer(glConfig, defaultGLProps, WebGLRenderer);
|
|
14578
14200
|
state.internal.actualRenderer = renderer;
|
|
14579
|
-
state.set({ isLegacy: true, gl: renderer, renderer });
|
|
14201
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14580
14202
|
}
|
|
14581
14203
|
let raycaster = state.raycaster;
|
|
14582
14204
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
14583
14205
|
const { params, ...options } = raycastOptions || {};
|
|
14584
14206
|
if (!is.equ(options, raycaster, shallowLoose)) applyProps(raycaster, { ...options });
|
|
14585
|
-
if (!is.equ(params, raycaster.params, shallowLoose))
|
|
14207
|
+
if (!is.equ(params, raycaster.params, shallowLoose)) {
|
|
14586
14208
|
applyProps(raycaster, { params: { ...raycaster.params, ...params } });
|
|
14209
|
+
}
|
|
14210
|
+
let tempCamera = state.camera;
|
|
14587
14211
|
if (!state.camera || state.camera === lastCamera && !is.equ(lastCamera, cameraOptions, shallowLoose)) {
|
|
14588
14212
|
lastCamera = cameraOptions;
|
|
14589
14213
|
const isCamera = cameraOptions?.isCamera;
|
|
@@ -14603,6 +14227,7 @@ function createRoot(canvas) {
|
|
|
14603
14227
|
if (!state.camera && !cameraOptions?.rotation) camera.lookAt(0, 0, 0);
|
|
14604
14228
|
}
|
|
14605
14229
|
state.set({ camera });
|
|
14230
|
+
tempCamera = camera;
|
|
14606
14231
|
raycaster.camera = camera;
|
|
14607
14232
|
}
|
|
14608
14233
|
if (!state.scene) {
|
|
@@ -14620,7 +14245,7 @@ function createRoot(canvas) {
|
|
|
14620
14245
|
rootScene: scene,
|
|
14621
14246
|
internal: { ...prev.internal, container: scene }
|
|
14622
14247
|
}));
|
|
14623
|
-
const camera =
|
|
14248
|
+
const camera = tempCamera;
|
|
14624
14249
|
if (camera && !camera.parent) scene.add(camera);
|
|
14625
14250
|
}
|
|
14626
14251
|
if (events && !state.events.handlers) {
|
|
@@ -14634,9 +14259,17 @@ function createRoot(canvas) {
|
|
|
14634
14259
|
wasEnabled = enabled;
|
|
14635
14260
|
});
|
|
14636
14261
|
}
|
|
14262
|
+
if (_sizeProps !== void 0) {
|
|
14263
|
+
state.set({ _sizeProps });
|
|
14264
|
+
}
|
|
14265
|
+
if (forceEven !== void 0 && state.internal.forceEven !== forceEven) {
|
|
14266
|
+
state.set((prev) => ({ internal: { ...prev.internal, forceEven } }));
|
|
14267
|
+
}
|
|
14637
14268
|
const size = computeInitialSize(canvas, propsSize);
|
|
14638
|
-
if (!is.equ(size, state.size, shallowLoose)) {
|
|
14269
|
+
if (!state._sizeImperative && !is.equ(size, state.size, shallowLoose)) {
|
|
14270
|
+
const wasImperative = state._sizeImperative;
|
|
14639
14271
|
state.setSize(size.width, size.height, size.top, size.left);
|
|
14272
|
+
if (!wasImperative) state.set({ _sizeImperative: false });
|
|
14640
14273
|
}
|
|
14641
14274
|
if (dpr !== void 0 && !is.equ(dpr, lastConfiguredProps.dpr, shallowLoose)) {
|
|
14642
14275
|
state.setDpr(dpr);
|
|
@@ -14658,10 +14291,10 @@ function createRoot(canvas) {
|
|
|
14658
14291
|
lastConfiguredProps.performance = performance;
|
|
14659
14292
|
}
|
|
14660
14293
|
if (!state.xr) {
|
|
14661
|
-
const handleXRFrame = (timestamp,
|
|
14294
|
+
const handleXRFrame = (timestamp, _frame) => {
|
|
14662
14295
|
const state2 = store.getState();
|
|
14663
14296
|
if (state2.frameloop === "never") return;
|
|
14664
|
-
advance(timestamp
|
|
14297
|
+
advance(timestamp);
|
|
14665
14298
|
};
|
|
14666
14299
|
const actualRenderer = state.internal.actualRenderer;
|
|
14667
14300
|
const handleSessionChange = () => {
|
|
@@ -14673,16 +14306,16 @@ function createRoot(canvas) {
|
|
|
14673
14306
|
};
|
|
14674
14307
|
const xr = {
|
|
14675
14308
|
connect() {
|
|
14676
|
-
const { gl, renderer: renderer2
|
|
14677
|
-
const
|
|
14678
|
-
|
|
14679
|
-
|
|
14309
|
+
const { gl, renderer: renderer2 } = store.getState();
|
|
14310
|
+
const xrManager = (renderer2 || gl).xr;
|
|
14311
|
+
xrManager.addEventListener("sessionstart", handleSessionChange);
|
|
14312
|
+
xrManager.addEventListener("sessionend", handleSessionChange);
|
|
14680
14313
|
},
|
|
14681
14314
|
disconnect() {
|
|
14682
|
-
const { gl, renderer: renderer2
|
|
14683
|
-
const
|
|
14684
|
-
|
|
14685
|
-
|
|
14315
|
+
const { gl, renderer: renderer2 } = store.getState();
|
|
14316
|
+
const xrManager = (renderer2 || gl).xr;
|
|
14317
|
+
xrManager.removeEventListener("sessionstart", handleSessionChange);
|
|
14318
|
+
xrManager.removeEventListener("sessionend", handleSessionChange);
|
|
14686
14319
|
}
|
|
14687
14320
|
};
|
|
14688
14321
|
if (typeof renderer.xr?.addEventListener === "function") xr.connect();
|
|
@@ -14694,61 +14327,92 @@ function createRoot(canvas) {
|
|
|
14694
14327
|
const oldType = renderer.shadowMap.type;
|
|
14695
14328
|
renderer.shadowMap.enabled = !!shadows;
|
|
14696
14329
|
if (is.boo(shadows)) {
|
|
14697
|
-
renderer.shadowMap.type =
|
|
14330
|
+
renderer.shadowMap.type = PCFShadowMap;
|
|
14698
14331
|
} else if (is.str(shadows)) {
|
|
14332
|
+
if (shadows === "soft") {
|
|
14333
|
+
notifyDepreciated({
|
|
14334
|
+
heading: 'shadows="soft" is deprecated',
|
|
14335
|
+
body: "Three has depreciated soft and improved basic PCFShadows, we converted for you.",
|
|
14336
|
+
link: "https://github.com/mrdoob/three.js/wiki/Migration-Guide?utm_source=chatgpt.com#181--182"
|
|
14337
|
+
});
|
|
14338
|
+
}
|
|
14699
14339
|
const types = {
|
|
14700
14340
|
basic: BasicShadowMap,
|
|
14701
14341
|
percentage: PCFShadowMap,
|
|
14702
|
-
soft:
|
|
14342
|
+
soft: PCFShadowMap,
|
|
14703
14343
|
variance: VSMShadowMap
|
|
14704
14344
|
};
|
|
14705
|
-
renderer.shadowMap.type = types[shadows] ??
|
|
14345
|
+
renderer.shadowMap.type = types[shadows] ?? PCFShadowMap;
|
|
14706
14346
|
} else if (is.obj(shadows)) {
|
|
14707
14347
|
Object.assign(renderer.shadowMap, shadows);
|
|
14708
14348
|
}
|
|
14709
|
-
if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type)
|
|
14349
|
+
if (oldEnabled !== renderer.shadowMap.enabled || oldType !== renderer.shadowMap.type) {
|
|
14710
14350
|
renderer.shadowMap.needsUpdate = true;
|
|
14711
|
-
}
|
|
14712
|
-
{
|
|
14713
|
-
const legacyChanged = legacy !== lastConfiguredProps.legacy;
|
|
14714
|
-
const linearChanged = linear !== lastConfiguredProps.linear;
|
|
14715
|
-
const flatChanged = flat !== lastConfiguredProps.flat;
|
|
14716
|
-
if (legacyChanged) {
|
|
14717
|
-
ColorManagement.enabled = !legacy;
|
|
14718
|
-
lastConfiguredProps.legacy = legacy;
|
|
14719
|
-
}
|
|
14720
|
-
if (!configured || linearChanged) {
|
|
14721
|
-
renderer.outputColorSpace = linear ? LinearSRGBColorSpace : SRGBColorSpace;
|
|
14722
|
-
lastConfiguredProps.linear = linear;
|
|
14723
|
-
}
|
|
14724
|
-
if (!configured || flatChanged) {
|
|
14725
|
-
renderer.toneMapping = flat ? NoToneMapping : ACESFilmicToneMapping;
|
|
14726
|
-
lastConfiguredProps.flat = flat;
|
|
14727
14351
|
}
|
|
14728
|
-
|
|
14729
|
-
|
|
14730
|
-
|
|
14352
|
+
}
|
|
14353
|
+
if (!configured) {
|
|
14354
|
+
renderer.outputColorSpace = SRGBColorSpace;
|
|
14355
|
+
renderer.toneMapping = ACESFilmicToneMapping;
|
|
14731
14356
|
}
|
|
14732
14357
|
if (textureColorSpace !== lastConfiguredProps.textureColorSpace) {
|
|
14733
14358
|
if (state.textureColorSpace !== textureColorSpace) state.set(() => ({ textureColorSpace }));
|
|
14734
14359
|
lastConfiguredProps.textureColorSpace = textureColorSpace;
|
|
14735
14360
|
}
|
|
14736
|
-
|
|
14737
|
-
|
|
14361
|
+
const r3fProps = ["textureColorSpace"];
|
|
14362
|
+
const constructorOnlyProps = ["samples", "antialias", "alpha", "canvas", "powerPreference"];
|
|
14363
|
+
const nonApplyProps = [...r3fProps, ...constructorOnlyProps];
|
|
14364
|
+
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, renderer, shallowLoose)) {
|
|
14365
|
+
const glProps = {};
|
|
14366
|
+
for (const key in glConfig) {
|
|
14367
|
+
if (!nonApplyProps.includes(key)) glProps[key] = glConfig[key];
|
|
14368
|
+
}
|
|
14369
|
+
applyProps(renderer, glProps);
|
|
14370
|
+
}
|
|
14738
14371
|
if (rendererConfig && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && state.renderer) {
|
|
14739
14372
|
const currentRenderer = state.renderer;
|
|
14740
14373
|
if (!is.equ(rendererConfig, currentRenderer, shallowLoose)) {
|
|
14741
|
-
|
|
14374
|
+
const rendererProps = {};
|
|
14375
|
+
for (const key in rendererConfig) {
|
|
14376
|
+
if (!nonApplyProps.includes(key)) rendererProps[key] = rendererConfig[key];
|
|
14377
|
+
}
|
|
14378
|
+
applyProps(currentRenderer, rendererProps);
|
|
14742
14379
|
}
|
|
14743
14380
|
}
|
|
14744
14381
|
const scheduler = getScheduler();
|
|
14745
14382
|
const rootId = state.internal.rootId;
|
|
14746
14383
|
if (!rootId) {
|
|
14747
|
-
const newRootId = scheduler.generateRootId();
|
|
14384
|
+
const newRootId = canvasId || scheduler.generateRootId();
|
|
14748
14385
|
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14749
14386
|
getState: () => store.getState(),
|
|
14750
14387
|
onError: (err) => store.getState().setError(err)
|
|
14751
14388
|
});
|
|
14389
|
+
const unregisterCanvasTarget = scheduler.register(
|
|
14390
|
+
() => {
|
|
14391
|
+
const state2 = store.getState();
|
|
14392
|
+
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
14393
|
+
const renderer2 = state2.internal.actualRenderer;
|
|
14394
|
+
renderer2.setCanvasTarget(state2.internal.canvasTarget);
|
|
14395
|
+
}
|
|
14396
|
+
},
|
|
14397
|
+
{
|
|
14398
|
+
id: `${newRootId}_canvasTarget`,
|
|
14399
|
+
rootId: newRootId,
|
|
14400
|
+
phase: "start",
|
|
14401
|
+
system: true
|
|
14402
|
+
}
|
|
14403
|
+
);
|
|
14404
|
+
const unregisterEventsFlush = scheduler.register(
|
|
14405
|
+
() => {
|
|
14406
|
+
const state2 = store.getState();
|
|
14407
|
+
state2.events.flush?.();
|
|
14408
|
+
},
|
|
14409
|
+
{
|
|
14410
|
+
id: `${newRootId}_events`,
|
|
14411
|
+
rootId: newRootId,
|
|
14412
|
+
phase: "input",
|
|
14413
|
+
system: true
|
|
14414
|
+
}
|
|
14415
|
+
);
|
|
14752
14416
|
const unregisterFrustum = scheduler.register(
|
|
14753
14417
|
() => {
|
|
14754
14418
|
const state2 = store.getState();
|
|
@@ -14759,7 +14423,7 @@ function createRoot(canvas) {
|
|
|
14759
14423
|
{
|
|
14760
14424
|
id: `${newRootId}_frustum`,
|
|
14761
14425
|
rootId: newRootId,
|
|
14762
|
-
|
|
14426
|
+
before: "render",
|
|
14763
14427
|
system: true
|
|
14764
14428
|
}
|
|
14765
14429
|
);
|
|
@@ -14771,7 +14435,7 @@ function createRoot(canvas) {
|
|
|
14771
14435
|
{
|
|
14772
14436
|
id: `${newRootId}_visibility`,
|
|
14773
14437
|
rootId: newRootId,
|
|
14774
|
-
|
|
14438
|
+
before: "render",
|
|
14775
14439
|
system: true,
|
|
14776
14440
|
after: `${newRootId}_frustum`
|
|
14777
14441
|
}
|
|
@@ -14783,18 +14447,22 @@ function createRoot(canvas) {
|
|
|
14783
14447
|
const userHandlesRender = scheduler.hasUserJobsInPhase("render", newRootId);
|
|
14784
14448
|
if (userHandlesRender || state2.internal.priority) return;
|
|
14785
14449
|
try {
|
|
14786
|
-
if (state2.
|
|
14450
|
+
if (state2.renderPipeline?.render) state2.renderPipeline.render();
|
|
14787
14451
|
else if (renderer2?.render) renderer2.render(state2.scene, state2.camera);
|
|
14788
14452
|
} catch (error) {
|
|
14789
14453
|
state2.setError(error instanceof Error ? error : new Error(String(error)));
|
|
14790
14454
|
}
|
|
14791
14455
|
},
|
|
14792
14456
|
{
|
|
14793
|
-
|
|
14457
|
+
// Use canvas ID directly as job ID if available, otherwise use generated rootId
|
|
14458
|
+
id: canvasId || `${newRootId}_render`,
|
|
14794
14459
|
rootId: newRootId,
|
|
14795
14460
|
phase: "render",
|
|
14796
|
-
system: true
|
|
14461
|
+
system: true,
|
|
14797
14462
|
// Internal flag: this is a system job, not user-controlled
|
|
14463
|
+
// Apply scheduler config for render ordering and rate limiting
|
|
14464
|
+
...schedulerConfig?.after && { after: schedulerConfig.after },
|
|
14465
|
+
...schedulerConfig?.fps && { fps: schedulerConfig.fps }
|
|
14798
14466
|
}
|
|
14799
14467
|
);
|
|
14800
14468
|
state.set((state2) => ({
|
|
@@ -14803,6 +14471,8 @@ function createRoot(canvas) {
|
|
|
14803
14471
|
rootId: newRootId,
|
|
14804
14472
|
unregisterRoot: () => {
|
|
14805
14473
|
unregisterRoot();
|
|
14474
|
+
unregisterCanvasTarget();
|
|
14475
|
+
unregisterEventsFlush();
|
|
14806
14476
|
unregisterFrustum();
|
|
14807
14477
|
unregisterVisibility();
|
|
14808
14478
|
unregisterRender();
|
|
@@ -14861,15 +14531,24 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14861
14531
|
const renderer = state.internal.actualRenderer;
|
|
14862
14532
|
const unregisterRoot = state.internal.unregisterRoot;
|
|
14863
14533
|
if (unregisterRoot) unregisterRoot();
|
|
14534
|
+
const unregisterPrimary = state.internal.unregisterPrimary;
|
|
14535
|
+
if (unregisterPrimary) unregisterPrimary();
|
|
14536
|
+
const canvasTarget = state.internal.canvasTarget;
|
|
14537
|
+
if (canvasTarget?.dispose) canvasTarget.dispose();
|
|
14864
14538
|
state.events.disconnect?.();
|
|
14865
14539
|
cleanupHelperGroup(root.store);
|
|
14866
|
-
renderer
|
|
14867
|
-
|
|
14868
|
-
|
|
14540
|
+
if (state.isLegacy && renderer) {
|
|
14541
|
+
;
|
|
14542
|
+
renderer.renderLists?.dispose?.();
|
|
14543
|
+
renderer.forceContextLoss?.();
|
|
14544
|
+
}
|
|
14545
|
+
if (!state.internal.isSecondary) {
|
|
14546
|
+
if (renderer?.xr) state.xr.disconnect();
|
|
14547
|
+
}
|
|
14869
14548
|
dispose(state.scene);
|
|
14870
14549
|
_roots.delete(canvas);
|
|
14871
14550
|
if (callback) callback(canvas);
|
|
14872
|
-
} catch
|
|
14551
|
+
} catch {
|
|
14873
14552
|
}
|
|
14874
14553
|
}, 500);
|
|
14875
14554
|
}
|
|
@@ -14877,36 +14556,34 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14877
14556
|
}
|
|
14878
14557
|
}
|
|
14879
14558
|
function createPortal(children, container, state) {
|
|
14880
|
-
return /* @__PURE__ */ jsx(
|
|
14559
|
+
return /* @__PURE__ */ jsx(Portal, { children, container, state });
|
|
14881
14560
|
}
|
|
14882
|
-
function
|
|
14561
|
+
function Portal({ children, container, state }) {
|
|
14883
14562
|
const isRef = useCallback((obj) => obj && "current" in obj, []);
|
|
14884
|
-
const [resolvedContainer,
|
|
14563
|
+
const [resolvedContainer, _setResolvedContainer] = useState(() => {
|
|
14885
14564
|
if (isRef(container)) return container.current ?? null;
|
|
14886
14565
|
return container;
|
|
14887
14566
|
});
|
|
14567
|
+
const setResolvedContainer = useCallback(
|
|
14568
|
+
(newContainer) => {
|
|
14569
|
+
if (!newContainer || newContainer === resolvedContainer) return;
|
|
14570
|
+
_setResolvedContainer(isRef(newContainer) ? newContainer.current : newContainer);
|
|
14571
|
+
},
|
|
14572
|
+
[resolvedContainer, _setResolvedContainer, isRef]
|
|
14573
|
+
);
|
|
14888
14574
|
useMemo(() => {
|
|
14889
|
-
if (isRef(container)) {
|
|
14890
|
-
|
|
14891
|
-
|
|
14892
|
-
|
|
14893
|
-
const updated = container.current;
|
|
14894
|
-
if (updated && updated !== resolvedContainer) {
|
|
14895
|
-
setResolvedContainer(updated);
|
|
14896
|
-
}
|
|
14897
|
-
});
|
|
14898
|
-
} else if (current !== resolvedContainer) {
|
|
14899
|
-
setResolvedContainer(current);
|
|
14900
|
-
}
|
|
14901
|
-
} else if (container !== resolvedContainer) {
|
|
14902
|
-
setResolvedContainer(container);
|
|
14575
|
+
if (isRef(container) && !container.current) {
|
|
14576
|
+
return queueMicrotask(() => {
|
|
14577
|
+
setResolvedContainer(container.current);
|
|
14578
|
+
});
|
|
14903
14579
|
}
|
|
14904
|
-
|
|
14580
|
+
setResolvedContainer(container);
|
|
14581
|
+
}, [container, isRef, setResolvedContainer]);
|
|
14905
14582
|
if (!resolvedContainer) return /* @__PURE__ */ jsx(Fragment, {});
|
|
14906
14583
|
const portalKey = resolvedContainer.uuid ?? `portal-${resolvedContainer.id ?? "unknown"}`;
|
|
14907
|
-
return /* @__PURE__ */ jsx(
|
|
14584
|
+
return /* @__PURE__ */ jsx(PortalInner, { children, container: resolvedContainer, state }, portalKey);
|
|
14908
14585
|
}
|
|
14909
|
-
function
|
|
14586
|
+
function PortalInner({ state = {}, children, container }) {
|
|
14910
14587
|
const { events, size, injectScene = true, ...rest } = state;
|
|
14911
14588
|
const previousRoot = useStore();
|
|
14912
14589
|
const [raycaster] = useState(() => new Raycaster());
|
|
@@ -14927,11 +14604,12 @@ function Portal({ state = {}, children, container }) {
|
|
|
14927
14604
|
};
|
|
14928
14605
|
}, [portalScene, container, injectScene]);
|
|
14929
14606
|
const inject = useMutableCallback((rootState, injectState) => {
|
|
14607
|
+
const resolvedSize = { ...rootState.size, ...injectState.size, ...size };
|
|
14930
14608
|
let viewport = void 0;
|
|
14931
|
-
if (injectState.camera && size) {
|
|
14609
|
+
if (injectState.camera && (size || injectState.size)) {
|
|
14932
14610
|
const camera = injectState.camera;
|
|
14933
|
-
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(),
|
|
14934
|
-
if (camera !== rootState.camera) updateCamera(camera,
|
|
14611
|
+
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
14612
|
+
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14935
14613
|
}
|
|
14936
14614
|
return {
|
|
14937
14615
|
// The intersect consists of the previous root state
|
|
@@ -14948,7 +14626,7 @@ function Portal({ state = {}, children, container }) {
|
|
|
14948
14626
|
previousRoot,
|
|
14949
14627
|
// Events, size and viewport can be overridden by the inject layer
|
|
14950
14628
|
events: { ...rootState.events, ...injectState.events, ...events },
|
|
14951
|
-
size:
|
|
14629
|
+
size: resolvedSize,
|
|
14952
14630
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14953
14631
|
// Layers are allowed to override events
|
|
14954
14632
|
setEvents: (events2) => injectState.set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
@@ -14960,9 +14638,13 @@ function Portal({ state = {}, children, container }) {
|
|
|
14960
14638
|
const store = createWithEqualityFn((set, get) => ({ ...rest, set, get }));
|
|
14961
14639
|
const onMutate = (prev) => store.setState((state2) => inject.current(prev, state2));
|
|
14962
14640
|
onMutate(previousRoot.getState());
|
|
14963
|
-
previousRoot.subscribe(onMutate);
|
|
14964
14641
|
return store;
|
|
14965
14642
|
}, [previousRoot, container]);
|
|
14643
|
+
useIsomorphicLayoutEffect(() => {
|
|
14644
|
+
const onMutate = (prev) => usePortalStore.setState((state2) => inject.current(prev, state2));
|
|
14645
|
+
const unsubscribe = previousRoot.subscribe(onMutate);
|
|
14646
|
+
return unsubscribe;
|
|
14647
|
+
}, [previousRoot, usePortalStore]);
|
|
14966
14648
|
return (
|
|
14967
14649
|
// @ts-ignore, reconciler types are not maintained
|
|
14968
14650
|
/* @__PURE__ */ jsx(Fragment, { children: reconciler.createPortal(
|
|
@@ -14976,21 +14658,59 @@ function flushSync(fn) {
|
|
|
14976
14658
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14977
14659
|
}
|
|
14978
14660
|
|
|
14661
|
+
function parseBackground(background) {
|
|
14662
|
+
if (!background) return null;
|
|
14663
|
+
if (typeof background === "object" && !background.isColor) {
|
|
14664
|
+
const { backgroundMap, envMap, files, preset, ...rest } = background;
|
|
14665
|
+
return {
|
|
14666
|
+
...rest,
|
|
14667
|
+
preset,
|
|
14668
|
+
files: envMap || files,
|
|
14669
|
+
backgroundFiles: backgroundMap,
|
|
14670
|
+
background: true
|
|
14671
|
+
};
|
|
14672
|
+
}
|
|
14673
|
+
if (typeof background === "number") {
|
|
14674
|
+
return { color: background, background: true };
|
|
14675
|
+
}
|
|
14676
|
+
if (typeof background === "string") {
|
|
14677
|
+
if (background in presetsObj) {
|
|
14678
|
+
return { preset: background, background: true };
|
|
14679
|
+
}
|
|
14680
|
+
if (/^(https?:\/\/|\/|\.\/|\.\.\/)|\.(hdr|exr|jpg|jpeg|png|webp|gif)$/i.test(background)) {
|
|
14681
|
+
return { files: background, background: true };
|
|
14682
|
+
}
|
|
14683
|
+
return { color: background, background: true };
|
|
14684
|
+
}
|
|
14685
|
+
if (background.isColor) {
|
|
14686
|
+
return { color: background, background: true };
|
|
14687
|
+
}
|
|
14688
|
+
return null;
|
|
14689
|
+
}
|
|
14690
|
+
|
|
14691
|
+
function clearHmrCaches(store) {
|
|
14692
|
+
store.setState((state) => ({
|
|
14693
|
+
nodes: {},
|
|
14694
|
+
uniforms: {},
|
|
14695
|
+
buffers: {},
|
|
14696
|
+
gpuStorage: {},
|
|
14697
|
+
_hmrVersion: state._hmrVersion + 1
|
|
14698
|
+
}));
|
|
14699
|
+
}
|
|
14700
|
+
|
|
14979
14701
|
function CanvasImpl({
|
|
14980
14702
|
ref,
|
|
14981
14703
|
children,
|
|
14982
14704
|
fallback,
|
|
14983
14705
|
resize,
|
|
14984
14706
|
style,
|
|
14707
|
+
id,
|
|
14985
14708
|
gl,
|
|
14986
|
-
renderer,
|
|
14709
|
+
renderer: rendererProp,
|
|
14987
14710
|
events = createPointerEvents,
|
|
14988
14711
|
eventSource,
|
|
14989
14712
|
eventPrefix,
|
|
14990
14713
|
shadows,
|
|
14991
|
-
linear,
|
|
14992
|
-
flat,
|
|
14993
|
-
legacy,
|
|
14994
14714
|
orthographic,
|
|
14995
14715
|
frameloop,
|
|
14996
14716
|
dpr,
|
|
@@ -14998,14 +14718,34 @@ function CanvasImpl({
|
|
|
14998
14718
|
raycaster,
|
|
14999
14719
|
camera,
|
|
15000
14720
|
scene,
|
|
14721
|
+
autoUpdateFrustum,
|
|
14722
|
+
occlusion,
|
|
15001
14723
|
onPointerMissed,
|
|
15002
14724
|
onDragOverMissed,
|
|
15003
14725
|
onDropMissed,
|
|
15004
14726
|
onCreated,
|
|
14727
|
+
hmr,
|
|
14728
|
+
width,
|
|
14729
|
+
height,
|
|
14730
|
+
background,
|
|
14731
|
+
forceEven,
|
|
15005
14732
|
...props
|
|
15006
14733
|
}) {
|
|
14734
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14735
|
+
let primaryCanvas;
|
|
14736
|
+
let scheduler;
|
|
14737
|
+
let renderer;
|
|
14738
|
+
if (isRendererConfig) {
|
|
14739
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14740
|
+
primaryCanvas = pc;
|
|
14741
|
+
scheduler = sc;
|
|
14742
|
+
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
14743
|
+
} else {
|
|
14744
|
+
renderer = rendererProp;
|
|
14745
|
+
}
|
|
15007
14746
|
React.useMemo(() => extend(THREE), []);
|
|
15008
14747
|
const Bridge = useBridge();
|
|
14748
|
+
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15009
14749
|
const hasInitialSizeRef = React.useRef(false);
|
|
15010
14750
|
const measureConfig = React.useMemo(() => {
|
|
15011
14751
|
if (!hasInitialSizeRef.current) {
|
|
@@ -15022,7 +14762,21 @@ function CanvasImpl({
|
|
|
15022
14762
|
};
|
|
15023
14763
|
}, [resize, hasInitialSizeRef.current]);
|
|
15024
14764
|
const [containerRef, containerRect] = useMeasure(measureConfig);
|
|
15025
|
-
|
|
14765
|
+
const effectiveSize = React.useMemo(() => {
|
|
14766
|
+
let w = width ?? containerRect.width;
|
|
14767
|
+
let h = height ?? containerRect.height;
|
|
14768
|
+
if (forceEven) {
|
|
14769
|
+
w = Math.ceil(w / 2) * 2;
|
|
14770
|
+
h = Math.ceil(h / 2) * 2;
|
|
14771
|
+
}
|
|
14772
|
+
return {
|
|
14773
|
+
width: w,
|
|
14774
|
+
height: h,
|
|
14775
|
+
top: containerRect.top,
|
|
14776
|
+
left: containerRect.left
|
|
14777
|
+
};
|
|
14778
|
+
}, [width, height, containerRect, forceEven]);
|
|
14779
|
+
if (!hasInitialSizeRef.current && effectiveSize.width > 0 && effectiveSize.height > 0) {
|
|
15026
14780
|
hasInitialSizeRef.current = true;
|
|
15027
14781
|
}
|
|
15028
14782
|
const canvasRef = React.useRef(null);
|
|
@@ -15041,7 +14795,7 @@ function CanvasImpl({
|
|
|
15041
14795
|
useIsomorphicLayoutEffect(() => {
|
|
15042
14796
|
effectActiveRef.current = true;
|
|
15043
14797
|
const canvas = canvasRef.current;
|
|
15044
|
-
if (
|
|
14798
|
+
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
15045
14799
|
if (!root.current) {
|
|
15046
14800
|
root.current = createRoot(canvas);
|
|
15047
14801
|
notifyAlpha({
|
|
@@ -15061,21 +14815,26 @@ function CanvasImpl({
|
|
|
15061
14815
|
async function run() {
|
|
15062
14816
|
if (!effectActiveRef.current || !root.current) return;
|
|
15063
14817
|
await root.current.configure({
|
|
14818
|
+
id,
|
|
14819
|
+
primaryCanvas,
|
|
14820
|
+
scheduler,
|
|
15064
14821
|
gl,
|
|
15065
14822
|
renderer,
|
|
15066
14823
|
scene,
|
|
15067
14824
|
events,
|
|
15068
14825
|
shadows,
|
|
15069
|
-
linear,
|
|
15070
|
-
flat,
|
|
15071
|
-
legacy,
|
|
15072
14826
|
orthographic,
|
|
15073
14827
|
frameloop,
|
|
15074
14828
|
dpr,
|
|
15075
14829
|
performance,
|
|
15076
14830
|
raycaster,
|
|
15077
14831
|
camera,
|
|
15078
|
-
|
|
14832
|
+
autoUpdateFrustum,
|
|
14833
|
+
occlusion,
|
|
14834
|
+
size: effectiveSize,
|
|
14835
|
+
// Store size props for reset functionality
|
|
14836
|
+
_sizeProps: width !== void 0 || height !== void 0 ? { width, height } : null,
|
|
14837
|
+
forceEven,
|
|
15079
14838
|
// Pass mutable reference to onPointerMissed so it's free to update
|
|
15080
14839
|
onPointerMissed: (...args) => handlePointerMissed.current?.(...args),
|
|
15081
14840
|
onDragOverMissed: (...args) => handleDragOverMissed.current?.(...args),
|
|
@@ -15099,7 +14858,10 @@ function CanvasImpl({
|
|
|
15099
14858
|
});
|
|
15100
14859
|
if (!effectActiveRef.current || !root.current) return;
|
|
15101
14860
|
root.current.render(
|
|
15102
|
-
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */
|
|
14861
|
+
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
14862
|
+
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
14863
|
+
children ?? null
|
|
14864
|
+
] }) }) })
|
|
15103
14865
|
);
|
|
15104
14866
|
}
|
|
15105
14867
|
run();
|
|
@@ -15121,6 +14883,28 @@ function CanvasImpl({
|
|
|
15121
14883
|
};
|
|
15122
14884
|
}
|
|
15123
14885
|
}, []);
|
|
14886
|
+
React.useEffect(() => {
|
|
14887
|
+
if (hmr === false) return;
|
|
14888
|
+
const canvas = canvasRef.current;
|
|
14889
|
+
if (!canvas) return;
|
|
14890
|
+
const handleHMR = () => {
|
|
14891
|
+
queueMicrotask(() => {
|
|
14892
|
+
const rootEntry = _roots.get(canvas);
|
|
14893
|
+
if (rootEntry?.store) clearHmrCaches(rootEntry.store);
|
|
14894
|
+
});
|
|
14895
|
+
};
|
|
14896
|
+
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
14897
|
+
const hot = import.meta.hot;
|
|
14898
|
+
hot.on("vite:afterUpdate", handleHMR);
|
|
14899
|
+
return () => hot.off?.("vite:afterUpdate", handleHMR);
|
|
14900
|
+
}
|
|
14901
|
+
if (typeof module !== "undefined" && module.hot) {
|
|
14902
|
+
const hot = module.hot;
|
|
14903
|
+
hot.addStatusHandler((status) => {
|
|
14904
|
+
if (status === "idle") handleHMR();
|
|
14905
|
+
});
|
|
14906
|
+
}
|
|
14907
|
+
}, [hmr]);
|
|
15124
14908
|
const pointerEvents = eventSource ? "none" : "auto";
|
|
15125
14909
|
return /* @__PURE__ */ jsx(
|
|
15126
14910
|
"div",
|
|
@@ -15135,7 +14919,16 @@ function CanvasImpl({
|
|
|
15135
14919
|
...style
|
|
15136
14920
|
},
|
|
15137
14921
|
...props,
|
|
15138
|
-
children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
14922
|
+
children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
14923
|
+
"canvas",
|
|
14924
|
+
{
|
|
14925
|
+
ref: canvasRef,
|
|
14926
|
+
id,
|
|
14927
|
+
className: "r3f-canvas",
|
|
14928
|
+
style: { display: "block", width: "100%", height: "100%" },
|
|
14929
|
+
children: fallback
|
|
14930
|
+
}
|
|
14931
|
+
) })
|
|
15139
14932
|
}
|
|
15140
14933
|
);
|
|
15141
14934
|
}
|
|
@@ -15145,4 +14938,4 @@ function Canvas(props) {
|
|
|
15145
14938
|
|
|
15146
14939
|
extend(THREE);
|
|
15147
14940
|
|
|
15148
|
-
export { Block, Canvas, ErrorBoundary, IsObject, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS,
|
|
14941
|
+
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, reconciler, registerPrimary, removeInteractivity, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
|