UNPKG

@motion-core/motion-gpu

Version:

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

33 lines (32 loc) 1.1 kB
import { createPointerController } from "../core/pointer.js"; import { useMotionGPU } from "./motiongpu-context.js"; import { useEffect, useRef } from "react"; //#region src/lib/react/use-pointer.ts /** * Tracks normalized pointer coordinates and click/tap snapshots for the active `FragCanvas`. */ function usePointer(options = {}) { const motiongpu = useMotionGPU(); const motiongpuRef = useRef(motiongpu); const controllerRef = useRef(null); motiongpuRef.current = motiongpu; if (!controllerRef.current) controllerRef.current = createPointerController({ getRenderMode: () => motiongpuRef.current.renderMode.current, invalidate: () => motiongpuRef.current.invalidate(), advance: () => motiongpuRef.current.advance() }, options); const controller = controllerRef.current; const canvas = motiongpu.canvas; useEffect(() => { controller.updateOptions(options); }); useEffect(() => { if (!canvas) return; controller.mount(canvas); return controller.destroy; }, [canvas, controller]); return controller; } //#endregion export { usePointer }; //# sourceMappingURL=use-pointer.js.map