Added smoothing variables to constraint creation, and now Active checkbox is functional.Also initial work was done on the freeze constraint.

This commit is contained in:
Benjy Cook 2011-07-03 21:25:54 +00:00
parent 775ab37ad5
commit e358064704
2 changed files with 53 additions and 20 deletions

@ -41,6 +41,12 @@ def getConsObj(bone):
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 @@ def addNewConstraint(m_constraint, cons_obj):
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,21 +68,14 @@ def removeConstraint(m_constraint, cons_obj):
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
#If the constraint exists, we need to remove it
#Then create a new one.
def updateConstraintTargetBone(m_constraint, context):
def updateConstraintBoneType(m_constraint, context):
#If the constraint exists, we need to remove it
#from the old bone
obj = context.active_object
@ -103,7 +102,10 @@ def setConstraint(m_constraint):
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 @@ def setConstraint(m_constraint):
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 @@ def setConstraint(m_constraint):
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

@ -37,7 +37,7 @@ class MocapConstraint(bpy.types.PropertyGroup):
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 @@ class MocapConstraint(bpy.types.PropertyGroup):
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 @@ class MocapConstraint(bpy.types.PropertyGroup):
("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 @@ class MocapConstraintsPanel(bpy.types.Panel):
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 @@ def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
register()