Move apply logic to common and eliminate selected bool
This commit is contained in:
69
common.py
69
common.py
@ -1,4 +1,5 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
|
||||
def getArmatureObject(context):
|
||||
@ -96,10 +97,14 @@ def createKeyframe(context, bone_name, transform, index_int, new_marker, loc):
|
||||
pass
|
||||
|
||||
|
||||
def setKeyframesFromBones(context, new_marker):
|
||||
arm_object = getArmatureObject(context)
|
||||
def setKeyframesFromBones(context, arm_object, new_marker):
|
||||
none_selected = True
|
||||
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
|
||||
|
||||
if bone.rotation_mode == "XYZ":
|
||||
@ -157,3 +162,61 @@ def setKeyframesFromBones(context, new_marker):
|
||||
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))
|
Reference in New Issue
Block a user