How can i split mesh faces without losing faces materials assignments. The code i used is here (the other variables you can’t see are declared in the main code), it works but it loses materials assignments and gets the final mesh with only a material:
void defragMesh()
{
myMesh = new Mesh();
myMesh.vertices = startMesh.vertices;
myMesh.triangles = startMesh.triangles;
myMesh.uv = startMesh.uv;
myMesh.normals = startMesh.normals;
newVertices = new Vector3[myMesh.triangles.Length];
int[] newTris = new int[myMesh.triangles.Length];
Vector2[] newUV = new Vector2[myMesh.triangles.Length];
Vector3[] newNormals = new Vector3[myMesh.triangles.Length];
for(int i = 0; i < myMesh.triangles.Length; i++)
{
newVertices _= myMesh.vertices[myMesh.triangles*];*_
newUV = myMesh.uv[myMesh.triangles*];*
newNormals = myMesh.normals[myMesh.triangles*];*
_ newTris = i;
* }*_
* myMesh.vertices = newVertices;*
* myMesh.triangles = newTris;*
* myMesh.uv = newUV;*
* myMesh.normals = newNormals;*
* normals = new Vector3[myMesh.triangles.Length / 3];*
* int index = 0;*
* for(int i = 0; i < normals.Length; i++)*
* {*
* Vector3 v = newVertices[index++];*
_ normals = Vector3.Cross(newVertices[index++] - v, newVertices[index++] - v).normalized;
* }*_
* }*