-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
SimpleMesh.js
60 lines (52 loc) · 1.64 KB
/
SimpleMesh.js
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
import { Mesh, MeshGeometry, MeshMaterial } from '@pixi/mesh';
import { Texture } from '@pixi/core';
/**
* The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
* For more robust customization, use {@link PIXI.Mesh}.
*
* @class
* @extends PIXI.Mesh
* @memberof PIXI
*/
export class SimpleMesh extends Mesh
{
/**
* @param {PIXI.Texture} [texture=Texture.EMPTY] - 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 {number} [drawMode] - the drawMode, can be any of the Mesh.DRAW_MODES consts
*/
constructor(texture = Texture.EMPTY, vertices, uvs, indices, drawMode)
{
const geometry = new MeshGeometry(vertices, uvs, indices);
geometry.getBuffer('aVertexPosition').static = false;
const meshMaterial = new MeshMaterial(texture);
super(geometry, meshMaterial, null, drawMode);
/**
* upload vertices buffer each frame
* @member {boolean}
*/
this.autoUpdate = true;
}
/**
* Collection of vertices data.
* @member {Float32Array}
*/
get vertices()
{
return this.geometry.getBuffer('aVertexPosition').data;
}
set vertices(value)
{
this.geometry.getBuffer('aVertexPosition').data = value;
}
_render(renderer)
{
if (this.autoUpdate)
{
this.geometry.getBuffer('aVertexPosition').update();
}
super._render(renderer);
}
}