I'm just getting into scripting in blender, and I'm trying to write a script that will split a terrain mesh into equal chunks. This is what I have so far
import bpy terrain = bpy.context.active_object chunk_size = 31 #deselect all faces bpy.ops.object.editmode_toggle() bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.editmode_toggle() #main loop for i in range(16): #select chunk_base obj = bpy.context.active_object obj.data.polygons.select = True #enter_edit_mode bpy.ops.object.editmode_toggle() #select_chunk for i in range(chunk_size): bpy.ops.mesh.select_more() #separate chunk bpy.ops.mesh.separate(type='SELECTED') #exit_editmode bpy.ops.object.editmode_toggle()
And it does split the mesh into chunks of equal sizes, however, if I were to apply this to a larger, or higher resolution mesh, it would still create only 16 chunks, due to the range in the for loop. I need to find a way to automatically set the number of iterations of the loop, based on the number of vertices in the mesh.
I've thought of using the dimensions of the mesh, however this wouldn't account for the resolution of the mesh.
Any suggestions would be helpful. thank you.