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