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