/** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics * @param apiShape R3.D3.API.Shape * @param radiusTop * @param radiusBottom * @param height * @param numSegments * @constructor */ R3.D3.Shape.ConvexHull.Cylinder = function( physics, apiShape, radiusTop, radiusBottom, height, numSegments ) { this.physics = physics; this.physics.isNotCannonThrow(); if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { shapeType : R3.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER }; } if (R3.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } this.radiusTop = radiusTop; if (R3.Utils.UndefinedOrNull(radiusBottom)) { radiusBottom = 1; } this.radiusBottom = radiusBottom; if (R3.Utils.UndefinedOrNull(height)) { height = radiusBottom / 2; } this.height = height; if (R3.Utils.UndefinedOrNull(numSegments)) { numSegments = 20; } this.numSegments = numSegments; R3.D3.Shape.ConvexHull.call( this, this.physics, apiShape ); }; R3.D3.Shape.ConvexHull.Cylinder.prototype = Object.create(R3.D3.Shape.ConvexHull.prototype); R3.D3.Shape.ConvexHull.Cylinder.prototype.constructor = R3.D3.Shape.ConvexHull.Cylinder; /** * * @returns {R3.D3.Shape.Cylinder|*|SEA3D.Cylinder} */ R3.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() { this.instance = new CANNON.Cylinder( this.radiusTop, this.radiusBottom, this.height, this.numSegments ); R3.D3.Shape.prototype.createInstance.call(this); }; R3.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(); }; R3.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; }; R3.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() { var apiShape = R3.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; }; R3.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 = R3.D3.Shape.ConvexHull.FromObject(physics, objectShape); * * Instead, do this: */ var apiShape = R3.D3.API.Shape.FromObject(objectShape); var inheritableProperties = R3.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); for (var property in inheritableProperties) { if (inheritableProperties.hasOwnProperty(property)) { apiShape[property] = inheritableProperties[property]; } } return new R3.D3.Shape.ConvexHull.Cylinder( physics, apiShape, objectShape.radiusTop, objectShape.radiusBottom, objectShape.height, objectShape.numSegments ); };