@react-three/fiber 10.0.0-canary.ba354c7 → 10.0.0-canary.c385e9f

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as three_examples_jsm_inspector_Inspector_js from 'three/examples/jsm/inspector/Inspector.js';
1
2
  import * as three_webgpu from 'three/webgpu';
2
3
  import { CubeRenderTarget, RenderTarget, WebGPURenderer, Node, StorageTexture, Data3DTexture, CanvasTarget, ShaderNodeObject, Euler as Euler$2, Color as Color$2, ColorRepresentation as ColorRepresentation$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, Loader as Loader$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera } from 'three/webgpu';
3
4
  import * as THREE$1 from 'three';
@@ -47,6 +48,9 @@ function _mergeNamespaces(n, m) {
47
48
  declare const R3F_BUILD_LEGACY = true;
48
49
  declare const R3F_BUILD_WEBGPU = true;
49
50
 
51
+ /** Lazily load the three Inspector. Keeps it out of the eager module graph — see note above. */
52
+ declare function loadInspector(): Promise<typeof three_examples_jsm_inspector_Inspector_js.Inspector>;
53
+
50
54
  var THREE = /*#__PURE__*/_mergeNamespaces({
51
55
  __proto__: null,
52
56
  CubeRenderTarget: CubeRenderTarget,
@@ -58,7 +62,8 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
58
62
  WebGLCubeRenderTarget: WebGLCubeRenderTarget,
59
63
  WebGLRenderTarget: WebGLRenderTarget,
60
64
  WebGLRenderer: WebGLRenderer,
61
- WebGLRendererParameters: WebGLRendererParameters
65
+ WebGLRendererParameters: WebGLRendererParameters,
66
+ loadInspector: loadInspector
62
67
  }, [three_webgpu]);
63
68
 
64
69
  //* Utility Types ==============================
@@ -358,6 +363,33 @@ type BufferRecord = Record<string, BufferLike>
358
363
  */
359
364
  type BufferStore = Record<string, BufferLike | BufferRecord>
360
365
 
366
+ //* Node Types (useNodes) ========================================
367
+
368
+ /**
369
+ * Structural shape of a TSL node as stored on `state.nodes`.
370
+ *
371
+ * Deliberately minimal rather than three's nominal `Node`: in @types/three several node classes
372
+ * TSL hands back (OperatorNode, ConstNode, ...) do not extend `Node` cleanly, so a `Node` bound
373
+ * would reject values `useNodes` creators legitimately return. This is the same shape
374
+ * `useNodes` already constrains creators to (`TSLNodeLike`).
375
+ */
376
+ interface NodeLike {
377
+ uuid?: string
378
+ nodeType?: string | null
379
+ /** label method for chaining - sets the node's label and returns self */
380
+ label?: ((label: string) => NodeLike) | string
381
+ setName?: (name: string) => this
382
+ }
383
+
384
+ /** Flat record of TSL nodes (no nested scopes) */
385
+ type NodeRecord = Record<string, NodeLike>
386
+
387
+ /**
388
+ * Node store that can contain both root-level nodes and scoped node objects.
389
+ * Structure: { wobble: OperatorNode, fx: { blur: ShaderCallable } }
390
+ */
391
+ type NodeStore = Record<string, NodeLike | NodeRecord>
392
+
361
393
  //* Storage Types (useGPUStorage) ========================================
362
394
 
363
395
  /**
@@ -496,6 +528,18 @@ interface InternalState {
496
528
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
497
529
  */
498
530
  canvasTarget?: CanvasTarget
531
+ /**
532
+ * Set when this root's canvas target has been resized and the backend's cached render pass
533
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
534
+ *
535
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
536
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
537
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
538
+ * invalidate some other canvas's descriptor instead.
539
+ *
540
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
541
+ */
542
+ canvasTargetSizeDirty?: boolean
499
543
  /**
500
544
  * Whether multi-canvas rendering is active.
501
545
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -605,7 +649,7 @@ interface RootState {
605
649
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
606
650
  uniforms: UniformStore
607
651
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
608
- nodes: Record<string, any>
652
+ nodes: NodeStore
609
653
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
610
654
  buffers: BufferStore
611
655
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -617,7 +661,7 @@ interface RootState {
617
661
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
618
662
  renderPipeline: ThreeRenderPipeline | null
619
663
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
620
- passes: Record<string, any>
664
+ passes: PassRecord
621
665
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
622
666
  _hmrVersion: number
623
667
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -705,12 +749,19 @@ type DefaultRendererProps = {
705
749
  */
706
750
  interface CanvasSchedulerConfig {
707
751
  /**
708
- * Render this canvas after another canvas completes.
709
- * Pass the `id` of another canvas.
752
+ * Run this Canvas root before the referenced Canvas root id(s).
710
753
  */
711
- after?: string
754
+ before?: string | string[]
712
755
  /**
713
- * Limit this canvas's render rate (frames per second).
756
+ * Run this Canvas root after the referenced Canvas root id(s).
757
+ */
758
+ after?: string | string[]
759
+ /**
760
+ * Numeric root order. Lower values run first.
761
+ */
762
+ order?: number
763
+ /**
764
+ * Limit this Canvas's default render job (frames per second).
714
765
  */
715
766
  fps?: number
716
767
  }
@@ -1158,7 +1209,33 @@ declare global {
1158
1209
  * ergonomics. The result is three's structural type, so members stay in sync with the
1159
1210
  * installed three instead of needing to be mirrored by hand.
1160
1211
  */
1161
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1212
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<UniformNodeTypeFor<T>, T>
1213
+
1214
+ /**
1215
+ * three's node type name for a uniform value type, mirroring the `uniform()` overloads.
1216
+ * A `UniformNode<number>` is a `Node<'float'>`, so TSL math (`.mul`, `.add`, ...) accepts it.
1217
+ * Unknown or unlisted value types resolve to `unknown`, which TSL math rejects: narrow with
1218
+ * `as UniformNode<number>` (or the matching value type) at the call site.
1219
+ */
1220
+ type UniformNodeTypeFor<T> = T extends number
1221
+ ? 'float'
1222
+ : T extends boolean
1223
+ ? 'bool'
1224
+ : T extends three_webgpu.Color
1225
+ ? 'color'
1226
+ : T extends three_webgpu.Vector2
1227
+ ? 'vec2'
1228
+ : T extends three_webgpu.Vector3
1229
+ ? 'vec3'
1230
+ : T extends three_webgpu.Vector4
1231
+ ? 'vec4'
1232
+ : T extends three_webgpu.Matrix2
1233
+ ? 'mat2'
1234
+ : T extends three_webgpu.Matrix3
1235
+ ? 'mat3'
1236
+ : T extends three_webgpu.Matrix4
1237
+ ? 'mat4'
1238
+ : unknown
1162
1239
 
1163
1240
  /**
1164
1241
  * ShaderCallable - the return type of Fn()
@@ -1311,30 +1388,97 @@ declare global {
1311
1388
  */
1312
1389
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1313
1390
 
1314
- /** Pass record - stores TSL pass nodes for render pipeline */
1315
- type PassRecord = Record<string, any>
1391
+ /**
1392
+ * The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
1393
+ * `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
1394
+ * `getTextureNode`, `setMRT` and `dispose` track the installed version.
1395
+ */
1396
+ type ScenePassNode = three_webgpu.PassNode
1397
+
1398
+ /**
1399
+ * Pass record - stores TSL pass nodes for render pipeline.
1400
+ *
1401
+ * `scenePass` is the only key the library owns. It is optional here because this is also the
1402
+ * shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
1403
+ * or `clearPasses()`. Inside the callbacks it is always present; see
1404
+ * {@link RenderPipelineCallbackState}.
1405
+ *
1406
+ * Every other key is user-registered, via a callback's return value. Those are TSL nodes of
1407
+ * any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
1408
+ * `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
1409
+ * site when you need a member, e.g. `passes.velocity as TextureNode`.
1410
+ */
1411
+ interface PassRecord {
1412
+ scenePass?: ScenePassNode
1413
+ [key: string]: three_webgpu.Node
1414
+ }
1415
+
1416
+ /**
1417
+ * State passed to pipeline callbacks after the active pipeline has been created.
1418
+ *
1419
+ * `passes.scenePass` is required here: the hook installs the default scene pass before either
1420
+ * callback runs, so callbacks can use it without a guard or a cast.
1421
+ *
1422
+ * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
1423
+ * the legacy renderer before either callback can run, so a callback never sees WebGL.
1424
+ */
1425
+ type RenderPipelineCallbackState = RootState & {
1426
+ renderPipeline: ThreeRenderPipeline
1427
+ passes: PassRecord & { scenePass: ScenePassNode }
1428
+ renderer: three_webgpu.WebGPURenderer
1429
+ isLegacy: false
1430
+ }
1431
+
1432
+ /**
1433
+ * What a callback may return to register entries into `state.passes`.
1434
+ *
1435
+ * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
1436
+ * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
1437
+ * store entry would leave the store pointing at a node the hook never disposes, and the hook
1438
+ * disposing a pass nothing references. So returning it is a type error.
1439
+ */
1440
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1316
1441
 
1317
1442
  /** Setup callback - runs first to configure MRT, create additional passes */
1318
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1443
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1319
1444
 
1320
1445
  /** Main callback - runs second to configure outputNode, create effect passes */
1321
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1446
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1322
1447
 
1323
- /** Return type for useRenderPipeline hook */
1324
- interface UseRenderPipelineReturn {
1448
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1449
+ interface UseRenderPipelineActions {
1325
1450
  /** Current passes from state */
1326
1451
  passes: PassRecord
1327
- /** RenderPipeline instance (null if not initialized) */
1328
- renderPipeline: ThreeRenderPipeline | null
1329
1452
  /** Clear all passes from state */
1330
1453
  clearPasses: () => void
1331
1454
  /** Reset RenderPipeline entirely (clears PP + passes) */
1332
1455
  reset: () => void
1333
1456
  /** Re-run setup/main callbacks with current closure values */
1334
1457
  rebuild: () => void
1335
- /** True when RenderPipeline is configured and ready */
1336
- isReady: boolean
1337
1458
  }
1459
+
1460
+ /**
1461
+ * Return type for useRenderPipeline hook, discriminated on `isReady`.
1462
+ *
1463
+ * `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
1464
+ * callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
1465
+ * `clearPasses()` empties the record while leaving the pipeline in place.
1466
+ */
1467
+ type UseRenderPipelineReturn = UseRenderPipelineActions &
1468
+ (
1469
+ | {
1470
+ /** True when RenderPipeline is configured and ready */
1471
+ isReady: true
1472
+ /** RenderPipeline instance */
1473
+ renderPipeline: ThreeRenderPipeline
1474
+ }
1475
+ | {
1476
+ /** False until the pipeline has been created */
1477
+ isReady: false
1478
+ /** Not initialized yet, or torn down by reset() */
1479
+ renderPipeline: null
1480
+ }
1481
+ )
1338
1482
  }
1339
1483
 
1340
1484
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -1878,7 +2022,7 @@ declare namespace useLoader {
1878
2022
  *
1879
2023
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1880
2024
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1881
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
2025
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1882
2026
  *
1883
2027
  * @example
1884
2028
  * // Simple priority (backwards compat)
@@ -2174,7 +2318,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2174
2318
  * Invalidates the view, requesting a frame to be rendered.
2175
2319
  * In demand mode, this triggers the scheduler to run frames.
2176
2320
  *
2177
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2321
+ * With a state argument, only that root's jobs run on the requested frames; other
2322
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2323
+ *
2324
+ * @param state - Optional root state; targets the invalidation at that root
2178
2325
  * @param frames - Number of frames to request (default: 1)
2179
2326
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2180
2327
  *
@@ -2185,14 +2332,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2185
2332
  * Advances the frameloop and runs render effects.
2186
2333
  * Useful for when manually rendering via `frameloop="never"`.
2187
2334
  *
2335
+ * With a state argument, only that root is stepped. Without one, every
2336
+ * registered root is stepped for backwards compatibility.
2337
+ *
2188
2338
  * @param timestamp - The timestamp to use for this frame
2189
2339
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2190
- * @param state - Ignored (kept for backwards compat)
2191
- * @param frame - Ignored (kept for backwards compat)
2340
+ * @param state - Optional root state; targets the manual step at that root
2192
2341
  *
2193
2342
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2194
2343
  */
2195
- declare function advance(timestamp: number): void;
2344
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2196
2345
 
2197
2346
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2198
2347
  declare function ReactReconciler<
@@ -3747,4 +3896,4 @@ declare function isOnce(value: unknown): value is {
3747
3896
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3748
3897
 
3749
3898
  export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, 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, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, reconciler, registerPrimary, removeInteractivity, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
3750
- export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameNextCallback, FrameNextState, FrameState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeProps, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };
3899
+ export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameNextCallback, FrameNextState, FrameState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeLike, NodeProps, NodeRecord, NodeStore, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };