Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/bmesh_from_pydata.py
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/5b3a4e720a7ed938cc6e to your computer and use it in GitHub Desktop.
Save zeffii/5b3a4e720a7ed938cc6e to your computer and use it in GitHub Desktop.
def bmesh_from_pydata(verts=[], edges=[], faces=[]):
''' verts is necessary, edges/faces are optional '''
if not verts:
print("verts data seems empty")
return
bm = bmesh.new()
[bm.verts.new(co) for co in verts]
bm.verts.index_update()
if faces:
for face in faces:
bm.faces.new(tuple(bm.verts[i] for i in face))
bm.faces.index_update()
if edges:
for edge in edges:
edge_seq = tuple(bm.verts[i] for i in edge)
try:
bm.edges.new(edge_seq)
except ValueError:
# edge exists!
pass
bm.edges.index_update()
return bm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment