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