Skip to content

Commit

Permalink
1.5.5 Various Feature updates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Menithal committed Sep 14, 2019
1 parent 6e5326b commit 29d6b58
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hifi_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions hifi_tools/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 """
Expand Down Expand Up @@ -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,

Expand Down
4 changes: 2 additions & 2 deletions hifi_tools/ui/vrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions hifi_tools/utils/bones/bones_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion hifi_tools/utils/helpers/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
12 changes: 8 additions & 4 deletions hifi_tools/utils/helpers/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 29d6b58

Please sign in to comment.