public void Start2() { if (mf == null) mf = GetComponent<MeshFilter>(); if (meshList.Count > 0) { var list = new List<CombineInstance>(); var r = mf.GetComponent<MeshRenderer>(); var enumerable = new[] { mf.renderer }.Concat(meshList); r.sharedMaterials = enumerable.SelectMany(a => a.sharedMaterials).ToArray(); foreach (var a in enumerable) { var sharedMesh = a.GetComponent<MeshFilter>().sharedMesh; for (int i = 0; i < sharedMesh.subMeshCount; i++) { var ci = new CombineInstance(); ci.transform = tr.worldToLocalMatrix * a.transform.localToWorldMatrix; ci.mesh = sharedMesh; ci.subMeshIndex = i; list.Add(ci); } } mf.mesh.CombineMeshes(list.ToArray(), false); foreach (var a in meshList) Destroy(a.gameObject); } lossyScale = mf.transform.lossyScale; elements.Clear(); lab = new Dictionary<int, List<Tr>>(); vertices = mf.mesh.vertices; oldVertices = (Vector3[])vertices.Clone(); normals = mf.mesh.normals; tangents = mf.mesh.tangents; uvs = mf.mesh.uv; for (int x = 0; x < mf.mesh.subMeshCount; x++) { var trs = mf.mesh.GetIndices(x); for (int i = 0; i < trs.Length; i += 3) { var tr = new Tr() { ind = new[] { trs[i], trs[i + 1], trs[i + 2] }, pointers = new[] { i, i + 1, i + 2 }, group = x }; flat.Add(tr); for (int j = 0; j < 3; j++) { List<Tr> lt; if (!lab.TryGetValue(trs[i + j], out lt)) lab[trs[i + j]] = lt = new List<Tr>(); lt.Add(tr); } } } foreach (Tr t in flat) { if (!t.went) { Element element = new Element(); element.MeshTest = this; elements.Add(element); var color32 = new Color32((byte)(Random.value * 255), (byte)(Random.value * 255), (byte)(Random.value * 255), 255); Go(t, color32, element, 0); } } }