I am trying to generate correct UVs for meshes I have combined with CombineMeshes().
UnityEditor.Unwrapping.GeneratePerTriangleUV() seems to do what I want, but the documentation just says “You’ll need to merge them yourself.”
This function seems to be giving me back one UV pair per triangle, but I don’t know how to merge/map those onto the vertex UV pairs that the mesh seems to have (the UV array is the same size as the vertex array, while the generated UV array is the same size as the triangle array).
Here is my function:
public GameObject MeshCombination(Material material, CombineInstance[] combines)
{
GameObject newMeshObj = new GameObject(material.name);
MeshFilter targetFilter = null;
targetFilter = newMeshObj.AddComponent<MeshFilter>();
newMeshObj.AddComponent<MeshRenderer>();
targetFilter.sharedMesh = new Mesh();
targetFilter.sharedMesh.CombineMeshes(combines);
Vector2[] triangleUV = UnityEditor.Unwrapping.GeneratePerTriangleUV(targetFilter.sharedMesh);
// How do I merge the per triangle UVs and assign them to the mesh?
targetFilter.renderer.material = material;
return newMeshObj;
}
Thanks in advance for whatever help you guys can give me!