@react-three/fiber 10.0.0-canary.0706a92 → 10.0.0-canary.07c4f9d
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 +1799 -1583
- package/dist/index.d.cts +110 -38
- package/dist/index.d.mts +110 -38
- package/dist/index.d.ts +110 -38
- package/dist/index.mjs +1802 -1586
- package/dist/legacy.cjs +2264 -2053
- package/dist/legacy.d.cts +109 -40
- package/dist/legacy.d.mts +109 -40
- package/dist/legacy.d.ts +109 -40
- package/dist/legacy.mjs +2266 -2055
- package/dist/webgpu/index.cjs +2131 -2132
- package/dist/webgpu/index.d.cts +147 -90
- package/dist/webgpu/index.d.mts +147 -90
- package/dist/webgpu/index.d.ts +147 -90
- package/dist/webgpu/index.mjs +2527 -2528
- package/package.json +6 -6
- 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,555 +111,229 @@ 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;
|
|
262
|
+
}
|
|
263
|
+
return data;
|
|
421
264
|
}
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
265
|
+
function dispose(obj) {
|
|
266
|
+
if (obj.type !== "Scene") obj.dispose?.();
|
|
267
|
+
for (const p in obj) {
|
|
268
|
+
const prop = obj[p];
|
|
269
|
+
if (prop?.type !== "Scene") prop?.dispose?.();
|
|
270
|
+
}
|
|
428
271
|
}
|
|
429
|
-
function
|
|
430
|
-
|
|
431
|
-
|
|
272
|
+
function getInstanceProps(pendingProps) {
|
|
273
|
+
const props = {};
|
|
274
|
+
for (const key in pendingProps) {
|
|
275
|
+
if (!REACT_INTERNAL_PROPS.includes(key)) props[key] = pendingProps[key];
|
|
432
276
|
}
|
|
433
|
-
|
|
434
|
-
|
|
277
|
+
return props;
|
|
278
|
+
}
|
|
279
|
+
function prepare(target, root, type, props) {
|
|
280
|
+
const object = target;
|
|
281
|
+
let instance = object?.__r3f;
|
|
282
|
+
if (!instance) {
|
|
283
|
+
instance = {
|
|
284
|
+
root,
|
|
285
|
+
type,
|
|
286
|
+
parent: null,
|
|
287
|
+
children: [],
|
|
288
|
+
props: getInstanceProps(props),
|
|
289
|
+
object,
|
|
290
|
+
eventCount: 0,
|
|
291
|
+
handlers: {},
|
|
292
|
+
isHidden: false
|
|
293
|
+
};
|
|
294
|
+
if (object) object.__r3f = instance;
|
|
435
295
|
}
|
|
436
|
-
return
|
|
296
|
+
return instance;
|
|
437
297
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const useIsomorphicLayoutEffect = /* @__PURE__ */ (() => typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"))() ? React.useLayoutEffect : React.useEffect;
|
|
444
|
-
function useMutableCallback(fn) {
|
|
445
|
-
const ref = React.useRef(fn);
|
|
446
|
-
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
447
|
-
return ref;
|
|
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();
|
|
448
303
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
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
|
+
}
|
|
460
317
|
}
|
|
461
|
-
function
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const
|
|
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
|
-
};
|
|
620
|
-
if (object) object.__r3f = instance;
|
|
621
|
-
}
|
|
622
|
-
return instance;
|
|
623
|
-
}
|
|
624
|
-
function invalidateInstance(instance) {
|
|
625
|
-
if (!instance.parent) return;
|
|
626
|
-
instance.props.onUpdate?.(instance.object);
|
|
627
|
-
const state = instance.root?.getState?.();
|
|
628
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
const tempFrustum = new Frustum();
|
|
632
|
-
let hasWarnedWebGL = false;
|
|
633
|
-
let tslModule = null;
|
|
634
|
-
async function loadTSL() {
|
|
635
|
-
if (tslModule) return tslModule;
|
|
636
|
-
try {
|
|
637
|
-
const tsl = await import('three/tsl');
|
|
638
|
-
tslModule = { uniform: tsl.uniform, nodeObject: tsl.nodeObject };
|
|
639
|
-
return tslModule;
|
|
640
|
-
} catch {
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function createOcclusionObserverNode(store, uniform) {
|
|
645
|
-
const node = new Node("float");
|
|
646
|
-
node.updateType = NodeUpdateType.OBJECT;
|
|
647
|
-
node.update = function(frame) {
|
|
648
|
-
const { internal } = store.getState();
|
|
649
|
-
const registry = internal.visibilityRegistry;
|
|
650
|
-
const cache = internal.occlusionCache;
|
|
651
|
-
for (const entry of registry.values()) {
|
|
652
|
-
const { object, handlers } = entry;
|
|
653
|
-
if (handlers.onOccluded || handlers.onVisible) {
|
|
654
|
-
const isOccluded = frame.renderer.isOccluded(object);
|
|
655
|
-
cache.set(object, isOccluded);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
node.setup = function() {
|
|
660
|
-
return uniform(0);
|
|
661
|
-
};
|
|
662
|
-
return node;
|
|
318
|
+
function createOcclusionObserverNode(store, uniform) {
|
|
319
|
+
const node = new Node("float");
|
|
320
|
+
node.updateType = NodeUpdateType.OBJECT;
|
|
321
|
+
node.update = function(frame) {
|
|
322
|
+
const { internal } = store.getState();
|
|
323
|
+
const registry = internal.visibilityRegistry;
|
|
324
|
+
const cache = internal.occlusionCache;
|
|
325
|
+
for (const entry of registry.values()) {
|
|
326
|
+
const { object, handlers } = entry;
|
|
327
|
+
if (handlers.onOccluded || handlers.onVisible) {
|
|
328
|
+
const isOccluded = frame.renderer.isOccluded(object);
|
|
329
|
+
cache.set(object, isOccluded);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
node.setup = function() {
|
|
334
|
+
return uniform(0);
|
|
335
|
+
};
|
|
336
|
+
return node;
|
|
663
337
|
}
|
|
664
338
|
let occlusionSetupPromise = null;
|
|
665
339
|
function enableOcclusion(store) {
|
|
@@ -943,9 +617,9 @@ function diffProps(instance, newProps) {
|
|
|
943
617
|
const { root, key } = resolve(instance.object, prop);
|
|
944
618
|
if (root.constructor && root.constructor.length === 0) {
|
|
945
619
|
const ctor = getMemoizedPrototype(root);
|
|
946
|
-
if (!is.und(ctor)) changedProps[
|
|
620
|
+
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
947
621
|
} else {
|
|
948
|
-
changedProps[
|
|
622
|
+
changedProps[prop] = 0;
|
|
949
623
|
}
|
|
950
624
|
}
|
|
951
625
|
return changedProps;
|
|
@@ -1062,1333 +736,928 @@ function applyProps(object, props) {
|
|
|
1062
736
|
return object;
|
|
1063
737
|
}
|
|
1064
738
|
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
if (!state) {
|
|
1070
|
-
state = {
|
|
1071
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1072
|
-
captured: /* @__PURE__ */ new Map(),
|
|
1073
|
-
initialClick: [0, 0],
|
|
1074
|
-
initialHits: []
|
|
1075
|
-
};
|
|
1076
|
-
internal.pointerMap.set(pointerId, state);
|
|
739
|
+
const shownNotices = /* @__PURE__ */ new Set();
|
|
740
|
+
function notifyDepreciated({ heading, body, link }) {
|
|
741
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_DEPRECATION_WARNINGS !== "true") {
|
|
742
|
+
return;
|
|
1077
743
|
}
|
|
1078
|
-
return
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
function makeId(event) {
|
|
1084
|
-
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
1085
|
-
}
|
|
1086
|
-
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
1087
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1088
|
-
if (!pointerState) return;
|
|
1089
|
-
const captureData = pointerState.captured.get(obj);
|
|
1090
|
-
if (captureData) {
|
|
1091
|
-
pointerState.captured.delete(obj);
|
|
1092
|
-
captureData.target.releasePointerCapture(pointerId);
|
|
744
|
+
if (shownNotices.has(heading)) return;
|
|
745
|
+
shownNotices.add(heading);
|
|
746
|
+
const caller = getCallerFrame();
|
|
747
|
+
if (caller) {
|
|
748
|
+
console.log();
|
|
1093
749
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
}
|
|
1104
|
-
});
|
|
1105
|
-
if (pointerState.captured.has(object)) {
|
|
1106
|
-
releaseInternalPointerCapture(internal, object, pointerId);
|
|
1107
|
-
}
|
|
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;");
|
|
1108
759
|
}
|
|
1109
|
-
unregisterVisibility(store, object);
|
|
1110
760
|
}
|
|
1111
|
-
function
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
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+)$/);
|
|
1120
770
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
771
|
+
if (!match) return null;
|
|
772
|
+
const [, fn, url, line] = match;
|
|
773
|
+
return {
|
|
774
|
+
functionName: fn ?? "<anonymous>",
|
|
775
|
+
location: formatLocation(url, Number(line))
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function formatLocation(url, line) {
|
|
779
|
+
const clean = url.split("?")[0];
|
|
780
|
+
const file = clean.split("/").pop() ?? clean;
|
|
781
|
+
return `${file}:${line}`;
|
|
782
|
+
}
|
|
783
|
+
function notifyAlpha({ message, link }) {
|
|
784
|
+
if (typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0) && process.env.R3F_SHOW_ALPHA_WARNINGS !== "true") {
|
|
785
|
+
return;
|
|
1129
786
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
const
|
|
1155
|
-
const
|
|
1156
|
-
if (
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
const bPriority = bState?.events?.priority ?? 1;
|
|
1167
|
-
return bPriority - aPriority || a.distance - b.distance;
|
|
1168
|
-
}).filter((item) => {
|
|
1169
|
-
const id = makeId(item);
|
|
1170
|
-
if (duplicates.has(id)) return false;
|
|
1171
|
-
duplicates.add(id);
|
|
1172
|
-
return true;
|
|
1173
|
-
});
|
|
1174
|
-
if (state.events.filter) hits = state.events.filter(hits, state);
|
|
1175
|
-
for (const hit of hits) {
|
|
1176
|
-
let eventObject = hit.object;
|
|
1177
|
-
while (eventObject) {
|
|
1178
|
-
if (eventObject.__r3f?.eventCount) {
|
|
1179
|
-
intersections.push({ ...hit, eventObject });
|
|
1180
|
-
}
|
|
1181
|
-
eventObject = eventObject.parent;
|
|
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;");
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
|
|
797
|
+
function isInternalRendererAccess(stack, callerDepth = 2) {
|
|
798
|
+
if (!stack) return false;
|
|
799
|
+
const caller = stack.split("\n")[callerDepth] ?? "";
|
|
800
|
+
return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
|
|
804
|
+
const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
|
|
805
|
+
const createStore = (invalidate, advance) => {
|
|
806
|
+
const rootStore = createWithEqualityFn((set, get) => {
|
|
807
|
+
const position = new Vector3();
|
|
808
|
+
const defaultTarget = new Vector3();
|
|
809
|
+
const tempTarget = new Vector3();
|
|
810
|
+
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
811
|
+
const { width, height, top, left } = size;
|
|
812
|
+
const aspect = width / height;
|
|
813
|
+
if (target.isVector3) tempTarget.copy(target);
|
|
814
|
+
else tempTarget.set(...target);
|
|
815
|
+
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
816
|
+
if (isOrthographicCamera(camera)) {
|
|
817
|
+
return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect };
|
|
818
|
+
} else {
|
|
819
|
+
const fov = camera.fov * Math.PI / 180;
|
|
820
|
+
const h = 2 * Math.tan(fov / 2) * distance;
|
|
821
|
+
const w = h * (width / height);
|
|
822
|
+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1182
823
|
}
|
|
1183
824
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
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
|
+
);
|
|
1190
878
|
}
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
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
|
+
get().invalidate();
|
|
913
|
+
}
|
|
1220
914
|
}
|
|
1221
|
-
|
|
1222
|
-
const raycastEvent = {
|
|
1223
|
-
...hit,
|
|
1224
|
-
...extractEventProps,
|
|
1225
|
-
pointer,
|
|
1226
|
-
intersections,
|
|
1227
|
-
stopped: localState.stopped,
|
|
1228
|
-
delta,
|
|
1229
|
-
unprojectedPoint,
|
|
1230
|
-
ray: raycaster.ray,
|
|
1231
|
-
camera,
|
|
1232
|
-
pointerId: eventPointerId,
|
|
1233
|
-
// Hijack stopPropagation, which just sets a flag
|
|
1234
|
-
stopPropagation() {
|
|
1235
|
-
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
1236
|
-
if (
|
|
1237
|
-
// ...if this pointer hasn't been captured
|
|
1238
|
-
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
1239
|
-
pointerState.captured.has(hit.eventObject)
|
|
1240
|
-
) {
|
|
1241
|
-
raycastEvent.stopped = localState.stopped = true;
|
|
1242
|
-
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1243
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1244
|
-
cancelPointer([...higher, hit], eventPointerId);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
},
|
|
1248
|
-
// there should be a distinction between target and currentTarget
|
|
1249
|
-
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1250
|
-
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1251
|
-
nativeEvent: event
|
|
1252
|
-
};
|
|
1253
|
-
callback(raycastEvent);
|
|
1254
|
-
if (localState.stopped === true) break;
|
|
915
|
+
return;
|
|
1255
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
|
+
get().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
|
+
const rootId = get().internal.rootId;
|
|
935
|
+
if (rootId) getScheduler().setRootFrameloop(rootId, frameloop);
|
|
936
|
+
set(() => ({ frameloop }));
|
|
937
|
+
},
|
|
938
|
+
setError: (error) => set(() => ({ error })),
|
|
939
|
+
error: null,
|
|
940
|
+
//* TSL State (managed via hooks: useUniforms, useNodes, useBuffers, useGPUStorage, useTextures, useRenderPipeline) ==============================
|
|
941
|
+
uniforms: {},
|
|
942
|
+
nodes: {},
|
|
943
|
+
buffers: {},
|
|
944
|
+
gpuStorage: {},
|
|
945
|
+
textures: /* @__PURE__ */ new Map(),
|
|
946
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
947
|
+
renderPipeline: null,
|
|
948
|
+
passes: {},
|
|
949
|
+
_hmrVersion: 0,
|
|
950
|
+
_sizeImperative: false,
|
|
951
|
+
_sizeProps: null,
|
|
952
|
+
previousRoot: void 0,
|
|
953
|
+
internal: {
|
|
954
|
+
// Events
|
|
955
|
+
interaction: [],
|
|
956
|
+
subscribers: [],
|
|
957
|
+
// Per-pointer state (new unified structure)
|
|
958
|
+
pointerMap: /* @__PURE__ */ new Map(),
|
|
959
|
+
pointerDirty: /* @__PURE__ */ new Map(),
|
|
960
|
+
lastEvent: React.createRef(),
|
|
961
|
+
// Deprecated but kept for backwards compatibility
|
|
962
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
963
|
+
initialClick: [0, 0],
|
|
964
|
+
initialHits: [],
|
|
965
|
+
capturedMap: /* @__PURE__ */ new Map(),
|
|
966
|
+
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
967
|
+
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
968
|
+
// Occlusion system (WebGPU only)
|
|
969
|
+
occlusionEnabled: false,
|
|
970
|
+
occlusionObserver: null,
|
|
971
|
+
occlusionCache: /* @__PURE__ */ new Map(),
|
|
972
|
+
helperGroup: null,
|
|
973
|
+
// Updates
|
|
974
|
+
active: false,
|
|
975
|
+
frames: 0,
|
|
976
|
+
priority: 0,
|
|
977
|
+
subscribe: (ref, priority, store) => {
|
|
978
|
+
const internal = get().internal;
|
|
979
|
+
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
980
|
+
internal.subscribers.push({ ref, priority, store });
|
|
981
|
+
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
982
|
+
return () => {
|
|
983
|
+
const internal2 = get().internal;
|
|
984
|
+
if (internal2?.subscribers) {
|
|
985
|
+
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
986
|
+
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
},
|
|
990
|
+
// Renderer Storage (single source of truth)
|
|
991
|
+
actualRenderer: null,
|
|
992
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
993
|
+
scheduler: null
|
|
1256
994
|
}
|
|
1257
|
-
}
|
|
1258
|
-
return
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
if (instance?.eventCount) {
|
|
1273
|
-
const handlers = instance.handlers;
|
|
1274
|
-
const data = { ...hoveredObj, intersections };
|
|
1275
|
-
handlers.onPointerOut?.(data);
|
|
1276
|
-
handlers.onPointerLeave?.(data);
|
|
1277
|
-
handlers.onDragOverLeave?.(data);
|
|
995
|
+
};
|
|
996
|
+
return rootState;
|
|
997
|
+
});
|
|
998
|
+
const state = rootStore.getState();
|
|
999
|
+
Object.defineProperty(state, "gl", {
|
|
1000
|
+
get() {
|
|
1001
|
+
const currentState = rootStore.getState();
|
|
1002
|
+
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1003
|
+
const stack = new Error().stack || "";
|
|
1004
|
+
if (!isInternalRendererAccess(stack)) {
|
|
1005
|
+
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1006
|
+
notifyDepreciated({
|
|
1007
|
+
heading: "Accessing state.gl in WebGPU mode",
|
|
1008
|
+
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
|
|
1009
|
+
});
|
|
1278
1010
|
}
|
|
1279
1011
|
}
|
|
1012
|
+
return currentState.internal.actualRenderer;
|
|
1013
|
+
},
|
|
1014
|
+
set(value) {
|
|
1015
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1016
|
+
},
|
|
1017
|
+
enumerable: true,
|
|
1018
|
+
configurable: true
|
|
1019
|
+
});
|
|
1020
|
+
Object.defineProperty(state, "renderer", {
|
|
1021
|
+
get() {
|
|
1022
|
+
return rootStore.getState().internal.actualRenderer;
|
|
1023
|
+
},
|
|
1024
|
+
set(value) {
|
|
1025
|
+
rootStore.getState().internal.actualRenderer = value;
|
|
1026
|
+
},
|
|
1027
|
+
enumerable: true,
|
|
1028
|
+
configurable: true
|
|
1029
|
+
});
|
|
1030
|
+
let oldScene = state.scene;
|
|
1031
|
+
rootStore.subscribe(() => {
|
|
1032
|
+
const currentState = rootStore.getState();
|
|
1033
|
+
const { scene, rootScene, set } = currentState;
|
|
1034
|
+
if (scene !== oldScene) {
|
|
1035
|
+
oldScene = scene;
|
|
1036
|
+
if (scene?.isScene && scene !== rootScene) {
|
|
1037
|
+
set({ rootScene: scene });
|
|
1038
|
+
}
|
|
1280
1039
|
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1040
|
+
});
|
|
1041
|
+
let oldSize = state.size;
|
|
1042
|
+
let oldDpr = state.viewport.dpr;
|
|
1043
|
+
let oldCamera = state.camera;
|
|
1044
|
+
rootStore.subscribe(() => {
|
|
1045
|
+
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1046
|
+
const actualRenderer = internal.actualRenderer;
|
|
1047
|
+
const canvasTarget = internal.canvasTarget;
|
|
1048
|
+
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1049
|
+
oldSize = size;
|
|
1050
|
+
oldDpr = viewport.dpr;
|
|
1051
|
+
updateCamera(camera, size);
|
|
1052
|
+
const resizeTarget = canvasTarget ?? actualRenderer;
|
|
1053
|
+
if (viewport.dpr > 0) resizeTarget.setPixelRatio(viewport.dpr);
|
|
1054
|
+
resizeTarget.setSize(size.width, size.height, false);
|
|
1055
|
+
internal.canvasTargetSizeDirty = true;
|
|
1286
1056
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1057
|
+
if (camera !== oldCamera) {
|
|
1058
|
+
oldCamera = camera;
|
|
1059
|
+
const { rootScene } = rootStore.getState();
|
|
1060
|
+
if (camera && rootScene && !camera.parent) {
|
|
1061
|
+
rootScene.add(camera);
|
|
1062
|
+
}
|
|
1063
|
+
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1064
|
+
const currentState = rootStore.getState();
|
|
1065
|
+
if (currentState.autoUpdateFrustum && camera) {
|
|
1066
|
+
updateFrustum(camera, currentState.frustum);
|
|
1067
|
+
}
|
|
1292
1068
|
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1069
|
+
});
|
|
1070
|
+
rootStore.subscribe((state2) => invalidate(state2));
|
|
1071
|
+
return rootStore;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
const memoizedLoaders = /* @__PURE__ */ new WeakMap();
|
|
1075
|
+
const isConstructor$1 = (value) => typeof value === "function" && value?.prototype?.constructor === value;
|
|
1076
|
+
function getLoader$1(Proto) {
|
|
1077
|
+
if (isConstructor$1(Proto)) {
|
|
1078
|
+
let loader = memoizedLoaders.get(Proto);
|
|
1079
|
+
if (!loader) {
|
|
1080
|
+
loader = new Proto();
|
|
1081
|
+
memoizedLoaders.set(Proto, loader);
|
|
1298
1082
|
}
|
|
1083
|
+
return loader;
|
|
1299
1084
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
handlers.onPointerLeave?.(data);
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
internal.pointerMap.delete(pointerId);
|
|
1085
|
+
return Proto;
|
|
1086
|
+
}
|
|
1087
|
+
function loadingFn(extensions, onProgress) {
|
|
1088
|
+
return function(Proto, input) {
|
|
1089
|
+
const loader = getLoader$1(Proto);
|
|
1090
|
+
if (extensions) extensions(loader);
|
|
1091
|
+
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1092
|
+
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1093
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1094
|
+
return data;
|
|
1095
|
+
});
|
|
1315
1096
|
}
|
|
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
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1097
|
+
return new Promise(
|
|
1098
|
+
(res, reject) => loader.load(
|
|
1099
|
+
input,
|
|
1100
|
+
(data) => {
|
|
1101
|
+
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1102
|
+
res(data);
|
|
1103
|
+
},
|
|
1104
|
+
onProgress,
|
|
1105
|
+
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1106
|
+
)
|
|
1107
|
+
);
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1111
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1112
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1113
|
+
const fn = loadingFn(extensions, onProgress);
|
|
1114
|
+
const results = cacheKeys.map(
|
|
1115
|
+
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1116
|
+
);
|
|
1117
|
+
const stableRef = useRef(null);
|
|
1118
|
+
const previous = stableRef.current;
|
|
1119
|
+
const stable = previous !== null && previous.length === results.length && previous.every((value, i) => value === results[i]) ? previous : results;
|
|
1120
|
+
stableRef.current = stable;
|
|
1121
|
+
return Array.isArray(input) ? stable : stable[0];
|
|
1122
|
+
}
|
|
1123
|
+
useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
|
|
1124
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
1125
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1126
|
+
cacheKeys.forEach(
|
|
1127
|
+
(key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
|
|
1128
|
+
);
|
|
1129
|
+
};
|
|
1130
|
+
useLoader.clear = function(loader, input, cacheKey) {
|
|
1131
|
+
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1132
|
+
cacheKeys.forEach((key) => clear([loader, key]));
|
|
1133
|
+
};
|
|
1134
|
+
useLoader.loader = getLoader$1;
|
|
1135
|
+
|
|
1136
|
+
function useFrame(callback, priorityOrOptions) {
|
|
1137
|
+
const store = React.useContext(context);
|
|
1138
|
+
const isInsideCanvas = store !== null;
|
|
1139
|
+
const scheduler = getScheduler();
|
|
1140
|
+
const optionsKey = typeof priorityOrOptions === "number" ? `p:${priorityOrOptions}` : priorityOrOptions ? JSON.stringify({
|
|
1141
|
+
id: priorityOrOptions.id,
|
|
1142
|
+
phase: priorityOrOptions.phase,
|
|
1143
|
+
priority: priorityOrOptions.priority,
|
|
1144
|
+
fps: priorityOrOptions.fps,
|
|
1145
|
+
drop: priorityOrOptions.drop,
|
|
1146
|
+
enabled: priorityOrOptions.enabled,
|
|
1147
|
+
before: priorityOrOptions.before,
|
|
1148
|
+
after: priorityOrOptions.after
|
|
1149
|
+
}) : "";
|
|
1150
|
+
const options = React.useMemo(() => {
|
|
1151
|
+
return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
|
|
1152
|
+
}, [optionsKey]);
|
|
1153
|
+
const reactId = React.useId();
|
|
1154
|
+
const id = options.id ?? reactId;
|
|
1155
|
+
const callbackRef = useMutableCallback(callback);
|
|
1156
|
+
const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
|
|
1157
|
+
useIsomorphicLayoutEffect(() => {
|
|
1158
|
+
if (!callback) return;
|
|
1159
|
+
if (isInsideCanvas) {
|
|
1374
1160
|
const state = store.getState();
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
const isPointerDown = name === "onPointerDown";
|
|
1384
|
-
const isPointerUp = name === "onPointerUp";
|
|
1385
|
-
const isWheel = name === "onWheel";
|
|
1386
|
-
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
1387
|
-
if (isPointerMove && canDeferRaycasts) {
|
|
1388
|
-
events.compute?.(event, state);
|
|
1389
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1390
|
-
return;
|
|
1391
|
-
}
|
|
1392
|
-
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
1393
|
-
events.compute?.(event, state);
|
|
1394
|
-
internal.pointerDirty.set(pointerId, event);
|
|
1395
|
-
return;
|
|
1396
|
-
}
|
|
1397
|
-
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
1398
|
-
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
1399
|
-
internal.pointerDirty.delete(pointerId);
|
|
1400
|
-
processDeferredPointer(deferredEvent, pointerId);
|
|
1401
|
-
}
|
|
1402
|
-
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
1403
|
-
const hits = intersect(event, filter);
|
|
1404
|
-
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
1405
|
-
if (isPointerDown) {
|
|
1406
|
-
const pointerState2 = getPointerState(internal, pointerId);
|
|
1407
|
-
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
1408
|
-
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
1409
|
-
}
|
|
1410
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1411
|
-
const initialHits = pointerState?.initialHits ?? [];
|
|
1412
|
-
if (isClickEvent && !hits.length) {
|
|
1413
|
-
if (delta <= 2) {
|
|
1414
|
-
pointerMissed(event, internal.interaction);
|
|
1415
|
-
if (onPointerMissed) onPointerMissed(event);
|
|
1161
|
+
const rootId = state.internal.rootId;
|
|
1162
|
+
if (isLegacyPriority) {
|
|
1163
|
+
state.internal.priority++;
|
|
1164
|
+
let parentRoot = state.previousRoot;
|
|
1165
|
+
while (parentRoot) {
|
|
1166
|
+
const parentState = parentRoot.getState();
|
|
1167
|
+
if (parentState?.internal) parentState.internal.priority++;
|
|
1168
|
+
parentRoot = parentState?.previousRoot;
|
|
1416
1169
|
}
|
|
1170
|
+
notifyDepreciated({
|
|
1171
|
+
heading: "useFrame with numeric priority is deprecated",
|
|
1172
|
+
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 })',
|
|
1173
|
+
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
1174
|
+
});
|
|
1417
1175
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
handlers.onPointerMove?.(data);
|
|
1448
|
-
} else if (isDragOver) {
|
|
1449
|
-
const id = makeId(data);
|
|
1450
|
-
const pointerState2 = getPointerState(internal, pointerId);
|
|
1451
|
-
const hoveredItem = pointerState2.hovered.get(id);
|
|
1452
|
-
if (!hoveredItem) {
|
|
1453
|
-
pointerState2.hovered.set(id, data);
|
|
1454
|
-
handlers.onDragOverEnter?.(data);
|
|
1455
|
-
} else if (hoveredItem.stopped) {
|
|
1456
|
-
data.stopPropagation();
|
|
1457
|
-
}
|
|
1458
|
-
handlers.onDragOver?.(data);
|
|
1459
|
-
} else if (isDrop) {
|
|
1460
|
-
handlers.onDrop?.(data);
|
|
1461
|
-
} else {
|
|
1462
|
-
const handler = handlers[name];
|
|
1463
|
-
if (handler) {
|
|
1464
|
-
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
1465
|
-
pointerMissed(
|
|
1466
|
-
event,
|
|
1467
|
-
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1468
|
-
);
|
|
1469
|
-
handler(data);
|
|
1470
|
-
}
|
|
1471
|
-
} else {
|
|
1472
|
-
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
1473
|
-
pointerMissed(
|
|
1474
|
-
event,
|
|
1475
|
-
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
1476
|
-
);
|
|
1176
|
+
const wrappedCallback = (frameState, delta) => {
|
|
1177
|
+
const localState = store.getState();
|
|
1178
|
+
const mergedState = {
|
|
1179
|
+
...localState,
|
|
1180
|
+
time: frameState.time,
|
|
1181
|
+
delta: frameState.delta,
|
|
1182
|
+
elapsed: frameState.elapsed,
|
|
1183
|
+
frame: frameState.frame
|
|
1184
|
+
};
|
|
1185
|
+
callbackRef.current?.(mergedState, delta);
|
|
1186
|
+
};
|
|
1187
|
+
const unregister = scheduler.register(wrappedCallback, {
|
|
1188
|
+
id,
|
|
1189
|
+
rootId,
|
|
1190
|
+
...options
|
|
1191
|
+
});
|
|
1192
|
+
return () => {
|
|
1193
|
+
unregister();
|
|
1194
|
+
if (isLegacyPriority) {
|
|
1195
|
+
const currentState = store.getState();
|
|
1196
|
+
if (currentState.internal) {
|
|
1197
|
+
currentState.internal.priority--;
|
|
1198
|
+
let parentRoot = currentState.previousRoot;
|
|
1199
|
+
while (parentRoot) {
|
|
1200
|
+
const parentState = parentRoot.getState();
|
|
1201
|
+
if (parentState?.internal) parentState.internal.priority--;
|
|
1202
|
+
parentRoot = parentState?.previousRoot;
|
|
1477
1203
|
}
|
|
1478
1204
|
}
|
|
1479
1205
|
}
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
internal.pointerDirty.clear();
|
|
1491
|
-
}
|
|
1492
|
-
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
1493
|
-
}
|
|
1494
|
-
const DOM_EVENTS = {
|
|
1495
|
-
onClick: ["click", false],
|
|
1496
|
-
onContextMenu: ["contextmenu", false],
|
|
1497
|
-
onDoubleClick: ["dblclick", false],
|
|
1498
|
-
onDragEnter: ["dragenter", false],
|
|
1499
|
-
onDragLeave: ["dragleave", false],
|
|
1500
|
-
onDragOver: ["dragover", false],
|
|
1501
|
-
onDrop: ["drop", false],
|
|
1502
|
-
onWheel: ["wheel", true],
|
|
1503
|
-
onPointerDown: ["pointerdown", true],
|
|
1504
|
-
onPointerUp: ["pointerup", true],
|
|
1505
|
-
onPointerLeave: ["pointerleave", true],
|
|
1506
|
-
onPointerMove: ["pointermove", true],
|
|
1507
|
-
onPointerCancel: ["pointercancel", true],
|
|
1508
|
-
onLostPointerCapture: ["lostpointercapture", true]
|
|
1509
|
-
};
|
|
1510
|
-
function createPointerEvents(store) {
|
|
1511
|
-
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
1512
|
-
let nextXRPointerId = XR_POINTER_ID_START;
|
|
1513
|
-
const xrPointers = /* @__PURE__ */ new Map();
|
|
1514
|
-
return {
|
|
1515
|
-
priority: 1,
|
|
1516
|
-
enabled: true,
|
|
1517
|
-
frameTimedRaycasts: true,
|
|
1518
|
-
alwaysFireOnScroll: true,
|
|
1519
|
-
updateOnFrame: false,
|
|
1520
|
-
compute(event, state) {
|
|
1521
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1522
|
-
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
1523
|
-
},
|
|
1524
|
-
connected: void 0,
|
|
1525
|
-
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
1526
|
-
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
1527
|
-
{}
|
|
1528
|
-
),
|
|
1529
|
-
update: (pointerId) => {
|
|
1530
|
-
const { events, internal } = store.getState();
|
|
1531
|
-
if (!events.handlers) return;
|
|
1532
|
-
if (pointerId !== void 0) {
|
|
1533
|
-
const event = internal.pointerDirty.get(pointerId);
|
|
1534
|
-
if (event) {
|
|
1535
|
-
internal.pointerDirty.delete(pointerId);
|
|
1536
|
-
processDeferredPointer(event, pointerId);
|
|
1537
|
-
} else if (internal.lastEvent?.current) {
|
|
1538
|
-
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
1539
|
-
}
|
|
1540
|
-
} else {
|
|
1541
|
-
flushDeferredPointers();
|
|
1542
|
-
if (internal.lastEvent?.current) {
|
|
1543
|
-
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
},
|
|
1547
|
-
flush: () => {
|
|
1548
|
-
const { events, internal } = store.getState();
|
|
1549
|
-
flushDeferredPointers();
|
|
1550
|
-
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
1551
|
-
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
1552
|
-
}
|
|
1553
|
-
},
|
|
1554
|
-
connect: (target) => {
|
|
1555
|
-
if (!target) return;
|
|
1556
|
-
const { set, events } = store.getState();
|
|
1557
|
-
events.disconnect?.();
|
|
1558
|
-
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
1559
|
-
if (events.handlers) {
|
|
1560
|
-
for (const name in events.handlers) {
|
|
1561
|
-
const event = events.handlers[name];
|
|
1562
|
-
const [eventName, passive] = DOM_EVENTS[name];
|
|
1563
|
-
target.addEventListener(eventName, event, { passive });
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
},
|
|
1567
|
-
disconnect: () => {
|
|
1568
|
-
const { set, events } = store.getState();
|
|
1569
|
-
if (events.connected) {
|
|
1570
|
-
if (events.handlers) {
|
|
1571
|
-
for (const name in events.handlers) {
|
|
1572
|
-
const event = events.handlers[name];
|
|
1573
|
-
const [eventName] = DOM_EVENTS[name];
|
|
1574
|
-
events.connected.removeEventListener(eventName, event);
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
1578
|
-
}
|
|
1579
|
-
},
|
|
1580
|
-
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
1581
|
-
registerPointer: (config) => {
|
|
1582
|
-
const pointerId = nextXRPointerId++;
|
|
1583
|
-
xrPointers.set(pointerId, config);
|
|
1584
|
-
const { internal } = store.getState();
|
|
1585
|
-
getPointerState(internal, pointerId);
|
|
1586
|
-
return pointerId;
|
|
1587
|
-
},
|
|
1588
|
-
unregisterPointer: (pointerId) => {
|
|
1589
|
-
xrPointers.delete(pointerId);
|
|
1590
|
-
const { internal } = store.getState();
|
|
1591
|
-
const pointerState = internal.pointerMap.get(pointerId);
|
|
1592
|
-
if (pointerState) {
|
|
1593
|
-
for (const [, hoveredObj] of pointerState.hovered) {
|
|
1594
|
-
const eventObject = hoveredObj.eventObject;
|
|
1595
|
-
const instance = eventObject.__r3f;
|
|
1596
|
-
if (instance?.eventCount) {
|
|
1597
|
-
const handlers = instance.handlers;
|
|
1598
|
-
const data = { ...hoveredObj, intersections: [] };
|
|
1599
|
-
handlers.onPointerOut?.(data);
|
|
1600
|
-
handlers.onPointerLeave?.(data);
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
internal.pointerMap.delete(pointerId);
|
|
1604
|
-
}
|
|
1605
|
-
internal.pointerDirty.delete(pointerId);
|
|
1206
|
+
};
|
|
1207
|
+
} else {
|
|
1208
|
+
return scheduler.register(
|
|
1209
|
+
(state, delta) => {
|
|
1210
|
+
const frameState = state;
|
|
1211
|
+
if (!frameState.renderer) return;
|
|
1212
|
+
callbackRef.current?.(frameState, delta);
|
|
1213
|
+
},
|
|
1214
|
+
{ id, ...options }
|
|
1215
|
+
);
|
|
1606
1216
|
}
|
|
1607
|
-
};
|
|
1217
|
+
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
1218
|
+
const isPaused = React.useSyncExternalStore(
|
|
1219
|
+
// Subscribe function
|
|
1220
|
+
React.useCallback(
|
|
1221
|
+
(onStoreChange) => {
|
|
1222
|
+
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
1223
|
+
},
|
|
1224
|
+
[id]
|
|
1225
|
+
),
|
|
1226
|
+
// getSnapshot function
|
|
1227
|
+
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
1228
|
+
// getServerSnapshot function (SSR)
|
|
1229
|
+
React.useCallback(() => false, [])
|
|
1230
|
+
);
|
|
1231
|
+
const controls = React.useMemo(() => {
|
|
1232
|
+
const scheduler2 = getScheduler();
|
|
1233
|
+
return {
|
|
1234
|
+
/** The job's unique ID */
|
|
1235
|
+
id,
|
|
1236
|
+
/**
|
|
1237
|
+
* Access to the global scheduler for frame loop control.
|
|
1238
|
+
* Use for controlling the entire frame loop, adding phases, etc.
|
|
1239
|
+
*/
|
|
1240
|
+
scheduler: scheduler2,
|
|
1241
|
+
/**
|
|
1242
|
+
* The root that currently owns this job. Resolve on access because ambient
|
|
1243
|
+
* jobs can be adopted by a Canvas after the controls object is created.
|
|
1244
|
+
*/
|
|
1245
|
+
get rootId() {
|
|
1246
|
+
return getScheduler().getJobRootId(id);
|
|
1247
|
+
},
|
|
1248
|
+
/**
|
|
1249
|
+
* Manually step this job only.
|
|
1250
|
+
* Bypasses FPS limiting - always runs.
|
|
1251
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1252
|
+
*/
|
|
1253
|
+
step: (timestamp) => {
|
|
1254
|
+
getScheduler().stepJob(id, timestamp);
|
|
1255
|
+
},
|
|
1256
|
+
/**
|
|
1257
|
+
* Manually step ALL jobs in the scheduler.
|
|
1258
|
+
* Useful for frameloop='never' mode.
|
|
1259
|
+
* @param timestamp Optional timestamp (defaults to performance.now())
|
|
1260
|
+
*/
|
|
1261
|
+
stepAll: (timestamp) => {
|
|
1262
|
+
getScheduler().step(timestamp);
|
|
1263
|
+
},
|
|
1264
|
+
/**
|
|
1265
|
+
* Request frames for this job's owning root without waking sibling roots.
|
|
1266
|
+
*/
|
|
1267
|
+
invalidate: (frames, stackFrames) => {
|
|
1268
|
+
const scheduler3 = getScheduler();
|
|
1269
|
+
const rootId = scheduler3.getJobRootId(id);
|
|
1270
|
+
if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
|
|
1271
|
+
},
|
|
1272
|
+
/**
|
|
1273
|
+
* Pause this job (set enabled=false).
|
|
1274
|
+
* Job remains registered but won't run.
|
|
1275
|
+
*/
|
|
1276
|
+
pause: () => {
|
|
1277
|
+
getScheduler().pauseJob(id);
|
|
1278
|
+
},
|
|
1279
|
+
/**
|
|
1280
|
+
* Resume this job (set enabled=true).
|
|
1281
|
+
*/
|
|
1282
|
+
resume: () => {
|
|
1283
|
+
getScheduler().resumeJob(id);
|
|
1284
|
+
},
|
|
1285
|
+
/**
|
|
1286
|
+
* Reactive paused state - automatically updates when pause/resume is called.
|
|
1287
|
+
* No need for forceUpdate() in your components.
|
|
1288
|
+
*/
|
|
1289
|
+
isPaused
|
|
1290
|
+
};
|
|
1291
|
+
}, [id, isPaused]);
|
|
1292
|
+
return controls;
|
|
1608
1293
|
}
|
|
1609
1294
|
|
|
1610
|
-
const
|
|
1611
|
-
function
|
|
1612
|
-
if (typeof
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
if (shownNotices.has(heading)) return;
|
|
1616
|
-
shownNotices.add(heading);
|
|
1617
|
-
const caller = getCallerFrame();
|
|
1618
|
-
if (caller) {
|
|
1619
|
-
console.log();
|
|
1620
|
-
}
|
|
1621
|
-
const boxStyle = "background: #ff9800; color: #1a1a1a; padding: 8px 12px; border-radius: 4px; font-weight: 500;";
|
|
1622
|
-
if (caller) {
|
|
1623
|
-
console.log(`%c\u26A0\uFE0F ${heading}`, boxStyle);
|
|
1624
|
-
}
|
|
1625
|
-
if (body || link) {
|
|
1626
|
-
let message = "";
|
|
1627
|
-
if (body) message += body;
|
|
1628
|
-
if (link) message += (body ? "\n\n" : "") + `More info: ${link}`;
|
|
1629
|
-
console.warn(`%c${message}`, "font-weight: bold;");
|
|
1630
|
-
}
|
|
1295
|
+
const IsObject = (url) => url === Object(url) && !Array.isArray(url) && typeof url !== "function";
|
|
1296
|
+
function getUrls(input) {
|
|
1297
|
+
if (typeof input === "string") return [input];
|
|
1298
|
+
if (Array.isArray(input)) return input;
|
|
1299
|
+
return Object.values(input);
|
|
1631
1300
|
}
|
|
1632
|
-
function
|
|
1633
|
-
|
|
1634
|
-
if (
|
|
1635
|
-
|
|
1636
|
-
const frame = lines[depth];
|
|
1637
|
-
if (!frame) return null;
|
|
1638
|
-
let match = frame.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?$/);
|
|
1639
|
-
if (!match) {
|
|
1640
|
-
match = frame.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
|
|
1641
|
-
}
|
|
1642
|
-
if (!match) return null;
|
|
1643
|
-
const [, fn, url, line] = match;
|
|
1644
|
-
return {
|
|
1645
|
-
functionName: fn ?? "<anonymous>",
|
|
1646
|
-
location: formatLocation(url, Number(line))
|
|
1647
|
-
};
|
|
1301
|
+
function inputSignature(input) {
|
|
1302
|
+
if (typeof input === "string") return input;
|
|
1303
|
+
if (Array.isArray(input)) return input.join("\0");
|
|
1304
|
+
return Object.keys(input).sort().map((key) => `${key}\0${input[key]}`).join("");
|
|
1648
1305
|
}
|
|
1649
|
-
function
|
|
1650
|
-
|
|
1651
|
-
const file = clean.split("/").pop() ?? clean;
|
|
1652
|
-
return `${file}:${line}`;
|
|
1306
|
+
function allUrlsCached(urls, textureCache) {
|
|
1307
|
+
return urls.every((url) => textureCache.has(url));
|
|
1653
1308
|
}
|
|
1654
|
-
function
|
|
1655
|
-
if (typeof
|
|
1656
|
-
return;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1309
|
+
function buildFromCache(input, textureCache) {
|
|
1310
|
+
if (typeof input === "string") {
|
|
1311
|
+
return textureCache.get(input);
|
|
1312
|
+
} else if (Array.isArray(input)) {
|
|
1313
|
+
return input.map((url) => textureCache.get(url));
|
|
1314
|
+
} else {
|
|
1315
|
+
const result = {};
|
|
1316
|
+
const objInput = input;
|
|
1317
|
+
for (const key in objInput) {
|
|
1318
|
+
result[key] = textureCache.get(objInput[key]);
|
|
1319
|
+
}
|
|
1320
|
+
return result;
|
|
1664
1321
|
}
|
|
1665
1322
|
}
|
|
1666
|
-
|
|
1667
|
-
const
|
|
1668
|
-
const
|
|
1669
|
-
function
|
|
1670
|
-
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
const
|
|
1676
|
-
const
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
const
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1323
|
+
function useTexture(input, optionsOrOnLoad) {
|
|
1324
|
+
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
1325
|
+
const store = useStore();
|
|
1326
|
+
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
1327
|
+
const { onLoad, cache = true } = options;
|
|
1328
|
+
const onLoadRef = useRef(onLoad);
|
|
1329
|
+
onLoadRef.current = onLoad;
|
|
1330
|
+
const onLoadCalledForRef = useRef(null);
|
|
1331
|
+
const inputKey = useMemo(() => inputSignature(input), [input]);
|
|
1332
|
+
const stableInput = useMemo(() => input, [inputKey]);
|
|
1333
|
+
const urls = useMemo(() => getUrls(stableInput), [stableInput]);
|
|
1334
|
+
const cachedResult = useMemo(() => {
|
|
1335
|
+
if (!cache) return null;
|
|
1336
|
+
const textures = store.getState().textures;
|
|
1337
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
1338
|
+
return buildFromCache(stableInput, textures);
|
|
1339
|
+
}, [cache, urls, stableInput, store]);
|
|
1340
|
+
const loadedTextures = useLoader(
|
|
1341
|
+
TextureLoader,
|
|
1342
|
+
IsObject(stableInput) ? Object.values(stableInput) : stableInput
|
|
1343
|
+
);
|
|
1344
|
+
useLayoutEffect(() => {
|
|
1345
|
+
if (cachedResult) return;
|
|
1346
|
+
if (onLoadCalledForRef.current === inputKey) return;
|
|
1347
|
+
onLoadCalledForRef.current = inputKey;
|
|
1348
|
+
onLoadRef.current?.(loadedTextures);
|
|
1349
|
+
}, [cachedResult, loadedTextures, inputKey]);
|
|
1350
|
+
useEffect(() => {
|
|
1351
|
+
if (cachedResult) return;
|
|
1352
|
+
if ("initTexture" in renderer) {
|
|
1353
|
+
let textureArray = [];
|
|
1354
|
+
if (Array.isArray(loadedTextures)) {
|
|
1355
|
+
textureArray = loadedTextures;
|
|
1356
|
+
} else if (loadedTextures instanceof Texture$1) {
|
|
1357
|
+
textureArray = [loadedTextures];
|
|
1358
|
+
} else if (IsObject(loadedTextures)) {
|
|
1359
|
+
textureArray = Object.values(loadedTextures);
|
|
1695
1360
|
}
|
|
1361
|
+
textureArray.forEach((texture) => {
|
|
1362
|
+
if (texture instanceof Texture$1) {
|
|
1363
|
+
renderer.initTexture(texture);
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1696
1366
|
}
|
|
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
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
onDropMissed: void 0,
|
|
1737
|
-
performance: {
|
|
1738
|
-
current: 1,
|
|
1739
|
-
min: 0.5,
|
|
1740
|
-
max: 1,
|
|
1741
|
-
debounce: 200,
|
|
1742
|
-
regress: () => {
|
|
1743
|
-
const state2 = get();
|
|
1744
|
-
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
1745
|
-
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
1746
|
-
performanceTimeout = setTimeout(
|
|
1747
|
-
() => setPerformanceCurrent(get().performance.max),
|
|
1748
|
-
state2.performance.debounce
|
|
1749
|
-
);
|
|
1367
|
+
}, [renderer, loadedTextures, cachedResult]);
|
|
1368
|
+
const mappedTextures = useMemo(() => {
|
|
1369
|
+
if (cachedResult) return cachedResult;
|
|
1370
|
+
if (IsObject(stableInput)) {
|
|
1371
|
+
const keyed = {};
|
|
1372
|
+
const textureArray = loadedTextures;
|
|
1373
|
+
let i = 0;
|
|
1374
|
+
for (const key in stableInput) keyed[key] = textureArray[i++];
|
|
1375
|
+
return keyed;
|
|
1376
|
+
} else {
|
|
1377
|
+
return loadedTextures;
|
|
1378
|
+
}
|
|
1379
|
+
}, [stableInput, loadedTextures, cachedResult]);
|
|
1380
|
+
useEffect(() => {
|
|
1381
|
+
if (!cache) return;
|
|
1382
|
+
const urlTextureMap = [];
|
|
1383
|
+
if (typeof stableInput === "string") {
|
|
1384
|
+
urlTextureMap.push([stableInput, mappedTextures]);
|
|
1385
|
+
} else if (Array.isArray(stableInput)) {
|
|
1386
|
+
const textureArray = mappedTextures;
|
|
1387
|
+
stableInput.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
1388
|
+
} else if (IsObject(stableInput)) {
|
|
1389
|
+
const textureRecord = mappedTextures;
|
|
1390
|
+
for (const key in stableInput) {
|
|
1391
|
+
const url = stableInput[key];
|
|
1392
|
+
urlTextureMap.push([url, textureRecord[key]]);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
store.setState((state) => {
|
|
1396
|
+
const refs = new Map(state._textureRefs);
|
|
1397
|
+
let textures = state.textures;
|
|
1398
|
+
let added = false;
|
|
1399
|
+
for (const [url, texture] of urlTextureMap) {
|
|
1400
|
+
if (!textures.has(url)) {
|
|
1401
|
+
if (!added) {
|
|
1402
|
+
textures = new Map(textures);
|
|
1403
|
+
added = true;
|
|
1404
|
+
}
|
|
1405
|
+
textures.set(url, texture);
|
|
1750
1406
|
}
|
|
1407
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
1408
|
+
}
|
|
1409
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
1410
|
+
});
|
|
1411
|
+
return () => store.setState((state) => {
|
|
1412
|
+
const refs = new Map(state._textureRefs);
|
|
1413
|
+
for (const [url] of urlTextureMap) {
|
|
1414
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
1415
|
+
if (next <= 0) refs.delete(url);
|
|
1416
|
+
else refs.set(url, next);
|
|
1417
|
+
}
|
|
1418
|
+
return { _textureRefs: refs };
|
|
1419
|
+
});
|
|
1420
|
+
}, [cache, stableInput, mappedTextures, store]);
|
|
1421
|
+
return mappedTextures;
|
|
1422
|
+
}
|
|
1423
|
+
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
1424
|
+
useTexture.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
1425
|
+
const Texture = ({
|
|
1426
|
+
children,
|
|
1427
|
+
input,
|
|
1428
|
+
onLoad,
|
|
1429
|
+
cache
|
|
1430
|
+
}) => {
|
|
1431
|
+
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
1432
|
+
const ret = useTexture(input, options);
|
|
1433
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
function useTextures(selector) {
|
|
1437
|
+
const store = useStore();
|
|
1438
|
+
const registry = useMemo(() => {
|
|
1439
|
+
const getState = store.getState;
|
|
1440
|
+
const setState = store.setState;
|
|
1441
|
+
const getOne = (key) => getState().textures.get(key);
|
|
1442
|
+
return {
|
|
1443
|
+
get all() {
|
|
1444
|
+
return getState().textures;
|
|
1751
1445
|
},
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
top: 0,
|
|
1759
|
-
left: 0,
|
|
1760
|
-
aspect: 0,
|
|
1761
|
-
distance: 0,
|
|
1762
|
-
factor: 0,
|
|
1763
|
-
getCurrentViewport
|
|
1446
|
+
get(input) {
|
|
1447
|
+
if (typeof input === "string") return getOne(input);
|
|
1448
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
1449
|
+
const out = {};
|
|
1450
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
1451
|
+
return out;
|
|
1764
1452
|
},
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
const currentSize = state2.size;
|
|
1774
|
-
const newSize = {
|
|
1775
|
-
width: propW ?? currentSize.width,
|
|
1776
|
-
height: propH ?? currentSize.height,
|
|
1777
|
-
top: currentSize.top,
|
|
1778
|
-
left: currentSize.left
|
|
1779
|
-
};
|
|
1780
|
-
set((s) => ({
|
|
1781
|
-
size: newSize,
|
|
1782
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1783
|
-
}));
|
|
1784
|
-
getScheduler().invalidate();
|
|
1785
|
-
}
|
|
1453
|
+
has: (key) => getState().textures.has(key),
|
|
1454
|
+
add(keyOrRecord, texture) {
|
|
1455
|
+
setState((state) => {
|
|
1456
|
+
const textures = new Map(state.textures);
|
|
1457
|
+
if (typeof keyOrRecord === "string") {
|
|
1458
|
+
textures.set(keyOrRecord, texture);
|
|
1459
|
+
} else {
|
|
1460
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
1786
1461
|
}
|
|
1787
|
-
return;
|
|
1788
|
-
}
|
|
1789
|
-
const w = width;
|
|
1790
|
-
const h = height ?? width;
|
|
1791
|
-
const t = top ?? state2.size.top;
|
|
1792
|
-
const l = left ?? state2.size.left;
|
|
1793
|
-
const size = { width: w, height: h, top: t, left: l };
|
|
1794
|
-
set((s) => ({
|
|
1795
|
-
size,
|
|
1796
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1797
|
-
_sizeImperative: true
|
|
1798
|
-
}));
|
|
1799
|
-
getScheduler().invalidate();
|
|
1800
|
-
},
|
|
1801
|
-
setDpr: (dpr) => set((state2) => {
|
|
1802
|
-
const resolved = calculateDpr(dpr);
|
|
1803
|
-
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
1804
|
-
}),
|
|
1805
|
-
setFrameloop: (frameloop = "always") => {
|
|
1806
|
-
set(() => ({ frameloop }));
|
|
1807
|
-
getScheduler().frameloop = frameloop;
|
|
1462
|
+
return { textures };
|
|
1463
|
+
});
|
|
1808
1464
|
},
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1818
|
-
renderPipeline: null,
|
|
1819
|
-
passes: {},
|
|
1820
|
-
_hmrVersion: 0,
|
|
1821
|
-
_sizeImperative: false,
|
|
1822
|
-
_sizeProps: null,
|
|
1823
|
-
previousRoot: void 0,
|
|
1824
|
-
internal: {
|
|
1825
|
-
// Events
|
|
1826
|
-
interaction: [],
|
|
1827
|
-
subscribers: [],
|
|
1828
|
-
// Per-pointer state (new unified structure)
|
|
1829
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
1830
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1831
|
-
lastEvent: React.createRef(),
|
|
1832
|
-
// Deprecated but kept for backwards compatibility
|
|
1833
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1834
|
-
initialClick: [0, 0],
|
|
1835
|
-
initialHits: [],
|
|
1836
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
1837
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1838
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1839
|
-
// Occlusion system (WebGPU only)
|
|
1840
|
-
occlusionEnabled: false,
|
|
1841
|
-
occlusionObserver: null,
|
|
1842
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1843
|
-
helperGroup: null,
|
|
1844
|
-
// Updates
|
|
1845
|
-
active: false,
|
|
1846
|
-
frames: 0,
|
|
1847
|
-
priority: 0,
|
|
1848
|
-
subscribe: (ref, priority, store) => {
|
|
1849
|
-
const internal = get().internal;
|
|
1850
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1851
|
-
internal.subscribers.push({ ref, priority, store });
|
|
1852
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1853
|
-
return () => {
|
|
1854
|
-
const internal2 = get().internal;
|
|
1855
|
-
if (internal2?.subscribers) {
|
|
1856
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1857
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1858
|
-
}
|
|
1859
|
-
};
|
|
1860
|
-
},
|
|
1861
|
-
// Renderer Storage (single source of truth)
|
|
1862
|
-
actualRenderer: null,
|
|
1863
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1864
|
-
scheduler: null
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
return rootState;
|
|
1868
|
-
});
|
|
1869
|
-
const state = rootStore.getState();
|
|
1870
|
-
Object.defineProperty(state, "gl", {
|
|
1871
|
-
get() {
|
|
1872
|
-
const currentState = rootStore.getState();
|
|
1873
|
-
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1874
|
-
const stack = new Error().stack || "";
|
|
1875
|
-
if (!isInternalRendererAccess(stack)) {
|
|
1876
|
-
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1877
|
-
notifyDepreciated({
|
|
1878
|
-
heading: "Accessing state.gl in WebGPU mode",
|
|
1879
|
-
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
|
|
1880
|
-
});
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
return currentState.internal.actualRenderer;
|
|
1884
|
-
},
|
|
1885
|
-
set(value) {
|
|
1886
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1887
|
-
},
|
|
1888
|
-
enumerable: true,
|
|
1889
|
-
configurable: true
|
|
1890
|
-
});
|
|
1891
|
-
Object.defineProperty(state, "renderer", {
|
|
1892
|
-
get() {
|
|
1893
|
-
return rootStore.getState().internal.actualRenderer;
|
|
1894
|
-
},
|
|
1895
|
-
set(value) {
|
|
1896
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1897
|
-
},
|
|
1898
|
-
enumerable: true,
|
|
1899
|
-
configurable: true
|
|
1900
|
-
});
|
|
1901
|
-
let oldScene = state.scene;
|
|
1902
|
-
rootStore.subscribe(() => {
|
|
1903
|
-
const currentState = rootStore.getState();
|
|
1904
|
-
const { scene, rootScene, set } = currentState;
|
|
1905
|
-
if (scene !== oldScene) {
|
|
1906
|
-
oldScene = scene;
|
|
1907
|
-
if (scene?.isScene && scene !== rootScene) {
|
|
1908
|
-
set({ rootScene: scene });
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
});
|
|
1912
|
-
let oldSize = state.size;
|
|
1913
|
-
let oldDpr = state.viewport.dpr;
|
|
1914
|
-
let oldCamera = state.camera;
|
|
1915
|
-
rootStore.subscribe(() => {
|
|
1916
|
-
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1917
|
-
const actualRenderer = internal.actualRenderer;
|
|
1918
|
-
const canvasTarget = internal.canvasTarget;
|
|
1919
|
-
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1920
|
-
oldSize = size;
|
|
1921
|
-
oldDpr = viewport.dpr;
|
|
1922
|
-
updateCamera(camera, size);
|
|
1923
|
-
if (internal.isSecondary && canvasTarget) {
|
|
1924
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1925
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1926
|
-
} else {
|
|
1927
|
-
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1928
|
-
actualRenderer.setSize(size.width, size.height, false);
|
|
1929
|
-
if (canvasTarget) {
|
|
1930
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1931
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1465
|
+
dispose(key, options) {
|
|
1466
|
+
const state = getState();
|
|
1467
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
1468
|
+
if (refs > 0 && !options?.force) {
|
|
1469
|
+
console.warn(
|
|
1470
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
1471
|
+
);
|
|
1472
|
+
return false;
|
|
1932
1473
|
}
|
|
1474
|
+
state.textures.get(key)?.dispose();
|
|
1475
|
+
setState((s) => {
|
|
1476
|
+
const textures = new Map(s.textures);
|
|
1477
|
+
textures.delete(key);
|
|
1478
|
+
const nextRefs = new Map(s._textureRefs);
|
|
1479
|
+
nextRefs.delete(key);
|
|
1480
|
+
return { textures, _textureRefs: nextRefs };
|
|
1481
|
+
});
|
|
1482
|
+
return true;
|
|
1483
|
+
},
|
|
1484
|
+
disposeAll() {
|
|
1485
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
1486
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
1933
1487
|
}
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
}
|
|
1941
|
-
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1942
|
-
const currentState = rootStore.getState();
|
|
1943
|
-
if (currentState.autoUpdateFrustum && camera) {
|
|
1944
|
-
updateFrustum(camera, currentState.frustum);
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
rootStore.subscribe((state2) => invalidate(state2));
|
|
1949
|
-
return rootStore;
|
|
1950
|
-
};
|
|
1488
|
+
};
|
|
1489
|
+
}, [store]);
|
|
1490
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
1491
|
+
const selected = useThree(subscribe);
|
|
1492
|
+
return selector ? selected : registry;
|
|
1493
|
+
}
|
|
1951
1494
|
|
|
1952
|
-
|
|
1953
|
-
const
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1495
|
+
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
1496
|
+
const isLegacy = useThree((s) => s.isLegacy);
|
|
1497
|
+
const size = useThree((s) => s.size);
|
|
1498
|
+
let width;
|
|
1499
|
+
let height;
|
|
1500
|
+
let opts;
|
|
1501
|
+
if (typeof widthOrOptions === "object") {
|
|
1502
|
+
opts = widthOrOptions;
|
|
1503
|
+
} else if (typeof widthOrOptions === "number") {
|
|
1504
|
+
width = widthOrOptions;
|
|
1505
|
+
if (typeof heightOrOptions === "object") {
|
|
1506
|
+
height = widthOrOptions;
|
|
1507
|
+
opts = heightOrOptions;
|
|
1508
|
+
} else if (typeof heightOrOptions === "number") {
|
|
1509
|
+
height = heightOrOptions;
|
|
1510
|
+
opts = options;
|
|
1511
|
+
} else {
|
|
1512
|
+
height = widthOrOptions;
|
|
1960
1513
|
}
|
|
1961
|
-
return loader;
|
|
1962
1514
|
}
|
|
1963
|
-
return
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
if (extensions) extensions(loader);
|
|
1969
|
-
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1970
|
-
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1971
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1972
|
-
return data;
|
|
1973
|
-
});
|
|
1974
|
-
}
|
|
1975
|
-
return new Promise(
|
|
1976
|
-
(res, reject) => loader.load(
|
|
1977
|
-
input,
|
|
1978
|
-
(data) => {
|
|
1979
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1980
|
-
res(data);
|
|
1981
|
-
},
|
|
1982
|
-
onProgress,
|
|
1983
|
-
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1984
|
-
)
|
|
1985
|
-
);
|
|
1986
|
-
};
|
|
1987
|
-
}
|
|
1988
|
-
function useLoader(loader, input, extensions, onProgress, cacheKey) {
|
|
1989
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
1990
|
-
const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
|
|
1991
|
-
const fn = loadingFn(extensions, onProgress);
|
|
1992
|
-
const results = cacheKeys.map(
|
|
1993
|
-
(key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
|
|
1994
|
-
);
|
|
1995
|
-
return Array.isArray(input) ? results : results[0];
|
|
1515
|
+
return useMemo(() => {
|
|
1516
|
+
const w = width ?? size.width;
|
|
1517
|
+
const h = height ?? size.height;
|
|
1518
|
+
return new WebGLRenderTarget(w, h, opts);
|
|
1519
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
1996
1520
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
1521
|
+
|
|
1522
|
+
const presetsObj = {
|
|
1523
|
+
apartment: "lebombo_1k.hdr",
|
|
1524
|
+
city: "potsdamer_platz_1k.hdr",
|
|
1525
|
+
dawn: "kiara_1_dawn_1k.hdr",
|
|
1526
|
+
forest: "forest_slope_1k.hdr",
|
|
1527
|
+
lobby: "st_fagans_interior_1k.hdr",
|
|
1528
|
+
night: "dikhololo_night_1k.hdr",
|
|
1529
|
+
park: "rooitou_park_1k.hdr",
|
|
1530
|
+
studio: "studio_small_03_1k.hdr",
|
|
1531
|
+
sunset: "venice_sunset_1k.hdr",
|
|
1532
|
+
warehouse: "empty_warehouse_01_1k.hdr"
|
|
2007
1533
|
};
|
|
2008
|
-
useLoader.loader = getLoader;
|
|
2009
1534
|
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
const
|
|
2028
|
-
|
|
2029
|
-
const
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
}
|
|
2044
|
-
notifyDepreciated({
|
|
2045
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
2046
|
-
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 })',
|
|
2047
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2048
|
-
});
|
|
1535
|
+
const CUBEMAP_ROOT = "https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/";
|
|
1536
|
+
const isArray = (arr) => Array.isArray(arr);
|
|
1537
|
+
const defaultFiles = ["/px.png", "/nx.png", "/py.png", "/ny.png", "/pz.png", "/nz.png"];
|
|
1538
|
+
function useEnvironment({
|
|
1539
|
+
files = defaultFiles,
|
|
1540
|
+
path = "",
|
|
1541
|
+
preset = void 0,
|
|
1542
|
+
colorSpace = void 0,
|
|
1543
|
+
extensions
|
|
1544
|
+
} = {}) {
|
|
1545
|
+
if (preset) {
|
|
1546
|
+
validatePreset(preset);
|
|
1547
|
+
files = presetsObj[preset];
|
|
1548
|
+
path = CUBEMAP_ROOT;
|
|
1549
|
+
}
|
|
1550
|
+
const multiFile = isArray(files);
|
|
1551
|
+
const { extension, isCubemap } = getExtension(files);
|
|
1552
|
+
const loader = getLoader(extension);
|
|
1553
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1554
|
+
const renderer = useThree((state) => state.renderer);
|
|
1555
|
+
useLayoutEffect(() => {
|
|
1556
|
+
if (extension !== "webp" && extension !== "jpg" && extension !== "jpeg") return;
|
|
1557
|
+
function clearGainmapTexture() {
|
|
1558
|
+
useLoader.clear(loader, multiFile ? [files] : files);
|
|
1559
|
+
}
|
|
1560
|
+
renderer.domElement.addEventListener("webglcontextlost", clearGainmapTexture, { once: true });
|
|
1561
|
+
}, [extension, files, loader, multiFile, renderer.domElement]);
|
|
1562
|
+
const loaderResult = useLoader(
|
|
1563
|
+
loader,
|
|
1564
|
+
multiFile ? [files] : files,
|
|
1565
|
+
(loader2) => {
|
|
1566
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1567
|
+
loader2.setRenderer?.(renderer);
|
|
2049
1568
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
const mergedState = {
|
|
2053
|
-
...localState,
|
|
2054
|
-
time: frameState.time,
|
|
2055
|
-
delta: frameState.delta,
|
|
2056
|
-
elapsed: frameState.elapsed,
|
|
2057
|
-
frame: frameState.frame
|
|
2058
|
-
};
|
|
2059
|
-
callbackRef.current?.(mergedState, delta);
|
|
2060
|
-
};
|
|
2061
|
-
const unregister = scheduler.register(wrappedCallback, {
|
|
2062
|
-
id,
|
|
2063
|
-
rootId,
|
|
2064
|
-
...options
|
|
2065
|
-
});
|
|
2066
|
-
return () => {
|
|
2067
|
-
unregister();
|
|
2068
|
-
if (isLegacyPriority) {
|
|
2069
|
-
const currentState = store.getState();
|
|
2070
|
-
if (currentState.internal) {
|
|
2071
|
-
currentState.internal.priority--;
|
|
2072
|
-
let parentRoot = currentState.previousRoot;
|
|
2073
|
-
while (parentRoot) {
|
|
2074
|
-
const parentState = parentRoot.getState();
|
|
2075
|
-
if (parentState?.internal) parentState.internal.priority--;
|
|
2076
|
-
parentRoot = parentState?.previousRoot;
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
};
|
|
2081
|
-
} else {
|
|
2082
|
-
return scheduler.register(
|
|
2083
|
-
(state, delta) => {
|
|
2084
|
-
const frameState = state;
|
|
2085
|
-
if (!frameState.renderer) return;
|
|
2086
|
-
callbackRef.current?.(frameState, delta);
|
|
2087
|
-
},
|
|
2088
|
-
{ id, ...options }
|
|
2089
|
-
);
|
|
1569
|
+
loader2.setPath?.(path);
|
|
1570
|
+
if (extensions) extensions(loader2);
|
|
2090
1571
|
}
|
|
2091
|
-
}, [store, scheduler, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2092
|
-
const isPaused = React.useSyncExternalStore(
|
|
2093
|
-
// Subscribe function
|
|
2094
|
-
React.useCallback(
|
|
2095
|
-
(onStoreChange) => {
|
|
2096
|
-
return getScheduler().subscribeJobState(id, onStoreChange);
|
|
2097
|
-
},
|
|
2098
|
-
[id]
|
|
2099
|
-
),
|
|
2100
|
-
// getSnapshot function
|
|
2101
|
-
React.useCallback(() => getScheduler().isJobPaused(id), [id]),
|
|
2102
|
-
// getServerSnapshot function (SSR)
|
|
2103
|
-
React.useCallback(() => false, [])
|
|
2104
1572
|
);
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
1573
|
+
let texture = multiFile ? (
|
|
1574
|
+
// @ts-ignore
|
|
1575
|
+
loaderResult[0]
|
|
1576
|
+
) : loaderResult;
|
|
1577
|
+
if (extension === "jpg" || extension === "jpeg" || extension === "webp") {
|
|
1578
|
+
texture = texture.renderTarget?.texture;
|
|
1579
|
+
}
|
|
1580
|
+
texture.mapping = isCubemap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
1581
|
+
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
1582
|
+
return texture;
|
|
1583
|
+
}
|
|
1584
|
+
const preloadDefaultOptions = {
|
|
1585
|
+
files: defaultFiles,
|
|
1586
|
+
path: "",
|
|
1587
|
+
preset: void 0,
|
|
1588
|
+
extensions: void 0
|
|
1589
|
+
};
|
|
1590
|
+
useEnvironment.preload = (preloadOptions) => {
|
|
1591
|
+
const options = { ...preloadDefaultOptions, ...preloadOptions };
|
|
1592
|
+
let { files, path = "" } = options;
|
|
1593
|
+
const { preset, extensions } = options;
|
|
1594
|
+
if (preset) {
|
|
1595
|
+
validatePreset(preset);
|
|
1596
|
+
files = presetsObj[preset];
|
|
1597
|
+
path = CUBEMAP_ROOT;
|
|
1598
|
+
}
|
|
1599
|
+
const { extension } = getExtension(files);
|
|
1600
|
+
if (extension === "webp" || extension === "jpg" || extension === "jpeg") {
|
|
1601
|
+
throw new Error("useEnvironment: Preloading gainmaps is not supported");
|
|
1602
|
+
}
|
|
1603
|
+
const loader = getLoader(extension);
|
|
1604
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1605
|
+
useLoader.preload(loader, isArray(files) ? [files] : files, (loader2) => {
|
|
1606
|
+
loader2.setPath?.(path);
|
|
1607
|
+
if (extensions) extensions(loader2);
|
|
1608
|
+
});
|
|
1609
|
+
};
|
|
1610
|
+
const clearDefaultOptins = {
|
|
1611
|
+
files: defaultFiles,
|
|
1612
|
+
preset: void 0
|
|
1613
|
+
};
|
|
1614
|
+
useEnvironment.clear = (clearOptions) => {
|
|
1615
|
+
const options = { ...clearDefaultOptins, ...clearOptions };
|
|
1616
|
+
let { files } = options;
|
|
1617
|
+
const { preset } = options;
|
|
1618
|
+
if (preset) {
|
|
1619
|
+
validatePreset(preset);
|
|
1620
|
+
files = presetsObj[preset];
|
|
1621
|
+
}
|
|
1622
|
+
const { extension } = getExtension(files);
|
|
1623
|
+
const loader = getLoader(extension);
|
|
1624
|
+
if (!loader) throw new Error("useEnvironment: Unrecognized file extension: " + files);
|
|
1625
|
+
useLoader.clear(loader, isArray(files) ? [files] : files);
|
|
1626
|
+
};
|
|
1627
|
+
function validatePreset(preset) {
|
|
1628
|
+
if (!(preset in presetsObj)) throw new Error("Preset must be one of: " + Object.keys(presetsObj).join(", "));
|
|
1629
|
+
}
|
|
1630
|
+
function getExtension(files) {
|
|
1631
|
+
const isCubemap = isArray(files) && files.length === 6;
|
|
1632
|
+
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
1633
|
+
const firstEntry = isArray(files) ? files[0] : files;
|
|
1634
|
+
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();
|
|
1635
|
+
return { extension, isCubemap, isGainmap };
|
|
1636
|
+
}
|
|
1637
|
+
function getLoader(extension) {
|
|
1638
|
+
const loader = extension === "cube" ? CubeTextureLoader : extension === "hdr" ? HDRLoader : extension === "exr" ? EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader : extension === "webp" ? GainMapLoader : null;
|
|
1639
|
+
return loader;
|
|
2152
1640
|
}
|
|
2153
1641
|
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
if (
|
|
2157
|
-
|
|
2158
|
-
return Object.values(input);
|
|
1642
|
+
function useStore() {
|
|
1643
|
+
const store = useContext(context);
|
|
1644
|
+
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
1645
|
+
return store;
|
|
2159
1646
|
}
|
|
2160
|
-
function
|
|
2161
|
-
return
|
|
1647
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
1648
|
+
return useStore()(selector, equalityFn);
|
|
2162
1649
|
}
|
|
2163
|
-
function
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
return input.map((url) => textureCache.get(url));
|
|
2168
|
-
} else {
|
|
2169
|
-
const result = {};
|
|
2170
|
-
const objInput = input;
|
|
2171
|
-
for (const key in objInput) {
|
|
2172
|
-
result[key] = textureCache.get(objInput[key]);
|
|
2173
|
-
}
|
|
2174
|
-
return result;
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
function useTexture(input, optionsOrOnLoad) {
|
|
2178
|
-
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2179
|
-
const store = useStore();
|
|
2180
|
-
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2181
|
-
const { onLoad, cache = true } = options;
|
|
2182
|
-
const onLoadRef = useRef(onLoad);
|
|
2183
|
-
onLoadRef.current = onLoad;
|
|
2184
|
-
const onLoadCalledForRef = useRef(null);
|
|
2185
|
-
const urls = useMemo(() => getUrls(input), [input]);
|
|
2186
|
-
const cachedResult = useMemo(() => {
|
|
2187
|
-
if (!cache) return null;
|
|
2188
|
-
const textures = store.getState().textures;
|
|
2189
|
-
if (!allUrlsCached(urls, textures)) return null;
|
|
2190
|
-
return buildFromCache(input, textures);
|
|
2191
|
-
}, [cache, urls, input, store]);
|
|
2192
|
-
const loadedTextures = useLoader(
|
|
2193
|
-
TextureLoader,
|
|
2194
|
-
IsObject(input) ? Object.values(input) : input
|
|
2195
|
-
);
|
|
2196
|
-
const inputKey = urls.join("\0");
|
|
2197
|
-
useLayoutEffect(() => {
|
|
2198
|
-
if (cachedResult) return;
|
|
2199
|
-
if (onLoadCalledForRef.current === inputKey) return;
|
|
2200
|
-
onLoadCalledForRef.current = inputKey;
|
|
2201
|
-
onLoadRef.current?.(loadedTextures);
|
|
2202
|
-
}, [cachedResult, loadedTextures, inputKey]);
|
|
2203
|
-
useEffect(() => {
|
|
2204
|
-
if (cachedResult) return;
|
|
2205
|
-
if ("initTexture" in renderer) {
|
|
2206
|
-
let textureArray = [];
|
|
2207
|
-
if (Array.isArray(loadedTextures)) {
|
|
2208
|
-
textureArray = loadedTextures;
|
|
2209
|
-
} else if (loadedTextures instanceof Texture$1) {
|
|
2210
|
-
textureArray = [loadedTextures];
|
|
2211
|
-
} else if (IsObject(loadedTextures)) {
|
|
2212
|
-
textureArray = Object.values(loadedTextures);
|
|
2213
|
-
}
|
|
2214
|
-
textureArray.forEach((texture) => {
|
|
2215
|
-
if (texture instanceof Texture$1) {
|
|
2216
|
-
renderer.initTexture(texture);
|
|
2217
|
-
}
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
}, [renderer, loadedTextures, cachedResult]);
|
|
2221
|
-
const mappedTextures = useMemo(() => {
|
|
2222
|
-
if (cachedResult) return cachedResult;
|
|
2223
|
-
if (IsObject(input)) {
|
|
2224
|
-
const keyed = {};
|
|
2225
|
-
const textureArray = loadedTextures;
|
|
2226
|
-
let i = 0;
|
|
2227
|
-
for (const key in input) keyed[key] = textureArray[i++];
|
|
2228
|
-
return keyed;
|
|
2229
|
-
} else {
|
|
2230
|
-
return loadedTextures;
|
|
2231
|
-
}
|
|
2232
|
-
}, [input, loadedTextures, cachedResult]);
|
|
2233
|
-
useEffect(() => {
|
|
2234
|
-
if (!cache) return;
|
|
2235
|
-
const urlTextureMap = [];
|
|
2236
|
-
if (typeof input === "string") {
|
|
2237
|
-
urlTextureMap.push([input, mappedTextures]);
|
|
2238
|
-
} else if (Array.isArray(input)) {
|
|
2239
|
-
const textureArray = mappedTextures;
|
|
2240
|
-
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
2241
|
-
} else if (IsObject(input)) {
|
|
2242
|
-
const textureRecord = mappedTextures;
|
|
2243
|
-
for (const key in input) {
|
|
2244
|
-
const url = input[key];
|
|
2245
|
-
urlTextureMap.push([url, textureRecord[key]]);
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
store.setState((state) => {
|
|
2249
|
-
const refs = new Map(state._textureRefs);
|
|
2250
|
-
let textures = state.textures;
|
|
2251
|
-
let added = false;
|
|
2252
|
-
for (const [url, texture] of urlTextureMap) {
|
|
2253
|
-
if (!textures.has(url)) {
|
|
2254
|
-
if (!added) {
|
|
2255
|
-
textures = new Map(textures);
|
|
2256
|
-
added = true;
|
|
2257
|
-
}
|
|
2258
|
-
textures.set(url, texture);
|
|
2259
|
-
}
|
|
2260
|
-
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2261
|
-
}
|
|
2262
|
-
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2263
|
-
});
|
|
2264
|
-
return () => store.setState((state) => {
|
|
2265
|
-
const refs = new Map(state._textureRefs);
|
|
2266
|
-
for (const [url] of urlTextureMap) {
|
|
2267
|
-
const next = (refs.get(url) ?? 0) - 1;
|
|
2268
|
-
if (next <= 0) refs.delete(url);
|
|
2269
|
-
else refs.set(url, next);
|
|
2270
|
-
}
|
|
2271
|
-
return { _textureRefs: refs };
|
|
2272
|
-
});
|
|
2273
|
-
}, [cache, input, mappedTextures, store]);
|
|
2274
|
-
return mappedTextures;
|
|
2275
|
-
}
|
|
2276
|
-
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
2277
|
-
useTexture.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
2278
|
-
const Texture = ({
|
|
2279
|
-
children,
|
|
2280
|
-
input,
|
|
2281
|
-
onLoad,
|
|
2282
|
-
cache
|
|
2283
|
-
}) => {
|
|
2284
|
-
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
2285
|
-
const ret = useTexture(input, options);
|
|
2286
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
2287
|
-
};
|
|
2288
|
-
|
|
2289
|
-
function useTextures(selector) {
|
|
2290
|
-
const store = useStore();
|
|
2291
|
-
const registry = useMemo(() => {
|
|
2292
|
-
const getState = store.getState;
|
|
2293
|
-
const setState = store.setState;
|
|
2294
|
-
const getOne = (key) => getState().textures.get(key);
|
|
2295
|
-
return {
|
|
2296
|
-
get all() {
|
|
2297
|
-
return getState().textures;
|
|
2298
|
-
},
|
|
2299
|
-
get(input) {
|
|
2300
|
-
if (typeof input === "string") return getOne(input);
|
|
2301
|
-
if (Array.isArray(input)) return input.map(getOne);
|
|
2302
|
-
const out = {};
|
|
2303
|
-
for (const name in input) out[name] = getOne(input[name]);
|
|
2304
|
-
return out;
|
|
2305
|
-
},
|
|
2306
|
-
has: (key) => getState().textures.has(key),
|
|
2307
|
-
add(keyOrRecord, texture) {
|
|
2308
|
-
setState((state) => {
|
|
2309
|
-
const textures = new Map(state.textures);
|
|
2310
|
-
if (typeof keyOrRecord === "string") {
|
|
2311
|
-
textures.set(keyOrRecord, texture);
|
|
2312
|
-
} else {
|
|
2313
|
-
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2314
|
-
}
|
|
2315
|
-
return { textures };
|
|
2316
|
-
});
|
|
2317
|
-
},
|
|
2318
|
-
dispose(key, options) {
|
|
2319
|
-
const state = getState();
|
|
2320
|
-
const refs = state._textureRefs.get(key) ?? 0;
|
|
2321
|
-
if (refs > 0 && !options?.force) {
|
|
2322
|
-
console.warn(
|
|
2323
|
-
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2324
|
-
);
|
|
2325
|
-
return false;
|
|
2326
|
-
}
|
|
2327
|
-
state.textures.get(key)?.dispose();
|
|
2328
|
-
setState((s) => {
|
|
2329
|
-
const textures = new Map(s.textures);
|
|
2330
|
-
textures.delete(key);
|
|
2331
|
-
const nextRefs = new Map(s._textureRefs);
|
|
2332
|
-
nextRefs.delete(key);
|
|
2333
|
-
return { textures, _textureRefs: nextRefs };
|
|
2334
|
-
});
|
|
2335
|
-
return true;
|
|
2336
|
-
},
|
|
2337
|
-
disposeAll() {
|
|
2338
|
-
for (const texture of getState().textures.values()) texture.dispose();
|
|
2339
|
-
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2340
|
-
}
|
|
2341
|
-
};
|
|
2342
|
-
}, [store]);
|
|
2343
|
-
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2344
|
-
const selected = useThree(subscribe);
|
|
2345
|
-
return selector ? selected : registry;
|
|
2346
|
-
}
|
|
2347
|
-
|
|
2348
|
-
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2349
|
-
const isLegacy = useThree((s) => s.isLegacy);
|
|
2350
|
-
const size = useThree((s) => s.size);
|
|
2351
|
-
let width;
|
|
2352
|
-
let height;
|
|
2353
|
-
let opts;
|
|
2354
|
-
if (typeof widthOrOptions === "object") {
|
|
2355
|
-
opts = widthOrOptions;
|
|
2356
|
-
} else if (typeof widthOrOptions === "number") {
|
|
2357
|
-
width = widthOrOptions;
|
|
2358
|
-
if (typeof heightOrOptions === "object") {
|
|
2359
|
-
height = widthOrOptions;
|
|
2360
|
-
opts = heightOrOptions;
|
|
2361
|
-
} else if (typeof heightOrOptions === "number") {
|
|
2362
|
-
height = heightOrOptions;
|
|
2363
|
-
opts = options;
|
|
2364
|
-
} else {
|
|
2365
|
-
height = widthOrOptions;
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
return useMemo(() => {
|
|
2369
|
-
const w = width ?? size.width;
|
|
2370
|
-
const h = height ?? size.height;
|
|
2371
|
-
return new WebGLRenderTarget(w, h, opts);
|
|
2372
|
-
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
function useStore() {
|
|
2376
|
-
const store = useContext(context);
|
|
2377
|
-
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
2378
|
-
return store;
|
|
2379
|
-
}
|
|
2380
|
-
function useThree(selector = (state) => state, equalityFn) {
|
|
2381
|
-
return useStore()(selector, equalityFn);
|
|
2382
|
-
}
|
|
2383
|
-
function useInstanceHandle(ref) {
|
|
2384
|
-
const instance = useRef(null);
|
|
2385
|
-
useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
2386
|
-
return instance;
|
|
1650
|
+
function useInstanceHandle(ref) {
|
|
1651
|
+
const instance = useRef(null);
|
|
1652
|
+
useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
1653
|
+
return instance;
|
|
2387
1654
|
}
|
|
2388
1655
|
function useGraph(object) {
|
|
2389
1656
|
return useMemo(() => buildGraph(object), [object]);
|
|
2390
1657
|
}
|
|
2391
1658
|
|
|
1659
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
1660
|
+
|
|
2392
1661
|
let effectId = 0;
|
|
2393
1662
|
function addEffect(callback) {
|
|
2394
1663
|
notifyDepreciated({
|
|
@@ -2417,13 +1686,19 @@ function addTail(callback) {
|
|
|
2417
1686
|
return getScheduler().onIdle(callback);
|
|
2418
1687
|
}
|
|
2419
1688
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
2420
|
-
|
|
1689
|
+
const rootId = state?.internal?.rootId;
|
|
1690
|
+
const scheduler = getScheduler();
|
|
1691
|
+
if (rootId) scheduler.invalidateRoot(rootId, frames, stackFrames);
|
|
1692
|
+
else scheduler.invalidate(frames, stackFrames);
|
|
2421
1693
|
}
|
|
2422
|
-
function advance(timestamp) {
|
|
2423
|
-
|
|
1694
|
+
function advance(timestamp, runGlobalEffects, state) {
|
|
1695
|
+
const rootId = state?.internal?.rootId;
|
|
1696
|
+
const scheduler = getScheduler();
|
|
1697
|
+
if (rootId) scheduler.stepRoot(rootId, timestamp);
|
|
1698
|
+
else scheduler.step(timestamp);
|
|
2424
1699
|
}
|
|
2425
1700
|
|
|
2426
|
-
const version = "10.0.0-alpha.
|
|
1701
|
+
const version = "10.0.0-alpha.4";
|
|
2427
1702
|
const packageData = {
|
|
2428
1703
|
version: version};
|
|
2429
1704
|
|
|
@@ -13480,206 +12755,789 @@ Check the top-level render call using <` + i + ">.");
|
|
|
13480
12755
|
var o = 1 << 31 - vn(n);
|
|
13481
12756
|
e.entanglements[1] |= o, n &= ~o;
|
|
13482
12757
|
}
|
|
13483
|
-
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12758
|
+
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12759
|
+
}
|
|
12760
|
+
}
|
|
12761
|
+
break;
|
|
12762
|
+
case 31:
|
|
12763
|
+
case 13:
|
|
12764
|
+
n = On(e, 2), n !== null && We(n, e, 2), Ls(), rl(e, 2);
|
|
12765
|
+
}
|
|
12766
|
+
}, le.batchedUpdates = function(e, n) {
|
|
12767
|
+
return e(n);
|
|
12768
|
+
}, le.createComponentSelector = function(e) {
|
|
12769
|
+
return { $$typeof: pm, value: e };
|
|
12770
|
+
}, le.createContainer = function(e, n, o, i, s, u, f, p, g, S) {
|
|
12771
|
+
return Ka(e, n, false, null, o, i, u, null, f, p, g, S);
|
|
12772
|
+
}, le.createHasPseudoClassSelector = function(e) {
|
|
12773
|
+
return { $$typeof: hm, value: e };
|
|
12774
|
+
}, le.createHydrationContainer = function(e, n, o, i, s, u, f, p, g, S, T, _, I, O) {
|
|
12775
|
+
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;
|
|
12776
|
+
}, le.createPortal = function(e, n, o) {
|
|
12777
|
+
var i = 3 < arguments.length && arguments[3] !== void 0 ? arguments[3] : null;
|
|
12778
|
+
try {
|
|
12779
|
+
vt(i);
|
|
12780
|
+
var s = false;
|
|
12781
|
+
} catch {
|
|
12782
|
+
s = true;
|
|
12783
|
+
}
|
|
12784
|
+
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 };
|
|
12785
|
+
}, le.createRoleSelector = function(e) {
|
|
12786
|
+
return { $$typeof: mm, value: e };
|
|
12787
|
+
}, le.createTestNameSelector = function(e) {
|
|
12788
|
+
return { $$typeof: gm, value: e };
|
|
12789
|
+
}, le.createTextSelector = function(e) {
|
|
12790
|
+
return { $$typeof: ym, value: e };
|
|
12791
|
+
}, le.defaultOnCaughtError = function(e) {
|
|
12792
|
+
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") + ".");
|
|
12793
|
+
typeof e == "object" && e !== null && typeof e.environmentName == "string" ? ri("error", [`%o
|
|
12794
|
+
|
|
12795
|
+
%s
|
|
12796
|
+
|
|
12797
|
+
%s
|
|
12798
|
+
`, e, n, o], e.environmentName)() : console.error(`%o
|
|
12799
|
+
|
|
12800
|
+
%s
|
|
12801
|
+
|
|
12802
|
+
%s
|
|
12803
|
+
`, e, n, o);
|
|
12804
|
+
}, le.defaultOnRecoverableError = function(e) {
|
|
12805
|
+
qg(e);
|
|
12806
|
+
}, le.defaultOnUncaughtError = function(e) {
|
|
12807
|
+
qg(e), console.warn(`%s
|
|
12808
|
+
|
|
12809
|
+
%s
|
|
12810
|
+
`, 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.
|
|
12811
|
+
Visit https://react.dev/link/error-boundaries to learn more about error boundaries.`);
|
|
12812
|
+
}, le.deferredUpdates = function(e) {
|
|
12813
|
+
var n = x.T, o = wt();
|
|
12814
|
+
try {
|
|
12815
|
+
return an(32), x.T = null, e();
|
|
12816
|
+
} finally {
|
|
12817
|
+
an(o), x.T = n;
|
|
12818
|
+
}
|
|
12819
|
+
}, le.discreteUpdates = function(e, n, o, i, s) {
|
|
12820
|
+
var u = x.T, f = wt();
|
|
12821
|
+
try {
|
|
12822
|
+
return an(2), x.T = null, e(n, o, i, s);
|
|
12823
|
+
} finally {
|
|
12824
|
+
an(f), x.T = u, ye === Jn && (Pp = me() + Fg);
|
|
12825
|
+
}
|
|
12826
|
+
}, le.findAllNodes = kc, le.findBoundingRects = function(e, n) {
|
|
12827
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12828
|
+
n = kc(e, n), e = [];
|
|
12829
|
+
for (var o = 0; o < n.length; o++) e.push(ma(n[o]));
|
|
12830
|
+
for (n = e.length - 1; 0 < n; n--) {
|
|
12831
|
+
o = e[n];
|
|
12832
|
+
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) {
|
|
12833
|
+
var g = e[p], S = g.x, T = S + g.width, _ = g.y, I = _ + g.height;
|
|
12834
|
+
if (i >= S && u >= _ && s <= T && f <= I) {
|
|
12835
|
+
e.splice(n, 1);
|
|
12836
|
+
break;
|
|
12837
|
+
} else if (i !== S || o.width !== g.width || I < u || _ > f) {
|
|
12838
|
+
if (!(u !== _ || o.height !== g.height || T < i || S > s)) {
|
|
12839
|
+
S > i && (g.width += S - i, g.x = i), T < s && (g.width = s - S), e.splice(n, 1);
|
|
12840
|
+
break;
|
|
12841
|
+
}
|
|
12842
|
+
} else {
|
|
12843
|
+
_ > u && (g.height += _ - u, g.y = u), I < f && (g.height = f - _), e.splice(n, 1);
|
|
12844
|
+
break;
|
|
12845
|
+
}
|
|
12846
|
+
}
|
|
12847
|
+
}
|
|
12848
|
+
return e;
|
|
12849
|
+
}, le.findHostInstance = function(e) {
|
|
12850
|
+
var n = e._reactInternals;
|
|
12851
|
+
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));
|
|
12852
|
+
return e = mu(n), e === null ? null : ot(e.stateNode);
|
|
12853
|
+
}, le.findHostInstanceWithNoPortals = function(e) {
|
|
12854
|
+
return e = Ed(e), e = e !== null ? _p(e) : null, e === null ? null : ot(e.stateNode);
|
|
12855
|
+
}, le.findHostInstanceWithWarning = function(e, n) {
|
|
12856
|
+
var o = e._reactInternals;
|
|
12857
|
+
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));
|
|
12858
|
+
if (e = mu(o), e === null) return null;
|
|
12859
|
+
if (e.mode & 8) {
|
|
12860
|
+
var i = G(o) || "Component";
|
|
12861
|
+
mb[i] || (mb[i] = true, B(e, function() {
|
|
12862
|
+
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);
|
|
12863
|
+
}));
|
|
12864
|
+
}
|
|
12865
|
+
return ot(e.stateNode);
|
|
12866
|
+
}, le.flushPassiveEffects = el, le.flushSyncFromReconciler = function(e) {
|
|
12867
|
+
var n = ye;
|
|
12868
|
+
ye |= 1;
|
|
12869
|
+
var o = x.T, i = wt();
|
|
12870
|
+
try {
|
|
12871
|
+
if (an(2), x.T = null, e) return e();
|
|
12872
|
+
} finally {
|
|
12873
|
+
an(i), x.T = o, ye = n, (ye & (Zn | uo)) === Jn && Wa(0);
|
|
12874
|
+
}
|
|
12875
|
+
}, le.flushSyncWork = Ls, le.focusWithin = function(e, n) {
|
|
12876
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12877
|
+
for (e = Ef(e), n = hh(e, n), n = Array.from(n), e = 0; e < n.length; ) {
|
|
12878
|
+
var o = n[e++], i = o.tag;
|
|
12879
|
+
if (!Kr(o)) {
|
|
12880
|
+
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
12881
|
+
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
12882
|
+
}
|
|
12883
|
+
}
|
|
12884
|
+
return false;
|
|
12885
|
+
}, le.getFindAllNodesFailureDescription = function(e, n) {
|
|
12886
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12887
|
+
var o = 0, i = [];
|
|
12888
|
+
e = [Ef(e), 0];
|
|
12889
|
+
for (var s = 0; s < e.length; ) {
|
|
12890
|
+
var u = e[s++], f = u.tag, p = e[s++], g = n[p];
|
|
12891
|
+
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;
|
|
12892
|
+
}
|
|
12893
|
+
if (o < n.length) {
|
|
12894
|
+
for (e = []; o < n.length; o++) e.push(Sc(n[o]));
|
|
12895
|
+
return `findAllNodes was able to match part of the selector:
|
|
12896
|
+
` + (i.join(" > ") + `
|
|
12897
|
+
|
|
12898
|
+
No matching component was found for:
|
|
12899
|
+
`) + e.join(" > ");
|
|
12900
|
+
}
|
|
12901
|
+
return null;
|
|
12902
|
+
}, le.getPublicRootInstance = function(e) {
|
|
12903
|
+
if (e = e.current, !e.child) return null;
|
|
12904
|
+
switch (e.child.tag) {
|
|
12905
|
+
case 27:
|
|
12906
|
+
case 5:
|
|
12907
|
+
return ot(e.child.stateNode);
|
|
12908
|
+
default:
|
|
12909
|
+
return e.child.stateNode;
|
|
12910
|
+
}
|
|
12911
|
+
}, le.injectIntoDevTools = function() {
|
|
12912
|
+
var e = { bundleType: 1, version: Jt, rendererPackageName: Zt, currentDispatcherRef: x, reconcilerVersion: "19.2.0" };
|
|
12913
|
+
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);
|
|
12914
|
+
}, le.isAlreadyRendering = Ns, le.observeVisibleRects = function(e, n, o, i) {
|
|
12915
|
+
function s() {
|
|
12916
|
+
var S = kc(e, n);
|
|
12917
|
+
u.forEach(function(T) {
|
|
12918
|
+
0 > S.indexOf(T) && g(T);
|
|
12919
|
+
}), S.forEach(function(T) {
|
|
12920
|
+
0 > u.indexOf(T) && p(T);
|
|
12921
|
+
});
|
|
12922
|
+
}
|
|
12923
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12924
|
+
var u = kc(e, n);
|
|
12925
|
+
o = zr(u, o, i);
|
|
12926
|
+
var f = o.disconnect, p = o.observe, g = o.unobserve;
|
|
12927
|
+
return bm.push(s), { disconnect: function() {
|
|
12928
|
+
var S = bm.indexOf(s);
|
|
12929
|
+
0 <= S && bm.splice(S, 1), f();
|
|
12930
|
+
} };
|
|
12931
|
+
}, le.shouldError = function(e) {
|
|
12932
|
+
return pu(e);
|
|
12933
|
+
}, le.shouldSuspend = function(e) {
|
|
12934
|
+
return fu(e);
|
|
12935
|
+
}, le.startHostTransition = function(e, n, o, i) {
|
|
12936
|
+
if (e.tag !== 5) throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");
|
|
12937
|
+
var s = uf(e).queue;
|
|
12938
|
+
Hp(e), nt(e, s, n, Xt, o === null ? Em : function() {
|
|
12939
|
+
x.T === null && console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");
|
|
12940
|
+
var u = uf(e);
|
|
12941
|
+
return u.next === null && (u = e.alternate.memoizedState), qi(e, u.next.queue, {}, Nt(e)), o(i);
|
|
12942
|
+
});
|
|
12943
|
+
}, le.updateContainer = function(e, n, o, i) {
|
|
12944
|
+
var s = n.current, u = Nt(s);
|
|
12945
|
+
return As(s, u, e, n, o, i), u;
|
|
12946
|
+
}, le.updateContainerSync = Wh, le;
|
|
12947
|
+
}, Tt.exports.default = Tt.exports, Object.defineProperty(Tt.exports, "__esModule", { value: true }));
|
|
12948
|
+
})(Mg)), Mg.exports;
|
|
12949
|
+
}
|
|
12950
|
+
var Eb;
|
|
12951
|
+
function n0() {
|
|
12952
|
+
return Eb || (Eb = 1, process.env.NODE_ENV === "production" ? Rm.exports = Kb() : Rm.exports = e0()), Rm.exports;
|
|
12953
|
+
}
|
|
12954
|
+
var t0 = n0();
|
|
12955
|
+
const r0 = Xb(t0);
|
|
12956
|
+
|
|
12957
|
+
const DEFAULT_POINTER_ID = 0;
|
|
12958
|
+
const XR_POINTER_ID_START = 1e3;
|
|
12959
|
+
function getPointerState(internal, pointerId) {
|
|
12960
|
+
let state = internal.pointerMap.get(pointerId);
|
|
12961
|
+
if (!state) {
|
|
12962
|
+
state = {
|
|
12963
|
+
hovered: /* @__PURE__ */ new Map(),
|
|
12964
|
+
captured: /* @__PURE__ */ new Map(),
|
|
12965
|
+
initialClick: [0, 0],
|
|
12966
|
+
initialHits: []
|
|
12967
|
+
};
|
|
12968
|
+
internal.pointerMap.set(pointerId, state);
|
|
12969
|
+
}
|
|
12970
|
+
return state;
|
|
12971
|
+
}
|
|
12972
|
+
function getPointerId(event) {
|
|
12973
|
+
return "pointerId" in event ? event.pointerId : DEFAULT_POINTER_ID;
|
|
12974
|
+
}
|
|
12975
|
+
function makeId(event) {
|
|
12976
|
+
return (event.eventObject || event.object).uuid + "/" + event.index + event.instanceId;
|
|
12977
|
+
}
|
|
12978
|
+
function releaseInternalPointerCapture(internal, obj, pointerId) {
|
|
12979
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
12980
|
+
if (!pointerState) return;
|
|
12981
|
+
const captureData = pointerState.captured.get(obj);
|
|
12982
|
+
if (captureData) {
|
|
12983
|
+
pointerState.captured.delete(obj);
|
|
12984
|
+
try {
|
|
12985
|
+
captureData.target.releasePointerCapture?.(pointerId);
|
|
12986
|
+
} catch {
|
|
12987
|
+
}
|
|
12988
|
+
}
|
|
12989
|
+
}
|
|
12990
|
+
function swapInteractivity(store, object, newObject) {
|
|
12991
|
+
const { internal } = store.getState();
|
|
12992
|
+
for (let i = 0; i < internal.interaction.length; i++) {
|
|
12993
|
+
if (internal.interaction[i] === object) internal.interaction[i] = newObject;
|
|
12994
|
+
}
|
|
12995
|
+
for (const pointerState of internal.pointerMap.values()) {
|
|
12996
|
+
for (let i = 0; i < pointerState.initialHits.length; i++) {
|
|
12997
|
+
if (pointerState.initialHits[i] === object) pointerState.initialHits[i] = newObject;
|
|
12998
|
+
}
|
|
12999
|
+
pointerState.hovered.forEach((value, key) => {
|
|
13000
|
+
if (value.eventObject === object || value.object === object) {
|
|
13001
|
+
pointerState.hovered.delete(key);
|
|
13002
|
+
const next = {
|
|
13003
|
+
...value,
|
|
13004
|
+
eventObject: value.eventObject === object ? newObject : value.eventObject,
|
|
13005
|
+
object: value.object === object ? newObject : value.object
|
|
13006
|
+
};
|
|
13007
|
+
pointerState.hovered.set(makeId(next), next);
|
|
13008
|
+
}
|
|
13009
|
+
});
|
|
13010
|
+
const captureData = pointerState.captured.get(object);
|
|
13011
|
+
if (captureData) {
|
|
13012
|
+
pointerState.captured.delete(object);
|
|
13013
|
+
pointerState.captured.set(newObject, {
|
|
13014
|
+
...captureData,
|
|
13015
|
+
intersection: {
|
|
13016
|
+
...captureData.intersection,
|
|
13017
|
+
object: captureData.intersection.object === object ? newObject : captureData.intersection.object,
|
|
13018
|
+
eventObject: captureData.intersection.eventObject === object ? newObject : captureData.intersection.eventObject
|
|
13019
|
+
}
|
|
13020
|
+
});
|
|
13021
|
+
}
|
|
13022
|
+
}
|
|
13023
|
+
unregisterVisibility(store, object);
|
|
13024
|
+
}
|
|
13025
|
+
function removeInteractivity(store, object) {
|
|
13026
|
+
const { internal } = store.getState();
|
|
13027
|
+
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
13028
|
+
for (const [pointerId, pointerState] of internal.pointerMap) {
|
|
13029
|
+
pointerState.initialHits = pointerState.initialHits.filter((o) => o !== object);
|
|
13030
|
+
pointerState.hovered.forEach((value, key) => {
|
|
13031
|
+
if (value.eventObject === object || value.object === object) {
|
|
13032
|
+
pointerState.hovered.delete(key);
|
|
13033
|
+
}
|
|
13034
|
+
});
|
|
13035
|
+
if (pointerState.captured.has(object)) {
|
|
13036
|
+
releaseInternalPointerCapture(internal, object, pointerId);
|
|
13037
|
+
}
|
|
13038
|
+
}
|
|
13039
|
+
unregisterVisibility(store, object);
|
|
13040
|
+
}
|
|
13041
|
+
function createEvents(store) {
|
|
13042
|
+
function calculateDistance(event, pointerId) {
|
|
13043
|
+
const { internal } = store.getState();
|
|
13044
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13045
|
+
if (!pointerState) return 0;
|
|
13046
|
+
const [initialX, initialY] = pointerState.initialClick;
|
|
13047
|
+
const dx = event.offsetX - initialX;
|
|
13048
|
+
const dy = event.offsetY - initialY;
|
|
13049
|
+
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
13050
|
+
}
|
|
13051
|
+
function filterPointerEvents(objects) {
|
|
13052
|
+
return objects.filter(
|
|
13053
|
+
(obj) => ["Move", "Over", "Enter", "Out", "Leave"].some(
|
|
13054
|
+
(name) => obj.__r3f?.handlers["onPointer" + name]
|
|
13055
|
+
) || ["OverEnter", "OverLeave", "Over"].some(
|
|
13056
|
+
(name) => obj.__r3f?.handlers["onDrag" + name]
|
|
13057
|
+
) || obj.__r3f?.handlers.onDrop
|
|
13058
|
+
);
|
|
13059
|
+
}
|
|
13060
|
+
function intersect(event, filter) {
|
|
13061
|
+
const state = store.getState();
|
|
13062
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
13063
|
+
const intersections = [];
|
|
13064
|
+
const eventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
|
|
13065
|
+
for (let i = 0; i < eventsObjects.length; i++) {
|
|
13066
|
+
const state2 = getRootState(eventsObjects[i]);
|
|
13067
|
+
if (state2) {
|
|
13068
|
+
state2.raycaster.camera = void 0;
|
|
13069
|
+
}
|
|
13070
|
+
}
|
|
13071
|
+
if (!state.previousRoot) {
|
|
13072
|
+
state.events.compute?.(event, state);
|
|
13073
|
+
}
|
|
13074
|
+
function handleRaycast(obj) {
|
|
13075
|
+
const state2 = getRootState(obj);
|
|
13076
|
+
if (!state2 || !state2.events.enabled || state2.raycaster.camera === null) return [];
|
|
13077
|
+
if (state2.raycaster.camera === void 0) {
|
|
13078
|
+
state2.events.compute?.(event, state2, state2.previousRoot?.getState());
|
|
13079
|
+
if (state2.raycaster.camera === void 0) state2.raycaster.camera = null;
|
|
13080
|
+
}
|
|
13081
|
+
if (!state2.raycaster.camera) return [];
|
|
13082
|
+
obj.updateWorldMatrix(true, true);
|
|
13083
|
+
return state2.raycaster.intersectObject(obj, true);
|
|
13084
|
+
}
|
|
13085
|
+
let hits = eventsObjects.flatMap(handleRaycast).sort((a, b) => {
|
|
13086
|
+
const aInteractivePriority = a.object.userData?.interactivePriority;
|
|
13087
|
+
const bInteractivePriority = b.object.userData?.interactivePriority;
|
|
13088
|
+
if (aInteractivePriority !== void 0 || bInteractivePriority !== void 0) {
|
|
13089
|
+
if (aInteractivePriority !== void 0 && bInteractivePriority === void 0) return -1;
|
|
13090
|
+
if (bInteractivePriority !== void 0 && aInteractivePriority === void 0) return 1;
|
|
13091
|
+
if (aInteractivePriority !== bInteractivePriority) {
|
|
13092
|
+
return (bInteractivePriority ?? 0) - (aInteractivePriority ?? 0);
|
|
13093
|
+
}
|
|
13094
|
+
}
|
|
13095
|
+
const aState = getRootState(a.object);
|
|
13096
|
+
const bState = getRootState(b.object);
|
|
13097
|
+
const aPriority = aState?.events?.priority ?? 1;
|
|
13098
|
+
const bPriority = bState?.events?.priority ?? 1;
|
|
13099
|
+
return bPriority - aPriority || a.distance - b.distance;
|
|
13100
|
+
}).filter((item) => {
|
|
13101
|
+
const id = makeId(item);
|
|
13102
|
+
if (duplicates.has(id)) return false;
|
|
13103
|
+
duplicates.add(id);
|
|
13104
|
+
return true;
|
|
13105
|
+
});
|
|
13106
|
+
if (state.events.filter) hits = state.events.filter(hits, state);
|
|
13107
|
+
for (const hit of hits) {
|
|
13108
|
+
let eventObject = hit.object;
|
|
13109
|
+
while (eventObject) {
|
|
13110
|
+
if (eventObject.__r3f?.eventCount) {
|
|
13111
|
+
intersections.push({ ...hit, eventObject });
|
|
13112
|
+
}
|
|
13113
|
+
eventObject = eventObject.parent;
|
|
13114
|
+
}
|
|
13115
|
+
}
|
|
13116
|
+
if ("pointerId" in event) {
|
|
13117
|
+
const pointerId = event.pointerId;
|
|
13118
|
+
const pointerState = state.internal.pointerMap.get(pointerId);
|
|
13119
|
+
if (pointerState?.captured.size) {
|
|
13120
|
+
for (const captureData of pointerState.captured.values()) {
|
|
13121
|
+
if (!duplicates.has(makeId(captureData.intersection))) intersections.push(captureData.intersection);
|
|
13122
|
+
}
|
|
13123
|
+
}
|
|
13124
|
+
}
|
|
13125
|
+
return intersections;
|
|
13126
|
+
}
|
|
13127
|
+
function handleIntersects(intersections, event, delta, callback) {
|
|
13128
|
+
if (intersections.length) {
|
|
13129
|
+
const localState = { stopped: false };
|
|
13130
|
+
for (const hit of intersections) {
|
|
13131
|
+
const state = getRootState(hit.object);
|
|
13132
|
+
if (state) {
|
|
13133
|
+
const { raycaster, pointer, camera, internal } = state;
|
|
13134
|
+
const unprojectedPoint = new Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
13135
|
+
const hasPointerCapture = (id) => {
|
|
13136
|
+
const pointerState = internal.pointerMap.get(id);
|
|
13137
|
+
return pointerState?.captured.has(hit.eventObject) ?? false;
|
|
13138
|
+
};
|
|
13139
|
+
const setPointerCapture = (id) => {
|
|
13140
|
+
const captureData = { intersection: hit, target: event.target };
|
|
13141
|
+
const pointerState = getPointerState(internal, id);
|
|
13142
|
+
pointerState.captured.set(hit.eventObject, captureData);
|
|
13143
|
+
event.target.setPointerCapture(id);
|
|
13144
|
+
};
|
|
13145
|
+
const releasePointerCapture = (id) => {
|
|
13146
|
+
releaseInternalPointerCapture(internal, hit.eventObject, id);
|
|
13147
|
+
};
|
|
13148
|
+
const extractEventProps = {};
|
|
13149
|
+
for (const prop in event) {
|
|
13150
|
+
const property = event[prop];
|
|
13151
|
+
if (typeof property !== "function") extractEventProps[prop] = property;
|
|
13152
|
+
}
|
|
13153
|
+
const eventPointerId = "pointerId" in event ? event.pointerId : void 0;
|
|
13154
|
+
const raycastEvent = {
|
|
13155
|
+
...hit,
|
|
13156
|
+
...extractEventProps,
|
|
13157
|
+
pointer,
|
|
13158
|
+
intersections,
|
|
13159
|
+
stopped: localState.stopped,
|
|
13160
|
+
delta,
|
|
13161
|
+
unprojectedPoint,
|
|
13162
|
+
ray: raycaster.ray,
|
|
13163
|
+
camera,
|
|
13164
|
+
pointerId: eventPointerId,
|
|
13165
|
+
// Hijack stopPropagation, which just sets a flag
|
|
13166
|
+
stopPropagation() {
|
|
13167
|
+
const pointerState = eventPointerId !== void 0 ? internal.pointerMap.get(eventPointerId) : void 0;
|
|
13168
|
+
if (
|
|
13169
|
+
// ...if this pointer hasn't been captured
|
|
13170
|
+
!pointerState?.captured.size || // ... or if the hit object is capturing the pointer
|
|
13171
|
+
pointerState.captured.has(hit.eventObject)
|
|
13172
|
+
) {
|
|
13173
|
+
raycastEvent.stopped = localState.stopped = true;
|
|
13174
|
+
if (pointerState?.hovered.size && Array.from(pointerState.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
13175
|
+
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
13176
|
+
cancelPointer([...higher, hit], eventPointerId);
|
|
13177
|
+
}
|
|
13484
13178
|
}
|
|
13485
|
-
}
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13179
|
+
},
|
|
13180
|
+
// there should be a distinction between target and currentTarget
|
|
13181
|
+
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13182
|
+
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
13183
|
+
nativeEvent: event
|
|
13184
|
+
};
|
|
13185
|
+
callback(raycastEvent);
|
|
13186
|
+
if (localState.stopped === true) break;
|
|
13490
13187
|
}
|
|
13491
|
-
}
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13188
|
+
}
|
|
13189
|
+
}
|
|
13190
|
+
return intersections;
|
|
13191
|
+
}
|
|
13192
|
+
function cancelPointer(intersections, pointerId) {
|
|
13193
|
+
const { internal } = store.getState();
|
|
13194
|
+
const pid = pointerId ?? DEFAULT_POINTER_ID;
|
|
13195
|
+
const pointerState = internal.pointerMap.get(pid);
|
|
13196
|
+
if (!pointerState) return;
|
|
13197
|
+
for (const [hoveredId, hoveredObj] of pointerState.hovered) {
|
|
13198
|
+
if (!intersections.length || !intersections.find(
|
|
13199
|
+
(hit) => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId
|
|
13200
|
+
)) {
|
|
13201
|
+
const eventObject = hoveredObj.eventObject;
|
|
13202
|
+
const instance = eventObject.__r3f;
|
|
13203
|
+
pointerState.hovered.delete(hoveredId);
|
|
13204
|
+
if (instance?.eventCount) {
|
|
13205
|
+
const handlers = instance.handlers;
|
|
13206
|
+
const data = { ...hoveredObj, intersections };
|
|
13207
|
+
handlers.onPointerOut?.(data);
|
|
13208
|
+
handlers.onPointerLeave?.(data);
|
|
13209
|
+
handlers.onDragOverLeave?.(data);
|
|
13508
13210
|
}
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
|
|
13522
|
-
|
|
13523
|
-
|
|
13524
|
-
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
an(o), x.T = n;
|
|
13211
|
+
}
|
|
13212
|
+
}
|
|
13213
|
+
}
|
|
13214
|
+
function pointerMissed(event, objects) {
|
|
13215
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13216
|
+
const instance = objects[i].__r3f;
|
|
13217
|
+
instance?.handlers.onPointerMissed?.(event);
|
|
13218
|
+
}
|
|
13219
|
+
}
|
|
13220
|
+
function dragOverMissed(event, objects) {
|
|
13221
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13222
|
+
const instance = objects[i].__r3f;
|
|
13223
|
+
instance?.handlers.onDragOverMissed?.(event);
|
|
13224
|
+
}
|
|
13225
|
+
}
|
|
13226
|
+
function dropMissed(event, objects) {
|
|
13227
|
+
for (let i = 0; i < objects.length; i++) {
|
|
13228
|
+
const instance = objects[i].__r3f;
|
|
13229
|
+
instance?.handlers.onDropMissed?.(event);
|
|
13230
|
+
}
|
|
13231
|
+
}
|
|
13232
|
+
function cleanupPointer(pointerId) {
|
|
13233
|
+
const { internal } = store.getState();
|
|
13234
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13235
|
+
if (pointerState) {
|
|
13236
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13237
|
+
const eventObject = hoveredObj.eventObject;
|
|
13238
|
+
const instance = eventObject.__r3f;
|
|
13239
|
+
if (instance?.eventCount) {
|
|
13240
|
+
const handlers = instance.handlers;
|
|
13241
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13242
|
+
handlers.onPointerOut?.(data);
|
|
13243
|
+
handlers.onPointerLeave?.(data);
|
|
13543
13244
|
}
|
|
13544
|
-
}
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13245
|
+
}
|
|
13246
|
+
internal.pointerMap.delete(pointerId);
|
|
13247
|
+
}
|
|
13248
|
+
internal.pointerDirty.delete(pointerId);
|
|
13249
|
+
}
|
|
13250
|
+
function processDeferredPointer(event, pointerId) {
|
|
13251
|
+
const state = store.getState();
|
|
13252
|
+
const { internal } = state;
|
|
13253
|
+
if (!state.events.enabled) return;
|
|
13254
|
+
const filter = filterPointerEvents;
|
|
13255
|
+
const hits = intersect(event, filter);
|
|
13256
|
+
cancelPointer(hits, pointerId);
|
|
13257
|
+
function onIntersect(data) {
|
|
13258
|
+
const eventObject = data.eventObject;
|
|
13259
|
+
const instance = eventObject.__r3f;
|
|
13260
|
+
if (!instance?.eventCount) return;
|
|
13261
|
+
const handlers = instance.handlers;
|
|
13262
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13263
|
+
const id = makeId(data);
|
|
13264
|
+
const pointerState = getPointerState(internal, pointerId);
|
|
13265
|
+
const hoveredItem = pointerState.hovered.get(id);
|
|
13266
|
+
if (!hoveredItem) {
|
|
13267
|
+
pointerState.hovered.set(id, data);
|
|
13268
|
+
handlers.onPointerOver?.(data);
|
|
13269
|
+
handlers.onPointerEnter?.(data);
|
|
13270
|
+
} else if (hoveredItem.stopped) {
|
|
13271
|
+
data.stopPropagation();
|
|
13550
13272
|
}
|
|
13551
|
-
}
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13273
|
+
}
|
|
13274
|
+
handlers.onPointerMove?.(data);
|
|
13275
|
+
}
|
|
13276
|
+
handleIntersects(hits, event, 0, onIntersect);
|
|
13277
|
+
}
|
|
13278
|
+
function handlePointer(name) {
|
|
13279
|
+
switch (name) {
|
|
13280
|
+
case "onPointerLeave":
|
|
13281
|
+
case "onDragLeave":
|
|
13282
|
+
return () => cancelPointer([]);
|
|
13283
|
+
// Global cancel of these events
|
|
13284
|
+
case "onPointerCancel":
|
|
13285
|
+
return (event) => {
|
|
13286
|
+
const pointerId = getPointerId(event);
|
|
13287
|
+
cleanupPointer(pointerId);
|
|
13288
|
+
};
|
|
13289
|
+
case "onLostPointerCapture":
|
|
13290
|
+
return (event) => {
|
|
13291
|
+
const { internal } = store.getState();
|
|
13292
|
+
const pointerId = getPointerId(event);
|
|
13293
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13294
|
+
if (pointerState?.captured.size) {
|
|
13295
|
+
requestAnimationFrame(() => {
|
|
13296
|
+
const pointerState2 = internal.pointerMap.get(pointerId);
|
|
13297
|
+
if (pointerState2?.captured.size) {
|
|
13298
|
+
pointerState2.captured.clear();
|
|
13566
13299
|
}
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13300
|
+
cancelPointer([], pointerId);
|
|
13301
|
+
});
|
|
13302
|
+
}
|
|
13303
|
+
};
|
|
13304
|
+
}
|
|
13305
|
+
return function handleEvent(event) {
|
|
13306
|
+
const state = store.getState();
|
|
13307
|
+
const { onPointerMissed, onDragOverMissed, onDropMissed, internal, events } = state;
|
|
13308
|
+
const pointerId = getPointerId(event);
|
|
13309
|
+
internal.lastEvent.current = event;
|
|
13310
|
+
if (!events.enabled) return;
|
|
13311
|
+
const isPointerMove = name === "onPointerMove";
|
|
13312
|
+
const isDragOver = name === "onDragOver";
|
|
13313
|
+
const isDrop = name === "onDrop";
|
|
13314
|
+
const isClickEvent = name === "onClick" || name === "onContextMenu" || name === "onDoubleClick";
|
|
13315
|
+
const isPointerDown = name === "onPointerDown";
|
|
13316
|
+
const isPointerUp = name === "onPointerUp";
|
|
13317
|
+
const isWheel = name === "onWheel";
|
|
13318
|
+
const canDeferRaycasts = events.frameTimedRaycasts && state.frameloop === "always";
|
|
13319
|
+
if (isPointerMove && canDeferRaycasts) {
|
|
13320
|
+
events.compute?.(event, state);
|
|
13321
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13322
|
+
return;
|
|
13323
|
+
}
|
|
13324
|
+
if (isWheel && canDeferRaycasts && !events.alwaysFireOnScroll) {
|
|
13325
|
+
events.compute?.(event, state);
|
|
13326
|
+
internal.pointerDirty.set(pointerId, event);
|
|
13327
|
+
return;
|
|
13328
|
+
}
|
|
13329
|
+
if ((isClickEvent || isPointerDown || isPointerUp) && internal.pointerDirty.has(pointerId)) {
|
|
13330
|
+
const deferredEvent = internal.pointerDirty.get(pointerId);
|
|
13331
|
+
internal.pointerDirty.delete(pointerId);
|
|
13332
|
+
processDeferredPointer(deferredEvent, pointerId);
|
|
13333
|
+
}
|
|
13334
|
+
const filter = isPointerMove || isDragOver || isDrop ? filterPointerEvents : void 0;
|
|
13335
|
+
const hits = intersect(event, filter);
|
|
13336
|
+
const delta = isClickEvent ? calculateDistance(event, pointerId) : 0;
|
|
13337
|
+
if (isPointerDown) {
|
|
13338
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13339
|
+
pointerState2.initialClick = [event.offsetX, event.offsetY];
|
|
13340
|
+
pointerState2.initialHits = hits.map((hit) => hit.eventObject);
|
|
13341
|
+
}
|
|
13342
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13343
|
+
const initialHits = pointerState?.initialHits ?? [];
|
|
13344
|
+
if (isClickEvent && !hits.length) {
|
|
13345
|
+
if (delta <= 2) {
|
|
13346
|
+
pointerMissed(event, internal.interaction);
|
|
13347
|
+
if (onPointerMissed) onPointerMissed(event);
|
|
13348
|
+
}
|
|
13349
|
+
}
|
|
13350
|
+
if (isDragOver && !hits.length) {
|
|
13351
|
+
dragOverMissed(event, internal.interaction);
|
|
13352
|
+
if (onDragOverMissed) onDragOverMissed(event);
|
|
13353
|
+
}
|
|
13354
|
+
if (isDrop && !hits.length) {
|
|
13355
|
+
dropMissed(event, internal.interaction);
|
|
13356
|
+
if (onDropMissed) onDropMissed(event);
|
|
13357
|
+
}
|
|
13358
|
+
if (isPointerMove || isDragOver) {
|
|
13359
|
+
cancelPointer(hits, pointerId);
|
|
13360
|
+
}
|
|
13361
|
+
function onIntersect(data) {
|
|
13362
|
+
const eventObject = data.eventObject;
|
|
13363
|
+
const instance = eventObject.__r3f;
|
|
13364
|
+
if (!instance?.eventCount) return;
|
|
13365
|
+
const handlers = instance.handlers;
|
|
13366
|
+
if (isPointerMove) {
|
|
13367
|
+
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
13368
|
+
const id = makeId(data);
|
|
13369
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13370
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13371
|
+
if (!hoveredItem) {
|
|
13372
|
+
pointerState2.hovered.set(id, data);
|
|
13373
|
+
handlers.onPointerOver?.(data);
|
|
13374
|
+
handlers.onPointerEnter?.(data);
|
|
13375
|
+
} else if (hoveredItem.stopped) {
|
|
13376
|
+
data.stopPropagation();
|
|
13570
13377
|
}
|
|
13571
13378
|
}
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
if (
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
var o = n[e++], i = o.tag;
|
|
13604
|
-
if (!Kr(o)) {
|
|
13605
|
-
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
13606
|
-
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
13379
|
+
handlers.onPointerMove?.(data);
|
|
13380
|
+
} else if (isDragOver) {
|
|
13381
|
+
const id = makeId(data);
|
|
13382
|
+
const pointerState2 = getPointerState(internal, pointerId);
|
|
13383
|
+
const hoveredItem = pointerState2.hovered.get(id);
|
|
13384
|
+
if (!hoveredItem) {
|
|
13385
|
+
pointerState2.hovered.set(id, data);
|
|
13386
|
+
handlers.onDragOverEnter?.(data);
|
|
13387
|
+
} else if (hoveredItem.stopped) {
|
|
13388
|
+
data.stopPropagation();
|
|
13389
|
+
}
|
|
13390
|
+
handlers.onDragOver?.(data);
|
|
13391
|
+
} else if (isDrop) {
|
|
13392
|
+
handlers.onDrop?.(data);
|
|
13393
|
+
} else {
|
|
13394
|
+
const handler = handlers[name];
|
|
13395
|
+
if (handler) {
|
|
13396
|
+
if (!isClickEvent || initialHits.includes(eventObject)) {
|
|
13397
|
+
pointerMissed(
|
|
13398
|
+
event,
|
|
13399
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13400
|
+
);
|
|
13401
|
+
handler(data);
|
|
13402
|
+
}
|
|
13403
|
+
} else {
|
|
13404
|
+
if (isClickEvent && initialHits.includes(eventObject)) {
|
|
13405
|
+
pointerMissed(
|
|
13406
|
+
event,
|
|
13407
|
+
internal.interaction.filter((object) => !initialHits.includes(object))
|
|
13408
|
+
);
|
|
13409
|
+
}
|
|
13607
13410
|
}
|
|
13608
13411
|
}
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13412
|
+
}
|
|
13413
|
+
handleIntersects(hits, event, delta, onIntersect);
|
|
13414
|
+
};
|
|
13415
|
+
}
|
|
13416
|
+
function flushDeferredPointers() {
|
|
13417
|
+
const { internal, events } = store.getState();
|
|
13418
|
+
if (!events.frameTimedRaycasts) return;
|
|
13419
|
+
for (const [pointerId, event] of internal.pointerDirty) {
|
|
13420
|
+
processDeferredPointer(event, pointerId);
|
|
13421
|
+
}
|
|
13422
|
+
internal.pointerDirty.clear();
|
|
13423
|
+
}
|
|
13424
|
+
return { handlePointer, flushDeferredPointers, processDeferredPointer };
|
|
13425
|
+
}
|
|
13426
|
+
const DOM_EVENTS = {
|
|
13427
|
+
onClick: ["click", false],
|
|
13428
|
+
onContextMenu: ["contextmenu", false],
|
|
13429
|
+
onDoubleClick: ["dblclick", false],
|
|
13430
|
+
onDragEnter: ["dragenter", false],
|
|
13431
|
+
onDragLeave: ["dragleave", false],
|
|
13432
|
+
onDragOver: ["dragover", false],
|
|
13433
|
+
onDrop: ["drop", false],
|
|
13434
|
+
onWheel: ["wheel", true],
|
|
13435
|
+
onPointerDown: ["pointerdown", true],
|
|
13436
|
+
onPointerUp: ["pointerup", true],
|
|
13437
|
+
onPointerLeave: ["pointerleave", true],
|
|
13438
|
+
onPointerMove: ["pointermove", true],
|
|
13439
|
+
onPointerCancel: ["pointercancel", true],
|
|
13440
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
13441
|
+
};
|
|
13442
|
+
function createPointerEvents(store) {
|
|
13443
|
+
const { handlePointer, flushDeferredPointers, processDeferredPointer } = createEvents(store);
|
|
13444
|
+
let nextXRPointerId = XR_POINTER_ID_START;
|
|
13445
|
+
const xrPointers = /* @__PURE__ */ new Map();
|
|
13446
|
+
return {
|
|
13447
|
+
priority: 1,
|
|
13448
|
+
enabled: true,
|
|
13449
|
+
frameTimedRaycasts: true,
|
|
13450
|
+
alwaysFireOnScroll: true,
|
|
13451
|
+
updateOnFrame: false,
|
|
13452
|
+
compute(event, state) {
|
|
13453
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
13454
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
13455
|
+
},
|
|
13456
|
+
connected: void 0,
|
|
13457
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
13458
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
13459
|
+
{}
|
|
13460
|
+
),
|
|
13461
|
+
update: (pointerId) => {
|
|
13462
|
+
const { events, internal } = store.getState();
|
|
13463
|
+
if (!events.handlers) return;
|
|
13464
|
+
if (pointerId !== void 0) {
|
|
13465
|
+
const event = internal.pointerDirty.get(pointerId);
|
|
13466
|
+
if (event) {
|
|
13467
|
+
internal.pointerDirty.delete(pointerId);
|
|
13468
|
+
processDeferredPointer(event, pointerId);
|
|
13469
|
+
} else if (internal.lastEvent?.current) {
|
|
13470
|
+
processDeferredPointer(internal.lastEvent.current, pointerId);
|
|
13617
13471
|
}
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
No matching component was found for:
|
|
13624
|
-
`) + e.join(" > ");
|
|
13472
|
+
} else {
|
|
13473
|
+
flushDeferredPointers();
|
|
13474
|
+
if (internal.lastEvent?.current) {
|
|
13475
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13625
13476
|
}
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13477
|
+
}
|
|
13478
|
+
},
|
|
13479
|
+
flush: () => {
|
|
13480
|
+
const { events, internal } = store.getState();
|
|
13481
|
+
flushDeferredPointers();
|
|
13482
|
+
if (events.updateOnFrame && internal.lastEvent?.current && events.handlers) {
|
|
13483
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13484
|
+
}
|
|
13485
|
+
},
|
|
13486
|
+
connect: (target) => {
|
|
13487
|
+
if (!target) return;
|
|
13488
|
+
const { set, events } = store.getState();
|
|
13489
|
+
events.disconnect?.();
|
|
13490
|
+
set((state) => ({ events: { ...state.events, connected: target } }));
|
|
13491
|
+
if (events.handlers) {
|
|
13492
|
+
for (const name in events.handlers) {
|
|
13493
|
+
const event = events.handlers[name];
|
|
13494
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
13495
|
+
target.addEventListener(eventName, event, { passive });
|
|
13635
13496
|
}
|
|
13636
|
-
}
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
|
|
13641
|
-
|
|
13642
|
-
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
}
|
|
13497
|
+
}
|
|
13498
|
+
},
|
|
13499
|
+
disconnect: () => {
|
|
13500
|
+
const { set, events } = store.getState();
|
|
13501
|
+
if (events.connected) {
|
|
13502
|
+
if (events.handlers) {
|
|
13503
|
+
for (const name in events.handlers) {
|
|
13504
|
+
const event = events.handlers[name];
|
|
13505
|
+
const [eventName] = DOM_EVENTS[name];
|
|
13506
|
+
events.connected.removeEventListener(eventName, event);
|
|
13507
|
+
}
|
|
13647
13508
|
}
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13509
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
13510
|
+
}
|
|
13511
|
+
},
|
|
13512
|
+
// PREVIEW (A8): the XR pointer registration API may change before stable.
|
|
13513
|
+
registerPointer: (config) => {
|
|
13514
|
+
const pointerId = nextXRPointerId++;
|
|
13515
|
+
xrPointers.set(pointerId, config);
|
|
13516
|
+
const { internal } = store.getState();
|
|
13517
|
+
getPointerState(internal, pointerId);
|
|
13518
|
+
return pointerId;
|
|
13519
|
+
},
|
|
13520
|
+
unregisterPointer: (pointerId) => {
|
|
13521
|
+
xrPointers.delete(pointerId);
|
|
13522
|
+
const { internal } = store.getState();
|
|
13523
|
+
const pointerState = internal.pointerMap.get(pointerId);
|
|
13524
|
+
if (pointerState) {
|
|
13525
|
+
for (const [, hoveredObj] of pointerState.hovered) {
|
|
13526
|
+
const eventObject = hoveredObj.eventObject;
|
|
13527
|
+
const instance = eventObject.__r3f;
|
|
13528
|
+
if (instance?.eventCount) {
|
|
13529
|
+
const handlers = instance.handlers;
|
|
13530
|
+
const data = { ...hoveredObj, intersections: [] };
|
|
13531
|
+
handlers.onPointerOut?.(data);
|
|
13532
|
+
handlers.onPointerLeave?.(data);
|
|
13533
|
+
}
|
|
13534
|
+
}
|
|
13535
|
+
internal.pointerMap.delete(pointerId);
|
|
13536
|
+
}
|
|
13537
|
+
internal.pointerDirty.delete(pointerId);
|
|
13538
|
+
}
|
|
13539
|
+
};
|
|
13678
13540
|
}
|
|
13679
|
-
var t0 = n0();
|
|
13680
|
-
const r0 = Xb(t0);
|
|
13681
|
-
|
|
13682
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13683
13541
|
|
|
13684
13542
|
function createReconciler(config) {
|
|
13685
13543
|
const reconciler2 = r0(config);
|
|
@@ -13844,7 +13702,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
13844
13702
|
}
|
|
13845
13703
|
}
|
|
13846
13704
|
const reconstructed = [];
|
|
13847
|
-
function
|
|
13705
|
+
function flushReconstructedInstances() {
|
|
13706
|
+
if (reconstructed.length === 0) return;
|
|
13707
|
+
try {
|
|
13708
|
+
swapReconstructedInstances();
|
|
13709
|
+
} finally {
|
|
13710
|
+
reconstructed.length = 0;
|
|
13711
|
+
}
|
|
13712
|
+
}
|
|
13713
|
+
function swapReconstructedInstances() {
|
|
13848
13714
|
for (const [instance] of reconstructed) {
|
|
13849
13715
|
const parent = instance.parent;
|
|
13850
13716
|
if (parent) {
|
|
@@ -13862,7 +13728,9 @@ function swapInstances() {
|
|
|
13862
13728
|
}
|
|
13863
13729
|
}
|
|
13864
13730
|
if (instance.isHidden) unhideInstance(instance);
|
|
13865
|
-
if (isObject3D(instance.object)
|
|
13731
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13732
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13733
|
+
}
|
|
13866
13734
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
13867
13735
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
13868
13736
|
}
|
|
@@ -13871,9 +13739,13 @@ function swapInstances() {
|
|
|
13871
13739
|
const parent = instance.parent;
|
|
13872
13740
|
if (parent) {
|
|
13873
13741
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13742
|
+
const prevObject = instance.object;
|
|
13874
13743
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
13875
13744
|
instance.object.__r3f = instance;
|
|
13876
13745
|
setFiberRef(fiber, instance.object);
|
|
13746
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13747
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13748
|
+
}
|
|
13877
13749
|
delete instance.appliedOnce;
|
|
13878
13750
|
instance.eventCount = 0;
|
|
13879
13751
|
instance.handlers = {};
|
|
@@ -13893,14 +13765,114 @@ function swapInstances() {
|
|
|
13893
13765
|
invalidateInstance(instance);
|
|
13894
13766
|
}
|
|
13895
13767
|
}
|
|
13896
|
-
reconstructed.length = 0;
|
|
13897
13768
|
}
|
|
13898
13769
|
const handleTextInstance = () => {
|
|
13899
13770
|
};
|
|
13900
13771
|
const NO_CONTEXT = {};
|
|
13901
13772
|
let currentUpdatePriority = NoEventPriority;
|
|
13902
|
-
|
|
13903
|
-
|
|
13773
|
+
function getEventPriority(type) {
|
|
13774
|
+
switch (type) {
|
|
13775
|
+
case "beforetoggle":
|
|
13776
|
+
case "cancel":
|
|
13777
|
+
case "click":
|
|
13778
|
+
case "close":
|
|
13779
|
+
case "contextmenu":
|
|
13780
|
+
case "copy":
|
|
13781
|
+
case "cut":
|
|
13782
|
+
case "auxclick":
|
|
13783
|
+
case "dblclick":
|
|
13784
|
+
case "dragend":
|
|
13785
|
+
case "dragstart":
|
|
13786
|
+
case "drop":
|
|
13787
|
+
case "focusin":
|
|
13788
|
+
case "focusout":
|
|
13789
|
+
case "input":
|
|
13790
|
+
case "invalid":
|
|
13791
|
+
case "keydown":
|
|
13792
|
+
case "keypress":
|
|
13793
|
+
case "keyup":
|
|
13794
|
+
case "mousedown":
|
|
13795
|
+
case "mouseup":
|
|
13796
|
+
case "paste":
|
|
13797
|
+
case "pause":
|
|
13798
|
+
case "play":
|
|
13799
|
+
case "pointercancel":
|
|
13800
|
+
case "pointerdown":
|
|
13801
|
+
case "pointerup":
|
|
13802
|
+
case "ratechange":
|
|
13803
|
+
case "reset":
|
|
13804
|
+
case "resize":
|
|
13805
|
+
case "seeked":
|
|
13806
|
+
case "submit":
|
|
13807
|
+
case "touchcancel":
|
|
13808
|
+
case "touchend":
|
|
13809
|
+
case "touchstart":
|
|
13810
|
+
case "volumechange":
|
|
13811
|
+
case "change":
|
|
13812
|
+
case "selectionchange":
|
|
13813
|
+
case "compositionstart":
|
|
13814
|
+
case "compositionend":
|
|
13815
|
+
case "compositionupdate":
|
|
13816
|
+
case "beforeinput":
|
|
13817
|
+
case "blur":
|
|
13818
|
+
case "fullscreenchange":
|
|
13819
|
+
case "focus":
|
|
13820
|
+
case "hashchange":
|
|
13821
|
+
case "popstate":
|
|
13822
|
+
case "select":
|
|
13823
|
+
case "selectstart":
|
|
13824
|
+
return e;
|
|
13825
|
+
case "drag":
|
|
13826
|
+
case "dragenter":
|
|
13827
|
+
case "dragexit":
|
|
13828
|
+
case "dragleave":
|
|
13829
|
+
case "dragover":
|
|
13830
|
+
case "mousemove":
|
|
13831
|
+
case "mouseout":
|
|
13832
|
+
case "mouseover":
|
|
13833
|
+
case "pointermove":
|
|
13834
|
+
case "pointerout":
|
|
13835
|
+
case "pointerover":
|
|
13836
|
+
case "scroll":
|
|
13837
|
+
case "touchmove":
|
|
13838
|
+
case "wheel":
|
|
13839
|
+
case "mouseenter":
|
|
13840
|
+
case "mouseleave":
|
|
13841
|
+
case "pointerenter":
|
|
13842
|
+
case "pointerleave":
|
|
13843
|
+
return o;
|
|
13844
|
+
case "message": {
|
|
13845
|
+
switch (unstable_getCurrentPriorityLevel()) {
|
|
13846
|
+
case unstable_ImmediatePriority:
|
|
13847
|
+
return e;
|
|
13848
|
+
case unstable_UserBlockingPriority:
|
|
13849
|
+
return o;
|
|
13850
|
+
case unstable_NormalPriority:
|
|
13851
|
+
case unstable_LowPriority:
|
|
13852
|
+
return r;
|
|
13853
|
+
case unstable_IdlePriority:
|
|
13854
|
+
return i$1;
|
|
13855
|
+
default:
|
|
13856
|
+
return r;
|
|
13857
|
+
}
|
|
13858
|
+
}
|
|
13859
|
+
default:
|
|
13860
|
+
return r;
|
|
13861
|
+
}
|
|
13862
|
+
}
|
|
13863
|
+
function scheduleMicrotask(callback) {
|
|
13864
|
+
if (typeof queueMicrotask === "function") {
|
|
13865
|
+
queueMicrotask(callback);
|
|
13866
|
+
} else if (typeof Promise !== "undefined") {
|
|
13867
|
+
Promise.resolve().then(callback).catch((error) => {
|
|
13868
|
+
setTimeout(() => {
|
|
13869
|
+
throw error;
|
|
13870
|
+
});
|
|
13871
|
+
});
|
|
13872
|
+
} else {
|
|
13873
|
+
setTimeout(callback);
|
|
13874
|
+
}
|
|
13875
|
+
}
|
|
13904
13876
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
13905
13877
|
isPrimaryRenderer: false,
|
|
13906
13878
|
warnsIfNotActing: false,
|
|
@@ -13939,16 +13911,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13939
13911
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
13940
13912
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
13941
13913
|
if (reconstruct) {
|
|
13942
|
-
reconstructed.push([instance,
|
|
13914
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
13943
13915
|
} else {
|
|
13944
13916
|
const changedProps = diffProps(instance, newProps);
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
|
|
13917
|
+
const attach2 = instance.props.attach;
|
|
13918
|
+
instance.props = getInstanceProps(newProps);
|
|
13919
|
+
if (attach2 !== void 0) instance.props.attach = attach2;
|
|
13920
|
+
else delete instance.props.attach;
|
|
13921
|
+
if (Object.keys(changedProps).length) applyProps(instance.object, changedProps);
|
|
13949
13922
|
}
|
|
13950
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
13951
|
-
if (isTailSibling) swapInstances();
|
|
13952
13923
|
},
|
|
13953
13924
|
finalizeInitialChildren: (instance) => {
|
|
13954
13925
|
for (const prop in instance.props) {
|
|
@@ -13973,8 +13944,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13973
13944
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
13974
13945
|
return prepare(target, container, "", {});
|
|
13975
13946
|
},
|
|
13976
|
-
|
|
13977
|
-
|
|
13947
|
+
// Reconstructed instances are swapped once all mutations are committed,
|
|
13948
|
+
// before layout effects run so refs point to the new objects
|
|
13949
|
+
resetAfterCommit: flushReconstructedInstances,
|
|
13978
13950
|
shouldSetTextContent: () => false,
|
|
13979
13951
|
clearContainer: () => false,
|
|
13980
13952
|
hideInstance,
|
|
@@ -13982,6 +13954,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13982
13954
|
createTextInstance: handleTextInstance,
|
|
13983
13955
|
hideTextInstance: handleTextInstance,
|
|
13984
13956
|
unhideTextInstance: handleTextInstance,
|
|
13957
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
13958
|
+
supportsMicrotasks: true,
|
|
13959
|
+
scheduleMicrotask,
|
|
13985
13960
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
13986
13961
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
13987
13962
|
noTimeout: -1,
|
|
@@ -14022,28 +13997,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14022
13997
|
},
|
|
14023
13998
|
resolveUpdatePriority() {
|
|
14024
13999
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14025
|
-
|
|
14026
|
-
|
|
14027
|
-
|
|
14028
|
-
case "dblclick":
|
|
14029
|
-
case "dragenter":
|
|
14030
|
-
case "dragleave":
|
|
14031
|
-
case "drop":
|
|
14032
|
-
case "pointercancel":
|
|
14033
|
-
case "pointerdown":
|
|
14034
|
-
case "pointerup":
|
|
14035
|
-
return e;
|
|
14036
|
-
case "dragover":
|
|
14037
|
-
case "pointermove":
|
|
14038
|
-
case "pointerout":
|
|
14039
|
-
case "pointerover":
|
|
14040
|
-
case "pointerenter":
|
|
14041
|
-
case "pointerleave":
|
|
14042
|
-
case "wheel":
|
|
14043
|
-
return o;
|
|
14044
|
-
default:
|
|
14045
|
-
return r;
|
|
14046
|
-
}
|
|
14000
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
14001
|
+
if (eventType === void 0) return r;
|
|
14002
|
+
return getEventPriority(eventType);
|
|
14047
14003
|
},
|
|
14048
14004
|
resetFormInstance() {
|
|
14049
14005
|
},
|
|
@@ -14354,7 +14310,7 @@ function createRoot(canvas) {
|
|
|
14354
14310
|
const handleXRFrame = (timestamp, _frame) => {
|
|
14355
14311
|
const state2 = store.getState();
|
|
14356
14312
|
if (state2.frameloop === "never") return;
|
|
14357
|
-
advance(timestamp);
|
|
14313
|
+
advance(timestamp, true, state2);
|
|
14358
14314
|
};
|
|
14359
14315
|
const actualRenderer = state.internal.actualRenderer;
|
|
14360
14316
|
const handleSessionChange = () => {
|
|
@@ -14362,7 +14318,7 @@ function createRoot(canvas) {
|
|
|
14362
14318
|
const renderer2 = state2.internal.actualRenderer;
|
|
14363
14319
|
actualRenderer.xr.enabled = actualRenderer.xr.isPresenting;
|
|
14364
14320
|
renderer2.xr.setAnimationLoop(renderer2.xr.isPresenting ? handleXRFrame : null);
|
|
14365
|
-
if (!renderer2.xr.isPresenting) invalidate();
|
|
14321
|
+
if (!renderer2.xr.isPresenting) invalidate(state2);
|
|
14366
14322
|
};
|
|
14367
14323
|
const xr = {
|
|
14368
14324
|
connect() {
|
|
@@ -14444,7 +14400,11 @@ function createRoot(canvas) {
|
|
|
14444
14400
|
const newRootId = canvasId || scheduler.generateRootId();
|
|
14445
14401
|
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14446
14402
|
getState: () => store.getState(),
|
|
14447
|
-
onError: (err) => store.getState().setError(err)
|
|
14403
|
+
onError: (err) => store.getState().setError(err),
|
|
14404
|
+
frameloop: store.getState().frameloop,
|
|
14405
|
+
before: schedulerConfig?.before,
|
|
14406
|
+
after: schedulerConfig?.after,
|
|
14407
|
+
order: schedulerConfig?.order
|
|
14448
14408
|
});
|
|
14449
14409
|
const unregisterCanvasTarget = scheduler.register(
|
|
14450
14410
|
() => {
|
|
@@ -14452,6 +14412,10 @@ function createRoot(canvas) {
|
|
|
14452
14412
|
if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
|
|
14453
14413
|
const renderer2 = state2.internal.actualRenderer;
|
|
14454
14414
|
renderer2.setCanvasTarget(state2.internal.canvasTarget);
|
|
14415
|
+
if (state2.internal.canvasTargetSizeDirty) {
|
|
14416
|
+
state2.internal.canvasTargetSizeDirty = false;
|
|
14417
|
+
renderer2.backend?.updateSize?.();
|
|
14418
|
+
}
|
|
14455
14419
|
}
|
|
14456
14420
|
},
|
|
14457
14421
|
{
|
|
@@ -14520,8 +14484,7 @@ function createRoot(canvas) {
|
|
|
14520
14484
|
phase: "render",
|
|
14521
14485
|
system: true,
|
|
14522
14486
|
// Internal flag: this is a system job, not user-controlled
|
|
14523
|
-
//
|
|
14524
|
-
...schedulerConfig?.after && { after: schedulerConfig.after },
|
|
14487
|
+
// FPS throttles only the default render job; Canvas ordering belongs to the root.
|
|
14525
14488
|
...schedulerConfig?.fps && { fps: schedulerConfig.fps }
|
|
14526
14489
|
}
|
|
14527
14490
|
);
|
|
@@ -14540,8 +14503,21 @@ function createRoot(canvas) {
|
|
|
14540
14503
|
scheduler
|
|
14541
14504
|
}
|
|
14542
14505
|
}));
|
|
14506
|
+
} else {
|
|
14507
|
+
const constraintsChanged = !is.equ(schedulerConfig?.before, lastConfiguredProps.schedulerBefore, shallowLoose) || !is.equ(schedulerConfig?.after, lastConfiguredProps.schedulerAfter, shallowLoose);
|
|
14508
|
+
if (constraintsChanged) {
|
|
14509
|
+
scheduler.setRootConstraints(rootId, {
|
|
14510
|
+
before: schedulerConfig?.before,
|
|
14511
|
+
after: schedulerConfig?.after
|
|
14512
|
+
});
|
|
14513
|
+
}
|
|
14514
|
+
if (schedulerConfig?.order !== lastConfiguredProps.schedulerOrder) {
|
|
14515
|
+
scheduler.setRootOrder(rootId, schedulerConfig?.order ?? 0);
|
|
14516
|
+
}
|
|
14543
14517
|
}
|
|
14544
|
-
|
|
14518
|
+
lastConfiguredProps.schedulerBefore = schedulerConfig?.before;
|
|
14519
|
+
lastConfiguredProps.schedulerAfter = schedulerConfig?.after;
|
|
14520
|
+
lastConfiguredProps.schedulerOrder = schedulerConfig?.order;
|
|
14545
14521
|
onCreated = onCreatedCallback;
|
|
14546
14522
|
configured = true;
|
|
14547
14523
|
resolve();
|
|
@@ -14583,14 +14559,19 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14583
14559
|
const fiber = root?.fiber;
|
|
14584
14560
|
if (fiber) {
|
|
14585
14561
|
const state = root?.store.getState();
|
|
14586
|
-
if (state)
|
|
14562
|
+
if (state) {
|
|
14563
|
+
state.internal.active = false;
|
|
14564
|
+
const unregisterRoot = state.internal.unregisterRoot;
|
|
14565
|
+
if (unregisterRoot) {
|
|
14566
|
+
unregisterRoot();
|
|
14567
|
+
state.internal.unregisterRoot = void 0;
|
|
14568
|
+
}
|
|
14569
|
+
}
|
|
14587
14570
|
reconciler.updateContainer(null, fiber, null, () => {
|
|
14588
14571
|
if (state) {
|
|
14589
14572
|
setTimeout(() => {
|
|
14590
14573
|
try {
|
|
14591
14574
|
const renderer = state.internal.actualRenderer;
|
|
14592
|
-
const unregisterRoot = state.internal.unregisterRoot;
|
|
14593
|
-
if (unregisterRoot) unregisterRoot();
|
|
14594
14575
|
const unregisterPrimary = state.internal.unregisterPrimary;
|
|
14595
14576
|
if (unregisterPrimary) unregisterPrimary();
|
|
14596
14577
|
const canvasTarget = state.internal.canvasTarget;
|
|
@@ -14608,7 +14589,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14608
14589
|
dispose(state.scene);
|
|
14609
14590
|
_roots.delete(canvas);
|
|
14610
14591
|
if (callback) callback(canvas);
|
|
14611
|
-
} catch {
|
|
14592
|
+
} catch (error) {
|
|
14593
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
14612
14594
|
}
|
|
14613
14595
|
}, 500);
|
|
14614
14596
|
}
|
|
@@ -14719,6 +14701,212 @@ function flushSync(fn) {
|
|
|
14719
14701
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14720
14702
|
}
|
|
14721
14703
|
|
|
14704
|
+
const isRef = (obj) => obj.current && obj.current.isScene;
|
|
14705
|
+
const resolveScene = (scene) => isRef(scene) ? scene.current : scene;
|
|
14706
|
+
function setEnvProps(background, scene, defaultScene, texture, sceneProps = {}) {
|
|
14707
|
+
sceneProps = {
|
|
14708
|
+
backgroundBlurriness: 0,
|
|
14709
|
+
backgroundIntensity: 1,
|
|
14710
|
+
backgroundRotation: [0, 0, 0],
|
|
14711
|
+
environmentIntensity: 1,
|
|
14712
|
+
environmentRotation: [0, 0, 0],
|
|
14713
|
+
...sceneProps
|
|
14714
|
+
};
|
|
14715
|
+
const target = resolveScene(scene || defaultScene);
|
|
14716
|
+
const oldbg = target.background;
|
|
14717
|
+
const oldenv = target.environment;
|
|
14718
|
+
const oldSceneProps = {
|
|
14719
|
+
// @ts-ignore
|
|
14720
|
+
backgroundBlurriness: target.backgroundBlurriness,
|
|
14721
|
+
// @ts-ignore
|
|
14722
|
+
backgroundIntensity: target.backgroundIntensity,
|
|
14723
|
+
// @ts-ignore
|
|
14724
|
+
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
14725
|
+
// @ts-ignore
|
|
14726
|
+
environmentIntensity: target.environmentIntensity,
|
|
14727
|
+
// @ts-ignore
|
|
14728
|
+
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
14729
|
+
};
|
|
14730
|
+
if (background !== "only") target.environment = texture;
|
|
14731
|
+
if (background) target.background = texture;
|
|
14732
|
+
applyProps(target, sceneProps);
|
|
14733
|
+
return () => {
|
|
14734
|
+
if (background !== "only") target.environment = oldenv;
|
|
14735
|
+
if (background) target.background = oldbg;
|
|
14736
|
+
applyProps(target, oldSceneProps);
|
|
14737
|
+
};
|
|
14738
|
+
}
|
|
14739
|
+
function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
14740
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14741
|
+
React.useLayoutEffect(() => {
|
|
14742
|
+
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
14743
|
+
});
|
|
14744
|
+
return null;
|
|
14745
|
+
}
|
|
14746
|
+
function EnvironmentCube({
|
|
14747
|
+
background = false,
|
|
14748
|
+
scene,
|
|
14749
|
+
blur,
|
|
14750
|
+
backgroundBlurriness,
|
|
14751
|
+
backgroundIntensity,
|
|
14752
|
+
backgroundRotation,
|
|
14753
|
+
environmentIntensity,
|
|
14754
|
+
environmentRotation,
|
|
14755
|
+
...rest
|
|
14756
|
+
}) {
|
|
14757
|
+
const texture = useEnvironment(rest);
|
|
14758
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14759
|
+
React.useLayoutEffect(() => {
|
|
14760
|
+
return setEnvProps(background, scene, defaultScene, texture, {
|
|
14761
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
14762
|
+
backgroundIntensity,
|
|
14763
|
+
backgroundRotation,
|
|
14764
|
+
environmentIntensity,
|
|
14765
|
+
environmentRotation
|
|
14766
|
+
});
|
|
14767
|
+
});
|
|
14768
|
+
React.useEffect(() => {
|
|
14769
|
+
return () => {
|
|
14770
|
+
texture.dispose();
|
|
14771
|
+
};
|
|
14772
|
+
}, [texture]);
|
|
14773
|
+
return null;
|
|
14774
|
+
}
|
|
14775
|
+
function EnvironmentPortal({
|
|
14776
|
+
children,
|
|
14777
|
+
near = 0.1,
|
|
14778
|
+
far = 1e3,
|
|
14779
|
+
resolution = 256,
|
|
14780
|
+
frames = 1,
|
|
14781
|
+
map,
|
|
14782
|
+
background = false,
|
|
14783
|
+
blur,
|
|
14784
|
+
backgroundBlurriness,
|
|
14785
|
+
backgroundIntensity,
|
|
14786
|
+
backgroundRotation,
|
|
14787
|
+
environmentIntensity,
|
|
14788
|
+
environmentRotation,
|
|
14789
|
+
scene,
|
|
14790
|
+
files,
|
|
14791
|
+
path,
|
|
14792
|
+
preset = void 0,
|
|
14793
|
+
extensions
|
|
14794
|
+
}) {
|
|
14795
|
+
const renderer = useThree((state) => state.renderer);
|
|
14796
|
+
const isLegacy = useThree((state) => state.isLegacy);
|
|
14797
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14798
|
+
const camera = React.useRef(null);
|
|
14799
|
+
const [virtualScene] = React.useState(() => new Scene());
|
|
14800
|
+
const fbo = React.useMemo(() => {
|
|
14801
|
+
const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
|
|
14802
|
+
fbo2.texture.type = HalfFloatType;
|
|
14803
|
+
return fbo2;
|
|
14804
|
+
}, [resolution, isLegacy]);
|
|
14805
|
+
React.useEffect(() => {
|
|
14806
|
+
return () => {
|
|
14807
|
+
fbo.dispose();
|
|
14808
|
+
};
|
|
14809
|
+
}, [fbo]);
|
|
14810
|
+
React.useLayoutEffect(() => {
|
|
14811
|
+
if (frames === 1) {
|
|
14812
|
+
const autoClear = renderer.autoClear;
|
|
14813
|
+
renderer.autoClear = true;
|
|
14814
|
+
camera.current.update(renderer, virtualScene);
|
|
14815
|
+
renderer.autoClear = autoClear;
|
|
14816
|
+
}
|
|
14817
|
+
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
14818
|
+
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
14819
|
+
backgroundIntensity,
|
|
14820
|
+
backgroundRotation,
|
|
14821
|
+
environmentIntensity,
|
|
14822
|
+
environmentRotation
|
|
14823
|
+
});
|
|
14824
|
+
}, [
|
|
14825
|
+
children,
|
|
14826
|
+
virtualScene,
|
|
14827
|
+
fbo.texture,
|
|
14828
|
+
scene,
|
|
14829
|
+
defaultScene,
|
|
14830
|
+
background,
|
|
14831
|
+
frames,
|
|
14832
|
+
renderer,
|
|
14833
|
+
blur,
|
|
14834
|
+
backgroundBlurriness,
|
|
14835
|
+
backgroundIntensity,
|
|
14836
|
+
backgroundRotation,
|
|
14837
|
+
environmentIntensity,
|
|
14838
|
+
environmentRotation
|
|
14839
|
+
]);
|
|
14840
|
+
let count = 1;
|
|
14841
|
+
useFrame(() => {
|
|
14842
|
+
if (frames === Infinity || count < frames) {
|
|
14843
|
+
const autoClear = renderer.autoClear;
|
|
14844
|
+
renderer.autoClear = true;
|
|
14845
|
+
camera.current.update(renderer, virtualScene);
|
|
14846
|
+
renderer.autoClear = autoClear;
|
|
14847
|
+
count++;
|
|
14848
|
+
}
|
|
14849
|
+
});
|
|
14850
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal(
|
|
14851
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14852
|
+
children,
|
|
14853
|
+
/* @__PURE__ */ jsx("cubeCamera", { ref: camera, args: [near, far, fbo] }),
|
|
14854
|
+
files || preset ? /* @__PURE__ */ jsx(EnvironmentCube, { background: true, files, preset, path, extensions }) : map ? /* @__PURE__ */ jsx(EnvironmentMap, { background: true, map, extensions }) : null
|
|
14855
|
+
] }),
|
|
14856
|
+
virtualScene
|
|
14857
|
+
) });
|
|
14858
|
+
}
|
|
14859
|
+
function EnvironmentGround(props) {
|
|
14860
|
+
const textureDefault = useEnvironment(props);
|
|
14861
|
+
const texture = props.map || textureDefault;
|
|
14862
|
+
React.useMemo(() => extend({ GroundProjectedEnvImpl: GroundedSkybox }), []);
|
|
14863
|
+
React.useEffect(() => {
|
|
14864
|
+
return () => {
|
|
14865
|
+
textureDefault.dispose();
|
|
14866
|
+
};
|
|
14867
|
+
}, [textureDefault]);
|
|
14868
|
+
const height = props.ground?.height ?? 15;
|
|
14869
|
+
const radius = props.ground?.radius ?? 60;
|
|
14870
|
+
const scale = props.ground?.scale ?? 1e3;
|
|
14871
|
+
const args = React.useMemo(
|
|
14872
|
+
() => [texture, height, radius],
|
|
14873
|
+
[texture, height, radius]
|
|
14874
|
+
);
|
|
14875
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14876
|
+
/* @__PURE__ */ jsx(EnvironmentMap, { ...props, map: texture }),
|
|
14877
|
+
/* @__PURE__ */ jsx("groundProjectedEnvImpl", { args, scale })
|
|
14878
|
+
] });
|
|
14879
|
+
}
|
|
14880
|
+
function EnvironmentColor({ color, scene }) {
|
|
14881
|
+
const defaultScene = useThree((state) => state.scene);
|
|
14882
|
+
React.useLayoutEffect(() => {
|
|
14883
|
+
if (color === void 0) return;
|
|
14884
|
+
const target = resolveScene(scene || defaultScene);
|
|
14885
|
+
const oldBg = target.background;
|
|
14886
|
+
target.background = new Color(color);
|
|
14887
|
+
return () => {
|
|
14888
|
+
target.background = oldBg;
|
|
14889
|
+
};
|
|
14890
|
+
});
|
|
14891
|
+
return null;
|
|
14892
|
+
}
|
|
14893
|
+
function EnvironmentDualSource(props) {
|
|
14894
|
+
const { backgroundFiles, ...envProps } = props;
|
|
14895
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14896
|
+
/* @__PURE__ */ jsx(EnvironmentCube, { ...envProps, background: false }),
|
|
14897
|
+
/* @__PURE__ */ jsx(EnvironmentCube, { ...props, files: backgroundFiles, background: "only" })
|
|
14898
|
+
] });
|
|
14899
|
+
}
|
|
14900
|
+
function Environment(props) {
|
|
14901
|
+
if (props.color && !props.files && !props.preset && !props.map) {
|
|
14902
|
+
return /* @__PURE__ */ jsx(EnvironmentColor, { ...props });
|
|
14903
|
+
}
|
|
14904
|
+
if (props.backgroundFiles && props.backgroundFiles !== props.files) {
|
|
14905
|
+
return /* @__PURE__ */ jsx(EnvironmentDualSource, { ...props });
|
|
14906
|
+
}
|
|
14907
|
+
return props.ground ? /* @__PURE__ */ jsx(EnvironmentGround, { ...props }) : props.map ? /* @__PURE__ */ jsx(EnvironmentMap, { ...props }) : props.children ? /* @__PURE__ */ jsx(EnvironmentPortal, { ...props }) : /* @__PURE__ */ jsx(EnvironmentCube, { ...props });
|
|
14908
|
+
}
|
|
14909
|
+
|
|
14722
14910
|
function parseBackground(background) {
|
|
14723
14911
|
if (!background) return null;
|
|
14724
14912
|
if (typeof background === "object" && !background.isColor) {
|
|
@@ -14762,14 +14950,36 @@ function parseRendererConfig(rendererProp) {
|
|
|
14762
14950
|
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14763
14951
|
}
|
|
14764
14952
|
|
|
14953
|
+
const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
|
|
14954
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
14955
|
+
function getKindRegistry(store, kind) {
|
|
14956
|
+
let registry = registries.get(store);
|
|
14957
|
+
if (!registry) {
|
|
14958
|
+
registry = {
|
|
14959
|
+
nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14960
|
+
uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14961
|
+
buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
|
|
14962
|
+
gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
|
|
14963
|
+
};
|
|
14964
|
+
registries.set(store, registry);
|
|
14965
|
+
}
|
|
14966
|
+
return registry[kind];
|
|
14967
|
+
}
|
|
14968
|
+
function invalidateResource(store, kind, scopeKey) {
|
|
14969
|
+
const registry = getKindRegistry(store, kind);
|
|
14970
|
+
{
|
|
14971
|
+
registry.valid.clear();
|
|
14972
|
+
registry.staged.clear();
|
|
14973
|
+
}
|
|
14974
|
+
}
|
|
14975
|
+
function invalidateAllResources(store) {
|
|
14976
|
+
for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
|
|
14977
|
+
}
|
|
14978
|
+
|
|
14765
14979
|
function clearHmrCaches(store) {
|
|
14766
|
-
store.
|
|
14767
|
-
|
|
14768
|
-
|
|
14769
|
-
buffers: {},
|
|
14770
|
-
gpuStorage: {},
|
|
14771
|
-
_hmrVersion: state._hmrVersion + 1
|
|
14772
|
-
}));
|
|
14980
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14981
|
+
invalidateAllResources(primary);
|
|
14982
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14773
14983
|
}
|
|
14774
14984
|
|
|
14775
14985
|
function CanvasImpl({
|
|
@@ -14906,7 +15116,7 @@ function CanvasImpl({
|
|
|
14906
15116
|
onDropMissed: (...args) => handleDropMissed.current?.(...args),
|
|
14907
15117
|
onCreated: (state) => {
|
|
14908
15118
|
state.events.connect?.(
|
|
14909
|
-
eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15119
|
+
eventSource ? isRef$1(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
14910
15120
|
);
|
|
14911
15121
|
if (eventPrefix) {
|
|
14912
15122
|
state.setEvents({
|
|
@@ -14955,6 +15165,7 @@ function CanvasImpl({
|
|
|
14955
15165
|
const canvas = canvasRef.current;
|
|
14956
15166
|
if (canvas) {
|
|
14957
15167
|
return () => {
|
|
15168
|
+
if (canvas.isConnected) return;
|
|
14958
15169
|
unmountComponentAtNode(canvas);
|
|
14959
15170
|
root.current = null;
|
|
14960
15171
|
};
|
|
@@ -15019,4 +15230,4 @@ function Canvas(props) {
|
|
|
15019
15230
|
|
|
15020
15231
|
extend(THREE);
|
|
15021
15232
|
|
|
15022
|
-
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,
|
|
15233
|
+
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 };
|