UNPKG

@motion-core/motion-gpu

Version:

Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.

44 lines (43 loc) 1.38 kB
import "../core/error-report.js"; import "../core/current-value.js"; import "../core/texture-loader.js"; import { createTextureLoadController } from "../core/texture-load-controller.js"; import { useEffect, useRef } from "react"; //#region src/lib/react/use-texture.ts /** * Loads textures from URLs and exposes reactive loading/error state. * * @param urlInput - URLs array or lazy URL provider. * @param options - Loader options passed to URL fetch/decode pipeline. * @returns Reactive texture loading state with reload support. */ function useTexture(urlInput, options = {}) { const optionsRef = useRef(options); const urlInputRef = useRef(urlInput); const controllerRef = useRef(null); optionsRef.current = options; urlInputRef.current = urlInput; controllerRef.current ??= createTextureLoadController({ getUrls: () => { const input = urlInputRef.current; return typeof input === "function" ? input() : input; }, getOptions: () => optionsRef.current }); const controller = controllerRef.current; useEffect(() => { controller.resume(); controller.reload(); return controller.dispose; }, [controller]); return { textures: controller.textures, loading: controller.loading, error: controller.error, errorReport: controller.errorReport, reload: controller.reload }; } //#endregion export { useTexture }; //# sourceMappingURL=use-texture.js.map