/** * 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.boundingSphereRadius, apiShape.collisionResponse, apiShape.frictionMaterial, apiShape.parentMesh, apiShape.parentEntity ); var componentType = GameLib.Component.COMPONENT_SHAPE; var linkedObjects = { parentMesh : GameLib.D3.Mesh }; 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_CONVEX_HULL_CYLINDER; } if (this instanceof GameLib.D3.Shape.ConvexHull) { componentType = GameLib.Component.SHAPE_TYPE_CONVEX_HULL; } GameLib.Component.call( this, componentType, linkedObjects ); }; 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'); }; GameLib.D3.Shape.prototype.visualize = function() { }; /** * 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, this.boundingSphereRadius, this.collisionResponse, GameLib.Utils.IdOrNull(this.frictionMaterial), GameLib.Utils.IdOrNull(this.parentMesh), GameLib.Utils.IdOrNull(this.parentEntity) ); return apiShape; }; /** * Converts a standard object mesh to a GameLib.D3.Shape * @param physics GameLib.D3.Physics * @param objectShape {Object} * @constructor */ GameLib.D3.Shape.FromObject = function(physics, objectShape) { throw ('not implemented'); };