|
@@ -10,6 +10,10 @@
|
|
|
//See https://github.com/schteppe/cannon.js/blob/gh-pages/demos/collisionFilter.html
|
|
|
private _currentCollisionGroup = 2;
|
|
|
|
|
|
+ private _debugBoxMesh:Mesh;
|
|
|
+ private _debugSphereMesh:Mesh;
|
|
|
+ private _debugMaterial:StandardMaterial;
|
|
|
+
|
|
|
public constructor(private _useDeltaForWorldStep: boolean = true, iterations: number = 10) {
|
|
|
if (!this.isSupported()) {
|
|
|
Tools.Error("CannonJS is not available. Please make sure you included the js file.");
|
|
@@ -469,8 +473,82 @@
|
|
|
joint.physicsJoint.motorEquation.minForce = lowerLimit === void 0 ? -upperLimit : lowerLimit;
|
|
|
}
|
|
|
|
|
|
+ private _getDebugMaterial(scene:Scene):Material{
|
|
|
+ if(!this._debugMaterial){
|
|
|
+ this._debugMaterial = new StandardMaterial('', scene);
|
|
|
+ this._debugMaterial.wireframe = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._debugMaterial;
|
|
|
+ }
|
|
|
+
|
|
|
+ private _getDebugBoxMesh(scene:Scene):AbstractMesh{
|
|
|
+ if(!this._debugBoxMesh){
|
|
|
+ this._debugBoxMesh = MeshBuilder.CreateBox('physicsBodyBoxViewMesh', { size: 1 }, scene);
|
|
|
+ this._debugBoxMesh.renderingGroupId = 1;
|
|
|
+ this._debugBoxMesh.rotationQuaternion = Quaternion.Identity();
|
|
|
+ this._debugBoxMesh.material = this._getDebugMaterial(scene);
|
|
|
+ scene.removeMesh(this._debugBoxMesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._debugBoxMesh.createInstance('physicsBodyBoxViewInstance');
|
|
|
+ }
|
|
|
+
|
|
|
+ private _getDebugSphereMesh(scene:Scene):AbstractMesh{
|
|
|
+ if(!this._debugSphereMesh){
|
|
|
+ this._debugSphereMesh = MeshBuilder.CreateSphere('physicsBodySphereViewMesh', { diameter: 1 }, scene);
|
|
|
+ this._debugSphereMesh.renderingGroupId = 1;
|
|
|
+ this._debugSphereMesh.rotationQuaternion = Quaternion.Identity();
|
|
|
+ this._debugSphereMesh.material = this._getDebugMaterial(scene);
|
|
|
+ scene.removeMesh(this._debugSphereMesh);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._debugSphereMesh.createInstance('physicsBodyBoxViewInstance');
|
|
|
+ }
|
|
|
+
|
|
|
+ public getDebugMesh(impostor:PhysicsImpostor, scene:Scene):AbstractMesh{
|
|
|
+ var body = impostor.physicsBody;
|
|
|
+ var shape = body.shapes[0];
|
|
|
+ var mesh:AbstractMesh;
|
|
|
+
|
|
|
+ if (shape.halfExtents) {
|
|
|
+ mesh = this._getDebugBoxMesh(scene);
|
|
|
+ mesh.scaling.x = shape.halfExtents.x * 2;
|
|
|
+ mesh.scaling.y = shape.halfExtents.y * 2;
|
|
|
+ mesh.scaling.z = shape.halfExtents.z * 2;
|
|
|
+ } else if(shape.boundingSphereRadius){
|
|
|
+ mesh = this._getDebugSphereMesh(scene);
|
|
|
+ mesh.scaling.x = shape.boundingSphereRadius * 2;
|
|
|
+ mesh.scaling.y = shape.boundingSphereRadius * 2;
|
|
|
+ mesh.scaling.z = shape.boundingSphereRadius * 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ return mesh;
|
|
|
+ }
|
|
|
+
|
|
|
+ public syncMeshWithImpostor(mesh:AbstractMesh, impostor:PhysicsImpostor){
|
|
|
+ var body = impostor.physicsBody;
|
|
|
+
|
|
|
+ mesh.position.x = body.position.x;
|
|
|
+ mesh.position.y = body.position.y;
|
|
|
+ mesh.position.z = body.position.z;
|
|
|
+
|
|
|
+ mesh.rotationQuaternion.x = body.quaternion.x;
|
|
|
+ mesh.rotationQuaternion.y = body.quaternion.y;
|
|
|
+ mesh.rotationQuaternion.z = body.quaternion.z;
|
|
|
+ mesh.rotationQuaternion.w = body.quaternion.w;
|
|
|
+ }
|
|
|
+
|
|
|
public dispose() {
|
|
|
- //nothing to do, actually.
|
|
|
+ if(this._debugBoxMesh){
|
|
|
+ this._debugBoxMesh.dispose();
|
|
|
+ }
|
|
|
+ if(this._debugSphereMesh){
|
|
|
+ this._debugSphereMesh.dispose();
|
|
|
+ }
|
|
|
+ if(this._debugMaterial){
|
|
|
+ this._debugMaterial.dispose();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|