Typing
This commit is contained in:
+7
-8
@@ -2,7 +2,7 @@ import bpy
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from .dictionaries import bone_names
|
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 bpy.types import Object, ShapeKey, Mesh, Context
|
||||||
from functools import lru_cache
|
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:
|
def _get_shape_key_co(shape_key: ShapeKey) -> np.ndarray:
|
||||||
return np.array([v.co for v in shape_key.data])
|
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" _.")))
|
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:
|
if armature_name:
|
||||||
obj = bpy.data.objects[armature_name]
|
obj = bpy.data.objects[armature_name]
|
||||||
if obj.type == "ARMATURE":
|
if obj.type == "ARMATURE":
|
||||||
@@ -58,17 +58,17 @@ def get_armature(context, armature_name=None) -> Optional[Object]:
|
|||||||
return obj
|
return obj
|
||||||
return next((obj for obj in context.view_layer.objects if obj.type == 'ARMATURE'), None)
|
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']
|
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:
|
if context.scene.selected_armature:
|
||||||
armature = bpy.data.objects.get(context.scene.selected_armature)
|
armature = bpy.data.objects.get(context.scene.selected_armature)
|
||||||
if is_valid_armature(armature):
|
if is_valid_armature(armature):
|
||||||
return armature
|
return armature
|
||||||
return None
|
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 ""
|
context.scene.selected_armature = armature.name if armature else ""
|
||||||
|
|
||||||
def is_valid_armature(armature: Object) -> bool:
|
def is_valid_armature(armature: Object) -> bool:
|
||||||
@@ -78,7 +78,7 @@ def is_valid_armature(armature: Object) -> bool:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def select_current_armature(context):
|
def select_current_armature(context: Context) -> bool:
|
||||||
armature = get_selected_armature(context)
|
armature = get_selected_armature(context)
|
||||||
if armature:
|
if armature:
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
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):
|
if armature and is_valid_armature(armature):
|
||||||
return [obj for obj in bpy.data.objects if obj.type == 'MESH' and obj.parent == armature]
|
return [obj for obj in bpy.data.objects if obj.type == 'MESH' and obj.parent == armature]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import re
|
import re
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple, Optional, Set
|
||||||
from bpy.types import Material, Operator, Context, Object
|
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.common import clean_material_names, get_selected_armature, is_valid_armature, get_all_meshes
|
||||||
from ..core.register import register_wrap
|
from ..core.register import register_wrap
|
||||||
@@ -68,7 +68,7 @@ class CombineMaterials(Operator):
|
|||||||
armature = get_selected_armature(context)
|
armature = get_selected_armature(context)
|
||||||
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:
|
def execute(self, context: Context) -> Set[str]:
|
||||||
armature = get_selected_armature(context)
|
armature = get_selected_armature(context)
|
||||||
if not armature:
|
if not armature:
|
||||||
self.report({'WARNING'}, "No armature selected")
|
self.report({'WARNING'}, "No armature selected")
|
||||||
@@ -90,7 +90,7 @@ class CombineMaterials(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def consolidate_materials(self, meshes: List[Object]) -> None:
|
def consolidate_materials(self, meshes: List[Object]) -> None:
|
||||||
mat_mapping: dict = {}
|
mat_mapping: Dict[str, Material] = {}
|
||||||
num_combined: int = 0
|
num_combined: int = 0
|
||||||
for mesh in meshes:
|
for mesh in meshes:
|
||||||
for slot in mesh.material_slots:
|
for slot in mesh.material_slots:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Set
|
||||||
from bpy.types import Operator, Context, Object
|
from bpy.types import Operator, Context, Object
|
||||||
from ..core.register import register_wrap
|
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
|
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)
|
armature = get_selected_armature(context)
|
||||||
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:
|
def execute(self, context: Context) -> Set[str]:
|
||||||
self.join_all_meshes(context)
|
self.join_all_meshes(context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class JoinSelectedMeshes(Operator):
|
|||||||
def poll(cls, context: Context) -> bool:
|
def poll(cls, context: Context) -> bool:
|
||||||
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:
|
def execute(self, context: Context) -> Set[str]:
|
||||||
self.join_selected_meshes(context)
|
self.join_selected_meshes(context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@@ -85,3 +85,4 @@ class JoinSelectedMeshes(Operator):
|
|||||||
self.report({'INFO'}, "Selected meshes joined successfully")
|
self.report({'INFO'}, "Selected meshes joined successfully")
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, "No mesh objects selected")
|
self.report({'WARNING'}, "No mesh objects selected")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user