Last active
December 28, 2015 18:53
-
-
Save zeffii/cad08a04c491bfcbbe1e to your computer and use it in GitHub Desktop.
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
# 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() |
Author
zeffii
commented
Dec 28, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment