2017-06-24 02:42:28 +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 halfExtents
|
2017-06-30 14:20:22 +02:00
|
|
|
* @param activeMesh
|
2017-06-24 02:42:28 +02:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Shape.Box = function (
|
|
|
|
physics,
|
|
|
|
apiShape,
|
2017-06-30 14:20:22 +02:00
|
|
|
halfExtents,
|
|
|
|
activeMesh
|
2017-06-24 02:42:28 +02:00
|
|
|
) {
|
|
|
|
this.physics = physics;
|
|
|
|
this.physics.isNotCannonThrow();
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(halfExtents)) {
|
|
|
|
halfExtents = new GameLib.Vector3(
|
|
|
|
physics,
|
|
|
|
new GameLib.API.Vector3(
|
|
|
|
1,1,1
|
|
|
|
)
|
|
|
|
);
|
2017-06-30 14:35:51 +02:00
|
|
|
} else if (halfExtents instanceof GameLib.API.Vector3) {
|
|
|
|
halfExtents = new GameLib.Vector3(
|
|
|
|
this.physics,
|
|
|
|
halfExtents,
|
|
|
|
this
|
|
|
|
)
|
2017-06-24 02:42:28 +02:00
|
|
|
}
|
|
|
|
this.halfExtents = halfExtents;
|
|
|
|
|
2017-07-02 12:48:31 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(activeMesh)) {
|
|
|
|
activeMesh = null;
|
|
|
|
}
|
|
|
|
this.activeMesh = activeMesh;
|
|
|
|
|
2017-06-24 02:42:28 +02:00
|
|
|
GameLib.D3.Shape.call(
|
|
|
|
this,
|
|
|
|
this.physics,
|
|
|
|
apiShape
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Shape.Box.prototype = Object.create(GameLib.D3.Shape.prototype);
|
|
|
|
GameLib.D3.Shape.Box.prototype.constructor = GameLib.D3.Shape.Box;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {GameLib.D3.Shape.Box|*|SEA3D.Box}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Shape.Box.prototype.createInstance = function() {
|
|
|
|
|
|
|
|
var instance = new CANNON.Box(
|
|
|
|
this.halfExtents.instance
|
|
|
|
);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Shape.Box.prototype.updateInstance = function() {
|
|
|
|
this.instance.halfExtents.x = this.halfExtents.x;
|
|
|
|
this.instance.halfExtents.y = this.halfExtents.y;
|
|
|
|
this.instance.halfExtents.z = this.halfExtents.z;
|
|
|
|
this.instance.updateBoundingSphereRadius();
|
2017-06-30 14:20:22 +02:00
|
|
|
this.instance.updateConvexPolyhedronRepresentation();
|
|
|
|
};
|
|
|
|
|
2017-08-31 21:10:34 +02:00
|
|
|
GameLib.D3.Shape.prototype.visualize = function() {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-30 14:20:22 +02:00
|
|
|
GameLib.D3.Shape.Box.prototype.toApiObject = function() {
|
|
|
|
|
|
|
|
var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this);
|
|
|
|
|
|
|
|
apiShape.halfExtents = this.halfExtents.toApiObject();
|
|
|
|
apiShape.activeMesh = GameLib.Utils.IdOrNull(this.activeMesh);
|
|
|
|
|
|
|
|
return apiShape;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Shape.Box.prototype.setFromMesh = function() {
|
|
|
|
|
|
|
|
if (this.activeMesh === null) {
|
|
|
|
console.log('select a mesh first');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var box = this.activeMesh.getBoundingBox();
|
|
|
|
|
|
|
|
this.halfExtents.x = box.x / 2;
|
|
|
|
this.halfExtents.y = box.y / 2;
|
|
|
|
this.halfExtents.z = box.z / 2;
|
|
|
|
|
|
|
|
this.halfExtents.updateInstance();
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Shape.Box.FromObject = function(physics, objectShape) {
|
|
|
|
|
2017-06-30 14:35:51 +02:00
|
|
|
var apiShape = GameLib.D3.API.Shape.FromObject(objectShape);
|
2017-06-30 14:20:22 +02:00
|
|
|
|
2017-06-30 14:35:51 +02:00
|
|
|
apiShape.halfExtents = GameLib.API.Vector3.FromObject(objectShape.halfExtents);
|
2017-06-30 14:20:22 +02:00
|
|
|
apiShape.activeMesh = objectShape.activeMesh;
|
|
|
|
|
|
|
|
return new GameLib.D3.Shape.Box(
|
2017-06-30 14:22:11 +02:00
|
|
|
physics,
|
2017-06-30 14:20:22 +02:00
|
|
|
apiShape,
|
|
|
|
apiShape.halfExtents,
|
|
|
|
apiShape.activeMesh
|
|
|
|
);
|
|
|
|
|
2017-06-24 02:42:28 +02:00
|
|
|
};
|