@react-three/fiber 10.0.0-canary.2c50459 → 10.0.0-canary.4a21acb

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.
@@ -1,5 +1,5 @@
1
1
  import * as webgpu from 'three/webgpu';
2
- import { RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, WebGLCubeRenderTarget, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, Vector4, PostProcessing } from 'three/webgpu';
2
+ import { CubeRenderTarget, RenderTarget, CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader, Scene, HalfFloatType, Color, Frustum, Matrix4, Group, BoxGeometry, MeshBasicNodeMaterial, Mesh, Node, NodeUpdateType, Layers, ShaderMaterial, Uniform, SRGBColorSpace, RGBAFormat, UnsignedByteType, Vector3, Vector2, TextureLoader, Texture as Texture$1, CanvasTarget, Raycaster, OrthographicCamera, PerspectiveCamera, PCFShadowMap, VSMShadowMap, BasicShadowMap, ACESFilmicToneMapping, WebGPURenderer, Vector4, RenderPipeline } from 'three/webgpu';
3
3
  import { Inspector } from 'three/addons/inspector/Inspector.js';
4
4
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
@@ -43,13 +43,16 @@ const WebGLRenderer = class WebGLRenderer2 {
43
43
  }
44
44
  };
45
45
  const WebGLRenderTarget = null;
46
+ const WebGLCubeRenderTarget = null;
46
47
 
47
48
  const THREE = /*#__PURE__*/_mergeNamespaces({
48
49
  __proto__: null,
50
+ CubeRenderTargetCompat: CubeRenderTarget,
49
51
  Inspector: Inspector,
50
52
  R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
51
53
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
52
54
  RenderTargetCompat: RenderTarget,
55
+ WebGLCubeRenderTarget: WebGLCubeRenderTarget,
53
56
  WebGLRenderTarget: WebGLRenderTarget,
54
57
  WebGLRenderer: WebGLRenderer
55
58
  }, [webgpu]);
@@ -323,15 +326,16 @@ function EnvironmentPortal({
323
326
  preset = void 0,
324
327
  extensions
325
328
  }) {
326
- const gl = useThree$1((state) => state.gl);
329
+ const renderer = useThree$1((state) => state.renderer);
330
+ const isLegacy = useThree$1((state) => state.isLegacy);
327
331
  const defaultScene = useThree$1((state) => state.scene);
328
332
  const camera = React.useRef(null);
329
333
  const [virtualScene] = React.useState(() => new Scene());
330
334
  const fbo = React.useMemo(() => {
331
- const fbo2 = new WebGLCubeRenderTarget(resolution);
335
+ const fbo2 = isLegacy ? new WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
332
336
  fbo2.texture.type = HalfFloatType;
333
337
  return fbo2;
334
- }, [resolution]);
338
+ }, [resolution, isLegacy]);
335
339
  React.useEffect(() => {
336
340
  return () => {
337
341
  fbo.dispose();
@@ -339,10 +343,10 @@ function EnvironmentPortal({
339
343
  }, [fbo]);
340
344
  React.useLayoutEffect(() => {
341
345
  if (frames === 1) {
342
- const autoClear = gl.autoClear;
343
- gl.autoClear = true;
344
- camera.current.update(gl, virtualScene);
345
- gl.autoClear = autoClear;
346
+ const autoClear = renderer.autoClear;
347
+ renderer.autoClear = true;
348
+ camera.current.update(renderer, virtualScene);
349
+ renderer.autoClear = autoClear;
346
350
  }
347
351
  return setEnvProps(background, scene, defaultScene, fbo.texture, {
348
352
  backgroundBlurriness: blur ?? backgroundBlurriness,
@@ -359,7 +363,7 @@ function EnvironmentPortal({
359
363
  defaultScene,
360
364
  background,
361
365
  frames,
362
- gl,
366
+ renderer,
363
367
  blur,
364
368
  backgroundBlurriness,
365
369
  backgroundIntensity,
@@ -370,10 +374,10 @@ function EnvironmentPortal({
370
374
  let count = 1;
371
375
  useFrame$1(() => {
372
376
  if (frames === Infinity || count < frames) {
373
- const autoClear = gl.autoClear;
374
- gl.autoClear = true;
375
- camera.current.update(gl, virtualScene);
376
- gl.autoClear = autoClear;
377
+ const autoClear = renderer.autoClear;
378
+ renderer.autoClear = true;
379
+ camera.current.update(renderer, virtualScene);
380
+ renderer.autoClear = autoClear;
377
381
  count++;
378
382
  }
379
383
  });
@@ -616,8 +620,7 @@ function prepare(target, root, type, props) {
616
620
  object,
617
621
  eventCount: 0,
618
622
  handlers: {},
619
- isHidden: false,
620
- deferredRefs: []
623
+ isHidden: false
621
624
  };
622
625
  if (object) object.__r3f = instance;
623
626
  }
@@ -774,6 +777,17 @@ function unregisterVisibility(store, object) {
774
777
  internal.visibilityRegistry.delete(object.uuid);
775
778
  internal.occlusionCache.delete(object);
776
779
  }
780
+ function updateVisibilityHandlers(store, object, handlers) {
781
+ const { internal } = store.getState();
782
+ const entry = internal.visibilityRegistry.get(object.uuid);
783
+ if (!entry) return false;
784
+ entry.handlers = handlers;
785
+ if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
786
+ object.occlusionTest = true;
787
+ enableOcclusion(store);
788
+ }
789
+ return true;
790
+ }
777
791
  function checkVisibility(state) {
778
792
  const { internal, camera } = state;
779
793
  const registry = internal.visibilityRegistry;
@@ -961,10 +975,7 @@ function applyProps(object, props) {
961
975
  continue;
962
976
  }
963
977
  if (value === void 0) continue;
964
- if (isFromRef(value)) {
965
- instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
966
- continue;
967
- }
978
+ if (isFromRef(value)) continue;
968
979
  if (isOnce(value)) {
969
980
  if (instance?.appliedOnce?.has(prop)) continue;
970
981
  if (instance) {
@@ -1000,6 +1011,19 @@ function applyProps(object, props) {
1000
1011
  } else if (isVectorLike(target) && is.num(value)) {
1001
1012
  if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
1002
1013
  else target.set(value);
1014
+ } else if (root instanceof ShaderMaterial && key === "uniforms" && is.obj(value)) {
1015
+ if (!is.obj(root.uniforms)) root.uniforms = {};
1016
+ const uniforms = root.uniforms;
1017
+ const nextUniforms = value;
1018
+ for (const name in nextUniforms) {
1019
+ const uniform = nextUniforms[name];
1020
+ const targetUniform = uniforms[name];
1021
+ if (targetUniform) Object.assign(targetUniform, uniform);
1022
+ else {
1023
+ const nextUniform = uniform instanceof Uniform ? uniform.clone() : new Uniform(uniform.value);
1024
+ uniforms[name] = nextUniform;
1025
+ }
1026
+ }
1003
1027
  } else {
1004
1028
  root[key] = value;
1005
1029
  if (key.endsWith("Node") && root.isMaterial) {
@@ -1018,6 +1042,9 @@ function applyProps(object, props) {
1018
1042
  if (instance.eventCount && object2.raycast !== null) {
1019
1043
  rootState.internal.interaction.push(object2);
1020
1044
  }
1045
+ }
1046
+ if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
1047
+ const object2 = instance.object;
1021
1048
  const root = findInitialRoot(instance);
1022
1049
  const visibilityHandlers = {
1023
1050
  onFramed: instance.handlers.onFramed,
@@ -1025,7 +1052,9 @@ function applyProps(object, props) {
1025
1052
  onVisible: instance.handlers.onVisible
1026
1053
  };
1027
1054
  if (hasVisibilityHandlers(visibilityHandlers)) {
1028
- registerVisibility(root, object2, visibilityHandlers);
1055
+ if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
1056
+ registerVisibility(root, object2, visibilityHandlers);
1057
+ }
1029
1058
  } else {
1030
1059
  unregisterVisibility(root, object2);
1031
1060
  }
@@ -1553,6 +1582,7 @@ function createPointerEvents(store) {
1553
1582
  set((state) => ({ events: { ...state.events, connected: void 0 } }));
1554
1583
  }
1555
1584
  },
1585
+ // PREVIEW (A8): the XR pointer registration API may change before stable.
1556
1586
  registerPointer: (config) => {
1557
1587
  const pointerId = nextXRPointerId++;
1558
1588
  xrPointers.set(pointerId, config);
@@ -1639,6 +1669,13 @@ function notifyAlpha({ message, link }) {
1639
1669
  }
1640
1670
  }
1641
1671
 
1672
+ const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
1673
+ function isInternalRendererAccess(stack, callerDepth = 2) {
1674
+ if (!stack) return false;
1675
+ const caller = stack.split("\n")[callerDepth] ?? "";
1676
+ return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
1677
+ }
1678
+
1642
1679
  const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
1643
1680
  const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
1644
1681
  const createStore = (invalidate, advance) => {
@@ -1771,6 +1808,7 @@ const createStore = (invalidate, advance) => {
1771
1808
  }),
1772
1809
  setFrameloop: (frameloop = "always") => {
1773
1810
  set(() => ({ frameloop }));
1811
+ getScheduler().frameloop = frameloop;
1774
1812
  },
1775
1813
  setError: (error) => set(() => ({ error })),
1776
1814
  error: null,
@@ -1838,8 +1876,7 @@ const createStore = (invalidate, advance) => {
1838
1876
  const currentState = rootStore.getState();
1839
1877
  if (!currentState.isLegacy && currentState.internal.actualRenderer) {
1840
1878
  const stack = new Error().stack || "";
1841
- const isInternalAccess = stack.includes("zustand") || stack.includes("setState") || stack.includes("Object.assign") || stack.includes("react-three-fiber/packages/fiber/src/core");
1842
- if (!isInternalAccess) {
1879
+ if (!isInternalRendererAccess(stack)) {
1843
1880
  const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
1844
1881
  notifyDepreciated({
1845
1882
  heading: "Accessing state.gl in WebGPU mode",
@@ -1952,19 +1989,25 @@ function loadingFn(extensions, onProgress) {
1952
1989
  );
1953
1990
  };
1954
1991
  }
1955
- function useLoader(loader, input, extensions, onProgress) {
1956
- const keys = Array.isArray(input) ? input : [input];
1992
+ function useLoader(loader, input, extensions, onProgress, cacheKey) {
1993
+ const inputs = Array.isArray(input) ? input : [input];
1994
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
1957
1995
  const fn = loadingFn(extensions, onProgress);
1958
- const results = keys.map((key) => suspend(fn, [loader, key], { equal: is.equ }));
1996
+ const results = cacheKeys.map(
1997
+ (key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
1998
+ );
1959
1999
  return Array.isArray(input) ? results : results[0];
1960
2000
  }
1961
- useLoader.preload = function(loader, input, extensions, onProgress) {
1962
- const keys = Array.isArray(input) ? input : [input];
1963
- keys.forEach((key) => preload(loadingFn(extensions, onProgress), [loader, key]));
2001
+ useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
2002
+ const inputs = Array.isArray(input) ? input : [input];
2003
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
2004
+ cacheKeys.forEach(
2005
+ (key, index) => preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
2006
+ );
1964
2007
  };
1965
- useLoader.clear = function(loader, input) {
1966
- const keys = Array.isArray(input) ? input : [input];
1967
- keys.forEach((key) => clear([loader, key]));
2008
+ useLoader.clear = function(loader, input, cacheKey) {
2009
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
2010
+ cacheKeys.forEach((key) => clear([loader, key]));
1968
2011
  };
1969
2012
  useLoader.loader = getLoader;
1970
2013
 
@@ -2384,7 +2427,7 @@ function advance(timestamp) {
2384
2427
  getScheduler().step(timestamp);
2385
2428
  }
2386
2429
 
2387
- const version = "10.0.0-alpha.2";
2430
+ const version = "10.0.0-alpha.3";
2388
2431
  const packageData = {
2389
2432
  version: version};
2390
2433
 
@@ -13823,6 +13866,7 @@ function swapInstances() {
13823
13866
  }
13824
13867
  }
13825
13868
  if (instance.isHidden) unhideInstance(instance);
13869
+ if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
13826
13870
  if (instance.object.__r3f) delete instance.object.__r3f;
13827
13871
  if (instance.type !== "primitive") disposeOnIdle(instance.object);
13828
13872
  }
@@ -13835,6 +13879,8 @@ function swapInstances() {
13835
13879
  instance.object.__r3f = instance;
13836
13880
  setFiberRef(fiber, instance.object);
13837
13881
  delete instance.appliedOnce;
13882
+ instance.eventCount = 0;
13883
+ instance.handlers = {};
13838
13884
  applyProps(instance.object, instance.props);
13839
13885
  if (instance.props.attach) {
13840
13886
  attach(parent, instance);
@@ -14050,11 +14096,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
14050
14096
  cloneMutableTextInstance(textInstance) {
14051
14097
  return textInstance;
14052
14098
  },
14099
+ // React 19.2 added these for root-level view transitions. They only run for hosts that opt into
14100
+ // view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
14101
+ // into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
14102
+ // React never calls them. They stay as no-ops rather than throws: the host config is shared by
14103
+ // every root, and a throw here would turn a React-internal probe into a hard crash for users.
14104
+ // Guarded by a test asserting a full render + unmount never reaches them.
14053
14105
  cloneRootViewTransitionContainer(_rootContainer) {
14054
- throw new Error("Not implemented.");
14055
14106
  },
14056
14107
  removeRootViewTransitionClone(_rootContainer, _clone) {
14057
- throw new Error("Not implemented.");
14058
14108
  },
14059
14109
  // https://github.com/facebook/react/pull/32465
14060
14110
  createFragmentInstance: (_fiber) => null,
@@ -14139,6 +14189,7 @@ function createRoot(canvas) {
14139
14189
  const lastConfiguredProps = {};
14140
14190
  let configured = false;
14141
14191
  let pending = null;
14192
+ let rendererSetup = null;
14142
14193
  return {
14143
14194
  async configure(props = {}) {
14144
14195
  let resolve;
@@ -14169,7 +14220,7 @@ function createRoot(canvas) {
14169
14220
  forceEven
14170
14221
  } = props;
14171
14222
  const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || SRGBColorSpace;
14172
- const state = store.getState();
14223
+ let state = store.getState();
14173
14224
  const defaultGPUProps = {
14174
14225
  canvas,
14175
14226
  antialias: true
@@ -14183,52 +14234,64 @@ function createRoot(canvas) {
14183
14234
  throw new Error("Cannot use both gl and renderer props at the same time");
14184
14235
  }
14185
14236
  let renderer = state.internal.actualRenderer;
14186
- if (primaryCanvas && !state.internal.actualRenderer) {
14187
- const primary = await waitForPrimary(primaryCanvas);
14188
- renderer = primary.renderer;
14189
- state.internal.actualRenderer = renderer;
14190
- const canvasTarget = new CanvasTarget(canvas);
14191
- primary.store.setState((prev) => ({
14192
- internal: { ...prev.internal, isMultiCanvas: true }
14193
- }));
14194
- state.set((prev) => ({
14195
- webGPUSupported: primary.store.getState().webGPUSupported,
14196
- renderer,
14197
- primaryStore: primary.store,
14198
- internal: {
14199
- ...prev.internal,
14200
- canvasTarget,
14201
- isMultiCanvas: true,
14202
- isSecondary: true,
14203
- targetId: primaryCanvas
14204
- }
14205
- }));
14206
- } else if (!state.internal.actualRenderer) {
14207
- renderer = await resolveRenderer(rendererConfig, defaultGPUProps, WebGPURenderer);
14208
- if (!renderer.hasInitialized?.()) {
14209
- const size2 = computeInitialSize(canvas, propsSize);
14210
- if (size2.width > 0 && size2.height > 0) {
14211
- const pixelRatio = calculateDpr(dpr);
14212
- canvas.width = size2.width * pixelRatio;
14213
- canvas.height = size2.height * pixelRatio;
14214
- }
14215
- await renderer.init();
14216
- }
14217
- const backend = renderer.backend;
14218
- const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
14219
- state.internal.actualRenderer = renderer;
14220
- state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
14221
- if (canvasId && !state.internal.isSecondary) {
14222
- const canvasTarget = new CanvasTarget(canvas);
14223
- const unregisterPrimary = registerPrimary(canvasId, renderer, store);
14224
- state.set((prev) => ({
14225
- internal: {
14226
- ...prev.internal,
14227
- canvasTarget,
14228
- unregisterPrimary
14237
+ if (!state.internal.actualRenderer) {
14238
+ if (!rendererSetup) {
14239
+ rendererSetup = (async () => {
14240
+ if (primaryCanvas) {
14241
+ const primary = await waitForPrimary(primaryCanvas);
14242
+ renderer = primary.renderer;
14243
+ state.internal.actualRenderer = renderer;
14244
+ const canvasTarget = new CanvasTarget(canvas);
14245
+ primary.store.setState((prev) => ({
14246
+ internal: { ...prev.internal, isMultiCanvas: true }
14247
+ }));
14248
+ state.set((prev) => ({
14249
+ webGPUSupported: primary.store.getState().webGPUSupported,
14250
+ renderer,
14251
+ primaryStore: primary.store,
14252
+ internal: {
14253
+ ...prev.internal,
14254
+ canvasTarget,
14255
+ isMultiCanvas: true,
14256
+ isSecondary: true,
14257
+ targetId: primaryCanvas
14258
+ }
14259
+ }));
14260
+ } else {
14261
+ renderer = await resolveRenderer(rendererConfig, defaultGPUProps, WebGPURenderer);
14262
+ if (!renderer.hasInitialized?.()) {
14263
+ const size2 = computeInitialSize(canvas, propsSize);
14264
+ if (size2.width > 0 && size2.height > 0) {
14265
+ const pixelRatio = calculateDpr(dpr);
14266
+ canvas.width = size2.width * pixelRatio;
14267
+ canvas.height = size2.height * pixelRatio;
14268
+ }
14269
+ await renderer.init();
14270
+ }
14271
+ const backend = renderer.backend;
14272
+ const isWebGPUBackend = backend && "isWebGPUBackend" in backend;
14273
+ state.internal.actualRenderer = renderer;
14274
+ state.set({ webGPUSupported: isWebGPUBackend, renderer, primaryStore: store });
14275
+ if (canvasId && !state.internal.isSecondary) {
14276
+ const canvasTarget = new CanvasTarget(canvas);
14277
+ const unregisterPrimary = registerPrimary(canvasId, renderer, store);
14278
+ state.set((prev) => ({
14279
+ internal: {
14280
+ ...prev.internal,
14281
+ canvasTarget,
14282
+ unregisterPrimary
14283
+ }
14284
+ }));
14285
+ }
14229
14286
  }
14230
- }));
14287
+ })().catch((err) => {
14288
+ rendererSetup = null;
14289
+ throw err;
14290
+ });
14231
14291
  }
14292
+ await rendererSetup;
14293
+ state = store.getState();
14294
+ renderer = state.internal.actualRenderer;
14232
14295
  }
14233
14296
  let raycaster = state.raycaster;
14234
14297
  if (!raycaster) state.set({ raycaster: raycaster = new Raycaster() });
@@ -14578,7 +14641,8 @@ function unmountComponentAtNode(canvas, callback) {
14578
14641
  dispose(state.scene);
14579
14642
  _roots.delete(canvas);
14580
14643
  if (callback) callback(canvas);
14581
- } catch {
14644
+ } catch (error) {
14645
+ console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
14582
14646
  }
14583
14647
  }, 500);
14584
14648
  }
@@ -14641,6 +14705,7 @@ function PortalInner({ state = {}, children, container }) {
14641
14705
  viewport = rootState.viewport.getCurrentViewport(camera, new Vector3(), resolvedSize);
14642
14706
  if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
14643
14707
  }
14708
+ const set = injectState.set;
14644
14709
  return {
14645
14710
  // The intersect consists of the previous root state
14646
14711
  ...rootState,
@@ -14659,7 +14724,7 @@ function PortalInner({ state = {}, children, container }) {
14659
14724
  size: resolvedSize,
14660
14725
  viewport: { ...rootState.viewport, ...viewport },
14661
14726
  // Layers are allowed to override events
14662
- setEvents: (events2) => injectState.set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
14727
+ setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
14663
14728
  // Container for child attachment - the portalScene (injected or container itself)
14664
14729
  internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
14665
14730
  };
@@ -14718,14 +14783,146 @@ function parseBackground(background) {
14718
14783
  return null;
14719
14784
  }
14720
14785
 
14786
+ function parseRendererConfig(rendererProp) {
14787
+ const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
14788
+ if (isRendererConfig) {
14789
+ const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
14790
+ return {
14791
+ primaryCanvas: pc,
14792
+ scheduler: sc,
14793
+ renderer: Object.keys(rest).length > 0 ? rest : rendererProp
14794
+ };
14795
+ }
14796
+ return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
14797
+ }
14798
+
14799
+ const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
14800
+ const ROOT_SCOPE = "";
14801
+ const registries = /* @__PURE__ */ new WeakMap();
14802
+ function getKindRegistry(store, kind) {
14803
+ let registry = registries.get(store);
14804
+ if (!registry) {
14805
+ registry = {
14806
+ nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14807
+ uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14808
+ buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14809
+ gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
14810
+ };
14811
+ registries.set(store, registry);
14812
+ }
14813
+ return registry[kind];
14814
+ }
14815
+ function resolvePrimary$1(store) {
14816
+ return store.getState().primaryStore ?? store;
14817
+ }
14818
+ function isScopeValid(store, kind, scopeKey) {
14819
+ return getKindRegistry(store, kind).valid.has(scopeKey);
14820
+ }
14821
+ function peekStaged(store, kind, scopeKey) {
14822
+ return getKindRegistry(store, kind).staged.get(scopeKey);
14823
+ }
14824
+ function stageEntries(store, kind, scopeKey, entries) {
14825
+ const { staged } = getKindRegistry(store, kind);
14826
+ const current = staged.get(scopeKey);
14827
+ if (current) Object.assign(current, entries);
14828
+ else staged.set(scopeKey, { ...entries });
14829
+ }
14830
+ function readCommittedScope(map, scopeKey, isLeaf) {
14831
+ if (scopeKey === ROOT_SCOPE) {
14832
+ const leaves = {};
14833
+ for (const [key, value] of Object.entries(map)) if (isLeaf(value)) leaves[key] = value;
14834
+ return leaves;
14835
+ }
14836
+ const scopeData = map[scopeKey];
14837
+ if (scopeData && typeof scopeData === "object" && !isLeaf(scopeData)) return scopeData;
14838
+ return {};
14839
+ }
14840
+ function withStagedOverlay(store, kind, committed) {
14841
+ const { staged } = getKindRegistry(store, kind);
14842
+ if (staged.size === 0) return committed;
14843
+ const view = { ...committed };
14844
+ for (const [scopeKey, entries] of staged) {
14845
+ if (scopeKey === ROOT_SCOPE) Object.assign(view, entries);
14846
+ else view[scopeKey] = { ...view[scopeKey], ...entries };
14847
+ }
14848
+ return view;
14849
+ }
14850
+ function flushStagedScope(store, kind, scopeKey, isLeaf) {
14851
+ const registry = getKindRegistry(store, kind);
14852
+ const staged = registry.staged.get(scopeKey);
14853
+ if (!staged) return;
14854
+ registry.staged.delete(scopeKey);
14855
+ const replace = !registry.valid.has(scopeKey);
14856
+ store.setState((state) => {
14857
+ const map = state[kind];
14858
+ if (scopeKey === ROOT_SCOPE) {
14859
+ if (!replace) return { [kind]: { ...map, ...staged } };
14860
+ const next = {};
14861
+ for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
14862
+ return { [kind]: { ...next, ...staged } };
14863
+ }
14864
+ const current = replace ? {} : map[scopeKey] ?? {};
14865
+ return { [kind]: { ...map, [scopeKey]: { ...current, ...staged } } };
14866
+ });
14867
+ registry.valid.add(scopeKey);
14868
+ }
14869
+ function invalidateResource(store, kind, scopeKey) {
14870
+ const registry = getKindRegistry(store, kind);
14871
+ if (scopeKey === void 0) {
14872
+ registry.valid.clear();
14873
+ registry.staged.clear();
14874
+ } else {
14875
+ registry.valid.delete(scopeKey);
14876
+ registry.staged.delete(scopeKey);
14877
+ }
14878
+ }
14879
+ function rebuildResource(store, kind, userScope) {
14880
+ const primary = resolvePrimary$1(store);
14881
+ invalidateResource(primary, kind, userScope === "root" ? ROOT_SCOPE : userScope);
14882
+ primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
14883
+ }
14884
+ function invalidateAllResources(store) {
14885
+ for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
14886
+ }
14887
+ function removeResourceEntries(store, kind, names, scope, isLeaf) {
14888
+ const staged = peekStaged(store, kind, scope ?? ROOT_SCOPE);
14889
+ if (staged) for (const name of names) delete staged[name];
14890
+ store.setState((state) => {
14891
+ const map = state[kind];
14892
+ if (scope) {
14893
+ const currentScope = { ...map[scope] };
14894
+ for (const name of names) delete currentScope[name];
14895
+ return { [kind]: { ...map, [scope]: currentScope } };
14896
+ }
14897
+ const next = { ...map };
14898
+ for (const name of names) if (isLeaf(next[name])) delete next[name];
14899
+ return { [kind]: next };
14900
+ });
14901
+ }
14902
+ function clearResourceEntries(store, kind, scope, isLeaf) {
14903
+ const registry = getKindRegistry(store, kind);
14904
+ if (scope && scope !== "root") registry.staged.delete(scope);
14905
+ else if (scope === "root") registry.staged.delete(ROOT_SCOPE);
14906
+ else registry.staged.clear();
14907
+ store.setState((state) => {
14908
+ const map = state[kind];
14909
+ if (scope && scope !== "root") {
14910
+ const { [scope]: _, ...rest } = map;
14911
+ return { [kind]: rest };
14912
+ }
14913
+ if (scope === "root") {
14914
+ const next = {};
14915
+ for (const [key, value] of Object.entries(map)) if (!isLeaf(value)) next[key] = value;
14916
+ return { [kind]: next };
14917
+ }
14918
+ return { [kind]: {} };
14919
+ });
14920
+ }
14921
+
14721
14922
  function clearHmrCaches(store) {
14722
- store.setState((state) => ({
14723
- nodes: {},
14724
- uniforms: {},
14725
- buffers: {},
14726
- gpuStorage: {},
14727
- _hmrVersion: state._hmrVersion + 1
14728
- }));
14923
+ const primary = store.getState().primaryStore ?? store;
14924
+ invalidateAllResources(primary);
14925
+ primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
14729
14926
  }
14730
14927
 
14731
14928
  function CanvasImpl({
@@ -14761,18 +14958,7 @@ function CanvasImpl({
14761
14958
  forceEven,
14762
14959
  ...props
14763
14960
  }) {
14764
- const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
14765
- let primaryCanvas;
14766
- let scheduler;
14767
- let renderer;
14768
- if (isRendererConfig) {
14769
- const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
14770
- primaryCanvas = pc;
14771
- scheduler = sc;
14772
- renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
14773
- } else {
14774
- renderer = rendererProp;
14775
- }
14961
+ const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
14776
14962
  React.useMemo(() => extend(THREE), []);
14777
14963
  const Bridge = useBridge();
14778
14964
  const backgroundProps = React.useMemo(() => parseBackground(background), [background]);
@@ -14817,6 +15003,7 @@ function CanvasImpl({
14817
15003
  const handleDropMissed = useMutableCallback(onDropMissed);
14818
15004
  const [block, setBlock] = React.useState(false);
14819
15005
  const [error, setError] = React.useState(false);
15006
+ const [fallbackVisible, setFallbackVisible] = React.useState(false);
14820
15007
  if (block) throw block;
14821
15008
  if (error) throw error;
14822
15009
  const root = React.useRef(null);
@@ -14824,6 +15011,7 @@ function CanvasImpl({
14824
15011
  const unsubscribeErrorRef = React.useRef(null);
14825
15012
  useIsomorphicLayoutEffect(() => {
14826
15013
  effectActiveRef.current = true;
15014
+ if (fallbackVisible) return;
14827
15015
  const canvas = canvasRef.current;
14828
15016
  if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
14829
15017
  if (!root.current) {
@@ -14844,7 +15032,7 @@ function CanvasImpl({
14844
15032
  }
14845
15033
  async function run() {
14846
15034
  if (!effectActiveRef.current || !root.current) return;
14847
- await root.current.configure({
15035
+ const configured = await root.current.configure({
14848
15036
  id,
14849
15037
  primaryCanvas,
14850
15038
  scheduler,
@@ -14885,8 +15073,20 @@ function CanvasImpl({
14885
15073
  }
14886
15074
  onCreated?.(state);
14887
15075
  }
14888
- });
14889
- if (!effectActiveRef.current || !root.current) return;
15076
+ }).then(
15077
+ () => true,
15078
+ // Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
15079
+ // inside <canvas>, which browsers don't display, so surface it as visible DOM
15080
+ // instead; with no fallback, rethrow to an external error boundary. (#3757)
15081
+ (setupError) => {
15082
+ if (effectActiveRef.current) {
15083
+ if (fallback != null) setFallbackVisible(true);
15084
+ else setError(setupError);
15085
+ }
15086
+ return false;
15087
+ }
15088
+ );
15089
+ if (!configured || !effectActiveRef.current || !root.current) return;
14890
15090
  root.current.render(
14891
15091
  /* @__PURE__ */ jsx(Bridge, { children: /* @__PURE__ */ jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxs(React.Suspense, { fallback: /* @__PURE__ */ jsx(Block, { set: setBlock }), children: [
14892
15092
  backgroundProps && /* @__PURE__ */ jsx(Environment, { ...backgroundProps }),
@@ -14949,7 +15149,11 @@ function CanvasImpl({
14949
15149
  ...style
14950
15150
  },
14951
15151
  ...props,
14952
- children: /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
15152
+ children: fallbackVisible ? (
15153
+ // Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
15154
+ // it exists in the tree but browsers never paint it, which is the whole bug (#3757).
15155
+ fallback
15156
+ ) : /* @__PURE__ */ jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsx(
14953
15157
  "canvas",
14954
15158
  {
14955
15159
  ref: canvasRef,
@@ -15031,30 +15235,31 @@ let ScopedStore = _ScopedStore;
15031
15235
  function createScopedStore(data) {
15032
15236
  return new ScopedStore(data);
15033
15237
  }
15034
- function createLazyCreatorState(state) {
15238
+ function createLazyCreatorState(state, store) {
15035
15239
  let _uniforms = null;
15036
15240
  let _nodes = null;
15037
15241
  let _buffers = null;
15038
15242
  let _gpuStorage = null;
15243
+ const view = (kind) => store ? withStagedOverlay(store, kind, state[kind]) : state[kind];
15039
15244
  return Object.create(state, {
15040
15245
  uniforms: {
15041
15246
  get() {
15042
- return _uniforms ?? (_uniforms = createScopedStore(state.uniforms));
15247
+ return _uniforms ?? (_uniforms = createScopedStore(view("uniforms")));
15043
15248
  }
15044
15249
  },
15045
15250
  nodes: {
15046
15251
  get() {
15047
- return _nodes ?? (_nodes = createScopedStore(state.nodes));
15252
+ return _nodes ?? (_nodes = createScopedStore(view("nodes")));
15048
15253
  }
15049
15254
  },
15050
15255
  buffers: {
15051
15256
  get() {
15052
- return _buffers ?? (_buffers = createScopedStore(state.buffers));
15257
+ return _buffers ?? (_buffers = createScopedStore(view("buffers")));
15053
15258
  }
15054
15259
  },
15055
15260
  gpuStorage: {
15056
15261
  get() {
15057
- return _gpuStorage ?? (_gpuStorage = createScopedStore(state.gpuStorage));
15262
+ return _gpuStorage ?? (_gpuStorage = createScopedStore(view("gpuStorage")));
15058
15263
  }
15059
15264
  }
15060
15265
  });
@@ -15177,65 +15382,56 @@ function useCompareMemoize(value, deep) {
15177
15382
  return ref.current;
15178
15383
  }
15179
15384
 
15385
+ function useScopedResource(options) {
15386
+ const { store, kind, scope, isLeaf, create, prepare, reconcile, input } = options;
15387
+ const scopeKey = scope ?? ROOT_SCOPE;
15388
+ const version = store((s) => s._hmrVersion);
15389
+ const entries = useMemo(() => {
15390
+ const staged = peekStaged(store, kind, scopeKey);
15391
+ const reusable = isScopeValid(store, kind, scopeKey);
15392
+ const map = store.getState()[kind];
15393
+ const committed = reusable ? readCommittedScope(map, scopeKey, isLeaf) : void 0;
15394
+ const result = {};
15395
+ let fresh = null;
15396
+ for (const [name, candidate] of Object.entries(create())) {
15397
+ const existing = staged?.[name] ?? committed?.[name];
15398
+ if (existing !== void 0) {
15399
+ result[name] = existing;
15400
+ reconcile?.(existing, candidate);
15401
+ } else {
15402
+ const value = prepare ? prepare(name, candidate) : candidate;
15403
+ result[name] = value;
15404
+ (fresh ?? (fresh = {}))[name] = value;
15405
+ }
15406
+ }
15407
+ if (fresh) stageEntries(store, kind, scopeKey, fresh);
15408
+ return result;
15409
+ }, [store, kind, scopeKey, version, input]);
15410
+ useIsomorphicLayoutEffect(() => {
15411
+ flushStagedScope(store, kind, scopeKey, isLeaf);
15412
+ });
15413
+ return entries;
15414
+ }
15415
+
15180
15416
  const isUniformNode$1 = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
15181
15417
  function useUniforms(creatorOrScope, scope) {
15182
15418
  const store = usePrimaryStore();
15183
15419
  const removeUniforms2 = useCallback(
15184
- (names, targetScope) => {
15185
- const nameArray = Array.isArray(names) ? names : [names];
15186
- store.setState((state) => {
15187
- if (targetScope) {
15188
- const currentScope = { ...state.uniforms[targetScope] };
15189
- for (const name of nameArray) delete currentScope[name];
15190
- return { uniforms: { ...state.uniforms, [targetScope]: currentScope } };
15191
- }
15192
- const uniforms2 = { ...state.uniforms };
15193
- for (const name of nameArray) if (isUniformNode$1(uniforms2[name])) delete uniforms2[name];
15194
- return { uniforms: uniforms2 };
15195
- });
15196
- },
15420
+ (names, targetScope) => removeResourceEntries(store, "uniforms", Array.isArray(names) ? names : [names], targetScope, isUniformNode$1),
15197
15421
  [store]
15198
15422
  );
15199
15423
  const clearUniforms = useCallback(
15200
- (targetScope) => {
15201
- store.setState((state) => {
15202
- if (targetScope && targetScope !== "root") {
15203
- const { [targetScope]: _, ...rest } = state.uniforms;
15204
- return { uniforms: rest };
15205
- }
15206
- if (targetScope === "root") {
15207
- const uniforms2 = {};
15208
- for (const [key, value] of Object.entries(state.uniforms)) {
15209
- if (!isUniformNode$1(value)) uniforms2[key] = value;
15210
- }
15211
- return { uniforms: uniforms2 };
15212
- }
15213
- return { uniforms: {} };
15214
- });
15215
- },
15424
+ (targetScope) => clearResourceEntries(store, "uniforms", targetScope, isUniformNode$1),
15216
15425
  [store]
15217
15426
  );
15218
15427
  const rebuildUniforms = useCallback(
15219
- (targetScope) => {
15220
- store.setState((state) => {
15221
- let newUniforms = {};
15222
- if (targetScope && targetScope !== "root") {
15223
- const { [targetScope]: _, ...rest } = state.uniforms;
15224
- newUniforms = rest;
15225
- } else if (targetScope === "root") {
15226
- for (const [key, value] of Object.entries(state.uniforms)) {
15227
- if (!isUniformNode$1(value)) newUniforms[key] = value;
15228
- }
15229
- }
15230
- return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
15231
- });
15232
- },
15428
+ (targetScope) => rebuildResource(store, "uniforms", targetScope),
15233
15429
  [store]
15234
15430
  );
15235
15431
  const inputForMemoization = useMemo(() => {
15236
15432
  let raw = creatorOrScope;
15237
15433
  if (is.fun(creatorOrScope)) {
15238
- const wrappedState = createLazyCreatorState(store.getState());
15434
+ const wrappedState = createLazyCreatorState(store.getState(), store);
15239
15435
  raw = creatorOrScope(wrappedState);
15240
15436
  }
15241
15437
  if (raw && typeof raw === "object" && !Array.isArray(raw)) {
@@ -15250,80 +15446,43 @@ function useUniforms(creatorOrScope, scope) {
15250
15446
  const memoizedInput = useCompareMemoize(inputForMemoization);
15251
15447
  const isReader = memoizedInput === void 0 || typeof memoizedInput === "string";
15252
15448
  const storeUniforms = usePrimaryThree((s) => s.uniforms);
15253
- const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
15254
- const readerDep = isReader ? storeUniforms : null;
15255
- const creatorDep = isReader ? null : hmrVersion;
15256
- const uniforms = useMemo(() => {
15257
- if (memoizedInput === void 0) {
15258
- return storeUniforms;
15259
- }
15260
- if (typeof memoizedInput === "string") {
15261
- const scopeData = storeUniforms[memoizedInput];
15262
- if (scopeData && !isUniformNode$1(scopeData)) return scopeData;
15263
- return {};
15264
- }
15265
- const state = store.getState();
15266
- const set = store.setState;
15267
- if (typeof memoizedInput !== "object" || memoizedInput === null) {
15268
- throw new Error("Invalid uniform input");
15269
- }
15270
- const created = memoizedInput;
15271
- const result = {};
15272
- let hasNewUniforms = false;
15273
- let targetRecord = state.uniforms;
15274
- if (scope) {
15275
- if (!state.uniforms[scope]) state.uniforms[scope] = {};
15276
- targetRecord = state.uniforms[scope];
15277
- }
15278
- for (const [name, node] of Object.entries(created)) {
15279
- if (targetRecord[name]) {
15280
- result[name] = targetRecord[name];
15281
- const existingVal = result[name].value;
15282
- const newVal = vectorize(node);
15283
- let equals = newVal === existingVal;
15284
- if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
15285
- if (isThreeVector(existingVal) && isThreeVector(newVal)) {
15286
- equals = vectorEquals(existingVal, newVal);
15287
- } else if (isSameThreeType(existingVal, newVal)) {
15288
- equals = existingVal.equals(newVal);
15289
- }
15290
- }
15291
- if (!equals) result[name].value = newVal;
15292
- } else {
15293
- result[name] = createUniform(name, node, scope);
15294
- hasNewUniforms = true;
15295
- }
15296
- }
15297
- if (hasNewUniforms) {
15298
- if (scope) {
15299
- set((s) => ({
15300
- uniforms: {
15301
- ...s.uniforms,
15302
- [scope]: { ...s.uniforms[scope], ...result }
15303
- }
15304
- }));
15305
- } else {
15306
- set((s) => ({ uniforms: { ...s.uniforms, ...result } }));
15307
- }
15449
+ const created = useScopedResource({
15450
+ store,
15451
+ kind: "uniforms",
15452
+ scope: isReader ? void 0 : scope,
15453
+ isLeaf: isUniformNode$1,
15454
+ input: memoizedInput,
15455
+ create: () => {
15456
+ if (isReader) return {};
15457
+ if (typeof memoizedInput !== "object" || memoizedInput === null) throw new Error("Invalid uniform input");
15458
+ return memoizedInput;
15459
+ },
15460
+ prepare: (name, candidate) => createUniform(name, candidate, scope),
15461
+ reconcile: (existing, candidate) => {
15462
+ const existingVal = existing.value;
15463
+ const newVal = vectorize(candidate);
15464
+ let equals = newVal === existingVal;
15465
+ if (!equals && hasEqualsMethod(existingVal) && hasEqualsMethod(newVal)) {
15466
+ if (isThreeVector(existingVal) && isThreeVector(newVal)) {
15467
+ equals = vectorEquals(existingVal, newVal);
15468
+ } else if (isSameThreeType(existingVal, newVal)) {
15469
+ equals = existingVal.equals(newVal);
15470
+ }
15471
+ }
15472
+ if (!equals) existing.value = newVal;
15308
15473
  }
15309
- return result;
15310
- }, [store, memoizedInput, scope, readerDep, creatorDep]);
15474
+ });
15475
+ let uniforms = created;
15476
+ if (memoizedInput === void 0) {
15477
+ uniforms = storeUniforms;
15478
+ } else if (typeof memoizedInput === "string") {
15479
+ const scopeData = storeUniforms[memoizedInput];
15480
+ uniforms = scopeData && !isUniformNode$1(scopeData) ? scopeData : {};
15481
+ }
15311
15482
  return { ...uniforms, removeUniforms: removeUniforms2, clearUniforms, rebuildUniforms };
15312
15483
  }
15313
15484
  function rebuildAllUniforms(store, scope) {
15314
- store = store.getState().primaryStore ?? store;
15315
- store.setState((state) => {
15316
- let newUniforms = {};
15317
- if (scope && scope !== "root") {
15318
- const { [scope]: _, ...rest } = state.uniforms;
15319
- newUniforms = rest;
15320
- } else if (scope === "root") {
15321
- for (const [key, value] of Object.entries(state.uniforms)) {
15322
- if (!isUniformNode$1(value)) newUniforms[key] = value;
15323
- }
15324
- }
15325
- return { uniforms: newUniforms, _hmrVersion: state._hmrVersion + 1 };
15326
- });
15485
+ rebuildResource(store, "uniforms", scope);
15327
15486
  }
15328
15487
  function removeUniforms(set, names, scope) {
15329
15488
  set((state) => {
@@ -15387,192 +15546,91 @@ function isSameThreeType(a, b) {
15387
15546
  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;
15388
15547
  }
15389
15548
 
15549
+ const uniformOf = uniform;
15390
15550
  const isUniformNode = (value) => value !== null && typeof value === "object" && "value" in value && "uuid" in value;
15391
15551
  const isTSLNode$1 = (value) => value !== null && typeof value === "object" && "uuid" in value && "nodeType" in value;
15392
15552
  function useUniform(name, value) {
15393
15553
  const store = useStore();
15394
- const hmrVersion = useThree((s) => s._hmrVersion);
15395
- return useMemo(() => {
15396
- const state = store.getState();
15397
- const set = store.setState;
15398
- const existing = state.uniforms[name];
15399
- if (existing && isUniformNode(existing)) {
15554
+ const registered = useScopedResource({
15555
+ store,
15556
+ kind: "uniforms",
15557
+ scope: void 0,
15558
+ isLeaf: isUniformNode,
15559
+ input: name,
15560
+ create: () => value === void 0 ? {} : { [name]: value },
15561
+ prepare: createNamedUniform,
15562
+ reconcile: (existing2) => {
15400
15563
  if (value !== void 0 && !isTSLNode$1(value) && !isUniformNode(value)) {
15401
- existing.value = typeof value === "string" ? new Color(value) : value;
15564
+ existing2.value = typeof value === "string" ? new Color(value) : value;
15402
15565
  }
15403
- return existing;
15404
- }
15405
- if (value === void 0) {
15406
- throw new Error(
15407
- `[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
15408
- );
15409
- }
15410
- if (isUniformNode(value)) {
15411
- const node2 = value;
15412
- if (typeof node2.setName === "function") {
15413
- node2.setName(name);
15414
- }
15415
- set((s) => ({
15416
- uniforms: { ...s.uniforms, [name]: node2 }
15417
- }));
15418
- return node2;
15419
- }
15420
- let node;
15421
- if (isTSLNode$1(value)) {
15422
- node = uniform(value);
15423
- } else if (typeof value === "string") {
15424
- node = uniform(new Color(value));
15425
- } else {
15426
- node = uniform(value);
15427
- }
15428
- if (typeof node.setName === "function") {
15429
- node.setName(name);
15430
15566
  }
15431
- set((s) => ({
15432
- uniforms: {
15433
- ...s.uniforms,
15434
- [name]: node
15435
- }
15436
- }));
15437
- return node;
15438
- }, [store, name, hmrVersion]);
15567
+ });
15568
+ if (registered[name]) return registered[name];
15569
+ const existing = peekStaged(store, "uniforms", ROOT_SCOPE)?.[name] ?? store.getState().uniforms[name];
15570
+ if (existing && isUniformNode(existing)) return existing;
15571
+ throw new Error(
15572
+ `[useUniform] Uniform "${name}" not found. Create it first with: useUniform('${name}', initialValue)`
15573
+ );
15574
+ }
15575
+ function createNamedUniform(name, value) {
15576
+ let node;
15577
+ if (isUniformNode(value)) {
15578
+ node = value;
15579
+ } else if (isTSLNode$1(value)) {
15580
+ node = uniformOf(value);
15581
+ } else if (typeof value === "string") {
15582
+ node = uniform(new Color(value));
15583
+ } else {
15584
+ node = uniformOf(value);
15585
+ }
15586
+ if (typeof node.setName === "function") {
15587
+ node.setName(name);
15588
+ }
15589
+ return node;
15439
15590
  }
15440
15591
 
15441
15592
  const isTSLNode = (value) => value !== null && typeof value === "object" && ("uuid" in value || "nodeType" in value);
15442
15593
  function useNodes(creatorOrScope, scope) {
15443
15594
  const store = usePrimaryStore();
15444
15595
  const removeNodes2 = useCallback(
15445
- (names, targetScope) => {
15446
- const nameArray = Array.isArray(names) ? names : [names];
15447
- store.setState((state) => {
15448
- if (targetScope) {
15449
- const currentScope = { ...state.nodes[targetScope] };
15450
- for (const name of nameArray) delete currentScope[name];
15451
- return { nodes: { ...state.nodes, [targetScope]: currentScope } };
15452
- }
15453
- const nodes2 = { ...state.nodes };
15454
- for (const name of nameArray) if (isTSLNode(nodes2[name])) delete nodes2[name];
15455
- return { nodes: nodes2 };
15456
- });
15457
- },
15596
+ (names, targetScope) => removeResourceEntries(store, "nodes", Array.isArray(names) ? names : [names], targetScope, isTSLNode),
15458
15597
  [store]
15459
15598
  );
15460
15599
  const clearNodes = useCallback(
15461
- (targetScope) => {
15462
- store.setState((state) => {
15463
- if (targetScope && targetScope !== "root") {
15464
- const { [targetScope]: _, ...rest } = state.nodes;
15465
- return { nodes: rest };
15466
- }
15467
- if (targetScope === "root") {
15468
- const nodes2 = {};
15469
- for (const [key, value] of Object.entries(state.nodes)) {
15470
- if (!isTSLNode(value)) nodes2[key] = value;
15471
- }
15472
- return { nodes: nodes2 };
15473
- }
15474
- return { nodes: {} };
15475
- });
15476
- },
15600
+ (targetScope) => clearResourceEntries(store, "nodes", targetScope, isTSLNode),
15477
15601
  [store]
15478
15602
  );
15479
15603
  const rebuildNodes = useCallback(
15480
- (targetScope) => {
15481
- store.setState((state) => {
15482
- let newNodes = state.nodes;
15483
- if (targetScope && targetScope !== "root") {
15484
- const { [targetScope]: _, ...rest } = state.nodes;
15485
- newNodes = rest;
15486
- } else if (targetScope === "root") {
15487
- newNodes = {};
15488
- for (const [key, value] of Object.entries(state.nodes)) {
15489
- if (!isTSLNode(value)) newNodes[key] = value;
15490
- }
15491
- } else {
15492
- newNodes = {};
15493
- }
15494
- return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
15495
- });
15496
- },
15604
+ (targetScope) => rebuildResource(store, "nodes", targetScope),
15497
15605
  [store]
15498
15606
  );
15499
15607
  const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
15500
15608
  const storeNodes = usePrimaryThree((s) => s.nodes);
15501
- const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
15502
- const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
15503
- const readerDep = isReader ? storeNodes : null;
15504
- const creatorDep = isReader ? null : hmrVersion;
15505
- const nodes = useMemo(() => {
15506
- if (creatorOrScope === void 0) {
15507
- return storeNodes;
15508
- }
15509
- if (typeof creatorOrScope === "string") {
15510
- const scopeData = storeNodes[creatorOrScope];
15511
- if (scopeData && !isTSLNode(scopeData)) return scopeData;
15512
- return {};
15513
- }
15514
- const state = store.getState();
15515
- const set = store.setState;
15516
- const creator = creatorOrScope;
15517
- const wrappedState = createLazyCreatorState(state);
15518
- const created = creator(wrappedState);
15519
- const result = {};
15520
- let hasNewNodes = false;
15521
- if (scope) {
15522
- const currentScope = state.nodes[scope] ?? {};
15523
- for (const [name, node] of Object.entries(created)) {
15524
- if (currentScope[name]) {
15525
- result[name] = currentScope[name];
15526
- } else {
15527
- node.setName?.(`${scope}.${name}`);
15528
- result[name] = node;
15529
- hasNewNodes = true;
15530
- }
15531
- }
15532
- if (hasNewNodes) {
15533
- set((s) => ({
15534
- nodes: {
15535
- ...s.nodes,
15536
- [scope]: { ...s.nodes[scope], ...result }
15537
- }
15538
- }));
15539
- }
15540
- return result;
15541
- }
15542
- for (const [name, node] of Object.entries(created)) {
15543
- const existing = state.nodes[name];
15544
- if (existing && isTSLNode(existing)) {
15545
- result[name] = existing;
15546
- } else {
15547
- node.setName?.(name);
15548
- result[name] = node;
15549
- hasNewNodes = true;
15550
- }
15551
- }
15552
- if (hasNewNodes) {
15553
- set((s) => ({ nodes: { ...s.nodes, ...result } }));
15609
+ const created = useScopedResource({
15610
+ store,
15611
+ kind: "nodes",
15612
+ scope: isReader ? void 0 : scope,
15613
+ isLeaf: isTSLNode,
15614
+ create: () => {
15615
+ if (isReader) return {};
15616
+ return creatorOrScope(createLazyCreatorState(store.getState(), store));
15617
+ },
15618
+ prepare: (name, node) => {
15619
+ node.setName?.(scope ? `${scope}.${name}` : name);
15620
+ return node;
15554
15621
  }
15555
- return result;
15556
- }, [store, scopeDep, readerDep, creatorDep]);
15622
+ });
15623
+ let nodes = created;
15624
+ if (creatorOrScope === void 0) {
15625
+ nodes = storeNodes;
15626
+ } else if (typeof creatorOrScope === "string") {
15627
+ const scopeData = storeNodes[creatorOrScope];
15628
+ nodes = scopeData && !isTSLNode(scopeData) ? scopeData : {};
15629
+ }
15557
15630
  return { ...nodes, removeNodes: removeNodes2, clearNodes, rebuildNodes };
15558
15631
  }
15559
15632
  function rebuildAllNodes(store, scope) {
15560
- store = store.getState().primaryStore ?? store;
15561
- store.setState((state) => {
15562
- let newNodes = state.nodes;
15563
- if (scope && scope !== "root") {
15564
- const { [scope]: _, ...rest } = state.nodes;
15565
- newNodes = rest;
15566
- } else if (scope === "root") {
15567
- newNodes = {};
15568
- for (const [key, value] of Object.entries(state.nodes)) {
15569
- if (!isTSLNode(value)) newNodes[key] = value;
15570
- }
15571
- } else {
15572
- newNodes = {};
15573
- }
15574
- return { nodes: newNodes, _hmrVersion: state._hmrVersion + 1 };
15575
- });
15633
+ rebuildResource(store, "nodes", scope);
15576
15634
  }
15577
15635
  function removeNodes(set, names, scope) {
15578
15636
  set((state) => {
@@ -15608,7 +15666,7 @@ function useLocalNodes(creator) {
15608
15666
  const textures = usePrimaryThree((s) => s.textures);
15609
15667
  const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
15610
15668
  return useMemo(() => {
15611
- const wrappedState = createLazyCreatorState(store.getState());
15669
+ const wrappedState = createLazyCreatorState(store.getState(), store);
15612
15670
  return creator(wrappedState);
15613
15671
  }, [store, creator, uniforms, nodes, textures, hmrVersion]);
15614
15672
  }
@@ -15629,58 +15687,15 @@ const disposeBuffer = (buffer) => {
15629
15687
  function useBuffers(creatorOrScope, scope) {
15630
15688
  const store = usePrimaryStore();
15631
15689
  const removeBuffers = useCallback(
15632
- (names, targetScope) => {
15633
- const nameArray = Array.isArray(names) ? names : [names];
15634
- store.setState((state) => {
15635
- if (targetScope) {
15636
- const currentScope = { ...state.buffers[targetScope] };
15637
- for (const name of nameArray) delete currentScope[name];
15638
- return { buffers: { ...state.buffers, [targetScope]: currentScope } };
15639
- }
15640
- const buffers2 = { ...state.buffers };
15641
- for (const name of nameArray) if (isBufferLike(buffers2[name])) delete buffers2[name];
15642
- return { buffers: buffers2 };
15643
- });
15644
- },
15690
+ (names, targetScope) => removeResourceEntries(store, "buffers", Array.isArray(names) ? names : [names], targetScope, isBufferLike),
15645
15691
  [store]
15646
15692
  );
15647
15693
  const clearBuffers = useCallback(
15648
- (targetScope) => {
15649
- store.setState((state) => {
15650
- if (targetScope && targetScope !== "root") {
15651
- const { [targetScope]: _, ...rest } = state.buffers;
15652
- return { buffers: rest };
15653
- }
15654
- if (targetScope === "root") {
15655
- const buffers2 = {};
15656
- for (const [key, value] of Object.entries(state.buffers)) {
15657
- if (!isBufferLike(value)) buffers2[key] = value;
15658
- }
15659
- return { buffers: buffers2 };
15660
- }
15661
- return { buffers: {} };
15662
- });
15663
- },
15694
+ (targetScope) => clearResourceEntries(store, "buffers", targetScope, isBufferLike),
15664
15695
  [store]
15665
15696
  );
15666
15697
  const rebuildBuffers = useCallback(
15667
- (targetScope) => {
15668
- store.setState((state) => {
15669
- let newBuffers = state.buffers;
15670
- if (targetScope && targetScope !== "root") {
15671
- const { [targetScope]: _, ...rest } = state.buffers;
15672
- newBuffers = rest;
15673
- } else if (targetScope === "root") {
15674
- newBuffers = {};
15675
- for (const [key, value] of Object.entries(state.buffers)) {
15676
- if (!isBufferLike(value)) newBuffers[key] = value;
15677
- }
15678
- } else {
15679
- newBuffers = {};
15680
- }
15681
- return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
15682
- });
15683
- },
15698
+ (targetScope) => rebuildResource(store, "buffers", targetScope),
15684
15699
  [store]
15685
15700
  );
15686
15701
  const disposeBuffers = useCallback(
@@ -15699,85 +15714,33 @@ function useBuffers(creatorOrScope, scope) {
15699
15714
  );
15700
15715
  const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
15701
15716
  const storeBuffers = usePrimaryThree((s) => s.buffers);
15702
- const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
15703
- const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
15704
- const readerDep = isReader ? storeBuffers : null;
15705
- const creatorDep = isReader ? null : hmrVersion;
15706
- const buffers = useMemo(() => {
15707
- if (creatorOrScope === void 0) {
15708
- return storeBuffers;
15709
- }
15710
- if (typeof creatorOrScope === "string") {
15711
- const scopeData = storeBuffers[creatorOrScope];
15712
- if (scopeData && !isBufferLike(scopeData)) return scopeData;
15713
- return {};
15714
- }
15715
- const state = store.getState();
15716
- const set = store.setState;
15717
- const creator = creatorOrScope;
15718
- const wrappedState = createLazyCreatorState(state);
15719
- const created = creator(wrappedState);
15720
- const result = {};
15721
- let hasNewBuffers = false;
15722
- if (scope) {
15723
- const currentScope = state.buffers[scope] ?? {};
15724
- for (const [name, buffer] of Object.entries(created)) {
15725
- if (currentScope[name]) {
15726
- result[name] = currentScope[name];
15727
- } else {
15728
- if ("setName" in buffer && typeof buffer.setName === "function") {
15729
- buffer.setName(`${scope}.${name}`);
15730
- }
15731
- result[name] = buffer;
15732
- hasNewBuffers = true;
15733
- }
15734
- }
15735
- if (hasNewBuffers) {
15736
- set((s) => ({
15737
- buffers: {
15738
- ...s.buffers,
15739
- [scope]: { ...s.buffers[scope], ...result }
15740
- }
15741
- }));
15742
- }
15743
- return result;
15744
- }
15745
- for (const [name, buffer] of Object.entries(created)) {
15746
- const existing = state.buffers[name];
15747
- if (existing && isBufferLike(existing)) {
15748
- result[name] = existing;
15749
- } else {
15750
- if ("setName" in buffer && typeof buffer.setName === "function") {
15751
- buffer.setName(name);
15752
- }
15753
- result[name] = buffer;
15754
- hasNewBuffers = true;
15717
+ const created = useScopedResource({
15718
+ store,
15719
+ kind: "buffers",
15720
+ scope: isReader ? void 0 : scope,
15721
+ isLeaf: isBufferLike,
15722
+ create: () => {
15723
+ if (isReader) return {};
15724
+ return creatorOrScope(createLazyCreatorState(store.getState(), store));
15725
+ },
15726
+ prepare: (name, buffer) => {
15727
+ if ("setName" in buffer && typeof buffer.setName === "function") {
15728
+ buffer.setName(scope ? `${scope}.${name}` : name);
15755
15729
  }
15730
+ return buffer;
15756
15731
  }
15757
- if (hasNewBuffers) {
15758
- set((s) => ({ buffers: { ...s.buffers, ...result } }));
15759
- }
15760
- return result;
15761
- }, [store, scopeDep, readerDep, creatorDep]);
15732
+ });
15733
+ let buffers = created;
15734
+ if (creatorOrScope === void 0) {
15735
+ buffers = storeBuffers;
15736
+ } else if (typeof creatorOrScope === "string") {
15737
+ const scopeData = storeBuffers[creatorOrScope];
15738
+ buffers = scopeData && !isBufferLike(scopeData) ? scopeData : {};
15739
+ }
15762
15740
  return { ...buffers, removeBuffers, clearBuffers, rebuildBuffers, disposeBuffers };
15763
15741
  }
15764
15742
  function rebuildAllBuffers(store, scope) {
15765
- store = store.getState().primaryStore ?? store;
15766
- store.setState((state) => {
15767
- let newBuffers = state.buffers;
15768
- if (scope && scope !== "root") {
15769
- const { [scope]: _, ...rest } = state.buffers;
15770
- newBuffers = rest;
15771
- } else if (scope === "root") {
15772
- newBuffers = {};
15773
- for (const [key, value] of Object.entries(state.buffers)) {
15774
- if (!isBufferLike(value)) newBuffers[key] = value;
15775
- }
15776
- } else {
15777
- newBuffers = {};
15778
- }
15779
- return { buffers: newBuffers, _hmrVersion: state._hmrVersion + 1 };
15780
- });
15743
+ rebuildResource(store, "buffers", scope);
15781
15744
  }
15782
15745
 
15783
15746
  const isStorageLike = (value) => {
@@ -15796,58 +15759,15 @@ const disposeStorage = (storage) => {
15796
15759
  function useGPUStorage(creatorOrScope, scope) {
15797
15760
  const store = usePrimaryStore();
15798
15761
  const removeStorage = useCallback(
15799
- (names, targetScope) => {
15800
- const nameArray = Array.isArray(names) ? names : [names];
15801
- store.setState((state) => {
15802
- if (targetScope) {
15803
- const currentScope = { ...state.gpuStorage[targetScope] };
15804
- for (const name of nameArray) delete currentScope[name];
15805
- return { gpuStorage: { ...state.gpuStorage, [targetScope]: currentScope } };
15806
- }
15807
- const gpuStorage2 = { ...state.gpuStorage };
15808
- for (const name of nameArray) if (isStorageLike(gpuStorage2[name])) delete gpuStorage2[name];
15809
- return { gpuStorage: gpuStorage2 };
15810
- });
15811
- },
15762
+ (names, targetScope) => removeResourceEntries(store, "gpuStorage", Array.isArray(names) ? names : [names], targetScope, isStorageLike),
15812
15763
  [store]
15813
15764
  );
15814
15765
  const clearStorage = useCallback(
15815
- (targetScope) => {
15816
- store.setState((state) => {
15817
- if (targetScope && targetScope !== "root") {
15818
- const { [targetScope]: _, ...rest } = state.gpuStorage;
15819
- return { gpuStorage: rest };
15820
- }
15821
- if (targetScope === "root") {
15822
- const gpuStorage2 = {};
15823
- for (const [key, value] of Object.entries(state.gpuStorage)) {
15824
- if (!isStorageLike(value)) gpuStorage2[key] = value;
15825
- }
15826
- return { gpuStorage: gpuStorage2 };
15827
- }
15828
- return { gpuStorage: {} };
15829
- });
15830
- },
15766
+ (targetScope) => clearResourceEntries(store, "gpuStorage", targetScope, isStorageLike),
15831
15767
  [store]
15832
15768
  );
15833
15769
  const rebuildStorage = useCallback(
15834
- (targetScope) => {
15835
- store.setState((state) => {
15836
- let newStorage = state.gpuStorage;
15837
- if (targetScope && targetScope !== "root") {
15838
- const { [targetScope]: _, ...rest } = state.gpuStorage;
15839
- newStorage = rest;
15840
- } else if (targetScope === "root") {
15841
- newStorage = {};
15842
- for (const [key, value] of Object.entries(state.gpuStorage)) {
15843
- if (!isStorageLike(value)) newStorage[key] = value;
15844
- }
15845
- } else {
15846
- newStorage = {};
15847
- }
15848
- return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
15849
- });
15850
- },
15770
+ (targetScope) => rebuildResource(store, "gpuStorage", targetScope),
15851
15771
  [store]
15852
15772
  );
15853
15773
  const disposeStorageFn = useCallback(
@@ -15866,72 +15786,33 @@ function useGPUStorage(creatorOrScope, scope) {
15866
15786
  );
15867
15787
  const isReader = creatorOrScope === void 0 || typeof creatorOrScope === "string";
15868
15788
  const storeStorage = usePrimaryThree((s) => s.gpuStorage);
15869
- const hmrVersion = usePrimaryThree((s) => s._hmrVersion);
15870
- const scopeDep = typeof creatorOrScope === "string" ? creatorOrScope : scope;
15871
- const readerDep = isReader ? storeStorage : null;
15872
- const creatorDep = isReader ? null : hmrVersion;
15873
- const gpuStorage = useMemo(() => {
15874
- if (creatorOrScope === void 0) {
15875
- return storeStorage;
15876
- }
15877
- if (typeof creatorOrScope === "string") {
15878
- const scopeData = storeStorage[creatorOrScope];
15879
- if (scopeData && !isStorageLike(scopeData)) return scopeData;
15880
- return {};
15881
- }
15882
- const state = store.getState();
15883
- const set = store.setState;
15884
- const creator = creatorOrScope;
15885
- const wrappedState = createLazyCreatorState(state);
15886
- const created = creator(wrappedState);
15887
- const result = {};
15888
- let hasNewStorage = false;
15889
- if (scope) {
15890
- const currentScope = state.gpuStorage[scope] ?? {};
15891
- for (const [name, storage] of Object.entries(created)) {
15892
- if (currentScope[name]) {
15893
- result[name] = currentScope[name];
15894
- } else {
15895
- if ("setName" in storage && typeof storage.setName === "function") {
15896
- storage.setName(`${scope}.${name}`);
15897
- }
15898
- if ("name" in storage && typeof storage.name === "string") {
15899
- storage.name = `${scope}.${name}`;
15900
- }
15901
- result[name] = storage;
15902
- hasNewStorage = true;
15903
- }
15904
- }
15905
- if (hasNewStorage) {
15906
- set((s) => ({
15907
- gpuStorage: {
15908
- ...s.gpuStorage,
15909
- [scope]: { ...s.gpuStorage[scope], ...result }
15910
- }
15911
- }));
15789
+ const created = useScopedResource({
15790
+ store,
15791
+ kind: "gpuStorage",
15792
+ scope: isReader ? void 0 : scope,
15793
+ isLeaf: isStorageLike,
15794
+ create: () => {
15795
+ if (isReader) return {};
15796
+ return creatorOrScope(createLazyCreatorState(store.getState(), store));
15797
+ },
15798
+ prepare: (name, storage) => {
15799
+ const label = scope ? `${scope}.${name}` : name;
15800
+ if ("setName" in storage && typeof storage.setName === "function") {
15801
+ storage.setName(label);
15912
15802
  }
15913
- return result;
15914
- }
15915
- for (const [name, storage] of Object.entries(created)) {
15916
- const existing = state.gpuStorage[name];
15917
- if (existing && isStorageLike(existing)) {
15918
- result[name] = existing;
15919
- } else {
15920
- if ("setName" in storage && typeof storage.setName === "function") {
15921
- storage.setName(name);
15922
- }
15923
- if ("name" in storage && typeof storage.name === "string") {
15924
- storage.name = name;
15925
- }
15926
- result[name] = storage;
15927
- hasNewStorage = true;
15803
+ if ("name" in storage && typeof storage.name === "string") {
15804
+ storage.name = label;
15928
15805
  }
15806
+ return storage;
15929
15807
  }
15930
- if (hasNewStorage) {
15931
- set((s) => ({ gpuStorage: { ...s.gpuStorage, ...result } }));
15932
- }
15933
- return result;
15934
- }, [store, scopeDep, readerDep, creatorDep]);
15808
+ });
15809
+ let gpuStorage = created;
15810
+ if (creatorOrScope === void 0) {
15811
+ gpuStorage = storeStorage;
15812
+ } else if (typeof creatorOrScope === "string") {
15813
+ const scopeData = storeStorage[creatorOrScope];
15814
+ gpuStorage = scopeData && !isStorageLike(scopeData) ? scopeData : {};
15815
+ }
15935
15816
  return {
15936
15817
  ...gpuStorage,
15937
15818
  removeStorage,
@@ -15941,22 +15822,7 @@ function useGPUStorage(creatorOrScope, scope) {
15941
15822
  };
15942
15823
  }
15943
15824
  function rebuildAllStorage(store, scope) {
15944
- store = store.getState().primaryStore ?? store;
15945
- store.setState((state) => {
15946
- let newStorage = state.gpuStorage;
15947
- if (scope && scope !== "root") {
15948
- const { [scope]: _, ...rest } = state.gpuStorage;
15949
- newStorage = rest;
15950
- } else if (scope === "root") {
15951
- newStorage = {};
15952
- for (const [key, value] of Object.entries(state.gpuStorage)) {
15953
- if (!isStorageLike(value)) newStorage[key] = value;
15954
- }
15955
- } else {
15956
- newStorage = {};
15957
- }
15958
- return { gpuStorage: newStorage, _hmrVersion: state._hmrVersion + 1 };
15959
- });
15825
+ rebuildResource(store, "gpuStorage", scope);
15960
15826
  }
15961
15827
 
15962
15828
  function useRenderPipeline(mainCB, setupCB) {
@@ -15997,12 +15863,12 @@ function useRenderPipeline(mainCB, setupCB) {
15997
15863
  const state = store.getState();
15998
15864
  const set = store.setState;
15999
15865
  try {
16000
- let pp = state.renderPipeline;
15866
+ let pipeline = state.renderPipeline;
16001
15867
  let currentPasses = { ...state.passes };
16002
- let justCreatedPP = false;
16003
- if (!pp) {
16004
- pp = new PostProcessing(renderer);
16005
- justCreatedPP = true;
15868
+ let justCreatedPipeline = false;
15869
+ if (!pipeline) {
15870
+ pipeline = new RenderPipeline(renderer);
15871
+ justCreatedPipeline = true;
16006
15872
  }
16007
15873
  const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
16008
15874
  let scenePass;
@@ -16013,9 +15879,9 @@ function useRenderPipeline(mainCB, setupCB) {
16013
15879
  scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
16014
15880
  }
16015
15881
  currentPasses.scenePass = scenePass;
16016
- if (!pp.outputNode || justCreatedPP) pp.outputNode = scenePass;
16017
- set({ renderPipeline: pp, passes: currentPasses });
16018
- const shouldRunCallbacks = justCreatedPP || !callbacksRanRef.current || !cacheValid;
15882
+ if (!pipeline.outputNode || justCreatedPipeline) pipeline.outputNode = scenePass;
15883
+ set({ renderPipeline: pipeline, passes: currentPasses });
15884
+ const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
16019
15885
  if (shouldRunCallbacks) {
16020
15886
  if (setupCBRef.current) {
16021
15887
  const freshState = store.getState();
@@ -16036,7 +15902,7 @@ function useRenderPipeline(mainCB, setupCB) {
16036
15902
  callbacksRanRef.current = true;
16037
15903
  }
16038
15904
  } catch (error) {
16039
- console.error("[useRenderPipeline] Setup error:", error);
15905
+ console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
16040
15906
  }
16041
15907
  }, [store, renderer, scene, camera, isLegacy, rebuildVersion]);
16042
15908
  const passes = useThree((s) => s.passes);