Beispiel #1
0
 public override void UpdateGameObjects(GameObject[] gos, bool recalcBounds = true, bool updateVertices = true, bool updateNormals = true, bool updateTangents = true, bool updateUV = false, bool updateUV2 = false, bool updateUV3 = false, bool updateUV4 = false, bool updateColors = false, bool updateSkinningInfo = false)
 {
     if (gos == null)
     {
         Debug.LogError("list of game objects cannot be null");
         return;
     }
     for (int i = 0; i < this.meshCombiners.Count; i++)
     {
         this.meshCombiners[i].gosToUpdate.Clear();
     }
     for (int j = 0; j < gos.Length; j++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh = null;
         this.obj2MeshCombinerMap.TryGetValue(gos[j].GetInstanceID(), out combinedMesh);
         if (combinedMesh != null)
         {
             combinedMesh.gosToUpdate.Add(gos[j]);
         }
         else
         {
             Debug.LogWarning("Object " + gos[j] + " is not in the combined mesh.");
         }
     }
     for (int k = 0; k < this.meshCombiners.Count; k++)
     {
         if (this.meshCombiners[k].gosToUpdate.Count > 0)
         {
             this.meshCombiners[k].isDirty = true;
             GameObject[] gos2 = this.meshCombiners[k].gosToUpdate.ToArray();
             this.meshCombiners[k].combinedMesh.UpdateGameObjects(gos2, recalcBounds, updateVertices, updateNormals, updateTangents, updateUV, updateUV2, updateUV3, updateUV4, updateColors, updateSkinningInfo);
         }
     }
 }
Beispiel #2
0
 public override int GetNumVerticesFor(int gameObjectID)
 {
     MB3_MultiMeshCombiner.CombinedMesh combinedMesh = null;
     if (this.obj2MeshCombinerMap.TryGetValue(gameObjectID, out combinedMesh))
     {
         return(combinedMesh.combinedMesh.GetNumVerticesFor(gameObjectID));
     }
     return(-1);
 }
Beispiel #3
0
 public override int GetNumVerticesFor(GameObject go)
 {
     MB3_MultiMeshCombiner.CombinedMesh combinedMesh = null;
     if (this.obj2MeshCombinerMap.TryGetValue(go.GetInstanceID(), out combinedMesh))
     {
         return(combinedMesh.combinedMesh.GetNumVerticesFor(go));
     }
     return(-1);
 }
Beispiel #4
0
 private bool _bakeStep1(GameObject[] gos, int[] deleteGOinstanceIDs, bool disableRendererInSource)
 {
     for (int i = 0; i < this.meshCombiners.Count; i++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh = this.meshCombiners[i];
         if (combinedMesh.combinedMesh.targetRenderer == null)
         {
             combinedMesh.combinedMesh.resultSceneObject = this._resultSceneObject;
             combinedMesh.combinedMesh.BuildSceneMeshObject(gos, true);
             if (this._LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug("BuildSO combiner {0} goID {1} targetRenID {2} meshID {3}", new object[]
                 {
                     i,
                     combinedMesh.combinedMesh.targetRenderer.gameObject.GetInstanceID(),
                     combinedMesh.combinedMesh.targetRenderer.GetInstanceID(),
                     combinedMesh.combinedMesh.GetMesh().GetInstanceID()
                 });
             }
         }
         else if (combinedMesh.combinedMesh.targetRenderer.transform.parent != this.resultSceneObject.transform)
         {
             Debug.LogError("targetRender objects must be children of resultSceneObject");
             return(false);
         }
         if (combinedMesh.gosToAdd.Count > 0 || combinedMesh.gosToDelete.Count > 0)
         {
             combinedMesh.combinedMesh.AddDeleteGameObjectsByID(combinedMesh.gosToAdd.ToArray(), combinedMesh.gosToDelete.ToArray(), disableRendererInSource);
             if (this._LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug("Baked combiner {0} obsAdded {1} objsRemoved {2} goID {3} targetRenID {4} meshID {5}", new object[]
                 {
                     i,
                     combinedMesh.gosToAdd.Count,
                     combinedMesh.gosToDelete.Count,
                     combinedMesh.combinedMesh.targetRenderer.gameObject.GetInstanceID(),
                     combinedMesh.combinedMesh.targetRenderer.GetInstanceID(),
                     combinedMesh.combinedMesh.GetMesh().GetInstanceID()
                 });
             }
         }
         Renderer targetRenderer = combinedMesh.combinedMesh.targetRenderer;
         Mesh     mesh           = combinedMesh.combinedMesh.GetMesh();
         if (targetRenderer is MeshRenderer)
         {
             MeshFilter component = targetRenderer.gameObject.GetComponent <MeshFilter>();
             component.sharedMesh = mesh;
         }
         else
         {
             SkinnedMeshRenderer skinnedMeshRenderer = (SkinnedMeshRenderer)targetRenderer;
             skinnedMeshRenderer.sharedMesh = mesh;
         }
     }
     for (int j = 0; j < this.meshCombiners.Count; j++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh2 = this.meshCombiners[j];
         for (int k = 0; k < combinedMesh2.gosToDelete.Count; k++)
         {
             this.obj2MeshCombinerMap.Remove(combinedMesh2.gosToDelete[k]);
         }
     }
     for (int l = 0; l < this.meshCombiners.Count; l++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh3 = this.meshCombiners[l];
         for (int m = 0; m < combinedMesh3.gosToAdd.Count; m++)
         {
             this.obj2MeshCombinerMap.Add(combinedMesh3.gosToAdd[m].GetInstanceID(), combinedMesh3);
         }
         if (combinedMesh3.gosToAdd.Count > 0 || combinedMesh3.gosToDelete.Count > 0)
         {
             combinedMesh3.gosToDelete.Clear();
             combinedMesh3.gosToAdd.Clear();
             combinedMesh3.numVertsInListToDelete = 0;
             combinedMesh3.numVertsInListToAdd    = 0;
             combinedMesh3.isDirty = true;
         }
     }
     if (this.LOG_LEVEL >= MB2_LogLevel.debug)
     {
         string text = "Meshes in combined:";
         for (int n = 0; n < this.meshCombiners.Count; n++)
         {
             string text2 = text;
             text = string.Concat(new object[]
             {
                 text2,
                 " mesh",
                 n,
                 "(",
                 this.meshCombiners[n].combinedMesh.GetObjectsInCombined().Count,
                 ")\n"
             });
         }
         text = text + "children in result: " + this.resultSceneObject.transform.childCount;
         MB2_Log.LogDebug(text, new object[]
         {
             this.LOG_LEVEL
         });
     }
     return(this.meshCombiners.Count > 0);
 }
Beispiel #5
0
 private void _distributeAmongBakers(GameObject[] gos, int[] deleteGOinstanceIDs)
 {
     if (gos == null)
     {
         gos = MB3_MultiMeshCombiner.empty;
     }
     if (deleteGOinstanceIDs == null)
     {
         deleteGOinstanceIDs = MB3_MultiMeshCombiner.emptyIDs;
     }
     if (this.resultSceneObject == null)
     {
         this.resultSceneObject = new GameObject("CombinedMesh-" + base.name);
     }
     for (int i = 0; i < this.meshCombiners.Count; i++)
     {
         this.meshCombiners[i].extraSpace = this._maxVertsInMesh - this.meshCombiners[i].combinedMesh.GetMesh().vertexCount;
     }
     for (int j = 0; j < deleteGOinstanceIDs.Length; j++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh = null;
         if (this.obj2MeshCombinerMap.TryGetValue(deleteGOinstanceIDs[j], out combinedMesh))
         {
             if (this.LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug(string.Concat(new object[]
                 {
                     "MB2_MultiMeshCombiner.Removing ",
                     deleteGOinstanceIDs[j],
                     " from meshCombiner ",
                     this.meshCombiners.IndexOf(combinedMesh)
                 }), new object[0]);
             }
             combinedMesh.numVertsInListToDelete += combinedMesh.combinedMesh.GetNumVerticesFor(deleteGOinstanceIDs[j]);
             combinedMesh.gosToDelete.Add(deleteGOinstanceIDs[j]);
         }
         else
         {
             Debug.LogWarning("Object " + deleteGOinstanceIDs[j] + " in the list of objects to delete is not in the combined mesh.");
         }
     }
     for (int k = 0; k < gos.Length; k++)
     {
         GameObject gameObject  = gos[k];
         int        vertexCount = MB_Utility.GetMesh(gameObject).vertexCount;
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh2 = null;
         for (int l = 0; l < this.meshCombiners.Count; l++)
         {
             if (this.meshCombiners[l].extraSpace + this.meshCombiners[l].numVertsInListToDelete - this.meshCombiners[l].numVertsInListToAdd > vertexCount)
             {
                 combinedMesh2 = this.meshCombiners[l];
                 if (this.LOG_LEVEL >= MB2_LogLevel.debug)
                 {
                     MB2_Log.LogDebug(string.Concat(new object[]
                     {
                         "MB2_MultiMeshCombiner.Added ",
                         gos[k],
                         " to combinedMesh ",
                         l
                     }), new object[]
                     {
                         this.LOG_LEVEL
                     });
                 }
                 break;
             }
         }
         if (combinedMesh2 == null)
         {
             combinedMesh2 = new MB3_MultiMeshCombiner.CombinedMesh(this.maxVertsInMesh, this._resultSceneObject, this._LOG_LEVEL);
             this._setMBValues(combinedMesh2.combinedMesh);
             this.meshCombiners.Add(combinedMesh2);
             if (this.LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug("MB2_MultiMeshCombiner.Created new combinedMesh", new object[0]);
             }
         }
         combinedMesh2.gosToAdd.Add(gameObject);
         combinedMesh2.numVertsInListToAdd += vertexCount;
     }
 }
 private void _distributeAmongBakers(GameObject[] gos, int[] deleteGOinstanceIDs)
 {
     if (gos == null)
     {
         gos = MB3_MultiMeshCombiner.empty;
     }
     if (deleteGOinstanceIDs == null)
     {
         deleteGOinstanceIDs = MB3_MultiMeshCombiner.emptyIDs;
     }
     if (this.resultSceneObject == null)
     {
         this.resultSceneObject = new GameObject("CombinedMesh-" + base.name);
     }
     for (int i = 0; i < this.meshCombiners.Count; i++)
     {
         this.meshCombiners[i].extraSpace = this._maxVertsInMesh - this.meshCombiners[i].combinedMesh.GetMesh().vertexCount;
     }
     for (int j = 0; j < deleteGOinstanceIDs.Length; j++)
     {
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh = null;
         if (this.obj2MeshCombinerMap.TryGetValue(deleteGOinstanceIDs[j], out combinedMesh))
         {
             if (this.LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug(string.Concat(new object[]
                 {
                     "MB2_MultiMeshCombiner.Removing ",
                     deleteGOinstanceIDs[j],
                     " from meshCombiner ",
                     this.meshCombiners.IndexOf(combinedMesh)
                 }), new object[0]);
             }
             combinedMesh.numVertsInListToDelete += combinedMesh.combinedMesh.GetNumVerticesFor(deleteGOinstanceIDs[j]);
             combinedMesh.gosToDelete.Add(deleteGOinstanceIDs[j]);
         }
         else
         {
             Debug.LogWarning("Object " + deleteGOinstanceIDs[j] + " in the list of objects to delete is not in the combined mesh.");
         }
     }
     for (int k = 0; k < gos.Length; k++)
     {
         GameObject gameObject = gos[k];
         int vertexCount = MB_Utility.GetMesh(gameObject).vertexCount;
         MB3_MultiMeshCombiner.CombinedMesh combinedMesh2 = null;
         for (int l = 0; l < this.meshCombiners.Count; l++)
         {
             if (this.meshCombiners[l].extraSpace + this.meshCombiners[l].numVertsInListToDelete - this.meshCombiners[l].numVertsInListToAdd > vertexCount)
             {
                 combinedMesh2 = this.meshCombiners[l];
                 if (this.LOG_LEVEL >= MB2_LogLevel.debug)
                 {
                     MB2_Log.LogDebug(string.Concat(new object[]
                     {
                         "MB2_MultiMeshCombiner.Added ",
                         gos[k],
                         " to combinedMesh ",
                         l
                     }), new object[]
                     {
                         this.LOG_LEVEL
                     });
                 }
                 break;
             }
         }
         if (combinedMesh2 == null)
         {
             combinedMesh2 = new MB3_MultiMeshCombiner.CombinedMesh(this.maxVertsInMesh, this._resultSceneObject, this._LOG_LEVEL);
             this._setMBValues(combinedMesh2.combinedMesh);
             this.meshCombiners.Add(combinedMesh2);
             if (this.LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug("MB2_MultiMeshCombiner.Created new combinedMesh", new object[0]);
             }
         }
         combinedMesh2.gosToAdd.Add(gameObject);
         combinedMesh2.numVertsInListToAdd += vertexCount;
     }
 }