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