Use words_separated instead of mixedCase for common functions

This commit is contained in:
2025-01-13 15:50:03 -06:00
parent cb3999de33
commit 21f2278990
3 changed files with 76 additions and 76 deletions

104
common.py
View File

@ -2,7 +2,7 @@ import bpy
import mathutils
def getArmatureData(context):
def get_armature_data(context):
try:
arm_object = context.active_object
if arm_object and arm_object.type == "ARMATURE":
@ -15,18 +15,18 @@ def getArmatureData(context):
return None, None
def getArmatureAction(context):
def get_armature_action(context):
try:
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
if getattr(arm_object.animation_data.action, "pose_markers", None):
return getattr(arm_object.animation_data, "action", None)
except:
pass
def searchPoseMarker(context, posename, type):
def search_pose_marker(context, posename, type):
try:
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
if type == "marker":
return pose_library.pose_markers.get(posename, None)
if type == "frame":
@ -37,8 +37,8 @@ def searchPoseMarker(context, posename, type):
pass
def findFcurve(context, bone_name, transform, index_int):
arm_object, pose_library = getArmatureData(context)
def find_fcurve(context, bone_name, transform, index_int):
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
active_frame = pose_markers.active.frame
@ -50,8 +50,8 @@ def findFcurve(context, bone_name, transform, index_int):
return None
def createFcurve(context, bone_name, transform, index_int):
arm_object, pose_library = getArmatureData(context)
def create_fcurve(context, bone_name, transform, index_int):
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
try:
@ -62,8 +62,8 @@ def createFcurve(context, bone_name, transform, index_int):
pass
def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
arm_object, pose_library = getArmatureData(context)
def create_keyframe(context, bone_name, transform, index_int, new_marker, loc):
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
try:
@ -74,7 +74,7 @@ def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
pass
def setKeyframesFromBones(context, arm_object, new_marker):
def set_keyframes_from_bones(context, arm_object, new_marker):
none_selected = True
for bone in arm_object.pose.bones:
if bone.bone.select:
@ -99,47 +99,47 @@ def setKeyframesFromBones(context, arm_object, new_marker):
loc_x = bone.location[0]
loc_y = bone.location[1]
loc_z = bone.location[2]
createFcurve(context, bone_name, "location", 0)
createFcurve(context, bone_name, "location", 1)
createFcurve(context, bone_name, "location", 2)
createKeyframe(context, bone_name, "location", 0, new_marker, loc_x)
createKeyframe(context, bone_name, "location", 1, new_marker, loc_y)
createKeyframe(context, bone_name, "location", 2, new_marker, loc_z)
create_fcurve(context, bone_name, "location", 0)
create_fcurve(context, bone_name, "location", 1)
create_fcurve(context, bone_name, "location", 2)
create_keyframe(context, bone_name, "location", 0, new_marker, loc_x)
create_keyframe(context, bone_name, "location", 1, new_marker, loc_y)
create_keyframe(context, bone_name, "location", 2, new_marker, loc_z)
if rot_mode == "rotation_quaternion":
rot_w = bone.rotation_quaternion[0]
rot_x = bone.rotation_quaternion[1]
rot_y = bone.rotation_quaternion[2]
rot_z = bone.rotation_quaternion[3]
createFcurve(context, bone_name, rot_mode, 0)
createFcurve(context, bone_name, rot_mode, 1)
createFcurve(context, bone_name, rot_mode, 2)
createFcurve(context, bone_name, rot_mode, 3)
createKeyframe(context, bone_name, rot_mode, 0, new_marker, rot_w)
createKeyframe(context, bone_name, rot_mode, 1, new_marker, rot_x)
createKeyframe(context, bone_name, rot_mode, 2, new_marker, rot_y)
createKeyframe(context, bone_name, rot_mode, 3, new_marker, rot_z)
create_fcurve(context, bone_name, rot_mode, 0)
create_fcurve(context, bone_name, rot_mode, 1)
create_fcurve(context, bone_name, rot_mode, 2)
create_fcurve(context, bone_name, rot_mode, 3)
create_keyframe(context, bone_name, rot_mode, 0, new_marker, rot_w)
create_keyframe(context, bone_name, rot_mode, 1, new_marker, rot_x)
create_keyframe(context, bone_name, rot_mode, 2, new_marker, rot_y)
create_keyframe(context, bone_name, rot_mode, 3, new_marker, rot_z)
elif rot_mode == "rotation_euler":
rot_x = bone.rotation_euler[0]
rot_y = bone.rotation_euler[1]
rot_z = bone.rotation_euler[2]
createFcurve(context, bone_name, rot_mode, 0)
createFcurve(context, bone_name, rot_mode, 1)
createFcurve(context, bone_name, rot_mode, 2)
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)
create_fcurve(context, bone_name, rot_mode, 0)
create_fcurve(context, bone_name, rot_mode, 1)
create_fcurve(context, bone_name, rot_mode, 2)
create_keyframe(context, bone_name, rot_mode, 0, new_marker, rot_x)
create_keyframe(context, bone_name, rot_mode, 1, new_marker, rot_y)
create_keyframe(context, bone_name, rot_mode, 2, new_marker, rot_z)
scl_x = bone.scale[0]
scl_y = bone.scale[1]
scl_z = bone.scale[2]
createFcurve(context, bone_name, "scale", 0)
createFcurve(context, bone_name, "scale", 1)
createFcurve(context, bone_name, "scale", 2)
createKeyframe(context, bone_name, "scale", 0, new_marker, scl_x)
createKeyframe(context, bone_name, "scale", 1, new_marker, scl_y)
createKeyframe(context, bone_name, "scale", 2, new_marker, scl_z)
create_fcurve(context, bone_name, "scale", 0)
create_fcurve(context, bone_name, "scale", 1)
create_fcurve(context, bone_name, "scale", 2)
create_keyframe(context, bone_name, "scale", 0, new_marker, scl_x)
create_keyframe(context, bone_name, "scale", 1, new_marker, scl_y)
create_keyframe(context, bone_name, "scale", 2, new_marker, scl_z)
def setBonesfromKeyframes(context, arm_object, active_marker):
def set_bones_from_keyframes(context, arm_object, active_marker):
none_selected = True
for bone in arm_object.pose.bones:
if bone.bone.select:
@ -161,21 +161,21 @@ def setBonesfromKeyframes(context, arm_object, active_marker):
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
loc_x = find_fcurve(context, bone_name, "location", 0) or 0.0
loc_y = find_fcurve(context, bone_name, "location", 1) or 0.0
loc_z = find_fcurve(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
rot_w = find_fcurve(context, bone_name, rot_mode, 0) or 1.0
rot_x = find_fcurve(context, bone_name, rot_mode, 1) or 0.0
rot_y = find_fcurve(context, bone_name, rot_mode, 2) or 0.0
rot_z = find_fcurve(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
rot_x = find_fcurve(context, bone_name, rot_mode, 0) or 0.0
rot_y = find_fcurve(context, bone_name, rot_mode, 1) or 0.0
rot_z = find_fcurve(context, bone_name, rot_mode, 2) or 0.0
scl_x = find_fcurve(context, bone_name, "scale", 0) or 1.0
scl_y = find_fcurve(context, bone_name, "scale", 1) or 1.0
scl_z = find_fcurve(context, bone_name, "scale", 2) or 1.0
bone.location = mathutils.Vector((loc_x, loc_y, loc_z))
if bone.rotation_mode == "XYZ":

8
gui.py
View File

@ -20,8 +20,8 @@ class DATA_PT_DSPLPanel(bpy.types.Panel):
# Detect Armature object and parent
armature_layout = dspl_panel_layout.column(align=True)
active_obj = context.active_object
arm_object, pose_library = getArmatureData(context)
pose_library_action = getArmatureAction(context)
arm_object, pose_library = get_armature_data(context)
pose_library_action = get_armature_action(context)
if arm_object:
if arm_object == active_obj:
@ -147,7 +147,7 @@ class OBJECT_MT_AddPoseMenu(bpy.types.Menu):
bl_label = "Add Pose"
def draw(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
dspl_add_menu_layout = self.layout
dspl_add_menu_layout.operator(
@ -162,7 +162,7 @@ class OBJECT_MT_ReplacePoseMenu(bpy.types.Menu):
bl_label = "Add Pose"
def draw(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
dspl_replace_menu_layout = self.layout
for pm in pose_library.pose_markers:

View File

@ -13,7 +13,7 @@ class DSPL_OT_CreatePoseLibrary(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
arm_object.pose_library = bpy.data.actions.new(
name=arm_object.name + "_PoseLib")
arm_object.pose_library.use_fake_user = True
@ -31,7 +31,7 @@ class DSPL_OT_ConvertPoseLibrary(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
if pose_library is None:
arm_object.pose_library = arm_object.animation_data.action
arm_object.animation_data.action = None
@ -52,7 +52,7 @@ class DSPL_OT_AddPose(bpy.types.Operator):
replace: bpy.props.BoolProperty(name="Replace", description="Replace existing pose", default=False, options={'SKIP_SAVE'})
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
if self.replace == False:
pose_markers = pose_library.pose_markers
new_name = self.posename
@ -80,7 +80,7 @@ class DSPL_OT_AddPose(bpy.types.Operator):
pose_markers.new(name=pose_name)
pose_markers[pose_name].frame = new_marker
setKeyframesFromBones(context, arm_object, new_marker)
set_keyframes_from_bones(context, arm_object, new_marker)
pose_library.pose_markers.active = pose_markers[pose_name]
bpy.context.area.tag_redraw()
@ -105,7 +105,7 @@ class DSPL_OT_AddPose(bpy.types.Operator):
new_marker = target_frame
setKeyframesFromBones(context, arm_object, new_marker)
set_keyframes_from_bones(context, arm_object, new_marker)
self.report({'INFO'}, "DSPL: Replaced " + pose_markers[new_name].name + " on frame " + str(pose_markers[new_name].frame))
@ -124,10 +124,10 @@ class DSPL_OT_RemovePose(bpy.types.Operator):
posename: bpy.props.StringProperty()
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
if self.posename:
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
pose_library.pose_markers.active_index = search_pose_marker(context, posename=self.posename, type="index")
active_index = pose_library.pose_markers.active_index
else:
active_index = pose_markers.active_index
@ -173,12 +173,12 @@ class DSPL_OT_RenamePose(bpy.types.Operator):
pose_new_name: bpy.props.StringProperty()
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
active_marker = pose_markers.active
if self.posename:
target_marker = searchPoseMarker(context, posename=self.posename, type="marker")
target_marker = search_pose_marker(context, posename=self.posename, type="marker")
else:
target_marker = active_marker
@ -211,12 +211,12 @@ class DSPL_OT_MovePose(bpy.types.Operator):
posename: bpy.props.StringProperty(name="Pose Name", default="", options={'SKIP_SAVE'})
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
if self.posename:
active_index = searchPoseMarker(context, posename=self.posename, type="index")
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
active_index = search_pose_marker(context, posename=self.posename, type="index")
active_marker = search_pose_marker(context, posename=self.posename, type="marker")
active_frame = active_marker.frame
active_posename = active_marker.name
else:
@ -261,21 +261,21 @@ class DSPL_OT_ApplyPose(bpy.types.Operator):
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
pose_markers = pose_library.pose_markers
if self.posename:
active_marker = searchPoseMarker(context, posename=self.posename, type="marker")
active_marker = search_pose_marker(context, posename=self.posename, type="marker")
active_frame = active_marker.frame
active_posename = active_marker.name
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
pose_library.pose_markers.active_index = search_pose_marker(context, posename=self.posename, type="index")
else:
active_index = pose_markers.active_index
active_marker = pose_markers.active
active_frame = active_marker.frame
active_posename = active_marker.name
setBonesfromKeyframes(context, arm_object, active_marker)
set_bones_from_keyframes(context, arm_object, active_marker)
self.report({'INFO'}, "DSPL: Applied " + active_posename)
@ -284,8 +284,8 @@ class DSPL_OT_ApplyPose(bpy.types.Operator):
def invoke(self, context, event):
if event.ctrl:
# Select
arm_object, pose_library = getArmatureData(context)
pose_library.pose_markers.active_index = searchPoseMarker(context, posename=self.posename, type="index")
arm_object, pose_library = get_armature_data(context)
pose_library.pose_markers.active_index = search_pose_marker(context, posename=self.posename, type="index")
return {'FINISHED'}
elif event.alt:
# Remove
@ -354,7 +354,7 @@ class DSPL_OT_BrowsePoses(bpy.types.Operator):
def invoke(self, context, event):
bpy.context.area.tag_redraw()
self.arm_object, self.pose_library = getArmatureData(context)
self.arm_object, self.pose_library = get_armature_data(context)
if self.pose_library is None:
self.report({'WARNING'}, "DSPL: Pose Library not active")
@ -383,7 +383,7 @@ class DSPL_OT_UnlinkPoseLibrary(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
arm_object, pose_library = getArmatureData(context)
arm_object, pose_library = get_armature_data(context)
try:
arm_object.pose_library = None