forked from bartvdbraak/blender
Continued changes to storing of retargeted animation data, making it possible to easily switch between all retargeted clips, and stitch them with the future operator
This commit is contained in:
parent
11d4cfaa71
commit
8afad10f98
@ -186,6 +186,8 @@ def setConstraint(m_constraint, context):
|
|||||||
bone = bones[m_constraint.constrained_bone]
|
bone = bones[m_constraint.constrained_bone]
|
||||||
cons_obj = getConsObj(bone)
|
cons_obj = getConsObj(bone)
|
||||||
real_constraint = cons_obj.constraints[m_constraint.real_constraint]
|
real_constraint = cons_obj.constraints[m_constraint.real_constraint]
|
||||||
|
NLATracks = obj.data.mocapNLATracks[obj.data.active_mocap]
|
||||||
|
obj.animation_data.action = bpy.data.actions[NLATracks.auto_fix_track]
|
||||||
|
|
||||||
#frame changing section
|
#frame changing section
|
||||||
setConstraintFraming(m_constraint, context)
|
setConstraintFraming(m_constraint, context)
|
||||||
@ -364,8 +366,9 @@ def bakeAllConstraints(obj, s_frame, e_frame, bones):
|
|||||||
simpleBake += [end_bone]
|
simpleBake += [end_bone]
|
||||||
for bone in selectedBones:
|
for bone in selectedBones:
|
||||||
bone.bone.select = True
|
bone.bone.select = True
|
||||||
tracks = [track for track in obj.data.mocapNLATracks if track.active][0]
|
NLATracks = obj.data.mocapNLATracks[obj.data.active_mocap]
|
||||||
constraintTrack = obj.animation_data.nla_tracks[tracks.auto_fix_track]
|
obj.animation_data.action = bpy.data.actions[NLATracks.auto_fix_track]
|
||||||
|
constraintTrack = obj.animation_data.nla_tracks[NLATracks.auto_fix_track]
|
||||||
constraintStrip = constraintTrack.strips[0]
|
constraintStrip = constraintTrack.strips[0]
|
||||||
constraintStrip.action_frame_start = s_frame
|
constraintStrip.action_frame_start = s_frame
|
||||||
constraintStrip.action_frame_end = e_frame
|
constraintStrip.action_frame_end = e_frame
|
||||||
@ -404,8 +407,9 @@ def unbakeConstraints(context):
|
|||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
bones = obj.pose.bones
|
bones = obj.pose.bones
|
||||||
scene = bpy.context.scene
|
scene = bpy.context.scene
|
||||||
tracks = obj.data.mocapNLATracks[obj.animation_data.action]
|
NLATracks = obj.data.mocapNLATracks[obj.data.active_mocap]
|
||||||
constraintTrack = obj.animation_data.nla_tracks[tracks.auto_fix_track]
|
obj.animation_data.action = bpy.data.actions[NLATracks.auto_fix_track]
|
||||||
|
constraintTrack = obj.animation_data.nla_tracks[NLATracks.auto_fix_track]
|
||||||
constraintStrip = constraintTrack.strips[0]
|
constraintStrip = constraintTrack.strips[0]
|
||||||
action = constraintStrip.action
|
action = constraintStrip.action
|
||||||
# delete the fcurves on the strip
|
# delete the fcurves on the strip
|
||||||
|
@ -52,7 +52,6 @@ def createDictionary(perf_arm, end_arm):
|
|||||||
feetBones = [bone.name for bone in perf_arm.bones if bone.foot]
|
feetBones = [bone.name for bone in perf_arm.bones if bone.foot]
|
||||||
return feetBones, root
|
return feetBones, root
|
||||||
|
|
||||||
|
|
||||||
def loadMapping(perf_arm, end_arm):
|
def loadMapping(perf_arm, end_arm):
|
||||||
|
|
||||||
for end_bone in end_arm.bones:
|
for end_bone in end_arm.bones:
|
||||||
@ -273,8 +272,8 @@ def copyTranslation(performer_obj, enduser_obj, perfFeet, root, s_frame, e_frame
|
|||||||
linearAvg.append(hipV.length / endV.length)
|
linearAvg.append(hipV.length / endV.length)
|
||||||
|
|
||||||
action_name = performer_obj.animation_data.action.name
|
action_name = performer_obj.animation_data.action.name
|
||||||
#if you have a parent, and that parent is a previously created stride bone
|
#is there a stride_bone?
|
||||||
if enduser_obj.parent:
|
if "stride_bone" in bpy.data.objects:
|
||||||
stride_action = bpy.data.actions.new("Stride Bone " + action_name)
|
stride_action = bpy.data.actions.new("Stride Bone " + action_name)
|
||||||
stride_bone = enduser_obj.parent
|
stride_bone = enduser_obj.parent
|
||||||
stride_bone.animation_data.action = stride_action
|
stride_bone.animation_data.action = stride_action
|
||||||
@ -386,17 +385,17 @@ def originalLocationTarget(end_bone, enduser_obj):
|
|||||||
|
|
||||||
|
|
||||||
#create the specified NLA setup for base animation, constraints and tweak layer.
|
#create the specified NLA setup for base animation, constraints and tweak layer.
|
||||||
def NLASystemInitialize(enduser_obj, s_frame, name):
|
def NLASystemInitialize(enduser_arm, context):#enduser_obj, name):
|
||||||
|
enduser_obj = context.active_object
|
||||||
|
NLATracks = enduser_arm.mocapNLATracks[enduser_obj.data.active_mocap]
|
||||||
|
name = NLATracks.name
|
||||||
anim_data = enduser_obj.animation_data
|
anim_data = enduser_obj.animation_data
|
||||||
if not name in enduser_obj.data.mocapNLATracks:
|
s_frame = 0
|
||||||
NLATracks = enduser_obj.data.mocapNLATracks.add()
|
print(name)
|
||||||
NLATracks.name = name
|
if ("Base " + name) in bpy.data.actions:
|
||||||
|
mocapAction = bpy.data.actions[("Base " + name)]
|
||||||
else:
|
else:
|
||||||
NLATracks = enduser_obj.data.mocapNLATracks[name]
|
print("That retargeted anim has no base action")
|
||||||
for track in enduser_obj.data.mocapNLATracks:
|
|
||||||
track.active = False
|
|
||||||
mocapAction = anim_data.action
|
|
||||||
mocapAction.name = "Base " + name
|
|
||||||
anim_data.use_nla = True
|
anim_data.use_nla = True
|
||||||
for track in anim_data.nla_tracks:
|
for track in anim_data.nla_tracks:
|
||||||
anim_data.nla_tracks.remove(track)
|
anim_data.nla_tracks.remove(track)
|
||||||
@ -407,28 +406,46 @@ def NLASystemInitialize(enduser_obj, s_frame, name):
|
|||||||
constraintTrack = anim_data.nla_tracks.new()
|
constraintTrack = anim_data.nla_tracks.new()
|
||||||
constraintTrack.name = "Auto fixes " + name
|
constraintTrack.name = "Auto fixes " + name
|
||||||
NLATracks.auto_fix_track = constraintTrack.name
|
NLATracks.auto_fix_track = constraintTrack.name
|
||||||
constraintAction = bpy.data.actions.new("Auto fixes " + name)
|
if ("Auto fixes " + name) in bpy.data.actions:
|
||||||
|
constraintAction = bpy.data.actions[("Auto fixes " + name)]
|
||||||
|
else:
|
||||||
|
constraintAction = bpy.data.actions.new("Auto fixes " + name)
|
||||||
constraintStrip = constraintTrack.strips.new("Auto fixes " + name, s_frame, constraintAction)
|
constraintStrip = constraintTrack.strips.new("Auto fixes " + name, s_frame, constraintAction)
|
||||||
constraintStrip.extrapolation = "NOTHING"
|
constraintStrip.extrapolation = "NOTHING"
|
||||||
userTrack = anim_data.nla_tracks.new()
|
userTrack = anim_data.nla_tracks.new()
|
||||||
userTrack.name = "Manual fixes " + name
|
userTrack.name = "Manual fixes " + name
|
||||||
NLATracks.manual_fix_track = userTrack.name
|
NLATracks.manual_fix_track = userTrack.name
|
||||||
if enduser_obj.parent.animation_data:
|
if ("Manual fixes " + name) in bpy.data.actions:
|
||||||
NLATracks.stride_action = enduser_obj.parent.animation_data.action.name
|
userAction = bpy.data.actions[("Manual fixes " + name)]
|
||||||
userAction = bpy.data.actions.new("Manual fixes " + name)
|
else:
|
||||||
|
userAction = bpy.data.actions.new("Manual fixes " + name)
|
||||||
userStrip = userTrack.strips.new("Manual fixes " + name, s_frame, userAction)
|
userStrip = userTrack.strips.new("Manual fixes " + name, s_frame, userAction)
|
||||||
userStrip.extrapolation = "HOLD"
|
userStrip.extrapolation = "HOLD"
|
||||||
#userStrip.blend_type = "MULITPLY" - doesn't work due to work, will be activated soon
|
#userStrip.blend_type = "MULITPLY" - doesn't work due to work, will be activated soon
|
||||||
anim_data.nla_tracks.active = constraintTrack
|
anim_data.nla_tracks.active = constraintTrack
|
||||||
NLATracks.active = True
|
|
||||||
#anim_data.action = constraintAction
|
#anim_data.action = constraintAction
|
||||||
anim_data.action_extrapolation = "NOTHING"
|
anim_data.action_extrapolation = "NOTHING"
|
||||||
|
#set the stride_bone's action
|
||||||
|
if "stride_bone" in bpy.data.objects:
|
||||||
|
stride_bone = bpy.data.objects["stride_bone"]
|
||||||
|
if NLATracks.stride_action:
|
||||||
|
stride_bone.animation_data.action = bpy.data.actions[NLATracks.stride_action]
|
||||||
|
else:
|
||||||
|
NLATracks.stride_action = stride_bone.animation_data.action.name
|
||||||
|
anim_data.action = None
|
||||||
|
|
||||||
|
|
||||||
#Main function that runs the retargeting sequence.
|
#Main function that runs the retargeting sequence.
|
||||||
def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
|
def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
|
||||||
perf_arm = performer_obj.data
|
perf_arm = performer_obj.data
|
||||||
end_arm = enduser_obj.data
|
end_arm = enduser_obj.data
|
||||||
|
|
||||||
|
try:
|
||||||
|
enduser_obj.animation_data.action = bpy.data.actions.new("temp")
|
||||||
|
except:
|
||||||
|
print("no need to create new action")
|
||||||
|
|
||||||
|
|
||||||
print("creating Dictionary")
|
print("creating Dictionary")
|
||||||
feetBones, root = createDictionary(perf_arm, end_arm)
|
feetBones, root = createDictionary(perf_arm, end_arm)
|
||||||
print("cleaning stuff up")
|
print("cleaning stuff up")
|
||||||
@ -437,7 +454,11 @@ def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
|
|||||||
print("Creating intermediate armature (for first pass)")
|
print("Creating intermediate armature (for first pass)")
|
||||||
inter_obj = createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene)
|
inter_obj = createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene)
|
||||||
print("First pass: retargeting from intermediate to end user")
|
print("First pass: retargeting from intermediate to end user")
|
||||||
|
|
||||||
|
|
||||||
retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene)
|
retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene)
|
||||||
|
name = performer_obj.animation_data.action.name
|
||||||
|
enduser_obj.animation_data.action.name = "Base " + name
|
||||||
print("Second pass: retargeting root translation and clean up")
|
print("Second pass: retargeting root translation and clean up")
|
||||||
stride_bone = copyTranslation(performer_obj, enduser_obj, feetBones, root, s_frame, e_frame, scene, enduser_obj_mat)
|
stride_bone = copyTranslation(performer_obj, enduser_obj, feetBones, root, s_frame, e_frame, scene, enduser_obj_mat)
|
||||||
IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene)
|
IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene)
|
||||||
@ -445,7 +466,14 @@ def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
|
|||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_name(name=inter_obj.name, extend=False)
|
bpy.ops.object.select_name(name=inter_obj.name, extend=False)
|
||||||
bpy.ops.object.delete()
|
bpy.ops.object.delete()
|
||||||
NLASystemInitialize(enduser_obj, s_frame, performer_obj.animation_data.action.name)
|
bpy.ops.object.select_name(name=enduser_obj.name, extend=False)
|
||||||
|
|
||||||
|
if not name in [tracks.name for tracks in end_arm.mocapNLATracks]:
|
||||||
|
NLATracks = end_arm.mocapNLATracks.add()
|
||||||
|
NLATracks.name = name
|
||||||
|
else:
|
||||||
|
NLATracks = end_arm.mocapNLATracks[name]
|
||||||
|
end_arm.active_mocap = name
|
||||||
print("retargeting done!")
|
print("retargeting done!")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -127,7 +127,6 @@ bpy.utils.register_class(AnimationStitchSettings)
|
|||||||
|
|
||||||
class MocapNLATracks(bpy.types.PropertyGroup):
|
class MocapNLATracks(bpy.types.PropertyGroup):
|
||||||
name = bpy.props.StringProperty()
|
name = bpy.props.StringProperty()
|
||||||
active = bpy.props.BoolProperty()
|
|
||||||
base_track = bpy.props.StringProperty()
|
base_track = bpy.props.StringProperty()
|
||||||
auto_fix_track = bpy.props.StringProperty()
|
auto_fix_track = bpy.props.StringProperty()
|
||||||
manual_fix_track = bpy.props.StringProperty()
|
manual_fix_track = bpy.props.StringProperty()
|
||||||
@ -136,7 +135,7 @@ class MocapNLATracks(bpy.types.PropertyGroup):
|
|||||||
bpy.utils.register_class(MocapNLATracks)
|
bpy.utils.register_class(MocapNLATracks)
|
||||||
|
|
||||||
bpy.types.Armature.stitch_settings = bpy.props.PointerProperty(type=AnimationStitchSettings)
|
bpy.types.Armature.stitch_settings = bpy.props.PointerProperty(type=AnimationStitchSettings)
|
||||||
|
bpy.types.Armature.active_mocap = bpy.props.StringProperty(update=retarget.NLASystemInitialize)
|
||||||
bpy.types.Armature.mocapNLATracks = bpy.props.CollectionProperty(type=MocapNLATracks)
|
bpy.types.Armature.mocapNLATracks = bpy.props.CollectionProperty(type=MocapNLATracks)
|
||||||
|
|
||||||
#Update function for IK functionality. Is called when IK prop checkboxes are toggled.
|
#Update function for IK functionality. Is called when IK prop checkboxes are toggled.
|
||||||
@ -349,6 +348,8 @@ class ExtraToolsPanel(bpy.types.Panel):
|
|||||||
activeIsArmature = isinstance(context.active_object.data, bpy.types.Armature)
|
activeIsArmature = isinstance(context.active_object.data, bpy.types.Armature)
|
||||||
if activeIsArmature:
|
if activeIsArmature:
|
||||||
enduser_arm = context.active_object.data
|
enduser_arm = context.active_object.data
|
||||||
|
layout.label("Retargeted Animations:")
|
||||||
|
layout.prop_search(enduser_arm, "active_mocap",enduser_arm, "mocapNLATracks")
|
||||||
settings = enduser_arm.stitch_settings
|
settings = enduser_arm.stitch_settings
|
||||||
layout.prop_search(settings, "first_action", enduser_arm, "mocapNLATracks")
|
layout.prop_search(settings, "first_action", enduser_arm, "mocapNLATracks")
|
||||||
layout.prop_search(settings, "second_action", enduser_arm, "mocapNLATracks")
|
layout.prop_search(settings, "second_action", enduser_arm, "mocapNLATracks")
|
||||||
|
Loading…
Reference in New Issue
Block a user