forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMesh.js
More file actions
82 lines (65 loc) · 1.97 KB
/
Copy pathMesh.js
File metadata and controls
82 lines (65 loc) · 1.97 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var Class = require('../../utils/Class');
var GameObject = require('../GameObject');
var Components = require('../components');
var MeshRender = require('./MeshRender');
var Mesh = new Class({
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.Flip,
Components.GetBounds,
Components.Origin,
Components.RenderTarget,
Components.ScaleMode,
Components.Size,
Components.Texture,
Components.Transform,
Components.Visible,
Components.ScrollFactor,
MeshRender
],
initialize:
function Mesh (scene, x, y, vertices, uv, indices, colors, alphas, texture, frame)
{
GameObject.call(this, scene, 'Mesh');
this.setTexture(texture, frame);
this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin();
if (vertices.length !== uv.length)
{
throw new Error('Phaser: Vertex count must match UV count');
}
var verticesUB = (vertices.length / 2) | 0;
if (colors.length > 0 && colors.length < verticesUB)
{
throw new Error('Phaser: Color count must match Vertex count');
}
if (alphas.length > 0 && alphas.length < verticesUB)
{
throw new Error('Phaser: Alpha count must match Vertex count');
}
var i;
if (colors.length === 0)
{
for (i = 0; i < verticesUB; ++i)
{
colors[i] = 0xFFFFFF;
}
}
if (alphas.length === 0)
{
for (i = 0; i < verticesUB; ++i)
{
alphas[i] = 1.0;
}
}
this.vertices = new Float32Array(vertices);
this.uv = new Float32Array(uv);
this.indices = new Uint16Array(indices);
this.colors = new Uint32Array(colors);
this.alphas = new Float32Array(alphas);
}
});
module.exports = Mesh;