Exemplo n.º 1
0
        static private void MakeBatch(List <MeshSubsetCombineUtility.MeshContainer> meshes, Transform staticBatchRootTransform, int batchIndex)
        {
            if (meshes.Count < 2)
            {
                return;
            }

            List <MeshSubsetCombineUtility.MeshInstance>    meshInstances       = new List <MeshSubsetCombineUtility.MeshInstance>();
            List <MeshSubsetCombineUtility.SubMeshInstance> allSubMeshInstances = new List <MeshSubsetCombineUtility.SubMeshInstance>();

            foreach (MeshSubsetCombineUtility.MeshContainer mesh in meshes)
            {
                meshInstances.Add(mesh.instance);
                allSubMeshInstances.AddRange(mesh.subMeshInstances);
            }

            string combinedMeshName = CombinedMeshPrefix;

            combinedMeshName += " (root: " + ((staticBatchRootTransform != null) ? staticBatchRootTransform.name : "scene") + ")";
            if (batchIndex > 0)
            {
                combinedMeshName += " " + (batchIndex + 1);
            }

            Mesh combinedMesh = StaticBatchingHelper.InternalCombineVertices(meshInstances.ToArray(), combinedMeshName);

            StaticBatchingHelper.InternalCombineIndices(allSubMeshInstances.ToArray(), combinedMesh);
            int totalSubMeshCount = 0;

            foreach (MeshSubsetCombineUtility.MeshContainer mesh in meshes)
            {
                // Changing the mesh resets the static batch info, so we have to assign sharedMesh first
                MeshFilter filter = (MeshFilter)mesh.gameObject.GetComponent(typeof(MeshFilter));
                filter.sharedMesh = combinedMesh;

                int      subMeshCount = mesh.subMeshInstances.Count();
                Renderer renderer     = mesh.gameObject.GetComponent <Renderer>();
                renderer.SetStaticBatchInfo(totalSubMeshCount, subMeshCount);
                renderer.staticBatchRootTransform = staticBatchRootTransform;

                // For some reason if GOs were created dynamically
                // then we need to toggle renderer to avoid caching old geometry
                renderer.enabled = false;
                renderer.enabled = true;

                // Remove the additionalVertexStreamsMesh, all its data has been copied into the combined mesh.
                MeshRenderer meshRenderer = renderer as MeshRenderer;
                if (meshRenderer != null)
                {
                    meshRenderer.additionalVertexStreams = null;
                }

                totalSubMeshCount += subMeshCount;
            }
        }
Exemplo n.º 2
0
 private static void MakeBatch(List <MeshSubsetCombineUtility.MeshContainer> meshes, Transform staticBatchRootTransform, int batchIndex)
 {
     if (meshes.Count >= 2)
     {
         List <MeshSubsetCombineUtility.MeshInstance>    list  = new List <MeshSubsetCombineUtility.MeshInstance>();
         List <MeshSubsetCombineUtility.SubMeshInstance> list2 = new List <MeshSubsetCombineUtility.SubMeshInstance>();
         foreach (MeshSubsetCombineUtility.MeshContainer mesh2 in meshes)
         {
             MeshSubsetCombineUtility.MeshContainer current = mesh2;
             list.Add(current.instance);
             list2.AddRange(current.subMeshInstances);
         }
         string str = "Combined Mesh";
         str = str + " (root: " + ((!(staticBatchRootTransform != null)) ? "scene" : staticBatchRootTransform.name) + ")";
         if (batchIndex > 0)
         {
             str = str + " " + (batchIndex + 1);
         }
         Mesh mesh = StaticBatchingHelper.InternalCombineVertices(list.ToArray(), str);
         StaticBatchingHelper.InternalCombineIndices(list2.ToArray(), mesh);
         int num = 0;
         foreach (MeshSubsetCombineUtility.MeshContainer mesh3 in meshes)
         {
             MeshSubsetCombineUtility.MeshContainer current2 = mesh3;
             MeshFilter meshFilter = (MeshFilter)current2.gameObject.GetComponent(typeof(MeshFilter));
             meshFilter.sharedMesh = mesh;
             int      num2      = current2.subMeshInstances.Count();
             Renderer component = current2.gameObject.GetComponent <Renderer>();
             component.SetStaticBatchInfo(num, num2);
             component.staticBatchRootTransform = staticBatchRootTransform;
             component.enabled = false;
             component.enabled = true;
             MeshRenderer meshRenderer = component as MeshRenderer;
             if (meshRenderer != null)
             {
                 meshRenderer.additionalVertexStreams = null;
             }
             num += num2;
         }
     }
 }
Exemplo n.º 3
0
        private static void CombineRoot(GameObject staticBatchRoot)
        {
            MeshFilter[] filters;
            GameObject[] gos;
            if (staticBatchRoot == null)
            {
                filters = (MeshFilter[])Object.FindObjectsOfType(typeof(MeshFilter));
            }
            else
            {
                filters = staticBatchRoot.GetComponentsInChildren <MeshFilter>();
            }

            gos = new GameObject[filters.Length];
            for (int i = 0; i < filters.Length; i++)
            {
                gos[i] = filters[i].gameObject;
            }

            StaticBatchingHelper.CombineMeshes(gos, staticBatchRoot);
        }
Exemplo n.º 4
0
 public static void Combine(GameObject[] gos, GameObject staticBatchRoot)
 {
     using (s_CombineMarker.Auto())
         StaticBatchingHelper.CombineMeshes(gos, staticBatchRoot);
 }