@react-three/fiber 10.0.0-canary.5c62eb9 → 10.0.0-canary.5d86b8f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2314 -2080
- package/dist/index.d.cts +71 -35
- package/dist/index.d.mts +71 -35
- package/dist/index.d.ts +71 -35
- package/dist/index.mjs +2317 -2083
- package/dist/legacy.cjs +2268 -2034
- package/dist/legacy.d.cts +71 -34
- package/dist/legacy.d.mts +71 -34
- package/dist/legacy.d.ts +71 -34
- package/dist/legacy.mjs +2270 -2036
- package/dist/webgpu/index.cjs +2602 -2609
- package/dist/webgpu/index.d.cts +105 -39
- package/dist/webgpu/index.d.mts +105 -39
- package/dist/webgpu/index.d.ts +105 -39
- package/dist/webgpu/index.mjs +2605 -2612
- package/package.json +3 -3
- package/readme.md +0 -1
package/dist/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,1327 +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
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
928
|
+
return;
|
|
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
|
+
}
|
|
1238
1000
|
};
|
|
1239
|
-
|
|
1240
|
-
|
|
1001
|
+
},
|
|
1002
|
+
// Renderer Storage (single source of truth)
|
|
1003
|
+
actualRenderer: null,
|
|
1004
|
+
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1005
|
+
scheduler: null
|
|
1006
|
+
}
|
|
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
|
+
});
|
|
1241
1022
|
}
|
|
1242
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
|
+
}
|
|
1243
1051
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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);
|
|
1264
1073
|
}
|
|
1265
1074
|
}
|
|
1266
1075
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
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);
|
|
1086
|
+
}
|
|
1278
1087
|
}
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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);
|
|
1284
1101
|
}
|
|
1102
|
+
return loader;
|
|
1285
1103
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
handlers.onPointerLeave?.(data);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
internal.pointerMap.delete(pointerId);
|
|
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
|
+
});
|
|
1301
1115
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
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
|
-
function
|
|
1655
|
-
|
|
1656
|
-
const
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
const
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
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);
|
|
1680
1354
|
}
|
|
1355
|
+
textureArray.forEach((texture) => {
|
|
1356
|
+
if (texture instanceof webgpu.Texture) {
|
|
1357
|
+
renderer.initTexture(texture);
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1681
1360
|
}
|
|
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
|
-
onDropMissed: void 0,
|
|
1722
|
-
performance: {
|
|
1723
|
-
current: 1,
|
|
1724
|
-
min: 0.5,
|
|
1725
|
-
max: 1,
|
|
1726
|
-
debounce: 200,
|
|
1727
|
-
regress: () => {
|
|
1728
|
-
const state2 = get();
|
|
1729
|
-
if (performanceTimeout) clearTimeout(performanceTimeout);
|
|
1730
|
-
if (state2.performance.current !== state2.performance.min) setPerformanceCurrent(state2.performance.min);
|
|
1731
|
-
performanceTimeout = setTimeout(
|
|
1732
|
-
() => setPerformanceCurrent(get().performance.max),
|
|
1733
|
-
state2.performance.debounce
|
|
1734
|
-
);
|
|
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);
|
|
1735
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;
|
|
1736
1439
|
},
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
top: 0,
|
|
1744
|
-
left: 0,
|
|
1745
|
-
aspect: 0,
|
|
1746
|
-
distance: 0,
|
|
1747
|
-
factor: 0,
|
|
1748
|
-
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;
|
|
1749
1446
|
},
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
const currentSize = state2.size;
|
|
1759
|
-
const newSize = {
|
|
1760
|
-
width: propW ?? currentSize.width,
|
|
1761
|
-
height: propH ?? currentSize.height,
|
|
1762
|
-
top: currentSize.top,
|
|
1763
|
-
left: currentSize.left
|
|
1764
|
-
};
|
|
1765
|
-
set((s) => ({
|
|
1766
|
-
size: newSize,
|
|
1767
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
1768
|
-
}));
|
|
1769
|
-
scheduler.getScheduler().invalidate();
|
|
1770
|
-
}
|
|
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]);
|
|
1771
1455
|
}
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
const w = width;
|
|
1775
|
-
const h = height ?? width;
|
|
1776
|
-
const t = top ?? state2.size.top;
|
|
1777
|
-
const l = left ?? state2.size.left;
|
|
1778
|
-
const size = { width: w, height: h, top: t, left: l };
|
|
1779
|
-
set((s) => ({
|
|
1780
|
-
size,
|
|
1781
|
-
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
1782
|
-
_sizeImperative: true
|
|
1783
|
-
}));
|
|
1784
|
-
scheduler.getScheduler().invalidate();
|
|
1785
|
-
},
|
|
1786
|
-
setDpr: (dpr) => set((state2) => {
|
|
1787
|
-
const resolved = calculateDpr(dpr);
|
|
1788
|
-
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
1789
|
-
}),
|
|
1790
|
-
setFrameloop: (frameloop = "always") => {
|
|
1791
|
-
set(() => ({ frameloop }));
|
|
1456
|
+
return { textures };
|
|
1457
|
+
});
|
|
1792
1458
|
},
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
_textureRefs: /* @__PURE__ */ new Map(),
|
|
1802
|
-
renderPipeline: null,
|
|
1803
|
-
passes: {},
|
|
1804
|
-
_hmrVersion: 0,
|
|
1805
|
-
_sizeImperative: false,
|
|
1806
|
-
_sizeProps: null,
|
|
1807
|
-
previousRoot: void 0,
|
|
1808
|
-
internal: {
|
|
1809
|
-
// Events
|
|
1810
|
-
interaction: [],
|
|
1811
|
-
subscribers: [],
|
|
1812
|
-
// Per-pointer state (new unified structure)
|
|
1813
|
-
pointerMap: /* @__PURE__ */ new Map(),
|
|
1814
|
-
pointerDirty: /* @__PURE__ */ new Map(),
|
|
1815
|
-
lastEvent: React__namespace.createRef(),
|
|
1816
|
-
// Deprecated but kept for backwards compatibility
|
|
1817
|
-
hovered: /* @__PURE__ */ new Map(),
|
|
1818
|
-
initialClick: [0, 0],
|
|
1819
|
-
initialHits: [],
|
|
1820
|
-
capturedMap: /* @__PURE__ */ new Map(),
|
|
1821
|
-
// Visibility tracking (onFramed, onOccluded, onVisible)
|
|
1822
|
-
visibilityRegistry: /* @__PURE__ */ new Map(),
|
|
1823
|
-
// Occlusion system (WebGPU only)
|
|
1824
|
-
occlusionEnabled: false,
|
|
1825
|
-
occlusionObserver: null,
|
|
1826
|
-
occlusionCache: /* @__PURE__ */ new Map(),
|
|
1827
|
-
helperGroup: null,
|
|
1828
|
-
// Updates
|
|
1829
|
-
active: false,
|
|
1830
|
-
frames: 0,
|
|
1831
|
-
priority: 0,
|
|
1832
|
-
subscribe: (ref, priority, store) => {
|
|
1833
|
-
const internal = get().internal;
|
|
1834
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1835
|
-
internal.subscribers.push({ ref, priority, store });
|
|
1836
|
-
internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
|
|
1837
|
-
return () => {
|
|
1838
|
-
const internal2 = get().internal;
|
|
1839
|
-
if (internal2?.subscribers) {
|
|
1840
|
-
internal2.priority = internal2.priority - (priority > 0 ? 1 : 0);
|
|
1841
|
-
internal2.subscribers = internal2.subscribers.filter((s) => s.ref !== ref);
|
|
1842
|
-
}
|
|
1843
|
-
};
|
|
1844
|
-
},
|
|
1845
|
-
// Renderer Storage (single source of truth)
|
|
1846
|
-
actualRenderer: null,
|
|
1847
|
-
// Scheduler for useFrameNext (initialized in renderer.tsx)
|
|
1848
|
-
scheduler: null
|
|
1849
|
-
}
|
|
1850
|
-
};
|
|
1851
|
-
return rootState;
|
|
1852
|
-
});
|
|
1853
|
-
const state = rootStore.getState();
|
|
1854
|
-
Object.defineProperty(state, "gl", {
|
|
1855
|
-
get() {
|
|
1856
|
-
const currentState = rootStore.getState();
|
|
1857
|
-
if (!currentState.isLegacy && currentState.internal.actualRenderer) {
|
|
1858
|
-
const stack = new Error().stack || "";
|
|
1859
|
-
if (!isInternalRendererAccess(stack)) {
|
|
1860
|
-
const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
|
|
1861
|
-
notifyDepreciated({
|
|
1862
|
-
heading: "Accessing state.gl in WebGPU mode",
|
|
1863
|
-
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
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
return currentState.internal.actualRenderer;
|
|
1868
|
-
},
|
|
1869
|
-
set(value) {
|
|
1870
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1871
|
-
},
|
|
1872
|
-
enumerable: true,
|
|
1873
|
-
configurable: true
|
|
1874
|
-
});
|
|
1875
|
-
Object.defineProperty(state, "renderer", {
|
|
1876
|
-
get() {
|
|
1877
|
-
return rootStore.getState().internal.actualRenderer;
|
|
1878
|
-
},
|
|
1879
|
-
set(value) {
|
|
1880
|
-
rootStore.getState().internal.actualRenderer = value;
|
|
1881
|
-
},
|
|
1882
|
-
enumerable: true,
|
|
1883
|
-
configurable: true
|
|
1884
|
-
});
|
|
1885
|
-
let oldScene = state.scene;
|
|
1886
|
-
rootStore.subscribe(() => {
|
|
1887
|
-
const currentState = rootStore.getState();
|
|
1888
|
-
const { scene, rootScene, set } = currentState;
|
|
1889
|
-
if (scene !== oldScene) {
|
|
1890
|
-
oldScene = scene;
|
|
1891
|
-
if (scene?.isScene && scene !== rootScene) {
|
|
1892
|
-
set({ rootScene: scene });
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
});
|
|
1896
|
-
let oldSize = state.size;
|
|
1897
|
-
let oldDpr = state.viewport.dpr;
|
|
1898
|
-
let oldCamera = state.camera;
|
|
1899
|
-
rootStore.subscribe(() => {
|
|
1900
|
-
const { camera, size, viewport, set, internal } = rootStore.getState();
|
|
1901
|
-
const actualRenderer = internal.actualRenderer;
|
|
1902
|
-
const canvasTarget = internal.canvasTarget;
|
|
1903
|
-
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
|
|
1904
|
-
oldSize = size;
|
|
1905
|
-
oldDpr = viewport.dpr;
|
|
1906
|
-
updateCamera(camera, size);
|
|
1907
|
-
if (internal.isSecondary && canvasTarget) {
|
|
1908
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1909
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1910
|
-
} else {
|
|
1911
|
-
if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
|
|
1912
|
-
actualRenderer.setSize(size.width, size.height, false);
|
|
1913
|
-
if (canvasTarget) {
|
|
1914
|
-
if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
|
|
1915
|
-
canvasTarget.setSize(size.width, size.height, false);
|
|
1459
|
+
dispose(key, options) {
|
|
1460
|
+
const state = getState();
|
|
1461
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
1462
|
+
if (refs > 0 && !options?.force) {
|
|
1463
|
+
console.warn(
|
|
1464
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
1465
|
+
);
|
|
1466
|
+
return false;
|
|
1916
1467
|
}
|
|
1468
|
+
state.textures.get(key)?.dispose();
|
|
1469
|
+
setState((s) => {
|
|
1470
|
+
const textures = new Map(s.textures);
|
|
1471
|
+
textures.delete(key);
|
|
1472
|
+
const nextRefs = new Map(s._textureRefs);
|
|
1473
|
+
nextRefs.delete(key);
|
|
1474
|
+
return { textures, _textureRefs: nextRefs };
|
|
1475
|
+
});
|
|
1476
|
+
return true;
|
|
1477
|
+
},
|
|
1478
|
+
disposeAll() {
|
|
1479
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
1480
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
1917
1481
|
}
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
}
|
|
1925
|
-
set((state2) => ({ viewport: { ...state2.viewport, ...state2.viewport.getCurrentViewport(camera) } }));
|
|
1926
|
-
const currentState = rootStore.getState();
|
|
1927
|
-
if (currentState.autoUpdateFrustum && camera) {
|
|
1928
|
-
updateFrustum(camera, currentState.frustum);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
});
|
|
1932
|
-
rootStore.subscribe((state2) => invalidate(state2));
|
|
1933
|
-
return rootStore;
|
|
1934
|
-
};
|
|
1482
|
+
};
|
|
1483
|
+
}, [store]);
|
|
1484
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
1485
|
+
const selected = useThree(subscribe);
|
|
1486
|
+
return selector ? selected : registry;
|
|
1487
|
+
}
|
|
1935
1488
|
|
|
1936
|
-
|
|
1937
|
-
const
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
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;
|
|
1944
1507
|
}
|
|
1945
|
-
return loader;
|
|
1946
1508
|
}
|
|
1947
|
-
return
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
if (extensions) extensions(loader);
|
|
1953
|
-
if ("loadAsync" in loader && typeof loader.loadAsync === "function") {
|
|
1954
|
-
return loader.loadAsync(input, onProgress).then((data) => {
|
|
1955
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1956
|
-
return data;
|
|
1957
|
-
});
|
|
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);
|
|
1958
1514
|
}
|
|
1959
|
-
|
|
1960
|
-
(res, reject) => loader.load(
|
|
1961
|
-
input,
|
|
1962
|
-
(data) => {
|
|
1963
|
-
if (isObject3D(data?.scene)) Object.assign(data, buildGraph(data.scene));
|
|
1964
|
-
res(data);
|
|
1965
|
-
},
|
|
1966
|
-
onProgress,
|
|
1967
|
-
(error) => reject(new Error(`Could not load ${input}: ${error?.message}`))
|
|
1968
|
-
)
|
|
1969
|
-
);
|
|
1970
|
-
};
|
|
1971
|
-
}
|
|
1972
|
-
function useLoader(loader, input, extensions, onProgress) {
|
|
1973
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1974
|
-
const fn = loadingFn(extensions, onProgress);
|
|
1975
|
-
const results = keys.map((key) => suspendReact.suspend(fn, [loader, key], { equal: is.equ }));
|
|
1976
|
-
return Array.isArray(input) ? results : results[0];
|
|
1515
|
+
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
1977
1516
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
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"
|
|
1985
1529
|
};
|
|
1986
|
-
useLoader.loader = getLoader;
|
|
1987
1530
|
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
}
|
|
2022
|
-
notifyDepreciated({
|
|
2023
|
-
heading: "useFrame with numeric priority is deprecated",
|
|
2024
|
-
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 })',
|
|
2025
|
-
link: "https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe"
|
|
2026
|
-
});
|
|
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);
|
|
2027
1564
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
const mergedState = {
|
|
2031
|
-
...localState,
|
|
2032
|
-
time: frameState.time,
|
|
2033
|
-
delta: frameState.delta,
|
|
2034
|
-
elapsed: frameState.elapsed,
|
|
2035
|
-
frame: frameState.frame
|
|
2036
|
-
};
|
|
2037
|
-
callbackRef.current?.(mergedState, delta);
|
|
2038
|
-
};
|
|
2039
|
-
const unregister = scheduler$1.register(wrappedCallback, {
|
|
2040
|
-
id,
|
|
2041
|
-
rootId,
|
|
2042
|
-
...options
|
|
2043
|
-
});
|
|
2044
|
-
return () => {
|
|
2045
|
-
unregister();
|
|
2046
|
-
if (isLegacyPriority) {
|
|
2047
|
-
const currentState = store.getState();
|
|
2048
|
-
if (currentState.internal) {
|
|
2049
|
-
currentState.internal.priority--;
|
|
2050
|
-
let parentRoot = currentState.previousRoot;
|
|
2051
|
-
while (parentRoot) {
|
|
2052
|
-
const parentState = parentRoot.getState();
|
|
2053
|
-
if (parentState?.internal) parentState.internal.priority--;
|
|
2054
|
-
parentRoot = parentState?.previousRoot;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
};
|
|
2059
|
-
} else {
|
|
2060
|
-
return scheduler$1.register(
|
|
2061
|
-
(state, delta) => {
|
|
2062
|
-
const frameState = state;
|
|
2063
|
-
if (!frameState.renderer) return;
|
|
2064
|
-
callbackRef.current?.(frameState, delta);
|
|
2065
|
-
},
|
|
2066
|
-
{ id, ...options }
|
|
2067
|
-
);
|
|
1565
|
+
loader2.setPath?.(path);
|
|
1566
|
+
if (extensions) extensions(loader2);
|
|
2068
1567
|
}
|
|
2069
|
-
}, [store, scheduler$1, id, optionsKey, isLegacyPriority, isInsideCanvas]);
|
|
2070
|
-
const isPaused = React__namespace.useSyncExternalStore(
|
|
2071
|
-
// Subscribe function
|
|
2072
|
-
React__namespace.useCallback(
|
|
2073
|
-
(onStoreChange) => {
|
|
2074
|
-
return scheduler.getScheduler().subscribeJobState(id, onStoreChange);
|
|
2075
|
-
},
|
|
2076
|
-
[id]
|
|
2077
|
-
),
|
|
2078
|
-
// getSnapshot function
|
|
2079
|
-
React__namespace.useCallback(() => scheduler.getScheduler().isJobPaused(id), [id]),
|
|
2080
|
-
// getServerSnapshot function (SSR)
|
|
2081
|
-
React__namespace.useCallback(() => false, [])
|
|
2082
1568
|
);
|
|
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
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
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;
|
|
2130
1636
|
}
|
|
2131
1637
|
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
if (
|
|
2135
|
-
|
|
2136
|
-
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;
|
|
2137
1642
|
}
|
|
2138
|
-
function
|
|
2139
|
-
return
|
|
1643
|
+
function useThree(selector = (state) => state, equalityFn) {
|
|
1644
|
+
return useStore()(selector, equalityFn);
|
|
2140
1645
|
}
|
|
2141
|
-
function
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
return input.map((url) => textureCache.get(url));
|
|
2146
|
-
} else {
|
|
2147
|
-
const result = {};
|
|
2148
|
-
const objInput = input;
|
|
2149
|
-
for (const key in objInput) {
|
|
2150
|
-
result[key] = textureCache.get(objInput[key]);
|
|
2151
|
-
}
|
|
2152
|
-
return result;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
function useTexture(input, optionsOrOnLoad) {
|
|
2156
|
-
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
2157
|
-
const store = useStore();
|
|
2158
|
-
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
2159
|
-
const { onLoad, cache = true } = options;
|
|
2160
|
-
const onLoadRef = React.useRef(onLoad);
|
|
2161
|
-
onLoadRef.current = onLoad;
|
|
2162
|
-
const onLoadCalledForRef = React.useRef(null);
|
|
2163
|
-
const urls = React.useMemo(() => getUrls(input), [input]);
|
|
2164
|
-
const cachedResult = React.useMemo(() => {
|
|
2165
|
-
if (!cache) return null;
|
|
2166
|
-
const textures = store.getState().textures;
|
|
2167
|
-
if (!allUrlsCached(urls, textures)) return null;
|
|
2168
|
-
return buildFromCache(input, textures);
|
|
2169
|
-
}, [cache, urls, input, store]);
|
|
2170
|
-
const loadedTextures = useLoader(
|
|
2171
|
-
webgpu.TextureLoader,
|
|
2172
|
-
IsObject(input) ? Object.values(input) : input
|
|
2173
|
-
);
|
|
2174
|
-
const inputKey = urls.join("\0");
|
|
2175
|
-
React.useLayoutEffect(() => {
|
|
2176
|
-
if (cachedResult) return;
|
|
2177
|
-
if (onLoadCalledForRef.current === inputKey) return;
|
|
2178
|
-
onLoadCalledForRef.current = inputKey;
|
|
2179
|
-
onLoadRef.current?.(loadedTextures);
|
|
2180
|
-
}, [cachedResult, loadedTextures, inputKey]);
|
|
2181
|
-
React.useEffect(() => {
|
|
2182
|
-
if (cachedResult) return;
|
|
2183
|
-
if ("initTexture" in renderer) {
|
|
2184
|
-
let textureArray = [];
|
|
2185
|
-
if (Array.isArray(loadedTextures)) {
|
|
2186
|
-
textureArray = loadedTextures;
|
|
2187
|
-
} else if (loadedTextures instanceof webgpu.Texture) {
|
|
2188
|
-
textureArray = [loadedTextures];
|
|
2189
|
-
} else if (IsObject(loadedTextures)) {
|
|
2190
|
-
textureArray = Object.values(loadedTextures);
|
|
2191
|
-
}
|
|
2192
|
-
textureArray.forEach((texture) => {
|
|
2193
|
-
if (texture instanceof webgpu.Texture) {
|
|
2194
|
-
renderer.initTexture(texture);
|
|
2195
|
-
}
|
|
2196
|
-
});
|
|
2197
|
-
}
|
|
2198
|
-
}, [renderer, loadedTextures, cachedResult]);
|
|
2199
|
-
const mappedTextures = React.useMemo(() => {
|
|
2200
|
-
if (cachedResult) return cachedResult;
|
|
2201
|
-
if (IsObject(input)) {
|
|
2202
|
-
const keyed = {};
|
|
2203
|
-
const textureArray = loadedTextures;
|
|
2204
|
-
let i = 0;
|
|
2205
|
-
for (const key in input) keyed[key] = textureArray[i++];
|
|
2206
|
-
return keyed;
|
|
2207
|
-
} else {
|
|
2208
|
-
return loadedTextures;
|
|
2209
|
-
}
|
|
2210
|
-
}, [input, loadedTextures, cachedResult]);
|
|
2211
|
-
React.useEffect(() => {
|
|
2212
|
-
if (!cache) return;
|
|
2213
|
-
const urlTextureMap = [];
|
|
2214
|
-
if (typeof input === "string") {
|
|
2215
|
-
urlTextureMap.push([input, mappedTextures]);
|
|
2216
|
-
} else if (Array.isArray(input)) {
|
|
2217
|
-
const textureArray = mappedTextures;
|
|
2218
|
-
input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
|
|
2219
|
-
} else if (IsObject(input)) {
|
|
2220
|
-
const textureRecord = mappedTextures;
|
|
2221
|
-
for (const key in input) {
|
|
2222
|
-
const url = input[key];
|
|
2223
|
-
urlTextureMap.push([url, textureRecord[key]]);
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
store.setState((state) => {
|
|
2227
|
-
const refs = new Map(state._textureRefs);
|
|
2228
|
-
let textures = state.textures;
|
|
2229
|
-
let added = false;
|
|
2230
|
-
for (const [url, texture] of urlTextureMap) {
|
|
2231
|
-
if (!textures.has(url)) {
|
|
2232
|
-
if (!added) {
|
|
2233
|
-
textures = new Map(textures);
|
|
2234
|
-
added = true;
|
|
2235
|
-
}
|
|
2236
|
-
textures.set(url, texture);
|
|
2237
|
-
}
|
|
2238
|
-
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
2239
|
-
}
|
|
2240
|
-
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
2241
|
-
});
|
|
2242
|
-
return () => store.setState((state) => {
|
|
2243
|
-
const refs = new Map(state._textureRefs);
|
|
2244
|
-
for (const [url] of urlTextureMap) {
|
|
2245
|
-
const next = (refs.get(url) ?? 0) - 1;
|
|
2246
|
-
if (next <= 0) refs.delete(url);
|
|
2247
|
-
else refs.set(url, next);
|
|
2248
|
-
}
|
|
2249
|
-
return { _textureRefs: refs };
|
|
2250
|
-
});
|
|
2251
|
-
}, [cache, input, mappedTextures, store]);
|
|
2252
|
-
return mappedTextures;
|
|
2253
|
-
}
|
|
2254
|
-
useTexture.preload = (url) => useLoader.preload(webgpu.TextureLoader, url);
|
|
2255
|
-
useTexture.clear = (input) => useLoader.clear(webgpu.TextureLoader, input);
|
|
2256
|
-
const Texture = ({
|
|
2257
|
-
children,
|
|
2258
|
-
input,
|
|
2259
|
-
onLoad,
|
|
2260
|
-
cache
|
|
2261
|
-
}) => {
|
|
2262
|
-
const options = typeof onLoad === "function" ? { onLoad, cache } : { ...onLoad, cache };
|
|
2263
|
-
const ret = useTexture(input, options);
|
|
2264
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.(ret) });
|
|
2265
|
-
};
|
|
2266
|
-
|
|
2267
|
-
function useTextures(selector) {
|
|
2268
|
-
const store = useStore();
|
|
2269
|
-
const registry = React.useMemo(() => {
|
|
2270
|
-
const getState = store.getState;
|
|
2271
|
-
const setState = store.setState;
|
|
2272
|
-
const getOne = (key) => getState().textures.get(key);
|
|
2273
|
-
return {
|
|
2274
|
-
get all() {
|
|
2275
|
-
return getState().textures;
|
|
2276
|
-
},
|
|
2277
|
-
get(input) {
|
|
2278
|
-
if (typeof input === "string") return getOne(input);
|
|
2279
|
-
if (Array.isArray(input)) return input.map(getOne);
|
|
2280
|
-
const out = {};
|
|
2281
|
-
for (const name in input) out[name] = getOne(input[name]);
|
|
2282
|
-
return out;
|
|
2283
|
-
},
|
|
2284
|
-
has: (key) => getState().textures.has(key),
|
|
2285
|
-
add(keyOrRecord, texture) {
|
|
2286
|
-
setState((state) => {
|
|
2287
|
-
const textures = new Map(state.textures);
|
|
2288
|
-
if (typeof keyOrRecord === "string") {
|
|
2289
|
-
textures.set(keyOrRecord, texture);
|
|
2290
|
-
} else {
|
|
2291
|
-
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
2292
|
-
}
|
|
2293
|
-
return { textures };
|
|
2294
|
-
});
|
|
2295
|
-
},
|
|
2296
|
-
dispose(key, options) {
|
|
2297
|
-
const state = getState();
|
|
2298
|
-
const refs = state._textureRefs.get(key) ?? 0;
|
|
2299
|
-
if (refs > 0 && !options?.force) {
|
|
2300
|
-
console.warn(
|
|
2301
|
-
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
2302
|
-
);
|
|
2303
|
-
return false;
|
|
2304
|
-
}
|
|
2305
|
-
state.textures.get(key)?.dispose();
|
|
2306
|
-
setState((s) => {
|
|
2307
|
-
const textures = new Map(s.textures);
|
|
2308
|
-
textures.delete(key);
|
|
2309
|
-
const nextRefs = new Map(s._textureRefs);
|
|
2310
|
-
nextRefs.delete(key);
|
|
2311
|
-
return { textures, _textureRefs: nextRefs };
|
|
2312
|
-
});
|
|
2313
|
-
return true;
|
|
2314
|
-
},
|
|
2315
|
-
disposeAll() {
|
|
2316
|
-
for (const texture of getState().textures.values()) texture.dispose();
|
|
2317
|
-
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
2318
|
-
}
|
|
2319
|
-
};
|
|
2320
|
-
}, [store]);
|
|
2321
|
-
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
2322
|
-
const selected = useThree(subscribe);
|
|
2323
|
-
return selector ? selected : registry;
|
|
2324
|
-
}
|
|
2325
|
-
|
|
2326
|
-
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|
|
2327
|
-
const isLegacy = useThree((s) => s.isLegacy);
|
|
2328
|
-
const size = useThree((s) => s.size);
|
|
2329
|
-
let width;
|
|
2330
|
-
let height;
|
|
2331
|
-
let opts;
|
|
2332
|
-
if (typeof widthOrOptions === "object") {
|
|
2333
|
-
opts = widthOrOptions;
|
|
2334
|
-
} else if (typeof widthOrOptions === "number") {
|
|
2335
|
-
width = widthOrOptions;
|
|
2336
|
-
if (typeof heightOrOptions === "object") {
|
|
2337
|
-
height = widthOrOptions;
|
|
2338
|
-
opts = heightOrOptions;
|
|
2339
|
-
} else if (typeof heightOrOptions === "number") {
|
|
2340
|
-
height = heightOrOptions;
|
|
2341
|
-
opts = options;
|
|
2342
|
-
} else {
|
|
2343
|
-
height = widthOrOptions;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
return React.useMemo(() => {
|
|
2347
|
-
const w = width ?? size.width;
|
|
2348
|
-
const h = height ?? size.height;
|
|
2349
|
-
{
|
|
2350
|
-
return isLegacy ? new three.WebGLRenderTarget(w, h, opts) : new webgpu.RenderTarget(w, h, opts);
|
|
2351
|
-
}
|
|
2352
|
-
}, [width, height, size.width, size.height, opts, isLegacy]);
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
function useStore() {
|
|
2356
|
-
const store = React.useContext(context);
|
|
2357
|
-
if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
|
|
2358
|
-
return store;
|
|
2359
|
-
}
|
|
2360
|
-
function useThree(selector = (state) => state, equalityFn) {
|
|
2361
|
-
return useStore()(selector, equalityFn);
|
|
2362
|
-
}
|
|
2363
|
-
function useInstanceHandle(ref) {
|
|
2364
|
-
const instance = React.useRef(null);
|
|
2365
|
-
React.useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
2366
|
-
return instance;
|
|
1646
|
+
function useInstanceHandle(ref) {
|
|
1647
|
+
const instance = React.useRef(null);
|
|
1648
|
+
React.useImperativeHandle(instance, () => ref.current.__r3f, [ref]);
|
|
1649
|
+
return instance;
|
|
2367
1650
|
}
|
|
2368
1651
|
function useGraph(object) {
|
|
2369
1652
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
2370
1653
|
}
|
|
2371
1654
|
|
|
1655
|
+
const t = 1, o = 8, r = 32, e = 2, i$1 = 268435456;
|
|
1656
|
+
|
|
2372
1657
|
let effectId = 0;
|
|
2373
1658
|
function addEffect(callback) {
|
|
2374
1659
|
notifyDepreciated({
|
|
@@ -2403,7 +1688,7 @@ function advance(timestamp) {
|
|
|
2403
1688
|
scheduler.getScheduler().step(timestamp);
|
|
2404
1689
|
}
|
|
2405
1690
|
|
|
2406
|
-
const version = "10.0.0-alpha.
|
|
1691
|
+
const version = "10.0.0-alpha.3";
|
|
2407
1692
|
const packageData = {
|
|
2408
1693
|
version: version};
|
|
2409
1694
|
|
|
@@ -13460,206 +12745,789 @@ Check the top-level render call using <` + i + ">.");
|
|
|
13460
12745
|
var o = 1 << 31 - vn(n);
|
|
13461
12746
|
e.entanglements[1] |= o, n &= ~o;
|
|
13462
12747
|
}
|
|
13463
|
-
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12748
|
+
Kn(e), (ye & (Zn | uo)) === Jn && (Pp = me() + Fg, Wa(0));
|
|
12749
|
+
}
|
|
12750
|
+
}
|
|
12751
|
+
break;
|
|
12752
|
+
case 31:
|
|
12753
|
+
case 13:
|
|
12754
|
+
n = On(e, 2), n !== null && We(n, e, 2), Ls(), rl(e, 2);
|
|
12755
|
+
}
|
|
12756
|
+
}, le.batchedUpdates = function(e, n) {
|
|
12757
|
+
return e(n);
|
|
12758
|
+
}, le.createComponentSelector = function(e) {
|
|
12759
|
+
return { $$typeof: pm, value: e };
|
|
12760
|
+
}, le.createContainer = function(e, n, o, i, s, u, f, p, g, S) {
|
|
12761
|
+
return Ka(e, n, false, null, o, i, u, null, f, p, g, S);
|
|
12762
|
+
}, le.createHasPseudoClassSelector = function(e) {
|
|
12763
|
+
return { $$typeof: hm, value: e };
|
|
12764
|
+
}, le.createHydrationContainer = function(e, n, o, i, s, u, f, p, g, S, T, _, I, O) {
|
|
12765
|
+
return e = Ka(o, i, true, e, s, u, p, O, g, S, T, _), e.context = Dh(null), o = e.current, i = Nt(o), i = Xo(i), s = zo(i), s.callback = n ?? null, Mt(o, s, i), ur(i, "hydrateRoot()", null), n = i, e.current.lanes = n, Ci(e, n), Kn(e), e;
|
|
12766
|
+
}, le.createPortal = function(e, n, o) {
|
|
12767
|
+
var i = 3 < arguments.length && arguments[3] !== void 0 ? arguments[3] : null;
|
|
12768
|
+
try {
|
|
12769
|
+
vt(i);
|
|
12770
|
+
var s = false;
|
|
12771
|
+
} catch {
|
|
12772
|
+
s = true;
|
|
12773
|
+
}
|
|
12774
|
+
return s && (console.error("The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", typeof Symbol == "function" && Symbol.toStringTag && i[Symbol.toStringTag] || i.constructor.name || "Object"), vt(i)), { $$typeof: Ao, key: i == null ? null : "" + i, children: e, containerInfo: n, implementation: o };
|
|
12775
|
+
}, le.createRoleSelector = function(e) {
|
|
12776
|
+
return { $$typeof: mm, value: e };
|
|
12777
|
+
}, le.createTestNameSelector = function(e) {
|
|
12778
|
+
return { $$typeof: gm, value: e };
|
|
12779
|
+
}, le.createTextSelector = function(e) {
|
|
12780
|
+
return { $$typeof: ym, value: e };
|
|
12781
|
+
}, le.defaultOnCaughtError = function(e) {
|
|
12782
|
+
var n = bd ? "The above error occurred in the <" + bd + "> component." : "The above error occurred in one of your React components.", o = "React will try to recreate this component tree from scratch using the error boundary you provided, " + ((Cg || "Anonymous") + ".");
|
|
12783
|
+
typeof e == "object" && e !== null && typeof e.environmentName == "string" ? ri("error", [`%o
|
|
12784
|
+
|
|
12785
|
+
%s
|
|
12786
|
+
|
|
12787
|
+
%s
|
|
12788
|
+
`, e, n, o], e.environmentName)() : console.error(`%o
|
|
12789
|
+
|
|
12790
|
+
%s
|
|
12791
|
+
|
|
12792
|
+
%s
|
|
12793
|
+
`, e, n, o);
|
|
12794
|
+
}, le.defaultOnRecoverableError = function(e) {
|
|
12795
|
+
qg(e);
|
|
12796
|
+
}, le.defaultOnUncaughtError = function(e) {
|
|
12797
|
+
qg(e), console.warn(`%s
|
|
12798
|
+
|
|
12799
|
+
%s
|
|
12800
|
+
`, bd ? "An error occurred in the <" + bd + "> component." : "An error occurred in one of your React components.", `Consider adding an error boundary to your tree to customize error handling behavior.
|
|
12801
|
+
Visit https://react.dev/link/error-boundaries to learn more about error boundaries.`);
|
|
12802
|
+
}, le.deferredUpdates = function(e) {
|
|
12803
|
+
var n = x.T, o = wt();
|
|
12804
|
+
try {
|
|
12805
|
+
return an(32), x.T = null, e();
|
|
12806
|
+
} finally {
|
|
12807
|
+
an(o), x.T = n;
|
|
12808
|
+
}
|
|
12809
|
+
}, le.discreteUpdates = function(e, n, o, i, s) {
|
|
12810
|
+
var u = x.T, f = wt();
|
|
12811
|
+
try {
|
|
12812
|
+
return an(2), x.T = null, e(n, o, i, s);
|
|
12813
|
+
} finally {
|
|
12814
|
+
an(f), x.T = u, ye === Jn && (Pp = me() + Fg);
|
|
12815
|
+
}
|
|
12816
|
+
}, le.findAllNodes = kc, le.findBoundingRects = function(e, n) {
|
|
12817
|
+
if (!xr) throw Error("Test selector API is not supported by this renderer.");
|
|
12818
|
+
n = kc(e, n), e = [];
|
|
12819
|
+
for (var o = 0; o < n.length; o++) e.push(ma(n[o]));
|
|
12820
|
+
for (n = e.length - 1; 0 < n; n--) {
|
|
12821
|
+
o = e[n];
|
|
12822
|
+
for (var i = o.x, s = i + o.width, u = o.y, f = u + o.height, p = n - 1; 0 <= p; p--) if (n !== p) {
|
|
12823
|
+
var g = e[p], S = g.x, T = S + g.width, _ = g.y, I = _ + g.height;
|
|
12824
|
+
if (i >= S && u >= _ && s <= T && f <= I) {
|
|
12825
|
+
e.splice(n, 1);
|
|
12826
|
+
break;
|
|
12827
|
+
} else if (i !== S || o.width !== g.width || I < u || _ > f) {
|
|
12828
|
+
if (!(u !== _ || o.height !== g.height || T < i || S > s)) {
|
|
12829
|
+
S > i && (g.width += S - i, g.x = i), T < s && (g.width = s - S), e.splice(n, 1);
|
|
12830
|
+
break;
|
|
12831
|
+
}
|
|
12832
|
+
} else {
|
|
12833
|
+
_ > u && (g.height += _ - u, g.y = u), I < f && (g.height = f - _), e.splice(n, 1);
|
|
12834
|
+
break;
|
|
12835
|
+
}
|
|
12836
|
+
}
|
|
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
|
+
}
|
|
13464
13168
|
}
|
|
13465
|
-
}
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
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;
|
|
13470
13177
|
}
|
|
13471
|
-
}
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
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);
|
|
13488
13200
|
}
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
|
|
13522
|
-
an(o), x.T = n;
|
|
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);
|
|
13523
13234
|
}
|
|
13524
|
-
}
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
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();
|
|
13530
13262
|
}
|
|
13531
|
-
}
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
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();
|
|
13546
13289
|
}
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
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();
|
|
13550
13367
|
}
|
|
13551
13368
|
}
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
if (
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
var o = n[e++], i = o.tag;
|
|
13584
|
-
if (!Kr(o)) {
|
|
13585
|
-
if ((i === 5 || i === 26 || i === 27) && Ft(o.stateNode)) return true;
|
|
13586
|
-
for (o = o.child; o !== null; ) n.push(o), o = o.sibling;
|
|
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
|
+
}
|
|
13587
13400
|
}
|
|
13588
13401
|
}
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
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);
|
|
13597
13461
|
}
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
No matching component was found for:
|
|
13604
|
-
`) + e.join(" > ");
|
|
13462
|
+
} else {
|
|
13463
|
+
flushDeferredPointers();
|
|
13464
|
+
if (internal.lastEvent?.current) {
|
|
13465
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
13605
13466
|
}
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
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 });
|
|
13615
13486
|
}
|
|
13616
|
-
}
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
}
|
|
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
|
+
}
|
|
13627
13498
|
}
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
|
|
13641
|
-
|
|
13642
|
-
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
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
|
+
};
|
|
13658
13530
|
}
|
|
13659
|
-
var t0 = n0();
|
|
13660
|
-
const r0 = Xb(t0);
|
|
13661
|
-
|
|
13662
|
-
const t = 1, o = 8, r = 32, e = 2;
|
|
13663
13531
|
|
|
13664
13532
|
function createReconciler(config) {
|
|
13665
13533
|
const reconciler2 = r0(config);
|
|
@@ -13824,7 +13692,15 @@ function setFiberRef(fiber, publicInstance) {
|
|
|
13824
13692
|
}
|
|
13825
13693
|
}
|
|
13826
13694
|
const reconstructed = [];
|
|
13827
|
-
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() {
|
|
13828
13704
|
for (const [instance] of reconstructed) {
|
|
13829
13705
|
const parent = instance.parent;
|
|
13830
13706
|
if (parent) {
|
|
@@ -13842,6 +13718,9 @@ function swapInstances() {
|
|
|
13842
13718
|
}
|
|
13843
13719
|
}
|
|
13844
13720
|
if (instance.isHidden) unhideInstance(instance);
|
|
13721
|
+
if (isObject3D(instance.object) && !instance.parent) {
|
|
13722
|
+
removeInteractivity(findInitialRoot(instance), instance.object);
|
|
13723
|
+
}
|
|
13845
13724
|
if (instance.object.__r3f) delete instance.object.__r3f;
|
|
13846
13725
|
if (instance.type !== "primitive") disposeOnIdle(instance.object);
|
|
13847
13726
|
}
|
|
@@ -13850,10 +13729,16 @@ function swapInstances() {
|
|
|
13850
13729
|
const parent = instance.parent;
|
|
13851
13730
|
if (parent) {
|
|
13852
13731
|
const target = catalogue[toPascalCase(instance.type)];
|
|
13732
|
+
const prevObject = instance.object;
|
|
13853
13733
|
instance.object = instance.props.object ?? new target(...instance.props.args ?? []);
|
|
13854
13734
|
instance.object.__r3f = instance;
|
|
13855
13735
|
setFiberRef(fiber, instance.object);
|
|
13736
|
+
if (isObject3D(prevObject) && isObject3D(instance.object)) {
|
|
13737
|
+
swapInteractivity(findInitialRoot(instance), prevObject, instance.object);
|
|
13738
|
+
}
|
|
13856
13739
|
delete instance.appliedOnce;
|
|
13740
|
+
instance.eventCount = 0;
|
|
13741
|
+
instance.handlers = {};
|
|
13857
13742
|
applyProps(instance.object, instance.props);
|
|
13858
13743
|
if (instance.props.attach) {
|
|
13859
13744
|
attach(parent, instance);
|
|
@@ -13870,14 +13755,114 @@ function swapInstances() {
|
|
|
13870
13755
|
invalidateInstance(instance);
|
|
13871
13756
|
}
|
|
13872
13757
|
}
|
|
13873
|
-
reconstructed.length = 0;
|
|
13874
13758
|
}
|
|
13875
13759
|
const handleTextInstance = () => {
|
|
13876
13760
|
};
|
|
13877
13761
|
const NO_CONTEXT = {};
|
|
13878
13762
|
let currentUpdatePriority = NoEventPriority;
|
|
13879
|
-
|
|
13880
|
-
|
|
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
|
+
}
|
|
13881
13866
|
const reconciler = /* @__PURE__ */ createReconciler({
|
|
13882
13867
|
isPrimaryRenderer: false,
|
|
13883
13868
|
warnsIfNotActing: false,
|
|
@@ -13916,16 +13901,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13916
13901
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
13917
13902
|
else if (newProps.args?.some((value, index) => value !== oldProps.args?.[index])) reconstruct = true;
|
|
13918
13903
|
if (reconstruct) {
|
|
13919
|
-
reconstructed.push([instance,
|
|
13904
|
+
reconstructed.push([instance, getInstanceProps(newProps), fiber]);
|
|
13920
13905
|
} else {
|
|
13921
13906
|
const changedProps = diffProps(instance, newProps);
|
|
13922
|
-
|
|
13923
|
-
|
|
13924
|
-
|
|
13925
|
-
|
|
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);
|
|
13926
13912
|
}
|
|
13927
|
-
const isTailSibling = fiber.sibling === null || (fiber.flags & Update) === NoFlags;
|
|
13928
|
-
if (isTailSibling) swapInstances();
|
|
13929
13913
|
},
|
|
13930
13914
|
finalizeInitialChildren: (instance) => {
|
|
13931
13915
|
for (const prop in instance.props) {
|
|
@@ -13950,8 +13934,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13950
13934
|
const target = container.getState().internal.container ?? container.getState().scene;
|
|
13951
13935
|
return prepare(target, container, "", {});
|
|
13952
13936
|
},
|
|
13953
|
-
|
|
13954
|
-
|
|
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,
|
|
13955
13940
|
shouldSetTextContent: () => false,
|
|
13956
13941
|
clearContainer: () => false,
|
|
13957
13942
|
hideInstance,
|
|
@@ -13959,6 +13944,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13959
13944
|
createTextInstance: handleTextInstance,
|
|
13960
13945
|
hideTextInstance: handleTextInstance,
|
|
13961
13946
|
unhideTextInstance: handleTextInstance,
|
|
13947
|
+
// Mirrors react-dom, which flushes discrete work in microtasks
|
|
13948
|
+
supportsMicrotasks: true,
|
|
13949
|
+
scheduleMicrotask,
|
|
13962
13950
|
scheduleTimeout: typeof setTimeout === "function" ? setTimeout : void 0,
|
|
13963
13951
|
cancelTimeout: typeof clearTimeout === "function" ? clearTimeout : void 0,
|
|
13964
13952
|
noTimeout: -1,
|
|
@@ -13999,28 +13987,9 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13999
13987
|
},
|
|
14000
13988
|
resolveUpdatePriority() {
|
|
14001
13989
|
if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
|
|
14002
|
-
|
|
14003
|
-
|
|
14004
|
-
|
|
14005
|
-
case "dblclick":
|
|
14006
|
-
case "dragenter":
|
|
14007
|
-
case "dragleave":
|
|
14008
|
-
case "drop":
|
|
14009
|
-
case "pointercancel":
|
|
14010
|
-
case "pointerdown":
|
|
14011
|
-
case "pointerup":
|
|
14012
|
-
return e;
|
|
14013
|
-
case "dragover":
|
|
14014
|
-
case "pointermove":
|
|
14015
|
-
case "pointerout":
|
|
14016
|
-
case "pointerover":
|
|
14017
|
-
case "pointerenter":
|
|
14018
|
-
case "pointerleave":
|
|
14019
|
-
case "wheel":
|
|
14020
|
-
return o;
|
|
14021
|
-
default:
|
|
14022
|
-
return r;
|
|
14023
|
-
}
|
|
13990
|
+
const eventType = typeof window !== "undefined" ? window.event?.type : void 0;
|
|
13991
|
+
if (eventType === void 0) return r;
|
|
13992
|
+
return getEventPriority(eventType);
|
|
14024
13993
|
},
|
|
14025
13994
|
resetFormInstance() {
|
|
14026
13995
|
},
|
|
@@ -14069,11 +14038,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
14069
14038
|
cloneMutableTextInstance(textInstance) {
|
|
14070
14039
|
return textInstance;
|
|
14071
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.
|
|
14072
14047
|
cloneRootViewTransitionContainer(_rootContainer) {
|
|
14073
|
-
throw new Error("Not implemented.");
|
|
14074
14048
|
},
|
|
14075
14049
|
removeRootViewTransitionClone(_rootContainer, _clone) {
|
|
14076
|
-
throw new Error("Not implemented.");
|
|
14077
14050
|
},
|
|
14078
14051
|
// https://github.com/facebook/react/pull/32465
|
|
14079
14052
|
createFragmentInstance: (_fiber) => null,
|
|
@@ -14158,6 +14131,7 @@ function createRoot(canvas) {
|
|
|
14158
14131
|
const lastConfiguredProps = {};
|
|
14159
14132
|
let configured = false;
|
|
14160
14133
|
let pending = null;
|
|
14134
|
+
let rendererSetup = null;
|
|
14161
14135
|
return {
|
|
14162
14136
|
async configure(props = {}) {
|
|
14163
14137
|
let resolve;
|
|
@@ -14188,7 +14162,7 @@ function createRoot(canvas) {
|
|
|
14188
14162
|
forceEven
|
|
14189
14163
|
} = props;
|
|
14190
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;
|
|
14191
|
-
|
|
14165
|
+
let state = store.getState();
|
|
14192
14166
|
const defaultGLProps = {
|
|
14193
14167
|
canvas,
|
|
14194
14168
|
powerPreference: "high-performance",
|
|
@@ -14216,56 +14190,68 @@ function createRoot(canvas) {
|
|
|
14216
14190
|
"The `primaryCanvas` prop for multi-canvas rendering cannot be used with WebGL. Remove the `gl` prop or use WebGPU."
|
|
14217
14191
|
);
|
|
14218
14192
|
}
|
|
14219
|
-
if (
|
|
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
|
-
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14263
|
-
|
|
14264
|
-
|
|
14265
|
-
|
|
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
|
+
}
|
|
14266
14246
|
}
|
|
14267
|
-
}))
|
|
14247
|
+
})().catch((err) => {
|
|
14248
|
+
rendererSetup = null;
|
|
14249
|
+
throw err;
|
|
14250
|
+
});
|
|
14268
14251
|
}
|
|
14252
|
+
await rendererSetup;
|
|
14253
|
+
state = store.getState();
|
|
14254
|
+
renderer = state.internal.actualRenderer;
|
|
14269
14255
|
}
|
|
14270
14256
|
let raycaster = state.raycaster;
|
|
14271
14257
|
if (!raycaster) state.set({ raycaster: raycaster = new webgpu.Raycaster() });
|
|
@@ -14615,7 +14601,8 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14615
14601
|
dispose(state.scene);
|
|
14616
14602
|
_roots.delete(canvas);
|
|
14617
14603
|
if (callback) callback(canvas);
|
|
14618
|
-
} catch {
|
|
14604
|
+
} catch (error) {
|
|
14605
|
+
console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
|
|
14619
14606
|
}
|
|
14620
14607
|
}, 500);
|
|
14621
14608
|
}
|
|
@@ -14678,6 +14665,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14678
14665
|
viewport = rootState.viewport.getCurrentViewport(camera, new webgpu.Vector3(), resolvedSize);
|
|
14679
14666
|
if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
|
|
14680
14667
|
}
|
|
14668
|
+
const set = injectState.set;
|
|
14681
14669
|
return {
|
|
14682
14670
|
// The intersect consists of the previous root state
|
|
14683
14671
|
...rootState,
|
|
@@ -14696,7 +14684,7 @@ function PortalInner({ state = {}, children, container }) {
|
|
|
14696
14684
|
size: resolvedSize,
|
|
14697
14685
|
viewport: { ...rootState.viewport, ...viewport },
|
|
14698
14686
|
// Layers are allowed to override events
|
|
14699
|
-
setEvents: (events2) =>
|
|
14687
|
+
setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
|
|
14700
14688
|
// Container for child attachment - the portalScene (injected or container itself)
|
|
14701
14689
|
internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
|
|
14702
14690
|
};
|
|
@@ -14725,6 +14713,212 @@ function flushSync(fn) {
|
|
|
14725
14713
|
return reconciler.flushSyncFromReconciler(fn);
|
|
14726
14714
|
}
|
|
14727
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
|
+
|
|
14728
14922
|
function parseBackground(background) {
|
|
14729
14923
|
if (!background) return null;
|
|
14730
14924
|
if (typeof background === "object" && !background.isColor) {
|
|
@@ -14768,14 +14962,36 @@ function parseRendererConfig(rendererProp) {
|
|
|
14768
14962
|
return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
|
|
14769
14963
|
}
|
|
14770
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
|
+
|
|
14771
14991
|
function clearHmrCaches(store) {
|
|
14772
|
-
store.
|
|
14773
|
-
|
|
14774
|
-
|
|
14775
|
-
buffers: {},
|
|
14776
|
-
gpuStorage: {},
|
|
14777
|
-
_hmrVersion: state._hmrVersion + 1
|
|
14778
|
-
}));
|
|
14992
|
+
const primary = store.getState().primaryStore ?? store;
|
|
14993
|
+
invalidateAllResources(primary);
|
|
14994
|
+
primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
|
|
14779
14995
|
}
|
|
14780
14996
|
|
|
14781
14997
|
function CanvasImpl({
|
|
@@ -14856,6 +15072,7 @@ function CanvasImpl({
|
|
|
14856
15072
|
const handleDropMissed = useMutableCallback(onDropMissed);
|
|
14857
15073
|
const [block, setBlock] = React__namespace.useState(false);
|
|
14858
15074
|
const [error, setError] = React__namespace.useState(false);
|
|
15075
|
+
const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
|
|
14859
15076
|
if (block) throw block;
|
|
14860
15077
|
if (error) throw error;
|
|
14861
15078
|
const root = React__namespace.useRef(null);
|
|
@@ -14863,6 +15080,7 @@ function CanvasImpl({
|
|
|
14863
15080
|
const unsubscribeErrorRef = React__namespace.useRef(null);
|
|
14864
15081
|
useIsomorphicLayoutEffect(() => {
|
|
14865
15082
|
effectActiveRef.current = true;
|
|
15083
|
+
if (fallbackVisible) return;
|
|
14866
15084
|
const canvas = canvasRef.current;
|
|
14867
15085
|
if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
|
|
14868
15086
|
if (!root.current) {
|
|
@@ -14883,7 +15101,7 @@ function CanvasImpl({
|
|
|
14883
15101
|
}
|
|
14884
15102
|
async function run() {
|
|
14885
15103
|
if (!effectActiveRef.current || !root.current) return;
|
|
14886
|
-
await root.current.configure({
|
|
15104
|
+
const configured = await root.current.configure({
|
|
14887
15105
|
id,
|
|
14888
15106
|
primaryCanvas,
|
|
14889
15107
|
scheduler,
|
|
@@ -14910,7 +15128,7 @@ function CanvasImpl({
|
|
|
14910
15128
|
onDropMissed: (...args) => handleDropMissed.current?.(...args),
|
|
14911
15129
|
onCreated: (state) => {
|
|
14912
15130
|
state.events.connect?.(
|
|
14913
|
-
eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
15131
|
+
eventSource ? isRef$1(eventSource) ? eventSource.current : eventSource : divRef.current
|
|
14914
15132
|
);
|
|
14915
15133
|
if (eventPrefix) {
|
|
14916
15134
|
state.setEvents({
|
|
@@ -14924,8 +15142,20 @@ function CanvasImpl({
|
|
|
14924
15142
|
}
|
|
14925
15143
|
onCreated?.(state);
|
|
14926
15144
|
}
|
|
14927
|
-
})
|
|
14928
|
-
|
|
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;
|
|
14929
15159
|
root.current.render(
|
|
14930
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: [
|
|
14931
15161
|
backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
|
|
@@ -14988,7 +15218,11 @@ function CanvasImpl({
|
|
|
14988
15218
|
...style
|
|
14989
15219
|
},
|
|
14990
15220
|
...props,
|
|
14991
|
-
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(
|
|
14992
15226
|
"canvas",
|
|
14993
15227
|
{
|
|
14994
15228
|
ref: canvasRef,
|
|
@@ -15026,7 +15260,6 @@ exports.REACT_INTERNAL_PROPS = REACT_INTERNAL_PROPS;
|
|
|
15026
15260
|
exports.RESERVED_PROPS = RESERVED_PROPS;
|
|
15027
15261
|
exports.Texture = Texture;
|
|
15028
15262
|
exports._roots = _roots;
|
|
15029
|
-
exports.act = act;
|
|
15030
15263
|
exports.addAfterEffect = addAfterEffect;
|
|
15031
15264
|
exports.addEffect = addEffect;
|
|
15032
15265
|
exports.addTail = addTail;
|
|
@@ -15065,7 +15298,7 @@ exports.isFromRef = isFromRef;
|
|
|
15065
15298
|
exports.isObject3D = isObject3D;
|
|
15066
15299
|
exports.isOnce = isOnce;
|
|
15067
15300
|
exports.isOrthographicCamera = isOrthographicCamera;
|
|
15068
|
-
exports.isRef = isRef;
|
|
15301
|
+
exports.isRef = isRef$1;
|
|
15069
15302
|
exports.isRenderer = isRenderer;
|
|
15070
15303
|
exports.isTexture = isTexture;
|
|
15071
15304
|
exports.isVectorLike = isVectorLike;
|
|
@@ -15076,6 +15309,7 @@ exports.reconciler = reconciler;
|
|
|
15076
15309
|
exports.registerPrimary = registerPrimary;
|
|
15077
15310
|
exports.removeInteractivity = removeInteractivity;
|
|
15078
15311
|
exports.resolve = resolve;
|
|
15312
|
+
exports.swapInteractivity = swapInteractivity;
|
|
15079
15313
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
15080
15314
|
exports.unregisterPrimary = unregisterPrimary;
|
|
15081
15315
|
exports.updateCamera = updateCamera;
|