|
@@ -8,6 +8,7 @@ module BABYLON {
|
|
|
|
|
|
private _debugBoxMesh:Mesh;
|
|
|
private _debugSphereMesh:Mesh;
|
|
|
+ private _debugMaterial:StandardMaterial;
|
|
|
|
|
|
constructor(iterations?: number) {
|
|
|
this.world = new OIMO.World(1 / 60, 2, iterations, true);
|
|
@@ -391,35 +392,51 @@ module BABYLON {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public getDebugMesh(imposter:PhysicsImpostor, scene:Scene):AbstractMesh{
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- var body = imposter.physicsBody;
|
|
|
+ return this._debugSphereMesh.createInstance('physicsBodyBoxViewInstance');
|
|
|
+ }
|
|
|
+
|
|
|
+ public getDebugMesh(impostor:PhysicsImpostor, scene:Scene):AbstractMesh{
|
|
|
+ var body = impostor.physicsBody;
|
|
|
var shape = body.shapes;
|
|
|
- var mesh:InstancedMesh;
|
|
|
+ var mesh:AbstractMesh;
|
|
|
|
|
|
if (shape.halfWidth) {
|
|
|
- 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 = this._getDebugBoxMesh(scene);
|
|
|
mesh.scaling.x = shape.halfWidth * 2;
|
|
|
mesh.scaling.y = shape.halfHeight * 2;
|
|
|
mesh.scaling.z = shape.halfDepth * 2;
|
|
|
} else if(shape.radius){
|
|
|
- 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 = this._getDebugSphereMesh(scene);
|
|
|
mesh.scaling.x = shape.radius * 2;
|
|
|
mesh.scaling.y = shape.radius * 2;
|
|
|
mesh.scaling.z = shape.radius * 2;
|
|
@@ -428,9 +445,8 @@ module BABYLON {
|
|
|
return mesh;
|
|
|
}
|
|
|
|
|
|
- public syncMeshWithImposter(mesh:AbstractMesh, imposter:PhysicsImpostor){
|
|
|
-
|
|
|
- var body = imposter.physicsBody;
|
|
|
+ public syncMeshWithImpostor(mesh:AbstractMesh, impostor:PhysicsImpostor){
|
|
|
+ var body = impostor.physicsBody;
|
|
|
|
|
|
mesh.position.x = body.position.x;
|
|
|
mesh.position.y = body.position.y;
|
|
@@ -440,7 +456,6 @@ module BABYLON {
|
|
|
mesh.rotationQuaternion.y = body.orientation.y;
|
|
|
mesh.rotationQuaternion.z = body.orientation.z;
|
|
|
mesh.rotationQuaternion.w = body.orientation.s;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public dispose() {
|
|
@@ -450,6 +465,9 @@ module BABYLON {
|
|
|
if(this._debugSphereMesh){
|
|
|
this._debugSphereMesh.dispose();
|
|
|
}
|
|
|
+ if(this._debugMaterial){
|
|
|
+ this._debugMaterial.dispose();
|
|
|
+ }
|
|
|
this.world.clear();
|
|
|
}
|
|
|
}
|