- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
import { Mesh, MeshGeometry, MeshMaterial } from '@pixi/mesh';
import { Texture } from '@pixi/core';
import type { ITypedArray, IArrayBuffer, Renderer } from '@pixi/core';
import type { DRAW_MODES } from '@pixi/constants';
/**
* The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
* For more robust customization, use {@link PIXI.Mesh}.
* @memberof PIXI
*/
export class SimpleMesh extends Mesh
{
/** Upload vertices buffer each frame. */
public autoUpdate: boolean;
/**
* @param texture - The texture to use
* @param {Float32Array} [vertices] - if you want to specify the vertices
* @param {Float32Array} [uvs] - if you want to specify the uvs
* @param {Uint16Array} [indices] - if you want to specify the indices
* @param drawMode - the drawMode, can be any of the Mesh.DRAW_MODES consts
*/
constructor(
texture: Texture = Texture.EMPTY,
vertices?: IArrayBuffer,
uvs?: IArrayBuffer,
indices?: IArrayBuffer,
drawMode?: DRAW_MODES
)
{
const geometry = new MeshGeometry(vertices, uvs, indices);
geometry.getBuffer('aVertexPosition').static = false;
const meshMaterial = new MeshMaterial(texture);
super(geometry, meshMaterial, null, drawMode);
this.autoUpdate = true;
}
/**
* Collection of vertices data.
* @type {Float32Array}
*/
get vertices(): ITypedArray
{
return this.geometry.getBuffer('aVertexPosition').data;
}
set vertices(value: ITypedArray)
{
this.geometry.getBuffer('aVertexPosition').data = value;
}
_render(renderer: Renderer): void
{
if (this.autoUpdate)
{
this.geometry.getBuffer('aVertexPosition').update();
}
super._render(renderer);
}
}