r3-legacy/src/game-lib-d3-api-shape.js

107 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-06-24 02:42:28 +02:00
/**
* Raw Shape API object - should always correspond with the Shape Schema
* @param id
* @param name
2017-09-02 12:55:57 +02:00
* @param boundingSphereRadius
* @param collisionResponse
* @param frictionMaterial
* @param parentMesh
2017-06-24 02:42:28 +02:00
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Shape = function(
id,
name,
2017-09-02 12:55:57 +02:00
boundingSphereRadius,
collisionResponse,
frictionMaterial,
parentMesh,
2017-06-24 02:42:28 +02:00
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
2017-06-24 02:42:28 +02:00
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 + ')';
}
2017-06-24 02:42:28 +02:00
}
this.name = name;
2017-09-02 12:55:57 +02:00
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;
2017-06-24 02:42:28 +02:00
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,
2017-09-02 12:55:57 +02:00
objectShape.boundingSphereRadius,
objectShape.collisionResponse,
objectShape.frictionMaterial,
objectShape.parentMesh,
2017-06-24 02:42:28 +02:00
objectShape.parentEntity
);
};