import { SpriteSheet } from "../sprites/types.js"; import { TextureOptions, TexturePreset } from "./texturePresets.js"; import { Loader } from "three"; import { NormalSourceDescriptor } from "@three-flatland/normals"; import { BakedAssetLoaderOptions } from "@three-flatland/bake"; //#region src/loaders/SpriteSheetLoader.d.ts /** * Shape accepted by `SpriteSheetLoaderOptions.normals`. * * - `false` — no normals generated. * - `true` — auto-synthesize one region per frame. * - `NormalSourceDescriptor` — user provides defaults (and optionally * regions). Frame-derived regions fill in when `regions` is absent. */ type SpriteSheetNormalsOption = false | true | NormalSourceDescriptor; /** * Options for loading a spritesheet. */ interface SpriteSheetLoaderOptions extends BakedAssetLoaderOptions { /** Texture preset or custom options. Overrides loader and global defaults. */ texture?: TexturePreset | TextureOptions; /** * Normal-map generation. When truthy, the loader synthesizes one * region per sprite frame (pixel rects from the sheet JSON), probes * for a baked `.normal.png` sibling with a matching * descriptor hash, and falls back to an in-memory bake. * * The resulting texture is attached to `SpriteSheet.normalMap`, * 1:1 co-registered with the atlas. */ normals?: SpriteSheetNormalsOption; /** * Alpha hitmask generation. When `true`, the loader probes for a * baked `.alpha.png` sidecar and falls back to a * runtime readback via `AlphaMap.fromTexture`. * * The resulting map is attached to `SpriteSheet.alphaMap` and * consumed by `hitTestMode: 'alpha'`. Spec §8.4. */ alpha?: boolean; } /** * Loader for spritesheet JSON files. * * Extends Three.js's Loader class for compatibility with R3F's useLoader. * Supports: * - JSON Hash format (TexturePacker default) * - JSON Array format * * @example * ```typescript * // Three.js usage - static API * const sheet = await SpriteSheetLoader.load('/sprites/player.json'); * * // R3F usage - works with useLoader * import { SpriteSheetLoader } from 'three-flatland/react'; * const sheet = useLoader(SpriteSheetLoader, '/sprites/player.json'); * * // Override preset via extension * const sheet = useLoader(SpriteSheetLoader, '/sprites/ui.json', (loader) => { * loader.preset = 'smooth'; * }); * * // Set loader-level default * SpriteSheetLoader.options = 'smooth'; * ``` */ declare class SpriteSheetLoader extends Loader { private static cache; /** * Texture options for this loader class. * When undefined, falls through to TextureConfig.options. */ static options: TexturePreset | TextureOptions | undefined; /** * Instance-level preset override. * Set via R3F's useLoader extension callback. * * @example * ```tsx * const sheet = useLoader(SpriteSheetLoader, '/sprites/ui.json', (loader) => { * loader.preset = 'smooth'; * }); * ``` */ preset: TexturePreset | TextureOptions | undefined; /** * Normal-map generation. See {@link SpriteSheetLoaderOptions.normals}. */ normals: SpriteSheetNormalsOption; /** * Alpha hitmask generation. See {@link SpriteSheetLoaderOptions.alpha}. */ alpha: boolean; /** * Generate this sheet's normal map in the browser on every load * instead of loading a pre-baked sidecar. The in-memory bake runs on * every load; the sidecar probe and "no baked sibling" warn are * skipped. Not a dev-iteration knob. * See {@link BakedAssetLoaderOptions.forceRuntime}. */ forceRuntime: boolean; /** * Load a spritesheet asynchronously (for R3F useLoader compatibility). * Presets are automatically applied. */ loadAsync(url: string): Promise; /** * Load a spritesheet from a JSON file (static method for Three.js usage). * Results are cached by URL and resolved options. */ static load(url: string, options?: SpriteSheetLoaderOptions): Promise; /** * Get cache key including resolved options. */ private static getCacheKey; /** * Load without caching. */ private static loadUncached; /** * Synthesize a descriptor from the sheet's frame rects and hand it * to `resolveNormalMap`. One region per frame — region-local alpha * clamping keeps adjacent frames from bleeding gradients into each * other. */ private static resolveSheetNormals; /** * Parse JSON Hash format. Returns the ordered frame names + per-frame * durations alongside the frame map so the animation parser can * resolve Aseprite `frameTags` (which use integer indices into the * frames array — relies on insertion order being preserved). */ private static parseJSONHash; /** * Parse JSON Array format. */ private static parseJSONArray; /** * Load a texture with the specified options. */ private static loadTexture; /** * Create a SpriteSheet object. */ private static createSpriteSheet; /** * Normalize a frame's optional polygon payload to a SpriteFrameMesh. * * Two accepted inputs: * - our own \`mesh\` field — already local [-0.5, 0.5] + frame-local * UV [0, 1], pre-triangulated; passed through * - TexturePacker polygon-trim output (\`vertices\`/\`triangles\` in * source-image pixels, y-down) — normalized here. Frame-local UVs * are derived from the vertex position within the (trimmed) frame * rect, so the shader's instanceUV atlas remap applies unchanged. */ private static parseFrameMesh; /** * Clear the cache. */ static clearCache(): void; /** * Preload multiple spritesheets. */ static preload(urls: string[], options?: SpriteSheetLoaderOptions): Promise; } //#endregion export { SpriteSheetLoader, SpriteSheetLoaderOptions, SpriteSheetNormalsOption }; //# sourceMappingURL=SpriteSheetLoader.d.ts.map