|
@@ -4,7 +4,7 @@ import { AbstractMesh } from "../Meshes/abstractMesh";
|
|
import { Mesh } from "../Meshes/mesh";
|
|
import { Mesh } from "../Meshes/mesh";
|
|
import { BoxBuilder } from "../Meshes/Builders/boxBuilder";
|
|
import { BoxBuilder } from "../Meshes/Builders/boxBuilder";
|
|
import { SphereBuilder } from "../Meshes/Builders/sphereBuilder";
|
|
import { SphereBuilder } from "../Meshes/Builders/sphereBuilder";
|
|
-import { Quaternion, Color3 } from "../Maths/math";
|
|
|
|
|
|
+import { Quaternion, Color3, Vector3 } from "../Maths/math";
|
|
import { Material } from "../Materials/material";
|
|
import { Material } from "../Materials/material";
|
|
import { EngineStore } from "../Engines/engineStore";
|
|
import { EngineStore } from "../Engines/engineStore";
|
|
import { StandardMaterial } from "../Materials/standardMaterial";
|
|
import { StandardMaterial } from "../Materials/standardMaterial";
|
|
@@ -33,6 +33,7 @@ export class PhysicsViewer {
|
|
private _debugBoxMesh: Mesh;
|
|
private _debugBoxMesh: Mesh;
|
|
private _debugSphereMesh: Mesh;
|
|
private _debugSphereMesh: Mesh;
|
|
private _debugMaterial: StandardMaterial;
|
|
private _debugMaterial: StandardMaterial;
|
|
|
|
+ private _debugMeshMeshes = new Array<Mesh>();
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a new PhysicsViewer
|
|
* Creates a new PhysicsViewer
|
|
@@ -65,6 +66,9 @@ export class PhysicsViewer {
|
|
if (impostor.isDisposed) {
|
|
if (impostor.isDisposed) {
|
|
this.hideImpostor(this._impostors[i--]);
|
|
this.hideImpostor(this._impostors[i--]);
|
|
} else {
|
|
} else {
|
|
|
|
+ if (impostor.type === PhysicsImpostor.MeshImpostor) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
let mesh = this._meshes[i];
|
|
let mesh = this._meshes[i];
|
|
|
|
|
|
if (mesh && plugin) {
|
|
if (mesh && plugin) {
|
|
@@ -77,9 +81,10 @@ export class PhysicsViewer {
|
|
/**
|
|
/**
|
|
* Renders a specified physic impostor
|
|
* Renders a specified physic impostor
|
|
* @param impostor defines the impostor to render
|
|
* @param impostor defines the impostor to render
|
|
|
|
+ * @param targetMesh defines the mesh represented by the impostor
|
|
* @returns the new debug mesh used to render the impostor
|
|
* @returns the new debug mesh used to render the impostor
|
|
*/
|
|
*/
|
|
- public showImpostor(impostor: PhysicsImpostor): Nullable<AbstractMesh> {
|
|
|
|
|
|
+ public showImpostor(impostor: PhysicsImpostor, targetMesh?: Mesh): Nullable<AbstractMesh> {
|
|
|
|
|
|
if (!this._scene) {
|
|
if (!this._scene) {
|
|
return null;
|
|
return null;
|
|
@@ -91,7 +96,7 @@ export class PhysicsViewer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var debugMesh = this._getDebugMesh(impostor);
|
|
|
|
|
|
+ var debugMesh = this._getDebugMesh(impostor, targetMesh);
|
|
|
|
|
|
if (debugMesh) {
|
|
if (debugMesh) {
|
|
this._impostors[this._numMeshes] = impostor;
|
|
this._impostors[this._numMeshes] = impostor;
|
|
@@ -131,6 +136,12 @@ export class PhysicsViewer {
|
|
|
|
|
|
utilityLayerScene.removeMesh(mesh);
|
|
utilityLayerScene.removeMesh(mesh);
|
|
mesh.dispose();
|
|
mesh.dispose();
|
|
|
|
+
|
|
|
|
+ let index = this._debugMeshMeshes.indexOf(mesh as Mesh);
|
|
|
|
+ if (index > -1) {
|
|
|
|
+ this._debugMeshMeshes.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
this._numMeshes--;
|
|
this._numMeshes--;
|
|
if (this._numMeshes > 0) {
|
|
if (this._numMeshes > 0) {
|
|
this._meshes[i] = this._meshes[this._numMeshes];
|
|
this._meshes[i] = this._meshes[this._numMeshes];
|
|
@@ -168,6 +179,7 @@ export class PhysicsViewer {
|
|
this._debugBoxMesh = BoxBuilder.CreateBox('physicsBodyBoxViewMesh', { size: 1 }, scene);
|
|
this._debugBoxMesh = BoxBuilder.CreateBox('physicsBodyBoxViewMesh', { size: 1 }, scene);
|
|
this._debugBoxMesh.rotationQuaternion = Quaternion.Identity();
|
|
this._debugBoxMesh.rotationQuaternion = Quaternion.Identity();
|
|
this._debugBoxMesh.material = this._getDebugMaterial(scene);
|
|
this._debugBoxMesh.material = this._getDebugMaterial(scene);
|
|
|
|
+ this._debugBoxMesh.setEnabled(false);
|
|
}
|
|
}
|
|
|
|
|
|
return this._debugBoxMesh.createInstance('physicsBodyBoxViewInstance');
|
|
return this._debugBoxMesh.createInstance('physicsBodyBoxViewInstance');
|
|
@@ -178,12 +190,24 @@ export class PhysicsViewer {
|
|
this._debugSphereMesh = SphereBuilder.CreateSphere('physicsBodySphereViewMesh', { diameter: 1 }, scene);
|
|
this._debugSphereMesh = SphereBuilder.CreateSphere('physicsBodySphereViewMesh', { diameter: 1 }, scene);
|
|
this._debugSphereMesh.rotationQuaternion = Quaternion.Identity();
|
|
this._debugSphereMesh.rotationQuaternion = Quaternion.Identity();
|
|
this._debugSphereMesh.material = this._getDebugMaterial(scene);
|
|
this._debugSphereMesh.material = this._getDebugMaterial(scene);
|
|
|
|
+ this._debugSphereMesh.setEnabled(false);
|
|
}
|
|
}
|
|
|
|
|
|
return this._debugSphereMesh.createInstance('physicsBodyBoxViewInstance');
|
|
return this._debugSphereMesh.createInstance('physicsBodyBoxViewInstance');
|
|
}
|
|
}
|
|
|
|
|
|
- private _getDebugMesh(impostor: PhysicsImpostor): Nullable<AbstractMesh> {
|
|
|
|
|
|
+ private _getDebugMeshMesh(mesh: Mesh, scene: Scene): AbstractMesh {
|
|
|
|
+ var wireframeOver = new Mesh(mesh.name, scene, null, mesh);
|
|
|
|
+ wireframeOver.position = Vector3.Zero();
|
|
|
|
+ wireframeOver.setParent(mesh);
|
|
|
|
+ wireframeOver.material = this._getDebugMaterial(scene);
|
|
|
|
+
|
|
|
|
+ this._debugMeshMeshes.push(wireframeOver);
|
|
|
|
+
|
|
|
|
+ return wireframeOver;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private _getDebugMesh(impostor: PhysicsImpostor, targetMesh?: Mesh): Nullable<AbstractMesh> {
|
|
if (!this._utilityLayer) {
|
|
if (!this._utilityLayer) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -191,24 +215,32 @@ export class PhysicsViewer {
|
|
var mesh: Nullable<AbstractMesh> = null;
|
|
var mesh: Nullable<AbstractMesh> = null;
|
|
const utilityLayerScene = this._utilityLayer.utilityLayerScene;
|
|
const utilityLayerScene = this._utilityLayer.utilityLayerScene;
|
|
|
|
|
|
- if (impostor.type == PhysicsImpostor.BoxImpostor) {
|
|
|
|
- mesh = this._getDebugBoxMesh(utilityLayerScene);
|
|
|
|
- impostor.getBoxSizeToRef(mesh.scaling);
|
|
|
|
- } else if (impostor.type == PhysicsImpostor.SphereImpostor) {
|
|
|
|
- mesh = this._getDebugSphereMesh(utilityLayerScene);
|
|
|
|
- var radius = impostor.getRadius();
|
|
|
|
- mesh.scaling.x = radius * 2;
|
|
|
|
- mesh.scaling.y = radius * 2;
|
|
|
|
- mesh.scaling.z = radius * 2;
|
|
|
|
|
|
+ switch(impostor.type) {
|
|
|
|
+ case PhysicsImpostor.BoxImpostor:
|
|
|
|
+ mesh = this._getDebugBoxMesh(utilityLayerScene);
|
|
|
|
+ impostor.getBoxSizeToRef(mesh.scaling);
|
|
|
|
+ break;
|
|
|
|
+ case PhysicsImpostor.SphereImpostor:
|
|
|
|
+ mesh = this._getDebugSphereMesh(utilityLayerScene);
|
|
|
|
+ var radius = impostor.getRadius();
|
|
|
|
+ mesh.scaling.x = radius * 2;
|
|
|
|
+ mesh.scaling.y = radius * 2;
|
|
|
|
+ mesh.scaling.z = radius * 2;
|
|
|
|
+ break;
|
|
|
|
+ case PhysicsImpostor.MeshImpostor:
|
|
|
|
+ if (targetMesh) {
|
|
|
|
+ mesh = this._getDebugMeshMesh(targetMesh, utilityLayerScene);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
-
|
|
|
|
return mesh;
|
|
return mesh;
|
|
}
|
|
}
|
|
|
|
|
|
/** Releases all resources */
|
|
/** Releases all resources */
|
|
public dispose() {
|
|
public dispose() {
|
|
- for (var i = 0; i < this._numMeshes; i++) {
|
|
|
|
- this.hideImpostor(this._impostors[i]);
|
|
|
|
|
|
+ let count = this._numMeshes;
|
|
|
|
+ for (var index = 0; index < count; index++) {
|
|
|
|
+ this.hideImpostor(this._impostors[0]);
|
|
}
|
|
}
|
|
|
|
|
|
if (this._debugBoxMesh) {
|
|
if (this._debugBoxMesh) {
|