Getting UV points from a BMesh object in Blender

When working with a BMesh object in the Blender Python API, we can get UV points from the vertices of the object itself, just like with the base object.

Add a cube to the scene (if you havn’t one by default). The cube already has an automatically generated UV map. Switch to edit mode and select one polygon.

Now let’s get the UV coordinates for the selected polygon using the BMesh object.

Create a BMesh object and copy the geometry of the currently active object (the cube) to it. Ensure vertices indices.

First, let’s take the selected polygon.

We also need a pointer to the current UV layer.

Get a pointer to the meshloop of the selected polygon.

Now, using the meshloop, we can get a combined list of vertices of the 3D object itself (in BMesh) and points on the UV map.

We can get the coordinates of the points themselves using the “uv” property of the points on the UV map (BMLoopUV). Get the combined list with the vertex index on the geometry and the corresponding coordinates on the UV map for that vertex.

Another useful option is to get a list of all mesh vertices, linking a vertex with its coordinates on the UV map. This call can be executed in a single line.

The first element in the resulting list is a pointer to a vertex in 3D space in the BMesh object, and the second is a vector with its coordinates in 2D UV space.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted