Strange mesh triangle/vertices access behaviour

Hi,

I have imported a blender (v 2.91.2) file (see the attached) into a Unity (2019.2.0f6) project, and used Mesh.triangles and vertices to access its mesh. However, most of triangle trio vertices are wrong (zero area faces with duplicate vertices) but some are OK (matching the blender model):

MeshFilter mf = g.GetComponent<MeshFilter>();
Mesh mesh;
 if (mf != null)
{
  mesh = mf.mesh;
  Vector3[] V = mesh.vertices;
  Vector3[] N = mesh.normals;
  int[] T = mesh.triangles;
  Debug.Log("index " + " " + T[0] + " " + T[1] + " " + T[2]);
  Debug.Log("vertex " + " " + V[T[0]] + " " + V[T[1]] + " " + V[T[2]]);
}

The Log results are

As you see, vertices 1 and 2 are the same (this vertex duplication happens for most other triangles as well).
I am sure that the blender mesh is OK (no loose vertices, zero length edge or faces, duplicate vertices, etc). The game object is also rendered correctly in editor and game. So the issue is only in the script. What’s the issue?

7458173–915410–villa x.zip (135 KB)

In Blender (and many 3D packages) a single vert can have multiple normals. This is necessary when you are going for that lowpoly “faceted” look (sharp edges), since each face adjacent shares the verts along its shared edge, yet has different lighting normals to produce the sharp delineation.

In Unity, everything in a vertex correlates 1-to-1 with the UV, normal, tangent, color, etc., so when you import anything that has a faceted edge, Unity has to duplicate the verts at that corner so that each vert can have a different normal.

It should not be making zero-area triangles though. That has to be in Blender.

To see it, export your object as OBJ and find those numbers and prove there are no zero-area trianges in the OBJ data. It’s easy enough to write a quick python script to digest the vertex positions and triangles and compute the area of each triangle. I think you’ll find you have zero-area tris in your blender file. :slight_smile:

If you want to tinker with other procgen stuff, you’re welcome to sniff around my MakeGeo project.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

1 Like

Well, if you look carefully, the vertices are not the same. This would make up a very slim triangle, but it still seems to exist. They differ by only 0.012 on the x axis.

Maybe that’s the result of some manual / badly carried out operations in blender.

1 Like

Omg, yes. Thank you. There’s a tiny difference between the vertices.