forked from bartvdbraak/blender
Finished Freeze constraint, and target space option for Freeze and Point constraints.
This commit is contained in:
parent
de1c4fafc7
commit
a552d8e610
@ -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
|
||||
|
@ -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():
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user