[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37333] branches/soc-2011-pepper/release/ scripts/modules/retarget.py: retarget. py updated with function to complete the retarget to the end user, with inheritance and bone roll taken under account
Benjy Cook
benjycook at hotmail.com
Thu Jun 9 14:30:24 CEST 2011
Revision: 37333
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37333
Author: benjycook
Date: 2011-06-09 12:30:24 +0000 (Thu, 09 Jun 2011)
Log Message:
-----------
retarget.py updated with function to complete the retarget to the end user, with inheritance and bone roll taken under account
Modified Paths:
--------------
branches/soc-2011-pepper/release/scripts/modules/retarget.py
Modified: branches/soc-2011-pepper/release/scripts/modules/retarget.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/modules/retarget.py 2011-06-09 11:19:34 UTC (rev 37332)
+++ branches/soc-2011-pepper/release/scripts/modules/retarget.py 2011-06-09 12:30:24 UTC (rev 37333)
@@ -3,9 +3,18 @@
from math import radians, acos
performer_obj = bpy.data.objects["performer"]
enduser_obj = bpy.data.objects["enduser"]
+end_arm = bpy.data.armatures["enduser_arm"]
scene = bpy.context.scene
+#TODO: Only selected bones get retargeted.
+# Selected Bones/chains get original pos empties, if ppl want IK instead of FK
+# Some "magic" numbers - frame start and end, eulers of all orders instead of just quats keyframed
+
+
+
# dictionary of mapping
+# this is currently manuall input'ed, but will
+# be created from a more comfortable UI in the future
bonemap = { "LeftFoot": ("DEF_Foot.L","DEF_Toes.L"),
"LeftUpLeg": "DEF_Thigh.L",
"Hips": "DEF_Hip",
@@ -26,6 +35,7 @@
"RightUpLeg": "DEF_Thigh.R",
"RightLeg": "DEF_Shin.R",
"LeftLeg": "DEF_Shin.L"}
+
# creation of a reverse map
# multiple keys get mapped to list values
bonemapr = {}
@@ -42,9 +52,11 @@
# list of empties created to keep track of "original"
# position data
# in final product, these locations can be stored as custom props
+# these help with constraining, etc.
constraints = []
+
#creation of intermediate armature
# the intermediate armature has the hiearchy of the end user,
# does not have rotation inheritence
@@ -103,9 +115,12 @@
if len(perf_bone_name) > 1:
performer_bones_s = [performer_bones[name] for name in perf_bone_name]
#we need to map several performance bone to a single
+ for perf_bone in performer_bones_s:
+ locOfOriginal(inter_bone,perf_bone)
inter_bone.matrix_basis = manyPerfToSingleInterRetarget(inter_bone,performer_bones_s)
else:
perf_bone = performer_bones[perf_bone_name[0]]
+ locOfOriginal(inter_bone,perf_bone)
inter_bone.matrix_basis = singleBoneRetarget(inter_bone,perf_bone)
inter_bone.keyframe_insert("rotation_quaternion")
@@ -121,6 +136,8 @@
#resets roll
bpy.ops.armature.calculate_roll(type='Z')
bpy.ops.object.mode_set(mode="OBJECT")
+ inter_arm = bpy.data.armatures["enduser_arm.001"]
+ inter_arm.name = "inter_arm"
performer_bones = performer_obj.pose.bones
inter_bones = inter_obj.pose.bones
@@ -132,5 +149,50 @@
scene.frame_set(t)
inter_bone = inter_bones["DEF_Hip"]
retargetPerfToInter(inter_bone)
-
-createIntermediate()
\ No newline at end of file
+
+ return inter_obj,inter_arm
+
+# this procedure copies the rotations over from the intermediate
+# armature to the end user one.
+# As the hierarchies are 1 to 1, this is a simple matter of
+# copying the rotation, while keeping in mind bone roll, parenting, etc.
+# TODO: Control Bones: If a certain bone is constrained in a way
+# that its rotation is determined by another (a control bone)
+# We should determine the right pos of the control bone.
+# Scale: ? Should work but needs testing.
+def retargetEnduser():
+ inter_bones = inter_obj.pose.bones
+ end_bones = enduser_obj.pose.bones
+
+ def bakeTransform(end_bone):
+ src_bone = inter_bones[end_bone.name]
+ trg_bone = end_bone
+ bake_matrix = src_bone.matrix
+ rest_matrix = trg_bone.bone.matrix_local
+
+ if trg_bone.parent and trg_bone.bone.use_inherit_rotation:
+ parent_mat = src_bone.parent.matrix
+ parent_rest = trg_bone.parent.bone.matrix_local
+ parent_rest_inv = parent_rest.copy()
+ parent_rest_inv.invert()
+ parent_mat_inv = parent_mat.copy()
+ parent_mat_inv.invert()
+ bake_matrix = parent_mat_inv * bake_matrix
+ rest_matrix = parent_rest_inv * rest_matrix
+
+ rest_matrix_inv = rest_matrix.copy()
+ rest_matrix_inv.invert()
+ bake_matrix = rest_matrix_inv * bake_matrix
+ trg_bone.matrix_basis = bake_matrix
+ end_bone.keyframe_insert("rotation_quaternion")
+
+ for bone in end_bone.children:
+ bakeTransform(bone)
+
+ for t in range(1,150):
+ scene.frame_set(t)
+ end_bone = end_bones["DEF_Hip"]
+ bakeTransform(end_bone)
+
+inter_obj, inter_arm = createIntermediate()
+retargetEnduser()
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list