@react-three/fiber 10.0.0-canary.2c50459 → 10.0.0-canary.4bc4a97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2247 -2004
- package/dist/index.d.cts +71 -35
- package/dist/index.d.mts +71 -35
- package/dist/index.d.ts +71 -35
- package/dist/index.mjs +2250 -2007
- package/dist/legacy.cjs +2282 -2039
- package/dist/legacy.d.cts +71 -34
- package/dist/legacy.d.mts +71 -34
- package/dist/legacy.d.ts +71 -34
- package/dist/legacy.mjs +2284 -2041
- package/dist/webgpu/index.cjs +2615 -2613
- package/dist/webgpu/index.d.cts +105 -39
- package/dist/webgpu/index.d.mts +105 -39
- package/dist/webgpu/index.d.ts +105 -39
- package/dist/webgpu/index.mjs +2618 -2616
- package/package.json +5 -5
- package/readme.md +1 -2
- package/react-reconciler/constants.d.ts +0 -7
- package/react-reconciler/constants.js +0 -1
- package/react-reconciler/index.d.ts +0 -1044
- package/react-reconciler/index.js +0 -208
package/dist/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,1320 +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
|
-
const raycastEvent = {
|
|
1189
|
-
...hit,
|
|
1190
|
-
...extractEventProps,
|
|
1191
|
-
pointer,
|
|
1192
|
-
intersections,
|
|
1193
|
-
stopped: localState.stopped,
|
|
1194
|
-
delta,
|
|
1195
|
-
unprojectedPoint,
|
|
1196
|
-
ray: raycaster.ray,
|
|
1197
|
-
camera,
|
|
1198
|
-
pointerId: eventPointerId,
|
|
1199
|
-
// Hijack stopPropagation, which just sets a flag
|
|
1200
|
-
stopPropagation() {
|
|
1201
|
-
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1202
|
-
if (
|
|
1203
|
-
// ...if this pointer hasn't been captured
|
|
1204
|
-
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1205
|
-
pointerState.captured.has(hit.eventObject)
|
|
1206
|
-
) {
|
|
1207
|
-
raycastEvent.stopped = localState.stopped = true;
|
|
1208
|
-
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1209
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1210
|
-
cancelPointer([...higher, hit], eventPointerId);
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
},
|
|
1214
|
-
// there should be a distinction between target and currentTarget
|
|
1215
|
-
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1216
|
-
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1217
|
-
nativeEvent: event
|
|
1218
|
-
};
|
|
1219
|
-
callback(raycastEvent);
|
|
1220
|
-
if (localState.stopped === true) break;
|
|
908
|
+
return;
|
|
1221
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
|
+
}
|
|
980
|
+
};
|
|
981
|
+
},
|
|
982
|
+
// Renderer Storage (single source of truth)
|
|
983
|
+
actualRenderer: null,
|
|
984
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
985
|
+
scheduler: null
|
|
1222
986
|
}
|
|
1223
|
-
}
|
|
1224
|
-
return
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
if (instance?.eventCount) {
|
|
1239
|
-
const handlers = instance.handlers;
|
|
1240
|
-
const data = { ...hoveredObj, intersections };
|
|
1241
|
-
handlers.onPointerOut?.(data);
|
|
1242
|
-
handlers.onPointerLeave?.(data);
|
|
1243
|
-
handlers.onDragOverLeave?.(data);
|
|
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
|
+
});
|
|
1244
1002
|
}
|
|
1245
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
|
+
}
|
|
1246
1031
|
}
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1269
|
-
if (pointerState) {
|
|
1270
|
-
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1271
|
-
const eventObject = hoveredObj.eventObject;
|
|
1272
|
-
const instance = eventObject.__r3f;
|
|
1273
|
-
if (instance?.eventCount) {
|
|
1274
|
-
const handlers = instance.handlers;
|
|
1275
|
-
const data = { ...hoveredObj, intersections: [] };
|
|
1276
|
-
handlers.onPointerOut?.(data);
|
|
1277
|
-
handlers.onPointerLeave?.(data);
|
|
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);
|
|
1278
1053
|
}
|
|
1279
1054
|
}
|
|
1280
|
-
internal.pointerMap.delete(pointerId);
|
|
1281
1055
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
const eventObject = data.eventObject;
|
|
1293
|
-
const instance = eventObject.__r3f;
|
|
1294
|
-
if (!instance?.eventCount) return;
|
|
1295
|
-
const handlers = instance.handlers;
|
|
1296
|
-
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
1297
|
-
const id = makeId(data);
|
|
1298
|
-
const pointerState = getPointerState(internal, pointerId);
|
|
1299
|
-
const hoveredItem = pointerState.hovered.get(id);
|
|
1300
|
-
if (!hoveredItem) {
|
|
1301
|
-
pointerState.hovered.set(id, data);
|
|
1302
|
-
handlers.onPointerOver?.(data);
|
|
1303
|
-
handlers.onPointerEnter?.(data);
|
|
1304
|
-
} else if (hoveredItem.stopped) {
|
|
1305
|
-
data.stopPropagation();
|
|
1306
|
-
}
|
|
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);
|
|
1307
1066
|
}
|
|
1308
|
-
handlers.onPointerMove?.(data);
|
|
1309
1067
|
}
|
|
1310
|
-
|
|
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);
|
|
1081
|
+
}
|
|
1082
|
+
return loader;
|
|
1311
1083
|
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
case "onLostPointerCapture":
|
|
1324
|
-
return (event) => {
|
|
1325
|
-
const { internal } = store.getState();
|
|
1326
|
-
const pointerId = getPointerId(event);
|
|
1327
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1328
|
-
if (pointerState?.captured.size) {
|
|
1329
|
-
requestAnimationFrame(() => {
|
|
1330
|
-
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
1331
|
-
if (pointerState2?.captured.size) {
|
|
1332
|
-
pointerState2.captured.clear();
|
|
1333
|
-
}
|
|
1334
|
-
cancelPointer([], pointerId);
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
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
|
+
});
|
|
1338
1095
|
}
|
|
1339
|
-
return
|
|
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
|
-
const
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
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
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
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);
|
|
1334
|
+
}
|
|
1335
|
+
textureArray.forEach((texture) => {
|
|
1336
|
+
if (texture instanceof Texture$1) {
|
|
1337
|
+
renderer.initTexture(texture);
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
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);
|
|
1707
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;
|
|
1708
1419
|
},
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
top: 0,
|
|
1716
|
-
left: 0,
|
|
1717
|
-
aspect: 0,
|
|
1718
|
-
distance: 0,
|
|
1719
|
-
factor: 0,
|
|
1720
|
-
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;
|
|
1721
1426
|
},
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
const currentSize = state2.size;
|
|
1731
|
-
const newSize = {
|
|
1732
|
-
width: propW ?? currentSize.width,
|
|
1733
|
-
height: propH ?? currentSize.height,
|
|
1734
|
-
top: currentSize.top,
|
|
1735
|
-
left: currentSize.left
|
|
1736
|
-
};
|
|
1737
|
-
set((s) => ({
|
|
1738
|
-
size: newSize,
|
|
1739
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1740
|
-
}));
|
|
1741
|
-
getScheduler().invalidate();
|
|
1742
|
-
}
|
|
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]);
|
|
1743
1435
|
}
|
|
1744
|
-
return;
|
|
1436
|
+
return { textures };
|
|
1437
|
+
});
|
|
1438
|
+
},
|
|
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;
|
|
1745
1447
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
}));
|
|
1756
|
-
getScheduler().invalidate();
|
|
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;
|
|
1757
1457
|
},
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
}),
|
|
1762
|
-
setFrameloop: (frameloop = "always") => {
|
|
1763
|
-
set(() => ({ frameloop }));
|
|
1764
|
-
},
|
|
1765
|
-
setError: (error) => set(() => ({ error })),
|
|
1766
|
-
error: null,
|
|
1767
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1768
|
-
uniforms: {},
|
|
1769
|
-
nodes: {},
|
|
1770
|
-
buffers: {},
|
|
1771
|
-
gpuStorage: {},
|
|
1772
|
-
textures: /* @__PURE__ */ new Map(),
|
|
1773
|
-
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1774
|
-
renderPipeline: null,
|
|
1775
|
-
passes: {},
|
|
1776
|
-
_hmrVersion: 0,
|
|
1777
|
-
_sizeImperative: false,
|
|
1778
|
-
_sizeProps: null,
|
|
1779
|
-
previousRoot: void 0,
|
|
1780
|
-
internal: {
|
|
1781
|
-
// Events
|
|
1782
|
-
interaction: [],
|
|
1783
|
-
subscribers: [],
|
|
1784
|
-
// Per-pointer state (new unified structure)
|
|
1785
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
1786
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1787
|
-
lastEvent: React.createRef(),
|
|
1788
|
-
// Deprecated but kept for backwards compatibility
|
|
1789
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1790
|
-
initialClick: [0, 0],
|
|
1791
|
-
initialHits: [],
|
|
1792
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
1793
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1794
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1795
|
-
// Occlusion system (WebGPU only)
|
|
1796
|
-
occlusionEnabled: false,
|
|
1797
|
-
occlusionObserver: null,
|
|
1798
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1799
|
-
helperGroup: null,
|
|
1800
|
-
// Updates
|
|
1801
|
-
active: false,
|
|
1802
|
-
frames: 0,
|
|
1803
|
-
priority: 0,
|
|
1804
|
-
subscribe: (ref, priority, store) => {
|
|
1805
|
-
const internal = get().internal;
|
|
1806
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1807
|
-
internal.subscribers.push({ ref, priority, store });
|
|
1808
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1809
|
-
return () => {
|
|
1810
|
-
const internal2 = get().internal;
|
|
1811
|
-
if (internal2?.subscribers) {
|
|
1812
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1813
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1814
|
-
}
|
|
1815
|
-
};
|
|
1816
|
-
},
|
|
1817
|
-
// Renderer Storage (single source of truth)
|
|
1818
|
-
actualRenderer: null,
|
|
1819
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1820
|
-
scheduler: null
|
|
1458
|
+
disposeAll() {
|
|
1459
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
1460
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
1821
1461
|
}
|
|
1822
1462
|
};
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
const currentState = rootStore.getState();
|
|
1829
|
-
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1830
|
-
const stack = new Error().stack || "";
|
|
1831
|
-
const isInternalAccess = stack.includes("zustand") || stack.includes("setState") || stack.includes("Object.assign") || stack.includes("react-three-fiber/packages/fiber/src/core");
|
|
1832
|
-
if (!isInternalAccess) {
|
|
1833
|
-
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1834
|
-
notifyDepreciated({
|
|
1835
|
-
heading: "Accessing state.gl in WebGPU mode",
|
|
1836
|
-
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
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
return currentState.internal.actualRenderer;
|
|
1841
|
-
},
|
|
1842
|
-
set(value) {
|
|
1843
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1844
|
-
},
|
|
1845
|
-
enumerable: true,
|
|
1846
|
-
configurable: true
|
|
1847
|
-
});
|
|
1848
|
-
Object.defineProperty(state, "renderer", {
|
|
1849
|
-
get() {
|
|
1850
|
-
return rootStore.getState().internal.actualRenderer;
|
|
1851
|
-
},
|
|
1852
|
-
set(value) {
|
|
1853
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1854
|
-
},
|
|
1855
|
-
enumerable: true,
|
|
1856
|
-
configurable: true
|
|
1857
|
-
});
|
|
1858
|
-
let oldScene = state.scene;
|
|
1859
|
-
rootStore.subscribe(() => {
|
|
1860
|
-
const currentState = rootStore.getState();
|
|
1861
|
-
const { scene, rootScene, set } = currentState;
|
|
1862
|
-
if (scene !== oldScene) {
|
|
1863
|
-
oldScene = scene;
|
|
1864
|
-
if (scene?.isScene && scene !== rootScene) {
|
|
1865
|
-
set({ rootScene: scene });
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
});
|
|
1869
|
-
let oldSize = state.size;
|
|
1870
|
-
let oldDpr = state.viewport.dpr;
|
|
1871
|
-
let oldCamera = state.camera;
|
|
1872
|
-
rootStore.subscribe(() => {
|
|
1873
|
-
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1874
|
-
const actualRenderer = internal.actualRenderer;
|
|
1875
|
-
const canvasTarget = internal.canvasTarget;
|
|
1876
|
-
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1877
|
-
oldSize = size;
|
|
1878
|
-
oldDpr = viewport.dpr;
|
|
1879
|
-
updateCamera(camera, size);
|
|
1880
|
-
if (internal.isSecondary && canvasTarget) {
|
|
1881
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1882
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1883
|
-
} else {
|
|
1884
|
-
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1885
|
-
actualRenderer.setSize(size.width, size.height, false);
|
|
1886
|
-
if (canvasTarget) {
|
|
1887
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1888
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
if (camera !== oldCamera) {
|
|
1893
|
-
oldCamera = camera;
|
|
1894
|
-
const { rootScene } = rootStore.getState();
|
|
1895
|
-
if (camera && rootScene && !camera.parent) {
|
|
1896
|
-
rootScene.add(camera);
|
|
1897
|
-
}
|
|
1898
|
-
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1899
|
-
const currentState = rootStore.getState();
|
|
1900
|
-
if (currentState.autoUpdateFrustum && camera) {
|
|
1901
|
-
updateFrustum(camera, currentState.frustum);
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
});
|
|
1905
|
-
rootStore.subscribe((state2) => invalidate(state2));
|
|
1906
|
-
return rootStore;
|
|
1907
|
-
};
|
|
1463
|
+
}, [store]);
|
|
1464
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
1465
|
+
const selected = useThree(subscribe);
|
|
1466
|
+
return selector ? selected : registry;
|
|
1467
|
+
}
|
|
1908
1468
|
|
|
1909
|
-
|
|
1910
|
-
const
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
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;
|
|
1917
1487
|
}
|
|
1918
|
-
return loader;
|
|
1919
1488
|
}
|
|
1920
|
-
return
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
if (extensions) extensions(loader);
|
|
1926
|
-
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1927
|
-
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1928
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1929
|
-
return data;
|
|
1930
|
-
});
|
|
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);
|
|
1931
1494
|
}
|
|
1932
|
-
|
|
1933
|
-
(res, reject) => loader.load(
|
|
1934
|
-
input,
|
|
1935
|
-
(data) => {
|
|
1936
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1937
|
-
res(data);
|
|
1938
|
-
},
|
|
1939
|
-
onProgress,
|
|
1940
|
-
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1941
|
-
)
|
|
1942
|
-
);
|
|
1943
|
-
};
|
|
1944
|
-
}
|
|
1945
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
1946
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1947
|
-
const fn = loadingFn(extensions, onProgress);
|
|
1948
|
-
const results = keys.map((key) => suspend(fn, [loader, key], { equal: is.equ }));
|
|
1949
|
-
return Array.isArray(input) ? results : results[0];
|
|
1495
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
1950
1496
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
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"
|
|
1958
1509
|
};
|
|
1959
|
-
useLoader.loader = getLoader;
|
|
1960
1510
|
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
const
|
|
1979
|
-
|
|
1980
|
-
const
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
}
|
|
1995
|
-
notifyDepreciated({
|
|
1996
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
1997
|
-
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 })',
|
|
1998
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
1999
|
-
});
|
|
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);
|
|
2000
1544
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
const mergedState = {
|
|
2004
|
-
...localState,
|
|
2005
|
-
time: frameState.time,
|
|
2006
|
-
delta: frameState.delta,
|
|
2007
|
-
elapsed: frameState.elapsed,
|
|
2008
|
-
frame: frameState.frame
|
|
2009
|
-
};
|
|
2010
|
-
callbackRef.current?.(mergedState, delta);
|
|
2011
|
-
};
|
|
2012
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2013
|
-
id,
|
|
2014
|
-
rootId,
|
|
2015
|
-
...options
|
|
2016
|
-
});
|
|
2017
|
-
return () => {
|
|
2018
|
-
unregister();
|
|
2019
|
-
if (isLegacyPriority) {
|
|
2020
|
-
const currentState = store.getState();
|
|
2021
|
-
if (currentState.internal) {
|
|
2022
|
-
currentState.internal.priority--;
|
|
2023
|
-
let parentRoot = currentState.previousRoot;
|
|
2024
|
-
while (parentRoot) {
|
|
2025
|
-
const parentState = parentRoot.getState();
|
|
2026
|
-
if (parentState?.internal) parentState.internal.priority--;
|
|
2027
|
-
parentRoot = parentState?.previousRoot;
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
};
|
|
2032
|
-
} else {
|
|
2033
|
-
return scheduler.register(
|
|
2034
|
-
(state, delta) => {
|
|
2035
|
-
const frameState = state;
|
|
2036
|
-
if (!frameState.renderer) return;
|
|
2037
|
-
callbackRef.current?.(frameState, delta);
|
|
2038
|
-
},
|
|
2039
|
-
{ id, ...options }
|
|
2040
|
-
);
|
|
1545
|
+
loader2.setPath?.(path);
|
|
1546
|
+
if (extensions) extensions(loader2);
|
|
2041
1547
|
}
|
|
2042
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2043
|
-
const isPaused = React.useSyncExternalStore(
|
|
2044
|
-
// Subscribe function
|
|
2045
|
-
React.useCallback(
|
|
2046
|
-
(onStoreChange) => {
|
|
2047
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2048
|
-
},
|
|
2049
|
-
[id]
|
|
2050
|
-
),
|
|
2051
|
-
// getSnapshot function
|
|
2052
|
-
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2053
|
-
// getServerSnapshot function (SSR)
|
|
2054
|
-
React.useCallback(() => false, [])
|
|
2055
1548
|
);
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
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
|
-
|
|
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;
|
|
2103
1616
|
}
|
|
2104
1617
|
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
if (
|
|
2108
|
-
|
|
2109
|
-
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;
|
|
2110
1622
|
}
|
|
2111
|
-
function
|
|
2112
|
-
return
|
|
1623
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
1624
|
+
return useStore()(selector, equalityFn);
|
|
2113
1625
|
}
|
|
2114
|
-
function
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
return input.map((url) => textureCache.get(url));
|
|
2119
|
-
} else {
|
|
2120
|
-
const result = {};
|
|
2121
|
-
const objInput = input;
|
|
2122
|
-
for (const key in objInput) {
|
|
2123
|
-
result[key] = textureCache.get(objInput[key]);
|
|
2124
|
-
}
|
|
2125
|
-
return result;
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
function useTexture(input, optionsOrOnLoad) {
|
|
2129
|
-
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2130
|
-
const store = useStore();
|
|
2131
|
-
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2132
|
-
const { onLoad, cache = true } = options;
|
|
2133
|
-
const onLoadRef = useRef(onLoad);
|
|
2134
|
-
onLoadRef.current = onLoad;
|
|
2135
|
-
const onLoadCalledForRef = useRef(null);
|
|
2136
|
-
const urls = useMemo(() => getUrls(input), [input]);
|
|
2137
|
-
const cachedResult = useMemo(() => {
|
|
2138
|
-
if (!cache) return null;
|
|
2139
|
-
const textures = store.getState().textures;
|
|
2140
|
-
if (!allUrlsCached(urls, textures)) return null;
|
|
2141
|
-
return buildFromCache(input, textures);
|
|
2142
|
-
}, [cache, urls, input, store]);
|
|
2143
|
-
const loadedTextures = useLoader(
|
|
2144
|
-
TextureLoader,
|
|
2145
|
-
IsObject(input) ? Object.values(input) : input
|
|
2146
|
-
);
|
|
2147
|
-
const inputKey = urls.join("\0");
|
|
2148
|
-
useLayoutEffect(() => {
|
|
2149
|
-
if (cachedResult) return;
|
|
2150
|
-
if (onLoadCalledForRef.current === inputKey) return;
|
|
2151
|
-
onLoadCalledForRef.current = inputKey;
|
|
2152
|
-
onLoadRef.current?.(loadedTextures);
|
|
2153
|
-
}, [cachedResult, loadedTextures, inputKey]);
|
|
2154
|
-
useEffect(() => {
|
|
2155
|
-
if (cachedResult) return;
|
|
2156
|
-
if ("initTexture" in renderer) {
|
|
2157
|
-
let textureArray = [];
|
|
2158
|
-
if (Array.isArray(loadedTextures)) {
|
|
2159
|
-
textureArray = loadedTextures;
|
|
2160
|
-
} else if (loadedTextures instanceof Texture$1) {
|
|
2161
|
-
textureArray = [loadedTextures];
|
|
2162
|
-
} else if (IsObject(loadedTextures)) {
|
|
2163
|
-
textureArray = Object.values(loadedTextures);
|
|
2164
|
-
}
|
|
2165
|
-
textureArray.forEach((texture) => {
|
|
2166
|
-
if (texture instanceof Texture$1) {
|
|
2167
|
-
renderer.initTexture(texture);
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
|
-
}
|
|
2171
|
-
}, [renderer, loadedTextures, cachedResult]);
|
|
2172
|
-
const mappedTextures = useMemo(() => {
|
|
2173
|
-
if (cachedResult) return cachedResult;
|
|
2174
|
-
if (IsObject(input)) {
|
|
2175
|
-
const keyed = {};
|
|
2176
|
-
const textureArray = loadedTextures;
|
|
2177
|
-
let i = 0;
|
|
2178
|
-
for (const key in input) keyed[key] = textureArray[i++];
|
|
2179
|
-
return keyed;
|
|
2180
|
-
} else {
|
|
2181
|
-
return loadedTextures;
|
|
2182
|
-
}
|
|
2183
|
-
}, [input, loadedTextures, cachedResult]);
|
|
2184
|
-
useEffect(() => {
|
|
2185
|
-
if (!cache) return;
|
|
2186
|
-
const urlTextureMap = [];
|
|
2187
|
-
if (typeof input === "string") {
|
|
2188
|
-
urlTextureMap.push([input, mappedTextures]);
|
|
2189
|
-
} else if (Array.isArray(input)) {
|
|
2190
|
-
const textureArray = mappedTextures;
|
|
2191
|
-
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
2192
|
-
} else if (IsObject(input)) {
|
|
2193
|
-
const textureRecord = mappedTextures;
|
|
2194
|
-
for (const key in input) {
|
|
2195
|
-
const url = input[key];
|
|
2196
|
-
urlTextureMap.push([url, textureRecord[key]]);
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
store.setState((state) => {
|
|
2200
|
-
const refs = new Map(state._textureRefs);
|
|
2201
|
-
let textures = state.textures;
|
|
2202
|
-
let added = false;
|
|
2203
|
-
for (const [url, texture] of urlTextureMap) {
|
|
2204
|
-
if (!textures.has(url)) {
|
|
2205
|
-
if (!added) {
|
|
2206
|
-
textures = new Map(textures);
|
|
2207
|
-
added = true;
|
|
2208
|
-
}
|
|
2209
|
-
textures.set(url, texture);
|
|
2210
|
-
}
|
|
2211
|
-
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2212
|
-
}
|
|
2213
|
-
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2214
|
-
});
|
|
2215
|
-
return () => store.setState((state) => {
|
|
2216
|
-
const refs = new Map(state._textureRefs);
|
|
2217
|
-
for (const [url] of urlTextureMap) {
|
|
2218
|
-
const next = (refs.get(url) ?? 0) - 1;
|
|
2219
|
-
if (next <= 0) refs.delete(url);
|
|
2220
|
-
else refs.set(url, next);
|
|
2221
|
-
}
|
|
2222
|
-
return { _textureRefs: refs };
|
|
2223
|
-
});
|
|
2224
|
-
}, [cache, input, mappedTextures, store]);
|
|
2225
|
-
return mappedTextures;
|
|
2226
|
-
}
|
|
2227
|
-
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
2228
|
-
useTexture.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
2229
|
-
const Texture = ({
|
|
2230
|
-
children,
|
|
2231
|
-
input,
|
|
2232
|
-
onLoad,
|
|
2233
|
-
cache
|
|
2234
|
-
}) => {
|
|
2235
|
-
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
2236
|
-
const ret = useTexture(input, options);
|
|
2237
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
2238
|
-
};
|
|
2239
|
-
|
|
2240
|
-
function useTextures(selector) {
|
|
2241
|
-
const store = useStore();
|
|
2242
|
-
const registry = useMemo(() => {
|
|
2243
|
-
const getState = store.getState;
|
|
2244
|
-
const setState = store.setState;
|
|
2245
|
-
const getOne = (key) => getState().textures.get(key);
|
|
2246
|
-
return {
|
|
2247
|
-
get all() {
|
|
2248
|
-
return getState().textures;
|
|
2249
|
-
},
|
|
2250
|
-
get(input) {
|
|
2251
|
-
if (typeof input === "string") return getOne(input);
|
|
2252
|
-
if (Array.isArray(input)) return input.map(getOne);
|
|
2253
|
-
const out = {};
|
|
2254
|
-
for (const name in input) out[name] = getOne(input[name]);
|
|
2255
|
-
return out;
|
|
2256
|
-
},
|
|
2257
|
-
has: (key) => getState().textures.has(key),
|
|
2258
|
-
add(keyOrRecord, texture) {
|
|
2259
|
-
setState((state) => {
|
|
2260
|
-
const textures = new Map(state.textures);
|
|
2261
|
-
if (typeof keyOrRecord === "string") {
|
|
2262
|
-
textures.set(keyOrRecord, texture);
|
|
2263
|
-
} else {
|
|
2264
|
-
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2265
|
-
}
|
|
2266
|
-
return { textures };
|
|
2267
|
-
});
|
|
2268
|
-
},
|
|
2269
|
-
dispose(key, options) {
|
|
2270
|
-
const state = getState();
|
|
2271
|
-
const refs = state._textureRefs.get(key) ?? 0;
|
|
2272
|
-
if (refs > 0 && !options?.force) {
|
|
2273
|
-
console.warn(
|
|
2274
|
-
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2275
|
-
);
|
|
2276
|
-
return false;
|
|
2277
|
-
}
|
|
2278
|
-
state.textures.get(key)?.dispose();
|
|
2279
|
-
setState((s) => {
|
|
2280
|
-
const textures = new Map(s.textures);
|
|
2281
|
-
textures.delete(key);
|
|
2282
|
-
const nextRefs = new Map(s._textureRefs);
|
|
2283
|
-
nextRefs.delete(key);
|
|
2284
|
-
return { textures, _textureRefs: nextRefs };
|
|
2285
|
-
});
|
|
2286
|
-
return true;
|
|
2287
|
-
},
|
|
2288
|
-
disposeAll() {
|
|
2289
|
-
for (const texture of getState().textures.values()) texture.dispose();
|
|
2290
|
-
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
}, [store]);
|
|
2294
|
-
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2295
|
-
const selected = useThree(subscribe);
|
|
2296
|
-
return selector ? selected : registry;
|
|
2297
|
-
}
|
|
2298
|
-
|
|
2299
|
-
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2300
|
-
const isLegacy = useThree((s) => s.isLegacy);
|
|
2301
|
-
const size = useThree((s) => s.size);
|
|
2302
|
-
let width;
|
|
2303
|
-
let height;
|
|
2304
|
-
let opts;
|
|
2305
|
-
if (typeof widthOrOptions === "object") {
|
|
2306
|
-
opts = widthOrOptions;
|
|
2307
|
-
} else if (typeof widthOrOptions === "number") {
|
|
2308
|
-
width = widthOrOptions;
|
|
2309
|
-
if (typeof heightOrOptions === "object") {
|
|
2310
|
-
height = widthOrOptions;
|
|
2311
|
-
opts = heightOrOptions;
|
|
2312
|
-
} else if (typeof heightOrOptions === "number") {
|
|
2313
|
-
height = heightOrOptions;
|
|
2314
|
-
opts = options;
|
|
2315
|
-
} else {
|
|
2316
|
-
height = widthOrOptions;
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
return useMemo(() => {
|
|
2320
|
-
const w = width ?? size.width;
|
|
2321
|
-
const h = height ?? size.height;
|
|
2322
|
-
{
|
|
2323
|
-
return isLegacy ? new WebGLRenderTarget(w, h, opts) : new RenderTarget(w, h, opts);
|
|
2324
|
-
}
|
|
2325
|
-
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
function useStore() {
|
|
2329
|
-
const store = useContext(context);
|
|
2330
|
-
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
2331
|
-
return store;
|
|
2332
|
-
}
|
|
2333
|
-
function useThree(selector = (state) => state, equalityFn) {
|
|
2334
|
-
return useStore()(selector, equalityFn);
|
|
2335
|
-
}
|
|
2336
|
-
function useInstanceHandle(ref) {
|
|
2337
|
-
const instance = useRef(null);
|
|
2338
|
-
useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
2339
|
-
return instance;
|
|
1626
|
+
function useInstanceHandle(ref) {
|
|
1627
|
+
const instance = useRef(null);
|
|
1628
|
+
useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
1629
|
+
return instance;
|
|
2340
1630
|
}
|
|
2341
1631
|
function useGraph(object) {
|
|
2342
1632
|
return useMemo(() => buildGraph(object), [object]);
|
|
2343
1633
|
}
|
|
2344
1634
|
|
|
1635
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
1636
|
+
|
|
2345
1637
|
let effectId = 0;
|
|
2346
1638
|
function addEffect(callback) {
|
|
2347
1639
|
notifyDepreciated({
|
|
@@ -2376,7 +1668,7 @@ function advance(timestamp) {
|
|
|
2376
1668
|
getScheduler().step(timestamp);
|
|
2377
1669
|
}
|
|
2378
1670
|
|
|
2379
|
-
const version = "10.0.0-alpha.
|
|
1671
|
+
const version = "10.0.0-alpha.3";
|
|
2380
1672
|
const packageData = {
|
|
2381
1673
|
version: version};
|
|
2382
1674
|
|
|
@@ -13522,117 +12814,700 @@ Visit https://react.dev/link/error-boundaries to learn more about error boundari
|
|
|
13522
12814
|
break;
|
|
13523
12815
|
}
|
|
13524
12816
|
}
|
|
13525
|
-
}
|
|
13526
|
-
return e;
|
|
13527
|
-
}, le.findHostInstance = function(e) {
|
|
13528
|
-
var n = e._reactInternals;
|
|
13529
|
-
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));
|
|
13530
|
-
return e = mu(n), e === null ? null : ot(e.stateNode);
|
|
13531
|
-
}, le.findHostInstanceWithNoPortals = function(e) {
|
|
13532
|
-
return e = Ed(e), e = e !== null ? _p(e) : null, e === null ? null : ot(e.stateNode);
|
|
13533
|
-
}, le.findHostInstanceWithWarning = function(e, n) {
|
|
13534
|
-
var o = e._reactInternals;
|
|
13535
|
-
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));
|
|
13536
|
-
if (e = mu(o), e === null) return null;
|
|
13537
|
-
if (e.mode & 8) {
|
|
13538
|
-
var i = G(o) || "Component";
|
|
13539
|
-
mb[i] || (mb[i] = true, B(e, function() {
|
|
13540
|
-
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);
|
|
13541
|
-
}));
|
|
13542
|
-
}
|
|
13543
|
-
return ot(e.stateNode);
|
|
13544
|
-
}, le.flushPassiveEffects = el, le.flushSyncFromReconciler = function(e) {
|
|
13545
|
-
var n = ye;
|
|
13546
|
-
ye |= 1;
|
|
13547
|
-
var o = x.T, i = wt();
|
|
13548
|
-
try {
|
|
13549
|
-
if (an(2), x.T = null, e) return e();
|
|
13550
|
-
} finally {
|
|
13551
|
-
an(i), x.T = o, ye = n, (ye & (Zn | uo)) === Jn && Wa(0);
|
|
13552
|
-
}
|
|
13553
|
-
}, le.flushSyncWork = Ls, le.focusWithin = function(e, n) {
|
|
13554
|
-
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
13555
|
-
for (e = Ef(e), n = hh(e, n), n = Array.from(n), e = 0; e < n.length; ) {
|
|
13556
|
-
var o = n[e++], i = o.tag;
|
|
13557
|
-
if (!Kr(o)) {
|
|
13558
|
-
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
13559
|
-
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
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
|
+
}
|
|
13148
|
+
}
|
|
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;
|
|
13157
|
+
}
|
|
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);
|
|
13180
|
+
}
|
|
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);
|
|
13214
|
+
}
|
|
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();
|
|
13242
|
+
}
|
|
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();
|
|
13269
|
+
}
|
|
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();
|
|
13347
|
+
}
|
|
13348
|
+
}
|
|
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
|
+
}
|
|
13560
13380
|
}
|
|
13561
13381
|
}
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
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);
|
|
13570
13441
|
}
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
No matching component was found for:
|
|
13577
|
-
`) + e.join(" > ");
|
|
13442
|
+
} else {
|
|
13443
|
+
flushDeferredPointers();
|
|
13444
|
+
if (internal.lastEvent?.current) {
|
|
13445
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13578
13446
|
}
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
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 });
|
|
13588
13466
|
}
|
|
13589
|
-
}
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
}
|
|
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
|
+
}
|
|
13600
13478
|
}
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
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
|
+
};
|
|
13631
13510
|
}
|
|
13632
|
-
var t0 = n0();
|
|
13633
|
-
const r0 = Xb(t0);
|
|
13634
|
-
|
|
13635
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13636
13511
|
|
|
13637
13512
|
function createReconciler(config) {
|
|
13638
13513
|
const reconciler2 = r0(config);
|
|
@@ -13797,7 +13672,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
13797
13672
|
}
|
|
13798
13673
|
}
|
|
13799
13674
|
const reconstructed = [];
|
|
13800
|
-
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() {
|
|
13801
13684
|
for (const [instance] of reconstructed) {
|
|
13802
13685
|
const parent = instance.parent;
|
|
13803
13686
|
if (parent) {
|
|
@@ -13815,6 +13698,9 @@ function swapInstances() {
|
|
|
13815
13698
|
}
|
|
13816
13699
|
}
|
|
13817
13700
|
if (instance.isHidden) unhideInstance(instance);
|
|
13701
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13702
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13703
|
+
}
|
|
13818
13704
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
13819
13705
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
13820
13706
|
}
|
|
@@ -13823,10 +13709,16 @@ function swapInstances() {
|
|
|
13823
13709
|
const parent = instance.parent;
|
|
13824
13710
|
if (parent) {
|
|
13825
13711
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13712
|
+
const prevObject = instance.object;
|
|
13826
13713
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
13827
13714
|
instance.object.__r3f = instance;
|
|
13828
13715
|
setFiberRef(fiber, instance.object);
|
|
13716
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13717
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13718
|
+
}
|
|
13829
13719
|
delete instance.appliedOnce;
|
|
13720
|
+
instance.eventCount = 0;
|
|
13721
|
+
instance.handlers = {};
|
|
13830
13722
|
applyProps(instance.object, instance.props);
|
|
13831
13723
|
if (instance.props.attach) {
|
|
13832
13724
|
attach(parent, instance);
|
|
@@ -13843,14 +13735,114 @@ function swapInstances() {
|
|
|
13843
13735
|
invalidateInstance(instance);
|
|
13844
13736
|
}
|
|
13845
13737
|
}
|
|
13846
|
-
reconstructed.length = 0;
|
|
13847
13738
|
}
|
|
13848
13739
|
const handleTextInstance = () => {
|
|
13849
13740
|
};
|
|
13850
13741
|
const NO_CONTEXT = {};
|
|
13851
13742
|
let currentUpdatePriority = NoEventPriority;
|
|
13852
|
-
|
|
13853
|
-
|
|
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
|
+
}
|
|
13854
13846
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
13855
13847
|
isPrimaryRenderer: false,
|
|
13856
13848
|
warnsIfNotActing: false,
|
|
@@ -13889,16 +13881,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13889
13881
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
13890
13882
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
13891
13883
|
if (reconstruct) {
|
|
13892
|
-
reconstructed.push([instance,
|
|
13884
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
13893
13885
|
} else {
|
|
13894
13886
|
const changedProps = diffProps(instance, newProps);
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
|
|
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);
|
|
13899
13892
|
}
|
|
13900
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
13901
|
-
if (isTailSibling) swapInstances();
|
|
13902
13893
|
},
|
|
13903
13894
|
finalizeInitialChildren: (instance) => {
|
|
13904
13895
|
for (const prop in instance.props) {
|
|
@@ -13923,8 +13914,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13923
13914
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
13924
13915
|
return prepare(target, container, "", {});
|
|
13925
13916
|
},
|
|
13926
|
-
|
|
13927
|
-
|
|
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,
|
|
13928
13920
|
shouldSetTextContent: () => false,
|
|
13929
13921
|
clearContainer: () => false,
|
|
13930
13922
|
hideInstance,
|
|
@@ -13932,6 +13924,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13932
13924
|
createTextInstance: handleTextInstance,
|
|
13933
13925
|
hideTextInstance: handleTextInstance,
|
|
13934
13926
|
unhideTextInstance: handleTextInstance,
|
|
13927
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
13928
|
+
supportsMicrotasks: true,
|
|
13929
|
+
scheduleMicrotask,
|
|
13935
13930
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
13936
13931
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
13937
13932
|
noTimeout: -1,
|
|
@@ -13972,28 +13967,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13972
13967
|
},
|
|
13973
13968
|
resolveUpdatePriority() {
|
|
13974
13969
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
13975
|
-
|
|
13976
|
-
|
|
13977
|
-
|
|
13978
|
-
case "dblclick":
|
|
13979
|
-
case "dragenter":
|
|
13980
|
-
case "dragleave":
|
|
13981
|
-
case "drop":
|
|
13982
|
-
case "pointercancel":
|
|
13983
|
-
case "pointerdown":
|
|
13984
|
-
case "pointerup":
|
|
13985
|
-
return e;
|
|
13986
|
-
case "dragover":
|
|
13987
|
-
case "pointermove":
|
|
13988
|
-
case "pointerout":
|
|
13989
|
-
case "pointerover":
|
|
13990
|
-
case "pointerenter":
|
|
13991
|
-
case "pointerleave":
|
|
13992
|
-
case "wheel":
|
|
13993
|
-
return o;
|
|
13994
|
-
default:
|
|
13995
|
-
return r;
|
|
13996
|
-
}
|
|
13970
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
13971
|
+
if (eventType === void 0) return r;
|
|
13972
|
+
return getEventPriority(eventType);
|
|
13997
13973
|
},
|
|
13998
13974
|
resetFormInstance() {
|
|
13999
13975
|
},
|
|
@@ -14042,11 +14018,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14042
14018
|
cloneMutableTextInstance(textInstance) {
|
|
14043
14019
|
return textInstance;
|
|
14044
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.
|
|
14045
14027
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14046
|
-
throw new Error("Not implemented.");
|
|
14047
14028
|
},
|
|
14048
14029
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14049
|
-
throw new Error("Not implemented.");
|
|
14050
14030
|
},
|
|
14051
14031
|
// https://github.com/facebook/react/pull/32465
|
|
14052
14032
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14131,6 +14111,7 @@ function createRoot(canvas) {
|
|
|
14131
14111
|
const lastConfiguredProps = {};
|
|
14132
14112
|
let configured = false;
|
|
14133
14113
|
let pending = null;
|
|
14114
|
+
let rendererSetup = null;
|
|
14134
14115
|
return {
|
|
14135
14116
|
async configure(props = {}) {
|
|
14136
14117
|
let resolve;
|
|
@@ -14161,7 +14142,7 @@ function createRoot(canvas) {
|
|
|
14161
14142
|
forceEven
|
|
14162
14143
|
} = props;
|
|
14163
14144
|
const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
|
|
14164
|
-
|
|
14145
|
+
let state = store.getState();
|
|
14165
14146
|
const defaultGLProps = {
|
|
14166
14147
|
canvas,
|
|
14167
14148
|
powerPreference: "high-performance",
|
|
@@ -14189,56 +14170,68 @@ function createRoot(canvas) {
|
|
|
14189
14170
|
"The `primaryCanvas` prop for multi-canvas rendering cannot be used with WebGL. Remove the `gl` prop or use WebGPU."
|
|
14190
14171
|
);
|
|
14191
14172
|
}
|
|
14192
|
-
if (
|
|
14193
|
-
|
|
14194
|
-
|
|
14195
|
-
|
|
14196
|
-
|
|
14197
|
-
|
|
14198
|
-
|
|
14199
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
14239
14226
|
}
|
|
14240
|
-
}))
|
|
14227
|
+
})().catch((err) => {
|
|
14228
|
+
rendererSetup = null;
|
|
14229
|
+
throw err;
|
|
14230
|
+
});
|
|
14241
14231
|
}
|
|
14232
|
+
await rendererSetup;
|
|
14233
|
+
state = store.getState();
|
|
14234
|
+
renderer = state.internal.actualRenderer;
|
|
14242
14235
|
}
|
|
14243
14236
|
let raycaster = state.raycaster;
|
|
14244
14237
|
if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
|
|
@@ -14588,7 +14581,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14588
14581
|
dispose(state.scene);
|
|
14589
14582
|
_roots.delete(canvas);
|
|
14590
14583
|
if (callback) callback(canvas);
|
|
14591
|
-
} catch {
|
|
14584
|
+
} catch (error) {
|
|
14585
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
14592
14586
|
}
|
|
14593
14587
|
}, 500);
|
|
14594
14588
|
}
|
|
@@ -14651,6 +14645,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14651
14645
|
viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
|
|
14652
14646
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14653
14647
|
}
|
|
14648
|
+
const set = injectState.set;
|
|
14654
14649
|
return {
|
|
14655
14650
|
// The intersect consists of the previous root state
|
|
14656
14651
|
...rootState,
|
|
@@ -14669,7 +14664,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14669
14664
|
size: resolvedSize,
|
|
14670
14665
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14671
14666
|
// Layers are allowed to override events
|
|
14672
|
-
setEvents: (events2) =>
|
|
14667
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
14673
14668
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
14674
14669
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
14675
14670
|
};
|
|
@@ -14698,6 +14693,212 @@ function flushSync(fn) {
|
|
|
14698
14693
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14699
14694
|
}
|
|
14700
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
|
+
|
|
14701
14902
|
function parseBackground(background) {
|
|
14702
14903
|
if (!background) return null;
|
|
14703
14904
|
if (typeof background === "object" && !background.isColor) {
|
|
@@ -14728,14 +14929,49 @@ function parseBackground(background) {
|
|
|
14728
14929
|
return null;
|
|
14729
14930
|
}
|
|
14730
14931
|
|
|
14932
|
+
function parseRendererConfig(rendererProp) {
|
|
14933
|
+
const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
|
|
14934
|
+
if (isRendererConfig) {
|
|
14935
|
+
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14936
|
+
return {
|
|
14937
|
+
primaryCanvas: pc,
|
|
14938
|
+
scheduler: sc,
|
|
14939
|
+
renderer: Object.keys(rest).length > 0 ? rest : rendererProp
|
|
14940
|
+
};
|
|
14941
|
+
}
|
|
14942
|
+
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14943
|
+
}
|
|
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
|
+
|
|
14731
14971
|
function clearHmrCaches(store) {
|
|
14732
|
-
store.
|
|
14733
|
-
|
|
14734
|
-
|
|
14735
|
-
buffers: {},
|
|
14736
|
-
gpuStorage: {},
|
|
14737
|
-
_hmrVersion: state._hmrVersion + 1
|
|
14738
|
-
}));
|
|
14972
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14973
|
+
invalidateAllResources(primary);
|
|
14974
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14739
14975
|
}
|
|
14740
14976
|
|
|
14741
14977
|
function CanvasImpl({
|
|
@@ -14771,18 +15007,7 @@ function CanvasImpl({
|
|
|
14771
15007
|
forceEven,
|
|
14772
15008
|
...props
|
|
14773
15009
|
}) {
|
|
14774
|
-
const
|
|
14775
|
-
let primaryCanvas;
|
|
14776
|
-
let scheduler;
|
|
14777
|
-
let renderer;
|
|
14778
|
-
if (isRendererConfig) {
|
|
14779
|
-
const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
|
|
14780
|
-
primaryCanvas = pc;
|
|
14781
|
-
scheduler = sc;
|
|
14782
|
-
renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
|
|
14783
|
-
} else {
|
|
14784
|
-
renderer = rendererProp;
|
|
14785
|
-
}
|
|
15010
|
+
const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
|
|
14786
15011
|
React.useMemo(() => extend(THREE), []);
|
|
14787
15012
|
const Bridge = useBridge();
|
|
14788
15013
|
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
@@ -14827,6 +15052,7 @@ function CanvasImpl({
|
|
|
14827
15052
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
14828
15053
|
const [block, setBlock] = React.useState(false);
|
|
14829
15054
|
const [error, setError] = React.useState(false);
|
|
15055
|
+
const [fallbackVisible, setFallbackVisible] = React.useState(false);
|
|
14830
15056
|
if (block) throw block;
|
|
14831
15057
|
if (error) throw error;
|
|
14832
15058
|
const root = React.useRef(null);
|
|
@@ -14834,6 +15060,7 @@ function CanvasImpl({
|
|
|
14834
15060
|
const unsubscribeErrorRef = React.useRef(null);
|
|
14835
15061
|
useIsomorphicLayoutEffect(() => {
|
|
14836
15062
|
effectActiveRef.current = true;
|
|
15063
|
+
if (fallbackVisible) return;
|
|
14837
15064
|
const canvas = canvasRef.current;
|
|
14838
15065
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
14839
15066
|
if (!root.current) {
|
|
@@ -14854,7 +15081,7 @@ function CanvasImpl({
|
|
|
14854
15081
|
}
|
|
14855
15082
|
async function run() {
|
|
14856
15083
|
if (!effectActiveRef.current || !root.current) return;
|
|
14857
|
-
await root.current.configure({
|
|
15084
|
+
const configured = await root.current.configure({
|
|
14858
15085
|
id,
|
|
14859
15086
|
primaryCanvas,
|
|
14860
15087
|
scheduler,
|
|
@@ -14881,7 +15108,7 @@ function CanvasImpl({
|
|
|
14881
15108
|
onDropMissed: (...args) => handleDropMissed.current?.(...args),
|
|
14882
15109
|
onCreated: (state) => {
|
|
14883
15110
|
state.events.connect?.(
|
|
14884
|
-
eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15111
|
+
eventSource ? isRef$1(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
14885
15112
|
);
|
|
14886
15113
|
if (eventPrefix) {
|
|
14887
15114
|
state.setEvents({
|
|
@@ -14895,8 +15122,20 @@ function CanvasImpl({
|
|
|
14895
15122
|
}
|
|
14896
15123
|
onCreated?.(state);
|
|
14897
15124
|
}
|
|
14898
|
-
})
|
|
14899
|
-
|
|
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;
|
|
14900
15139
|
root.current.render(
|
|
14901
15140
|
/* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
|
|
14902
15141
|
backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
|
|
@@ -14959,7 +15198,11 @@ function CanvasImpl({
|
|
|
14959
15198
|
...style
|
|
14960
15199
|
},
|
|
14961
15200
|
...props,
|
|
14962
|
-
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(
|
|
14963
15206
|
"canvas",
|
|
14964
15207
|
{
|
|
14965
15208
|
ref: canvasRef,
|
|
@@ -14978,4 +15221,4 @@ function Canvas(props) {
|
|
|
14978
15221
|
|
|
14979
15222
|
extend(THREE);
|
|
14980
15223
|
|
|
14981
|
-
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 };
|