# VibeStack Weekly (https://vibestackweekly.com) | Blender LOD maker for AI 3D models (make_lods.py) # From https://vibestackweekly.com/ai-retopology-low-poly-game-ready-3d-models/#lod-script # MIT License. Copyright (c) 2026 VibeStack Weekly. # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or # substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """make_lods.py - decimate an AI-generated 3D model to triangle budgets and export LOD levels named _LOD0, _LOD1, ... (the suffix Unity's LOD Group import uses). Run with Blender (tested with 5.2.3 LTS), no add-ons needed: blender -b -P make_lods.py -- model.glb model_lods.fbx 15000 5000 1500 or with the bpy module from PyPI: python make_lods.py model.glb model_lods.fbx 15000 5000 1500 Each number is a triangle budget for one LOD level, most detailed first. Give a single budget (e.g. 15000) to just shrink the model to one game-ready mesh. Input: .glb/.gltf/.fbx/.obj. Output: .fbx or .glb. Static meshes only: rigged (skinned) meshes are refused, because decimating them needs care. https://vibestackweekly.com/ai-retopology-low-poly-game-ready-3d-models/ """ import sys, os import bpy argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else sys.argv[1:] if len(argv) < 3: sys.exit("usage: make_lods.py INPUT OUTPUT BUDGET [BUDGET ...]") src, dst, budgets = argv[0], argv[1], [int(b) for b in argv[2:]] def tris(obj): return sum(len(p.vertices) - 2 for p in obj.data.polygons) bpy.ops.wm.read_factory_settings(use_empty=True) ext = os.path.splitext(src)[1].lower() if ext in (".glb", ".gltf"): bpy.ops.import_scene.gltf(filepath=src) elif ext == ".fbx": bpy.ops.import_scene.fbx(filepath=src) elif ext == ".obj": bpy.ops.wm.obj_import(filepath=src) else: sys.exit("unsupported input: " + ext) meshes = [o for o in bpy.context.scene.objects if o.type == "MESH"] if not meshes: sys.exit("no meshes found") if any(m.type == "ARMATURE" for o in meshes for m in o.modifiers) or \ any(o.type == "ARMATURE" for o in bpy.context.scene.objects): sys.exit("rigged model found: this script is for static meshes") # Bake each object's transform into a world-space copy so LODs line up. total = sum(tris(o) for o in meshes) print(f"input: {len(meshes)} mesh(es), {total} triangles") deps = bpy.context.evaluated_depsgraph_get() lods = [] for i, budget in enumerate(budgets): ratio = min(1.0, budget / total) level = 0 # triangles in this LOD level for o in meshes: mod = o.modifiers.new("LODDecimate", "DECIMATE") mod.decimate_type = "COLLAPSE" mod.ratio = ratio mod.use_collapse_triangulate = True deps.update() me = bpy.data.meshes.new_from_object(o.evaluated_get(deps)) o.modifiers.remove(mod) me.transform(o.matrix_world) base = o.name if len(meshes) > 1 else os.path.splitext(os.path.basename(src))[0] lod = bpy.data.objects.new(f"{base}_LOD{i}", me) bpy.context.scene.collection.objects.link(lod) lods.append(lod) level += tris(lod) print(f"LOD{i}: budget {budget}, got {level} triangles (ratio {ratio:.3f})") for o in list(bpy.context.scene.objects): o.select_set(o in lods) out = os.path.splitext(dst)[1].lower() if out == ".fbx": bpy.ops.export_scene.fbx(filepath=dst, use_selection=True, path_mode="COPY", embed_textures=True) elif out == ".glb": bpy.ops.export_scene.gltf(filepath=dst, export_format="GLB", use_selection=True) else: sys.exit("unsupported output: " + out) print("wrote", dst)