Function to select bones in pose
This commit is contained in:
433
common.py
433
common.py
@ -1,212 +1,223 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
|
|
||||||
|
|
||||||
def getArmatureData(context):
|
def getArmatureData(context):
|
||||||
try:
|
try:
|
||||||
arm_object = context.active_object
|
arm_object = context.active_object
|
||||||
if arm_object and arm_object.type == "ARMATURE":
|
if arm_object and arm_object.type == "ARMATURE":
|
||||||
return arm_object, getattr(arm_object, "pose_library", None)
|
return arm_object, getattr(arm_object, "pose_library", None)
|
||||||
elif arm_object and arm_object.parent and arm_object.parent.type == "ARMATURE":
|
elif arm_object and arm_object.parent and arm_object.parent.type == "ARMATURE":
|
||||||
return arm_object.parent, getattr(arm_object.parent, "pose_library", None)
|
return arm_object.parent, getattr(arm_object.parent, "pose_library", None)
|
||||||
else:
|
else:
|
||||||
return None, None
|
return None, None
|
||||||
except:
|
except:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def getArmatureAction(context):
|
def getArmatureAction(context):
|
||||||
try:
|
try:
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
if getattr(arm_object.animation_data.action, "pose_markers", None):
|
if getattr(arm_object.animation_data.action, "pose_markers", None):
|
||||||
return getattr(arm_object.animation_data, "action", None)
|
return getattr(arm_object.animation_data, "action", None)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def searchPoseMarker(context, posename, type):
|
def searchPoseMarker(context, posename, type):
|
||||||
try:
|
try:
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
if type == "marker":
|
if type == "marker":
|
||||||
return pose_library.pose_markers.get(posename, None)
|
return pose_library.pose_markers.get(posename, None)
|
||||||
if type == "frame":
|
if type == "frame":
|
||||||
return pose_library.pose_markers.get(posename, None).frame
|
return pose_library.pose_markers.get(posename, None).frame
|
||||||
if type == "index":
|
if type == "index":
|
||||||
return pose_library.pose_markers.find(posename)
|
return pose_library.pose_markers.find(posename)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def findFcurve(context, bone_name, transform, index_int):
|
def selectBonesinPose(context, posename, active_marker):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
try:
|
||||||
pose_markers = pose_library.pose_markers
|
arm_object, pose_library = getArmatureData(context)
|
||||||
active_frame = pose_markers.active.frame
|
for bone in arm_object.pose.bones:
|
||||||
|
bone.bone.select = False
|
||||||
fcurve_object = pose_library.fcurves.find(
|
if findKeyframe(context, bone, active_marker.frame):
|
||||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int)
|
bone.bone.select = True
|
||||||
if hasattr(fcurve_object, 'evaluate'):
|
except:
|
||||||
return fcurve_object.evaluate(active_frame)
|
pass
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
def findFcurve(context, bone_name, transform, index_int):
|
||||||
|
arm_object, pose_library = getArmatureData(context)
|
||||||
def createFcurve(context, bone_name, transform, index_int):
|
pose_markers = pose_library.pose_markers
|
||||||
arm_object, pose_library = getArmatureData(context)
|
active_frame = pose_markers.active.frame
|
||||||
pose_markers = pose_library.pose_markers
|
|
||||||
|
fcurve_object = pose_library.fcurves.find(
|
||||||
try:
|
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int)
|
||||||
pose_library.fcurves.new(
|
if hasattr(fcurve_object, 'evaluate'):
|
||||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int, action_group=bone_name)
|
return fcurve_object.evaluate(active_frame)
|
||||||
return
|
else:
|
||||||
except:
|
return None
|
||||||
pass
|
|
||||||
|
|
||||||
|
def createFcurve(context, bone_name, transform, index_int):
|
||||||
def findKeyframe(context, bone, active_frame):
|
arm_object, pose_library = getArmatureData(context)
|
||||||
arm_object, pose_library = getArmatureData(context)
|
pose_markers = pose_library.pose_markers
|
||||||
|
|
||||||
for fcu in pose_library.fcurves:
|
try:
|
||||||
if fcu.data_path.startswith('pose.bones["'+bone.name+'"]'):
|
pose_library.fcurves.new(
|
||||||
for kp in fcu.keyframe_points:
|
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int, action_group=bone_name)
|
||||||
if kp.co.x == active_frame:
|
return
|
||||||
return fcu.data_path
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
|
|
||||||
arm_object, pose_library = getArmatureData(context)
|
def findKeyframe(context, bone, active_frame):
|
||||||
pose_markers = pose_library.pose_markers
|
arm_object, pose_library = getArmatureData(context)
|
||||||
|
|
||||||
try:
|
for fcu in pose_library.fcurves:
|
||||||
pose_library.fcurves.find(
|
if fcu.data_path.startswith('pose.bones["'+bone.name+'"]'):
|
||||||
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int).keyframe_points.insert(new_marker, loc)
|
for kp in fcu.keyframe_points:
|
||||||
return
|
if kp.co.x == active_frame:
|
||||||
except:
|
return fcu.data_path
|
||||||
pass
|
|
||||||
|
|
||||||
|
def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
|
||||||
def setKeyframesFromBones(context, arm_object, new_marker):
|
arm_object, pose_library = getArmatureData(context)
|
||||||
none_selected = True
|
pose_markers = pose_library.pose_markers
|
||||||
for bone in arm_object.pose.bones:
|
|
||||||
if bone.bone.select:
|
try:
|
||||||
none_selected = False
|
pose_library.fcurves.find(
|
||||||
|
'pose.bones["'+bone_name+'"].'+transform+'', index=index_int).keyframe_points.insert(new_marker, loc)
|
||||||
for bone in arm_object.pose.bones:
|
return
|
||||||
if bone.bone.select or none_selected == True:
|
except:
|
||||||
bone_name = bone.name
|
pass
|
||||||
|
|
||||||
if bone.rotation_mode == "XYZ":
|
|
||||||
rot_mode = "rotation_euler"
|
def setKeyframesFromBones(context, arm_object, new_marker):
|
||||||
elif bone.rotation_mode == "YZX":
|
none_selected = True
|
||||||
rot_mode = "rotation_euler"
|
for bone in arm_object.pose.bones:
|
||||||
elif bone.rotation_mode == "ZXY":
|
if bone.bone.select:
|
||||||
rot_mode = "rotation_euler"
|
none_selected = False
|
||||||
elif bone.rotation_mode == "QUATERNION":
|
|
||||||
rot_mode = "rotation_quaternion"
|
for bone in arm_object.pose.bones:
|
||||||
else:
|
if bone.bone.select or none_selected == True:
|
||||||
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
bone_name = bone.name
|
||||||
rot_mode = None
|
|
||||||
|
if bone.rotation_mode == "XYZ":
|
||||||
loc_x = bone.location[0]
|
rot_mode = "rotation_euler"
|
||||||
loc_y = bone.location[1]
|
elif bone.rotation_mode == "YZX":
|
||||||
loc_z = bone.location[2]
|
rot_mode = "rotation_euler"
|
||||||
createFcurve(context, bone_name, "location", 0)
|
elif bone.rotation_mode == "ZXY":
|
||||||
createFcurve(context, bone_name, "location", 1)
|
rot_mode = "rotation_euler"
|
||||||
createFcurve(context, bone_name, "location", 2)
|
elif bone.rotation_mode == "QUATERNION":
|
||||||
createKeyframe(context, bone_name, "location", 0, new_marker, loc_x)
|
rot_mode = "rotation_quaternion"
|
||||||
createKeyframe(context, bone_name, "location", 1, new_marker, loc_y)
|
else:
|
||||||
createKeyframe(context, bone_name, "location", 2, new_marker, loc_z)
|
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
||||||
if rot_mode == "rotation_quaternion":
|
rot_mode = None
|
||||||
rot_w = bone.rotation_quaternion[0]
|
|
||||||
rot_x = bone.rotation_quaternion[1]
|
loc_x = bone.location[0]
|
||||||
rot_y = bone.rotation_quaternion[2]
|
loc_y = bone.location[1]
|
||||||
rot_z = bone.rotation_quaternion[3]
|
loc_z = bone.location[2]
|
||||||
createFcurve(context, bone_name, rot_mode, 0)
|
createFcurve(context, bone_name, "location", 0)
|
||||||
createFcurve(context, bone_name, rot_mode, 1)
|
createFcurve(context, bone_name, "location", 1)
|
||||||
createFcurve(context, bone_name, rot_mode, 2)
|
createFcurve(context, bone_name, "location", 2)
|
||||||
createFcurve(context, bone_name, rot_mode, 3)
|
createKeyframe(context, bone_name, "location", 0, new_marker, loc_x)
|
||||||
createKeyframe(context, bone_name, rot_mode, 0, new_marker, rot_w)
|
createKeyframe(context, bone_name, "location", 1, new_marker, loc_y)
|
||||||
createKeyframe(context, bone_name, rot_mode, 1, new_marker, rot_x)
|
createKeyframe(context, bone_name, "location", 2, new_marker, loc_z)
|
||||||
createKeyframe(context, bone_name, rot_mode, 2, new_marker, rot_y)
|
if rot_mode == "rotation_quaternion":
|
||||||
createKeyframe(context, bone_name, rot_mode, 3, new_marker, rot_z)
|
rot_w = bone.rotation_quaternion[0]
|
||||||
elif rot_mode == "rotation_euler":
|
rot_x = bone.rotation_quaternion[1]
|
||||||
rot_x = bone.rotation_euler[0]
|
rot_y = bone.rotation_quaternion[2]
|
||||||
rot_y = bone.rotation_euler[1]
|
rot_z = bone.rotation_quaternion[3]
|
||||||
rot_z = bone.rotation_euler[2]
|
createFcurve(context, bone_name, rot_mode, 0)
|
||||||
createFcurve(context, bone_name, rot_mode, 0)
|
createFcurve(context, bone_name, rot_mode, 1)
|
||||||
createFcurve(context, bone_name, rot_mode, 1)
|
createFcurve(context, bone_name, rot_mode, 2)
|
||||||
createFcurve(context, bone_name, rot_mode, 2)
|
createFcurve(context, bone_name, rot_mode, 3)
|
||||||
createKeyframe(context, bone_name, rot_mode, 0, new_marker, rot_x)
|
createKeyframe(context, bone_name, rot_mode, 0, new_marker, rot_w)
|
||||||
createKeyframe(context, bone_name, rot_mode, 1, new_marker, rot_y)
|
createKeyframe(context, bone_name, rot_mode, 1, new_marker, rot_x)
|
||||||
createKeyframe(context, bone_name, rot_mode, 2, new_marker, rot_z)
|
createKeyframe(context, bone_name, rot_mode, 2, new_marker, rot_y)
|
||||||
scl_x = bone.scale[0]
|
createKeyframe(context, bone_name, rot_mode, 3, new_marker, rot_z)
|
||||||
scl_y = bone.scale[1]
|
elif rot_mode == "rotation_euler":
|
||||||
scl_z = bone.scale[2]
|
rot_x = bone.rotation_euler[0]
|
||||||
createFcurve(context, bone_name, "scale", 0)
|
rot_y = bone.rotation_euler[1]
|
||||||
createFcurve(context, bone_name, "scale", 1)
|
rot_z = bone.rotation_euler[2]
|
||||||
createFcurve(context, bone_name, "scale", 2)
|
createFcurve(context, bone_name, rot_mode, 0)
|
||||||
createKeyframe(context, bone_name, "scale", 0, new_marker, scl_x)
|
createFcurve(context, bone_name, rot_mode, 1)
|
||||||
createKeyframe(context, bone_name, "scale", 1, new_marker, scl_y)
|
createFcurve(context, bone_name, rot_mode, 2)
|
||||||
createKeyframe(context, bone_name, "scale", 2, new_marker, scl_z)
|
createKeyframe(context, bone_name, rot_mode, 0, new_marker, rot_x)
|
||||||
|
createKeyframe(context, bone_name, rot_mode, 1, new_marker, rot_y)
|
||||||
|
createKeyframe(context, bone_name, rot_mode, 2, new_marker, rot_z)
|
||||||
def setBonesfromKeyframes(context, arm_object, active_marker):
|
scl_x = bone.scale[0]
|
||||||
none_selected = True
|
scl_y = bone.scale[1]
|
||||||
for bone in arm_object.pose.bones:
|
scl_z = bone.scale[2]
|
||||||
if bone.bone.select:
|
createFcurve(context, bone_name, "scale", 0)
|
||||||
none_selected = False
|
createFcurve(context, bone_name, "scale", 1)
|
||||||
|
createFcurve(context, bone_name, "scale", 2)
|
||||||
for bone in arm_object.pose.bones:
|
createKeyframe(context, bone_name, "scale", 0, new_marker, scl_x)
|
||||||
if bone.bone.select or none_selected == True:
|
createKeyframe(context, bone_name, "scale", 1, new_marker, scl_y)
|
||||||
bone_name = bone.name
|
createKeyframe(context, bone_name, "scale", 2, new_marker, scl_z)
|
||||||
|
|
||||||
if findKeyframe(context, bone, active_marker.frame) is None:
|
|
||||||
continue
|
def setBonesfromKeyframes(context, arm_object, active_marker):
|
||||||
|
none_selected = True
|
||||||
if bone.rotation_mode == "XYZ":
|
for bone in arm_object.pose.bones:
|
||||||
rot_mode = "rotation_euler"
|
if bone.bone.select:
|
||||||
elif bone.rotation_mode == "YZX":
|
none_selected = False
|
||||||
rot_mode = "rotation_euler"
|
|
||||||
elif bone.rotation_mode == "ZXY":
|
for bone in arm_object.pose.bones:
|
||||||
rot_mode = "rotation_euler"
|
if bone.bone.select or none_selected == True:
|
||||||
elif bone.rotation_mode == "QUATERNION":
|
bone_name = bone.name
|
||||||
rot_mode = "rotation_quaternion"
|
|
||||||
else:
|
if findKeyframe(context, bone, active_marker.frame) is None:
|
||||||
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
continue
|
||||||
rot_mode = None
|
|
||||||
|
if bone.rotation_mode == "XYZ":
|
||||||
loc_x = findFcurve(context, bone_name, "location", 0) or 0.0
|
rot_mode = "rotation_euler"
|
||||||
loc_y = findFcurve(context, bone_name, "location", 1) or 0.0
|
elif bone.rotation_mode == "YZX":
|
||||||
loc_z = findFcurve(context, bone_name, "location", 2) or 0.0
|
rot_mode = "rotation_euler"
|
||||||
if rot_mode == "rotation_quaternion":
|
elif bone.rotation_mode == "ZXY":
|
||||||
rot_w = findFcurve(context, bone_name, rot_mode, 0) or 1.0
|
rot_mode = "rotation_euler"
|
||||||
rot_x = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
elif bone.rotation_mode == "QUATERNION":
|
||||||
rot_y = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
rot_mode = "rotation_quaternion"
|
||||||
rot_z = findFcurve(context, bone_name, rot_mode, 3) or 0.0
|
else:
|
||||||
elif rot_mode == "rotation_euler":
|
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
||||||
rot_x = findFcurve(context, bone_name, rot_mode, 0) or 0.0
|
rot_mode = None
|
||||||
rot_y = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
|
||||||
rot_z = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
loc_x = findFcurve(context, bone_name, "location", 0) or 0.0
|
||||||
scl_x = findFcurve(context, bone_name, "scale", 0) or 1.0
|
loc_y = findFcurve(context, bone_name, "location", 1) or 0.0
|
||||||
scl_y = findFcurve(context, bone_name, "scale", 1) or 1.0
|
loc_z = findFcurve(context, bone_name, "location", 2) or 0.0
|
||||||
scl_z = findFcurve(context, bone_name, "scale", 2) or 1.0
|
if rot_mode == "rotation_quaternion":
|
||||||
|
rot_w = findFcurve(context, bone_name, rot_mode, 0) or 1.0
|
||||||
bone.location = mathutils.Vector((loc_x, loc_y, loc_z))
|
rot_x = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
||||||
if bone.rotation_mode == "XYZ":
|
rot_y = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
||||||
bone.rotation_euler = mathutils.Euler(
|
rot_z = findFcurve(context, bone_name, rot_mode, 3) or 0.0
|
||||||
(rot_x, rot_y, rot_z))
|
elif rot_mode == "rotation_euler":
|
||||||
elif bone.rotation_mode == "YZX":
|
rot_x = findFcurve(context, bone_name, rot_mode, 0) or 0.0
|
||||||
bone.rotation_euler = mathutils.Euler(
|
rot_y = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
||||||
(rot_x, rot_y, rot_z))
|
rot_z = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
||||||
elif bone.rotation_mode == "ZXY":
|
scl_x = findFcurve(context, bone_name, "scale", 0) or 1.0
|
||||||
bone.rotation_euler = mathutils.Euler(
|
scl_y = findFcurve(context, bone_name, "scale", 1) or 1.0
|
||||||
(rot_z, rot_x, rot_y))
|
scl_z = findFcurve(context, bone_name, "scale", 2) or 1.0
|
||||||
elif bone.rotation_mode == "YXZ":
|
|
||||||
bone.rotation_euler = mathutils.Euler(
|
bone.location = mathutils.Vector((loc_x, loc_y, loc_z))
|
||||||
(rot_y, rot_x, rot_z))
|
if bone.rotation_mode == "XYZ":
|
||||||
elif bone.rotation_mode == "XZY":
|
bone.rotation_euler = mathutils.Euler(
|
||||||
bone.rotation_euler = mathutils.Euler(
|
(rot_x, rot_y, rot_z))
|
||||||
(rot_x, rot_z, rot_y))
|
elif bone.rotation_mode == "YZX":
|
||||||
elif rot_mode == "rotation_quaternion":
|
bone.rotation_euler = mathutils.Euler(
|
||||||
bone.rotation_quaternion = mathutils.Quaternion(
|
(rot_x, rot_y, rot_z))
|
||||||
(rot_w, rot_x, rot_y, rot_z))
|
elif bone.rotation_mode == "ZXY":
|
||||||
|
bone.rotation_euler = mathutils.Euler(
|
||||||
|
(rot_z, rot_x, rot_y))
|
||||||
|
elif bone.rotation_mode == "YXZ":
|
||||||
|
bone.rotation_euler = mathutils.Euler(
|
||||||
|
(rot_y, rot_x, rot_z))
|
||||||
|
elif bone.rotation_mode == "XZY":
|
||||||
|
bone.rotation_euler = mathutils.Euler(
|
||||||
|
(rot_x, rot_z, rot_y))
|
||||||
|
elif rot_mode == "rotation_quaternion":
|
||||||
|
bone.rotation_quaternion = mathutils.Quaternion(
|
||||||
|
(rot_w, rot_x, rot_y, rot_z))
|
||||||
bone.scale = mathutils.Vector((scl_x, scl_y, scl_z))
|
bone.scale = mathutils.Vector((scl_x, scl_y, scl_z))
|
923
operators.py
923
operators.py
@ -1,458 +1,465 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import blf
|
import blf
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
|
|
||||||
# Operator to create a new pose library
|
# Operator to create a new pose library
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_CreatePoseLibrary(bpy.types.Operator):
|
class DSPL_OT_CreatePoseLibrary(bpy.types.Operator):
|
||||||
bl_idname = "dspl.create_pose_library"
|
bl_idname = "dspl.create_pose_library"
|
||||||
bl_label = "Create Pose Library"
|
bl_label = "Create Pose Library"
|
||||||
bl_description = "Create Pose Library"
|
bl_description = "Create Pose Library"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
arm_object.pose_library = bpy.data.actions.new(
|
arm_object.pose_library = bpy.data.actions.new(
|
||||||
name=arm_object.name + "_PoseLib")
|
name=arm_object.name + "_PoseLib")
|
||||||
arm_object.pose_library.use_fake_user = True
|
arm_object.pose_library.use_fake_user = True
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
# Operator to convert an action to pose library
|
# Operator to convert an action to pose library
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_ConvertPoseLibrary(bpy.types.Operator):
|
class DSPL_OT_ConvertPoseLibrary(bpy.types.Operator):
|
||||||
bl_idname = "dspl.convert_pose_library"
|
bl_idname = "dspl.convert_pose_library"
|
||||||
bl_label = "Convert Pose Library"
|
bl_label = "Convert Pose Library"
|
||||||
bl_description = "Convert Pose Library"
|
bl_description = "Convert Pose Library"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
if pose_library is None:
|
if pose_library is None:
|
||||||
arm_object.pose_library = arm_object.animation_data.action
|
arm_object.pose_library = arm_object.animation_data.action
|
||||||
arm_object.animation_data.action = None
|
arm_object.animation_data.action = None
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
# Operator to add keyframes and marker to pose library
|
# Operator to add keyframes and marker to pose library
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_AddPose(bpy.types.Operator):
|
class DSPL_OT_AddPose(bpy.types.Operator):
|
||||||
bl_idname = "dspl.add_pose"
|
bl_idname = "dspl.add_pose"
|
||||||
bl_label = "Add Pose"
|
bl_label = "Add Pose"
|
||||||
bl_description = "Add Pose"
|
bl_description = "Add Pose"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
posename: bpy.props.StringProperty(default="Pose")
|
posename: bpy.props.StringProperty(default="Pose")
|
||||||
replace: bpy.props.BoolProperty(name="Replace", description="Replace existing pose", default=False, options={'SKIP_SAVE'})
|
replace: bpy.props.BoolProperty(name="Replace", description="Replace existing pose", default=False, options={'SKIP_SAVE'})
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
if self.replace == False:
|
if self.replace == False:
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
new_name = self.posename
|
new_name = self.posename
|
||||||
counter = 1
|
counter = 1
|
||||||
|
|
||||||
# Find first unused marker frame
|
# Find first unused marker frame
|
||||||
for f in range(0, len(pose_markers) + 1):
|
for f in range(0, len(pose_markers) + 1):
|
||||||
f += 1
|
f += 1
|
||||||
for pm in pose_markers:
|
for pm in pose_markers:
|
||||||
name_check = pm.name
|
name_check = pm.name
|
||||||
frame_check = pm.frame
|
frame_check = pm.frame
|
||||||
if frame_check == f:
|
if frame_check == f:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
new_marker = f
|
new_marker = f
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check for duplicate names
|
# Check for duplicate names
|
||||||
while pose_markers.find(new_name) > -1:
|
while pose_markers.find(new_name) > -1:
|
||||||
new_name = self.posename + ".{:03d}".format(counter)
|
new_name = self.posename + ".{:03d}".format(counter)
|
||||||
counter += 1
|
counter += 1
|
||||||
else:
|
else:
|
||||||
pose_name = new_name
|
pose_name = new_name
|
||||||
|
|
||||||
pose_markers.new(name=pose_name)
|
pose_markers.new(name=pose_name)
|
||||||
pose_markers[pose_name].frame = new_marker
|
pose_markers[pose_name].frame = new_marker
|
||||||
|
|
||||||
setKeyframesFromBones(context, arm_object, new_marker)
|
setKeyframesFromBones(context, arm_object, new_marker)
|
||||||
|
|
||||||
pose_library.pose_markers.active = pose_markers[pose_name]
|
pose_library.pose_markers.active = pose_markers[pose_name]
|
||||||
bpy.context.area.tag_redraw()
|
bpy.context.area.tag_redraw()
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Added " + pose_markers[new_name].name + " to frame " + str(pose_markers[new_name].frame))
|
self.report({'INFO'}, "DSPL: Added " + pose_markers[new_name].name + " to frame " + str(pose_markers[new_name].frame))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
active_marker = pose_markers.active
|
active_marker = pose_markers.active
|
||||||
new_name = self.posename
|
new_name = self.posename
|
||||||
counter = 1
|
counter = 1
|
||||||
|
|
||||||
for pm in pose_markers:
|
for pm in pose_markers:
|
||||||
name_check = pm.name
|
name_check = pm.name
|
||||||
frame_check = pm.frame
|
frame_check = pm.frame
|
||||||
if name_check == new_name:
|
if name_check == new_name:
|
||||||
target_name = name_check
|
target_name = name_check
|
||||||
target_frame = frame_check
|
target_frame = frame_check
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
new_marker = target_frame
|
new_marker = target_frame
|
||||||
|
|
||||||
setKeyframesFromBones(context, arm_object, new_marker)
|
setKeyframesFromBones(context, arm_object, new_marker)
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Replaced " + pose_markers[new_name].name + " on frame " + str(pose_markers[new_name].frame))
|
self.report({'INFO'}, "DSPL: Replaced " + pose_markers[new_name].name + " on frame " + str(pose_markers[new_name].frame))
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
# Operator to remove keyframes and marker
|
# Operator to remove keyframes and marker
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_RemovePose(bpy.types.Operator):
|
class DSPL_OT_RemovePose(bpy.types.Operator):
|
||||||
bl_idname = "dspl.remove_pose"
|
bl_idname = "dspl.remove_pose"
|
||||||
bl_label = "Remove Pose"
|
bl_label = "Remove Pose"
|
||||||
bl_description = "Remove Pose"
|
bl_description = "Remove Pose"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
posename: bpy.props.StringProperty()
|
posename: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
if self.posename:
|
if self.posename:
|
||||||
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
||||||
active_index = pose_library.pose_markers.active_index
|
active_index = pose_library.pose_markers.active_index
|
||||||
else:
|
else:
|
||||||
active_index = pose_markers.active_index
|
active_index = pose_markers.active_index
|
||||||
active_marker = pose_markers.active
|
active_marker = pose_markers.active
|
||||||
active_frame = active_marker.frame
|
active_frame = active_marker.frame
|
||||||
|
|
||||||
fcurves = pose_library.fcurves
|
fcurves = pose_library.fcurves
|
||||||
for fcu in fcurves:
|
for fcu in fcurves:
|
||||||
for kf in fcu.keyframe_points.values():
|
for kf in fcu.keyframe_points.values():
|
||||||
if kf.co.x == active_frame:
|
if kf.co.x == active_frame:
|
||||||
fcu.keyframe_points.remove(kf)
|
fcu.keyframe_points.remove(kf)
|
||||||
|
|
||||||
if active_index <= 0:
|
if active_index <= 0:
|
||||||
next_index = active_index
|
next_index = active_index
|
||||||
next_marker = pose_markers[next_index]
|
next_marker = pose_markers[next_index]
|
||||||
elif (active_index + 1) >= len(pose_markers):
|
elif (active_index + 1) >= len(pose_markers):
|
||||||
next_index = active_index - 1
|
next_index = active_index - 1
|
||||||
next_marker = pose_markers[next_index]
|
next_marker = pose_markers[next_index]
|
||||||
else:
|
else:
|
||||||
next_index = active_index
|
next_index = active_index
|
||||||
next_marker = pose_markers[next_index]
|
next_marker = pose_markers[next_index]
|
||||||
|
|
||||||
pose_markers.remove(marker=active_marker)
|
pose_markers.remove(marker=active_marker)
|
||||||
|
|
||||||
pose_library.pose_markers.active = next_marker
|
pose_library.pose_markers.active = next_marker
|
||||||
pose_library.pose_markers.active_index = next_index
|
pose_library.pose_markers.active_index = next_index
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Removed " + self.posename)
|
self.report({'INFO'}, "DSPL: Removed " + self.posename)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
# Operator to rename the current pose
|
# Operator to rename the current pose
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_RenamePose(bpy.types.Operator):
|
class DSPL_OT_RenamePose(bpy.types.Operator):
|
||||||
bl_idname = "dspl.rename_pose"
|
bl_idname = "dspl.rename_pose"
|
||||||
bl_label = "Rename Pose"
|
bl_label = "Rename Pose"
|
||||||
bl_description = "Rename Pose"
|
bl_description = "Rename Pose"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
posename: bpy.props.StringProperty()
|
posename: bpy.props.StringProperty()
|
||||||
pose_new_name: bpy.props.StringProperty()
|
pose_new_name: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
active_marker = pose_markers.active
|
active_marker = pose_markers.active
|
||||||
|
|
||||||
if self.posename:
|
if self.posename:
|
||||||
target_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
target_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
||||||
else:
|
else:
|
||||||
target_marker = active_marker
|
target_marker = active_marker
|
||||||
|
|
||||||
if self.pose_new_name:
|
if self.pose_new_name:
|
||||||
target_marker.name = self.pose_new_name
|
target_marker.name = self.pose_new_name
|
||||||
context.area.tag_redraw()
|
context.area.tag_redraw()
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Renamed " + self.posename + " to " + self.pose_new_name + " on frame " + str(active_marker.frame))
|
self.report({'INFO'}, "DSPL: Renamed " + self.posename + " to " + self.pose_new_name + " on frame " + str(active_marker.frame))
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
else:
|
else:
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
self.pose_new_name = self.posename
|
self.pose_new_name = self.posename
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
|
|
||||||
# Operator to reorder pose markers
|
# Operator to reorder pose markers
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_MovePose(bpy.types.Operator):
|
class DSPL_OT_MovePose(bpy.types.Operator):
|
||||||
bl_idname = "dspl.move_pose"
|
bl_idname = "dspl.move_pose"
|
||||||
bl_label = "Move Pose"
|
bl_label = "Move Pose"
|
||||||
bl_description = "Move pose"
|
bl_description = "Move pose"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
direction: bpy.props.StringProperty(name="Direction", default="DOWN")
|
direction: bpy.props.StringProperty(name="Direction", default="DOWN")
|
||||||
posename: bpy.props.StringProperty(name="Pose Name", default="", options={'SKIP_SAVE'})
|
posename: bpy.props.StringProperty(name="Pose Name", default="", options={'SKIP_SAVE'})
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
|
|
||||||
if self.posename:
|
if self.posename:
|
||||||
active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
||||||
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
||||||
active_frame = active_marker.frame
|
active_frame = active_marker.frame
|
||||||
active_posename = active_marker.name
|
active_posename = active_marker.name
|
||||||
else:
|
else:
|
||||||
active_marker = pose_markers.active
|
active_marker = pose_markers.active
|
||||||
active_index = pose_markers.active_index
|
active_index = pose_markers.active_index
|
||||||
|
|
||||||
if self.direction == "UP":
|
if self.direction == "UP":
|
||||||
move_dir = -1
|
move_dir = -1
|
||||||
elif self.direction == "DOWN":
|
elif self.direction == "DOWN":
|
||||||
move_dir = 1
|
move_dir = 1
|
||||||
|
|
||||||
swap_index = active_index + move_dir
|
swap_index = active_index + move_dir
|
||||||
|
|
||||||
if swap_index < 0:
|
if swap_index < 0:
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
elif swap_index >= len(pose_library.pose_markers):
|
elif swap_index >= len(pose_library.pose_markers):
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
swap_marker = pose_markers[swap_index]
|
swap_marker = pose_markers[swap_index]
|
||||||
|
|
||||||
tmp_marker_name = swap_marker.name
|
tmp_marker_name = swap_marker.name
|
||||||
tmp_marker_frame = swap_marker.frame
|
tmp_marker_frame = swap_marker.frame
|
||||||
pose_library.pose_markers[swap_index].name = active_marker.name
|
pose_library.pose_markers[swap_index].name = active_marker.name
|
||||||
pose_library.pose_markers[swap_index].frame = active_marker.frame
|
pose_library.pose_markers[swap_index].frame = active_marker.frame
|
||||||
pose_library.pose_markers[active_index].name = tmp_marker_name
|
pose_library.pose_markers[active_index].name = tmp_marker_name
|
||||||
pose_library.pose_markers[active_index].frame = tmp_marker_frame
|
pose_library.pose_markers[active_index].frame = tmp_marker_frame
|
||||||
pose_library.pose_markers.active_index = swap_index
|
pose_library.pose_markers.active_index = swap_index
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
# Operator to apply a pose from active marker
|
# Operator to apply a pose from active marker
|
||||||
|
|
||||||
|
|
||||||
class DSPL_OT_ApplyPose(bpy.types.Operator):
|
class DSPL_OT_ApplyPose(bpy.types.Operator):
|
||||||
bl_idname = "dspl.apply_pose"
|
bl_idname = "dspl.apply_pose"
|
||||||
bl_label = "Apply Pose"
|
bl_label = "Apply Pose"
|
||||||
bl_description = "Apply Pose (Ctrl+Click to select, Shift+Click to rename, Alt+Click to remove)"
|
bl_description = "Apply Pose (Ctrl+Click to select bones, Shift+Click to rename, Alt+Click to remove)"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
posename: bpy.props.StringProperty()
|
posename: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pose_markers = pose_library.pose_markers
|
pose_markers = pose_library.pose_markers
|
||||||
|
|
||||||
if self.posename:
|
if self.posename:
|
||||||
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
||||||
active_frame = active_marker.frame
|
active_frame = active_marker.frame
|
||||||
active_posename = active_marker.name
|
active_posename = active_marker.name
|
||||||
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
||||||
else:
|
else:
|
||||||
active_index = pose_markers.active_index
|
active_index = pose_markers.active_index
|
||||||
active_marker = pose_markers.active
|
active_marker = pose_markers.active
|
||||||
active_frame = active_marker.frame
|
active_frame = active_marker.frame
|
||||||
active_posename = active_marker.name
|
active_posename = active_marker.name
|
||||||
|
|
||||||
setBonesfromKeyframes(context, arm_object, active_marker)
|
setBonesfromKeyframes(context, arm_object, active_marker)
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Applied " + active_posename)
|
self.report({'INFO'}, "DSPL: Applied " + active_posename)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
if event.ctrl:
|
if event.ctrl:
|
||||||
# Select
|
# Select bones
|
||||||
arm_object, pose_library = getArmatureData(context)
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
|
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
|
||||||
return {'FINISHED'}
|
|
||||||
elif event.alt:
|
arm_object.select = True
|
||||||
# Remove
|
bpy.context.view_layer.objects.active = arm_object
|
||||||
bpy.ops.dspl.remove_pose(posename = self.posename)
|
bpy.ops.object.mode_set(mode='POSE')
|
||||||
return {'FINISHED'}
|
selectBonesinPose(context, self.posename, active_marker)
|
||||||
elif event.shift:
|
|
||||||
# Rename
|
self.execute(context)
|
||||||
bpy.ops.dspl.rename_pose('INVOKE_DEFAULT', posename = self.posename)
|
return {'FINISHED'}
|
||||||
return {'FINISHED'}
|
elif event.alt:
|
||||||
else:
|
# Remove
|
||||||
return self.execute(context)
|
bpy.ops.dspl.remove_pose(posename = self.posename)
|
||||||
|
return {'FINISHED'}
|
||||||
|
elif event.shift:
|
||||||
# Operator to preview up and down pose list
|
# Rename
|
||||||
|
bpy.ops.dspl.rename_pose('INVOKE_DEFAULT', posename = self.posename)
|
||||||
|
return {'FINISHED'}
|
||||||
class DSPL_OT_BrowsePoses(bpy.types.Operator):
|
else:
|
||||||
bl_idname = "dspl.browse_poses"
|
return self.execute(context)
|
||||||
bl_label = "Browse Poses"
|
|
||||||
bl_description = "Browse Poses"
|
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
# Operator to preview up and down pose list
|
||||||
|
|
||||||
|
|
||||||
def draw_callback_px(self, context, test):
|
class DSPL_OT_BrowsePoses(bpy.types.Operator):
|
||||||
font_id = 1
|
bl_idname = "dspl.browse_poses"
|
||||||
font_size = 24
|
bl_label = "Browse Poses"
|
||||||
font_dpi = 72
|
bl_description = "Browse Poses"
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
blf.position(font_id, 15, 30, 0)
|
|
||||||
mod_var = self.pose_library.pose_markers.active.name
|
|
||||||
blf.color(font_id, 1.0, 1.0, 1.0, 1.0)
|
def draw_callback_px(self, context, test):
|
||||||
blf.size(font_id, font_size)
|
font_id = 1
|
||||||
blf.draw(font_id, "Previewing pose: " + mod_var)
|
font_size = 24
|
||||||
|
font_dpi = 72
|
||||||
|
|
||||||
def modal(self, context, event):
|
blf.position(font_id, 15, 30, 0)
|
||||||
context.area.tag_redraw()
|
mod_var = self.pose_library.pose_markers.active.name
|
||||||
|
blf.color(font_id, 1.0, 1.0, 1.0, 1.0)
|
||||||
if event.value == 'PRESS':
|
blf.size(font_id, font_size)
|
||||||
if event.type in {'LEFT_ARROW', 'UP_ARROW'}:
|
blf.draw(font_id, "Previewing pose: " + mod_var)
|
||||||
if self.pose_library.pose_markers.active_index <= 0:
|
|
||||||
self.pose_library.pose_markers.active_index = len(self.pose_library.pose_markers) - 1
|
|
||||||
else:
|
def modal(self, context, event):
|
||||||
self.pose_library.pose_markers.active_index = self.pose_library.pose_markers.active_index - 1
|
context.area.tag_redraw()
|
||||||
bpy.ops.dspl.apply_pose()
|
|
||||||
elif event.type in {'RIGHT_ARROW', 'DOWN_ARROW'}:
|
if event.value == 'PRESS':
|
||||||
if self.pose_library.pose_markers.active_index + 1 >= len(self.pose_library.pose_markers):
|
if event.type in {'LEFT_ARROW', 'UP_ARROW'}:
|
||||||
self.pose_library.pose_markers.active_index = 0
|
if self.pose_library.pose_markers.active_index <= 0:
|
||||||
else:
|
self.pose_library.pose_markers.active_index = len(self.pose_library.pose_markers) - 1
|
||||||
self.pose_library.pose_markers.active_index = self.pose_library.pose_markers.active_index + 1
|
else:
|
||||||
bpy.ops.dspl.apply_pose()
|
self.pose_library.pose_markers.active_index = self.pose_library.pose_markers.active_index - 1
|
||||||
|
bpy.ops.dspl.apply_pose()
|
||||||
if event.type in {'LEFTMOUSE', 'RET', 'NUMPAD_ENTER'}:
|
elif event.type in {'RIGHT_ARROW', 'DOWN_ARROW'}:
|
||||||
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
|
if self.pose_library.pose_markers.active_index + 1 >= len(self.pose_library.pose_markers):
|
||||||
return {'FINISHED'}
|
self.pose_library.pose_markers.active_index = 0
|
||||||
|
else:
|
||||||
elif event.type in {'RIGHTMOUSE', 'ESC'}:
|
self.pose_library.pose_markers.active_index = self.pose_library.pose_markers.active_index + 1
|
||||||
self.arm_object.pose.backup_restore()
|
bpy.ops.dspl.apply_pose()
|
||||||
self.pose_library.pose_markers.active_index = self.backup_index
|
|
||||||
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
|
if event.type in {'LEFTMOUSE', 'RET', 'NUMPAD_ENTER'}:
|
||||||
return {'CANCELLED'}
|
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
|
||||||
|
return {'FINISHED'}
|
||||||
return {'RUNNING_MODAL'}
|
|
||||||
|
elif event.type in {'RIGHTMOUSE', 'ESC'}:
|
||||||
|
self.arm_object.pose.backup_restore()
|
||||||
def invoke(self, context, event):
|
self.pose_library.pose_markers.active_index = self.backup_index
|
||||||
bpy.context.area.tag_redraw()
|
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
|
||||||
|
return {'CANCELLED'}
|
||||||
self.arm_object, self.pose_library = getArmatureData(context)
|
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
if self.pose_library is None:
|
|
||||||
self.report({'WARNING'}, "DSPL: Pose Library not active")
|
|
||||||
return {'CANCELLED'}
|
def invoke(self, context, event):
|
||||||
|
bpy.context.area.tag_redraw()
|
||||||
self.arm_object.pose.backup_create(self.pose_library)
|
|
||||||
self.backup_index = self.pose_library.pose_markers.active_index
|
self.arm_object, self.pose_library = getArmatureData(context)
|
||||||
bpy.ops.dspl.apply_pose()
|
|
||||||
|
if self.pose_library is None:
|
||||||
if context.area.type == 'VIEW_3D':
|
self.report({'WARNING'}, "DSPL: Pose Library not active")
|
||||||
self.report({'INFO'}, "DSPL: Browsing Poses")
|
return {'CANCELLED'}
|
||||||
args = (self, context)
|
|
||||||
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
|
self.arm_object.pose.backup_create(self.pose_library)
|
||||||
context.window_manager.modal_handler_add(self)
|
self.backup_index = self.pose_library.pose_markers.active_index
|
||||||
return {'RUNNING_MODAL'}
|
bpy.ops.dspl.apply_pose()
|
||||||
return {'CANCELLED'}
|
|
||||||
|
if context.area.type == 'VIEW_3D':
|
||||||
|
self.report({'INFO'}, "DSPL: Browsing Poses")
|
||||||
# Operator to unlink a pose library and mark for removal
|
args = (self, context)
|
||||||
|
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
|
||||||
|
context.window_manager.modal_handler_add(self)
|
||||||
class DSPL_OT_UnlinkPoseLibrary(bpy.types.Operator):
|
return {'RUNNING_MODAL'}
|
||||||
bl_idname = "dspl.unlink_pose_library"
|
return {'CANCELLED'}
|
||||||
bl_label = "Unlink Pose Library"
|
|
||||||
bl_description = "Unlink Pose Library"
|
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
# Operator to unlink a pose library and mark for removal
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
arm_object, pose_library = getArmatureData(context)
|
class DSPL_OT_UnlinkPoseLibrary(bpy.types.Operator):
|
||||||
|
bl_idname = "dspl.unlink_pose_library"
|
||||||
try:
|
bl_label = "Unlink Pose Library"
|
||||||
arm_object.pose_library = None
|
bl_description = "Unlink Pose Library"
|
||||||
# arm_object.pose_library.use_fake_user = False
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
# if not arm_object.pose_library.name.startswith("del_"):
|
|
||||||
# arm_object.pose_library.name = "del_{}".format(arm_object.pose_library.name)
|
def execute(self, context):
|
||||||
except:
|
arm_object, pose_library = getArmatureData(context)
|
||||||
pass
|
|
||||||
|
try:
|
||||||
return {'FINISHED'}
|
arm_object.pose_library = None
|
||||||
|
# arm_object.pose_library.use_fake_user = False
|
||||||
|
# if not arm_object.pose_library.name.startswith("del_"):
|
||||||
# Operator to protect orphaned legacy pose libraries
|
# arm_object.pose_library.name = "del_{}".format(arm_object.pose_library.name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
class DSPL_OT_ProtectOrphanPoseLibrary(bpy.types.Operator):
|
|
||||||
bl_idname = "dspl.protect_orphan_pose_library"
|
return {'FINISHED'}
|
||||||
bl_label = "Protect Orphaned Pose Libraries"
|
|
||||||
bl_description = "Protect Orphaned Pose Libraries"
|
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
# Operator to protect orphaned legacy pose libraries
|
||||||
|
|
||||||
only_poselibs: bpy.props.BoolProperty(name="Only Poselibs", description="Only named poselibs", default=False, options={'SKIP_SAVE'})
|
|
||||||
protect: bpy.props.BoolProperty(name="Protect", description="Or not", default=True, options={'SKIP_SAVE'})
|
class DSPL_OT_ProtectOrphanPoseLibrary(bpy.types.Operator):
|
||||||
|
bl_idname = "dspl.protect_orphan_pose_library"
|
||||||
def check(self, context):
|
bl_label = "Protect Orphaned Pose Libraries"
|
||||||
return True
|
bl_description = "Protect Orphaned Pose Libraries"
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
def invoke(self, context, event):
|
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
only_poselibs: bpy.props.BoolProperty(name="Only Poselibs", description="Only named poselibs", default=False, options={'SKIP_SAVE'})
|
||||||
|
protect: bpy.props.BoolProperty(name="Protect", description="Or not", default=True, options={'SKIP_SAVE'})
|
||||||
def draw(self, context):
|
|
||||||
layout = self.layout
|
def check(self, context):
|
||||||
orphaned_act = [act for act in bpy.data.actions if act.users == 0]
|
return True
|
||||||
if orphaned_act:
|
|
||||||
|
def invoke(self, context, event):
|
||||||
# bpy.types.Scene.my_prop = bpy.props.BoolVectorProperty(name="boo", size = len(orphaned_act), default=True)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
col = layout.column()
|
|
||||||
col.label(text="Orphaned actions", icon="ORPHAN_DATA")
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
for act in orphaned_act:
|
orphaned_act = [act for act in bpy.data.actions if act.users == 0]
|
||||||
entryrow = col.row()
|
if orphaned_act:
|
||||||
protectbutton = entryrow.prop(self, "protect", text=act.name)
|
|
||||||
|
# bpy.types.Scene.my_prop = bpy.props.BoolVectorProperty(name="boo", size = len(orphaned_act), default=True)
|
||||||
col.split()
|
col = layout.column()
|
||||||
else:
|
col.label(text="Orphaned actions", icon="ORPHAN_DATA")
|
||||||
layout.label(text="No orphans here")
|
|
||||||
|
for act in orphaned_act:
|
||||||
def execute(self, context):
|
entryrow = col.row()
|
||||||
orphaned_act = [act for act in bpy.data.actions if act.users == 0]
|
protectbutton = entryrow.prop(self, "protect", text=act.name)
|
||||||
if orphaned_act:
|
|
||||||
for act in orphaned_act:
|
col.split()
|
||||||
if "_loc" in act.name or "PoseLib" in act.name:
|
else:
|
||||||
self.report({'INFO'}, "DSPL: Protecting orphaned action: " + act.name)
|
layout.label(text="No orphans here")
|
||||||
act.use_fake_user = True
|
|
||||||
|
def execute(self, context):
|
||||||
return {'FINISHED'}
|
orphaned_act = [act for act in bpy.data.actions if act.users == 0]
|
||||||
|
if orphaned_act:
|
||||||
|
for act in orphaned_act:
|
||||||
classes = (
|
if "_loc" in act.name or "PoseLib" in act.name:
|
||||||
DSPL_OT_CreatePoseLibrary,
|
self.report({'INFO'}, "DSPL: Protecting orphaned action: " + act.name)
|
||||||
DSPL_OT_ConvertPoseLibrary,
|
act.use_fake_user = True
|
||||||
DSPL_OT_AddPose,
|
|
||||||
DSPL_OT_RemovePose,
|
return {'FINISHED'}
|
||||||
DSPL_OT_RenamePose,
|
|
||||||
DSPL_OT_MovePose,
|
|
||||||
DSPL_OT_ApplyPose,
|
classes = (
|
||||||
DSPL_OT_BrowsePoses,
|
DSPL_OT_CreatePoseLibrary,
|
||||||
DSPL_OT_UnlinkPoseLibrary,
|
DSPL_OT_ConvertPoseLibrary,
|
||||||
DSPL_OT_ProtectOrphanPoseLibrary
|
DSPL_OT_AddPose,
|
||||||
)
|
DSPL_OT_RemovePose,
|
||||||
|
DSPL_OT_RenamePose,
|
||||||
register, unregister = bpy.utils.register_classes_factory(classes)
|
DSPL_OT_MovePose,
|
||||||
|
DSPL_OT_ApplyPose,
|
||||||
|
DSPL_OT_BrowsePoses,
|
||||||
|
DSPL_OT_UnlinkPoseLibrary,
|
||||||
|
DSPL_OT_ProtectOrphanPoseLibrary
|
||||||
|
)
|
||||||
|
|
||||||
|
register, unregister = bpy.utils.register_classes_factory(classes)
|
||||||
|
Reference in New Issue
Block a user