def triangulate(ob='empty', proxy=False):
'''Requires a mesh. Returns an index array for viewing
the coordinates as triangles. Store this!!! rather than recalculating
every time. !!!Could use for_each_get with the mesh and polygons if
all the faces have 3 points!!! Could also write bmesh to mesh and use
foreach_get'''
if ob == 'empty':
ob = bpy.context.object
if proxy:
mods = True
else:
mods = False
proxy = ob.to_mesh(bpy.context.scene, mods, 'PREVIEW')
obm = get_bmesh(proxy)
bmesh.ops.triangulate(obm, faces=obm.faces)
obm.to_mesh(proxy)
count = len(proxy.polygons)
tri_idx = np.zeros(count * 3, dtype=np.int64)
proxy.polygons.foreach_get('vertices', tri_idx)
bpy.data.meshes.remove(proxy)
obm.free()
return tri_idx.reshape(count, 3)
评论列表
文章目录