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 []