Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rigify/utils/rig.py')
-rw-r--r--rigify/utils/rig.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py
index 414ea133..41027c69 100644
--- a/rigify/utils/rig.py
+++ b/rigify/utils/rig.py
@@ -50,6 +50,12 @@ outdated_types = {"pitchipoy.limbs.super_limb": "limbs.super_limb",
"spine": ""
}
+def get_rigify_type(pose_bone):
+ return pose_bone.rigify_type.replace(" ", "")
+
+def is_rig_base_bone(obj, name):
+ return bool(get_rigify_type(obj.pose.bones[name]))
+
def upgradeMetarigTypes(metarig, revert=False):
"""Replaces rigify_type properties from old versions with their current names
@@ -89,6 +95,34 @@ def get_resource(resource_name):
return module
+def attach_persistent_script(obj, script):
+ """Make sure the ui script always follows the rig around"""
+ skip = False
+ driver = None
+
+ if not obj.animation_data:
+ obj.animation_data_create()
+
+ for fcurve in obj.animation_data.drivers:
+ if fcurve.data_path == 'pass_index':
+ driver = fcurve.driver
+ for variable in driver.variables:
+ if variable.name == script.name:
+ skip = True
+ break
+ break
+
+ if not skip:
+ if not driver:
+ fcurve = obj.driver_add("pass_index")
+ driver = fcurve.driver
+
+ variable = driver.variables.new()
+ variable.name = script.name
+ variable.targets[0].id_type = 'TEXT'
+ variable.targets[0].id = script
+
+
def connected_children_names(obj, bone_name):
""" Returns a list of bone names (in order) of the bones that form a single
connected chain starting with the given bone as a parent.
@@ -124,6 +158,23 @@ def has_connected_children(bone):
return t
+def _list_bone_names_depth_first_sorted_rec(result_list, bone):
+ result_list.append(bone.name)
+
+ for child in sorted(list(bone.children), key=lambda b: b.name):
+ _list_bone_names_depth_first_sorted_rec(result_list, child)
+
+def list_bone_names_depth_first_sorted(obj):
+ """Returns a list of bone names in depth first name sorted order."""
+ result_list = []
+
+ for bone in sorted(list(obj.data.bones), key=lambda b: b.name):
+ if bone.parent is None:
+ _list_bone_names_depth_first_sorted_rec(result_list, bone)
+
+ return result_list
+
+
def write_metarig(obj, layers=False, func_name="create", groups=False):
"""
Write a metarig as a python script, this rig is to have all info needed for
@@ -248,6 +299,8 @@ def write_metarig(obj, layers=False, func_name="create", groups=False):
code.append("\n arm.layers = [(x in " + str(active_layers) + ") for x in range(" + str(len(arm.layers)) + ")]")
+ code.append("\n return bones")
+
code.append('\nif __name__ == "__main__":')
code.append(" " + func_name + "(bpy.context.active_object)\n")