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:
authorAlexander Gavrilov <angavrilov@gmail.com>2020-11-25 14:07:44 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2020-11-25 14:42:56 +0300
commit292b5975d6d4d470f51ff683d5b5a5d979e887a4 (patch)
tree98623b8bc46f0d6c07a0ad3ced951bf45393ed3d /rigify/utils/rig.py
parent1a9a9d008dea3fab2bdfd04a57bcdd364ae5d0b8 (diff)
Rigify: support including Inherit Scale and constraints in metarig.
Also fix metarig Inherit Scale support in limbs.super_finger.
Diffstat (limited to 'rigify/utils/rig.py')
-rw-r--r--rigify/utils/rig.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py
index e1957a21..bcb3ff74 100644
--- a/rigify/utils/rig.py
+++ b/rigify/utils/rig.py
@@ -23,6 +23,8 @@ import importlib
import importlib.util
import os
+from bpy.types import bpy_struct, bpy_prop_array, Constraint
+
RIG_DIR = "rigs" # Name of the directory where rig types are kept
METARIG_DIR = "metarigs" # Name of the directory where metarigs are kept
TEMPLATE_DIR = "ui_templates" # Name of the directory where ui templates are kept
@@ -147,6 +149,30 @@ def list_bone_names_depth_first_sorted(obj):
return result_list
+def _get_property_value(obj, name):
+ value = getattr(obj, name, None)
+ if isinstance(value, bpy_prop_array):
+ value = tuple(value)
+ return value
+
+def _generate_properties(lines, prefix, obj, base_class, *, defaults={}, objects={}):
+ block_props = set(prop.identifier for prop in base_class.bl_rna.properties) - set(defaults.keys())
+
+ for prop in type(obj).bl_rna.properties:
+ if prop.identifier not in block_props and not prop.is_readonly:
+ cur_value = _get_property_value(obj, prop.identifier)
+
+ if prop.identifier in defaults:
+ if cur_value == defaults[prop.identifier]:
+ continue
+
+ if isinstance(cur_value, bpy_struct):
+ if cur_value in objects:
+ lines.append('%s.%s = %s' % (prefix, prop.identifier, objects[cur_value]))
+ else:
+ lines.append('%s.%s = %r' % (prefix, prop.identifier, cur_value))
+
+
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
@@ -211,6 +237,8 @@ def write_metarig(obj, layers=False, func_name="create", groups=False):
code.append(" bone.tail = %.4f, %.4f, %.4f" % bone.tail.to_tuple(4))
code.append(" bone.roll = %.4f" % bone.roll)
code.append(" bone.use_connect = %s" % str(bone.use_connect))
+ if bone.inherit_scale != 'FULL':
+ code.append(" bone.inherit_scale = %r" % str(bone.inherit_scale))
if bone.parent:
code.append(" bone.parent = arm.edit_bones[bones[%r]]" % bone.parent.name)
code.append(" bones[%r] = bone.name" % bone.name)
@@ -243,6 +271,29 @@ def write_metarig(obj, layers=False, func_name="create", groups=False):
code.append(" pbone.rigify_parameters.%s = %s" % (param_name, str(param)))
code.append(" except AttributeError:")
code.append(" pass")
+ # Constraints
+ for con in pbone.constraints:
+ code.append(" con = pbone.constraints.new(%r)" % (con.type))
+ code.append(" con.name = %r" % (con.name))
+ # Add target first because of target_space handling
+ if con.type == 'ARMATURE':
+ for tgt in con.targets:
+ code.append(" tgt = con.targets.new()")
+ code.append(" tgt.target = obj")
+ code.append(" tgt.subtarget = %r" % (tgt.subtarget))
+ code.append(" tgt.weight = %.3f" % (tgt.weight))
+ elif getattr(con, 'target', None) == obj:
+ code.append(" con.target = obj")
+ # Generic properties
+ _generate_properties(
+ code, " con", con, Constraint,
+ defaults={
+ 'owner_space': 'WORLD', 'target_space': 'WORLD',
+ 'mute': False, 'influence': 1.0,
+ 'target': obj,
+ },
+ objects={obj: 'obj'},
+ )
code.append("\n bpy.ops.object.mode_set(mode='EDIT')")
code.append(" for bone in arm.edit_bones:")