Skip to content
Snippets Groups Projects
Commit 72e2f73b authored by Nathan Vegdahl's avatar Nathan Vegdahl
Browse files

Rigify: constraints are now copied over from metarig.

This allows advanced users to do certain limited custom rigging work
in the metarig, and have it transfer to the generated rig.
Custom properties are also copied when using the copy_bone function
in utils.
TODO: transfer drivers from the metarig as well.
parent 3dbeaddc
No related branches found
No related tags found
No related merge requests found
......@@ -130,6 +130,15 @@ def generate_rig(context, metarig):
obj.select = True
scene.objects.active = obj
# Copy over bone properties
for bone in metarig.data.bones:
bone_gen = obj.data.bones[bone.name]
# B-bone stuff
bone_gen.bbone_segments = bone.bbone_segments
bone_gen.bbone_in = bone.bbone_in
bone_gen.bbone_out = bone.bbone_out
# Copy over the pose_bone properties
for bone in metarig.pose.bones:
bone_gen = obj.pose.bones[bone.name]
......@@ -146,14 +155,28 @@ def generate_rig(context, metarig):
for prop in bone.keys():
bone_gen[prop] = bone[prop]
# Copy over bone properties
for bone in metarig.data.bones:
bone_gen = obj.data.bones[bone.name]
# B-bone stuff
bone_gen.bbone_segments = bone.bbone_segments
bone_gen.bbone_in = bone.bbone_in
bone_gen.bbone_out = bone.bbone_out
# 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)
# Set metarig target to rig target
if "target" in keys:
if getattr(con2, "target") == metarig:
setattr(con2, "target", obj)
t.tick("Duplicate rig: ")
#----------------------------------
......
......@@ -185,6 +185,17 @@ def copy_bone(obj, bone_name, assign_name=''):
pose_bone_2.lock_rotation_w = pose_bone_1.lock_rotation_w
pose_bone_2.lock_rotations_4d = pose_bone_1.lock_rotations_4d
# Copy custom properties
for key in pose_bone_1.keys():
if key != "_RNA_UI" \
and key != "rigify_parameters" \
and key != "rigify_type":
prop1 = rna_idprop_ui_prop_get(pose_bone_1, key, create=False)
prop2 = rna_idprop_ui_prop_get(pose_bone_2, key, create=True)
pose_bone_2[key] = pose_bone_1[key]
for key in prop1.keys():
prop2[key] = prop1[key]
bpy.ops.object.mode_set(mode='EDIT')
return bone_name_2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment