[Script] Chunked terrain LODs generator

This script would generate seamless LODs for your chunked terrain.

http://www.pasteall.org/70816/python


# Chunked terrain LODs generator
# Author - motorsep
# ver 1.0
# Blender 2.77
# June 18th 2016


import bpy
import random


object = bpy.context.active_object
mesh = object.data


ratio = 0.5
vert_group = "Group"
apply_mod = 0 ### To apply Decimate modifier or not (1 - apply; 0 - leave it in the modifiers stack)


for object in bpy.context.selected_objects:
    if object.type == 'MESH':
       bpy.context.scene.objects.active = object
       object.select = True
       bpy.ops.object.mode_set( mode = 'EDIT' )
       bpy.ops.mesh.select_mode( type = 'VERT' )
       bpy.ops.mesh.select_all( action = 'DESELECT' )
       bpy.ops.mesh.select_non_manifold()
       bpy.ops.mesh.select_all( action = 'INVERT' )
       
       if bpy.context.scene.objects.active.vertex_groups.active:
             bpy.ops.object.vertex_group_remove( all=True )


       bpy.ops.object.vertex_group_add()
       bpy.ops.object.vertex_group_assign()
       bpy.ops.object.mode_set( mode = 'OBJECT' )


       if bpy.context.scene.objects.active.modifiers.find('Decimate') == 1:
             bpy.ops.object.modifier_remove( modifier='Decimate' )       
       
       modi = object.modifiers.new("Decimate", "DECIMATE")
       modi.ratio = ratio
       modi.vertex_group = vert_group
       
       if apply_mod:
             bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Decimate")

Copy your original terrain chunks into another layer, select them, open the script in the Text Editor and run it (don’t forger to edit ratio and whether to apply modifier or not).

Feel free to improve it and maybe add UI with ratio value, one button to generate LOD and separate button to apply modifier :eyebrowlift: