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