0
\$\begingroup\$

I am experimenting with Hex grid layouts and testing the most efficient way of building a hex map.

I tried 2 things:

  1. Build my own hex mesh using 6 triangles and 7 vertices
  2. Use blender to create a Hex and import it

For 1. The mesh renderer I created is attached to an object prefab and I instantiate one for each Hex in my grid. 2 is almost similar but I imported the .fbx model from blender and I created a prefab from it. Then instantiate one per hex in my grid.

Question: Why is the Blender approach giving me better performance then when I create the meshes myself?

When I use the first approach with the meshes I created, I'm getting around 44FPS

44 FPS for created Mesh

But when I use the Blender approach I get around 60 FPS

60 FPS for Blender model

Info on how I'm creating my meshes. I create 7 vertices, Marked on this screenshot from 0 to 6 WireFrame of my Hex

Then my triangles will be:

List<int> triangles = new List<int>() {
            0, 2, 1,
            0, 3, 2,
            0, 4, 3,
            0, 5, 4,
            0, 6, 5,
            0, 1, 6,
        };


 //Create the Mesh
 m_mesh = new Mesh();
 m_mesh.name = "Hex";
 m_mesh.vertices = vertices.ToArray();
 m_mesh.triangles = triangles.ToArray();
 m_mesh.uv = uvs.ToArray();
 m_mesh.RecalculateNormals();
\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Let me share an insight in the form of a meme:

Hexagon cut into triangle two ways: left, into 6 triangles radiating from the center, like pizza slices; right: cut in a Z shape into 4 triangles.

The way you've chosen to generate your hexagon mesh in Unity is like the one on the left, with 7 vertices and 6 triangles per hex.

I'd bet that Blender has chosen to triangulate it without adding an extra vertex in the center, which lets it use only 6 vertices and 4 triangles, like the example on the right.

Checking your rendering stats backs this up:

Unity Mesh Blender Mesh Ratio
Tris 121.7 k 81.7 k ~6:4
Verts 145.1 k 125.1 k ~7:6

So, no special magic, the Blender version just has less data to push down the graphics pipe, so it can be drawn in fewer batches. If you use the 4-triangle split in your Unity code, I'd expect you'd see the difference disappear.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .