Join Meshes Improvements, better error handling
This commit is contained in:
+40
-14
@@ -18,32 +18,46 @@ class JoinAllMeshes(Operator):
|
|||||||
return armature is not None and is_valid_armature(armature)
|
return armature is not None and is_valid_armature(armature)
|
||||||
|
|
||||||
def execute(self, context: Context) -> Set[str]:
|
def execute(self, context: Context) -> Set[str]:
|
||||||
self.join_all_meshes(context)
|
try:
|
||||||
return {'FINISHED'}
|
self.join_all_meshes(context)
|
||||||
|
return {'FINISHED'}
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"{t('Optimization.join_error')}: {str(e)}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
def join_all_meshes(self, context: Context) -> None:
|
def join_all_meshes(self, context: Context) -> None:
|
||||||
if not select_current_armature(context):
|
if not select_current_armature(context):
|
||||||
self.report({'WARNING'}, t("Optimization.no_armature_selected"))
|
raise ValueError(t("Optimization.no_armature_selected"))
|
||||||
return
|
|
||||||
|
|
||||||
armature = get_selected_armature(context)
|
armature = get_selected_armature(context)
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
|
||||||
meshes: List[Object] = get_all_meshes(context)
|
meshes: List[Object] = get_all_meshes(context)
|
||||||
|
if not meshes:
|
||||||
|
raise ValueError(t("Optimization.no_meshes_found"))
|
||||||
|
|
||||||
for mesh in meshes:
|
for mesh in meshes:
|
||||||
mesh.select_set(True)
|
mesh.select_set(True)
|
||||||
|
|
||||||
if bpy.context.selected_objects:
|
if bpy.context.selected_objects:
|
||||||
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
|
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
|
||||||
bpy.ops.object.join()
|
try:
|
||||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
bpy.ops.object.join()
|
||||||
|
except RuntimeError as e:
|
||||||
|
raise RuntimeError(f"{t('Optimization.join_operation_failed')}: {str(e)}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||||
|
except RuntimeError as e:
|
||||||
|
raise RuntimeError(f"{t('Optimization.transform_apply_failed')}: {str(e)}")
|
||||||
|
|
||||||
fix_uv_coordinates(context)
|
fix_uv_coordinates(context)
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
self.report({'INFO'}, t("Optimization.meshes_joined"))
|
self.report({'INFO'}, t("Optimization.meshes_joined"))
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, t("Optimization.no_mesh_selected"))
|
raise ValueError(t("Optimization.no_mesh_selected"))
|
||||||
|
|
||||||
context.view_layer.objects.active = armature
|
context.view_layer.objects.active = armature
|
||||||
|
|
||||||
@@ -59,15 +73,18 @@ class JoinSelectedMeshes(Operator):
|
|||||||
return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1
|
return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1
|
||||||
|
|
||||||
def execute(self, context: Context) -> Set[str]:
|
def execute(self, context: Context) -> Set[str]:
|
||||||
self.join_selected_meshes(context)
|
try:
|
||||||
return {'FINISHED'}
|
self.join_selected_meshes(context)
|
||||||
|
return {'FINISHED'}
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"{t('Optimization.join_error')}: {str(e)}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
def join_selected_meshes(self, context: Context) -> None:
|
def join_selected_meshes(self, context: Context) -> None:
|
||||||
selected_objects: List[Object] = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
|
selected_objects: List[Object] = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
|
||||||
|
|
||||||
if len(selected_objects) < 2:
|
if len(selected_objects) < 2:
|
||||||
self.report({'WARNING'}, t("Optimization.select_at_least_two_meshes"))
|
raise ValueError(t("Optimization.select_at_least_two_meshes"))
|
||||||
return
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
@@ -77,11 +94,20 @@ class JoinSelectedMeshes(Operator):
|
|||||||
|
|
||||||
if bpy.context.selected_objects:
|
if bpy.context.selected_objects:
|
||||||
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
|
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
|
||||||
bpy.ops.object.join()
|
try:
|
||||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
bpy.ops.object.join()
|
||||||
|
except RuntimeError as e:
|
||||||
|
raise RuntimeError(f"{t('Optimization.join_operation_failed')}: {str(e)}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||||
|
except RuntimeError as e:
|
||||||
|
raise RuntimeError(f"{t('Optimization.transform_apply_failed')}: {str(e)}")
|
||||||
|
|
||||||
fix_uv_coordinates(context)
|
fix_uv_coordinates(context)
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
self.report({'INFO'}, t("Optimization.selected_meshes_joined"))
|
self.report({'INFO'}, t("Optimization.selected_meshes_joined"))
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, t("Optimization.no_mesh_selected"))
|
raise ValueError(t("Optimization.no_mesh_selected"))
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,9 @@
|
|||||||
"Optimization.remove_doubles_completed": "Remove doubles operation completed",
|
"Optimization.remove_doubles_completed": "Remove doubles operation completed",
|
||||||
"Optimization.select_armature": "Please select an armature",
|
"Optimization.select_armature": "Please select an armature",
|
||||||
"Optimization.material_attribute_mismatch": "Attribute mismatch in material {material_name}, skipping",
|
"Optimization.material_attribute_mismatch": "Attribute mismatch in material {material_name}, skipping",
|
||||||
|
"Optimization.join_error": "Error during mesh joining",
|
||||||
|
"Optimization.join_operation_failed": "Join operation failed",
|
||||||
|
"Optimization.transform_apply_failed": "Transform apply failed",
|
||||||
"Tools.select_armature": "Please select an armature",
|
"Tools.select_armature": "Please select an armature",
|
||||||
"Tools.label": "Tools",
|
"Tools.label": "Tools",
|
||||||
"Tools.tools_title.label": "Tools:",
|
"Tools.tools_title.label": "Tools:",
|
||||||
|
|||||||
Reference in New Issue
Block a user