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