- create a Plane with radius 0.5
- add a particle system to your Ngon
- set the grid resolution to (number of divisions on the shortest dimension) + 1
- set the Dupli Object on the Ngon particle system to the Plane
- in Object Mode on the Ngon, press Make Local -> Selected Objects and Data
- ctrl+shift+a to make duplicates real
but who wants to manually do all that nonsense.. here's a script. It assumes a few things.
- the geometry is nicely constructed by 1 x 1 elements
- there is no other object in the scene other than the Ngon. (not even hidden stuff)
here:
import bpy
def quantize(original_obj, numdiv_shortest_side):
bpy.ops.object.visual_transform_apply()
# make a plane
bpy.ops.mesh.primitive_plane_add(radius=0.5)
plane = bpy.context.active_object
plane.select = False
# add particle system to original object
ps = original_obj.modifiers.new("grid particles", type='PARTICLE_SYSTEM')
psettings = ps.particle_system.settings
# particle settings
psettings.distribution = 'GRID'
psettings.emit_from = 'FACE'
psettings.physics_type = 'NO'
psettings.grid_resolution = numdiv_shortest_side
psettings.use_render_emitter = True
psettings.show_unborn = True
psettings.use_scale_dupli = True
psettings.particle_size = 1.0
psettings.render_type = 'OBJECT'
psettings.dupli_object = plane
original_obj.select = True
bpy.context.scene.objects.active = original_obj
bpy.ops.object.duplicates_make_real()
original_obj.select = False
bpy.ops.object.make_local(type='SELECT_OBDATA')
# find first of the new objects, to join the rest onto
joiner = None
for obj in bpy.data.objects:
if not obj in {plane, original_obj}:
joiner = obj
break
bpy.context.scene.objects.active = joiner
bpy.ops.object.join()
# deselect everything
bpy.ops.object.select_all(action='DESELECT')
bpy.context.scene.objects.active = None
plane.select = True
original_obj.select = True
bpy.ops.object.delete()
# enter the remaining object and remove doubles
bpy.context.scene.objects.active = joiner
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.remove_doubles(threshold=0.0001)
bpy.ops.object.mode_set(mode='OBJECT')
original_obj = bpy.context.active_object
numdiv_shortest_side = 21 # int(min(original_obj.dimensions)) + 1
quantize(original_obj, numdiv_shortest_side)
craziest script i've ever written I think..