[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38074] branches/soc-2011-pepper/release/ scripts: Added smoothing variables to constraint creation, and now Active checkbox is functional. Also initial work was done on the freeze constraint.

Benjy Cook benjycook at hotmail.com
Sun Jul 3 23:25:54 CEST 2011


Revision: 38074
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38074
Author:   benjycook
Date:     2011-07-03 21:25:54 +0000 (Sun, 03 Jul 2011)
Log Message:
-----------
Added smoothing variables to constraint creation, and now Active checkbox is functional.Also initial work was done on the freeze constraint.

Modified Paths:
--------------
    branches/soc-2011-pepper/release/scripts/modules/mocap_constraints.py
    branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py

Modified: branches/soc-2011-pepper/release/scripts/modules/mocap_constraints.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/modules/mocap_constraints.py	2011-07-03 21:23:41 UTC (rev 38073)
+++ branches/soc-2011-pepper/release/scripts/modules/mocap_constraints.py	2011-07-03 21:25:54 UTC (rev 38074)
@@ -41,6 +41,12 @@
         cons_obj = bone
     return cons_obj
 
+def consObjToBone(cons_obj):
+    if cons_obj.name[-3:] == "Org":
+        return cons_obj.name[:-3]
+    else:
+        return cons_obj.name
+
 ### And and Remove Constraints (called from operators)
 
 
@@ -53,7 +59,7 @@
         c_type = "FLOOR"
     real_constraint = cons_obj.constraints.new(c_type)
     real_constraint.name = "Mocap constraint " + str(len(cons_obj.constraints))
-    m_constraint.real_constraint_bone = cons_obj.name
+    m_constraint.real_constraint_bone = consObjToBone(cons_obj)
     m_constraint.real_constraint = real_constraint.name
     setConstraint(m_constraint)
 
@@ -62,22 +68,15 @@
     oldConstraint = cons_obj.constraints[m_constraint.real_constraint]
     cons_obj.constraints.remove(oldConstraint)
 
-### Update functions. There are 3: UpdateType, UpdateBone
+### Update functions. There are 2: UpdateType/UpdateBone
 ### and update for the others.
 
 
 def updateConstraint(self, context):
     setConstraint(self)
 
-
-def updateConstraintType(m_constraint, context):
-    pass
+def updateConstraintBoneType(m_constraint, context):
     #If the constraint exists, we need to remove it
-    #Then create a new one.
-
-
-def updateConstraintTargetBone(m_constraint, context):
-    #If the constraint exists, we need to remove it
     #from the old bone
     obj = context.active_object
     bones = obj.pose.bones
@@ -103,7 +102,10 @@
     real_constraint = cons_obj.constraints[m_constraint.real_constraint]
 
     #frame changing section
-    fcurves = obj.animation_data.action.fcurves
+    if isinstance(cons_obj, bpy.types.PoseBone):
+        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.
@@ -111,17 +113,14 @@
         fcurve = fcurve[0]
         for i in range(len(fcurve.keyframe_points) - 1, 0, -1):
             fcurve.keyframe_points.remove(fcurve.keyframe_points[i])
-    s, e = bpy.context.scene.frame_start, bpy.context.scene.frame_end
-    real_constraint.influence = 0
-    real_constraint.keyframe_insert(data_path="influence", frame=s)
-    real_constraint.keyframe_insert(data_path="influence", frame=e)
     s, e = m_constraint.s_frame, m_constraint.e_frame
+    s_in, s_out = m_constraint.smooth_in, m_constraint.smooth_out
     real_constraint.influence = 1
     real_constraint.keyframe_insert(data_path="influence", frame=s)
     real_constraint.keyframe_insert(data_path="influence", frame=e)
     real_constraint.influence = 0
-    real_constraint.keyframe_insert(data_path="influence", frame=s - 10)
-    real_constraint.keyframe_insert(data_path="influence", frame=e + 10)
+    real_constraint.keyframe_insert(data_path="influence", frame=s - s_in)
+    real_constraint.keyframe_insert(data_path="influence", frame=e + s_out)
 
     #Set the blender constraint parameters
     if m_constraint.type == "point":
@@ -139,3 +138,23 @@
         real_constraint.use_min_x = True
         real_constraint.use_min_y = True
         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.max_x = x
+        real_constraint.max_y = y
+        real_constraint.max_z = z
+        real_constraint.min_x = x
+        real_constraint.min_y = y
+        real_constraint.min_z = z
+        real_constraint.use_max_x = True
+        real_constraint.use_max_y = True
+        real_constraint.use_max_z = True
+        real_constraint.use_min_x = True
+        real_constraint.use_min_y = True
+        real_constraint.use_min_z = True
+    
+    # active check
+    real_constraint.mute = not m_constraint.active
\ No newline at end of file

Modified: branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py	2011-07-03 21:23:41 UTC (rev 38073)
+++ branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py	2011-07-03 21:25:54 UTC (rev 38074)
@@ -37,7 +37,7 @@
     constrained_bone = bpy.props.StringProperty(name="Bone",
         default="",
         description="Constrained Bone",
-        update=updateConstraintTargetBone)
+        update=updateConstraintBoneType)
     constrained_boneB = bpy.props.StringProperty(name="Bone (2)",
         default="",
         description="Other Constrained Bone (optional, depends on type)",
@@ -50,6 +50,16 @@
         default=500,
         description="End frame of constrain",
         update=updateConstraint)
+    smooth_in = bpy.props.IntProperty(name="In",
+        default=10,
+        description="Amount of frames to smooth in",
+        update=updateConstraint,
+        min=0)
+    smooth_out = bpy.props.IntProperty(name="Out",
+        default=10,
+        description="Amount of frames to smooth out",
+        update=updateConstraint,
+        min=0)
     targetMesh = bpy.props.StringProperty(name="Mesh",
         default="",
         description="Target of Constraint - Mesh (optional, depends on type)",
@@ -83,7 +93,7 @@
             ("floor", "Stay above", "Bone does not cross specified mesh object eg floor"),
             ("distance", "Maintain distance", "Target bones maintained specified distance")],
         description="Type of constraint",
-        update=updateConstraint)
+        update=updateConstraintBoneType)
     real_constraint = bpy.props.StringProperty()
     real_constraint_bone = bpy.props.StringProperty()
 
@@ -231,6 +241,10 @@
                         frameRow.label("Frame Range:")
                         frameRow.prop(m_constraint, 's_frame')
                         frameRow.prop(m_constraint, 'e_frame')
+                        smoothRow = box.row()
+                        smoothRow.label("Smoothing:")
+                        smoothRow.prop(m_constraint, 'smooth_in')
+                        smoothRow.prop(m_constraint, 'smooth_out')
                         targetRow = box.row()
                         targetLabelCol = targetRow.column()
                         targetLabelCol.label("Target settings:")
@@ -329,4 +343,4 @@
     bpy.utils.unregister_module(__name__)
 
 if __name__ == "__main__":
-    register()
+    register()
\ No newline at end of file




More information about the Bf-blender-cvs mailing list