@gnsx/react-three-fiber 10.0.1 → 10.0.3

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.
@@ -59,1076 +59,1076 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
59
59
  WebGLShadowMap: WebGLShadowMap
60
60
  }, [three_webgpu]);
61
61
 
62
- //* Utility Types ==============================
63
-
64
- type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
65
- type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
66
- type Properties<T> = Pick<T, NonFunctionKeys<T>>
67
- type Mutable<P> = { -readonly [K in keyof P]: P[K] }
68
- type IsOptional<T> = undefined extends T ? true : false
69
- type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
70
- ? IsOptional<First> extends true
71
- ? IsAllOptional<Rest>
72
- : false
73
- : true
74
-
75
- //* Camera Types ==============================
76
-
77
- type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
78
-
79
- //* Act Type ==============================
80
-
81
- type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
82
-
83
- //* Bridge & Block Types ==============================
84
-
85
- type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
86
-
87
- type SetBlock = false | Promise<null> | null
88
- type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
89
-
90
- //* Object Map Type ==============================
91
-
92
- /* Original version
93
- export interface ObjectMap {
94
- nodes: { [name: string]: THREE.Object3D }
95
- materials: { [name: string]: THREE.Material }
96
- meshes: { [name: string]: THREE.Mesh }
97
- }
98
- */
99
- /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
100
- It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
101
- I will keep the use here)
102
- https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
103
- His description is:
104
- The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
105
- */
106
- interface ObjectMap<
107
- T extends { nodes?: string; materials?: string; meshes?: string } = {
108
- nodes: string
109
- materials: string
110
- meshes: string
111
- },
112
- > {
113
- nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
114
- materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
115
- meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
116
- }
117
-
118
- //* Equality Config ==============================
119
-
120
- interface EquConfig {
121
- /** Compare arrays by reference equality a === b (default), or by shallow equality */
122
- arrays?: 'reference' | 'shallow'
123
- /** Compare objects by reference equality a === b (default), or by shallow equality */
124
- objects?: 'reference' | 'shallow'
125
- /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
126
- strict?: boolean
127
- }
128
-
129
- //* Disposable Type ==============================
130
-
131
- interface Disposable {
132
- type?: string
133
- dispose?: () => void
62
+ //* Utility Types ==============================
63
+
64
+ type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
65
+ type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
66
+ type Properties<T> = Pick<T, NonFunctionKeys<T>>
67
+ type Mutable<P> = { -readonly [K in keyof P]: P[K] }
68
+ type IsOptional<T> = undefined extends T ? true : false
69
+ type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
70
+ ? IsOptional<First> extends true
71
+ ? IsAllOptional<Rest>
72
+ : false
73
+ : true
74
+
75
+ //* Camera Types ==============================
76
+
77
+ type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
78
+
79
+ //* Act Type ==============================
80
+
81
+ type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
82
+
83
+ //* Bridge & Block Types ==============================
84
+
85
+ type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
86
+
87
+ type SetBlock = false | Promise<null> | null
88
+ type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
89
+
90
+ //* Object Map Type ==============================
91
+
92
+ /* Original version
93
+ export interface ObjectMap {
94
+ nodes: { [name: string]: THREE.Object3D }
95
+ materials: { [name: string]: THREE.Material }
96
+ meshes: { [name: string]: THREE.Mesh }
97
+ }
98
+ */
99
+ /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
100
+ It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
101
+ I will keep the use here)
102
+ https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
103
+ His description is:
104
+ The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
105
+ */
106
+ interface ObjectMap<
107
+ T extends { nodes?: string; materials?: string; meshes?: string } = {
108
+ nodes: string
109
+ materials: string
110
+ meshes: string
111
+ },
112
+ > {
113
+ nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
114
+ materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
115
+ meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
116
+ }
117
+
118
+ //* Equality Config ==============================
119
+
120
+ interface EquConfig {
121
+ /** Compare arrays by reference equality a === b (default), or by shallow equality */
122
+ arrays?: 'reference' | 'shallow'
123
+ /** Compare objects by reference equality a === b (default), or by shallow equality */
124
+ objects?: 'reference' | 'shallow'
125
+ /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
126
+ strict?: boolean
127
+ }
128
+
129
+ //* Disposable Type ==============================
130
+
131
+ interface Disposable {
132
+ type?: string
133
+ dispose?: () => void
134
+ }
135
+
136
+ //* Event-related Types =====================================
137
+
138
+ interface Intersection extends THREE$1.Intersection {
139
+ /** The event source (the object which registered the handler) */
140
+ eventObject: THREE$1.Object3D
141
+ }
142
+
143
+ type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
144
+
145
+ interface IntersectionEvent<TSourceEvent> extends Intersection {
146
+ /** The event source (the object which registered the handler) */
147
+ eventObject: THREE$1.Object3D
148
+ /** An array of intersections */
149
+ intersections: Intersection[]
150
+ /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
151
+ unprojectedPoint: THREE$1.Vector3
152
+ /** Normalized event coordinates */
153
+ pointer: THREE$1.Vector2
154
+ /** pointerId of the original event for multiple pointer events */
155
+ pointerId: number
156
+ /** Delta between first click and this event */
157
+ delta: number
158
+ /** The ray that pierced it */
159
+ ray: THREE$1.Ray
160
+ /** The camera that was used by the raycaster */
161
+ camera: Camera
162
+ /** stopPropagation will stop underlying handlers from firing */
163
+ stopPropagation: () => void
164
+ /** The original host event */
165
+ nativeEvent: TSourceEvent
166
+ /** If the event was stopped by calling stopPropagation */
167
+ stopped: boolean
168
+ }
169
+
170
+ type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
171
+ type DomEvent = PointerEvent | MouseEvent | WheelEvent
172
+
173
+ /** DOM event handlers registered on the canvas element */
174
+ interface Events {
175
+ onClick: EventListener
176
+ onContextMenu: EventListener
177
+ onDoubleClick: EventListener
178
+ onWheel: EventListener
179
+ onPointerDown: EventListener
180
+ onPointerUp: EventListener
181
+ onPointerLeave: EventListener
182
+ onPointerMove: EventListener
183
+ onPointerCancel: EventListener
184
+ onLostPointerCapture: EventListener
185
+ onDragEnter: EventListener
186
+ onDragLeave: EventListener
187
+ onDragOver: EventListener
188
+ onDrop: EventListener
189
+ }
190
+
191
+ /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
192
+ interface EventHandlers {
193
+ onClick?: (event: ThreeEvent<MouseEvent>) => void
194
+ onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
195
+ onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
196
+ /** Fires continuously while dragging over the object */
197
+ onDragOver?: (event: ThreeEvent<DragEvent>) => void
198
+ /** Fires once when drag enters the object */
199
+ onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
200
+ /** Fires once when drag leaves the object */
201
+ onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
202
+ /** Fires when drag misses this object (for objects that have drag handlers) */
203
+ onDragOverMissed?: (event: DragEvent) => void
204
+ /** Fires when a drop occurs on this object */
205
+ onDrop?: (event: ThreeEvent<DragEvent>) => void
206
+ /** Fires when a drop misses this object (for objects that have drop handlers) */
207
+ onDropMissed?: (event: DragEvent) => void
208
+ onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
209
+ onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
210
+ onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
211
+ onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
212
+ onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
213
+ onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
214
+ onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
215
+ onPointerMissed?: (event: MouseEvent) => void
216
+ onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
217
+ onWheel?: (event: ThreeEvent<WheelEvent>) => void
218
+ onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
219
+
220
+ //* Visibility Events --------------------------------
221
+ /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
222
+ onFramed?: (inView: boolean) => void
223
+ /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
224
+ onOccluded?: (occluded: boolean) => void
225
+ /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
226
+ onVisible?: (visible: boolean) => void
227
+ }
228
+
229
+ type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
230
+ type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
231
+
232
+ /** Configuration for XR pointer registration (controllers/hands) */
233
+ interface XRPointerConfig {
234
+ /** Ray origin (updated each frame by XR system) */
235
+ ray: THREE$1.Ray
236
+ /** Optional: custom compute function for this pointer */
237
+ compute?: (state: RootState) => void
238
+ /** Pointer type identifier */
239
+ type: 'controller' | 'hand' | 'gaze'
240
+ /** Which hand (for controller/hand types) */
241
+ handedness?: 'left' | 'right'
242
+ }
243
+
244
+ interface EventManager<TTarget> {
245
+ /** Determines if the event layer is active */
246
+ enabled: boolean
247
+ /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
248
+ priority: number
249
+ /** The compute function needs to set up the raycaster and an xy- pointer */
250
+ compute?: ComputeFunction
251
+ /** The filter can re-order or re-structure the intersections */
252
+ filter?: FilterFunction
253
+ /** The target node the event layer is tied to */
254
+ connected?: TTarget
255
+ /** All the pointer event handlers through which the host forwards native events */
256
+ handlers?: Events
257
+ /** Allows re-connecting to another target */
258
+ connect?: (target: TTarget) => void
259
+ /** Removes all existing events handlers from the target */
260
+ disconnect?: () => void
261
+ /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
262
+ * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
263
+ * @param pointerId - Optional pointer ID to update specific pointer only
264
+ */
265
+ update?: (pointerId?: number) => void
266
+ /** Defer pointer move raycasting to frame start (default: true) */
267
+ frameTimedRaycasts?: boolean
268
+ /** Always fire raycaster immediately on scroll events (default: true) */
269
+ alwaysFireOnScroll?: boolean
270
+ /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
271
+ updateOnFrame?: boolean
272
+ /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
273
+ flush?: () => void
274
+ /** Register an XR pointer (controller/hand). Returns assigned pointerId */
275
+ registerPointer?: (config: XRPointerConfig) => number
276
+ /** Unregister an XR pointer */
277
+ unregisterPointer?: (pointerId: number) => void
278
+ }
279
+
280
+ interface PointerCaptureTarget {
281
+ intersection: Intersection
282
+ target: Element
283
+ }
284
+
285
+ //* Visibility System Types =====================================
286
+
287
+ /** Entry in the visibility registry for tracking object visibility state */
288
+ interface VisibilityEntry {
289
+ object: THREE$1.Object3D
290
+ handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
291
+ lastFramedState: boolean | null
292
+ lastOccludedState: boolean | null
293
+ lastVisibleState: boolean | null
294
+ }
295
+
296
+ //* Scheduler Types (useFrame) ==============================
297
+
298
+
299
+
300
+ // Public Options --------------------------------
301
+
302
+ /**
303
+ * Options for useFrame hook
304
+ */
305
+ interface UseFrameNextOptions {
306
+ /** Optional stable id for the job. Auto-generated if not provided */
307
+ id?: string
308
+ /** Named phase to run in. Default: 'update' */
309
+ phase?: string
310
+ /** Run before this phase or job id */
311
+ before?: string | string[]
312
+ /** Run after this phase or job id */
313
+ after?: string | string[]
314
+ /** Priority within phase. Higher runs first. Default: 0 */
315
+ priority?: number
316
+ /** Max frames per second for this job */
317
+ fps?: number
318
+ /** If true, skip frames when behind. If false, try to catch up. Default: true */
319
+ drop?: boolean
320
+ /** Enable/disable without unregistering. Default: true */
321
+ enabled?: boolean
322
+ }
323
+
324
+ /** Alias for UseFrameNextOptions */
325
+ type UseFrameOptions = UseFrameNextOptions
326
+
327
+ /**
328
+ * Options for addPhase
329
+ */
330
+ interface AddPhaseOptions {
331
+ /** Insert this phase before the specified phase */
332
+ before?: string
333
+ /** Insert this phase after the specified phase */
334
+ after?: string
335
+ }
336
+
337
+ // Frame State --------------------------------
338
+
339
+ /**
340
+ * Timing-only state for independent/outside mode (no RootState)
341
+ */
342
+ interface FrameTimingState {
343
+ /** High-resolution timestamp from RAF (ms) */
344
+ time: number
345
+ /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
346
+ delta: number
347
+ /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
348
+ elapsed: number
349
+ /** Incrementing frame counter */
350
+ frame: number
351
+ }
352
+
353
+ /**
354
+ * State passed to useFrame callbacks (extends RootState with timing)
355
+ */
356
+ interface FrameNextState extends RootState, FrameTimingState {}
357
+
358
+ /** Alias for FrameNextState */
359
+ type FrameState = FrameNextState
360
+
361
+ // Root Options --------------------------------
362
+
363
+ /**
364
+ * Options for registerRoot
365
+ */
366
+ interface RootOptions {
367
+ /** State provider for callbacks. Optional in independent mode. */
368
+ getState?: () => any
369
+ /** Error handler for job errors. Falls back to console.error if not provided. */
370
+ onError?: (error: Error) => void
371
+ }
372
+
373
+ // Callback Types --------------------------------
374
+
375
+ /**
376
+ * Callback function for useFrame
377
+ */
378
+ type FrameNextCallback = (state: FrameNextState, delta: number) => void
379
+
380
+ /** Alias for FrameNextCallback */
381
+ type FrameCallback = FrameNextCallback
382
+
383
+ // Controls returned from useFrame --------------------------------
384
+
385
+ /**
386
+ * Controls object returned from useFrame hook
387
+ */
388
+ interface FrameNextControls {
389
+ /** The job's unique ID */
390
+ id: string
391
+ /** Access to the global scheduler for frame loop control */
392
+ scheduler: SchedulerApi
393
+ /** Manually step this job only (bypasses FPS limiting) */
394
+ step(timestamp?: number): void
395
+ /** Manually step ALL jobs in the scheduler */
396
+ stepAll(timestamp?: number): void
397
+ /** Pause this job (set enabled=false) */
398
+ pause(): void
399
+ /** Resume this job (set enabled=true) */
400
+ resume(): void
401
+ /** Reactive paused state - automatically triggers re-render when changed */
402
+ isPaused: boolean
403
+ }
404
+
405
+ /** Alias for FrameNextControls */
406
+ type FrameControls = FrameNextControls
407
+
408
+ // Scheduler Interface --------------------------------
409
+
410
+ /**
411
+ * Public interface for the global Scheduler
412
+ */
413
+ interface SchedulerApi {
414
+ //* Phase Management --------------------------------
415
+
416
+ /** Add a named phase to the scheduler */
417
+ addPhase(name: string, options?: AddPhaseOptions): void
418
+ /** Get the ordered list of phase names */
419
+ readonly phases: string[]
420
+ /** Check if a phase exists */
421
+ hasPhase(name: string): boolean
422
+
423
+ //* Root Management --------------------------------
424
+
425
+ /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
426
+ registerRoot(id: string, options?: RootOptions): () => void
427
+ /** Unregister a root */
428
+ unregisterRoot(id: string): void
429
+ /** Generate a unique root ID */
430
+ generateRootId(): string
431
+ /** Get the number of registered roots */
432
+ getRootCount(): number
433
+ /** Check if any root is registered and ready */
434
+ readonly isReady: boolean
435
+ /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
436
+ onRootReady(callback: () => void): () => void
437
+
438
+ //* Job Registration --------------------------------
439
+
440
+ /** Register a job with the scheduler (returns unsubscribe function) */
441
+ register(
442
+ callback: FrameNextCallback,
443
+ options?: {
444
+ id?: string
445
+ rootId?: string
446
+ phase?: string
447
+ before?: string | string[]
448
+ after?: string | string[]
449
+ priority?: number
450
+ fps?: number
451
+ drop?: boolean
452
+ enabled?: boolean
453
+ },
454
+ ): () => void
455
+ /** Update a job's options */
456
+ updateJob(
457
+ id: string,
458
+ options: {
459
+ priority?: number
460
+ fps?: number
461
+ drop?: boolean
462
+ enabled?: boolean
463
+ phase?: string
464
+ before?: string | string[]
465
+ after?: string | string[]
466
+ },
467
+ ): void
468
+ /** Unregister a job by ID */
469
+ unregister(id: string, rootId?: string): void
470
+ /** Get the number of registered jobs */
471
+ getJobCount(): number
472
+ /** Get all job IDs */
473
+ getJobIds(): string[]
474
+
475
+ //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
476
+
477
+ /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
478
+ registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
479
+
480
+ //* Idle Callbacks (for legacy addTail) --------------------------------
481
+
482
+ /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
483
+ onIdle(callback: (timestamp: number) => void): () => void
484
+
485
+ //* Frame Loop Control --------------------------------
486
+
487
+ /** Start the scheduler loop */
488
+ start(): void
489
+ /** Stop the scheduler loop */
490
+ stop(): void
491
+ /** Check if the scheduler is running */
492
+ readonly isRunning: boolean
493
+ /** Get/set the frameloop mode ('always', 'demand', 'never') */
494
+ frameloop: Frameloop
495
+ /** Independent mode - runs without Canvas, callbacks receive timing-only state */
496
+ independent: boolean
497
+
498
+ //* Manual Stepping --------------------------------
499
+
500
+ /** Manually step all jobs once (for frameloop='never' or testing) */
501
+ step(timestamp?: number): void
502
+ /** Manually step a single job by ID */
503
+ stepJob(id: string, timestamp?: number): void
504
+ /** Request frame(s) to be rendered (for frameloop='demand') */
505
+ invalidate(frames?: number): void
506
+
507
+ //* Per-Job Control --------------------------------
508
+
509
+ /** Check if a job is paused */
510
+ isJobPaused(id: string): boolean
511
+ /** Pause a job */
512
+ pauseJob(id: string): void
513
+ /** Resume a job */
514
+ resumeJob(id: string): void
515
+ /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
516
+ subscribeJobState(id: string, listener: () => void): () => void
517
+ }
518
+
519
+ //* Buffer Types (useBuffers) ========================================
520
+
521
+ /**
522
+ * Buffer-like types for GPU compute and storage operations.
523
+ * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
524
+ *
525
+ * @example
526
+ * ```tsx
527
+ * const { positions, velocities } = useBuffers(() => ({
528
+ * positions: instancedArray(count, 'vec3'), // StorageBufferNode
529
+ * velocities: new Float32Array(count * 3), // TypedArray
530
+ * }), 'particles')
531
+ * ```
532
+ */
533
+ type BufferLike =
534
+ | Float32Array
535
+ | Uint32Array
536
+ | Int32Array
537
+ | Float64Array
538
+ | Uint8Array
539
+ | Int8Array
540
+ | Uint16Array
541
+ | Int16Array
542
+ | THREE$1.BufferAttribute // Base class for all buffer attributes
543
+ | Node // TSL buffer nodes (instancedArray, storage)
544
+
545
+ /** Flat record of buffer-like values (no nested scopes) */
546
+ type BufferRecord = Record<string, BufferLike>
547
+
548
+ /**
549
+ * Buffer store that can contain both root-level buffers and scoped buffer objects.
550
+ * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
551
+ */
552
+ type BufferStore = Record<string, BufferLike | BufferRecord>
553
+
554
+ //* Storage Types (useGPUStorage) ========================================
555
+
556
+ /**
557
+ * GPU storage types for texture-based storage operations.
558
+ * Includes Three.js storage textures and TSL storage texture nodes.
559
+ *
560
+ * @example
561
+ * ```tsx
562
+ * const { heightMap } = useGPUStorage(() => ({
563
+ * heightMap: new StorageTexture(512, 512),
564
+ * }), 'terrain')
565
+ * ```
566
+ */
567
+ type StorageLike =
568
+ | StorageTexture // GPU storage texture
569
+ | Data3DTexture // 3D texture (can be used as storage)
570
+ | Node // TSL storage texture nodes (storageTexture)
571
+
572
+ /** Flat record of storage-like values (no nested scopes) */
573
+ type StorageRecord = Record<string, StorageLike>
574
+
575
+ /**
576
+ * Storage store that can contain both root-level storage and scoped storage objects.
577
+ * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
578
+ */
579
+ type StorageStore = Record<string, StorageLike | StorageRecord>
580
+
581
+ //* Renderer Types ========================================
582
+
583
+ /** Default renderer type - union of WebGL and WebGPU renderers */
584
+ type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
585
+
586
+ //* Core Store Types ========================================
587
+
588
+ type Subscription = {
589
+ ref: React$1.RefObject<RenderCallback>
590
+ priority: number
591
+ store: RootStore
134
592
  }
135
593
 
136
- //* Event-related Types =====================================
137
-
138
- interface Intersection extends THREE$1.Intersection {
139
- /** The event source (the object which registered the handler) */
140
- eventObject: THREE$1.Object3D
141
- }
142
-
143
- type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
144
-
145
- interface IntersectionEvent<TSourceEvent> extends Intersection {
146
- /** The event source (the object which registered the handler) */
147
- eventObject: THREE$1.Object3D
148
- /** An array of intersections */
149
- intersections: Intersection[]
150
- /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
151
- unprojectedPoint: THREE$1.Vector3
152
- /** Normalized event coordinates */
153
- pointer: THREE$1.Vector2
154
- /** pointerId of the original event for multiple pointer events */
155
- pointerId: number
156
- /** Delta between first click and this event */
157
- delta: number
158
- /** The ray that pierced it */
159
- ray: THREE$1.Ray
160
- /** The camera that was used by the raycaster */
161
- camera: Camera
162
- /** stopPropagation will stop underlying handlers from firing */
163
- stopPropagation: () => void
164
- /** The original host event */
165
- nativeEvent: TSourceEvent
166
- /** If the event was stopped by calling stopPropagation */
167
- stopped: boolean
168
- }
169
-
170
- type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
171
- type DomEvent = PointerEvent | MouseEvent | WheelEvent
172
-
173
- /** DOM event handlers registered on the canvas element */
174
- interface Events {
175
- onClick: EventListener
176
- onContextMenu: EventListener
177
- onDoubleClick: EventListener
178
- onWheel: EventListener
179
- onPointerDown: EventListener
180
- onPointerUp: EventListener
181
- onPointerLeave: EventListener
182
- onPointerMove: EventListener
183
- onPointerCancel: EventListener
184
- onLostPointerCapture: EventListener
185
- onDragEnter: EventListener
186
- onDragLeave: EventListener
187
- onDragOver: EventListener
188
- onDrop: EventListener
189
- }
190
-
191
- /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
192
- interface EventHandlers {
193
- onClick?: (event: ThreeEvent<MouseEvent>) => void
194
- onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
195
- onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
196
- /** Fires continuously while dragging over the object */
197
- onDragOver?: (event: ThreeEvent<DragEvent>) => void
198
- /** Fires once when drag enters the object */
199
- onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
200
- /** Fires once when drag leaves the object */
201
- onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
202
- /** Fires when drag misses this object (for objects that have drag handlers) */
203
- onDragOverMissed?: (event: DragEvent) => void
204
- /** Fires when a drop occurs on this object */
205
- onDrop?: (event: ThreeEvent<DragEvent>) => void
206
- /** Fires when a drop misses this object (for objects that have drop handlers) */
207
- onDropMissed?: (event: DragEvent) => void
208
- onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
209
- onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
210
- onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
211
- onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
212
- onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
213
- onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
214
- onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
215
- onPointerMissed?: (event: MouseEvent) => void
216
- onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
217
- onWheel?: (event: ThreeEvent<WheelEvent>) => void
218
- onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
219
-
220
- //* Visibility Events --------------------------------
221
- /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
222
- onFramed?: (inView: boolean) => void
223
- /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
224
- onOccluded?: (occluded: boolean) => void
225
- /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
226
- onVisible?: (visible: boolean) => void
227
- }
228
-
229
- type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
230
- type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
231
-
232
- /** Configuration for XR pointer registration (controllers/hands) */
233
- interface XRPointerConfig {
234
- /** Ray origin (updated each frame by XR system) */
235
- ray: THREE$1.Ray
236
- /** Optional: custom compute function for this pointer */
237
- compute?: (state: RootState) => void
238
- /** Pointer type identifier */
239
- type: 'controller' | 'hand' | 'gaze'
240
- /** Which hand (for controller/hand types) */
241
- handedness?: 'left' | 'right'
242
- }
243
-
244
- interface EventManager<TTarget> {
245
- /** Determines if the event layer is active */
246
- enabled: boolean
247
- /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
248
- priority: number
249
- /** The compute function needs to set up the raycaster and an xy- pointer */
250
- compute?: ComputeFunction
251
- /** The filter can re-order or re-structure the intersections */
252
- filter?: FilterFunction
253
- /** The target node the event layer is tied to */
254
- connected?: TTarget
255
- /** All the pointer event handlers through which the host forwards native events */
256
- handlers?: Events
257
- /** Allows re-connecting to another target */
258
- connect?: (target: TTarget) => void
259
- /** Removes all existing events handlers from the target */
260
- disconnect?: () => void
261
- /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
262
- * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
263
- * @param pointerId - Optional pointer ID to update specific pointer only
264
- */
265
- update?: (pointerId?: number) => void
266
- /** Defer pointer move raycasting to frame start (default: true) */
267
- frameTimedRaycasts?: boolean
268
- /** Always fire raycaster immediately on scroll events (default: true) */
269
- alwaysFireOnScroll?: boolean
270
- /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
271
- updateOnFrame?: boolean
272
- /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
273
- flush?: () => void
274
- /** Register an XR pointer (controller/hand). Returns assigned pointerId */
275
- registerPointer?: (config: XRPointerConfig) => number
276
- /** Unregister an XR pointer */
277
- unregisterPointer?: (pointerId: number) => void
278
- }
279
-
280
- interface PointerCaptureTarget {
281
- intersection: Intersection
282
- target: Element
283
- }
284
-
285
- //* Visibility System Types =====================================
286
-
287
- /** Entry in the visibility registry for tracking object visibility state */
288
- interface VisibilityEntry {
289
- object: THREE$1.Object3D
290
- handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
291
- lastFramedState: boolean | null
292
- lastOccludedState: boolean | null
293
- lastVisibleState: boolean | null
594
+ /** Per-pointer state for multi-touch and XR support */
595
+ type PointerState = {
596
+ /** Objects currently hovered by this pointer */
597
+ hovered: Map<string, ThreeEvent<DomEvent>>
598
+ /** Objects capturing this pointer */
599
+ captured: Map<THREE$1.Object3D, PointerCaptureTarget>
600
+ /** Initial click position [x, y] */
601
+ initialClick: [x: number, y: number]
602
+ /** Objects hit on initial click */
603
+ initialHits: THREE$1.Object3D[]
294
604
  }
295
605
 
296
- //* Scheduler Types (useFrame) ==============================
297
-
298
-
299
-
300
- // Public Options --------------------------------
301
-
302
- /**
303
- * Options for useFrame hook
304
- */
305
- interface UseFrameNextOptions {
306
- /** Optional stable id for the job. Auto-generated if not provided */
307
- id?: string
308
- /** Named phase to run in. Default: 'update' */
309
- phase?: string
310
- /** Run before this phase or job id */
311
- before?: string | string[]
312
- /** Run after this phase or job id */
313
- after?: string | string[]
314
- /** Priority within phase. Higher runs first. Default: 0 */
315
- priority?: number
316
- /** Max frames per second for this job */
317
- fps?: number
318
- /** If true, skip frames when behind. If false, try to catch up. Default: true */
319
- drop?: boolean
320
- /** Enable/disable without unregistering. Default: true */
321
- enabled?: boolean
322
- }
323
-
324
- /** Alias for UseFrameNextOptions */
325
- type UseFrameOptions = UseFrameNextOptions
326
-
327
- /**
328
- * Options for addPhase
329
- */
330
- interface AddPhaseOptions {
331
- /** Insert this phase before the specified phase */
332
- before?: string
333
- /** Insert this phase after the specified phase */
334
- after?: string
335
- }
336
-
337
- // Frame State --------------------------------
338
-
339
- /**
340
- * Timing-only state for independent/outside mode (no RootState)
341
- */
342
- interface FrameTimingState {
343
- /** High-resolution timestamp from RAF (ms) */
344
- time: number
345
- /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
346
- delta: number
347
- /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
348
- elapsed: number
349
- /** Incrementing frame counter */
350
- frame: number
351
- }
352
-
353
- /**
354
- * State passed to useFrame callbacks (extends RootState with timing)
355
- */
356
- interface FrameNextState extends RootState, FrameTimingState {}
357
-
358
- /** Alias for FrameNextState */
359
- type FrameState = FrameNextState
360
-
361
- // Root Options --------------------------------
362
-
363
- /**
364
- * Options for registerRoot
365
- */
366
- interface RootOptions {
367
- /** State provider for callbacks. Optional in independent mode. */
368
- getState?: () => any
369
- /** Error handler for job errors. Falls back to console.error if not provided. */
370
- onError?: (error: Error) => void
371
- }
372
-
373
- // Callback Types --------------------------------
374
-
375
- /**
376
- * Callback function for useFrame
377
- */
378
- type FrameNextCallback = (state: FrameNextState, delta: number) => void
379
-
380
- /** Alias for FrameNextCallback */
381
- type FrameCallback = FrameNextCallback
382
-
383
- // Controls returned from useFrame --------------------------------
384
-
385
- /**
386
- * Controls object returned from useFrame hook
387
- */
388
- interface FrameNextControls {
389
- /** The job's unique ID */
390
- id: string
391
- /** Access to the global scheduler for frame loop control */
392
- scheduler: SchedulerApi
393
- /** Manually step this job only (bypasses FPS limiting) */
394
- step(timestamp?: number): void
395
- /** Manually step ALL jobs in the scheduler */
396
- stepAll(timestamp?: number): void
397
- /** Pause this job (set enabled=false) */
398
- pause(): void
399
- /** Resume this job (set enabled=true) */
400
- resume(): void
401
- /** Reactive paused state - automatically triggers re-render when changed */
402
- isPaused: boolean
403
- }
404
-
405
- /** Alias for FrameNextControls */
406
- type FrameControls = FrameNextControls
407
-
408
- // Scheduler Interface --------------------------------
409
-
410
- /**
411
- * Public interface for the global Scheduler
412
- */
413
- interface SchedulerApi {
414
- //* Phase Management --------------------------------
415
-
416
- /** Add a named phase to the scheduler */
417
- addPhase(name: string, options?: AddPhaseOptions): void
418
- /** Get the ordered list of phase names */
419
- readonly phases: string[]
420
- /** Check if a phase exists */
421
- hasPhase(name: string): boolean
422
-
423
- //* Root Management --------------------------------
424
-
425
- /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
426
- registerRoot(id: string, options?: RootOptions): () => void
427
- /** Unregister a root */
428
- unregisterRoot(id: string): void
429
- /** Generate a unique root ID */
430
- generateRootId(): string
431
- /** Get the number of registered roots */
432
- getRootCount(): number
433
- /** Check if any root is registered and ready */
434
- readonly isReady: boolean
435
- /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
436
- onRootReady(callback: () => void): () => void
437
-
438
- //* Job Registration --------------------------------
439
-
440
- /** Register a job with the scheduler (returns unsubscribe function) */
441
- register(
442
- callback: FrameNextCallback,
443
- options?: {
444
- id?: string
445
- rootId?: string
446
- phase?: string
447
- before?: string | string[]
448
- after?: string | string[]
449
- priority?: number
450
- fps?: number
451
- drop?: boolean
452
- enabled?: boolean
453
- },
454
- ): () => void
455
- /** Update a job's options */
456
- updateJob(
457
- id: string,
458
- options: {
459
- priority?: number
460
- fps?: number
461
- drop?: boolean
462
- enabled?: boolean
463
- phase?: string
464
- before?: string | string[]
465
- after?: string | string[]
466
- },
467
- ): void
468
- /** Unregister a job by ID */
469
- unregister(id: string, rootId?: string): void
470
- /** Get the number of registered jobs */
471
- getJobCount(): number
472
- /** Get all job IDs */
473
- getJobIds(): string[]
474
-
475
- //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
476
-
477
- /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
478
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
479
-
480
- //* Idle Callbacks (for legacy addTail) --------------------------------
481
-
482
- /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
483
- onIdle(callback: (timestamp: number) => void): () => void
484
-
485
- //* Frame Loop Control --------------------------------
486
-
487
- /** Start the scheduler loop */
488
- start(): void
489
- /** Stop the scheduler loop */
490
- stop(): void
491
- /** Check if the scheduler is running */
492
- readonly isRunning: boolean
493
- /** Get/set the frameloop mode ('always', 'demand', 'never') */
494
- frameloop: Frameloop
495
- /** Independent mode - runs without Canvas, callbacks receive timing-only state */
496
- independent: boolean
497
-
498
- //* Manual Stepping --------------------------------
499
-
500
- /** Manually step all jobs once (for frameloop='never' or testing) */
501
- step(timestamp?: number): void
502
- /** Manually step a single job by ID */
503
- stepJob(id: string, timestamp?: number): void
504
- /** Request frame(s) to be rendered (for frameloop='demand') */
505
- invalidate(frames?: number): void
506
-
507
- //* Per-Job Control --------------------------------
508
-
509
- /** Check if a job is paused */
510
- isJobPaused(id: string): boolean
511
- /** Pause a job */
512
- pauseJob(id: string): void
513
- /** Resume a job */
514
- resumeJob(id: string): void
515
- /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
516
- subscribeJobState(id: string, listener: () => void): () => void
606
+ type Dpr = number | [min: number, max: number]
607
+
608
+ interface Size {
609
+ width: number
610
+ height: number
611
+ top: number
612
+ left: number
613
+ }
614
+
615
+ type Frameloop = 'always' | 'demand' | 'never'
616
+
617
+ interface Viewport extends Size {
618
+ /** The initial pixel ratio */
619
+ initialDpr: number
620
+ /** Current pixel ratio */
621
+ dpr: number
622
+ /** size.width / viewport.width */
623
+ factor: number
624
+ /** Camera distance */
625
+ distance: number
626
+ /** Camera aspect ratio: width / height */
627
+ aspect: number
628
+ }
629
+
630
+ type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
631
+
632
+ interface Performance {
633
+ /** Current performance normal, between min and max */
634
+ current: number
635
+ /** How low the performance can go, between 0 and max */
636
+ min: number
637
+ /** How high the performance can go, between min and max */
638
+ max: number
639
+ /** Time until current returns to max in ms */
640
+ debounce: number
641
+ /** Sets current to min, puts the system in regression */
642
+ regress: () => void
643
+ }
644
+
645
+ interface InternalState {
646
+ interaction: THREE$1.Object3D[]
647
+ subscribers: Subscription[]
648
+ /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
649
+ pointerMap: Map<number, PointerState>
650
+ /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
651
+ pointerDirty: Map<number, DomEvent>
652
+ /** Last event received (for events.update() compatibility) */
653
+ lastEvent: React$1.RefObject<DomEvent | null>
654
+ /** @deprecated Use pointerMap.get(pointerId).hovered instead */
655
+ hovered: Map<string, ThreeEvent<DomEvent>>
656
+ /** @deprecated Use pointerMap.get(pointerId).captured instead */
657
+ capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
658
+ /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
659
+ initialClick: [x: number, y: number]
660
+ /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
661
+ initialHits: THREE$1.Object3D[]
662
+ /** Visibility event registry (onFramed, onOccluded, onVisible) */
663
+ visibilityRegistry: Map<string, VisibilityEntry>
664
+ /** Whether occlusion queries are enabled (WebGPU only) */
665
+ occlusionEnabled: boolean
666
+ /** Reference to the invisible occlusion observer mesh */
667
+ occlusionObserver: THREE$1.Mesh | null
668
+ /** Cached occlusion results from render pass - keyed by Object3D */
669
+ occlusionCache: Map<THREE$1.Object3D, boolean | null>
670
+ /** Internal helper group for R3F system objects (occlusion observer, etc.) */
671
+ helperGroup: THREE$1.Group | null
672
+ active: boolean
673
+ priority: number
674
+ frames: number
675
+ subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
676
+ /** Internal renderer storage - use state.renderer or state.gl to access */
677
+ actualRenderer: R3FRenderer
678
+ /** Global scheduler reference (for useFrame hook) */
679
+ scheduler: SchedulerApi | null
680
+ /** This root's unique ID in the global scheduler */
681
+ rootId?: string
682
+ /** Function to unregister this root from the global scheduler */
683
+ unregisterRoot?: () => void
684
+ /** Container for child attachment (scene for root, original container for portals) */
685
+ container?: THREE$1.Object3D
686
+ /**
687
+ * CanvasTarget for multi-canvas WebGPU rendering.
688
+ * Created for all WebGPU canvases to support renderer sharing.
689
+ * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
690
+ */
691
+ canvasTarget?: CanvasTarget
692
+ /**
693
+ * Whether multi-canvas rendering is active.
694
+ * True when any canvas uses `target` prop to share a renderer.
695
+ * When true, setCanvasTarget is called before each render.
696
+ */
697
+ isMultiCanvas?: boolean
698
+ /**
699
+ * Whether this canvas is a secondary canvas sharing another's renderer.
700
+ * True when `target` prop is used.
701
+ */
702
+ isSecondary?: boolean
703
+ /**
704
+ * The id of the primary canvas this secondary canvas targets.
705
+ * Only set when isSecondary is true.
706
+ */
707
+ targetId?: string
708
+ /**
709
+ * Function to unregister this primary canvas from the registry.
710
+ * Only set when this canvas has an `id` prop.
711
+ */
712
+ unregisterPrimary?: () => void
713
+ /** Whether canvas dimensions are forced to even numbers */
714
+ forceEven?: boolean
715
+ }
716
+
717
+ interface XRManager {
718
+ connect: () => void
719
+ disconnect: () => void
720
+ }
721
+
722
+ //* Root State Interface ====================================
723
+
724
+ interface RootState {
725
+ /** Set current state */
726
+ set: StoreApi<RootState>['setState']
727
+ /** Get current state */
728
+ get: StoreApi<RootState>['getState']
729
+ /**
730
+ * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
731
+ * - For primary/independent canvases: points to its own store (self-reference)
732
+ * - For secondary canvases: points to the primary canvas's store
733
+ *
734
+ * Hooks like useNodes/useUniforms should read from primaryStore to ensure
735
+ * consistent shared state across all canvases sharing a renderer.
736
+ */
737
+ primaryStore: RootStore
738
+ /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
739
+ gl: THREE$1.WebGLRenderer
740
+ /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
741
+ renderer: R3FRenderer
742
+ /** Inspector of the webGPU Renderer. Init in the canvas */
743
+ inspector: any // Inspector type from three/webgpu
744
+
745
+ /** Default camera */
746
+ camera: ThreeCamera
747
+ /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
748
+ frustum: THREE$1.Frustum
749
+ /** Whether to automatically update the frustum each frame (default: true) */
750
+ autoUpdateFrustum: boolean
751
+ /** Default scene (may be overridden in portals to point to the portal container) */
752
+ scene: THREE$1.Scene
753
+ /** The actual root THREE.Scene - always points to the true scene, even inside portals */
754
+ rootScene: THREE$1.Scene
755
+ /** Default raycaster */
756
+ raycaster: THREE$1.Raycaster
757
+ /** Event layer interface, contains the event handler and the node they're connected to */
758
+ events: EventManager<any>
759
+ /** XR interface */
760
+ xr: XRManager
761
+ /** Currently used controls */
762
+ controls: THREE$1.EventDispatcher | null
763
+ /** Normalized event coordinates */
764
+ pointer: THREE$1.Vector2
765
+ /** @deprecated Normalized event coordinates, use "pointer" instead! */
766
+ mouse: THREE$1.Vector2
767
+ /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
768
+ textureColorSpace: THREE$1.ColorSpace
769
+ /** Render loop flags */
770
+ frameloop: Frameloop
771
+ performance: Performance
772
+ /** Reactive pixel-size of the canvas */
773
+ size: Size
774
+ /** Reactive size of the viewport in threejs units */
775
+ viewport: Viewport & {
776
+ getCurrentViewport: (
777
+ camera?: ThreeCamera,
778
+ target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
779
+ size?: Size,
780
+ ) => Omit<Viewport, 'dpr' | 'initialDpr'>
781
+ }
782
+ /** Flags the canvas for render, but doesn't render in itself */
783
+ invalidate: (frames?: number, stackFrames?: boolean) => void
784
+ /** Advance (render) one step */
785
+ advance: (timestamp: number, runGlobalEffects?: boolean) => void
786
+ /** Shortcut to setting the event layer */
787
+ setEvents: (events: Partial<EventManager<any>>) => void
788
+ /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
789
+ setSize: (width?: number, height?: number, top?: number, left?: number) => void
790
+ /** Shortcut to manual setting the pixel ratio */
791
+ setDpr: (dpr: Dpr) => void
792
+ /** Shortcut to setting frameloop flags */
793
+ setFrameloop: (frameloop: Frameloop) => void
794
+ /** Set error state to propagate to error boundary */
795
+ setError: (error: Error | null) => void
796
+ /** Current error state (null when no error) */
797
+ error: Error | null
798
+ /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
799
+ uniforms: UniformStore
800
+ /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
801
+ nodes: Record<string, any>
802
+ /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
803
+ buffers: BufferStore
804
+ /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
805
+ gpuStorage: StorageStore
806
+ /** Global TSL texture nodes - use useTextures() hook for operations */
807
+ textures: Map<string, any>
808
+ /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
809
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
810
+ /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
811
+ passes: Record<string, any>
812
+ /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
813
+ _hmrVersion: number
814
+ /** Internal: whether setSize() has taken ownership of canvas dimensions */
815
+ _sizeImperative: boolean
816
+ /** Internal: stored size props from Canvas for reset functionality */
817
+ _sizeProps: { width?: number; height?: number } | null
818
+ /** When the canvas was clicked but nothing was hit */
819
+ onPointerMissed?: (event: MouseEvent) => void
820
+ /** When a dragover event has missed any target */
821
+ onDragOverMissed?: (event: DragEvent) => void
822
+ /** When a drop event has missed any target */
823
+ onDropMissed?: (event: DragEvent) => void
824
+ /** If this state model is layered (via createPortal) then this contains the previous layer */
825
+ previousRoot?: RootStore
826
+ /** Internals */
827
+ internal: InternalState
828
+ // flags for triggers
829
+ // if we are using the webGl renderer, this will be true
830
+ isLegacy: boolean
831
+ // regardless of renderer, if the system supports webGpu, this will be true
832
+ webGPUSupported: boolean
833
+ //if we are on native
834
+ isNative: boolean
517
835
  }
518
836
 
519
- //* Buffer Types (useBuffers) ========================================
520
-
521
- /**
522
- * Buffer-like types for GPU compute and storage operations.
523
- * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
524
- *
525
- * @example
526
- * ```tsx
527
- * const { positions, velocities } = useBuffers(() => ({
528
- * positions: instancedArray(count, 'vec3'), // StorageBufferNode
529
- * velocities: new Float32Array(count * 3), // TypedArray
530
- * }), 'particles')
531
- * ```
532
- */
533
- type BufferLike =
534
- | Float32Array
535
- | Uint32Array
536
- | Int32Array
537
- | Float64Array
538
- | Uint8Array
539
- | Int8Array
540
- | Uint16Array
541
- | Int16Array
542
- | THREE$1.BufferAttribute // Base class for all buffer attributes
543
- | Node // TSL buffer nodes (instancedArray, storage)
544
-
545
- /** Flat record of buffer-like values (no nested scopes) */
546
- type BufferRecord = Record<string, BufferLike>
547
-
548
- /**
549
- * Buffer store that can contain both root-level buffers and scoped buffer objects.
550
- * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
551
- */
552
- type BufferStore = Record<string, BufferLike | BufferRecord>
553
-
554
- //* Storage Types (useGPUStorage) ========================================
555
-
556
- /**
557
- * GPU storage types for texture-based storage operations.
558
- * Includes Three.js storage textures and TSL storage texture nodes.
559
- *
560
- * @example
561
- * ```tsx
562
- * const { heightMap } = useGPUStorage(() => ({
563
- * heightMap: new StorageTexture(512, 512),
564
- * }), 'terrain')
565
- * ```
566
- */
567
- type StorageLike =
568
- | StorageTexture // GPU storage texture
569
- | Data3DTexture // 3D texture (can be used as storage)
570
- | Node // TSL storage texture nodes (storageTexture)
571
-
572
- /** Flat record of storage-like values (no nested scopes) */
573
- type StorageRecord = Record<string, StorageLike>
574
-
575
- /**
576
- * Storage store that can contain both root-level storage and scoped storage objects.
577
- * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
578
- */
579
- type StorageStore = Record<string, StorageLike | StorageRecord>
580
-
581
- //* Renderer Types ========================================
582
-
583
- /** Default renderer type - union of WebGL and WebGPU renderers */
584
- type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
585
-
586
- //* Core Store Types ========================================
587
-
588
- type Subscription = {
589
- ref: React$1.RefObject<RenderCallback>
590
- priority: number
591
- store: RootStore
592
- }
593
-
594
- /** Per-pointer state for multi-touch and XR support */
595
- type PointerState = {
596
- /** Objects currently hovered by this pointer */
597
- hovered: Map<string, ThreeEvent<DomEvent>>
598
- /** Objects capturing this pointer */
599
- captured: Map<THREE$1.Object3D, PointerCaptureTarget>
600
- /** Initial click position [x, y] */
601
- initialClick: [x: number, y: number]
602
- /** Objects hit on initial click */
603
- initialHits: THREE$1.Object3D[]
604
- }
605
-
606
- type Dpr = number | [min: number, max: number]
607
-
608
- interface Size {
609
- width: number
610
- height: number
611
- top: number
612
- left: number
613
- }
614
-
615
- type Frameloop = 'always' | 'demand' | 'never'
616
-
617
- interface Viewport extends Size {
618
- /** The initial pixel ratio */
619
- initialDpr: number
620
- /** Current pixel ratio */
621
- dpr: number
622
- /** size.width / viewport.width */
623
- factor: number
624
- /** Camera distance */
625
- distance: number
626
- /** Camera aspect ratio: width / height */
627
- aspect: number
628
- }
629
-
630
- type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
631
-
632
- interface Performance {
633
- /** Current performance normal, between min and max */
634
- current: number
635
- /** How low the performance can go, between 0 and max */
636
- min: number
637
- /** How high the performance can go, between min and max */
638
- max: number
639
- /** Time until current returns to max in ms */
640
- debounce: number
641
- /** Sets current to min, puts the system in regression */
642
- regress: () => void
643
- }
644
-
645
- interface InternalState {
646
- interaction: THREE$1.Object3D[]
647
- subscribers: Subscription[]
648
- /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
649
- pointerMap: Map<number, PointerState>
650
- /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
651
- pointerDirty: Map<number, DomEvent>
652
- /** Last event received (for events.update() compatibility) */
653
- lastEvent: React$1.RefObject<DomEvent | null>
654
- /** @deprecated Use pointerMap.get(pointerId).hovered instead */
655
- hovered: Map<string, ThreeEvent<DomEvent>>
656
- /** @deprecated Use pointerMap.get(pointerId).captured instead */
657
- capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
658
- /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
659
- initialClick: [x: number, y: number]
660
- /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
661
- initialHits: THREE$1.Object3D[]
662
- /** Visibility event registry (onFramed, onOccluded, onVisible) */
663
- visibilityRegistry: Map<string, VisibilityEntry>
664
- /** Whether occlusion queries are enabled (WebGPU only) */
665
- occlusionEnabled: boolean
666
- /** Reference to the invisible occlusion observer mesh */
667
- occlusionObserver: THREE$1.Mesh | null
668
- /** Cached occlusion results from render pass - keyed by Object3D */
669
- occlusionCache: Map<THREE$1.Object3D, boolean | null>
670
- /** Internal helper group for R3F system objects (occlusion observer, etc.) */
671
- helperGroup: THREE$1.Group | null
672
- active: boolean
673
- priority: number
674
- frames: number
675
- subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
676
- /** Internal renderer storage - use state.renderer or state.gl to access */
677
- actualRenderer: R3FRenderer
678
- /** Global scheduler reference (for useFrame hook) */
679
- scheduler: SchedulerApi | null
680
- /** This root's unique ID in the global scheduler */
681
- rootId?: string
682
- /** Function to unregister this root from the global scheduler */
683
- unregisterRoot?: () => void
684
- /** Container for child attachment (scene for root, original container for portals) */
685
- container?: THREE$1.Object3D
686
- /**
687
- * CanvasTarget for multi-canvas WebGPU rendering.
688
- * Created for all WebGPU canvases to support renderer sharing.
689
- * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
690
- */
691
- canvasTarget?: CanvasTarget
692
- /**
693
- * Whether multi-canvas rendering is active.
694
- * True when any canvas uses `target` prop to share a renderer.
695
- * When true, setCanvasTarget is called before each render.
696
- */
697
- isMultiCanvas?: boolean
698
- /**
699
- * Whether this canvas is a secondary canvas sharing another's renderer.
700
- * True when `target` prop is used.
701
- */
702
- isSecondary?: boolean
703
- /**
704
- * The id of the primary canvas this secondary canvas targets.
705
- * Only set when isSecondary is true.
706
- */
707
- targetId?: string
708
- /**
709
- * Function to unregister this primary canvas from the registry.
710
- * Only set when this canvas has an `id` prop.
711
- */
712
- unregisterPrimary?: () => void
713
- /** Whether canvas dimensions are forced to even numbers */
714
- forceEven?: boolean
715
- }
716
-
717
- interface XRManager {
718
- connect: () => void
719
- disconnect: () => void
720
- }
721
-
722
- //* Root State Interface ====================================
723
-
724
- interface RootState {
725
- /** Set current state */
726
- set: StoreApi<RootState>['setState']
727
- /** Get current state */
728
- get: StoreApi<RootState>['getState']
729
- /**
730
- * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
731
- * - For primary/independent canvases: points to its own store (self-reference)
732
- * - For secondary canvases: points to the primary canvas's store
733
- *
734
- * Hooks like useNodes/useUniforms should read from primaryStore to ensure
735
- * consistent shared state across all canvases sharing a renderer.
736
- */
737
- primaryStore: RootStore
738
- /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
739
- gl: THREE$1.WebGLRenderer
740
- /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
741
- renderer: R3FRenderer
742
- /** Inspector of the webGPU Renderer. Init in the canvas */
743
- inspector: any // Inspector type from three/webgpu
744
-
745
- /** Default camera */
746
- camera: ThreeCamera
747
- /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
748
- frustum: THREE$1.Frustum
749
- /** Whether to automatically update the frustum each frame (default: true) */
750
- autoUpdateFrustum: boolean
751
- /** Default scene (may be overridden in portals to point to the portal container) */
752
- scene: THREE$1.Scene
753
- /** The actual root THREE.Scene - always points to the true scene, even inside portals */
754
- rootScene: THREE$1.Scene
755
- /** Default raycaster */
756
- raycaster: THREE$1.Raycaster
757
- /** Event layer interface, contains the event handler and the node they're connected to */
758
- events: EventManager<any>
759
- /** XR interface */
760
- xr: XRManager
761
- /** Currently used controls */
762
- controls: THREE$1.EventDispatcher | null
763
- /** Normalized event coordinates */
764
- pointer: THREE$1.Vector2
765
- /** @deprecated Normalized event coordinates, use "pointer" instead! */
766
- mouse: THREE$1.Vector2
767
- /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
768
- textureColorSpace: THREE$1.ColorSpace
769
- /** Render loop flags */
770
- frameloop: Frameloop
771
- performance: Performance
772
- /** Reactive pixel-size of the canvas */
773
- size: Size
774
- /** Reactive size of the viewport in threejs units */
775
- viewport: Viewport & {
776
- getCurrentViewport: (
777
- camera?: ThreeCamera,
778
- target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
779
- size?: Size,
780
- ) => Omit<Viewport, 'dpr' | 'initialDpr'>
781
- }
782
- /** Flags the canvas for render, but doesn't render in itself */
783
- invalidate: (frames?: number, stackFrames?: boolean) => void
784
- /** Advance (render) one step */
785
- advance: (timestamp: number, runGlobalEffects?: boolean) => void
786
- /** Shortcut to setting the event layer */
787
- setEvents: (events: Partial<EventManager<any>>) => void
788
- /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
789
- setSize: (width?: number, height?: number, top?: number, left?: number) => void
790
- /** Shortcut to manual setting the pixel ratio */
791
- setDpr: (dpr: Dpr) => void
792
- /** Shortcut to setting frameloop flags */
793
- setFrameloop: (frameloop: Frameloop) => void
794
- /** Set error state to propagate to error boundary */
795
- setError: (error: Error | null) => void
796
- /** Current error state (null when no error) */
797
- error: Error | null
798
- /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
799
- uniforms: UniformStore
800
- /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
801
- nodes: Record<string, any>
802
- /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
803
- buffers: BufferStore
804
- /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
805
- gpuStorage: StorageStore
806
- /** Global TSL texture nodes - use useTextures() hook for operations */
807
- textures: Map<string, any>
808
- /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
809
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
810
- /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
811
- passes: Record<string, any>
812
- /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
813
- _hmrVersion: number
814
- /** Internal: whether setSize() has taken ownership of canvas dimensions */
815
- _sizeImperative: boolean
816
- /** Internal: stored size props from Canvas for reset functionality */
817
- _sizeProps: { width?: number; height?: number } | null
818
- /** When the canvas was clicked but nothing was hit */
819
- onPointerMissed?: (event: MouseEvent) => void
820
- /** When a dragover event has missed any target */
821
- onDragOverMissed?: (event: DragEvent) => void
822
- /** When a drop event has missed any target */
823
- onDropMissed?: (event: DragEvent) => void
824
- /** If this state model is layered (via createPortal) then this contains the previous layer */
825
- previousRoot?: RootStore
826
- /** Internals */
827
- internal: InternalState
828
- // flags for triggers
829
- // if we are using the webGl renderer, this will be true
830
- isLegacy: boolean
831
- // regardless of renderer, if the system supports webGpu, this will be true
832
- webGPUSupported: boolean
833
- //if we are on native
834
- isNative: boolean
835
- }
836
-
837
837
  type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>
838
838
 
839
- //* Base Renderer Types =====================================
840
-
841
- // Shim for OffscreenCanvas since it was removed from DOM types
842
- interface OffscreenCanvas$1 extends EventTarget {}
843
-
844
- interface BaseRendererProps {
845
- canvas: HTMLCanvasElement | OffscreenCanvas$1
846
- powerPreference?: 'high-performance' | 'low-power' | 'default'
847
- antialias?: boolean
848
- alpha?: boolean
849
- }
850
-
851
- type RendererFactory<TRenderer, TParams> =
852
- | TRenderer
853
- | ((defaultProps: TParams) => TRenderer)
854
- | ((defaultProps: TParams) => Promise<TRenderer>)
855
-
856
- interface Renderer {
857
- render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
858
- }
859
-
860
- //* Color Management Config ==============================
861
-
862
- /**
863
- * Color management configuration shared by both WebGL and WebGPU renderers.
864
- */
865
- interface ColorManagementConfig {
866
- /**
867
- * Color space assigned to 8-bit input textures (color maps).
868
- * Defaults to sRGB. Most textures are authored in sRGB.
869
- * @default THREE.SRGBColorSpace
870
- */
871
- textureColorSpace?: THREE$1.ColorSpace
872
- }
873
-
874
- //* WebGL Renderer Props ==============================
875
-
876
- type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
877
- canvas: HTMLCanvasElement | OffscreenCanvas$1
878
- }
879
-
880
- type GLProps =
881
- | Renderer
882
- | ((defaultProps: DefaultGLProps) => Renderer)
883
- | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
884
- | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
885
-
886
- //* WebGPU Renderer Props ==============================
887
-
888
- type DefaultRendererProps = {
889
- canvas: HTMLCanvasElement | OffscreenCanvas$1
890
- [key: string]: any
891
- }
892
-
893
- /**
894
- * Canvas-level scheduler configuration.
895
- * Controls render timing relative to other canvases.
896
- */
897
- interface CanvasSchedulerConfig {
898
- /**
899
- * Render this canvas after another canvas completes.
900
- * Pass the `id` of another canvas.
901
- */
902
- after?: string
903
- /**
904
- * Limit this canvas's render rate (frames per second).
905
- */
906
- fps?: number
907
- }
908
-
909
- /**
910
- * Extended renderer configuration for multi-canvas support and color management.
911
- */
912
- interface RendererConfigExtended extends ColorManagementConfig {
913
- /** Share renderer from another canvas (WebGPU only) */
914
- primaryCanvas?: string
915
- /** Canvas-level scheduler options */
916
- scheduler?: CanvasSchedulerConfig
917
- }
918
-
919
- type RendererProps =
920
- | any // WebGPURenderer
921
- | ((defaultProps: DefaultRendererProps) => any)
922
- | ((defaultProps: DefaultRendererProps) => Promise<any>)
923
- | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
924
-
925
- //* Camera Props ==============================
926
-
927
- type CameraProps = (
928
- | THREE$1.Camera
929
- | Partial<
930
- ThreeElement<typeof THREE$1.Camera> &
931
- ThreeElement<typeof THREE$1.PerspectiveCamera> &
932
- ThreeElement<typeof THREE$1.OrthographicCamera>
933
- >
934
- ) & {
935
- /** Flags the camera as manual, putting projection into your own hands */
936
- manual?: boolean
937
- }
938
-
939
- //* Render Props ==============================
940
-
941
- interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
942
- /**
943
- * Unique identifier for multi-canvas renderer sharing.
944
- * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
945
- * Also sets the HTML `id` attribute on the canvas element.
946
- * @example <Canvas id="main-viewer">...</Canvas>
947
- */
948
- id?: string
949
- /**
950
- * Share the renderer from another canvas instead of creating a new one.
951
- * Pass the `id` of the primary canvas to share its WebGPURenderer.
952
- * Only available with WebGPU (not legacy WebGL).
953
- *
954
- * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
955
- * @internal
956
- */
957
- primaryCanvas?: string
958
- /**
959
- * Canvas-level scheduler options. Controls render timing relative to other canvases.
960
- *
961
- * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
962
- * @internal
963
- */
964
- scheduler?: CanvasSchedulerConfig
965
- /** A threejs renderer instance or props that go into the default renderer */
966
- gl?: GLProps
967
- /** A WebGPU renderer instance or props that go into the default renderer */
968
- renderer?: RendererProps
969
- /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
970
- size?: Size
971
- /**
972
- * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
973
- * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
974
- * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
975
- */
976
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
977
- /** Creates an orthographic camera */
978
- orthographic?: boolean
979
- /**
980
- * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
981
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
982
- */
983
- frameloop?: Frameloop
984
- /**
985
- * R3F performance options for adaptive performance.
986
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
987
- */
988
- performance?: Partial<Omit<Performance, 'regress'>>
989
- /** Target pixel ratio. Can clamp between a range: `[min, max]` */
990
- dpr?: Dpr
991
- /** Props that go into the default raycaster */
992
- raycaster?: Partial<THREE$1.Raycaster>
993
- /** A `THREE.Scene` instance or props that go into the default scene */
994
- scene?: THREE$1.Scene | Partial<THREE$1.Scene>
995
- /** A `THREE.Camera` instance or props that go into the default camera */
996
- camera?: CameraProps
997
- /** An R3F event manager to manage elements' pointer events */
998
- events?: (store: RootStore) => EventManager<HTMLElement>
999
- /** Callback after the canvas has rendered (but not yet committed) */
1000
- onCreated?: (state: RootState) => void
1001
- /** Response for pointer clicks that have missed any target */
1002
- onPointerMissed?: (event: MouseEvent) => void
1003
- /** Response for dragover events that have missed any target */
1004
- onDragOverMissed?: (event: DragEvent) => void
1005
- /** Response for drop events that have missed any target */
1006
- onDropMissed?: (event: DragEvent) => void
1007
- /** Whether to automatically update the frustum each frame (default: true) */
1008
- autoUpdateFrustum?: boolean
1009
- /**
1010
- * Enable WebGPU occlusion queries for onOccluded/onVisible events.
1011
- * Auto-enabled when any object uses onOccluded or onVisible handlers.
1012
- * Only works with WebGPU renderer - WebGL will log a warning.
1013
- */
1014
- occlusion?: boolean
1015
- /** Internal: stored size props from Canvas for reset functionality */
1016
- _sizeProps?: { width?: number; height?: number } | null
1017
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1018
- forceEven?: boolean
1019
- }
1020
-
1021
- //* Reconciler Root ==============================
1022
-
1023
- interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
1024
- configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
1025
- render: (element: ReactNode) => RootStore
1026
- unmount: () => void
1027
- }
1028
-
1029
- //* Inject State ==============================
1030
-
1031
- type InjectState = Partial<
1032
- Omit<RootState, 'events'> & {
1033
- events?: {
1034
- enabled?: boolean
1035
- priority?: number
1036
- compute?: ComputeFunction
1037
- connected?: any
1038
- }
1039
- /**
1040
- * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
1041
- * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
1042
- * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
1043
- */
1044
- injectScene?: boolean
1045
- }
839
+ //* Base Renderer Types =====================================
840
+
841
+ // Shim for OffscreenCanvas since it was removed from DOM types
842
+ interface OffscreenCanvas$1 extends EventTarget {}
843
+
844
+ interface BaseRendererProps {
845
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
846
+ powerPreference?: 'high-performance' | 'low-power' | 'default'
847
+ antialias?: boolean
848
+ alpha?: boolean
849
+ }
850
+
851
+ type RendererFactory<TRenderer, TParams> =
852
+ | TRenderer
853
+ | ((defaultProps: TParams) => TRenderer)
854
+ | ((defaultProps: TParams) => Promise<TRenderer>)
855
+
856
+ interface Renderer {
857
+ render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
858
+ }
859
+
860
+ //* Color Management Config ==============================
861
+
862
+ /**
863
+ * Color management configuration shared by both WebGL and WebGPU renderers.
864
+ */
865
+ interface ColorManagementConfig {
866
+ /**
867
+ * Color space assigned to 8-bit input textures (color maps).
868
+ * Defaults to sRGB. Most textures are authored in sRGB.
869
+ * @default THREE.SRGBColorSpace
870
+ */
871
+ textureColorSpace?: THREE$1.ColorSpace
872
+ }
873
+
874
+ //* WebGL Renderer Props ==============================
875
+
876
+ type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
877
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
878
+ }
879
+
880
+ type GLProps =
881
+ | Renderer
882
+ | ((defaultProps: DefaultGLProps) => Renderer)
883
+ | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
884
+ | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
885
+
886
+ //* WebGPU Renderer Props ==============================
887
+
888
+ type DefaultRendererProps = {
889
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
890
+ [key: string]: any
891
+ }
892
+
893
+ /**
894
+ * Canvas-level scheduler configuration.
895
+ * Controls render timing relative to other canvases.
896
+ */
897
+ interface CanvasSchedulerConfig {
898
+ /**
899
+ * Render this canvas after another canvas completes.
900
+ * Pass the `id` of another canvas.
901
+ */
902
+ after?: string
903
+ /**
904
+ * Limit this canvas's render rate (frames per second).
905
+ */
906
+ fps?: number
907
+ }
908
+
909
+ /**
910
+ * Extended renderer configuration for multi-canvas support and color management.
911
+ */
912
+ interface RendererConfigExtended extends ColorManagementConfig {
913
+ /** Share renderer from another canvas (WebGPU only) */
914
+ primaryCanvas?: string
915
+ /** Canvas-level scheduler options */
916
+ scheduler?: CanvasSchedulerConfig
917
+ }
918
+
919
+ type RendererProps =
920
+ | any // WebGPURenderer
921
+ | ((defaultProps: DefaultRendererProps) => any)
922
+ | ((defaultProps: DefaultRendererProps) => Promise<any>)
923
+ | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
924
+
925
+ //* Camera Props ==============================
926
+
927
+ type CameraProps = (
928
+ | THREE$1.Camera
929
+ | Partial<
930
+ ThreeElement<typeof THREE$1.Camera> &
931
+ ThreeElement<typeof THREE$1.PerspectiveCamera> &
932
+ ThreeElement<typeof THREE$1.OrthographicCamera>
933
+ >
934
+ ) & {
935
+ /** Flags the camera as manual, putting projection into your own hands */
936
+ manual?: boolean
937
+ }
938
+
939
+ //* Render Props ==============================
940
+
941
+ interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
942
+ /**
943
+ * Unique identifier for multi-canvas renderer sharing.
944
+ * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
945
+ * Also sets the HTML `id` attribute on the canvas element.
946
+ * @example <Canvas id="main-viewer">...</Canvas>
947
+ */
948
+ id?: string
949
+ /**
950
+ * Share the renderer from another canvas instead of creating a new one.
951
+ * Pass the `id` of the primary canvas to share its WebGPURenderer.
952
+ * Only available with WebGPU (not legacy WebGL).
953
+ *
954
+ * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
955
+ * @internal
956
+ */
957
+ primaryCanvas?: string
958
+ /**
959
+ * Canvas-level scheduler options. Controls render timing relative to other canvases.
960
+ *
961
+ * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
962
+ * @internal
963
+ */
964
+ scheduler?: CanvasSchedulerConfig
965
+ /** A threejs renderer instance or props that go into the default renderer */
966
+ gl?: GLProps
967
+ /** A WebGPU renderer instance or props that go into the default renderer */
968
+ renderer?: RendererProps
969
+ /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
970
+ size?: Size
971
+ /**
972
+ * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
973
+ * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
974
+ * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
975
+ */
976
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
977
+ /** Creates an orthographic camera */
978
+ orthographic?: boolean
979
+ /**
980
+ * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
981
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
982
+ */
983
+ frameloop?: Frameloop
984
+ /**
985
+ * R3F performance options for adaptive performance.
986
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
987
+ */
988
+ performance?: Partial<Omit<Performance, 'regress'>>
989
+ /** Target pixel ratio. Can clamp between a range: `[min, max]` */
990
+ dpr?: Dpr
991
+ /** Props that go into the default raycaster */
992
+ raycaster?: Partial<THREE$1.Raycaster>
993
+ /** A `THREE.Scene` instance or props that go into the default scene */
994
+ scene?: THREE$1.Scene | Partial<THREE$1.Scene>
995
+ /** A `THREE.Camera` instance or props that go into the default camera */
996
+ camera?: CameraProps
997
+ /** An R3F event manager to manage elements' pointer events */
998
+ events?: (store: RootStore) => EventManager<HTMLElement>
999
+ /** Callback after the canvas has rendered (but not yet committed) */
1000
+ onCreated?: (state: RootState) => void
1001
+ /** Response for pointer clicks that have missed any target */
1002
+ onPointerMissed?: (event: MouseEvent) => void
1003
+ /** Response for dragover events that have missed any target */
1004
+ onDragOverMissed?: (event: DragEvent) => void
1005
+ /** Response for drop events that have missed any target */
1006
+ onDropMissed?: (event: DragEvent) => void
1007
+ /** Whether to automatically update the frustum each frame (default: true) */
1008
+ autoUpdateFrustum?: boolean
1009
+ /**
1010
+ * Enable WebGPU occlusion queries for onOccluded/onVisible events.
1011
+ * Auto-enabled when any object uses onOccluded or onVisible handlers.
1012
+ * Only works with WebGPU renderer - WebGL will log a warning.
1013
+ */
1014
+ occlusion?: boolean
1015
+ /** Internal: stored size props from Canvas for reset functionality */
1016
+ _sizeProps?: { width?: number; height?: number } | null
1017
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1018
+ forceEven?: boolean
1019
+ }
1020
+
1021
+ //* Reconciler Root ==============================
1022
+
1023
+ interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
1024
+ configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
1025
+ render: (element: ReactNode) => RootStore
1026
+ unmount: () => void
1027
+ }
1028
+
1029
+ //* Inject State ==============================
1030
+
1031
+ type InjectState = Partial<
1032
+ Omit<RootState, 'events'> & {
1033
+ events?: {
1034
+ enabled?: boolean
1035
+ priority?: number
1036
+ compute?: ComputeFunction
1037
+ connected?: any
1038
+ }
1039
+ /**
1040
+ * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
1041
+ * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
1042
+ * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
1043
+ */
1044
+ injectScene?: boolean
1045
+ }
1046
1046
  >
1047
1047
 
1048
- //* Reconciler Types ==============================
1049
-
1050
- // FiberRoot is an opaque internal React type - we define it locally
1051
- // to avoid bundling @types/react-reconciler which causes absolute path issues
1052
- type FiberRoot = any
1053
-
1054
- interface Root {
1055
- fiber: FiberRoot
1056
- store: RootStore
1057
- }
1058
-
1059
- type AttachFnType<O = any> = (parent: any, self: O) => () => void
1060
- type AttachType<O = any> = string | AttachFnType<O>
1061
-
1062
- type ConstructorRepresentation<T = any> = new (...args: any[]) => T
1063
-
1064
- interface Catalogue {
1065
- [name: string]: ConstructorRepresentation
1066
- }
1067
-
1068
- // TODO: handle constructor overloads
1069
- // https://github.com/pmndrs/react-three-fiber/pull/2931
1070
- // https://github.com/microsoft/TypeScript/issues/37079
1071
- type Args<T> = T extends ConstructorRepresentation
1072
- ? T extends typeof Color$1
1073
- ? [r: number, g: number, b: number] | [color: ColorRepresentation]
1074
- : ConstructorParameters<T>
1075
- : any[]
1076
-
1077
- type ArgsProp<P> = P extends ConstructorRepresentation
1078
- ? IsAllOptional<ConstructorParameters<P>> extends true
1079
- ? { args?: Args<P> }
1080
- : { args: Args<P> }
1081
- : { args: unknown[] }
1082
-
1083
- type InstanceProps<T = any, P = any> = ArgsProp<P> & {
1084
- object?: T
1085
- dispose?: null
1086
- attach?: AttachType<T>
1087
- onUpdate?: (self: T) => void
1088
- }
1089
-
1090
- interface Instance<O = any> {
1091
- root: RootStore
1092
- type: string
1093
- parent: Instance | null
1094
- children: Instance[]
1095
- props: InstanceProps<O> & Record<string, unknown>
1096
- object: O & { __r3f?: Instance<O> }
1097
- eventCount: number
1098
- handlers: Partial<EventHandlers>
1099
- attach?: AttachType<O>
1100
- previousAttach?: any
1101
- isHidden: boolean
1102
- /** Deferred ref props to apply in commitMount */
1103
- deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1104
- /** Set of props that have been applied via once() */
1105
- appliedOnce?: Set<string>
1106
- }
1107
-
1108
- interface HostConfig {
1109
- type: string
1110
- props: Instance['props']
1111
- container: RootStore
1112
- instance: Instance
1113
- textInstance: void
1114
- suspenseInstance: Instance
1115
- hydratableInstance: never
1116
- formInstance: never
1117
- publicInstance: Instance['object']
1118
- hostContext: {}
1119
- childSet: never
1120
- timeoutHandle: number | undefined
1121
- noTimeout: -1
1122
- TransitionStatus: null
1123
- }
1124
- declare global {
1125
- var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
1048
+ //* Reconciler Types ==============================
1049
+
1050
+ // FiberRoot is an opaque internal React type - we define it locally
1051
+ // to avoid bundling @types/react-reconciler which causes absolute path issues
1052
+ type FiberRoot = any
1053
+
1054
+ interface Root {
1055
+ fiber: FiberRoot
1056
+ store: RootStore
1057
+ }
1058
+
1059
+ type AttachFnType<O = any> = (parent: any, self: O) => () => void
1060
+ type AttachType<O = any> = string | AttachFnType<O>
1061
+
1062
+ type ConstructorRepresentation<T = any> = new (...args: any[]) => T
1063
+
1064
+ interface Catalogue {
1065
+ [name: string]: ConstructorRepresentation
1066
+ }
1067
+
1068
+ // TODO: handle constructor overloads
1069
+ // https://github.com/pmndrs/react-three-fiber/pull/2931
1070
+ // https://github.com/microsoft/TypeScript/issues/37079
1071
+ type Args<T> = T extends ConstructorRepresentation
1072
+ ? T extends typeof Color$1
1073
+ ? [r: number, g: number, b: number] | [color: ColorRepresentation]
1074
+ : ConstructorParameters<T>
1075
+ : any[]
1076
+
1077
+ type ArgsProp<P> = P extends ConstructorRepresentation
1078
+ ? IsAllOptional<ConstructorParameters<P>> extends true
1079
+ ? { args?: Args<P> }
1080
+ : { args: Args<P> }
1081
+ : { args: unknown[] }
1082
+
1083
+ type InstanceProps<T = any, P = any> = ArgsProp<P> & {
1084
+ object?: T
1085
+ dispose?: null
1086
+ attach?: AttachType<T>
1087
+ onUpdate?: (self: T) => void
1088
+ }
1089
+
1090
+ interface Instance<O = any> {
1091
+ root: RootStore
1092
+ type: string
1093
+ parent: Instance | null
1094
+ children: Instance[]
1095
+ props: InstanceProps<O> & Record<string, unknown>
1096
+ object: O & { __r3f?: Instance<O> }
1097
+ eventCount: number
1098
+ handlers: Partial<EventHandlers>
1099
+ attach?: AttachType<O>
1100
+ previousAttach?: any
1101
+ isHidden: boolean
1102
+ /** Deferred ref props to apply in commitMount */
1103
+ deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1104
+ /** Set of props that have been applied via once() */
1105
+ appliedOnce?: Set<string>
1126
1106
  }
1127
1107
 
1128
- //* Loop Types ==============================
1129
-
1130
- type GlobalRenderCallback = (timestamp: number) => void
1131
-
1108
+ interface HostConfig {
1109
+ type: string
1110
+ props: Instance['props']
1111
+ container: RootStore
1112
+ instance: Instance
1113
+ textInstance: void
1114
+ suspenseInstance: Instance
1115
+ hydratableInstance: never
1116
+ formInstance: never
1117
+ publicInstance: Instance['object']
1118
+ hostContext: {}
1119
+ childSet: never
1120
+ timeoutHandle: number | undefined
1121
+ noTimeout: -1
1122
+ TransitionStatus: null
1123
+ }
1124
+ declare global {
1125
+ var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
1126
+ }
1127
+
1128
+ //* Loop Types ==============================
1129
+
1130
+ type GlobalRenderCallback = (timestamp: number) => void
1131
+
1132
1132
  type GlobalEffectType = 'before' | 'after' | 'tail'
1133
1133
 
1134
1134
  declare const presetsObj: {
@@ -1145,647 +1145,647 @@ declare const presetsObj: {
1145
1145
  };
1146
1146
  type PresetsType = keyof typeof presetsObj;
1147
1147
 
1148
- //* Background Types ==============================
1149
-
1150
- /**
1151
- * Expanded object form for background configuration.
1152
- * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
1153
- */
1154
- interface BackgroundConfig {
1155
- /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
1156
- preset?: PresetsType
1157
- /** Files for cube texture (6 faces) or single HDR/EXR */
1158
- files?: string | string[]
1159
- /** Separate files for scene.background (visual backdrop) */
1160
- backgroundMap?: string | string[]
1161
- backgroundRotation?: Euler$1 | [number, number, number]
1162
- backgroundBlurriness?: number
1163
- backgroundIntensity?: number
1164
- /** Separate files for scene.environment (PBR lighting/reflections) */
1165
- envMap?: string | string[]
1166
- environmentRotation?: Euler$1 | [number, number, number]
1167
- environmentIntensity?: number
1168
- path?: string
1169
- extensions?: (loader: Loader) => void
1170
- }
1171
-
1172
- /**
1173
- * Background prop type for Canvas.
1174
- *
1175
- * String detection priority:
1176
- * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1177
- * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
1178
- * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
1179
- *
1180
- * @example Color
1181
- * ```tsx
1182
- * <Canvas background="red" />
1183
- * <Canvas background="#ff0000" />
1184
- * <Canvas background={0xff0000} />
1185
- * ```
1186
- *
1187
- * @example Preset
1188
- * ```tsx
1189
- * <Canvas background="city" />
1190
- * ```
1191
- *
1192
- * @example URL
1193
- * ```tsx
1194
- * <Canvas background="/path/to/env.hdr" />
1195
- * <Canvas background="./sky.jpg" />
1196
- * ```
1197
- *
1198
- * @example Object form
1199
- * ```tsx
1200
- * <Canvas background={{
1201
- * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1202
- * backgroundMap: 'path/to/sky.jpg',
1203
- * envMap: 'path/to/lighting.hdr',
1204
- * backgroundBlurriness: 0.5,
1205
- * }} />
1206
- * ```
1207
- */
1208
- type BackgroundProp =
1209
- | ColorRepresentation // "red", "#ff0000", 0xff0000
1210
- | string // URL or preset
1211
- | BackgroundConfig // Expanded object form
1212
-
1213
- //* Canvas Types ==============================
1214
-
1215
- interface CanvasProps
1216
- extends
1217
- Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1218
- React$1.HTMLAttributes<HTMLDivElement> {
1219
- children?: React$1.ReactNode
1220
- ref?: React$1.Ref<HTMLCanvasElement>
1221
- /** Canvas fallback content, similar to img's alt prop */
1222
- fallback?: React$1.ReactNode
1223
- /**
1224
- * Options to pass to useMeasure.
1225
- * @see https://github.com/pmndrs/react-use-measure#api
1226
- */
1227
- resize?: Options
1228
- /** The target where events are being subscribed to, default: the div that wraps canvas */
1229
- eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1230
- /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1231
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1232
- /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1233
- hmr?: boolean
1234
- /** Canvas resolution width in pixels. If omitted, uses container width. */
1235
- width?: number
1236
- /** Canvas resolution height in pixels. If omitted, uses container height. */
1237
- height?: number
1238
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1239
- forceEven?: boolean
1240
- /**
1241
- * Scene background configuration.
1242
- * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1243
- * @see BackgroundProp for full documentation and examples
1244
- */
1245
- background?: BackgroundProp
1148
+ //* Background Types ==============================
1149
+
1150
+ /**
1151
+ * Expanded object form for background configuration.
1152
+ * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
1153
+ */
1154
+ interface BackgroundConfig {
1155
+ /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
1156
+ preset?: PresetsType
1157
+ /** Files for cube texture (6 faces) or single HDR/EXR */
1158
+ files?: string | string[]
1159
+ /** Separate files for scene.background (visual backdrop) */
1160
+ backgroundMap?: string | string[]
1161
+ backgroundRotation?: Euler$1 | [number, number, number]
1162
+ backgroundBlurriness?: number
1163
+ backgroundIntensity?: number
1164
+ /** Separate files for scene.environment (PBR lighting/reflections) */
1165
+ envMap?: string | string[]
1166
+ environmentRotation?: Euler$1 | [number, number, number]
1167
+ environmentIntensity?: number
1168
+ path?: string
1169
+ extensions?: (loader: Loader) => void
1246
1170
  }
1247
1171
 
1248
- //* Loader Types ==============================
1249
-
1250
- type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1251
-
1252
- // Define a loader-like interface that matches THREE.Loader's load signature
1253
- // This works for both generic and non-generic THREE.Loader instances
1254
- interface LoaderLike {
1255
- load(
1256
- url: InputLike,
1257
- onLoad?: (result: any) => void,
1258
- onProgress?: (event: ProgressEvent<EventTarget>) => void,
1259
- onError?: (error: unknown) => void,
1260
- ): any
1261
- }
1262
-
1263
- type GLTFLike = { scene: THREE$1.Object3D }
1264
-
1265
- type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1266
- T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1267
-
1268
- // Infer result type from the load method's callback parameter
1269
- type InferLoadResult<T> = T extends {
1270
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1271
- }
1272
- ? R
1273
- : T extends ConstructorRepresentation<any>
1274
- ? InstanceType<T> extends {
1275
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1276
- }
1277
- ? R
1278
- : any
1279
- : any
1280
-
1281
- type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1282
- InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1283
-
1284
- type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1285
- loader: LoaderInstance<T>,
1172
+ /**
1173
+ * Background prop type for Canvas.
1174
+ *
1175
+ * String detection priority:
1176
+ * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1177
+ * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
1178
+ * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
1179
+ *
1180
+ * @example Color
1181
+ * ```tsx
1182
+ * <Canvas background="red" />
1183
+ * <Canvas background="#ff0000" />
1184
+ * <Canvas background={0xff0000} />
1185
+ * ```
1186
+ *
1187
+ * @example Preset
1188
+ * ```tsx
1189
+ * <Canvas background="city" />
1190
+ * ```
1191
+ *
1192
+ * @example URL
1193
+ * ```tsx
1194
+ * <Canvas background="/path/to/env.hdr" />
1195
+ * <Canvas background="./sky.jpg" />
1196
+ * ```
1197
+ *
1198
+ * @example Object form
1199
+ * ```tsx
1200
+ * <Canvas background={{
1201
+ * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1202
+ * backgroundMap: 'path/to/sky.jpg',
1203
+ * envMap: 'path/to/lighting.hdr',
1204
+ * backgroundBlurriness: 0.5,
1205
+ * }} />
1206
+ * ```
1207
+ */
1208
+ type BackgroundProp =
1209
+ | ColorRepresentation // "red", "#ff0000", 0xff0000
1210
+ | string // URL or preset
1211
+ | BackgroundConfig // Expanded object form
1212
+
1213
+ //* Canvas Types ==============================
1214
+
1215
+ interface CanvasProps
1216
+ extends
1217
+ Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1218
+ React$1.HTMLAttributes<HTMLDivElement> {
1219
+ children?: React$1.ReactNode
1220
+ ref?: React$1.Ref<HTMLCanvasElement>
1221
+ /** Canvas fallback content, similar to img's alt prop */
1222
+ fallback?: React$1.ReactNode
1223
+ /**
1224
+ * Options to pass to useMeasure.
1225
+ * @see https://github.com/pmndrs/react-use-measure#api
1226
+ */
1227
+ resize?: Options
1228
+ /** The target where events are being subscribed to, default: the div that wraps canvas */
1229
+ eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1230
+ /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1231
+ eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1232
+ /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1233
+ hmr?: boolean
1234
+ /** Canvas resolution width in pixels. If omitted, uses container width. */
1235
+ width?: number
1236
+ /** Canvas resolution height in pixels. If omitted, uses container height. */
1237
+ height?: number
1238
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1239
+ forceEven?: boolean
1240
+ /**
1241
+ * Scene background configuration.
1242
+ * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1243
+ * @see BackgroundProp for full documentation and examples
1244
+ */
1245
+ background?: BackgroundProp
1246
+ }
1247
+
1248
+ //* Loader Types ==============================
1249
+
1250
+ type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1251
+
1252
+ // Define a loader-like interface that matches THREE.Loader's load signature
1253
+ // This works for both generic and non-generic THREE.Loader instances
1254
+ interface LoaderLike {
1255
+ load(
1256
+ url: InputLike,
1257
+ onLoad?: (result: any) => void,
1258
+ onProgress?: (event: ProgressEvent<EventTarget>) => void,
1259
+ onError?: (error: unknown) => void,
1260
+ ): any
1261
+ }
1262
+
1263
+ type GLTFLike = { scene: THREE$1.Object3D }
1264
+
1265
+ type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1266
+ T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1267
+
1268
+ // Infer result type from the load method's callback parameter
1269
+ type InferLoadResult<T> = T extends {
1270
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1271
+ }
1272
+ ? R
1273
+ : T extends ConstructorRepresentation<any>
1274
+ ? InstanceType<T> extends {
1275
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1276
+ }
1277
+ ? R
1278
+ : any
1279
+ : any
1280
+
1281
+ type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1282
+ InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1283
+
1284
+ type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1285
+ loader: LoaderInstance<T>,
1286
1286
  ) => void
1287
1287
 
1288
- //* Renderer Props ========================================
1289
-
1290
- type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1291
-
1292
- type WebGLProps =
1293
- | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1294
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1295
-
1296
- interface WebGLShadowConfig {
1297
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1298
- }
1299
-
1300
- //* Legacy-specific Types ========================================
1301
-
1302
- /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1303
- type LegacyRenderer = THREE$1.WebGLRenderer
1304
-
1305
- /** Legacy internal state with narrowed renderer type */
1306
- interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1307
- actualRenderer: THREE$1.WebGLRenderer
1308
- }
1309
-
1310
- /**
1311
- * Legacy-specific RootState with narrowed renderer type.
1312
- * Automatically used when importing from `@react-three/fiber/legacy`.
1313
- *
1314
- * @example
1315
- * ```tsx
1316
- * import { useThree } from '@react-three/fiber/legacy'
1317
- *
1318
- * function MyComponent() {
1319
- * const { renderer } = useThree()
1320
- * // renderer is typed as THREE.WebGLRenderer
1321
- * renderer.shadowMap.enabled = true
1322
- * }
1323
- * ```
1324
- */
1325
- interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1326
- /** The WebGL renderer instance */
1327
- renderer: THREE$1.WebGLRenderer
1328
- /** Internals with WebGL renderer */
1329
- internal: LegacyInternalState
1288
+ //* Renderer Props ========================================
1289
+
1290
+ type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1291
+
1292
+ type WebGLProps =
1293
+ | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1294
+ | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1295
+
1296
+ interface WebGLShadowConfig {
1297
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1330
1298
  }
1331
1299
 
1332
- //* RenderTarget Types ==============================
1333
-
1334
-
1300
+ //* Legacy-specific Types ========================================
1301
+
1302
+ /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1303
+ type LegacyRenderer = THREE$1.WebGLRenderer
1304
+
1305
+ /** Legacy internal state with narrowed renderer type */
1306
+ interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1307
+ actualRenderer: THREE$1.WebGLRenderer
1308
+ }
1309
+
1310
+ /**
1311
+ * Legacy-specific RootState with narrowed renderer type.
1312
+ * Automatically used when importing from `@react-three/fiber/legacy`.
1313
+ *
1314
+ * @example
1315
+ * ```tsx
1316
+ * import { useThree } from '@react-three/fiber/legacy'
1317
+ *
1318
+ * function MyComponent() {
1319
+ * const { renderer } = useThree()
1320
+ * // renderer is typed as THREE.WebGLRenderer
1321
+ * renderer.shadowMap.enabled = true
1322
+ * }
1323
+ * ```
1324
+ */
1325
+ interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1326
+ /** The WebGL renderer instance */
1327
+ renderer: THREE$1.WebGLRenderer
1328
+ /** Internals with WebGL renderer */
1329
+ internal: LegacyInternalState
1330
+ }
1331
+
1332
+ //* RenderTarget Types ==============================
1333
+
1334
+
1335
1335
  type RenderTargetOptions = RenderTargetOptions$1
1336
1336
 
1337
- //* Global Types ==============================
1338
-
1339
- declare global {
1340
- /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1341
- interface UniformNode<T = unknown> extends Node {
1342
- value: T
1343
- }
1344
-
1345
- /**
1346
- * ShaderCallable - the return type of Fn()
1347
- * A callable shader function node that can be invoked with parameters.
1348
- * The function returns a ShaderNodeObject when called.
1349
- *
1350
- * @example
1351
- * ```tsx
1352
- * // Define a shader function
1353
- * const blendColorFn = Fn(([color1, color2, factor]) => {
1354
- * return mix(color1, color2, factor)
1355
- * })
1356
- *
1357
- * // Type when retrieving from nodes store
1358
- * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1359
- *
1360
- * // Or with specific return type
1361
- * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1362
- * ```
1363
- */
1364
- type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1365
-
1366
- /**
1367
- * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1368
- * This is the common return type for TSL operations (add, mul, sin, etc.)
1369
- *
1370
- * @example
1371
- * ```tsx
1372
- * const { wobble } = nodes as { wobble: ShaderNodeRef }
1373
- * ```
1374
- */
1375
- type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1376
-
1377
- /**
1378
- * TSLNodeType - Union of all common TSL node types
1379
- * Used by ScopedStore to properly type node access from the store.
1380
- *
1381
- * Includes:
1382
- * - Node: base Three.js node type
1383
- * - ShaderCallable: function nodes created with Fn()
1384
- * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1385
- *
1386
- * @example
1387
- * ```tsx
1388
- * // In useLocalNodes, nodes are typed as TSLNodeType
1389
- * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1390
- * positionNode: nodes.myPosition, // Works - Node is in union
1391
- * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1392
- * }))
1393
- *
1394
- * // Can narrow with type guard or assertion when needed
1395
- * if (typeof blendColorFn === 'function') {
1396
- * blendColorFn(someColor, 0.5)
1397
- * }
1398
- * ```
1399
- */
1400
- type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1401
-
1402
- /** Flat record of uniform nodes (no nested scopes) */
1403
- type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1404
-
1405
- /**
1406
- * Uniform store that can contain both root-level uniforms and scoped uniform objects
1407
- * Used by state.uniforms which has structure like:
1408
- * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1409
- */
1410
- type UniformStore = Record<string, UniformNode | UniformRecord>
1411
-
1412
- /**
1413
- * Helper to safely access a uniform node from the store.
1414
- * Use this when accessing state.uniforms to get proper typing.
1415
- * @example
1416
- * const uTime = uniforms.uTime as UniformNode<number>
1417
- * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1418
- */
1419
- type GetUniform<T = unknown> = UniformNode<T>
1420
-
1421
- /**
1422
- * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1423
- * Supports:
1424
- * - Primitives: number, string (color), boolean
1425
- * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1426
- * - Plain objects: { x, y, z, w } converted to vectors
1427
- * - TSL nodes: color(), vec3(), float() for type casting
1428
- * - UniformNode: existing uniforms (reused as-is)
1429
- */
1430
- type UniformValue =
1431
- | number
1432
- | string
1433
- | boolean
1434
- | three_webgpu.Color
1435
- | three_webgpu.Vector2
1436
- | three_webgpu.Vector3
1437
- | three_webgpu.Vector4
1438
- | three_webgpu.Matrix3
1439
- | three_webgpu.Matrix4
1440
- | three_webgpu.Euler
1441
- | three_webgpu.Quaternion
1442
- | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1443
- | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1444
- | Node // TSL nodes like color(), vec3(), float() for type casting
1445
- | UniformNode
1446
-
1447
- /** Input record for useUniforms - accepts raw values or UniformNodes */
1448
- type UniformInputRecord = Record<string, UniformValue>
1449
- }
1450
-
1451
- //* Module Augmentation ==============================
1452
-
1453
- declare module 'three/tsl' {
1454
- /**
1455
- * Fn with array parameter destructuring
1456
- * @example Fn(([uv, skew]) => { ... })
1457
- */
1458
- export function Fn<R extends Node = Node>(
1459
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1460
- ): ShaderCallable<R>
1461
-
1462
- /**
1463
- * Fn with object parameter destructuring
1464
- * @example Fn(({ color, intensity }) => { ... })
1465
- */
1466
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1467
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1468
- ): ShaderCallable<R>
1469
-
1470
- /**
1471
- * Fn with array params + layout
1472
- * @example Fn(([a, b]) => { ... }, { layout: [...] })
1473
- */
1474
- export function Fn<R extends Node = Node>(
1475
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1476
- layout: { layout?: unknown },
1477
- ): ShaderCallable<R>
1478
-
1479
- /**
1480
- * Fn with object params + layout
1481
- */
1482
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1483
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1484
- layout: { layout?: unknown },
1485
- ): ShaderCallable<R>
1337
+ //* Global Types ==============================
1338
+
1339
+ declare global {
1340
+ /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1341
+ interface UniformNode<T = unknown> extends Node {
1342
+ value: T
1343
+ }
1344
+
1345
+ /**
1346
+ * ShaderCallable - the return type of Fn()
1347
+ * A callable shader function node that can be invoked with parameters.
1348
+ * The function returns a ShaderNodeObject when called.
1349
+ *
1350
+ * @example
1351
+ * ```tsx
1352
+ * // Define a shader function
1353
+ * const blendColorFn = Fn(([color1, color2, factor]) => {
1354
+ * return mix(color1, color2, factor)
1355
+ * })
1356
+ *
1357
+ * // Type when retrieving from nodes store
1358
+ * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1359
+ *
1360
+ * // Or with specific return type
1361
+ * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1362
+ * ```
1363
+ */
1364
+ type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1365
+
1366
+ /**
1367
+ * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1368
+ * This is the common return type for TSL operations (add, mul, sin, etc.)
1369
+ *
1370
+ * @example
1371
+ * ```tsx
1372
+ * const { wobble } = nodes as { wobble: ShaderNodeRef }
1373
+ * ```
1374
+ */
1375
+ type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1376
+
1377
+ /**
1378
+ * TSLNodeType - Union of all common TSL node types
1379
+ * Used by ScopedStore to properly type node access from the store.
1380
+ *
1381
+ * Includes:
1382
+ * - Node: base Three.js node type
1383
+ * - ShaderCallable: function nodes created with Fn()
1384
+ * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1385
+ *
1386
+ * @example
1387
+ * ```tsx
1388
+ * // In useLocalNodes, nodes are typed as TSLNodeType
1389
+ * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1390
+ * positionNode: nodes.myPosition, // Works - Node is in union
1391
+ * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1392
+ * }))
1393
+ *
1394
+ * // Can narrow with type guard or assertion when needed
1395
+ * if (typeof blendColorFn === 'function') {
1396
+ * blendColorFn(someColor, 0.5)
1397
+ * }
1398
+ * ```
1399
+ */
1400
+ type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1401
+
1402
+ /** Flat record of uniform nodes (no nested scopes) */
1403
+ type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1404
+
1405
+ /**
1406
+ * Uniform store that can contain both root-level uniforms and scoped uniform objects
1407
+ * Used by state.uniforms which has structure like:
1408
+ * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1409
+ */
1410
+ type UniformStore = Record<string, UniformNode | UniformRecord>
1411
+
1412
+ /**
1413
+ * Helper to safely access a uniform node from the store.
1414
+ * Use this when accessing state.uniforms to get proper typing.
1415
+ * @example
1416
+ * const uTime = uniforms.uTime as UniformNode<number>
1417
+ * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1418
+ */
1419
+ type GetUniform<T = unknown> = UniformNode<T>
1420
+
1421
+ /**
1422
+ * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1423
+ * Supports:
1424
+ * - Primitives: number, string (color), boolean
1425
+ * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1426
+ * - Plain objects: { x, y, z, w } converted to vectors
1427
+ * - TSL nodes: color(), vec3(), float() for type casting
1428
+ * - UniformNode: existing uniforms (reused as-is)
1429
+ */
1430
+ type UniformValue =
1431
+ | number
1432
+ | string
1433
+ | boolean
1434
+ | three_webgpu.Color
1435
+ | three_webgpu.Vector2
1436
+ | three_webgpu.Vector3
1437
+ | three_webgpu.Vector4
1438
+ | three_webgpu.Matrix3
1439
+ | three_webgpu.Matrix4
1440
+ | three_webgpu.Euler
1441
+ | three_webgpu.Quaternion
1442
+ | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1443
+ | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1444
+ | Node // TSL nodes like color(), vec3(), float() for type casting
1445
+ | UniformNode
1446
+
1447
+ /** Input record for useUniforms - accepts raw values or UniformNodes */
1448
+ type UniformInputRecord = Record<string, UniformValue>
1449
+ }
1450
+
1451
+ //* Module Augmentation ==============================
1452
+
1453
+ declare module 'three/tsl' {
1454
+ /**
1455
+ * Fn with array parameter destructuring
1456
+ * @example Fn(([uv, skew]) => { ... })
1457
+ */
1458
+ export function Fn<R extends Node = Node>(
1459
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1460
+ ): ShaderCallable<R>
1461
+
1462
+ /**
1463
+ * Fn with object parameter destructuring
1464
+ * @example Fn(({ color, intensity }) => { ... })
1465
+ */
1466
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1467
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1468
+ ): ShaderCallable<R>
1469
+
1470
+ /**
1471
+ * Fn with array params + layout
1472
+ * @example Fn(([a, b]) => { ... }, { layout: [...] })
1473
+ */
1474
+ export function Fn<R extends Node = Node>(
1475
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1476
+ layout: { layout?: unknown },
1477
+ ): ShaderCallable<R>
1478
+
1479
+ /**
1480
+ * Fn with object params + layout
1481
+ */
1482
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1483
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1484
+ layout: { layout?: unknown },
1485
+ ): ShaderCallable<R>
1486
+ }
1487
+
1488
+ /**
1489
+ * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1490
+ */
1491
+
1492
+
1493
+
1494
+ declare global {
1495
+ /** Pass record - stores TSL pass nodes for render pipeline */
1496
+ type PassRecord = Record<string, any>
1497
+
1498
+ /** Setup callback - runs first to configure MRT, create additional passes */
1499
+ type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1500
+
1501
+ /** Main callback - runs second to configure outputNode, create effect passes */
1502
+ type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1503
+
1504
+ /** Return type for useRenderPipeline hook */
1505
+ interface UseRenderPipelineReturn {
1506
+ /** Current passes from state */
1507
+ passes: PassRecord
1508
+ /** RenderPipeline instance (null if not initialized) */
1509
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1510
+ /** Clear all passes from state */
1511
+ clearPasses: () => void
1512
+ /** Reset RenderPipeline entirely (clears PP + passes) */
1513
+ reset: () => void
1514
+ /** Re-run setup/main callbacks with current closure values */
1515
+ rebuild: () => void
1516
+ /** True when RenderPipeline is configured and ready */
1517
+ isReady: boolean
1518
+ }
1519
+ }
1520
+
1521
+ //* useFrameNext Types ==============================
1522
+
1523
+
1524
+
1525
+ //* Global Type Declarations ==============================
1526
+
1527
+ declare global {
1528
+ // Job --------------------------------
1529
+
1530
+ /**
1531
+ * Internal job representation in the scheduler
1532
+ */
1533
+ interface Job {
1534
+ /** Unique identifier */
1535
+ id: string
1536
+ /** The callback to execute */
1537
+ callback: FrameNextCallback
1538
+ /** Phase this job belongs to */
1539
+ phase: string
1540
+ /** Run before these phases/job ids */
1541
+ before: Set<string>
1542
+ /** Run after these phases/job ids */
1543
+ after: Set<string>
1544
+ /** Priority within phase (higher first) */
1545
+ priority: number
1546
+ /** Insertion order for deterministic tie-breaking */
1547
+ index: number
1548
+ /** Max FPS for this job (undefined = no limit) */
1549
+ fps?: number
1550
+ /** Drop frames when behind (true) or catch up (false) */
1551
+ drop: boolean
1552
+ /** Last run timestamp (ms) */
1553
+ lastRun?: number
1554
+ /** Whether job is enabled */
1555
+ enabled: boolean
1556
+ /** Internal flag: system jobs (like default render) don't block user render takeover */
1557
+ system?: boolean
1558
+ }
1559
+
1560
+ // Phase Graph --------------------------------
1561
+
1562
+ /**
1563
+ * A node in the phase graph
1564
+ */
1565
+ interface PhaseNode {
1566
+ /** Phase name */
1567
+ name: string
1568
+ /** Whether this was auto-generated from a before/after constraint */
1569
+ isAutoGenerated: boolean
1570
+ }
1571
+
1572
+ /**
1573
+ * Options for creating a job from hook options
1574
+ */
1575
+ interface JobOptions {
1576
+ id?: string
1577
+ phase?: string
1578
+ before?: string | string[]
1579
+ after?: string | string[]
1580
+ priority?: number
1581
+ fps?: number
1582
+ drop?: boolean
1583
+ enabled?: boolean
1584
+ }
1585
+
1586
+ // Frame Loop State --------------------------------
1587
+
1588
+ /**
1589
+ * Internal frame loop state
1590
+ */
1591
+ interface FrameLoopState {
1592
+ /** Whether the loop is running */
1593
+ running: boolean
1594
+ /** Current RAF handle */
1595
+ rafHandle: number | null
1596
+ /** Last frame timestamp in ms (null = uninitialized) */
1597
+ lastTime: number | null
1598
+ /** Frame counter */
1599
+ frameCount: number
1600
+ /** Elapsed time since first frame in ms */
1601
+ elapsedTime: number
1602
+ /** createdAt timestamp in ms */
1603
+ createdAt: number
1604
+ }
1605
+
1606
+ // Root Entry --------------------------------
1607
+
1608
+ /**
1609
+ * Internal representation of a registered root (Canvas).
1610
+ * Tracks jobs and manages rebuild state for this root.
1611
+ * @internal
1612
+ */
1613
+ interface RootEntry {
1614
+ /** Unique identifier for this root */
1615
+ id: string
1616
+ /** Function to get the root's current state. Returns any to support independent mode. */
1617
+ getState: () => any
1618
+ /** Map of job IDs to Job objects */
1619
+ jobs: Map<string, Job>
1620
+ /** Cached sorted job list for execution order */
1621
+ sortedJobs: Job[]
1622
+ /** Whether sortedJobs needs rebuilding */
1623
+ needsRebuild: boolean
1624
+ }
1625
+
1626
+ /**
1627
+ * Internal representation of a global job (deprecated API).
1628
+ * Global jobs run once per frame, not per-root.
1629
+ * Used by legacy addEffect/addAfterEffect APIs.
1630
+ * @internal
1631
+ * @deprecated Use useFrame with phases instead
1632
+ */
1633
+ interface GlobalJob {
1634
+ /** Unique identifier for this global job */
1635
+ id: string
1636
+ /** Callback invoked with RAF timestamp in ms */
1637
+ callback: (timestamp: number) => void
1638
+ }
1639
+
1640
+ // HMR Support --------------------------------
1641
+
1642
+ /**
1643
+ * Hot Module Replacement data structure for preserving scheduler state
1644
+ * @internal
1645
+ */
1646
+ interface HMRData {
1647
+ /** Shared data object for storing values across reloads */
1648
+ data: Record<string, any>
1649
+ /** Optional function to accept HMR updates */
1650
+ accept?: () => void
1651
+ }
1652
+
1653
+ // Default Phases --------------------------------
1654
+
1655
+ /**
1656
+ * Default phase names for the scheduler
1657
+ */
1658
+ type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1659
+ }
1660
+
1661
+ type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1662
+
1663
+ interface MathRepresentation {
1664
+ set(...args: number[]): any
1665
+ }
1666
+ interface VectorRepresentation extends MathRepresentation {
1667
+ setScalar(value: number): any
1668
+ }
1669
+ type MathTypes = MathRepresentation | Euler$2 | Color$2
1670
+
1671
+ type MathType<T extends MathTypes> = T extends Color$2
1672
+ ? Args<typeof Color$2> | ColorRepresentation$1
1673
+ : T extends VectorRepresentation | Layers$1 | Euler$2
1674
+ ? T | MutableOrReadonlyParameters<T['set']> | number
1675
+ : T | MutableOrReadonlyParameters<T['set']>
1676
+
1677
+ type MathProps<P> = {
1678
+ [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1679
+ }
1680
+
1681
+ type Vector2 = MathType<Vector2$1>
1682
+ type Vector3 = MathType<Vector3$1>
1683
+ type Vector4 = MathType<Vector4$1>
1684
+ type Color = MathType<Color$2>
1685
+ type Layers = MathType<Layers$1>
1686
+ type Quaternion = MathType<Quaternion$1>
1687
+ type Euler = MathType<Euler$2>
1688
+ type Matrix3 = MathType<Matrix3$1>
1689
+ type Matrix4 = MathType<Matrix4$1>
1690
+
1691
+ interface RaycastableRepresentation {
1692
+ raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1693
+ }
1694
+ type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1695
+
1696
+ /**
1697
+ * Props for geometry transform methods that can be called with `once()`.
1698
+ * These methods modify the geometry in-place and only make sense to call once on mount.
1699
+ *
1700
+ * @example
1701
+ * import { once } from '@react-three/fiber'
1702
+ *
1703
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1704
+ * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1705
+ * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1706
+ */
1707
+ interface GeometryTransformProps {
1708
+ /** Rotate the geometry about the X axis (radians). Use with once(). */
1709
+ rotateX?: number
1710
+ /** Rotate the geometry about the Y axis (radians). Use with once(). */
1711
+ rotateY?: number
1712
+ /** Rotate the geometry about the Z axis (radians). Use with once(). */
1713
+ rotateZ?: number
1714
+ /** Translate the geometry (x, y, z). Use with once(). */
1715
+ translate?: [x: number, y: number, z: number]
1716
+ /** Scale the geometry (x, y, z). Use with once(). */
1717
+ scale?: [x: number, y: number, z: number]
1718
+ /** Center the geometry based on bounding box. Use with once(). */
1719
+ center?: true
1720
+ /** Apply a Matrix4 transformation. Use with once(). */
1721
+ applyMatrix4?: Matrix4$1
1722
+ /** Apply a Quaternion rotation. Use with once(). */
1723
+ applyQuaternion?: Quaternion$1
1724
+ }
1725
+
1726
+ type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1727
+
1728
+ /**
1729
+ * Workaround for @types/three TSL node type issues.
1730
+ * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1731
+ * This transforms `Node | null` properties to accept any object with node-like shape.
1732
+ */
1733
+ type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1734
+
1735
+ /**
1736
+ * For node material properties (colorNode, positionNode, etc.), accept broader types
1737
+ * since @types/three has broken inheritance for TSL node subclasses.
1738
+ */
1739
+ type NodeProps<P> = {
1740
+ [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1741
+ }
1742
+
1743
+ interface ReactProps<P> {
1744
+ children?: React.ReactNode
1745
+ ref?: React.Ref<P>
1746
+ key?: React.Key
1747
+ }
1748
+
1749
+ type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1750
+ Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1751
+ >
1752
+
1753
+ type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1754
+ Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1755
+ >
1756
+
1757
+ type ThreeToJSXElements<T extends Record<string, any>> = {
1758
+ [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1759
+ }
1760
+
1761
+ type ThreeExports = typeof import('three/webgpu')
1762
+ type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1763
+
1764
+ interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1765
+ primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1766
+ // Conflicts with DOM types can be accessed through a three* prefix
1767
+ threeAudio: ThreeElementsImpl['audio']
1768
+ threeSource: ThreeElementsImpl['source']
1769
+ threeLine: ThreeElementsImpl['line']
1770
+ threePath: ThreeElementsImpl['path']
1486
1771
  }
1487
1772
 
1488
- /**
1489
- * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1490
- */
1491
-
1492
-
1493
-
1494
- declare global {
1495
- /** Pass record - stores TSL pass nodes for render pipeline */
1496
- type PassRecord = Record<string, any>
1497
-
1498
- /** Setup callback - runs first to configure MRT, create additional passes */
1499
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1500
-
1501
- /** Main callback - runs second to configure outputNode, create effect passes */
1502
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1503
-
1504
- /** Return type for useRenderPipeline hook */
1505
- interface UseRenderPipelineReturn {
1506
- /** Current passes from state */
1507
- passes: PassRecord
1508
- /** RenderPipeline instance (null if not initialized) */
1509
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1510
- /** Clear all passes from state */
1511
- clearPasses: () => void
1512
- /** Reset RenderPipeline entirely (clears PP + passes) */
1513
- reset: () => void
1514
- /** Re-run setup/main callbacks with current closure values */
1515
- rebuild: () => void
1516
- /** True when RenderPipeline is configured and ready */
1517
- isReady: boolean
1518
- }
1773
+ declare module 'react' {
1774
+ namespace JSX {
1775
+ interface IntrinsicElements extends ThreeElements {}
1776
+ }
1519
1777
  }
1520
1778
 
1521
- //* useFrameNext Types ==============================
1522
-
1523
-
1524
-
1525
- //* Global Type Declarations ==============================
1526
-
1527
- declare global {
1528
- // Job --------------------------------
1529
-
1530
- /**
1531
- * Internal job representation in the scheduler
1532
- */
1533
- interface Job {
1534
- /** Unique identifier */
1535
- id: string
1536
- /** The callback to execute */
1537
- callback: FrameNextCallback
1538
- /** Phase this job belongs to */
1539
- phase: string
1540
- /** Run before these phases/job ids */
1541
- before: Set<string>
1542
- /** Run after these phases/job ids */
1543
- after: Set<string>
1544
- /** Priority within phase (higher first) */
1545
- priority: number
1546
- /** Insertion order for deterministic tie-breaking */
1547
- index: number
1548
- /** Max FPS for this job (undefined = no limit) */
1549
- fps?: number
1550
- /** Drop frames when behind (true) or catch up (false) */
1551
- drop: boolean
1552
- /** Last run timestamp (ms) */
1553
- lastRun?: number
1554
- /** Whether job is enabled */
1555
- enabled: boolean
1556
- /** Internal flag: system jobs (like default render) don't block user render takeover */
1557
- system?: boolean
1558
- }
1559
-
1560
- // Phase Graph --------------------------------
1561
-
1562
- /**
1563
- * A node in the phase graph
1564
- */
1565
- interface PhaseNode {
1566
- /** Phase name */
1567
- name: string
1568
- /** Whether this was auto-generated from a before/after constraint */
1569
- isAutoGenerated: boolean
1570
- }
1571
-
1572
- /**
1573
- * Options for creating a job from hook options
1574
- */
1575
- interface JobOptions {
1576
- id?: string
1577
- phase?: string
1578
- before?: string | string[]
1579
- after?: string | string[]
1580
- priority?: number
1581
- fps?: number
1582
- drop?: boolean
1583
- enabled?: boolean
1584
- }
1585
-
1586
- // Frame Loop State --------------------------------
1587
-
1588
- /**
1589
- * Internal frame loop state
1590
- */
1591
- interface FrameLoopState {
1592
- /** Whether the loop is running */
1593
- running: boolean
1594
- /** Current RAF handle */
1595
- rafHandle: number | null
1596
- /** Last frame timestamp in ms (null = uninitialized) */
1597
- lastTime: number | null
1598
- /** Frame counter */
1599
- frameCount: number
1600
- /** Elapsed time since first frame in ms */
1601
- elapsedTime: number
1602
- /** createdAt timestamp in ms */
1603
- createdAt: number
1604
- }
1605
-
1606
- // Root Entry --------------------------------
1607
-
1608
- /**
1609
- * Internal representation of a registered root (Canvas).
1610
- * Tracks jobs and manages rebuild state for this root.
1611
- * @internal
1612
- */
1613
- interface RootEntry {
1614
- /** Unique identifier for this root */
1615
- id: string
1616
- /** Function to get the root's current state. Returns any to support independent mode. */
1617
- getState: () => any
1618
- /** Map of job IDs to Job objects */
1619
- jobs: Map<string, Job>
1620
- /** Cached sorted job list for execution order */
1621
- sortedJobs: Job[]
1622
- /** Whether sortedJobs needs rebuilding */
1623
- needsRebuild: boolean
1624
- }
1625
-
1626
- /**
1627
- * Internal representation of a global job (deprecated API).
1628
- * Global jobs run once per frame, not per-root.
1629
- * Used by legacy addEffect/addAfterEffect APIs.
1630
- * @internal
1631
- * @deprecated Use useFrame with phases instead
1632
- */
1633
- interface GlobalJob {
1634
- /** Unique identifier for this global job */
1635
- id: string
1636
- /** Callback invoked with RAF timestamp in ms */
1637
- callback: (timestamp: number) => void
1638
- }
1639
-
1640
- // HMR Support --------------------------------
1641
-
1642
- /**
1643
- * Hot Module Replacement data structure for preserving scheduler state
1644
- * @internal
1645
- */
1646
- interface HMRData {
1647
- /** Shared data object for storing values across reloads */
1648
- data: Record<string, any>
1649
- /** Optional function to accept HMR updates */
1650
- accept?: () => void
1651
- }
1652
-
1653
- // Default Phases --------------------------------
1654
-
1655
- /**
1656
- * Default phase names for the scheduler
1657
- */
1658
- type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1779
+ declare module 'react/jsx-runtime' {
1780
+ namespace JSX {
1781
+ interface IntrinsicElements extends ThreeElements {}
1782
+ }
1659
1783
  }
1660
1784
 
1661
- type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1662
-
1663
- interface MathRepresentation {
1664
- set(...args: number[]): any
1665
- }
1666
- interface VectorRepresentation extends MathRepresentation {
1667
- setScalar(value: number): any
1668
- }
1669
- type MathTypes = MathRepresentation | Euler$2 | Color$2
1670
-
1671
- type MathType<T extends MathTypes> = T extends Color$2
1672
- ? Args<typeof Color$2> | ColorRepresentation$1
1673
- : T extends VectorRepresentation | Layers$1 | Euler$2
1674
- ? T | MutableOrReadonlyParameters<T['set']> | number
1675
- : T | MutableOrReadonlyParameters<T['set']>
1676
-
1677
- type MathProps<P> = {
1678
- [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1679
- }
1680
-
1681
- type Vector2 = MathType<Vector2$1>
1682
- type Vector3 = MathType<Vector3$1>
1683
- type Vector4 = MathType<Vector4$1>
1684
- type Color = MathType<Color$2>
1685
- type Layers = MathType<Layers$1>
1686
- type Quaternion = MathType<Quaternion$1>
1687
- type Euler = MathType<Euler$2>
1688
- type Matrix3 = MathType<Matrix3$1>
1689
- type Matrix4 = MathType<Matrix4$1>
1690
-
1691
- interface RaycastableRepresentation {
1692
- raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1693
- }
1694
- type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1695
-
1696
- /**
1697
- * Props for geometry transform methods that can be called with `once()`.
1698
- * These methods modify the geometry in-place and only make sense to call once on mount.
1699
- *
1700
- * @example
1701
- * import { once } from '@react-three/fiber'
1702
- *
1703
- * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1704
- * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1705
- * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1706
- */
1707
- interface GeometryTransformProps {
1708
- /** Rotate the geometry about the X axis (radians). Use with once(). */
1709
- rotateX?: number
1710
- /** Rotate the geometry about the Y axis (radians). Use with once(). */
1711
- rotateY?: number
1712
- /** Rotate the geometry about the Z axis (radians). Use with once(). */
1713
- rotateZ?: number
1714
- /** Translate the geometry (x, y, z). Use with once(). */
1715
- translate?: [x: number, y: number, z: number]
1716
- /** Scale the geometry (x, y, z). Use with once(). */
1717
- scale?: [x: number, y: number, z: number]
1718
- /** Center the geometry based on bounding box. Use with once(). */
1719
- center?: true
1720
- /** Apply a Matrix4 transformation. Use with once(). */
1721
- applyMatrix4?: Matrix4$1
1722
- /** Apply a Quaternion rotation. Use with once(). */
1723
- applyQuaternion?: Quaternion$1
1724
- }
1725
-
1726
- type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1727
-
1728
- /**
1729
- * Workaround for @types/three TSL node type issues.
1730
- * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1731
- * This transforms `Node | null` properties to accept any object with node-like shape.
1732
- */
1733
- type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1734
-
1735
- /**
1736
- * For node material properties (colorNode, positionNode, etc.), accept broader types
1737
- * since @types/three has broken inheritance for TSL node subclasses.
1738
- */
1739
- type NodeProps<P> = {
1740
- [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1741
- }
1742
-
1743
- interface ReactProps<P> {
1744
- children?: React.ReactNode
1745
- ref?: React.Ref<P>
1746
- key?: React.Key
1747
- }
1748
-
1749
- type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1750
- Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1751
- >
1752
-
1753
- type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1754
- Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1755
- >
1756
-
1757
- type ThreeToJSXElements<T extends Record<string, any>> = {
1758
- [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1759
- }
1760
-
1761
- type ThreeExports = typeof import('three/webgpu')
1762
- type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1763
-
1764
- interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1765
- primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1766
- // Conflicts with DOM types can be accessed through a three* prefix
1767
- threeAudio: ThreeElementsImpl['audio']
1768
- threeSource: ThreeElementsImpl['source']
1769
- threeLine: ThreeElementsImpl['line']
1770
- threePath: ThreeElementsImpl['path']
1771
- }
1772
-
1773
- declare module 'react' {
1774
- namespace JSX {
1775
- interface IntrinsicElements extends ThreeElements {}
1776
- }
1777
- }
1778
-
1779
- declare module 'react/jsx-runtime' {
1780
- namespace JSX {
1781
- interface IntrinsicElements extends ThreeElements {}
1782
- }
1783
- }
1784
-
1785
- declare module 'react/jsx-dev-runtime' {
1786
- namespace JSX {
1787
- interface IntrinsicElements extends ThreeElements {}
1788
- }
1785
+ declare module 'react/jsx-dev-runtime' {
1786
+ namespace JSX {
1787
+ interface IntrinsicElements extends ThreeElements {}
1788
+ }
1789
1789
  }
1790
1790
 
1791
1791
  type three_d_Color = Color;
@@ -1895,7 +1895,7 @@ type EnvironmentLoaderProps = {
1895
1895
  * const texture = useEnvironment({ preset: 'sunset' })
1896
1896
  * ```
1897
1897
  */
1898
- declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown> | CubeTexture;
1898
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE$1.TextureEventMap> | CubeTexture<unknown>;
1899
1899
  declare namespace useEnvironment {
1900
1900
  var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1901
1901
  var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
@@ -4718,51 +4718,51 @@ declare function createTextureOperations(set: StoreApi<RootState>['setState']):
4718
4718
  */
4719
4719
  declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
4720
4720
 
4721
- //* Renderer Props ========================================
4722
-
4723
- type WebGPUDefaultProps = Omit<WebGPURendererParameters, 'canvas'> & BaseRendererProps
4724
-
4725
- type WebGPUProps =
4726
- | RendererFactory<WebGPURenderer, WebGPUDefaultProps>
4727
- | Partial<Properties<WebGPURenderer> | WebGPURendererParameters>
4728
-
4729
- // WebGPU doesn't have shadow maps in the same way
4730
- interface WebGPUShadowConfig {
4731
- shadows?: boolean // Simplified for WebGPU
4732
- }
4733
-
4734
- //* WebGPU-specific Types ========================================
4735
-
4736
- /** WebGPU renderer type - re-exported as R3FRenderer from @react-three/fiber/webgpu */
4737
- type WebGPUR3FRenderer = WebGPURenderer
4738
-
4739
- /** WebGPU internal state with narrowed renderer type */
4740
- interface WebGPUInternalState extends Omit<InternalState, 'actualRenderer'> {
4741
- actualRenderer: WebGPURenderer
4742
- }
4743
-
4744
- /**
4745
- * WebGPU-specific RootState with narrowed renderer type.
4746
- * Automatically used when importing from `@react-three/fiber/webgpu`.
4747
- *
4748
- * @example
4749
- * ```tsx
4750
- * import { useThree } from '@react-three/fiber/webgpu'
4751
- *
4752
- * function MyComponent() {
4753
- * const { renderer } = useThree()
4754
- * // renderer is typed as WebGPURenderer
4755
- * renderer.compute(computePass)
4756
- * }
4757
- * ```
4758
- */
4759
- interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'> {
4760
- /** @deprecated Use `renderer` instead */
4761
- gl: WebGPURenderer
4762
- /** The WebGPU renderer instance */
4763
- renderer: WebGPURenderer
4764
- /** Internals with WebGPU renderer */
4765
- internal: WebGPUInternalState
4721
+ //* Renderer Props ========================================
4722
+
4723
+ type WebGPUDefaultProps = Omit<WebGPURendererParameters, 'canvas'> & BaseRendererProps
4724
+
4725
+ type WebGPUProps =
4726
+ | RendererFactory<WebGPURenderer, WebGPUDefaultProps>
4727
+ | Partial<Properties<WebGPURenderer> | WebGPURendererParameters>
4728
+
4729
+ // WebGPU doesn't have shadow maps in the same way
4730
+ interface WebGPUShadowConfig {
4731
+ shadows?: boolean // Simplified for WebGPU
4732
+ }
4733
+
4734
+ //* WebGPU-specific Types ========================================
4735
+
4736
+ /** WebGPU renderer type - re-exported as R3FRenderer from @react-three/fiber/webgpu */
4737
+ type WebGPUR3FRenderer = WebGPURenderer
4738
+
4739
+ /** WebGPU internal state with narrowed renderer type */
4740
+ interface WebGPUInternalState extends Omit<InternalState, 'actualRenderer'> {
4741
+ actualRenderer: WebGPURenderer
4742
+ }
4743
+
4744
+ /**
4745
+ * WebGPU-specific RootState with narrowed renderer type.
4746
+ * Automatically used when importing from `@react-three/fiber/webgpu`.
4747
+ *
4748
+ * @example
4749
+ * ```tsx
4750
+ * import { useThree } from '@react-three/fiber/webgpu'
4751
+ *
4752
+ * function MyComponent() {
4753
+ * const { renderer } = useThree()
4754
+ * // renderer is typed as WebGPURenderer
4755
+ * renderer.compute(computePass)
4756
+ * }
4757
+ * ```
4758
+ */
4759
+ interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'> {
4760
+ /** @deprecated Use `renderer` instead */
4761
+ gl: WebGPURenderer
4762
+ /** The WebGPU renderer instance */
4763
+ renderer: WebGPURenderer
4764
+ /** Internals with WebGPU renderer */
4765
+ internal: WebGPUInternalState
4766
4766
  }
4767
4767
 
4768
4768
  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, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getScheduler, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };