def convex_hull(mesh, clean=True):
'''
Get a new Trimesh object representing the convex hull of the
current mesh. Requires scipy >.12.
Argments
--------
clean: boolean, if True will fix normals and winding
to be coherent (as qhull/scipy outputs are not)
Returns
--------
convex: Trimesh object of convex hull of current mesh
'''
type_trimesh = type_named(mesh, 'Trimesh')
c = ConvexHull(mesh.vertices.view(np.ndarray).reshape((-1,3)))
vid = np.sort(c.vertices)
mask = np.zeros(len(c.points), dtype=np.int64)
mask[vid] = np.arange(len(vid))
faces = mask[c.simplices]
vertices = c.points[vid].copy()
convex = type_trimesh(vertices = vertices,
faces = faces,
process = True)
if clean:
# the normals and triangle winding returned by scipy/qhull's
# ConvexHull are apparently random, so we need to completely fix them
convex.fix_normals()
return convex
评论列表
文章目录