107 lines
2.7 KiB
JavaScript
107 lines
2.7 KiB
JavaScript
/**
|
|
* Raw Shape API object - should always correspond with the Shape Schema
|
|
* @param id
|
|
* @param name
|
|
* @param boundingSphereRadius
|
|
* @param collisionResponse
|
|
* @param frictionMaterial
|
|
* @param parentMesh
|
|
* @param parentEntity
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Shape = function(
|
|
id,
|
|
name,
|
|
boundingSphereRadius,
|
|
collisionResponse,
|
|
frictionMaterial,
|
|
parentMesh,
|
|
parentEntity
|
|
) {
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
id = GameLib.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'Shape (' + this.id + ')';
|
|
|
|
if (this instanceof GameLib.D3.Shape.ConvexHull) {
|
|
name = 'Shape Convex Hull (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.ConvexHull.Cylinder) {
|
|
name = 'Shape Convex Hull Cylinder (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.HeightMap) {
|
|
name = 'Shape Heightmap (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.Box) {
|
|
name = 'Shape Box (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.Plane) {
|
|
name = 'Shape Plane (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.Sphere) {
|
|
name = 'Shape Sphere (' + this.id + ')';
|
|
}
|
|
|
|
if (this instanceof GameLib.D3.Shape.TriMesh) {
|
|
name = 'Shape TriMesh (' + this.id + ')';
|
|
}
|
|
}
|
|
this.name = name;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(boundingSphereRadius)) {
|
|
boundingSphereRadius = 0;
|
|
}
|
|
this.boundingSphereRadius = boundingSphereRadius;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(collisionResponse)) {
|
|
collisionResponse = true;
|
|
}
|
|
this.collisionResponse = collisionResponse;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(frictionMaterial)) {
|
|
frictionMaterial = null;
|
|
}
|
|
this.frictionMaterial = frictionMaterial;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
|
parentMesh = null;
|
|
}
|
|
this.parentMesh = parentMesh;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
parentEntity = null;
|
|
}
|
|
this.parentEntity = parentEntity;
|
|
};
|
|
|
|
GameLib.D3.API.Shape.prototype = Object.create(GameLib.Component.prototype);
|
|
GameLib.D3.API.Shape.prototype.constructor = GameLib.D3.API.Shape;
|
|
|
|
/**
|
|
* Creates an API Shape from an Object Shape
|
|
* @param objectShape
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Shape.FromObject = function(objectShape) {
|
|
return new GameLib.D3.API.Shape(
|
|
objectShape.id,
|
|
objectShape.name,
|
|
objectShape.boundingSphereRadius,
|
|
objectShape.collisionResponse,
|
|
objectShape.frictionMaterial,
|
|
objectShape.parentMesh,
|
|
objectShape.parentEntity
|
|
);
|
|
};
|
|
|