Files
1960-utils/Blender/_Source/L1960_Tools_1_5_0/PrepareLods.py
2024-03-24 20:20:59 +01:00

40 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import bpy
class MESH_OT_prepare_lods_decimate(bpy.types.Operator):
"""Copy current Mesh and apply decimate Modifier"""
bl_idname = "mesh.prepare_lods_decimate"
bl_label = "Copy current Mesh and apply decimate Modifier"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
#Selected Mesh
obj = bpy.context.active_object
if obj not in bpy.context.selected_objects or obj.type != "MESH":
self.report({'WARNING'}, 'Select a Mesh to continue')
return {"CANCELLED"}
if not obj.name[:-1].endswith('LOD'):
obj.name = obj.name + '_LOD0'
LODnumber = context.scene.lod_slider #Get from Slider
startLODcount = int(obj.name[-1])
endLODcount = startLODcount + LODnumber
for i in range (startLODcount + 1, endLODcount):
new_obj = obj.copy()
new_obj.data = obj.data.copy()
new_obj.name = obj.name[:-1] + str(i)
bpy.context.collection.objects.link(new_obj)
for t in range (startLODcount, i):
newModifierName = 'LOD_Decimate_' + str(t)
new_obj.modifiers.new(type='DECIMATE', name=newModifierName)
mod = new_obj.modifiers[newModifierName]
mod.ratio = 0.49
mod.use_collapse_triangulate = True
self.report({'INFO'}, 'LOD´s created')
return {"FINISHED"}