0

I'm making a program where a large and complicated mesh is procedurally generated. At first I generated a large number of smaller meshes, which works just fine, but then I decided to merge them together and some triangles got corrupted. Some triangles are very l o n g, when they absolutely shouldn't be After a bit of looking i managed to pinpoint the problem:

Debug.Log(fullTriangles == fullTriangles);
boxMesh.triangles = fullTriangles;
Debug.Log(boxMesh.triangles == fullTriangles);

first log returns true, second log returns false

This only occurs when I use the large mesh. For the many smaller meshes both debugs return true.

Here's a picture of the mesh. It loops on itself in many places, is in no way convex, has several floating islands, and is in general very difficult from a rendering perspective. The mesh is a slight mess

Other information that might matter:

  • The many small meshes in the large mesh do not share any verticies in the large mesh, but some verticies have the same positions
  • Each small mesh is made of one or several triangles, that do share verticies
  • The small meshes are not submeshes

Why does this happend, and what can I do to fix it?

1 Answers1

1

I'm guessing that your mesh has too many vertices, take a look at mesh index format.

To avoid this problem, you could either run a mesh welder, or batch smaller meshes together. You could also merge smaller meshes into a bigger one, but keeping count of the merged mesh number of vertices. If it exceeds the vertex count limit, create another merged mesh (and so on).

As a side note, keep in mind that comparing arrays with " == " will not compare the values in the array, but the arrays references. You could use Enumerable.SequenceEqual, or run a simple for loop.

Stev
  • 161
  • 3