Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created March 31, 2023 19:50
Show Gist options
  • Save SuddenDevelopment/d9e6e246ac91e9a2c36a63fb7aecb287 to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/d9e6e246ac91e9a2c36a63fb7aecb287 to your computer and use it in GitHub Desktop.
dice a blender object by its vertices
def diceObj(obj):
bm = getBMesh(obj)
# add one for both ends of a row because we want to start from the center
# hold all the planes to bisect with as (location), (normal)
arrPlanes = []
# get each X and Y from
# get verts by faces so we have a normal
for face in bm.faces:
for v in face.verts:
arrPlanes.append(
[v.co, face.normal + mathutils.Vector((1, 0, 0))])
arrPlanes.append(
[v.co, face.normal + mathutils.Vector((0, 1, 0))])
arrPlanes.append(
[v.co, face.normal + mathutils.Vector((0, 0, 1))])
for plane in arrPlanes:
geo = list(bm.verts) + list(bm.edges) + list(bm.faces)
bmesh.ops.bisect_plane(
bm,
geom=geo,
dist=0,
plane_co=plane[0],
plane_no=plane[1],
clear_inner=False,
clear_outer=False)
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
obj.data.update()
setBMesh(obj, bm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment