bmesh – deleting by mode (context)

To remove vertices, edges or polygons from a bmesh object, it is most convenient to use the remove() method for the corresponding set of elements. In addition, the bmesh object has a bmesh.ops.delete() operator, which allows us to delete elements using different modes (context).

There are seven contexts for the bmesh.ops.delete() delete operator:

  • VERTS – removing vertices
  • EDGES – removing edges
  • FACES_ONLY – removing only faces
  • EDGES_FACES – removing only faces and edges
  • FACES – removing faces
  • FACES_KEEP_BOUNDARY – removing faces, saving their boundaries
  • TAGGED_ONLY – only tagged (undocumented)

The required context is specified in the third parameter of the deleting operator.

Let’s add Suzanne to the scene.

To work with bmesh correctly, we need to switch to editing mode.

Create a bmesh object and transfer data from the current active mesh (Suzanne) to it.

Create a list of selected polygons.

This list is passed as the second parameter to the delete() operator. If we use deletion contexts for points or edges, we will need to form the selection list from points or edges, respectively. When calling the operator, only elements from this list will be deleted.

Now we can execute the operator

In the first parameter of the operator we passed a pointer to the bmesh object, in the second – we passed the created selection list, and in the third we specified the context.

When calling the operator, the selected polygons will be deleted, and since the context for deleting polygons was used while preserving their boundaries, the edges around the deleted polygons will not be deleted.

Once the removal is done, we can return the geometry to the active mesh.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments