浏览代码

Fix HighlightLayer crash when working with an InstancedMesh.

Added multiple checks to HighlightLayer to allow InstancedMesh:es. This by referring to their source rather than themselves when adding or removing.
Erik Hughes 8 年之前
父节点
当前提交
448c2104de
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/Layer/babylon.highlightlayer.ts

+ 8 - 0
src/Layer/babylon.highlightlayer.ts

@@ -631,6 +631,8 @@
          * @param mesh The mesh to exclude from the highlight layer
          */
         public addExcludedMesh(mesh: Mesh) {
+            mesh = mesh instanceof BABYLON.InstancedMesh ? mesh.sourceMesh : mesh;
+
             var meshExcluded = this._excludedMeshes[mesh.id];
             if (!meshExcluded) {
                 this._excludedMeshes[mesh.id] = {
@@ -650,6 +652,8 @@
           * @param mesh The mesh to highlight
           */
         public removeExcludedMesh(mesh: Mesh) {
+            mesh = mesh instanceof BABYLON.InstancedMesh ? mesh.sourceMesh : mesh;
+
             var meshExcluded = this._excludedMeshes[mesh.id];
             if (meshExcluded) {
                 mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
@@ -666,6 +670,8 @@
          * @param glowEmissiveOnly Extract the glow from the emissive texture
          */
         public addMesh(mesh: Mesh, color: Color3, glowEmissiveOnly = false) {
+            mesh = mesh instanceof BABYLON.InstancedMesh ? mesh.sourceMesh : mesh;
+
             var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
                 meshHighlight.color = color;
@@ -696,6 +702,8 @@
          * @param mesh The mesh to highlight
          */
         public removeMesh(mesh: Mesh) {
+            mesh = mesh instanceof BABYLON.InstancedMesh ? mesh.sourceMesh : mesh;
+            
             var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
                 mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);