Finished Freeze constraint, and target space option for Freeze and Point constraints.
authorBenjy Cook <benjycook@hotmail.com>
Mon, 4 Jul 2011 11:35:29 +0000 (11:35 +0000)
committerBenjy Cook <benjycook@hotmail.com>
Mon, 4 Jul 2011 11:35:29 +0000 (11:35 +0000)
release/scripts/modules/mocap_constraints.py
release/scripts/modules/retarget.py
release/scripts/startup/ui_mocap.py

index 1892988c63996d8506e8a4dfbe29ca33d5844a89..e12d510a6f942ad0ef93c2fb639a720d2584d61e 100644 (file)
@@ -23,7 +23,6 @@ from mathutils import *
 
 ### Utility Functions
 
-
 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])
@@ -85,9 +84,10 @@ def updateConstraintBoneType(m_constraint, context):
         cons_obj = getConsObj(bone)
         removeConstraint(m_constraint, cons_obj)
     #Regardless, after that we create a new constraint
-    bone = bones[m_constraint.constrained_bone]
-    cons_obj = getConsObj(bone)
-    addNewConstraint(m_constraint, cons_obj)
+    if m_constraint.constrained_bone:
+        bone = bones[m_constraint.constrained_bone]
+        cons_obj = getConsObj(bone)
+        addNewConstraint(m_constraint, cons_obj)
 
 
 # Function that copies all settings from m_constraint to the real Blender constraints
@@ -106,6 +106,7 @@ def setConstraint(m_constraint):
         fcurves = obj.animation_data.action.fcurves
     else:
         fcurves = cons_obj.animation_data.action.fcurves
+        
     influence_RNA = real_constraint.path_from_id("influence")
     fcurve = [fcurve for fcurve in fcurves if fcurve.data_path == influence_RNA]
     #clear the fcurve and set the frames.
@@ -120,11 +121,10 @@ def setConstraint(m_constraint):
     real_constraint.keyframe_insert(data_path="influence", frame=e)
     real_constraint.influence = 0
     real_constraint.keyframe_insert(data_path="influence", frame=s - s_in)
-    real_constraint.keyframe_insert(data_path="influence", frame=e + s_out)
-
+    real_constraint.keyframe_insert(data_path="influence", frame=e + s_out)   
     #Set the blender constraint parameters
     if m_constraint.type == "point":
-        real_constraint.target_space = "WORLD"  # temporary for now, just World is supported
+        real_constraint.owner_space = m_constraint.targetSpace
         x, y, z = m_constraint.targetPoint
         real_constraint.max_x = x
         real_constraint.max_y = y
@@ -140,9 +140,13 @@ def setConstraint(m_constraint):
         real_constraint.use_min_z = True
 
     if m_constraint.type == "freeze":
-        real_constraint.target_space = "WORLD" 
-        bpy.context.scene.frame_set(m_constraint.s_frame)
-        x, y, z = cons_obj.location.copy()
+        real_constraint.owner_space = m_constraint.targetSpace 
+        bpy.context.scene.frame_set(s)
+        if isinstance(cons_obj, bpy.types.PoseBone):
+            x, y, z = cons_obj.center + (cons_obj.vector / 2)
+        else:
+            x, y, z = cons_obj.matrix_world.to_translation()
+
         real_constraint.max_x = x
         real_constraint.max_y = y
         real_constraint.max_z = z
index 64b9bb51eed7f747e9447b812ef8bffef6f2ea0a..9a3ed4b70cbd1fe1f0bd004f49ac458285fc772c 100644 (file)
@@ -348,6 +348,7 @@ def restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, str
             empty.parent = stride_bone
     performer_obj.matrix_world = perf_obj_mat
     enduser_obj.matrix_world = enduser_obj_mat
+    enduser_obj.parent = stride_bone
 
 
 def totalRetarget():
index f4762f38c547196594fbe5155078063195f5ce8d..71d291fd014f5961ea31973bcf3bd4fc84e52d64 100644 (file)
@@ -22,6 +22,15 @@ import bpy
 
 from bpy.props import *
 from bpy import *
+import mocap_constraints
+import retarget
+import mocap_tools
+### reloads modules (for testing purposes only)
+from imp import reload
+reload(mocap_constraints)
+reload(retarget)
+reload(mocap_tools)
+
 from mocap_constraints import *
 
 # MocapConstraint class
@@ -72,17 +81,13 @@ class MocapConstraint(bpy.types.PropertyGroup):
         default=False,
         description="Constraint has been baked to NLA layer",
         update=updateConstraint)
-    targetFrame = bpy.props.IntProperty(name="Frame",
-        default=1,
-        description="Target of Constraint - Frame (optional, depends on type)",
-        update=updateConstraint)
     targetPoint = bpy.props.FloatVectorProperty(name="Point", size=3,
         subtype="XYZ", default=(0.0, 0.0, 0.0),
         description="Target of Constraint - Point",
         update=updateConstraint)
     targetSpace = bpy.props.EnumProperty(
-        items=[("world", "World Space", "Evaluate target in global space"),
-            ("object", "Object space", "Evaluate target in object space"),
+        items=[("WORLD", "World Space", "Evaluate target in global space"),
+            ("LOCAL", "Object space", "Evaluate target in object space"),
             ("constrained_boneB", "Other Bone Space", "Evaluate target in specified other bone space")],
         name="Space",
         description="In which space should Point type target be evaluated",
@@ -111,7 +116,11 @@ def toggleIKBone(self, context):
             print(self.name + " IK toggled ON!")
             ik = self.constraints.new('IK')
             #ik the whole chain up to the root, excluding
-            chainLen = len(self.bone.parent_recursive)
+            chainLen = 0
+            for parent_bone in self.parent_recursive:
+                chainLen+=1
+                if hasIKConstraint(parent_bone):
+                    break
             ik.chain_count = chainLen
             for bone in self.parent_recursive:
                 if bone.is_in_ik_chain:
@@ -159,10 +168,6 @@ def updateIKRetarget():
 
 updateIKRetarget()
 
-import retarget
-import mocap_tools
-
-
 class MocapPanel(bpy.types.Panel):
     # Motion capture retargeting panel
     bl_label = "Mocap tools"
@@ -251,11 +256,10 @@ class MocapConstraintsPanel(bpy.types.Panel):
                         targetPropCol = targetRow.column()
                         if m_constraint.type == "floor":
                             targetPropCol.prop_search(m_constraint, 'targetMesh', bpy.data, "objects")
-                        if m_constraint.type == "freeze":
-                            targetPropCol.prop(m_constraint, 'targetFrame')
+                        if m_constraint.type == "point" or m_constraint.type == "freeze":
+                            box.prop(m_constraint, 'targetSpace')
                         if m_constraint.type == "point":
                             targetPropCol.prop(m_constraint, 'targetPoint')
-                            box.prop(m_constraint, 'targetSpace')
                         checkRow = box.row()
                         checkRow.prop(m_constraint, 'active')
                         checkRow.prop(m_constraint, 'baked')