Basic Start of Armature Selection
This commit is contained in:
@@ -2,7 +2,7 @@ import bpy
|
||||
import re
|
||||
from typing import List, Tuple, Optional
|
||||
from bpy.types import Material, Operator, Context, Object
|
||||
from ..core.common import clean_material_names
|
||||
from ..core.common import clean_material_names, get_selected_armature
|
||||
from ..core.register import register_wrap
|
||||
from ..functions.translations import t
|
||||
|
||||
@@ -65,17 +65,19 @@ class CombineMaterials(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: Context) -> bool:
|
||||
return context.active_object is not None
|
||||
return context.active_object is not None and get_selected_armature(context) is not None
|
||||
|
||||
def execute(self, context: Context) -> set:
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
armature: Optional[Object] = next((obj for obj in bpy.data.objects if obj.type == 'ARMATURE'), None)
|
||||
armature = get_selected_armature(context)
|
||||
if not armature:
|
||||
self.report({'WARNING'}, "No armature selected")
|
||||
return {'CANCELLED'}
|
||||
|
||||
meshes: List[Object] = [obj for obj in bpy.data.objects if obj.type == 'MESH' and 'Armature' in obj.modifiers and obj.modifiers['Armature'].object == armature]
|
||||
if not meshes:
|
||||
self.report({'WARNING'}, "No meshes found for the selected armature")
|
||||
return {'CANCELLED'}
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
@@ -125,4 +127,3 @@ class CombineMaterials(Operator):
|
||||
for obj in bpy.data.objects:
|
||||
if obj.type == 'MESH':
|
||||
clean_material_names(obj)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import bpy
|
||||
from typing import List, Optional
|
||||
from bpy.types import Operator, Context, Object
|
||||
from ..core.register import register_wrap
|
||||
from ..core.common import fix_uv_coordinates
|
||||
from ..core.common import fix_uv_coordinates, get_selected_armature
|
||||
from ..functions.translations import t
|
||||
|
||||
@register_wrap
|
||||
@@ -14,21 +14,22 @@ class JoinAllMeshes(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: Context) -> bool:
|
||||
return context.mode == 'OBJECT'
|
||||
return context.mode == 'OBJECT' and get_selected_armature(context) is not None
|
||||
|
||||
def execute(self, context: Context) -> set:
|
||||
self.join_all_meshes(context)
|
||||
return {'FINISHED'}
|
||||
|
||||
def join_all_meshes(self, context: Context) -> None:
|
||||
if not bpy.data.objects:
|
||||
self.report({'INFO'}, "No objects in the scene")
|
||||
armature = get_selected_armature(context)
|
||||
if not armature:
|
||||
self.report({'WARNING'}, "No armature selected")
|
||||
return
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
meshes: List[Object] = [obj for obj in bpy.data.objects if obj.type == 'MESH']
|
||||
meshes: List[Object] = [obj for obj in bpy.data.objects if obj.type == 'MESH' and 'Armature' in obj.modifiers and obj.modifiers['Armature'].object == armature]
|
||||
for mesh in meshes:
|
||||
mesh.select_set(True)
|
||||
|
||||
@@ -52,7 +53,7 @@ class JoinSelectedMeshes(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: Context) -> bool:
|
||||
return context.mode == 'OBJECT'
|
||||
return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1
|
||||
|
||||
def execute(self, context: Context) -> set:
|
||||
self.join_selected_meshes(context)
|
||||
@@ -61,8 +62,8 @@ class JoinSelectedMeshes(Operator):
|
||||
def join_selected_meshes(self, context: Context) -> None:
|
||||
selected_objects: List[Object] = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
|
||||
|
||||
if not selected_objects:
|
||||
self.report({'WARNING'}, "No mesh objects selected")
|
||||
if len(selected_objects) < 2:
|
||||
self.report({'WARNING'}, "Please select at least two mesh objects")
|
||||
return
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
@@ -81,4 +82,3 @@ class JoinSelectedMeshes(Operator):
|
||||
self.report({'INFO'}, "Selected meshes joined successfully")
|
||||
else:
|
||||
self.report({'WARNING'}, "No mesh objects selected")
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import re
|
||||
from typing import List, Tuple, Optional, TypedDict
|
||||
from bpy.types import Material, Operator, Context, Object
|
||||
from ..core.register import register_wrap
|
||||
from ..core.common import get_armature
|
||||
from ..core.common import get_selected_armature
|
||||
|
||||
|
||||
class meshEntry(TypedDict):
|
||||
@@ -23,20 +23,19 @@ class RemoveDoublesSafely(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: Context) -> bool:
|
||||
return context.mode == 'OBJECT'
|
||||
return context.mode == 'OBJECT' and get_selected_armature(context) is not None
|
||||
|
||||
def execute(self, context: Context) -> set:
|
||||
if not bpy.data.objects:
|
||||
self.report({'INFO'}, "No objects in the scene")
|
||||
return
|
||||
armature = get_selected_armature(context)
|
||||
if not armature:
|
||||
self.report({'WARNING'}, "No armature selected")
|
||||
return {'CANCELLED'}
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
objects: List[Object] = get_armature(context).children if get_armature(context) else context.view_layer.objects
|
||||
objects: List[Object] = [obj for obj in armature.children if obj.type == 'MESH']
|
||||
|
||||
meshes: List[Object] = [obj for obj in objects if obj.type == 'MESH']
|
||||
|
||||
for mesh in meshes:
|
||||
for mesh in objects:
|
||||
if mesh.data.name not in [stored_object["mesh"].data.name for stored_object in self.objects_to_do]:
|
||||
mesh_shapekeys = {"mesh":mesh,"shapekeys":[]}
|
||||
mesh_data: bpy.types.Mesh = mesh.data
|
||||
@@ -45,12 +44,10 @@ class RemoveDoublesSafely(Operator):
|
||||
for shape in mesh_data.shape_keys.key_blocks:
|
||||
mesh_shapekeys["shapekeys"].append(shape.name)
|
||||
self.objects_to_do.append(mesh_shapekeys)
|
||||
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context: Context, event: bpy.types.Event) -> set:
|
||||
|
||||
self.execute(context)
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
@@ -62,7 +59,6 @@ class RemoveDoublesSafely(Operator):
|
||||
mesh_data: bpy.types.Mesh = mesh["mesh"].data
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
for index, point in enumerate(mesh["mesh"].active_shape_key.points):
|
||||
if point.co.xyz != mesh_data.shape_keys.key_blocks[0].points[index].co.xyz:
|
||||
@@ -70,18 +66,10 @@ class RemoveDoublesSafely(Operator):
|
||||
print("shapekey has a moved vertex at index \""+str(index)+"\", excluding from double merging!")
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
|
||||
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
mesh["mesh"].select_set(False)
|
||||
|
||||
|
||||
def modal(self, context: Context, event: bpy.types.Event) -> set:
|
||||
|
||||
|
||||
|
||||
|
||||
if len(self.objects_to_do) > 0:
|
||||
mesh = self.objects_to_do[0]
|
||||
mesh_data: bpy.types.Mesh = mesh["mesh"].data
|
||||
@@ -131,10 +119,3 @@ class RemoveDoublesSafely(Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import List, Optional
|
||||
import re
|
||||
from bpy.types import Operator, Context, Object
|
||||
from ..core.dictionaries import bone_names
|
||||
from ..core.common import get_armature, simplify_bonename
|
||||
from ..core.common import get_selected_armature, simplify_bonename
|
||||
from ..functions.translations import t
|
||||
|
||||
@register_wrap
|
||||
@@ -16,12 +16,13 @@ class ConvertToResonite(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: Context) -> bool:
|
||||
if not get_armature(context):
|
||||
return False
|
||||
return True
|
||||
return get_selected_armature(context) is not None
|
||||
|
||||
def execute(self, context: Context) -> set:
|
||||
armature = get_armature(context)
|
||||
armature = get_selected_armature(context)
|
||||
if not armature:
|
||||
self.report({'WARNING'}, "No armature selected")
|
||||
return {'CANCELLED'}
|
||||
|
||||
translate_bone_fails = 0
|
||||
untranslated_bones = set()
|
||||
@@ -89,8 +90,6 @@ class ConvertToResonite(Operator):
|
||||
'thumb_3_r': "thumb3.R"
|
||||
}
|
||||
|
||||
|
||||
|
||||
context.view_layer.objects.active = armature
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
@@ -111,5 +110,4 @@ class ConvertToResonite(Operator):
|
||||
else:
|
||||
self.report({'INFO'}, "Successfully translated all bones to humanoid names")
|
||||
|
||||
|
||||
return {'FINISHED'}
|
||||
return {'FINISHED'}
|
||||
|
||||
Reference in New Issue
Block a user