@react-three/fiber 10.0.0-canary.76d2134 → 10.0.0-canary.8f5b4d3
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 +2178 -2179
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +2181 -2182
- package/dist/legacy.cjs +2176 -2177
- package/dist/legacy.d.cts +3 -4
- package/dist/legacy.d.mts +3 -4
- package/dist/legacy.d.ts +3 -4
- package/dist/legacy.mjs +2179 -2180
- package/dist/webgpu/index.cjs +2176 -2177
- package/dist/webgpu/index.d.cts +3 -4
- package/dist/webgpu/index.d.mts +3 -4
- package/dist/webgpu/index.d.ts +3 -4
- package/dist/webgpu/index.mjs +2179 -2180
- package/package.json +1 -1
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_getCurrentPriorityLevel, unstable_IdlePriority, unstable_LowPriority, unstable_NormalPriority, unstable_UserBlockingPriority, unstable_ImmediatePriority, unstable_scheduleCallback } 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) {
|
|
@@ -114,555 +113,229 @@ function getPrimaryIds() {
|
|
|
114
113
|
return Array.from(primaryRegistry.keys());
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
var __defProp = Object.defineProperty;
|
|
117
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
118
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
119
|
+
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
120
|
+
function useMutableCallback(fn) {
|
|
121
|
+
const ref = React.useRef(fn);
|
|
122
|
+
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
123
|
+
return ref;
|
|
124
|
+
}
|
|
125
|
+
function useBridge() {
|
|
126
|
+
const fiber = useFiber();
|
|
127
|
+
const ContextBridge = useContextBridge();
|
|
128
|
+
return React.useMemo(
|
|
129
|
+
() => ({ children }) => {
|
|
130
|
+
const strict = !!traverseFiber(fiber, true, (node) => node.type === React.StrictMode);
|
|
131
|
+
const Root = strict ? React.StrictMode : React.Fragment;
|
|
132
|
+
return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) });
|
|
133
|
+
},
|
|
134
|
+
[fiber, ContextBridge]
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function Block({ set }) {
|
|
138
|
+
useIsomorphicLayoutEffect(() => {
|
|
139
|
+
set(new Promise(() => null));
|
|
140
|
+
return () => set(false);
|
|
141
|
+
}, [set]);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
145
|
+
var _a;
|
|
146
|
+
return _a = class extends React.Component {
|
|
147
|
+
constructor() {
|
|
148
|
+
super(...arguments);
|
|
149
|
+
__publicField(this, "state", { error: false });
|
|
150
|
+
}
|
|
151
|
+
componentDidCatch(err) {
|
|
152
|
+
this.props.set(err);
|
|
153
|
+
}
|
|
154
|
+
render() {
|
|
155
|
+
return this.state.error ? null : this.props.children;
|
|
156
|
+
}
|
|
157
|
+
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
158
|
+
})();
|
|
129
159
|
|
|
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);
|
|
160
|
+
const is = {
|
|
161
|
+
obj: (a) => a === Object(a) && !is.arr(a) && typeof a !== "function",
|
|
162
|
+
fun: (a) => typeof a === "function",
|
|
163
|
+
str: (a) => typeof a === "string",
|
|
164
|
+
num: (a) => typeof a === "number",
|
|
165
|
+
boo: (a) => typeof a === "boolean",
|
|
166
|
+
und: (a) => a === void 0,
|
|
167
|
+
nul: (a) => a === null,
|
|
168
|
+
arr: (a) => Array.isArray(a),
|
|
169
|
+
equ(a, b, { arrays = "shallow", objects = "reference", strict = true } = {}) {
|
|
170
|
+
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
171
|
+
if (is.str(a) || is.num(a) || is.boo(a)) return a === b;
|
|
172
|
+
const isObj = is.obj(a);
|
|
173
|
+
if (isObj && objects === "reference") return a === b;
|
|
174
|
+
const isArr = is.arr(a);
|
|
175
|
+
if (isArr && arrays === "reference") return a === b;
|
|
176
|
+
if ((isArr || isObj) && a === b) return true;
|
|
177
|
+
let i;
|
|
178
|
+
for (i in a) if (!(i in b)) return false;
|
|
179
|
+
if (isObj && arrays === "shallow" && objects === "shallow") {
|
|
180
|
+
for (i in strict ? b : a) if (!is.equ(a[i], b[i], { strict, objects: "reference" })) return false;
|
|
181
|
+
} else {
|
|
182
|
+
for (i in strict ? b : a) if (a[i] !== b[i]) return false;
|
|
154
183
|
}
|
|
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);
|
|
184
|
+
if (is.und(i)) {
|
|
185
|
+
if (isArr && a.length === 0 && b.length === 0) return true;
|
|
186
|
+
if (isObj && Object.keys(a).length === 0 && Object.keys(b).length === 0) return true;
|
|
187
|
+
if (a !== b) return false;
|
|
166
188
|
}
|
|
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];
|
|
189
|
+
return true;
|
|
216
190
|
}
|
|
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
191
|
};
|
|
222
|
-
|
|
223
|
-
|
|
192
|
+
const isOrthographicCamera = (def) => def && def.isOrthographicCamera;
|
|
193
|
+
const isRef$1 = (obj) => obj !== null && typeof obj === "object" && obj.hasOwnProperty("current");
|
|
194
|
+
const isColorRepresentation = (value) => value != null && (typeof value === "string" || typeof value === "number" || value.isColor);
|
|
195
|
+
const isObject3D = (object) => object?.isObject3D;
|
|
196
|
+
const isTexture = (value) => !!value?.isTexture;
|
|
197
|
+
const isVectorLike = (object) => object !== null && typeof object === "object" && "set" in object && typeof object.set === "function";
|
|
198
|
+
const isCopyable = (object) => isVectorLike(object) && "copy" in object && typeof object.copy === "function";
|
|
199
|
+
const hasConstructor = (object) => !!object?.constructor;
|
|
200
|
+
|
|
201
|
+
function calculateDpr(dpr) {
|
|
202
|
+
const target = typeof window !== "undefined" ? window.devicePixelRatio ?? 2 : 1;
|
|
203
|
+
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
224
204
|
}
|
|
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 };
|
|
205
|
+
function getUuidPrefix(uuid) {
|
|
206
|
+
return uuid.split("-")[0];
|
|
231
207
|
}
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
|
|
208
|
+
function updateCamera(camera, size) {
|
|
209
|
+
if (camera.manual) return;
|
|
210
|
+
if (isOrthographicCamera(camera)) {
|
|
211
|
+
camera.left = size.width / -2;
|
|
212
|
+
camera.right = size.width / 2;
|
|
213
|
+
camera.top = size.height / 2;
|
|
214
|
+
camera.bottom = size.height / -2;
|
|
215
|
+
} else {
|
|
216
|
+
camera.aspect = size.width / size.height;
|
|
217
|
+
}
|
|
218
|
+
camera.updateProjectionMatrix();
|
|
235
219
|
}
|
|
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
|
-
};
|
|
220
|
+
const frustumMatrix = new Matrix4();
|
|
221
|
+
function updateFrustum(camera, frustum) {
|
|
222
|
+
const target = frustum ?? new Frustum();
|
|
223
|
+
frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
224
|
+
target.setFromProjectionMatrix(frustumMatrix);
|
|
225
|
+
return target;
|
|
271
226
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return
|
|
227
|
+
|
|
228
|
+
const REACT_INTERNAL_PROPS = ["children", "key", "ref"];
|
|
229
|
+
function findInitialRoot(instance) {
|
|
230
|
+
let root = instance.root;
|
|
231
|
+
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
232
|
+
return root;
|
|
278
233
|
}
|
|
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
|
|
234
|
+
function getRootState(obj) {
|
|
235
|
+
let state = obj.__r3f?.root.getState();
|
|
236
|
+
if (!state) {
|
|
237
|
+
obj.traverseAncestors((ancestor) => {
|
|
238
|
+
const parentState = ancestor.__r3f?.root.getState();
|
|
239
|
+
if (parentState) {
|
|
240
|
+
state = parentState;
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
299
243
|
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return () => {
|
|
303
|
-
texture.dispose();
|
|
304
|
-
};
|
|
305
|
-
}, [texture]);
|
|
306
|
-
return null;
|
|
244
|
+
}
|
|
245
|
+
return state;
|
|
307
246
|
}
|
|
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
|
|
247
|
+
function buildGraph(object) {
|
|
248
|
+
const data = { nodes: {}, materials: {}, meshes: {} };
|
|
249
|
+
if (object) {
|
|
250
|
+
object.traverse((obj) => {
|
|
251
|
+
if (obj.name) data.nodes[obj.name] = obj;
|
|
252
|
+
if (obj.material) {
|
|
253
|
+
const material = Array.isArray(obj.material) ? obj.material[0] : obj.material;
|
|
254
|
+
const nameAlreadyUsed = data.materials[material.name];
|
|
255
|
+
let materialName = material.name;
|
|
256
|
+
if (nameAlreadyUsed) {
|
|
257
|
+
materialName = materialName + `-${getUuidPrefix(material.uuid)}`;
|
|
258
|
+
material.userData.materialCacheName = materialName;
|
|
259
|
+
}
|
|
260
|
+
data.materials[materialName] = material;
|
|
261
|
+
}
|
|
262
|
+
if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
|
|
356
263
|
});
|
|
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
|
-
) });
|
|
264
|
+
}
|
|
265
|
+
return data;
|
|
391
266
|
}
|
|
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
|
-
] });
|
|
267
|
+
function dispose(obj) {
|
|
268
|
+
if (obj.type !== "Scene") obj.dispose?.();
|
|
269
|
+
for (const p in obj) {
|
|
270
|
+
const prop = obj[p];
|
|
271
|
+
if (prop?.type !== "Scene") prop?.dispose?.();
|
|
272
|
+
}
|
|
412
273
|
}
|
|
413
|
-
function
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
274
|
+
function getInstanceProps(pendingProps) {
|
|
275
|
+
const props = {};
|
|
276
|
+
for (const key in pendingProps) {
|
|
277
|
+
if (!REACT_INTERNAL_PROPS.includes(key)) props[key] = pendingProps[key];
|
|
278
|
+
}
|
|
279
|
+
return props;
|
|
280
|
+
}
|
|
281
|
+
function prepare(target, root, type, props) {
|
|
282
|
+
const object = target;
|
|
283
|
+
let instance = object?.__r3f;
|
|
284
|
+
if (!instance) {
|
|
285
|
+
instance = {
|
|
286
|
+
root,
|
|
287
|
+
type,
|
|
288
|
+
parent: null,
|
|
289
|
+
children: [],
|
|
290
|
+
props: getInstanceProps(props),
|
|
291
|
+
object,
|
|
292
|
+
eventCount: 0,
|
|
293
|
+
handlers: {},
|
|
294
|
+
isHidden: false
|
|
422
295
|
};
|
|
423
|
-
|
|
424
|
-
|
|
296
|
+
if (object) object.__r3f = instance;
|
|
297
|
+
}
|
|
298
|
+
return instance;
|
|
425
299
|
}
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
] });
|
|
300
|
+
function invalidateInstance(instance) {
|
|
301
|
+
if (!instance.parent) return;
|
|
302
|
+
instance.props.onUpdate?.(instance.object);
|
|
303
|
+
const state = instance.root?.getState?.();
|
|
304
|
+
if (state && state.internal.frames === 0) state.invalidate();
|
|
432
305
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
306
|
+
|
|
307
|
+
const tempFrustum = new Frustum();
|
|
308
|
+
let hasWarnedWebGL = false;
|
|
309
|
+
let tslModule = null;
|
|
310
|
+
async function loadTSL() {
|
|
311
|
+
if (tslModule) return tslModule;
|
|
312
|
+
try {
|
|
313
|
+
const tsl = await import('three/tsl');
|
|
314
|
+
tslModule = { uniform: tsl.uniform, nodeObject: tsl.nodeObject };
|
|
315
|
+
return tslModule;
|
|
316
|
+
} catch {
|
|
317
|
+
return null;
|
|
439
318
|
}
|
|
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
319
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
[fiber, ContextBridge]
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
function Block({ set }) {
|
|
465
|
-
useIsomorphicLayoutEffect(() => {
|
|
466
|
-
set(new Promise(() => null));
|
|
467
|
-
return () => set(false);
|
|
468
|
-
}, [set]);
|
|
469
|
-
return null;
|
|
470
|
-
}
|
|
471
|
-
const ErrorBoundary = /* @__PURE__ */ (() => {
|
|
472
|
-
var _a;
|
|
473
|
-
return _a = class extends React.Component {
|
|
474
|
-
constructor() {
|
|
475
|
-
super(...arguments);
|
|
476
|
-
__publicField(this, "state", { error: false });
|
|
477
|
-
}
|
|
478
|
-
componentDidCatch(err) {
|
|
479
|
-
this.props.set(err);
|
|
480
|
-
}
|
|
481
|
-
render() {
|
|
482
|
-
return this.state.error ? null : this.props.children;
|
|
483
|
-
}
|
|
484
|
-
}, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
|
|
485
|
-
})();
|
|
486
|
-
|
|
487
|
-
const is = {
|
|
488
|
-
obj: (a) => a === Object(a) && !is.arr(a) && typeof a !== "function",
|
|
489
|
-
fun: (a) => typeof a === "function",
|
|
490
|
-
str: (a) => typeof a === "string",
|
|
491
|
-
num: (a) => typeof a === "number",
|
|
492
|
-
boo: (a) => typeof a === "boolean",
|
|
493
|
-
und: (a) => a === void 0,
|
|
494
|
-
nul: (a) => a === null,
|
|
495
|
-
arr: (a) => Array.isArray(a),
|
|
496
|
-
equ(a, b, { arrays = "shallow", objects = "reference", strict = true } = {}) {
|
|
497
|
-
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
498
|
-
if (is.str(a) || is.num(a) || is.boo(a)) return a === b;
|
|
499
|
-
const isObj = is.obj(a);
|
|
500
|
-
if (isObj && objects === "reference") return a === b;
|
|
501
|
-
const isArr = is.arr(a);
|
|
502
|
-
if (isArr && arrays === "reference") return a === b;
|
|
503
|
-
if ((isArr || isObj) && a === b) return true;
|
|
504
|
-
let i;
|
|
505
|
-
for (i in a) if (!(i in b)) return false;
|
|
506
|
-
if (isObj && arrays === "shallow" && objects === "shallow") {
|
|
507
|
-
for (i in strict ? b : a) if (!is.equ(a[i], b[i], { strict, objects: "reference" })) return false;
|
|
508
|
-
} else {
|
|
509
|
-
for (i in strict ? b : a) if (a[i] !== b[i]) return false;
|
|
510
|
-
}
|
|
511
|
-
if (is.und(i)) {
|
|
512
|
-
if (isArr && a.length === 0 && b.length === 0) return true;
|
|
513
|
-
if (isObj && Object.keys(a).length === 0 && Object.keys(b).length === 0) return true;
|
|
514
|
-
if (a !== b) return false;
|
|
515
|
-
}
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
const isOrthographicCamera = (def) => def && def.isOrthographicCamera;
|
|
520
|
-
const isRef = (obj) => obj !== null && typeof obj === "object" && obj.hasOwnProperty("current");
|
|
521
|
-
const isColorRepresentation = (value) => value != null && (typeof value === "string" || typeof value === "number" || value.isColor);
|
|
522
|
-
const isObject3D = (object) => object?.isObject3D;
|
|
523
|
-
const isTexture = (value) => !!value?.isTexture;
|
|
524
|
-
const isVectorLike = (object) => object !== null && typeof object === "object" && "set" in object && typeof object.set === "function";
|
|
525
|
-
const isCopyable = (object) => isVectorLike(object) && "copy" in object && typeof object.copy === "function";
|
|
526
|
-
const hasConstructor = (object) => !!object?.constructor;
|
|
527
|
-
|
|
528
|
-
function calculateDpr(dpr) {
|
|
529
|
-
const target = typeof window !== "undefined" ? window.devicePixelRatio ?? 2 : 1;
|
|
530
|
-
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
531
|
-
}
|
|
532
|
-
function getUuidPrefix(uuid) {
|
|
533
|
-
return uuid.split("-")[0];
|
|
534
|
-
}
|
|
535
|
-
function updateCamera(camera, size) {
|
|
536
|
-
if (camera.manual) return;
|
|
537
|
-
if (isOrthographicCamera(camera)) {
|
|
538
|
-
camera.left = size.width / -2;
|
|
539
|
-
camera.right = size.width / 2;
|
|
540
|
-
camera.top = size.height / 2;
|
|
541
|
-
camera.bottom = size.height / -2;
|
|
542
|
-
} else {
|
|
543
|
-
camera.aspect = size.width / size.height;
|
|
544
|
-
}
|
|
545
|
-
camera.updateProjectionMatrix();
|
|
546
|
-
}
|
|
547
|
-
const frustumMatrix = new Matrix4();
|
|
548
|
-
function updateFrustum(camera, frustum) {
|
|
549
|
-
const target = frustum ?? new Frustum();
|
|
550
|
-
frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
551
|
-
target.setFromProjectionMatrix(frustumMatrix);
|
|
552
|
-
return target;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const REACT_INTERNAL_PROPS = ["children", "key", "ref"];
|
|
556
|
-
function findInitialRoot(instance) {
|
|
557
|
-
let root = instance.root;
|
|
558
|
-
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
559
|
-
return root;
|
|
560
|
-
}
|
|
561
|
-
function getRootState(obj) {
|
|
562
|
-
let state = obj.__r3f?.root.getState();
|
|
563
|
-
if (!state) {
|
|
564
|
-
obj.traverseAncestors((ancestor) => {
|
|
565
|
-
const parentState = ancestor.__r3f?.root.getState();
|
|
566
|
-
if (parentState) {
|
|
567
|
-
state = parentState;
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
return state;
|
|
573
|
-
}
|
|
574
|
-
function buildGraph(object) {
|
|
575
|
-
const data = { nodes: {}, materials: {}, meshes: {} };
|
|
576
|
-
if (object) {
|
|
577
|
-
object.traverse((obj) => {
|
|
578
|
-
if (obj.name) data.nodes[obj.name] = obj;
|
|
579
|
-
if (obj.material) {
|
|
580
|
-
const material = Array.isArray(obj.material) ? obj.material[0] : obj.material;
|
|
581
|
-
const nameAlreadyUsed = data.materials[material.name];
|
|
582
|
-
let materialName = material.name;
|
|
583
|
-
if (nameAlreadyUsed) {
|
|
584
|
-
materialName = materialName + `-${getUuidPrefix(material.uuid)}`;
|
|
585
|
-
material.userData.materialCacheName = materialName;
|
|
586
|
-
}
|
|
587
|
-
data.materials[materialName] = material;
|
|
588
|
-
}
|
|
589
|
-
if (obj.isMesh && !data.meshes[obj.name]) data.meshes[obj.name] = obj;
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
return data;
|
|
593
|
-
}
|
|
594
|
-
function dispose(obj) {
|
|
595
|
-
if (obj.type !== "Scene") obj.dispose?.();
|
|
596
|
-
for (const p in obj) {
|
|
597
|
-
const prop = obj[p];
|
|
598
|
-
if (prop?.type !== "Scene") prop?.dispose?.();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
function getInstanceProps(pendingProps) {
|
|
602
|
-
const props = {};
|
|
603
|
-
for (const key in pendingProps) {
|
|
604
|
-
if (!REACT_INTERNAL_PROPS.includes(key)) props[key] = pendingProps[key];
|
|
605
|
-
}
|
|
606
|
-
return props;
|
|
607
|
-
}
|
|
608
|
-
function prepare(target, root, type, props) {
|
|
609
|
-
const object = target;
|
|
610
|
-
let instance = object?.__r3f;
|
|
611
|
-
if (!instance) {
|
|
612
|
-
instance = {
|
|
613
|
-
root,
|
|
614
|
-
type,
|
|
615
|
-
parent: null,
|
|
616
|
-
children: [],
|
|
617
|
-
props: getInstanceProps(props),
|
|
618
|
-
object,
|
|
619
|
-
eventCount: 0,
|
|
620
|
-
handlers: {},
|
|
621
|
-
isHidden: false
|
|
622
|
-
};
|
|
623
|
-
if (object) object.__r3f = instance;
|
|
624
|
-
}
|
|
625
|
-
return instance;
|
|
626
|
-
}
|
|
627
|
-
function invalidateInstance(instance) {
|
|
628
|
-
if (!instance.parent) return;
|
|
629
|
-
instance.props.onUpdate?.(instance.object);
|
|
630
|
-
const state = instance.root?.getState?.();
|
|
631
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
const tempFrustum = new Frustum();
|
|
635
|
-
let hasWarnedWebGL = false;
|
|
636
|
-
let tslModule = null;
|
|
637
|
-
async function loadTSL() {
|
|
638
|
-
if (tslModule) return tslModule;
|
|
639
|
-
try {
|
|
640
|
-
const tsl = await import('three/tsl');
|
|
641
|
-
tslModule = { uniform: tsl.uniform, nodeObject: tsl.nodeObject };
|
|
642
|
-
return tslModule;
|
|
643
|
-
} catch {
|
|
644
|
-
return null;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
function createOcclusionObserverNode(store, uniform) {
|
|
648
|
-
const node = new Node("float");
|
|
649
|
-
node.updateType = NodeUpdateType.OBJECT;
|
|
650
|
-
node.update = function(frame) {
|
|
651
|
-
const { internal } = store.getState();
|
|
652
|
-
const registry = internal.visibilityRegistry;
|
|
653
|
-
const cache = internal.occlusionCache;
|
|
654
|
-
for (const entry of registry.values()) {
|
|
655
|
-
const { object, handlers } = entry;
|
|
656
|
-
if (handlers.onOccluded || handlers.onVisible) {
|
|
657
|
-
const isOccluded = frame.renderer.isOccluded(object);
|
|
658
|
-
cache.set(object, isOccluded);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
node.setup = function() {
|
|
663
|
-
return uniform(0);
|
|
664
|
-
};
|
|
665
|
-
return node;
|
|
320
|
+
function createOcclusionObserverNode(store, uniform) {
|
|
321
|
+
const node = new Node("float");
|
|
322
|
+
node.updateType = NodeUpdateType.OBJECT;
|
|
323
|
+
node.update = function(frame) {
|
|
324
|
+
const { internal } = store.getState();
|
|
325
|
+
const registry = internal.visibilityRegistry;
|
|
326
|
+
const cache = internal.occlusionCache;
|
|
327
|
+
for (const entry of registry.values()) {
|
|
328
|
+
const { object, handlers } = entry;
|
|
329
|
+
if (handlers.onOccluded || handlers.onVisible) {
|
|
330
|
+
const isOccluded = frame.renderer.isOccluded(object);
|
|
331
|
+
cache.set(object, isOccluded);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
node.setup = function() {
|
|
336
|
+
return uniform(0);
|
|
337
|
+
};
|
|
338
|
+
return node;
|
|
666
339
|
}
|
|
667
340
|
let occlusionSetupPromise = null;
|
|
668
341
|
function enableOcclusion(store) {
|
|
@@ -1065,1348 +738,888 @@ function applyProps(object, props) {
|
|
|
1065
738
|
return object;
|
|
1066
739
|
}
|
|
1067
740
|
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (!state) {
|
|
1073
|
-
state = {
|
|
1074
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1075
|
-
captured: /* @__PURE__ */ new Map(),
|
|
1076
|
-
initialClick: [0, 0],
|
|
1077
|
-
initialHits: []
|
|
1078
|
-
};
|
|
1079
|
-
internal.pointerMap.set(pointerId, state);
|
|
741
|
+
const shownNotices = /* @__PURE__ */ new Set();
|
|
742
|
+
function notifyDepreciated({ heading, body, link }) {
|
|
743
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
|
|
744
|
+
return;
|
|
1080
745
|
}
|
|
1081
|
-
return
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
function makeId(event) {
|
|
1087
|
-
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1088
|
-
}
|
|
1089
|
-
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1090
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1091
|
-
if (!pointerState) return;
|
|
1092
|
-
const captureData = pointerState.captured.get(obj);
|
|
1093
|
-
if (captureData) {
|
|
1094
|
-
pointerState.captured.delete(obj);
|
|
1095
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
746
|
+
if (shownNotices.has(heading)) return;
|
|
747
|
+
shownNotices.add(heading);
|
|
748
|
+
const caller = getCallerFrame();
|
|
749
|
+
if (caller) {
|
|
750
|
+
console.log();
|
|
1096
751
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
for (let i = 0; i < internal.interaction.length; i++) {
|
|
1101
|
-
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
752
|
+
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
753
|
+
if (caller) {
|
|
754
|
+
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
1102
755
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
if (value.eventObject === object || value.object === object) {
|
|
1109
|
-
pointerState.hovered.delete(key);
|
|
1110
|
-
const next = {
|
|
1111
|
-
...value,
|
|
1112
|
-
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
1113
|
-
object: value.object === object ? newObject : value.object
|
|
1114
|
-
};
|
|
1115
|
-
pointerState.hovered.set(makeId(next), next);
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
const captureData = pointerState.captured.get(object);
|
|
1119
|
-
if (captureData) {
|
|
1120
|
-
pointerState.captured.delete(object);
|
|
1121
|
-
pointerState.captured.set(newObject, {
|
|
1122
|
-
...captureData,
|
|
1123
|
-
intersection: {
|
|
1124
|
-
...captureData.intersection,
|
|
1125
|
-
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
1126
|
-
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
756
|
+
if (body || link) {
|
|
757
|
+
let message = "";
|
|
758
|
+
if (body) message += body;
|
|
759
|
+
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
760
|
+
console.warn(`%c${message}`, "font-weight: bold;");
|
|
1130
761
|
}
|
|
1131
|
-
unregisterVisibility(store, object);
|
|
1132
762
|
}
|
|
1133
|
-
function
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
});
|
|
1143
|
-
if (pointerState.captured.has(object)) {
|
|
1144
|
-
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1145
|
-
}
|
|
763
|
+
function getCallerFrame(depth = 3) {
|
|
764
|
+
const stack = new Error().stack;
|
|
765
|
+
if (!stack) return null;
|
|
766
|
+
const lines = stack.split("\n");
|
|
767
|
+
const frame = lines[depth];
|
|
768
|
+
if (!frame) return null;
|
|
769
|
+
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
770
|
+
if (!match) {
|
|
771
|
+
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
1146
772
|
}
|
|
1147
|
-
|
|
773
|
+
if (!match) return null;
|
|
774
|
+
const [, fn, url, line] = match;
|
|
775
|
+
return {
|
|
776
|
+
functionName: fn ?? "<anonymous>",
|
|
777
|
+
location: formatLocation(url, Number(line))
|
|
778
|
+
};
|
|
1148
779
|
}
|
|
1149
|
-
function
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
780
|
+
function formatLocation(url, line) {
|
|
781
|
+
const clean = url.split("?")[0];
|
|
782
|
+
const file = clean.split("/").pop() ?? clean;
|
|
783
|
+
return `${file}:${line}`;
|
|
784
|
+
}
|
|
785
|
+
function notifyAlpha({ message, link }) {
|
|
786
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
787
|
+
return;
|
|
1158
788
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
) || obj.__r3f?.handlers.onDrop
|
|
1166
|
-
);
|
|
789
|
+
if (shownNotices.has(message)) return;
|
|
790
|
+
shownNotices.add(message);
|
|
791
|
+
const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
|
|
792
|
+
console.log(`%c\u{1F52C} ${message}`, boxStyle);
|
|
793
|
+
{
|
|
794
|
+
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
1167
795
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
799
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
800
|
+
if (!stack) return false;
|
|
801
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
802
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
806
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
|
|
807
|
+
const createStore = (invalidate, advance) => {
|
|
808
|
+
const rootStore = createWithEqualityFn((set, get) => {
|
|
809
|
+
const position = new Vector3();
|
|
810
|
+
const defaultTarget = new Vector3();
|
|
811
|
+
const tempTarget = new Vector3();
|
|
812
|
+
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
813
|
+
const { width, height, top, left } = size;
|
|
814
|
+
const aspect = width / height;
|
|
815
|
+
if (target.isVector3) tempTarget.copy(target);
|
|
816
|
+
else tempTarget.set(...target);
|
|
817
|
+
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
818
|
+
if (isOrthographicCamera(camera)) {
|
|
819
|
+
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
820
|
+
} else {
|
|
821
|
+
const fov = camera.fov * Math.PI / 180;
|
|
822
|
+
const h = 2 * Math.tan(fov / 2) * distance;
|
|
823
|
+
const w = h * (width / height);
|
|
824
|
+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1188
825
|
}
|
|
1189
|
-
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
1190
826
|
}
|
|
1191
|
-
let
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
827
|
+
let performanceTimeout = void 0;
|
|
828
|
+
const setPerformanceCurrent = (current) => set((state2) => ({ performance: { ...state2.performance, current } }));
|
|
829
|
+
const pointer = new Vector2();
|
|
830
|
+
const rootState = {
|
|
831
|
+
set,
|
|
832
|
+
get,
|
|
833
|
+
// Mock objects that have to be configured
|
|
834
|
+
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
835
|
+
primaryStore: null,
|
|
836
|
+
gl: null,
|
|
837
|
+
renderer: null,
|
|
838
|
+
camera: null,
|
|
839
|
+
frustum: new Frustum(),
|
|
840
|
+
autoUpdateFrustum: true,
|
|
841
|
+
raycaster: null,
|
|
842
|
+
events: {
|
|
843
|
+
priority: 1,
|
|
844
|
+
enabled: true,
|
|
845
|
+
connected: false,
|
|
846
|
+
frameTimedRaycasts: true,
|
|
847
|
+
alwaysFireOnScroll: true,
|
|
848
|
+
updateOnFrame: false
|
|
849
|
+
},
|
|
850
|
+
scene: null,
|
|
851
|
+
rootScene: null,
|
|
852
|
+
xr: null,
|
|
853
|
+
inspector: null,
|
|
854
|
+
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
855
|
+
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
856
|
+
textureColorSpace: SRGBColorSpace,
|
|
857
|
+
isLegacy: false,
|
|
858
|
+
webGPUSupported: false,
|
|
859
|
+
isNative: false,
|
|
860
|
+
controls: null,
|
|
861
|
+
pointer,
|
|
862
|
+
mouse: pointer,
|
|
863
|
+
frameloop: "always",
|
|
864
|
+
onPointerMissed: void 0,
|
|
865
|
+
onDragOverMissed: void 0,
|
|
866
|
+
onDropMissed: void 0,
|
|
867
|
+
performance: {
|
|
868
|
+
current: 1,
|
|
869
|
+
min: 0.5,
|
|
870
|
+
max: 1,
|
|
871
|
+
debounce: 200,
|
|
872
|
+
regress: () => {
|
|
873
|
+
const state2 = get();
|
|
874
|
+
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
875
|
+
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
876
|
+
performanceTimeout = setTimeout(
|
|
877
|
+
() => setPerformanceCurrent(get().performance.max),
|
|
878
|
+
state2.performance.debounce
|
|
879
|
+
);
|
|
1199
880
|
}
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
881
|
+
},
|
|
882
|
+
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
883
|
+
viewport: {
|
|
884
|
+
initialDpr: 0,
|
|
885
|
+
dpr: 0,
|
|
886
|
+
width: 0,
|
|
887
|
+
height: 0,
|
|
888
|
+
top: 0,
|
|
889
|
+
left: 0,
|
|
890
|
+
aspect: 0,
|
|
891
|
+
distance: 0,
|
|
892
|
+
factor: 0,
|
|
893
|
+
getCurrentViewport
|
|
894
|
+
},
|
|
895
|
+
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
896
|
+
setSize: (width, height, top, left) => {
|
|
897
|
+
const state2 = get();
|
|
898
|
+
if (width === void 0) {
|
|
899
|
+
set({ _sizeImperative: false });
|
|
900
|
+
if (state2._sizeProps) {
|
|
901
|
+
const { width: propW, height: propH } = state2._sizeProps;
|
|
902
|
+
if (propW !== void 0 || propH !== void 0) {
|
|
903
|
+
const currentSize = state2.size;
|
|
904
|
+
const newSize = {
|
|
905
|
+
width: propW ?? currentSize.width,
|
|
906
|
+
height: propH ?? currentSize.height,
|
|
907
|
+
top: currentSize.top,
|
|
908
|
+
left: currentSize.left
|
|
909
|
+
};
|
|
910
|
+
set((s) => ({
|
|
911
|
+
size: newSize,
|
|
912
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
913
|
+
}));
|
|
914
|
+
getScheduler().invalidate();
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return;
|
|
1218
918
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
919
|
+
const w = width;
|
|
920
|
+
const h = height ?? width;
|
|
921
|
+
const t = top ?? state2.size.top;
|
|
922
|
+
const l = left ?? state2.size.left;
|
|
923
|
+
const size = { width: w, height: h, top: t, left: l };
|
|
924
|
+
set((s) => ({
|
|
925
|
+
size,
|
|
926
|
+
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
927
|
+
_sizeImperative: true
|
|
928
|
+
}));
|
|
929
|
+
getScheduler().invalidate();
|
|
930
|
+
},
|
|
931
|
+
setDpr: (dpr) => set((state2) => {
|
|
932
|
+
const resolved = calculateDpr(dpr);
|
|
933
|
+
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
934
|
+
}),
|
|
935
|
+
setFrameloop: (frameloop = "always") => {
|
|
936
|
+
set(() => ({ frameloop }));
|
|
937
|
+
getScheduler().frameloop = frameloop;
|
|
938
|
+
},
|
|
939
|
+
setError: (error) => set(() => ({ error })),
|
|
940
|
+
error: null,
|
|
941
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
942
|
+
uniforms: {},
|
|
943
|
+
nodes: {},
|
|
944
|
+
buffers: {},
|
|
945
|
+
gpuStorage: {},
|
|
946
|
+
textures: /* @__PURE__ */ new Map(),
|
|
947
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
948
|
+
renderPipeline: null,
|
|
949
|
+
passes: {},
|
|
950
|
+
_hmrVersion: 0,
|
|
951
|
+
_sizeImperative: false,
|
|
952
|
+
_sizeProps: null,
|
|
953
|
+
previousRoot: void 0,
|
|
954
|
+
internal: {
|
|
955
|
+
// Events
|
|
956
|
+
interaction: [],
|
|
957
|
+
subscribers: [],
|
|
958
|
+
// Per-pointer state (new unified structure)
|
|
959
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
960
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
961
|
+
lastEvent: React.createRef(),
|
|
962
|
+
// Deprecated but kept for backwards compatibility
|
|
963
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
964
|
+
initialClick: [0, 0],
|
|
965
|
+
initialHits: [],
|
|
966
|
+
capturedMap: /* @__PURE__ */ new Map(),
|
|
967
|
+
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
968
|
+
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
969
|
+
// Occlusion system (WebGPU only)
|
|
970
|
+
occlusionEnabled: false,
|
|
971
|
+
occlusionObserver: null,
|
|
972
|
+
occlusionCache: /* @__PURE__ */ new Map(),
|
|
973
|
+
helperGroup: null,
|
|
974
|
+
// Updates
|
|
975
|
+
active: false,
|
|
976
|
+
frames: 0,
|
|
977
|
+
priority: 0,
|
|
978
|
+
subscribe: (ref, priority, store) => {
|
|
979
|
+
const internal = get().internal;
|
|
980
|
+
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
981
|
+
internal.subscribers.push({ ref, priority, store });
|
|
982
|
+
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
983
|
+
return () => {
|
|
984
|
+
const internal2 = get().internal;
|
|
985
|
+
if (internal2?.subscribers) {
|
|
986
|
+
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
987
|
+
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
},
|
|
991
|
+
// Renderer Storage (single source of truth)
|
|
992
|
+
actualRenderer: null,
|
|
993
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
994
|
+
scheduler: null
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
return rootState;
|
|
998
|
+
});
|
|
999
|
+
const state = rootStore.getState();
|
|
1000
|
+
Object.defineProperty(state, "gl", {
|
|
1001
|
+
get() {
|
|
1002
|
+
const currentState = rootStore.getState();
|
|
1003
|
+
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1004
|
+
const stack = new Error().stack || "";
|
|
1005
|
+
if (!isInternalRendererAccess(stack)) {
|
|
1006
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1007
|
+
notifyDepreciated({
|
|
1008
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
1009
|
+
body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
|
|
1010
|
+
});
|
|
1228
1011
|
}
|
|
1229
1012
|
}
|
|
1013
|
+
return currentState.internal.actualRenderer;
|
|
1014
|
+
},
|
|
1015
|
+
set(value) {
|
|
1016
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1017
|
+
},
|
|
1018
|
+
enumerable: true,
|
|
1019
|
+
configurable: true
|
|
1020
|
+
});
|
|
1021
|
+
Object.defineProperty(state, "renderer", {
|
|
1022
|
+
get() {
|
|
1023
|
+
return rootStore.getState().internal.actualRenderer;
|
|
1024
|
+
},
|
|
1025
|
+
set(value) {
|
|
1026
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1027
|
+
},
|
|
1028
|
+
enumerable: true,
|
|
1029
|
+
configurable: true
|
|
1030
|
+
});
|
|
1031
|
+
let oldScene = state.scene;
|
|
1032
|
+
rootStore.subscribe(() => {
|
|
1033
|
+
const currentState = rootStore.getState();
|
|
1034
|
+
const { scene, rootScene, set } = currentState;
|
|
1035
|
+
if (scene !== oldScene) {
|
|
1036
|
+
oldScene = scene;
|
|
1037
|
+
if (scene?.isScene && scene !== rootScene) {
|
|
1038
|
+
set({ rootScene: scene });
|
|
1039
|
+
}
|
|
1230
1040
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
1253
|
-
};
|
|
1254
|
-
const extractEventProps = {};
|
|
1255
|
-
for (const prop in event) {
|
|
1256
|
-
const property = event[prop];
|
|
1257
|
-
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
1258
|
-
}
|
|
1259
|
-
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
1260
|
-
const raycastEvent = {
|
|
1261
|
-
...hit,
|
|
1262
|
-
...extractEventProps,
|
|
1263
|
-
pointer,
|
|
1264
|
-
intersections,
|
|
1265
|
-
stopped: localState.stopped,
|
|
1266
|
-
delta,
|
|
1267
|
-
unprojectedPoint,
|
|
1268
|
-
ray: raycaster.ray,
|
|
1269
|
-
camera,
|
|
1270
|
-
pointerId: eventPointerId,
|
|
1271
|
-
// Hijack stopPropagation, which just sets a flag
|
|
1272
|
-
stopPropagation() {
|
|
1273
|
-
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1274
|
-
if (
|
|
1275
|
-
// ...if this pointer hasn't been captured
|
|
1276
|
-
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1277
|
-
pointerState.captured.has(hit.eventObject)
|
|
1278
|
-
) {
|
|
1279
|
-
raycastEvent.stopped = localState.stopped = true;
|
|
1280
|
-
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1281
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1282
|
-
cancelPointer([...higher, hit], eventPointerId);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
},
|
|
1286
|
-
// there should be a distinction between target and currentTarget
|
|
1287
|
-
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1288
|
-
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1289
|
-
nativeEvent: event
|
|
1290
|
-
};
|
|
1291
|
-
callback(raycastEvent);
|
|
1292
|
-
if (localState.stopped === true) break;
|
|
1041
|
+
});
|
|
1042
|
+
let oldSize = state.size;
|
|
1043
|
+
let oldDpr = state.viewport.dpr;
|
|
1044
|
+
let oldCamera = state.camera;
|
|
1045
|
+
rootStore.subscribe(() => {
|
|
1046
|
+
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1047
|
+
const actualRenderer = internal.actualRenderer;
|
|
1048
|
+
const canvasTarget = internal.canvasTarget;
|
|
1049
|
+
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1050
|
+
oldSize = size;
|
|
1051
|
+
oldDpr = viewport.dpr;
|
|
1052
|
+
updateCamera(camera, size);
|
|
1053
|
+
if (internal.isSecondary && canvasTarget) {
|
|
1054
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1055
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1056
|
+
} else {
|
|
1057
|
+
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1058
|
+
actualRenderer.setSize(size.width, size.height, false);
|
|
1059
|
+
if (canvasTarget) {
|
|
1060
|
+
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1061
|
+
canvasTarget.setSize(size.width, size.height, false);
|
|
1293
1062
|
}
|
|
1294
1063
|
}
|
|
1295
1064
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
if (
|
|
1305
|
-
(
|
|
1306
|
-
)) {
|
|
1307
|
-
const eventObject = hoveredObj.eventObject;
|
|
1308
|
-
const instance = eventObject.__r3f;
|
|
1309
|
-
pointerState.hovered.delete(hoveredId);
|
|
1310
|
-
if (instance?.eventCount) {
|
|
1311
|
-
const handlers = instance.handlers;
|
|
1312
|
-
const data = { ...hoveredObj, intersections };
|
|
1313
|
-
handlers.onPointerOut?.(data);
|
|
1314
|
-
handlers.onPointerLeave?.(data);
|
|
1315
|
-
handlers.onDragOverLeave?.(data);
|
|
1316
|
-
}
|
|
1065
|
+
if (camera !== oldCamera) {
|
|
1066
|
+
oldCamera = camera;
|
|
1067
|
+
const { rootScene } = rootStore.getState();
|
|
1068
|
+
if (camera && rootScene && !camera.parent) {
|
|
1069
|
+
rootScene.add(camera);
|
|
1070
|
+
}
|
|
1071
|
+
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1072
|
+
const currentState = rootStore.getState();
|
|
1073
|
+
if (currentState.autoUpdateFrustum && camera) {
|
|
1074
|
+
updateFrustum(camera, currentState.frustum);
|
|
1317
1075
|
}
|
|
1318
1076
|
}
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1077
|
+
});
|
|
1078
|
+
rootStore.subscribe((state2) => invalidate(state2));
|
|
1079
|
+
return rootStore;
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
const memoizedLoaders = /* @__PURE__ */ new WeakMap();
|
|
1083
|
+
const isConstructor$1 = (value) => typeof value === "function" && value?.prototype?.constructor === value;
|
|
1084
|
+
function getLoader$1(Proto) {
|
|
1085
|
+
if (isConstructor$1(Proto)) {
|
|
1086
|
+
let loader = memoizedLoaders.get(Proto);
|
|
1087
|
+
if (!loader) {
|
|
1088
|
+
loader = new Proto();
|
|
1089
|
+
memoizedLoaders.set(Proto, loader);
|
|
1324
1090
|
}
|
|
1091
|
+
return loader;
|
|
1325
1092
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
function cleanupPointer(pointerId) {
|
|
1339
|
-
const { internal } = store.getState();
|
|
1340
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1341
|
-
if (pointerState) {
|
|
1342
|
-
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1343
|
-
const eventObject = hoveredObj.eventObject;
|
|
1344
|
-
const instance = eventObject.__r3f;
|
|
1345
|
-
if (instance?.eventCount) {
|
|
1346
|
-
const handlers = instance.handlers;
|
|
1347
|
-
const data = { ...hoveredObj, intersections: [] };
|
|
1348
|
-
handlers.onPointerOut?.(data);
|
|
1349
|
-
handlers.onPointerLeave?.(data);
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
internal.pointerMap.delete(pointerId);
|
|
1093
|
+
return Proto;
|
|
1094
|
+
}
|
|
1095
|
+
function loadingFn(extensions, onProgress) {
|
|
1096
|
+
return function(Proto, input) {
|
|
1097
|
+
const loader = getLoader$1(Proto);
|
|
1098
|
+
if (extensions) extensions(loader);
|
|
1099
|
+
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1100
|
+
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1101
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1102
|
+
return data;
|
|
1103
|
+
});
|
|
1353
1104
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1105
|
+
return new Promise(
|
|
1106
|
+
(res, reject) => loader.load(
|
|
1107
|
+
input,
|
|
1108
|
+
(data) => {
|
|
1109
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1110
|
+
res(data);
|
|
1111
|
+
},
|
|
1112
|
+
onProgress,
|
|
1113
|
+
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1114
|
+
)
|
|
1115
|
+
);
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1119
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1120
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1121
|
+
const fn = loadingFn(extensions, onProgress);
|
|
1122
|
+
const results = cacheKeys.map(
|
|
1123
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1124
|
+
);
|
|
1125
|
+
return Array.isArray(input) ? results : results[0];
|
|
1126
|
+
}
|
|
1127
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1128
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1129
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1130
|
+
cacheKeys.forEach(
|
|
1131
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1132
|
+
);
|
|
1133
|
+
};
|
|
1134
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1135
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1136
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
1137
|
+
};
|
|
1138
|
+
useLoader.loader = getLoader$1;
|
|
1139
|
+
|
|
1140
|
+
function useFrame(callback, priorityOrOptions) {
|
|
1141
|
+
const store = React.useContext(context);
|
|
1142
|
+
const isInsideCanvas = store !== null;
|
|
1143
|
+
const scheduler = getScheduler();
|
|
1144
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
1145
|
+
id: priorityOrOptions.id,
|
|
1146
|
+
phase: priorityOrOptions.phase,
|
|
1147
|
+
priority: priorityOrOptions.priority,
|
|
1148
|
+
fps: priorityOrOptions.fps,
|
|
1149
|
+
drop: priorityOrOptions.drop,
|
|
1150
|
+
enabled: priorityOrOptions.enabled,
|
|
1151
|
+
before: priorityOrOptions.before,
|
|
1152
|
+
after: priorityOrOptions.after
|
|
1153
|
+
}) : "";
|
|
1154
|
+
const options = React.useMemo(() => {
|
|
1155
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
1156
|
+
}, [optionsKey]);
|
|
1157
|
+
const reactId = React.useId();
|
|
1158
|
+
const id = options.id ?? reactId;
|
|
1159
|
+
const callbackRef = useMutableCallback(callback);
|
|
1160
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
1161
|
+
useIsomorphicLayoutEffect(() => {
|
|
1162
|
+
if (!callback) return;
|
|
1163
|
+
if (isInsideCanvas) {
|
|
1164
|
+
const state = store.getState();
|
|
1165
|
+
const rootId = state.internal.rootId;
|
|
1166
|
+
if (isLegacyPriority) {
|
|
1167
|
+
state.internal.priority++;
|
|
1168
|
+
let parentRoot = state.previousRoot;
|
|
1169
|
+
while (parentRoot) {
|
|
1170
|
+
const parentState = parentRoot.getState();
|
|
1171
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
1172
|
+
parentRoot = parentState?.previousRoot;
|
|
1378
1173
|
}
|
|
1174
|
+
notifyDepreciated({
|
|
1175
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
1176
|
+
body: 'Using useFrame(callback, number) to control render order is deprecated.\n\nFor custom rendering, use: useFrame(callback, { phase: "render" })\nFor execution order within update phase, use: useFrame(callback, { priority: number })',
|
|
1177
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
1178
|
+
});
|
|
1379
1179
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return () => cancelPointer([]);
|
|
1389
|
-
// Global cancel of these events
|
|
1390
|
-
case "onPointerCancel":
|
|
1391
|
-
return (event) => {
|
|
1392
|
-
const pointerId = getPointerId(event);
|
|
1393
|
-
cleanupPointer(pointerId);
|
|
1180
|
+
const wrappedCallback = (frameState, delta) => {
|
|
1181
|
+
const localState = store.getState();
|
|
1182
|
+
const mergedState = {
|
|
1183
|
+
...localState,
|
|
1184
|
+
time: frameState.time,
|
|
1185
|
+
delta: frameState.delta,
|
|
1186
|
+
elapsed: frameState.elapsed,
|
|
1187
|
+
frame: frameState.frame
|
|
1394
1188
|
};
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1189
|
+
callbackRef.current?.(mergedState, delta);
|
|
1190
|
+
};
|
|
1191
|
+
const unregister = scheduler.register(wrappedCallback, {
|
|
1192
|
+
id,
|
|
1193
|
+
rootId,
|
|
1194
|
+
...options
|
|
1195
|
+
});
|
|
1196
|
+
return () => {
|
|
1197
|
+
unregister();
|
|
1198
|
+
if (isLegacyPriority) {
|
|
1199
|
+
const currentState = store.getState();
|
|
1200
|
+
if (currentState.internal) {
|
|
1201
|
+
currentState.internal.priority--;
|
|
1202
|
+
let parentRoot = currentState.previousRoot;
|
|
1203
|
+
while (parentRoot) {
|
|
1204
|
+
const parentState = parentRoot.getState();
|
|
1205
|
+
if (parentState?.internal) parentState.internal.priority--;
|
|
1206
|
+
parentRoot = parentState?.previousRoot;
|
|
1207
|
+
}
|
|
1408
1208
|
}
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
return function handleEvent(event) {
|
|
1412
|
-
const state = store.getState();
|
|
1413
|
-
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
1414
|
-
const pointerId = getPointerId(event);
|
|
1415
|
-
internal.lastEvent.current = event;
|
|
1416
|
-
if (!events.enabled) return;
|
|
1417
|
-
const isPointerMove = name === "onPointerMove";
|
|
1418
|
-
const isDragOver = name === "onDragOver";
|
|
1419
|
-
const isDrop = name === "onDrop";
|
|
1420
|
-
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
1421
|
-
const isPointerDown = name === "onPointerDown";
|
|
1422
|
-
const isPointerUp = name === "onPointerUp";
|
|
1423
|
-
const isWheel = name === "onWheel";
|
|
1424
|
-
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1425
|
-
if (isPointerMove && canDeferRaycasts) {
|
|
1426
|
-
events.compute?.(event, state);
|
|
1427
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1428
|
-
return;
|
|
1429
|
-
}
|
|
1430
|
-
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1431
|
-
events.compute?.(event, state);
|
|
1432
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1433
|
-
return;
|
|
1434
|
-
}
|
|
1435
|
-
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1436
|
-
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1437
|
-
internal.pointerDirty.delete(pointerId);
|
|
1438
|
-
processDeferredPointer(deferredEvent, pointerId);
|
|
1439
|
-
}
|
|
1440
|
-
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1441
|
-
const hits = intersect(event, filter);
|
|
1442
|
-
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1443
|
-
if (isPointerDown) {
|
|
1444
|
-
const pointerState2 = getPointerState(internal, pointerId);
|
|
1445
|
-
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1446
|
-
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1447
|
-
}
|
|
1448
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1449
|
-
const initialHits = pointerState?.initialHits ?? [];
|
|
1450
|
-
if (isClickEvent && !hits.length) {
|
|
1451
|
-
if (delta <= 2) {
|
|
1452
|
-
pointerMissed(event, internal.interaction);
|
|
1453
|
-
if (onPointerMissed) onPointerMissed(event);
|
|
1454
1209
|
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1210
|
+
};
|
|
1211
|
+
} else {
|
|
1212
|
+
return scheduler.register(
|
|
1213
|
+
(state, delta) => {
|
|
1214
|
+
const frameState = state;
|
|
1215
|
+
if (!frameState.renderer) return;
|
|
1216
|
+
callbackRef.current?.(frameState, delta);
|
|
1217
|
+
},
|
|
1218
|
+
{ id, ...options }
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
1222
|
+
const isPaused = React.useSyncExternalStore(
|
|
1223
|
+
// Subscribe function
|
|
1224
|
+
React.useCallback(
|
|
1225
|
+
(onStoreChange) => {
|
|
1226
|
+
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
1227
|
+
},
|
|
1228
|
+
[id]
|
|
1229
|
+
),
|
|
1230
|
+
// getSnapshot function
|
|
1231
|
+
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
1232
|
+
// getServerSnapshot function (SSR)
|
|
1233
|
+
React.useCallback(() => false, [])
|
|
1234
|
+
);
|
|
1235
|
+
const controls = React.useMemo(() => {
|
|
1236
|
+
const scheduler2 = getScheduler();
|
|
1237
|
+
return {
|
|
1238
|
+
/** The job's unique ID */
|
|
1239
|
+
id,
|
|
1240
|
+
/**
|
|
1241
|
+
* Access to the global scheduler for frame loop control.
|
|
1242
|
+
* Use for controlling the entire frame loop, adding phases, etc.
|
|
1243
|
+
*/
|
|
1244
|
+
scheduler: scheduler2,
|
|
1245
|
+
/**
|
|
1246
|
+
* Manually step this job only.
|
|
1247
|
+
* Bypasses FPS limiting - always runs.
|
|
1248
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1249
|
+
*/
|
|
1250
|
+
step: (timestamp) => {
|
|
1251
|
+
getScheduler().stepJob(id, timestamp);
|
|
1252
|
+
},
|
|
1253
|
+
/**
|
|
1254
|
+
* Manually step ALL jobs in the scheduler.
|
|
1255
|
+
* Useful for frameloop='never' mode.
|
|
1256
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1257
|
+
*/
|
|
1258
|
+
stepAll: (timestamp) => {
|
|
1259
|
+
getScheduler().step(timestamp);
|
|
1260
|
+
},
|
|
1261
|
+
/**
|
|
1262
|
+
* Pause this job (set enabled=false).
|
|
1263
|
+
* Job remains registered but won't run.
|
|
1264
|
+
*/
|
|
1265
|
+
pause: () => {
|
|
1266
|
+
getScheduler().pauseJob(id);
|
|
1267
|
+
},
|
|
1268
|
+
/**
|
|
1269
|
+
* Resume this job (set enabled=true).
|
|
1270
|
+
*/
|
|
1271
|
+
resume: () => {
|
|
1272
|
+
getScheduler().resumeJob(id);
|
|
1273
|
+
},
|
|
1274
|
+
/**
|
|
1275
|
+
* Reactive paused state - automatically updates when pause/resume is called.
|
|
1276
|
+
* No need for forceUpdate() in your components.
|
|
1277
|
+
*/
|
|
1278
|
+
isPaused
|
|
1520
1279
|
};
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1280
|
+
}, [id, isPaused]);
|
|
1281
|
+
return controls;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
const IsObject = (url) => url === Object(url) && !Array.isArray(url) && typeof url !== "function";
|
|
1285
|
+
function getUrls(input) {
|
|
1286
|
+
if (typeof input === "string") return [input];
|
|
1287
|
+
if (Array.isArray(input)) return input;
|
|
1288
|
+
return Object.values(input);
|
|
1289
|
+
}
|
|
1290
|
+
function allUrlsCached(urls, textureCache) {
|
|
1291
|
+
return urls.every((url) => textureCache.has(url));
|
|
1292
|
+
}
|
|
1293
|
+
function buildFromCache(input, textureCache) {
|
|
1294
|
+
if (typeof input === "string") {
|
|
1295
|
+
return textureCache.get(input);
|
|
1296
|
+
} else if (Array.isArray(input)) {
|
|
1297
|
+
return input.map((url) => textureCache.get(url));
|
|
1298
|
+
} else {
|
|
1299
|
+
const result = {};
|
|
1300
|
+
const objInput = input;
|
|
1301
|
+
for (const key in objInput) {
|
|
1302
|
+
result[key] = textureCache.get(objInput[key]);
|
|
1527
1303
|
}
|
|
1528
|
-
|
|
1304
|
+
return result;
|
|
1529
1305
|
}
|
|
1530
|
-
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1531
1306
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
const
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
const { events, internal } = store.getState();
|
|
1569
|
-
if (!events.handlers) return;
|
|
1570
|
-
if (pointerId !== void 0) {
|
|
1571
|
-
const event = internal.pointerDirty.get(pointerId);
|
|
1572
|
-
if (event) {
|
|
1573
|
-
internal.pointerDirty.delete(pointerId);
|
|
1574
|
-
processDeferredPointer(event, pointerId);
|
|
1575
|
-
} else if (internal.lastEvent?.current) {
|
|
1576
|
-
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1577
|
-
}
|
|
1578
|
-
} else {
|
|
1579
|
-
flushDeferredPointers();
|
|
1580
|
-
if (internal.lastEvent?.current) {
|
|
1581
|
-
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
},
|
|
1585
|
-
flush: () => {
|
|
1586
|
-
const { events, internal } = store.getState();
|
|
1587
|
-
flushDeferredPointers();
|
|
1588
|
-
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1589
|
-
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1307
|
+
function useTexture(input, optionsOrOnLoad) {
|
|
1308
|
+
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
1309
|
+
const store = useStore();
|
|
1310
|
+
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
1311
|
+
const { onLoad, cache = true } = options;
|
|
1312
|
+
const onLoadRef = useRef(onLoad);
|
|
1313
|
+
onLoadRef.current = onLoad;
|
|
1314
|
+
const onLoadCalledForRef = useRef(null);
|
|
1315
|
+
const urls = useMemo(() => getUrls(input), [input]);
|
|
1316
|
+
const cachedResult = useMemo(() => {
|
|
1317
|
+
if (!cache) return null;
|
|
1318
|
+
const textures = store.getState().textures;
|
|
1319
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
1320
|
+
return buildFromCache(input, textures);
|
|
1321
|
+
}, [cache, urls, input, store]);
|
|
1322
|
+
const loadedTextures = useLoader(
|
|
1323
|
+
TextureLoader,
|
|
1324
|
+
IsObject(input) ? Object.values(input) : input
|
|
1325
|
+
);
|
|
1326
|
+
const inputKey = urls.join("\0");
|
|
1327
|
+
useLayoutEffect(() => {
|
|
1328
|
+
if (cachedResult) return;
|
|
1329
|
+
if (onLoadCalledForRef.current === inputKey) return;
|
|
1330
|
+
onLoadCalledForRef.current = inputKey;
|
|
1331
|
+
onLoadRef.current?.(loadedTextures);
|
|
1332
|
+
}, [cachedResult, loadedTextures, inputKey]);
|
|
1333
|
+
useEffect(() => {
|
|
1334
|
+
if (cachedResult) return;
|
|
1335
|
+
if ("initTexture" in renderer) {
|
|
1336
|
+
let textureArray = [];
|
|
1337
|
+
if (Array.isArray(loadedTextures)) {
|
|
1338
|
+
textureArray = loadedTextures;
|
|
1339
|
+
} else if (loadedTextures instanceof Texture$1) {
|
|
1340
|
+
textureArray = [loadedTextures];
|
|
1341
|
+
} else if (IsObject(loadedTextures)) {
|
|
1342
|
+
textureArray = Object.values(loadedTextures);
|
|
1590
1343
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
const { set, events } = store.getState();
|
|
1595
|
-
events.disconnect?.();
|
|
1596
|
-
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
1597
|
-
if (events.handlers) {
|
|
1598
|
-
for (const name in events.handlers) {
|
|
1599
|
-
const event = events.handlers[name];
|
|
1600
|
-
const [eventName, passive] = DOM_EVENTS[name];
|
|
1601
|
-
target.addEventListener(eventName, event, { passive });
|
|
1344
|
+
textureArray.forEach((texture) => {
|
|
1345
|
+
if (texture instanceof Texture$1) {
|
|
1346
|
+
renderer.initTexture(texture);
|
|
1602
1347
|
}
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
}, [renderer, loadedTextures, cachedResult]);
|
|
1351
|
+
const mappedTextures = useMemo(() => {
|
|
1352
|
+
if (cachedResult) return cachedResult;
|
|
1353
|
+
if (IsObject(input)) {
|
|
1354
|
+
const keyed = {};
|
|
1355
|
+
const textureArray = loadedTextures;
|
|
1356
|
+
let i = 0;
|
|
1357
|
+
for (const key in input) keyed[key] = textureArray[i++];
|
|
1358
|
+
return keyed;
|
|
1359
|
+
} else {
|
|
1360
|
+
return loadedTextures;
|
|
1361
|
+
}
|
|
1362
|
+
}, [input, loadedTextures, cachedResult]);
|
|
1363
|
+
useEffect(() => {
|
|
1364
|
+
if (!cache) return;
|
|
1365
|
+
const urlTextureMap = [];
|
|
1366
|
+
if (typeof input === "string") {
|
|
1367
|
+
urlTextureMap.push([input, mappedTextures]);
|
|
1368
|
+
} else if (Array.isArray(input)) {
|
|
1369
|
+
const textureArray = mappedTextures;
|
|
1370
|
+
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
1371
|
+
} else if (IsObject(input)) {
|
|
1372
|
+
const textureRecord = mappedTextures;
|
|
1373
|
+
for (const key in input) {
|
|
1374
|
+
const url = input[key];
|
|
1375
|
+
urlTextureMap.push([url, textureRecord[key]]);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
store.setState((state) => {
|
|
1379
|
+
const refs = new Map(state._textureRefs);
|
|
1380
|
+
let textures = state.textures;
|
|
1381
|
+
let added = false;
|
|
1382
|
+
for (const [url, texture] of urlTextureMap) {
|
|
1383
|
+
if (!textures.has(url)) {
|
|
1384
|
+
if (!added) {
|
|
1385
|
+
textures = new Map(textures);
|
|
1386
|
+
added = true;
|
|
1613
1387
|
}
|
|
1388
|
+
textures.set(url, texture);
|
|
1614
1389
|
}
|
|
1615
|
-
set(
|
|
1390
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
1616
1391
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
const
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1392
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
1393
|
+
});
|
|
1394
|
+
return () => store.setState((state) => {
|
|
1395
|
+
const refs = new Map(state._textureRefs);
|
|
1396
|
+
for (const [url] of urlTextureMap) {
|
|
1397
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
1398
|
+
if (next <= 0) refs.delete(url);
|
|
1399
|
+
else refs.set(url, next);
|
|
1400
|
+
}
|
|
1401
|
+
return { _textureRefs: refs };
|
|
1402
|
+
});
|
|
1403
|
+
}, [cache, input, mappedTextures, store]);
|
|
1404
|
+
return mappedTextures;
|
|
1405
|
+
}
|
|
1406
|
+
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
1407
|
+
useTexture.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
1408
|
+
const Texture = ({
|
|
1409
|
+
children,
|
|
1410
|
+
input,
|
|
1411
|
+
onLoad,
|
|
1412
|
+
cache
|
|
1413
|
+
}) => {
|
|
1414
|
+
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
1415
|
+
const ret = useTexture(input, options);
|
|
1416
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
function useTextures(selector) {
|
|
1420
|
+
const store = useStore();
|
|
1421
|
+
const registry = useMemo(() => {
|
|
1422
|
+
const getState = store.getState;
|
|
1423
|
+
const setState = store.setState;
|
|
1424
|
+
const getOne = (key) => getState().textures.get(key);
|
|
1425
|
+
return {
|
|
1426
|
+
get all() {
|
|
1427
|
+
return getState().textures;
|
|
1428
|
+
},
|
|
1429
|
+
get(input) {
|
|
1430
|
+
if (typeof input === "string") return getOne(input);
|
|
1431
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
1432
|
+
const out = {};
|
|
1433
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
1434
|
+
return out;
|
|
1435
|
+
},
|
|
1436
|
+
has: (key) => getState().textures.has(key),
|
|
1437
|
+
add(keyOrRecord, texture) {
|
|
1438
|
+
setState((state) => {
|
|
1439
|
+
const textures = new Map(state.textures);
|
|
1440
|
+
if (typeof keyOrRecord === "string") {
|
|
1441
|
+
textures.set(keyOrRecord, texture);
|
|
1442
|
+
} else {
|
|
1443
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
1639
1444
|
}
|
|
1445
|
+
return { textures };
|
|
1446
|
+
});
|
|
1447
|
+
},
|
|
1448
|
+
dispose(key, options) {
|
|
1449
|
+
const state = getState();
|
|
1450
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
1451
|
+
if (refs > 0 && !options?.force) {
|
|
1452
|
+
console.warn(
|
|
1453
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
1454
|
+
);
|
|
1455
|
+
return false;
|
|
1640
1456
|
}
|
|
1641
|
-
|
|
1457
|
+
state.textures.get(key)?.dispose();
|
|
1458
|
+
setState((s) => {
|
|
1459
|
+
const textures = new Map(s.textures);
|
|
1460
|
+
textures.delete(key);
|
|
1461
|
+
const nextRefs = new Map(s._textureRefs);
|
|
1462
|
+
nextRefs.delete(key);
|
|
1463
|
+
return { textures, _textureRefs: nextRefs };
|
|
1464
|
+
});
|
|
1465
|
+
return true;
|
|
1466
|
+
},
|
|
1467
|
+
disposeAll() {
|
|
1468
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
1469
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
1642
1470
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1471
|
+
};
|
|
1472
|
+
}, [store]);
|
|
1473
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
1474
|
+
const selected = useThree(subscribe);
|
|
1475
|
+
return selector ? selected : registry;
|
|
1646
1476
|
}
|
|
1647
1477
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
if (
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
console.warn(`%c${message}`, "font-weight: bold;");
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
function getCallerFrame(depth = 3) {
|
|
1671
|
-
const stack = new Error().stack;
|
|
1672
|
-
if (!stack) return null;
|
|
1673
|
-
const lines = stack.split("\n");
|
|
1674
|
-
const frame = lines[depth];
|
|
1675
|
-
if (!frame) return null;
|
|
1676
|
-
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
1677
|
-
if (!match) {
|
|
1678
|
-
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
1679
|
-
}
|
|
1680
|
-
if (!match) return null;
|
|
1681
|
-
const [, fn, url, line] = match;
|
|
1682
|
-
return {
|
|
1683
|
-
functionName: fn ?? "<anonymous>",
|
|
1684
|
-
location: formatLocation(url, Number(line))
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
function formatLocation(url, line) {
|
|
1688
|
-
const clean = url.split("?")[0];
|
|
1689
|
-
const file = clean.split("/").pop() ?? clean;
|
|
1690
|
-
return `${file}:${line}`;
|
|
1691
|
-
}
|
|
1692
|
-
function notifyAlpha({ message, link }) {
|
|
1693
|
-
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
1694
|
-
return;
|
|
1695
|
-
}
|
|
1696
|
-
if (shownNotices.has(message)) return;
|
|
1697
|
-
shownNotices.add(message);
|
|
1698
|
-
const boxStyle = "background: #6366f1; color: #ffffff; padding: 6px 10px; border-radius: 4px; font-weight: 500;";
|
|
1699
|
-
console.log(`%c\u{1F52C} ${message}`, boxStyle);
|
|
1700
|
-
{
|
|
1701
|
-
console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
|
|
1478
|
+
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
1479
|
+
const isLegacy = useThree((s) => s.isLegacy);
|
|
1480
|
+
const size = useThree((s) => s.size);
|
|
1481
|
+
let width;
|
|
1482
|
+
let height;
|
|
1483
|
+
let opts;
|
|
1484
|
+
if (typeof widthOrOptions === "object") {
|
|
1485
|
+
opts = widthOrOptions;
|
|
1486
|
+
} else if (typeof widthOrOptions === "number") {
|
|
1487
|
+
width = widthOrOptions;
|
|
1488
|
+
if (typeof heightOrOptions === "object") {
|
|
1489
|
+
height = widthOrOptions;
|
|
1490
|
+
opts = heightOrOptions;
|
|
1491
|
+
} else if (typeof heightOrOptions === "number") {
|
|
1492
|
+
height = heightOrOptions;
|
|
1493
|
+
opts = options;
|
|
1494
|
+
} else {
|
|
1495
|
+
height = widthOrOptions;
|
|
1496
|
+
}
|
|
1702
1497
|
}
|
|
1498
|
+
return useMemo(() => {
|
|
1499
|
+
const w = width ?? size.width;
|
|
1500
|
+
const h = height ?? size.height;
|
|
1501
|
+
return new WebGLRenderTarget(w, h, opts);
|
|
1502
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
1703
1503
|
}
|
|
1704
1504
|
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1505
|
+
const presetsObj = {
|
|
1506
|
+
apartment: "lebombo_1k.hdr",
|
|
1507
|
+
city: "potsdamer_platz_1k.hdr",
|
|
1508
|
+
dawn: "kiara_1_dawn_1k.hdr",
|
|
1509
|
+
forest: "forest_slope_1k.hdr",
|
|
1510
|
+
lobby: "st_fagans_interior_1k.hdr",
|
|
1511
|
+
night: "dikhololo_night_1k.hdr",
|
|
1512
|
+
park: "rooitou_park_1k.hdr",
|
|
1513
|
+
studio: "studio_small_03_1k.hdr",
|
|
1514
|
+
sunset: "venice_sunset_1k.hdr",
|
|
1515
|
+
warehouse: "empty_warehouse_01_1k.hdr"
|
|
1516
|
+
};
|
|
1711
1517
|
|
|
1712
|
-
const
|
|
1713
|
-
const
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
1727
|
-
} else {
|
|
1728
|
-
const fov = camera.fov * Math.PI / 180;
|
|
1729
|
-
const h = 2 * Math.tan(fov / 2) * distance;
|
|
1730
|
-
const w = h * (width / height);
|
|
1731
|
-
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
let performanceTimeout = void 0;
|
|
1735
|
-
const setPerformanceCurrent = (current) => set((state2) => ({ performance: { ...state2.performance, current } }));
|
|
1736
|
-
const pointer = new Vector2();
|
|
1737
|
-
const rootState = {
|
|
1738
|
-
set,
|
|
1739
|
-
get,
|
|
1740
|
-
// Mock objects that have to be configured
|
|
1741
|
-
// primaryStore is set after store creation (self-reference for primary, primary's store for secondary)
|
|
1742
|
-
primaryStore: null,
|
|
1743
|
-
gl: null,
|
|
1744
|
-
renderer: null,
|
|
1745
|
-
camera: null,
|
|
1746
|
-
frustum: new Frustum(),
|
|
1747
|
-
autoUpdateFrustum: true,
|
|
1748
|
-
raycaster: null,
|
|
1749
|
-
events: {
|
|
1750
|
-
priority: 1,
|
|
1751
|
-
enabled: true,
|
|
1752
|
-
connected: false,
|
|
1753
|
-
frameTimedRaycasts: true,
|
|
1754
|
-
alwaysFireOnScroll: true,
|
|
1755
|
-
updateOnFrame: false
|
|
1756
|
-
},
|
|
1757
|
-
scene: null,
|
|
1758
|
-
rootScene: null,
|
|
1759
|
-
xr: null,
|
|
1760
|
-
inspector: null,
|
|
1761
|
-
invalidate: (frames = 1, stackFrames = false) => invalidate(get(), frames, stackFrames),
|
|
1762
|
-
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
1763
|
-
textureColorSpace: SRGBColorSpace,
|
|
1764
|
-
isLegacy: false,
|
|
1765
|
-
webGPUSupported: false,
|
|
1766
|
-
isNative: false,
|
|
1767
|
-
controls: null,
|
|
1768
|
-
pointer,
|
|
1769
|
-
mouse: pointer,
|
|
1770
|
-
frameloop: "always",
|
|
1771
|
-
onPointerMissed: void 0,
|
|
1772
|
-
onDragOverMissed: void 0,
|
|
1773
|
-
onDropMissed: void 0,
|
|
1774
|
-
performance: {
|
|
1775
|
-
current: 1,
|
|
1776
|
-
min: 0.5,
|
|
1777
|
-
max: 1,
|
|
1778
|
-
debounce: 200,
|
|
1779
|
-
regress: () => {
|
|
1780
|
-
const state2 = get();
|
|
1781
|
-
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
1782
|
-
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
1783
|
-
performanceTimeout = setTimeout(
|
|
1784
|
-
() => setPerformanceCurrent(get().performance.max),
|
|
1785
|
-
state2.performance.debounce
|
|
1786
|
-
);
|
|
1787
|
-
}
|
|
1788
|
-
},
|
|
1789
|
-
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
1790
|
-
viewport: {
|
|
1791
|
-
initialDpr: 0,
|
|
1792
|
-
dpr: 0,
|
|
1793
|
-
width: 0,
|
|
1794
|
-
height: 0,
|
|
1795
|
-
top: 0,
|
|
1796
|
-
left: 0,
|
|
1797
|
-
aspect: 0,
|
|
1798
|
-
distance: 0,
|
|
1799
|
-
factor: 0,
|
|
1800
|
-
getCurrentViewport
|
|
1801
|
-
},
|
|
1802
|
-
setEvents: (events) => set((state2) => ({ ...state2, events: { ...state2.events, ...events } })),
|
|
1803
|
-
setSize: (width, height, top, left) => {
|
|
1804
|
-
const state2 = get();
|
|
1805
|
-
if (width === void 0) {
|
|
1806
|
-
set({ _sizeImperative: false });
|
|
1807
|
-
if (state2._sizeProps) {
|
|
1808
|
-
const { width: propW, height: propH } = state2._sizeProps;
|
|
1809
|
-
if (propW !== void 0 || propH !== void 0) {
|
|
1810
|
-
const currentSize = state2.size;
|
|
1811
|
-
const newSize = {
|
|
1812
|
-
width: propW ?? currentSize.width,
|
|
1813
|
-
height: propH ?? currentSize.height,
|
|
1814
|
-
top: currentSize.top,
|
|
1815
|
-
left: currentSize.left
|
|
1816
|
-
};
|
|
1817
|
-
set((s) => ({
|
|
1818
|
-
size: newSize,
|
|
1819
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1820
|
-
}));
|
|
1821
|
-
getScheduler().invalidate();
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
return;
|
|
1825
|
-
}
|
|
1826
|
-
const w = width;
|
|
1827
|
-
const h = height ?? width;
|
|
1828
|
-
const t = top ?? state2.size.top;
|
|
1829
|
-
const l = left ?? state2.size.left;
|
|
1830
|
-
const size = { width: w, height: h, top: t, left: l };
|
|
1831
|
-
set((s) => ({
|
|
1832
|
-
size,
|
|
1833
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1834
|
-
_sizeImperative: true
|
|
1835
|
-
}));
|
|
1836
|
-
getScheduler().invalidate();
|
|
1837
|
-
},
|
|
1838
|
-
setDpr: (dpr) => set((state2) => {
|
|
1839
|
-
const resolved = calculateDpr(dpr);
|
|
1840
|
-
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
1841
|
-
}),
|
|
1842
|
-
setFrameloop: (frameloop = "always") => {
|
|
1843
|
-
set(() => ({ frameloop }));
|
|
1844
|
-
getScheduler().frameloop = frameloop;
|
|
1845
|
-
},
|
|
1846
|
-
setError: (error) => set(() => ({ error })),
|
|
1847
|
-
error: null,
|
|
1848
|
-
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
1849
|
-
uniforms: {},
|
|
1850
|
-
nodes: {},
|
|
1851
|
-
buffers: {},
|
|
1852
|
-
gpuStorage: {},
|
|
1853
|
-
textures: /* @__PURE__ */ new Map(),
|
|
1854
|
-
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1855
|
-
renderPipeline: null,
|
|
1856
|
-
passes: {},
|
|
1857
|
-
_hmrVersion: 0,
|
|
1858
|
-
_sizeImperative: false,
|
|
1859
|
-
_sizeProps: null,
|
|
1860
|
-
previousRoot: void 0,
|
|
1861
|
-
internal: {
|
|
1862
|
-
// Events
|
|
1863
|
-
interaction: [],
|
|
1864
|
-
subscribers: [],
|
|
1865
|
-
// Per-pointer state (new unified structure)
|
|
1866
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
1867
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1868
|
-
lastEvent: React.createRef(),
|
|
1869
|
-
// Deprecated but kept for backwards compatibility
|
|
1870
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1871
|
-
initialClick: [0, 0],
|
|
1872
|
-
initialHits: [],
|
|
1873
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
1874
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1875
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1876
|
-
// Occlusion system (WebGPU only)
|
|
1877
|
-
occlusionEnabled: false,
|
|
1878
|
-
occlusionObserver: null,
|
|
1879
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1880
|
-
helperGroup: null,
|
|
1881
|
-
// Updates
|
|
1882
|
-
active: false,
|
|
1883
|
-
frames: 0,
|
|
1884
|
-
priority: 0,
|
|
1885
|
-
subscribe: (ref, priority, store) => {
|
|
1886
|
-
const internal = get().internal;
|
|
1887
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1888
|
-
internal.subscribers.push({ ref, priority, store });
|
|
1889
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1890
|
-
return () => {
|
|
1891
|
-
const internal2 = get().internal;
|
|
1892
|
-
if (internal2?.subscribers) {
|
|
1893
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1894
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
},
|
|
1898
|
-
// Renderer Storage (single source of truth)
|
|
1899
|
-
actualRenderer: null,
|
|
1900
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1901
|
-
scheduler: null
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
return rootState;
|
|
1905
|
-
});
|
|
1906
|
-
const state = rootStore.getState();
|
|
1907
|
-
Object.defineProperty(state, "gl", {
|
|
1908
|
-
get() {
|
|
1909
|
-
const currentState = rootStore.getState();
|
|
1910
|
-
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1911
|
-
const stack = new Error().stack || "";
|
|
1912
|
-
if (!isInternalRendererAccess(stack)) {
|
|
1913
|
-
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1914
|
-
notifyDepreciated({
|
|
1915
|
-
heading: "Accessing state.gl in WebGPU mode",
|
|
1916
|
-
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
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
return currentState.internal.actualRenderer;
|
|
1921
|
-
},
|
|
1922
|
-
set(value) {
|
|
1923
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1924
|
-
},
|
|
1925
|
-
enumerable: true,
|
|
1926
|
-
configurable: true
|
|
1927
|
-
});
|
|
1928
|
-
Object.defineProperty(state, "renderer", {
|
|
1929
|
-
get() {
|
|
1930
|
-
return rootStore.getState().internal.actualRenderer;
|
|
1931
|
-
},
|
|
1932
|
-
set(value) {
|
|
1933
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1934
|
-
},
|
|
1935
|
-
enumerable: true,
|
|
1936
|
-
configurable: true
|
|
1937
|
-
});
|
|
1938
|
-
let oldScene = state.scene;
|
|
1939
|
-
rootStore.subscribe(() => {
|
|
1940
|
-
const currentState = rootStore.getState();
|
|
1941
|
-
const { scene, rootScene, set } = currentState;
|
|
1942
|
-
if (scene !== oldScene) {
|
|
1943
|
-
oldScene = scene;
|
|
1944
|
-
if (scene?.isScene && scene !== rootScene) {
|
|
1945
|
-
set({ rootScene: scene });
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
});
|
|
1949
|
-
let oldSize = state.size;
|
|
1950
|
-
let oldDpr = state.viewport.dpr;
|
|
1951
|
-
let oldCamera = state.camera;
|
|
1952
|
-
rootStore.subscribe(() => {
|
|
1953
|
-
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1954
|
-
const actualRenderer = internal.actualRenderer;
|
|
1955
|
-
const canvasTarget = internal.canvasTarget;
|
|
1956
|
-
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1957
|
-
oldSize = size;
|
|
1958
|
-
oldDpr = viewport.dpr;
|
|
1959
|
-
updateCamera(camera, size);
|
|
1960
|
-
if (internal.isSecondary && canvasTarget) {
|
|
1961
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1962
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1963
|
-
} else {
|
|
1964
|
-
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1965
|
-
actualRenderer.setSize(size.width, size.height, false);
|
|
1966
|
-
if (canvasTarget) {
|
|
1967
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1968
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
if (camera !== oldCamera) {
|
|
1973
|
-
oldCamera = camera;
|
|
1974
|
-
const { rootScene } = rootStore.getState();
|
|
1975
|
-
if (camera && rootScene && !camera.parent) {
|
|
1976
|
-
rootScene.add(camera);
|
|
1977
|
-
}
|
|
1978
|
-
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1979
|
-
const currentState = rootStore.getState();
|
|
1980
|
-
if (currentState.autoUpdateFrustum && camera) {
|
|
1981
|
-
updateFrustum(camera, currentState.frustum);
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
rootStore.subscribe((state2) => invalidate(state2));
|
|
1986
|
-
return rootStore;
|
|
1987
|
-
};
|
|
1988
|
-
|
|
1989
|
-
const memoizedLoaders = /* @__PURE__ */ new WeakMap();
|
|
1990
|
-
const isConstructor$1 = (value) => typeof value === "function" && value?.prototype?.constructor === value;
|
|
1991
|
-
function getLoader(Proto) {
|
|
1992
|
-
if (isConstructor$1(Proto)) {
|
|
1993
|
-
let loader = memoizedLoaders.get(Proto);
|
|
1994
|
-
if (!loader) {
|
|
1995
|
-
loader = new Proto();
|
|
1996
|
-
memoizedLoaders.set(Proto, loader);
|
|
1997
|
-
}
|
|
1998
|
-
return loader;
|
|
1999
|
-
}
|
|
2000
|
-
return Proto;
|
|
2001
|
-
}
|
|
2002
|
-
function loadingFn(extensions, onProgress) {
|
|
2003
|
-
return function(Proto, input) {
|
|
2004
|
-
const loader = getLoader(Proto);
|
|
2005
|
-
if (extensions) extensions(loader);
|
|
2006
|
-
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
2007
|
-
return loader.loadAsync(input, onProgress).then((data) => {
|
|
2008
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
2009
|
-
return data;
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
return new Promise(
|
|
2013
|
-
(res, reject) => loader.load(
|
|
2014
|
-
input,
|
|
2015
|
-
(data) => {
|
|
2016
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
2017
|
-
res(data);
|
|
2018
|
-
},
|
|
2019
|
-
onProgress,
|
|
2020
|
-
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
2021
|
-
)
|
|
2022
|
-
);
|
|
2023
|
-
};
|
|
2024
|
-
}
|
|
2025
|
-
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
2026
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
2027
|
-
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2028
|
-
const fn = loadingFn(extensions, onProgress);
|
|
2029
|
-
const results = cacheKeys.map(
|
|
2030
|
-
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
2031
|
-
);
|
|
2032
|
-
return Array.isArray(input) ? results : results[0];
|
|
2033
|
-
}
|
|
2034
|
-
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
2035
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
2036
|
-
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2037
|
-
cacheKeys.forEach(
|
|
2038
|
-
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
2039
|
-
);
|
|
2040
|
-
};
|
|
2041
|
-
useLoader.clear = function(loader, input, cacheKey) {
|
|
2042
|
-
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
2043
|
-
cacheKeys.forEach((key) => clear([loader, key]));
|
|
2044
|
-
};
|
|
2045
|
-
useLoader.loader = getLoader;
|
|
2046
|
-
|
|
2047
|
-
function useFrame(callback, priorityOrOptions) {
|
|
2048
|
-
const store = React.useContext(context);
|
|
2049
|
-
const isInsideCanvas = store !== null;
|
|
2050
|
-
const scheduler = getScheduler();
|
|
2051
|
-
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
2052
|
-
id: priorityOrOptions.id,
|
|
2053
|
-
phase: priorityOrOptions.phase,
|
|
2054
|
-
priority: priorityOrOptions.priority,
|
|
2055
|
-
fps: priorityOrOptions.fps,
|
|
2056
|
-
drop: priorityOrOptions.drop,
|
|
2057
|
-
enabled: priorityOrOptions.enabled,
|
|
2058
|
-
before: priorityOrOptions.before,
|
|
2059
|
-
after: priorityOrOptions.after
|
|
2060
|
-
}) : "";
|
|
2061
|
-
const options = React.useMemo(() => {
|
|
2062
|
-
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
2063
|
-
}, [optionsKey]);
|
|
2064
|
-
const reactId = React.useId();
|
|
2065
|
-
const id = options.id ?? reactId;
|
|
2066
|
-
const callbackRef = useMutableCallback(callback);
|
|
2067
|
-
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
2068
|
-
useIsomorphicLayoutEffect(() => {
|
|
2069
|
-
if (!callback) return;
|
|
2070
|
-
if (isInsideCanvas) {
|
|
2071
|
-
const state = store.getState();
|
|
2072
|
-
const rootId = state.internal.rootId;
|
|
2073
|
-
if (isLegacyPriority) {
|
|
2074
|
-
state.internal.priority++;
|
|
2075
|
-
let parentRoot = state.previousRoot;
|
|
2076
|
-
while (parentRoot) {
|
|
2077
|
-
const parentState = parentRoot.getState();
|
|
2078
|
-
if (parentState?.internal) parentState.internal.priority++;
|
|
2079
|
-
parentRoot = parentState?.previousRoot;
|
|
2080
|
-
}
|
|
2081
|
-
notifyDepreciated({
|
|
2082
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
2083
|
-
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 })',
|
|
2084
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
const wrappedCallback = (frameState, delta) => {
|
|
2088
|
-
const localState = store.getState();
|
|
2089
|
-
const mergedState = {
|
|
2090
|
-
...localState,
|
|
2091
|
-
time: frameState.time,
|
|
2092
|
-
delta: frameState.delta,
|
|
2093
|
-
elapsed: frameState.elapsed,
|
|
2094
|
-
frame: frameState.frame
|
|
2095
|
-
};
|
|
2096
|
-
callbackRef.current?.(mergedState, delta);
|
|
2097
|
-
};
|
|
2098
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2099
|
-
id,
|
|
2100
|
-
rootId,
|
|
2101
|
-
...options
|
|
2102
|
-
});
|
|
2103
|
-
return () => {
|
|
2104
|
-
unregister();
|
|
2105
|
-
if (isLegacyPriority) {
|
|
2106
|
-
const currentState = store.getState();
|
|
2107
|
-
if (currentState.internal) {
|
|
2108
|
-
currentState.internal.priority--;
|
|
2109
|
-
let parentRoot = currentState.previousRoot;
|
|
2110
|
-
while (parentRoot) {
|
|
2111
|
-
const parentState = parentRoot.getState();
|
|
2112
|
-
if (parentState?.internal) parentState.internal.priority--;
|
|
2113
|
-
parentRoot = parentState?.previousRoot;
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
};
|
|
2118
|
-
} else {
|
|
2119
|
-
return scheduler.register(
|
|
2120
|
-
(state, delta) => {
|
|
2121
|
-
const frameState = state;
|
|
2122
|
-
if (!frameState.renderer) return;
|
|
2123
|
-
callbackRef.current?.(frameState, delta);
|
|
2124
|
-
},
|
|
2125
|
-
{ id, ...options }
|
|
2126
|
-
);
|
|
2127
|
-
}
|
|
2128
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2129
|
-
const isPaused = React.useSyncExternalStore(
|
|
2130
|
-
// Subscribe function
|
|
2131
|
-
React.useCallback(
|
|
2132
|
-
(onStoreChange) => {
|
|
2133
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2134
|
-
},
|
|
2135
|
-
[id]
|
|
2136
|
-
),
|
|
2137
|
-
// getSnapshot function
|
|
2138
|
-
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2139
|
-
// getServerSnapshot function (SSR)
|
|
2140
|
-
React.useCallback(() => false, [])
|
|
2141
|
-
);
|
|
2142
|
-
const controls = React.useMemo(() => {
|
|
2143
|
-
const scheduler2 = getScheduler();
|
|
2144
|
-
return {
|
|
2145
|
-
/** The job's unique ID */
|
|
2146
|
-
id,
|
|
2147
|
-
/**
|
|
2148
|
-
* Access to the global scheduler for frame loop control.
|
|
2149
|
-
* Use for controlling the entire frame loop, adding phases, etc.
|
|
2150
|
-
*/
|
|
2151
|
-
scheduler: scheduler2,
|
|
2152
|
-
/**
|
|
2153
|
-
* Manually step this job only.
|
|
2154
|
-
* Bypasses FPS limiting - always runs.
|
|
2155
|
-
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2156
|
-
*/
|
|
2157
|
-
step: (timestamp) => {
|
|
2158
|
-
getScheduler().stepJob(id, timestamp);
|
|
2159
|
-
},
|
|
2160
|
-
/**
|
|
2161
|
-
* Manually step ALL jobs in the scheduler.
|
|
2162
|
-
* Useful for frameloop='never' mode.
|
|
2163
|
-
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
2164
|
-
*/
|
|
2165
|
-
stepAll: (timestamp) => {
|
|
2166
|
-
getScheduler().step(timestamp);
|
|
2167
|
-
},
|
|
2168
|
-
/**
|
|
2169
|
-
* Pause this job (set enabled=false).
|
|
2170
|
-
* Job remains registered but won't run.
|
|
2171
|
-
*/
|
|
2172
|
-
pause: () => {
|
|
2173
|
-
getScheduler().pauseJob(id);
|
|
2174
|
-
},
|
|
2175
|
-
/**
|
|
2176
|
-
* Resume this job (set enabled=true).
|
|
2177
|
-
*/
|
|
2178
|
-
resume: () => {
|
|
2179
|
-
getScheduler().resumeJob(id);
|
|
2180
|
-
},
|
|
2181
|
-
/**
|
|
2182
|
-
* Reactive paused state - automatically updates when pause/resume is called.
|
|
2183
|
-
* No need for forceUpdate() in your components.
|
|
2184
|
-
*/
|
|
2185
|
-
isPaused
|
|
2186
|
-
};
|
|
2187
|
-
}, [id, isPaused]);
|
|
2188
|
-
return controls;
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
const IsObject = (url) => url === Object(url) && !Array.isArray(url) && typeof url !== "function";
|
|
2192
|
-
function getUrls(input) {
|
|
2193
|
-
if (typeof input === "string") return [input];
|
|
2194
|
-
if (Array.isArray(input)) return input;
|
|
2195
|
-
return Object.values(input);
|
|
2196
|
-
}
|
|
2197
|
-
function allUrlsCached(urls, textureCache) {
|
|
2198
|
-
return urls.every((url) => textureCache.has(url));
|
|
2199
|
-
}
|
|
2200
|
-
function buildFromCache(input, textureCache) {
|
|
2201
|
-
if (typeof input === "string") {
|
|
2202
|
-
return textureCache.get(input);
|
|
2203
|
-
} else if (Array.isArray(input)) {
|
|
2204
|
-
return input.map((url) => textureCache.get(url));
|
|
2205
|
-
} else {
|
|
2206
|
-
const result = {};
|
|
2207
|
-
const objInput = input;
|
|
2208
|
-
for (const key in objInput) {
|
|
2209
|
-
result[key] = textureCache.get(objInput[key]);
|
|
2210
|
-
}
|
|
2211
|
-
return result;
|
|
1518
|
+
const CUBEMAP_ROOT = "https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/";
|
|
1519
|
+
const isArray = (arr) => Array.isArray(arr);
|
|
1520
|
+
const defaultFiles = ["/px.png", "/nx.png", "/py.png", "/ny.png", "/pz.png", "/nz.png"];
|
|
1521
|
+
function useEnvironment({
|
|
1522
|
+
files = defaultFiles,
|
|
1523
|
+
path = "",
|
|
1524
|
+
preset = void 0,
|
|
1525
|
+
colorSpace = void 0,
|
|
1526
|
+
extensions
|
|
1527
|
+
} = {}) {
|
|
1528
|
+
if (preset) {
|
|
1529
|
+
validatePreset(preset);
|
|
1530
|
+
files = presetsObj[preset];
|
|
1531
|
+
path = CUBEMAP_ROOT;
|
|
2212
1532
|
}
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
const
|
|
2216
|
-
|
|
2217
|
-
const
|
|
2218
|
-
const { onLoad, cache = true } = options;
|
|
2219
|
-
const onLoadRef = useRef(onLoad);
|
|
2220
|
-
onLoadRef.current = onLoad;
|
|
2221
|
-
const onLoadCalledForRef = useRef(null);
|
|
2222
|
-
const urls = useMemo(() => getUrls(input), [input]);
|
|
2223
|
-
const cachedResult = useMemo(() => {
|
|
2224
|
-
if (!cache) return null;
|
|
2225
|
-
const textures = store.getState().textures;
|
|
2226
|
-
if (!allUrlsCached(urls, textures)) return null;
|
|
2227
|
-
return buildFromCache(input, textures);
|
|
2228
|
-
}, [cache, urls, input, store]);
|
|
2229
|
-
const loadedTextures = useLoader(
|
|
2230
|
-
TextureLoader,
|
|
2231
|
-
IsObject(input) ? Object.values(input) : input
|
|
2232
|
-
);
|
|
2233
|
-
const inputKey = urls.join("\0");
|
|
1533
|
+
const multiFile = isArray(files);
|
|
1534
|
+
const { extension, isCubemap } = getExtension(files);
|
|
1535
|
+
const loader = getLoader(extension);
|
|
1536
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1537
|
+
const renderer = useThree((state) => state.renderer);
|
|
2234
1538
|
useLayoutEffect(() => {
|
|
2235
|
-
if (
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
onLoadRef.current?.(loadedTextures);
|
|
2239
|
-
}, [cachedResult, loadedTextures, inputKey]);
|
|
2240
|
-
useEffect(() => {
|
|
2241
|
-
if (cachedResult) return;
|
|
2242
|
-
if ("initTexture" in renderer) {
|
|
2243
|
-
let textureArray = [];
|
|
2244
|
-
if (Array.isArray(loadedTextures)) {
|
|
2245
|
-
textureArray = loadedTextures;
|
|
2246
|
-
} else if (loadedTextures instanceof Texture$1) {
|
|
2247
|
-
textureArray = [loadedTextures];
|
|
2248
|
-
} else if (IsObject(loadedTextures)) {
|
|
2249
|
-
textureArray = Object.values(loadedTextures);
|
|
2250
|
-
}
|
|
2251
|
-
textureArray.forEach((texture) => {
|
|
2252
|
-
if (texture instanceof Texture$1) {
|
|
2253
|
-
renderer.initTexture(texture);
|
|
2254
|
-
}
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
}, [renderer, loadedTextures, cachedResult]);
|
|
2258
|
-
const mappedTextures = useMemo(() => {
|
|
2259
|
-
if (cachedResult) return cachedResult;
|
|
2260
|
-
if (IsObject(input)) {
|
|
2261
|
-
const keyed = {};
|
|
2262
|
-
const textureArray = loadedTextures;
|
|
2263
|
-
let i = 0;
|
|
2264
|
-
for (const key in input) keyed[key] = textureArray[i++];
|
|
2265
|
-
return keyed;
|
|
2266
|
-
} else {
|
|
2267
|
-
return loadedTextures;
|
|
1539
|
+
if (extension !== "webp" && extension !== "jpg" && extension !== "jpeg") return;
|
|
1540
|
+
function clearGainmapTexture() {
|
|
1541
|
+
useLoader.clear(loader, multiFile ? [files] : files);
|
|
2268
1542
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
2278
|
-
} else if (IsObject(input)) {
|
|
2279
|
-
const textureRecord = mappedTextures;
|
|
2280
|
-
for (const key in input) {
|
|
2281
|
-
const url = input[key];
|
|
2282
|
-
urlTextureMap.push([url, textureRecord[key]]);
|
|
1543
|
+
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
1544
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
1545
|
+
const loaderResult = useLoader(
|
|
1546
|
+
loader,
|
|
1547
|
+
multiFile ? [files] : files,
|
|
1548
|
+
(loader2) => {
|
|
1549
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1550
|
+
loader2.setRenderer?.(renderer);
|
|
2283
1551
|
}
|
|
1552
|
+
loader2.setPath?.(path);
|
|
1553
|
+
if (extensions) extensions(loader2);
|
|
2284
1554
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
}
|
|
2297
|
-
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2298
|
-
}
|
|
2299
|
-
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2300
|
-
});
|
|
2301
|
-
return () => store.setState((state) => {
|
|
2302
|
-
const refs = new Map(state._textureRefs);
|
|
2303
|
-
for (const [url] of urlTextureMap) {
|
|
2304
|
-
const next = (refs.get(url) ?? 0) - 1;
|
|
2305
|
-
if (next <= 0) refs.delete(url);
|
|
2306
|
-
else refs.set(url, next);
|
|
2307
|
-
}
|
|
2308
|
-
return { _textureRefs: refs };
|
|
2309
|
-
});
|
|
2310
|
-
}, [cache, input, mappedTextures, store]);
|
|
2311
|
-
return mappedTextures;
|
|
2312
|
-
}
|
|
2313
|
-
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
2314
|
-
useTexture.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
2315
|
-
const Texture = ({
|
|
2316
|
-
children,
|
|
2317
|
-
input,
|
|
2318
|
-
onLoad,
|
|
2319
|
-
cache
|
|
2320
|
-
}) => {
|
|
2321
|
-
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
2322
|
-
const ret = useTexture(input, options);
|
|
2323
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
2324
|
-
};
|
|
2325
|
-
|
|
2326
|
-
function useTextures(selector) {
|
|
2327
|
-
const store = useStore();
|
|
2328
|
-
const registry = useMemo(() => {
|
|
2329
|
-
const getState = store.getState;
|
|
2330
|
-
const setState = store.setState;
|
|
2331
|
-
const getOne = (key) => getState().textures.get(key);
|
|
2332
|
-
return {
|
|
2333
|
-
get all() {
|
|
2334
|
-
return getState().textures;
|
|
2335
|
-
},
|
|
2336
|
-
get(input) {
|
|
2337
|
-
if (typeof input === "string") return getOne(input);
|
|
2338
|
-
if (Array.isArray(input)) return input.map(getOne);
|
|
2339
|
-
const out = {};
|
|
2340
|
-
for (const name in input) out[name] = getOne(input[name]);
|
|
2341
|
-
return out;
|
|
2342
|
-
},
|
|
2343
|
-
has: (key) => getState().textures.has(key),
|
|
2344
|
-
add(keyOrRecord, texture) {
|
|
2345
|
-
setState((state) => {
|
|
2346
|
-
const textures = new Map(state.textures);
|
|
2347
|
-
if (typeof keyOrRecord === "string") {
|
|
2348
|
-
textures.set(keyOrRecord, texture);
|
|
2349
|
-
} else {
|
|
2350
|
-
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2351
|
-
}
|
|
2352
|
-
return { textures };
|
|
2353
|
-
});
|
|
2354
|
-
},
|
|
2355
|
-
dispose(key, options) {
|
|
2356
|
-
const state = getState();
|
|
2357
|
-
const refs = state._textureRefs.get(key) ?? 0;
|
|
2358
|
-
if (refs > 0 && !options?.force) {
|
|
2359
|
-
console.warn(
|
|
2360
|
-
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2361
|
-
);
|
|
2362
|
-
return false;
|
|
2363
|
-
}
|
|
2364
|
-
state.textures.get(key)?.dispose();
|
|
2365
|
-
setState((s) => {
|
|
2366
|
-
const textures = new Map(s.textures);
|
|
2367
|
-
textures.delete(key);
|
|
2368
|
-
const nextRefs = new Map(s._textureRefs);
|
|
2369
|
-
nextRefs.delete(key);
|
|
2370
|
-
return { textures, _textureRefs: nextRefs };
|
|
2371
|
-
});
|
|
2372
|
-
return true;
|
|
2373
|
-
},
|
|
2374
|
-
disposeAll() {
|
|
2375
|
-
for (const texture of getState().textures.values()) texture.dispose();
|
|
2376
|
-
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
}, [store]);
|
|
2380
|
-
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2381
|
-
const selected = useThree(subscribe);
|
|
2382
|
-
return selector ? selected : registry;
|
|
1555
|
+
);
|
|
1556
|
+
let texture = multiFile ? (
|
|
1557
|
+
// @ts-ignore
|
|
1558
|
+
loaderResult[0]
|
|
1559
|
+
) : loaderResult;
|
|
1560
|
+
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
1561
|
+
texture = texture.renderTarget?.texture;
|
|
1562
|
+
}
|
|
1563
|
+
texture.mapping = isCubemap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
1564
|
+
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
1565
|
+
return texture;
|
|
2383
1566
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
} else if (typeof heightOrOptions === "number") {
|
|
2399
|
-
height = heightOrOptions;
|
|
2400
|
-
opts = options;
|
|
2401
|
-
} else {
|
|
2402
|
-
height = widthOrOptions;
|
|
2403
|
-
}
|
|
1567
|
+
const preloadDefaultOptions = {
|
|
1568
|
+
files: defaultFiles,
|
|
1569
|
+
path: "",
|
|
1570
|
+
preset: void 0,
|
|
1571
|
+
extensions: void 0
|
|
1572
|
+
};
|
|
1573
|
+
useEnvironment.preload = (preloadOptions) => {
|
|
1574
|
+
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
1575
|
+
let { files, path = "" } = options;
|
|
1576
|
+
const { preset, extensions } = options;
|
|
1577
|
+
if (preset) {
|
|
1578
|
+
validatePreset(preset);
|
|
1579
|
+
files = presetsObj[preset];
|
|
1580
|
+
path = CUBEMAP_ROOT;
|
|
2404
1581
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
1582
|
+
const { extension } = getExtension(files);
|
|
1583
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1584
|
+
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
1585
|
+
}
|
|
1586
|
+
const loader = getLoader(extension);
|
|
1587
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1588
|
+
useLoader.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
1589
|
+
loader2.setPath?.(path);
|
|
1590
|
+
if (extensions) extensions(loader2);
|
|
1591
|
+
});
|
|
1592
|
+
};
|
|
1593
|
+
const clearDefaultOptins = {
|
|
1594
|
+
files: defaultFiles,
|
|
1595
|
+
preset: void 0
|
|
1596
|
+
};
|
|
1597
|
+
useEnvironment.clear = (clearOptions) => {
|
|
1598
|
+
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
1599
|
+
let { files } = options;
|
|
1600
|
+
const { preset } = options;
|
|
1601
|
+
if (preset) {
|
|
1602
|
+
validatePreset(preset);
|
|
1603
|
+
files = presetsObj[preset];
|
|
1604
|
+
}
|
|
1605
|
+
const { extension } = getExtension(files);
|
|
1606
|
+
const loader = getLoader(extension);
|
|
1607
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1608
|
+
useLoader.clear(loader, isArray(files) ? [files] : files);
|
|
1609
|
+
};
|
|
1610
|
+
function validatePreset(preset) {
|
|
1611
|
+
if (!(preset in presetsObj)) throw new Error("Preset must be one of: " + Object.keys(presetsObj).join(", "));
|
|
1612
|
+
}
|
|
1613
|
+
function getExtension(files) {
|
|
1614
|
+
const isCubemap = isArray(files) && files.length === 6;
|
|
1615
|
+
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
1616
|
+
const firstEntry = isArray(files) ? files[0] : files;
|
|
1617
|
+
const extension = isCubemap ? "cube" : isGainmap ? "webp" : firstEntry.startsWith("data:application/exr") ? "exr" : firstEntry.startsWith("data:application/hdr") ? "hdr" : firstEntry.startsWith("data:image/jpeg") ? "jpg" : firstEntry.split(".").pop()?.split("?")?.shift()?.toLowerCase();
|
|
1618
|
+
return { extension, isCubemap, isGainmap };
|
|
1619
|
+
}
|
|
1620
|
+
function getLoader(extension) {
|
|
1621
|
+
const loader = extension === "cube" ? CubeTextureLoader : extension === "hdr" ? HDRLoader : extension === "exr" ? EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader : extension === "webp" ? GainMapLoader : null;
|
|
1622
|
+
return loader;
|
|
2410
1623
|
}
|
|
2411
1624
|
|
|
2412
1625
|
function useStore() {
|
|
@@ -2426,6 +1639,8 @@ function useGraph(object) {
|
|
|
2426
1639
|
return useMemo(() => buildGraph(object), [object]);
|
|
2427
1640
|
}
|
|
2428
1641
|
|
|
1642
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
1643
|
+
|
|
2429
1644
|
let effectId = 0;
|
|
2430
1645
|
function addEffect(callback) {
|
|
2431
1646
|
notifyDepreciated({
|
|
@@ -13333,390 +12548,968 @@ Check the top-level render call using <` + i + ">.");
|
|
|
13333
12548
|
var i = x.H;
|
|
13334
12549
|
x.H = $o;
|
|
13335
12550
|
try {
|
|
13336
|
-
return Br(e, n, o);
|
|
13337
|
-
} finally {
|
|
13338
|
-
x.H = i;
|
|
12551
|
+
return Br(e, n, o);
|
|
12552
|
+
} finally {
|
|
12553
|
+
x.H = i;
|
|
12554
|
+
}
|
|
12555
|
+
}, useRef: function() {
|
|
12556
|
+
return z = "useRef", D(), N(), xe().memoizedState;
|
|
12557
|
+
}, useState: function() {
|
|
12558
|
+
z = "useState", D(), N();
|
|
12559
|
+
var e = x.H;
|
|
12560
|
+
x.H = $o;
|
|
12561
|
+
try {
|
|
12562
|
+
return Br(gr);
|
|
12563
|
+
} finally {
|
|
12564
|
+
x.H = e;
|
|
12565
|
+
}
|
|
12566
|
+
}, useDebugValue: function() {
|
|
12567
|
+
z = "useDebugValue", D(), N();
|
|
12568
|
+
}, useDeferredValue: function(e, n) {
|
|
12569
|
+
return z = "useDeferredValue", D(), N(), nc(e, n);
|
|
12570
|
+
}, useTransition: function() {
|
|
12571
|
+
return z = "useTransition", D(), N(), Qp();
|
|
12572
|
+
}, useSyncExternalStore: function(e, n, o) {
|
|
12573
|
+
return z = "useSyncExternalStore", D(), N(), ta(e, n, o);
|
|
12574
|
+
}, useId: function() {
|
|
12575
|
+
return z = "useId", D(), N(), xe().memoizedState;
|
|
12576
|
+
}, useFormState: function(e) {
|
|
12577
|
+
return z = "useFormState", D(), N(), hs(e);
|
|
12578
|
+
}, useActionState: function(e) {
|
|
12579
|
+
return z = "useActionState", D(), N(), hs(e);
|
|
12580
|
+
}, useOptimistic: function(e, n) {
|
|
12581
|
+
return z = "useOptimistic", D(), N(), rf(e, n);
|
|
12582
|
+
}, useMemoCache: function(e) {
|
|
12583
|
+
return D(), Oa(e);
|
|
12584
|
+
}, useHostTransitionStatus: ia, useCacheRefresh: function() {
|
|
12585
|
+
return z = "useCacheRefresh", N(), xe().memoizedState;
|
|
12586
|
+
}, useEffectEvent: function(e) {
|
|
12587
|
+
return z = "useEffectEvent", D(), N(), oa(e);
|
|
12588
|
+
} }, dm = { readContext: function(e) {
|
|
12589
|
+
return Ce(), Ee(e);
|
|
12590
|
+
}, use: function(e) {
|
|
12591
|
+
return D(), we(e);
|
|
12592
|
+
}, useCallback: function(e, n) {
|
|
12593
|
+
return z = "useCallback", D(), N(), Ma(e, n);
|
|
12594
|
+
}, useContext: function(e) {
|
|
12595
|
+
return z = "useContext", D(), N(), Ee(e);
|
|
12596
|
+
}, useEffect: function(e, n) {
|
|
12597
|
+
z = "useEffect", D(), N(), Qn(2048, Ut, e, n);
|
|
12598
|
+
}, useImperativeHandle: function(e, n, o) {
|
|
12599
|
+
return z = "useImperativeHandle", D(), N(), aa(e, n, o);
|
|
12600
|
+
}, useInsertionEffect: function(e, n) {
|
|
12601
|
+
return z = "useInsertionEffect", D(), N(), Qn(4, Wt, e, n);
|
|
12602
|
+
}, useLayoutEffect: function(e, n) {
|
|
12603
|
+
return z = "useLayoutEffect", D(), N(), Qn(4, Rr, e, n);
|
|
12604
|
+
}, useMemo: function(e, n) {
|
|
12605
|
+
z = "useMemo", D(), N();
|
|
12606
|
+
var o = x.H;
|
|
12607
|
+
x.H = $o;
|
|
12608
|
+
try {
|
|
12609
|
+
return Vi(e, n);
|
|
12610
|
+
} finally {
|
|
12611
|
+
x.H = o;
|
|
12612
|
+
}
|
|
12613
|
+
}, useReducer: function(e, n, o) {
|
|
12614
|
+
z = "useReducer", D(), N();
|
|
12615
|
+
var i = x.H;
|
|
12616
|
+
x.H = $o;
|
|
12617
|
+
try {
|
|
12618
|
+
return Qi(e, n, o);
|
|
12619
|
+
} finally {
|
|
12620
|
+
x.H = i;
|
|
12621
|
+
}
|
|
12622
|
+
}, useRef: function() {
|
|
12623
|
+
return z = "useRef", D(), N(), xe().memoizedState;
|
|
12624
|
+
}, useState: function() {
|
|
12625
|
+
z = "useState", D(), N();
|
|
12626
|
+
var e = x.H;
|
|
12627
|
+
x.H = $o;
|
|
12628
|
+
try {
|
|
12629
|
+
return Qi(gr);
|
|
12630
|
+
} finally {
|
|
12631
|
+
x.H = e;
|
|
12632
|
+
}
|
|
12633
|
+
}, useDebugValue: function() {
|
|
12634
|
+
z = "useDebugValue", D(), N();
|
|
12635
|
+
}, useDeferredValue: function(e, n) {
|
|
12636
|
+
return z = "useDeferredValue", D(), N(), sf(e, n);
|
|
12637
|
+
}, useTransition: function() {
|
|
12638
|
+
return z = "useTransition", D(), N(), Ro();
|
|
12639
|
+
}, useSyncExternalStore: function(e, n, o) {
|
|
12640
|
+
return z = "useSyncExternalStore", D(), N(), ta(e, n, o);
|
|
12641
|
+
}, useId: function() {
|
|
12642
|
+
return z = "useId", D(), N(), xe().memoizedState;
|
|
12643
|
+
}, useFormState: function(e) {
|
|
12644
|
+
return z = "useFormState", D(), N(), $t(e);
|
|
12645
|
+
}, useActionState: function(e) {
|
|
12646
|
+
return z = "useActionState", D(), N(), $t(e);
|
|
12647
|
+
}, useOptimistic: function(e, n) {
|
|
12648
|
+
return z = "useOptimistic", D(), N(), of(e, n);
|
|
12649
|
+
}, useMemoCache: function(e) {
|
|
12650
|
+
return D(), Oa(e);
|
|
12651
|
+
}, useHostTransitionStatus: ia, useCacheRefresh: function() {
|
|
12652
|
+
return z = "useCacheRefresh", N(), xe().memoizedState;
|
|
12653
|
+
}, useEffectEvent: function(e) {
|
|
12654
|
+
return z = "useEffectEvent", D(), N(), oa(e);
|
|
12655
|
+
} };
|
|
12656
|
+
var Fy = {}, Hy = /* @__PURE__ */ new Set(), Ay = /* @__PURE__ */ new Set(), jy = /* @__PURE__ */ new Set(), Dy = /* @__PURE__ */ new Set(), Wy = /* @__PURE__ */ new Set(), Uy = /* @__PURE__ */ new Set(), By = /* @__PURE__ */ new Set(), Oy = /* @__PURE__ */ new Set(), My = /* @__PURE__ */ new Set(), Qy = /* @__PURE__ */ new Set();
|
|
12657
|
+
Object.freeze(Fy);
|
|
12658
|
+
var zg = { enqueueSetState: function(e, n, o) {
|
|
12659
|
+
e = e._reactInternals;
|
|
12660
|
+
var i = Nt(e), s = zo(i);
|
|
12661
|
+
s.payload = n, o != null && (df(o), s.callback = o), n = Mt(e, s, i), n !== null && (ur(i, "this.setState()", e), We(n, e, i), Bi(n, e, i));
|
|
12662
|
+
}, enqueueReplaceState: function(e, n, o) {
|
|
12663
|
+
e = e._reactInternals;
|
|
12664
|
+
var i = Nt(e), s = zo(i);
|
|
12665
|
+
s.tag = Cy, s.payload = n, o != null && (df(o), s.callback = o), n = Mt(e, s, i), n !== null && (ur(i, "this.replaceState()", e), We(n, e, i), Bi(n, e, i));
|
|
12666
|
+
}, enqueueForceUpdate: function(e, n) {
|
|
12667
|
+
e = e._reactInternals;
|
|
12668
|
+
var o = Nt(e), i = zo(o);
|
|
12669
|
+
i.tag = Ty, n != null && (df(n), i.callback = n), n = Mt(e, i, o), n !== null && (ur(o, "this.forceUpdate()", e), We(n, e, o), Bi(n, e, o));
|
|
12670
|
+
} }, bd = null, Cg = null, Tg = Error("This is not a real error. It's an implementation detail of React's selective hydration feature. If this leaks into userspace, it's a bug in React. Please file an issue."), Cn = false, $y = {}, Vy = {}, qy = {}, Gy = {}, vd = false, Jy = {}, fm = {}, _g = { dehydrated: null, treeContext: null, retryLane: 0, hydrationErrors: null }, Zy = false, Yy = null;
|
|
12671
|
+
Yy = /* @__PURE__ */ new Set();
|
|
12672
|
+
var Si = false, Tn = false, Rg = false, Xy = typeof WeakSet == "function" ? WeakSet : Set, Gn = null, Sd = null, kd = null, _n = null, nr = false, Vo = null, Wn = false, wd = 8192, Vb = { getCacheForType: function(e) {
|
|
12673
|
+
var n = Ee(un), o = n.data.get(e);
|
|
12674
|
+
return o === void 0 && (o = e(), n.data.set(e, o)), o;
|
|
12675
|
+
}, cacheSignal: function() {
|
|
12676
|
+
return Ee(un).controller.signal;
|
|
12677
|
+
}, getOwner: function() {
|
|
12678
|
+
return di;
|
|
12679
|
+
} }, pm = 0, hm = 1, mm = 2, gm = 3, ym = 4;
|
|
12680
|
+
if (typeof Symbol == "function" && Symbol.for) {
|
|
12681
|
+
var bp = Symbol.for;
|
|
12682
|
+
pm = bp("selector.component"), hm = bp("selector.has_pseudo_class"), mm = bp("selector.role"), gm = bp("selector.test_id"), ym = bp("selector.text");
|
|
12683
|
+
}
|
|
12684
|
+
var bm = [], qb = typeof WeakMap == "function" ? WeakMap : Map, Jn = 0, Zn = 2, uo = 4, ki = 0, vp = 1, iu = 2, vm = 3, Tl = 4, Sm = 6, Ky = 5, ye = Jn, je = null, se = null, ae = 0, tr = 0, km = 1, lu = 2, Sp = 3, eb = 4, Eg = 5, kp = 6, wm = 7, Ig = 8, su = 9, Le = tr, Er = null, _l = false, Pd = false, Lg = false, Ta = 0, nn = ki, Rl = 0, El = 0, Ng = 0, rr = 0, uu = 0, wp = null, Bt = null, Pm = false, xm = 0, nb = 0, tb = 300, Pp = 1 / 0, Fg = 500, xp = null, gn = null, Il = null, zm = 0, Hg = 1, Ag = 2, rb = 3, Ll = 0, ob = 1, ab = 2, ib = 3, lb = 4, Cm = 5, Rn = 0, Nl = null, xd = null, qo = 0, jg = 0, Dg = -0, Wg = null, sb = null, ub = null, Go = zm, cb = null, Gb = 50, zp = 0, Ug = null, Bg = false, Tm = false, Jb = 50, cu = 0, Cp = null, zd = false, _m = null, db = false, fb = /* @__PURE__ */ new Set(), Zb = {}, co = null, Cd = null, pb = false;
|
|
12685
|
+
try {
|
|
12686
|
+
var o0 = Object.preventExtensions({});
|
|
12687
|
+
} catch {
|
|
12688
|
+
pb = true;
|
|
12689
|
+
}
|
|
12690
|
+
var hb = false, mb = {}, gb = null, yb = null, bb = null, vb = null, Sb = null, kb = null, wb = null, Pb = null, xb = null, zb = null;
|
|
12691
|
+
return gb = function(e, n, o, i) {
|
|
12692
|
+
n = Yn(e, n), n !== null && (o = _d(n.memoizedState, o, 0, i), n.memoizedState = o, n.baseState = o, e.memoizedProps = ze({}, e.memoizedProps), o = On(e, 2), o !== null && We(o, e, 2));
|
|
12693
|
+
}, yb = function(e, n, o) {
|
|
12694
|
+
n = Yn(e, n), n !== null && (o = du(n.memoizedState, o, 0), n.memoizedState = o, n.baseState = o, e.memoizedProps = ze({}, e.memoizedProps), o = On(e, 2), o !== null && We(o, e, 2));
|
|
12695
|
+
}, bb = function(e, n, o, i) {
|
|
12696
|
+
n = Yn(e, n), n !== null && (o = F(n.memoizedState, o, i), n.memoizedState = o, n.baseState = o, e.memoizedProps = ze({}, e.memoizedProps), o = On(e, 2), o !== null && We(o, e, 2));
|
|
12697
|
+
}, vb = function(e, n, o) {
|
|
12698
|
+
e.pendingProps = _d(e.memoizedProps, n, 0, o), e.alternate && (e.alternate.pendingProps = e.pendingProps), n = On(e, 2), n !== null && We(n, e, 2);
|
|
12699
|
+
}, Sb = function(e, n) {
|
|
12700
|
+
e.pendingProps = du(e.memoizedProps, n, 0), e.alternate && (e.alternate.pendingProps = e.pendingProps), n = On(e, 2), n !== null && We(n, e, 2);
|
|
12701
|
+
}, kb = function(e, n, o) {
|
|
12702
|
+
e.pendingProps = F(e.memoizedProps, n, o), e.alternate && (e.alternate.pendingProps = e.pendingProps), n = On(e, 2), n !== null && We(n, e, 2);
|
|
12703
|
+
}, wb = function(e) {
|
|
12704
|
+
var n = On(e, 2);
|
|
12705
|
+
n !== null && We(n, e, 2);
|
|
12706
|
+
}, Pb = function(e) {
|
|
12707
|
+
var n = ut(), o = On(e, n);
|
|
12708
|
+
o !== null && We(o, e, n);
|
|
12709
|
+
}, xb = function(e) {
|
|
12710
|
+
pu = e;
|
|
12711
|
+
}, zb = function(e) {
|
|
12712
|
+
fu = e;
|
|
12713
|
+
}, le.attemptContinuousHydration = function(e) {
|
|
12714
|
+
if (e.tag === 13 || e.tag === 31) {
|
|
12715
|
+
var n = On(e, 67108864);
|
|
12716
|
+
n !== null && We(n, e, 67108864), rl(e, 67108864);
|
|
12717
|
+
}
|
|
12718
|
+
}, le.attemptHydrationAtCurrentPriority = function(e) {
|
|
12719
|
+
if (e.tag === 13 || e.tag === 31) {
|
|
12720
|
+
var n = Nt(e);
|
|
12721
|
+
n = Xo(n);
|
|
12722
|
+
var o = On(e, n);
|
|
12723
|
+
o !== null && We(o, e, n), rl(e, n);
|
|
12724
|
+
}
|
|
12725
|
+
}, le.attemptSynchronousHydration = function(e) {
|
|
12726
|
+
switch (e.tag) {
|
|
12727
|
+
case 3:
|
|
12728
|
+
if (e = e.stateNode, e.current.memoizedState.isDehydrated) {
|
|
12729
|
+
var n = _t(e.pendingLanes);
|
|
12730
|
+
if (n !== 0) {
|
|
12731
|
+
for (e.pendingLanes |= 2, e.entangledLanes |= 2; n; ) {
|
|
12732
|
+
var o = 1 << 31 - vn(n);
|
|
12733
|
+
e.entanglements[1] |= o, n &= ~o;
|
|
12734
|
+
}
|
|
12735
|
+
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12736
|
+
}
|
|
12737
|
+
}
|
|
12738
|
+
break;
|
|
12739
|
+
case 31:
|
|
12740
|
+
case 13:
|
|
12741
|
+
n = On(e, 2), n !== null && We(n, e, 2), Ls(), rl(e, 2);
|
|
12742
|
+
}
|
|
12743
|
+
}, le.batchedUpdates = function(e, n) {
|
|
12744
|
+
return e(n);
|
|
12745
|
+
}, le.createComponentSelector = function(e) {
|
|
12746
|
+
return { $$typeof: pm, value: e };
|
|
12747
|
+
}, le.createContainer = function(e, n, o, i, s, u, f, p, g, S) {
|
|
12748
|
+
return Ka(e, n, false, null, o, i, u, null, f, p, g, S);
|
|
12749
|
+
}, le.createHasPseudoClassSelector = function(e) {
|
|
12750
|
+
return { $$typeof: hm, value: e };
|
|
12751
|
+
}, le.createHydrationContainer = function(e, n, o, i, s, u, f, p, g, S, T, _, I, O) {
|
|
12752
|
+
return e = Ka(o, i, true, e, s, u, p, O, g, S, T, _), e.context = Dh(null), o = e.current, i = Nt(o), i = Xo(i), s = zo(i), s.callback = n ?? null, Mt(o, s, i), ur(i, "hydrateRoot()", null), n = i, e.current.lanes = n, Ci(e, n), Kn(e), e;
|
|
12753
|
+
}, le.createPortal = function(e, n, o) {
|
|
12754
|
+
var i = 3 < arguments.length && arguments[3] !== void 0 ? arguments[3] : null;
|
|
12755
|
+
try {
|
|
12756
|
+
vt(i);
|
|
12757
|
+
var s = false;
|
|
12758
|
+
} catch {
|
|
12759
|
+
s = true;
|
|
13339
12760
|
}
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
12761
|
+
return s && (console.error("The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", typeof Symbol == "function" && Symbol.toStringTag && i[Symbol.toStringTag] || i.constructor.name || "Object"), vt(i)), { $$typeof: Ao, key: i == null ? null : "" + i, children: e, containerInfo: n, implementation: o };
|
|
12762
|
+
}, le.createRoleSelector = function(e) {
|
|
12763
|
+
return { $$typeof: mm, value: e };
|
|
12764
|
+
}, le.createTestNameSelector = function(e) {
|
|
12765
|
+
return { $$typeof: gm, value: e };
|
|
12766
|
+
}, le.createTextSelector = function(e) {
|
|
12767
|
+
return { $$typeof: ym, value: e };
|
|
12768
|
+
}, le.defaultOnCaughtError = function(e) {
|
|
12769
|
+
var n = bd ? "The above error occurred in the <" + bd + "> component." : "The above error occurred in one of your React components.", o = "React will try to recreate this component tree from scratch using the error boundary you provided, " + ((Cg || "Anonymous") + ".");
|
|
12770
|
+
typeof e == "object" && e !== null && typeof e.environmentName == "string" ? ri("error", [`%o
|
|
12771
|
+
|
|
12772
|
+
%s
|
|
12773
|
+
|
|
12774
|
+
%s
|
|
12775
|
+
`, e, n, o], e.environmentName)() : console.error(`%o
|
|
12776
|
+
|
|
12777
|
+
%s
|
|
12778
|
+
|
|
12779
|
+
%s
|
|
12780
|
+
`, e, n, o);
|
|
12781
|
+
}, le.defaultOnRecoverableError = function(e) {
|
|
12782
|
+
qg(e);
|
|
12783
|
+
}, le.defaultOnUncaughtError = function(e) {
|
|
12784
|
+
qg(e), console.warn(`%s
|
|
12785
|
+
|
|
12786
|
+
%s
|
|
12787
|
+
`, bd ? "An error occurred in the <" + bd + "> component." : "An error occurred in one of your React components.", `Consider adding an error boundary to your tree to customize error handling behavior.
|
|
12788
|
+
Visit https://react.dev/link/error-boundaries to learn more about error boundaries.`);
|
|
12789
|
+
}, le.deferredUpdates = function(e) {
|
|
12790
|
+
var n = x.T, o = wt();
|
|
13346
12791
|
try {
|
|
13347
|
-
return
|
|
12792
|
+
return an(32), x.T = null, e();
|
|
13348
12793
|
} finally {
|
|
13349
|
-
x.
|
|
12794
|
+
an(o), x.T = n;
|
|
13350
12795
|
}
|
|
13351
|
-
},
|
|
13352
|
-
|
|
13353
|
-
}, useDeferredValue: function(e, n) {
|
|
13354
|
-
return z = "useDeferredValue", D(), N(), nc(e, n);
|
|
13355
|
-
}, useTransition: function() {
|
|
13356
|
-
return z = "useTransition", D(), N(), Qp();
|
|
13357
|
-
}, useSyncExternalStore: function(e, n, o) {
|
|
13358
|
-
return z = "useSyncExternalStore", D(), N(), ta(e, n, o);
|
|
13359
|
-
}, useId: function() {
|
|
13360
|
-
return z = "useId", D(), N(), xe().memoizedState;
|
|
13361
|
-
}, useFormState: function(e) {
|
|
13362
|
-
return z = "useFormState", D(), N(), hs(e);
|
|
13363
|
-
}, useActionState: function(e) {
|
|
13364
|
-
return z = "useActionState", D(), N(), hs(e);
|
|
13365
|
-
}, useOptimistic: function(e, n) {
|
|
13366
|
-
return z = "useOptimistic", D(), N(), rf(e, n);
|
|
13367
|
-
}, useMemoCache: function(e) {
|
|
13368
|
-
return D(), Oa(e);
|
|
13369
|
-
}, useHostTransitionStatus: ia, useCacheRefresh: function() {
|
|
13370
|
-
return z = "useCacheRefresh", N(), xe().memoizedState;
|
|
13371
|
-
}, useEffectEvent: function(e) {
|
|
13372
|
-
return z = "useEffectEvent", D(), N(), oa(e);
|
|
13373
|
-
} }, dm = { readContext: function(e) {
|
|
13374
|
-
return Ce(), Ee(e);
|
|
13375
|
-
}, use: function(e) {
|
|
13376
|
-
return D(), we(e);
|
|
13377
|
-
}, useCallback: function(e, n) {
|
|
13378
|
-
return z = "useCallback", D(), N(), Ma(e, n);
|
|
13379
|
-
}, useContext: function(e) {
|
|
13380
|
-
return z = "useContext", D(), N(), Ee(e);
|
|
13381
|
-
}, useEffect: function(e, n) {
|
|
13382
|
-
z = "useEffect", D(), N(), Qn(2048, Ut, e, n);
|
|
13383
|
-
}, useImperativeHandle: function(e, n, o) {
|
|
13384
|
-
return z = "useImperativeHandle", D(), N(), aa(e, n, o);
|
|
13385
|
-
}, useInsertionEffect: function(e, n) {
|
|
13386
|
-
return z = "useInsertionEffect", D(), N(), Qn(4, Wt, e, n);
|
|
13387
|
-
}, useLayoutEffect: function(e, n) {
|
|
13388
|
-
return z = "useLayoutEffect", D(), N(), Qn(4, Rr, e, n);
|
|
13389
|
-
}, useMemo: function(e, n) {
|
|
13390
|
-
z = "useMemo", D(), N();
|
|
13391
|
-
var o = x.H;
|
|
13392
|
-
x.H = $o;
|
|
12796
|
+
}, le.discreteUpdates = function(e, n, o, i, s) {
|
|
12797
|
+
var u = x.T, f = wt();
|
|
13393
12798
|
try {
|
|
13394
|
-
return
|
|
12799
|
+
return an(2), x.T = null, e(n, o, i, s);
|
|
13395
12800
|
} finally {
|
|
13396
|
-
x.
|
|
12801
|
+
an(f), x.T = u, ye === Jn && (Pp = me() + Fg);
|
|
13397
12802
|
}
|
|
13398
|
-
},
|
|
13399
|
-
|
|
13400
|
-
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13404
|
-
|
|
13405
|
-
|
|
12803
|
+
}, le.findAllNodes = kc, le.findBoundingRects = function(e, n) {
|
|
12804
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12805
|
+
n = kc(e, n), e = [];
|
|
12806
|
+
for (var o = 0; o < n.length; o++) e.push(ma(n[o]));
|
|
12807
|
+
for (n = e.length - 1; 0 < n; n--) {
|
|
12808
|
+
o = e[n];
|
|
12809
|
+
for (var i = o.x, s = i + o.width, u = o.y, f = u + o.height, p = n - 1; 0 <= p; p--) if (n !== p) {
|
|
12810
|
+
var g = e[p], S = g.x, T = S + g.width, _ = g.y, I = _ + g.height;
|
|
12811
|
+
if (i >= S && u >= _ && s <= T && f <= I) {
|
|
12812
|
+
e.splice(n, 1);
|
|
12813
|
+
break;
|
|
12814
|
+
} else if (i !== S || o.width !== g.width || I < u || _ > f) {
|
|
12815
|
+
if (!(u !== _ || o.height !== g.height || T < i || S > s)) {
|
|
12816
|
+
S > i && (g.width += S - i, g.x = i), T < s && (g.width = s - S), e.splice(n, 1);
|
|
12817
|
+
break;
|
|
12818
|
+
}
|
|
12819
|
+
} else {
|
|
12820
|
+
_ > u && (g.height += _ - u, g.y = u), I < f && (g.height = f - _), e.splice(n, 1);
|
|
12821
|
+
break;
|
|
12822
|
+
}
|
|
12823
|
+
}
|
|
13406
12824
|
}
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
12825
|
+
return e;
|
|
12826
|
+
}, le.findHostInstance = function(e) {
|
|
12827
|
+
var n = e._reactInternals;
|
|
12828
|
+
if (n === void 0) throw typeof e.render == "function" ? Error("Unable to find node on an unmounted component.") : (e = Object.keys(e).join(","), Error("Argument appears to not be a ReactComponent. Keys: " + e));
|
|
12829
|
+
return e = mu(n), e === null ? null : ot(e.stateNode);
|
|
12830
|
+
}, le.findHostInstanceWithNoPortals = function(e) {
|
|
12831
|
+
return e = Ed(e), e = e !== null ? _p(e) : null, e === null ? null : ot(e.stateNode);
|
|
12832
|
+
}, le.findHostInstanceWithWarning = function(e, n) {
|
|
12833
|
+
var o = e._reactInternals;
|
|
12834
|
+
if (o === void 0) throw typeof e.render == "function" ? Error("Unable to find node on an unmounted component.") : (e = Object.keys(e).join(","), Error("Argument appears to not be a ReactComponent. Keys: " + e));
|
|
12835
|
+
if (e = mu(o), e === null) return null;
|
|
12836
|
+
if (e.mode & 8) {
|
|
12837
|
+
var i = G(o) || "Component";
|
|
12838
|
+
mb[i] || (mb[i] = true, B(e, function() {
|
|
12839
|
+
o.mode & 8 ? console.error("%s is deprecated in StrictMode. %s was passed an instance of %s which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node", n, n, i) : console.error("%s is deprecated in StrictMode. %s was passed an instance of %s which renders StrictMode children. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node", n, n, i);
|
|
12840
|
+
}));
|
|
12841
|
+
}
|
|
12842
|
+
return ot(e.stateNode);
|
|
12843
|
+
}, le.flushPassiveEffects = el, le.flushSyncFromReconciler = function(e) {
|
|
12844
|
+
var n = ye;
|
|
12845
|
+
ye |= 1;
|
|
12846
|
+
var o = x.T, i = wt();
|
|
13413
12847
|
try {
|
|
13414
|
-
return
|
|
12848
|
+
if (an(2), x.T = null, e) return e();
|
|
13415
12849
|
} finally {
|
|
13416
|
-
x.
|
|
12850
|
+
an(i), x.T = o, ye = n, (ye & (Zn | uo)) === Jn && Wa(0);
|
|
12851
|
+
}
|
|
12852
|
+
}, le.flushSyncWork = Ls, le.focusWithin = function(e, n) {
|
|
12853
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12854
|
+
for (e = Ef(e), n = hh(e, n), n = Array.from(n), e = 0; e < n.length; ) {
|
|
12855
|
+
var o = n[e++], i = o.tag;
|
|
12856
|
+
if (!Kr(o)) {
|
|
12857
|
+
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
12858
|
+
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
12859
|
+
}
|
|
12860
|
+
}
|
|
12861
|
+
return false;
|
|
12862
|
+
}, le.getFindAllNodesFailureDescription = function(e, n) {
|
|
12863
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12864
|
+
var o = 0, i = [];
|
|
12865
|
+
e = [Ef(e), 0];
|
|
12866
|
+
for (var s = 0; s < e.length; ) {
|
|
12867
|
+
var u = e[s++], f = u.tag, p = e[s++], g = n[p];
|
|
12868
|
+
if ((f !== 5 && f !== 26 && f !== 27 || !Kr(u)) && (If(u, g) && (i.push(Sc(g)), p++, p > o && (o = p)), p < n.length)) for (u = u.child; u !== null; ) e.push(u, p), u = u.sibling;
|
|
12869
|
+
}
|
|
12870
|
+
if (o < n.length) {
|
|
12871
|
+
for (e = []; o < n.length; o++) e.push(Sc(n[o]));
|
|
12872
|
+
return `findAllNodes was able to match part of the selector:
|
|
12873
|
+
` + (i.join(" > ") + `
|
|
12874
|
+
|
|
12875
|
+
No matching component was found for:
|
|
12876
|
+
`) + e.join(" > ");
|
|
12877
|
+
}
|
|
12878
|
+
return null;
|
|
12879
|
+
}, le.getPublicRootInstance = function(e) {
|
|
12880
|
+
if (e = e.current, !e.child) return null;
|
|
12881
|
+
switch (e.child.tag) {
|
|
12882
|
+
case 27:
|
|
12883
|
+
case 5:
|
|
12884
|
+
return ot(e.child.stateNode);
|
|
12885
|
+
default:
|
|
12886
|
+
return e.child.stateNode;
|
|
12887
|
+
}
|
|
12888
|
+
}, le.injectIntoDevTools = function() {
|
|
12889
|
+
var e = { bundleType: 1, version: Jt, rendererPackageName: Zt, currentDispatcherRef: x, reconcilerVersion: "19.2.0" };
|
|
12890
|
+
return jo !== null && (e.rendererConfig = jo), e.overrideHookState = gb, e.overrideHookStateDeletePath = yb, e.overrideHookStateRenamePath = bb, e.overrideProps = vb, e.overridePropsDeletePath = Sb, e.overridePropsRenamePath = kb, e.scheduleUpdate = wb, e.scheduleRetry = Pb, e.setErrorHandler = xb, e.setSuspenseHandler = zb, e.scheduleRefresh = hu, e.scheduleRoot = Fl, e.setRefreshHandler = Ir, e.getCurrentFiber = Ic, Ep(e);
|
|
12891
|
+
}, le.isAlreadyRendering = Ns, le.observeVisibleRects = function(e, n, o, i) {
|
|
12892
|
+
function s() {
|
|
12893
|
+
var S = kc(e, n);
|
|
12894
|
+
u.forEach(function(T) {
|
|
12895
|
+
0 > S.indexOf(T) && g(T);
|
|
12896
|
+
}), S.forEach(function(T) {
|
|
12897
|
+
0 > u.indexOf(T) && p(T);
|
|
12898
|
+
});
|
|
12899
|
+
}
|
|
12900
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12901
|
+
var u = kc(e, n);
|
|
12902
|
+
o = zr(u, o, i);
|
|
12903
|
+
var f = o.disconnect, p = o.observe, g = o.unobserve;
|
|
12904
|
+
return bm.push(s), { disconnect: function() {
|
|
12905
|
+
var S = bm.indexOf(s);
|
|
12906
|
+
0 <= S && bm.splice(S, 1), f();
|
|
12907
|
+
} };
|
|
12908
|
+
}, le.shouldError = function(e) {
|
|
12909
|
+
return pu(e);
|
|
12910
|
+
}, le.shouldSuspend = function(e) {
|
|
12911
|
+
return fu(e);
|
|
12912
|
+
}, le.startHostTransition = function(e, n, o, i) {
|
|
12913
|
+
if (e.tag !== 5) throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");
|
|
12914
|
+
var s = uf(e).queue;
|
|
12915
|
+
Hp(e), nt(e, s, n, Xt, o === null ? Em : function() {
|
|
12916
|
+
x.T === null && console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");
|
|
12917
|
+
var u = uf(e);
|
|
12918
|
+
return u.next === null && (u = e.alternate.memoizedState), qi(e, u.next.queue, {}, Nt(e)), o(i);
|
|
12919
|
+
});
|
|
12920
|
+
}, le.updateContainer = function(e, n, o, i) {
|
|
12921
|
+
var s = n.current, u = Nt(s);
|
|
12922
|
+
return As(s, u, e, n, o, i), u;
|
|
12923
|
+
}, le.updateContainerSync = Wh, le;
|
|
12924
|
+
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true }));
|
|
12925
|
+
})(Mg)), Mg.exports;
|
|
12926
|
+
}
|
|
12927
|
+
var Eb;
|
|
12928
|
+
function n0() {
|
|
12929
|
+
return Eb || (Eb = 1, process.env.NODE_ENV === "production" ? Rm.exports = Kb() : Rm.exports = e0()), Rm.exports;
|
|
12930
|
+
}
|
|
12931
|
+
var t0 = n0();
|
|
12932
|
+
const r0 = Xb(t0);
|
|
12933
|
+
|
|
12934
|
+
const DEFAULT_POINTER_ID = 0;
|
|
12935
|
+
const XR_POINTER_ID_START = 1e3;
|
|
12936
|
+
function getPointerState(internal, pointerId) {
|
|
12937
|
+
let state = internal.pointerMap.get(pointerId);
|
|
12938
|
+
if (!state) {
|
|
12939
|
+
state = {
|
|
12940
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
12941
|
+
captured: /* @__PURE__ */ new Map(),
|
|
12942
|
+
initialClick: [0, 0],
|
|
12943
|
+
initialHits: []
|
|
12944
|
+
};
|
|
12945
|
+
internal.pointerMap.set(pointerId, state);
|
|
12946
|
+
}
|
|
12947
|
+
return state;
|
|
12948
|
+
}
|
|
12949
|
+
function getPointerId(event) {
|
|
12950
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
12951
|
+
}
|
|
12952
|
+
function makeId(event) {
|
|
12953
|
+
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
12954
|
+
}
|
|
12955
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
12956
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
12957
|
+
if (!pointerState) return;
|
|
12958
|
+
const captureData = pointerState.captured.get(obj);
|
|
12959
|
+
if (captureData) {
|
|
12960
|
+
pointerState.captured.delete(obj);
|
|
12961
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
12962
|
+
}
|
|
12963
|
+
}
|
|
12964
|
+
function swapInteractivity(store, object, newObject) {
|
|
12965
|
+
const { internal } = store.getState();
|
|
12966
|
+
for (let i = 0; i < internal.interaction.length; i++) {
|
|
12967
|
+
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
12968
|
+
}
|
|
12969
|
+
for (const pointerState of internal.pointerMap.values()) {
|
|
12970
|
+
for (let i = 0; i < pointerState.initialHits.length; i++) {
|
|
12971
|
+
if (pointerState.initialHits[i] === object) pointerState.initialHits[i] = newObject;
|
|
12972
|
+
}
|
|
12973
|
+
pointerState.hovered.forEach((value, key) => {
|
|
12974
|
+
if (value.eventObject === object || value.object === object) {
|
|
12975
|
+
pointerState.hovered.delete(key);
|
|
12976
|
+
const next = {
|
|
12977
|
+
...value,
|
|
12978
|
+
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
12979
|
+
object: value.object === object ? newObject : value.object
|
|
12980
|
+
};
|
|
12981
|
+
pointerState.hovered.set(makeId(next), next);
|
|
12982
|
+
}
|
|
12983
|
+
});
|
|
12984
|
+
const captureData = pointerState.captured.get(object);
|
|
12985
|
+
if (captureData) {
|
|
12986
|
+
pointerState.captured.delete(object);
|
|
12987
|
+
pointerState.captured.set(newObject, {
|
|
12988
|
+
...captureData,
|
|
12989
|
+
intersection: {
|
|
12990
|
+
...captureData.intersection,
|
|
12991
|
+
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
12992
|
+
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
13417
12993
|
}
|
|
13418
|
-
}
|
|
13419
|
-
|
|
13420
|
-
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
return z = "useActionState", D(), N(), $t(e);
|
|
13432
|
-
}, useOptimistic: function(e, n) {
|
|
13433
|
-
return z = "useOptimistic", D(), N(), of(e, n);
|
|
13434
|
-
}, useMemoCache: function(e) {
|
|
13435
|
-
return D(), Oa(e);
|
|
13436
|
-
}, useHostTransitionStatus: ia, useCacheRefresh: function() {
|
|
13437
|
-
return z = "useCacheRefresh", N(), xe().memoizedState;
|
|
13438
|
-
}, useEffectEvent: function(e) {
|
|
13439
|
-
return z = "useEffectEvent", D(), N(), oa(e);
|
|
13440
|
-
} };
|
|
13441
|
-
var Fy = {}, Hy = /* @__PURE__ */ new Set(), Ay = /* @__PURE__ */ new Set(), jy = /* @__PURE__ */ new Set(), Dy = /* @__PURE__ */ new Set(), Wy = /* @__PURE__ */ new Set(), Uy = /* @__PURE__ */ new Set(), By = /* @__PURE__ */ new Set(), Oy = /* @__PURE__ */ new Set(), My = /* @__PURE__ */ new Set(), Qy = /* @__PURE__ */ new Set();
|
|
13442
|
-
Object.freeze(Fy);
|
|
13443
|
-
var zg = { enqueueSetState: function(e, n, o) {
|
|
13444
|
-
e = e._reactInternals;
|
|
13445
|
-
var i = Nt(e), s = zo(i);
|
|
13446
|
-
s.payload = n, o != null && (df(o), s.callback = o), n = Mt(e, s, i), n !== null && (ur(i, "this.setState()", e), We(n, e, i), Bi(n, e, i));
|
|
13447
|
-
}, enqueueReplaceState: function(e, n, o) {
|
|
13448
|
-
e = e._reactInternals;
|
|
13449
|
-
var i = Nt(e), s = zo(i);
|
|
13450
|
-
s.tag = Cy, s.payload = n, o != null && (df(o), s.callback = o), n = Mt(e, s, i), n !== null && (ur(i, "this.replaceState()", e), We(n, e, i), Bi(n, e, i));
|
|
13451
|
-
}, enqueueForceUpdate: function(e, n) {
|
|
13452
|
-
e = e._reactInternals;
|
|
13453
|
-
var o = Nt(e), i = zo(o);
|
|
13454
|
-
i.tag = Ty, n != null && (df(n), i.callback = n), n = Mt(e, i, o), n !== null && (ur(o, "this.forceUpdate()", e), We(n, e, o), Bi(n, e, o));
|
|
13455
|
-
} }, bd = null, Cg = null, Tg = Error("This is not a real error. It's an implementation detail of React's selective hydration feature. If this leaks into userspace, it's a bug in React. Please file an issue."), Cn = false, $y = {}, Vy = {}, qy = {}, Gy = {}, vd = false, Jy = {}, fm = {}, _g = { dehydrated: null, treeContext: null, retryLane: 0, hydrationErrors: null }, Zy = false, Yy = null;
|
|
13456
|
-
Yy = /* @__PURE__ */ new Set();
|
|
13457
|
-
var Si = false, Tn = false, Rg = false, Xy = typeof WeakSet == "function" ? WeakSet : Set, Gn = null, Sd = null, kd = null, _n = null, nr = false, Vo = null, Wn = false, wd = 8192, Vb = { getCacheForType: function(e) {
|
|
13458
|
-
var n = Ee(un), o = n.data.get(e);
|
|
13459
|
-
return o === void 0 && (o = e(), n.data.set(e, o)), o;
|
|
13460
|
-
}, cacheSignal: function() {
|
|
13461
|
-
return Ee(un).controller.signal;
|
|
13462
|
-
}, getOwner: function() {
|
|
13463
|
-
return di;
|
|
13464
|
-
} }, pm = 0, hm = 1, mm = 2, gm = 3, ym = 4;
|
|
13465
|
-
if (typeof Symbol == "function" && Symbol.for) {
|
|
13466
|
-
var bp = Symbol.for;
|
|
13467
|
-
pm = bp("selector.component"), hm = bp("selector.has_pseudo_class"), mm = bp("selector.role"), gm = bp("selector.test_id"), ym = bp("selector.text");
|
|
12994
|
+
});
|
|
12995
|
+
}
|
|
12996
|
+
}
|
|
12997
|
+
unregisterVisibility(store, object);
|
|
12998
|
+
}
|
|
12999
|
+
function removeInteractivity(store, object) {
|
|
13000
|
+
const { internal } = store.getState();
|
|
13001
|
+
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
13002
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
13003
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
13004
|
+
pointerState.hovered.forEach((value, key) => {
|
|
13005
|
+
if (value.eventObject === object || value.object === object) {
|
|
13006
|
+
pointerState.hovered.delete(key);
|
|
13468
13007
|
}
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13008
|
+
});
|
|
13009
|
+
if (pointerState.captured.has(object)) {
|
|
13010
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
13011
|
+
}
|
|
13012
|
+
}
|
|
13013
|
+
unregisterVisibility(store, object);
|
|
13014
|
+
}
|
|
13015
|
+
function createEvents(store) {
|
|
13016
|
+
function calculateDistance(event, pointerId) {
|
|
13017
|
+
const { internal } = store.getState();
|
|
13018
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13019
|
+
if (!pointerState) return 0;
|
|
13020
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
13021
|
+
const dx = event.offsetX - initialX;
|
|
13022
|
+
const dy = event.offsetY - initialY;
|
|
13023
|
+
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
13024
|
+
}
|
|
13025
|
+
function filterPointerEvents(objects) {
|
|
13026
|
+
return objects.filter(
|
|
13027
|
+
(obj) => ["Move", "Over", "Enter", "Out", "Leave"].some(
|
|
13028
|
+
(name) => obj.__r3f?.handlers["onPointer" + name]
|
|
13029
|
+
) || ["OverEnter", "OverLeave", "Over"].some(
|
|
13030
|
+
(name) => obj.__r3f?.handlers["onDrag" + name]
|
|
13031
|
+
) || obj.__r3f?.handlers.onDrop
|
|
13032
|
+
);
|
|
13033
|
+
}
|
|
13034
|
+
function intersect(event, filter) {
|
|
13035
|
+
const state = store.getState();
|
|
13036
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
13037
|
+
const intersections = [];
|
|
13038
|
+
const eventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
|
|
13039
|
+
for (let i = 0; i < eventsObjects.length; i++) {
|
|
13040
|
+
const state2 = getRootState(eventsObjects[i]);
|
|
13041
|
+
if (state2) {
|
|
13042
|
+
state2.raycaster.camera = void 0;
|
|
13474
13043
|
}
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
}, zb = function(e) {
|
|
13497
|
-
fu = e;
|
|
13498
|
-
}, le.attemptContinuousHydration = function(e) {
|
|
13499
|
-
if (e.tag === 13 || e.tag === 31) {
|
|
13500
|
-
var n = On(e, 67108864);
|
|
13501
|
-
n !== null && We(n, e, 67108864), rl(e, 67108864);
|
|
13044
|
+
}
|
|
13045
|
+
if (!state.previousRoot) {
|
|
13046
|
+
state.events.compute?.(event, state);
|
|
13047
|
+
}
|
|
13048
|
+
function handleRaycast(obj) {
|
|
13049
|
+
const state2 = getRootState(obj);
|
|
13050
|
+
if (!state2 || !state2.events.enabled || state2.raycaster.camera === null) return [];
|
|
13051
|
+
if (state2.raycaster.camera === void 0) {
|
|
13052
|
+
state2.events.compute?.(event, state2, state2.previousRoot?.getState());
|
|
13053
|
+
if (state2.raycaster.camera === void 0) state2.raycaster.camera = null;
|
|
13054
|
+
}
|
|
13055
|
+
return state2.raycaster.camera ? state2.raycaster.intersectObject(obj, true) : [];
|
|
13056
|
+
}
|
|
13057
|
+
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
13058
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
13059
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
13060
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
13061
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
13062
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
13063
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
13064
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
13502
13065
|
}
|
|
13503
|
-
}
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13066
|
+
}
|
|
13067
|
+
const aState = getRootState(a.object);
|
|
13068
|
+
const bState = getRootState(b.object);
|
|
13069
|
+
const aPriority = aState?.events?.priority ?? 1;
|
|
13070
|
+
const bPriority = bState?.events?.priority ?? 1;
|
|
13071
|
+
return bPriority - aPriority || a.distance - b.distance;
|
|
13072
|
+
}).filter((item) => {
|
|
13073
|
+
const id = makeId(item);
|
|
13074
|
+
if (duplicates.has(id)) return false;
|
|
13075
|
+
duplicates.add(id);
|
|
13076
|
+
return true;
|
|
13077
|
+
});
|
|
13078
|
+
if (state.events.filter) hits = state.events.filter(hits, state);
|
|
13079
|
+
for (const hit of hits) {
|
|
13080
|
+
let eventObject = hit.object;
|
|
13081
|
+
while (eventObject) {
|
|
13082
|
+
if (eventObject.__r3f?.eventCount) {
|
|
13083
|
+
intersections.push({ ...hit, eventObject });
|
|
13509
13084
|
}
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13085
|
+
eventObject = eventObject.parent;
|
|
13086
|
+
}
|
|
13087
|
+
}
|
|
13088
|
+
if ("pointerId" in event) {
|
|
13089
|
+
const pointerId = event.pointerId;
|
|
13090
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
13091
|
+
if (pointerState?.captured.size) {
|
|
13092
|
+
for (const captureData of pointerState.captured.values()) {
|
|
13093
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
13094
|
+
}
|
|
13095
|
+
}
|
|
13096
|
+
}
|
|
13097
|
+
return intersections;
|
|
13098
|
+
}
|
|
13099
|
+
function handleIntersects(intersections, event, delta, callback) {
|
|
13100
|
+
if (intersections.length) {
|
|
13101
|
+
const localState = { stopped: false };
|
|
13102
|
+
for (const hit of intersections) {
|
|
13103
|
+
const state = getRootState(hit.object);
|
|
13104
|
+
if (state) {
|
|
13105
|
+
const { raycaster, pointer, camera, internal } = state;
|
|
13106
|
+
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
13107
|
+
const hasPointerCapture = (id) => {
|
|
13108
|
+
const pointerState = internal.pointerMap.get(id);
|
|
13109
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
13110
|
+
};
|
|
13111
|
+
const setPointerCapture = (id) => {
|
|
13112
|
+
const captureData = { intersection: hit, target: event.target };
|
|
13113
|
+
const pointerState = getPointerState(internal, id);
|
|
13114
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
13115
|
+
event.target.setPointerCapture(id);
|
|
13116
|
+
};
|
|
13117
|
+
const releasePointerCapture = (id) => {
|
|
13118
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
13119
|
+
};
|
|
13120
|
+
const extractEventProps = {};
|
|
13121
|
+
for (const prop in event) {
|
|
13122
|
+
const property = event[prop];
|
|
13123
|
+
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
13124
|
+
}
|
|
13125
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
13126
|
+
const raycastEvent = {
|
|
13127
|
+
...hit,
|
|
13128
|
+
...extractEventProps,
|
|
13129
|
+
pointer,
|
|
13130
|
+
intersections,
|
|
13131
|
+
stopped: localState.stopped,
|
|
13132
|
+
delta,
|
|
13133
|
+
unprojectedPoint,
|
|
13134
|
+
ray: raycaster.ray,
|
|
13135
|
+
camera,
|
|
13136
|
+
pointerId: eventPointerId,
|
|
13137
|
+
// Hijack stopPropagation, which just sets a flag
|
|
13138
|
+
stopPropagation() {
|
|
13139
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
13140
|
+
if (
|
|
13141
|
+
// ...if this pointer hasn't been captured
|
|
13142
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
13143
|
+
pointerState.captured.has(hit.eventObject)
|
|
13144
|
+
) {
|
|
13145
|
+
raycastEvent.stopped = localState.stopped = true;
|
|
13146
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
13147
|
+
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
13148
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
13519
13149
|
}
|
|
13520
|
-
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
13521
13150
|
}
|
|
13522
|
-
}
|
|
13523
|
-
|
|
13524
|
-
|
|
13525
|
-
|
|
13526
|
-
|
|
13151
|
+
},
|
|
13152
|
+
// there should be a distinction between target and currentTarget
|
|
13153
|
+
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13154
|
+
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13155
|
+
nativeEvent: event
|
|
13156
|
+
};
|
|
13157
|
+
callback(raycastEvent);
|
|
13158
|
+
if (localState.stopped === true) break;
|
|
13527
13159
|
}
|
|
13528
|
-
}
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13160
|
+
}
|
|
13161
|
+
}
|
|
13162
|
+
return intersections;
|
|
13163
|
+
}
|
|
13164
|
+
function cancelPointer(intersections, pointerId) {
|
|
13165
|
+
const { internal } = store.getState();
|
|
13166
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
13167
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
13168
|
+
if (!pointerState) return;
|
|
13169
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
13170
|
+
if (!intersections.length || !intersections.find(
|
|
13171
|
+
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
13172
|
+
)) {
|
|
13173
|
+
const eventObject = hoveredObj.eventObject;
|
|
13174
|
+
const instance = eventObject.__r3f;
|
|
13175
|
+
pointerState.hovered.delete(hoveredId);
|
|
13176
|
+
if (instance?.eventCount) {
|
|
13177
|
+
const handlers = instance.handlers;
|
|
13178
|
+
const data = { ...hoveredObj, intersections };
|
|
13179
|
+
handlers.onPointerOut?.(data);
|
|
13180
|
+
handlers.onPointerLeave?.(data);
|
|
13181
|
+
handlers.onDragOverLeave?.(data);
|
|
13545
13182
|
}
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
an(o), x.T = n;
|
|
13183
|
+
}
|
|
13184
|
+
}
|
|
13185
|
+
}
|
|
13186
|
+
function pointerMissed(event, objects) {
|
|
13187
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13188
|
+
const instance = objects[i].__r3f;
|
|
13189
|
+
instance?.handlers.onPointerMissed?.(event);
|
|
13190
|
+
}
|
|
13191
|
+
}
|
|
13192
|
+
function dragOverMissed(event, objects) {
|
|
13193
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13194
|
+
const instance = objects[i].__r3f;
|
|
13195
|
+
instance?.handlers.onDragOverMissed?.(event);
|
|
13196
|
+
}
|
|
13197
|
+
}
|
|
13198
|
+
function dropMissed(event, objects) {
|
|
13199
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13200
|
+
const instance = objects[i].__r3f;
|
|
13201
|
+
instance?.handlers.onDropMissed?.(event);
|
|
13202
|
+
}
|
|
13203
|
+
}
|
|
13204
|
+
function cleanupPointer(pointerId) {
|
|
13205
|
+
const { internal } = store.getState();
|
|
13206
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13207
|
+
if (pointerState) {
|
|
13208
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13209
|
+
const eventObject = hoveredObj.eventObject;
|
|
13210
|
+
const instance = eventObject.__r3f;
|
|
13211
|
+
if (instance?.eventCount) {
|
|
13212
|
+
const handlers = instance.handlers;
|
|
13213
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13214
|
+
handlers.onPointerOut?.(data);
|
|
13215
|
+
handlers.onPointerLeave?.(data);
|
|
13580
13216
|
}
|
|
13581
|
-
}
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13217
|
+
}
|
|
13218
|
+
internal.pointerMap.delete(pointerId);
|
|
13219
|
+
}
|
|
13220
|
+
internal.pointerDirty.delete(pointerId);
|
|
13221
|
+
}
|
|
13222
|
+
function processDeferredPointer(event, pointerId) {
|
|
13223
|
+
const state = store.getState();
|
|
13224
|
+
const { internal } = state;
|
|
13225
|
+
if (!state.events.enabled) return;
|
|
13226
|
+
const filter = filterPointerEvents;
|
|
13227
|
+
const hits = intersect(event, filter);
|
|
13228
|
+
cancelPointer(hits, pointerId);
|
|
13229
|
+
function onIntersect(data) {
|
|
13230
|
+
const eventObject = data.eventObject;
|
|
13231
|
+
const instance = eventObject.__r3f;
|
|
13232
|
+
if (!instance?.eventCount) return;
|
|
13233
|
+
const handlers = instance.handlers;
|
|
13234
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13235
|
+
const id = makeId(data);
|
|
13236
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
13237
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
13238
|
+
if (!hoveredItem) {
|
|
13239
|
+
pointerState.hovered.set(id, data);
|
|
13240
|
+
handlers.onPointerOver?.(data);
|
|
13241
|
+
handlers.onPointerEnter?.(data);
|
|
13242
|
+
} else if (hoveredItem.stopped) {
|
|
13243
|
+
data.stopPropagation();
|
|
13244
|
+
}
|
|
13245
|
+
}
|
|
13246
|
+
handlers.onPointerMove?.(data);
|
|
13247
|
+
}
|
|
13248
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
13249
|
+
}
|
|
13250
|
+
function handlePointer(name) {
|
|
13251
|
+
switch (name) {
|
|
13252
|
+
case "onPointerLeave":
|
|
13253
|
+
case "onDragLeave":
|
|
13254
|
+
return () => cancelPointer([]);
|
|
13255
|
+
// Global cancel of these events
|
|
13256
|
+
case "onPointerCancel":
|
|
13257
|
+
return (event) => {
|
|
13258
|
+
const pointerId = getPointerId(event);
|
|
13259
|
+
cleanupPointer(pointerId);
|
|
13260
|
+
};
|
|
13261
|
+
case "onLostPointerCapture":
|
|
13262
|
+
return (event) => {
|
|
13263
|
+
const { internal } = store.getState();
|
|
13264
|
+
const pointerId = getPointerId(event);
|
|
13265
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13266
|
+
if (pointerState?.captured.size) {
|
|
13267
|
+
requestAnimationFrame(() => {
|
|
13268
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
13269
|
+
if (pointerState2?.captured.size) {
|
|
13270
|
+
pointerState2.captured.clear();
|
|
13271
|
+
}
|
|
13272
|
+
cancelPointer([], pointerId);
|
|
13273
|
+
});
|
|
13274
|
+
}
|
|
13275
|
+
};
|
|
13276
|
+
}
|
|
13277
|
+
return function handleEvent(event) {
|
|
13278
|
+
const state = store.getState();
|
|
13279
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
13280
|
+
const pointerId = getPointerId(event);
|
|
13281
|
+
internal.lastEvent.current = event;
|
|
13282
|
+
if (!events.enabled) return;
|
|
13283
|
+
const isPointerMove = name === "onPointerMove";
|
|
13284
|
+
const isDragOver = name === "onDragOver";
|
|
13285
|
+
const isDrop = name === "onDrop";
|
|
13286
|
+
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
13287
|
+
const isPointerDown = name === "onPointerDown";
|
|
13288
|
+
const isPointerUp = name === "onPointerUp";
|
|
13289
|
+
const isWheel = name === "onWheel";
|
|
13290
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
13291
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
13292
|
+
events.compute?.(event, state);
|
|
13293
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13294
|
+
return;
|
|
13295
|
+
}
|
|
13296
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
13297
|
+
events.compute?.(event, state);
|
|
13298
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13299
|
+
return;
|
|
13300
|
+
}
|
|
13301
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
13302
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
13303
|
+
internal.pointerDirty.delete(pointerId);
|
|
13304
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
13305
|
+
}
|
|
13306
|
+
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
13307
|
+
const hits = intersect(event, filter);
|
|
13308
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
13309
|
+
if (isPointerDown) {
|
|
13310
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13311
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
13312
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
13313
|
+
}
|
|
13314
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13315
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
13316
|
+
if (isClickEvent && !hits.length) {
|
|
13317
|
+
if (delta <= 2) {
|
|
13318
|
+
pointerMissed(event, internal.interaction);
|
|
13319
|
+
if (onPointerMissed) onPointerMissed(event);
|
|
13587
13320
|
}
|
|
13588
|
-
}
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13321
|
+
}
|
|
13322
|
+
if (isDragOver && !hits.length) {
|
|
13323
|
+
dragOverMissed(event, internal.interaction);
|
|
13324
|
+
if (onDragOverMissed) onDragOverMissed(event);
|
|
13325
|
+
}
|
|
13326
|
+
if (isDrop && !hits.length) {
|
|
13327
|
+
dropMissed(event, internal.interaction);
|
|
13328
|
+
if (onDropMissed) onDropMissed(event);
|
|
13329
|
+
}
|
|
13330
|
+
if (isPointerMove || isDragOver) {
|
|
13331
|
+
cancelPointer(hits, pointerId);
|
|
13332
|
+
}
|
|
13333
|
+
function onIntersect(data) {
|
|
13334
|
+
const eventObject = data.eventObject;
|
|
13335
|
+
const instance = eventObject.__r3f;
|
|
13336
|
+
if (!instance?.eventCount) return;
|
|
13337
|
+
const handlers = instance.handlers;
|
|
13338
|
+
if (isPointerMove) {
|
|
13339
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13340
|
+
const id = makeId(data);
|
|
13341
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13342
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13343
|
+
if (!hoveredItem) {
|
|
13344
|
+
pointerState2.hovered.set(id, data);
|
|
13345
|
+
handlers.onPointerOver?.(data);
|
|
13346
|
+
handlers.onPointerEnter?.(data);
|
|
13347
|
+
} else if (hoveredItem.stopped) {
|
|
13348
|
+
data.stopPropagation();
|
|
13607
13349
|
}
|
|
13608
13350
|
}
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
if (
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
var o = n[e++], i = o.tag;
|
|
13641
|
-
if (!Kr(o)) {
|
|
13642
|
-
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
13643
|
-
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
13351
|
+
handlers.onPointerMove?.(data);
|
|
13352
|
+
} else if (isDragOver) {
|
|
13353
|
+
const id = makeId(data);
|
|
13354
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13355
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13356
|
+
if (!hoveredItem) {
|
|
13357
|
+
pointerState2.hovered.set(id, data);
|
|
13358
|
+
handlers.onDragOverEnter?.(data);
|
|
13359
|
+
} else if (hoveredItem.stopped) {
|
|
13360
|
+
data.stopPropagation();
|
|
13361
|
+
}
|
|
13362
|
+
handlers.onDragOver?.(data);
|
|
13363
|
+
} else if (isDrop) {
|
|
13364
|
+
handlers.onDrop?.(data);
|
|
13365
|
+
} else {
|
|
13366
|
+
const handler = handlers[name];
|
|
13367
|
+
if (handler) {
|
|
13368
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
13369
|
+
pointerMissed(
|
|
13370
|
+
event,
|
|
13371
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13372
|
+
);
|
|
13373
|
+
handler(data);
|
|
13374
|
+
}
|
|
13375
|
+
} else {
|
|
13376
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
13377
|
+
pointerMissed(
|
|
13378
|
+
event,
|
|
13379
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13380
|
+
);
|
|
13381
|
+
}
|
|
13644
13382
|
}
|
|
13645
13383
|
}
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13384
|
+
}
|
|
13385
|
+
handleIntersects(hits, event, delta, onIntersect);
|
|
13386
|
+
};
|
|
13387
|
+
}
|
|
13388
|
+
function flushDeferredPointers() {
|
|
13389
|
+
const { internal, events } = store.getState();
|
|
13390
|
+
if (!events.frameTimedRaycasts) return;
|
|
13391
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
13392
|
+
processDeferredPointer(event, pointerId);
|
|
13393
|
+
}
|
|
13394
|
+
internal.pointerDirty.clear();
|
|
13395
|
+
}
|
|
13396
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
13397
|
+
}
|
|
13398
|
+
const DOM_EVENTS = {
|
|
13399
|
+
onClick: ["click", false],
|
|
13400
|
+
onContextMenu: ["contextmenu", false],
|
|
13401
|
+
onDoubleClick: ["dblclick", false],
|
|
13402
|
+
onDragEnter: ["dragenter", false],
|
|
13403
|
+
onDragLeave: ["dragleave", false],
|
|
13404
|
+
onDragOver: ["dragover", false],
|
|
13405
|
+
onDrop: ["drop", false],
|
|
13406
|
+
onWheel: ["wheel", true],
|
|
13407
|
+
onPointerDown: ["pointerdown", true],
|
|
13408
|
+
onPointerUp: ["pointerup", true],
|
|
13409
|
+
onPointerLeave: ["pointerleave", true],
|
|
13410
|
+
onPointerMove: ["pointermove", true],
|
|
13411
|
+
onPointerCancel: ["pointercancel", true],
|
|
13412
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
13413
|
+
};
|
|
13414
|
+
function createPointerEvents(store) {
|
|
13415
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
13416
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
13417
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
13418
|
+
return {
|
|
13419
|
+
priority: 1,
|
|
13420
|
+
enabled: true,
|
|
13421
|
+
frameTimedRaycasts: true,
|
|
13422
|
+
alwaysFireOnScroll: true,
|
|
13423
|
+
updateOnFrame: false,
|
|
13424
|
+
compute(event, state) {
|
|
13425
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
13426
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
13427
|
+
},
|
|
13428
|
+
connected: void 0,
|
|
13429
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
13430
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
13431
|
+
{}
|
|
13432
|
+
),
|
|
13433
|
+
update: (pointerId) => {
|
|
13434
|
+
const { events, internal } = store.getState();
|
|
13435
|
+
if (!events.handlers) return;
|
|
13436
|
+
if (pointerId !== void 0) {
|
|
13437
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
13438
|
+
if (event) {
|
|
13439
|
+
internal.pointerDirty.delete(pointerId);
|
|
13440
|
+
processDeferredPointer(event, pointerId);
|
|
13441
|
+
} else if (internal.lastEvent?.current) {
|
|
13442
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
13654
13443
|
}
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
No matching component was found for:
|
|
13661
|
-
`) + e.join(" > ");
|
|
13444
|
+
} else {
|
|
13445
|
+
flushDeferredPointers();
|
|
13446
|
+
if (internal.lastEvent?.current) {
|
|
13447
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13662
13448
|
}
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13449
|
+
}
|
|
13450
|
+
},
|
|
13451
|
+
flush: () => {
|
|
13452
|
+
const { events, internal } = store.getState();
|
|
13453
|
+
flushDeferredPointers();
|
|
13454
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
13455
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13456
|
+
}
|
|
13457
|
+
},
|
|
13458
|
+
connect: (target) => {
|
|
13459
|
+
if (!target) return;
|
|
13460
|
+
const { set, events } = store.getState();
|
|
13461
|
+
events.disconnect?.();
|
|
13462
|
+
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
13463
|
+
if (events.handlers) {
|
|
13464
|
+
for (const name in events.handlers) {
|
|
13465
|
+
const event = events.handlers[name];
|
|
13466
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
13467
|
+
target.addEventListener(eventName, event, { passive });
|
|
13672
13468
|
}
|
|
13673
|
-
}
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
}
|
|
13469
|
+
}
|
|
13470
|
+
},
|
|
13471
|
+
disconnect: () => {
|
|
13472
|
+
const { set, events } = store.getState();
|
|
13473
|
+
if (events.connected) {
|
|
13474
|
+
if (events.handlers) {
|
|
13475
|
+
for (const name in events.handlers) {
|
|
13476
|
+
const event = events.handlers[name];
|
|
13477
|
+
const [eventName] = DOM_EVENTS[name];
|
|
13478
|
+
events.connected.removeEventListener(eventName, event);
|
|
13479
|
+
}
|
|
13480
|
+
}
|
|
13481
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
13482
|
+
}
|
|
13483
|
+
},
|
|
13484
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
13485
|
+
registerPointer: (config) => {
|
|
13486
|
+
const pointerId = nextXRPointerId++;
|
|
13487
|
+
xrPointers.set(pointerId, config);
|
|
13488
|
+
const { internal } = store.getState();
|
|
13489
|
+
getPointerState(internal, pointerId);
|
|
13490
|
+
return pointerId;
|
|
13491
|
+
},
|
|
13492
|
+
unregisterPointer: (pointerId) => {
|
|
13493
|
+
xrPointers.delete(pointerId);
|
|
13494
|
+
const { internal } = store.getState();
|
|
13495
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13496
|
+
if (pointerState) {
|
|
13497
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13498
|
+
const eventObject = hoveredObj.eventObject;
|
|
13499
|
+
const instance = eventObject.__r3f;
|
|
13500
|
+
if (instance?.eventCount) {
|
|
13501
|
+
const handlers = instance.handlers;
|
|
13502
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13503
|
+
handlers.onPointerOut?.(data);
|
|
13504
|
+
handlers.onPointerLeave?.(data);
|
|
13505
|
+
}
|
|
13684
13506
|
}
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
var S = bm.indexOf(s);
|
|
13691
|
-
0 <= S && bm.splice(S, 1), f();
|
|
13692
|
-
} };
|
|
13693
|
-
}, le.shouldError = function(e) {
|
|
13694
|
-
return pu(e);
|
|
13695
|
-
}, le.shouldSuspend = function(e) {
|
|
13696
|
-
return fu(e);
|
|
13697
|
-
}, le.startHostTransition = function(e, n, o, i) {
|
|
13698
|
-
if (e.tag !== 5) throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");
|
|
13699
|
-
var s = uf(e).queue;
|
|
13700
|
-
Hp(e), nt(e, s, n, Xt, o === null ? Em : function() {
|
|
13701
|
-
x.T === null && console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");
|
|
13702
|
-
var u = uf(e);
|
|
13703
|
-
return u.next === null && (u = e.alternate.memoizedState), qi(e, u.next.queue, {}, Nt(e)), o(i);
|
|
13704
|
-
});
|
|
13705
|
-
}, le.updateContainer = function(e, n, o, i) {
|
|
13706
|
-
var s = n.current, u = Nt(s);
|
|
13707
|
-
return As(s, u, e, n, o, i), u;
|
|
13708
|
-
}, le.updateContainerSync = Wh, le;
|
|
13709
|
-
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true }));
|
|
13710
|
-
})(Mg)), Mg.exports;
|
|
13711
|
-
}
|
|
13712
|
-
var Eb;
|
|
13713
|
-
function n0() {
|
|
13714
|
-
return Eb || (Eb = 1, process.env.NODE_ENV === "production" ? Rm.exports = Kb() : Rm.exports = e0()), Rm.exports;
|
|
13507
|
+
internal.pointerMap.delete(pointerId);
|
|
13508
|
+
}
|
|
13509
|
+
internal.pointerDirty.delete(pointerId);
|
|
13510
|
+
}
|
|
13511
|
+
};
|
|
13715
13512
|
}
|
|
13716
|
-
var t0 = n0();
|
|
13717
|
-
const r0 = Xb(t0);
|
|
13718
|
-
|
|
13719
|
-
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
13720
13513
|
|
|
13721
13514
|
function createReconciler(config) {
|
|
13722
13515
|
const reconciler2 = r0(config);
|
|
@@ -14855,6 +14648,212 @@ function flushSync(fn) {
|
|
|
14855
14648
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14856
14649
|
}
|
|
14857
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
|
+
|
|
14858
14857
|
function parseBackground(background) {
|
|
14859
14858
|
if (!background) return null;
|
|
14860
14859
|
if (typeof background === "object" && !background.isColor) {
|
|
@@ -15064,7 +15063,7 @@ function CanvasImpl({
|
|
|
15064
15063
|
onDropMissed: (...args) => handleDropMissed.current?.(...args),
|
|
15065
15064
|
onCreated: (state) => {
|
|
15066
15065
|
state.events.connect?.(
|
|
15067
|
-
eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15066
|
+
eventSource ? isRef$1(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15068
15067
|
);
|
|
15069
15068
|
if (eventPrefix) {
|
|
15070
15069
|
state.setEvents({
|
|
@@ -15177,4 +15176,4 @@ function Canvas(props) {
|
|
|
15177
15176
|
|
|
15178
15177
|
extend(THREE);
|
|
15179
15178
|
|
|
15180
|
-
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, 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 };
|
|
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 };
|