2017-08-29 21:58:11 +02:00
|
|
|
/**
|
|
|
|
* Face
|
|
|
|
* @param id
|
|
|
|
* @param name
|
|
|
|
* @param v0index
|
|
|
|
* @param v1index
|
|
|
|
* @param v2index
|
|
|
|
* @param materialIndex
|
|
|
|
* @param uvs [[v0uv (GameLib.Vector2), v1uv(GameLib.Vector2), v2uv(GameLib.Vector2)]]
|
|
|
|
* @param color
|
|
|
|
* @param vertexColors
|
|
|
|
* @param vertexNormals
|
|
|
|
* @param normal
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Face = function(
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
v0index,
|
|
|
|
v1index,
|
|
|
|
v2index,
|
|
|
|
materialIndex,
|
|
|
|
uvs,
|
|
|
|
color,
|
|
|
|
vertexColors,
|
|
|
|
vertexNormals,
|
|
|
|
normal
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'Face ' + id;
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(v0index)) {
|
|
|
|
v0index = -1;
|
|
|
|
}
|
|
|
|
this.v0index = v0index;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(v1index)) {
|
|
|
|
v1index = -1;
|
|
|
|
}
|
|
|
|
this.v1index = v1index;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(v2index)) {
|
|
|
|
v2index = -1;
|
|
|
|
}
|
|
|
|
this.v2index = v2index;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(materialIndex)) {
|
|
|
|
materialIndex = -1;
|
|
|
|
}
|
|
|
|
this.materialIndex = materialIndex;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(uvs)) {
|
2017-09-05 05:22:52 +02:00
|
|
|
uvs = [[new GameLib.API.Vector2(0,0), new GameLib.API.Vector2(0,0), new GameLib.API.Vector2(0,0)]];
|
2017-08-29 21:58:11 +02:00
|
|
|
}
|
|
|
|
this.uvs = uvs;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(color)) {
|
|
|
|
color = null;
|
|
|
|
}
|
|
|
|
this.color = color;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
|
|
|
|
vertexColors = [];
|
|
|
|
}
|
|
|
|
this.vertexColors = vertexColors;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(vertexNormals)) {
|
|
|
|
vertexNormals = [];
|
|
|
|
}
|
|
|
|
this.vertexNormals = vertexNormals;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(normal)) {
|
|
|
|
normal = null;
|
|
|
|
}
|
|
|
|
this.normal = normal;
|
|
|
|
};
|
|
|
|
|
2017-09-02 12:54:49 +02:00
|
|
|
/**
|
|
|
|
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
|
|
|
|
*/
|
|
|
|
|
2017-08-29 21:58:11 +02:00
|
|
|
// GameLib.D3.API.Face.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
// GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an API Face from a data object
|
|
|
|
* @constructor
|
|
|
|
* @param objectFace
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Face.FromObject = function(objectFace) {
|
|
|
|
return new GameLib.D3.API.Face(
|
|
|
|
objectFace.id,
|
|
|
|
objectFace.name,
|
|
|
|
objectFace.v0index,
|
|
|
|
objectFace.v1index,
|
|
|
|
objectFace.v2index,
|
|
|
|
objectFace.materialIndex,
|
|
|
|
objectFace.uvs,
|
|
|
|
objectFace.color,
|
|
|
|
objectFace.vertexColors,
|
|
|
|
objectFace.vertexNormals,
|
|
|
|
objectFace.normal
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone a Face
|
|
|
|
* @returns {GameLib.D3.API.Face}
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Face.prototype.clone = function(){
|
|
|
|
return new GameLib.D3.API.Face(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.v0index,
|
|
|
|
this.v1index,
|
|
|
|
this.v2index,
|
|
|
|
this.materialIndex,
|
|
|
|
this.uvs,
|
|
|
|
this.color,
|
|
|
|
this.vertexColors,
|
|
|
|
this.vertexNormals,
|
|
|
|
this.normal
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if two triangles are equal (their vertex indices match in some order)
|
|
|
|
* @param triangle
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Face.prototype.equals = function(triangle) {
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v0index) &&
|
|
|
|
(this.v1index === triangle.v1index) &&
|
|
|
|
(this.v2index === triangle.v2index)
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v0index) &&
|
|
|
|
(this.v1index === triangle.v2index) &&
|
|
|
|
(this.v2index === triangle.v1index)
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v1index) &&
|
|
|
|
(this.v1index === triangle.v0index) &&
|
|
|
|
(this.v2index === triangle.v2index)
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v1index) &&
|
|
|
|
(this.v1index === triangle.v2index) &&
|
|
|
|
(this.v2index === triangle.v0index)
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v2index) &&
|
|
|
|
(this.v1index === triangle.v0index) &&
|
|
|
|
(this.v2index === triangle.v1index)
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(this.v0index === triangle.v2index) &&
|
|
|
|
(this.v1index === triangle.v1index) &&
|
|
|
|
(this.v2index === triangle.v0index)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|