Move apply logic to common and eliminate selected bool
This commit is contained in:
@ -40,9 +40,6 @@ class dsplVars(bpy.types.PropertyGroup):
|
|||||||
pose_new_name: bpy.props.StringProperty(
|
pose_new_name: bpy.props.StringProperty(
|
||||||
name="Pose Name", description="New name for pose",
|
name="Pose Name", description="New name for pose",
|
||||||
default="Pose", override={'LIBRARY_OVERRIDABLE'})
|
default="Pose", override={'LIBRARY_OVERRIDABLE'})
|
||||||
only_selected: bpy.props.BoolProperty(
|
|
||||||
name="Only selected Bones", description="Process only selected bones",
|
|
||||||
default=False, options={'HIDDEN'}, override={'LIBRARY_OVERRIDABLE'})
|
|
||||||
numero: bpy.props.IntProperty(
|
numero: bpy.props.IntProperty(
|
||||||
name='Numero', default=666, override={'LIBRARY_OVERRIDABLE'})
|
name='Numero', default=666, override={'LIBRARY_OVERRIDABLE'})
|
||||||
|
|
||||||
|
69
common.py
69
common.py
@ -1,4 +1,5 @@
|
|||||||
import bpy
|
import bpy
|
||||||
|
import mathutils
|
||||||
|
|
||||||
|
|
||||||
def getArmatureObject(context):
|
def getArmatureObject(context):
|
||||||
@ -96,10 +97,14 @@ def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def setKeyframesFromBones(context, new_marker):
|
def setKeyframesFromBones(context, arm_object, new_marker):
|
||||||
arm_object = getArmatureObject(context)
|
none_selected = True
|
||||||
for bone in arm_object.pose.bones:
|
for bone in arm_object.pose.bones:
|
||||||
if bone.bone.select or arm_object.dsplvars.only_selected == False:
|
if bone.bone.select:
|
||||||
|
none_selected = False
|
||||||
|
|
||||||
|
for bone in arm_object.pose.bones:
|
||||||
|
if bone.bone.select or none_selected == True:
|
||||||
bone_name = bone.name
|
bone_name = bone.name
|
||||||
|
|
||||||
if bone.rotation_mode == "XYZ":
|
if bone.rotation_mode == "XYZ":
|
||||||
@ -157,3 +162,61 @@ def setKeyframesFromBones(context, new_marker):
|
|||||||
createKeyframe(context, bone_name, "scale", 2, new_marker, scl_z)
|
createKeyframe(context, bone_name, "scale", 2, new_marker, scl_z)
|
||||||
|
|
||||||
|
|
||||||
|
def setBonesfromKeyframes(context, arm_object, active_marker):
|
||||||
|
none_selected = True
|
||||||
|
for bone in arm_object.pose.bones:
|
||||||
|
if bone.bone.select:
|
||||||
|
none_selected = False
|
||||||
|
|
||||||
|
for bone in arm_object.pose.bones:
|
||||||
|
if bone.bone.select or none_selected == True:
|
||||||
|
bone_name = bone.name
|
||||||
|
|
||||||
|
if bone.rotation_mode == "XYZ":
|
||||||
|
rot_mode = "rotation_euler"
|
||||||
|
elif bone.rotation_mode == "YZX":
|
||||||
|
rot_mode = "rotation_euler"
|
||||||
|
elif bone.rotation_mode == "ZXY":
|
||||||
|
rot_mode = "rotation_euler"
|
||||||
|
elif bone.rotation_mode == "QUATERNION":
|
||||||
|
rot_mode = "rotation_quaternion"
|
||||||
|
else:
|
||||||
|
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
||||||
|
rot_mode = None
|
||||||
|
|
||||||
|
loc_x = findFcurve(context, bone_name, "location", 0) or 0.0
|
||||||
|
loc_y = findFcurve(context, bone_name, "location", 1) or 0.0
|
||||||
|
loc_z = findFcurve(context, bone_name, "location", 2) or 0.0
|
||||||
|
if rot_mode == "rotation_quaternion":
|
||||||
|
rot_w = findFcurve(context, bone_name, rot_mode, 0) or 1.0
|
||||||
|
rot_x = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
||||||
|
rot_y = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
||||||
|
rot_z = findFcurve(context, bone_name, rot_mode, 3) or 0.0
|
||||||
|
elif rot_mode == "rotation_euler":
|
||||||
|
rot_x = findFcurve(context, bone_name, rot_mode, 0) or 0.0
|
||||||
|
rot_y = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
||||||
|
rot_z = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
||||||
|
scl_x = findFcurve(context, bone_name, "scale", 0) or 1.0
|
||||||
|
scl_y = findFcurve(context, bone_name, "scale", 1) or 1.0
|
||||||
|
scl_z = findFcurve(context, bone_name, "scale", 2) or 1.0
|
||||||
|
|
||||||
|
bone.location = mathutils.Vector((loc_x, loc_y, loc_z))
|
||||||
|
if bone.rotation_mode == "XYZ":
|
||||||
|
bone.rotation_euler = mathutils.Euler(
|
||||||
|
(rot_x, rot_y, rot_z))
|
||||||
|
elif bone.rotation_mode == "YZX":
|
||||||
|
bone.rotation_euler = mathutils.Euler(
|
||||||
|
(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))
|
2
gui.py
2
gui.py
@ -75,8 +75,6 @@ class DATA_PT_DSPLPanel(bpy.types.Panel):
|
|||||||
if active_pose_library.pose_markers.active:
|
if active_pose_library.pose_markers.active:
|
||||||
quick_apply_layout = quick_pose_controls_layout.split(
|
quick_apply_layout = quick_pose_controls_layout.split(
|
||||||
align=True)
|
align=True)
|
||||||
quick_apply_layout.prop(arm_object.dsplvars,
|
|
||||||
"only_selected", icon='GROUP_BONE', text="Selected", toggle=True)
|
|
||||||
quick_apply_layout.operator(
|
quick_apply_layout.operator(
|
||||||
"dspl.browse_poses", icon='CON_ARMATURE', text="Browse")
|
"dspl.browse_poses", icon='CON_ARMATURE', text="Browse")
|
||||||
if dsplsettings.new_menu == False:
|
if dsplsettings.new_menu == False:
|
||||||
|
67
operators.py
67
operators.py
@ -1,5 +1,4 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
|
||||||
import blf
|
import blf
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
@ -62,9 +61,10 @@ class DSPL_OT_DrawNewPoseMenu(bpy.types.Operator):
|
|||||||
pose_library = getPoseLib(context)
|
pose_library = getPoseLib(context)
|
||||||
dspl_new_pose_menu.prop(
|
dspl_new_pose_menu.prop(
|
||||||
arm_object.dsplvars, "pose_new_name", text="Name")
|
arm_object.dsplvars, "pose_new_name", text="Name")
|
||||||
dspl_new_pose_menu.prop(
|
# dspl_new_pose_menu.prop(
|
||||||
arm_object.dsplvars,
|
# # Might want to add this back in some form to match native copy/paste pose
|
||||||
"only_selected", icon='GROUP_BONE', text="Selected", toggle=True)
|
# arm_object.dsplvars,
|
||||||
|
# "only_selected", icon='GROUP_BONE', text="Selected", toggle=True)
|
||||||
dspl_new_pose_menu.operator(
|
dspl_new_pose_menu.operator(
|
||||||
"dspl.add_pose", icon='ADD', text="Add New Pose").posename = arm_object.dsplvars.pose_new_name
|
"dspl.add_pose", icon='ADD', text="Add New Pose").posename = arm_object.dsplvars.pose_new_name
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ class DSPL_OT_AddPose(bpy.types.Operator):
|
|||||||
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, new_marker)
|
setKeyframesFromBones(context, arm_object, new_marker)
|
||||||
|
|
||||||
action_object.pose_markers.active = pose_markers[pose_name]
|
action_object.pose_markers.active = pose_markers[pose_name]
|
||||||
bpy.context.area.tag_redraw()
|
bpy.context.area.tag_redraw()
|
||||||
@ -189,7 +189,7 @@ class DSPL_OT_AddPose(bpy.types.Operator):
|
|||||||
|
|
||||||
new_marker = target_frame
|
new_marker = target_frame
|
||||||
|
|
||||||
setKeyframesFromBones(context, 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))
|
||||||
|
|
||||||
@ -365,60 +365,9 @@ class DSPL_OT_ApplyPose(bpy.types.Operator):
|
|||||||
active_frame = active_marker.frame
|
active_frame = active_marker.frame
|
||||||
active_posename = active_marker.name
|
active_posename = active_marker.name
|
||||||
|
|
||||||
for bone in arm_object.pose.bones:
|
setBonesfromKeyframes(context, arm_object, active_marker)
|
||||||
if bone.bone.select or arm_object.dsplvars.only_selected == False:
|
|
||||||
bone_name = bone.name
|
|
||||||
|
|
||||||
if bone.rotation_mode == "XYZ":
|
print("Applied pose - " + active_posename)
|
||||||
rot_mode = "rotation_euler"
|
|
||||||
elif bone.rotation_mode == "YZX":
|
|
||||||
rot_mode = "rotation_euler"
|
|
||||||
elif bone.rotation_mode == "ZXY":
|
|
||||||
rot_mode = "rotation_euler"
|
|
||||||
elif bone.rotation_mode == "QUATERNION":
|
|
||||||
rot_mode = "rotation_quaternion"
|
|
||||||
else:
|
|
||||||
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
|
||||||
rot_mode = None
|
|
||||||
|
|
||||||
loc_x = findFcurve(context, bone_name, "location", 0) or 0.0
|
|
||||||
loc_y = findFcurve(context, bone_name, "location", 1) or 0.0
|
|
||||||
loc_z = findFcurve(context, bone_name, "location", 2) or 0.0
|
|
||||||
if rot_mode == "rotation_quaternion":
|
|
||||||
rot_w = findFcurve(context, bone_name, rot_mode, 0) or 1.0
|
|
||||||
rot_x = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
|
||||||
rot_y = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
|
||||||
rot_z = findFcurve(context, bone_name, rot_mode, 3) or 0.0
|
|
||||||
elif rot_mode == "rotation_euler":
|
|
||||||
rot_x = findFcurve(context, bone_name, rot_mode, 0) or 0.0
|
|
||||||
rot_y = findFcurve(context, bone_name, rot_mode, 1) or 0.0
|
|
||||||
rot_z = findFcurve(context, bone_name, rot_mode, 2) or 0.0
|
|
||||||
scl_x = findFcurve(context, bone_name, "scale", 0) or 1.0
|
|
||||||
scl_y = findFcurve(context, bone_name, "scale", 1) or 1.0
|
|
||||||
scl_z = findFcurve(context, bone_name, "scale", 2) or 1.0
|
|
||||||
|
|
||||||
bone.location = mathutils.Vector((loc_x, loc_y, loc_z))
|
|
||||||
if bone.rotation_mode == "XYZ":
|
|
||||||
bone.rotation_euler = mathutils.Euler(
|
|
||||||
(rot_x, rot_y, rot_z))
|
|
||||||
elif bone.rotation_mode == "YZX":
|
|
||||||
bone.rotation_euler = mathutils.Euler(
|
|
||||||
(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))
|
|
||||||
|
|
||||||
self.report({'INFO'}, "DSPL: Applied " + active_posename)
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user