@react-three/fiber 10.0.0-canary.f81281f → 10.0.0-canary.fbd44ae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extension.cjs +8 -7
- package/dist/extension.d.cts +10 -47
- package/dist/extension.d.mts +10 -47
- package/dist/extension.d.ts +10 -47
- package/dist/extension.mjs +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.d.ts +8 -9
- package/dist/index.mjs +3 -3
- package/dist/legacy.cjs +13 -13
- package/dist/legacy.d.cts +10 -7
- package/dist/legacy.d.mts +10 -7
- package/dist/legacy.d.ts +10 -7
- package/dist/legacy.mjs +4 -4
- package/dist/shared/{fiber.DAg-9ieU.d.ts → fiber.3jeDXXYd.d.mts} +183 -542
- package/dist/shared/{fiber.Ddgoyqql.d.mts → fiber.B_KQAb3I.d.ts} +183 -542
- package/dist/shared/fiber.Bi_S5KAx.cjs +16630 -0
- package/dist/shared/fiber.C6hitYDY.d.cts +48 -0
- package/dist/shared/fiber.CFK811nR.mjs +16532 -0
- package/dist/shared/{fiber.Bw8YnGg5.d.ts → fiber.C_MFx7We.d.cts} +555 -19
- package/dist/shared/{fiber.Bw8YnGg5.d.cts → fiber.C_MFx7We.d.mts} +555 -19
- package/dist/shared/{fiber.Bw8YnGg5.d.mts → fiber.C_MFx7We.d.ts} +555 -19
- package/dist/shared/fiber.D4fD6H74.d.mts +48 -0
- package/dist/shared/{fiber.C_v1rkNg.mjs → fiber.QxL_6jra.mjs} +113 -52
- package/dist/shared/fiber.YgTUGbja.d.ts +48 -0
- package/dist/shared/{fiber.B6zNSmwj.cjs → fiber.eR9ie2vQ.cjs} +116 -50
- package/dist/shared/{fiber.DiPB625B.d.cts → fiber.fR3DaJb1.d.cts} +183 -542
- package/dist/webgpu/index.cjs +13 -13
- package/dist/webgpu/index.d.cts +5 -6
- package/dist/webgpu/index.d.mts +5 -6
- package/dist/webgpu/index.d.ts +5 -6
- package/dist/webgpu/index.mjs +4 -4
- package/package.json +7 -7
- package/readme.md +1 -1
- package/dist/shared/fiber.BGL2rpse.cjs +0 -15129
- package/dist/shared/fiber.Ch4JrXS2.mjs +0 -15031
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { FrameTimingState, FrameCallback as FrameCallback$1, SchedulerApi } from '@pmndrs/scheduler';
|
|
2
|
-
import * as React from 'react';
|
|
3
2
|
import * as THREE from 'three';
|
|
4
|
-
import { WebGLRenderer, WebGLRenderTarget } from 'three';
|
|
3
|
+
import { WebGLRenderer, WebGLRenderTarget, Color as Color$1, ColorRepresentation } from 'three';
|
|
5
4
|
import * as ThreeWebGPU from 'three/webgpu';
|
|
6
|
-
import { WebGPURenderer, RenderTarget, CanvasTarget } from 'three/webgpu';
|
|
5
|
+
import { WebGPURenderer, RenderTarget, CanvasTarget, WebGPURendererParameters } from 'three/webgpu';
|
|
6
|
+
import * as React$1 from 'react';
|
|
7
|
+
import { ReactNode } from 'react';
|
|
7
8
|
import { StoreApi } from 'zustand';
|
|
8
9
|
import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
|
|
9
10
|
import { uniform, nodeObject } from 'three/tsl';
|
|
@@ -31,10 +32,10 @@ type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
|
|
|
31
32
|
|
|
32
33
|
//* Bridge & Block Types ==============================
|
|
33
34
|
|
|
34
|
-
type Bridge = React.FC<{ children?: React.ReactNode }>
|
|
35
|
+
type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
|
|
35
36
|
|
|
36
37
|
type SetBlock = false | Promise<null> | null
|
|
37
|
-
type UnblockProps = { set: React.Dispatch<React.SetStateAction<SetBlock>>; children: React.ReactNode }
|
|
38
|
+
type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
|
|
38
39
|
|
|
39
40
|
//* Object Map Type ==============================
|
|
40
41
|
|
|
@@ -382,7 +383,7 @@ type R3FRendererSupport = ForRegisteredRenderer<WebGPUSupport, WebGLSupport, Ren
|
|
|
382
383
|
//* Core Store Types ========================================
|
|
383
384
|
|
|
384
385
|
type Subscription = {
|
|
385
|
-
ref: React.RefObject<RenderCallback>
|
|
386
|
+
ref: React$1.RefObject<RenderCallback>
|
|
386
387
|
priority: number
|
|
387
388
|
store: RootStore
|
|
388
389
|
}
|
|
@@ -446,7 +447,7 @@ interface InternalState {
|
|
|
446
447
|
/** Pointers needing raycast this frame (used with frameTimedRaycasts) */
|
|
447
448
|
pointerDirty: Map<number, DomEvent>
|
|
448
449
|
/** Last event received (for events.update() compatibility) */
|
|
449
|
-
lastEvent: React.RefObject<DomEvent | null>
|
|
450
|
+
lastEvent: React$1.RefObject<DomEvent | null>
|
|
450
451
|
/** @deprecated Use pointerMap.get(pointerId).hovered instead */
|
|
451
452
|
hovered: Map<string, ThreeEvent<DomEvent>>
|
|
452
453
|
/** @deprecated Use pointerMap.get(pointerId).captured instead */
|
|
@@ -468,7 +469,7 @@ interface InternalState {
|
|
|
468
469
|
active: boolean
|
|
469
470
|
priority: number
|
|
470
471
|
frames: number
|
|
471
|
-
subscribe: (callback: React.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
|
|
472
|
+
subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
|
|
472
473
|
/** Internal renderer storage - use state.renderer or state.gl to access */
|
|
473
474
|
actualRenderer: R3FRenderer
|
|
474
475
|
/**
|
|
@@ -477,6 +478,11 @@ interface InternalState {
|
|
|
477
478
|
* Selected once, from the entry's provider, and copied into portals with the rest of `internal`.
|
|
478
479
|
*/
|
|
479
480
|
support: R3FRendererSupport
|
|
481
|
+
/**
|
|
482
|
+
* Releases this root's lease on its renderer. The last release disposes a renderer R3F created;
|
|
483
|
+
* a renderer passed in as an instance is never disposed by R3F.
|
|
484
|
+
*/
|
|
485
|
+
releaseRenderer?: () => void | Promise<void>
|
|
480
486
|
/** Global scheduler reference (for useFrame hook) */
|
|
481
487
|
scheduler: SchedulerApi | null
|
|
482
488
|
/**
|
|
@@ -487,8 +493,14 @@ interface InternalState {
|
|
|
487
493
|
renderOverride?: (() => void) | null
|
|
488
494
|
/** This root's unique ID in the global scheduler */
|
|
489
495
|
rootId?: string
|
|
496
|
+
/** Scheduler id reserved when a primary publishes its renderer, before root jobs are installed. */
|
|
497
|
+
pendingRootId?: string
|
|
498
|
+
/** Default scheduler predecessor when borrowing a primary renderer. */
|
|
499
|
+
sharedAfter?: string
|
|
490
500
|
/** Function to unregister this root from the global scheduler */
|
|
491
501
|
unregisterRoot?: () => void
|
|
502
|
+
/** Function to stop following devicePixelRatio changes */
|
|
503
|
+
unwatchDpr?: () => void
|
|
492
504
|
/** Container for child attachment (scene for root, original container for portals) */
|
|
493
505
|
container?: THREE.Object3D
|
|
494
506
|
/**
|
|
@@ -498,7 +510,8 @@ interface InternalState {
|
|
|
498
510
|
* around the canvas element -- so sizing it is sizing the renderer. A secondary owns a target
|
|
499
511
|
* R3F created for its own element. Either way there is exactly one target per canvas element,
|
|
500
512
|
* and the canvas-target job makes it the renderer's active one before this root renders.
|
|
501
|
-
* Absent on WebGL and on
|
|
513
|
+
* Absent on WebGL and on a WebGPU canvas that is neither a primary nor sharing, where the renderer
|
|
514
|
+
* is sized directly.
|
|
502
515
|
* @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
|
|
503
516
|
*/
|
|
504
517
|
canvasTarget?: CanvasTarget
|
|
@@ -516,25 +529,36 @@ interface InternalState {
|
|
|
516
529
|
canvasTargetSizeDirty?: boolean
|
|
517
530
|
/**
|
|
518
531
|
* Whether multi-canvas rendering is active.
|
|
519
|
-
* True
|
|
532
|
+
* True on a `<Canvas primary>` once another canvas shares its renderer, and on that canvas.
|
|
520
533
|
* When true, setCanvasTarget is called before each render.
|
|
521
534
|
*/
|
|
522
535
|
isMultiCanvas?: boolean
|
|
523
536
|
/**
|
|
524
|
-
* Whether this canvas is a secondary canvas sharing another's renderer
|
|
525
|
-
*
|
|
537
|
+
* Whether this canvas is a secondary canvas sharing another's renderer: it found a
|
|
538
|
+
* `<Canvas primary>` (automatically, or through `share="id"`) and borrows its renderer.
|
|
526
539
|
*/
|
|
527
540
|
isSecondary?: boolean
|
|
528
541
|
/**
|
|
529
|
-
* The id of the primary canvas this secondary canvas
|
|
530
|
-
* Only set when isSecondary is true
|
|
542
|
+
* The id of the primary canvas this secondary canvas shares.
|
|
543
|
+
* Only set when isSecondary is true and the primary has an `id`.
|
|
531
544
|
*/
|
|
532
545
|
targetId?: string
|
|
533
546
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
547
|
+
* This secondary stopped sharing because the primary's renderer fell back to its
|
|
548
|
+
* WebGL2 backend (#3965): it owns the renderer it constructed, so it is not
|
|
549
|
+
* `isSecondary` (which marks a canvas borrowing another's renderer).
|
|
550
|
+
*/
|
|
551
|
+
sharedRendererFallback?: boolean
|
|
552
|
+
/**
|
|
553
|
+
* Function to withdraw this primary canvas from the registry.
|
|
554
|
+
* Only set on a `<Canvas primary>`.
|
|
536
555
|
*/
|
|
537
556
|
unregisterPrimary?: () => void
|
|
557
|
+
/**
|
|
558
|
+
* Function to stop tracking this canvas as one that built its own WebGPU renderer while no primary
|
|
559
|
+
* existed (for the late-primary warning).
|
|
560
|
+
*/
|
|
561
|
+
untrackStandalone?: () => void
|
|
538
562
|
/** Whether canvas dimensions are forced to even numbers */
|
|
539
563
|
forceEven?: boolean
|
|
540
564
|
}
|
|
@@ -654,6 +678,511 @@ interface RootState {
|
|
|
654
678
|
|
|
655
679
|
type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>
|
|
656
680
|
|
|
681
|
+
//* Reconciler Types ==============================
|
|
682
|
+
|
|
683
|
+
// FiberRoot is an opaque internal React type - we define it locally
|
|
684
|
+
// to avoid bundling @types/react-reconciler which causes absolute path issues
|
|
685
|
+
type FiberRoot = any
|
|
686
|
+
|
|
687
|
+
/** A promise tagged with its state, the protocol React's `use` reads */
|
|
688
|
+
type TrackedPromise<T> = Promise<T> &
|
|
689
|
+
({ status: 'pending' } | { status: 'fulfilled'; value: T } | { status: 'rejected'; reason: unknown })
|
|
690
|
+
|
|
691
|
+
interface Root {
|
|
692
|
+
fiber: FiberRoot
|
|
693
|
+
store: RootStore
|
|
694
|
+
state:
|
|
695
|
+
| { status: 'open' }
|
|
696
|
+
| { status: 'closing'; token: symbol; settled: Promise<void>; settle: () => void }
|
|
697
|
+
| { status: 'disposed' }
|
|
698
|
+
configuration: {
|
|
699
|
+
previous?: RenderProps<HTMLCanvasElement | OffscreenCanvas>
|
|
700
|
+
apply: (props: RenderProps<HTMLCanvasElement | OffscreenCanvas>) => void
|
|
701
|
+
}
|
|
702
|
+
/** Settles once all accepted configuration has been applied */
|
|
703
|
+
ready: TrackedPromise<unknown>
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
type AttachFnType<O = any> = (parent: any, self: O) => () => void
|
|
707
|
+
type AttachType<O = any> = string | AttachFnType<O>
|
|
708
|
+
|
|
709
|
+
type ConstructorRepresentation<T = any> = new (...args: any[]) => T
|
|
710
|
+
|
|
711
|
+
interface Catalogue {
|
|
712
|
+
[name: string]: ConstructorRepresentation
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// TODO: handle constructor overloads
|
|
716
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2931
|
|
717
|
+
// https://github.com/microsoft/TypeScript/issues/37079
|
|
718
|
+
type Args<T> = T extends ConstructorRepresentation
|
|
719
|
+
? T extends typeof Color$1
|
|
720
|
+
? [r: number, g: number, b: number] | [color: ColorRepresentation]
|
|
721
|
+
: ConstructorParameters<T>
|
|
722
|
+
: any[]
|
|
723
|
+
|
|
724
|
+
type ArgsProp<P> = P extends ConstructorRepresentation
|
|
725
|
+
? IsAllOptional<ConstructorParameters<P>> extends true
|
|
726
|
+
? { args?: Args<P> }
|
|
727
|
+
: { args: Args<P> }
|
|
728
|
+
: { args: unknown[] }
|
|
729
|
+
|
|
730
|
+
type InstanceProps<T = any, P = any> = ArgsProp<P> & {
|
|
731
|
+
object?: T
|
|
732
|
+
dispose?: null
|
|
733
|
+
attach?: AttachType<T>
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
interface Instance<O = any> {
|
|
737
|
+
root: RootStore
|
|
738
|
+
type: string
|
|
739
|
+
parent: Instance | null
|
|
740
|
+
children: Instance[]
|
|
741
|
+
props: InstanceProps<O> & Record<string, unknown>
|
|
742
|
+
object: O & { __r3f?: Instance<O> }
|
|
743
|
+
eventCount: number
|
|
744
|
+
handlers: Partial<EventHandlers>
|
|
745
|
+
attach?: AttachType<O>
|
|
746
|
+
previousAttach?: any
|
|
747
|
+
previousVisible: boolean | undefined
|
|
748
|
+
isHidden: boolean
|
|
749
|
+
/** Set of props that have been applied via once() */
|
|
750
|
+
appliedOnce?: Set<string>
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
interface HostConfig {
|
|
754
|
+
type: string
|
|
755
|
+
props: Instance['props']
|
|
756
|
+
container: RootStore
|
|
757
|
+
instance: Instance
|
|
758
|
+
textInstance: void
|
|
759
|
+
suspenseInstance: Instance
|
|
760
|
+
hydratableInstance: never
|
|
761
|
+
formInstance: never
|
|
762
|
+
publicInstance: Instance['object']
|
|
763
|
+
hostContext: {}
|
|
764
|
+
childSet: never
|
|
765
|
+
timeoutHandle: number | undefined
|
|
766
|
+
noTimeout: -1
|
|
767
|
+
TransitionStatus: null
|
|
768
|
+
}
|
|
769
|
+
declare global {
|
|
770
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
//* Base Renderer Types =====================================
|
|
774
|
+
|
|
775
|
+
// Shim for OffscreenCanvas since it was removed from DOM types
|
|
776
|
+
interface OffscreenCanvas$1 extends EventTarget {}
|
|
777
|
+
|
|
778
|
+
interface BaseRendererProps {
|
|
779
|
+
canvas: HTMLCanvasElement | OffscreenCanvas$1
|
|
780
|
+
powerPreference?: 'high-performance' | 'low-power' | 'default'
|
|
781
|
+
antialias?: boolean
|
|
782
|
+
alpha?: boolean
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
type RendererFactory<TRenderer, TParams> =
|
|
786
|
+
| TRenderer
|
|
787
|
+
| ((defaultProps: TParams) => TRenderer)
|
|
788
|
+
| ((defaultProps: TParams) => Promise<TRenderer>)
|
|
789
|
+
|
|
790
|
+
interface Renderer {
|
|
791
|
+
render: (scene: THREE.Scene, camera: THREE.Camera) => any
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
//* Color Management Config ==============================
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Color management configuration shared by both WebGL and WebGPU renderers.
|
|
798
|
+
*/
|
|
799
|
+
interface ColorManagementConfig {
|
|
800
|
+
/**
|
|
801
|
+
* Color space assigned to 8-bit input textures (color maps).
|
|
802
|
+
* Defaults to sRGB. Most textures are authored in sRGB.
|
|
803
|
+
* @default THREE.SRGBColorSpace
|
|
804
|
+
*/
|
|
805
|
+
textureColorSpace?: THREE.ColorSpace
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
//* Renderer Settings ==============================
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Shadow map setting: `true` uses `THREE.PCFShadowMap`, a string picks a type, an object is assigned
|
|
812
|
+
* to `renderer.shadowMap`.
|
|
813
|
+
*
|
|
814
|
+
* `'soft'` is a deprecated alias of `'percentage'`: both map to `THREE.PCFShadowMap`, because three.js
|
|
815
|
+
* deprecated `PCFSoftShadowMap` and made `PCFShadowMap` soft. Using `'soft'` logs a deprecation notice.
|
|
816
|
+
* @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
|
|
817
|
+
*/
|
|
818
|
+
type ShadowsConfig = boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE.WebGLShadowMap>
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Renderer-wide settings R3F reads from the `renderer` / `gl` props bag. They are not renderer
|
|
822
|
+
* properties: R3F applies them itself, and only on the canvas that owns its renderer.
|
|
823
|
+
*/
|
|
824
|
+
interface RendererSettingsConfig extends ColorManagementConfig {
|
|
825
|
+
/**
|
|
826
|
+
* Enables shadows. Only on a renderer R3F builds from a props bag: a renderer instance or factory
|
|
827
|
+
* keeps the `shadowMap` you give it.
|
|
828
|
+
* @example <Canvas renderer={{ shadows: 'variance' }} />
|
|
829
|
+
*/
|
|
830
|
+
shadows?: ShadowsConfig
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
//* WebGL Renderer Props ==============================
|
|
834
|
+
|
|
835
|
+
type DefaultGLProps = Omit<THREE.WebGLRendererParameters, 'canvas'> & {
|
|
836
|
+
canvas: HTMLCanvasElement | OffscreenCanvas$1
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
type GLProps =
|
|
840
|
+
| Renderer
|
|
841
|
+
| ((defaultProps: DefaultGLProps) => Renderer)
|
|
842
|
+
| ((defaultProps: DefaultGLProps) => Promise<Renderer>)
|
|
843
|
+
| (Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> & RendererSettingsConfig)
|
|
844
|
+
|
|
845
|
+
//* WebGPU Renderer Props ==============================
|
|
846
|
+
|
|
847
|
+
type DefaultRendererProps = {
|
|
848
|
+
canvas: HTMLCanvasElement | OffscreenCanvas$1
|
|
849
|
+
[key: string]: any
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Canvas-level scheduler configuration.
|
|
854
|
+
* Controls render timing relative to other canvases.
|
|
855
|
+
*/
|
|
856
|
+
interface CanvasSchedulerConfig {
|
|
857
|
+
/**
|
|
858
|
+
* Run this Canvas root before the referenced Canvas root id(s).
|
|
859
|
+
*/
|
|
860
|
+
before?: string | string[]
|
|
861
|
+
/**
|
|
862
|
+
* Run this Canvas root after the referenced Canvas root id(s).
|
|
863
|
+
*/
|
|
864
|
+
after?: string | string[]
|
|
865
|
+
/**
|
|
866
|
+
* Numeric root order. Lower values run first.
|
|
867
|
+
*/
|
|
868
|
+
order?: number
|
|
869
|
+
/**
|
|
870
|
+
* Limit this Canvas's default render job (frames per second).
|
|
871
|
+
*/
|
|
872
|
+
fps?: number
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* The config keys the `renderer` props bag accepts besides the renderer's own parameters and
|
|
877
|
+
* properties. Multi-canvas and scheduling are Canvas props (`primary`, `share`, `scheduler`).
|
|
878
|
+
*/
|
|
879
|
+
type RendererConfigExtended = RendererSettingsConfig
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* The `renderer` prop: opt into three's WebGPU renderer.
|
|
883
|
+
* - `true` (the `<Canvas renderer>` shorthand) or `{}`: a default `WebGPURenderer`
|
|
884
|
+
* - a props bag: constructor parameters (`antialias`, `forceWebGL`, ...) and renderer properties
|
|
885
|
+
* (`toneMapping`, ...), plus `shadows` and `textureColorSpace`
|
|
886
|
+
* - a renderer instance, or a sync/async factory receiving the default props. Structural, like
|
|
887
|
+
* the `gl` prop: anything with `render()`, so a wrapped or mocked renderer is accepted.
|
|
888
|
+
*
|
|
889
|
+
* Everything here configures a renderer this canvas owns. A canvas sharing a primary's renderer
|
|
890
|
+
* ignores a props bag (with a dev warning): renderer-wide settings come from the `<Canvas primary>`.
|
|
891
|
+
*/
|
|
892
|
+
type RendererProps =
|
|
893
|
+
| boolean
|
|
894
|
+
| Renderer
|
|
895
|
+
| ((defaultProps: DefaultRendererProps) => Renderer)
|
|
896
|
+
| ((defaultProps: DefaultRendererProps) => Promise<Renderer>)
|
|
897
|
+
| (Partial<Properties<WebGPURenderer> & WebGPURendererParameters> & RendererConfigExtended)
|
|
898
|
+
|
|
899
|
+
//* Camera Props ==============================
|
|
900
|
+
|
|
901
|
+
type CameraProps = (
|
|
902
|
+
| THREE.Camera
|
|
903
|
+
| Partial<
|
|
904
|
+
ThreeElement<typeof THREE.Camera> &
|
|
905
|
+
ThreeElement<typeof THREE.PerspectiveCamera> &
|
|
906
|
+
ThreeElement<typeof THREE.OrthographicCamera>
|
|
907
|
+
>
|
|
908
|
+
) & {
|
|
909
|
+
/** Flags the camera as manual, putting projection into your own hands */
|
|
910
|
+
manual?: boolean
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
//* Render Props ==============================
|
|
914
|
+
|
|
915
|
+
interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
|
|
916
|
+
/**
|
|
917
|
+
* Canvas id. Sets the HTML `id` attribute on the canvas element and the canvas's scheduler root
|
|
918
|
+
* id (so `scheduler={{ after: 'main' }}` can order against it). On a `<Canvas primary>` it is the
|
|
919
|
+
* name other canvases pass to `share="id"`.
|
|
920
|
+
* @example <Canvas id="main-viewer">...</Canvas>
|
|
921
|
+
*/
|
|
922
|
+
id?: string
|
|
923
|
+
/**
|
|
924
|
+
* Make this canvas the owner of a WebGPU renderer that other canvases share. Every other WebGPU
|
|
925
|
+
* canvas mounted with or after it borrows its renderer (drawing into its own element through a
|
|
926
|
+
* `CanvasTarget`) unless it passes `share={false}` or its own renderer instance/factory.
|
|
927
|
+
* Renderer-wide settings (`renderer={{ shadows, toneMapping, ... }}`) belong on the primary.
|
|
928
|
+
*
|
|
929
|
+
* WebGPU only: on the root entry `primary` selects WebGPU like the `renderer` prop does. Several
|
|
930
|
+
* primaries need distinct `id`s, and the other canvases then pick one with `share="id"`.
|
|
931
|
+
* Read when the renderer is created; changing it later needs a remount.
|
|
932
|
+
* @example <Canvas primary renderer={{ shadows: true }}>...</Canvas>
|
|
933
|
+
*/
|
|
934
|
+
primary?: boolean
|
|
935
|
+
/**
|
|
936
|
+
* Renderer sharing for a non-primary canvas (WebGPU only).
|
|
937
|
+
* - omitted: share the primary's renderer when exactly one `<Canvas primary>` is mounted, else
|
|
938
|
+
* own a renderer as usual
|
|
939
|
+
* - `"id"`: share the renderer of `<Canvas id="id" primary>`, waiting for it to mount
|
|
940
|
+
* - `false`: always own a renderer, even while a primary exists
|
|
941
|
+
*
|
|
942
|
+
* Read when the renderer is created; changing it later needs a remount.
|
|
943
|
+
* @example <Canvas share="main">...</Canvas>
|
|
944
|
+
*/
|
|
945
|
+
share?: string | false
|
|
946
|
+
/**
|
|
947
|
+
* Canvas-level scheduler options: this canvas's order relative to other canvases, and an fps cap
|
|
948
|
+
* for its default render. A canvas sharing a primary's renderer runs after the primary unless
|
|
949
|
+
* `before`/`after` are given here.
|
|
950
|
+
* @example <Canvas scheduler={{ after: 'main', fps: 30 }}>...</Canvas>
|
|
951
|
+
*/
|
|
952
|
+
scheduler?: CanvasSchedulerConfig
|
|
953
|
+
/** A threejs renderer instance or props that go into the default renderer */
|
|
954
|
+
gl?: GLProps
|
|
955
|
+
/** A WebGPU renderer instance or props that go into the default renderer */
|
|
956
|
+
renderer?: RendererProps
|
|
957
|
+
/** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
|
|
958
|
+
size?: Size
|
|
959
|
+
/** Creates an orthographic camera */
|
|
960
|
+
orthographic?: boolean
|
|
961
|
+
/**
|
|
962
|
+
* R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
|
|
963
|
+
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
|
|
964
|
+
*/
|
|
965
|
+
frameloop?: Frameloop
|
|
966
|
+
/**
|
|
967
|
+
* R3F performance options for adaptive performance.
|
|
968
|
+
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
|
|
969
|
+
*/
|
|
970
|
+
performance?: Partial<Omit<Performance, 'regress'>>
|
|
971
|
+
/** Target pixel ratio. Can clamp between a range: `[min, max]` */
|
|
972
|
+
dpr?: Dpr
|
|
973
|
+
/**
|
|
974
|
+
* Props that go into the default raycaster. `params` is merged into the raycaster's defaults,
|
|
975
|
+
* so a single threshold can be set: `raycaster={{ params: { Points: { threshold: 0.2 } } }}`.
|
|
976
|
+
*/
|
|
977
|
+
raycaster?: Partial<Omit<THREE.Raycaster, 'params'>> & { params?: Partial<THREE.RaycasterParameters> }
|
|
978
|
+
/** A `THREE.Scene` instance or props that go into the default scene */
|
|
979
|
+
scene?: THREE.Scene | Partial<THREE.Scene>
|
|
980
|
+
/** A `THREE.Camera` instance or props that go into the default camera */
|
|
981
|
+
camera?: CameraProps
|
|
982
|
+
/** An R3F event manager to manage elements' pointer events */
|
|
983
|
+
events?: (store: RootStore) => EventManager<Element>
|
|
984
|
+
/** Callback after the canvas has rendered (but not yet committed) */
|
|
985
|
+
onCreated?: (state: RootState) => void
|
|
986
|
+
/** Response for pointer clicks that have missed any target */
|
|
987
|
+
onPointerMissed?: (event: MouseEvent) => void
|
|
988
|
+
/** Response for dragover events that have missed any target */
|
|
989
|
+
onDragOverMissed?: (event: DragEvent) => void
|
|
990
|
+
/** Response for drop events that have missed any target */
|
|
991
|
+
onDropMissed?: (event: DragEvent) => void
|
|
992
|
+
/** Whether to automatically update the frustum each frame (default: true) */
|
|
993
|
+
autoUpdateFrustum?: boolean
|
|
994
|
+
/**
|
|
995
|
+
* Enable WebGPU occlusion queries for onOccluded/onVisible events.
|
|
996
|
+
* Auto-enabled when any object uses onOccluded or onVisible handlers.
|
|
997
|
+
* Only works with WebGPU renderer - WebGL will log a warning.
|
|
998
|
+
*/
|
|
999
|
+
occlusion?: boolean
|
|
1000
|
+
/** Internal: stored size props from Canvas for reset functionality */
|
|
1001
|
+
_sizeProps?: { width?: number; height?: number } | null
|
|
1002
|
+
/**
|
|
1003
|
+
* Internal: the token a Canvas announced `primary` with before this root existed, so configure
|
|
1004
|
+
* continues that announcement instead of starting a second one.
|
|
1005
|
+
* @internal
|
|
1006
|
+
*/
|
|
1007
|
+
_primaryToken?: object
|
|
1008
|
+
/** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
|
|
1009
|
+
forceEven?: boolean
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
//* Reconciler Root ==============================
|
|
1013
|
+
|
|
1014
|
+
interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
|
|
1015
|
+
ready: TrackedPromise<unknown>
|
|
1016
|
+
configure: (config?: RenderProps<TCanvas>) => TrackedPromise<ReconcilerRoot<TCanvas>>
|
|
1017
|
+
render: (element: ReactNode) => RootStore
|
|
1018
|
+
unmount: () => void
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
//* Inject State ==============================
|
|
1022
|
+
|
|
1023
|
+
type InjectState = Partial<
|
|
1024
|
+
Omit<RootState, 'events'> & {
|
|
1025
|
+
events?: {
|
|
1026
|
+
enabled?: boolean
|
|
1027
|
+
priority?: number
|
|
1028
|
+
compute?: ComputeFunction
|
|
1029
|
+
connected?: any
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
|
|
1033
|
+
* This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
|
|
1034
|
+
* Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
|
|
1035
|
+
*/
|
|
1036
|
+
injectScene?: boolean
|
|
1037
|
+
}
|
|
1038
|
+
>
|
|
1039
|
+
|
|
1040
|
+
type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
|
|
1041
|
+
|
|
1042
|
+
interface MathRepresentation {
|
|
1043
|
+
set(...args: number[]): any
|
|
1044
|
+
}
|
|
1045
|
+
interface VectorRepresentation extends MathRepresentation {
|
|
1046
|
+
setScalar(value: number): any
|
|
1047
|
+
}
|
|
1048
|
+
type MathTypes = MathRepresentation | THREE.Euler | THREE.Color
|
|
1049
|
+
|
|
1050
|
+
type MathType<T extends MathTypes> = T extends THREE.Color
|
|
1051
|
+
? Args<typeof THREE.Color> | THREE.ColorRepresentation
|
|
1052
|
+
: T extends VectorRepresentation | THREE.Layers | THREE.Euler
|
|
1053
|
+
? T | MutableOrReadonlyParameters<T['set']> | number
|
|
1054
|
+
: T | MutableOrReadonlyParameters<T['set']>
|
|
1055
|
+
|
|
1056
|
+
type MathProps<P> = {
|
|
1057
|
+
[K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
type Vector2 = MathType<THREE.Vector2>
|
|
1061
|
+
type Vector3 = MathType<THREE.Vector3>
|
|
1062
|
+
type Vector4 = MathType<THREE.Vector4>
|
|
1063
|
+
type Color = MathType<THREE.Color>
|
|
1064
|
+
type Layers = MathType<THREE.Layers>
|
|
1065
|
+
type Quaternion = MathType<THREE.Quaternion>
|
|
1066
|
+
type Euler = MathType<THREE.Euler>
|
|
1067
|
+
type Matrix3 = MathType<THREE.Matrix3>
|
|
1068
|
+
type Matrix4 = MathType<THREE.Matrix4>
|
|
1069
|
+
|
|
1070
|
+
interface RaycastableRepresentation {
|
|
1071
|
+
raycast(raycaster: THREE.Raycaster, intersects: THREE.Intersection[]): void
|
|
1072
|
+
}
|
|
1073
|
+
type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Props for geometry transform methods that can be called with `once()`.
|
|
1077
|
+
* These methods modify the geometry in-place and only make sense to call once on mount.
|
|
1078
|
+
*
|
|
1079
|
+
* @example
|
|
1080
|
+
* import { once } from '@react-three/fiber'
|
|
1081
|
+
*
|
|
1082
|
+
* <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
|
|
1083
|
+
* <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
|
|
1084
|
+
* <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
|
|
1085
|
+
*/
|
|
1086
|
+
interface GeometryTransformProps {
|
|
1087
|
+
/** Rotate the geometry about the X axis (radians). Use with once(). */
|
|
1088
|
+
rotateX?: number
|
|
1089
|
+
/** Rotate the geometry about the Y axis (radians). Use with once(). */
|
|
1090
|
+
rotateY?: number
|
|
1091
|
+
/** Rotate the geometry about the Z axis (radians). Use with once(). */
|
|
1092
|
+
rotateZ?: number
|
|
1093
|
+
/** Translate the geometry (x, y, z). Use with once(). */
|
|
1094
|
+
translate?: [x: number, y: number, z: number]
|
|
1095
|
+
/** Scale the geometry (x, y, z). Use with once(). */
|
|
1096
|
+
scale?: [x: number, y: number, z: number]
|
|
1097
|
+
/** Center the geometry based on bounding box. Use with once(). */
|
|
1098
|
+
center?: true
|
|
1099
|
+
/** Apply a Matrix4 transformation. Use with once(). */
|
|
1100
|
+
applyMatrix4?: THREE.Matrix4
|
|
1101
|
+
/** Apply a Quaternion rotation. Use with once(). */
|
|
1102
|
+
applyQuaternion?: THREE.Quaternion
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
type GeometryProps<P> = P extends THREE.BufferGeometry ? GeometryTransformProps : {}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Workaround for @types/three TSL node type issues.
|
|
1109
|
+
* The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
|
|
1110
|
+
* This transforms `Node | null` properties to accept any object with node-like shape.
|
|
1111
|
+
*/
|
|
1112
|
+
type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* For node material properties (colorNode, positionNode, etc.), accept broader types
|
|
1116
|
+
* since @types/three has broken inheritance for TSL node subclasses. NodeClass requires
|
|
1117
|
+
* `nodeType`, so this structural key test remains neutral to the selected Three entry.
|
|
1118
|
+
*/
|
|
1119
|
+
type NodeProps<P> = {
|
|
1120
|
+
[K in keyof P as NonNullable<P[K]> extends { nodeType: string | null } ? K : never]?: TSLNodeInput
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
interface ReactProps<P> {
|
|
1124
|
+
children?: React.ReactNode
|
|
1125
|
+
ref?: React.Ref<P>
|
|
1126
|
+
key?: React.Key
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
|
|
1130
|
+
Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
|
|
1131
|
+
>
|
|
1132
|
+
|
|
1133
|
+
type ThreeElement<T extends ConstructorRepresentation> = Mutable<
|
|
1134
|
+
Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
|
|
1135
|
+
>
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Every constructor export of a three namespace as an uncapitalized JSX element. Non-constructor
|
|
1139
|
+
* exports (constants, functions, nested namespaces) are dropped from the keys rather than mapped
|
|
1140
|
+
* to `never`: a single `never`-valued key in `JSX.IntrinsicElements` collapses the props of any
|
|
1141
|
+
* tag typed `React.ElementType` (#3898).
|
|
1142
|
+
*/
|
|
1143
|
+
type ThreeToJSXElements<T extends Record<string, any>> = {
|
|
1144
|
+
[K in keyof T & string as T[K] extends ConstructorRepresentation ? Uncapitalize<K> : never]: ThreeElement<T[K]>
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/** Method names of Object3D, excluded from the `primitive` element's typed props. */
|
|
1148
|
+
type Object3DMethod = NonNullable<
|
|
1149
|
+
{
|
|
1150
|
+
[K in keyof THREE.Object3D]-?: THREE.Object3D[K] extends (...args: any[]) => any ? K : never
|
|
1151
|
+
}[keyof THREE.Object3D]
|
|
1152
|
+
>
|
|
1153
|
+
|
|
1154
|
+
/** Look up a key present in a generic element map. */
|
|
1155
|
+
type ElementOf<E, K extends string> = E[Extract<keyof E, K>]
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* The JSX element map derived from an entry's Three.js exports. Each entry declares its own
|
|
1159
|
+
* `ThreeElements` from this (`src/index.tsx`, `src/legacy.tsx`, `src/webgpu/index.tsx`) and augments
|
|
1160
|
+
* react's `IntrinsicElements` with it, so `/legacy` never advertises node materials and `/webgpu`
|
|
1161
|
+
* never advertises a `<webGLRenderer>`.
|
|
1162
|
+
*/
|
|
1163
|
+
type ThreeElementsOf<T extends Record<string, any>> = Omit<
|
|
1164
|
+
ThreeToJSXElements<T>,
|
|
1165
|
+
'audio' | 'source' | 'line' | 'path'
|
|
1166
|
+
> & {
|
|
1167
|
+
/**
|
|
1168
|
+
* `primitive` wraps a pre-existing object, so its props cannot be derived from one class.
|
|
1169
|
+
* Events are typed from `EventHandlers` (`onClick={(e) => ...}` infers `e`), the ref is
|
|
1170
|
+
* untyped, and any other prop is accepted and applied to the object by name. Object3D's own
|
|
1171
|
+
* methods are left out of the typed surface: they return `this`, so a subclass element's
|
|
1172
|
+
* props (`ThreeElements['group']`) could not be spread onto a primitive otherwise.
|
|
1173
|
+
*/
|
|
1174
|
+
primitive: Omit<ThreeElement<typeof THREE.Object3D>, 'args' | 'object' | 'ref' | Object3DMethod> & {
|
|
1175
|
+
object: object
|
|
1176
|
+
ref?: React.Ref<any>
|
|
1177
|
+
[prop: string]: unknown
|
|
1178
|
+
}
|
|
1179
|
+
// Conflicts with DOM types can be accessed through a three* prefix
|
|
1180
|
+
threeAudio: ElementOf<ThreeToJSXElements<T>, 'audio'>
|
|
1181
|
+
threeSource: ElementOf<ThreeToJSXElements<T>, 'source'>
|
|
1182
|
+
threeLine: ElementOf<ThreeToJSXElements<T>, 'line'>
|
|
1183
|
+
threePath: ElementOf<ThreeToJSXElements<T>, 'path'>
|
|
1184
|
+
}
|
|
1185
|
+
|
|
657
1186
|
interface RootExtension {
|
|
658
1187
|
/** Unique name. Registering the same name again replaces the entry (HMR-safe); roots it already
|
|
659
1188
|
* set up are not set up a second time, but get the new entry's dispose and hmr. */
|
|
@@ -695,7 +1224,14 @@ declare function useStore(): RootStore;
|
|
|
695
1224
|
*/
|
|
696
1225
|
declare function useThree<T = RootState>(selector?: (state: RootState) => T, equalityFn?: <T>(state: T, newState: T) => boolean): T;
|
|
697
1226
|
|
|
698
|
-
|
|
1227
|
+
/**
|
|
1228
|
+
* React context that carries the current root's {@link RootStore}. Each root provides its store and
|
|
1229
|
+
* each portal provides its own scoped one; `useStore`, and every hook built on it, reads it.
|
|
1230
|
+
*
|
|
1231
|
+
* Stored on `globalThis` under `Symbol.for('@react-three/fiber.context')`, so every copy and entry
|
|
1232
|
+
* of fiber shares a single context.
|
|
1233
|
+
*/
|
|
1234
|
+
declare const context: React$1.Context<RootStore>;
|
|
699
1235
|
|
|
700
|
-
export { useStore as
|
|
701
|
-
export type {
|
|
1236
|
+
export { useStore as a$, useThree as b0, registerRootExtension as u, setRenderOverride as v, context as x };
|
|
1237
|
+
export type { Events as $, Viewport as A, RenderCallback as B, Color as C, Dpr as D, Euler as E, Frameloop as F, GeometryTransformProps as G, Performance as H, InternalState as I, RootState as J, RootStore as K, Layers as L, MutableOrReadonlyParameters as M, NodeProps as N, Object3DMethod as O, PointerState as P, Quaternion as Q, RaycastableRepresentation as R, Subscription as S, TSLNodeInput as T, Intersection as U, VectorRepresentation as V, Camera as W, XRManager as X, IntersectionEvent as Y, ThreeEvent as Z, DomEvent as _, MathRepresentation as a, EventHandlers as a0, FilterFunction as a1, ComputeFunction as a2, XRPointerConfig as a3, EventManager as a4, PointerCaptureTarget as a5, VisibilityEntry as a6, OffscreenCanvas$1 as a7, BaseRendererProps as a8, RendererFactory as a9, Properties as aA, Mutable as aB, IsOptional as aC, IsAllOptional as aD, ThreeCamera as aE, Act as aF, Bridge as aG, SetBlock as aH, UnblockProps as aI, ObjectMap as aJ, EquConfig as aK, Disposable as aL, FrameNextState as aM, FrameState as aN, FrameNextCallback as aO, FrameCallback as aP, ThreeNamespace as aQ, ThreeCore as aR, OcclusionSupport as aS, WebGLSupport as aT, WebGPUSupport as aU, RendererSupport as aV, RendererProvider as aW, Register as aX, RegisteredRenderer as aY, ForRegisteredRenderer as aZ, R3FRendererSupport as a_, Renderer as aa, ColorManagementConfig as ab, ShadowsConfig as ac, RendererSettingsConfig as ad, DefaultGLProps as ae, GLProps as af, DefaultRendererProps as ag, CanvasSchedulerConfig as ah, RendererConfigExtended as ai, RendererProps as aj, CameraProps as ak, RenderProps as al, InjectState as am, FiberRoot as an, TrackedPromise as ao, Root as ap, AttachFnType as aq, AttachType as ar, Catalogue as as, Args as at, ArgsProp as au, InstanceProps as av, Instance as aw, HostConfig as ax, NonFunctionKeys as ay, Overwrite as az, MathTypes as b, MathType as c, MathProps as d, Vector2 as e, Vector3 as f, Vector4 as g, Matrix3 as h, Matrix4 as i, EventProps as j, GeometryProps as k, ReactProps as l, ConstructorRepresentation as m, ElementProps as n, ThreeElement as o, ThreeToJSXElements as p, ThreeElementsOf as q, ElementOf as r, R3FRenderTarget as s, ReconcilerRoot as t, RootExtension as w, R3FRenderer as y, Size as z };
|