r3-legacy/src/game-lib-d3-shape-convex-hu...

127 lines
3.4 KiB
JavaScript
Raw Normal View History

2017-09-02 12:55:57 +02:00
/**
* 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(radiusTop)) {
radiusTop = 1;
}
this.radiusTop = radiusTop;
if (GameLib.Utils.UndefinedOrNull(radiusBottom)) {
radiusBottom = 1;
}
this.radiusBottom = radiusBottom;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = radiusBottom / 2;
2017-09-02 12:55:57 +02:00
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(numSegments)) {
numSegments = 20;
2017-09-02 12:55:57 +02:00
}
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() {
2017-10-23 14:52:35 +02:00
this.instance = new CANNON.Cylinder(
2017-09-02 12:55:57 +02:00
this.radiusTop,
this.radiusBottom,
this.height,
this.numSegments
);
2017-10-23 14:52:35 +02:00
GameLib.D3.Shape.prototype.createInstance.call(this);
2017-09-02 12:55:57 +02:00
};
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;
2017-09-02 12:55:57 +02:00
};
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];
}
}
2017-09-02 12:55:57 +02:00
return new GameLib.D3.Shape.ConvexHull.Cylinder(
physics,
apiShape,
objectShape.radiusTop,
objectShape.radiusBottom,
objectShape.height,
objectShape.numSegments
2017-09-02 12:55:57 +02:00
);
};