This commit is contained in:
Yusarina
2024-07-24 00:52:04 +01:00
parent 76046f7c6d
commit a8d7cd3032
3 changed files with 14 additions and 14 deletions
+7 -8
View File
@@ -2,7 +2,7 @@ import bpy
import numpy as np
from .dictionaries import bone_names
from typing import List, Optional
from typing import List, Optional, Tuple
from bpy.types import Object, ShapeKey, Mesh, Context
from functools import lru_cache
@@ -42,10 +42,10 @@ def has_shapekeys(mesh_obj: Object) -> bool:
def _get_shape_key_co(shape_key: ShapeKey) -> np.ndarray:
return np.array([v.co for v in shape_key.data])
def simplify_bonename(n):
def simplify_bonename(n: str) -> str:
return n.lower().translate(dict.fromkeys(map(ord, u" _.")))
def get_armature(context, armature_name=None) -> Optional[Object]:
def get_armature(context: Context, armature_name: Optional[str] = None) -> Optional[Object]:
if armature_name:
obj = bpy.data.objects[armature_name]
if obj.type == "ARMATURE":
@@ -58,17 +58,17 @@ def get_armature(context, armature_name=None) -> Optional[Object]:
return obj
return next((obj for obj in context.view_layer.objects if obj.type == 'ARMATURE'), None)
def get_armatures(self, context):
def get_armatures(self, context: Context) -> List[Tuple[str, str, str]]:
return [(obj.name, obj.name, "") for obj in bpy.data.objects if obj.type == 'ARMATURE']
def get_selected_armature(context):
def get_selected_armature(context: Context) -> Optional[Object]:
if context.scene.selected_armature:
armature = bpy.data.objects.get(context.scene.selected_armature)
if is_valid_armature(armature):
return armature
return None
def set_selected_armature(context, armature):
def set_selected_armature(context: Context, armature: Optional[Object]) -> None:
context.scene.selected_armature = armature.name if armature else ""
def is_valid_armature(armature: Object) -> bool:
@@ -78,7 +78,7 @@ def is_valid_armature(armature: Object) -> bool:
return False
return True
def select_current_armature(context):
def select_current_armature(context: Context) -> bool:
armature = get_selected_armature(context)
if armature:
bpy.ops.object.select_all(action='DESELECT')
@@ -92,4 +92,3 @@ def get_all_meshes(context: Context) -> List[Object]:
if armature and is_valid_armature(armature):
return [obj for obj in bpy.data.objects if obj.type == 'MESH' and obj.parent == armature]
return []
+3 -3
View File
@@ -1,6 +1,6 @@
import bpy
import re
from typing import List, Tuple, Optional
from typing import List, Tuple, Optional, Set
from bpy.types import Material, Operator, Context, Object
from ..core.common import clean_material_names, get_selected_armature, is_valid_armature, get_all_meshes
from ..core.register import register_wrap
@@ -68,7 +68,7 @@ class CombineMaterials(Operator):
armature = get_selected_armature(context)
return armature is not None and is_valid_armature(armature)
def execute(self, context: Context) -> set:
def execute(self, context: Context) -> Set[str]:
armature = get_selected_armature(context)
if not armature:
self.report({'WARNING'}, "No armature selected")
@@ -90,7 +90,7 @@ class CombineMaterials(Operator):
return {'FINISHED'}
def consolidate_materials(self, meshes: List[Object]) -> None:
mat_mapping: dict = {}
mat_mapping: Dict[str, Material] = {}
num_combined: int = 0
for mesh in meshes:
for slot in mesh.material_slots:
+4 -3
View File
@@ -1,5 +1,5 @@
import bpy
from typing import List, Optional
from typing import List, Optional, Set
from bpy.types import Operator, Context, Object
from ..core.register import register_wrap
from ..core.common import fix_uv_coordinates, get_selected_armature, is_valid_armature, select_current_armature, get_all_meshes
@@ -17,7 +17,7 @@ class JoinAllMeshes(Operator):
armature = get_selected_armature(context)
return armature is not None and is_valid_armature(armature)
def execute(self, context: Context) -> set:
def execute(self, context: Context) -> Set[str]:
self.join_all_meshes(context)
return {'FINISHED'}
@@ -58,7 +58,7 @@ class JoinSelectedMeshes(Operator):
def poll(cls, context: Context) -> bool:
return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1
def execute(self, context: Context) -> set:
def execute(self, context: Context) -> Set[str]:
self.join_selected_meshes(context)
return {'FINISHED'}
@@ -85,3 +85,4 @@ class JoinSelectedMeshes(Operator):
self.report({'INFO'}, "Selected meshes joined successfully")
else:
self.report({'WARNING'}, "No mesh objects selected")