11import os
22import copy
3+ import math
34
45import bpy
56
1213bl_info = {
1314 "name" : "Automated LOD Generation Tool" ,
1415 "author" : "Nico Breycha" ,
15- "version" : (0 , 0 , 2 ),
16+ "version" : (0 , 0 , 3 ),
1617 "blender" : (4 , 0 , 0 ),
1718 "location" : "View3D > Sidebar > Tool Tab" ,
1819 "description" : "Combines the Operator from all the other plugins." ,
@@ -39,6 +40,9 @@ def _select_all_except_original():
3940 import_fp_comb = context .scene .import_fp_comb
4041 export_fp_comb = context .scene .export_fp_comb
4142
43+ # Preprocessing
44+ rot_correction_comb = context .scene .rot_correction_comb
45+
4246 # Cleanup Properties
4347 initial_reduction_comb = context .scene .initial_reduction_comb
4448 loose_threshold_comb = context .scene .loose_threshold_comb
@@ -63,19 +67,19 @@ def _select_all_except_original():
6367
6468 restore_dict = {
6569 "initial_reduction" : context .scene .initial_reduction ,
66- "loose_threshold_comb " : context .scene .loose_threshold ,
70+ "loose_threshold " : context .scene .loose_threshold ,
6771 "boundary_length" : context .scene .boundary_length ,
6872 "merge_threshold" : context .scene .merge_threshold ,
6973 "number_of_modules" : context .scene .number_of_modules ,
7074 "lod_count" : context .scene .lod_count ,
7175 "reduction_percentage" : context .scene .reduction_percentage ,
72- "baker_settings_comb " : context .scene .baker_settings
76+ "baker_settings " : context .scene .baker_settings
7377 }
7478
7579 # Preserve the original values of the properties with shallow copy.
7680 restore_dict = copy .copy (restore_dict )
7781
78- # Override Operator Properties
82+ # Override Operator Properties for non-comb components
7983 context .scene .initial_reduction = initial_reduction_comb
8084 context .scene .loose_threshold = loose_threshold_comb
8185 context .scene .boundary_length = boundary_length_comb
@@ -102,6 +106,20 @@ def _select_all_except_original():
102106 bpy .context .view_layer .objects .active = obj
103107
104108 bpy .ops .object .join ()
109+ bpy .ops .object .transform_apply (location = True , rotation = True , scale = True )
110+
111+ # Apply rotation correction if needed
112+ obj = bpy .context .active_object
113+
114+ if rot_correction_comb [0 ] != 0 :
115+ obj .rotation_euler [0 ] = math .radians (rot_correction_comb [0 ])
116+ if rot_correction_comb [1 ] != 0 :
117+ obj .rotation_euler [1 ] = math .radians (rot_correction_comb [1 ])
118+ if rot_correction_comb [2 ] != 0 :
119+ obj .rotation_euler [2 ] = math .radians (rot_correction_comb [2 ])
120+
121+ bpy .ops .object .transform_apply (location = True , rotation = True , scale = True )
122+
105123
106124 # Rename the original mesh. We will use it later for baking.
107125 original_mesh = bpy .context .active_object
@@ -128,6 +146,7 @@ def _select_all_except_original():
128146 print ("Starting Slicing" )
129147 launch_operator_by_name (SLICE_IDNAME )
130148
149+
131150 # Ensure Target Polycount set by the user as intial polycount.
132151 parts = []
133152
@@ -177,18 +196,18 @@ def _select_all_except_original():
177196
178197 # Restore Operator Properties
179198 context .scene .initial_reduction = restore_dict ["initial_reduction" ]
180- context .scene .loose_threshold = restore_dict ["loose_threshold_comb " ]
199+ context .scene .loose_threshold = restore_dict ["loose_threshold " ]
181200 context .scene .boundary_length = restore_dict ["boundary_length" ]
182201 context .scene .merge_threshold = restore_dict ["merge_threshold" ]
183202 context .scene .number_of_modules = restore_dict ["number_of_modules" ]
184203 context .scene .lod_count = restore_dict ["lod_count" ]
185204 context .scene .reduction_percentage = restore_dict ["reduction_percentage" ]
186205
187- context .scene .baker_settings .highpoly_mesh_name = restore_dict ["baker_settings_comb " ].highpoly_mesh_name
188- context .scene .baker_settings .ray_distance = restore_dict ["baker_settings_comb " ].ray_distance
189- context .scene .baker_settings .texture_resolution = restore_dict ["baker_settings_comb " ].texture_resolution
190- context .scene .baker_settings .texture_margin = restore_dict ["baker_settings_comb " ].texture_margin
191- context .scene .baker_settings .save_path = restore_dict ["baker_settings_comb " ].save_path
206+ context .scene .baker_settings .highpoly_mesh_name = restore_dict ["baker_settings " ].highpoly_mesh_name
207+ context .scene .baker_settings .ray_distance = restore_dict ["baker_settings " ].ray_distance
208+ context .scene .baker_settings .texture_resolution = restore_dict ["baker_settings " ].texture_resolution
209+ context .scene .baker_settings .texture_margin = restore_dict ["baker_settings " ].texture_margin
210+ context .scene .baker_settings .save_path = restore_dict ["baker_settings " ].save_path
192211
193212 # Save .blend File
194213 bpy .ops .wm .save_as_mainfile (filepath = blend_file_path , check_existing = False , compress = True )
@@ -211,6 +230,7 @@ def draw(self, context):
211230
212231 io_box = layout .box ()
213232 io_box .prop (scene , "import_fp_comb" , text = "Import Filepath" )
233+ io_box .prop (scene , "rot_correction_comb" , text = "Rotation Correction" )
214234 io_box .prop (scene , "export_fp_comb" , text = "Export Filepath" )
215235
216236 # Create a box for Cleanup Properties and add labeled properties
@@ -257,6 +277,10 @@ def register():
257277 for cls in classes :
258278 register_class (cls )
259279
280+ # Preprocessing Properties
281+ bpy .types .Scene .rot_correction_comb = bpy .props .FloatVectorProperty (name = "Initial Rotation Correction" ,
282+ default = (0.0 , 0.0 , 0.0 ), subtype = "EULER" )
283+
260284 # Cleanup Properties
261285 bpy .types .Scene .initial_reduction_comb = bpy .props .IntProperty (name = "Initial Reduction" , default = 1000000 )
262286 bpy .types .Scene .loose_threshold_comb = bpy .props .IntProperty (name = "Loose Component Vertex Thr" , default = 1000 )
@@ -288,6 +312,7 @@ def unregister():
288312 unregister_class (cls )
289313
290314 # Cleanup Properties
315+ del bpy .types .Scene .rot_correction_comb
291316 del bpy .types .Scene .initial_reduction_comb
292317 del bpy .types .Scene .baker_settings_comb
293318 del bpy .types .Scene .loose_threshold_comb
0 commit comments