I am trying to use the following example script to combine small parts of a mesh into one, so I am able to make a dynamic terrain: http://unity3d.com/support/documentation/ScriptReference/Mesh.CombineMeshes.html.
The problem is that it flips the normals of some of the meshes. How come and how to solve this?
The following image shows that the normals of the edges of my model are flipped, while some of the edges are still ok. These blocks all exist out of a center plane, corners and edges.
[638-flipped+normals.png*_|638]
What it should be:
[632-no+flipped+normals.png*_|632]
private static void CombineMesh(GameObject iceBerg)
{
MeshFilter[] meshes = iceBerg.GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshes.Length];
for (int i = 0; i < meshes.Length; i++)
{
combine_.mesh = meshes*.sharedMesh;*_
combine_.transform = meshes*.transform.localToWorldMatrix;_
_meshes.gameObject.active = false;
}
MeshFilter meshFilter = iceBerg.AddComponent();
meshFilter.mesh = new Mesh();
meshFilter.mesh.CombineMeshes(combine);
MeshRenderer renderer = iceBerg.AddComponent();
renderer.material = (Material)Resources.Load(“Materials/GridIce”);
MeshCollider col = iceBerg.AddComponent();
col.smoothSphereCollisions = true;
}
_*