3
$\begingroup$

I have terrain (ANT Landscape plugin) that I would like to cut up into chunks (don't need to be equal size) for a game engine so that I can do occlusion culling / or load and unload chunks around the player.

I am trying the knife project feature that I saw in the answer here but it doesn't work for my terrain mesh (using the terrain plugin).

I also tried some answers here that contain some Python scripts, but couldn't get them to work.

Any ideas of how I can cut the mesh up quickly in to chunks. I've been doing it manually so far, but it takes forever to do as some terrains can be rather big. I don't mind having to do a little clean up of the mesh after.

Picture below shows the knife project method (following instructions from linked answer).

enter image description here

enter image description here

Thanks

Edit:

Example of mesh (terrain is usually much large than this) that I am trying to break into chunks.

enter image description here

How I am manually doing it.

enter image description here

Blend file that contains terrain and grid for the knife projecting method.

$\endgroup$
  • $\begingroup$ A blend file sample, or at least an image, of your mesh that produced that "result", would be helpful. Also if you are doing something manually, explaining that will be useful to a scripter to answer this q. $\endgroup$ – batFINGER May 30 '17 at 13:14
  • $\begingroup$ @batFINGER Oops, you are right, I was meant to include other images but forgot. Thanks. Also added the Blend file that I was using for testing. $\endgroup$ – JacketPotatoeFan May 30 '17 at 13:57
  • $\begingroup$ Maybe it could be useful to know the reason of cutting meshes in chunks.. Keep in mind that meshes for the games need to have as small amount of geometry as possible. By cutting it either with Boolean or with Knife Project or with Bisect you'll create additional geometry. $\endgroup$ – Mr Zak May 30 '17 at 15:52
  • $\begingroup$ @MrZak I did mention in my message that it is terrain that will be used in a game engine. I've added a tiny bit more detail if it makes it more clear. I don't mind doing a little clean up if it speeds up the overall process. $\endgroup$ – JacketPotatoeFan May 30 '17 at 20:23
3
$\begingroup$

Script Version.

enter image description here Displaced dense grid mesh split 2 in x, 2 in y.

Since the map is one continuous mesh and you wish to split into a grid, have used a modified version of @Codemanx's answer

Splits the mesh into chunks, locally using bounding box.

Run script in object mode.

Edit x_segments, y_segments, z_segments to suit.

import bpy, bmesh
from bpy import context
from  mathutils import Vector
# bounding box helper methods
def bbox(ob):
    return (Vector(b) for b in ob.bound_box)

def bbox_center(ob):
    return sum(bbox(ob), Vector()) / 8

def bbox_axes(ob):
    bb = list(bbox(ob))
    return tuple(bb[i] for i in (0, 4, 3, 1))

def slice(bm, start, end, segments):
    if segments == 1:
        return
    def geom(bm):
        return bm.verts[:] + bm.edges[:] + bm.faces[:]
    planes = [start.lerp(end, f / segments) for f in range(1, segments)]
    #p0 = start
    plane_no = (end - start).normalized() 
    while(planes): 
        p0 = planes.pop(0)                 
        ret = bmesh.ops.bisect_plane(bm, 
                geom=geom(bm),
                plane_co=p0, 
                plane_no=plane_no)
        bmesh.ops.split_edges(bm, 
                edges=[e for e in ret['geom_cut'] 
                if isinstance(e, bmesh.types.BMEdge)])


bm = bmesh.new()
ob = context.object
me = ob.data
bm.from_mesh(me)

o, x, y, z = bbox_axes(ob)        

x_segments = 2
y_segments = 2
z_segments = 1

slice(bm, o, x, x_segments)
slice(bm, o, y, y_segments)
slice(bm, o, z, z_segments)    
bm.to_mesh(me)

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.separate(type='LOOSE')
bpy.ops.object.mode_set() 

See this answer re boolean chopping https://blender.stackexchange.com/a/133136/15543 Note: May not work correctly if modifiers are on object being sliced

$\endgroup$
  • $\begingroup$ Downloaded 2.8 and gave it a test. Works perfectly. $\endgroup$ – JacketPotatoeFan Mar 1 at 19:25
  • 1
    $\begingroup$ Cheers,(long time since I commented and upvoted question lol) Whooops On a re-look have a feeling this one will also work in 2.7x too, whereas the other 2 variants I am testing (that actually use mw) wont.. including the boolean version linked which is giving grief if there are already modifiers in the stack. (eg the landscape in answer is simply a texture displacement modifier.) $\endgroup$ – batFINGER Mar 1 at 19:51
1
$\begingroup$

if you need to have distinct chunks for your map you can either generate the geometry with a dispace or scupting or a combination of different methods.

To generate a map, you want to add a Plane and apply two Array modifiers ; one to extend on X, the other on Y. This way you have an iterative object, so you can add some other modifiers on top (bellow in the menu) like a Displace !You need to set the 'Texture coordinate' field to Global. If you use subsurface use simple subdivision and watch their stacking order.

You can apply the modifiers, you'll notice that the new mesh is not merged, go on and customize here if needed but dont give it to much details for now. The very small objects should be added via seamless textures and different stencil must be used at different point on the texture stack to fake the ground.

This is a ground with a cloud texture into the displace. enter image description here

Then just get to Object mode and hit P->'by-loose-parts', it will split the selected object into several objects, every part is being removed from the old object.mesh and added to a new object.

enter image description here

(I had to redo the scene so the two grounds are differents but the procedure is the same)

$\endgroup$
  • $\begingroup$ Terrain is created using the ANT Landscape plugin. I do some tweaks to the mesh then I need to cut that up into chunks. $\endgroup$ – JacketPotatoeFan May 30 '17 at 22:11

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.