Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Last active March 1, 2023 20:26
Show Gist options
  • Save SuddenDevelopment/acccd4dfe0d401b007a7df4aa410db81 to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/acccd4dfe0d401b007a7df4aa410db81 to your computer and use it in GitHub Desktop.
knifecut a grid of squares into a belnder object with bisect plane
import bpy
import bmesh
import math
def diceObj(obj, intSize = 0.5):
arrDimensions = obj.dimensions
# add one for both ends of a row because we want to start from the center
intRowsX = math.floor((arrDimensions[0]/intSize) + 1)
intRowsY = math.floor((arrDimensions[1]/intSize) + 1)
bm = bmesh.new()
bm.from_mesh(obj.data)
# hold allt he planes to bisect with as (location), (normal)
arrPlanes=[]
for i in range(intRowsX):
intLocation = intSize*i
arrNormal = (1,0,0)
arrPlaneLocation = (intLocation,0,0)
arrPlanes.append([arrPlaneLocation, arrNormal])
arrPlaneLocation = (-intLocation,0,0)
arrPlanes.append([arrPlaneLocation, arrNormal])
for i in range(intRowsY):
intLocation = intSize*i
arrNormal = (0,1,0)
arrPlaneLocation = (0,intLocation,0)
arrPlanes.append([arrPlaneLocation, arrNormal])
arrPlaneLocation = (0,-intLocation,0)
arrPlanes.append([arrPlaneLocation, arrNormal])
print(arrPlanes)
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)
bm.to_mesh(obj.data)
obj.data.update()
bm.free()
obj = bpy.context.active_object
diceObj(obj,0.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment