@react-three/fiber 10.0.0-canary.2c50459 → 10.0.0-canary.4bc4a97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2247 -2004
- package/dist/index.d.cts +71 -35
- package/dist/index.d.mts +71 -35
- package/dist/index.d.ts +71 -35
- package/dist/index.mjs +2250 -2007
- package/dist/legacy.cjs +2282 -2039
- package/dist/legacy.d.cts +71 -34
- package/dist/legacy.d.mts +71 -34
- package/dist/legacy.d.ts +71 -34
- package/dist/legacy.mjs +2284 -2041
- package/dist/webgpu/index.cjs +2615 -2613
- package/dist/webgpu/index.d.cts +105 -39
- package/dist/webgpu/index.d.mts +105 -39
- package/dist/webgpu/index.d.ts +105 -39
- package/dist/webgpu/index.mjs +2618 -2616
- package/package.json +5 -5
- package/readme.md +1 -2
- package/react-reconciler/constants.d.ts +0 -7
- package/react-reconciler/constants.js +0 -1
- package/react-reconciler/index.d.ts +0 -1044
- package/react-reconciler/index.js +0 -208
package/dist/legacy.cjs
CHANGED
|
@@ -5,15 +5,14 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
const React = require('react');
|
|
6
6
|
const useMeasure = require('react-use-measure');
|
|
7
7
|
const itsFine = require('its-fine');
|
|
8
|
-
const
|
|
8
|
+
const traditional = require('zustand/traditional');
|
|
9
|
+
const scheduler = require('@pmndrs/scheduler');
|
|
10
|
+
const Tb = require('scheduler');
|
|
9
11
|
const GroundedSkybox_js = require('three/examples/jsm/objects/GroundedSkybox.js');
|
|
10
12
|
const HDRLoader_js = require('three/examples/jsm/loaders/HDRLoader.js');
|
|
11
13
|
const EXRLoader_js = require('three/examples/jsm/loaders/EXRLoader.js');
|
|
12
14
|
const UltraHDRLoader_js = require('three/examples/jsm/loaders/UltraHDRLoader.js');
|
|
13
15
|
const gainmapJs = require('@monogrid/gainmap-js');
|
|
14
|
-
const Tb = require('scheduler');
|
|
15
|
-
const traditional = require('zustand/traditional');
|
|
16
|
-
const scheduler = require('@pmndrs/scheduler');
|
|
17
16
|
const suspendReact = require('suspend-react');
|
|
18
17
|
|
|
19
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -62,9 +61,12 @@ const WebGPURenderer = class WebGPURenderer2 {
|
|
|
62
61
|
}
|
|
63
62
|
};
|
|
64
63
|
const RenderTarget = null;
|
|
64
|
+
const CubeRenderTarget = null;
|
|
65
65
|
|
|
66
66
|
const THREE = /*#__PURE__*/_mergeNamespaces({
|
|
67
67
|
__proto__: null,
|
|
68
|
+
CubeRenderTarget: CubeRenderTarget,
|
|
69
|
+
CubeRenderTargetCompat: three.WebGLCubeRenderTarget,
|
|
68
70
|
Inspector: Inspector,
|
|
69
71
|
R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
|
|
70
72
|
R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
|
|
@@ -131,550 +133,223 @@ function getPrimaryIds() {
|
|
|
131
133
|
return Array.from(primaryRegistry.keys());
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
136
|
+
var __defProp = Object.defineProperty;
|
|
137
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
138
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
139
|
+
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
140
|
+
function useMutableCallback(fn) {
|
|
141
|
+
const ref = React__namespace.useRef(fn);
|
|
142
|
+
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
143
|
+
return ref;
|
|
144
|
+
}
|
|
145
|
+
function useBridge() {
|
|
146
|
+
const fiber = itsFine.useFiber();
|
|
147
|
+
const ContextBridge = itsFine.useContextBridge();
|
|
148
|
+
return React__namespace.useMemo(
|
|
149
|
+
() => ({ children }) => {
|
|
150
|
+
const strict = !!itsFine.traverseFiber(fiber, true, (node) => node.type === React__namespace.StrictMode);
|
|
151
|
+
const Root = strict ? React__namespace.StrictMode : React__namespace.Fragment;
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) });
|
|
153
|
+
},
|
|
154
|
+
[fiber, ContextBridge]
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function Block({ set }) {
|
|
158
|
+
useIsomorphicLayoutEffect(() => {
|
|
159
|
+
set(new Promise(() => null));
|
|
160
|
+
return () => set(false);
|
|
161
|
+
}, [set]);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
165
|
+
var _a;
|
|
166
|
+
return _a = class extends React__namespace.Component {
|
|
167
|
+
constructor() {
|
|
168
|
+
super(...arguments);
|
|
169
|
+
__publicField(this, "state", { error: false });
|
|
170
|
+
}
|
|
171
|
+
componentDidCatch(err) {
|
|
172
|
+
this.props.set(err);
|
|
173
|
+
}
|
|
174
|
+
render() {
|
|
175
|
+
return this.state.error ? null : this.props.children;
|
|
176
|
+
}
|
|
177
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
178
|
+
})();
|
|
146
179
|
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} = {}) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
fiber.useLoader.clear(loader, multiFile ? [files] : files);
|
|
180
|
+
const is = {
|
|
181
|
+
obj: (a) => a === Object(a) && !is.arr(a) && typeof a !== "function",
|
|
182
|
+
fun: (a) => typeof a === "function",
|
|
183
|
+
str: (a) => typeof a === "string",
|
|
184
|
+
num: (a) => typeof a === "number",
|
|
185
|
+
boo: (a) => typeof a === "boolean",
|
|
186
|
+
und: (a) => a === void 0,
|
|
187
|
+
nul: (a) => a === null,
|
|
188
|
+
arr: (a) => Array.isArray(a),
|
|
189
|
+
equ(a, b, { arrays = "shallow", objects = "reference", strict = true } = {}) {
|
|
190
|
+
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
191
|
+
if (is.str(a) || is.num(a) || is.boo(a)) return a === b;
|
|
192
|
+
const isObj = is.obj(a);
|
|
193
|
+
if (isObj && objects === "reference") return a === b;
|
|
194
|
+
const isArr = is.arr(a);
|
|
195
|
+
if (isArr && arrays === "reference") return a === b;
|
|
196
|
+
if ((isArr || isObj) && a === b) return true;
|
|
197
|
+
let i;
|
|
198
|
+
for (i in a) if (!(i in b)) return false;
|
|
199
|
+
if (isObj && arrays === "shallow" && objects === "shallow") {
|
|
200
|
+
for (i in strict ? b : a) if (!is.equ(a[i], b[i], { strict, objects: "reference" })) return false;
|
|
201
|
+
} else {
|
|
202
|
+
for (i in strict ? b : a) if (a[i] !== b[i]) return false;
|
|
171
203
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
multiFile ? [files] : files,
|
|
177
|
-
(loader2) => {
|
|
178
|
-
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
179
|
-
loader2.setRenderer?.(renderer);
|
|
180
|
-
}
|
|
181
|
-
loader2.setPath?.(path);
|
|
182
|
-
if (extensions) extensions(loader2);
|
|
204
|
+
if (is.und(i)) {
|
|
205
|
+
if (isArr && a.length === 0 && b.length === 0) return true;
|
|
206
|
+
if (isObj && Object.keys(a).length === 0 && Object.keys(b).length === 0) return true;
|
|
207
|
+
if (a !== b) return false;
|
|
183
208
|
}
|
|
184
|
-
|
|
185
|
-
let texture = multiFile ? (
|
|
186
|
-
// @ts-ignore
|
|
187
|
-
loaderResult[0]
|
|
188
|
-
) : loaderResult;
|
|
189
|
-
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
190
|
-
texture = texture.renderTarget?.texture;
|
|
191
|
-
}
|
|
192
|
-
texture.mapping = isCubemap ? three.CubeReflectionMapping : three.EquirectangularReflectionMapping;
|
|
193
|
-
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
194
|
-
return texture;
|
|
195
|
-
}
|
|
196
|
-
const preloadDefaultOptions = {
|
|
197
|
-
files: defaultFiles,
|
|
198
|
-
path: "",
|
|
199
|
-
preset: void 0,
|
|
200
|
-
extensions: void 0
|
|
201
|
-
};
|
|
202
|
-
useEnvironment.preload = (preloadOptions) => {
|
|
203
|
-
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
204
|
-
let { files, path = "" } = options;
|
|
205
|
-
const { preset, extensions } = options;
|
|
206
|
-
if (preset) {
|
|
207
|
-
validatePreset(preset);
|
|
208
|
-
files = presetsObj[preset];
|
|
209
|
-
path = CUBEMAP_ROOT;
|
|
210
|
-
}
|
|
211
|
-
const { extension } = getExtension(files);
|
|
212
|
-
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
213
|
-
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
214
|
-
}
|
|
215
|
-
const loader = getLoader$1(extension);
|
|
216
|
-
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
217
|
-
fiber.useLoader.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
218
|
-
loader2.setPath?.(path);
|
|
219
|
-
if (extensions) extensions(loader2);
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
const clearDefaultOptins = {
|
|
223
|
-
files: defaultFiles,
|
|
224
|
-
preset: void 0
|
|
225
|
-
};
|
|
226
|
-
useEnvironment.clear = (clearOptions) => {
|
|
227
|
-
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
228
|
-
let { files } = options;
|
|
229
|
-
const { preset } = options;
|
|
230
|
-
if (preset) {
|
|
231
|
-
validatePreset(preset);
|
|
232
|
-
files = presetsObj[preset];
|
|
209
|
+
return true;
|
|
233
210
|
}
|
|
234
|
-
const { extension } = getExtension(files);
|
|
235
|
-
const loader = getLoader$1(extension);
|
|
236
|
-
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
237
|
-
fiber.useLoader.clear(loader, isArray(files) ? [files] : files);
|
|
238
211
|
};
|
|
239
|
-
|
|
240
|
-
|
|
212
|
+
const isOrthographicCamera = (def) => def && def.isOrthographicCamera;
|
|
213
|
+
const isRef$1 = (obj) => obj !== null && typeof obj === "object" && obj.hasOwnProperty("current");
|
|
214
|
+
const isColorRepresentation = (value) => value != null && (typeof value === "string" || typeof value === "number" || value.isColor);
|
|
215
|
+
const isObject3D = (object) => object?.isObject3D;
|
|
216
|
+
const isTexture = (value) => !!value?.isTexture;
|
|
217
|
+
const isVectorLike = (object) => object !== null && typeof object === "object" && "set" in object && typeof object.set === "function";
|
|
218
|
+
const isCopyable = (object) => isVectorLike(object) && "copy" in object && typeof object.copy === "function";
|
|
219
|
+
const hasConstructor = (object) => !!object?.constructor;
|
|
220
|
+
|
|
221
|
+
function calculateDpr(dpr) {
|
|
222
|
+
const target = typeof window !== "undefined" ? window.devicePixelRatio ?? 2 : 1;
|
|
223
|
+
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
241
224
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
245
|
-
const firstEntry = isArray(files) ? files[0] : files;
|
|
246
|
-
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();
|
|
247
|
-
return { extension, isCubemap, isGainmap };
|
|
225
|
+
function getUuidPrefix(uuid) {
|
|
226
|
+
return uuid.split("-")[0];
|
|
248
227
|
}
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
228
|
+
function updateCamera(camera, size) {
|
|
229
|
+
if (camera.manual) return;
|
|
230
|
+
if (isOrthographicCamera(camera)) {
|
|
231
|
+
camera.left = size.width / -2;
|
|
232
|
+
camera.right = size.width / 2;
|
|
233
|
+
camera.top = size.height / 2;
|
|
234
|
+
camera.bottom = size.height / -2;
|
|
235
|
+
} else {
|
|
236
|
+
camera.aspect = size.width / size.height;
|
|
237
|
+
}
|
|
238
|
+
camera.updateProjectionMatrix();
|
|
252
239
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
backgroundIntensity: 1,
|
|
260
|
-
backgroundRotation: [0, 0, 0],
|
|
261
|
-
environmentIntensity: 1,
|
|
262
|
-
environmentRotation: [0, 0, 0],
|
|
263
|
-
...sceneProps
|
|
264
|
-
};
|
|
265
|
-
const target = resolveScene(scene || defaultScene);
|
|
266
|
-
const oldbg = target.background;
|
|
267
|
-
const oldenv = target.environment;
|
|
268
|
-
const oldSceneProps = {
|
|
269
|
-
// @ts-ignore
|
|
270
|
-
backgroundBlurriness: target.backgroundBlurriness,
|
|
271
|
-
// @ts-ignore
|
|
272
|
-
backgroundIntensity: target.backgroundIntensity,
|
|
273
|
-
// @ts-ignore
|
|
274
|
-
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
275
|
-
// @ts-ignore
|
|
276
|
-
environmentIntensity: target.environmentIntensity,
|
|
277
|
-
// @ts-ignore
|
|
278
|
-
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
279
|
-
};
|
|
280
|
-
if (background !== "only") target.environment = texture;
|
|
281
|
-
if (background) target.background = texture;
|
|
282
|
-
fiber.applyProps(target, sceneProps);
|
|
283
|
-
return () => {
|
|
284
|
-
if (background !== "only") target.environment = oldenv;
|
|
285
|
-
if (background) target.background = oldbg;
|
|
286
|
-
fiber.applyProps(target, oldSceneProps);
|
|
287
|
-
};
|
|
240
|
+
const frustumMatrix = new three.Matrix4();
|
|
241
|
+
function updateFrustum(camera, frustum) {
|
|
242
|
+
const target = frustum ?? new three.Frustum();
|
|
243
|
+
frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
244
|
+
target.setFromProjectionMatrix(frustumMatrix);
|
|
245
|
+
return target;
|
|
288
246
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return
|
|
247
|
+
|
|
248
|
+
const REACT_INTERNAL_PROPS = ["children", "key", "ref"];
|
|
249
|
+
function findInitialRoot(instance) {
|
|
250
|
+
let root = instance.root;
|
|
251
|
+
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
252
|
+
return root;
|
|
295
253
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
...rest
|
|
306
|
-
}) {
|
|
307
|
-
const texture = useEnvironment(rest);
|
|
308
|
-
const defaultScene = fiber.useThree((state) => state.scene);
|
|
309
|
-
React__namespace.useLayoutEffect(() => {
|
|
310
|
-
return setEnvProps(background, scene, defaultScene, texture, {
|
|
311
|
-
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
312
|
-
backgroundIntensity,
|
|
313
|
-
backgroundRotation,
|
|
314
|
-
environmentIntensity,
|
|
315
|
-
environmentRotation
|
|
254
|
+
function getRootState(obj) {
|
|
255
|
+
let state = obj.__r3f?.root.getState();
|
|
256
|
+
if (!state) {
|
|
257
|
+
obj.traverseAncestors((ancestor) => {
|
|
258
|
+
const parentState = ancestor.__r3f?.root.getState();
|
|
259
|
+
if (parentState) {
|
|
260
|
+
state = parentState;
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
316
263
|
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return () => {
|
|
320
|
-
texture.dispose();
|
|
321
|
-
};
|
|
322
|
-
}, [texture]);
|
|
323
|
-
return null;
|
|
264
|
+
}
|
|
265
|
+
return state;
|
|
324
266
|
}
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
path,
|
|
342
|
-
preset = void 0,
|
|
343
|
-
extensions
|
|
344
|
-
}) {
|
|
345
|
-
const gl = fiber.useThree((state) => state.gl);
|
|
346
|
-
const defaultScene = fiber.useThree((state) => state.scene);
|
|
347
|
-
const camera = React__namespace.useRef(null);
|
|
348
|
-
const [virtualScene] = React__namespace.useState(() => new three.Scene());
|
|
349
|
-
const fbo = React__namespace.useMemo(() => {
|
|
350
|
-
const fbo2 = new three.WebGLCubeRenderTarget(resolution);
|
|
351
|
-
fbo2.texture.type = three.HalfFloatType;
|
|
352
|
-
return fbo2;
|
|
353
|
-
}, [resolution]);
|
|
354
|
-
React__namespace.useEffect(() => {
|
|
355
|
-
return () => {
|
|
356
|
-
fbo.dispose();
|
|
357
|
-
};
|
|
358
|
-
}, [fbo]);
|
|
359
|
-
React__namespace.useLayoutEffect(() => {
|
|
360
|
-
if (frames === 1) {
|
|
361
|
-
const autoClear = gl.autoClear;
|
|
362
|
-
gl.autoClear = true;
|
|
363
|
-
camera.current.update(gl, virtualScene);
|
|
364
|
-
gl.autoClear = autoClear;
|
|
365
|
-
}
|
|
366
|
-
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
367
|
-
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
368
|
-
backgroundIntensity,
|
|
369
|
-
backgroundRotation,
|
|
370
|
-
environmentIntensity,
|
|
371
|
-
environmentRotation
|
|
267
|
+
function buildGraph(object) {
|
|
268
|
+
const data = { nodes: {}, materials: {}, meshes: {} };
|
|
269
|
+
if (object) {
|
|
270
|
+
object.traverse((obj) => {
|
|
271
|
+
if (obj.name) data.nodes[obj.name] = obj;
|
|
272
|
+
if (obj.material) {
|
|
273
|
+
const material = Array.isArray(obj.material) ? obj.material[0] : obj.material;
|
|
274
|
+
const nameAlreadyUsed = data.materials[material.name];
|
|
275
|
+
let materialName = material.name;
|
|
276
|
+
if (nameAlreadyUsed) {
|
|
277
|
+
materialName = materialName + `-${getUuidPrefix(material.uuid)}`;
|
|
278
|
+
material.userData.materialCacheName = materialName;
|
|
279
|
+
}
|
|
280
|
+
data.materials[materialName] = material;
|
|
281
|
+
}
|
|
282
|
+
if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
|
|
372
283
|
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
virtualScene,
|
|
376
|
-
fbo.texture,
|
|
377
|
-
scene,
|
|
378
|
-
defaultScene,
|
|
379
|
-
background,
|
|
380
|
-
frames,
|
|
381
|
-
gl,
|
|
382
|
-
blur,
|
|
383
|
-
backgroundBlurriness,
|
|
384
|
-
backgroundIntensity,
|
|
385
|
-
backgroundRotation,
|
|
386
|
-
environmentIntensity,
|
|
387
|
-
environmentRotation
|
|
388
|
-
]);
|
|
389
|
-
let count = 1;
|
|
390
|
-
fiber.useFrame(() => {
|
|
391
|
-
if (frames === Infinity || count < frames) {
|
|
392
|
-
const autoClear = gl.autoClear;
|
|
393
|
-
gl.autoClear = true;
|
|
394
|
-
camera.current.update(gl, virtualScene);
|
|
395
|
-
gl.autoClear = autoClear;
|
|
396
|
-
count++;
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(
|
|
400
|
-
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
401
|
-
children,
|
|
402
|
-
/* @__PURE__ */ jsxRuntime.jsx("cubeCamera", { ref: camera, args: [near, far, fbo] }),
|
|
403
|
-
files || preset ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { background: true, files, preset, path, extensions }) : map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { background: true, map, extensions }) : null
|
|
404
|
-
] }),
|
|
405
|
-
virtualScene
|
|
406
|
-
) });
|
|
407
|
-
}
|
|
408
|
-
function EnvironmentGround(props) {
|
|
409
|
-
const textureDefault = useEnvironment(props);
|
|
410
|
-
const texture = props.map || textureDefault;
|
|
411
|
-
React__namespace.useMemo(() => fiber.extend({ GroundProjectedEnvImpl: GroundedSkybox_js.GroundedSkybox }), []);
|
|
412
|
-
React__namespace.useEffect(() => {
|
|
413
|
-
return () => {
|
|
414
|
-
textureDefault.dispose();
|
|
415
|
-
};
|
|
416
|
-
}, [textureDefault]);
|
|
417
|
-
const height = props.ground?.height ?? 15;
|
|
418
|
-
const radius = props.ground?.radius ?? 60;
|
|
419
|
-
const scale = props.ground?.scale ?? 1e3;
|
|
420
|
-
const args = React__namespace.useMemo(
|
|
421
|
-
() => [texture, height, radius],
|
|
422
|
-
[texture, height, radius]
|
|
423
|
-
);
|
|
424
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
425
|
-
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props, map: texture }),
|
|
426
|
-
/* @__PURE__ */ jsxRuntime.jsx("groundProjectedEnvImpl", { args, scale })
|
|
427
|
-
] });
|
|
428
|
-
}
|
|
429
|
-
function EnvironmentColor({ color, scene }) {
|
|
430
|
-
const defaultScene = fiber.useThree((state) => state.scene);
|
|
431
|
-
React__namespace.useLayoutEffect(() => {
|
|
432
|
-
if (color === void 0) return;
|
|
433
|
-
const target = resolveScene(scene || defaultScene);
|
|
434
|
-
const oldBg = target.background;
|
|
435
|
-
target.background = new three.Color(color);
|
|
436
|
-
return () => {
|
|
437
|
-
target.background = oldBg;
|
|
438
|
-
};
|
|
439
|
-
});
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
function EnvironmentDualSource(props) {
|
|
443
|
-
const { backgroundFiles, ...envProps } = props;
|
|
444
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
445
|
-
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...envProps, background: false }),
|
|
446
|
-
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props, files: backgroundFiles, background: "only" })
|
|
447
|
-
] });
|
|
284
|
+
}
|
|
285
|
+
return data;
|
|
448
286
|
}
|
|
449
|
-
function
|
|
450
|
-
if (
|
|
451
|
-
|
|
287
|
+
function dispose(obj) {
|
|
288
|
+
if (obj.type !== "Scene") obj.dispose?.();
|
|
289
|
+
for (const p in obj) {
|
|
290
|
+
const prop = obj[p];
|
|
291
|
+
if (prop?.type !== "Scene") prop?.dispose?.();
|
|
452
292
|
}
|
|
453
|
-
|
|
454
|
-
|
|
293
|
+
}
|
|
294
|
+
function getInstanceProps(pendingProps) {
|
|
295
|
+
const props = {};
|
|
296
|
+
for (const key in pendingProps) {
|
|
297
|
+
if (!REACT_INTERNAL_PROPS.includes(key)) props[key] = pendingProps[key];
|
|
455
298
|
}
|
|
456
|
-
return props
|
|
299
|
+
return props;
|
|
457
300
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
301
|
+
function prepare(target, root, type, props) {
|
|
302
|
+
const object = target;
|
|
303
|
+
let instance = object?.__r3f;
|
|
304
|
+
if (!instance) {
|
|
305
|
+
instance = {
|
|
306
|
+
root,
|
|
307
|
+
type,
|
|
308
|
+
parent: null,
|
|
309
|
+
children: [],
|
|
310
|
+
props: getInstanceProps(props),
|
|
311
|
+
object,
|
|
312
|
+
eventCount: 0,
|
|
313
|
+
handlers: {},
|
|
314
|
+
isHidden: false
|
|
315
|
+
};
|
|
316
|
+
if (object) object.__r3f = instance;
|
|
317
|
+
}
|
|
318
|
+
return instance;
|
|
468
319
|
}
|
|
469
|
-
function
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const strict = !!itsFine.traverseFiber(fiber, true, (node) => node.type === React__namespace.StrictMode);
|
|
475
|
-
const Root = strict ? React__namespace.StrictMode : React__namespace.Fragment;
|
|
476
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Root, { children: /* @__PURE__ */ jsxRuntime.jsx(ContextBridge, { children }) });
|
|
477
|
-
},
|
|
478
|
-
[fiber, ContextBridge]
|
|
479
|
-
);
|
|
320
|
+
function invalidateInstance(instance) {
|
|
321
|
+
if (!instance.parent) return;
|
|
322
|
+
instance.props.onUpdate?.(instance.object);
|
|
323
|
+
const state = instance.root?.getState?.();
|
|
324
|
+
if (state && state.internal.frames === 0) state.invalidate();
|
|
480
325
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return
|
|
326
|
+
|
|
327
|
+
const tempFrustum = new three.Frustum();
|
|
328
|
+
let hasWarnedWebGL = false;
|
|
329
|
+
let tslModule = null;
|
|
330
|
+
async function loadTSL() {
|
|
331
|
+
if (tslModule) return tslModule;
|
|
332
|
+
try {
|
|
333
|
+
const tsl = await import('three/tsl');
|
|
334
|
+
tslModule = { uniform: tsl.uniform, nodeObject: tsl.nodeObject };
|
|
335
|
+
return tslModule;
|
|
336
|
+
} catch {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
487
339
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
502
|
-
})();
|
|
503
|
-
|
|
504
|
-
const is = {
|
|
505
|
-
obj: (a) => a === Object(a) && !is.arr(a) && typeof a !== "function",
|
|
506
|
-
fun: (a) => typeof a === "function",
|
|
507
|
-
str: (a) => typeof a === "string",
|
|
508
|
-
num: (a) => typeof a === "number",
|
|
509
|
-
boo: (a) => typeof a === "boolean",
|
|
510
|
-
und: (a) => a === void 0,
|
|
511
|
-
nul: (a) => a === null,
|
|
512
|
-
arr: (a) => Array.isArray(a),
|
|
513
|
-
equ(a, b, { arrays = "shallow", objects = "reference", strict = true } = {}) {
|
|
514
|
-
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
515
|
-
if (is.str(a) || is.num(a) || is.boo(a)) return a === b;
|
|
516
|
-
const isObj = is.obj(a);
|
|
517
|
-
if (isObj && objects === "reference") return a === b;
|
|
518
|
-
const isArr = is.arr(a);
|
|
519
|
-
if (isArr && arrays === "reference") return a === b;
|
|
520
|
-
if ((isArr || isObj) && a === b) return true;
|
|
521
|
-
let i;
|
|
522
|
-
for (i in a) if (!(i in b)) return false;
|
|
523
|
-
if (isObj && arrays === "shallow" && objects === "shallow") {
|
|
524
|
-
for (i in strict ? b : a) if (!is.equ(a[i], b[i], { strict, objects: "reference" })) return false;
|
|
525
|
-
} else {
|
|
526
|
-
for (i in strict ? b : a) if (a[i] !== b[i]) return false;
|
|
527
|
-
}
|
|
528
|
-
if (is.und(i)) {
|
|
529
|
-
if (isArr && a.length === 0 && b.length === 0) return true;
|
|
530
|
-
if (isObj && Object.keys(a).length === 0 && Object.keys(b).length === 0) return true;
|
|
531
|
-
if (a !== b) return false;
|
|
532
|
-
}
|
|
533
|
-
return true;
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
const isOrthographicCamera = (def) => def && def.isOrthographicCamera;
|
|
537
|
-
const isRef = (obj) => obj !== null && typeof obj === "object" && obj.hasOwnProperty("current");
|
|
538
|
-
const isColorRepresentation = (value) => value != null && (typeof value === "string" || typeof value === "number" || value.isColor);
|
|
539
|
-
const isObject3D = (object) => object?.isObject3D;
|
|
540
|
-
const isTexture = (value) => !!value?.isTexture;
|
|
541
|
-
const isVectorLike = (object) => object !== null && typeof object === "object" && "set" in object && typeof object.set === "function";
|
|
542
|
-
const isCopyable = (object) => isVectorLike(object) && "copy" in object && typeof object.copy === "function";
|
|
543
|
-
const hasConstructor = (object) => !!object?.constructor;
|
|
544
|
-
|
|
545
|
-
function calculateDpr(dpr) {
|
|
546
|
-
const target = typeof window !== "undefined" ? window.devicePixelRatio ?? 2 : 1;
|
|
547
|
-
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
548
|
-
}
|
|
549
|
-
function getUuidPrefix(uuid) {
|
|
550
|
-
return uuid.split("-")[0];
|
|
551
|
-
}
|
|
552
|
-
function updateCamera(camera, size) {
|
|
553
|
-
if (camera.manual) return;
|
|
554
|
-
if (isOrthographicCamera(camera)) {
|
|
555
|
-
camera.left = size.width / -2;
|
|
556
|
-
camera.right = size.width / 2;
|
|
557
|
-
camera.top = size.height / 2;
|
|
558
|
-
camera.bottom = size.height / -2;
|
|
559
|
-
} else {
|
|
560
|
-
camera.aspect = size.width / size.height;
|
|
561
|
-
}
|
|
562
|
-
camera.updateProjectionMatrix();
|
|
563
|
-
}
|
|
564
|
-
const frustumMatrix = new three.Matrix4();
|
|
565
|
-
function updateFrustum(camera, frustum) {
|
|
566
|
-
const target = frustum ?? new three.Frustum();
|
|
567
|
-
frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
568
|
-
target.setFromProjectionMatrix(frustumMatrix);
|
|
569
|
-
return target;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const REACT_INTERNAL_PROPS = ["children", "key", "ref"];
|
|
573
|
-
function findInitialRoot(instance) {
|
|
574
|
-
let root = instance.root;
|
|
575
|
-
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
576
|
-
return root;
|
|
577
|
-
}
|
|
578
|
-
function getRootState(obj) {
|
|
579
|
-
let state = obj.__r3f?.root.getState();
|
|
580
|
-
if (!state) {
|
|
581
|
-
obj.traverseAncestors((ancestor) => {
|
|
582
|
-
const parentState = ancestor.__r3f?.root.getState();
|
|
583
|
-
if (parentState) {
|
|
584
|
-
state = parentState;
|
|
585
|
-
return false;
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
return state;
|
|
590
|
-
}
|
|
591
|
-
function buildGraph(object) {
|
|
592
|
-
const data = { nodes: {}, materials: {}, meshes: {} };
|
|
593
|
-
if (object) {
|
|
594
|
-
object.traverse((obj) => {
|
|
595
|
-
if (obj.name) data.nodes[obj.name] = obj;
|
|
596
|
-
if (obj.material) {
|
|
597
|
-
const material = Array.isArray(obj.material) ? obj.material[0] : obj.material;
|
|
598
|
-
const nameAlreadyUsed = data.materials[material.name];
|
|
599
|
-
let materialName = material.name;
|
|
600
|
-
if (nameAlreadyUsed) {
|
|
601
|
-
materialName = materialName + `-${getUuidPrefix(material.uuid)}`;
|
|
602
|
-
material.userData.materialCacheName = materialName;
|
|
603
|
-
}
|
|
604
|
-
data.materials[materialName] = material;
|
|
605
|
-
}
|
|
606
|
-
if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
return data;
|
|
610
|
-
}
|
|
611
|
-
function dispose(obj) {
|
|
612
|
-
if (obj.type !== "Scene") obj.dispose?.();
|
|
613
|
-
for (const p in obj) {
|
|
614
|
-
const prop = obj[p];
|
|
615
|
-
if (prop?.type !== "Scene") prop?.dispose?.();
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
function getInstanceProps(pendingProps) {
|
|
619
|
-
const props = {};
|
|
620
|
-
for (const key in pendingProps) {
|
|
621
|
-
if (!REACT_INTERNAL_PROPS.includes(key)) props[key] = pendingProps[key];
|
|
622
|
-
}
|
|
623
|
-
return props;
|
|
624
|
-
}
|
|
625
|
-
function prepare(target, root, type, props) {
|
|
626
|
-
const object = target;
|
|
627
|
-
let instance = object?.__r3f;
|
|
628
|
-
if (!instance) {
|
|
629
|
-
instance = {
|
|
630
|
-
root,
|
|
631
|
-
type,
|
|
632
|
-
parent: null,
|
|
633
|
-
children: [],
|
|
634
|
-
props: getInstanceProps(props),
|
|
635
|
-
object,
|
|
636
|
-
eventCount: 0,
|
|
637
|
-
handlers: {},
|
|
638
|
-
isHidden: false,
|
|
639
|
-
deferredRefs: []
|
|
640
|
-
};
|
|
641
|
-
if (object) object.__r3f = instance;
|
|
642
|
-
}
|
|
643
|
-
return instance;
|
|
644
|
-
}
|
|
645
|
-
function invalidateInstance(instance) {
|
|
646
|
-
if (!instance.parent) return;
|
|
647
|
-
instance.props.onUpdate?.(instance.object);
|
|
648
|
-
const state = instance.root?.getState?.();
|
|
649
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
const tempFrustum = new three.Frustum();
|
|
653
|
-
let hasWarnedWebGL = false;
|
|
654
|
-
let tslModule = null;
|
|
655
|
-
async function loadTSL() {
|
|
656
|
-
if (tslModule) return tslModule;
|
|
657
|
-
try {
|
|
658
|
-
const tsl = await import('three/tsl');
|
|
659
|
-
tslModule = { uniform: tsl.uniform, nodeObject: tsl.nodeObject };
|
|
660
|
-
return tslModule;
|
|
661
|
-
} catch {
|
|
662
|
-
return null;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function createOcclusionObserverNode(store, uniform) {
|
|
666
|
-
const node = new three.Node("float");
|
|
667
|
-
node.updateType = three.NodeUpdateType.OBJECT;
|
|
668
|
-
node.update = function(frame) {
|
|
669
|
-
const { internal } = store.getState();
|
|
670
|
-
const registry = internal.visibilityRegistry;
|
|
671
|
-
const cache = internal.occlusionCache;
|
|
672
|
-
for (const entry of registry.values()) {
|
|
673
|
-
const { object, handlers } = entry;
|
|
674
|
-
if (handlers.onOccluded || handlers.onVisible) {
|
|
675
|
-
const isOccluded = frame.renderer.isOccluded(object);
|
|
676
|
-
cache.set(object, isOccluded);
|
|
677
|
-
}
|
|
340
|
+
function createOcclusionObserverNode(store, uniform) {
|
|
341
|
+
const node = new three.Node("float");
|
|
342
|
+
node.updateType = three.NodeUpdateType.OBJECT;
|
|
343
|
+
node.update = function(frame) {
|
|
344
|
+
const { internal } = store.getState();
|
|
345
|
+
const registry = internal.visibilityRegistry;
|
|
346
|
+
const cache = internal.occlusionCache;
|
|
347
|
+
for (const entry of registry.values()) {
|
|
348
|
+
const { object, handlers } = entry;
|
|
349
|
+
if (handlers.onOccluded || handlers.onVisible) {
|
|
350
|
+
const isOccluded = frame.renderer.isOccluded(object);
|
|
351
|
+
cache.set(object, isOccluded);
|
|
352
|
+
}
|
|
678
353
|
}
|
|
679
354
|
};
|
|
680
355
|
node.setup = function() {
|
|
@@ -793,6 +468,17 @@ function unregisterVisibility(store, object) {
|
|
|
793
468
|
internal.visibilityRegistry.delete(object.uuid);
|
|
794
469
|
internal.occlusionCache.delete(object);
|
|
795
470
|
}
|
|
471
|
+
function updateVisibilityHandlers(store, object, handlers) {
|
|
472
|
+
const { internal } = store.getState();
|
|
473
|
+
const entry = internal.visibilityRegistry.get(object.uuid);
|
|
474
|
+
if (!entry) return false;
|
|
475
|
+
entry.handlers = handlers;
|
|
476
|
+
if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
|
|
477
|
+
object.occlusionTest = true;
|
|
478
|
+
enableOcclusion(store);
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
796
482
|
function checkVisibility(state) {
|
|
797
483
|
const { internal, camera } = state;
|
|
798
484
|
const registry = internal.visibilityRegistry;
|
|
@@ -953,9 +639,9 @@ function diffProps(instance, newProps) {
|
|
|
953
639
|
const { root, key } = resolve(instance.object, prop);
|
|
954
640
|
if (root.constructor && root.constructor.length === 0) {
|
|
955
641
|
const ctor = getMemoizedPrototype(root);
|
|
956
|
-
if (!is.und(ctor)) changedProps[
|
|
642
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
957
643
|
} else {
|
|
958
|
-
changedProps[
|
|
644
|
+
changedProps[prop] = 0;
|
|
959
645
|
}
|
|
960
646
|
}
|
|
961
647
|
return changedProps;
|
|
@@ -980,10 +666,7 @@ function applyProps(object, props) {
|
|
|
980
666
|
continue;
|
|
981
667
|
}
|
|
982
668
|
if (value === void 0) continue;
|
|
983
|
-
if (isFromRef(value))
|
|
984
|
-
instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
669
|
+
if (isFromRef(value)) continue;
|
|
987
670
|
if (isOnce(value)) {
|
|
988
671
|
if (instance?.appliedOnce?.has(prop)) continue;
|
|
989
672
|
if (instance) {
|
|
@@ -1019,6 +702,19 @@ function applyProps(object, props) {
|
|
|
1019
702
|
} else if (isVectorLike(target) && is.num(value)) {
|
|
1020
703
|
if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
|
|
1021
704
|
else target.set(value);
|
|
705
|
+
} else if (root instanceof three.ShaderMaterial && key === "uniforms" && is.obj(value)) {
|
|
706
|
+
if (!is.obj(root.uniforms)) root.uniforms = {};
|
|
707
|
+
const uniforms = root.uniforms;
|
|
708
|
+
const nextUniforms = value;
|
|
709
|
+
for (const name in nextUniforms) {
|
|
710
|
+
const uniform = nextUniforms[name];
|
|
711
|
+
const targetUniform = uniforms[name];
|
|
712
|
+
if (targetUniform) Object.assign(targetUniform, uniform);
|
|
713
|
+
else {
|
|
714
|
+
const nextUniform = uniform instanceof three.Uniform ? uniform.clone() : new three.Uniform(uniform.value);
|
|
715
|
+
uniforms[name] = nextUniform;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
1022
718
|
} else {
|
|
1023
719
|
root[key] = value;
|
|
1024
720
|
if (key.endsWith("Node") && root.isMaterial) {
|
|
@@ -1037,6 +733,9 @@ function applyProps(object, props) {
|
|
|
1037
733
|
if (instance.eventCount && object2.raycast !== null) {
|
|
1038
734
|
rootState.internal.interaction.push(object2);
|
|
1039
735
|
}
|
|
736
|
+
}
|
|
737
|
+
if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
|
|
738
|
+
const object2 = instance.object;
|
|
1040
739
|
const root = findInitialRoot(instance);
|
|
1041
740
|
const visibilityHandlers = {
|
|
1042
741
|
onFramed: instance.handlers.onFramed,
|
|
@@ -1044,7 +743,9 @@ function applyProps(object, props) {
|
|
|
1044
743
|
onVisible: instance.handlers.onVisible
|
|
1045
744
|
};
|
|
1046
745
|
if (hasVisibilityHandlers(visibilityHandlers)) {
|
|
1047
|
-
|
|
746
|
+
if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
|
|
747
|
+
registerVisibility(root, object2, visibilityHandlers);
|
|
748
|
+
}
|
|
1048
749
|
} else {
|
|
1049
750
|
unregisterVisibility(root, object2);
|
|
1050
751
|
}
|
|
@@ -1057,1318 +758,909 @@ function applyProps(object, props) {
|
|
|
1057
758
|
return object;
|
|
1058
759
|
}
|
|
1059
760
|
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
761
|
+
const shownNotices = /* @__PURE__ */ new Set();
|
|
762
|
+
function notifyDepreciated({ heading, body, link }) {
|
|
763
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (shownNotices.has(heading)) return;
|
|
767
|
+
shownNotices.add(heading);
|
|
768
|
+
const caller = getCallerFrame();
|
|
769
|
+
if (caller) {
|
|
770
|
+
console.log();
|
|
771
|
+
}
|
|
772
|
+
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
773
|
+
if (caller) {
|
|
774
|
+
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
775
|
+
}
|
|
776
|
+
if (body || link) {
|
|
777
|
+
let message = "";
|
|
778
|
+
if (body) message += body;
|
|
779
|
+
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
780
|
+
console.warn(`%c${message}`, "font-weight: bold;");
|
|
1072
781
|
}
|
|
1073
|
-
return state;
|
|
1074
782
|
}
|
|
1075
|
-
function
|
|
1076
|
-
|
|
783
|
+
function getCallerFrame(depth = 3) {
|
|
784
|
+
const stack = new Error().stack;
|
|
785
|
+
if (!stack) return null;
|
|
786
|
+
const lines = stack.split("\n");
|
|
787
|
+
const frame = lines[depth];
|
|
788
|
+
if (!frame) return null;
|
|
789
|
+
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
790
|
+
if (!match) {
|
|
791
|
+
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
792
|
+
}
|
|
793
|
+
if (!match) return null;
|
|
794
|
+
const [, fn, url, line] = match;
|
|
795
|
+
return {
|
|
796
|
+
functionName: fn ?? "<anonymous>",
|
|
797
|
+
location: formatLocation(url, Number(line))
|
|
798
|
+
};
|
|
1077
799
|
}
|
|
1078
|
-
function
|
|
1079
|
-
|
|
800
|
+
function formatLocation(url, line) {
|
|
801
|
+
const clean = url.split("?")[0];
|
|
802
|
+
const file = clean.split("/").pop() ?? clean;
|
|
803
|
+
return `${file}:${line}`;
|
|
1080
804
|
}
|
|
1081
|
-
function
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
const captureData = pointerState.captured.get(obj);
|
|
1085
|
-
if (captureData) {
|
|
1086
|
-
pointerState.captured.delete(obj);
|
|
1087
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
805
|
+
function notifyAlpha({ message, link }) {
|
|
806
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
807
|
+
return;
|
|
1088
808
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
pointerState.hovered.forEach((value, key) => {
|
|
1096
|
-
if (value.eventObject === object || value.object === object) {
|
|
1097
|
-
pointerState.hovered.delete(key);
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1100
|
-
if (pointerState.captured.has(object)) {
|
|
1101
|
-
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1102
|
-
}
|
|
809
|
+
if (shownNotices.has(message)) return;
|
|
810
|
+
shownNotices.add(message);
|
|
811
|
+
const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
|
|
812
|
+
console.log(`%c\u{1F52C} ${message}`, boxStyle);
|
|
813
|
+
{
|
|
814
|
+
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
1103
815
|
}
|
|
1104
|
-
unregisterVisibility(store, object);
|
|
1105
816
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
if (!state.previousRoot) {
|
|
1137
|
-
state.events.compute?.(event, state);
|
|
1138
|
-
}
|
|
1139
|
-
function handleRaycast(obj) {
|
|
1140
|
-
const state2 = getRootState(obj);
|
|
1141
|
-
if (!state2 || !state2.events.enabled || state2.raycaster.camera === null) return [];
|
|
1142
|
-
if (state2.raycaster.camera === void 0) {
|
|
1143
|
-
state2.events.compute?.(event, state2, state2.previousRoot?.getState());
|
|
1144
|
-
if (state2.raycaster.camera === void 0) state2.raycaster.camera = null;
|
|
1145
|
-
}
|
|
1146
|
-
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1147
|
-
}
|
|
1148
|
-
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
1149
|
-
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
1150
|
-
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
1151
|
-
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
1152
|
-
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
1153
|
-
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
1154
|
-
if (aInteractivePriority !== bInteractivePriority) {
|
|
1155
|
-
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
const aState = getRootState(a.object);
|
|
1159
|
-
const bState = getRootState(b.object);
|
|
1160
|
-
const aPriority = aState?.events?.priority ?? 1;
|
|
1161
|
-
const bPriority = bState?.events?.priority ?? 1;
|
|
1162
|
-
return bPriority - aPriority || a.distance - b.distance;
|
|
1163
|
-
}).filter((item) => {
|
|
1164
|
-
const id = makeId(item);
|
|
1165
|
-
if (duplicates.has(id)) return false;
|
|
1166
|
-
duplicates.add(id);
|
|
1167
|
-
return true;
|
|
1168
|
-
});
|
|
1169
|
-
if (state.events.filter) hits = state.events.filter(hits, state);
|
|
1170
|
-
for (const hit of hits) {
|
|
1171
|
-
let eventObject = hit.object;
|
|
1172
|
-
while (eventObject) {
|
|
1173
|
-
if (eventObject.__r3f?.eventCount) {
|
|
1174
|
-
intersections.push({ ...hit, eventObject });
|
|
1175
|
-
}
|
|
1176
|
-
eventObject = eventObject.parent;
|
|
817
|
+
|
|
818
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
819
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
820
|
+
if (!stack) return false;
|
|
821
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
822
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
826
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
|
|
827
|
+
const createStore = (invalidate, advance) => {
|
|
828
|
+
const rootStore = traditional.createWithEqualityFn((set, get) => {
|
|
829
|
+
const position = new three.Vector3();
|
|
830
|
+
const defaultTarget = new three.Vector3();
|
|
831
|
+
const tempTarget = new three.Vector3();
|
|
832
|
+
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
833
|
+
const { width, height, top, left } = size;
|
|
834
|
+
const aspect = width / height;
|
|
835
|
+
if (target.isVector3) tempTarget.copy(target);
|
|
836
|
+
else tempTarget.set(...target);
|
|
837
|
+
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
838
|
+
if (isOrthographicCamera(camera)) {
|
|
839
|
+
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
840
|
+
} else {
|
|
841
|
+
const fov = camera.fov * Math.PI / 180;
|
|
842
|
+
const h = 2 * Math.tan(fov / 2) * distance;
|
|
843
|
+
const w = h * (width / height);
|
|
844
|
+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1177
845
|
}
|
|
1178
846
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
847
|
+
let performanceTimeout = void 0;
|
|
848
|
+
const setPerformanceCurrent = (current) => set((state2) => ({ performance: { ...state2.performance, current } }));
|
|
849
|
+
const pointer = new three.Vector2();
|
|
850
|
+
const rootState = {
|
|
851
|
+
set,
|
|
852
|
+
get,
|
|
853
|
+
// Mock objects that have to be configured
|
|
854
|
+
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
855
|
+
primaryStore: null,
|
|
856
|
+
gl: null,
|
|
857
|
+
renderer: null,
|
|
858
|
+
camera: null,
|
|
859
|
+
frustum: new three.Frustum(),
|
|
860
|
+
autoUpdateFrustum: true,
|
|
861
|
+
raycaster: null,
|
|
862
|
+
events: {
|
|
863
|
+
priority: 1,
|
|
864
|
+
enabled: true,
|
|
865
|
+
connected: false,
|
|
866
|
+
frameTimedRaycasts: true,
|
|
867
|
+
alwaysFireOnScroll: true,
|
|
868
|
+
updateOnFrame: false
|
|
869
|
+
},
|
|
870
|
+
scene: null,
|
|
871
|
+
rootScene: null,
|
|
872
|
+
xr: null,
|
|
873
|
+
inspector: null,
|
|
874
|
+
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
875
|
+
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
876
|
+
textureColorSpace: three.SRGBColorSpace,
|
|
877
|
+
isLegacy: false,
|
|
878
|
+
webGPUSupported: false,
|
|
879
|
+
isNative: false,
|
|
880
|
+
controls: null,
|
|
881
|
+
pointer,
|
|
882
|
+
mouse: pointer,
|
|
883
|
+
frameloop: "always",
|
|
884
|
+
onPointerMissed: void 0,
|
|
885
|
+
onDragOverMissed: void 0,
|
|
886
|
+
onDropMissed: void 0,
|
|
887
|
+
performance: {
|
|
888
|
+
current: 1,
|
|
889
|
+
min: 0.5,
|
|
890
|
+
max: 1,
|
|
891
|
+
debounce: 200,
|
|
892
|
+
regress: () => {
|
|
893
|
+
const state2 = get();
|
|
894
|
+
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
895
|
+
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
896
|
+
performanceTimeout = setTimeout(
|
|
897
|
+
() => setPerformanceCurrent(get().performance.max),
|
|
898
|
+
state2.performance.debounce
|
|
899
|
+
);
|
|
1185
900
|
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
901
|
+
},
|
|
902
|
+
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
903
|
+
viewport: {
|
|
904
|
+
initialDpr: 0,
|
|
905
|
+
dpr: 0,
|
|
906
|
+
width: 0,
|
|
907
|
+
height: 0,
|
|
908
|
+
top: 0,
|
|
909
|
+
left: 0,
|
|
910
|
+
aspect: 0,
|
|
911
|
+
distance: 0,
|
|
912
|
+
factor: 0,
|
|
913
|
+
getCurrentViewport
|
|
914
|
+
},
|
|
915
|
+
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
916
|
+
setSize: (width, height, top, left) => {
|
|
917
|
+
const state2 = get();
|
|
918
|
+
if (width === void 0) {
|
|
919
|
+
set({ _sizeImperative: false });
|
|
920
|
+
if (state2._sizeProps) {
|
|
921
|
+
const { width: propW, height: propH } = state2._sizeProps;
|
|
922
|
+
if (propW !== void 0 || propH !== void 0) {
|
|
923
|
+
const currentSize = state2.size;
|
|
924
|
+
const newSize = {
|
|
925
|
+
width: propW ?? currentSize.width,
|
|
926
|
+
height: propH ?? currentSize.height,
|
|
927
|
+
top: currentSize.top,
|
|
928
|
+
left: currentSize.left
|
|
929
|
+
};
|
|
930
|
+
set((s) => ({
|
|
931
|
+
size: newSize,
|
|
932
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
933
|
+
}));
|
|
934
|
+
scheduler.getScheduler().invalidate();
|
|
935
|
+
}
|
|
1215
936
|
}
|
|
1216
|
-
|
|
1217
|
-
const raycastEvent = {
|
|
1218
|
-
...hit,
|
|
1219
|
-
...extractEventProps,
|
|
1220
|
-
pointer,
|
|
1221
|
-
intersections,
|
|
1222
|
-
stopped: localState.stopped,
|
|
1223
|
-
delta,
|
|
1224
|
-
unprojectedPoint,
|
|
1225
|
-
ray: raycaster.ray,
|
|
1226
|
-
camera,
|
|
1227
|
-
pointerId: eventPointerId,
|
|
1228
|
-
// Hijack stopPropagation, which just sets a flag
|
|
1229
|
-
stopPropagation() {
|
|
1230
|
-
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1231
|
-
if (
|
|
1232
|
-
// ...if this pointer hasn't been captured
|
|
1233
|
-
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1234
|
-
pointerState.captured.has(hit.eventObject)
|
|
1235
|
-
) {
|
|
1236
|
-
raycastEvent.stopped = localState.stopped = true;
|
|
1237
|
-
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1238
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1239
|
-
cancelPointer([...higher, hit], eventPointerId);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
},
|
|
1243
|
-
// there should be a distinction between target and currentTarget
|
|
1244
|
-
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1245
|
-
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1246
|
-
nativeEvent: event
|
|
1247
|
-
};
|
|
1248
|
-
callback(raycastEvent);
|
|
1249
|
-
if (localState.stopped === true) break;
|
|
937
|
+
return;
|
|
1250
938
|
}
|
|
939
|
+
const w = width;
|
|
940
|
+
const h = height ?? width;
|
|
941
|
+
const t = top ?? state2.size.top;
|
|
942
|
+
const l = left ?? state2.size.left;
|
|
943
|
+
const size = { width: w, height: h, top: t, left: l };
|
|
944
|
+
set((s) => ({
|
|
945
|
+
size,
|
|
946
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
947
|
+
_sizeImperative: true
|
|
948
|
+
}));
|
|
949
|
+
scheduler.getScheduler().invalidate();
|
|
950
|
+
},
|
|
951
|
+
setDpr: (dpr) => set((state2) => {
|
|
952
|
+
const resolved = calculateDpr(dpr);
|
|
953
|
+
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
954
|
+
}),
|
|
955
|
+
setFrameloop: (frameloop = "always") => {
|
|
956
|
+
set(() => ({ frameloop }));
|
|
957
|
+
scheduler.getScheduler().frameloop = frameloop;
|
|
958
|
+
},
|
|
959
|
+
setError: (error) => set(() => ({ error })),
|
|
960
|
+
error: null,
|
|
961
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
962
|
+
uniforms: {},
|
|
963
|
+
nodes: {},
|
|
964
|
+
buffers: {},
|
|
965
|
+
gpuStorage: {},
|
|
966
|
+
textures: /* @__PURE__ */ new Map(),
|
|
967
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
968
|
+
renderPipeline: null,
|
|
969
|
+
passes: {},
|
|
970
|
+
_hmrVersion: 0,
|
|
971
|
+
_sizeImperative: false,
|
|
972
|
+
_sizeProps: null,
|
|
973
|
+
previousRoot: void 0,
|
|
974
|
+
internal: {
|
|
975
|
+
// Events
|
|
976
|
+
interaction: [],
|
|
977
|
+
subscribers: [],
|
|
978
|
+
// Per-pointer state (new unified structure)
|
|
979
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
980
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
981
|
+
lastEvent: React__namespace.createRef(),
|
|
982
|
+
// Deprecated but kept for backwards compatibility
|
|
983
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
984
|
+
initialClick: [0, 0],
|
|
985
|
+
initialHits: [],
|
|
986
|
+
capturedMap: /* @__PURE__ */ new Map(),
|
|
987
|
+
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
988
|
+
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
989
|
+
// Occlusion system (WebGPU only)
|
|
990
|
+
occlusionEnabled: false,
|
|
991
|
+
occlusionObserver: null,
|
|
992
|
+
occlusionCache: /* @__PURE__ */ new Map(),
|
|
993
|
+
helperGroup: null,
|
|
994
|
+
// Updates
|
|
995
|
+
active: false,
|
|
996
|
+
frames: 0,
|
|
997
|
+
priority: 0,
|
|
998
|
+
subscribe: (ref, priority, store) => {
|
|
999
|
+
const internal = get().internal;
|
|
1000
|
+
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1001
|
+
internal.subscribers.push({ ref, priority, store });
|
|
1002
|
+
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1003
|
+
return () => {
|
|
1004
|
+
const internal2 = get().internal;
|
|
1005
|
+
if (internal2?.subscribers) {
|
|
1006
|
+
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1007
|
+
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
},
|
|
1011
|
+
// Renderer Storage (single source of truth)
|
|
1012
|
+
actualRenderer: null,
|
|
1013
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1014
|
+
scheduler: null
|
|
1251
1015
|
}
|
|
1252
|
-
}
|
|
1253
|
-
return
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
if (instance?.eventCount) {
|
|
1268
|
-
const handlers = instance.handlers;
|
|
1269
|
-
const data = { ...hoveredObj, intersections };
|
|
1270
|
-
handlers.onPointerOut?.(data);
|
|
1271
|
-
handlers.onPointerLeave?.(data);
|
|
1272
|
-
handlers.onDragOverLeave?.(data);
|
|
1016
|
+
};
|
|
1017
|
+
return rootState;
|
|
1018
|
+
});
|
|
1019
|
+
const state = rootStore.getState();
|
|
1020
|
+
Object.defineProperty(state, "gl", {
|
|
1021
|
+
get() {
|
|
1022
|
+
const currentState = rootStore.getState();
|
|
1023
|
+
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1024
|
+
const stack = new Error().stack || "";
|
|
1025
|
+
if (!isInternalRendererAccess(stack)) {
|
|
1026
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1027
|
+
notifyDepreciated({
|
|
1028
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
1029
|
+
body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
|
|
1030
|
+
});
|
|
1273
1031
|
}
|
|
1274
1032
|
}
|
|
1033
|
+
return currentState.internal.actualRenderer;
|
|
1034
|
+
},
|
|
1035
|
+
set(value) {
|
|
1036
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1037
|
+
},
|
|
1038
|
+
enumerable: true,
|
|
1039
|
+
configurable: true
|
|
1040
|
+
});
|
|
1041
|
+
Object.defineProperty(state, "renderer", {
|
|
1042
|
+
get() {
|
|
1043
|
+
return rootStore.getState().internal.actualRenderer;
|
|
1044
|
+
},
|
|
1045
|
+
set(value) {
|
|
1046
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1047
|
+
},
|
|
1048
|
+
enumerable: true,
|
|
1049
|
+
configurable: true
|
|
1050
|
+
});
|
|
1051
|
+
let oldScene = state.scene;
|
|
1052
|
+
rootStore.subscribe(() => {
|
|
1053
|
+
const currentState = rootStore.getState();
|
|
1054
|
+
const { scene, rootScene, set } = currentState;
|
|
1055
|
+
if (scene !== oldScene) {
|
|
1056
|
+
oldScene = scene;
|
|
1057
|
+
if (scene?.isScene && scene !== rootScene) {
|
|
1058
|
+
set({ rootScene: scene });
|
|
1059
|
+
}
|
|
1275
1060
|
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1298
|
-
if (pointerState) {
|
|
1299
|
-
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1300
|
-
const eventObject = hoveredObj.eventObject;
|
|
1301
|
-
const instance = eventObject.__r3f;
|
|
1302
|
-
if (instance?.eventCount) {
|
|
1303
|
-
const handlers = instance.handlers;
|
|
1304
|
-
const data = { ...hoveredObj, intersections: [] };
|
|
1305
|
-
handlers.onPointerOut?.(data);
|
|
1306
|
-
handlers.onPointerLeave?.(data);
|
|
1061
|
+
});
|
|
1062
|
+
let oldSize = state.size;
|
|
1063
|
+
let oldDpr = state.viewport.dpr;
|
|
1064
|
+
let oldCamera = state.camera;
|
|
1065
|
+
rootStore.subscribe(() => {
|
|
1066
|
+
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1067
|
+
const actualRenderer = internal.actualRenderer;
|
|
1068
|
+
const canvasTarget = internal.canvasTarget;
|
|
1069
|
+
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1070
|
+
oldSize = size;
|
|
1071
|
+
oldDpr = viewport.dpr;
|
|
1072
|
+
updateCamera(camera, size);
|
|
1073
|
+
if (internal.isSecondary && canvasTarget) {
|
|
1074
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1075
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1076
|
+
} else {
|
|
1077
|
+
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1078
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1079
|
+
if (canvasTarget) {
|
|
1080
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1081
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1307
1082
|
}
|
|
1308
1083
|
}
|
|
1309
|
-
internal.pointerMap.delete(pointerId);
|
|
1310
1084
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
const eventObject = data.eventObject;
|
|
1322
|
-
const instance = eventObject.__r3f;
|
|
1323
|
-
if (!instance?.eventCount) return;
|
|
1324
|
-
const handlers = instance.handlers;
|
|
1325
|
-
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1326
|
-
const id = makeId(data);
|
|
1327
|
-
const pointerState = getPointerState(internal, pointerId);
|
|
1328
|
-
const hoveredItem = pointerState.hovered.get(id);
|
|
1329
|
-
if (!hoveredItem) {
|
|
1330
|
-
pointerState.hovered.set(id, data);
|
|
1331
|
-
handlers.onPointerOver?.(data);
|
|
1332
|
-
handlers.onPointerEnter?.(data);
|
|
1333
|
-
} else if (hoveredItem.stopped) {
|
|
1334
|
-
data.stopPropagation();
|
|
1335
|
-
}
|
|
1085
|
+
if (camera !== oldCamera) {
|
|
1086
|
+
oldCamera = camera;
|
|
1087
|
+
const { rootScene } = rootStore.getState();
|
|
1088
|
+
if (camera && rootScene && !camera.parent) {
|
|
1089
|
+
rootScene.add(camera);
|
|
1090
|
+
}
|
|
1091
|
+
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1092
|
+
const currentState = rootStore.getState();
|
|
1093
|
+
if (currentState.autoUpdateFrustum && camera) {
|
|
1094
|
+
updateFrustum(camera, currentState.frustum);
|
|
1336
1095
|
}
|
|
1337
|
-
handlers.onPointerMove?.(data);
|
|
1338
1096
|
}
|
|
1339
|
-
|
|
1097
|
+
});
|
|
1098
|
+
rootStore.subscribe((state2) => invalidate(state2));
|
|
1099
|
+
return rootStore;
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
const memoizedLoaders = /* @__PURE__ */ new WeakMap();
|
|
1103
|
+
const isConstructor$1 = (value) => typeof value === "function" && value?.prototype?.constructor === value;
|
|
1104
|
+
function getLoader$1(Proto) {
|
|
1105
|
+
if (isConstructor$1(Proto)) {
|
|
1106
|
+
let loader = memoizedLoaders.get(Proto);
|
|
1107
|
+
if (!loader) {
|
|
1108
|
+
loader = new Proto();
|
|
1109
|
+
memoizedLoaders.set(Proto, loader);
|
|
1110
|
+
}
|
|
1111
|
+
return loader;
|
|
1340
1112
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
case "onLostPointerCapture":
|
|
1353
|
-
return (event) => {
|
|
1354
|
-
const { internal } = store.getState();
|
|
1355
|
-
const pointerId = getPointerId(event);
|
|
1356
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1357
|
-
if (pointerState?.captured.size) {
|
|
1358
|
-
requestAnimationFrame(() => {
|
|
1359
|
-
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1360
|
-
if (pointerState2?.captured.size) {
|
|
1361
|
-
pointerState2.captured.clear();
|
|
1362
|
-
}
|
|
1363
|
-
cancelPointer([], pointerId);
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
};
|
|
1113
|
+
return Proto;
|
|
1114
|
+
}
|
|
1115
|
+
function loadingFn(extensions, onProgress) {
|
|
1116
|
+
return function(Proto, input) {
|
|
1117
|
+
const loader = getLoader$1(Proto);
|
|
1118
|
+
if (extensions) extensions(loader);
|
|
1119
|
+
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1120
|
+
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1121
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1122
|
+
return data;
|
|
1123
|
+
});
|
|
1367
1124
|
}
|
|
1368
|
-
return
|
|
1125
|
+
return new Promise(
|
|
1126
|
+
(res, reject) => loader.load(
|
|
1127
|
+
input,
|
|
1128
|
+
(data) => {
|
|
1129
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1130
|
+
res(data);
|
|
1131
|
+
},
|
|
1132
|
+
onProgress,
|
|
1133
|
+
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1134
|
+
)
|
|
1135
|
+
);
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1139
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1140
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1141
|
+
const fn = loadingFn(extensions, onProgress);
|
|
1142
|
+
const results = cacheKeys.map(
|
|
1143
|
+
(key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1144
|
+
);
|
|
1145
|
+
return Array.isArray(input) ? results : results[0];
|
|
1146
|
+
}
|
|
1147
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1148
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1149
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1150
|
+
cacheKeys.forEach(
|
|
1151
|
+
(key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1152
|
+
);
|
|
1153
|
+
};
|
|
1154
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1155
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1156
|
+
cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
|
|
1157
|
+
};
|
|
1158
|
+
useLoader.loader = getLoader$1;
|
|
1159
|
+
|
|
1160
|
+
function useFrame(callback, priorityOrOptions) {
|
|
1161
|
+
const store = React__namespace.useContext(context);
|
|
1162
|
+
const isInsideCanvas = store !== null;
|
|
1163
|
+
const scheduler$1 = scheduler.getScheduler();
|
|
1164
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
1165
|
+
id: priorityOrOptions.id,
|
|
1166
|
+
phase: priorityOrOptions.phase,
|
|
1167
|
+
priority: priorityOrOptions.priority,
|
|
1168
|
+
fps: priorityOrOptions.fps,
|
|
1169
|
+
drop: priorityOrOptions.drop,
|
|
1170
|
+
enabled: priorityOrOptions.enabled,
|
|
1171
|
+
before: priorityOrOptions.before,
|
|
1172
|
+
after: priorityOrOptions.after
|
|
1173
|
+
}) : "";
|
|
1174
|
+
const options = React__namespace.useMemo(() => {
|
|
1175
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
1176
|
+
}, [optionsKey]);
|
|
1177
|
+
const reactId = React__namespace.useId();
|
|
1178
|
+
const id = options.id ?? reactId;
|
|
1179
|
+
const callbackRef = useMutableCallback(callback);
|
|
1180
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
1181
|
+
useIsomorphicLayoutEffect(() => {
|
|
1182
|
+
if (!callback) return;
|
|
1183
|
+
if (isInsideCanvas) {
|
|
1369
1184
|
const state = store.getState();
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
const isPointerDown = name === "onPointerDown";
|
|
1379
|
-
const isPointerUp = name === "onPointerUp";
|
|
1380
|
-
const isWheel = name === "onWheel";
|
|
1381
|
-
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1382
|
-
if (isPointerMove && canDeferRaycasts) {
|
|
1383
|
-
events.compute?.(event, state);
|
|
1384
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1388
|
-
events.compute?.(event, state);
|
|
1389
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1390
|
-
return;
|
|
1391
|
-
}
|
|
1392
|
-
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1393
|
-
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1394
|
-
internal.pointerDirty.delete(pointerId);
|
|
1395
|
-
processDeferredPointer(deferredEvent, pointerId);
|
|
1396
|
-
}
|
|
1397
|
-
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1398
|
-
const hits = intersect(event, filter);
|
|
1399
|
-
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1400
|
-
if (isPointerDown) {
|
|
1401
|
-
const pointerState2 = getPointerState(internal, pointerId);
|
|
1402
|
-
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1403
|
-
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1404
|
-
}
|
|
1405
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1406
|
-
const initialHits = pointerState?.initialHits ?? [];
|
|
1407
|
-
if (isClickEvent && !hits.length) {
|
|
1408
|
-
if (delta <= 2) {
|
|
1409
|
-
pointerMissed(event, internal.interaction);
|
|
1410
|
-
if (onPointerMissed) onPointerMissed(event);
|
|
1185
|
+
const rootId = state.internal.rootId;
|
|
1186
|
+
if (isLegacyPriority) {
|
|
1187
|
+
state.internal.priority++;
|
|
1188
|
+
let parentRoot = state.previousRoot;
|
|
1189
|
+
while (parentRoot) {
|
|
1190
|
+
const parentState = parentRoot.getState();
|
|
1191
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
1192
|
+
parentRoot = parentState?.previousRoot;
|
|
1411
1193
|
}
|
|
1194
|
+
notifyDepreciated({
|
|
1195
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
1196
|
+
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within update phase, use: useFrame(callback, { priority: number })',
|
|
1197
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
1198
|
+
});
|
|
1412
1199
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
handlers.onPointerMove?.(data);
|
|
1443
|
-
} else if (isDragOver) {
|
|
1444
|
-
const id = makeId(data);
|
|
1445
|
-
const pointerState2 = getPointerState(internal, pointerId);
|
|
1446
|
-
const hoveredItem = pointerState2.hovered.get(id);
|
|
1447
|
-
if (!hoveredItem) {
|
|
1448
|
-
pointerState2.hovered.set(id, data);
|
|
1449
|
-
handlers.onDragOverEnter?.(data);
|
|
1450
|
-
} else if (hoveredItem.stopped) {
|
|
1451
|
-
data.stopPropagation();
|
|
1452
|
-
}
|
|
1453
|
-
handlers.onDragOver?.(data);
|
|
1454
|
-
} else if (isDrop) {
|
|
1455
|
-
handlers.onDrop?.(data);
|
|
1456
|
-
} else {
|
|
1457
|
-
const handler = handlers[name];
|
|
1458
|
-
if (handler) {
|
|
1459
|
-
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1460
|
-
pointerMissed(
|
|
1461
|
-
event,
|
|
1462
|
-
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1463
|
-
);
|
|
1464
|
-
handler(data);
|
|
1465
|
-
}
|
|
1466
|
-
} else {
|
|
1467
|
-
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1468
|
-
pointerMissed(
|
|
1469
|
-
event,
|
|
1470
|
-
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1471
|
-
);
|
|
1200
|
+
const wrappedCallback = (frameState, delta) => {
|
|
1201
|
+
const localState = store.getState();
|
|
1202
|
+
const mergedState = {
|
|
1203
|
+
...localState,
|
|
1204
|
+
time: frameState.time,
|
|
1205
|
+
delta: frameState.delta,
|
|
1206
|
+
elapsed: frameState.elapsed,
|
|
1207
|
+
frame: frameState.frame
|
|
1208
|
+
};
|
|
1209
|
+
callbackRef.current?.(mergedState, delta);
|
|
1210
|
+
};
|
|
1211
|
+
const unregister = scheduler$1.register(wrappedCallback, {
|
|
1212
|
+
id,
|
|
1213
|
+
rootId,
|
|
1214
|
+
...options
|
|
1215
|
+
});
|
|
1216
|
+
return () => {
|
|
1217
|
+
unregister();
|
|
1218
|
+
if (isLegacyPriority) {
|
|
1219
|
+
const currentState = store.getState();
|
|
1220
|
+
if (currentState.internal) {
|
|
1221
|
+
currentState.internal.priority--;
|
|
1222
|
+
let parentRoot = currentState.previousRoot;
|
|
1223
|
+
while (parentRoot) {
|
|
1224
|
+
const parentState = parentRoot.getState();
|
|
1225
|
+
if (parentState?.internal) parentState.internal.priority--;
|
|
1226
|
+
parentRoot = parentState?.previousRoot;
|
|
1472
1227
|
}
|
|
1473
1228
|
}
|
|
1474
1229
|
}
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1230
|
+
};
|
|
1231
|
+
} else {
|
|
1232
|
+
return scheduler$1.register(
|
|
1233
|
+
(state, delta) => {
|
|
1234
|
+
const frameState = state;
|
|
1235
|
+
if (!frameState.renderer) return;
|
|
1236
|
+
callbackRef.current?.(frameState, delta);
|
|
1237
|
+
},
|
|
1238
|
+
{ id, ...options }
|
|
1239
|
+
);
|
|
1484
1240
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
onDragEnter: ["dragenter", false],
|
|
1494
|
-
onDragLeave: ["dragleave", false],
|
|
1495
|
-
onDragOver: ["dragover", false],
|
|
1496
|
-
onDrop: ["drop", false],
|
|
1497
|
-
onWheel: ["wheel", true],
|
|
1498
|
-
onPointerDown: ["pointerdown", true],
|
|
1499
|
-
onPointerUp: ["pointerup", true],
|
|
1500
|
-
onPointerLeave: ["pointerleave", true],
|
|
1501
|
-
onPointerMove: ["pointermove", true],
|
|
1502
|
-
onPointerCancel: ["pointercancel", true],
|
|
1503
|
-
onLostPointerCapture: ["lostpointercapture", true]
|
|
1504
|
-
};
|
|
1505
|
-
function createPointerEvents(store) {
|
|
1506
|
-
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1507
|
-
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1508
|
-
const xrPointers = /* @__PURE__ */ new Map();
|
|
1509
|
-
return {
|
|
1510
|
-
priority: 1,
|
|
1511
|
-
enabled: true,
|
|
1512
|
-
frameTimedRaycasts: true,
|
|
1513
|
-
alwaysFireOnScroll: true,
|
|
1514
|
-
updateOnFrame: false,
|
|
1515
|
-
compute(event, state) {
|
|
1516
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1517
|
-
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
1518
|
-
},
|
|
1519
|
-
connected: void 0,
|
|
1520
|
-
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
1521
|
-
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1522
|
-
{}
|
|
1241
|
+
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
1242
|
+
const isPaused = React__namespace.useSyncExternalStore(
|
|
1243
|
+
// Subscribe function
|
|
1244
|
+
React__namespace.useCallback(
|
|
1245
|
+
(onStoreChange) => {
|
|
1246
|
+
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
1247
|
+
},
|
|
1248
|
+
[id]
|
|
1523
1249
|
),
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
const pointerId = nextXRPointerId++;
|
|
1577
|
-
xrPointers.set(pointerId, config);
|
|
1578
|
-
const { internal } = store.getState();
|
|
1579
|
-
getPointerState(internal, pointerId);
|
|
1580
|
-
return pointerId;
|
|
1581
|
-
},
|
|
1582
|
-
unregisterPointer: (pointerId) => {
|
|
1583
|
-
xrPointers.delete(pointerId);
|
|
1584
|
-
const { internal } = store.getState();
|
|
1585
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1586
|
-
if (pointerState) {
|
|
1587
|
-
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1588
|
-
const eventObject = hoveredObj.eventObject;
|
|
1589
|
-
const instance = eventObject.__r3f;
|
|
1590
|
-
if (instance?.eventCount) {
|
|
1591
|
-
const handlers = instance.handlers;
|
|
1592
|
-
const data = { ...hoveredObj, intersections: [] };
|
|
1593
|
-
handlers.onPointerOut?.(data);
|
|
1594
|
-
handlers.onPointerLeave?.(data);
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
internal.pointerMap.delete(pointerId);
|
|
1598
|
-
}
|
|
1599
|
-
internal.pointerDirty.delete(pointerId);
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1250
|
+
// getSnapshot function
|
|
1251
|
+
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
1252
|
+
// getServerSnapshot function (SSR)
|
|
1253
|
+
React__namespace.useCallback(() => false, [])
|
|
1254
|
+
);
|
|
1255
|
+
const controls = React__namespace.useMemo(() => {
|
|
1256
|
+
const scheduler2 = scheduler.getScheduler();
|
|
1257
|
+
return {
|
|
1258
|
+
/** The job's unique ID */
|
|
1259
|
+
id,
|
|
1260
|
+
/**
|
|
1261
|
+
* Access to the global scheduler for frame loop control.
|
|
1262
|
+
* Use for controlling the entire frame loop, adding phases, etc.
|
|
1263
|
+
*/
|
|
1264
|
+
scheduler: scheduler2,
|
|
1265
|
+
/**
|
|
1266
|
+
* Manually step this job only.
|
|
1267
|
+
* Bypasses FPS limiting - always runs.
|
|
1268
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1269
|
+
*/
|
|
1270
|
+
step: (timestamp) => {
|
|
1271
|
+
scheduler.getScheduler().stepJob(id, timestamp);
|
|
1272
|
+
},
|
|
1273
|
+
/**
|
|
1274
|
+
* Manually step ALL jobs in the scheduler.
|
|
1275
|
+
* Useful for frameloop='never' mode.
|
|
1276
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1277
|
+
*/
|
|
1278
|
+
stepAll: (timestamp) => {
|
|
1279
|
+
scheduler.getScheduler().step(timestamp);
|
|
1280
|
+
},
|
|
1281
|
+
/**
|
|
1282
|
+
* Pause this job (set enabled=false).
|
|
1283
|
+
* Job remains registered but won't run.
|
|
1284
|
+
*/
|
|
1285
|
+
pause: () => {
|
|
1286
|
+
scheduler.getScheduler().pauseJob(id);
|
|
1287
|
+
},
|
|
1288
|
+
/**
|
|
1289
|
+
* Resume this job (set enabled=true).
|
|
1290
|
+
*/
|
|
1291
|
+
resume: () => {
|
|
1292
|
+
scheduler.getScheduler().resumeJob(id);
|
|
1293
|
+
},
|
|
1294
|
+
/**
|
|
1295
|
+
* Reactive paused state - automatically updates when pause/resume is called.
|
|
1296
|
+
* No need for forceUpdate() in your components.
|
|
1297
|
+
*/
|
|
1298
|
+
isPaused
|
|
1299
|
+
};
|
|
1300
|
+
}, [id, isPaused]);
|
|
1301
|
+
return controls;
|
|
1602
1302
|
}
|
|
1603
1303
|
|
|
1604
|
-
const
|
|
1605
|
-
function
|
|
1606
|
-
if (typeof
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
if (shownNotices.has(heading)) return;
|
|
1610
|
-
shownNotices.add(heading);
|
|
1611
|
-
const caller = getCallerFrame();
|
|
1612
|
-
if (caller) {
|
|
1613
|
-
console.log();
|
|
1614
|
-
}
|
|
1615
|
-
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
1616
|
-
if (caller) {
|
|
1617
|
-
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
1618
|
-
}
|
|
1619
|
-
if (body || link) {
|
|
1620
|
-
let message = "";
|
|
1621
|
-
if (body) message += body;
|
|
1622
|
-
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
1623
|
-
console.warn(`%c${message}`, "font-weight: bold;");
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
function getCallerFrame(depth = 3) {
|
|
1627
|
-
const stack = new Error().stack;
|
|
1628
|
-
if (!stack) return null;
|
|
1629
|
-
const lines = stack.split("\n");
|
|
1630
|
-
const frame = lines[depth];
|
|
1631
|
-
if (!frame) return null;
|
|
1632
|
-
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
1633
|
-
if (!match) {
|
|
1634
|
-
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
1635
|
-
}
|
|
1636
|
-
if (!match) return null;
|
|
1637
|
-
const [, fn, url, line] = match;
|
|
1638
|
-
return {
|
|
1639
|
-
functionName: fn ?? "<anonymous>",
|
|
1640
|
-
location: formatLocation(url, Number(line))
|
|
1641
|
-
};
|
|
1304
|
+
const IsObject = (url) => url === Object(url) && !Array.isArray(url) && typeof url !== "function";
|
|
1305
|
+
function getUrls(input) {
|
|
1306
|
+
if (typeof input === "string") return [input];
|
|
1307
|
+
if (Array.isArray(input)) return input;
|
|
1308
|
+
return Object.values(input);
|
|
1642
1309
|
}
|
|
1643
|
-
function
|
|
1644
|
-
|
|
1645
|
-
const file = clean.split("/").pop() ?? clean;
|
|
1646
|
-
return `${file}:${line}`;
|
|
1310
|
+
function allUrlsCached(urls, textureCache) {
|
|
1311
|
+
return urls.every((url) => textureCache.has(url));
|
|
1647
1312
|
}
|
|
1648
|
-
function
|
|
1649
|
-
if (typeof
|
|
1650
|
-
return;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1313
|
+
function buildFromCache(input, textureCache) {
|
|
1314
|
+
if (typeof input === "string") {
|
|
1315
|
+
return textureCache.get(input);
|
|
1316
|
+
} else if (Array.isArray(input)) {
|
|
1317
|
+
return input.map((url) => textureCache.get(url));
|
|
1318
|
+
} else {
|
|
1319
|
+
const result = {};
|
|
1320
|
+
const objInput = input;
|
|
1321
|
+
for (const key in objInput) {
|
|
1322
|
+
result[key] = textureCache.get(objInput[key]);
|
|
1323
|
+
}
|
|
1324
|
+
return result;
|
|
1658
1325
|
}
|
|
1659
1326
|
}
|
|
1660
|
-
|
|
1661
|
-
const
|
|
1662
|
-
const
|
|
1663
|
-
const
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1327
|
+
function useTexture(input, optionsOrOnLoad) {
|
|
1328
|
+
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
1329
|
+
const store = useStore();
|
|
1330
|
+
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
1331
|
+
const { onLoad, cache = true } = options;
|
|
1332
|
+
const onLoadRef = React.useRef(onLoad);
|
|
1333
|
+
onLoadRef.current = onLoad;
|
|
1334
|
+
const onLoadCalledForRef = React.useRef(null);
|
|
1335
|
+
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
1336
|
+
const cachedResult = React.useMemo(() => {
|
|
1337
|
+
if (!cache) return null;
|
|
1338
|
+
const textures = store.getState().textures;
|
|
1339
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
1340
|
+
return buildFromCache(input, textures);
|
|
1341
|
+
}, [cache, urls, input, store]);
|
|
1342
|
+
const loadedTextures = useLoader(
|
|
1343
|
+
three.TextureLoader,
|
|
1344
|
+
IsObject(input) ? Object.values(input) : input
|
|
1345
|
+
);
|
|
1346
|
+
const inputKey = urls.join("\0");
|
|
1347
|
+
React.useLayoutEffect(() => {
|
|
1348
|
+
if (cachedResult) return;
|
|
1349
|
+
if (onLoadCalledForRef.current === inputKey) return;
|
|
1350
|
+
onLoadCalledForRef.current = inputKey;
|
|
1351
|
+
onLoadRef.current?.(loadedTextures);
|
|
1352
|
+
}, [cachedResult, loadedTextures, inputKey]);
|
|
1353
|
+
React.useEffect(() => {
|
|
1354
|
+
if (cachedResult) return;
|
|
1355
|
+
if ("initTexture" in renderer) {
|
|
1356
|
+
let textureArray = [];
|
|
1357
|
+
if (Array.isArray(loadedTextures)) {
|
|
1358
|
+
textureArray = loadedTextures;
|
|
1359
|
+
} else if (loadedTextures instanceof three.Texture) {
|
|
1360
|
+
textureArray = [loadedTextures];
|
|
1361
|
+
} else if (IsObject(loadedTextures)) {
|
|
1362
|
+
textureArray = Object.values(loadedTextures);
|
|
1363
|
+
}
|
|
1364
|
+
textureArray.forEach((texture) => {
|
|
1365
|
+
if (texture instanceof three.Texture) {
|
|
1366
|
+
renderer.initTexture(texture);
|
|
1367
|
+
}
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
}, [renderer, loadedTextures, cachedResult]);
|
|
1371
|
+
const mappedTextures = React.useMemo(() => {
|
|
1372
|
+
if (cachedResult) return cachedResult;
|
|
1373
|
+
if (IsObject(input)) {
|
|
1374
|
+
const keyed = {};
|
|
1375
|
+
const textureArray = loadedTextures;
|
|
1376
|
+
let i = 0;
|
|
1377
|
+
for (const key in input) keyed[key] = textureArray[i++];
|
|
1378
|
+
return keyed;
|
|
1379
|
+
} else {
|
|
1380
|
+
return loadedTextures;
|
|
1381
|
+
}
|
|
1382
|
+
}, [input, loadedTextures, cachedResult]);
|
|
1383
|
+
React.useEffect(() => {
|
|
1384
|
+
if (!cache) return;
|
|
1385
|
+
const urlTextureMap = [];
|
|
1386
|
+
if (typeof input === "string") {
|
|
1387
|
+
urlTextureMap.push([input, mappedTextures]);
|
|
1388
|
+
} else if (Array.isArray(input)) {
|
|
1389
|
+
const textureArray = mappedTextures;
|
|
1390
|
+
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
1391
|
+
} else if (IsObject(input)) {
|
|
1392
|
+
const textureRecord = mappedTextures;
|
|
1393
|
+
for (const key in input) {
|
|
1394
|
+
const url = input[key];
|
|
1395
|
+
urlTextureMap.push([url, textureRecord[key]]);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
store.setState((state) => {
|
|
1399
|
+
const refs = new Map(state._textureRefs);
|
|
1400
|
+
let textures = state.textures;
|
|
1401
|
+
let added = false;
|
|
1402
|
+
for (const [url, texture] of urlTextureMap) {
|
|
1403
|
+
if (!textures.has(url)) {
|
|
1404
|
+
if (!added) {
|
|
1405
|
+
textures = new Map(textures);
|
|
1406
|
+
added = true;
|
|
1407
|
+
}
|
|
1408
|
+
textures.set(url, texture);
|
|
1736
1409
|
}
|
|
1410
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
1411
|
+
}
|
|
1412
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
1413
|
+
});
|
|
1414
|
+
return () => store.setState((state) => {
|
|
1415
|
+
const refs = new Map(state._textureRefs);
|
|
1416
|
+
for (const [url] of urlTextureMap) {
|
|
1417
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
1418
|
+
if (next <= 0) refs.delete(url);
|
|
1419
|
+
else refs.set(url, next);
|
|
1420
|
+
}
|
|
1421
|
+
return { _textureRefs: refs };
|
|
1422
|
+
});
|
|
1423
|
+
}, [cache, input, mappedTextures, store]);
|
|
1424
|
+
return mappedTextures;
|
|
1425
|
+
}
|
|
1426
|
+
useTexture.preload = (url) => useLoader.preload(three.TextureLoader, url);
|
|
1427
|
+
useTexture.clear = (input) => useLoader.clear(three.TextureLoader, input);
|
|
1428
|
+
const Texture = ({
|
|
1429
|
+
children,
|
|
1430
|
+
input,
|
|
1431
|
+
onLoad,
|
|
1432
|
+
cache
|
|
1433
|
+
}) => {
|
|
1434
|
+
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
1435
|
+
const ret = useTexture(input, options);
|
|
1436
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
function useTextures(selector) {
|
|
1440
|
+
const store = useStore();
|
|
1441
|
+
const registry = React.useMemo(() => {
|
|
1442
|
+
const getState = store.getState;
|
|
1443
|
+
const setState = store.setState;
|
|
1444
|
+
const getOne = (key) => getState().textures.get(key);
|
|
1445
|
+
return {
|
|
1446
|
+
get all() {
|
|
1447
|
+
return getState().textures;
|
|
1737
1448
|
},
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
top: 0,
|
|
1745
|
-
left: 0,
|
|
1746
|
-
aspect: 0,
|
|
1747
|
-
distance: 0,
|
|
1748
|
-
factor: 0,
|
|
1749
|
-
getCurrentViewport
|
|
1449
|
+
get(input) {
|
|
1450
|
+
if (typeof input === "string") return getOne(input);
|
|
1451
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
1452
|
+
const out = {};
|
|
1453
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
1454
|
+
return out;
|
|
1750
1455
|
},
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
const currentSize = state2.size;
|
|
1760
|
-
const newSize = {
|
|
1761
|
-
width: propW ?? currentSize.width,
|
|
1762
|
-
height: propH ?? currentSize.height,
|
|
1763
|
-
top: currentSize.top,
|
|
1764
|
-
left: currentSize.left
|
|
1765
|
-
};
|
|
1766
|
-
set((s) => ({
|
|
1767
|
-
size: newSize,
|
|
1768
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1769
|
-
}));
|
|
1770
|
-
scheduler.getScheduler().invalidate();
|
|
1771
|
-
}
|
|
1456
|
+
has: (key) => getState().textures.has(key),
|
|
1457
|
+
add(keyOrRecord, texture) {
|
|
1458
|
+
setState((state) => {
|
|
1459
|
+
const textures = new Map(state.textures);
|
|
1460
|
+
if (typeof keyOrRecord === "string") {
|
|
1461
|
+
textures.set(keyOrRecord, texture);
|
|
1462
|
+
} else {
|
|
1463
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
1772
1464
|
}
|
|
1773
|
-
return;
|
|
1465
|
+
return { textures };
|
|
1466
|
+
});
|
|
1467
|
+
},
|
|
1468
|
+
dispose(key, options) {
|
|
1469
|
+
const state = getState();
|
|
1470
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
1471
|
+
if (refs > 0 && !options?.force) {
|
|
1472
|
+
console.warn(
|
|
1473
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
1474
|
+
);
|
|
1475
|
+
return false;
|
|
1774
1476
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
}));
|
|
1785
|
-
scheduler.getScheduler().invalidate();
|
|
1477
|
+
state.textures.get(key)?.dispose();
|
|
1478
|
+
setState((s) => {
|
|
1479
|
+
const textures = new Map(s.textures);
|
|
1480
|
+
textures.delete(key);
|
|
1481
|
+
const nextRefs = new Map(s._textureRefs);
|
|
1482
|
+
nextRefs.delete(key);
|
|
1483
|
+
return { textures, _textureRefs: nextRefs };
|
|
1484
|
+
});
|
|
1485
|
+
return true;
|
|
1786
1486
|
},
|
|
1787
|
-
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1790
|
-
}),
|
|
1791
|
-
setFrameloop: (frameloop = "always") => {
|
|
1792
|
-
set(() => ({ frameloop }));
|
|
1793
|
-
},
|
|
1794
|
-
setError: (error) => set(() => ({ error })),
|
|
1795
|
-
error: null,
|
|
1796
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1797
|
-
uniforms: {},
|
|
1798
|
-
nodes: {},
|
|
1799
|
-
buffers: {},
|
|
1800
|
-
gpuStorage: {},
|
|
1801
|
-
textures: /* @__PURE__ */ new Map(),
|
|
1802
|
-
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1803
|
-
renderPipeline: null,
|
|
1804
|
-
passes: {},
|
|
1805
|
-
_hmrVersion: 0,
|
|
1806
|
-
_sizeImperative: false,
|
|
1807
|
-
_sizeProps: null,
|
|
1808
|
-
previousRoot: void 0,
|
|
1809
|
-
internal: {
|
|
1810
|
-
// Events
|
|
1811
|
-
interaction: [],
|
|
1812
|
-
subscribers: [],
|
|
1813
|
-
// Per-pointer state (new unified structure)
|
|
1814
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
1815
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1816
|
-
lastEvent: React__namespace.createRef(),
|
|
1817
|
-
// Deprecated but kept for backwards compatibility
|
|
1818
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1819
|
-
initialClick: [0, 0],
|
|
1820
|
-
initialHits: [],
|
|
1821
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
1822
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1823
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1824
|
-
// Occlusion system (WebGPU only)
|
|
1825
|
-
occlusionEnabled: false,
|
|
1826
|
-
occlusionObserver: null,
|
|
1827
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1828
|
-
helperGroup: null,
|
|
1829
|
-
// Updates
|
|
1830
|
-
active: false,
|
|
1831
|
-
frames: 0,
|
|
1832
|
-
priority: 0,
|
|
1833
|
-
subscribe: (ref, priority, store) => {
|
|
1834
|
-
const internal = get().internal;
|
|
1835
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1836
|
-
internal.subscribers.push({ ref, priority, store });
|
|
1837
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1838
|
-
return () => {
|
|
1839
|
-
const internal2 = get().internal;
|
|
1840
|
-
if (internal2?.subscribers) {
|
|
1841
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1842
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1843
|
-
}
|
|
1844
|
-
};
|
|
1845
|
-
},
|
|
1846
|
-
// Renderer Storage (single source of truth)
|
|
1847
|
-
actualRenderer: null,
|
|
1848
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1849
|
-
scheduler: null
|
|
1487
|
+
disposeAll() {
|
|
1488
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
1489
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
1850
1490
|
}
|
|
1851
1491
|
};
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
const
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
const currentState = rootStore.getState();
|
|
1858
|
-
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1859
|
-
const stack = new Error().stack || "";
|
|
1860
|
-
const isInternalAccess = stack.includes("zustand") || stack.includes("setState") || stack.includes("Object.assign") || stack.includes("react-three-fiber/packages/fiber/src/core");
|
|
1861
|
-
if (!isInternalAccess) {
|
|
1862
|
-
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1863
|
-
notifyDepreciated({
|
|
1864
|
-
heading: "Accessing state.gl in WebGPU mode",
|
|
1865
|
-
body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
return currentState.internal.actualRenderer;
|
|
1870
|
-
},
|
|
1871
|
-
set(value) {
|
|
1872
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1873
|
-
},
|
|
1874
|
-
enumerable: true,
|
|
1875
|
-
configurable: true
|
|
1876
|
-
});
|
|
1877
|
-
Object.defineProperty(state, "renderer", {
|
|
1878
|
-
get() {
|
|
1879
|
-
return rootStore.getState().internal.actualRenderer;
|
|
1880
|
-
},
|
|
1881
|
-
set(value) {
|
|
1882
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1883
|
-
},
|
|
1884
|
-
enumerable: true,
|
|
1885
|
-
configurable: true
|
|
1886
|
-
});
|
|
1887
|
-
let oldScene = state.scene;
|
|
1888
|
-
rootStore.subscribe(() => {
|
|
1889
|
-
const currentState = rootStore.getState();
|
|
1890
|
-
const { scene, rootScene, set } = currentState;
|
|
1891
|
-
if (scene !== oldScene) {
|
|
1892
|
-
oldScene = scene;
|
|
1893
|
-
if (scene?.isScene && scene !== rootScene) {
|
|
1894
|
-
set({ rootScene: scene });
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
-
let oldSize = state.size;
|
|
1899
|
-
let oldDpr = state.viewport.dpr;
|
|
1900
|
-
let oldCamera = state.camera;
|
|
1901
|
-
rootStore.subscribe(() => {
|
|
1902
|
-
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1903
|
-
const actualRenderer = internal.actualRenderer;
|
|
1904
|
-
const canvasTarget = internal.canvasTarget;
|
|
1905
|
-
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1906
|
-
oldSize = size;
|
|
1907
|
-
oldDpr = viewport.dpr;
|
|
1908
|
-
updateCamera(camera, size);
|
|
1909
|
-
if (internal.isSecondary && canvasTarget) {
|
|
1910
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1911
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1912
|
-
} else {
|
|
1913
|
-
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1914
|
-
actualRenderer.setSize(size.width, size.height, false);
|
|
1915
|
-
if (canvasTarget) {
|
|
1916
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1917
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
if (camera !== oldCamera) {
|
|
1922
|
-
oldCamera = camera;
|
|
1923
|
-
const { rootScene } = rootStore.getState();
|
|
1924
|
-
if (camera && rootScene && !camera.parent) {
|
|
1925
|
-
rootScene.add(camera);
|
|
1926
|
-
}
|
|
1927
|
-
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1928
|
-
const currentState = rootStore.getState();
|
|
1929
|
-
if (currentState.autoUpdateFrustum && camera) {
|
|
1930
|
-
updateFrustum(camera, currentState.frustum);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
rootStore.subscribe((state2) => invalidate(state2));
|
|
1935
|
-
return rootStore;
|
|
1936
|
-
};
|
|
1492
|
+
}, [store]);
|
|
1493
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
1494
|
+
const selected = useThree(subscribe);
|
|
1495
|
+
return selector ? selected : registry;
|
|
1496
|
+
}
|
|
1937
1497
|
|
|
1938
|
-
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1498
|
+
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
1499
|
+
const isLegacy = useThree((s) => s.isLegacy);
|
|
1500
|
+
const size = useThree((s) => s.size);
|
|
1501
|
+
let width;
|
|
1502
|
+
let height;
|
|
1503
|
+
let opts;
|
|
1504
|
+
if (typeof widthOrOptions === "object") {
|
|
1505
|
+
opts = widthOrOptions;
|
|
1506
|
+
} else if (typeof widthOrOptions === "number") {
|
|
1507
|
+
width = widthOrOptions;
|
|
1508
|
+
if (typeof heightOrOptions === "object") {
|
|
1509
|
+
height = widthOrOptions;
|
|
1510
|
+
opts = heightOrOptions;
|
|
1511
|
+
} else if (typeof heightOrOptions === "number") {
|
|
1512
|
+
height = heightOrOptions;
|
|
1513
|
+
opts = options;
|
|
1514
|
+
} else {
|
|
1515
|
+
height = widthOrOptions;
|
|
1946
1516
|
}
|
|
1947
|
-
return loader;
|
|
1948
1517
|
}
|
|
1949
|
-
return
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
if (extensions) extensions(loader);
|
|
1955
|
-
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1956
|
-
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1957
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1958
|
-
return data;
|
|
1959
|
-
});
|
|
1960
|
-
}
|
|
1961
|
-
return new Promise(
|
|
1962
|
-
(res, reject) => loader.load(
|
|
1963
|
-
input,
|
|
1964
|
-
(data) => {
|
|
1965
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1966
|
-
res(data);
|
|
1967
|
-
},
|
|
1968
|
-
onProgress,
|
|
1969
|
-
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1970
|
-
)
|
|
1971
|
-
);
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
1975
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1976
|
-
const fn = loadingFn(extensions, onProgress);
|
|
1977
|
-
const results = keys.map((key) => suspendReact.suspend(fn, [loader, key], { equal: is.equ }));
|
|
1978
|
-
return Array.isArray(input) ? results : results[0];
|
|
1518
|
+
return React.useMemo(() => {
|
|
1519
|
+
const w = width ?? size.width;
|
|
1520
|
+
const h = height ?? size.height;
|
|
1521
|
+
return new three.WebGLRenderTarget(w, h, opts);
|
|
1522
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
1979
1523
|
}
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1524
|
+
|
|
1525
|
+
const presetsObj = {
|
|
1526
|
+
apartment: "lebombo_1k.hdr",
|
|
1527
|
+
city: "potsdamer_platz_1k.hdr",
|
|
1528
|
+
dawn: "kiara_1_dawn_1k.hdr",
|
|
1529
|
+
forest: "forest_slope_1k.hdr",
|
|
1530
|
+
lobby: "st_fagans_interior_1k.hdr",
|
|
1531
|
+
night: "dikhololo_night_1k.hdr",
|
|
1532
|
+
park: "rooitou_park_1k.hdr",
|
|
1533
|
+
studio: "studio_small_03_1k.hdr",
|
|
1534
|
+
sunset: "venice_sunset_1k.hdr",
|
|
1535
|
+
warehouse: "empty_warehouse_01_1k.hdr"
|
|
1987
1536
|
};
|
|
1988
|
-
useLoader.loader = getLoader;
|
|
1989
1537
|
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
const
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
}
|
|
2024
|
-
notifyDepreciated({
|
|
2025
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
2026
|
-
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within update phase, use: useFrame(callback, { priority: number })',
|
|
2027
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2028
|
-
});
|
|
1538
|
+
const CUBEMAP_ROOT = "https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/";
|
|
1539
|
+
const isArray = (arr) => Array.isArray(arr);
|
|
1540
|
+
const defaultFiles = ["/px.png", "/nx.png", "/py.png", "/ny.png", "/pz.png", "/nz.png"];
|
|
1541
|
+
function useEnvironment({
|
|
1542
|
+
files = defaultFiles,
|
|
1543
|
+
path = "",
|
|
1544
|
+
preset = void 0,
|
|
1545
|
+
colorSpace = void 0,
|
|
1546
|
+
extensions
|
|
1547
|
+
} = {}) {
|
|
1548
|
+
if (preset) {
|
|
1549
|
+
validatePreset(preset);
|
|
1550
|
+
files = presetsObj[preset];
|
|
1551
|
+
path = CUBEMAP_ROOT;
|
|
1552
|
+
}
|
|
1553
|
+
const multiFile = isArray(files);
|
|
1554
|
+
const { extension, isCubemap } = getExtension(files);
|
|
1555
|
+
const loader = getLoader(extension);
|
|
1556
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1557
|
+
const renderer = useThree((state) => state.renderer);
|
|
1558
|
+
React.useLayoutEffect(() => {
|
|
1559
|
+
if (extension !== "webp" && extension !== "jpg" && extension !== "jpeg") return;
|
|
1560
|
+
function clearGainmapTexture() {
|
|
1561
|
+
useLoader.clear(loader, multiFile ? [files] : files);
|
|
1562
|
+
}
|
|
1563
|
+
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
1564
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
1565
|
+
const loaderResult = useLoader(
|
|
1566
|
+
loader,
|
|
1567
|
+
multiFile ? [files] : files,
|
|
1568
|
+
(loader2) => {
|
|
1569
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1570
|
+
loader2.setRenderer?.(renderer);
|
|
2029
1571
|
}
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
const mergedState = {
|
|
2033
|
-
...localState,
|
|
2034
|
-
time: frameState.time,
|
|
2035
|
-
delta: frameState.delta,
|
|
2036
|
-
elapsed: frameState.elapsed,
|
|
2037
|
-
frame: frameState.frame
|
|
2038
|
-
};
|
|
2039
|
-
callbackRef.current?.(mergedState, delta);
|
|
2040
|
-
};
|
|
2041
|
-
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2042
|
-
id,
|
|
2043
|
-
rootId,
|
|
2044
|
-
...options
|
|
2045
|
-
});
|
|
2046
|
-
return () => {
|
|
2047
|
-
unregister();
|
|
2048
|
-
if (isLegacyPriority) {
|
|
2049
|
-
const currentState = store.getState();
|
|
2050
|
-
if (currentState.internal) {
|
|
2051
|
-
currentState.internal.priority--;
|
|
2052
|
-
let parentRoot = currentState.previousRoot;
|
|
2053
|
-
while (parentRoot) {
|
|
2054
|
-
const parentState = parentRoot.getState();
|
|
2055
|
-
if (parentState?.internal) parentState.internal.priority--;
|
|
2056
|
-
parentRoot = parentState?.previousRoot;
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
} else {
|
|
2062
|
-
return scheduler$1.register(
|
|
2063
|
-
(state, delta) => {
|
|
2064
|
-
const frameState = state;
|
|
2065
|
-
if (!frameState.renderer) return;
|
|
2066
|
-
callbackRef.current?.(frameState, delta);
|
|
2067
|
-
},
|
|
2068
|
-
{ id, ...options }
|
|
2069
|
-
);
|
|
1572
|
+
loader2.setPath?.(path);
|
|
1573
|
+
if (extensions) extensions(loader2);
|
|
2070
1574
|
}
|
|
2071
|
-
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2072
|
-
const isPaused = React__namespace.useSyncExternalStore(
|
|
2073
|
-
// Subscribe function
|
|
2074
|
-
React__namespace.useCallback(
|
|
2075
|
-
(onStoreChange) => {
|
|
2076
|
-
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2077
|
-
},
|
|
2078
|
-
[id]
|
|
2079
|
-
),
|
|
2080
|
-
// getSnapshot function
|
|
2081
|
-
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2082
|
-
// getServerSnapshot function (SSR)
|
|
2083
|
-
React__namespace.useCallback(() => false, [])
|
|
2084
1575
|
);
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
1576
|
+
let texture = multiFile ? (
|
|
1577
|
+
// @ts-ignore
|
|
1578
|
+
loaderResult[0]
|
|
1579
|
+
) : loaderResult;
|
|
1580
|
+
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
1581
|
+
texture = texture.renderTarget?.texture;
|
|
1582
|
+
}
|
|
1583
|
+
texture.mapping = isCubemap ? three.CubeReflectionMapping : three.EquirectangularReflectionMapping;
|
|
1584
|
+
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
1585
|
+
return texture;
|
|
1586
|
+
}
|
|
1587
|
+
const preloadDefaultOptions = {
|
|
1588
|
+
files: defaultFiles,
|
|
1589
|
+
path: "",
|
|
1590
|
+
preset: void 0,
|
|
1591
|
+
extensions: void 0
|
|
1592
|
+
};
|
|
1593
|
+
useEnvironment.preload = (preloadOptions) => {
|
|
1594
|
+
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
1595
|
+
let { files, path = "" } = options;
|
|
1596
|
+
const { preset, extensions } = options;
|
|
1597
|
+
if (preset) {
|
|
1598
|
+
validatePreset(preset);
|
|
1599
|
+
files = presetsObj[preset];
|
|
1600
|
+
path = CUBEMAP_ROOT;
|
|
1601
|
+
}
|
|
1602
|
+
const { extension } = getExtension(files);
|
|
1603
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1604
|
+
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
1605
|
+
}
|
|
1606
|
+
const loader = getLoader(extension);
|
|
1607
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1608
|
+
useLoader.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
1609
|
+
loader2.setPath?.(path);
|
|
1610
|
+
if (extensions) extensions(loader2);
|
|
1611
|
+
});
|
|
1612
|
+
};
|
|
1613
|
+
const clearDefaultOptins = {
|
|
1614
|
+
files: defaultFiles,
|
|
1615
|
+
preset: void 0
|
|
1616
|
+
};
|
|
1617
|
+
useEnvironment.clear = (clearOptions) => {
|
|
1618
|
+
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
1619
|
+
let { files } = options;
|
|
1620
|
+
const { preset } = options;
|
|
1621
|
+
if (preset) {
|
|
1622
|
+
validatePreset(preset);
|
|
1623
|
+
files = presetsObj[preset];
|
|
1624
|
+
}
|
|
1625
|
+
const { extension } = getExtension(files);
|
|
1626
|
+
const loader = getLoader(extension);
|
|
1627
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1628
|
+
useLoader.clear(loader, isArray(files) ? [files] : files);
|
|
1629
|
+
};
|
|
1630
|
+
function validatePreset(preset) {
|
|
1631
|
+
if (!(preset in presetsObj)) throw new Error("Preset must be one of: " + Object.keys(presetsObj).join(", "));
|
|
1632
|
+
}
|
|
1633
|
+
function getExtension(files) {
|
|
1634
|
+
const isCubemap = isArray(files) && files.length === 6;
|
|
1635
|
+
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
1636
|
+
const firstEntry = isArray(files) ? files[0] : files;
|
|
1637
|
+
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();
|
|
1638
|
+
return { extension, isCubemap, isGainmap };
|
|
1639
|
+
}
|
|
1640
|
+
function getLoader(extension) {
|
|
1641
|
+
const loader = extension === "cube" ? three.CubeTextureLoader : extension === "hdr" ? HDRLoader_js.HDRLoader : extension === "exr" ? EXRLoader_js.EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader_js.UltraHDRLoader : extension === "webp" ? gainmapJs.GainMapLoader : null;
|
|
1642
|
+
return loader;
|
|
2132
1643
|
}
|
|
2133
1644
|
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
if (
|
|
2137
|
-
|
|
2138
|
-
return Object.values(input);
|
|
1645
|
+
function useStore() {
|
|
1646
|
+
const store = React.useContext(context);
|
|
1647
|
+
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
1648
|
+
return store;
|
|
2139
1649
|
}
|
|
2140
|
-
function
|
|
2141
|
-
return
|
|
1650
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
1651
|
+
return useStore()(selector, equalityFn);
|
|
2142
1652
|
}
|
|
2143
|
-
function
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
return input.map((url) => textureCache.get(url));
|
|
2148
|
-
} else {
|
|
2149
|
-
const result = {};
|
|
2150
|
-
const objInput = input;
|
|
2151
|
-
for (const key in objInput) {
|
|
2152
|
-
result[key] = textureCache.get(objInput[key]);
|
|
2153
|
-
}
|
|
2154
|
-
return result;
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
function useTexture(input, optionsOrOnLoad) {
|
|
2158
|
-
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2159
|
-
const store = useStore();
|
|
2160
|
-
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2161
|
-
const { onLoad, cache = true } = options;
|
|
2162
|
-
const onLoadRef = React.useRef(onLoad);
|
|
2163
|
-
onLoadRef.current = onLoad;
|
|
2164
|
-
const onLoadCalledForRef = React.useRef(null);
|
|
2165
|
-
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2166
|
-
const cachedResult = React.useMemo(() => {
|
|
2167
|
-
if (!cache) return null;
|
|
2168
|
-
const textures = store.getState().textures;
|
|
2169
|
-
if (!allUrlsCached(urls, textures)) return null;
|
|
2170
|
-
return buildFromCache(input, textures);
|
|
2171
|
-
}, [cache, urls, input, store]);
|
|
2172
|
-
const loadedTextures = useLoader(
|
|
2173
|
-
three.TextureLoader,
|
|
2174
|
-
IsObject(input) ? Object.values(input) : input
|
|
2175
|
-
);
|
|
2176
|
-
const inputKey = urls.join("\0");
|
|
2177
|
-
React.useLayoutEffect(() => {
|
|
2178
|
-
if (cachedResult) return;
|
|
2179
|
-
if (onLoadCalledForRef.current === inputKey) return;
|
|
2180
|
-
onLoadCalledForRef.current = inputKey;
|
|
2181
|
-
onLoadRef.current?.(loadedTextures);
|
|
2182
|
-
}, [cachedResult, loadedTextures, inputKey]);
|
|
2183
|
-
React.useEffect(() => {
|
|
2184
|
-
if (cachedResult) return;
|
|
2185
|
-
if ("initTexture" in renderer) {
|
|
2186
|
-
let textureArray = [];
|
|
2187
|
-
if (Array.isArray(loadedTextures)) {
|
|
2188
|
-
textureArray = loadedTextures;
|
|
2189
|
-
} else if (loadedTextures instanceof three.Texture) {
|
|
2190
|
-
textureArray = [loadedTextures];
|
|
2191
|
-
} else if (IsObject(loadedTextures)) {
|
|
2192
|
-
textureArray = Object.values(loadedTextures);
|
|
2193
|
-
}
|
|
2194
|
-
textureArray.forEach((texture) => {
|
|
2195
|
-
if (texture instanceof three.Texture) {
|
|
2196
|
-
renderer.initTexture(texture);
|
|
2197
|
-
}
|
|
2198
|
-
});
|
|
2199
|
-
}
|
|
2200
|
-
}, [renderer, loadedTextures, cachedResult]);
|
|
2201
|
-
const mappedTextures = React.useMemo(() => {
|
|
2202
|
-
if (cachedResult) return cachedResult;
|
|
2203
|
-
if (IsObject(input)) {
|
|
2204
|
-
const keyed = {};
|
|
2205
|
-
const textureArray = loadedTextures;
|
|
2206
|
-
let i = 0;
|
|
2207
|
-
for (const key in input) keyed[key] = textureArray[i++];
|
|
2208
|
-
return keyed;
|
|
2209
|
-
} else {
|
|
2210
|
-
return loadedTextures;
|
|
2211
|
-
}
|
|
2212
|
-
}, [input, loadedTextures, cachedResult]);
|
|
2213
|
-
React.useEffect(() => {
|
|
2214
|
-
if (!cache) return;
|
|
2215
|
-
const urlTextureMap = [];
|
|
2216
|
-
if (typeof input === "string") {
|
|
2217
|
-
urlTextureMap.push([input, mappedTextures]);
|
|
2218
|
-
} else if (Array.isArray(input)) {
|
|
2219
|
-
const textureArray = mappedTextures;
|
|
2220
|
-
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
2221
|
-
} else if (IsObject(input)) {
|
|
2222
|
-
const textureRecord = mappedTextures;
|
|
2223
|
-
for (const key in input) {
|
|
2224
|
-
const url = input[key];
|
|
2225
|
-
urlTextureMap.push([url, textureRecord[key]]);
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
store.setState((state) => {
|
|
2229
|
-
const refs = new Map(state._textureRefs);
|
|
2230
|
-
let textures = state.textures;
|
|
2231
|
-
let added = false;
|
|
2232
|
-
for (const [url, texture] of urlTextureMap) {
|
|
2233
|
-
if (!textures.has(url)) {
|
|
2234
|
-
if (!added) {
|
|
2235
|
-
textures = new Map(textures);
|
|
2236
|
-
added = true;
|
|
2237
|
-
}
|
|
2238
|
-
textures.set(url, texture);
|
|
2239
|
-
}
|
|
2240
|
-
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2241
|
-
}
|
|
2242
|
-
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2243
|
-
});
|
|
2244
|
-
return () => store.setState((state) => {
|
|
2245
|
-
const refs = new Map(state._textureRefs);
|
|
2246
|
-
for (const [url] of urlTextureMap) {
|
|
2247
|
-
const next = (refs.get(url) ?? 0) - 1;
|
|
2248
|
-
if (next <= 0) refs.delete(url);
|
|
2249
|
-
else refs.set(url, next);
|
|
2250
|
-
}
|
|
2251
|
-
return { _textureRefs: refs };
|
|
2252
|
-
});
|
|
2253
|
-
}, [cache, input, mappedTextures, store]);
|
|
2254
|
-
return mappedTextures;
|
|
2255
|
-
}
|
|
2256
|
-
useTexture.preload = (url) => useLoader.preload(three.TextureLoader, url);
|
|
2257
|
-
useTexture.clear = (input) => useLoader.clear(three.TextureLoader, input);
|
|
2258
|
-
const Texture = ({
|
|
2259
|
-
children,
|
|
2260
|
-
input,
|
|
2261
|
-
onLoad,
|
|
2262
|
-
cache
|
|
2263
|
-
}) => {
|
|
2264
|
-
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
2265
|
-
const ret = useTexture(input, options);
|
|
2266
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
2267
|
-
};
|
|
2268
|
-
|
|
2269
|
-
function useTextures(selector) {
|
|
2270
|
-
const store = useStore();
|
|
2271
|
-
const registry = React.useMemo(() => {
|
|
2272
|
-
const getState = store.getState;
|
|
2273
|
-
const setState = store.setState;
|
|
2274
|
-
const getOne = (key) => getState().textures.get(key);
|
|
2275
|
-
return {
|
|
2276
|
-
get all() {
|
|
2277
|
-
return getState().textures;
|
|
2278
|
-
},
|
|
2279
|
-
get(input) {
|
|
2280
|
-
if (typeof input === "string") return getOne(input);
|
|
2281
|
-
if (Array.isArray(input)) return input.map(getOne);
|
|
2282
|
-
const out = {};
|
|
2283
|
-
for (const name in input) out[name] = getOne(input[name]);
|
|
2284
|
-
return out;
|
|
2285
|
-
},
|
|
2286
|
-
has: (key) => getState().textures.has(key),
|
|
2287
|
-
add(keyOrRecord, texture) {
|
|
2288
|
-
setState((state) => {
|
|
2289
|
-
const textures = new Map(state.textures);
|
|
2290
|
-
if (typeof keyOrRecord === "string") {
|
|
2291
|
-
textures.set(keyOrRecord, texture);
|
|
2292
|
-
} else {
|
|
2293
|
-
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2294
|
-
}
|
|
2295
|
-
return { textures };
|
|
2296
|
-
});
|
|
2297
|
-
},
|
|
2298
|
-
dispose(key, options) {
|
|
2299
|
-
const state = getState();
|
|
2300
|
-
const refs = state._textureRefs.get(key) ?? 0;
|
|
2301
|
-
if (refs > 0 && !options?.force) {
|
|
2302
|
-
console.warn(
|
|
2303
|
-
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2304
|
-
);
|
|
2305
|
-
return false;
|
|
2306
|
-
}
|
|
2307
|
-
state.textures.get(key)?.dispose();
|
|
2308
|
-
setState((s) => {
|
|
2309
|
-
const textures = new Map(s.textures);
|
|
2310
|
-
textures.delete(key);
|
|
2311
|
-
const nextRefs = new Map(s._textureRefs);
|
|
2312
|
-
nextRefs.delete(key);
|
|
2313
|
-
return { textures, _textureRefs: nextRefs };
|
|
2314
|
-
});
|
|
2315
|
-
return true;
|
|
2316
|
-
},
|
|
2317
|
-
disposeAll() {
|
|
2318
|
-
for (const texture of getState().textures.values()) texture.dispose();
|
|
2319
|
-
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2320
|
-
}
|
|
2321
|
-
};
|
|
2322
|
-
}, [store]);
|
|
2323
|
-
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2324
|
-
const selected = useThree(subscribe);
|
|
2325
|
-
return selector ? selected : registry;
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2329
|
-
const isLegacy = useThree((s) => s.isLegacy);
|
|
2330
|
-
const size = useThree((s) => s.size);
|
|
2331
|
-
let width;
|
|
2332
|
-
let height;
|
|
2333
|
-
let opts;
|
|
2334
|
-
if (typeof widthOrOptions === "object") {
|
|
2335
|
-
opts = widthOrOptions;
|
|
2336
|
-
} else if (typeof widthOrOptions === "number") {
|
|
2337
|
-
width = widthOrOptions;
|
|
2338
|
-
if (typeof heightOrOptions === "object") {
|
|
2339
|
-
height = widthOrOptions;
|
|
2340
|
-
opts = heightOrOptions;
|
|
2341
|
-
} else if (typeof heightOrOptions === "number") {
|
|
2342
|
-
height = heightOrOptions;
|
|
2343
|
-
opts = options;
|
|
2344
|
-
} else {
|
|
2345
|
-
height = widthOrOptions;
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
return React.useMemo(() => {
|
|
2349
|
-
const w = width ?? size.width;
|
|
2350
|
-
const h = height ?? size.height;
|
|
2351
|
-
return new three.WebGLRenderTarget(w, h, opts);
|
|
2352
|
-
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
function useStore() {
|
|
2356
|
-
const store = React.useContext(context);
|
|
2357
|
-
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
2358
|
-
return store;
|
|
2359
|
-
}
|
|
2360
|
-
function useThree(selector = (state) => state, equalityFn) {
|
|
2361
|
-
return useStore()(selector, equalityFn);
|
|
2362
|
-
}
|
|
2363
|
-
function useInstanceHandle(ref) {
|
|
2364
|
-
const instance = React.useRef(null);
|
|
2365
|
-
React.useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
2366
|
-
return instance;
|
|
1653
|
+
function useInstanceHandle(ref) {
|
|
1654
|
+
const instance = React.useRef(null);
|
|
1655
|
+
React.useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
1656
|
+
return instance;
|
|
2367
1657
|
}
|
|
2368
1658
|
function useGraph(object) {
|
|
2369
1659
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
2370
1660
|
}
|
|
2371
1661
|
|
|
1662
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
1663
|
+
|
|
2372
1664
|
let effectId = 0;
|
|
2373
1665
|
function addEffect(callback) {
|
|
2374
1666
|
notifyDepreciated({
|
|
@@ -2403,7 +1695,7 @@ function advance(timestamp) {
|
|
|
2403
1695
|
scheduler.getScheduler().step(timestamp);
|
|
2404
1696
|
}
|
|
2405
1697
|
|
|
2406
|
-
const version = "10.0.0-alpha.
|
|
1698
|
+
const version = "10.0.0-alpha.3";
|
|
2407
1699
|
const packageData = {
|
|
2408
1700
|
version: version};
|
|
2409
1701
|
|
|
@@ -13460,206 +12752,789 @@ Check the top-level render call using <` + i + ">.");
|
|
|
13460
12752
|
var o = 1 << 31 - vn(n);
|
|
13461
12753
|
e.entanglements[1] |= o, n &= ~o;
|
|
13462
12754
|
}
|
|
13463
|
-
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12755
|
+
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12756
|
+
}
|
|
12757
|
+
}
|
|
12758
|
+
break;
|
|
12759
|
+
case 31:
|
|
12760
|
+
case 13:
|
|
12761
|
+
n = On(e, 2), n !== null && We(n, e, 2), Ls(), rl(e, 2);
|
|
12762
|
+
}
|
|
12763
|
+
}, le.batchedUpdates = function(e, n) {
|
|
12764
|
+
return e(n);
|
|
12765
|
+
}, le.createComponentSelector = function(e) {
|
|
12766
|
+
return { $$typeof: pm, value: e };
|
|
12767
|
+
}, le.createContainer = function(e, n, o, i, s, u, f, p, g, S) {
|
|
12768
|
+
return Ka(e, n, false, null, o, i, u, null, f, p, g, S);
|
|
12769
|
+
}, le.createHasPseudoClassSelector = function(e) {
|
|
12770
|
+
return { $$typeof: hm, value: e };
|
|
12771
|
+
}, le.createHydrationContainer = function(e, n, o, i, s, u, f, p, g, S, T, _, I, O) {
|
|
12772
|
+
return e = Ka(o, i, true, e, s, u, p, O, g, S, T, _), e.context = Dh(null), o = e.current, i = Nt(o), i = Xo(i), s = zo(i), s.callback = n ?? null, Mt(o, s, i), ur(i, "hydrateRoot()", null), n = i, e.current.lanes = n, Ci(e, n), Kn(e), e;
|
|
12773
|
+
}, le.createPortal = function(e, n, o) {
|
|
12774
|
+
var i = 3 < arguments.length && arguments[3] !== void 0 ? arguments[3] : null;
|
|
12775
|
+
try {
|
|
12776
|
+
vt(i);
|
|
12777
|
+
var s = false;
|
|
12778
|
+
} catch {
|
|
12779
|
+
s = true;
|
|
12780
|
+
}
|
|
12781
|
+
return s && (console.error("The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", typeof Symbol == "function" && Symbol.toStringTag && i[Symbol.toStringTag] || i.constructor.name || "Object"), vt(i)), { $$typeof: Ao, key: i == null ? null : "" + i, children: e, containerInfo: n, implementation: o };
|
|
12782
|
+
}, le.createRoleSelector = function(e) {
|
|
12783
|
+
return { $$typeof: mm, value: e };
|
|
12784
|
+
}, le.createTestNameSelector = function(e) {
|
|
12785
|
+
return { $$typeof: gm, value: e };
|
|
12786
|
+
}, le.createTextSelector = function(e) {
|
|
12787
|
+
return { $$typeof: ym, value: e };
|
|
12788
|
+
}, le.defaultOnCaughtError = function(e) {
|
|
12789
|
+
var n = bd ? "The above error occurred in the <" + bd + "> component." : "The above error occurred in one of your React components.", o = "React will try to recreate this component tree from scratch using the error boundary you provided, " + ((Cg || "Anonymous") + ".");
|
|
12790
|
+
typeof e == "object" && e !== null && typeof e.environmentName == "string" ? ri("error", [`%o
|
|
12791
|
+
|
|
12792
|
+
%s
|
|
12793
|
+
|
|
12794
|
+
%s
|
|
12795
|
+
`, e, n, o], e.environmentName)() : console.error(`%o
|
|
12796
|
+
|
|
12797
|
+
%s
|
|
12798
|
+
|
|
12799
|
+
%s
|
|
12800
|
+
`, e, n, o);
|
|
12801
|
+
}, le.defaultOnRecoverableError = function(e) {
|
|
12802
|
+
qg(e);
|
|
12803
|
+
}, le.defaultOnUncaughtError = function(e) {
|
|
12804
|
+
qg(e), console.warn(`%s
|
|
12805
|
+
|
|
12806
|
+
%s
|
|
12807
|
+
`, bd ? "An error occurred in the <" + bd + "> component." : "An error occurred in one of your React components.", `Consider adding an error boundary to your tree to customize error handling behavior.
|
|
12808
|
+
Visit https://react.dev/link/error-boundaries to learn more about error boundaries.`);
|
|
12809
|
+
}, le.deferredUpdates = function(e) {
|
|
12810
|
+
var n = x.T, o = wt();
|
|
12811
|
+
try {
|
|
12812
|
+
return an(32), x.T = null, e();
|
|
12813
|
+
} finally {
|
|
12814
|
+
an(o), x.T = n;
|
|
12815
|
+
}
|
|
12816
|
+
}, le.discreteUpdates = function(e, n, o, i, s) {
|
|
12817
|
+
var u = x.T, f = wt();
|
|
12818
|
+
try {
|
|
12819
|
+
return an(2), x.T = null, e(n, o, i, s);
|
|
12820
|
+
} finally {
|
|
12821
|
+
an(f), x.T = u, ye === Jn && (Pp = me() + Fg);
|
|
12822
|
+
}
|
|
12823
|
+
}, le.findAllNodes = kc, le.findBoundingRects = function(e, n) {
|
|
12824
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12825
|
+
n = kc(e, n), e = [];
|
|
12826
|
+
for (var o = 0; o < n.length; o++) e.push(ma(n[o]));
|
|
12827
|
+
for (n = e.length - 1; 0 < n; n--) {
|
|
12828
|
+
o = e[n];
|
|
12829
|
+
for (var i = o.x, s = i + o.width, u = o.y, f = u + o.height, p = n - 1; 0 <= p; p--) if (n !== p) {
|
|
12830
|
+
var g = e[p], S = g.x, T = S + g.width, _ = g.y, I = _ + g.height;
|
|
12831
|
+
if (i >= S && u >= _ && s <= T && f <= I) {
|
|
12832
|
+
e.splice(n, 1);
|
|
12833
|
+
break;
|
|
12834
|
+
} else if (i !== S || o.width !== g.width || I < u || _ > f) {
|
|
12835
|
+
if (!(u !== _ || o.height !== g.height || T < i || S > s)) {
|
|
12836
|
+
S > i && (g.width += S - i, g.x = i), T < s && (g.width = s - S), e.splice(n, 1);
|
|
12837
|
+
break;
|
|
12838
|
+
}
|
|
12839
|
+
} else {
|
|
12840
|
+
_ > u && (g.height += _ - u, g.y = u), I < f && (g.height = f - _), e.splice(n, 1);
|
|
12841
|
+
break;
|
|
12842
|
+
}
|
|
12843
|
+
}
|
|
12844
|
+
}
|
|
12845
|
+
return e;
|
|
12846
|
+
}, le.findHostInstance = function(e) {
|
|
12847
|
+
var n = e._reactInternals;
|
|
12848
|
+
if (n === void 0) throw typeof e.render == "function" ? Error("Unable to find node on an unmounted component.") : (e = Object.keys(e).join(","), Error("Argument appears to not be a ReactComponent. Keys: " + e));
|
|
12849
|
+
return e = mu(n), e === null ? null : ot(e.stateNode);
|
|
12850
|
+
}, le.findHostInstanceWithNoPortals = function(e) {
|
|
12851
|
+
return e = Ed(e), e = e !== null ? _p(e) : null, e === null ? null : ot(e.stateNode);
|
|
12852
|
+
}, le.findHostInstanceWithWarning = function(e, n) {
|
|
12853
|
+
var o = e._reactInternals;
|
|
12854
|
+
if (o === void 0) throw typeof e.render == "function" ? Error("Unable to find node on an unmounted component.") : (e = Object.keys(e).join(","), Error("Argument appears to not be a ReactComponent. Keys: " + e));
|
|
12855
|
+
if (e = mu(o), e === null) return null;
|
|
12856
|
+
if (e.mode & 8) {
|
|
12857
|
+
var i = G(o) || "Component";
|
|
12858
|
+
mb[i] || (mb[i] = true, B(e, function() {
|
|
12859
|
+
o.mode & 8 ? console.error("%s is deprecated in StrictMode. %s was passed an instance of %s which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node", n, n, i) : console.error("%s is deprecated in StrictMode. %s was passed an instance of %s which renders StrictMode children. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node", n, n, i);
|
|
12860
|
+
}));
|
|
12861
|
+
}
|
|
12862
|
+
return ot(e.stateNode);
|
|
12863
|
+
}, le.flushPassiveEffects = el, le.flushSyncFromReconciler = function(e) {
|
|
12864
|
+
var n = ye;
|
|
12865
|
+
ye |= 1;
|
|
12866
|
+
var o = x.T, i = wt();
|
|
12867
|
+
try {
|
|
12868
|
+
if (an(2), x.T = null, e) return e();
|
|
12869
|
+
} finally {
|
|
12870
|
+
an(i), x.T = o, ye = n, (ye & (Zn | uo)) === Jn && Wa(0);
|
|
12871
|
+
}
|
|
12872
|
+
}, le.flushSyncWork = Ls, le.focusWithin = function(e, n) {
|
|
12873
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12874
|
+
for (e = Ef(e), n = hh(e, n), n = Array.from(n), e = 0; e < n.length; ) {
|
|
12875
|
+
var o = n[e++], i = o.tag;
|
|
12876
|
+
if (!Kr(o)) {
|
|
12877
|
+
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
12878
|
+
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
12879
|
+
}
|
|
12880
|
+
}
|
|
12881
|
+
return false;
|
|
12882
|
+
}, le.getFindAllNodesFailureDescription = function(e, n) {
|
|
12883
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12884
|
+
var o = 0, i = [];
|
|
12885
|
+
e = [Ef(e), 0];
|
|
12886
|
+
for (var s = 0; s < e.length; ) {
|
|
12887
|
+
var u = e[s++], f = u.tag, p = e[s++], g = n[p];
|
|
12888
|
+
if ((f !== 5 && f !== 26 && f !== 27 || !Kr(u)) && (If(u, g) && (i.push(Sc(g)), p++, p > o && (o = p)), p < n.length)) for (u = u.child; u !== null; ) e.push(u, p), u = u.sibling;
|
|
12889
|
+
}
|
|
12890
|
+
if (o < n.length) {
|
|
12891
|
+
for (e = []; o < n.length; o++) e.push(Sc(n[o]));
|
|
12892
|
+
return `findAllNodes was able to match part of the selector:
|
|
12893
|
+
` + (i.join(" > ") + `
|
|
12894
|
+
|
|
12895
|
+
No matching component was found for:
|
|
12896
|
+
`) + e.join(" > ");
|
|
12897
|
+
}
|
|
12898
|
+
return null;
|
|
12899
|
+
}, le.getPublicRootInstance = function(e) {
|
|
12900
|
+
if (e = e.current, !e.child) return null;
|
|
12901
|
+
switch (e.child.tag) {
|
|
12902
|
+
case 27:
|
|
12903
|
+
case 5:
|
|
12904
|
+
return ot(e.child.stateNode);
|
|
12905
|
+
default:
|
|
12906
|
+
return e.child.stateNode;
|
|
12907
|
+
}
|
|
12908
|
+
}, le.injectIntoDevTools = function() {
|
|
12909
|
+
var e = { bundleType: 1, version: Jt, rendererPackageName: Zt, currentDispatcherRef: x, reconcilerVersion: "19.2.0" };
|
|
12910
|
+
return jo !== null && (e.rendererConfig = jo), e.overrideHookState = gb, e.overrideHookStateDeletePath = yb, e.overrideHookStateRenamePath = bb, e.overrideProps = vb, e.overridePropsDeletePath = Sb, e.overridePropsRenamePath = kb, e.scheduleUpdate = wb, e.scheduleRetry = Pb, e.setErrorHandler = xb, e.setSuspenseHandler = zb, e.scheduleRefresh = hu, e.scheduleRoot = Fl, e.setRefreshHandler = Ir, e.getCurrentFiber = Ic, Ep(e);
|
|
12911
|
+
}, le.isAlreadyRendering = Ns, le.observeVisibleRects = function(e, n, o, i) {
|
|
12912
|
+
function s() {
|
|
12913
|
+
var S = kc(e, n);
|
|
12914
|
+
u.forEach(function(T) {
|
|
12915
|
+
0 > S.indexOf(T) && g(T);
|
|
12916
|
+
}), S.forEach(function(T) {
|
|
12917
|
+
0 > u.indexOf(T) && p(T);
|
|
12918
|
+
});
|
|
12919
|
+
}
|
|
12920
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12921
|
+
var u = kc(e, n);
|
|
12922
|
+
o = zr(u, o, i);
|
|
12923
|
+
var f = o.disconnect, p = o.observe, g = o.unobserve;
|
|
12924
|
+
return bm.push(s), { disconnect: function() {
|
|
12925
|
+
var S = bm.indexOf(s);
|
|
12926
|
+
0 <= S && bm.splice(S, 1), f();
|
|
12927
|
+
} };
|
|
12928
|
+
}, le.shouldError = function(e) {
|
|
12929
|
+
return pu(e);
|
|
12930
|
+
}, le.shouldSuspend = function(e) {
|
|
12931
|
+
return fu(e);
|
|
12932
|
+
}, le.startHostTransition = function(e, n, o, i) {
|
|
12933
|
+
if (e.tag !== 5) throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");
|
|
12934
|
+
var s = uf(e).queue;
|
|
12935
|
+
Hp(e), nt(e, s, n, Xt, o === null ? Em : function() {
|
|
12936
|
+
x.T === null && console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");
|
|
12937
|
+
var u = uf(e);
|
|
12938
|
+
return u.next === null && (u = e.alternate.memoizedState), qi(e, u.next.queue, {}, Nt(e)), o(i);
|
|
12939
|
+
});
|
|
12940
|
+
}, le.updateContainer = function(e, n, o, i) {
|
|
12941
|
+
var s = n.current, u = Nt(s);
|
|
12942
|
+
return As(s, u, e, n, o, i), u;
|
|
12943
|
+
}, le.updateContainerSync = Wh, le;
|
|
12944
|
+
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true }));
|
|
12945
|
+
})(Mg)), Mg.exports;
|
|
12946
|
+
}
|
|
12947
|
+
var Eb;
|
|
12948
|
+
function n0() {
|
|
12949
|
+
return Eb || (Eb = 1, process.env.NODE_ENV === "production" ? Rm.exports = Kb() : Rm.exports = e0()), Rm.exports;
|
|
12950
|
+
}
|
|
12951
|
+
var t0 = n0();
|
|
12952
|
+
const r0 = Xb(t0);
|
|
12953
|
+
|
|
12954
|
+
const DEFAULT_POINTER_ID = 0;
|
|
12955
|
+
const XR_POINTER_ID_START = 1e3;
|
|
12956
|
+
function getPointerState(internal, pointerId) {
|
|
12957
|
+
let state = internal.pointerMap.get(pointerId);
|
|
12958
|
+
if (!state) {
|
|
12959
|
+
state = {
|
|
12960
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
12961
|
+
captured: /* @__PURE__ */ new Map(),
|
|
12962
|
+
initialClick: [0, 0],
|
|
12963
|
+
initialHits: []
|
|
12964
|
+
};
|
|
12965
|
+
internal.pointerMap.set(pointerId, state);
|
|
12966
|
+
}
|
|
12967
|
+
return state;
|
|
12968
|
+
}
|
|
12969
|
+
function getPointerId(event) {
|
|
12970
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
12971
|
+
}
|
|
12972
|
+
function makeId(event) {
|
|
12973
|
+
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
12974
|
+
}
|
|
12975
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
12976
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
12977
|
+
if (!pointerState) return;
|
|
12978
|
+
const captureData = pointerState.captured.get(obj);
|
|
12979
|
+
if (captureData) {
|
|
12980
|
+
pointerState.captured.delete(obj);
|
|
12981
|
+
try {
|
|
12982
|
+
captureData.target.releasePointerCapture?.(pointerId);
|
|
12983
|
+
} catch {
|
|
12984
|
+
}
|
|
12985
|
+
}
|
|
12986
|
+
}
|
|
12987
|
+
function swapInteractivity(store, object, newObject) {
|
|
12988
|
+
const { internal } = store.getState();
|
|
12989
|
+
for (let i = 0; i < internal.interaction.length; i++) {
|
|
12990
|
+
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
12991
|
+
}
|
|
12992
|
+
for (const pointerState of internal.pointerMap.values()) {
|
|
12993
|
+
for (let i = 0; i < pointerState.initialHits.length; i++) {
|
|
12994
|
+
if (pointerState.initialHits[i] === object) pointerState.initialHits[i] = newObject;
|
|
12995
|
+
}
|
|
12996
|
+
pointerState.hovered.forEach((value, key) => {
|
|
12997
|
+
if (value.eventObject === object || value.object === object) {
|
|
12998
|
+
pointerState.hovered.delete(key);
|
|
12999
|
+
const next = {
|
|
13000
|
+
...value,
|
|
13001
|
+
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
13002
|
+
object: value.object === object ? newObject : value.object
|
|
13003
|
+
};
|
|
13004
|
+
pointerState.hovered.set(makeId(next), next);
|
|
13005
|
+
}
|
|
13006
|
+
});
|
|
13007
|
+
const captureData = pointerState.captured.get(object);
|
|
13008
|
+
if (captureData) {
|
|
13009
|
+
pointerState.captured.delete(object);
|
|
13010
|
+
pointerState.captured.set(newObject, {
|
|
13011
|
+
...captureData,
|
|
13012
|
+
intersection: {
|
|
13013
|
+
...captureData.intersection,
|
|
13014
|
+
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
13015
|
+
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
13016
|
+
}
|
|
13017
|
+
});
|
|
13018
|
+
}
|
|
13019
|
+
}
|
|
13020
|
+
unregisterVisibility(store, object);
|
|
13021
|
+
}
|
|
13022
|
+
function removeInteractivity(store, object) {
|
|
13023
|
+
const { internal } = store.getState();
|
|
13024
|
+
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
13025
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
13026
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
13027
|
+
pointerState.hovered.forEach((value, key) => {
|
|
13028
|
+
if (value.eventObject === object || value.object === object) {
|
|
13029
|
+
pointerState.hovered.delete(key);
|
|
13030
|
+
}
|
|
13031
|
+
});
|
|
13032
|
+
if (pointerState.captured.has(object)) {
|
|
13033
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
13034
|
+
}
|
|
13035
|
+
}
|
|
13036
|
+
unregisterVisibility(store, object);
|
|
13037
|
+
}
|
|
13038
|
+
function createEvents(store) {
|
|
13039
|
+
function calculateDistance(event, pointerId) {
|
|
13040
|
+
const { internal } = store.getState();
|
|
13041
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13042
|
+
if (!pointerState) return 0;
|
|
13043
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
13044
|
+
const dx = event.offsetX - initialX;
|
|
13045
|
+
const dy = event.offsetY - initialY;
|
|
13046
|
+
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
13047
|
+
}
|
|
13048
|
+
function filterPointerEvents(objects) {
|
|
13049
|
+
return objects.filter(
|
|
13050
|
+
(obj) => ["Move", "Over", "Enter", "Out", "Leave"].some(
|
|
13051
|
+
(name) => obj.__r3f?.handlers["onPointer" + name]
|
|
13052
|
+
) || ["OverEnter", "OverLeave", "Over"].some(
|
|
13053
|
+
(name) => obj.__r3f?.handlers["onDrag" + name]
|
|
13054
|
+
) || obj.__r3f?.handlers.onDrop
|
|
13055
|
+
);
|
|
13056
|
+
}
|
|
13057
|
+
function intersect(event, filter) {
|
|
13058
|
+
const state = store.getState();
|
|
13059
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
13060
|
+
const intersections = [];
|
|
13061
|
+
const eventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
|
|
13062
|
+
for (let i = 0; i < eventsObjects.length; i++) {
|
|
13063
|
+
const state2 = getRootState(eventsObjects[i]);
|
|
13064
|
+
if (state2) {
|
|
13065
|
+
state2.raycaster.camera = void 0;
|
|
13066
|
+
}
|
|
13067
|
+
}
|
|
13068
|
+
if (!state.previousRoot) {
|
|
13069
|
+
state.events.compute?.(event, state);
|
|
13070
|
+
}
|
|
13071
|
+
function handleRaycast(obj) {
|
|
13072
|
+
const state2 = getRootState(obj);
|
|
13073
|
+
if (!state2 || !state2.events.enabled || state2.raycaster.camera === null) return [];
|
|
13074
|
+
if (state2.raycaster.camera === void 0) {
|
|
13075
|
+
state2.events.compute?.(event, state2, state2.previousRoot?.getState());
|
|
13076
|
+
if (state2.raycaster.camera === void 0) state2.raycaster.camera = null;
|
|
13077
|
+
}
|
|
13078
|
+
if (!state2.raycaster.camera) return [];
|
|
13079
|
+
obj.updateWorldMatrix(true, true);
|
|
13080
|
+
return state2.raycaster.intersectObject(obj, true);
|
|
13081
|
+
}
|
|
13082
|
+
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
13083
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
13084
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
13085
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
13086
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
13087
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
13088
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
13089
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
13090
|
+
}
|
|
13091
|
+
}
|
|
13092
|
+
const aState = getRootState(a.object);
|
|
13093
|
+
const bState = getRootState(b.object);
|
|
13094
|
+
const aPriority = aState?.events?.priority ?? 1;
|
|
13095
|
+
const bPriority = bState?.events?.priority ?? 1;
|
|
13096
|
+
return bPriority - aPriority || a.distance - b.distance;
|
|
13097
|
+
}).filter((item) => {
|
|
13098
|
+
const id = makeId(item);
|
|
13099
|
+
if (duplicates.has(id)) return false;
|
|
13100
|
+
duplicates.add(id);
|
|
13101
|
+
return true;
|
|
13102
|
+
});
|
|
13103
|
+
if (state.events.filter) hits = state.events.filter(hits, state);
|
|
13104
|
+
for (const hit of hits) {
|
|
13105
|
+
let eventObject = hit.object;
|
|
13106
|
+
while (eventObject) {
|
|
13107
|
+
if (eventObject.__r3f?.eventCount) {
|
|
13108
|
+
intersections.push({ ...hit, eventObject });
|
|
13109
|
+
}
|
|
13110
|
+
eventObject = eventObject.parent;
|
|
13111
|
+
}
|
|
13112
|
+
}
|
|
13113
|
+
if ("pointerId" in event) {
|
|
13114
|
+
const pointerId = event.pointerId;
|
|
13115
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
13116
|
+
if (pointerState?.captured.size) {
|
|
13117
|
+
for (const captureData of pointerState.captured.values()) {
|
|
13118
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
13119
|
+
}
|
|
13120
|
+
}
|
|
13121
|
+
}
|
|
13122
|
+
return intersections;
|
|
13123
|
+
}
|
|
13124
|
+
function handleIntersects(intersections, event, delta, callback) {
|
|
13125
|
+
if (intersections.length) {
|
|
13126
|
+
const localState = { stopped: false };
|
|
13127
|
+
for (const hit of intersections) {
|
|
13128
|
+
const state = getRootState(hit.object);
|
|
13129
|
+
if (state) {
|
|
13130
|
+
const { raycaster, pointer, camera, internal } = state;
|
|
13131
|
+
const unprojectedPoint = new three.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
13132
|
+
const hasPointerCapture = (id) => {
|
|
13133
|
+
const pointerState = internal.pointerMap.get(id);
|
|
13134
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
13135
|
+
};
|
|
13136
|
+
const setPointerCapture = (id) => {
|
|
13137
|
+
const captureData = { intersection: hit, target: event.target };
|
|
13138
|
+
const pointerState = getPointerState(internal, id);
|
|
13139
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
13140
|
+
event.target.setPointerCapture(id);
|
|
13141
|
+
};
|
|
13142
|
+
const releasePointerCapture = (id) => {
|
|
13143
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
13144
|
+
};
|
|
13145
|
+
const extractEventProps = {};
|
|
13146
|
+
for (const prop in event) {
|
|
13147
|
+
const property = event[prop];
|
|
13148
|
+
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
13149
|
+
}
|
|
13150
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
13151
|
+
const raycastEvent = {
|
|
13152
|
+
...hit,
|
|
13153
|
+
...extractEventProps,
|
|
13154
|
+
pointer,
|
|
13155
|
+
intersections,
|
|
13156
|
+
stopped: localState.stopped,
|
|
13157
|
+
delta,
|
|
13158
|
+
unprojectedPoint,
|
|
13159
|
+
ray: raycaster.ray,
|
|
13160
|
+
camera,
|
|
13161
|
+
pointerId: eventPointerId,
|
|
13162
|
+
// Hijack stopPropagation, which just sets a flag
|
|
13163
|
+
stopPropagation() {
|
|
13164
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
13165
|
+
if (
|
|
13166
|
+
// ...if this pointer hasn't been captured
|
|
13167
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
13168
|
+
pointerState.captured.has(hit.eventObject)
|
|
13169
|
+
) {
|
|
13170
|
+
raycastEvent.stopped = localState.stopped = true;
|
|
13171
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
13172
|
+
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
13173
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
13174
|
+
}
|
|
13464
13175
|
}
|
|
13465
|
-
}
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
13176
|
+
},
|
|
13177
|
+
// there should be a distinction between target and currentTarget
|
|
13178
|
+
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13179
|
+
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13180
|
+
nativeEvent: event
|
|
13181
|
+
};
|
|
13182
|
+
callback(raycastEvent);
|
|
13183
|
+
if (localState.stopped === true) break;
|
|
13470
13184
|
}
|
|
13471
|
-
}
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
13185
|
+
}
|
|
13186
|
+
}
|
|
13187
|
+
return intersections;
|
|
13188
|
+
}
|
|
13189
|
+
function cancelPointer(intersections, pointerId) {
|
|
13190
|
+
const { internal } = store.getState();
|
|
13191
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
13192
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
13193
|
+
if (!pointerState) return;
|
|
13194
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
13195
|
+
if (!intersections.length || !intersections.find(
|
|
13196
|
+
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
13197
|
+
)) {
|
|
13198
|
+
const eventObject = hoveredObj.eventObject;
|
|
13199
|
+
const instance = eventObject.__r3f;
|
|
13200
|
+
pointerState.hovered.delete(hoveredId);
|
|
13201
|
+
if (instance?.eventCount) {
|
|
13202
|
+
const handlers = instance.handlers;
|
|
13203
|
+
const data = { ...hoveredObj, intersections };
|
|
13204
|
+
handlers.onPointerOut?.(data);
|
|
13205
|
+
handlers.onPointerLeave?.(data);
|
|
13206
|
+
handlers.onDragOverLeave?.(data);
|
|
13488
13207
|
}
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
|
|
13522
|
-
an(o), x.T = n;
|
|
13208
|
+
}
|
|
13209
|
+
}
|
|
13210
|
+
}
|
|
13211
|
+
function pointerMissed(event, objects) {
|
|
13212
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13213
|
+
const instance = objects[i].__r3f;
|
|
13214
|
+
instance?.handlers.onPointerMissed?.(event);
|
|
13215
|
+
}
|
|
13216
|
+
}
|
|
13217
|
+
function dragOverMissed(event, objects) {
|
|
13218
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13219
|
+
const instance = objects[i].__r3f;
|
|
13220
|
+
instance?.handlers.onDragOverMissed?.(event);
|
|
13221
|
+
}
|
|
13222
|
+
}
|
|
13223
|
+
function dropMissed(event, objects) {
|
|
13224
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13225
|
+
const instance = objects[i].__r3f;
|
|
13226
|
+
instance?.handlers.onDropMissed?.(event);
|
|
13227
|
+
}
|
|
13228
|
+
}
|
|
13229
|
+
function cleanupPointer(pointerId) {
|
|
13230
|
+
const { internal } = store.getState();
|
|
13231
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13232
|
+
if (pointerState) {
|
|
13233
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13234
|
+
const eventObject = hoveredObj.eventObject;
|
|
13235
|
+
const instance = eventObject.__r3f;
|
|
13236
|
+
if (instance?.eventCount) {
|
|
13237
|
+
const handlers = instance.handlers;
|
|
13238
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13239
|
+
handlers.onPointerOut?.(data);
|
|
13240
|
+
handlers.onPointerLeave?.(data);
|
|
13523
13241
|
}
|
|
13524
|
-
}
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
13242
|
+
}
|
|
13243
|
+
internal.pointerMap.delete(pointerId);
|
|
13244
|
+
}
|
|
13245
|
+
internal.pointerDirty.delete(pointerId);
|
|
13246
|
+
}
|
|
13247
|
+
function processDeferredPointer(event, pointerId) {
|
|
13248
|
+
const state = store.getState();
|
|
13249
|
+
const { internal } = state;
|
|
13250
|
+
if (!state.events.enabled) return;
|
|
13251
|
+
const filter = filterPointerEvents;
|
|
13252
|
+
const hits = intersect(event, filter);
|
|
13253
|
+
cancelPointer(hits, pointerId);
|
|
13254
|
+
function onIntersect(data) {
|
|
13255
|
+
const eventObject = data.eventObject;
|
|
13256
|
+
const instance = eventObject.__r3f;
|
|
13257
|
+
if (!instance?.eventCount) return;
|
|
13258
|
+
const handlers = instance.handlers;
|
|
13259
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13260
|
+
const id = makeId(data);
|
|
13261
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
13262
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
13263
|
+
if (!hoveredItem) {
|
|
13264
|
+
pointerState.hovered.set(id, data);
|
|
13265
|
+
handlers.onPointerOver?.(data);
|
|
13266
|
+
handlers.onPointerEnter?.(data);
|
|
13267
|
+
} else if (hoveredItem.stopped) {
|
|
13268
|
+
data.stopPropagation();
|
|
13530
13269
|
}
|
|
13531
|
-
}
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13270
|
+
}
|
|
13271
|
+
handlers.onPointerMove?.(data);
|
|
13272
|
+
}
|
|
13273
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
13274
|
+
}
|
|
13275
|
+
function handlePointer(name) {
|
|
13276
|
+
switch (name) {
|
|
13277
|
+
case "onPointerLeave":
|
|
13278
|
+
case "onDragLeave":
|
|
13279
|
+
return () => cancelPointer([]);
|
|
13280
|
+
// Global cancel of these events
|
|
13281
|
+
case "onPointerCancel":
|
|
13282
|
+
return (event) => {
|
|
13283
|
+
const pointerId = getPointerId(event);
|
|
13284
|
+
cleanupPointer(pointerId);
|
|
13285
|
+
};
|
|
13286
|
+
case "onLostPointerCapture":
|
|
13287
|
+
return (event) => {
|
|
13288
|
+
const { internal } = store.getState();
|
|
13289
|
+
const pointerId = getPointerId(event);
|
|
13290
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13291
|
+
if (pointerState?.captured.size) {
|
|
13292
|
+
requestAnimationFrame(() => {
|
|
13293
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
13294
|
+
if (pointerState2?.captured.size) {
|
|
13295
|
+
pointerState2.captured.clear();
|
|
13546
13296
|
}
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13297
|
+
cancelPointer([], pointerId);
|
|
13298
|
+
});
|
|
13299
|
+
}
|
|
13300
|
+
};
|
|
13301
|
+
}
|
|
13302
|
+
return function handleEvent(event) {
|
|
13303
|
+
const state = store.getState();
|
|
13304
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
13305
|
+
const pointerId = getPointerId(event);
|
|
13306
|
+
internal.lastEvent.current = event;
|
|
13307
|
+
if (!events.enabled) return;
|
|
13308
|
+
const isPointerMove = name === "onPointerMove";
|
|
13309
|
+
const isDragOver = name === "onDragOver";
|
|
13310
|
+
const isDrop = name === "onDrop";
|
|
13311
|
+
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
13312
|
+
const isPointerDown = name === "onPointerDown";
|
|
13313
|
+
const isPointerUp = name === "onPointerUp";
|
|
13314
|
+
const isWheel = name === "onWheel";
|
|
13315
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
13316
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
13317
|
+
events.compute?.(event, state);
|
|
13318
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13319
|
+
return;
|
|
13320
|
+
}
|
|
13321
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
13322
|
+
events.compute?.(event, state);
|
|
13323
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13324
|
+
return;
|
|
13325
|
+
}
|
|
13326
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
13327
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
13328
|
+
internal.pointerDirty.delete(pointerId);
|
|
13329
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
13330
|
+
}
|
|
13331
|
+
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
13332
|
+
const hits = intersect(event, filter);
|
|
13333
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
13334
|
+
if (isPointerDown) {
|
|
13335
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13336
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
13337
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
13338
|
+
}
|
|
13339
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13340
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
13341
|
+
if (isClickEvent && !hits.length) {
|
|
13342
|
+
if (delta <= 2) {
|
|
13343
|
+
pointerMissed(event, internal.interaction);
|
|
13344
|
+
if (onPointerMissed) onPointerMissed(event);
|
|
13345
|
+
}
|
|
13346
|
+
}
|
|
13347
|
+
if (isDragOver && !hits.length) {
|
|
13348
|
+
dragOverMissed(event, internal.interaction);
|
|
13349
|
+
if (onDragOverMissed) onDragOverMissed(event);
|
|
13350
|
+
}
|
|
13351
|
+
if (isDrop && !hits.length) {
|
|
13352
|
+
dropMissed(event, internal.interaction);
|
|
13353
|
+
if (onDropMissed) onDropMissed(event);
|
|
13354
|
+
}
|
|
13355
|
+
if (isPointerMove || isDragOver) {
|
|
13356
|
+
cancelPointer(hits, pointerId);
|
|
13357
|
+
}
|
|
13358
|
+
function onIntersect(data) {
|
|
13359
|
+
const eventObject = data.eventObject;
|
|
13360
|
+
const instance = eventObject.__r3f;
|
|
13361
|
+
if (!instance?.eventCount) return;
|
|
13362
|
+
const handlers = instance.handlers;
|
|
13363
|
+
if (isPointerMove) {
|
|
13364
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13365
|
+
const id = makeId(data);
|
|
13366
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13367
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13368
|
+
if (!hoveredItem) {
|
|
13369
|
+
pointerState2.hovered.set(id, data);
|
|
13370
|
+
handlers.onPointerOver?.(data);
|
|
13371
|
+
handlers.onPointerEnter?.(data);
|
|
13372
|
+
} else if (hoveredItem.stopped) {
|
|
13373
|
+
data.stopPropagation();
|
|
13550
13374
|
}
|
|
13551
13375
|
}
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
if (
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
var o = n[e++], i = o.tag;
|
|
13584
|
-
if (!Kr(o)) {
|
|
13585
|
-
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
13586
|
-
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
13376
|
+
handlers.onPointerMove?.(data);
|
|
13377
|
+
} else if (isDragOver) {
|
|
13378
|
+
const id = makeId(data);
|
|
13379
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13380
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13381
|
+
if (!hoveredItem) {
|
|
13382
|
+
pointerState2.hovered.set(id, data);
|
|
13383
|
+
handlers.onDragOverEnter?.(data);
|
|
13384
|
+
} else if (hoveredItem.stopped) {
|
|
13385
|
+
data.stopPropagation();
|
|
13386
|
+
}
|
|
13387
|
+
handlers.onDragOver?.(data);
|
|
13388
|
+
} else if (isDrop) {
|
|
13389
|
+
handlers.onDrop?.(data);
|
|
13390
|
+
} else {
|
|
13391
|
+
const handler = handlers[name];
|
|
13392
|
+
if (handler) {
|
|
13393
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
13394
|
+
pointerMissed(
|
|
13395
|
+
event,
|
|
13396
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13397
|
+
);
|
|
13398
|
+
handler(data);
|
|
13399
|
+
}
|
|
13400
|
+
} else {
|
|
13401
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
13402
|
+
pointerMissed(
|
|
13403
|
+
event,
|
|
13404
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13405
|
+
);
|
|
13406
|
+
}
|
|
13587
13407
|
}
|
|
13588
13408
|
}
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13409
|
+
}
|
|
13410
|
+
handleIntersects(hits, event, delta, onIntersect);
|
|
13411
|
+
};
|
|
13412
|
+
}
|
|
13413
|
+
function flushDeferredPointers() {
|
|
13414
|
+
const { internal, events } = store.getState();
|
|
13415
|
+
if (!events.frameTimedRaycasts) return;
|
|
13416
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
13417
|
+
processDeferredPointer(event, pointerId);
|
|
13418
|
+
}
|
|
13419
|
+
internal.pointerDirty.clear();
|
|
13420
|
+
}
|
|
13421
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
13422
|
+
}
|
|
13423
|
+
const DOM_EVENTS = {
|
|
13424
|
+
onClick: ["click", false],
|
|
13425
|
+
onContextMenu: ["contextmenu", false],
|
|
13426
|
+
onDoubleClick: ["dblclick", false],
|
|
13427
|
+
onDragEnter: ["dragenter", false],
|
|
13428
|
+
onDragLeave: ["dragleave", false],
|
|
13429
|
+
onDragOver: ["dragover", false],
|
|
13430
|
+
onDrop: ["drop", false],
|
|
13431
|
+
onWheel: ["wheel", true],
|
|
13432
|
+
onPointerDown: ["pointerdown", true],
|
|
13433
|
+
onPointerUp: ["pointerup", true],
|
|
13434
|
+
onPointerLeave: ["pointerleave", true],
|
|
13435
|
+
onPointerMove: ["pointermove", true],
|
|
13436
|
+
onPointerCancel: ["pointercancel", true],
|
|
13437
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
13438
|
+
};
|
|
13439
|
+
function createPointerEvents(store) {
|
|
13440
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
13441
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
13442
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
13443
|
+
return {
|
|
13444
|
+
priority: 1,
|
|
13445
|
+
enabled: true,
|
|
13446
|
+
frameTimedRaycasts: true,
|
|
13447
|
+
alwaysFireOnScroll: true,
|
|
13448
|
+
updateOnFrame: false,
|
|
13449
|
+
compute(event, state) {
|
|
13450
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
13451
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
13452
|
+
},
|
|
13453
|
+
connected: void 0,
|
|
13454
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
13455
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
13456
|
+
{}
|
|
13457
|
+
),
|
|
13458
|
+
update: (pointerId) => {
|
|
13459
|
+
const { events, internal } = store.getState();
|
|
13460
|
+
if (!events.handlers) return;
|
|
13461
|
+
if (pointerId !== void 0) {
|
|
13462
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
13463
|
+
if (event) {
|
|
13464
|
+
internal.pointerDirty.delete(pointerId);
|
|
13465
|
+
processDeferredPointer(event, pointerId);
|
|
13466
|
+
} else if (internal.lastEvent?.current) {
|
|
13467
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
13597
13468
|
}
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
No matching component was found for:
|
|
13604
|
-
`) + e.join(" > ");
|
|
13469
|
+
} else {
|
|
13470
|
+
flushDeferredPointers();
|
|
13471
|
+
if (internal.lastEvent?.current) {
|
|
13472
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13605
13473
|
}
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13474
|
+
}
|
|
13475
|
+
},
|
|
13476
|
+
flush: () => {
|
|
13477
|
+
const { events, internal } = store.getState();
|
|
13478
|
+
flushDeferredPointers();
|
|
13479
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
13480
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13481
|
+
}
|
|
13482
|
+
},
|
|
13483
|
+
connect: (target) => {
|
|
13484
|
+
if (!target) return;
|
|
13485
|
+
const { set, events } = store.getState();
|
|
13486
|
+
events.disconnect?.();
|
|
13487
|
+
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
13488
|
+
if (events.handlers) {
|
|
13489
|
+
for (const name in events.handlers) {
|
|
13490
|
+
const event = events.handlers[name];
|
|
13491
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
13492
|
+
target.addEventListener(eventName, event, { passive });
|
|
13615
13493
|
}
|
|
13616
|
-
}
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
}
|
|
13494
|
+
}
|
|
13495
|
+
},
|
|
13496
|
+
disconnect: () => {
|
|
13497
|
+
const { set, events } = store.getState();
|
|
13498
|
+
if (events.connected) {
|
|
13499
|
+
if (events.handlers) {
|
|
13500
|
+
for (const name in events.handlers) {
|
|
13501
|
+
const event = events.handlers[name];
|
|
13502
|
+
const [eventName] = DOM_EVENTS[name];
|
|
13503
|
+
events.connected.removeEventListener(eventName, event);
|
|
13504
|
+
}
|
|
13627
13505
|
}
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
|
|
13641
|
-
|
|
13642
|
-
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13506
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
13507
|
+
}
|
|
13508
|
+
},
|
|
13509
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
13510
|
+
registerPointer: (config) => {
|
|
13511
|
+
const pointerId = nextXRPointerId++;
|
|
13512
|
+
xrPointers.set(pointerId, config);
|
|
13513
|
+
const { internal } = store.getState();
|
|
13514
|
+
getPointerState(internal, pointerId);
|
|
13515
|
+
return pointerId;
|
|
13516
|
+
},
|
|
13517
|
+
unregisterPointer: (pointerId) => {
|
|
13518
|
+
xrPointers.delete(pointerId);
|
|
13519
|
+
const { internal } = store.getState();
|
|
13520
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13521
|
+
if (pointerState) {
|
|
13522
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13523
|
+
const eventObject = hoveredObj.eventObject;
|
|
13524
|
+
const instance = eventObject.__r3f;
|
|
13525
|
+
if (instance?.eventCount) {
|
|
13526
|
+
const handlers = instance.handlers;
|
|
13527
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13528
|
+
handlers.onPointerOut?.(data);
|
|
13529
|
+
handlers.onPointerLeave?.(data);
|
|
13530
|
+
}
|
|
13531
|
+
}
|
|
13532
|
+
internal.pointerMap.delete(pointerId);
|
|
13533
|
+
}
|
|
13534
|
+
internal.pointerDirty.delete(pointerId);
|
|
13535
|
+
}
|
|
13536
|
+
};
|
|
13658
13537
|
}
|
|
13659
|
-
var t0 = n0();
|
|
13660
|
-
const r0 = Xb(t0);
|
|
13661
|
-
|
|
13662
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13663
13538
|
|
|
13664
13539
|
function createReconciler(config) {
|
|
13665
13540
|
const reconciler2 = r0(config);
|
|
@@ -13824,7 +13699,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
13824
13699
|
}
|
|
13825
13700
|
}
|
|
13826
13701
|
const reconstructed = [];
|
|
13827
|
-
function
|
|
13702
|
+
function flushReconstructedInstances() {
|
|
13703
|
+
if (reconstructed.length === 0) return;
|
|
13704
|
+
try {
|
|
13705
|
+
swapReconstructedInstances();
|
|
13706
|
+
} finally {
|
|
13707
|
+
reconstructed.length = 0;
|
|
13708
|
+
}
|
|
13709
|
+
}
|
|
13710
|
+
function swapReconstructedInstances() {
|
|
13828
13711
|
for (const [instance] of reconstructed) {
|
|
13829
13712
|
const parent = instance.parent;
|
|
13830
13713
|
if (parent) {
|
|
@@ -13842,6 +13725,9 @@ function swapInstances() {
|
|
|
13842
13725
|
}
|
|
13843
13726
|
}
|
|
13844
13727
|
if (instance.isHidden) unhideInstance(instance);
|
|
13728
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13729
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13730
|
+
}
|
|
13845
13731
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
13846
13732
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
13847
13733
|
}
|
|
@@ -13850,10 +13736,16 @@ function swapInstances() {
|
|
|
13850
13736
|
const parent = instance.parent;
|
|
13851
13737
|
if (parent) {
|
|
13852
13738
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13739
|
+
const prevObject = instance.object;
|
|
13853
13740
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
13854
13741
|
instance.object.__r3f = instance;
|
|
13855
13742
|
setFiberRef(fiber, instance.object);
|
|
13743
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13744
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13745
|
+
}
|
|
13856
13746
|
delete instance.appliedOnce;
|
|
13747
|
+
instance.eventCount = 0;
|
|
13748
|
+
instance.handlers = {};
|
|
13857
13749
|
applyProps(instance.object, instance.props);
|
|
13858
13750
|
if (instance.props.attach) {
|
|
13859
13751
|
attach(parent, instance);
|
|
@@ -13870,14 +13762,114 @@ function swapInstances() {
|
|
|
13870
13762
|
invalidateInstance(instance);
|
|
13871
13763
|
}
|
|
13872
13764
|
}
|
|
13873
|
-
reconstructed.length = 0;
|
|
13874
13765
|
}
|
|
13875
13766
|
const handleTextInstance = () => {
|
|
13876
13767
|
};
|
|
13877
13768
|
const NO_CONTEXT = {};
|
|
13878
13769
|
let currentUpdatePriority = NoEventPriority;
|
|
13879
|
-
|
|
13880
|
-
|
|
13770
|
+
function getEventPriority(type) {
|
|
13771
|
+
switch (type) {
|
|
13772
|
+
case "beforetoggle":
|
|
13773
|
+
case "cancel":
|
|
13774
|
+
case "click":
|
|
13775
|
+
case "close":
|
|
13776
|
+
case "contextmenu":
|
|
13777
|
+
case "copy":
|
|
13778
|
+
case "cut":
|
|
13779
|
+
case "auxclick":
|
|
13780
|
+
case "dblclick":
|
|
13781
|
+
case "dragend":
|
|
13782
|
+
case "dragstart":
|
|
13783
|
+
case "drop":
|
|
13784
|
+
case "focusin":
|
|
13785
|
+
case "focusout":
|
|
13786
|
+
case "input":
|
|
13787
|
+
case "invalid":
|
|
13788
|
+
case "keydown":
|
|
13789
|
+
case "keypress":
|
|
13790
|
+
case "keyup":
|
|
13791
|
+
case "mousedown":
|
|
13792
|
+
case "mouseup":
|
|
13793
|
+
case "paste":
|
|
13794
|
+
case "pause":
|
|
13795
|
+
case "play":
|
|
13796
|
+
case "pointercancel":
|
|
13797
|
+
case "pointerdown":
|
|
13798
|
+
case "pointerup":
|
|
13799
|
+
case "ratechange":
|
|
13800
|
+
case "reset":
|
|
13801
|
+
case "resize":
|
|
13802
|
+
case "seeked":
|
|
13803
|
+
case "submit":
|
|
13804
|
+
case "touchcancel":
|
|
13805
|
+
case "touchend":
|
|
13806
|
+
case "touchstart":
|
|
13807
|
+
case "volumechange":
|
|
13808
|
+
case "change":
|
|
13809
|
+
case "selectionchange":
|
|
13810
|
+
case "compositionstart":
|
|
13811
|
+
case "compositionend":
|
|
13812
|
+
case "compositionupdate":
|
|
13813
|
+
case "beforeinput":
|
|
13814
|
+
case "blur":
|
|
13815
|
+
case "fullscreenchange":
|
|
13816
|
+
case "focus":
|
|
13817
|
+
case "hashchange":
|
|
13818
|
+
case "popstate":
|
|
13819
|
+
case "select":
|
|
13820
|
+
case "selectstart":
|
|
13821
|
+
return e;
|
|
13822
|
+
case "drag":
|
|
13823
|
+
case "dragenter":
|
|
13824
|
+
case "dragexit":
|
|
13825
|
+
case "dragleave":
|
|
13826
|
+
case "dragover":
|
|
13827
|
+
case "mousemove":
|
|
13828
|
+
case "mouseout":
|
|
13829
|
+
case "mouseover":
|
|
13830
|
+
case "pointermove":
|
|
13831
|
+
case "pointerout":
|
|
13832
|
+
case "pointerover":
|
|
13833
|
+
case "scroll":
|
|
13834
|
+
case "touchmove":
|
|
13835
|
+
case "wheel":
|
|
13836
|
+
case "mouseenter":
|
|
13837
|
+
case "mouseleave":
|
|
13838
|
+
case "pointerenter":
|
|
13839
|
+
case "pointerleave":
|
|
13840
|
+
return o;
|
|
13841
|
+
case "message": {
|
|
13842
|
+
switch (Tb.unstable_getCurrentPriorityLevel()) {
|
|
13843
|
+
case Tb.unstable_ImmediatePriority:
|
|
13844
|
+
return e;
|
|
13845
|
+
case Tb.unstable_UserBlockingPriority:
|
|
13846
|
+
return o;
|
|
13847
|
+
case Tb.unstable_NormalPriority:
|
|
13848
|
+
case Tb.unstable_LowPriority:
|
|
13849
|
+
return r;
|
|
13850
|
+
case Tb.unstable_IdlePriority:
|
|
13851
|
+
return i$1;
|
|
13852
|
+
default:
|
|
13853
|
+
return r;
|
|
13854
|
+
}
|
|
13855
|
+
}
|
|
13856
|
+
default:
|
|
13857
|
+
return r;
|
|
13858
|
+
}
|
|
13859
|
+
}
|
|
13860
|
+
function scheduleMicrotask(callback) {
|
|
13861
|
+
if (typeof queueMicrotask === "function") {
|
|
13862
|
+
queueMicrotask(callback);
|
|
13863
|
+
} else if (typeof Promise !== "undefined") {
|
|
13864
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
13865
|
+
setTimeout(() => {
|
|
13866
|
+
throw error;
|
|
13867
|
+
});
|
|
13868
|
+
});
|
|
13869
|
+
} else {
|
|
13870
|
+
setTimeout(callback);
|
|
13871
|
+
}
|
|
13872
|
+
}
|
|
13881
13873
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
13882
13874
|
isPrimaryRenderer: false,
|
|
13883
13875
|
warnsIfNotActing: false,
|
|
@@ -13916,16 +13908,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13916
13908
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
13917
13909
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
13918
13910
|
if (reconstruct) {
|
|
13919
|
-
reconstructed.push([instance,
|
|
13911
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
13920
13912
|
} else {
|
|
13921
13913
|
const changedProps = diffProps(instance, newProps);
|
|
13922
|
-
|
|
13923
|
-
|
|
13924
|
-
|
|
13925
|
-
|
|
13914
|
+
const attach2 = instance.props.attach;
|
|
13915
|
+
instance.props = getInstanceProps(newProps);
|
|
13916
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
13917
|
+
else delete instance.props.attach;
|
|
13918
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
13926
13919
|
}
|
|
13927
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
13928
|
-
if (isTailSibling) swapInstances();
|
|
13929
13920
|
},
|
|
13930
13921
|
finalizeInitialChildren: (instance) => {
|
|
13931
13922
|
for (const prop in instance.props) {
|
|
@@ -13950,8 +13941,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13950
13941
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
13951
13942
|
return prepare(target, container, "", {});
|
|
13952
13943
|
},
|
|
13953
|
-
|
|
13954
|
-
|
|
13944
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
13945
|
+
// before layout effects run so refs point to the new objects
|
|
13946
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
13955
13947
|
shouldSetTextContent: () => false,
|
|
13956
13948
|
clearContainer: () => false,
|
|
13957
13949
|
hideInstance,
|
|
@@ -13959,6 +13951,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13959
13951
|
createTextInstance: handleTextInstance,
|
|
13960
13952
|
hideTextInstance: handleTextInstance,
|
|
13961
13953
|
unhideTextInstance: handleTextInstance,
|
|
13954
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
13955
|
+
supportsMicrotasks: true,
|
|
13956
|
+
scheduleMicrotask,
|
|
13962
13957
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
13963
13958
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
13964
13959
|
noTimeout: -1,
|
|
@@ -13999,28 +13994,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13999
13994
|
},
|
|
14000
13995
|
resolveUpdatePriority() {
|
|
14001
13996
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14002
|
-
|
|
14003
|
-
|
|
14004
|
-
|
|
14005
|
-
case "dblclick":
|
|
14006
|
-
case "dragenter":
|
|
14007
|
-
case "dragleave":
|
|
14008
|
-
case "drop":
|
|
14009
|
-
case "pointercancel":
|
|
14010
|
-
case "pointerdown":
|
|
14011
|
-
case "pointerup":
|
|
14012
|
-
return e;
|
|
14013
|
-
case "dragover":
|
|
14014
|
-
case "pointermove":
|
|
14015
|
-
case "pointerout":
|
|
14016
|
-
case "pointerover":
|
|
14017
|
-
case "pointerenter":
|
|
14018
|
-
case "pointerleave":
|
|
14019
|
-
case "wheel":
|
|
14020
|
-
return o;
|
|
14021
|
-
default:
|
|
14022
|
-
return r;
|
|
14023
|
-
}
|
|
13997
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
13998
|
+
if (eventType === void 0) return r;
|
|
13999
|
+
return getEventPriority(eventType);
|
|
14024
14000
|
},
|
|
14025
14001
|
resetFormInstance() {
|
|
14026
14002
|
},
|
|
@@ -14069,11 +14045,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14069
14045
|
cloneMutableTextInstance(textInstance) {
|
|
14070
14046
|
return textInstance;
|
|
14071
14047
|
},
|
|
14048
|
+
// React 19.2 added these for root-level view transitions. They only run for hosts that opt into
|
|
14049
|
+
// view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
|
|
14050
|
+
// into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
|
|
14051
|
+
// React never calls them. They stay as no-ops rather than throws: the host config is shared by
|
|
14052
|
+
// every root, and a throw here would turn a React-internal probe into a hard crash for users.
|
|
14053
|
+
// Guarded by a test asserting a full render + unmount never reaches them.
|
|
14072
14054
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14073
|
-
throw new Error("Not implemented.");
|
|
14074
14055
|
},
|
|
14075
14056
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14076
|
-
throw new Error("Not implemented.");
|
|
14077
14057
|
},
|
|
14078
14058
|
// https://github.com/facebook/react/pull/32465
|
|
14079
14059
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14158,6 +14138,7 @@ function createRoot(canvas) {
|
|
|
14158
14138
|
const lastConfiguredProps = {};
|
|
14159
14139
|
let configured = false;
|
|
14160
14140
|
let pending = null;
|
|
14141
|
+
let rendererSetup = null;
|
|
14161
14142
|
return {
|
|
14162
14143
|
async configure(props = {}) {
|
|
14163
14144
|
let resolve;
|
|
@@ -14188,7 +14169,7 @@ function createRoot(canvas) {
|
|
|
14188
14169
|
forceEven
|
|
14189
14170
|
} = props;
|
|
14190
14171
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
|
|
14191
|
-
|
|
14172
|
+
let state = store.getState();
|
|
14192
14173
|
const defaultGLProps = {
|
|
14193
14174
|
canvas,
|
|
14194
14175
|
powerPreference: "high-performance",
|
|
@@ -14216,9 +14197,21 @@ function createRoot(canvas) {
|
|
|
14216
14197
|
);
|
|
14217
14198
|
}
|
|
14218
14199
|
if (!state.internal.actualRenderer) {
|
|
14219
|
-
|
|
14220
|
-
|
|
14221
|
-
|
|
14200
|
+
if (!rendererSetup) {
|
|
14201
|
+
rendererSetup = (async () => {
|
|
14202
|
+
{
|
|
14203
|
+
renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
|
|
14204
|
+
state.internal.actualRenderer = renderer;
|
|
14205
|
+
state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
|
|
14206
|
+
}
|
|
14207
|
+
})().catch((err) => {
|
|
14208
|
+
rendererSetup = null;
|
|
14209
|
+
throw err;
|
|
14210
|
+
});
|
|
14211
|
+
}
|
|
14212
|
+
await rendererSetup;
|
|
14213
|
+
state = store.getState();
|
|
14214
|
+
renderer = state.internal.actualRenderer;
|
|
14222
14215
|
}
|
|
14223
14216
|
let raycaster = state.raycaster;
|
|
14224
14217
|
if (!raycaster) state.set({ raycaster: raycaster = new three.Raycaster() });
|
|
@@ -14568,7 +14561,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14568
14561
|
dispose(state.scene);
|
|
14569
14562
|
_roots.delete(canvas);
|
|
14570
14563
|
if (callback) callback(canvas);
|
|
14571
|
-
} catch {
|
|
14564
|
+
} catch (error) {
|
|
14565
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
14572
14566
|
}
|
|
14573
14567
|
}, 500);
|
|
14574
14568
|
}
|
|
@@ -14631,6 +14625,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14631
14625
|
viewport = rootState.viewport.getCurrentViewport(camera, new three.Vector3(), resolvedSize);
|
|
14632
14626
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14633
14627
|
}
|
|
14628
|
+
const set = injectState.set;
|
|
14634
14629
|
return {
|
|
14635
14630
|
// The intersect consists of the previous root state
|
|
14636
14631
|
...rootState,
|
|
@@ -14649,7 +14644,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14649
14644
|
size: resolvedSize,
|
|
14650
14645
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14651
14646
|
// Layers are allowed to override events
|
|
14652
|
-
setEvents: (events2) =>
|
|
14647
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
14653
14648
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
14654
14649
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
14655
14650
|
};
|
|
@@ -14678,6 +14673,212 @@ function flushSync(fn) {
|
|
|
14678
14673
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14679
14674
|
}
|
|
14680
14675
|
|
|
14676
|
+
const isRef = (obj) => obj.current && obj.current.isScene;
|
|
14677
|
+
const resolveScene = (scene) => isRef(scene) ? scene.current : scene;
|
|
14678
|
+
function setEnvProps(background, scene, defaultScene, texture, sceneProps = {}) {
|
|
14679
|
+
sceneProps = {
|
|
14680
|
+
backgroundBlurriness: 0,
|
|
14681
|
+
backgroundIntensity: 1,
|
|
14682
|
+
backgroundRotation: [0, 0, 0],
|
|
14683
|
+
environmentIntensity: 1,
|
|
14684
|
+
environmentRotation: [0, 0, 0],
|
|
14685
|
+
...sceneProps
|
|
14686
|
+
};
|
|
14687
|
+
const target = resolveScene(scene || defaultScene);
|
|
14688
|
+
const oldbg = target.background;
|
|
14689
|
+
const oldenv = target.environment;
|
|
14690
|
+
const oldSceneProps = {
|
|
14691
|
+
// @ts-ignore
|
|
14692
|
+
backgroundBlurriness: target.backgroundBlurriness,
|
|
14693
|
+
// @ts-ignore
|
|
14694
|
+
backgroundIntensity: target.backgroundIntensity,
|
|
14695
|
+
// @ts-ignore
|
|
14696
|
+
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
14697
|
+
// @ts-ignore
|
|
14698
|
+
environmentIntensity: target.environmentIntensity,
|
|
14699
|
+
// @ts-ignore
|
|
14700
|
+
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
14701
|
+
};
|
|
14702
|
+
if (background !== "only") target.environment = texture;
|
|
14703
|
+
if (background) target.background = texture;
|
|
14704
|
+
applyProps(target, sceneProps);
|
|
14705
|
+
return () => {
|
|
14706
|
+
if (background !== "only") target.environment = oldenv;
|
|
14707
|
+
if (background) target.background = oldbg;
|
|
14708
|
+
applyProps(target, oldSceneProps);
|
|
14709
|
+
};
|
|
14710
|
+
}
|
|
14711
|
+
function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
14712
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14713
|
+
React__namespace.useLayoutEffect(() => {
|
|
14714
|
+
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
14715
|
+
});
|
|
14716
|
+
return null;
|
|
14717
|
+
}
|
|
14718
|
+
function EnvironmentCube({
|
|
14719
|
+
background = false,
|
|
14720
|
+
scene,
|
|
14721
|
+
blur,
|
|
14722
|
+
backgroundBlurriness,
|
|
14723
|
+
backgroundIntensity,
|
|
14724
|
+
backgroundRotation,
|
|
14725
|
+
environmentIntensity,
|
|
14726
|
+
environmentRotation,
|
|
14727
|
+
...rest
|
|
14728
|
+
}) {
|
|
14729
|
+
const texture = useEnvironment(rest);
|
|
14730
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14731
|
+
React__namespace.useLayoutEffect(() => {
|
|
14732
|
+
return setEnvProps(background, scene, defaultScene, texture, {
|
|
14733
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
14734
|
+
backgroundIntensity,
|
|
14735
|
+
backgroundRotation,
|
|
14736
|
+
environmentIntensity,
|
|
14737
|
+
environmentRotation
|
|
14738
|
+
});
|
|
14739
|
+
});
|
|
14740
|
+
React__namespace.useEffect(() => {
|
|
14741
|
+
return () => {
|
|
14742
|
+
texture.dispose();
|
|
14743
|
+
};
|
|
14744
|
+
}, [texture]);
|
|
14745
|
+
return null;
|
|
14746
|
+
}
|
|
14747
|
+
function EnvironmentPortal({
|
|
14748
|
+
children,
|
|
14749
|
+
near = 0.1,
|
|
14750
|
+
far = 1e3,
|
|
14751
|
+
resolution = 256,
|
|
14752
|
+
frames = 1,
|
|
14753
|
+
map,
|
|
14754
|
+
background = false,
|
|
14755
|
+
blur,
|
|
14756
|
+
backgroundBlurriness,
|
|
14757
|
+
backgroundIntensity,
|
|
14758
|
+
backgroundRotation,
|
|
14759
|
+
environmentIntensity,
|
|
14760
|
+
environmentRotation,
|
|
14761
|
+
scene,
|
|
14762
|
+
files,
|
|
14763
|
+
path,
|
|
14764
|
+
preset = void 0,
|
|
14765
|
+
extensions
|
|
14766
|
+
}) {
|
|
14767
|
+
const renderer = useThree((state) => state.renderer);
|
|
14768
|
+
const isLegacy = useThree((state) => state.isLegacy);
|
|
14769
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14770
|
+
const camera = React__namespace.useRef(null);
|
|
14771
|
+
const [virtualScene] = React__namespace.useState(() => new three.Scene());
|
|
14772
|
+
const fbo = React__namespace.useMemo(() => {
|
|
14773
|
+
const fbo2 = isLegacy ? new three.WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
|
|
14774
|
+
fbo2.texture.type = three.HalfFloatType;
|
|
14775
|
+
return fbo2;
|
|
14776
|
+
}, [resolution, isLegacy]);
|
|
14777
|
+
React__namespace.useEffect(() => {
|
|
14778
|
+
return () => {
|
|
14779
|
+
fbo.dispose();
|
|
14780
|
+
};
|
|
14781
|
+
}, [fbo]);
|
|
14782
|
+
React__namespace.useLayoutEffect(() => {
|
|
14783
|
+
if (frames === 1) {
|
|
14784
|
+
const autoClear = renderer.autoClear;
|
|
14785
|
+
renderer.autoClear = true;
|
|
14786
|
+
camera.current.update(renderer, virtualScene);
|
|
14787
|
+
renderer.autoClear = autoClear;
|
|
14788
|
+
}
|
|
14789
|
+
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
14790
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
14791
|
+
backgroundIntensity,
|
|
14792
|
+
backgroundRotation,
|
|
14793
|
+
environmentIntensity,
|
|
14794
|
+
environmentRotation
|
|
14795
|
+
});
|
|
14796
|
+
}, [
|
|
14797
|
+
children,
|
|
14798
|
+
virtualScene,
|
|
14799
|
+
fbo.texture,
|
|
14800
|
+
scene,
|
|
14801
|
+
defaultScene,
|
|
14802
|
+
background,
|
|
14803
|
+
frames,
|
|
14804
|
+
renderer,
|
|
14805
|
+
blur,
|
|
14806
|
+
backgroundBlurriness,
|
|
14807
|
+
backgroundIntensity,
|
|
14808
|
+
backgroundRotation,
|
|
14809
|
+
environmentIntensity,
|
|
14810
|
+
environmentRotation
|
|
14811
|
+
]);
|
|
14812
|
+
let count = 1;
|
|
14813
|
+
useFrame(() => {
|
|
14814
|
+
if (frames === Infinity || count < frames) {
|
|
14815
|
+
const autoClear = renderer.autoClear;
|
|
14816
|
+
renderer.autoClear = true;
|
|
14817
|
+
camera.current.update(renderer, virtualScene);
|
|
14818
|
+
renderer.autoClear = autoClear;
|
|
14819
|
+
count++;
|
|
14820
|
+
}
|
|
14821
|
+
});
|
|
14822
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: createPortal(
|
|
14823
|
+
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
14824
|
+
children,
|
|
14825
|
+
/* @__PURE__ */ jsxRuntime.jsx("cubeCamera", { ref: camera, args: [near, far, fbo] }),
|
|
14826
|
+
files || preset ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { background: true, files, preset, path, extensions }) : map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { background: true, map, extensions }) : null
|
|
14827
|
+
] }),
|
|
14828
|
+
virtualScene
|
|
14829
|
+
) });
|
|
14830
|
+
}
|
|
14831
|
+
function EnvironmentGround(props) {
|
|
14832
|
+
const textureDefault = useEnvironment(props);
|
|
14833
|
+
const texture = props.map || textureDefault;
|
|
14834
|
+
React__namespace.useMemo(() => extend({ GroundProjectedEnvImpl: GroundedSkybox_js.GroundedSkybox }), []);
|
|
14835
|
+
React__namespace.useEffect(() => {
|
|
14836
|
+
return () => {
|
|
14837
|
+
textureDefault.dispose();
|
|
14838
|
+
};
|
|
14839
|
+
}, [textureDefault]);
|
|
14840
|
+
const height = props.ground?.height ?? 15;
|
|
14841
|
+
const radius = props.ground?.radius ?? 60;
|
|
14842
|
+
const scale = props.ground?.scale ?? 1e3;
|
|
14843
|
+
const args = React__namespace.useMemo(
|
|
14844
|
+
() => [texture, height, radius],
|
|
14845
|
+
[texture, height, radius]
|
|
14846
|
+
);
|
|
14847
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
14848
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props, map: texture }),
|
|
14849
|
+
/* @__PURE__ */ jsxRuntime.jsx("groundProjectedEnvImpl", { args, scale })
|
|
14850
|
+
] });
|
|
14851
|
+
}
|
|
14852
|
+
function EnvironmentColor({ color, scene }) {
|
|
14853
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14854
|
+
React__namespace.useLayoutEffect(() => {
|
|
14855
|
+
if (color === void 0) return;
|
|
14856
|
+
const target = resolveScene(scene || defaultScene);
|
|
14857
|
+
const oldBg = target.background;
|
|
14858
|
+
target.background = new three.Color(color);
|
|
14859
|
+
return () => {
|
|
14860
|
+
target.background = oldBg;
|
|
14861
|
+
};
|
|
14862
|
+
});
|
|
14863
|
+
return null;
|
|
14864
|
+
}
|
|
14865
|
+
function EnvironmentDualSource(props) {
|
|
14866
|
+
const { backgroundFiles, ...envProps } = props;
|
|
14867
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
14868
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...envProps, background: false }),
|
|
14869
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props, files: backgroundFiles, background: "only" })
|
|
14870
|
+
] });
|
|
14871
|
+
}
|
|
14872
|
+
function Environment(props) {
|
|
14873
|
+
if (props.color && !props.files && !props.preset && !props.map) {
|
|
14874
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentColor, { ...props });
|
|
14875
|
+
}
|
|
14876
|
+
if (props.backgroundFiles && props.backgroundFiles !== props.files) {
|
|
14877
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentDualSource, { ...props });
|
|
14878
|
+
}
|
|
14879
|
+
return props.ground ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsxRuntime.jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsxRuntime.jsx(EnvironmentCube, { ...props });
|
|
14880
|
+
}
|
|
14881
|
+
|
|
14681
14882
|
function parseBackground(background) {
|
|
14682
14883
|
if (!background) return null;
|
|
14683
14884
|
if (typeof background === "object" && !background.isColor) {
|
|
@@ -14708,14 +14909,49 @@ function parseBackground(background) {
|
|
|
14708
14909
|
return null;
|
|
14709
14910
|
}
|
|
14710
14911
|
|
|
14912
|
+
function parseRendererConfig(rendererProp) {
|
|
14913
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14914
|
+
if (isRendererConfig) {
|
|
14915
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14916
|
+
return {
|
|
14917
|
+
primaryCanvas: pc,
|
|
14918
|
+
scheduler: sc,
|
|
14919
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14920
|
+
};
|
|
14921
|
+
}
|
|
14922
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14923
|
+
}
|
|
14924
|
+
|
|
14925
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14926
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14927
|
+
function getKindRegistry(store, kind) {
|
|
14928
|
+
let registry = registries.get(store);
|
|
14929
|
+
if (!registry) {
|
|
14930
|
+
registry = {
|
|
14931
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14932
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14933
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14934
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14935
|
+
};
|
|
14936
|
+
registries.set(store, registry);
|
|
14937
|
+
}
|
|
14938
|
+
return registry[kind];
|
|
14939
|
+
}
|
|
14940
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14941
|
+
const registry = getKindRegistry(store, kind);
|
|
14942
|
+
{
|
|
14943
|
+
registry.valid.clear();
|
|
14944
|
+
registry.staged.clear();
|
|
14945
|
+
}
|
|
14946
|
+
}
|
|
14947
|
+
function invalidateAllResources(store) {
|
|
14948
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14949
|
+
}
|
|
14950
|
+
|
|
14711
14951
|
function clearHmrCaches(store) {
|
|
14712
|
-
store.
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
buffers: {},
|
|
14716
|
-
gpuStorage: {},
|
|
14717
|
-
_hmrVersion: state._hmrVersion + 1
|
|
14718
|
-
}));
|
|
14952
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14953
|
+
invalidateAllResources(primary);
|
|
14954
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14719
14955
|
}
|
|
14720
14956
|
|
|
14721
14957
|
function CanvasImpl({
|
|
@@ -14751,18 +14987,7 @@ function CanvasImpl({
|
|
|
14751
14987
|
forceEven,
|
|
14752
14988
|
...props
|
|
14753
14989
|
}) {
|
|
14754
|
-
const
|
|
14755
|
-
let primaryCanvas;
|
|
14756
|
-
let scheduler;
|
|
14757
|
-
let renderer;
|
|
14758
|
-
if (isRendererConfig) {
|
|
14759
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14760
|
-
primaryCanvas = pc;
|
|
14761
|
-
scheduler = sc;
|
|
14762
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
14763
|
-
} else {
|
|
14764
|
-
renderer = rendererProp;
|
|
14765
|
-
}
|
|
14990
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
14766
14991
|
React__namespace.useMemo(() => extend(THREE), []);
|
|
14767
14992
|
const Bridge = useBridge();
|
|
14768
14993
|
const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
|
|
@@ -14807,6 +15032,7 @@ function CanvasImpl({
|
|
|
14807
15032
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
14808
15033
|
const [block, setBlock] = React__namespace.useState(false);
|
|
14809
15034
|
const [error, setError] = React__namespace.useState(false);
|
|
15035
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
14810
15036
|
if (block) throw block;
|
|
14811
15037
|
if (error) throw error;
|
|
14812
15038
|
const root = React__namespace.useRef(null);
|
|
@@ -14814,6 +15040,7 @@ function CanvasImpl({
|
|
|
14814
15040
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
14815
15041
|
useIsomorphicLayoutEffect(() => {
|
|
14816
15042
|
effectActiveRef.current = true;
|
|
15043
|
+
if (fallbackVisible) return;
|
|
14817
15044
|
const canvas = canvasRef.current;
|
|
14818
15045
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
14819
15046
|
if (!root.current) {
|
|
@@ -14834,7 +15061,7 @@ function CanvasImpl({
|
|
|
14834
15061
|
}
|
|
14835
15062
|
async function run() {
|
|
14836
15063
|
if (!effectActiveRef.current || !root.current) return;
|
|
14837
|
-
await root.current.configure({
|
|
15064
|
+
const configured = await root.current.configure({
|
|
14838
15065
|
id,
|
|
14839
15066
|
primaryCanvas,
|
|
14840
15067
|
scheduler,
|
|
@@ -14861,7 +15088,7 @@ function CanvasImpl({
|
|
|
14861
15088
|
onDropMissed: (...args) => handleDropMissed.current?.(...args),
|
|
14862
15089
|
onCreated: (state) => {
|
|
14863
15090
|
state.events.connect?.(
|
|
14864
|
-
eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15091
|
+
eventSource ? isRef$1(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
14865
15092
|
);
|
|
14866
15093
|
if (eventPrefix) {
|
|
14867
15094
|
state.setEvents({
|
|
@@ -14875,8 +15102,20 @@ function CanvasImpl({
|
|
|
14875
15102
|
}
|
|
14876
15103
|
onCreated?.(state);
|
|
14877
15104
|
}
|
|
14878
|
-
})
|
|
14879
|
-
|
|
15105
|
+
}).then(
|
|
15106
|
+
() => true,
|
|
15107
|
+
// Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
|
|
15108
|
+
// inside <canvas>, which browsers don't display, so surface it as visible DOM
|
|
15109
|
+
// instead; with no fallback, rethrow to an external error boundary. (#3757)
|
|
15110
|
+
(setupError) => {
|
|
15111
|
+
if (effectActiveRef.current) {
|
|
15112
|
+
if (fallback != null) setFallbackVisible(true);
|
|
15113
|
+
else setError(setupError);
|
|
15114
|
+
}
|
|
15115
|
+
return false;
|
|
15116
|
+
}
|
|
15117
|
+
);
|
|
15118
|
+
if (!configured || !effectActiveRef.current || !root.current) return;
|
|
14880
15119
|
root.current.render(
|
|
14881
15120
|
/* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Block, { set: setBlock }), children: [
|
|
14882
15121
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -14939,7 +15178,11 @@ function CanvasImpl({
|
|
|
14939
15178
|
...style
|
|
14940
15179
|
},
|
|
14941
15180
|
...props,
|
|
14942
|
-
children:
|
|
15181
|
+
children: fallbackVisible ? (
|
|
15182
|
+
// Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
|
|
15183
|
+
// it exists in the tree but browsers never paint it, which is the whole bug (#3757).
|
|
15184
|
+
fallback
|
|
15185
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14943
15186
|
"canvas",
|
|
14944
15187
|
{
|
|
14945
15188
|
ref: canvasRef,
|
|
@@ -14977,7 +15220,6 @@ exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
|
14977
15220
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
14978
15221
|
exports.Texture = Texture;
|
|
14979
15222
|
exports._roots = _roots;
|
|
14980
|
-
exports.act = act;
|
|
14981
15223
|
exports.addAfterEffect = addAfterEffect;
|
|
14982
15224
|
exports.addEffect = addEffect;
|
|
14983
15225
|
exports.addTail = addTail;
|
|
@@ -15016,7 +15258,7 @@ exports.isFromRef = isFromRef;
|
|
|
15016
15258
|
exports.isObject3D = isObject3D;
|
|
15017
15259
|
exports.isOnce = isOnce;
|
|
15018
15260
|
exports.isOrthographicCamera = isOrthographicCamera;
|
|
15019
|
-
exports.isRef = isRef;
|
|
15261
|
+
exports.isRef = isRef$1;
|
|
15020
15262
|
exports.isRenderer = isRenderer;
|
|
15021
15263
|
exports.isTexture = isTexture;
|
|
15022
15264
|
exports.isVectorLike = isVectorLike;
|
|
@@ -15027,6 +15269,7 @@ exports.reconciler = reconciler;
|
|
|
15027
15269
|
exports.registerPrimary = registerPrimary;
|
|
15028
15270
|
exports.removeInteractivity = removeInteractivity;
|
|
15029
15271
|
exports.resolve = resolve;
|
|
15272
|
+
exports.swapInteractivity = swapInteractivity;
|
|
15030
15273
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
15031
15274
|
exports.unregisterPrimary = unregisterPrimary;
|
|
15032
15275
|
exports.updateCamera = updateCamera;
|