Added One-Sided distance constraint. Also fixed some bugs and syntax in constraint and retarget scripts

This commit is contained in:
2011-07-05 10:56:34 +00:00
parent 90e8b83b45
commit 04c03db6af
2 changed files with 17 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ from mathutils import *
### Utility Functions ### Utility Functions
def hasIKConstraint(pose_bone): def hasIKConstraint(pose_bone):
#utility function / predicate, returns True if given bone has IK constraint #utility function / predicate, returns True if given bone has IK constraint
return ("IK" in [constraint.type for constraint in pose_bone.constraints]) return ("IK" in [constraint.type for constraint in pose_bone.constraints])
@@ -40,6 +41,7 @@ def getConsObj(bone):
cons_obj = bone cons_obj = bone
return cons_obj return cons_obj
def consObjToBone(cons_obj): def consObjToBone(cons_obj):
if cons_obj.name[-3:] == "Org": if cons_obj.name[-3:] == "Org":
return cons_obj.name[:-3] return cons_obj.name[:-3]
@@ -74,6 +76,7 @@ def removeConstraint(m_constraint, cons_obj):
def updateConstraint(self, context): def updateConstraint(self, context):
setConstraint(self) setConstraint(self)
def updateConstraintBoneType(m_constraint, context): def updateConstraintBoneType(m_constraint, context):
#If the constraint exists, we need to remove it #If the constraint exists, we need to remove it
#from the old bone #from the old bone
@@ -160,5 +163,11 @@ def setConstraint(m_constraint):
real_constraint.use_min_y = True real_constraint.use_min_y = True
real_constraint.use_min_z = True real_constraint.use_min_z = True
if m_constraint.type == "distance" and m_constraint.constrained_boneB:
real_constraint.owner_space = "WORLD"
real_constraint.target = getConsObj(bones[m_constraint.constrained_boneB])
real_constraint.limit_mode = "LIMITDIST_ONSURFACE"
real_constraint.distance = m_constraint.targetDist
# active check # active check
real_constraint.mute = not m_constraint.active real_constraint.mute = not m_constraint.active

View File

@@ -200,7 +200,7 @@ def retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene):
for t in range(s_frame, e_frame): for t in range(s_frame, e_frame):
scene.frame_set(t) scene.frame_set(t)
end_bone = end_bones[root] end_bone = end_bones[root]
end_bone.location = Vector((0,0,0)) end_bone.location = Vector((0, 0, 0))
end_bone.keyframe_insert("location") end_bone.keyframe_insert("location")
bakeTransform(end_bone) bakeTransform(end_bone)
@@ -369,7 +369,7 @@ def totalRetarget():
turnOffIK(enduser_obj) turnOffIK(enduser_obj)
inter_obj, inter_arm = createIntermediate(performer_obj, enduser_obj, bonemap, bonemapr, root, s_frame, e_frame, scene) inter_obj, inter_arm = createIntermediate(performer_obj, enduser_obj, bonemap, bonemapr, root, s_frame, e_frame, scene)
retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene) retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene)
stride_bone = copyTranslation(performer_obj, enduser_obj, ["RightFoot", "LeftFoot"], bonemap, bonemapr, root, s_frame, e_frame, scene,enduser_obj_mat) stride_bone = copyTranslation(performer_obj, enduser_obj, ["RightFoot", "LeftFoot"], bonemap, bonemapr, root, s_frame, e_frame, scene, enduser_obj_mat)
IKRetarget(bonemap, bonemapr, performer_obj, enduser_obj, s_frame, e_frame, scene) IKRetarget(bonemap, bonemapr, performer_obj, enduser_obj, s_frame, e_frame, scene)
restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, stride_bone) restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, stride_bone)
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')