Quantcast
Viewing all articles
Browse latest Browse all 4

Seperating one single mesh into meshes.

Hi. I've written a code to seperate a mesh into submeshes if it has seperated faces or vertices. It has been worked with a simple mesh but not working with a complex mesh. I cannot figured it out what am I doing wrong? Is there any better way to do this. public static Mesh[] Split(Mesh mesh) { List indices = new List(mesh.triangles); List> indexGroups = new List>(); // Listede index kaldıkça işleme devam et while (indices.Count > 0) { bool matchFound = false; // Her bir index grubun... foreach (List indexGroup in indexGroups) { // ...her bir indeks ile... (listeden atma işlemlerinin sağlığı açısından sondan başla) for (int i = indices.Count - 3; i >= 0; i -= 3) { // -indesi üçgen olarak al- int[] triangleIndices = new int[] { indices[i + 0], indices[i + 1], indices[i + 2] }; // ...bağlantısı varsa... if (indexGroup.Contains(triangleIndices[0]) || indexGroup.Contains(triangleIndices[1]) || indexGroup.Contains(triangleIndices[2])) { // ... bu ucgen indekslerini index gruba ekle ve indeks listesinden at indexGroup.AddRange(triangleIndices); // ... bu üçgen indekslerini index listesinden at indices.RemoveRange(i, 3); // yeni bir eşleşme bulunduğu için yeni bir grup oluşturmaya gerek yok, tekrar arama yapılmalı matchFound = true; } } } // Eğer eşleşme hiç yoksa yeni bir gruba ihtiyaç vardır if (!matchFound) { // yeni grubu oluştur List newGroup = new List(); // ilk 3 indeksi yeni gruba ekle newGroup.Add(indices[0]); newGroup.Add(indices[1]); newGroup.Add(indices[2]); // bu indeksleri indeks listesinden at indices.RemoveRange(0, 3); // yeni grubu grup listesine ekle indexGroups.Add(newGroup); } } // Indeks gruplarından yeni meshleri oluştur. Mesh[] meshes = new Mesh[indexGroups.Count]; for (int i = 0; i < indexGroups.Count; i++) { List indexGroup = indexGroups[i]; meshes[i] = new Mesh(); meshes[i].vertices = new Vector3[indexGroup.Count]; meshes[i].triangles = new int[indexGroup.Count]; for (int j = 0; j < indexGroup.Count; j++) { meshes[i].vertices[j] = mesh.vertices[indexGroup[j]]; meshes[i].triangles[j] = j; } meshes[i].RecalculateNormals(); meshes[i].Optimize(); meshes[i].RecalculateBounds(); } return meshes; }

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>