Assigning real indices to vertices created in bmesh

When we work with the bmesh object through the Blender Python API to create new geometry, all created vertices receive an index equal to -1. Although we can fully interact and control the created vertices, the lack of a numbered index can make it somewhat difficult to perceive the geometry and debug the code.

To assign sequential numbers to vertices in bmesh, the index_update() function is used.

Let’s see how it works. To do this, create a bmesh object from the currently active mesh.

And check the numbering of the current vertices indices.

Now create a new vertex with (0.0, 0.0, 2.0) coordinates.

And check the index numbers again.

As we see, a new vertex with index equal to -1 has appeared. And this is a new vertex created by us.

Now convert the indices to sequential order using the index_update() function.

And check the indices again.

After calling the index_update() function, all indices received ordinal numbers. This is also reflected in the data of the vertex we created.

In fact, the index_update() function consists of only two lines.

Important

Remember that calling index_update() does not guarantee that the resulting indices will exactly follow the order in which the vertices are created or the order in which the vertices follow each other.

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments