![]()
This Project was my first dive into creating a extension for blender. Wanted to showcase a understanding of how to set up a extension in blender and make my work easy to use for other artists.
I might extend or rewrite a version of this at some point that works inside geometry nodes. Using a function like this with a PCG system is where a Lots subdivision really shines.
#Function that recusively splits faces based on specific parameters
def _SplitFace(bm, face, minimum_area = 1.0, max_iterations = 1, irregularity = 0.0, side_favor = False, cur_iteration = 0):
if len(face.edges) != 4:
raise Exception("Encountered a face that is not a quad!")
elif cur_iteration >= max_iterations:
return [face]#breaks the recusion if too many iterations have been done
elif face.calc_area() <= minimum_area:
return [face] #return final face eventually to reselect everything
# Temporarily duplicates the face and deletes the original
result = bmesh.ops.duplicate(bm, geom=[face])
bmesh.ops.delete(bm, geom=[face], context='FACES')
face = [geom for geom in result['geom'] if isinstance(geom, bmesh.types.BMFace)][0]
# selects the side of the face to split
faceEdges = LotSubdivision._FindLongestEdge([face.edges[1], face.edges[3]] , [face.edges[0], face.edges[2]])
# Subdivide the edges of the selected faces
result = bmesh.ops.subdivide_edges(bm, edges=faceEdges, cuts=1, use_grid_fill=True)
newEdges = [geom for geom in result['geom_inner'] if isinstance(geom, bmesh.types.BMEdge)]
newFaces = [face for face in newEdges[0].link_faces if isinstance(face, bmesh.types.BMFace)]
#Slides the edges based on the random seed and the irregularity
newEdges[0].select = True
distance = clip(irregularity, 0.0, .970)
bpy.ops.transform.edge_slide(value = random.randint(-1, 1) * distance)
newEdges[0].select = False
#splitResultingFaces
outFaces = []
oFacesl = LotSubdivision._SplitFace(bm, newFaces[1], minimum_area, max_iterations, irregularity, not side_favor, cur_iteration + 1)
oFaces2 = LotSubdivision._SplitFace(bm, newFaces[0], minimum_area, max_iterations, irregularity, not side_favor, cur_iteration + 1)
outFaces.extend(oFacesl)
outFaces.extend(oFaces2)
return outFaces
The main function takes a face and splits