2016-12-15 14:53:39 +01:00
|
|
|
/**
|
|
|
|
* Raw Mesh API object - should always correspond with the Mesh Schema
|
|
|
|
* @param id
|
|
|
|
* @param meshType
|
|
|
|
* @param name
|
|
|
|
* @param vertices GameLib.D3.Vertex[]
|
|
|
|
* @param faces GameLib.D3.TriangleFace[]
|
|
|
|
* @param faceVertexUvs
|
|
|
|
* @param materials GameLib.D3.API.Material[]
|
2016-12-20 17:27:36 +01:00
|
|
|
* @param parentMesh
|
|
|
|
* @param parentScene
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param skeleton
|
|
|
|
* @param skinIndices
|
|
|
|
* @param skinWeights
|
|
|
|
* @param position GameLib.API.Vector3
|
|
|
|
* @param quaternion GameLib.API.Quaternion
|
|
|
|
* @param scale GameLib.API.Vector3
|
|
|
|
* @param localPosition GameLib.API.Vector3
|
|
|
|
* @param localRotation GameLib.API.Vector3
|
|
|
|
* @param localScale GameLib.API.Vector3
|
|
|
|
* @param up
|
2016-12-22 17:22:19 +01:00
|
|
|
* @param modelMatrix GameLib.API.Matrix4
|
2017-01-02 17:05:40 +01:00
|
|
|
* @param parentEntity
|
2017-01-04 16:12:30 +01:00
|
|
|
* @param renderOrder
|
2016-12-15 14:53:39 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Mesh = function(
|
|
|
|
id,
|
|
|
|
meshType,
|
|
|
|
name,
|
|
|
|
vertices,
|
|
|
|
faces,
|
|
|
|
faceVertexUvs,
|
|
|
|
materials,
|
2016-12-20 17:27:36 +01:00
|
|
|
parentMesh,
|
|
|
|
parentScene,
|
2016-12-15 14:53:39 +01:00
|
|
|
skeleton,
|
|
|
|
skinIndices,
|
|
|
|
skinWeights,
|
|
|
|
position,
|
|
|
|
quaternion,
|
|
|
|
scale,
|
|
|
|
localPosition,
|
|
|
|
localRotation,
|
|
|
|
localScale,
|
2016-12-22 17:22:19 +01:00
|
|
|
up,
|
2017-01-02 17:05:40 +01:00
|
|
|
modelMatrix,
|
2017-01-04 16:12:30 +01:00
|
|
|
parentEntity,
|
|
|
|
renderOrder
|
2016-12-15 14:53:39 +01:00
|
|
|
) {
|
2016-12-16 16:03:48 +01:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
2016-12-20 17:27:36 +01:00
|
|
|
GameLib.Component.COMPONENT_MESH,
|
|
|
|
{
|
2017-01-10 17:04:30 +01:00
|
|
|
'parentMesh' : GameLib.D3.Mesh,
|
|
|
|
'parentScene' : GameLib.D3.Scene,
|
|
|
|
'materials' : [GameLib.D3.Material],
|
|
|
|
'skeleton' : GameLib.D3.Skeleton
|
2017-01-02 17:05:40 +01:00
|
|
|
},
|
|
|
|
parentEntity
|
2016-12-16 16:03:48 +01:00
|
|
|
);
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(meshType)) {
|
|
|
|
meshType = GameLib.D3.Mesh.TYPE_NORMAL;
|
|
|
|
}
|
|
|
|
this.meshType = meshType;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'Mesh (' + meshType + ')';
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
2017-01-03 18:15:03 +01:00
|
|
|
vertices = [];
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
|
|
|
this.vertices = vertices;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
2017-01-03 18:15:03 +01:00
|
|
|
faces = [];
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
|
|
|
this.faces = faces;
|
|
|
|
|
2016-12-20 17:27:36 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
|
|
|
parentMesh = null;
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
2016-12-20 17:27:36 +01:00
|
|
|
this.parentMesh = parentMesh;
|
2016-12-15 14:53:39 +01:00
|
|
|
|
2016-12-20 17:27:36 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentScene)) {
|
|
|
|
parentScene = null;
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
2016-12-20 17:27:36 +01:00
|
|
|
this.parentScene = parentScene;
|
2016-12-15 14:53:39 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(skeleton)) {
|
|
|
|
skeleton = null;
|
|
|
|
}
|
|
|
|
this.skeleton = skeleton;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(faceVertexUvs)) {
|
|
|
|
faceVertexUvs = [];
|
|
|
|
}
|
|
|
|
this.faceVertexUvs = faceVertexUvs;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(skinIndices)) {
|
|
|
|
skinIndices = [];
|
|
|
|
}
|
|
|
|
this.skinIndices = skinIndices;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(skinWeights)) {
|
|
|
|
skinWeights = [];
|
|
|
|
}
|
|
|
|
this.skinWeights = skinWeights;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
|
|
|
materials = [];
|
|
|
|
}
|
|
|
|
this.materials = materials;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
|
|
|
position = new GameLib.API.Vector3(0,0,0);
|
|
|
|
}
|
|
|
|
this.position = position;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
|
|
|
quaternion = new GameLib.API.Quaternion();
|
|
|
|
}
|
|
|
|
this.quaternion = quaternion;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
|
|
|
scale = new GameLib.API.Vector3(1,1,1);
|
|
|
|
}
|
|
|
|
this.scale = scale;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(localPosition)) {
|
|
|
|
localPosition = new GameLib.API.Vector3(0,0,0);
|
|
|
|
}
|
|
|
|
this.localPosition = localPosition;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(localRotation)) {
|
|
|
|
localRotation = new GameLib.API.Vector3(0,0,0);
|
|
|
|
}
|
|
|
|
this.localRotation = localRotation;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(localScale)) {
|
|
|
|
localScale = new GameLib.API.Vector3(1,1,1);
|
|
|
|
}
|
|
|
|
this.localScale = localScale;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(up)) {
|
|
|
|
up = new GameLib.API.Vector3(0,1,0);
|
|
|
|
}
|
|
|
|
this.up = up;
|
2016-12-22 17:22:19 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(modelMatrix)) {
|
|
|
|
modelMatrix = new GameLib.API.Matrix4();
|
|
|
|
}
|
|
|
|
this.modelMatrix = modelMatrix;
|
2017-01-04 16:12:30 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(renderOrder)) {
|
|
|
|
renderOrder = 0;
|
|
|
|
}
|
|
|
|
this.renderOrder = renderOrder;
|
2016-12-16 16:03:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.API.Mesh.prototype = Object.create(GameLib.Component.prototype);
|
2017-01-05 19:34:28 +01:00
|
|
|
GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an API Mesh from an Object mesh
|
|
|
|
* @param objectMesh
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.D3.API.Mesh.FromObject = function (objectMesh){
|
2017-01-05 19:34:28 +01:00
|
|
|
|
|
|
|
var apiSkeleton = null;
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
if (objectMesh.skeleton) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiSkeleton = GameLib.D3.API.Skeleton.FromObject(objectMesh.skeleton);
|
2017-01-05 19:34:28 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiMaterials = [];
|
|
|
|
if (objectMesh.materials) {
|
|
|
|
apiMaterials = objectMesh.materials.map(
|
|
|
|
function (objectMaterial) {
|
2017-01-31 15:23:38 +01:00
|
|
|
/**
|
|
|
|
* From blender we only get Ids to materials (strings)
|
|
|
|
*/
|
|
|
|
if (objectMaterial instanceof Object) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.D3.API.Material.FromObject(objectMaterial);
|
2017-01-31 15:23:38 +01:00
|
|
|
} else {
|
|
|
|
return objectMaterial
|
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiVertices = [];
|
|
|
|
if (objectMesh.vertices) {
|
|
|
|
apiVertices = objectMesh.vertices.map(
|
|
|
|
function (objectVertex) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.D3.API.Vertex.FromObject(objectVertex);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiPosition = new GameLib.API.Vector3();
|
2017-01-31 11:38:47 +01:00
|
|
|
if (objectMesh.position) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiPosition = GameLib.API.Vector3.FromObject(objectMesh.position);
|
2017-01-31 11:38:47 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiQuaternion = new GameLib.API.Quaternion();
|
2017-01-31 11:38:47 +01:00
|
|
|
if (objectMesh.quaternion) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiQuaternion = GameLib.API.Quaternion.FromObject(objectMesh.quaternion);
|
2017-01-31 11:38:47 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiScale = new GameLib.API.Vector3(1,1,1);
|
|
|
|
if (objectMesh.scale) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiScale = GameLib.API.Vector3.FromObject(objectMesh.scale);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiLocalPosition = new GameLib.API.Vector3();
|
|
|
|
if (objectMesh.localPosition) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiLocalPosition = GameLib.API.Vector3.FromObject(objectMesh.localPosition);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiLocalRotation = new GameLib.API.Vector3();
|
|
|
|
if (objectMesh.localRotation) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiLocalRotation = GameLib.API.Vector3.FromObject(objectMesh.localRotation);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiLocalScale = new GameLib.API.Vector3(1,1,1);
|
|
|
|
if (objectMesh.localScale) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiLocalScale = GameLib.API.Vector3.FromObject(objectMesh.localScale);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiUp = new GameLib.API.Vector3(0,1,0);
|
|
|
|
if (objectMesh.up) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiUp = GameLib.API.Vector3.FromObject(objectMesh.up);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
var apiModelMatrix = new GameLib.API.Matrix4();
|
|
|
|
if (objectMesh.modelMatrix) {
|
2017-06-14 14:21:57 +02:00
|
|
|
apiModelMatrix = GameLib.API.Matrix4.FromObject(objectMesh.modelMatrix);
|
2017-01-10 17:04:30 +01:00
|
|
|
}
|
2017-01-31 11:38:47 +01:00
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
return new GameLib.D3.API.Mesh(
|
|
|
|
objectMesh.id,
|
|
|
|
objectMesh.meshType,
|
|
|
|
objectMesh.name,
|
2017-01-10 17:04:30 +01:00
|
|
|
apiVertices,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectMesh.faces,
|
|
|
|
objectMesh.faceVertexUvs,
|
2017-01-10 17:04:30 +01:00
|
|
|
apiMaterials,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectMesh.parentMesh,
|
|
|
|
objectMesh.parentScene,
|
|
|
|
apiSkeleton,
|
|
|
|
objectMesh.skinIndices,
|
|
|
|
objectMesh.skinWeights,
|
2017-01-31 11:38:47 +01:00
|
|
|
apiPosition,
|
|
|
|
apiQuaternion,
|
|
|
|
apiScale,
|
|
|
|
apiLocalPosition,
|
|
|
|
apiLocalRotation,
|
|
|
|
apiLocalScale,
|
|
|
|
apiUp,
|
|
|
|
apiModelMatrix,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectMesh.parentEntity,
|
|
|
|
objectMesh.renderOrder
|
|
|
|
);
|
|
|
|
};
|