Convex hull

The convex_hull() function allows us to create a convex hull for a mesh – a shape that completely encloses the mesh at its extreme points. With its help, we can quickly build simplified models from complex meshes.

To use the convex_hull() function, we must initialize the bmesh object structure first.

Let’s create a bmesh and load the geometry of the currently selected mesh into it.

Now we can call the convex_hull() function to build a convex hull around the geometry in the bmesh object.

Two parameters are passed to the function:

  • pointer to the bmesh geometry
  • set of points around which the convex hull will be built

In our case, we pass in the second parameter all the points of the bmesh.

The function returns a dictionary with four keys:

  • geom – list of vertices from which the convex hull is built
  • geom_interior – list of all geometry vertices
  • geom_unused – list of unused vertices, if such vertices exists
  • geom_holes – list of vertices that form holes in the geometry, if such vertices exists

We can use this information, for example, to select vertices that form only the constructed shell itself.

We need to deselect all points at starting point:

And after calling convex_hull(), select points from the list by “geom” key:

After performing the necessary actions, transfer the processed geometry from bmesh back to the original mesh, and clean and delete the bmesh itself, which we no longer need.

Full code:

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments