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

137 lines
3.4 KiB
JavaScript
Raw Normal View History

2017-06-24 02:42:28 +02:00
/**
* 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,
2017-09-02 12:55:57 +02:00
apiShape.boundingSphereRadius,
apiShape.collisionResponse,
apiShape.frictionMaterial,
apiShape.parentMesh,
2017-06-24 02:42:28 +02:00
apiShape.parentEntity
);
var componentType = GameLib.Component.COMPONENT_SHAPE;
2017-09-02 12:55:57 +02:00
var linkedObjects = {
frictionMaterial : GameLib.D3.FrictionMaterial,
2017-09-02 12:55:57 +02:00
parentMesh : GameLib.D3.Mesh
};
2017-06-24 02:42:28 +02:00
if (this instanceof GameLib.D3.Shape.Box) {
componentType = GameLib.Component.COMPONENT_SHAPE_BOX;
}
if (this instanceof GameLib.D3.Shape.ConvexHull) {
componentType = GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL;
}
if (this instanceof GameLib.D3.Shape.ConvexHull.Cylinder) {
componentType = GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL_CYLINDER;
}
2017-06-24 02:42:28 +02:00
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;
}
GameLib.Component.call(
this,
componentType,
linkedObjects
2017-06-24 02:42:28 +02:00
);
};
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() {
2017-10-23 14:52:35 +02:00
GameLib.Component.prototype.createInstance.call(this);
2017-06-24 02:42:28 +02:00
};
/**
* 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,
2017-09-02 12:55:57 +02:00
this.boundingSphereRadius,
this.collisionResponse,
GameLib.Utils.IdOrNull(this.frictionMaterial),
GameLib.Utils.IdOrNull(this.parentMesh),
2017-06-24 02:42:28 +02:00
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiShape;
};
/**
* Converts a standard object mesh to a GameLib.D3.Shape
2017-06-30 14:20:22 +02:00
* @param physics GameLib.D3.Physics
2017-06-24 02:42:28 +02:00
* @param objectShape {Object}
* @constructor
*/
2017-06-30 14:20:22 +02:00
GameLib.D3.Shape.FromObject = function(physics, objectShape) {
2017-06-30 14:35:51 +02:00
throw ('not implemented');
2017-06-24 02:42:28 +02:00
};
2017-09-05 05:22:52 +02:00
GameLib.D3.Shape.prototype.stopVisualize = function() {
GameLib.Event.Emit(
GameLib.Event.STOP_VISUALIZE,
{
mesh : this.mesh
}
)
};
GameLib.D3.Shape.prototype.visualize = function() {
GameLib.Event.Emit(
GameLib.Event.VISUALIZE,
{
shape : this
}
)
};