Unify calls to armature and pose library
This commit is contained in:
80
common.py
80
common.py
@ -2,60 +2,31 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
|
||||
def getArmatureObject(context):
|
||||
obj = context.active_object
|
||||
if obj:
|
||||
if obj.type == "ARMATURE":
|
||||
return obj
|
||||
elif obj.parent is not None and obj.parent.type == "ARMATURE":
|
||||
return obj.parent
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def getLegacyPoseLibrary(context):
|
||||
try:
|
||||
arm = getArmatureObject(context)
|
||||
return getattr(arm, "pose_library", None)
|
||||
except:
|
||||
pass
|
||||
def getArmatureData(context):
|
||||
try:
|
||||
arm_object = context.active_object
|
||||
if arm_object and arm_object.type == "ARMATURE":
|
||||
return arm_object, getattr(arm_object, "pose_library", None)
|
||||
elif arm_object and arm_object.parent and arm_object.parent.type == "ARMATURE":
|
||||
return arm_object.parent, getattr(arm_object.parent, "pose_library", None)
|
||||
else:
|
||||
return None, None
|
||||
except:
|
||||
return None, None
|
||||
|
||||
|
||||
def getArmatureAction(context):
|
||||
try:
|
||||
arm = getArmatureObject(context)
|
||||
return getattr(arm.animation_data, "action", None)
|
||||
arm_object, pose_library = getArmatureData(context)
|
||||
if getattr(arm_object.animation_data.action, "pose_markers", None):
|
||||
return getattr(arm_object.animation_data, "action", None)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def getDsplAction(context):
|
||||
try:
|
||||
arm = getArmatureObject(context)
|
||||
return getattr(arm.dspl, "pose_library", None)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def getPoseLib(context):
|
||||
arm = getArmatureObject(context)
|
||||
pose_library_dspl = getDsplAction(context)
|
||||
pose_library_action = getArmatureAction(context)
|
||||
pose_library_legacy = getLegacyPoseLibrary(context)
|
||||
|
||||
if pose_library_dspl:
|
||||
return pose_library_dspl
|
||||
elif pose_library_action and not pose_library_dspl:
|
||||
return pose_library_action
|
||||
elif pose_library_legacy and not pose_library_dspl:
|
||||
return pose_library_legacy
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def searchPoseMarker(context, posename, type):
|
||||
try:
|
||||
pose_library = getPoseLib(context)
|
||||
arm_object, pose_library = getArmatureData(context)
|
||||
if type == "marker":
|
||||
return pose_library.pose_markers.get(posename, None)
|
||||
if type == "frame":
|
||||
@ -67,12 +38,11 @@ def searchPoseMarker(context, posename, type):
|
||||
|
||||
|
||||
def findFcurve(context, bone_name, transform, index_int):
|
||||
arm_object = getArmatureObject(context)
|
||||
action_object = getPoseLib(context)
|
||||
pose_markers = action_object.pose_markers
|
||||
arm_object, pose_library = getArmatureData(context)
|
||||
pose_markers = pose_library.pose_markers
|
||||
active_frame = pose_markers.active.frame
|
||||
|
||||
fcurve_object = action_object.fcurves.find(
|
||||
fcurve_object = pose_library.fcurves.find(
|
||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int)
|
||||
if hasattr(fcurve_object, 'evaluate'):
|
||||
return fcurve_object.evaluate(active_frame)
|
||||
@ -81,12 +51,11 @@ def findFcurve(context, bone_name, transform, index_int):
|
||||
|
||||
|
||||
def createFcurve(context, bone_name, transform, index_int):
|
||||
arm_object = getArmatureObject(context)
|
||||
action_object = getPoseLib(context)
|
||||
pose_markers = action_object.pose_markers
|
||||
arm_object, pose_library = getArmatureData(context)
|
||||
pose_markers = pose_library.pose_markers
|
||||
|
||||
try:
|
||||
action_object.fcurves.new(
|
||||
pose_library.fcurves.new(
|
||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int, action_group=bone_name)
|
||||
return
|
||||
except:
|
||||
@ -94,12 +63,11 @@ def createFcurve(context, bone_name, transform, index_int):
|
||||
|
||||
|
||||
def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
|
||||
arm_object = getArmatureObject(context)
|
||||
action_object = getPoseLib(context)
|
||||
pose_markers = action_object.pose_markers
|
||||
arm_object, pose_library = getArmatureData(context)
|
||||
pose_markers = pose_library.pose_markers
|
||||
|
||||
try:
|
||||
action_object.fcurves.find(
|
||||
pose_library.fcurves.find(
|
||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int).keyframe_points.insert(new_marker, loc)
|
||||
return
|
||||
except:
|
||||
|
Reference in New Issue
Block a user