Trunk LOD batch generator script

Can anyone confirm the possibility of creating a script that can batch generate LOD for multiple objects? Is this something Python can do, or would it have to be done on the C++ level? I have over 20000 objects to apply LOD to and I really don’t want to do them 1 at a time.

You ca do it using a script with some BPY functions. Example:

With this script you can divide a mesh in tiles, the script are from the user @CoDEmanX

import bpy, bmeshfrom bpy import context as C
bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(C.object.data)
edges = []
for i in range(-10, 10, 2):
        ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(i,0,0), plane_no=(-1,0,0))
        bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])

for i in range(-10, 10, 2):
        ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(0,i,0), plane_no=(0,1,0))
        bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])
                
bmesh.update_edit_mesh(C.object.data)

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

So, modifying it is possible add more features, for example generate 2 mesh for each new tile and add a decimate modifier to each one.

This is great, but not what I was looking for. I was hoping there is a way to access the trunk LOD’s generate function via Python to quickly apply LOD to multiple objects. I can see that this does this, but I would sill have to manually designate the generated meshes for each LOD. Unless I am missing something, it would probably be faster to generate individually.

So, apply the lod it in realtime?

It’s all possible via Python, so take a look at how the generate lod is called (it’s an operator).

Thanks agoose77, do you happen to have a link to the API? I can’t find it in the 2.6 manual.

I don’t need it for real time, just to access it while developing via the text editor.

If you use this link:
http://www.blender.org/documentation/250PythonDoc/contents.html

For the API, you’ll find it goes to the most recent one.

And then you’ll find things like this function:
http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.ops.object.html?highlight=lod#bpy.ops.object.lod_generate

Bear in mind that to apply that command you have to be operating on an object. My BPY is a little too rust to be able to help you with that.

Thanks Geoff, I took a look and it is pretty straight forward. I am working off of this script;


import bpy

for ob in bpy.context.selected_objects:
    if ob.type == 'MESH' and bpy.ops.object.mode_set.poll():

        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        bpy.context.scene.objects.active = ob        
        me = ob.data
        bm = bmesh.from_edit_mesh(me)        
        terrainlod = bm.terrainlod[:]
        
        while terrainlod:
        bpy.ops.object.lod_generate(<i>count=2</i>, <i>target=0.25</i>, <i>package=True</i>)
#This doesn't generate the LOD and I don't know how to set the distance with bpy.data.objects[]LodLevel.distance

         

Still doing something wrong here.