2017-05-16 23:07:52 +00:00
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var GameObject = require('../GameObject');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Components = require('../components');
|
2017-05-16 23:07:52 +00:00
|
|
|
var MeshRender = require('./MeshRender');
|
|
|
|
|
|
|
|
var Mesh = new Class({
|
|
|
|
|
|
|
|
Extends: GameObject,
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
|
|
|
Components.Flip,
|
|
|
|
Components.GetBounds,
|
|
|
|
Components.Origin,
|
|
|
|
Components.ScaleMode,
|
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
|
|
|
Components.Transform,
|
|
|
|
Components.Visible,
|
2017-06-22 02:19:03 +00:00
|
|
|
Components.ScrollFactor,
|
2017-05-16 23:07:52 +00:00
|
|
|
MeshRender
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2018-01-23 19:29:47 +00:00
|
|
|
function Mesh (scene, x, y, vertices, uv, colors, alphas, texture, frame)
|
2017-05-16 23:07:52 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
GameObject.call(this, scene, 'Mesh');
|
2017-05-16 23:07:52 +00:00
|
|
|
|
|
|
|
this.setTexture(texture, frame);
|
|
|
|
this.setPosition(x, y);
|
|
|
|
this.setSizeToFrame();
|
|
|
|
this.setOrigin();
|
|
|
|
|
2017-05-17 16:12:17 +00:00
|
|
|
if (vertices.length !== uv.length)
|
|
|
|
{
|
|
|
|
throw new Error('Phaser: Vertex count must match UV count');
|
|
|
|
}
|
2017-05-23 12:29:40 +00:00
|
|
|
|
2017-06-28 08:03:13 +00:00
|
|
|
var verticesUB = (vertices.length / 2) | 0;
|
|
|
|
|
|
|
|
if (colors.length > 0 && colors.length < verticesUB)
|
2017-05-22 19:29:27 +00:00
|
|
|
{
|
|
|
|
throw new Error('Phaser: Color count must match Vertex count');
|
|
|
|
}
|
2017-05-23 12:29:40 +00:00
|
|
|
|
2017-06-28 08:03:13 +00:00
|
|
|
if (alphas.length > 0 && alphas.length < verticesUB)
|
2017-05-22 19:29:27 +00:00
|
|
|
{
|
|
|
|
throw new Error('Phaser: Alpha count must match Vertex count');
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:29:40 +00:00
|
|
|
var i;
|
|
|
|
|
2017-05-22 19:29:27 +00:00
|
|
|
if (colors.length === 0)
|
|
|
|
{
|
2017-06-28 08:03:13 +00:00
|
|
|
for (i = 0; i < verticesUB; ++i)
|
2017-05-22 19:29:27 +00:00
|
|
|
{
|
|
|
|
colors[i] = 0xFFFFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alphas.length === 0)
|
|
|
|
{
|
2017-06-28 08:03:13 +00:00
|
|
|
for (i = 0; i < verticesUB; ++i)
|
2017-05-22 19:29:27 +00:00
|
|
|
{
|
|
|
|
alphas[i] = 1.0;
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 16:12:17 +00:00
|
|
|
|
|
|
|
this.vertices = new Float32Array(vertices);
|
|
|
|
this.uv = new Float32Array(uv);
|
2017-05-22 19:29:27 +00:00
|
|
|
this.colors = new Uint32Array(colors);
|
|
|
|
this.alphas = new Float32Array(alphas);
|
2017-05-16 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Mesh;
|