import * as THREE from "three"; /** * Uniforms for `TilemapMaterial` */ export interface ITilemapUniforms { /** * Tile nunmbers in order. * * ``` * [ * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * ] * ``` */ tiles?: THREE.Uniform; /** * Size of the tile as UVs: * `{ x: 0.1, y: 0.1 }` */ tileSize?: THREE.Uniform; /** * Number of columns/rows in the tileset: * `{ x: 5, y: 5 }` */ tileCount?: THREE.Uniform; /** * Factor of tileset dimensions vs UVs * `{ x: 2, y: 1 }` */ tileFactor?: THREE.Uniform; /** * Number of columns/rows in the tilemap: * `{ x: 10, y: 5 }` */ tileRepeat?: THREE.Uniform; /** * Spacing between tiles in UVs: * `{ x: 0.01, y: 0.01 }` */ tileSpacing?: THREE.Uniform; [key: string]: THREE.IUniform | undefined; } /** * Options for `TilemapMaterial.tile()` */ export interface ITilemapTilingOptions { /** * An array of indices for tiles from the tileset to be * displayed on the tilemap in order: * * ``` * [ * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * 0, 1, 5, 2, 5, 3, 1, * ] * ``` */ tiles?: number[]; /** * Size of the tiles in the tileset in px: * `{ x: 16, y: 16 }` */ tileSize?: TVec; /** * Size of the tileset in px: * `{ x: 128, y: 128 }` */ tilesetSize?: TVec; /** * Describes the amount of rows/columns in the tilemap: * `{ x: 10, y: 5 }` */ repeat?: TVec; /** * Spacing between tiles in the tileset in px: * `spacing: 2` * * Default: `0` */ spacing?: number; } /** * Base material to render sprites: * * ``` * const tilemap = new THREE.Mesh( * new THREE.PlaneGeometry(10, 10), * new TilemapMeshBasicMaterial({ map: myTileset }), * ); * tilemap.material.tile({ * tile: [1, 2, 3, 4, 5, 6, 7, 8, 9], * tileSize: { x: 16, y: 16 }, * tilesetSize: { x: 96, y: 80 }, * }); * myScene.add(tilemap); * ``` */ export declare abstract class TilemapMaterial extends THREE.Material { /** * The texture for the Tilemap. * https://threejs.org/docs/?q=basicmat#api/en/materials/MeshBasicMaterial.map */ map?: THREE.Texture | null; /** * Uniforms of the shader. May be set before shader * compilation. * * ``` * const mat = new SpriteMaterial({ map: myTexture }); * mat.uniforms = { * myCustomUniform: { value: 10 }, * } * mat.tile({ * // ... * }); * ``` */ uniforms?: ITilemapUniforms; /** * The tiling options set via `.tile()`. Manipulating them * directly takes no effect until `.tile()` is called again. */ tiling?: Required>; /** * Sets the tiling options: * * ``` * const tilemap = new THREE.Mesh( * new THREE.PlaneGeometry(10, 10), * new TilemapMeshBasicMaterial({ map: myTileset }), * ); * tilemap.material.tile({ * tile: [1, 2, 3, 4, 5, 6, 7, 8, 9], * tileSize: { x: 16, y: 16 }, * tilesetSize: { x: 96, y: 80 }, * }); * myScene.add(tilemap); * ``` * * @param {ITilemapTilingOptions} options Tiling options to set. * @returns {void} */ tile(options: ITilemapTilingOptions): void; /** * Overrides `THREE.Material.onBeforeCompile()`. * https://threejs.org/docs/?q=Material#api/en/materials/Material.customProgramCacheKey * * Returns a custom shader cache key identifying the base * material and tiling type. When inheriting from this class * and overriding this method, ensure to adopt the original * key to prevent stale shaders across different configurationsL * * ``` * customProgramCacheKey() { * const originalKey = super.customProgramCacheKey(); * return `${originalKey}-${myKey}`; * } * ``` * * @returns {string} */ customProgramCacheKey(): string; /** * Overrides `THREE.Material.onBeforeCompile()`. * https://threejs.org/docs/?q=Material#api/en/materials/Material.onBeforeCompile * * Injects tiling shader fragments into the material's original * shader program. When inheriting from this class and overriding * this method, ensure to call `super.onBeforeCompile()` * or `this.injectShaderFragments()` to ensure the tiling shader * artifacts are injected. * * ``` * onBeforeCompile(shader) { * // My shader manipulation logic here... * this.injectShaderFragments(shader); * } * ``` * * @param {THREE.WebGLProgramParametersWithUniforms} shader * The shader provided by the renderer. * @returns {void} */ onBeforeCompile(shader: THREE.WebGLProgramParametersWithUniforms): void; /** * Injects tiling shader fragments into the material's original * shader program. * * @param {THREE.WebGLProgramParametersWithUniforms} shader * The shader provided by the renderer. * @returns {void} */ injectShaderFragments(shader: THREE.WebGLProgramParametersWithUniforms): void; /** * Used internally to merge `ITilemapTilingOptions` from`.tile()` * with Required> on * `this.tiling`. * * @param {ITilemapTilingOptions} options Tiling options to set. * @returns {void} */ setTilingOptions(options: ITilemapTilingOptions): void; /** * Used internally to merge pre-existing uniforms after the * shader is (re-)compiled. * * @param {THREE.WebGLProgramParametersWithUniforms} shader * The shader provided by the renderer. * @returns {void} */ mergeUniforms(shader?: THREE.WebGLProgramParametersWithUniforms): void; /** * Static method to create mixins of `THREE.Material`-based * classes and `TilemapMaterial`. Used internally to generate * mixin classes. Generates a new class instead of extending * the original class. Hence do not use to create mixins * during runtime or you'll risk leaking memory. * * @param {T} ctor The class to extend. * @returns {new () => T & TilemapMaterial} */ static extendClass THREE.Material, TParam extends THREE.MaterialParameters>(ctor: TCtor): new (args: TParam) => TCtor & TilemapMaterial; /** * Static method to extend instanciated materials by * TilemapMaterial's prototype. * * @param {T} material The material to extend. * @returns {TilemapMaterial & T} */ static extendMaterial(material: T): TilemapMaterial & T; }