[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38209] branches/soc-2011-salad: Merging r38196 through r38208 from soc-2011-pepper into soc-2011-salad

Sergey Sharybin g.ulairi at gmail.com
Thu Jul 7 23:04:52 CEST 2011


Revision: 38209
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38209
Author:   nazgul
Date:     2011-07-07 21:04:52 +0000 (Thu, 07 Jul 2011)
Log Message:
-----------
Merging r38196 through r38208 from soc-2011-pepper into soc-2011-salad

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38196
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38208

Modified Paths:
--------------
    branches/soc-2011-salad/release/scripts/modules/mocap_constraints.py
    branches/soc-2011-salad/release/scripts/modules/retarget.py
    branches/soc-2011-salad/release/scripts/startup/bl_operators/nla.py
    branches/soc-2011-salad/release/scripts/startup/ui_mocap.py
    branches/soc-2011-salad/source/blender/collada/AnimationExporter.cpp
    branches/soc-2011-salad/source/blender/collada/AnimationImporter.cpp
    branches/soc-2011-salad/source/blender/collada/AnimationImporter.h
    branches/soc-2011-salad/source/blender/collada/CameraExporter.cpp
    branches/soc-2011-salad/source/blenderplayer/bad_level_call_stubs/stubs.c

Property Changed:
----------------
    branches/soc-2011-salad/


Property changes on: branches/soc-2011-salad
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-30783,30792-30793,30797-30798,30815
/branches/soc-2011-cucumber:36829-36994
/branches/soc-2011-onion:36833-37529
/branches/soc-2011-pepper:36830-38195
/branches/soc-2011-tomato:36831-38205
/trunk/blender:36834-38196
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-30783,30792-30793,30797-30798,30815
/branches/soc-2011-cucumber:36829-36994
/branches/soc-2011-onion:36833-37529
/branches/soc-2011-pepper:36830-38208
/branches/soc-2011-tomato:36831-38205
/trunk/blender:36834-38196

Modified: branches/soc-2011-salad/release/scripts/modules/mocap_constraints.py
===================================================================
--- branches/soc-2011-salad/release/scripts/modules/mocap_constraints.py	2011-07-07 21:02:31 UTC (rev 38208)
+++ branches/soc-2011-salad/release/scripts/modules/mocap_constraints.py	2011-07-07 21:04:52 UTC (rev 38209)
@@ -20,6 +20,7 @@
 
 import bpy
 from mathutils import *
+from bl_operators import nla
 
 ### Utility Functions
 
@@ -96,7 +97,7 @@
 # Function that copies all settings from m_constraint to the real Blender constraints
 # Is only called when blender constraint already exists
 
-def setConstraintFraming(m_constraint, cons_obj, real_constraint):
+def setConstraintFraming(m_constraint, cons_obj, obj, real_constraint):
     if isinstance(cons_obj, bpy.types.PoseBone):
         fcurves = obj.animation_data.action.fcurves
     else:
@@ -129,7 +130,7 @@
     real_constraint = cons_obj.constraints[m_constraint.real_constraint]
 
     #frame changing section
-    setConstraintFraming(m_constraint, cons_obj, real_constraint)
+    setConstraintFraming(m_constraint, cons_obj, obj, real_constraint)
 
     #Set the blender constraint parameters
     if m_constraint.type == "point":
@@ -176,4 +177,92 @@
         real_constraint.distance = m_constraint.targetDist
 
     # active check
-    real_constraint.mute = not m_constraint.active
+    real_constraint.mute = (not m_constraint.active) and (m_constraint.baked)
+
+
+def updateBake(self, context):
+    if self.baked:
+        print("baking...")
+        bakeConstraint(self)
+    else:
+        print("unbaking...")
+        unbakeConstraint(self)
+
+
+def bakeTransformFK(anim_data, s_frame, e_frame, end_bone, bones, cons_obj):
+    mute_ik = False
+    for bone in bones:
+        bone.bone.select = False
+    ik = hasIKConstraint(end_bone)
+    if not isinstance(cons_obj, bpy.types.PoseBone) and ik:
+            if ik.chain_count == 0:
+                selectedBones = bones
+            else:
+                selectedBones = [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1]
+            mute_ik = True
+    else:
+        selectedBones = [end_bone]
+    print(selectedBones)
+    for bone in selectedBones:
+        bone.bone.select = True
+    anim_data.action = nla.bake(s_frame,
+        e_frame, action=anim_data.action)
+    return mute_ik
+
+
+def bakeConstraint(m_constraint):
+    obj = bpy.context.active_object
+    bones = obj.pose.bones
+    end_bone = bones[m_constraint.constrained_bone]
+    cons_obj = getConsObj(end_bone)
+    scene = bpy.context.scene
+    s_frame = scene.frame_start
+    e_frame = scene.frame_end
+    mute_ik = bakeTransformFK(obj.animation_data, s_frame, e_frame, end_bone, bones, cons_obj)
+    if mute_ik:
+        ik_con = hasIKConstraint(end_bone)
+        ik_con.mute = True
+    real_constraint = cons_obj.constraints[m_constraint.real_constraint]
+    real_constraint.mute = True
+    constraintTrack = obj.animation_data.nla_tracks["Mocap constraints"]
+    constraintStrip = constraintTrack.strips[0]
+    constraintStrip.action_frame_start = s_frame
+    constraintStrip.action_frame_end = e_frame
+    constraintStrip.frame_start = s_frame
+    constraintStrip.frame_end = e_frame
+
+
+def unbakeConstraint(m_constraint):
+    # to unbake a constraint we need to delete the whole strip
+    # and rebake all the other constraints
+    obj = bpy.context.active_object
+    bones = obj.pose.bones
+    end_bone = bones[m_constraint.constrained_bone]
+    cons_obj = getConsObj(end_bone)
+    scene = bpy.context.scene
+    s_frame = scene.frame_start
+    e_frame = scene.frame_end
+    constraintTrack = obj.animation_data.nla_tracks["Mocap constraints"]
+    constraintStrip = constraintTrack.strips[0]
+    action = constraintStrip.action
+    for fcurve in action.fcurves:
+        action.fcurves.remove(fcurve)
+    for other_m_constraint in obj.data.mocap_constraints:
+        if m_constraint != other_m_constraint:
+            bakeConstraint(other_m_constraint)
+    # It's a control empty: turn the ik back on
+    if not isinstance(cons_obj, bpy.types.PoseBone):
+        ik_con = hasIKConstraint(end_bone)
+        if ik_con:
+            ik_con.mute = False
+    real_constraint = cons_obj.constraints[m_constraint.real_constraint]
+    real_constraint.mute = False
+
+
+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

Modified: branches/soc-2011-salad/release/scripts/modules/retarget.py
===================================================================
--- branches/soc-2011-salad/release/scripts/modules/retarget.py	2011-07-07 21:02:31 UTC (rev 38208)
+++ branches/soc-2011-salad/release/scripts/modules/retarget.py	2011-07-07 21:04:52 UTC (rev 38209)
@@ -374,6 +374,21 @@
     bpy.ops.object.mode_set(mode='OBJECT')
     bpy.ops.object.select_name(name=inter_obj.name, extend=False)
     bpy.ops.object.delete()
+    anim_data = enduser_obj.animation_data
+    mocapAction = anim_data.action
+    mocapAction.name = "Base Mocap Action"
+    anim_data.use_nla = True
+    mocapTrack = anim_data.nla_tracks.new()
+    mocapTrack.name = "Base Mocap Track"
+    mocapStrip = mocapTrack.strips.new("Base Mocap Action", s_frame, mocapAction)
+    constraintTrack = anim_data.nla_tracks.new()
+    constraintTrack.name = "Mocap constraints"
+    constraintAction = bpy.data.actions.new("Mocap constraints Action")
+    constraintStrip = constraintTrack.strips.new("Mocap constraints Action", s_frame, constraintAction)
+    #constraintStrip.frame_end = e_frame
+    anim_data.nla_tracks.active = constraintTrack
+    anim_data.action = constraintAction
 
+
 if __name__ == "__main__":
     totalRetarget()

Modified: branches/soc-2011-salad/release/scripts/startup/bl_operators/nla.py
===================================================================
--- branches/soc-2011-salad/release/scripts/startup/bl_operators/nla.py	2011-07-07 21:02:31 UTC (rev 38208)
+++ branches/soc-2011-salad/release/scripts/startup/bl_operators/nla.py	2011-07-07 21:04:52 UTC (rev 38209)
@@ -83,7 +83,7 @@
          do_pose=True,
          do_object=True,
          do_constraint_clear=False,
-         ):
+         action=None):
 
     scene = bpy.context.scene
     obj = bpy.context.object
@@ -120,7 +120,8 @@
 
     # incase animation data hassnt been created
     atd = obj.animation_data_create()
-    action = bpy.data.actions.new("Action")
+    if action == None:
+        action = bpy.data.actions.new("Action")
     atd.action = action
 
     if do_pose:
@@ -253,37 +254,38 @@
     def invoke(self, context, event):
         wm = context.window_manager
         return wm.invoke_props_dialog(self)
-        
+
 #################################
 
+
 class ClearUselessActions(bpy.types.Operator):
     '''Mark actions with no F-Curves for deletion after save+reload of file preserving "action libraries"'''
     bl_idname = "anim.clear_useless_actions"
     bl_label = "Clear Useless Actions"
     bl_options = {'REGISTER', 'UNDO'}
-    
-    only_unused = BoolProperty(name="Only Unused", 
+
+    only_unused = BoolProperty(name="Only Unused",
             description="Only unused (Fake User only) actions get considered",
             default=True)
-    
+
     @classmethod
     def poll(cls, context):
         return len(bpy.data.actions) != 0
-        
+
     def execute(self, context):
         removed = 0
-        
+
         for action in bpy.data.actions:
             # if only user is "fake" user...
-            if ((self.only_unused is False) or 
+            if ((self.only_unused is False) or
                 (action.use_fake_user and action.users == 1)):
-                
-                # if it has F-Curves, then it's a "action library" (i.e. walk, wave, jump, etc.) 
+
+                # if it has F-Curves, then it's a "action library" (i.e. walk, wave, jump, etc.)
                 # and should be left alone as that's what fake users are for!
                 if not action.fcurves:
                     # mark action for deletion
                     action.user_clear()
                     removed += 1
-        
+
         self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions" % (removed))
         return {'FINISHED'}

Modified: branches/soc-2011-salad/release/scripts/startup/ui_mocap.py
===================================================================
--- branches/soc-2011-salad/release/scripts/startup/ui_mocap.py	2011-07-07 21:02:31 UTC (rev 38208)
+++ branches/soc-2011-salad/release/scripts/startup/ui_mocap.py	2011-07-07 21:04:52 UTC (rev 38209)
@@ -80,7 +80,7 @@
     baked = bpy.props.BoolProperty(name="Baked / Applied",
         default=False,
         description="Constraint has been baked to NLA layer",
-        update=updateConstraint)
+        update=updateBake)
     targetPoint = bpy.props.FloatVectorProperty(name="Point", size=3,
         subtype="XYZ", default=(0.0, 0.0, 0.0),
         description="Target of Constraint - Point",
@@ -157,11 +157,6 @@
     update=toggleIKBone, default=False)
 
 
-def hasIKConstraint(pose_bone):
-    #utility function / predicate, returns True if given bone has IK constraint
-    return ("IK" in [constraint.type for constraint in pose_bone.constraints])
-
-
 def updateIKRetarget():
     # ensures that Blender constraints and IK properties are in sync
     # currently runs when module is loaded, should run when scene is loaded
@@ -230,8 +225,6 @@
                         else:
                             row.label(" ")

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list