Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void SplitVertices (Mesh mesh)
- {
- var vertices = mesh.vertices.ToList();
- var vCnt = vertices.Count;
- if(vCnt == 0)
- return;
- var uvs = mesh.uv.ToList();
- var colors = mesh.colors.ToList();
- var tangents = mesh.tangents.ToList();
- var hasUvs = vCnt == uvs.Count;
- var hasColors = vCnt == colors.Count;
- var hasTangents = vCnt == tangents.Count;
- var unique = new HashSet<int>();
- var allTriangles = new List<int[]>();
- var submeshes = mesh.subMeshCount;
- for(int s = 0; s < submeshes; s++)
- {
- var triangles = mesh.GetTriangles(s);
- int tCnt = triangles.Length;
- int index;
- for(int t = 0; t < tCnt; t++)
- {
- index = triangles[t];
- if(unique.Contains(index))
- {
- vertices.Add(vertices[index]);
- if(hasUvs)
- uvs.Add(uvs[index]);
- if(hasColors)
- colors.Add(colors[index]);
- if(hasTangents)
- tangents.Add(tangents[index]);
- triangles[t] = vertices.Count - 1;
- }
- else
- unique.Add(index);
- }
- allTriangles.Add(triangles);
- }
- mesh.SetVertices(vertices);
- for(int s = 0; s < submeshes; s++)
- mesh.SetTriangles(allTriangles[s], s);
- if(hasUvs)
- mesh.SetUVs(0, uvs);
- if(hasColors)
- mesh.SetColors(colors);
- if(hasTangents)
- mesh.SetTangents(tangents);
- }
Advertisement
Add Comment
Please, Sign In to add comment