spriteMap.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import type { IDisposable, Scene } from "../scene";
  2. import { Vector2, Vector3 } from "../Maths/math.vector";
  3. import { Texture } from "../Materials/Textures/texture";
  4. import { RawTexture } from "../Materials/Textures/rawTexture";
  5. import type { ISpriteJSONSprite, ISpriteJSONAtlas } from "./ISprites";
  6. import "../Shaders/spriteMap.fragment";
  7. import "../Shaders/spriteMap.vertex";
  8. /**
  9. * Defines the basic options interface of a SpriteMap
  10. */
  11. export interface ISpriteMapOptions {
  12. /**
  13. * Vector2 of the number of cells in the grid.
  14. */
  15. stageSize?: Vector2;
  16. /**
  17. * Vector2 of the size of the output plane in World Units.
  18. */
  19. outputSize?: Vector2;
  20. /**
  21. * Vector3 of the position of the output plane in World Units.
  22. */
  23. outputPosition?: Vector3;
  24. /**
  25. * Vector3 of the rotation of the output plane.
  26. */
  27. outputRotation?: Vector3;
  28. /**
  29. * number of layers that the system will reserve in resources.
  30. */
  31. layerCount?: number;
  32. /**
  33. * number of max animation frames a single cell will reserve in resources.
  34. */
  35. maxAnimationFrames?: number;
  36. /**
  37. * number cell index of the base tile when the system compiles.
  38. */
  39. baseTile?: number;
  40. /**
  41. * boolean flip the sprite after its been repositioned by the framing data.
  42. */
  43. flipU?: boolean;
  44. /**
  45. * Vector3 scalar of the global RGB values of the SpriteMap.
  46. */
  47. colorMultiply?: Vector3;
  48. }
  49. /**
  50. * Defines the IDisposable interface in order to be cleanable from resources.
  51. */
  52. export interface ISpriteMap extends IDisposable {
  53. /**
  54. * String name of the SpriteMap.
  55. */
  56. name: string;
  57. /**
  58. * The JSON Array file from a https://www.codeandweb.com/texturepacker export. Or similar structure.
  59. */
  60. atlasJSON: ISpriteJSONAtlas;
  61. /**
  62. * Texture of the SpriteMap.
  63. */
  64. spriteSheet: Texture;
  65. /**
  66. * The parameters to initialize the SpriteMap with.
  67. */
  68. options: ISpriteMapOptions;
  69. }
  70. /**
  71. * Class used to manage a grid restricted sprite deployment on an Output plane.
  72. */
  73. export declare class SpriteMap implements ISpriteMap {
  74. /** The Name of the spriteMap */
  75. name: string;
  76. /** The JSON file with the frame and meta data */
  77. atlasJSON: ISpriteJSONAtlas;
  78. /** The systems Sprite Sheet Texture */
  79. spriteSheet: Texture;
  80. /** Arguments passed with the Constructor */
  81. options: ISpriteMapOptions;
  82. /** Public Sprite Storage array, parsed from atlasJSON */
  83. sprites: Array<ISpriteJSONSprite>;
  84. /** Returns the Number of Sprites in the System */
  85. get spriteCount(): number;
  86. /** Returns the Position of Output Plane*/
  87. get position(): Vector3;
  88. /** Returns the Position of Output Plane*/
  89. set position(v: Vector3);
  90. /** Returns the Rotation of Output Plane*/
  91. get rotation(): Vector3;
  92. /** Returns the Rotation of Output Plane*/
  93. set rotation(v: Vector3);
  94. /** Sets the AnimationMap*/
  95. get animationMap(): RawTexture;
  96. /** Sets the AnimationMap*/
  97. set animationMap(v: RawTexture);
  98. /** Scene that the SpriteMap was created in */
  99. private _scene;
  100. /** Texture Buffer of Float32 that holds tile frame data*/
  101. private _frameMap;
  102. /** Texture Buffers of Float32 that holds tileMap data*/
  103. private _tileMaps;
  104. /** Texture Buffer of Float32 that holds Animation Data*/
  105. private _animationMap;
  106. /** Custom ShaderMaterial Central to the System*/
  107. private _material;
  108. /** Custom ShaderMaterial Central to the System*/
  109. private _output;
  110. /** Systems Time Ticker*/
  111. private _time;
  112. /**
  113. * Creates a new SpriteMap
  114. * @param name defines the SpriteMaps Name
  115. * @param atlasJSON is the JSON file that controls the Sprites Frames and Meta
  116. * @param spriteSheet is the Texture that the Sprites are on.
  117. * @param options a basic deployment configuration
  118. * @param scene The Scene that the map is deployed on
  119. */
  120. constructor(name: string, atlasJSON: ISpriteJSONAtlas, spriteSheet: Texture, options: ISpriteMapOptions, scene: Scene);
  121. /**
  122. * Returns tileID location
  123. * @returns Vector2 the cell position ID
  124. */
  125. getTileID(): Vector2;
  126. /**
  127. * Gets the UV location of the mouse over the SpriteMap.
  128. * @returns Vector2 the UV position of the mouse interaction
  129. */
  130. getMousePosition(): Vector2;
  131. /**
  132. * Creates the "frame" texture Buffer
  133. * -------------------------------------
  134. * Structure of frames
  135. * "filename": "Falling-Water-2.png",
  136. * "frame": {"x":69,"y":103,"w":24,"h":32},
  137. * "rotated": true,
  138. * "trimmed": true,
  139. * "spriteSourceSize": {"x":4,"y":0,"w":24,"h":32},
  140. * "sourceSize": {"w":32,"h":32}
  141. * @returns RawTexture of the frameMap
  142. */
  143. private _createFrameBuffer;
  144. /**
  145. * Creates the tileMap texture Buffer
  146. * @param buffer normally and array of numbers, or a false to generate from scratch
  147. * @param _layer indicates what layer for a logic trigger dealing with the baseTile. The system uses this
  148. * @returns RawTexture of the tileMap
  149. */
  150. private _createTileBuffer;
  151. /**
  152. * Modifies the data of the tileMaps
  153. * @param _layer is the ID of the layer you want to edit on the SpriteMap
  154. * @param pos is the iVector2 Coordinates of the Tile
  155. * @param tile The SpriteIndex of the new Tile
  156. */
  157. changeTiles(_layer: number | undefined, pos: Vector2 | Vector2[], tile?: number): void;
  158. /**
  159. * Creates the animationMap texture Buffer
  160. * @param buffer normally and array of numbers, or a false to generate from scratch
  161. * @returns RawTexture of the animationMap
  162. */
  163. private _createTileAnimationBuffer;
  164. /**
  165. * Modifies the data of the animationMap
  166. * @param cellID is the Index of the Sprite
  167. * @param _frame is the target Animation frame
  168. * @param toCell is the Target Index of the next frame of the animation
  169. * @param time is a value between 0-1 that is the trigger for when the frame should change tiles
  170. * @param speed is a global scalar of the time variable on the map.
  171. */
  172. addAnimationToTile(cellID?: number, _frame?: number, toCell?: number, time?: number, speed?: number): void;
  173. /**
  174. * Exports the .tilemaps file
  175. */
  176. saveTileMaps(): void;
  177. /**
  178. * Imports the .tilemaps file
  179. * @param url of the .tilemaps file
  180. */
  181. loadTileMaps(url: string): void;
  182. /**
  183. * Release associated resources
  184. */
  185. dispose(): void;
  186. }