|
@@ -10,6 +10,9 @@
|
|
|
//See https://github.com/schteppe/cannon.js/blob/gh-pages/demos/collisionFilter.html
|
|
|
private _currentCollisionGroup = 2;
|
|
|
|
|
|
+ private _debugBoxMesh:Mesh;
|
|
|
+ private _debugSphereMesh:Mesh;
|
|
|
+
|
|
|
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 +472,65 @@
|
|
|
joint.physicsJoint.motorEquation.minForce = lowerLimit === void 0 ? -upperLimit : lowerLimit;
|
|
|
}
|
|
|
|
|
|
+ public getDebugMesh(imposter:PhysicsImpostor, scene:Scene):AbstractMesh{
|
|
|
+
|
|
|
+ var body = imposter.physicsBody;
|
|
|
+ var shape = body.shapes[0];
|
|
|
+ var mesh:InstancedMesh;
|
|
|
+
|
|
|
+ if (shape.halfExtents) {
|
|
|
+ if(!this._debugBoxMesh){
|
|
|
+ this._debugBoxMesh = MeshBuilder.CreateBox('physicsBodyBoxViewMesh', { size: 1 }, scene);
|
|
|
+ this._debugBoxMesh.renderingGroupId = 1;
|
|
|
+ this._debugBoxMesh.rotationQuaternion = Quaternion.Identity();
|
|
|
+ this._debugBoxMesh.material = new StandardMaterial('', scene);
|
|
|
+ this._debugBoxMesh.material.wireframe = true;
|
|
|
+ scene.removeMesh(this._debugBoxMesh);
|
|
|
+ }
|
|
|
+ mesh = this._debugBoxMesh.createInstance('physicsBodyBoxViewInstance');
|
|
|
+ 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){
|
|
|
+ if(!this._debugSphereMesh){
|
|
|
+ this._debugSphereMesh = MeshBuilder.CreateSphere('physicsBodySphereViewMesh', { diameter: 1 }, scene);
|
|
|
+ this._debugSphereMesh.renderingGroupId = 1;
|
|
|
+ this._debugSphereMesh.rotationQuaternion = Quaternion.Identity();
|
|
|
+ this._debugSphereMesh.material = new StandardMaterial('', scene);
|
|
|
+ this._debugSphereMesh.material.wireframe = true;
|
|
|
+ scene.removeMesh(this._debugSphereMesh);
|
|
|
+ }
|
|
|
+ mesh = this._debugSphereMesh.createInstance('physicsBodySphereViewInstance');
|
|
|
+ mesh.scaling.x = shape.boundingSphereRadius * 2;
|
|
|
+ mesh.scaling.y = shape.boundingSphereRadius * 2;
|
|
|
+ mesh.scaling.z = shape.boundingSphereRadius * 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ return mesh;
|
|
|
+ }
|
|
|
+
|
|
|
+ public syncMeshWithImposter(mesh:AbstractMesh, imposter:PhysicsImpostor){
|
|
|
+
|
|
|
+ var body = imposter.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();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|