@react-three/fiber 10.0.0-canary.c3fa45d → 10.0.0-canary.d6fdf72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +77 -97
- package/dist/index.d.cts +81 -54
- package/dist/index.d.mts +81 -54
- package/dist/index.d.ts +81 -54
- package/dist/index.mjs +77 -97
- package/dist/legacy.cjs +77 -97
- package/dist/legacy.d.cts +81 -54
- package/dist/legacy.d.mts +81 -54
- package/dist/legacy.d.ts +81 -54
- package/dist/legacy.mjs +77 -97
- package/dist/webgpu/index.cjs +77 -97
- package/dist/webgpu/index.d.cts +81 -54
- package/dist/webgpu/index.d.mts +81 -54
- package/dist/webgpu/index.d.ts +81 -54
- package/dist/webgpu/index.mjs +77 -97
- package/package.json +1 -1
package/dist/webgpu/index.d.mts
CHANGED
|
@@ -803,8 +803,10 @@ interface RootState {
|
|
|
803
803
|
buffers: BufferStore
|
|
804
804
|
/** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
|
|
805
805
|
gpuStorage: StorageStore
|
|
806
|
-
/** Global
|
|
807
|
-
textures: Map<string,
|
|
806
|
+
/** Global Texture registry (key → Texture, usually keyed by URL) - use useTextures() hook for access + lifecycle */
|
|
807
|
+
textures: Map<string, THREE$1.Texture>
|
|
808
|
+
/** Internal: refcount per texture key, driven by mounted useTexture consumers (registry enrollment is on by default) */
|
|
809
|
+
_textureRefs: Map<string, number>
|
|
808
810
|
/** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
|
|
809
811
|
renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
|
|
810
812
|
/** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
|
|
@@ -2575,11 +2577,16 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
|
|
|
2575
2577
|
/** Callback when texture(s) finish loading */
|
|
2576
2578
|
onLoad?: (texture: MappedTextureType<Url>) => void;
|
|
2577
2579
|
/**
|
|
2578
|
-
*
|
|
2579
|
-
* When true:
|
|
2580
|
+
* Register the texture(s) in R3F's global texture registry for access via useTextures().
|
|
2581
|
+
* When true (the default):
|
|
2580
2582
|
* - Textures persist until explicitly disposed
|
|
2581
|
-
* -
|
|
2582
|
-
*
|
|
2583
|
+
* - On mount, returns existing registered textures if available (preserving modifications like colorSpace)
|
|
2584
|
+
*
|
|
2585
|
+
* Reads are taken once at mount — a mounted `useTexture` does not re-render when the registry
|
|
2586
|
+
* changes. To react to registry swaps, use `useTextures(s => s.get(key))` instead.
|
|
2587
|
+
*
|
|
2588
|
+
* Pass `false` to opt out of registry enrollment entirely.
|
|
2589
|
+
* @default true
|
|
2583
2590
|
*/
|
|
2584
2591
|
cache?: boolean;
|
|
2585
2592
|
};
|
|
@@ -2603,15 +2610,18 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
|
|
|
2603
2610
|
* normal: '/normal.png'
|
|
2604
2611
|
* })
|
|
2605
2612
|
*
|
|
2606
|
-
* //
|
|
2607
|
-
* //
|
|
2608
|
-
* const diffuse = useTexture('/diffuse.png'
|
|
2613
|
+
* // Textures are registered in the global registry by default — the same texture
|
|
2614
|
+
* // object is shared across components and modifications (colorSpace, wrapS, etc.) are preserved
|
|
2615
|
+
* const diffuse = useTexture('/diffuse.png')
|
|
2609
2616
|
* diffuse.colorSpace = THREE.SRGBColorSpace
|
|
2610
2617
|
*
|
|
2611
2618
|
* // Another component gets the SAME texture with colorSpace already set
|
|
2612
|
-
* const sameDiffuse = useTexture('/diffuse.png'
|
|
2619
|
+
* const sameDiffuse = useTexture('/diffuse.png')
|
|
2613
2620
|
*
|
|
2614
|
-
* //
|
|
2621
|
+
* // Opt out of registry enrollment for a one-off texture
|
|
2622
|
+
* const scratch = useTexture('/scratch.png', { cache: false })
|
|
2623
|
+
*
|
|
2624
|
+
* // Access the registry directly
|
|
2615
2625
|
* const { get } = useTextures()
|
|
2616
2626
|
* const cached = get('/diffuse.png')
|
|
2617
2627
|
* ```
|
|
@@ -2628,63 +2638,80 @@ declare const Texture: ({ children, input, onLoad, cache, }: {
|
|
|
2628
2638
|
cache?: boolean;
|
|
2629
2639
|
}) => react_jsx_runtime.JSX.Element;
|
|
2630
2640
|
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2641
|
+
/** Accepted shapes for a registry read: a single key, a list of keys, or a name→key map. */
|
|
2642
|
+
type TextureInput = string | string[] | Record<string, string>;
|
|
2643
|
+
/** Result of a `get()` read, mirroring the input shape. */
|
|
2644
|
+
type TextureResult<Input extends TextureInput> = Input extends string ? Texture$1 | undefined : Input extends string[] ? (Texture$1 | undefined)[] : {
|
|
2645
|
+
[K in keyof Input]: Texture$1 | undefined;
|
|
2634
2646
|
};
|
|
2647
|
+
/** Options for `dispose()`. */
|
|
2648
|
+
interface DisposeOptions {
|
|
2649
|
+
/** Dispose even if the texture still has active references (default false). */
|
|
2650
|
+
force?: boolean;
|
|
2651
|
+
}
|
|
2635
2652
|
interface UseTexturesReturn {
|
|
2636
|
-
/** Map
|
|
2637
|
-
|
|
2638
|
-
/**
|
|
2639
|
-
get
|
|
2640
|
-
/** Check
|
|
2641
|
-
has
|
|
2642
|
-
/**
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2653
|
+
/** The live registry Map (key → Texture). Treat as read-only. */
|
|
2654
|
+
readonly all: Map<string, Texture$1>;
|
|
2655
|
+
/** Read one texture, an array of textures, or a name→texture record (mirrors the input shape). */
|
|
2656
|
+
get<Input extends TextureInput>(input: Input): TextureResult<Input>;
|
|
2657
|
+
/** Check whether a key exists in the registry. */
|
|
2658
|
+
has(key: string): boolean;
|
|
2659
|
+
/**
|
|
2660
|
+
* Register a texture (or a record of textures) that has no URL — e.g. a render
|
|
2661
|
+
* target or procedural texture. URL-loaded textures are registered automatically
|
|
2662
|
+
* by `useTexture` (registry enrollment is on by default).
|
|
2663
|
+
*/
|
|
2664
|
+
add(key: string, texture: Texture$1): void;
|
|
2665
|
+
add(record: Record<string, Texture$1>): void;
|
|
2666
|
+
/**
|
|
2667
|
+
* Dispose a texture's GPU resources and remove it from the registry.
|
|
2668
|
+
* Refcount-aware: if the key is still in use by a mounted `useTexture` consumer it is
|
|
2669
|
+
* skipped (with a warning) unless `{ force: true }` is passed.
|
|
2670
|
+
* @returns true if disposed, false if skipped.
|
|
2671
|
+
*/
|
|
2672
|
+
dispose(key: string, options?: DisposeOptions): boolean;
|
|
2673
|
+
/** Dispose every texture in the registry and clear it. Use on scene teardown. */
|
|
2674
|
+
disposeAll(): void;
|
|
2656
2675
|
}
|
|
2657
2676
|
/**
|
|
2658
|
-
*
|
|
2677
|
+
* Reactive Texture registry — load once with `useTexture`, reach the textures from anywhere.
|
|
2678
|
+
*
|
|
2679
|
+
* This is a registry of plain `Texture` objects (not TSL nodes), so the same texture can feed
|
|
2680
|
+
* a material map, a heightmap sampler, or anything else. It does **not** load — pair it with
|
|
2681
|
+
* `useTexture` for loading (registry enrollment is on by default); `useTextures` is for access and lifecycle.
|
|
2659
2682
|
*
|
|
2660
|
-
*
|
|
2661
|
-
*
|
|
2683
|
+
* The returned handle is **reactive**: the calling component re-renders when the registry
|
|
2684
|
+
* changes. Pass a selector to scope the subscription to a single read.
|
|
2662
2685
|
*
|
|
2663
2686
|
* @example
|
|
2664
2687
|
* ```tsx
|
|
2665
|
-
*
|
|
2688
|
+
* // Load + register once (anywhere in the tree) — registered by default
|
|
2689
|
+
* useTexture({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
|
|
2666
2690
|
*
|
|
2667
|
-
* //
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
2670
|
-
* const tex = useTexture('/textures/diffuse.png', { cache: true })
|
|
2671
|
-
* }
|
|
2672
|
-
*
|
|
2673
|
-
* // Access cached texture from anywhere
|
|
2674
|
-
* const diffuse = get('/textures/diffuse.png')
|
|
2675
|
-
* if (diffuse) material.map = diffuse
|
|
2691
|
+
* // Reach them from another component — record form lands straight into a material
|
|
2692
|
+
* const { map, normalMap } = useTextures().get({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
|
|
2693
|
+
* return <meshStandardMaterial map={map} normalMap={normalMap} />
|
|
2676
2694
|
*
|
|
2677
|
-
* //
|
|
2678
|
-
*
|
|
2695
|
+
* // A set of heightmaps at once
|
|
2696
|
+
* const [a, b, c] = useTextures().get(['/h0.png', '/h1.png', '/h2.png'])
|
|
2679
2697
|
*
|
|
2680
|
-
* //
|
|
2681
|
-
*
|
|
2698
|
+
* // Register a non-URL texture (render target / procedural)
|
|
2699
|
+
* useTextures().add('rt-main', renderTarget.texture)
|
|
2682
2700
|
*
|
|
2683
|
-
* //
|
|
2684
|
-
*
|
|
2701
|
+
* // Deliberate GPU cleanup (refcount-aware; force to override)
|
|
2702
|
+
* useTextures().dispose('/diffuse.jpg')
|
|
2703
|
+
* useTextures().disposeAll() // scene teardown
|
|
2685
2704
|
* ```
|
|
2705
|
+
*
|
|
2706
|
+
* @remarks
|
|
2707
|
+
* **Future expansion:** an imperative async loader (e.g. `await useTextures().load('/x.jpg')`) is
|
|
2708
|
+
* intentionally not included yet. It would let non-React code (loading screens, dynamic streaming)
|
|
2709
|
+
* populate the registry without Suspense, at the cost of putting loading back into this hook. It
|
|
2710
|
+
* will be added only if a concrete consumer needs imperative loading; for now, loading lives in
|
|
2711
|
+
* `useTexture`.
|
|
2686
2712
|
*/
|
|
2687
2713
|
declare function useTextures(): UseTexturesReturn;
|
|
2714
|
+
declare function useTextures<T>(selector: (registry: UseTexturesReturn) => T): T;
|
|
2688
2715
|
|
|
2689
2716
|
/**
|
|
2690
2717
|
* Creates a render target compatible with the current renderer.
|
|
@@ -4766,4 +4793,4 @@ interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'
|
|
|
4766
4793
|
}
|
|
4767
4794
|
|
|
4768
4795
|
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 };
|
|
4769
|
-
export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, WebGPURootState as RootState, RootStore, SchedulerApi, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput,
|
|
4796
|
+
export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeOptions, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, WebGPURootState as RootState, RootStore, SchedulerApi, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput, TextureInput, TextureOperations, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UniformCreator, UniformValue, UniformsWithUtils, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig, XRManager, XRPointerConfig };
|
package/dist/webgpu/index.d.ts
CHANGED
|
@@ -803,8 +803,10 @@ interface RootState {
|
|
|
803
803
|
buffers: BufferStore
|
|
804
804
|
/** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
|
|
805
805
|
gpuStorage: StorageStore
|
|
806
|
-
/** Global
|
|
807
|
-
textures: Map<string,
|
|
806
|
+
/** Global Texture registry (key → Texture, usually keyed by URL) - use useTextures() hook for access + lifecycle */
|
|
807
|
+
textures: Map<string, THREE$1.Texture>
|
|
808
|
+
/** Internal: refcount per texture key, driven by mounted useTexture consumers (registry enrollment is on by default) */
|
|
809
|
+
_textureRefs: Map<string, number>
|
|
808
810
|
/** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
|
|
809
811
|
renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
|
|
810
812
|
/** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
|
|
@@ -2575,11 +2577,16 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
|
|
|
2575
2577
|
/** Callback when texture(s) finish loading */
|
|
2576
2578
|
onLoad?: (texture: MappedTextureType<Url>) => void;
|
|
2577
2579
|
/**
|
|
2578
|
-
*
|
|
2579
|
-
* When true:
|
|
2580
|
+
* Register the texture(s) in R3F's global texture registry for access via useTextures().
|
|
2581
|
+
* When true (the default):
|
|
2580
2582
|
* - Textures persist until explicitly disposed
|
|
2581
|
-
* -
|
|
2582
|
-
*
|
|
2583
|
+
* - On mount, returns existing registered textures if available (preserving modifications like colorSpace)
|
|
2584
|
+
*
|
|
2585
|
+
* Reads are taken once at mount — a mounted `useTexture` does not re-render when the registry
|
|
2586
|
+
* changes. To react to registry swaps, use `useTextures(s => s.get(key))` instead.
|
|
2587
|
+
*
|
|
2588
|
+
* Pass `false` to opt out of registry enrollment entirely.
|
|
2589
|
+
* @default true
|
|
2583
2590
|
*/
|
|
2584
2591
|
cache?: boolean;
|
|
2585
2592
|
};
|
|
@@ -2603,15 +2610,18 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
|
|
|
2603
2610
|
* normal: '/normal.png'
|
|
2604
2611
|
* })
|
|
2605
2612
|
*
|
|
2606
|
-
* //
|
|
2607
|
-
* //
|
|
2608
|
-
* const diffuse = useTexture('/diffuse.png'
|
|
2613
|
+
* // Textures are registered in the global registry by default — the same texture
|
|
2614
|
+
* // object is shared across components and modifications (colorSpace, wrapS, etc.) are preserved
|
|
2615
|
+
* const diffuse = useTexture('/diffuse.png')
|
|
2609
2616
|
* diffuse.colorSpace = THREE.SRGBColorSpace
|
|
2610
2617
|
*
|
|
2611
2618
|
* // Another component gets the SAME texture with colorSpace already set
|
|
2612
|
-
* const sameDiffuse = useTexture('/diffuse.png'
|
|
2619
|
+
* const sameDiffuse = useTexture('/diffuse.png')
|
|
2613
2620
|
*
|
|
2614
|
-
* //
|
|
2621
|
+
* // Opt out of registry enrollment for a one-off texture
|
|
2622
|
+
* const scratch = useTexture('/scratch.png', { cache: false })
|
|
2623
|
+
*
|
|
2624
|
+
* // Access the registry directly
|
|
2615
2625
|
* const { get } = useTextures()
|
|
2616
2626
|
* const cached = get('/diffuse.png')
|
|
2617
2627
|
* ```
|
|
@@ -2628,63 +2638,80 @@ declare const Texture: ({ children, input, onLoad, cache, }: {
|
|
|
2628
2638
|
cache?: boolean;
|
|
2629
2639
|
}) => react_jsx_runtime.JSX.Element;
|
|
2630
2640
|
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2641
|
+
/** Accepted shapes for a registry read: a single key, a list of keys, or a name→key map. */
|
|
2642
|
+
type TextureInput = string | string[] | Record<string, string>;
|
|
2643
|
+
/** Result of a `get()` read, mirroring the input shape. */
|
|
2644
|
+
type TextureResult<Input extends TextureInput> = Input extends string ? Texture$1 | undefined : Input extends string[] ? (Texture$1 | undefined)[] : {
|
|
2645
|
+
[K in keyof Input]: Texture$1 | undefined;
|
|
2634
2646
|
};
|
|
2647
|
+
/** Options for `dispose()`. */
|
|
2648
|
+
interface DisposeOptions {
|
|
2649
|
+
/** Dispose even if the texture still has active references (default false). */
|
|
2650
|
+
force?: boolean;
|
|
2651
|
+
}
|
|
2635
2652
|
interface UseTexturesReturn {
|
|
2636
|
-
/** Map
|
|
2637
|
-
|
|
2638
|
-
/**
|
|
2639
|
-
get
|
|
2640
|
-
/** Check
|
|
2641
|
-
has
|
|
2642
|
-
/**
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2653
|
+
/** The live registry Map (key → Texture). Treat as read-only. */
|
|
2654
|
+
readonly all: Map<string, Texture$1>;
|
|
2655
|
+
/** Read one texture, an array of textures, or a name→texture record (mirrors the input shape). */
|
|
2656
|
+
get<Input extends TextureInput>(input: Input): TextureResult<Input>;
|
|
2657
|
+
/** Check whether a key exists in the registry. */
|
|
2658
|
+
has(key: string): boolean;
|
|
2659
|
+
/**
|
|
2660
|
+
* Register a texture (or a record of textures) that has no URL — e.g. a render
|
|
2661
|
+
* target or procedural texture. URL-loaded textures are registered automatically
|
|
2662
|
+
* by `useTexture` (registry enrollment is on by default).
|
|
2663
|
+
*/
|
|
2664
|
+
add(key: string, texture: Texture$1): void;
|
|
2665
|
+
add(record: Record<string, Texture$1>): void;
|
|
2666
|
+
/**
|
|
2667
|
+
* Dispose a texture's GPU resources and remove it from the registry.
|
|
2668
|
+
* Refcount-aware: if the key is still in use by a mounted `useTexture` consumer it is
|
|
2669
|
+
* skipped (with a warning) unless `{ force: true }` is passed.
|
|
2670
|
+
* @returns true if disposed, false if skipped.
|
|
2671
|
+
*/
|
|
2672
|
+
dispose(key: string, options?: DisposeOptions): boolean;
|
|
2673
|
+
/** Dispose every texture in the registry and clear it. Use on scene teardown. */
|
|
2674
|
+
disposeAll(): void;
|
|
2656
2675
|
}
|
|
2657
2676
|
/**
|
|
2658
|
-
*
|
|
2677
|
+
* Reactive Texture registry — load once with `useTexture`, reach the textures from anywhere.
|
|
2678
|
+
*
|
|
2679
|
+
* This is a registry of plain `Texture` objects (not TSL nodes), so the same texture can feed
|
|
2680
|
+
* a material map, a heightmap sampler, or anything else. It does **not** load — pair it with
|
|
2681
|
+
* `useTexture` for loading (registry enrollment is on by default); `useTextures` is for access and lifecycle.
|
|
2659
2682
|
*
|
|
2660
|
-
*
|
|
2661
|
-
*
|
|
2683
|
+
* The returned handle is **reactive**: the calling component re-renders when the registry
|
|
2684
|
+
* changes. Pass a selector to scope the subscription to a single read.
|
|
2662
2685
|
*
|
|
2663
2686
|
* @example
|
|
2664
2687
|
* ```tsx
|
|
2665
|
-
*
|
|
2688
|
+
* // Load + register once (anywhere in the tree) — registered by default
|
|
2689
|
+
* useTexture({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
|
|
2666
2690
|
*
|
|
2667
|
-
* //
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
2670
|
-
* const tex = useTexture('/textures/diffuse.png', { cache: true })
|
|
2671
|
-
* }
|
|
2672
|
-
*
|
|
2673
|
-
* // Access cached texture from anywhere
|
|
2674
|
-
* const diffuse = get('/textures/diffuse.png')
|
|
2675
|
-
* if (diffuse) material.map = diffuse
|
|
2691
|
+
* // Reach them from another component — record form lands straight into a material
|
|
2692
|
+
* const { map, normalMap } = useTextures().get({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
|
|
2693
|
+
* return <meshStandardMaterial map={map} normalMap={normalMap} />
|
|
2676
2694
|
*
|
|
2677
|
-
* //
|
|
2678
|
-
*
|
|
2695
|
+
* // A set of heightmaps at once
|
|
2696
|
+
* const [a, b, c] = useTextures().get(['/h0.png', '/h1.png', '/h2.png'])
|
|
2679
2697
|
*
|
|
2680
|
-
* //
|
|
2681
|
-
*
|
|
2698
|
+
* // Register a non-URL texture (render target / procedural)
|
|
2699
|
+
* useTextures().add('rt-main', renderTarget.texture)
|
|
2682
2700
|
*
|
|
2683
|
-
* //
|
|
2684
|
-
*
|
|
2701
|
+
* // Deliberate GPU cleanup (refcount-aware; force to override)
|
|
2702
|
+
* useTextures().dispose('/diffuse.jpg')
|
|
2703
|
+
* useTextures().disposeAll() // scene teardown
|
|
2685
2704
|
* ```
|
|
2705
|
+
*
|
|
2706
|
+
* @remarks
|
|
2707
|
+
* **Future expansion:** an imperative async loader (e.g. `await useTextures().load('/x.jpg')`) is
|
|
2708
|
+
* intentionally not included yet. It would let non-React code (loading screens, dynamic streaming)
|
|
2709
|
+
* populate the registry without Suspense, at the cost of putting loading back into this hook. It
|
|
2710
|
+
* will be added only if a concrete consumer needs imperative loading; for now, loading lives in
|
|
2711
|
+
* `useTexture`.
|
|
2686
2712
|
*/
|
|
2687
2713
|
declare function useTextures(): UseTexturesReturn;
|
|
2714
|
+
declare function useTextures<T>(selector: (registry: UseTexturesReturn) => T): T;
|
|
2688
2715
|
|
|
2689
2716
|
/**
|
|
2690
2717
|
* Creates a render target compatible with the current renderer.
|
|
@@ -4766,4 +4793,4 @@ interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'
|
|
|
4766
4793
|
}
|
|
4767
4794
|
|
|
4768
4795
|
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 };
|
|
4769
|
-
export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, WebGPURootState as RootState, RootStore, SchedulerApi, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput,
|
|
4796
|
+
export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeOptions, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, WebGPURootState as RootState, RootStore, SchedulerApi, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput, TextureInput, TextureOperations, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UniformCreator, UniformValue, UniformsWithUtils, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig, XRManager, XRPointerConfig };
|
package/dist/webgpu/index.mjs
CHANGED
|
@@ -2810,6 +2810,7 @@ const createStore = (invalidate, advance) => {
|
|
|
2810
2810
|
buffers: {},
|
|
2811
2811
|
gpuStorage: {},
|
|
2812
2812
|
textures: /* @__PURE__ */ new Map(),
|
|
2813
|
+
_textureRefs: /* @__PURE__ */ new Map(),
|
|
2813
2814
|
renderPipeline: null,
|
|
2814
2815
|
passes: {},
|
|
2815
2816
|
_hmrVersion: 0,
|
|
@@ -3173,18 +3174,18 @@ function buildFromCache(input, textureCache) {
|
|
|
3173
3174
|
function useTexture(input, optionsOrOnLoad) {
|
|
3174
3175
|
const renderer = useThree((state) => state.internal.actualRenderer);
|
|
3175
3176
|
const store = useStore();
|
|
3176
|
-
const textureCache = useThree((state) => state.textures);
|
|
3177
3177
|
const options = typeof optionsOrOnLoad === "function" ? { onLoad: optionsOrOnLoad } : optionsOrOnLoad ?? {};
|
|
3178
|
-
const { onLoad, cache =
|
|
3178
|
+
const { onLoad, cache = true } = options;
|
|
3179
3179
|
const onLoadRef = useRef(onLoad);
|
|
3180
3180
|
onLoadRef.current = onLoad;
|
|
3181
3181
|
const onLoadCalledForRef = useRef(null);
|
|
3182
3182
|
const urls = useMemo(() => getUrls(input), [input]);
|
|
3183
3183
|
const cachedResult = useMemo(() => {
|
|
3184
3184
|
if (!cache) return null;
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3185
|
+
const textures = store.getState().textures;
|
|
3186
|
+
if (!allUrlsCached(urls, textures)) return null;
|
|
3187
|
+
return buildFromCache(input, textures);
|
|
3188
|
+
}, [cache, urls, input, store]);
|
|
3188
3189
|
const loadedTextures = useLoader(
|
|
3189
3190
|
TextureLoader,
|
|
3190
3191
|
IsObject(input) ? Object.values(input) : input
|
|
@@ -3228,8 +3229,6 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3228
3229
|
}, [input, loadedTextures, cachedResult]);
|
|
3229
3230
|
useEffect(() => {
|
|
3230
3231
|
if (!cache) return;
|
|
3231
|
-
if (cachedResult) return;
|
|
3232
|
-
const set = store.setState;
|
|
3233
3232
|
const urlTextureMap = [];
|
|
3234
3233
|
if (typeof input === "string") {
|
|
3235
3234
|
urlTextureMap.push([input, mappedTextures]);
|
|
@@ -3243,18 +3242,32 @@ function useTexture(input, optionsOrOnLoad) {
|
|
|
3243
3242
|
urlTextureMap.push([url, textureRecord[key]]);
|
|
3244
3243
|
}
|
|
3245
3244
|
}
|
|
3246
|
-
|
|
3247
|
-
const
|
|
3248
|
-
let
|
|
3245
|
+
store.setState((state) => {
|
|
3246
|
+
const refs = new Map(state._textureRefs);
|
|
3247
|
+
let textures = state.textures;
|
|
3248
|
+
let added = false;
|
|
3249
3249
|
for (const [url, texture] of urlTextureMap) {
|
|
3250
|
-
if (!
|
|
3251
|
-
|
|
3252
|
-
|
|
3250
|
+
if (!textures.has(url)) {
|
|
3251
|
+
if (!added) {
|
|
3252
|
+
textures = new Map(textures);
|
|
3253
|
+
added = true;
|
|
3254
|
+
}
|
|
3255
|
+
textures.set(url, texture);
|
|
3253
3256
|
}
|
|
3257
|
+
refs.set(url, (refs.get(url) ?? 0) + 1);
|
|
3254
3258
|
}
|
|
3255
|
-
return
|
|
3259
|
+
return added ? { textures, _textureRefs: refs } : { _textureRefs: refs };
|
|
3256
3260
|
});
|
|
3257
|
-
|
|
3261
|
+
return () => store.setState((state) => {
|
|
3262
|
+
const refs = new Map(state._textureRefs);
|
|
3263
|
+
for (const [url] of urlTextureMap) {
|
|
3264
|
+
const next = (refs.get(url) ?? 0) - 1;
|
|
3265
|
+
if (next <= 0) refs.delete(url);
|
|
3266
|
+
else refs.set(url, next);
|
|
3267
|
+
}
|
|
3268
|
+
return { _textureRefs: refs };
|
|
3269
|
+
});
|
|
3270
|
+
}, [cache, input, mappedTextures, store]);
|
|
3258
3271
|
return mappedTextures;
|
|
3259
3272
|
}
|
|
3260
3273
|
useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
|
|
@@ -3270,96 +3283,63 @@ const Texture = ({
|
|
|
3270
3283
|
return /* @__PURE__ */ jsx(Fragment, { children: children?.(ret) });
|
|
3271
3284
|
};
|
|
3272
3285
|
|
|
3273
|
-
function
|
|
3274
|
-
if (entry instanceof Texture$1) return entry;
|
|
3275
|
-
if (entry && typeof entry === "object" && "value" in entry && entry.value instanceof Texture$1) {
|
|
3276
|
-
return entry.value;
|
|
3277
|
-
}
|
|
3278
|
-
return null;
|
|
3279
|
-
}
|
|
3280
|
-
function useTextures() {
|
|
3286
|
+
function useTextures(selector) {
|
|
3281
3287
|
const store = useStore();
|
|
3282
|
-
|
|
3283
|
-
const set = store.setState;
|
|
3288
|
+
const registry = useMemo(() => {
|
|
3284
3289
|
const getState = store.getState;
|
|
3285
|
-
const
|
|
3286
|
-
|
|
3287
|
-
const newMap = new Map(state.textures);
|
|
3288
|
-
newMap.set(key, value);
|
|
3289
|
-
return { textures: newMap };
|
|
3290
|
-
});
|
|
3291
|
-
};
|
|
3292
|
-
const addMultiple = (items) => {
|
|
3293
|
-
set((state) => {
|
|
3294
|
-
const newMap = new Map(state.textures);
|
|
3295
|
-
const entries = items instanceof Map ? items.entries() : Object.entries(items);
|
|
3296
|
-
for (const [key, value] of entries) {
|
|
3297
|
-
newMap.set(key, value);
|
|
3298
|
-
}
|
|
3299
|
-
return { textures: newMap };
|
|
3300
|
-
});
|
|
3301
|
-
};
|
|
3302
|
-
const remove = (key) => {
|
|
3303
|
-
set((state) => {
|
|
3304
|
-
const newMap = new Map(state.textures);
|
|
3305
|
-
newMap.delete(key);
|
|
3306
|
-
return { textures: newMap };
|
|
3307
|
-
});
|
|
3308
|
-
};
|
|
3309
|
-
const removeMultiple = (keys) => {
|
|
3310
|
-
set((state) => {
|
|
3311
|
-
const newMap = new Map(state.textures);
|
|
3312
|
-
for (const key of keys) newMap.delete(key);
|
|
3313
|
-
return { textures: newMap };
|
|
3314
|
-
});
|
|
3315
|
-
};
|
|
3316
|
-
const dispose = (key) => {
|
|
3317
|
-
const entry = getState().textures.get(key);
|
|
3318
|
-
if (entry) {
|
|
3319
|
-
const tex = getTextureValue(entry);
|
|
3320
|
-
tex?.dispose();
|
|
3321
|
-
}
|
|
3322
|
-
remove(key);
|
|
3323
|
-
};
|
|
3324
|
-
const disposeMultiple = (keys) => {
|
|
3325
|
-
const textures = getState().textures;
|
|
3326
|
-
for (const key of keys) {
|
|
3327
|
-
const entry = textures.get(key);
|
|
3328
|
-
if (entry) {
|
|
3329
|
-
const tex = getTextureValue(entry);
|
|
3330
|
-
tex?.dispose();
|
|
3331
|
-
}
|
|
3332
|
-
}
|
|
3333
|
-
removeMultiple(keys);
|
|
3334
|
-
};
|
|
3335
|
-
const disposeAll = () => {
|
|
3336
|
-
const textures = getState().textures;
|
|
3337
|
-
for (const entry of textures.values()) {
|
|
3338
|
-
const tex = getTextureValue(entry);
|
|
3339
|
-
tex?.dispose();
|
|
3340
|
-
}
|
|
3341
|
-
set({ textures: /* @__PURE__ */ new Map() });
|
|
3342
|
-
};
|
|
3290
|
+
const setState = store.setState;
|
|
3291
|
+
const getOne = (key) => getState().textures.get(key);
|
|
3343
3292
|
return {
|
|
3344
|
-
|
|
3345
|
-
get textures() {
|
|
3293
|
+
get all() {
|
|
3346
3294
|
return getState().textures;
|
|
3347
3295
|
},
|
|
3348
|
-
|
|
3349
|
-
|
|
3296
|
+
get(input) {
|
|
3297
|
+
if (typeof input === "string") return getOne(input);
|
|
3298
|
+
if (Array.isArray(input)) return input.map(getOne);
|
|
3299
|
+
const out = {};
|
|
3300
|
+
for (const name in input) out[name] = getOne(input[name]);
|
|
3301
|
+
return out;
|
|
3302
|
+
},
|
|
3350
3303
|
has: (key) => getState().textures.has(key),
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3304
|
+
add(keyOrRecord, texture) {
|
|
3305
|
+
setState((state) => {
|
|
3306
|
+
const textures = new Map(state.textures);
|
|
3307
|
+
if (typeof keyOrRecord === "string") {
|
|
3308
|
+
textures.set(keyOrRecord, texture);
|
|
3309
|
+
} else {
|
|
3310
|
+
for (const key in keyOrRecord) textures.set(key, keyOrRecord[key]);
|
|
3311
|
+
}
|
|
3312
|
+
return { textures };
|
|
3313
|
+
});
|
|
3314
|
+
},
|
|
3315
|
+
dispose(key, options) {
|
|
3316
|
+
const state = getState();
|
|
3317
|
+
const refs = state._textureRefs.get(key) ?? 0;
|
|
3318
|
+
if (refs > 0 && !options?.force) {
|
|
3319
|
+
console.warn(
|
|
3320
|
+
`[useTextures] "${key}" still has ${refs} active reference(s); skipping dispose. Pass { force: true } to override.`
|
|
3321
|
+
);
|
|
3322
|
+
return false;
|
|
3323
|
+
}
|
|
3324
|
+
state.textures.get(key)?.dispose();
|
|
3325
|
+
setState((s) => {
|
|
3326
|
+
const textures = new Map(s.textures);
|
|
3327
|
+
textures.delete(key);
|
|
3328
|
+
const nextRefs = new Map(s._textureRefs);
|
|
3329
|
+
nextRefs.delete(key);
|
|
3330
|
+
return { textures, _textureRefs: nextRefs };
|
|
3331
|
+
});
|
|
3332
|
+
return true;
|
|
3333
|
+
},
|
|
3334
|
+
disposeAll() {
|
|
3335
|
+
for (const texture of getState().textures.values()) texture.dispose();
|
|
3336
|
+
setState({ textures: /* @__PURE__ */ new Map(), _textureRefs: /* @__PURE__ */ new Map() });
|
|
3337
|
+
}
|
|
3361
3338
|
};
|
|
3362
3339
|
}, [store]);
|
|
3340
|
+
const subscribe = selector ? () => selector(registry) : (state) => state.textures;
|
|
3341
|
+
const selected = useThree(subscribe);
|
|
3342
|
+
return selector ? selected : registry;
|
|
3363
3343
|
}
|
|
3364
3344
|
|
|
3365
3345
|
function useRenderTarget(widthOrOptions, heightOrOptions, options) {
|