This is my first post on the Blender StackExchange, so I hope that it's well received :)

Essentially, I'm making a 3D game in Godot, and for that I need to divide my terrain up into chunks. I've already found and got working a fantastic piece of code from this thread which successfully divides the terrain up into different objects within the same scene based on a grid.

However, to really get an efficient workflow going, I now need to find a way to export each one of those separated objects as its own .obj file - as manually doing it all by hand is excruciating. Is there anybody familiar with scripting who would feel charitable enough to modify this existing code from that thread:

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:
    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() 
        p0 = planes.pop(0)                 
        ret = bmesh.ops.bisect_plane(bm, 
                edges=[e for e in ret['geom_cut'] 
                if isinstance(e, bmesh.types.BMEdge)])

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

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)    


Basically having that modified so it can also export each of those chunks as its own .obj file into a given directory, after splitting the terrain up. Is that possible, and is there anybody who would be willing to help out? I have no experience with python (even though Godots scripting language is quite python like...) so I don't really know where to start doing it by myself!

Thanks for reading.

~ Skelly <3

  • $\begingroup$ Hi, regarding the actual splitting, I needed similar thing, check this question & answer: blender.stackexchange.com/questions/145176/… $\endgroup$ Commented Sep 14, 2022 at 19:58
  • $\begingroup$ Hi, thanks for your reply - but getting the terrain sliced up into chunks is actually working fine with the existing script I've got. What I really need now is a way to save those resulting chunks as objs without needing to do it all manually - Id even be okay kicking someone 20 bucks or so to write the code if needs be, its just that its waaayy out of my field, haha. But thank you for your reply :) $\endgroup$
    – SkellySoft
    Commented Sep 15, 2022 at 5:45


You must log in to answer this question.

Browse other questions tagged .