index.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import type { BaseTexture } from '@pixi/core';
  2. import { BLEND_MODES } from '@pixi/constants';
  3. import { Buffer as Buffer_2 } from '@pixi/core';
  4. import { Container } from '@pixi/display';
  5. import type { ExtensionMetadata } from '@pixi/core';
  6. import { Geometry } from '@pixi/core';
  7. import type { IDestroyOptions } from '@pixi/display';
  8. import { Matrix } from '@pixi/math';
  9. import { ObjectRenderer } from '@pixi/core';
  10. import type { Renderer } from '@pixi/core';
  11. import { Shader } from '@pixi/core';
  12. import type { Sprite } from '@pixi/sprite';
  13. import { State } from '@pixi/core';
  14. import { TYPES } from '@pixi/constants';
  15. export declare interface IParticleProperties {
  16. vertices?: boolean;
  17. position?: boolean;
  18. rotation?: boolean;
  19. uvs?: boolean;
  20. tint?: boolean;
  21. alpha?: boolean;
  22. scale?: boolean;
  23. }
  24. export declare interface IParticleRendererProperty {
  25. attributeName: string;
  26. size: number;
  27. type?: TYPES;
  28. uploadFunction: (...params: any[]) => any;
  29. offset: number;
  30. }
  31. /**
  32. * The particle buffer manages the static and dynamic buffers for a particle container.
  33. * @private
  34. * @memberof PIXI
  35. */
  36. declare class ParticleBuffer {
  37. geometry: Geometry;
  38. staticStride: number;
  39. staticBuffer: Buffer_2;
  40. staticData: Float32Array;
  41. staticDataUint32: Uint32Array;
  42. dynamicStride: number;
  43. dynamicBuffer: Buffer_2;
  44. dynamicData: Float32Array;
  45. dynamicDataUint32: Uint32Array;
  46. _updateID: number;
  47. /** Holds the indices of the geometry (quads) to draw. */
  48. indexBuffer: Buffer_2;
  49. /** The number of particles the buffer can hold. */
  50. private size;
  51. /** A list of the properties that are dynamic. */
  52. private dynamicProperties;
  53. /** A list of the properties that are static. */
  54. private staticProperties;
  55. /**
  56. * @param {object} properties - The properties to upload.
  57. * @param {boolean[]} dynamicPropertyFlags - Flags for which properties are dynamic.
  58. * @param {number} size - The size of the batch.
  59. */
  60. constructor(properties: IParticleRendererProperty[], dynamicPropertyFlags: boolean[], size: number);
  61. /** Sets up the renderer context and necessary buffers. */
  62. private initBuffers;
  63. /**
  64. * Uploads the dynamic properties.
  65. * @param children - The children to upload.
  66. * @param startIndex - The index to start at.
  67. * @param amount - The number to upload.
  68. */
  69. uploadDynamic(children: Sprite[], startIndex: number, amount: number): void;
  70. /**
  71. * Uploads the static properties.
  72. * @param children - The children to upload.
  73. * @param startIndex - The index to start at.
  74. * @param amount - The number to upload.
  75. */
  76. uploadStatic(children: Sprite[], startIndex: number, amount: number): void;
  77. /** Destroys the ParticleBuffer. */
  78. destroy(): void;
  79. }
  80. /**
  81. * The ParticleContainer class is a really fast version of the Container built solely for speed,
  82. * so use when you need a lot of sprites or particles.
  83. *
  84. * The tradeoff of the ParticleContainer is that most advanced functionality will not work.
  85. * ParticleContainer implements the basic object transform (position, scale, rotation)
  86. * and some advanced functionality like tint (as of v4.5.6).
  87. *
  88. * Other more advanced functionality like masking, children, filters, etc will not work on sprites in this batch.
  89. *
  90. * It's extremely easy to use:
  91. * ```js
  92. * let container = new ParticleContainer();
  93. *
  94. * for (let i = 0; i < 100; ++i)
  95. * {
  96. * let sprite = PIXI.Sprite.from("myImage.png");
  97. * container.addChild(sprite);
  98. * }
  99. * ```
  100. *
  101. * And here you have a hundred sprites that will be rendered at the speed of light.
  102. * @memberof PIXI
  103. */
  104. export declare class ParticleContainer extends Container<Sprite> {
  105. /**
  106. * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL`
  107. * to reset the blend mode.
  108. * @default PIXI.BLEND_MODES.NORMAL
  109. */
  110. blendMode: BLEND_MODES;
  111. /**
  112. * If true, container allocates more batches in case there are more than `maxSize` particles.
  113. * @default false
  114. */
  115. autoResize: boolean;
  116. /**
  117. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  118. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  119. * The main disadvantage is movement of objects may appear less smooth.
  120. * Default to true here as performance is usually the priority for particles.
  121. * @default true
  122. */
  123. roundPixels: boolean;
  124. /**
  125. * The texture used to render the children.
  126. * @readonly
  127. */
  128. baseTexture: BaseTexture;
  129. tintRgb: Float32Array;
  130. /** @private */
  131. _maxSize: number;
  132. /** @private */
  133. _buffers: ParticleBuffer[];
  134. /** @private */
  135. _batchSize: number;
  136. /**
  137. * Set properties to be dynamic (true) / static (false).
  138. * @private
  139. */
  140. _properties: boolean[];
  141. /**
  142. * For every batch, stores _updateID corresponding to the last change in that batch.
  143. * @private
  144. */
  145. _bufferUpdateIDs: number[];
  146. /**
  147. * When child inserted, removed or changes position this number goes up.
  148. * @private
  149. */
  150. _updateID: number;
  151. /**
  152. * The tint applied to the container.
  153. * This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  154. * @default 0xFFFFFF
  155. */
  156. private _tint;
  157. /**
  158. * @param maxSize - The maximum number of particles that can be rendered by the container.
  159. * Affects size of allocated buffers.
  160. * @param properties - The properties of children that should be uploaded to the gpu and applied.
  161. * @param {boolean} [properties.vertices=false] - When true, vertices be uploaded and applied.
  162. * if sprite's ` scale/anchor/trim/frame/orig` is dynamic, please set `true`.
  163. * @param {boolean} [properties.position=true] - When true, position be uploaded and applied.
  164. * @param {boolean} [properties.rotation=false] - When true, rotation be uploaded and applied.
  165. * @param {boolean} [properties.uvs=false] - When true, uvs be uploaded and applied.
  166. * @param {boolean} [properties.tint=false] - When true, alpha and tint be uploaded and applied.
  167. * @param {number} [batchSize=16384] - Number of particles per batch. If less than maxSize, it uses maxSize instead.
  168. * @param {boolean} [autoResize=false] - If true, container allocates more batches in case
  169. * there are more than `maxSize` particles.
  170. */
  171. constructor(maxSize?: number, properties?: IParticleProperties, batchSize?: number, autoResize?: boolean);
  172. /**
  173. * Sets the private properties array to dynamic / static based on the passed properties object
  174. * @param properties - The properties to be uploaded
  175. */
  176. setProperties(properties: IParticleProperties): void;
  177. updateTransform(): void;
  178. /**
  179. * The tint applied to the container. This is a hex value.
  180. * A value of 0xFFFFFF will remove any tint effect.
  181. * IMPORTANT: This is a WebGL only feature and will be ignored by the canvas renderer.
  182. * @default 0xFFFFFF
  183. */
  184. get tint(): number;
  185. set tint(value: number);
  186. /**
  187. * Renders the container using the WebGL renderer.
  188. * @param renderer - The WebGL renderer.
  189. */
  190. render(renderer: Renderer): void;
  191. /**
  192. * Set the flag that static data should be updated to true
  193. * @param smallestChildIndex - The smallest child index.
  194. */
  195. protected onChildrenChange(smallestChildIndex: number): void;
  196. dispose(): void;
  197. /**
  198. * Destroys the container
  199. * @param options - Options parameter. A boolean will act as if all options
  200. * have been set to that value
  201. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  202. * destroy method called as well. 'options' will be passed on to those calls.
  203. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  204. * Should it destroy the texture of the child sprite
  205. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  206. * Should it destroy the base texture of the child sprite
  207. */
  208. destroy(options?: IDestroyOptions | boolean): void;
  209. }
  210. /**
  211. * Renderer for Particles that is designer for speed over feature set.
  212. * @memberof PIXI
  213. */
  214. export declare class ParticleRenderer extends ObjectRenderer {
  215. /** @ignore */
  216. static extension: ExtensionMetadata;
  217. /** The WebGL state in which this renderer will work. */
  218. readonly state: State;
  219. /** The default shader that is used if a sprite doesn't have a more specific one. */
  220. shader: Shader;
  221. tempMatrix: Matrix;
  222. properties: IParticleRendererProperty[];
  223. /**
  224. * @param renderer - The renderer this sprite batch works for.
  225. */
  226. constructor(renderer: Renderer);
  227. /**
  228. * Renders the particle container object.
  229. * @param container - The container to render using this ParticleRenderer.
  230. */
  231. render(container: ParticleContainer): void;
  232. /**
  233. * Creates one particle buffer for each child in the container we want to render and updates internal properties.
  234. * @param container - The container to render using this ParticleRenderer
  235. * @returns - The buffers
  236. */
  237. private generateBuffers;
  238. /**
  239. * Creates one more particle buffer, because container has autoResize feature.
  240. * @param container - The container to render using this ParticleRenderer
  241. * @returns - The generated buffer
  242. */
  243. private _generateOneMoreBuffer;
  244. /**
  245. * Uploads the vertices.
  246. * @param children - the array of sprites to render
  247. * @param startIndex - the index to start from in the children array
  248. * @param amount - the amount of children that will have their vertices uploaded
  249. * @param array - The vertices to upload.
  250. * @param stride - Stride to use for iteration.
  251. * @param offset - Offset to start at.
  252. */
  253. uploadVertices(children: Sprite[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void;
  254. /**
  255. * Uploads the position.
  256. * @param children - the array of sprites to render
  257. * @param startIndex - the index to start from in the children array
  258. * @param amount - the amount of children that will have their positions uploaded
  259. * @param array - The vertices to upload.
  260. * @param stride - Stride to use for iteration.
  261. * @param offset - Offset to start at.
  262. */
  263. uploadPosition(children: Sprite[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void;
  264. /**
  265. * Uploads the rotation.
  266. * @param children - the array of sprites to render
  267. * @param startIndex - the index to start from in the children array
  268. * @param amount - the amount of children that will have their rotation uploaded
  269. * @param array - The vertices to upload.
  270. * @param stride - Stride to use for iteration.
  271. * @param offset - Offset to start at.
  272. */
  273. uploadRotation(children: Sprite[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void;
  274. /**
  275. * Uploads the UVs.
  276. * @param children - the array of sprites to render
  277. * @param startIndex - the index to start from in the children array
  278. * @param amount - the amount of children that will have their rotation uploaded
  279. * @param array - The vertices to upload.
  280. * @param stride - Stride to use for iteration.
  281. * @param offset - Offset to start at.
  282. */
  283. uploadUvs(children: Sprite[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void;
  284. /**
  285. * Uploads the tint.
  286. * @param children - the array of sprites to render
  287. * @param startIndex - the index to start from in the children array
  288. * @param amount - the amount of children that will have their rotation uploaded
  289. * @param array - The vertices to upload.
  290. * @param stride - Stride to use for iteration.
  291. * @param offset - Offset to start at.
  292. */
  293. uploadTint(children: Sprite[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void;
  294. /** Destroys the ParticleRenderer. */
  295. destroy(): void;
  296. }
  297. export { }