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:
authorNathan Vegdahl <cessen@cessen.com>2011-06-24 00:17:34 +0400
committerNathan Vegdahl <cessen@cessen.com>2011-06-24 00:17:34 +0400
commit653ccca3171d69d9b49f340f405de6ce5f981661 (patch)
tree0fae83ad67e47b0d7dba11ef0f042501c13da391 /rigify/generate.py
parentb930f0c1a6b731554caadd485d221314a35a3ff9 (diff)
Rigify: drivers now get transfered from the metarig to the generated rig.
This is the last piece that should allow some pretty extensive custom rigging in the metarig, if advanced users choose to do so.
Diffstat (limited to 'rigify/generate.py')
-rw-r--r--rigify/generate.py76
1 files changed, 59 insertions, 17 deletions
diff --git a/rigify/generate.py b/rigify/generate.py
index 73552442..a2ac6f7a 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -17,6 +17,7 @@
#======================= END GPL LICENSE BLOCK ========================
import bpy
+import re
import time
import traceback
import sys
@@ -26,6 +27,7 @@ from rigify.utils import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, WGT_PREFIX, ROOT_NA
from rigify.utils import RIG_DIR
from rigify.utils import create_root_widget
from rigify.utils import random_id
+from rigify.utils import copy_attributes
from rigify.rig_ui_template import UI_SLIDERS, layers_ui, UI_REGISTER
from rigify import rigs
@@ -158,25 +160,53 @@ def generate_rig(context, metarig):
# Constraints
for con1 in bone.constraints:
con2 = bone_gen.constraints.new(type=con1.type)
-
- # Copy attributes
- keys = dir(con1)
- for key in keys:
- if not key.startswith("_") \
- and not key.startswith("error_") \
- and key != "is_valid" \
- and key != "rna_type" \
- and key != "type" \
- and key != "bl_rna":
- try:
- setattr(con2, key, getattr(con1, key))
- except AttributeError:
- print("Could not write to constraint attribute '%s'" % key)
+ copy_attributes(con1, con2)
# Set metarig target to rig target
- if "target" in keys:
- if getattr(con2, "target") == metarig:
- setattr(con2, "target", obj)
+ if "target" in dir(con2):
+ if con2.target == metarig:
+ con2.target = obj
+
+ # Copy drivers
+ for d1 in metarig.animation_data.drivers:
+ d2 = obj.driver_add(d1.data_path)
+ copy_attributes(d1, d2)
+ copy_attributes(d1.driver, d2.driver)
+
+ # Remove default modifiers, variables, etc.
+ for m in d2.modifiers:
+ d2.modifiers.remove(m)
+ for v in d2.driver.variables:
+ d2.driver.variables.remove(v)
+
+ # Copy modifiers
+ for m1 in d1.modifiers:
+ m2 = d2.modifiers.new(type=m1.type)
+ copy_attributes(m1, m2)
+
+ # Copy variables
+ for v1 in d1.driver.variables:
+ v2 = d2.driver.variables.new()
+ copy_attributes(v1, v2)
+ for i in range(len(v1.targets)):
+ copy_attributes(v1.targets[i], v2.targets[i])
+ # Switch metarig targets to rig targets
+ if v2.targets[i].id == metarig:
+ v2.targets[i].id = obj
+
+ # Mark targets that may need to be altered after rig generation
+ tar = v2.targets[i]
+ # If a custom property
+ if v2.type == 'SINGLE_PROP' \
+ and re.match('^pose.bones\["[^"\]]*"\]\["[^"\]]*"\]$', tar.data_path):
+ tar.data_path = "RIGIFY-" + tar.data_path
+
+ # Copy key frames
+ for i in range(len(d1.keyframe_points)):
+ d2.keyframe_points.add()
+ k1 = d1.keyframe_points[i]
+ k2 = d2.keyframe_points[i]
+ copy_attributes(k1, k2)
t.tick("Duplicate rig: ")
#----------------------------------
@@ -267,6 +297,18 @@ def generate_rig(context, metarig):
else:
obj.data.bones[bone].use_deform = False
+ # Alter marked driver targets
+ for d in obj.animation_data.drivers:
+ for v in d.driver.variables:
+ for tar in v.targets:
+ if tar.data_path.startswith("RIGIFY-"):
+ temp, bone, prop = tuple([x.strip('"]') for x in tar.data_path.split('["')])
+ if bone in obj.data.bones \
+ and prop in obj.pose.bones[bone].keys():
+ tar.data_path = tar.data_path[7:]
+ else:
+ tar.data_path = 'pose.bones["%s"]["%s"]' % (make_original_name(bone), prop)
+
# Move all the original bones to their layer.
for bone in original_bones:
obj.data.bones[bone].layers = ORG_LAYER