Compare commits
3 Commits
3dc5cff0a2
...
aa50442bc6
Author | SHA1 | Date | |
---|---|---|---|
aa50442bc6 | |||
4157a12531 | |||
13146b5a75 |
@ -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'})
|
||||||
|
|
||||||
|
71
common.py
71
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":
|
||||||
@ -111,7 +116,7 @@ def setKeyframesFromBones(context, new_marker):
|
|||||||
elif bone.rotation_mode == "QUATERNION":
|
elif bone.rotation_mode == "QUATERNION":
|
||||||
rot_mode = "rotation_quaternion"
|
rot_mode = "rotation_quaternion"
|
||||||
else:
|
else:
|
||||||
print("Unsupported bone!")
|
self.report({'WARNING'}, "DSPL: Unsupported bone: " + bone.name + ": " + bone.rotation_mode)
|
||||||
rot_mode = None
|
rot_mode = None
|
||||||
|
|
||||||
loc_x = bone.location[0]
|
loc_x = bone.location[0]
|
||||||
@ -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:
|
||||||
|
81
operators.py
81
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
|
||||||
|
|
||||||
@ -154,7 +154,6 @@ class DSPL_OT_AddPose(bpy.types.Operator):
|
|||||||
|
|
||||||
# Check for duplicate names
|
# Check for duplicate names
|
||||||
while pose_markers.find(new_name) > -1:
|
while pose_markers.find(new_name) > -1:
|
||||||
print("Duplicate posename detected")
|
|
||||||
new_name = self.posename + ".{:03d}".format(counter)
|
new_name = self.posename + ".{:03d}".format(counter)
|
||||||
counter += 1
|
counter += 1
|
||||||
else:
|
else:
|
||||||
@ -163,12 +162,12 @@ 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()
|
||||||
|
|
||||||
print("Added pose - " + 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:
|
||||||
arm_object = getArmatureObject(context)
|
arm_object = getArmatureObject(context)
|
||||||
@ -190,9 +189,9 @@ 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))
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@ -238,10 +237,11 @@ class DSPL_OT_RemovePose(bpy.types.Operator):
|
|||||||
|
|
||||||
pose_markers.remove(marker=active_marker)
|
pose_markers.remove(marker=active_marker)
|
||||||
|
|
||||||
print(next_index)
|
|
||||||
action_object.pose_markers.active = next_marker
|
action_object.pose_markers.active = next_marker
|
||||||
action_object.pose_markers.active_index = next_index
|
action_object.pose_markers.active_index = next_index
|
||||||
|
|
||||||
|
self.report({'INFO'}, "DSPL: Removed " + self.posename)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@ -365,59 +365,7 @@ 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":
|
|
||||||
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:
|
|
||||||
print("Unsupported bone!")
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
print("Applied pose - " + active_posename)
|
print("Applied pose - " + active_posename)
|
||||||
|
|
||||||
@ -500,7 +448,7 @@ class DSPL_OT_BrowsePoses(bpy.types.Operator):
|
|||||||
self.pose_lib = getPoseLib(context)
|
self.pose_lib = getPoseLib(context)
|
||||||
|
|
||||||
if self.pose_lib is None:
|
if self.pose_lib is None:
|
||||||
self.report({'WARNING'}, "Pose Library not active")
|
self.report({'WARNING'}, "DSPL: Pose Library not active")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
self.arm_object.pose.backup_create(self.pose_lib)
|
self.arm_object.pose.backup_create(self.pose_lib)
|
||||||
@ -508,12 +456,11 @@ class DSPL_OT_BrowsePoses(bpy.types.Operator):
|
|||||||
bpy.ops.dspl.apply_pose()
|
bpy.ops.dspl.apply_pose()
|
||||||
|
|
||||||
if context.area.type == 'VIEW_3D':
|
if context.area.type == 'VIEW_3D':
|
||||||
print("Starting modal")
|
self.report({'INFO'}, "DSPL: Browsing Poses")
|
||||||
args = (self, context)
|
args = (self, context)
|
||||||
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
|
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
|
||||||
context.window_manager.modal_handler_add(self)
|
context.window_manager.modal_handler_add(self)
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
print("not in 3d")
|
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
|
||||||
@ -576,7 +523,7 @@ class DSPL_OT_ProtectOrphanPoseLibrary(bpy.types.Operator):
|
|||||||
if orphaned_act:
|
if orphaned_act:
|
||||||
for act in orphaned_act:
|
for act in orphaned_act:
|
||||||
if "_loc" in act.name or "PoseLib" in act.name:
|
if "_loc" in act.name or "PoseLib" in act.name:
|
||||||
print("Protecting orphaned action: " + act.name)
|
self.report({'INFO'}, "DSPL: Protecting orphaned action: " + act.name)
|
||||||
act.use_fake_user = True
|
act.use_fake_user = True
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
Reference in New Issue
Block a user