From 29d6b58fa9ba6dc9be992b0484cde180aece8d39 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Sep 2019 17:47:10 +0300 Subject: [PATCH] 1.5.5 Various Feature updates New Bone Tools: - Rename Chain - Renames entire chain by the chain's root parent bone name# adding a number to end of all the bones. - Remove 001 - Removes all .001 endings from names. - Mirror Bone - Shorthand for Duplicating, Applying Mirrored Names, and then mirroring on the X axis from center. --- hifi_tools/__init__.py | 2 +- hifi_tools/ui/__init__.py | 59 +++++++++++++++++++++++++ hifi_tools/ui/vrc.py | 4 +- hifi_tools/utils/bones/bones_builder.py | 14 ++++++ hifi_tools/utils/helpers/materials.py | 2 +- hifi_tools/utils/helpers/mesh.py | 12 +++-- 6 files changed, 85 insertions(+), 8 deletions(-) diff --git a/hifi_tools/__init__.py b/hifi_tools/__init__.py index e1cee36..cc00cb8 100644 --- a/hifi_tools/__init__.py +++ b/hifi_tools/__init__.py @@ -20,7 +20,7 @@ bl_info = { "name": "Metaverse Toolkit Blender Add-on", "author": "Matti 'Menithal' Lahtinen", - "version": (1, 5, 4), + "version": (1, 5, 5), "blender": (2, 80, 0), "location": "File > Import-Export, Materials, Armature", "description": "Blender tools to allow for easier Content creation for Metaverses, such as High Fidelity", diff --git a/hifi_tools/ui/__init__.py b/hifi_tools/ui/__init__.py index 614cc85..f5bdff1 100644 --- a/hifi_tools/ui/__init__.py +++ b/hifi_tools/ui/__init__.py @@ -89,6 +89,9 @@ def draw(self, context): layout.operator(BONES_OT_MVT_TOOLSET_Combine_Disconnected.bl_idname) layout.operator(BONES_OT_MVT_TOOLSET_Connect_Selected.bl_idname) layout.operator(BONES_OT_MVT_TOOLSET_Disconnect_Selected.bl_idname) + layout.operator(BONES_OT_MVT_TOOLSET_Rename_Chain.bl_idname) + layout.operator(BONES_OT_MVT_TOOLSET_Remove_001.bl_idname) + layout.operator(BONES_OT_MVT_TOOLSET_Mirror_And_Rename_On_X.bl_idname) return None @@ -310,6 +313,59 @@ def execute(self, context): bpy.context.object.data.use_mirror_x = use_mirror_x return {'FINISHED'} +class BONES_OT_MVT_TOOLSET_Rename_Chain(bpy.types.Operator): + """ Rename bones to Chain From Root Name and Numbers Accordingly """ + bl_idname = "metaverse_toolset.rename_bone_chain" + bl_label = "Rename Chain to Root" + + bl_region_type = "TOOLS" + bl_space_type = "VIEW_3D" + + @classmethod + def poll(self, context): + return context.selected_bones is not None and len(context.selected_bones) > 1 + + def execute(self, context): + name = context.selected_bones[0].name + bones_builder.rename_selected_bone_chain(name, context.selected_bones) + return {'FINISHED'} + + +class BONES_OT_MVT_TOOLSET_Remove_001(bpy.types.Operator): + """ Remove .001 endings """ + bl_idname = "metaverse_toolset.remove_bone_001_ending" + bl_label = "Remove .001 from Names" + + bl_region_type = "TOOLS" + bl_space_type = "VIEW_3D" + + @classmethod + def poll(self, context): + return context.selected_bones is not None and len(context.selected_bones) > 1 + + def execute(self, context): + bones_builder.remove_001_endings(context.selected_bones) + return {'FINISHED'} + + + +class BONES_OT_MVT_TOOLSET_Mirror_And_Rename_On_X(bpy.types.Operator): + """ Mirrors and renames selected on the X axis """ + bl_idname = "metaverse_toolset.bones_mirror_and_rename" + bl_label = "Mirror Bones" + + bl_region_type = "TOOLS" + bl_space_type = "VIEW_3D" + + @classmethod + def poll(self, context): + return context.selected_bones is not None and len(context.selected_bones) > 0 + + def execute(self, context): + bones_builder.mirror_bones_x_and_rename() + return {'FINISHED'} + + class TEXTURES_OT_MVT_TOOLSET_Convert_To_Png(bpy.types.Operator): """ Converter to update All scene Textures to PNG """ @@ -507,6 +563,9 @@ class TEST_WT_workspace(bpy.types.WorkSpaceTool): BONES_OT_MVT_TOOLSET_Combine_Disconnected, BONES_OT_MVT_TOOLSET_Connect_Selected, BONES_OT_MVT_TOOLSET_Disconnect_Selected, + BONES_OT_MVT_TOOLSET_Rename_Chain, + BONES_OT_MVT_TOOLSET_Remove_001, + BONES_OT_MVT_TOOLSET_Mirror_And_Rename_On_X, ARMATURE_PT_MVT_TOOLSET, OBJECT_PT_MVT_TOOLSET_Assets_Display, diff --git a/hifi_tools/ui/vrc.py b/hifi_tools/ui/vrc.py index 3294be6..47b9575 100644 --- a/hifi_tools/ui/vrc.py +++ b/hifi_tools/ui/vrc.py @@ -39,7 +39,7 @@ 'vrc.v_aa', 'vrc.v_ch', 'vrc.v_dd', - 'vrc.v_ee', + 'vrc.v_e', 'vrc.v_ff', 'vrc.v_ih', 'vrc.v_kk', @@ -127,7 +127,7 @@ class ARMATURE_OT_MVT_TOOLSET_Sort_VRC_Shapekeys(bpy.types.Operator): @classmethod def poll(self, context): - return context.mode == "OBJECT" and context.active.object is not None and len(mesh.get_shape_keys(context.active_object)) > 0 + return context.mode == "OBJECT" and context.active_object is not None and context.active_object.type == "MESH" and len(mesh.get_shape_keys(context.active_object)) > 0 def execute(self, context): mesh.sort_shapekeys(bpy.context.active_object, expected_vrc_shapekeys) diff --git a/hifi_tools/utils/bones/bones_builder.py b/hifi_tools/utils/bones/bones_builder.py index 4ae65c6..bab94cb 100644 --- a/hifi_tools/utils/bones/bones_builder.py +++ b/hifi_tools/utils/bones/bones_builder.py @@ -529,6 +529,20 @@ def delete_bones(edit_bones, bones_to_remove): print(" Remove Bone:", removal_bone) edit_bones.remove(removal_bone) +def rename_selected_bone_chain(base_name, ebones): + # bpy.context.selected_bones + + for idx,ebone in enumerate(ebones): + ebone.name = base_name + str(idx+1) + +def remove_001_endings(ebones): + for ebone in ebones: + ebone.name = ebone.name.replace(".001","") + + +def mirror_bones_x_and_rename(): + bpy.ops.armature.duplicate_move(ARMATURE_OT_duplicate={"do_flip_names":True}) + bpy.ops.transform.resize(value=(-1,1,1),center_override=(0,0,0), constraint_axis=(True, False, False), orient_type='GLOBAL') def build_armature_structure(data, current_node, parent): diff --git a/hifi_tools/utils/helpers/materials.py b/hifi_tools/utils/helpers/materials.py index 9bca66f..53a3227 100644 --- a/hifi_tools/utils/helpers/materials.py +++ b/hifi_tools/utils/helpers/materials.py @@ -210,7 +210,7 @@ def correct_all_color_spaces_to_non_color(context): node.inputs.get("Subsurface Scattering")) normal_map_socket = node.inputs.get("Normal") - if normal_map_socket is not None: + if normal_map_socket is not None and len(normal_map_socket.links) is not 0: normal_map = normal_map_socket.links[0].from_node correct_node_color_space_to_non_color( normal_map.inputs.get("Color")) diff --git a/hifi_tools/utils/helpers/mesh.py b/hifi_tools/utils/helpers/mesh.py index eb49264..36ca731 100644 --- a/hifi_tools/utils/helpers/mesh.py +++ b/hifi_tools/utils/helpers/mesh.py @@ -115,21 +115,25 @@ def get_shape_keys(mesh): def generate_empty_shapekeys(obj, target_shapekey_list): - shape_keys = get_shape_keys(active) - + print("generate_empty_shapekeys", obj) + shape_keys = get_shape_keys(obj) for key in target_shapekey_list: - if shape_keys.find(key) is None: + print(key, shape_keys.find(key)) + if shape_keys.find(key) is -1: bpy.ops.object.shape_key_clear() obj.shape_key_add(name=key) def sort_shapekeys(obj, target_shapekey_list): - shape_keys = get_shape_keys(selected) + print("sort_shapekeys", obj) + shape_keys = get_shape_keys(obj) + print(shape_keys) name_list = [sk.name for sk in shape_keys] moved = 0 for key in reversed(target_shapekey_list): try: + index = name_list.index(key) bpy.context.object.active_shape_key_index = index + moved bpy.ops.object.shape_key_move(type='TOP')