@react-three/fiber 10.0.0-canary.20de6b2 → 10.0.0-canary.27df622
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 +106 -63
- package/dist/index.d.cts +270 -142
- package/dist/index.d.mts +270 -142
- package/dist/index.d.ts +270 -170
- package/dist/index.mjs +106 -63
- package/dist/legacy.cjs +105 -61
- package/dist/legacy.d.cts +274 -146
- package/dist/legacy.d.mts +274 -146
- package/dist/legacy.d.ts +274 -172
- package/dist/legacy.mjs +105 -61
- package/dist/webgpu/index.cjs +197 -135
- package/dist/webgpu/index.d.cts +333 -204
- package/dist/webgpu/index.d.mts +333 -204
- package/dist/webgpu/index.d.ts +333 -232
- package/dist/webgpu/index.mjs +197 -135
- package/package.json +2 -2
package/dist/webgpu/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ export { Scheduler, getScheduler } from '@pmndrs/scheduler';
|
|
|
11
11
|
import Tb, { unstable_getCurrentPriorityLevel, unstable_IdlePriority, unstable_LowPriority, unstable_NormalPriority, unstable_UserBlockingPriority, unstable_ImmediatePriority, unstable_scheduleCallback } from 'scheduler';
|
|
12
12
|
import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
|
|
13
13
|
import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
|
|
14
|
+
import { HDRCubeTextureLoader } from 'three/examples/jsm/loaders/HDRCubeTextureLoader.js';
|
|
14
15
|
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
15
16
|
import { UltraHDRLoader } from 'three/examples/jsm/loaders/UltraHDRLoader.js';
|
|
16
17
|
import { GainMapLoader } from '@monogrid/gainmap-js';
|
|
@@ -519,8 +520,10 @@ function hasVisibilityHandlers(handlers) {
|
|
|
519
520
|
}
|
|
520
521
|
|
|
521
522
|
const FROM_REF = Symbol.for("@react-three/fiber.fromRef");
|
|
522
|
-
function fromRef(ref) {
|
|
523
|
-
|
|
523
|
+
function fromRef(ref, transform) {
|
|
524
|
+
const marker = { [FROM_REF]: ref };
|
|
525
|
+
if (transform) marker.transform = transform;
|
|
526
|
+
return marker;
|
|
524
527
|
}
|
|
525
528
|
function isFromRef(value) {
|
|
526
529
|
return value !== null && typeof value === "object" && FROM_REF in value;
|
|
@@ -621,11 +624,9 @@ function diffProps(instance, newProps) {
|
|
|
621
624
|
for (const prop in instance.props) {
|
|
622
625
|
if (RESERVED_PROPS.includes(prop) || newProps.hasOwnProperty(prop)) continue;
|
|
623
626
|
const { root, key } = resolve(instance.object, prop);
|
|
624
|
-
if (
|
|
627
|
+
if (typeof root?.constructor === "function") {
|
|
625
628
|
const ctor = getMemoizedPrototype(root);
|
|
626
629
|
if (!is.und(ctor)) changedProps[prop] = ctor[key];
|
|
627
|
-
} else {
|
|
628
|
-
changedProps[prop] = 0;
|
|
629
630
|
}
|
|
630
631
|
}
|
|
631
632
|
return changedProps;
|
|
@@ -915,7 +916,7 @@ const createStore = (invalidate, advance) => {
|
|
|
915
916
|
size: newSize,
|
|
916
917
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
|
|
917
918
|
}));
|
|
918
|
-
|
|
919
|
+
get().invalidate();
|
|
919
920
|
}
|
|
920
921
|
}
|
|
921
922
|
return;
|
|
@@ -930,15 +931,16 @@ const createStore = (invalidate, advance) => {
|
|
|
930
931
|
viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
|
|
931
932
|
_sizeImperative: true
|
|
932
933
|
}));
|
|
933
|
-
|
|
934
|
+
get().invalidate();
|
|
934
935
|
},
|
|
935
936
|
setDpr: (dpr) => set((state2) => {
|
|
936
937
|
const resolved = calculateDpr(dpr);
|
|
937
938
|
return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
|
|
938
939
|
}),
|
|
939
940
|
setFrameloop: (frameloop = "always") => {
|
|
941
|
+
const rootId = get().internal.rootId;
|
|
942
|
+
if (rootId) getScheduler().setRootFrameloop(rootId, frameloop);
|
|
940
943
|
set(() => ({ frameloop }));
|
|
941
|
-
getScheduler().frameloop = frameloop;
|
|
942
944
|
},
|
|
943
945
|
setError: (error) => set(() => ({ error })),
|
|
944
946
|
error: null,
|
|
@@ -1057,7 +1059,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1057
1059
|
const resizeTarget = canvasTarget ?? actualRenderer;
|
|
1058
1060
|
if (viewport.dpr > 0) resizeTarget.setPixelRatio(viewport.dpr);
|
|
1059
1061
|
resizeTarget.setSize(size.width, size.height, false);
|
|
1060
|
-
|
|
1062
|
+
const activeTarget = actualRenderer.getCanvasTarget?.();
|
|
1063
|
+
if (!canvasTarget || activeTarget !== canvasTarget) internal.canvasTargetSizeDirty = true;
|
|
1061
1064
|
}
|
|
1062
1065
|
if (camera !== oldCamera) {
|
|
1063
1066
|
oldCamera = camera;
|
|
@@ -1243,6 +1246,13 @@ function useFrame$1(callback, priorityOrOptions) {
|
|
|
1243
1246
|
* Use for controlling the entire frame loop, adding phases, etc.
|
|
1244
1247
|
*/
|
|
1245
1248
|
scheduler: scheduler2,
|
|
1249
|
+
/**
|
|
1250
|
+
* The root that currently owns this job. Resolve on access because ambient
|
|
1251
|
+
* jobs can be adopted by a Canvas after the controls object is created.
|
|
1252
|
+
*/
|
|
1253
|
+
get rootId() {
|
|
1254
|
+
return getScheduler().getJobRootId(id);
|
|
1255
|
+
},
|
|
1246
1256
|
/**
|
|
1247
1257
|
* Manually step this job only.
|
|
1248
1258
|
* Bypasses FPS limiting - always runs.
|
|
@@ -1259,6 +1269,14 @@ function useFrame$1(callback, priorityOrOptions) {
|
|
|
1259
1269
|
stepAll: (timestamp) => {
|
|
1260
1270
|
getScheduler().step(timestamp);
|
|
1261
1271
|
},
|
|
1272
|
+
/**
|
|
1273
|
+
* Request frames for this job's owning root without waking sibling roots.
|
|
1274
|
+
*/
|
|
1275
|
+
invalidate: (frames, stackFrames) => {
|
|
1276
|
+
const scheduler3 = getScheduler();
|
|
1277
|
+
const rootId = scheduler3.getJobRootId(id);
|
|
1278
|
+
if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
|
|
1279
|
+
},
|
|
1262
1280
|
/**
|
|
1263
1281
|
* Pause this job (set enabled=false).
|
|
1264
1282
|
* Job remains registered but won't run.
|
|
@@ -1331,12 +1349,24 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
1331
1349
|
TextureLoader,
|
|
1332
1350
|
IsObject(stableInput) ? Object.values(stableInput) : stableInput
|
|
1333
1351
|
);
|
|
1352
|
+
const mappedTextures = useMemo(() => {
|
|
1353
|
+
if (cachedResult) return cachedResult;
|
|
1354
|
+
if (IsObject(stableInput)) {
|
|
1355
|
+
const keyed = {};
|
|
1356
|
+
const textureArray = loadedTextures;
|
|
1357
|
+
let i = 0;
|
|
1358
|
+
for (const key in stableInput) keyed[key] = textureArray[i++];
|
|
1359
|
+
return keyed;
|
|
1360
|
+
} else {
|
|
1361
|
+
return loadedTextures;
|
|
1362
|
+
}
|
|
1363
|
+
}, [stableInput, loadedTextures, cachedResult]);
|
|
1334
1364
|
useLayoutEffect(() => {
|
|
1335
1365
|
if (cachedResult) return;
|
|
1336
1366
|
if (onLoadCalledForRef.current === inputKey) return;
|
|
1337
1367
|
onLoadCalledForRef.current = inputKey;
|
|
1338
|
-
onLoadRef.current?.(
|
|
1339
|
-
}, [cachedResult,
|
|
1368
|
+
onLoadRef.current?.(mappedTextures);
|
|
1369
|
+
}, [cachedResult, mappedTextures, inputKey]);
|
|
1340
1370
|
useEffect(() => {
|
|
1341
1371
|
if (cachedResult) return;
|
|
1342
1372
|
if ("initTexture" in renderer) {
|
|
@@ -1355,18 +1385,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
1355
1385
|
});
|
|
1356
1386
|
}
|
|
1357
1387
|
}, [renderer, loadedTextures, cachedResult]);
|
|
1358
|
-
const mappedTextures = useMemo(() => {
|
|
1359
|
-
if (cachedResult) return cachedResult;
|
|
1360
|
-
if (IsObject(stableInput)) {
|
|
1361
|
-
const keyed = {};
|
|
1362
|
-
const textureArray = loadedTextures;
|
|
1363
|
-
let i = 0;
|
|
1364
|
-
for (const key in stableInput) keyed[key] = textureArray[i++];
|
|
1365
|
-
return keyed;
|
|
1366
|
-
} else {
|
|
1367
|
-
return loadedTextures;
|
|
1368
|
-
}
|
|
1369
|
-
}, [stableInput, loadedTextures, cachedResult]);
|
|
1370
1388
|
useEffect(() => {
|
|
1371
1389
|
if (!cache) return;
|
|
1372
1390
|
const urlTextureMap = [];
|
|
@@ -1568,7 +1586,7 @@ function useEnvironment({
|
|
|
1568
1586
|
texture = texture.renderTarget?.texture;
|
|
1569
1587
|
}
|
|
1570
1588
|
texture.mapping = isCubemap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
1571
|
-
texture.colorSpace = colorSpace ?? (isCubemap ? "srgb" : "srgb-linear");
|
|
1589
|
+
texture.colorSpace = colorSpace ?? (isCubemap && extension !== "hdr-cube" ? "srgb" : "srgb-linear");
|
|
1572
1590
|
return texture;
|
|
1573
1591
|
}
|
|
1574
1592
|
const preloadDefaultOptions = {
|
|
@@ -1621,11 +1639,12 @@ function getExtension(files) {
|
|
|
1621
1639
|
const isCubemap = isArray(files) && files.length === 6;
|
|
1622
1640
|
const isGainmap = isArray(files) && files.length === 3 && files.some((file) => file.endsWith("json"));
|
|
1623
1641
|
const firstEntry = isArray(files) ? files[0] : files;
|
|
1624
|
-
const
|
|
1642
|
+
const firstExtension = firstEntry.split(".").pop()?.split("?")?.shift()?.toLowerCase();
|
|
1643
|
+
const extension = isCubemap ? firstExtension === "hdr" ? "hdr-cube" : "cube" : isGainmap ? "webp" : firstEntry.startsWith("data:application/exr") ? "exr" : firstEntry.startsWith("data:application/hdr") ? "hdr" : firstEntry.startsWith("data:image/jpeg") ? "jpg" : firstExtension;
|
|
1625
1644
|
return { extension, isCubemap, isGainmap };
|
|
1626
1645
|
}
|
|
1627
1646
|
function getLoader(extension) {
|
|
1628
|
-
const loader = extension === "cube" ? CubeTextureLoader : extension === "hdr" ? HDRLoader : extension === "exr" ? EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader : extension === "webp" ? GainMapLoader : null;
|
|
1647
|
+
const loader = extension === "cube" ? CubeTextureLoader : extension === "hdr-cube" ? HDRCubeTextureLoader : extension === "hdr" ? HDRLoader : extension === "exr" ? EXRLoader : extension === "jpg" || extension === "jpeg" ? UltraHDRLoader : extension === "webp" ? GainMapLoader : null;
|
|
1629
1648
|
return loader;
|
|
1630
1649
|
}
|
|
1631
1650
|
|
|
@@ -1676,22 +1695,28 @@ function addTail(callback) {
|
|
|
1676
1695
|
return getScheduler().onIdle(callback);
|
|
1677
1696
|
}
|
|
1678
1697
|
function invalidate(state, frames = 1, stackFrames = false) {
|
|
1679
|
-
|
|
1698
|
+
const rootId = state?.internal?.rootId;
|
|
1699
|
+
const scheduler = getScheduler();
|
|
1700
|
+
if (rootId) scheduler.invalidateRoot(rootId, frames, stackFrames);
|
|
1701
|
+
else scheduler.invalidate(frames, stackFrames);
|
|
1680
1702
|
}
|
|
1681
|
-
function advance(timestamp) {
|
|
1682
|
-
|
|
1703
|
+
function advance(timestamp, runGlobalEffects, state) {
|
|
1704
|
+
const rootId = state?.internal?.rootId;
|
|
1705
|
+
const scheduler = getScheduler();
|
|
1706
|
+
if (rootId) scheduler.stepRoot(rootId, timestamp);
|
|
1707
|
+
else scheduler.step(timestamp);
|
|
1683
1708
|
}
|
|
1684
1709
|
|
|
1685
|
-
const version = "10.0.0-alpha.
|
|
1710
|
+
const version = "10.0.0-alpha.5";
|
|
1686
1711
|
const packageData = {
|
|
1687
1712
|
version: version};
|
|
1688
1713
|
|
|
1689
1714
|
function Xb(Tt) {
|
|
1690
1715
|
return Tt && Tt.__esModule && Object.prototype.hasOwnProperty.call(Tt, "default") ? Tt.default : Tt;
|
|
1691
1716
|
}
|
|
1692
|
-
var Rm = { exports: {} }, Og = { exports: {} }, _b;
|
|
1717
|
+
var Rm = { exports: {} }, Og = { exports: {} }, _b$1;
|
|
1693
1718
|
function Kb() {
|
|
1694
|
-
return _b || (_b = 1, (function(Tt) {
|
|
1719
|
+
return _b$1 || (_b$1 = 1, (function(Tt) {
|
|
1695
1720
|
Tt.exports = function(m) {
|
|
1696
1721
|
function Yn(t, r, a, l) {
|
|
1697
1722
|
return new uc(t, r, a, l);
|
|
@@ -13541,7 +13566,10 @@ function extend(objects) {
|
|
|
13541
13566
|
catalogue[Component] = objects;
|
|
13542
13567
|
return Component;
|
|
13543
13568
|
} else {
|
|
13544
|
-
|
|
13569
|
+
for (const name in objects) {
|
|
13570
|
+
const object = objects[name];
|
|
13571
|
+
if (isConstructor(object)) catalogue[name] = object;
|
|
13572
|
+
}
|
|
13545
13573
|
}
|
|
13546
13574
|
}
|
|
13547
13575
|
function validateInstance(type, props) {
|
|
@@ -13889,7 +13917,7 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13889
13917
|
getRootHostContext: () => NO_CONTEXT,
|
|
13890
13918
|
getChildHostContext: () => NO_CONTEXT,
|
|
13891
13919
|
commitUpdate(instance, type, oldProps, newProps, fiber) {
|
|
13892
|
-
validateInstance(type, newProps);
|
|
13920
|
+
validateInstance(instance.type, newProps);
|
|
13893
13921
|
let reconstruct = false;
|
|
13894
13922
|
if (instance.type === "primitive" && oldProps.object !== newProps.object) reconstruct = true;
|
|
13895
13923
|
else if (newProps.args?.length !== oldProps.args?.length) reconstruct = true;
|
|
@@ -13916,8 +13944,8 @@ const reconciler = /* @__PURE__ */ createReconciler({
|
|
|
13916
13944
|
for (const prop in instance.props) {
|
|
13917
13945
|
const value = instance.props[prop];
|
|
13918
13946
|
if (isFromRef(value)) {
|
|
13919
|
-
const ref = value
|
|
13920
|
-
if (ref.current != null) resolved[prop] = ref.current;
|
|
13947
|
+
const { [FROM_REF]: ref, transform } = value;
|
|
13948
|
+
if (ref.current != null) resolved[prop] = transform ? transform(ref.current) : ref.current;
|
|
13921
13949
|
}
|
|
13922
13950
|
}
|
|
13923
13951
|
if (Object.keys(resolved).length) applyProps(instance.object, resolved);
|
|
@@ -14198,9 +14226,8 @@ function createRoot(canvas) {
|
|
|
14198
14226
|
if (!renderer.hasInitialized?.()) {
|
|
14199
14227
|
const size2 = computeInitialSize(canvas, propsSize);
|
|
14200
14228
|
if (size2.width > 0 && size2.height > 0) {
|
|
14201
|
-
|
|
14202
|
-
|
|
14203
|
-
canvas.height = size2.height * pixelRatio;
|
|
14229
|
+
renderer.setPixelRatio(calculateDpr(dpr));
|
|
14230
|
+
renderer.setSize(size2.width, size2.height, false);
|
|
14204
14231
|
}
|
|
14205
14232
|
await renderer.init();
|
|
14206
14233
|
}
|
|
@@ -14209,7 +14236,7 @@ function createRoot(canvas) {
|
|
|
14209
14236
|
state.internal.actualRenderer = renderer;
|
|
14210
14237
|
state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
|
|
14211
14238
|
if (canvasId && !state.internal.isSecondary) {
|
|
14212
|
-
const canvasTarget =
|
|
14239
|
+
const canvasTarget = renderer.getCanvasTarget?.();
|
|
14213
14240
|
const unregisterPrimary = registerPrimary(canvasId, renderer, store);
|
|
14214
14241
|
state.set((prev) => ({
|
|
14215
14242
|
internal: {
|
|
@@ -14323,7 +14350,7 @@ function createRoot(canvas) {
|
|
|
14323
14350
|
const handleXRFrame = (timestamp, _frame) => {
|
|
14324
14351
|
const state2 = store.getState();
|
|
14325
14352
|
if (state2.frameloop === "never") return;
|
|
14326
|
-
advance(timestamp);
|
|
14353
|
+
advance(timestamp, true, state2);
|
|
14327
14354
|
};
|
|
14328
14355
|
const actualRenderer = state.internal.actualRenderer;
|
|
14329
14356
|
const handleSessionChange = () => {
|
|
@@ -14331,7 +14358,7 @@ function createRoot(canvas) {
|
|
|
14331
14358
|
const renderer2 = state2.internal.actualRenderer;
|
|
14332
14359
|
actualRenderer.xr.enabled = actualRenderer.xr.isPresenting;
|
|
14333
14360
|
renderer2.xr.setAnimationLoop(renderer2.xr.isPresenting ? handleXRFrame : null);
|
|
14334
|
-
if (!renderer2.xr.isPresenting) invalidate();
|
|
14361
|
+
if (!renderer2.xr.isPresenting) invalidate(state2);
|
|
14335
14362
|
};
|
|
14336
14363
|
const xr = {
|
|
14337
14364
|
connect() {
|
|
@@ -14413,14 +14440,19 @@ function createRoot(canvas) {
|
|
|
14413
14440
|
const newRootId = canvasId || scheduler.generateRootId();
|
|
14414
14441
|
const unregisterRoot = scheduler.registerRoot(newRootId, {
|
|
14415
14442
|
getState: () => store.getState(),
|
|
14416
|
-
onError: (err) => store.getState().setError(err)
|
|
14443
|
+
onError: (err) => store.getState().setError(err),
|
|
14444
|
+
frameloop: store.getState().frameloop,
|
|
14445
|
+
before: schedulerConfig?.before,
|
|
14446
|
+
after: schedulerConfig?.after,
|
|
14447
|
+
order: schedulerConfig?.order
|
|
14417
14448
|
});
|
|
14418
14449
|
const unregisterCanvasTarget = scheduler.register(
|
|
14419
14450
|
() => {
|
|
14420
14451
|
const state2 = store.getState();
|
|
14421
|
-
|
|
14452
|
+
const canvasTarget = state2.internal.canvasTarget;
|
|
14453
|
+
if (canvasTarget) {
|
|
14422
14454
|
const renderer2 = state2.internal.actualRenderer;
|
|
14423
|
-
renderer2.setCanvasTarget(
|
|
14455
|
+
if (renderer2.getCanvasTarget() !== canvasTarget) renderer2.setCanvasTarget(canvasTarget);
|
|
14424
14456
|
if (state2.internal.canvasTargetSizeDirty) {
|
|
14425
14457
|
state2.internal.canvasTargetSizeDirty = false;
|
|
14426
14458
|
renderer2.backend?.updateSize?.();
|
|
@@ -14493,8 +14525,7 @@ function createRoot(canvas) {
|
|
|
14493
14525
|
phase: "render",
|
|
14494
14526
|
system: true,
|
|
14495
14527
|
// Internal flag: this is a system job, not user-controlled
|
|
14496
|
-
//
|
|
14497
|
-
...schedulerConfig?.after && { after: schedulerConfig.after },
|
|
14528
|
+
// FPS throttles only the default render job; Canvas ordering belongs to the root.
|
|
14498
14529
|
...schedulerConfig?.fps && { fps: schedulerConfig.fps }
|
|
14499
14530
|
}
|
|
14500
14531
|
);
|
|
@@ -14513,8 +14544,21 @@ function createRoot(canvas) {
|
|
|
14513
14544
|
scheduler
|
|
14514
14545
|
}
|
|
14515
14546
|
}));
|
|
14547
|
+
} else {
|
|
14548
|
+
const constraintsChanged = !is.equ(schedulerConfig?.before, lastConfiguredProps.schedulerBefore, shallowLoose) || !is.equ(schedulerConfig?.after, lastConfiguredProps.schedulerAfter, shallowLoose);
|
|
14549
|
+
if (constraintsChanged) {
|
|
14550
|
+
scheduler.setRootConstraints(rootId, {
|
|
14551
|
+
before: schedulerConfig?.before,
|
|
14552
|
+
after: schedulerConfig?.after
|
|
14553
|
+
});
|
|
14554
|
+
}
|
|
14555
|
+
if (schedulerConfig?.order !== lastConfiguredProps.schedulerOrder) {
|
|
14556
|
+
scheduler.setRootOrder(rootId, schedulerConfig?.order ?? 0);
|
|
14557
|
+
}
|
|
14516
14558
|
}
|
|
14517
|
-
|
|
14559
|
+
lastConfiguredProps.schedulerBefore = schedulerConfig?.before;
|
|
14560
|
+
lastConfiguredProps.schedulerAfter = schedulerConfig?.after;
|
|
14561
|
+
lastConfiguredProps.schedulerOrder = schedulerConfig?.order;
|
|
14518
14562
|
onCreated = onCreatedCallback;
|
|
14519
14563
|
configured = true;
|
|
14520
14564
|
resolve();
|
|
@@ -14556,18 +14600,23 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
14556
14600
|
const fiber = root?.fiber;
|
|
14557
14601
|
if (fiber) {
|
|
14558
14602
|
const state = root?.store.getState();
|
|
14559
|
-
if (state)
|
|
14603
|
+
if (state) {
|
|
14604
|
+
state.internal.active = false;
|
|
14605
|
+
const unregisterRoot = state.internal.unregisterRoot;
|
|
14606
|
+
if (unregisterRoot) {
|
|
14607
|
+
unregisterRoot();
|
|
14608
|
+
state.internal.unregisterRoot = void 0;
|
|
14609
|
+
}
|
|
14610
|
+
}
|
|
14560
14611
|
reconciler.updateContainer(null, fiber, null, () => {
|
|
14561
14612
|
if (state) {
|
|
14562
14613
|
setTimeout(() => {
|
|
14563
14614
|
try {
|
|
14564
14615
|
const renderer = state.internal.actualRenderer;
|
|
14565
|
-
const unregisterRoot = state.internal.unregisterRoot;
|
|
14566
|
-
if (unregisterRoot) unregisterRoot();
|
|
14567
14616
|
const unregisterPrimary = state.internal.unregisterPrimary;
|
|
14568
14617
|
if (unregisterPrimary) unregisterPrimary();
|
|
14569
14618
|
const canvasTarget = state.internal.canvasTarget;
|
|
14570
|
-
if (canvasTarget?.dispose) canvasTarget.dispose();
|
|
14619
|
+
if (state.internal.isSecondary && canvasTarget?.dispose) canvasTarget.dispose();
|
|
14571
14620
|
state.events.disconnect?.();
|
|
14572
14621
|
cleanupHelperGroup(root.store);
|
|
14573
14622
|
if (state.isLegacy && renderer) {
|
|
@@ -14708,16 +14757,11 @@ function setEnvProps(background, scene, defaultScene, texture, sceneProps = {})
|
|
|
14708
14757
|
const oldbg = target.background;
|
|
14709
14758
|
const oldenv = target.environment;
|
|
14710
14759
|
const oldSceneProps = {
|
|
14711
|
-
// @ts-ignore
|
|
14712
14760
|
backgroundBlurriness: target.backgroundBlurriness,
|
|
14713
|
-
// @ts-ignore
|
|
14714
14761
|
backgroundIntensity: target.backgroundIntensity,
|
|
14715
|
-
|
|
14716
|
-
backgroundRotation: target.backgroundRotation?.clone?.() ?? [0, 0, 0],
|
|
14717
|
-
// @ts-ignore
|
|
14762
|
+
backgroundRotation: target.backgroundRotation.clone(),
|
|
14718
14763
|
environmentIntensity: target.environmentIntensity,
|
|
14719
|
-
|
|
14720
|
-
environmentRotation: target.environmentRotation?.clone?.() ?? [0, 0, 0]
|
|
14764
|
+
environmentRotation: target.environmentRotation.clone()
|
|
14721
14765
|
};
|
|
14722
14766
|
if (background !== "only") target.environment = texture;
|
|
14723
14767
|
if (background) target.background = texture;
|
|
@@ -15108,9 +15152,9 @@ function CanvasImpl({
|
|
|
15108
15152
|
React.useMemo(() => extend(THREE), []);
|
|
15109
15153
|
const Bridge = useBridge();
|
|
15110
15154
|
const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
|
|
15111
|
-
const
|
|
15155
|
+
const [hasInitialSize, setHasInitialSize] = React.useState(false);
|
|
15112
15156
|
const measureConfig = React.useMemo(() => {
|
|
15113
|
-
if (!
|
|
15157
|
+
if (!hasInitialSize) {
|
|
15114
15158
|
return {
|
|
15115
15159
|
...resize,
|
|
15116
15160
|
scroll: resize?.scroll ?? true,
|
|
@@ -15122,7 +15166,7 @@ function CanvasImpl({
|
|
|
15122
15166
|
debounce: { scroll: 50, resize: 0 },
|
|
15123
15167
|
...resize
|
|
15124
15168
|
};
|
|
15125
|
-
}, [
|
|
15169
|
+
}, [hasInitialSize, resize]);
|
|
15126
15170
|
const [containerRef, containerRect] = useMeasure(measureConfig);
|
|
15127
15171
|
const effectiveSize = React.useMemo(() => {
|
|
15128
15172
|
let w = width ?? containerRect.width;
|
|
@@ -15138,9 +15182,7 @@ function CanvasImpl({
|
|
|
15138
15182
|
left: containerRect.left
|
|
15139
15183
|
};
|
|
15140
15184
|
}, [width, height, containerRect, forceEven]);
|
|
15141
|
-
if (!
|
|
15142
|
-
hasInitialSizeRef.current = true;
|
|
15143
|
-
}
|
|
15185
|
+
if (!hasInitialSize && effectiveSize.width > 0 && effectiveSize.height > 0) setHasInitialSize(true);
|
|
15144
15186
|
const canvasRef = React.useRef(null);
|
|
15145
15187
|
const divRef = React.useRef(null);
|
|
15146
15188
|
React.useImperativeHandle(ref, () => canvasRef.current);
|
|
@@ -15254,6 +15296,7 @@ function CanvasImpl({
|
|
|
15254
15296
|
const canvas = canvasRef.current;
|
|
15255
15297
|
if (canvas) {
|
|
15256
15298
|
return () => {
|
|
15299
|
+
if (canvas.isConnected) return;
|
|
15257
15300
|
unmountComponentAtNode(canvas);
|
|
15258
15301
|
root.current = null;
|
|
15259
15302
|
};
|
|
@@ -15312,20 +15355,36 @@ function CanvasImpl({
|
|
|
15312
15355
|
}
|
|
15313
15356
|
);
|
|
15314
15357
|
}
|
|
15315
|
-
function Canvas(props) {
|
|
15358
|
+
function Canvas$1(props) {
|
|
15316
15359
|
return /* @__PURE__ */ jsx(FiberProvider, { children: /* @__PURE__ */ jsx(CanvasImpl, { ...props }) });
|
|
15317
15360
|
}
|
|
15318
15361
|
|
|
15362
|
+
const isObjectLike = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
15363
|
+
const hasValidLegacyNodeMarkers = (value) => {
|
|
15364
|
+
const hasUuid = "uuid" in value;
|
|
15365
|
+
const hasNodeType = "nodeType" in value;
|
|
15366
|
+
const uuid = Reflect.get(value, "uuid");
|
|
15367
|
+
const nodeType = Reflect.get(value, "nodeType");
|
|
15368
|
+
return (hasUuid || hasNodeType) && (!hasUuid || uuid === void 0 || typeof uuid === "string") && (!hasNodeType || nodeType === void 0 || nodeType === null || typeof nodeType === "string");
|
|
15369
|
+
};
|
|
15370
|
+
const isUniformNode = (value) => isObjectLike(value) && "isUniformNode" in value && value.isUniformNode === true;
|
|
15371
|
+
const isTSLNode = (value) => isObjectLike(value) && (Reflect.get(value, "isNode") === true || Reflect.get(value, "shaderNode") !== void 0 && typeof Reflect.get(value, "id") === "number" || hasValidLegacyNodeMarkers(value));
|
|
15372
|
+
const isBufferLike = (value) => ArrayBuffer.isView(value) && !(value instanceof DataView) || isObjectLike(value) && ("isBufferAttribute" in value || "isInterleavedBufferAttribute" in value || isTSLNode(value));
|
|
15373
|
+
const isStorageLike = (value) => isObjectLike(value) && ("isTexture" in value || "isData3DTexture" in value || isTSLNode(value));
|
|
15374
|
+
|
|
15319
15375
|
var __defProp = Object.defineProperty;
|
|
15320
15376
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15321
15377
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15322
|
-
var _a;
|
|
15378
|
+
var _a, _b;
|
|
15323
15379
|
const INTERNAL_DATA = Symbol("ScopedStore.data");
|
|
15324
|
-
|
|
15380
|
+
const INTERNAL_IS_LEAF = Symbol("ScopedStore.isLeaf");
|
|
15381
|
+
_b = INTERNAL_DATA, _a = INTERNAL_IS_LEAF;
|
|
15325
15382
|
const _ScopedStore = class _ScopedStore {
|
|
15326
|
-
constructor(data) {
|
|
15383
|
+
constructor(data, isLeaf) {
|
|
15384
|
+
__publicField(this, _b);
|
|
15327
15385
|
__publicField(this, _a);
|
|
15328
15386
|
this[INTERNAL_DATA] = data;
|
|
15387
|
+
this[INTERNAL_IS_LEAF] = isLeaf;
|
|
15329
15388
|
return new Proxy(this, {
|
|
15330
15389
|
get(target, prop, receiver) {
|
|
15331
15390
|
if (typeof prop === "string") {
|
|
@@ -15359,10 +15418,10 @@ const _ScopedStore = class _ScopedStore {
|
|
|
15359
15418
|
* If the key doesn't exist or isn't a scope object, returns an empty ScopedStore.
|
|
15360
15419
|
*/
|
|
15361
15420
|
scope(key) {
|
|
15362
|
-
const
|
|
15363
|
-
|
|
15364
|
-
|
|
15365
|
-
);
|
|
15421
|
+
const value = this[INTERNAL_DATA][key];
|
|
15422
|
+
const isLeaf = this[INTERNAL_IS_LEAF];
|
|
15423
|
+
const scope = value && typeof value === "object" && !isLeaf(value) ? value : {};
|
|
15424
|
+
return new _ScopedStore(scope, isLeaf);
|
|
15366
15425
|
}
|
|
15367
15426
|
/**
|
|
15368
15427
|
* Check if a key exists in the store.
|
|
@@ -15378,8 +15437,8 @@ const _ScopedStore = class _ScopedStore {
|
|
|
15378
15437
|
}
|
|
15379
15438
|
};
|
|
15380
15439
|
let ScopedStore = _ScopedStore;
|
|
15381
|
-
function createScopedStore(data) {
|
|
15382
|
-
return new ScopedStore(data);
|
|
15440
|
+
function createScopedStore(data, isLeaf) {
|
|
15441
|
+
return new ScopedStore(data, isLeaf);
|
|
15383
15442
|
}
|
|
15384
15443
|
function createLazyCreatorState(state, store) {
|
|
15385
15444
|
let _uniforms = null;
|
|
@@ -15390,22 +15449,22 @@ function createLazyCreatorState(state, store) {
|
|
|
15390
15449
|
return Object.create(state, {
|
|
15391
15450
|
uniforms: {
|
|
15392
15451
|
get() {
|
|
15393
|
-
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms")));
|
|
15452
|
+
return _uniforms ?? (_uniforms = createScopedStore(view("uniforms"), isUniformNode));
|
|
15394
15453
|
}
|
|
15395
15454
|
},
|
|
15396
15455
|
nodes: {
|
|
15397
15456
|
get() {
|
|
15398
|
-
return _nodes ?? (_nodes = createScopedStore(view("nodes")));
|
|
15457
|
+
return _nodes ?? (_nodes = createScopedStore(view("nodes"), isTSLNode));
|
|
15399
15458
|
}
|
|
15400
15459
|
},
|
|
15401
15460
|
buffers: {
|
|
15402
15461
|
get() {
|
|
15403
|
-
return _buffers ?? (_buffers = createScopedStore(view("buffers")));
|
|
15462
|
+
return _buffers ?? (_buffers = createScopedStore(view("buffers"), isBufferLike));
|
|
15404
15463
|
}
|
|
15405
15464
|
},
|
|
15406
15465
|
gpuStorage: {
|
|
15407
15466
|
get() {
|
|
15408
|
-
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage")));
|
|
15467
|
+
return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage"), isStorageLike));
|
|
15409
15468
|
}
|
|
15410
15469
|
}
|
|
15411
15470
|
});
|
|
@@ -15506,7 +15565,7 @@ function vectorize(inObject) {
|
|
|
15506
15565
|
return extractTSLValue(inObject);
|
|
15507
15566
|
}
|
|
15508
15567
|
if (obj.isVector2 || obj.isVector3 || obj.isVector4) return inObject;
|
|
15509
|
-
if (obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15568
|
+
if (obj.isMatrix2 || obj.isMatrix3 || obj.isMatrix4) return inObject;
|
|
15510
15569
|
if (obj.isColor || obj.isEuler || obj.isQuaternion || obj.isSpherical) return inObject;
|
|
15511
15570
|
if ("r" in obj && "g" in obj && "b" in obj && typeof obj.r === "number" && typeof obj.g === "number" && typeof obj.b === "number") {
|
|
15512
15571
|
const scale = obj.r > 1 || obj.g > 1 || obj.b > 1 ? 1 / 255 : 1;
|
|
@@ -15564,22 +15623,21 @@ function useScopedResource(options) {
|
|
|
15564
15623
|
return entries;
|
|
15565
15624
|
}
|
|
15566
15625
|
|
|
15567
|
-
const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15568
15626
|
function useUniforms(creatorOrScope, scope) {
|
|
15569
15627
|
const store = usePrimaryStore();
|
|
15570
15628
|
const removeUniforms2 = useCallback(
|
|
15571
|
-
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode
|
|
15629
|
+
(names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode),
|
|
15572
15630
|
[store]
|
|
15573
15631
|
);
|
|
15574
15632
|
const clearUniforms = useCallback(
|
|
15575
|
-
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode
|
|
15633
|
+
(targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode),
|
|
15576
15634
|
[store]
|
|
15577
15635
|
);
|
|
15578
15636
|
const rebuildUniforms = useCallback(
|
|
15579
15637
|
(targetScope) => rebuildResource(store, "uniforms", targetScope),
|
|
15580
15638
|
[store]
|
|
15581
15639
|
);
|
|
15582
|
-
const
|
|
15640
|
+
const processedInput = useMemo(() => {
|
|
15583
15641
|
let raw = creatorOrScope;
|
|
15584
15642
|
if (is.fun(creatorOrScope)) {
|
|
15585
15643
|
const wrappedState = createLazyCreatorState(store.getState(), store);
|
|
@@ -15590,23 +15648,24 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
15590
15648
|
for (const [key, value] of Object.entries(raw)) {
|
|
15591
15649
|
normalized[key] = vectorize(value);
|
|
15592
15650
|
}
|
|
15593
|
-
return normalized;
|
|
15651
|
+
return { candidates: raw, normalized };
|
|
15594
15652
|
}
|
|
15595
|
-
return raw;
|
|
15653
|
+
return { candidates: raw, normalized: raw };
|
|
15596
15654
|
}, [creatorOrScope, store]);
|
|
15597
|
-
const memoizedInput = useCompareMemoize(
|
|
15655
|
+
const memoizedInput = useCompareMemoize(processedInput.normalized);
|
|
15598
15656
|
const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
|
|
15599
15657
|
const storeUniforms = usePrimaryThree((s) => s.uniforms);
|
|
15600
15658
|
const created = useScopedResource({
|
|
15601
15659
|
store,
|
|
15602
15660
|
kind: "uniforms",
|
|
15603
15661
|
scope: isReader ? void 0 : scope,
|
|
15604
|
-
isLeaf: isUniformNode
|
|
15662
|
+
isLeaf: isUniformNode,
|
|
15605
15663
|
input: memoizedInput,
|
|
15606
15664
|
create: () => {
|
|
15607
15665
|
if (isReader) return {};
|
|
15608
|
-
if (typeof
|
|
15609
|
-
|
|
15666
|
+
if (typeof processedInput.candidates !== "object" || processedInput.candidates === null)
|
|
15667
|
+
throw new Error("Invalid uniform input");
|
|
15668
|
+
return processedInput.candidates;
|
|
15610
15669
|
},
|
|
15611
15670
|
prepare: (name, candidate) => createUniform(name, candidate, scope),
|
|
15612
15671
|
reconcile: (existing, candidate) => {
|
|
@@ -15628,7 +15687,7 @@ function useUniforms(creatorOrScope, scope) {
|
|
|
15628
15687
|
uniforms = storeUniforms;
|
|
15629
15688
|
} else if (typeof memoizedInput === "string") {
|
|
15630
15689
|
const scopeData = storeUniforms[memoizedInput];
|
|
15631
|
-
uniforms = scopeData && !isUniformNode
|
|
15690
|
+
uniforms = scopeData && !isUniformNode(scopeData) ? scopeData : {};
|
|
15632
15691
|
}
|
|
15633
15692
|
return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
|
|
15634
15693
|
}
|
|
@@ -15643,7 +15702,7 @@ function removeUniforms(set, names, scope) {
|
|
|
15643
15702
|
return { uniforms: { ...state.uniforms, [scope]: currentScope } };
|
|
15644
15703
|
}
|
|
15645
15704
|
const uniforms = { ...state.uniforms };
|
|
15646
|
-
for (const name of names) if (isUniformNode
|
|
15705
|
+
for (const name of names) if (isUniformNode(uniforms[name])) delete uniforms[name];
|
|
15647
15706
|
return { uniforms };
|
|
15648
15707
|
});
|
|
15649
15708
|
}
|
|
@@ -15657,7 +15716,7 @@ function clearRootUniforms(set) {
|
|
|
15657
15716
|
set((state) => {
|
|
15658
15717
|
const uniforms = {};
|
|
15659
15718
|
for (const [key, value] of Object.entries(state.uniforms)) {
|
|
15660
|
-
if (!isUniformNode
|
|
15719
|
+
if (!isUniformNode(value)) uniforms[key] = value;
|
|
15661
15720
|
}
|
|
15662
15721
|
return { uniforms };
|
|
15663
15722
|
});
|
|
@@ -15693,12 +15752,10 @@ function hasEqualsMethod(value) {
|
|
|
15693
15752
|
function isSameThreeType(a, b) {
|
|
15694
15753
|
const obj_a = a;
|
|
15695
15754
|
const obj_b = b;
|
|
15696
|
-
return obj_a.isColor && obj_b.isColor || obj_a.isMatrix3 && obj_b.isMatrix3 || obj_a.isMatrix4 && obj_b.isMatrix4 || obj_a.isEuler && obj_b.isEuler || obj_a.isQuaternion && obj_b.isQuaternion;
|
|
15755
|
+
return obj_a.isColor && obj_b.isColor || obj_a.isMatrix2 && obj_b.isMatrix2 || obj_a.isMatrix3 && obj_b.isMatrix3 || obj_a.isMatrix4 && obj_b.isMatrix4 || obj_a.isEuler && obj_b.isEuler || obj_a.isQuaternion && obj_b.isQuaternion;
|
|
15697
15756
|
}
|
|
15698
15757
|
|
|
15699
15758
|
const uniformOf = uniform;
|
|
15700
|
-
const isUniformNode = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
|
|
15701
|
-
const isTSLNode$1 = (value) => value !== null && typeof value === "object" && "uuid" in value && "nodeType" in value;
|
|
15702
15759
|
function useUniform(name, value) {
|
|
15703
15760
|
const store = useStore();
|
|
15704
15761
|
const registered = useScopedResource({
|
|
@@ -15710,7 +15767,7 @@ function useUniform(name, value) {
|
|
|
15710
15767
|
create: () => value === void 0 ? {} : { [name]: value },
|
|
15711
15768
|
prepare: createNamedUniform,
|
|
15712
15769
|
reconcile: (existing2) => {
|
|
15713
|
-
if (value !== void 0 && !isTSLNode
|
|
15770
|
+
if (value !== void 0 && !isTSLNode(value) && !isUniformNode(value)) {
|
|
15714
15771
|
existing2.value = typeof value === "string" ? new Color(value) : value;
|
|
15715
15772
|
}
|
|
15716
15773
|
}
|
|
@@ -15726,7 +15783,7 @@ function createNamedUniform(name, value) {
|
|
|
15726
15783
|
let node;
|
|
15727
15784
|
if (isUniformNode(value)) {
|
|
15728
15785
|
node = value;
|
|
15729
|
-
} else if (isTSLNode
|
|
15786
|
+
} else if (isTSLNode(value)) {
|
|
15730
15787
|
node = uniformOf(value);
|
|
15731
15788
|
} else if (typeof value === "string") {
|
|
15732
15789
|
node = uniform(new Color(value));
|
|
@@ -15739,7 +15796,6 @@ function createNamedUniform(name, value) {
|
|
|
15739
15796
|
return node;
|
|
15740
15797
|
}
|
|
15741
15798
|
|
|
15742
|
-
const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
|
|
15743
15799
|
function useNodes(creatorOrScope, scope) {
|
|
15744
15800
|
const store = usePrimaryStore();
|
|
15745
15801
|
const removeNodes2 = useCallback(
|
|
@@ -15766,7 +15822,8 @@ function useNodes(creatorOrScope, scope) {
|
|
|
15766
15822
|
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15767
15823
|
},
|
|
15768
15824
|
prepare: (name, node) => {
|
|
15769
|
-
|
|
15825
|
+
const setName = Reflect.get(node, "setName");
|
|
15826
|
+
if (typeof setName === "function") setName.call(node, scopedNodeName(scope, name));
|
|
15770
15827
|
return node;
|
|
15771
15828
|
}
|
|
15772
15829
|
});
|
|
@@ -15821,13 +15878,6 @@ function useLocalNodes(creator) {
|
|
|
15821
15878
|
}, [store, creator, uniforms, nodes, textures, hmrVersion]);
|
|
15822
15879
|
}
|
|
15823
15880
|
|
|
15824
|
-
const isBufferLike = (value) => {
|
|
15825
|
-
if (value === null || typeof value !== "object") return false;
|
|
15826
|
-
if (ArrayBuffer.isView(value)) return true;
|
|
15827
|
-
if ("isBufferAttribute" in value) return true;
|
|
15828
|
-
if ("uuid" in value || "nodeType" in value) return true;
|
|
15829
|
-
return false;
|
|
15830
|
-
};
|
|
15831
15881
|
const disposeBuffer = (buffer) => {
|
|
15832
15882
|
if (buffer === null || typeof buffer !== "object") return;
|
|
15833
15883
|
if ("dispose" in buffer && typeof buffer.dispose === "function") {
|
|
@@ -15874,9 +15924,8 @@ function useBuffers(creatorOrScope, scope) {
|
|
|
15874
15924
|
return creatorOrScope(createLazyCreatorState(store.getState(), store));
|
|
15875
15925
|
},
|
|
15876
15926
|
prepare: (name, buffer) => {
|
|
15877
|
-
|
|
15878
|
-
|
|
15879
|
-
}
|
|
15927
|
+
const setName = Reflect.get(buffer, "setName");
|
|
15928
|
+
if (typeof setName === "function") setName.call(buffer, scopedNodeName(scope, name));
|
|
15880
15929
|
return buffer;
|
|
15881
15930
|
}
|
|
15882
15931
|
});
|
|
@@ -15893,13 +15942,6 @@ function rebuildAllBuffers(store, scope) {
|
|
|
15893
15942
|
rebuildResource(store, "buffers", scope);
|
|
15894
15943
|
}
|
|
15895
15944
|
|
|
15896
|
-
const isStorageLike = (value) => {
|
|
15897
|
-
if (value === null || typeof value !== "object") return false;
|
|
15898
|
-
if ("isTexture" in value) return true;
|
|
15899
|
-
if ("isData3DTexture" in value) return true;
|
|
15900
|
-
if ("uuid" in value || "nodeType" in value) return true;
|
|
15901
|
-
return false;
|
|
15902
|
-
};
|
|
15903
15945
|
const disposeStorage = (storage) => {
|
|
15904
15946
|
if (storage === null || typeof storage !== "object") return;
|
|
15905
15947
|
if ("dispose" in storage && typeof storage.dispose === "function") {
|
|
@@ -15947,9 +15989,8 @@ function useGPUStorage(creatorOrScope, scope) {
|
|
|
15947
15989
|
},
|
|
15948
15990
|
prepare: (name, storage) => {
|
|
15949
15991
|
const label = scopedNodeName(scope, name);
|
|
15950
|
-
|
|
15951
|
-
|
|
15952
|
-
}
|
|
15992
|
+
const setName = Reflect.get(storage, "setName");
|
|
15993
|
+
if (typeof setName === "function") setName.call(storage, label);
|
|
15953
15994
|
if ("name" in storage && typeof storage.name === "string") {
|
|
15954
15995
|
storage.name = label;
|
|
15955
15996
|
}
|
|
@@ -15980,6 +16021,7 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
15980
16021
|
const { scene, camera, renderer, isLegacy } = useThree$1();
|
|
15981
16022
|
const callbacksRanRef = useRef(false);
|
|
15982
16023
|
const scenePassCacheRef = useRef(null);
|
|
16024
|
+
const forceScenePassRebuildRef = useRef(false);
|
|
15983
16025
|
const mainCBRef = useRef(mainCB);
|
|
15984
16026
|
const setupCBRef = useRef(setupCB);
|
|
15985
16027
|
mainCBRef.current = mainCB;
|
|
@@ -15987,7 +16029,7 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
15987
16029
|
const [rebuildVersion, setRebuildVersion] = useState(0);
|
|
15988
16030
|
useEffect(() => {
|
|
15989
16031
|
callbacksRanRef.current = false;
|
|
15990
|
-
|
|
16032
|
+
forceScenePassRebuildRef.current = true;
|
|
15991
16033
|
}, []);
|
|
15992
16034
|
const clearPasses = useCallback(() => {
|
|
15993
16035
|
store.setState({ passes: {} });
|
|
@@ -15997,12 +16039,14 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
15997
16039
|
renderPipeline: null,
|
|
15998
16040
|
passes: {}
|
|
15999
16041
|
});
|
|
16042
|
+
scenePassCacheRef.current?.scenePass.dispose();
|
|
16000
16043
|
callbacksRanRef.current = false;
|
|
16001
16044
|
scenePassCacheRef.current = null;
|
|
16045
|
+
forceScenePassRebuildRef.current = false;
|
|
16002
16046
|
}, [store]);
|
|
16003
16047
|
const rebuild = useCallback(() => {
|
|
16004
16048
|
callbacksRanRef.current = false;
|
|
16005
|
-
|
|
16049
|
+
forceScenePassRebuildRef.current = true;
|
|
16006
16050
|
setRebuildVersion((v) => v + 1);
|
|
16007
16051
|
}, []);
|
|
16008
16052
|
useLayoutEffect(() => {
|
|
@@ -16010,6 +16054,9 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16010
16054
|
throw new Error("useRenderPipeline is only available with WebGPU renderer. Set renderer prop on Canvas.");
|
|
16011
16055
|
}
|
|
16012
16056
|
if (!renderer || !scene || !camera) return;
|
|
16057
|
+
if (!("isWebGPURenderer" in renderer)) {
|
|
16058
|
+
throw new Error("useRenderPipeline: renderer is not a WebGPURenderer but isLegacy is false.");
|
|
16059
|
+
}
|
|
16013
16060
|
const state = store.getState();
|
|
16014
16061
|
const set = store.setState;
|
|
16015
16062
|
try {
|
|
@@ -16020,21 +16067,33 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16020
16067
|
pipeline = new RenderPipeline(renderer);
|
|
16021
16068
|
justCreatedPipeline = true;
|
|
16022
16069
|
}
|
|
16023
|
-
const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
16070
|
+
const cacheValid = !forceScenePassRebuildRef.current && scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
|
|
16071
|
+
let outgoingScenePass = null;
|
|
16024
16072
|
let scenePass;
|
|
16025
16073
|
if (cacheValid) {
|
|
16026
16074
|
scenePass = scenePassCacheRef.current.scenePass;
|
|
16027
16075
|
} else {
|
|
16076
|
+
outgoingScenePass = scenePassCacheRef.current?.scenePass ?? null;
|
|
16028
16077
|
scenePass = pass(scene, camera);
|
|
16029
16078
|
scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
|
|
16079
|
+
forceScenePassRebuildRef.current = false;
|
|
16030
16080
|
}
|
|
16031
16081
|
currentPasses.scenePass = scenePass;
|
|
16032
|
-
|
|
16082
|
+
let outputNodeChanged = false;
|
|
16083
|
+
if (!pipeline.outputNode || justCreatedPipeline || pipeline.outputNode === outgoingScenePass) {
|
|
16084
|
+
pipeline.outputNode = scenePass;
|
|
16085
|
+
outputNodeChanged = true;
|
|
16086
|
+
}
|
|
16033
16087
|
set({ renderPipeline: pipeline, passes: currentPasses });
|
|
16034
16088
|
const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
|
|
16035
16089
|
if (shouldRunCallbacks) {
|
|
16036
16090
|
if (setupCBRef.current) {
|
|
16037
|
-
const freshState = store.getState()
|
|
16091
|
+
const freshState = Object.assign({}, store.getState(), {
|
|
16092
|
+
renderPipeline: pipeline,
|
|
16093
|
+
passes: { ...currentPasses, scenePass },
|
|
16094
|
+
renderer,
|
|
16095
|
+
isLegacy: false
|
|
16096
|
+
});
|
|
16038
16097
|
const setupResult = setupCBRef.current(freshState);
|
|
16039
16098
|
if (setupResult && typeof setupResult === "object") {
|
|
16040
16099
|
currentPasses = { ...currentPasses, ...setupResult };
|
|
@@ -16042,34 +16101,37 @@ function useRenderPipeline(mainCB, setupCB) {
|
|
|
16042
16101
|
}
|
|
16043
16102
|
}
|
|
16044
16103
|
if (mainCBRef.current) {
|
|
16045
|
-
const freshState = store.getState()
|
|
16104
|
+
const freshState = Object.assign({}, store.getState(), {
|
|
16105
|
+
renderPipeline: pipeline,
|
|
16106
|
+
passes: { ...currentPasses, scenePass },
|
|
16107
|
+
renderer,
|
|
16108
|
+
isLegacy: false
|
|
16109
|
+
});
|
|
16046
16110
|
const mainResult = mainCBRef.current(freshState);
|
|
16047
16111
|
if (mainResult && typeof mainResult === "object") {
|
|
16048
16112
|
currentPasses = { ...currentPasses, ...mainResult };
|
|
16049
16113
|
set({ passes: currentPasses });
|
|
16050
16114
|
}
|
|
16051
16115
|
}
|
|
16116
|
+
outputNodeChanged = true;
|
|
16052
16117
|
callbacksRanRef.current = true;
|
|
16053
16118
|
}
|
|
16119
|
+
if (outputNodeChanged) pipeline.needsUpdate = true;
|
|
16120
|
+
if (outgoingScenePass && outgoingScenePass !== scenePass) outgoingScenePass.dispose();
|
|
16054
16121
|
} catch (error) {
|
|
16055
16122
|
console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
|
|
16056
16123
|
}
|
|
16057
16124
|
}, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
|
|
16058
16125
|
const passes = useThree$1((s) => s.passes);
|
|
16059
16126
|
const renderPipeline = useThree$1((s) => s.renderPipeline);
|
|
16060
|
-
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
clearPasses,
|
|
16064
|
-
reset,
|
|
16065
|
-
rebuild,
|
|
16066
|
-
// isReady indicates if RenderPipeline is configured and ready for rendering
|
|
16067
|
-
isReady: renderPipeline !== null
|
|
16068
|
-
};
|
|
16127
|
+
const actions = { passes, clearPasses, reset, rebuild };
|
|
16128
|
+
if (renderPipeline) return { ...actions, isReady: true, renderPipeline };
|
|
16129
|
+
return { ...actions, isReady: false, renderPipeline: null };
|
|
16069
16130
|
}
|
|
16070
16131
|
|
|
16071
16132
|
extend(THREE);
|
|
16072
16133
|
const useThree = useThree$1;
|
|
16073
16134
|
const useFrame = useFrame$1;
|
|
16135
|
+
const Canvas = Canvas$1;
|
|
16074
16136
|
|
|
16075
16137
|
export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef$1 as isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };
|