[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2350] trunk/py/scripts/addons/mocap: Updated Mocap addon with fixes for latest api changes and some reported bugs

Benjy Cook benjycook at hotmail.com
Fri Sep 23 22:39:49 CEST 2011


Revision: 2350
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2350
Author:   benjycook
Date:     2011-09-23 20:39:48 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Updated Mocap addon with fixes for latest api changes and some reported bugs

Modified Paths:
--------------
    trunk/py/scripts/addons/mocap/__init__.py
    trunk/py/scripts/addons/mocap/retarget.py

Modified: trunk/py/scripts/addons/mocap/__init__.py
===================================================================
--- trunk/py/scripts/addons/mocap/__init__.py	2011-09-23 09:28:59 UTC (rev 2349)
+++ trunk/py/scripts/addons/mocap/__init__.py	2011-09-23 20:39:48 UTC (rev 2350)
@@ -53,11 +53,19 @@
     from . import mocap_constraints
     from . import retarget
     from . import mocap_tools
+    
 
 # MocapConstraint class
 # Defines MocapConstraint datatype, used to add and configute mocap constraints
 # Attached to Armature data
 
+def hasIKConstraint(pose_bone):
+    #utility function / predicate, returns True if given bone has IK constraint
+    ik = [constraint for constraint in pose_bone.constraints if constraint.type == "IK"]
+    if ik:
+        return ik[0]
+    else:
+        return False
 
 class MocapConstraint(bpy.types.PropertyGroup):
     name = StringProperty(name="Name",

Modified: trunk/py/scripts/addons/mocap/retarget.py
===================================================================
--- trunk/py/scripts/addons/mocap/retarget.py	2011-09-23 09:28:59 UTC (rev 2349)
+++ trunk/py/scripts/addons/mocap/retarget.py	2011-09-23 20:39:48 UTC (rev 2350)
@@ -21,7 +21,7 @@
 import bpy
 from mathutils import Vector, Matrix
 from math import radians
-from bl_operators import nla
+from bpy_extras.anim_utils import bake_action
 
 
 def hasIKConstraint(pose_bone):
@@ -292,15 +292,15 @@
     if linearAvg:
         #determine the average change in scale needed
         avg = sum(linearAvg) / len(linearAvg)
-        scene.frame_set(s_frame)
-        initialPos = (tailLoc(perf_bones[perfRoot]) / avg)
-        for t in range(s_frame, e_frame):
-            scene.frame_set(t)
-            #calculate the new position, by dividing by the found ratio between performer and enduser
-            newTranslation = (tailLoc(perf_bones[perfRoot]) / avg)
-            stride_bone.location = enduser_obj_mat * (newTranslation - initialPos)
-            stride_bone.keyframe_insert("location")
     else:
+        avg = 1
+    scene.frame_set(s_frame)
+    initialPos = (tailLoc(perf_bones[perfRoot]) / avg)
+    for t in range(s_frame, e_frame):
+        scene.frame_set(t)
+        #calculate the new position, by dividing by the found ratio between performer and enduser
+        newTranslation = (tailLoc(perf_bones[perfRoot]) / avg)
+        stride_bone.location = enduser_obj_mat * (newTranslation - initialPos)
         stride_bone.keyframe_insert("location")
     stride_bone.animation_data.action.name = ("Stride Bone " + action_name)
 
@@ -520,8 +520,9 @@
     else:
         prepareForBake(enduser_obj)
         print("Retargeting pose (Advanced Retarget)")
-        nla.bake(s_frame, e_frame, action=enduser_obj.animation_data.action, only_selected=True, do_pose=True, do_object=False, step=step)
-    name = performer_obj.animation_data.action.name
+        bake_action(s_frame, e_frame, action=enduser_obj.animation_data.action, only_selected=True, do_pose=True, do_object=False, step=step)
+    name = performer_obj.animation_data.action.name[:10]
+    #We trim the name down to 10 chars because of Action Name length maximum
     enduser_obj.animation_data.action.name = "Base " + name
     print("Second pass: retargeting root translation and clean up")
     stride_bone = copyTranslation(performer_obj, enduser_obj, feetBones, root, s_frame, e_frame, scene, enduser_obj_mat)



More information about the Bf-extensions-cvs mailing list