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