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