index.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /// <reference path="./global.d.ts" />
  2. import type { BLEND_MODES } from '@pixi/constants';
  3. import type { Buffer as Buffer_2 } from '@pixi/core';
  4. import { Container } from '@pixi/display';
  5. import type { Dict } from '@pixi/utils';
  6. import { DRAW_MODES } from '@pixi/constants';
  7. import { Geometry } from '@pixi/core';
  8. import type { IArrayBuffer } from '@pixi/core';
  9. import type { IDestroyOptions } from '@pixi/display';
  10. import type { IPointData } from '@pixi/math';
  11. import { Program } from '@pixi/core';
  12. import type { Renderer } from '@pixi/core';
  13. import { Shader } from '@pixi/core';
  14. import { State } from '@pixi/core';
  15. import type { Texture } from '@pixi/core';
  16. import { TextureMatrix } from '@pixi/core';
  17. export declare interface IMeshMaterialOptions {
  18. alpha?: number;
  19. tint?: number;
  20. pluginName?: string;
  21. program?: Program;
  22. uniforms?: Dict<unknown>;
  23. }
  24. export declare interface Mesh extends GlobalMixins.Mesh {
  25. }
  26. /**
  27. * Base mesh class.
  28. *
  29. * This class empowers you to have maximum flexibility to render any kind of WebGL visuals you can think of.
  30. * This class assumes a certain level of WebGL knowledge.
  31. * If you know a bit this should abstract enough away to make your life easier!
  32. *
  33. * Pretty much ALL WebGL can be broken down into the following:
  34. * - Geometry - The structure and data for the mesh. This can include anything from positions, uvs, normals, colors etc..
  35. * - Shader - This is the shader that PixiJS will render the geometry with (attributes in the shader must match the geometry)
  36. * - State - This is the state of WebGL required to render the mesh.
  37. *
  38. * Through a combination of the above elements you can render anything you want, 2D or 3D!
  39. * @memberof PIXI
  40. */
  41. export declare class Mesh<T extends Shader = MeshMaterial> extends Container {
  42. /**
  43. * Represents the vertex and fragment shaders that processes the geometry and runs on the GPU.
  44. * Can be shared between multiple Mesh objects.
  45. * @type {PIXI.Shader|PIXI.MeshMaterial}
  46. */
  47. shader: T;
  48. /**
  49. * Represents the WebGL state the Mesh required to render, excludes shader and geometry. E.g.,
  50. * blend mode, culling, depth testing, direction of rendering triangles, backface, etc.
  51. */
  52. state: State;
  53. /** The way the Mesh should be drawn, can be any of the {@link PIXI.DRAW_MODES} constants. */
  54. drawMode: DRAW_MODES;
  55. /**
  56. * Typically the index of the IndexBuffer where to start drawing.
  57. * @default 0
  58. */
  59. start: number;
  60. /**
  61. * How much of the geometry to draw, by default `0` renders everything.
  62. * @default 0
  63. */
  64. size: number;
  65. private _geometry;
  66. /** This is the caching layer used by the batcher. */
  67. private vertexData;
  68. /** If geometry is changed used to decide to re-transform the vertexData. */
  69. private vertexDirty;
  70. private _transformID;
  71. /** Internal roundPixels field. */
  72. private _roundPixels;
  73. /** Batched UV's are cached for atlas textures. */
  74. private batchUvs;
  75. /**
  76. * These are used as easy access for batching.
  77. * @private
  78. */
  79. uvs: Float32Array;
  80. /**
  81. * These are used as easy access for batching.
  82. * @private
  83. */
  84. indices: Uint16Array;
  85. _tintRGB: number;
  86. _texture: Texture;
  87. /**
  88. * @param geometry - The geometry the mesh will use.
  89. * @param {PIXI.MeshMaterial} shader - The shader the mesh will use.
  90. * @param state - The state that the WebGL context is required to be in to render the mesh
  91. * if no state is provided, uses {@link PIXI.State.for2d} to create a 2D state for PixiJS.
  92. * @param drawMode - The drawMode, can be any of the {@link PIXI.DRAW_MODES} constants.
  93. */
  94. constructor(geometry: Geometry, shader: T, state?: State, drawMode?: DRAW_MODES);
  95. /**
  96. * Includes vertex positions, face indices, normals, colors, UVs, and
  97. * custom attributes within buffers, reducing the cost of passing all
  98. * this data to the GPU. Can be shared between multiple Mesh objects.
  99. */
  100. get geometry(): Geometry;
  101. set geometry(value: Geometry);
  102. /**
  103. * To change mesh uv's, change its uvBuffer data and increment its _updateID.
  104. * @readonly
  105. */
  106. get uvBuffer(): Buffer_2;
  107. /**
  108. * To change mesh vertices, change its uvBuffer data and increment its _updateID.
  109. * Incrementing _updateID is optional because most of Mesh objects do it anyway.
  110. * @readonly
  111. */
  112. get verticesBuffer(): Buffer_2;
  113. /** Alias for {@link PIXI.Mesh#shader}. */
  114. set material(value: T);
  115. get material(): T;
  116. /**
  117. * The blend mode to be applied to the Mesh. Apply a value of
  118. * `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  119. * @default PIXI.BLEND_MODES.NORMAL;
  120. */
  121. set blendMode(value: BLEND_MODES);
  122. get blendMode(): BLEND_MODES;
  123. /**
  124. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  125. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  126. * The main disadvantage is movement of objects may appear less smooth.
  127. * To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
  128. * @default false
  129. */
  130. set roundPixels(value: boolean);
  131. get roundPixels(): boolean;
  132. /**
  133. * The multiply tint applied to the Mesh. This is a hex value. A value of
  134. * `0xFFFFFF` will remove any tint effect.
  135. *
  136. * Null for non-MeshMaterial shaders
  137. * @default 0xFFFFFF
  138. */
  139. get tint(): number;
  140. set tint(value: number);
  141. /** The texture that the Mesh uses. Null for non-MeshMaterial shaders */
  142. get texture(): Texture;
  143. set texture(value: Texture);
  144. /**
  145. * Standard renderer draw.
  146. * @param renderer - Instance to renderer.
  147. */
  148. protected _render(renderer: Renderer): void;
  149. /**
  150. * Standard non-batching way of rendering.
  151. * @param renderer - Instance to renderer.
  152. */
  153. protected _renderDefault(renderer: Renderer): void;
  154. /**
  155. * Rendering by using the Batch system.
  156. * @param renderer - Instance to renderer.
  157. */
  158. protected _renderToBatch(renderer: Renderer): void;
  159. /** Updates vertexData field based on transform and vertices. */
  160. calculateVertices(): void;
  161. /** Updates uv field based on from geometry uv's or batchUvs. */
  162. calculateUvs(): void;
  163. /**
  164. * Updates the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
  165. * there must be a aVertexPosition attribute present in the geometry for bounds to be calculated correctly.
  166. */
  167. protected _calculateBounds(): void;
  168. /**
  169. * Tests if a point is inside this mesh. Works only for PIXI.DRAW_MODES.TRIANGLES.
  170. * @param point - The point to test.
  171. * @returns - The result of the test.
  172. */
  173. containsPoint(point: IPointData): boolean;
  174. destroy(options?: IDestroyOptions | boolean): void;
  175. /** The maximum number of vertices to consider batchable. Generally, the complexity of the geometry. */
  176. static BATCHABLE_SIZE: number;
  177. }
  178. /**
  179. * Class controls cache for UV mapping from Texture normal space to BaseTexture normal space.
  180. * @memberof PIXI
  181. */
  182. export declare class MeshBatchUvs {
  183. /** UV Buffer data. */
  184. readonly data: Float32Array;
  185. /** Buffer with normalized UV's. */
  186. uvBuffer: Buffer_2;
  187. /** Material UV matrix. */
  188. uvMatrix: TextureMatrix;
  189. private _bufferUpdateId;
  190. private _textureUpdateId;
  191. _updateID: number;
  192. /**
  193. * @param uvBuffer - Buffer with normalized uv's
  194. * @param uvMatrix - Material UV matrix
  195. */
  196. constructor(uvBuffer: Buffer_2, uvMatrix: TextureMatrix);
  197. /**
  198. * Updates
  199. * @param forceUpdate - force the update
  200. */
  201. update(forceUpdate?: boolean): void;
  202. }
  203. /**
  204. * Standard 2D geometry used in PixiJS.
  205. *
  206. * Geometry can be defined without passing in a style or data if required.
  207. *
  208. * ```js
  209. * const geometry = new PIXI.Geometry();
  210. *
  211. * geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
  212. * geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1], 2);
  213. * geometry.addIndex([0,1,2,1,3,2]);
  214. *
  215. * ```
  216. * @memberof PIXI
  217. */
  218. export declare class MeshGeometry extends Geometry {
  219. /**
  220. * Dirty flag to limit update calls on Mesh. For example,
  221. * limiting updates on a single Mesh instance with a shared Geometry
  222. * within the render loop.
  223. * @private
  224. * @default -1
  225. */
  226. _updateId: number;
  227. /**
  228. * @param {Float32Array|number[]} [vertices] - Positional data on geometry.
  229. * @param {Float32Array|number[]} [uvs] - Texture UVs.
  230. * @param {Uint16Array|number[]} [index] - IndexBuffer
  231. */
  232. constructor(vertices?: IArrayBuffer, uvs?: IArrayBuffer, index?: IArrayBuffer);
  233. /**
  234. * If the vertex position is updated.
  235. * @readonly
  236. * @private
  237. */
  238. get vertexDirtyId(): number;
  239. }
  240. export declare interface MeshMaterial extends GlobalMixins.MeshMaterial {
  241. }
  242. /**
  243. * Slightly opinionated default shader for PixiJS 2D objects.
  244. * @memberof PIXI
  245. */
  246. export declare class MeshMaterial extends Shader {
  247. /**
  248. * TextureMatrix instance for this Mesh, used to track Texture changes.
  249. * @readonly
  250. */
  251. readonly uvMatrix: TextureMatrix;
  252. /**
  253. * `true` if shader can be batch with the renderer's batch system.
  254. * @default true
  255. */
  256. batchable: boolean;
  257. /**
  258. * Renderer plugin for batching.
  259. * @default 'batch'
  260. */
  261. pluginName: string;
  262. _tintRGB: number;
  263. /**
  264. * Only do update if tint or alpha changes.
  265. * @private
  266. * @default false
  267. */
  268. private _colorDirty;
  269. private _alpha;
  270. private _tint;
  271. /**
  272. * @param uSampler - Texture that material uses to render.
  273. * @param options - Additional options
  274. * @param {number} [options.alpha=1] - Default alpha.
  275. * @param {number} [options.tint=0xFFFFFF] - Default tint.
  276. * @param {string} [options.pluginName='batch'] - Renderer plugin for batching.
  277. * @param {PIXI.Program} [options.program=0xFFFFFF] - Custom program.
  278. * @param {object} [options.uniforms] - Custom uniforms.
  279. */
  280. constructor(uSampler: Texture, options?: IMeshMaterialOptions);
  281. /** Reference to the texture being rendered. */
  282. get texture(): Texture;
  283. set texture(value: Texture);
  284. /**
  285. * This gets automatically set by the object using this.
  286. * @default 1
  287. */
  288. set alpha(value: number);
  289. get alpha(): number;
  290. /**
  291. * Multiply tint for the material.
  292. * @default 0xFFFFFF
  293. */
  294. set tint(value: number);
  295. get tint(): number;
  296. /** Gets called automatically by the Mesh. Intended to be overridden for custom {@link MeshMaterial} objects. */
  297. update(): void;
  298. }
  299. export { }