@react-three/fiber 10.0.0-alpha.2 → 10.0.0-canary.1b98c17

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.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as three_webgpu from 'three/webgpu';
2
- import { RenderTarget, Node, ShaderNodeObject, Euler as Euler$1, Color as Color$2, ColorRepresentation as ColorRepresentation$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Quaternion as Quaternion$1, Matrix3 as Matrix3$1, Matrix4 as Matrix4$1, Object3D, Texture as Texture$1, Frustum, OrthographicCamera } from 'three/webgpu';
2
+ import { 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
3
  import * as THREE$1 from 'three';
4
- import { WebGLRenderTarget, WebGLRenderer, Color as Color$1, ColorRepresentation, RenderTargetOptions as RenderTargetOptions$1 } from 'three';
4
+ import { WebGLRenderTarget, WebGLRenderer, Color as Color$1, ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1 } from 'three';
5
5
  import { WebGLRendererParameters } from 'three/src/renderers/WebGLRenderer.js';
6
6
  import { Inspector } from 'three/addons/inspector/Inspector.js';
7
7
  import * as React$1 from 'react';
@@ -10,6 +10,8 @@ import { StoreApi } from 'zustand';
10
10
  import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
11
11
  import { Options } from 'react-use-measure';
12
12
  import * as react_jsx_runtime from 'react/jsx-runtime';
13
+ import { ThreeElement as ThreeElement$1, Euler as Euler$3 } from '@react-three/fiber';
14
+ import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
13
15
 
14
16
  function _mergeNamespaces(n, m) {
15
17
  m.forEach(function (e) {
@@ -55,1282 +57,1741 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
55
57
  WebGLRendererParameters: WebGLRendererParameters
56
58
  }, [three_webgpu]);
57
59
 
58
- //* Utility Types ==============================
59
-
60
- type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
61
- type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
62
- type Properties<T> = Pick<T, NonFunctionKeys<T>>
63
- type Mutable<P> = { [K in keyof P]: P[K] | Readonly<P[K]> }
64
- type IsOptional<T> = undefined extends T ? true : false
65
- type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
66
- ? IsOptional<First> extends true
67
- ? IsAllOptional<Rest>
68
- : false
69
- : true
70
-
71
- //* Camera Types ==============================
72
-
73
- type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
74
-
75
- //* Act Type ==============================
76
-
77
- type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
78
-
79
- //* Bridge & Block Types ==============================
80
-
81
- type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
82
-
83
- type SetBlock = false | Promise<null> | null
84
- type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
85
-
86
- //* Object Map Type ==============================
87
-
88
- interface ObjectMap {
89
- nodes: { [name: string]: THREE$1.Object3D }
90
- materials: { [name: string]: THREE$1.Material }
91
- meshes: { [name: string]: THREE$1.Mesh }
92
- }
93
-
94
- //* Equality Config ==============================
95
-
96
- interface EquConfig {
97
- /** Compare arrays by reference equality a === b (default), or by shallow equality */
98
- arrays?: 'reference' | 'shallow'
99
- /** Compare objects by reference equality a === b (default), or by shallow equality */
100
- objects?: 'reference' | 'shallow'
101
- /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
102
- strict?: boolean
103
- }
104
-
105
- //* Disposable Type ==============================
106
-
107
- interface Disposable {
108
- type?: string
109
- dispose?: () => void
110
- }
111
-
112
- //* Event-related Types =====================================
113
-
114
- interface Intersection extends THREE$1.Intersection {
115
- /** The event source (the object which registered the handler) */
116
- eventObject: THREE$1.Object3D
117
- }
118
-
119
- type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
120
-
121
- interface IntersectionEvent<TSourceEvent> extends Intersection {
122
- /** The event source (the object which registered the handler) */
123
- eventObject: THREE$1.Object3D
124
- /** An array of intersections */
125
- intersections: Intersection[]
126
- /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
127
- unprojectedPoint: THREE$1.Vector3
128
- /** Normalized event coordinates */
129
- pointer: THREE$1.Vector2
130
- /** Delta between first click and this event */
131
- delta: number
132
- /** The ray that pierced it */
133
- ray: THREE$1.Ray
134
- /** The camera that was used by the raycaster */
135
- camera: Camera
136
- /** stopPropagation will stop underlying handlers from firing */
137
- stopPropagation: () => void
138
- /** The original host event */
139
- nativeEvent: TSourceEvent
140
- /** If the event was stopped by calling stopPropagation */
141
- stopped: boolean
142
- }
143
-
144
- type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
145
- type DomEvent = PointerEvent | MouseEvent | WheelEvent
146
-
147
- /** DOM event handlers registered on the canvas element */
148
- interface Events {
149
- onClick: EventListener
150
- onContextMenu: EventListener
151
- onDoubleClick: EventListener
152
- onWheel: EventListener
153
- onPointerDown: EventListener
154
- onPointerUp: EventListener
155
- onPointerLeave: EventListener
156
- onPointerMove: EventListener
157
- onPointerCancel: EventListener
158
- onLostPointerCapture: EventListener
159
- onDragEnter: EventListener
160
- onDragLeave: EventListener
161
- onDragOver: EventListener
162
- onDrop: EventListener
163
- }
164
-
165
- /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
166
- interface EventHandlers {
167
- onClick?: (event: ThreeEvent<MouseEvent>) => void
168
- onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
169
- onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
170
- /** Fires continuously while dragging over the object */
171
- onDragOver?: (event: ThreeEvent<DragEvent>) => void
172
- /** Fires once when drag enters the object */
173
- onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
174
- /** Fires once when drag leaves the object */
175
- onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
176
- /** Fires when drag misses this object (for objects that have drag handlers) */
177
- onDragOverMissed?: (event: DragEvent) => void
178
- /** Fires when a drop occurs on this object */
179
- onDrop?: (event: ThreeEvent<DragEvent>) => void
180
- /** Fires when a drop misses this object (for objects that have drop handlers) */
181
- onDropMissed?: (event: DragEvent) => void
182
- onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
183
- onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
184
- onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
185
- onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
186
- onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
187
- onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
188
- onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
189
- onPointerMissed?: (event: MouseEvent) => void
190
- onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
191
- onWheel?: (event: ThreeEvent<WheelEvent>) => void
192
- onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
193
-
194
- //* Visibility Events --------------------------------
195
- /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
196
- onFramed?: (inView: boolean) => void
197
- /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
198
- onOccluded?: (occluded: boolean) => void
199
- /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
200
- onVisible?: (visible: boolean) => void
201
- }
202
-
203
- type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
204
- type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
205
-
206
- interface EventManager<TTarget> {
207
- /** Determines if the event layer is active */
208
- enabled: boolean
209
- /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
210
- priority: number
211
- /** The compute function needs to set up the raycaster and an xy- pointer */
212
- compute?: ComputeFunction
213
- /** The filter can re-order or re-structure the intersections */
214
- filter?: FilterFunction
215
- /** The target node the event layer is tied to */
216
- connected?: TTarget
217
- /** All the pointer event handlers through which the host forwards native events */
218
- handlers?: Events
219
- /** Allows re-connecting to another target */
220
- connect?: (target: TTarget) => void
221
- /** Removes all existing events handlers from the target */
222
- disconnect?: () => void
223
- /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
224
- * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
225
- */
226
- update?: () => void
227
- }
228
-
229
- interface PointerCaptureTarget {
230
- intersection: Intersection
231
- target: Element
232
- }
233
-
234
- //* Visibility System Types =====================================
235
-
236
- /** Entry in the visibility registry for tracking object visibility state */
237
- interface VisibilityEntry {
238
- object: THREE$1.Object3D
239
- handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
240
- lastFramedState: boolean | null
241
- lastOccludedState: boolean | null
242
- lastVisibleState: boolean | null
243
- }
244
-
245
- //* Scheduler Types (useFrame) ==============================
246
-
247
-
248
-
249
- // Public Options --------------------------------
250
-
251
- /**
252
- * Options for useFrame hook
253
- */
254
- interface UseFrameNextOptions {
255
- /** Optional stable id for the job. Auto-generated if not provided */
256
- id?: string
257
- /** Named phase to run in. Default: 'update' */
258
- phase?: string
259
- /** Run before this phase or job id */
260
- before?: string | string[]
261
- /** Run after this phase or job id */
262
- after?: string | string[]
263
- /** Priority within phase. Higher runs first. Default: 0 */
264
- priority?: number
265
- /** Max frames per second for this job */
266
- fps?: number
267
- /** If true, skip frames when behind. If false, try to catch up. Default: true */
268
- drop?: boolean
269
- /** Enable/disable without unregistering. Default: true */
270
- enabled?: boolean
271
- }
272
-
273
- /** Alias for UseFrameNextOptions */
274
- type UseFrameOptions = UseFrameNextOptions
275
-
276
- /**
277
- * Options for addPhase
278
- */
279
- interface AddPhaseOptions {
280
- /** Insert this phase before the specified phase */
281
- before?: string
282
- /** Insert this phase after the specified phase */
283
- after?: string
284
- }
285
-
286
- // Frame State --------------------------------
287
-
288
- /**
289
- * Timing-only state for independent/outside mode (no RootState)
290
- */
291
- interface FrameTimingState {
292
- /** High-resolution timestamp from RAF (ms) */
293
- time: number
294
- /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
295
- delta: number
296
- /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
297
- elapsed: number
298
- /** Incrementing frame counter */
299
- frame: number
300
- }
301
-
302
- /**
303
- * State passed to useFrame callbacks (extends RootState with timing)
304
- */
305
- interface FrameNextState extends RootState, FrameTimingState {}
306
-
307
- /** Alias for FrameNextState */
308
- type FrameState = FrameNextState
309
-
310
- // Root Options --------------------------------
311
-
312
- /**
313
- * Options for registerRoot
314
- */
315
- interface RootOptions {
316
- /** State provider for callbacks. Optional in independent mode. */
317
- getState?: () => any
318
- /** Error handler for job errors. Falls back to console.error if not provided. */
319
- onError?: (error: Error) => void
320
- }
321
-
322
- // Callback Types --------------------------------
323
-
324
- /**
325
- * Callback function for useFrame
326
- */
327
- type FrameNextCallback = (state: FrameNextState, delta: number) => void
328
-
329
- /** Alias for FrameNextCallback */
330
- type FrameCallback = FrameNextCallback
331
-
332
- // Controls returned from useFrame --------------------------------
333
-
334
- /**
335
- * Controls object returned from useFrame hook
336
- */
337
- interface FrameNextControls {
338
- /** The job's unique ID */
339
- id: string
340
- /** Access to the global scheduler for frame loop control */
341
- scheduler: SchedulerApi
342
- /** Manually step this job only (bypasses FPS limiting) */
343
- step(timestamp?: number): void
344
- /** Manually step ALL jobs in the scheduler */
345
- stepAll(timestamp?: number): void
346
- /** Pause this job (set enabled=false) */
347
- pause(): void
348
- /** Resume this job (set enabled=true) */
349
- resume(): void
350
- /** Reactive paused state - automatically triggers re-render when changed */
351
- isPaused: boolean
352
- }
353
-
354
- /** Alias for FrameNextControls */
355
- type FrameControls = FrameNextControls
356
-
357
- // Scheduler Interface --------------------------------
358
-
359
- /**
360
- * Public interface for the global Scheduler
361
- */
362
- interface SchedulerApi {
363
- //* Phase Management --------------------------------
364
-
365
- /** Add a named phase to the scheduler */
366
- addPhase(name: string, options?: AddPhaseOptions): void
367
- /** Get the ordered list of phase names */
368
- readonly phases: string[]
369
- /** Check if a phase exists */
370
- hasPhase(name: string): boolean
371
-
372
- //* Root Management --------------------------------
373
-
374
- /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
375
- registerRoot(id: string, options?: RootOptions): () => void
376
- /** Unregister a root */
377
- unregisterRoot(id: string): void
378
- /** Generate a unique root ID */
379
- generateRootId(): string
380
- /** Get the number of registered roots */
381
- getRootCount(): number
382
- /** Check if any root is registered and ready */
383
- readonly isReady: boolean
384
- /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
385
- onRootReady(callback: () => void): () => void
386
-
387
- //* Job Registration --------------------------------
388
-
389
- /** Register a job with the scheduler (returns unsubscribe function) */
390
- register(
391
- callback: FrameNextCallback,
392
- options?: {
393
- id?: string
394
- rootId?: string
395
- phase?: string
396
- before?: string | string[]
397
- after?: string | string[]
398
- priority?: number
399
- fps?: number
400
- drop?: boolean
401
- enabled?: boolean
402
- },
403
- ): () => void
404
- /** Update a job's options */
405
- updateJob(
406
- id: string,
407
- options: {
408
- priority?: number
409
- fps?: number
410
- drop?: boolean
411
- enabled?: boolean
412
- phase?: string
413
- before?: string | string[]
414
- after?: string | string[]
415
- },
416
- ): void
417
- /** Unregister a job by ID */
418
- unregister(id: string, rootId?: string): void
419
- /** Get the number of registered jobs */
420
- getJobCount(): number
421
- /** Get all job IDs */
422
- getJobIds(): string[]
423
-
424
- //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
425
-
426
- /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
427
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
428
-
429
- //* Idle Callbacks (for legacy addTail) --------------------------------
430
-
431
- /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
432
- onIdle(callback: (timestamp: number) => void): () => void
433
-
434
- //* Frame Loop Control --------------------------------
435
-
436
- /** Start the scheduler loop */
437
- start(): void
438
- /** Stop the scheduler loop */
439
- stop(): void
440
- /** Check if the scheduler is running */
441
- readonly isRunning: boolean
442
- /** Get/set the frameloop mode ('always', 'demand', 'never') */
443
- frameloop: Frameloop
444
- /** Independent mode - runs without Canvas, callbacks receive timing-only state */
445
- independent: boolean
446
-
447
- //* Manual Stepping --------------------------------
448
-
449
- /** Manually step all jobs once (for frameloop='never' or testing) */
450
- step(timestamp?: number): void
451
- /** Manually step a single job by ID */
452
- stepJob(id: string, timestamp?: number): void
453
- /** Request frame(s) to be rendered (for frameloop='demand') */
454
- invalidate(frames?: number): void
455
-
456
- //* Per-Job Control --------------------------------
457
-
458
- /** Check if a job is paused */
459
- isJobPaused(id: string): boolean
460
- /** Pause a job */
461
- pauseJob(id: string): void
462
- /** Resume a job */
463
- resumeJob(id: string): void
464
- /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
465
- subscribeJobState(id: string, listener: () => void): () => void
466
- }
467
-
468
- //* Core Store Types ========================================
469
-
470
- type Subscription = {
471
- ref: React$1.RefObject<RenderCallback>
472
- priority: number
473
- store: RootStore
474
- }
475
-
476
- type Dpr = number | [min: number, max: number]
477
-
478
- interface Size {
479
- width: number
480
- height: number
481
- top: number
482
- left: number
483
- }
484
-
485
- type Frameloop = 'always' | 'demand' | 'never'
486
-
487
- interface Viewport extends Size {
488
- /** The initial pixel ratio */
489
- initialDpr: number
490
- /** Current pixel ratio */
491
- dpr: number
492
- /** size.width / viewport.width */
493
- factor: number
494
- /** Camera distance */
495
- distance: number
496
- /** Camera aspect ratio: width / height */
497
- aspect: number
498
- }
499
-
500
- type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
501
-
502
- interface Performance {
503
- /** Current performance normal, between min and max */
504
- current: number
505
- /** How low the performance can go, between 0 and max */
506
- min: number
507
- /** How high the performance can go, between min and max */
508
- max: number
509
- /** Time until current returns to max in ms */
510
- debounce: number
511
- /** Sets current to min, puts the system in regression */
512
- regress: () => void
513
- }
514
-
515
- interface InternalState {
516
- interaction: THREE$1.Object3D[]
517
- hovered: Map<string, ThreeEvent<DomEvent>>
518
- subscribers: Subscription[]
519
- capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
520
- initialClick: [x: number, y: number]
521
- initialHits: THREE$1.Object3D[]
522
- lastEvent: React$1.RefObject<DomEvent | null>
523
- /** Visibility event registry (onFramed, onOccluded, onVisible) */
524
- visibilityRegistry: Map<string, VisibilityEntry>
525
- /** Whether occlusion queries are enabled (WebGPU only) */
526
- occlusionEnabled: boolean
527
- /** Reference to the invisible occlusion observer mesh */
528
- occlusionObserver: THREE$1.Mesh | null
529
- /** Cached occlusion results from render pass - keyed by Object3D */
530
- occlusionCache: Map<THREE$1.Object3D, boolean | null>
531
- /** Internal helper group for R3F system objects (occlusion observer, etc.) */
532
- helperGroup: THREE$1.Group | null
533
- active: boolean
534
- priority: number
535
- frames: number
536
- subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
537
- /** Internal renderer storage - use state.renderer or state.gl to access */
538
- actualRenderer: THREE$1.WebGLRenderer | any // WebGPURenderer when available
539
- /** Global scheduler reference (for useFrame hook) */
540
- scheduler: SchedulerApi | null
541
- /** This root's unique ID in the global scheduler */
542
- rootId?: string
543
- /** Function to unregister this root from the global scheduler */
544
- unregisterRoot?: () => void
545
- /** Container for child attachment (scene for root, original container for portals) */
546
- container?: THREE$1.Object3D
547
- }
548
-
549
- interface XRManager {
550
- connect: () => void
551
- disconnect: () => void
552
- }
553
-
554
- //* Root State Interface ====================================
555
-
556
- interface RootState {
557
- /** Set current state */
558
- set: StoreApi<RootState>['setState']
559
- /** Get current state */
560
- get: StoreApi<RootState>['getState']
561
- /** (deprecated) The instance of the WebGLrenderer */
562
- gl: THREE$1.WebGLRenderer
563
- /** The instance of the WebGPU renderer, the fallback, OR the default renderer as a mask of gl */
564
- renderer: THREE$1.WebGLRenderer | any // WebGPURenderer when available
565
- /** Inspector of the webGPU Renderer. Init in the canvas */
566
- inspector: any // Inspector type from three/webgpu
567
-
568
- /** Default camera */
569
- camera: ThreeCamera
570
- /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
571
- frustum: THREE$1.Frustum
572
- /** Whether to automatically update the frustum each frame (default: true) */
573
- autoUpdateFrustum: boolean
574
- /** Default scene (may be overridden in portals to point to the portal container) */
575
- scene: THREE$1.Scene
576
- /** The actual root THREE.Scene - always points to the true scene, even inside portals */
577
- rootScene: THREE$1.Scene
578
- /** Default raycaster */
579
- raycaster: THREE$1.Raycaster
580
- /** Event layer interface, contains the event handler and the node they're connected to */
581
- events: EventManager<any>
582
- /** XR interface */
583
- xr: XRManager
584
- /** Currently used controls */
585
- controls: THREE$1.EventDispatcher | null
586
- /** Normalized event coordinates */
587
- pointer: THREE$1.Vector2
588
- /** @deprecated Normalized event coordinates, use "pointer" instead! */
589
- mouse: THREE$1.Vector2
590
- /* Whether to enable r139's THREE.ColorManagement */
591
- legacy: boolean
592
- /** Shortcut to gl.outputColorSpace = THREE.LinearSRGBColorSpace */
593
- linear: boolean
594
- /** Shortcut to gl.toneMapping = NoTonemapping */
595
- flat: boolean
596
- /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
597
- textureColorSpace: THREE$1.ColorSpace
598
- /** Render loop flags */
599
- frameloop: Frameloop
600
- performance: Performance
601
- /** Reactive pixel-size of the canvas */
602
- size: Size
603
- /** Reactive size of the viewport in threejs units */
604
- viewport: Viewport & {
605
- getCurrentViewport: (
606
- camera?: ThreeCamera,
607
- target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
608
- size?: Size,
609
- ) => Omit<Viewport, 'dpr' | 'initialDpr'>
610
- }
611
- /** Flags the canvas for render, but doesn't render in itself */
612
- invalidate: (frames?: number, stackFrames?: boolean) => void
613
- /** Advance (render) one step */
614
- advance: (timestamp: number, runGlobalEffects?: boolean) => void
615
- /** Shortcut to setting the event layer */
616
- setEvents: (events: Partial<EventManager<any>>) => void
617
- /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
618
- setSize: (width?: number, height?: number, top?: number, left?: number) => void
619
- /** Shortcut to manual setting the pixel ratio */
620
- setDpr: (dpr: Dpr) => void
621
- /** Shortcut to setting frameloop flags */
622
- setFrameloop: (frameloop: Frameloop) => void
623
- /** Set error state to propagate to error boundary */
624
- setError: (error: Error | null) => void
625
- /** Current error state (null when no error) */
626
- error: Error | null
627
- /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
628
- uniforms: UniformStore
629
- /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
630
- nodes: Record<string, any>
631
- /** Global TSL texture nodes - use useTextures() hook for operations */
632
- textures: Map<string, any>
633
- /** WebGPU PostProcessing instance - use usePostProcessing() hook */
634
- postProcessing: any | null // THREE.PostProcessing when available
635
- /** Global TSL pass nodes for post-processing - use usePostProcessing() hook */
636
- passes: Record<string, any>
637
- /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
638
- _hmrVersion: number
639
- /** Internal: whether setSize() has taken ownership of canvas dimensions */
640
- _sizeImperative: boolean
641
- /** Internal: stored size props from Canvas for reset functionality */
642
- _sizeProps: { width?: number; height?: number } | null
643
- /** When the canvas was clicked but nothing was hit */
644
- onPointerMissed?: (event: MouseEvent) => void
645
- /** When a dragover event has missed any target */
646
- onDragOverMissed?: (event: DragEvent) => void
647
- /** When a drop event has missed any target */
648
- onDropMissed?: (event: DragEvent) => void
649
- /** If this state model is layered (via createPortal) then this contains the previous layer */
650
- previousRoot?: RootStore
651
- /** Internals */
652
- internal: InternalState
653
- // flags for triggers
654
- // if we are using the webGl renderer, this will be true
655
- isLegacy: boolean
656
- // regardless of renderer, if the system supports webGpu, this will be true
657
- webGPUSupported: boolean
658
- //if we are on native
659
- isNative: boolean
660
- }
661
-
60
+ //* Utility Types ==============================
61
+
62
+ type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
63
+ type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
64
+ type Properties<T> = Pick<T, NonFunctionKeys<T>>
65
+ type Mutable<P> = { -readonly [K in keyof P]: P[K] }
66
+ type IsOptional<T> = undefined extends T ? true : false
67
+ type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
68
+ ? IsOptional<First> extends true
69
+ ? IsAllOptional<Rest>
70
+ : false
71
+ : true
72
+
73
+ //* Camera Types ==============================
74
+
75
+ type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
76
+
77
+ //* Act Type ==============================
78
+
79
+ type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
80
+
81
+ //* Bridge & Block Types ==============================
82
+
83
+ type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
84
+
85
+ type SetBlock = false | Promise<null> | null
86
+ type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
87
+
88
+ //* Object Map Type ==============================
89
+
90
+ /* Original version
91
+ export interface ObjectMap {
92
+ nodes: { [name: string]: THREE.Object3D }
93
+ materials: { [name: string]: THREE.Material }
94
+ meshes: { [name: string]: THREE.Mesh }
95
+ }
96
+ */
97
+ /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
98
+ It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
99
+ I will keep the use here)
100
+ https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
101
+ His description is:
102
+ The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
103
+ */
104
+ interface ObjectMap<
105
+ T extends { nodes?: string; materials?: string; meshes?: string } = {
106
+ nodes: string
107
+ materials: string
108
+ meshes: string
109
+ },
110
+ > {
111
+ nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
112
+ materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
113
+ meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
114
+ }
115
+
116
+ //* Equality Config ==============================
117
+
118
+ interface EquConfig {
119
+ /** Compare arrays by reference equality a === b (default), or by shallow equality */
120
+ arrays?: 'reference' | 'shallow'
121
+ /** Compare objects by reference equality a === b (default), or by shallow equality */
122
+ objects?: 'reference' | 'shallow'
123
+ /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
124
+ strict?: boolean
125
+ }
126
+
127
+ //* Disposable Type ==============================
128
+
129
+ interface Disposable {
130
+ type?: string
131
+ dispose?: () => void
132
+ }
133
+
134
+ //* Event-related Types =====================================
135
+
136
+ interface Intersection extends THREE$1.Intersection {
137
+ /** The event source (the object which registered the handler) */
138
+ eventObject: THREE$1.Object3D
139
+ }
140
+
141
+ type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
142
+
143
+ interface IntersectionEvent<TSourceEvent> extends Intersection {
144
+ /** The event source (the object which registered the handler) */
145
+ eventObject: THREE$1.Object3D
146
+ /** An array of intersections */
147
+ intersections: Intersection[]
148
+ /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
149
+ unprojectedPoint: THREE$1.Vector3
150
+ /** Normalized event coordinates */
151
+ pointer: THREE$1.Vector2
152
+ /** pointerId of the original event for multiple pointer events */
153
+ pointerId: number
154
+ /** Delta between first click and this event */
155
+ delta: number
156
+ /** The ray that pierced it */
157
+ ray: THREE$1.Ray
158
+ /** The camera that was used by the raycaster */
159
+ camera: Camera
160
+ /** stopPropagation will stop underlying handlers from firing */
161
+ stopPropagation: () => void
162
+ /** The original host event */
163
+ nativeEvent: TSourceEvent
164
+ /** If the event was stopped by calling stopPropagation */
165
+ stopped: boolean
166
+ }
167
+
168
+ type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
169
+ type DomEvent = PointerEvent | MouseEvent | WheelEvent
170
+
171
+ /** DOM event handlers registered on the canvas element */
172
+ interface Events {
173
+ onClick: EventListener
174
+ onContextMenu: EventListener
175
+ onDoubleClick: EventListener
176
+ onWheel: EventListener
177
+ onPointerDown: EventListener
178
+ onPointerUp: EventListener
179
+ onPointerLeave: EventListener
180
+ onPointerMove: EventListener
181
+ onPointerCancel: EventListener
182
+ onLostPointerCapture: EventListener
183
+ onDragEnter: EventListener
184
+ onDragLeave: EventListener
185
+ onDragOver: EventListener
186
+ onDrop: EventListener
187
+ }
188
+
189
+ /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
190
+ interface EventHandlers {
191
+ onClick?: (event: ThreeEvent<MouseEvent>) => void
192
+ onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
193
+ onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
194
+ /** Fires continuously while dragging over the object */
195
+ onDragOver?: (event: ThreeEvent<DragEvent>) => void
196
+ /** Fires once when drag enters the object */
197
+ onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
198
+ /** Fires once when drag leaves the object */
199
+ onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
200
+ /** Fires when drag misses this object (for objects that have drag handlers) */
201
+ onDragOverMissed?: (event: DragEvent) => void
202
+ /** Fires when a drop occurs on this object */
203
+ onDrop?: (event: ThreeEvent<DragEvent>) => void
204
+ /** Fires when a drop misses this object (for objects that have drop handlers) */
205
+ onDropMissed?: (event: DragEvent) => void
206
+ onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
207
+ onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
208
+ onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
209
+ onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
210
+ onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
211
+ onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
212
+ onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
213
+ onPointerMissed?: (event: MouseEvent) => void
214
+ onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
215
+ onWheel?: (event: ThreeEvent<WheelEvent>) => void
216
+ onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
217
+
218
+ //* Visibility Events --------------------------------
219
+ /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
220
+ onFramed?: (inView: boolean) => void
221
+ /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
222
+ onOccluded?: (occluded: boolean) => void
223
+ /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
224
+ onVisible?: (visible: boolean) => void
225
+ }
226
+
227
+ type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
228
+ type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
229
+
230
+ /** Configuration for XR pointer registration (controllers/hands) */
231
+ interface XRPointerConfig {
232
+ /** Ray origin (updated each frame by XR system) */
233
+ ray: THREE$1.Ray
234
+ /** Optional: custom compute function for this pointer */
235
+ compute?: (state: RootState) => void
236
+ /** Pointer type identifier */
237
+ type: 'controller' | 'hand' | 'gaze'
238
+ /** Which hand (for controller/hand types) */
239
+ handedness?: 'left' | 'right'
240
+ }
241
+
242
+ interface EventManager<TTarget> {
243
+ /** Determines if the event layer is active */
244
+ enabled: boolean
245
+ /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
246
+ priority: number
247
+ /** The compute function needs to set up the raycaster and an xy- pointer */
248
+ compute?: ComputeFunction
249
+ /** The filter can re-order or re-structure the intersections */
250
+ filter?: FilterFunction
251
+ /** The target node the event layer is tied to */
252
+ connected?: TTarget
253
+ /** All the pointer event handlers through which the host forwards native events */
254
+ handlers?: Events
255
+ /** Allows re-connecting to another target */
256
+ connect?: (target: TTarget) => void
257
+ /** Removes all existing events handlers from the target */
258
+ disconnect?: () => void
259
+ /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
260
+ * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
261
+ * @param pointerId - Optional pointer ID to update specific pointer only
262
+ */
263
+ update?: (pointerId?: number) => void
264
+ /** Defer pointer move raycasting to frame start (default: true) */
265
+ frameTimedRaycasts?: boolean
266
+ /** Always fire raycaster immediately on scroll events (default: true) */
267
+ alwaysFireOnScroll?: boolean
268
+ /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
269
+ updateOnFrame?: boolean
270
+ /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
271
+ flush?: () => void
272
+ /** Register an XR pointer (controller/hand). Returns assigned pointerId */
273
+ registerPointer?: (config: XRPointerConfig) => number
274
+ /** Unregister an XR pointer */
275
+ unregisterPointer?: (pointerId: number) => void
276
+ }
277
+
278
+ interface PointerCaptureTarget {
279
+ intersection: Intersection
280
+ target: Element
281
+ }
282
+
283
+ //* Visibility System Types =====================================
284
+
285
+ /** Entry in the visibility registry for tracking object visibility state */
286
+ interface VisibilityEntry {
287
+ object: THREE$1.Object3D
288
+ handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
289
+ lastFramedState: boolean | null
290
+ lastOccludedState: boolean | null
291
+ lastVisibleState: boolean | null
292
+ }
293
+
294
+ //* Scheduler Types (useFrame) ==============================
295
+
296
+
297
+
298
+ // Public Options --------------------------------
299
+
300
+ /**
301
+ * Options for useFrame hook
302
+ */
303
+ interface UseFrameNextOptions {
304
+ /** Optional stable id for the job. Auto-generated if not provided */
305
+ id?: string
306
+ /** Named phase to run in. Default: 'update' */
307
+ phase?: string
308
+ /** Run before this phase or job id */
309
+ before?: string | string[]
310
+ /** Run after this phase or job id */
311
+ after?: string | string[]
312
+ /** Priority within phase. Higher runs first. Default: 0 */
313
+ priority?: number
314
+ /** Max frames per second for this job */
315
+ fps?: number
316
+ /** If true, skip frames when behind. If false, try to catch up. Default: true */
317
+ drop?: boolean
318
+ /** Enable/disable without unregistering. Default: true */
319
+ enabled?: boolean
320
+ }
321
+
322
+ /** Alias for UseFrameNextOptions */
323
+ type UseFrameOptions = UseFrameNextOptions
324
+
325
+ /**
326
+ * Options for addPhase
327
+ */
328
+ interface AddPhaseOptions {
329
+ /** Insert this phase before the specified phase */
330
+ before?: string
331
+ /** Insert this phase after the specified phase */
332
+ after?: string
333
+ }
334
+
335
+ // Frame State --------------------------------
336
+
337
+ /**
338
+ * Timing-only state for independent/outside mode (no RootState)
339
+ */
340
+ interface FrameTimingState {
341
+ /** High-resolution timestamp from RAF (ms) */
342
+ time: number
343
+ /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
344
+ delta: number
345
+ /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
346
+ elapsed: number
347
+ /** Incrementing frame counter */
348
+ frame: number
349
+ }
350
+
351
+ /**
352
+ * State passed to useFrame callbacks (extends RootState with timing)
353
+ */
354
+ interface FrameNextState extends RootState, FrameTimingState {}
355
+
356
+ /** Alias for FrameNextState */
357
+ type FrameState = FrameNextState
358
+
359
+ // Root Options --------------------------------
360
+
361
+ /**
362
+ * Options for registerRoot
363
+ */
364
+ interface RootOptions {
365
+ /** State provider for callbacks. Optional in independent mode. */
366
+ getState?: () => any
367
+ /** Error handler for job errors. Falls back to console.error if not provided. */
368
+ onError?: (error: Error) => void
369
+ }
370
+
371
+ // Callback Types --------------------------------
372
+
373
+ /**
374
+ * Callback function for useFrame
375
+ */
376
+ type FrameNextCallback = (state: FrameNextState, delta: number) => void
377
+
378
+ /** Alias for FrameNextCallback */
379
+ type FrameCallback = FrameNextCallback
380
+
381
+ // Controls returned from useFrame --------------------------------
382
+
383
+ /**
384
+ * Controls object returned from useFrame hook
385
+ */
386
+ interface FrameNextControls {
387
+ /** The job's unique ID */
388
+ id: string
389
+ /** Access to the global scheduler for frame loop control */
390
+ scheduler: SchedulerApi
391
+ /** Manually step this job only (bypasses FPS limiting) */
392
+ step(timestamp?: number): void
393
+ /** Manually step ALL jobs in the scheduler */
394
+ stepAll(timestamp?: number): void
395
+ /** Pause this job (set enabled=false) */
396
+ pause(): void
397
+ /** Resume this job (set enabled=true) */
398
+ resume(): void
399
+ /** Reactive paused state - automatically triggers re-render when changed */
400
+ isPaused: boolean
401
+ }
402
+
403
+ /** Alias for FrameNextControls */
404
+ type FrameControls = FrameNextControls
405
+
406
+ // Scheduler Interface --------------------------------
407
+
408
+ /**
409
+ * Public interface for the global Scheduler
410
+ */
411
+ interface SchedulerApi {
412
+ //* Phase Management --------------------------------
413
+
414
+ /** Add a named phase to the scheduler */
415
+ addPhase(name: string, options?: AddPhaseOptions): void
416
+ /** Get the ordered list of phase names */
417
+ readonly phases: string[]
418
+ /** Check if a phase exists */
419
+ hasPhase(name: string): boolean
420
+
421
+ //* Root Management --------------------------------
422
+
423
+ /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
424
+ registerRoot(id: string, options?: RootOptions): () => void
425
+ /** Unregister a root */
426
+ unregisterRoot(id: string): void
427
+ /** Generate a unique root ID */
428
+ generateRootId(): string
429
+ /** Get the number of registered roots */
430
+ getRootCount(): number
431
+ /** Check if any root is registered and ready */
432
+ readonly isReady: boolean
433
+ /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
434
+ onRootReady(callback: () => void): () => void
435
+
436
+ //* Job Registration --------------------------------
437
+
438
+ /** Register a job with the scheduler (returns unsubscribe function) */
439
+ register(
440
+ callback: FrameNextCallback,
441
+ options?: {
442
+ id?: string
443
+ rootId?: string
444
+ phase?: string
445
+ before?: string | string[]
446
+ after?: string | string[]
447
+ priority?: number
448
+ fps?: number
449
+ drop?: boolean
450
+ enabled?: boolean
451
+ },
452
+ ): () => void
453
+ /** Update a job's options */
454
+ updateJob(
455
+ id: string,
456
+ options: {
457
+ priority?: number
458
+ fps?: number
459
+ drop?: boolean
460
+ enabled?: boolean
461
+ phase?: string
462
+ before?: string | string[]
463
+ after?: string | string[]
464
+ },
465
+ ): void
466
+ /** Unregister a job by ID */
467
+ unregister(id: string, rootId?: string): void
468
+ /** Get the number of registered jobs */
469
+ getJobCount(): number
470
+ /** Get all job IDs */
471
+ getJobIds(): string[]
472
+
473
+ //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
474
+
475
+ /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
476
+ registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
477
+
478
+ //* Idle Callbacks (for legacy addTail) --------------------------------
479
+
480
+ /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
481
+ onIdle(callback: (timestamp: number) => void): () => void
482
+
483
+ //* Frame Loop Control --------------------------------
484
+
485
+ /** Start the scheduler loop */
486
+ start(): void
487
+ /** Stop the scheduler loop */
488
+ stop(): void
489
+ /** Check if the scheduler is running */
490
+ readonly isRunning: boolean
491
+ /** Get/set the frameloop mode ('always', 'demand', 'never') */
492
+ frameloop: Frameloop
493
+ /** Independent mode - runs without Canvas, callbacks receive timing-only state */
494
+ independent: boolean
495
+
496
+ //* Manual Stepping --------------------------------
497
+
498
+ /** Manually step all jobs once (for frameloop='never' or testing) */
499
+ step(timestamp?: number): void
500
+ /** Manually step a single job by ID */
501
+ stepJob(id: string, timestamp?: number): void
502
+ /** Request frame(s) to be rendered (for frameloop='demand') */
503
+ invalidate(frames?: number): void
504
+
505
+ //* Per-Job Control --------------------------------
506
+
507
+ /** Check if a job is paused */
508
+ isJobPaused(id: string): boolean
509
+ /** Pause a job */
510
+ pauseJob(id: string): void
511
+ /** Resume a job */
512
+ resumeJob(id: string): void
513
+ /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
514
+ subscribeJobState(id: string, listener: () => void): () => void
515
+ }
516
+
517
+ //* Buffer Types (useBuffers) ========================================
518
+
519
+ /**
520
+ * Buffer-like types for GPU compute and storage operations.
521
+ * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
522
+ *
523
+ * @example
524
+ * ```tsx
525
+ * const { positions, velocities } = useBuffers(() => ({
526
+ * positions: instancedArray(count, 'vec3'), // StorageBufferNode
527
+ * velocities: new Float32Array(count * 3), // TypedArray
528
+ * }), 'particles')
529
+ * ```
530
+ */
531
+ type BufferLike =
532
+ | Float32Array
533
+ | Uint32Array
534
+ | Int32Array
535
+ | Float64Array
536
+ | Uint8Array
537
+ | Int8Array
538
+ | Uint16Array
539
+ | Int16Array
540
+ | THREE$1.BufferAttribute // Base class for all buffer attributes
541
+ | Node // TSL buffer nodes (instancedArray, storage)
542
+
543
+ /** Flat record of buffer-like values (no nested scopes) */
544
+ type BufferRecord = Record<string, BufferLike>
545
+
546
+ /**
547
+ * Buffer store that can contain both root-level buffers and scoped buffer objects.
548
+ * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
549
+ */
550
+ type BufferStore = Record<string, BufferLike | BufferRecord>
551
+
552
+ //* Storage Types (useGPUStorage) ========================================
553
+
554
+ /**
555
+ * GPU storage types for texture-based storage operations.
556
+ * Includes Three.js storage textures and TSL storage texture nodes.
557
+ *
558
+ * @example
559
+ * ```tsx
560
+ * const { heightMap } = useGPUStorage(() => ({
561
+ * heightMap: new StorageTexture(512, 512),
562
+ * }), 'terrain')
563
+ * ```
564
+ */
565
+ type StorageLike =
566
+ | StorageTexture // GPU storage texture
567
+ | Data3DTexture // 3D texture (can be used as storage)
568
+ | Node // TSL storage texture nodes (storageTexture)
569
+
570
+ /** Flat record of storage-like values (no nested scopes) */
571
+ type StorageRecord = Record<string, StorageLike>
572
+
573
+ /**
574
+ * Storage store that can contain both root-level storage and scoped storage objects.
575
+ * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
576
+ */
577
+ type StorageStore = Record<string, StorageLike | StorageRecord>
578
+
579
+ //* Renderer Types ========================================
580
+
581
+ /** Default renderer type - union of WebGL and WebGPU renderers */
582
+ type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
583
+
584
+ //* Core Store Types ========================================
585
+
586
+ type Subscription = {
587
+ ref: React$1.RefObject<RenderCallback>
588
+ priority: number
589
+ store: RootStore
590
+ }
591
+
592
+ /** Per-pointer state for multi-touch and XR support */
593
+ type PointerState = {
594
+ /** Objects currently hovered by this pointer */
595
+ hovered: Map<string, ThreeEvent<DomEvent>>
596
+ /** Objects capturing this pointer */
597
+ captured: Map<THREE$1.Object3D, PointerCaptureTarget>
598
+ /** Initial click position [x, y] */
599
+ initialClick: [x: number, y: number]
600
+ /** Objects hit on initial click */
601
+ initialHits: THREE$1.Object3D[]
602
+ }
603
+
604
+ type Dpr = number | [min: number, max: number]
605
+
606
+ interface Size {
607
+ width: number
608
+ height: number
609
+ top: number
610
+ left: number
611
+ }
612
+
613
+ type Frameloop = 'always' | 'demand' | 'never'
614
+
615
+ interface Viewport extends Size {
616
+ /** The initial pixel ratio */
617
+ initialDpr: number
618
+ /** Current pixel ratio */
619
+ dpr: number
620
+ /** size.width / viewport.width */
621
+ factor: number
622
+ /** Camera distance */
623
+ distance: number
624
+ /** Camera aspect ratio: width / height */
625
+ aspect: number
626
+ }
627
+
628
+ type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
629
+
630
+ interface Performance {
631
+ /** Current performance normal, between min and max */
632
+ current: number
633
+ /** How low the performance can go, between 0 and max */
634
+ min: number
635
+ /** How high the performance can go, between min and max */
636
+ max: number
637
+ /** Time until current returns to max in ms */
638
+ debounce: number
639
+ /** Sets current to min, puts the system in regression */
640
+ regress: () => void
641
+ }
642
+
643
+ interface InternalState {
644
+ interaction: THREE$1.Object3D[]
645
+ subscribers: Subscription[]
646
+ /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
647
+ pointerMap: Map<number, PointerState>
648
+ /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
649
+ pointerDirty: Map<number, DomEvent>
650
+ /** Last event received (for events.update() compatibility) */
651
+ lastEvent: React$1.RefObject<DomEvent | null>
652
+ /** @deprecated Use pointerMap.get(pointerId).hovered instead */
653
+ hovered: Map<string, ThreeEvent<DomEvent>>
654
+ /** @deprecated Use pointerMap.get(pointerId).captured instead */
655
+ capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
656
+ /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
657
+ initialClick: [x: number, y: number]
658
+ /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
659
+ initialHits: THREE$1.Object3D[]
660
+ /** Visibility event registry (onFramed, onOccluded, onVisible) */
661
+ visibilityRegistry: Map<string, VisibilityEntry>
662
+ /** Whether occlusion queries are enabled (WebGPU only) */
663
+ occlusionEnabled: boolean
664
+ /** Reference to the invisible occlusion observer mesh */
665
+ occlusionObserver: THREE$1.Mesh | null
666
+ /** Cached occlusion results from render pass - keyed by Object3D */
667
+ occlusionCache: Map<THREE$1.Object3D, boolean | null>
668
+ /** Internal helper group for R3F system objects (occlusion observer, etc.) */
669
+ helperGroup: THREE$1.Group | null
670
+ active: boolean
671
+ priority: number
672
+ frames: number
673
+ subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
674
+ /** Internal renderer storage - use state.renderer or state.gl to access */
675
+ actualRenderer: R3FRenderer
676
+ /** Global scheduler reference (for useFrame hook) */
677
+ scheduler: SchedulerApi | null
678
+ /** This root's unique ID in the global scheduler */
679
+ rootId?: string
680
+ /** Function to unregister this root from the global scheduler */
681
+ unregisterRoot?: () => void
682
+ /** Container for child attachment (scene for root, original container for portals) */
683
+ container?: THREE$1.Object3D
684
+ /**
685
+ * CanvasTarget for multi-canvas WebGPU rendering.
686
+ * Created for all WebGPU canvases to support renderer sharing.
687
+ * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
688
+ */
689
+ canvasTarget?: CanvasTarget
690
+ /**
691
+ * Whether multi-canvas rendering is active.
692
+ * True when any canvas uses `target` prop to share a renderer.
693
+ * When true, setCanvasTarget is called before each render.
694
+ */
695
+ isMultiCanvas?: boolean
696
+ /**
697
+ * Whether this canvas is a secondary canvas sharing another's renderer.
698
+ * True when `target` prop is used.
699
+ */
700
+ isSecondary?: boolean
701
+ /**
702
+ * The id of the primary canvas this secondary canvas targets.
703
+ * Only set when isSecondary is true.
704
+ */
705
+ targetId?: string
706
+ /**
707
+ * Function to unregister this primary canvas from the registry.
708
+ * Only set when this canvas has an `id` prop.
709
+ */
710
+ unregisterPrimary?: () => void
711
+ /** Whether canvas dimensions are forced to even numbers */
712
+ forceEven?: boolean
713
+ }
714
+
715
+ interface XRManager {
716
+ connect: () => void
717
+ disconnect: () => void
718
+ }
719
+
720
+ //* Root State Interface ====================================
721
+
722
+ interface RootState {
723
+ /** Set current state */
724
+ set: StoreApi<RootState>['setState']
725
+ /** Get current state */
726
+ get: StoreApi<RootState>['getState']
727
+ /**
728
+ * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
729
+ * - For primary/independent canvases: points to its own store (self-reference)
730
+ * - For secondary canvases: points to the primary canvas's store
731
+ *
732
+ * Hooks like useNodes/useUniforms should read from primaryStore to ensure
733
+ * consistent shared state across all canvases sharing a renderer.
734
+ */
735
+ primaryStore: RootStore
736
+ /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
737
+ gl: THREE$1.WebGLRenderer
738
+ /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
739
+ renderer: R3FRenderer
740
+ /** Inspector of the webGPU Renderer. Init in the canvas */
741
+ inspector: any // Inspector type from three/webgpu
742
+
743
+ /** Default camera */
744
+ camera: ThreeCamera
745
+ /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
746
+ frustum: THREE$1.Frustum
747
+ /** Whether to automatically update the frustum each frame (default: true) */
748
+ autoUpdateFrustum: boolean
749
+ /** Default scene (may be overridden in portals to point to the portal container) */
750
+ scene: THREE$1.Scene
751
+ /** The actual root THREE.Scene - always points to the true scene, even inside portals */
752
+ rootScene: THREE$1.Scene
753
+ /** Default raycaster */
754
+ raycaster: THREE$1.Raycaster
755
+ /** Event layer interface, contains the event handler and the node they're connected to */
756
+ events: EventManager<any>
757
+ /** XR interface */
758
+ xr: XRManager
759
+ /** Currently used controls */
760
+ controls: THREE$1.EventDispatcher | null
761
+ /** Normalized event coordinates */
762
+ pointer: THREE$1.Vector2
763
+ /** @deprecated Normalized event coordinates, use "pointer" instead! */
764
+ mouse: THREE$1.Vector2
765
+ /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
766
+ textureColorSpace: THREE$1.ColorSpace
767
+ /** Render loop flags */
768
+ frameloop: Frameloop
769
+ performance: Performance
770
+ /** Reactive pixel-size of the canvas */
771
+ size: Size
772
+ /** Reactive size of the viewport in threejs units */
773
+ viewport: Viewport & {
774
+ getCurrentViewport: (
775
+ camera?: ThreeCamera,
776
+ target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
777
+ size?: Size,
778
+ ) => Omit<Viewport, 'dpr' | 'initialDpr'>
779
+ }
780
+ /** Flags the canvas for render, but doesn't render in itself */
781
+ invalidate: (frames?: number, stackFrames?: boolean) => void
782
+ /** Advance (render) one step */
783
+ advance: (timestamp: number, runGlobalEffects?: boolean) => void
784
+ /** Shortcut to setting the event layer */
785
+ setEvents: (events: Partial<EventManager<any>>) => void
786
+ /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
787
+ setSize: (width?: number, height?: number, top?: number, left?: number) => void
788
+ /** Shortcut to manual setting the pixel ratio */
789
+ setDpr: (dpr: Dpr) => void
790
+ /** Shortcut to setting frameloop flags */
791
+ setFrameloop: (frameloop: Frameloop) => void
792
+ /** Set error state to propagate to error boundary */
793
+ setError: (error: Error | null) => void
794
+ /** Current error state (null when no error) */
795
+ error: Error | null
796
+ /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
797
+ uniforms: UniformStore
798
+ /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
799
+ nodes: Record<string, any>
800
+ /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
801
+ buffers: BufferStore
802
+ /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
803
+ gpuStorage: StorageStore
804
+ /** Global TSL texture nodes - use useTextures() hook for operations */
805
+ textures: Map<string, any>
806
+ /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
807
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
808
+ /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
809
+ passes: Record<string, any>
810
+ /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
811
+ _hmrVersion: number
812
+ /** Internal: whether setSize() has taken ownership of canvas dimensions */
813
+ _sizeImperative: boolean
814
+ /** Internal: stored size props from Canvas for reset functionality */
815
+ _sizeProps: { width?: number; height?: number } | null
816
+ /** When the canvas was clicked but nothing was hit */
817
+ onPointerMissed?: (event: MouseEvent) => void
818
+ /** When a dragover event has missed any target */
819
+ onDragOverMissed?: (event: DragEvent) => void
820
+ /** When a drop event has missed any target */
821
+ onDropMissed?: (event: DragEvent) => void
822
+ /** If this state model is layered (via createPortal) then this contains the previous layer */
823
+ previousRoot?: RootStore
824
+ /** Internals */
825
+ internal: InternalState
826
+ // flags for triggers
827
+ // if we are using the webGl renderer, this will be true
828
+ isLegacy: boolean
829
+ // regardless of renderer, if the system supports webGpu, this will be true
830
+ webGPUSupported: boolean
831
+ //if we are on native
832
+ isNative: boolean
833
+ }
834
+
662
835
  type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>
663
836
 
664
- //* Base Renderer Types =====================================
665
-
666
- // Shim for OffscreenCanvas since it was removed from DOM types
667
- interface OffscreenCanvas$1 extends EventTarget {}
668
-
669
- interface BaseRendererProps {
670
- canvas: HTMLCanvasElement | OffscreenCanvas$1
671
- powerPreference?: 'high-performance' | 'low-power' | 'default'
672
- antialias?: boolean
673
- alpha?: boolean
674
- }
675
-
676
- type RendererFactory<TRenderer, TParams> =
677
- | TRenderer
678
- | ((defaultProps: TParams) => TRenderer)
679
- | ((defaultProps: TParams) => Promise<TRenderer>)
680
-
681
- interface Renderer {
682
- render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
683
- }
684
-
685
- //* WebGL Renderer Props ==============================
686
-
687
- type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
688
- canvas: HTMLCanvasElement | OffscreenCanvas$1
689
- }
690
-
691
- type GLProps =
692
- | Renderer
693
- | ((defaultProps: DefaultGLProps) => Renderer)
694
- | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
695
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
696
-
697
- //* WebGPU Renderer Props ==============================
698
-
699
- type DefaultRendererProps = {
700
- canvas: HTMLCanvasElement | OffscreenCanvas$1
701
- [key: string]: any
702
- }
703
-
704
- type RendererProps =
705
- | any // WebGPURenderer
706
- | ((defaultProps: DefaultRendererProps) => any)
707
- | ((defaultProps: DefaultRendererProps) => Promise<any>)
708
- | Partial<Properties<any> | Record<string, any>>
709
-
710
- //* Camera Props ==============================
711
-
712
- type CameraProps = (
713
- | THREE$1.Camera
714
- | Partial<
715
- ThreeElement<typeof THREE$1.Camera> &
716
- ThreeElement<typeof THREE$1.PerspectiveCamera> &
717
- ThreeElement<typeof THREE$1.OrthographicCamera>
718
- >
719
- ) & {
720
- /** Flags the camera as manual, putting projection into your own hands */
721
- manual?: boolean
722
- }
723
-
724
- //* Render Props ==============================
725
-
726
- interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
727
- /** A threejs renderer instance or props that go into the default renderer */
728
- gl?: GLProps
729
- /** A WebGPU renderer instance or props that go into the default renderer */
730
- renderer?: RendererProps
731
- /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
732
- size?: Size
733
- /**
734
- * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
735
- * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
736
- * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
737
- */
738
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
739
- /**
740
- * Disables three r139 color management.
741
- * @see https://threejs.org/docs/#manual/en/introduction/Color-management
742
- */
743
- legacy?: boolean
744
- /** Switch off automatic sRGB encoding and gamma correction */
745
- linear?: boolean
746
- /** Use `THREE.NoToneMapping` instead of `THREE.ACESFilmicToneMapping` */
747
- flat?: boolean
748
- /** Working color space for automatic texture colorspace assignment. Defaults to THREE.SRGBColorSpace */
749
- /** Color space assigned to 8-bit input textures (color maps). Defaults to sRGB. Most textures are authored in sRGB. */
750
- textureColorSpace?: THREE$1.ColorSpace
751
- /** Creates an orthographic camera */
752
- orthographic?: boolean
753
- /**
754
- * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
755
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
756
- */
757
- frameloop?: Frameloop
758
- /**
759
- * R3F performance options for adaptive performance.
760
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
761
- */
762
- performance?: Partial<Omit<Performance, 'regress'>>
763
- /** Target pixel ratio. Can clamp between a range: `[min, max]` */
764
- dpr?: Dpr
765
- /** Props that go into the default raycaster */
766
- raycaster?: Partial<THREE$1.Raycaster>
767
- /** A `THREE.Scene` instance or props that go into the default scene */
768
- scene?: THREE$1.Scene | Partial<THREE$1.Scene>
769
- /** A `THREE.Camera` instance or props that go into the default camera */
770
- camera?: CameraProps
771
- /** An R3F event manager to manage elements' pointer events */
772
- events?: (store: RootStore) => EventManager<HTMLElement>
773
- /** Callback after the canvas has rendered (but not yet committed) */
774
- onCreated?: (state: RootState) => void
775
- /** Response for pointer clicks that have missed any target */
776
- onPointerMissed?: (event: MouseEvent) => void
777
- /** Response for dragover events that have missed any target */
778
- onDragOverMissed?: (event: DragEvent) => void
779
- /** Response for drop events that have missed any target */
780
- onDropMissed?: (event: DragEvent) => void
781
- /** Whether to automatically update the frustum each frame (default: true) */
782
- autoUpdateFrustum?: boolean
783
- /**
784
- * Enable WebGPU occlusion queries for onOccluded/onVisible events.
785
- * Auto-enabled when any object uses onOccluded or onVisible handlers.
786
- * Only works with WebGPU renderer - WebGL will log a warning.
787
- */
788
- occlusion?: boolean
789
- /** Internal: stored size props from Canvas for reset functionality */
790
- _sizeProps?: { width?: number; height?: number } | null
791
- }
792
-
793
- //* Reconciler Root ==============================
794
-
795
- interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
796
- configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
797
- render: (element: ReactNode) => RootStore
798
- unmount: () => void
799
- }
800
-
801
- //* Inject State ==============================
802
-
803
- type InjectState = Partial<
804
- Omit<RootState, 'events'> & {
805
- events?: {
806
- enabled?: boolean
807
- priority?: number
808
- compute?: ComputeFunction
809
- connected?: any
810
- }
811
- /**
812
- * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
813
- * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
814
- * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
815
- */
816
- injectScene?: boolean
817
- }
837
+ //* Base Renderer Types =====================================
838
+
839
+ // Shim for OffscreenCanvas since it was removed from DOM types
840
+ interface OffscreenCanvas$1 extends EventTarget {}
841
+
842
+ interface BaseRendererProps {
843
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
844
+ powerPreference?: 'high-performance' | 'low-power' | 'default'
845
+ antialias?: boolean
846
+ alpha?: boolean
847
+ }
848
+
849
+ type RendererFactory<TRenderer, TParams> =
850
+ | TRenderer
851
+ | ((defaultProps: TParams) => TRenderer)
852
+ | ((defaultProps: TParams) => Promise<TRenderer>)
853
+
854
+ interface Renderer {
855
+ render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
856
+ }
857
+
858
+ //* Color Management Config ==============================
859
+
860
+ /**
861
+ * Color management configuration shared by both WebGL and WebGPU renderers.
862
+ */
863
+ interface ColorManagementConfig {
864
+ /**
865
+ * Color space assigned to 8-bit input textures (color maps).
866
+ * Defaults to sRGB. Most textures are authored in sRGB.
867
+ * @default THREE.SRGBColorSpace
868
+ */
869
+ textureColorSpace?: THREE$1.ColorSpace
870
+ }
871
+
872
+ //* WebGL Renderer Props ==============================
873
+
874
+ type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
875
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
876
+ }
877
+
878
+ type GLProps =
879
+ | Renderer
880
+ | ((defaultProps: DefaultGLProps) => Renderer)
881
+ | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
882
+ | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
883
+
884
+ //* WebGPU Renderer Props ==============================
885
+
886
+ type DefaultRendererProps = {
887
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
888
+ [key: string]: any
889
+ }
890
+
891
+ /**
892
+ * Canvas-level scheduler configuration.
893
+ * Controls render timing relative to other canvases.
894
+ */
895
+ interface CanvasSchedulerConfig {
896
+ /**
897
+ * Render this canvas after another canvas completes.
898
+ * Pass the `id` of another canvas.
899
+ */
900
+ after?: string
901
+ /**
902
+ * Limit this canvas's render rate (frames per second).
903
+ */
904
+ fps?: number
905
+ }
906
+
907
+ /**
908
+ * Extended renderer configuration for multi-canvas support and color management.
909
+ */
910
+ interface RendererConfigExtended extends ColorManagementConfig {
911
+ /** Share renderer from another canvas (WebGPU only) */
912
+ primaryCanvas?: string
913
+ /** Canvas-level scheduler options */
914
+ scheduler?: CanvasSchedulerConfig
915
+ }
916
+
917
+ type RendererProps =
918
+ | any // WebGPURenderer
919
+ | ((defaultProps: DefaultRendererProps) => any)
920
+ | ((defaultProps: DefaultRendererProps) => Promise<any>)
921
+ | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
922
+
923
+ //* Camera Props ==============================
924
+
925
+ type CameraProps = (
926
+ | THREE$1.Camera
927
+ | Partial<
928
+ ThreeElement<typeof THREE$1.Camera> &
929
+ ThreeElement<typeof THREE$1.PerspectiveCamera> &
930
+ ThreeElement<typeof THREE$1.OrthographicCamera>
931
+ >
932
+ ) & {
933
+ /** Flags the camera as manual, putting projection into your own hands */
934
+ manual?: boolean
935
+ }
936
+
937
+ //* Render Props ==============================
938
+
939
+ interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
940
+ /**
941
+ * Unique identifier for multi-canvas renderer sharing.
942
+ * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
943
+ * Also sets the HTML `id` attribute on the canvas element.
944
+ * @example <Canvas id="main-viewer">...</Canvas>
945
+ */
946
+ id?: string
947
+ /**
948
+ * Share the renderer from another canvas instead of creating a new one.
949
+ * Pass the `id` of the primary canvas to share its WebGPURenderer.
950
+ * Only available with WebGPU (not legacy WebGL).
951
+ *
952
+ * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
953
+ * @internal
954
+ */
955
+ primaryCanvas?: string
956
+ /**
957
+ * Canvas-level scheduler options. Controls render timing relative to other canvases.
958
+ *
959
+ * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
960
+ * @internal
961
+ */
962
+ scheduler?: CanvasSchedulerConfig
963
+ /** A threejs renderer instance or props that go into the default renderer */
964
+ gl?: GLProps
965
+ /** A WebGPU renderer instance or props that go into the default renderer */
966
+ renderer?: RendererProps
967
+ /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
968
+ size?: Size
969
+ /**
970
+ * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
971
+ * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
972
+ * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
973
+ */
974
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
975
+ /** Creates an orthographic camera */
976
+ orthographic?: boolean
977
+ /**
978
+ * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
979
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
980
+ */
981
+ frameloop?: Frameloop
982
+ /**
983
+ * R3F performance options for adaptive performance.
984
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
985
+ */
986
+ performance?: Partial<Omit<Performance, 'regress'>>
987
+ /** Target pixel ratio. Can clamp between a range: `[min, max]` */
988
+ dpr?: Dpr
989
+ /** Props that go into the default raycaster */
990
+ raycaster?: Partial<THREE$1.Raycaster>
991
+ /** A `THREE.Scene` instance or props that go into the default scene */
992
+ scene?: THREE$1.Scene | Partial<THREE$1.Scene>
993
+ /** A `THREE.Camera` instance or props that go into the default camera */
994
+ camera?: CameraProps
995
+ /** An R3F event manager to manage elements' pointer events */
996
+ events?: (store: RootStore) => EventManager<HTMLElement>
997
+ /** Callback after the canvas has rendered (but not yet committed) */
998
+ onCreated?: (state: RootState) => void
999
+ /** Response for pointer clicks that have missed any target */
1000
+ onPointerMissed?: (event: MouseEvent) => void
1001
+ /** Response for dragover events that have missed any target */
1002
+ onDragOverMissed?: (event: DragEvent) => void
1003
+ /** Response for drop events that have missed any target */
1004
+ onDropMissed?: (event: DragEvent) => void
1005
+ /** Whether to automatically update the frustum each frame (default: true) */
1006
+ autoUpdateFrustum?: boolean
1007
+ /**
1008
+ * Enable WebGPU occlusion queries for onOccluded/onVisible events.
1009
+ * Auto-enabled when any object uses onOccluded or onVisible handlers.
1010
+ * Only works with WebGPU renderer - WebGL will log a warning.
1011
+ */
1012
+ occlusion?: boolean
1013
+ /** Internal: stored size props from Canvas for reset functionality */
1014
+ _sizeProps?: { width?: number; height?: number } | null
1015
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1016
+ forceEven?: boolean
1017
+ }
1018
+
1019
+ //* Reconciler Root ==============================
1020
+
1021
+ interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
1022
+ configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
1023
+ render: (element: ReactNode) => RootStore
1024
+ unmount: () => void
1025
+ }
1026
+
1027
+ //* Inject State ==============================
1028
+
1029
+ type InjectState = Partial<
1030
+ Omit<RootState, 'events'> & {
1031
+ events?: {
1032
+ enabled?: boolean
1033
+ priority?: number
1034
+ compute?: ComputeFunction
1035
+ connected?: any
1036
+ }
1037
+ /**
1038
+ * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
1039
+ * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
1040
+ * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
1041
+ */
1042
+ injectScene?: boolean
1043
+ }
818
1044
  >
819
1045
 
820
- //* Reconciler Types ==============================
821
-
822
- // FiberRoot is an opaque internal React type - we define it locally
823
- // to avoid bundling @types/react-reconciler which causes absolute path issues
824
- type FiberRoot = any
825
-
826
- interface Root {
827
- fiber: FiberRoot
828
- store: RootStore
829
- }
830
-
831
- type AttachFnType<O = any> = (parent: any, self: O) => () => void
832
- type AttachType<O = any> = string | AttachFnType<O>
833
-
834
- type ConstructorRepresentation<T = any> = new (...args: any[]) => T
835
-
836
- interface Catalogue {
837
- [name: string]: ConstructorRepresentation
838
- }
839
-
840
- // TODO: handle constructor overloads
841
- // https://github.com/pmndrs/react-three-fiber/pull/2931
842
- // https://github.com/microsoft/TypeScript/issues/37079
843
- type Args<T> = T extends ConstructorRepresentation
844
- ? T extends typeof Color$1
845
- ? [r: number, g: number, b: number] | [color: ColorRepresentation]
846
- : ConstructorParameters<T>
847
- : any[]
848
-
849
- type ArgsProp<P> = P extends ConstructorRepresentation
850
- ? IsAllOptional<ConstructorParameters<P>> extends true
851
- ? { args?: Args<P> }
852
- : { args: Args<P> }
853
- : { args: unknown[] }
854
-
855
- type InstanceProps<T = any, P = any> = ArgsProp<P> & {
856
- object?: T
857
- dispose?: null
858
- attach?: AttachType<T>
859
- onUpdate?: (self: T) => void
860
- }
861
-
862
- interface Instance<O = any> {
863
- root: RootStore
864
- type: string
865
- parent: Instance | null
866
- children: Instance[]
867
- props: InstanceProps<O> & Record<string, unknown>
868
- object: O & { __r3f?: Instance<O> }
869
- eventCount: number
870
- handlers: Partial<EventHandlers>
871
- attach?: AttachType<O>
872
- previousAttach?: any
873
- isHidden: boolean
874
- }
875
-
876
- interface HostConfig {
877
- type: string
878
- props: Instance['props']
879
- container: RootStore
880
- instance: Instance
881
- textInstance: void
882
- suspenseInstance: Instance
883
- hydratableInstance: never
884
- formInstance: never
885
- publicInstance: Instance['object']
886
- hostContext: {}
887
- childSet: never
888
- timeoutHandle: number | undefined
889
- noTimeout: -1
890
- TransitionStatus: null
891
- }
892
- declare global {
893
- var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
894
- }
895
-
896
- //* Loop Types ==============================
897
-
898
- type GlobalRenderCallback = (timestamp: number) => void
899
-
1046
+ //* Reconciler Types ==============================
1047
+
1048
+ // FiberRoot is an opaque internal React type - we define it locally
1049
+ // to avoid bundling @types/react-reconciler which causes absolute path issues
1050
+ type FiberRoot = any
1051
+
1052
+ interface Root {
1053
+ fiber: FiberRoot
1054
+ store: RootStore
1055
+ }
1056
+
1057
+ type AttachFnType<O = any> = (parent: any, self: O) => () => void
1058
+ type AttachType<O = any> = string | AttachFnType<O>
1059
+
1060
+ type ConstructorRepresentation<T = any> = new (...args: any[]) => T
1061
+
1062
+ interface Catalogue {
1063
+ [name: string]: ConstructorRepresentation
1064
+ }
1065
+
1066
+ // TODO: handle constructor overloads
1067
+ // https://github.com/pmndrs/react-three-fiber/pull/2931
1068
+ // https://github.com/microsoft/TypeScript/issues/37079
1069
+ type Args<T> = T extends ConstructorRepresentation
1070
+ ? T extends typeof Color$1
1071
+ ? [r: number, g: number, b: number] | [color: ColorRepresentation]
1072
+ : ConstructorParameters<T>
1073
+ : any[]
1074
+
1075
+ type ArgsProp<P> = P extends ConstructorRepresentation
1076
+ ? IsAllOptional<ConstructorParameters<P>> extends true
1077
+ ? { args?: Args<P> }
1078
+ : { args: Args<P> }
1079
+ : { args: unknown[] }
1080
+
1081
+ type InstanceProps<T = any, P = any> = ArgsProp<P> & {
1082
+ object?: T
1083
+ dispose?: null
1084
+ attach?: AttachType<T>
1085
+ onUpdate?: (self: T) => void
1086
+ }
1087
+
1088
+ interface Instance<O = any> {
1089
+ root: RootStore
1090
+ type: string
1091
+ parent: Instance | null
1092
+ children: Instance[]
1093
+ props: InstanceProps<O> & Record<string, unknown>
1094
+ object: O & { __r3f?: Instance<O> }
1095
+ eventCount: number
1096
+ handlers: Partial<EventHandlers>
1097
+ attach?: AttachType<O>
1098
+ previousAttach?: any
1099
+ isHidden: boolean
1100
+ /** Deferred ref props to apply in commitMount */
1101
+ deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1102
+ /** Set of props that have been applied via once() */
1103
+ appliedOnce?: Set<string>
1104
+ }
1105
+
1106
+ interface HostConfig {
1107
+ type: string
1108
+ props: Instance['props']
1109
+ container: RootStore
1110
+ instance: Instance
1111
+ textInstance: void
1112
+ suspenseInstance: Instance
1113
+ hydratableInstance: never
1114
+ formInstance: never
1115
+ publicInstance: Instance['object']
1116
+ hostContext: {}
1117
+ childSet: never
1118
+ timeoutHandle: number | undefined
1119
+ noTimeout: -1
1120
+ TransitionStatus: null
1121
+ }
1122
+ declare global {
1123
+ var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
1124
+ }
1125
+
1126
+ //* Loop Types ==============================
1127
+
1128
+ type GlobalRenderCallback = (timestamp: number) => void
1129
+
900
1130
  type GlobalEffectType = 'before' | 'after' | 'tail'
901
1131
 
902
- //* Canvas Types ==============================
903
-
904
- interface CanvasProps
905
- extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React$1.HTMLAttributes<HTMLDivElement> {
906
- children?: React$1.ReactNode
907
- ref?: React$1.Ref<HTMLCanvasElement>
908
- /** Canvas fallback content, similar to img's alt prop */
909
- fallback?: React$1.ReactNode
910
- /**
911
- * Options to pass to useMeasure.
912
- * @see https://github.com/pmndrs/react-use-measure#api
913
- */
914
- resize?: Options
915
- /** The target where events are being subscribed to, default: the div that wraps canvas */
916
- eventSource?: HTMLElement | React$1.RefObject<HTMLElement>
917
- /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
918
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
919
- /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
920
- hmr?: boolean
921
- /** Canvas resolution width in pixels. If omitted, uses container width. */
922
- width?: number
923
- /** Canvas resolution height in pixels. If omitted, uses container height. */
924
- height?: number
925
- }
926
-
927
- //* Loader Types ==============================
928
-
929
- type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
930
-
931
- // Define a loader-like interface that matches THREE.Loader's load signature
932
- // This works for both generic and non-generic THREE.Loader instances
933
- interface LoaderLike {
934
- load(
935
- url: InputLike,
936
- onLoad?: (result: any) => void,
937
- onProgress?: (event: ProgressEvent<EventTarget>) => void,
938
- onError?: (error: unknown) => void,
939
- ): any
940
- }
941
-
942
- type GLTFLike = { scene: THREE$1.Object3D }
943
-
944
- type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
945
- T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
946
-
947
- // Infer result type from the load method's callback parameter
948
- type InferLoadResult<T> = T extends {
949
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
950
- }
951
- ? R
952
- : T extends ConstructorRepresentation<any>
953
- ? InstanceType<T> extends {
954
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
955
- }
956
- ? R
957
- : any
958
- : any
959
-
960
- type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
961
- InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
962
-
963
- type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
964
- loader: LoaderInstance<T>,
1132
+ declare const presetsObj: {
1133
+ apartment: string;
1134
+ city: string;
1135
+ dawn: string;
1136
+ forest: string;
1137
+ lobby: string;
1138
+ night: string;
1139
+ park: string;
1140
+ studio: string;
1141
+ sunset: string;
1142
+ warehouse: string;
1143
+ };
1144
+ type PresetsType = keyof typeof presetsObj;
1145
+
1146
+ //* Background Types ==============================
1147
+
1148
+ /**
1149
+ * Expanded object form for background configuration.
1150
+ * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
1151
+ */
1152
+ interface BackgroundConfig {
1153
+ /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
1154
+ preset?: PresetsType
1155
+ /** Files for cube texture (6 faces) or single HDR/EXR */
1156
+ files?: string | string[]
1157
+ /** Separate files for scene.background (visual backdrop) */
1158
+ backgroundMap?: string | string[]
1159
+ backgroundRotation?: Euler$1 | [number, number, number]
1160
+ backgroundBlurriness?: number
1161
+ backgroundIntensity?: number
1162
+ /** Separate files for scene.environment (PBR lighting/reflections) */
1163
+ envMap?: string | string[]
1164
+ environmentRotation?: Euler$1 | [number, number, number]
1165
+ environmentIntensity?: number
1166
+ path?: string
1167
+ extensions?: (loader: Loader) => void
1168
+ }
1169
+
1170
+ /**
1171
+ * Background prop type for Canvas.
1172
+ *
1173
+ * String detection priority:
1174
+ * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1175
+ * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
1176
+ * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
1177
+ *
1178
+ * @example Color
1179
+ * ```tsx
1180
+ * <Canvas background="red" />
1181
+ * <Canvas background="#ff0000" />
1182
+ * <Canvas background={0xff0000} />
1183
+ * ```
1184
+ *
1185
+ * @example Preset
1186
+ * ```tsx
1187
+ * <Canvas background="city" />
1188
+ * ```
1189
+ *
1190
+ * @example URL
1191
+ * ```tsx
1192
+ * <Canvas background="/path/to/env.hdr" />
1193
+ * <Canvas background="./sky.jpg" />
1194
+ * ```
1195
+ *
1196
+ * @example Object form
1197
+ * ```tsx
1198
+ * <Canvas background={{
1199
+ * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1200
+ * backgroundMap: 'path/to/sky.jpg',
1201
+ * envMap: 'path/to/lighting.hdr',
1202
+ * backgroundBlurriness: 0.5,
1203
+ * }} />
1204
+ * ```
1205
+ */
1206
+ type BackgroundProp =
1207
+ | ColorRepresentation // "red", "#ff0000", 0xff0000
1208
+ | string // URL or preset
1209
+ | BackgroundConfig // Expanded object form
1210
+
1211
+ //* Canvas Types ==============================
1212
+
1213
+ interface CanvasProps
1214
+ extends
1215
+ Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1216
+ React$1.HTMLAttributes<HTMLDivElement> {
1217
+ children?: React$1.ReactNode
1218
+ ref?: React$1.Ref<HTMLCanvasElement>
1219
+ /** Canvas fallback content, similar to img's alt prop */
1220
+ fallback?: React$1.ReactNode
1221
+ /**
1222
+ * Options to pass to useMeasure.
1223
+ * @see https://github.com/pmndrs/react-use-measure#api
1224
+ */
1225
+ resize?: Options
1226
+ /** The target where events are being subscribed to, default: the div that wraps canvas */
1227
+ eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1228
+ /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1229
+ eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1230
+ /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1231
+ hmr?: boolean
1232
+ /** Canvas resolution width in pixels. If omitted, uses container width. */
1233
+ width?: number
1234
+ /** Canvas resolution height in pixels. If omitted, uses container height. */
1235
+ height?: number
1236
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1237
+ forceEven?: boolean
1238
+ /**
1239
+ * Scene background configuration.
1240
+ * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1241
+ * @see BackgroundProp for full documentation and examples
1242
+ */
1243
+ background?: BackgroundProp
1244
+ }
1245
+
1246
+ //* Loader Types ==============================
1247
+
1248
+ type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1249
+
1250
+ // Define a loader-like interface that matches THREE.Loader's load signature
1251
+ // This works for both generic and non-generic THREE.Loader instances
1252
+ interface LoaderLike {
1253
+ load(
1254
+ url: InputLike,
1255
+ onLoad?: (result: any) => void,
1256
+ onProgress?: (event: ProgressEvent<EventTarget>) => void,
1257
+ onError?: (error: unknown) => void,
1258
+ ): any
1259
+ }
1260
+
1261
+ type GLTFLike = { scene: THREE$1.Object3D }
1262
+
1263
+ type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1264
+ T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1265
+
1266
+ // Infer result type from the load method's callback parameter
1267
+ type InferLoadResult<T> = T extends {
1268
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1269
+ }
1270
+ ? R
1271
+ : T extends ConstructorRepresentation<any>
1272
+ ? InstanceType<T> extends {
1273
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1274
+ }
1275
+ ? R
1276
+ : any
1277
+ : any
1278
+
1279
+ type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1280
+ InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1281
+
1282
+ type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1283
+ loader: LoaderInstance<T>,
965
1284
  ) => void
966
1285
 
967
- type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
968
-
969
- type WebGLProps =
970
- | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
971
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
972
-
973
- interface WebGLShadowConfig {
974
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1286
+ //* Renderer Props ========================================
1287
+
1288
+ type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1289
+
1290
+ type WebGLProps =
1291
+ | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1292
+ | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1293
+
1294
+ interface WebGLShadowConfig {
1295
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1296
+ }
1297
+
1298
+ //* Legacy-specific Types ========================================
1299
+
1300
+ /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1301
+ type LegacyRenderer = THREE$1.WebGLRenderer
1302
+
1303
+ /** Legacy internal state with narrowed renderer type */
1304
+ interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1305
+ actualRenderer: THREE$1.WebGLRenderer
975
1306
  }
976
1307
 
977
- //* RenderTarget Types ==============================
978
-
979
-
1308
+ /**
1309
+ * Legacy-specific RootState with narrowed renderer type.
1310
+ * Automatically used when importing from `@react-three/fiber/legacy`.
1311
+ *
1312
+ * @example
1313
+ * ```tsx
1314
+ * import { useThree } from '@react-three/fiber/legacy'
1315
+ *
1316
+ * function MyComponent() {
1317
+ * const { renderer } = useThree()
1318
+ * // renderer is typed as THREE.WebGLRenderer
1319
+ * renderer.shadowMap.enabled = true
1320
+ * }
1321
+ * ```
1322
+ */
1323
+ interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1324
+ /** The WebGL renderer instance */
1325
+ renderer: THREE$1.WebGLRenderer
1326
+ /** Internals with WebGL renderer */
1327
+ internal: LegacyInternalState
1328
+ }
1329
+
1330
+ //* RenderTarget Types ==============================
1331
+
1332
+
980
1333
  type RenderTargetOptions = RenderTargetOptions$1
981
1334
 
982
- //* Global Types ==============================
983
-
984
- declare global {
985
- /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
986
- interface UniformNode<T = unknown> extends Node {
987
- value: T
988
- }
989
-
990
- /** Flat record of uniform nodes (no nested scopes) */
991
- type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
992
-
993
- /**
994
- * Uniform store that can contain both root-level uniforms and scoped uniform objects
995
- * Used by state.uniforms which has structure like:
996
- * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
997
- */
998
- type UniformStore = Record<string, UniformNode | UniformRecord>
999
-
1000
- /**
1001
- * Helper to safely access a uniform node from the store.
1002
- * Use this when accessing state.uniforms to get proper typing.
1003
- * @example
1004
- * const uTime = uniforms.uTime as UniformNode<number>
1005
- * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1006
- */
1007
- type GetUniform<T = unknown> = UniformNode<T>
1008
-
1009
- /**
1010
- * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1011
- * Supports: primitives, Three.js types, plain objects (converted to vectors), and UniformNodes
1012
- */
1013
- type UniformValue =
1014
- | number
1015
- | string
1016
- | boolean
1017
- | three_webgpu.Color
1018
- | three_webgpu.Vector2
1019
- | three_webgpu.Vector3
1020
- | three_webgpu.Vector4
1021
- | three_webgpu.Matrix3
1022
- | three_webgpu.Matrix4
1023
- | three_webgpu.Euler
1024
- | three_webgpu.Quaternion
1025
- | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1026
- | UniformNode
1027
-
1028
- /** Input record for useUniforms - accepts raw values or UniformNodes */
1029
- type UniformInputRecord = Record<string, UniformValue>
1030
- }
1031
-
1032
- //* Fn Return Type ==============================
1033
-
1034
- /** The return type of Fn() - a callable shader function node */
1035
- type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1036
-
1037
- //* Module Augmentation ==============================
1038
-
1039
- declare module 'three/tsl' {
1040
- /**
1041
- * Fn with array parameter destructuring
1042
- * @example Fn(([uv, skew]) => { ... })
1043
- */
1044
- export function Fn<R extends Node = Node>(
1045
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1046
- ): ShaderCallable<R>
1047
-
1048
- /**
1049
- * Fn with object parameter destructuring
1050
- * @example Fn(({ color, intensity }) => { ... })
1051
- */
1052
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1053
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1054
- ): ShaderCallable<R>
1055
-
1056
- /**
1057
- * Fn with array params + layout
1058
- * @example Fn(([a, b]) => { ... }, { layout: [...] })
1059
- */
1060
- export function Fn<R extends Node = Node>(
1061
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1062
- layout: { layout?: unknown },
1063
- ): ShaderCallable<R>
1064
-
1065
- /**
1066
- * Fn with object params + layout
1067
- */
1068
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1069
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1070
- layout: { layout?: unknown },
1071
- ): ShaderCallable<R>
1072
- }
1073
-
1074
- /**
1075
- * PostProcessing Types for usePostProcessing hook (WebGPU only)
1076
- */
1077
-
1078
-
1079
-
1080
- declare global {
1081
- /** Pass record - stores TSL pass nodes for post-processing */
1082
- type PassRecord = Record<string, any>
1083
-
1084
- /** Setup callback - runs first to configure MRT, create additional passes */
1085
- type PostProcessingSetupCallback = (state: RootState) => PassRecord | void
1086
-
1087
- /** Main callback - runs second to configure outputNode, create effect passes */
1088
- type PostProcessingMainCallback = (state: RootState) => PassRecord | void
1089
-
1090
- /** Return type for usePostProcessing hook */
1091
- interface UsePostProcessingReturn {
1092
- /** Current passes from state */
1093
- passes: PassRecord
1094
- /** PostProcessing instance (null if not initialized) */
1095
- postProcessing: any | null // THREE.PostProcessing
1096
- /** Clear all passes from state */
1097
- clearPasses: () => void
1098
- /** Reset PostProcessing entirely (clears PP + passes) */
1099
- reset: () => void
1100
- /** Re-run setup/main callbacks with current closure values */
1101
- rebuild: () => void
1102
- /** True when PostProcessing is configured and ready */
1103
- isReady: boolean
1104
- }
1105
- }
1106
-
1107
- //* useFrameNext Types ==============================
1108
-
1109
-
1110
-
1111
- //* Global Type Declarations ==============================
1112
-
1113
- declare global {
1114
- // Job --------------------------------
1115
-
1116
- /**
1117
- * Internal job representation in the scheduler
1118
- */
1119
- interface Job {
1120
- /** Unique identifier */
1121
- id: string
1122
- /** The callback to execute */
1123
- callback: FrameNextCallback
1124
- /** Phase this job belongs to */
1125
- phase: string
1126
- /** Run before these phases/job ids */
1127
- before: Set<string>
1128
- /** Run after these phases/job ids */
1129
- after: Set<string>
1130
- /** Priority within phase (higher first) */
1131
- priority: number
1132
- /** Insertion order for deterministic tie-breaking */
1133
- index: number
1134
- /** Max FPS for this job (undefined = no limit) */
1135
- fps?: number
1136
- /** Drop frames when behind (true) or catch up (false) */
1137
- drop: boolean
1138
- /** Last run timestamp (ms) */
1139
- lastRun?: number
1140
- /** Whether job is enabled */
1141
- enabled: boolean
1142
- /** Internal flag: system jobs (like default render) don't block user render takeover */
1143
- system?: boolean
1144
- }
1145
-
1146
- // Phase Graph --------------------------------
1147
-
1148
- /**
1149
- * A node in the phase graph
1150
- */
1151
- interface PhaseNode {
1152
- /** Phase name */
1153
- name: string
1154
- /** Whether this was auto-generated from a before/after constraint */
1155
- isAutoGenerated: boolean
1156
- }
1157
-
1158
- /**
1159
- * Options for creating a job from hook options
1160
- */
1161
- interface JobOptions {
1162
- id?: string
1163
- phase?: string
1164
- before?: string | string[]
1165
- after?: string | string[]
1166
- priority?: number
1167
- fps?: number
1168
- drop?: boolean
1169
- enabled?: boolean
1170
- }
1171
-
1172
- // Frame Loop State --------------------------------
1173
-
1174
- /**
1175
- * Internal frame loop state
1176
- */
1177
- interface FrameLoopState {
1178
- /** Whether the loop is running */
1179
- running: boolean
1180
- /** Current RAF handle */
1181
- rafHandle: number | null
1182
- /** Last frame timestamp in ms (null = uninitialized) */
1183
- lastTime: number | null
1184
- /** Frame counter */
1185
- frameCount: number
1186
- /** Elapsed time since first frame in ms */
1187
- elapsedTime: number
1188
- /** createdAt timestamp in ms */
1189
- createdAt: number
1190
- }
1191
-
1192
- // Root Entry --------------------------------
1193
-
1194
- /**
1195
- * Internal representation of a registered root (Canvas).
1196
- * Tracks jobs and manages rebuild state for this root.
1197
- * @internal
1198
- */
1199
- interface RootEntry {
1200
- /** Unique identifier for this root */
1201
- id: string
1202
- /** Function to get the root's current state. Returns any to support independent mode. */
1203
- getState: () => any
1204
- /** Map of job IDs to Job objects */
1205
- jobs: Map<string, Job>
1206
- /** Cached sorted job list for execution order */
1207
- sortedJobs: Job[]
1208
- /** Whether sortedJobs needs rebuilding */
1209
- needsRebuild: boolean
1210
- }
1211
-
1212
- /**
1213
- * Internal representation of a global job (deprecated API).
1214
- * Global jobs run once per frame, not per-root.
1215
- * Used by legacy addEffect/addAfterEffect APIs.
1216
- * @internal
1217
- * @deprecated Use useFrame with phases instead
1218
- */
1219
- interface GlobalJob {
1220
- /** Unique identifier for this global job */
1221
- id: string
1222
- /** Callback invoked with RAF timestamp in ms */
1223
- callback: (timestamp: number) => void
1224
- }
1225
-
1226
- // HMR Support --------------------------------
1227
-
1228
- /**
1229
- * Hot Module Replacement data structure for preserving scheduler state
1230
- * @internal
1231
- */
1232
- interface HMRData {
1233
- /** Shared data object for storing values across reloads */
1234
- data: Record<string, any>
1235
- /** Optional function to accept HMR updates */
1236
- accept?: () => void
1237
- }
1238
-
1239
- // Default Phases --------------------------------
1240
-
1241
- /**
1242
- * Default phase names for the scheduler
1243
- */
1244
- type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1245
- }
1246
-
1247
- type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1248
-
1249
- interface MathRepresentation {
1250
- set(...args: number[]): any
1251
- }
1252
- interface VectorRepresentation extends MathRepresentation {
1253
- setScalar(value: number): any
1254
- }
1255
- type MathTypes = MathRepresentation | Euler$1 | Color$2
1256
-
1257
- type MathType<T extends MathTypes> = T extends Color$2
1258
- ? Args<typeof Color$2> | ColorRepresentation$1
1259
- : T extends VectorRepresentation | Layers$1 | Euler$1
1260
- ? T | MutableOrReadonlyParameters<T['set']> | number
1261
- : T | MutableOrReadonlyParameters<T['set']>
1262
-
1263
- type MathProps<P> = {
1264
- [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1265
- }
1266
-
1267
- type Vector2 = MathType<Vector2$1>
1268
- type Vector3 = MathType<Vector3$1>
1269
- type Vector4 = MathType<Vector4$1>
1270
- type Color = MathType<Color$2>
1271
- type Layers = MathType<Layers$1>
1272
- type Quaternion = MathType<Quaternion$1>
1273
- type Euler = MathType<Euler$1>
1274
- type Matrix3 = MathType<Matrix3$1>
1275
- type Matrix4 = MathType<Matrix4$1>
1276
-
1277
- interface RaycastableRepresentation {
1278
- raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1279
- }
1280
- type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1281
-
1282
- interface ReactProps<P> {
1283
- children?: React.ReactNode
1284
- ref?: React.Ref<P>
1285
- key?: React.Key
1286
- }
1287
-
1288
- type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1289
- Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P>>
1290
- >
1291
-
1292
- type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1293
- Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1294
- >
1295
-
1296
- type ThreeToJSXElements<T extends Record<string, any>> = {
1297
- [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1298
- }
1299
-
1300
- type ThreeExports = typeof THREE
1301
- type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1302
-
1303
- interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1304
- primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1305
- // Conflicts with DOM types can be accessed through a three* prefix
1306
- threeAudio: ThreeElementsImpl['audio']
1307
- threeSource: ThreeElementsImpl['source']
1308
- threeLine: ThreeElementsImpl['line']
1309
- threePath: ThreeElementsImpl['path']
1310
- }
1311
-
1312
- declare module 'react' {
1313
- namespace JSX {
1314
- interface IntrinsicElements extends ThreeElements {}
1315
- }
1316
- }
1317
-
1318
- declare module 'react/jsx-runtime' {
1319
- namespace JSX {
1320
- interface IntrinsicElements extends ThreeElements {}
1321
- }
1322
- }
1323
-
1324
- declare module 'react/jsx-dev-runtime' {
1325
- namespace JSX {
1326
- interface IntrinsicElements extends ThreeElements {}
1327
- }
1335
+ //* Global Types ==============================
1336
+
1337
+ declare global {
1338
+ /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1339
+ interface UniformNode<T = unknown> extends Node {
1340
+ value: T
1341
+ }
1342
+
1343
+ /**
1344
+ * ShaderCallable - the return type of Fn()
1345
+ * A callable shader function node that can be invoked with parameters.
1346
+ * The function returns a ShaderNodeObject when called.
1347
+ *
1348
+ * @example
1349
+ * ```tsx
1350
+ * // Define a shader function
1351
+ * const blendColorFn = Fn(([color1, color2, factor]) => {
1352
+ * return mix(color1, color2, factor)
1353
+ * })
1354
+ *
1355
+ * // Type when retrieving from nodes store
1356
+ * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1357
+ *
1358
+ * // Or with specific return type
1359
+ * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1360
+ * ```
1361
+ */
1362
+ type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1363
+
1364
+ /**
1365
+ * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1366
+ * This is the common return type for TSL operations (add, mul, sin, etc.)
1367
+ *
1368
+ * @example
1369
+ * ```tsx
1370
+ * const { wobble } = nodes as { wobble: ShaderNodeRef }
1371
+ * ```
1372
+ */
1373
+ type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1374
+
1375
+ /**
1376
+ * TSLNodeType - Union of all common TSL node types
1377
+ * Used by ScopedStore to properly type node access from the store.
1378
+ *
1379
+ * Includes:
1380
+ * - Node: base Three.js node type
1381
+ * - ShaderCallable: function nodes created with Fn()
1382
+ * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1383
+ *
1384
+ * @example
1385
+ * ```tsx
1386
+ * // In useLocalNodes, nodes are typed as TSLNodeType
1387
+ * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1388
+ * positionNode: nodes.myPosition, // Works - Node is in union
1389
+ * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1390
+ * }))
1391
+ *
1392
+ * // Can narrow with type guard or assertion when needed
1393
+ * if (typeof blendColorFn === 'function') {
1394
+ * blendColorFn(someColor, 0.5)
1395
+ * }
1396
+ * ```
1397
+ */
1398
+ type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1399
+
1400
+ /** Flat record of uniform nodes (no nested scopes) */
1401
+ type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1402
+
1403
+ /**
1404
+ * Uniform store that can contain both root-level uniforms and scoped uniform objects
1405
+ * Used by state.uniforms which has structure like:
1406
+ * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1407
+ */
1408
+ type UniformStore = Record<string, UniformNode | UniformRecord>
1409
+
1410
+ /**
1411
+ * Helper to safely access a uniform node from the store.
1412
+ * Use this when accessing state.uniforms to get proper typing.
1413
+ * @example
1414
+ * const uTime = uniforms.uTime as UniformNode<number>
1415
+ * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1416
+ */
1417
+ type GetUniform<T = unknown> = UniformNode<T>
1418
+
1419
+ /**
1420
+ * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1421
+ * Supports:
1422
+ * - Primitives: number, string (color), boolean
1423
+ * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1424
+ * - Plain objects: { x, y, z, w } converted to vectors
1425
+ * - TSL nodes: color(), vec3(), float() for type casting
1426
+ * - UniformNode: existing uniforms (reused as-is)
1427
+ */
1428
+ type UniformValue =
1429
+ | number
1430
+ | string
1431
+ | boolean
1432
+ | three_webgpu.Color
1433
+ | three_webgpu.Vector2
1434
+ | three_webgpu.Vector3
1435
+ | three_webgpu.Vector4
1436
+ | three_webgpu.Matrix3
1437
+ | three_webgpu.Matrix4
1438
+ | three_webgpu.Euler
1439
+ | three_webgpu.Quaternion
1440
+ | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1441
+ | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1442
+ | Node // TSL nodes like color(), vec3(), float() for type casting
1443
+ | UniformNode
1444
+
1445
+ /** Input record for useUniforms - accepts raw values or UniformNodes */
1446
+ type UniformInputRecord = Record<string, UniformValue>
1447
+ }
1448
+
1449
+ //* Module Augmentation ==============================
1450
+
1451
+ declare module 'three/tsl' {
1452
+ /**
1453
+ * Fn with array parameter destructuring
1454
+ * @example Fn(([uv, skew]) => { ... })
1455
+ */
1456
+ export function Fn<R extends Node = Node>(
1457
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1458
+ ): ShaderCallable<R>
1459
+
1460
+ /**
1461
+ * Fn with object parameter destructuring
1462
+ * @example Fn(({ color, intensity }) => { ... })
1463
+ */
1464
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1465
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1466
+ ): ShaderCallable<R>
1467
+
1468
+ /**
1469
+ * Fn with array params + layout
1470
+ * @example Fn(([a, b]) => { ... }, { layout: [...] })
1471
+ */
1472
+ export function Fn<R extends Node = Node>(
1473
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1474
+ layout: { layout?: unknown },
1475
+ ): ShaderCallable<R>
1476
+
1477
+ /**
1478
+ * Fn with object params + layout
1479
+ */
1480
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1481
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1482
+ layout: { layout?: unknown },
1483
+ ): ShaderCallable<R>
1484
+ }
1485
+
1486
+ /**
1487
+ * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1488
+ */
1489
+
1490
+
1491
+
1492
+ declare global {
1493
+ /** Pass record - stores TSL pass nodes for render pipeline */
1494
+ type PassRecord = Record<string, any>
1495
+
1496
+ /** Setup callback - runs first to configure MRT, create additional passes */
1497
+ type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1498
+
1499
+ /** Main callback - runs second to configure outputNode, create effect passes */
1500
+ type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1501
+
1502
+ /** Return type for useRenderPipeline hook */
1503
+ interface UseRenderPipelineReturn {
1504
+ /** Current passes from state */
1505
+ passes: PassRecord
1506
+ /** RenderPipeline instance (null if not initialized) */
1507
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1508
+ /** Clear all passes from state */
1509
+ clearPasses: () => void
1510
+ /** Reset RenderPipeline entirely (clears PP + passes) */
1511
+ reset: () => void
1512
+ /** Re-run setup/main callbacks with current closure values */
1513
+ rebuild: () => void
1514
+ /** True when RenderPipeline is configured and ready */
1515
+ isReady: boolean
1516
+ }
1517
+ }
1518
+
1519
+ //* useFrameNext Types ==============================
1520
+
1521
+
1522
+
1523
+ //* Global Type Declarations ==============================
1524
+
1525
+ declare global {
1526
+ // Job --------------------------------
1527
+
1528
+ /**
1529
+ * Internal job representation in the scheduler
1530
+ */
1531
+ interface Job {
1532
+ /** Unique identifier */
1533
+ id: string
1534
+ /** The callback to execute */
1535
+ callback: FrameNextCallback
1536
+ /** Phase this job belongs to */
1537
+ phase: string
1538
+ /** Run before these phases/job ids */
1539
+ before: Set<string>
1540
+ /** Run after these phases/job ids */
1541
+ after: Set<string>
1542
+ /** Priority within phase (higher first) */
1543
+ priority: number
1544
+ /** Insertion order for deterministic tie-breaking */
1545
+ index: number
1546
+ /** Max FPS for this job (undefined = no limit) */
1547
+ fps?: number
1548
+ /** Drop frames when behind (true) or catch up (false) */
1549
+ drop: boolean
1550
+ /** Last run timestamp (ms) */
1551
+ lastRun?: number
1552
+ /** Whether job is enabled */
1553
+ enabled: boolean
1554
+ /** Internal flag: system jobs (like default render) don't block user render takeover */
1555
+ system?: boolean
1556
+ }
1557
+
1558
+ // Phase Graph --------------------------------
1559
+
1560
+ /**
1561
+ * A node in the phase graph
1562
+ */
1563
+ interface PhaseNode {
1564
+ /** Phase name */
1565
+ name: string
1566
+ /** Whether this was auto-generated from a before/after constraint */
1567
+ isAutoGenerated: boolean
1568
+ }
1569
+
1570
+ /**
1571
+ * Options for creating a job from hook options
1572
+ */
1573
+ interface JobOptions {
1574
+ id?: string
1575
+ phase?: string
1576
+ before?: string | string[]
1577
+ after?: string | string[]
1578
+ priority?: number
1579
+ fps?: number
1580
+ drop?: boolean
1581
+ enabled?: boolean
1582
+ }
1583
+
1584
+ // Frame Loop State --------------------------------
1585
+
1586
+ /**
1587
+ * Internal frame loop state
1588
+ */
1589
+ interface FrameLoopState {
1590
+ /** Whether the loop is running */
1591
+ running: boolean
1592
+ /** Current RAF handle */
1593
+ rafHandle: number | null
1594
+ /** Last frame timestamp in ms (null = uninitialized) */
1595
+ lastTime: number | null
1596
+ /** Frame counter */
1597
+ frameCount: number
1598
+ /** Elapsed time since first frame in ms */
1599
+ elapsedTime: number
1600
+ /** createdAt timestamp in ms */
1601
+ createdAt: number
1602
+ }
1603
+
1604
+ // Root Entry --------------------------------
1605
+
1606
+ /**
1607
+ * Internal representation of a registered root (Canvas).
1608
+ * Tracks jobs and manages rebuild state for this root.
1609
+ * @internal
1610
+ */
1611
+ interface RootEntry {
1612
+ /** Unique identifier for this root */
1613
+ id: string
1614
+ /** Function to get the root's current state. Returns any to support independent mode. */
1615
+ getState: () => any
1616
+ /** Map of job IDs to Job objects */
1617
+ jobs: Map<string, Job>
1618
+ /** Cached sorted job list for execution order */
1619
+ sortedJobs: Job[]
1620
+ /** Whether sortedJobs needs rebuilding */
1621
+ needsRebuild: boolean
1622
+ }
1623
+
1624
+ /**
1625
+ * Internal representation of a global job (deprecated API).
1626
+ * Global jobs run once per frame, not per-root.
1627
+ * Used by legacy addEffect/addAfterEffect APIs.
1628
+ * @internal
1629
+ * @deprecated Use useFrame with phases instead
1630
+ */
1631
+ interface GlobalJob {
1632
+ /** Unique identifier for this global job */
1633
+ id: string
1634
+ /** Callback invoked with RAF timestamp in ms */
1635
+ callback: (timestamp: number) => void
1636
+ }
1637
+
1638
+ // HMR Support --------------------------------
1639
+
1640
+ /**
1641
+ * Hot Module Replacement data structure for preserving scheduler state
1642
+ * @internal
1643
+ */
1644
+ interface HMRData {
1645
+ /** Shared data object for storing values across reloads */
1646
+ data: Record<string, any>
1647
+ /** Optional function to accept HMR updates */
1648
+ accept?: () => void
1649
+ }
1650
+
1651
+ // Default Phases --------------------------------
1652
+
1653
+ /**
1654
+ * Default phase names for the scheduler
1655
+ */
1656
+ type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1657
+ }
1658
+
1659
+ type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1660
+
1661
+ interface MathRepresentation {
1662
+ set(...args: number[]): any
1663
+ }
1664
+ interface VectorRepresentation extends MathRepresentation {
1665
+ setScalar(value: number): any
1666
+ }
1667
+ type MathTypes = MathRepresentation | Euler$2 | Color$2
1668
+
1669
+ type MathType<T extends MathTypes> = T extends Color$2
1670
+ ? Args<typeof Color$2> | ColorRepresentation$1
1671
+ : T extends VectorRepresentation | Layers$1 | Euler$2
1672
+ ? T | MutableOrReadonlyParameters<T['set']> | number
1673
+ : T | MutableOrReadonlyParameters<T['set']>
1674
+
1675
+ type MathProps<P> = {
1676
+ [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1677
+ }
1678
+
1679
+ type Vector2 = MathType<Vector2$1>
1680
+ type Vector3 = MathType<Vector3$1>
1681
+ type Vector4 = MathType<Vector4$1>
1682
+ type Color = MathType<Color$2>
1683
+ type Layers = MathType<Layers$1>
1684
+ type Quaternion = MathType<Quaternion$1>
1685
+ type Euler = MathType<Euler$2>
1686
+ type Matrix3 = MathType<Matrix3$1>
1687
+ type Matrix4 = MathType<Matrix4$1>
1688
+
1689
+ interface RaycastableRepresentation {
1690
+ raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1691
+ }
1692
+ type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1693
+
1694
+ /**
1695
+ * Props for geometry transform methods that can be called with `once()`.
1696
+ * These methods modify the geometry in-place and only make sense to call once on mount.
1697
+ *
1698
+ * @example
1699
+ * import { once } from '@react-three/fiber'
1700
+ *
1701
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1702
+ * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1703
+ * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1704
+ */
1705
+ interface GeometryTransformProps {
1706
+ /** Rotate the geometry about the X axis (radians). Use with once(). */
1707
+ rotateX?: number
1708
+ /** Rotate the geometry about the Y axis (radians). Use with once(). */
1709
+ rotateY?: number
1710
+ /** Rotate the geometry about the Z axis (radians). Use with once(). */
1711
+ rotateZ?: number
1712
+ /** Translate the geometry (x, y, z). Use with once(). */
1713
+ translate?: [x: number, y: number, z: number]
1714
+ /** Scale the geometry (x, y, z). Use with once(). */
1715
+ scale?: [x: number, y: number, z: number]
1716
+ /** Center the geometry based on bounding box. Use with once(). */
1717
+ center?: true
1718
+ /** Apply a Matrix4 transformation. Use with once(). */
1719
+ applyMatrix4?: Matrix4$1
1720
+ /** Apply a Quaternion rotation. Use with once(). */
1721
+ applyQuaternion?: Quaternion$1
1722
+ }
1723
+
1724
+ type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1725
+
1726
+ /**
1727
+ * Workaround for @types/three TSL node type issues.
1728
+ * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1729
+ * This transforms `Node | null` properties to accept any object with node-like shape.
1730
+ */
1731
+ type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1732
+
1733
+ /**
1734
+ * For node material properties (colorNode, positionNode, etc.), accept broader types
1735
+ * since @types/three has broken inheritance for TSL node subclasses.
1736
+ */
1737
+ type NodeProps<P> = {
1738
+ [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1739
+ }
1740
+
1741
+ interface ReactProps<P> {
1742
+ children?: React.ReactNode
1743
+ ref?: React.Ref<P>
1744
+ key?: React.Key
1745
+ }
1746
+
1747
+ type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1748
+ Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1749
+ >
1750
+
1751
+ type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1752
+ Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1753
+ >
1754
+
1755
+ type ThreeToJSXElements<T extends Record<string, any>> = {
1756
+ [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1757
+ }
1758
+
1759
+ type ThreeExports = typeof THREE
1760
+ type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1761
+
1762
+ interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1763
+ primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1764
+ // Conflicts with DOM types can be accessed through a three* prefix
1765
+ threeAudio: ThreeElementsImpl['audio']
1766
+ threeSource: ThreeElementsImpl['source']
1767
+ threeLine: ThreeElementsImpl['line']
1768
+ threePath: ThreeElementsImpl['path']
1769
+ }
1770
+
1771
+ declare module 'react' {
1772
+ namespace JSX {
1773
+ interface IntrinsicElements extends ThreeElements {}
1774
+ }
1775
+ }
1776
+
1777
+ declare module 'react/jsx-runtime' {
1778
+ namespace JSX {
1779
+ interface IntrinsicElements extends ThreeElements {}
1780
+ }
1781
+ }
1782
+
1783
+ declare module 'react/jsx-dev-runtime' {
1784
+ namespace JSX {
1785
+ interface IntrinsicElements extends ThreeElements {}
1786
+ }
1328
1787
  }
1329
1788
 
1330
1789
  type three_d_Color = Color;
1331
1790
  type three_d_ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = ElementProps<T, P>;
1332
1791
  type three_d_Euler = Euler;
1333
1792
  type three_d_EventProps<P> = EventProps<P>;
1793
+ type three_d_GeometryProps<P> = GeometryProps<P>;
1794
+ type three_d_GeometryTransformProps = GeometryTransformProps;
1334
1795
  type three_d_Layers = Layers;
1335
1796
  type three_d_MathProps<P> = MathProps<P>;
1336
1797
  type three_d_MathRepresentation = MathRepresentation;
@@ -1339,9 +1800,11 @@ type three_d_MathTypes = MathTypes;
1339
1800
  type three_d_Matrix3 = Matrix3;
1340
1801
  type three_d_Matrix4 = Matrix4;
1341
1802
  type three_d_MutableOrReadonlyParameters<T extends (...args: any) => any> = MutableOrReadonlyParameters<T>;
1803
+ type three_d_NodeProps<P> = NodeProps<P>;
1342
1804
  type three_d_Quaternion = Quaternion;
1343
1805
  type three_d_RaycastableRepresentation = RaycastableRepresentation;
1344
1806
  type three_d_ReactProps<P> = ReactProps<P>;
1807
+ type three_d_TSLNodeInput = TSLNodeInput;
1345
1808
  type three_d_ThreeElement<T extends ConstructorRepresentation> = ThreeElement<T>;
1346
1809
  type three_d_ThreeElements = ThreeElements;
1347
1810
  type three_d_ThreeElementsImpl = ThreeElementsImpl;
@@ -1352,12 +1815,324 @@ type three_d_Vector3 = Vector3;
1352
1815
  type three_d_Vector4 = Vector4;
1353
1816
  type three_d_VectorRepresentation = VectorRepresentation;
1354
1817
  declare namespace three_d {
1355
- export type { three_d_Color as Color, three_d_ElementProps as ElementProps, three_d_Euler as Euler, three_d_EventProps as EventProps, three_d_Layers as Layers, three_d_MathProps as MathProps, three_d_MathRepresentation as MathRepresentation, three_d_MathType as MathType, three_d_MathTypes as MathTypes, three_d_Matrix3 as Matrix3, three_d_Matrix4 as Matrix4, three_d_MutableOrReadonlyParameters as MutableOrReadonlyParameters, three_d_Quaternion as Quaternion, three_d_RaycastableRepresentation as RaycastableRepresentation, three_d_ReactProps as ReactProps, three_d_ThreeElement as ThreeElement, three_d_ThreeElements as ThreeElements, three_d_ThreeElementsImpl as ThreeElementsImpl, three_d_ThreeExports as ThreeExports, three_d_ThreeToJSXElements as ThreeToJSXElements, three_d_Vector2 as Vector2, three_d_Vector3 as Vector3, three_d_Vector4 as Vector4, three_d_VectorRepresentation as VectorRepresentation };
1818
+ export type { three_d_Color as Color, three_d_ElementProps as ElementProps, three_d_Euler as Euler, three_d_EventProps as EventProps, three_d_GeometryProps as GeometryProps, three_d_GeometryTransformProps as GeometryTransformProps, three_d_Layers as Layers, three_d_MathProps as MathProps, three_d_MathRepresentation as MathRepresentation, three_d_MathType as MathType, three_d_MathTypes as MathTypes, three_d_Matrix3 as Matrix3, three_d_Matrix4 as Matrix4, three_d_MutableOrReadonlyParameters as MutableOrReadonlyParameters, three_d_NodeProps as NodeProps, three_d_Quaternion as Quaternion, three_d_RaycastableRepresentation as RaycastableRepresentation, three_d_ReactProps as ReactProps, three_d_TSLNodeInput as TSLNodeInput, three_d_ThreeElement as ThreeElement, three_d_ThreeElements as ThreeElements, three_d_ThreeElementsImpl as ThreeElementsImpl, three_d_ThreeExports as ThreeExports, three_d_ThreeToJSXElements as ThreeToJSXElements, three_d_Vector2 as Vector2, three_d_Vector3 as Vector3, three_d_Vector4 as Vector4, three_d_VectorRepresentation as VectorRepresentation };
1819
+ }
1820
+
1821
+ /**
1822
+ * @fileoverview Registry for primary canvases that can be targeted by secondary canvases
1823
+ *
1824
+ * Enables multi-canvas WebGPU rendering where multiple Canvas components share
1825
+ * a single WebGPURenderer using Three.js CanvasTarget API.
1826
+ *
1827
+ * Primary canvas: Has `id` prop, creates its own renderer, registers here
1828
+ * Secondary canvas: Has `target="id"` prop, shares primary's renderer via CanvasTarget
1829
+ */
1830
+
1831
+ interface PrimaryCanvasEntry {
1832
+ /** The WebGPURenderer instance owned by this primary canvas */
1833
+ renderer: WebGPURenderer;
1834
+ /** The zustand store for this canvas */
1835
+ store: RootStore;
1836
+ }
1837
+ /**
1838
+ * Register a primary canvas that can be targeted by secondary canvases.
1839
+ *
1840
+ * @param id - Unique identifier for this primary canvas
1841
+ * @param renderer - The WebGPURenderer owned by this canvas
1842
+ * @param store - The zustand store for this canvas
1843
+ * @returns Cleanup function to unregister on unmount
1844
+ */
1845
+ declare function registerPrimary(id: string, renderer: WebGPURenderer, store: RootStore): () => void;
1846
+ /**
1847
+ * Get a registered primary canvas by id.
1848
+ *
1849
+ * @param id - The id of the primary canvas to look up
1850
+ * @returns The primary canvas entry or undefined if not found
1851
+ */
1852
+ declare function getPrimary(id: string): PrimaryCanvasEntry | undefined;
1853
+ /**
1854
+ * Wait for a primary canvas to be registered.
1855
+ * Returns immediately if already registered, otherwise waits.
1856
+ *
1857
+ * @param id - The id of the primary canvas to wait for
1858
+ * @param timeout - Optional timeout in ms (default: 5000)
1859
+ * @returns Promise that resolves with the primary canvas entry
1860
+ */
1861
+ declare function waitForPrimary(id: string, timeout?: number): Promise<PrimaryCanvasEntry>;
1862
+ /**
1863
+ * Check if a primary canvas with the given id exists.
1864
+ *
1865
+ * @param id - The id to check
1866
+ * @returns True if a primary canvas with this id is registered
1867
+ */
1868
+ declare function hasPrimary(id: string): boolean;
1869
+ /**
1870
+ * Unregister a primary canvas. Called on unmount.
1871
+ *
1872
+ * @param id - The id of the primary canvas to unregister
1873
+ */
1874
+ declare function unregisterPrimary(id: string): void;
1875
+ /**
1876
+ * Get all registered primary canvas ids. Useful for debugging.
1877
+ */
1878
+ declare function getPrimaryIds(): string[];
1879
+
1880
+ type EnvironmentLoaderProps = {
1881
+ files?: string | string[];
1882
+ path?: string;
1883
+ preset?: PresetsType;
1884
+ extensions?: (loader: Loader$1) => void;
1885
+ colorSpace?: ColorSpace;
1886
+ };
1887
+ /**
1888
+ * Loads environment textures for reflections and lighting.
1889
+ * Supports HDR files, presets, and cubemaps.
1890
+ *
1891
+ * @example Basic usage
1892
+ * ```jsx
1893
+ * const texture = useEnvironment({ preset: 'sunset' })
1894
+ * ```
1895
+ */
1896
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown> | CubeTexture;
1897
+ declare namespace useEnvironment {
1898
+ var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1899
+ var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
1356
1900
  }
1901
+ type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'encoding'>;
1902
+ type EnvironmentLoaderClearOptions = Pick<EnvironmentLoaderProps, 'files' | 'preset'>;
1903
+
1904
+ /**
1905
+ * Props for Environment component that sets up global cubemap for PBR materials and backgrounds.
1906
+ *
1907
+ * @property children - React children to render into custom environment portal
1908
+ * @property frames - Number of frames to render the environment. Use 1 for static, Infinity for animated (default: 1)
1909
+ * @property near - Near clipping plane for cube camera (default: 0.1)
1910
+ * @property far - Far clipping plane for cube camera (default: 1000)
1911
+ * @property resolution - Resolution of the cube render target (default: 256)
1912
+ * @property background - Whether to set scene.background. Can be true, false, or "only" (which only sets background) (default: false)
1913
+ *
1914
+ * @property blur - @deprecated Use backgroundBlurriness instead
1915
+ * @property backgroundBlurriness - Blur factor between 0 and 1 for background (default: 0, requires three.js 0.146+)
1916
+ * @property backgroundIntensity - Intensity factor for background (default: 1, requires three.js 0.163+)
1917
+ * @property backgroundRotation - Rotation for background as Euler angles (default: [0,0,0], requires three.js 0.163+)
1918
+ * @property environmentIntensity - Intensity factor for environment lighting (default: 1, requires three.js 0.163+)
1919
+ * @property environmentRotation - Rotation for environment as Euler angles (default: [0,0,0], requires three.js 0.163+)
1920
+ *
1921
+ * @property map - Pre-existing texture to use as environment map
1922
+ * @property preset - HDRI Haven preset: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse'. Not for production use.
1923
+ * @property scene - Custom THREE.Scene or ref to apply environment to (default: uses default scene)
1924
+ * @property ground - Ground projection settings. Use true for defaults or object with:
1925
+ * - height: Height of camera used to create env map (default: 15)
1926
+ * - radius: Radius of the world (default: 60)
1927
+ * - scale: Scale of backside projected sphere (default: 1000)
1928
+ *
1929
+ * Additional loader props:
1930
+ * @property files - File path(s) for environment. Supports .hdr, .exr, gainmap .jpg/.webp, or array of 6 cube faces
1931
+ * @property path - Base path for file loading
1932
+ * @property extensions - Texture extensions override
1933
+ */
1934
+ type EnvironmentProps = {
1935
+ children?: React$1.ReactNode;
1936
+ frames?: number;
1937
+ near?: number;
1938
+ far?: number;
1939
+ resolution?: number;
1940
+ background?: boolean | 'only';
1941
+ /** deprecated, use backgroundBlurriness */
1942
+ blur?: number;
1943
+ backgroundBlurriness?: number;
1944
+ backgroundIntensity?: number;
1945
+ backgroundRotation?: Euler$3;
1946
+ environmentIntensity?: number;
1947
+ environmentRotation?: Euler$3;
1948
+ map?: Texture$1;
1949
+ preset?: PresetsType;
1950
+ scene?: Scene | React$1.RefObject<Scene>;
1951
+ ground?: boolean | {
1952
+ radius?: number;
1953
+ height?: number;
1954
+ scale?: number;
1955
+ };
1956
+ /** Solid color for background (alternative to files/preset) */
1957
+ color?: ColorRepresentation$1;
1958
+ /** Separate files for background (when different from environment files) */
1959
+ backgroundFiles?: string | string[];
1960
+ } & EnvironmentLoaderProps;
1961
+ /**
1962
+ * Internal component that applies a pre-existing texture as environment map.
1963
+ * Sets scene.environment and optionally scene.background.
1964
+ *
1965
+ * @example
1966
+ * ```jsx
1967
+ * <CubeCamera>{(texture) => <EnvironmentMap map={texture} />}</CubeCamera>
1968
+ * ```
1969
+ */
1970
+ declare function EnvironmentMap({ scene, background, map, ...config }: EnvironmentProps): null;
1971
+ /**
1972
+ * Internal component that loads environment textures from files or presets.
1973
+ * Uses HDRLoader for .hdr, EXRLoader for .exr, UltraHDRLoader for .jpg/.jpeg HDR,
1974
+ * GainMapLoader for gainmap .webp, or CubeTextureLoader for arrays of images.
1975
+ *
1976
+ * @example With preset
1977
+ * ```jsx
1978
+ * <EnvironmentCube preset="sunset" />
1979
+ * ```
1980
+ *
1981
+ * @example From HDR file
1982
+ * ```jsx
1983
+ * <EnvironmentCube files="environment.hdr" />
1984
+ * ```
1985
+ *
1986
+ * @example From gainmap (smallest footprint)
1987
+ * ```jsx
1988
+ * <EnvironmentCube files={['file.webp', 'file-gainmap.webp', 'file.json']} />
1989
+ * ```
1990
+ *
1991
+ * @example From cube faces
1992
+ * ```jsx
1993
+ * <EnvironmentCube files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']} />
1994
+ * ```
1995
+ */
1996
+ declare function EnvironmentCube({ background, scene, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, ...rest }: EnvironmentProps): null;
1997
+ /**
1998
+ * Internal component that renders custom environment using a portal and cube camera.
1999
+ * Renders children into an off-buffer and films with a cube camera to create environment map.
2000
+ * Can be static (frames=1) or animated (frames=Infinity).
2001
+ *
2002
+ * @example Custom environment with sphere
2003
+ * ```jsx
2004
+ * <EnvironmentPortal background near={1} far={1000} resolution={256}>
2005
+ * <mesh scale={100}>
2006
+ * <sphereGeometry args={[1, 64, 64]} />
2007
+ * <meshBasicMaterial map={texture} side={THREE.BackSide} />
2008
+ * </mesh>
2009
+ * </EnvironmentPortal>
2010
+ * ```
2011
+ *
2012
+ * @example Animated environment
2013
+ * ```jsx
2014
+ * <EnvironmentPortal frames={Infinity} resolution={256}>
2015
+ * <Float>
2016
+ * <mesh />
2017
+ * </Float>
2018
+ * </EnvironmentPortal>
2019
+ * ```
2020
+ *
2021
+ * @example Mixed with preset
2022
+ * ```jsx
2023
+ * <EnvironmentPortal preset="warehouse">
2024
+ * <mesh />
2025
+ * </EnvironmentPortal>
2026
+ * ```
2027
+ */
2028
+ declare function EnvironmentPortal({ children, near, far, resolution, frames, map, background, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, scene, files, path, preset, extensions, }: EnvironmentProps): react_jsx_runtime.JSX.Element;
2029
+ declare module '@react-three/fiber' {
2030
+ interface ThreeElements {
2031
+ groundProjectedEnvImpl: ThreeElement$1<typeof GroundedSkybox>;
2032
+ }
2033
+ }
2034
+ /**
2035
+ * Sets up a global environment map for PBR materials and backgrounds.
2036
+ * Affects scene.environment and optionally scene.background unless a custom scene is passed.
2037
+ *
2038
+ * Supports multiple input methods:
2039
+ * - **Presets**: Selection of HDRI Haven assets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
2040
+ * - **Files**: HDR (.hdr), EXR (.exr), gainmap JPEG (.jpg), gainmap WebP (.webp), or cube faces (array of 6 images)
2041
+ * - **Texture**: Pre-existing cube texture via `map` prop
2042
+ * - **Custom Scene**: Render children into environment using portal and cube camera
2043
+ * - **Ground Projection**: Project environment onto ground plane
2044
+ *
2045
+ * @remarks
2046
+ * - Preset property is NOT meant for production and may fail (relies on CDNs)
2047
+ * - Gainmap format has the smallest file footprint
2048
+ * - Use `frames={Infinity}` for animated environments with low resolution for performance
2049
+ * - Ground projection places models on the "ground" within the environment map
2050
+ * - Supports self-hosting with @pmndrs/assets using dynamic imports
2051
+ *
2052
+ * @example Basic preset usage
2053
+ * ```jsx
2054
+ * <Environment preset="sunset" />
2055
+ * ```
2056
+ *
2057
+ * @example From HDR file
2058
+ * ```jsx
2059
+ * <Environment files="/hdr/environment.hdr" />
2060
+ * ```
2061
+ *
2062
+ * @example From gainmap (smallest footprint)
2063
+ * ```jsx
2064
+ * <Environment files={['file.webp', 'file-gainmap.webp', 'file.json']} />
2065
+ * ```
2066
+ *
2067
+ * @example With self-hosted assets
2068
+ * ```jsx
2069
+ * import { suspend } from 'suspend-react'
2070
+ * const city = import('@pmndrs/assets/hdri/city.exr').then(m => m.default)
2071
+ *
2072
+ * <Environment files={suspend(city)} />
2073
+ * ```
2074
+ *
2075
+ * @example From existing texture
2076
+ * ```jsx
2077
+ * <CubeCamera>{(texture) => <Environment map={texture} />}</CubeCamera>
2078
+ * ```
2079
+ *
2080
+ * @example Custom environment scene
2081
+ * ```jsx
2082
+ * <Environment background near={1} far={1000} resolution={256}>
2083
+ * <mesh scale={100}>
2084
+ * <sphereGeometry args={[1, 64, 64]} />
2085
+ * <meshBasicMaterial map={texture} side={THREE.BackSide} />
2086
+ * </mesh>
2087
+ * </Environment>
2088
+ * ```
2089
+ *
2090
+ * @example Animated environment
2091
+ * ```jsx
2092
+ * <Environment frames={Infinity} resolution={256}>
2093
+ * <Float>
2094
+ * <mesh />
2095
+ * </Float>
2096
+ * </Environment>
2097
+ * ```
2098
+ *
2099
+ * @example Mixed custom scene with preset
2100
+ * ```jsx
2101
+ * <Environment background preset="warehouse">
2102
+ * <mesh />
2103
+ * </Environment>
2104
+ * ```
2105
+ *
2106
+ * @example With ground projection
2107
+ * ```jsx
2108
+ * <Environment ground={{ height: 15, radius: 60 }} preset="city" />
2109
+ * ```
2110
+ *
2111
+ * @example As background only
2112
+ * ```jsx
2113
+ * <Environment background="only" preset="sunset" />
2114
+ * ```
2115
+ *
2116
+ * @example With rotation and intensity
2117
+ * ```jsx
2118
+ * <Environment
2119
+ * background
2120
+ * backgroundBlurriness={0.5}
2121
+ * backgroundIntensity={0.8}
2122
+ * backgroundRotation={[0, Math.PI / 2, 0]}
2123
+ * environmentIntensity={1.2}
2124
+ * environmentRotation={[0, Math.PI / 4, 0]}
2125
+ * preset="studio"
2126
+ * />
2127
+ * ```
2128
+ */
2129
+ declare function Environment(props: EnvironmentProps): react_jsx_runtime.JSX.Element;
1357
2130
 
1358
2131
  declare function removeInteractivity(store: RootStore, object: Object3D): void;
1359
2132
  declare function createEvents(store: RootStore): {
1360
2133
  handlePointer: (name: string) => (event: DomEvent) => void;
2134
+ flushDeferredPointers: () => void;
2135
+ processDeferredPointer: (event: DomEvent, pointerId: number) => void;
1361
2136
  };
1362
2137
  /** Default R3F event manager for web */
1363
2138
  declare function createPointerEvents(store: RootStore): EventManager<HTMLElement>;
@@ -1916,31 +2691,30 @@ declare function useTextures(): UseTexturesReturn;
1916
2691
  * - WebGPU build: Returns RenderTarget
1917
2692
  * - Default build: Returns whichever matches the active renderer
1918
2693
  *
1919
- * @param width - Target width (defaults to canvas width)
1920
- * @param height - Target height (defaults to canvas height)
1921
- * @param options - Three.js RenderTarget options
1922
- *
1923
2694
  * @example
1924
2695
  * ```tsx
1925
- * function PortalScene() {
1926
- * const fbo = useRenderTarget(512, 512, { depthBuffer: true })
1927
- *
1928
- * useFrame(({ renderer, scene, camera }) => {
1929
- * renderer.setRenderTarget(fbo)
1930
- * renderer.render(scene, camera)
1931
- * renderer.setRenderTarget(null)
1932
- * })
1933
- *
1934
- * return (
1935
- * <mesh>
1936
- * <planeGeometry />
1937
- * <meshBasicMaterial map={fbo.texture} />
1938
- * </mesh>
1939
- * )
1940
- * }
2696
+ * // Use canvas size
2697
+ * const fbo = useRenderTarget()
2698
+ *
2699
+ * // Use canvas size with options
2700
+ * const fbo = useRenderTarget({ samples: 4 })
2701
+ *
2702
+ * // Square render target
2703
+ * const fbo = useRenderTarget(512)
2704
+ *
2705
+ * // Square render target with options
2706
+ * const fbo = useRenderTarget(512, { depthBuffer: true })
2707
+ *
2708
+ * // Explicit dimensions
2709
+ * const fbo = useRenderTarget(512, 256)
2710
+ *
2711
+ * // Explicit dimensions with options
2712
+ * const fbo = useRenderTarget(512, 256, { samples: 4 })
1941
2713
  * ```
1942
2714
  */
1943
- declare function useRenderTarget(width?: number, height?: number, options?: RenderTargetOptions): RenderTarget<THREE$1.Texture<unknown>>;
2715
+ declare function useRenderTarget(options?: RenderTargetOptions): RenderTarget;
2716
+ declare function useRenderTarget(size: number, options?: RenderTargetOptions): RenderTarget;
2717
+ declare function useRenderTarget(width: number, height: number, options?: RenderTargetOptions): RenderTarget;
1944
2718
 
1945
2719
  /**
1946
2720
  * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
@@ -2045,7 +2819,7 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2045
2819
  *
2046
2820
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2047
2821
  */
2048
- declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame): void;
2822
+ declare function advance(timestamp: number): void;
2049
2823
 
2050
2824
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2051
2825
  declare function ReactReconciler<
@@ -3099,6 +3873,12 @@ declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
3099
3873
  declare function createRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
3100
3874
  declare function unmountComponentAtNode<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
3101
3875
  declare function createPortal(children: ReactNode, container: Object3D | RefObject<Object3D | null> | RefObject<Object3D>, state?: InjectState): JSX.Element;
3876
+ interface PortalProps {
3877
+ children: ReactNode;
3878
+ state?: InjectState;
3879
+ container: Object3D | RefObject<Object3D | null> | RefObject<Object3D>;
3880
+ }
3881
+ declare function Portal({ children, container, state }: PortalProps): JSX.Element;
3102
3882
  /**
3103
3883
  * Force React to flush any updates inside the provided callback synchronously and immediately.
3104
3884
  * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
@@ -3527,11 +4307,76 @@ declare const hasConstructor: (object: unknown) => object is {
3527
4307
  constructor?: Function;
3528
4308
  };
3529
4309
 
4310
+ /**
4311
+ * Symbol marker for deferred ref resolution.
4312
+ * Used to identify values that should be resolved from refs after mount.
4313
+ */
4314
+ declare const FROM_REF: unique symbol;
4315
+ /**
4316
+ * Defers prop application until the referenced object is available.
4317
+ * Useful for props like `target` that need sibling refs to be populated.
4318
+ *
4319
+ * @param ref - React ref object to resolve at mount time
4320
+ * @returns A marker value that applyProps will resolve after mount
4321
+ *
4322
+ * @example
4323
+ * const targetRef = useRef<THREE.Object3D>(null)
4324
+ *
4325
+ * <group ref={targetRef} position={[-3, -2, -15]} />
4326
+ * <spotLight target={fromRef(targetRef)} intensity={100} />
4327
+ */
4328
+ declare function fromRef<T>(ref: React$1.RefObject<T | null>): T;
4329
+ /**
4330
+ * Type guard to check if a value is a fromRef marker.
4331
+ *
4332
+ * @param value - Value to check
4333
+ * @returns True if value is a fromRef marker
4334
+ */
4335
+ declare function isFromRef(value: unknown): value is {
4336
+ [FROM_REF]: React$1.RefObject<any>;
4337
+ };
4338
+
4339
+ /**
4340
+ * Symbol marker for mount-only method calls.
4341
+ * Used to identify methods that should only be called once on initial mount.
4342
+ */
4343
+ declare const ONCE: unique symbol;
4344
+ /**
4345
+ * Marks a method call to be executed only on initial mount.
4346
+ * Useful for geometry transforms that should not be reapplied on every render.
4347
+ *
4348
+ * When `args` prop changes (triggering reconstruction), the method will be
4349
+ * called again on the new instance since appliedOnce is not carried over.
4350
+ *
4351
+ * @param args - Arguments to pass to the method
4352
+ * @returns A marker value that applyProps will execute once
4353
+ *
4354
+ * @example
4355
+ * // Rotate geometry on mount
4356
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
4357
+ *
4358
+ * // Multiple arguments
4359
+ * <bufferGeometry applyMatrix4={once(matrix)} />
4360
+ *
4361
+ * // No arguments
4362
+ * <geometry center={once()} />
4363
+ */
4364
+ declare function once<T>(...args: T[]): T;
4365
+ /**
4366
+ * Type guard to check if a value is a once marker.
4367
+ *
4368
+ * @param value - Value to check
4369
+ * @returns True if value is a once marker
4370
+ */
4371
+ declare function isOnce(value: unknown): value is {
4372
+ [ONCE]: any[] | true;
4373
+ };
4374
+
3530
4375
  /**
3531
4376
  * A DOM canvas which accepts threejs elements as children.
3532
4377
  * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
3533
4378
  */
3534
4379
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3535
4380
 
3536
- export { Block, Canvas, ErrorBoundary, IsObject, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Scheduler, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, getInstanceProps, getRootState, getScheduler, getUuidPrefix, hasConstructor, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isObject3D, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, prepare, reconciler, removeInteractivity, resolve, unmountComponentAtNode, updateCamera, updateFrustum, useBridge, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree };
3537
- export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BaseRendererProps, Bridge, Camera, CameraProps, CanvasProps, Catalogue, Color, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DomEvent, Dpr, ElementProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, Properties, Quaternion, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererFactory, RendererProps, Root, RootOptions, RootState, RootStore, SchedulerApi, SetBlock, Size, Subscription, TextureEntry, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager };
4381
+ 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, Scheduler, Texture, _roots, act, 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, getScheduler, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, reconciler, registerPrimary, removeInteractivity, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
4382
+ export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, 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, RootOptions, RootState, RootStore, SchedulerApi, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureEntry, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };