Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active December 28, 2015 18:53
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/cad08a04c491bfcbbe1e to your computer and use it in GitHub Desktop.
Save zeffii/cad08a04c491bfcbbe1e to your computer and use it in GitHub Desktop.
# start off in Edit Mode
import bpy
import bmesh
def big_dufus_function():
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
verts = []
faces = []
# get verts
verts.extend([v.co[:] for v in bm.verts])
add_vert = verts.append
add_face = faces.append
# get new verts and faces
for f in bm.faces:
if len(f.verts) == 6:
add_vert(f.calc_center_median()[:])
loop = [v.index for v in f.verts]
loop.append(loop[0])
for i in range(0,6,2):
idx1 = loop[i]
idx2 = loop[i+1]
idx3 = loop[i+2]
add_face([idx1, idx2, idx3, len(verts)-1])
# wipe all current bm, and overwrite the Mesh data
bm.clear()
bmesh.update_edit_mesh(me, True)
bpy.ops.object.mode_set(mode='OBJECT')
# use obtained new verts and face to do full over-write
mesh = obj.data
mesh.from_pydata(verts, [], faces)
mesh.update()
bpy.ops.object.mode_set(mode='EDIT')
big_dufus_function()
@zeffii
Copy link
Author

zeffii commented Dec 28, 2015

img lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment