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