40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
|
|
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"}
|