1
\$\begingroup\$

In the documentation of MeshUtility.SetPerTriangleUV2 it is said the following:

Will insert per-triangle uv2 in mesh and handle vertex splitting etc.

What do they mean by 'vertex splitting' ?

\$\endgroup\$
3

1 Answer 1

3
\$\begingroup\$

As described in the two answers I linked in the comments, each vertex we send to the GPU is one unique combination of {position, normal, texture coordinate 1, texture coordinate 2, tangent, vertex color, etc...} (depending on which attributes we're using)

If you have a single vertex location on your mesh that needs two different texture coordinates (like on a texture seam), then that vertex location gets split into two vertices to send to the GPU - both with the same position, but one with texture coordinate A and one with texture coordinate B.

What this passage says is that this method does the splitting for you automatically if needed.

Let's say your mesh was a quad, something like...

0 --- 1     Vertex     Position       UV 0
| \   |        0       (0, 1, 0)     (0, 1)
|  \  |        1       (1, 1, 0)     (1, 1)
|   \ |        2       (0, 0, 0)     (0, 0)
2 --- 3        3       (1, 0, 0)     (1, 0)

With triangle indices {0, 3, 1} {0, 2, 3}

Now let's say we call SetPerTriangleUV2 on this mesh, providing the UVs...

{(0, 0) (1, 0) (0.5, 0.5) (1, 0) (0.5, 0.5) (0, 0)}
    0      3        1        0        2        3

I labelled each UV coordinate here with the vertex it's going to apply to (in the order they're indexed by the mesh's triangles)

Notice that vertex 0 and 3 each get two different UVs assigned to them. So this method will make a copy of vertices 0 and 3 - one for the first triangle, with one set of UV2 coordinates, and one for the second triangle, with a different set of UV2 coordinates.

The vertex count after this operation will be 6, because we added two extra vertices to accommodate the split.

When the documentation says this method will "handle vertex splitting" it means that you don't need to check for this in your code and insert the extra vertex copies / update the indices yourself. The SetPerTriangleUV2 will detect where vertices need to be split, split them, and update the triangle indices accordingly to accommodate the new splits.

\$\endgroup\$
1
  • \$\begingroup\$ That makes sense now thanks to your explanations :) \$\endgroup\$
    – aybe
    Commented Jan 15, 2021 at 20:57

You must log in to answer this question.

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