- Home /
Textures break when mesh stops sharing vertices
I have a program which stops a mesh sharing vertices in the editor. However when I run a process on a test (see below) the textures go all weird and all go onto certain part of the robot not the whole thing.
Here is my code:
void Process() {
Transform curr = Selection.activeTransform;
if (curr == null) {
error = "Please select an appropriate object in the heirarchy";
Debug.Log (error);
return;
}
MeshFilter meshFil;
meshFil = curr.GetComponent<MeshFilter>();
if (meshFil == null || meshFil.sharedMesh == null) {
error = "No editable mesh filter is detected on selected object \n(" + curr.name + ")";
Debug.Log (error);
return;
}
GameObject gamObj = Instantiate (curr.gameObject) as GameObject;
meshFil = gamObj.GetComponent<MeshFilter>();
Mesh mesh = Instantiate (meshFil.sharedMesh) as Mesh;
meshFil.sharedMesh = mesh;
Selection.activeObject = gamObj.transform;
Vector3[] oldVerts = mesh.vertices;
int[] trigs = mesh.triangles;
Vector3[] newVerts = new Vector3[trigs.Length];
for (int i = 0; i < trigs.Length; i++) {
newVerts[i] = oldVerts[trigs[i]];
trigs[i] = i;
}
mesh.vertices = newVerts;
mesh.triangles = trigs;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
problem-photo.png
(91.9 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613200501im_/https://answers.unity.com/themes/thub/images/avi.jpg)