1
\$\begingroup\$

I'm creating hexagonal prisms from code and am having a difficult time understanding how UV mapping works, as the texture I apply to the hexagonal face comes out skewed:

enter image description here

Forgetting the sides for now, here is how I'm creating the hexagonal face:

    meshData.vertices.Add(new Vector3(x, y + 0.5f, z + 0.5f)); // N
    meshData.vertices.Add(new Vector3(x + 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z + 0.5f / 2)); // NE
    meshData.vertices.Add(new Vector3(x + 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z - 0.5f / 2)); // SE
    meshData.vertices.Add(new Vector3(x, y + 0.5f, z - 0.5f)); // S
    meshData.vertices.Add(new Vector3(x - 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z - 0.5f / 2)); // SW
    meshData.vertices.Add(new Vector3(x - 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z + 0.5f / 2)); // NW

This creates a regular hexagon. My texture is also a regular hexagon. So why does it get textured at an angle?

Here is my UV code:

    meshData.uv.Add(new Vector2(0.5f, 1));
    meshData.uv.Add(new Vector2(1, 0.75f));
    meshData.uv.Add(new Vector2(1, 0.25f));
    meshData.uv.Add(new Vector2(0.5f, 0));
    meshData.uv.Add(new Vector2(0, 0.25f));
    meshData.uv.Add(new Vector2(0, 0.75f));
\$\endgroup\$
2
  • \$\begingroup\$ When you create procedural meshes, you don't just need to set up the vertices but also the UV coordinates. \$\endgroup\$
    – Philipp
    Sep 10, 2016 at 17:31
  • 1
    \$\begingroup\$ Oops, forgot to paste those in. Updated. \$\endgroup\$
    – Matt
    Sep 10, 2016 at 18:02

1 Answer 1

1
\$\begingroup\$

Well, it turns out I misspoke--my hexagon texture was not, in fact, regular. I create most of my 2D programmer art in PowerPoint and mistakenly assumed that holding Shift while drawing a hexagon would make it regular. It turns out that this only creates an arbitrarily shaped six-sided polygon that scales proportionally.

Anyone who happens to be seeking a method for producing regular hexagons in PowerPoint can utilize the solution I found on SuperUser

\$\endgroup\$

You must log in to answer this question.

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