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

114 lines
2.8 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 = 1;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(numSegments)) {
numSegments = 1;
}
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() {
var instance = new CANNON.Cylinder(
this.radiusTop,
this.radiusBottom,
this.height,
this.numSegments
);
return instance;
};
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() {
console.log('todo: set from mesh');
};
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) {
var apiShape = GameLib.D3.Shape.ConvexHull.FromObject(objectShape);
var radiusTop = objectShape.radiusTop;
var radiusBottom = objectShape.radiusBottom;
var height = objectShape.height;
var numSegments = objectShape.numSegments;
return new GameLib.D3.Shape.ConvexHull.Cylinder(
physics,
apiShape,
radiusTop,
radiusBottom,
height,
numSegments
);
};