4
$\begingroup$

I have a mesh (just 1 face) that was created in another program that tries to optimise the mesh when exporting. I would like to subdivide it 1 x 1 square grid like pattern (which is basically how the program created it in the first place).

I tried subdivide, but that just adds more vertices to the edges.

Is there an easy / quick method instead of me cutting it up manually with the knife tool, as I will likely have more meshes like this to clean up and work with? enter image description here

File added (different mesh):

$\endgroup$
  • 3
    $\begingroup$ You could try the Remesh modifier. $\endgroup$ – Rich Sedman Sep 20 '16 at 11:18
  • $\begingroup$ Can you upload your file? There could be a way; i want to prove directly on your mesh $\endgroup$ – Fuboski Sep 20 '16 at 11:35
  • $\begingroup$ You can also try Grid Fill. Tab into Edit Mode, key A once or twice until everything is selected, key X to open the Delete menu, and select Only Faces. Key Space to open the search menu, type Grid Fill, then key Enter. $\endgroup$ – Shady Puck Sep 20 '16 at 11:52
  • $\begingroup$ Of course the subdivision didn't work. It only works on Tris and Quads. $\endgroup$ – Hendriks3D Sep 20 '16 at 16:32
  • $\begingroup$ @RichSedman I tried that, but the mesh vanished, I played with the settings but couldn't get it to show. $\endgroup$ – JacketPotatoeFan Sep 20 '16 at 17:01
5
$\begingroup$

Step 1: Creating a large mesh of 1x1 squares

There are several ways to accomplish step 1, here's one possibility: Create a new 1x1 square as a new object. Use the "Array" modifier to make a row of 1x1 squares, wider than your target object. Apply that modifier, then use a new "Array" modifier (set to Z offset instead of X) to make multiple rows, taller than the target object. Apply this modifier as well, and "Merge Doubles" on the resulting mesh of 1x1 squares.

You should end up with a mesh of connected 1x1 squares, that extends larger in all directions from the target object that you hope to cut.

Step 2. Use Knife Project

With your large mesh selected in Object Mode, shift-right-click on the original target object, to multi-select that. The target should be "active" selected object, with the new mesh a reddish-orange multi-selected color. Enter "Edit mode" on the target, with all vertices selected. Set your view to look along the axis perpendicular to the meshes (typically, numberpad 7, 1, or 3).

Finally, click the Knife Project button in the left margin. This should cut a batch of 1x1 squares into your target mesh.

$\endgroup$
5
$\begingroup$

I used the Sverchok add-on (visual coding for geometry)

enter image description here

the node setup

enter image description here

This generates:

  • A temporary plane that is subdivided n*n to match the given object's boundaries. (this you must tweak manually in this setup, but it could be done automatically)
  • For each polygon on the new subdivided plane it generates a point at the center of that polygon, and an identical point but with a z-offset. These pairs will form the start and end of a ray.
  • then it raycasts each point and generates a list mask (True, or False) of which rays hit something in the scene.
  • This mask list is used to discard those polygons in the subdivided plane that were not struck by the raycast

here's the gist that can be imported into sverchok from the sv import panel

https://gist.github.com/eea1bc4a29f6c983b408593fce44da74

Slightly more automated

Similar to the above setup, but finds the bounding box and uses the XY offset to place the start of the subdivided Plane automatically. All you need to do is adjust the number of sections X,Y in the Plane generator (but that could be automated too)

enter image description here

https://gist.github.com/d0e256b7b477f1641a50f13585f39d93

you'll have to press 'Get Selection' in the Objects-in node

$\endgroup$
1
$\begingroup$

Particle System

  • create a Plane with radius 0.5
  • add a particle system to your Ngon
  • set the grid resolution to number of divisions on the longest dimension
  • set the Dupli Object on the Ngon particle system to the Plane
  • ctrl + shift + a to make duplicates real
  • in Object Mode on the Ngon, press Make Local -> Selected Objects and Data

but who wants to manually do all that nonsense.. here's a script. It assumes a few things.

  • the plane is on XY
  • 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 = int(max(original_obj.dimensions[:2]))
quantize(original_obj, numdiv_shortest_side)

craziest script i've ever written I think..

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.