David Catuhe 6 年之前
父節點
當前提交
1a15bf24af

+ 1 - 1
inspector/src/components/actionTabs/tabs/debugTabComponent.tsx

@@ -41,7 +41,7 @@ export class DebugTabComponent extends PaneComponent {
 
             for (var mesh of scene.meshes) {
                 if (mesh.physicsImpostor) {
-                    let debugMesh = physicsViewer.showImpostor(mesh.physicsImpostor);
+                    let debugMesh = physicsViewer.showImpostor(mesh.physicsImpostor, mesh);
 
                     if (debugMesh) {
                         debugMesh.reservedDataStore = { hidden: true };

+ 1 - 4
inspector/src/components/actionTabs/tabs/propertyGrids/meshes/meshPropertyGridComponent.tsx

@@ -57,10 +57,7 @@ export class MeshPropertyGridComponent extends React.Component<IMeshPropertyGrid
         var wireframeOver = mesh.clone();
         wireframeOver.reservedDataStore = { hidden: true };
         wireframeOver.position = Vector3.Zero();
-        wireframeOver.scaling = new Vector3(1, 1, 1);
-        wireframeOver.rotation = Vector3.Zero();
-        wireframeOver.rotationQuaternion = null;
-        wireframeOver.parent = mesh;
+        wireframeOver.setParent(mesh);
         var material = new StandardMaterial("wireframeOver", scene);
         material.reservedDataStore = { hidden: true };
         wireframeOver.material = material;

+ 48 - 16
src/Debug/physicsViewer.ts

@@ -4,7 +4,7 @@ import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { BoxBuilder } from "../Meshes/Builders/boxBuilder";
 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 { EngineStore } from "../Engines/engineStore";
 import { StandardMaterial } from "../Materials/standardMaterial";
@@ -33,6 +33,7 @@ export class PhysicsViewer {
     private _debugBoxMesh: Mesh;
     private _debugSphereMesh: Mesh;
     private _debugMaterial: StandardMaterial;
+    private _debugMeshMeshes = new Array<Mesh>();
 
     /**
      * Creates a new PhysicsViewer
@@ -65,6 +66,9 @@ export class PhysicsViewer {
             if (impostor.isDisposed) {
                 this.hideImpostor(this._impostors[i--]);
             } else {
+                if (impostor.type === PhysicsImpostor.MeshImpostor) {
+                    continue;
+                }
                 let mesh = this._meshes[i];
 
                 if (mesh && plugin) {
@@ -77,9 +81,10 @@ export class PhysicsViewer {
     /**
      * Renders a specified physic impostor
      * @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
      */
-    public showImpostor(impostor: PhysicsImpostor): Nullable<AbstractMesh> {
+    public showImpostor(impostor: PhysicsImpostor, targetMesh?: Mesh): Nullable<AbstractMesh> {
 
         if (!this._scene) {
             return null;
@@ -91,7 +96,7 @@ export class PhysicsViewer {
             }
         }
 
-        var debugMesh = this._getDebugMesh(impostor);
+        var debugMesh = this._getDebugMesh(impostor, targetMesh);
 
         if (debugMesh) {
             this._impostors[this._numMeshes] = impostor;
@@ -131,6 +136,12 @@ export class PhysicsViewer {
 
                 utilityLayerScene.removeMesh(mesh);
                 mesh.dispose();
+
+                let index = this._debugMeshMeshes.indexOf(mesh as Mesh);
+                if (index > -1) {
+                    this._debugMeshMeshes.splice(index, 1);
+                }
+
                 this._numMeshes--;
                 if (this._numMeshes > 0) {
                     this._meshes[i] = this._meshes[this._numMeshes];
@@ -168,6 +179,7 @@ export class PhysicsViewer {
             this._debugBoxMesh = BoxBuilder.CreateBox('physicsBodyBoxViewMesh', { size: 1 }, scene);
             this._debugBoxMesh.rotationQuaternion = Quaternion.Identity();
             this._debugBoxMesh.material = this._getDebugMaterial(scene);
+            this._debugBoxMesh.setEnabled(false);
         }
 
         return this._debugBoxMesh.createInstance('physicsBodyBoxViewInstance');
@@ -178,12 +190,24 @@ export class PhysicsViewer {
             this._debugSphereMesh = SphereBuilder.CreateSphere('physicsBodySphereViewMesh', { diameter: 1 }, scene);
             this._debugSphereMesh.rotationQuaternion = Quaternion.Identity();
             this._debugSphereMesh.material = this._getDebugMaterial(scene);
+            this._debugSphereMesh.setEnabled(false);
         }
 
         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) {
             return null;
         }
@@ -191,24 +215,32 @@ export class PhysicsViewer {
         var mesh: Nullable<AbstractMesh> = null;
         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;
     }
 
     /** Releases all resources */
     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) {