/** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics * @param apiShape GameLib.D3.API.Shape * @param radiusTop * @param radiusBottom * @param height * @param numSegments * @constructor */ GameLib.D3.Shape.ConvexHull.Cylinder = function ( physics, apiShape, radiusTop, radiusBottom, height, numSegments ) { this.physics = physics; this.physics.isNotCannonThrow(); if (GameLib.Utils.UndefinedOrNull(apiShape)) { apiShape = { shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER }; } if (apiShape instanceof GameLib.D3.Shape.ConvexHull.Cylinder) { return apiShape; } if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } this.radiusTop = radiusTop; if (GameLib.Utils.UndefinedOrNull(radiusBottom)) { radiusBottom = 1; } this.radiusBottom = radiusBottom; if (GameLib.Utils.UndefinedOrNull(height)) { height = radiusBottom / 2; } this.height = height; if (GameLib.Utils.UndefinedOrNull(numSegments)) { numSegments = 20; } this.numSegments = numSegments; GameLib.D3.Shape.ConvexHull.call( this, this.physics, apiShape ); }; GameLib.D3.Shape.ConvexHull.Cylinder.prototype = Object.create(GameLib.D3.Shape.ConvexHull.prototype); GameLib.D3.Shape.ConvexHull.Cylinder.prototype.constructor = GameLib.D3.Shape.ConvexHull.Cylinder; /** * * @returns {GameLib.D3.Shape.Cylinder|*|SEA3D.Cylinder} */ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() { this.instance = new CANNON.Cylinder( this.radiusTop, this.radiusBottom, this.height, this.numSegments ); GameLib.D3.Shape.prototype.createInstance.call(this); }; GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() { console.log('todo : update cylinder instance'); // this.instance.radius = this.radius; // this.instance.updateAABB(); // this.instance.updateBoundingCylinderRadius(); // this.instance.updateEdges(); // this.instance.updateNormals(); // this.instance.updateTree(); }; GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh = function() { this.radiusTop = this.parentMesh.dimensions.x / 2; this.radiusBottom = this.parentMesh.dimensions.x / 2; this.height = this.parentMesh.dimensions.z; }; GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() { var apiShape = GameLib.D3.Shape.ConvexHull.prototype.toApiObject.call(this); apiShape.radiusTop = this.radiusTop; apiShape.radiusBottom = this.radiusBottom; apiShape.height = this.height; apiShape.numSegments = this.numSegments; return apiShape; }; GameLib.D3.Shape.ConvexHull.Cylinder.FromObject = function(physics, objectShape) { /** * Just a reminder that below line is wrong and commented out - we need to call the constructors eventually with * the right 'this' parameter and args. * * var apiShape = GameLib.D3.Shape.ConvexHull.FromObject(physics, objectShape); * * Instead, do this: */ var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); var inheritableProperties = GameLib.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); for (var property in inheritableProperties) { if (inheritableProperties.hasOwnProperty(property)) { apiShape[property] = inheritableProperties[property]; } } return new GameLib.D3.Shape.ConvexHull.Cylinder( physics, apiShape, objectShape.radiusTop, objectShape.radiusBottom, objectShape.height, objectShape.numSegments ); };