113 lines
2.7 KiB
JavaScript
113 lines
2.7 KiB
JavaScript
|
/**
|
||
|
* Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created
|
||
|
* @param physics GameLib.D3.Physics
|
||
|
* @param apiShape GameLib.D3.API.Shape
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.Shape = function (
|
||
|
physics,
|
||
|
apiShape
|
||
|
) {
|
||
|
this.physics = physics;
|
||
|
this.physics.isNotCannonThrow();
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(apiShape)) {
|
||
|
apiShape = {};
|
||
|
}
|
||
|
|
||
|
if (apiShape instanceof GameLib.D3.Shape) {
|
||
|
return apiShape;
|
||
|
}
|
||
|
|
||
|
GameLib.D3.API.Shape.call(
|
||
|
this,
|
||
|
apiShape.id,
|
||
|
apiShape.name,
|
||
|
apiShape.parentEntity
|
||
|
);
|
||
|
|
||
|
var componentType = GameLib.Component.COMPONENT_SHAPE;
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.Box) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_BOX;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.Sphere) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_SPHERE;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.TriMesh) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_TRI_MESH;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.Plane) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_PLANE;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.HeightMap) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.Cylinder) {
|
||
|
componentType = GameLib.Component.COMPONENT_SHAPE_CYLINDER;
|
||
|
}
|
||
|
|
||
|
if (this instanceof GameLib.D3.Shape.ConvexHull) {
|
||
|
componentType = GameLib.Component.SHAPE_TYPE_CONVEX_HULL;
|
||
|
}
|
||
|
|
||
|
GameLib.Component.call(
|
||
|
this,
|
||
|
componentType
|
||
|
);
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Shape.prototype = Object.create(GameLib.D3.API.Shape.prototype);
|
||
|
GameLib.D3.Shape.prototype.constructor = GameLib.D3.Shape;
|
||
|
|
||
|
/**
|
||
|
* Creates a shape instance or updates it
|
||
|
*/
|
||
|
GameLib.D3.Shape.prototype.createInstance = function() {
|
||
|
throw new Error('Do not instantiate this class directly - use a child class instead');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the mesh instance
|
||
|
*/
|
||
|
GameLib.D3.Shape.prototype.updateInstance = function() {
|
||
|
throw new Error('Do not instantiate this class directly - use a child class instead');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a GameLib.D3.Shape to a GameLib.D3.API.Shape
|
||
|
* @returns {GameLib.D3.API.Shape}
|
||
|
*/
|
||
|
GameLib.D3.Shape.prototype.toApiObject = function() {
|
||
|
|
||
|
var apiShape = new GameLib.D3.API.Shape(
|
||
|
this.id,
|
||
|
this.name,
|
||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||
|
);
|
||
|
|
||
|
return apiShape;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a standard object mesh to a GameLib.D3.Shape
|
||
|
* @param graphics GameLib.D3.Graphics
|
||
|
* @param objectShape {Object}
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.Shape.FromObject = function(graphics, objectShape) {
|
||
|
|
||
|
var apiShape = GameLib.D3.API.Shape.FromObject(objectShape);
|
||
|
|
||
|
return new GameLib.D3.Shape(
|
||
|
graphics,
|
||
|
apiShape
|
||
|
);
|
||
|
|
||
|
};
|