74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
/**
|
|
* Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created
|
|
* @param physics
|
|
* @param apiShape GameLib.D3.API.Shape
|
|
* @param vertices
|
|
* @param indices
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Shape.TriMesh = function (
|
|
physics,
|
|
apiShape,
|
|
vertices,
|
|
indices
|
|
) {
|
|
this.physics = physics;
|
|
this.physics.isNotCannonThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiShape)) {
|
|
apiShape = {
|
|
shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH
|
|
};
|
|
}
|
|
|
|
if (apiShape instanceof GameLib.D3.Shape.TriMesh) {
|
|
return apiShape;
|
|
}
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
|
vertices = [];
|
|
}
|
|
this.vertices = vertices;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(indices)) {
|
|
indices = [];
|
|
}
|
|
this.indices = indices;
|
|
|
|
GameLib.D3.Shape.call(
|
|
this,
|
|
this.physics,
|
|
apiShape
|
|
);
|
|
};
|
|
|
|
GameLib.D3.Shape.TriMesh.prototype = Object.create(GameLib.D3.Shape.prototype);
|
|
GameLib.D3.Shape.TriMesh.prototype.constructor = GameLib.D3.Shape.TriMesh;
|
|
|
|
/**
|
|
* Create instance
|
|
* @returns {GameLib.D3.Shape.TriMesh}
|
|
*/
|
|
GameLib.D3.Shape.TriMesh.prototype.createInstance = function() {
|
|
|
|
this.instance = new CANNON.TriMesh(
|
|
this.vertices,
|
|
this.indices
|
|
);
|
|
|
|
GameLib.D3.Shape.prototype.createInstance.call(this);
|
|
|
|
};
|
|
|
|
/**
|
|
* Update instance
|
|
*/
|
|
GameLib.D3.Shape.TriMesh.prototype.updateInstance = function() {
|
|
this.instance.vertices = this.vertices;
|
|
this.instance.indices = this.indices;
|
|
this.instance.updateAABB();
|
|
this.instance.updateBoundingSphereRadius();
|
|
this.instance.updateEdges();
|
|
this.instance.updateNormals();
|
|
this.instance.updateTree();
|
|
}; |