Created
May 26, 2015 19:45
-
-
Save zeffii/43ee4e2e9ce15a09bb43 to your computer and use it in GitHub Desktop.
bmesh_from_pydata, pydata_from_bmesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bmesh | |
def bmesh_from_pydata(verts, edges=None, faces=None): | |
''' verts is necessary, edges/faces are optional ''' | |
bm = bmesh.new() | |
add_vert = bm.verts.new | |
bm_verts = [add_vert(co) for co in verts] | |
bm.verts.index_update() | |
if faces: | |
add_face = bm.faces.new | |
for face in faces: | |
add_face([bm_verts[i] for i in face]) | |
bm.faces.index_update() | |
if edges: | |
add_edge = bm.edges.new | |
for edge in edges: | |
edge_seq = bm_verts[edge[0]], bm_verts[edge[1]] | |
try: | |
add_edge(edge_seq) | |
except ValueError: | |
# edge exists! | |
pass | |
bm.edges.index_update() | |
return bm | |
def pydata_from_bmesh(bm): | |
v = [v.co[:] for v in bm.verts] | |
e = [[i.index for i in e.verts] for e in bm.edges[:]] | |
p = [[i.index for i in p.verts] for p in bm.faces[:]] | |
return v, e, p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment