From 022c1f7529a364929b9595a80229cb5bf95b43fe Mon Sep 17 00:00:00 2001 From: Owl Date: Thu, 28 Aug 2025 18:38:44 -0400 Subject: fixed a few things with rotations/superbmd collada exporting --- bck_export.py | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'bck_export.py') diff --git a/bck_export.py b/bck_export.py index 105106f..293cd12 100644 --- a/bck_export.py +++ b/bck_export.py @@ -92,12 +92,23 @@ def export_bck_func(options, context): elif (fcurve.data_path == bone_data_path_str + "location"): bone_fcurves[int((3 * fcurve.array_index) + 2)] = fcurve + # get the rest pose matrix + rest_mat = data_bone.matrix_local.copy() + if (pose_bone.parent != None): + rest_mat = data_bone.parent.matrix_local.copy().inverted() * rest_mat.copy() + else: + rest_mat = mathutils.Matrix.Identity(4) + # if there are foreign rotation modes used # convert them to the euler order mode requested # and assign those fcurves to the bone_fcurves list # (this is tuff) if (options.euler_mode != pose_bone.rotation_mode): - # generate the temp fcurves + # generate the temp fcurves but first check if they are animation tracks named that way already + all_fcurves = list(armature.animation_data.action.fcurves) + for fcurve in all_fcurves: + if (fcurve.group.name == "temp" or fcurve.data_path == "temp_fcurves"): # delete this animation track + armature.animation_data.action.fcurves.remove(fcurve) for j in range(3): temp_fcurves[j] = armature.animation_data.action.fcurves.new("temp_fcurves", j, "temp") og_rot_values = [None, None, None, None] # to hold original data @@ -106,9 +117,13 @@ def export_bck_func(options, context): if ("Z" in pose_bone.rotation_mode): # go through all animation frames for j in range(options.first_frame, options.anim_length): - # get the og data + # get the og data, if there is no fcurve, get the rest pose values for k in range(3): - og_rot_values[k] = foreign_fcurves[k].evaluate(j) + if (og_rot_values[k] != None): + og_rot_values[k] = foreign_fcurves[k].evaluate(j) + else: + og_rot_values[k] = rest_mat.to_euler(pose_bone.rotation_mode) + # compile into a matrix, get the desired angles from it in the new euler order tmp = mathutils.Euler(og_rot_values[0:3], pose_bone.rotation_mode) tmp = tmp.to_matrix().to_euler(options.euler_mode) @@ -120,9 +135,13 @@ def export_bck_func(options, context): elif (pose_bone.rotation_mode == "QUATERNION"): # go through all animation frames for j in range(options.first_frame, options.anim_length): - # get the og data + # get the og data, if there is no fcurve, get the rest pose values for k in range(4): - og_rot_values[k] = foreign_fcurves[k].evaluate(j) + if (foreign_fcurves[k] != None): + og_rot_values[k] = foreign_fcurves[k].evaluate(j) + else: + og_rot_values[k] = rest_mat.to_quaternion()[k] + # compile into a quaternion, get the desired angles from it in the new euler order tmp = mathutils.Quaternion(og_rot_values).to_euler(options.euler_mode) # assign the respective points to the temp fcurves @@ -133,9 +152,12 @@ def export_bck_func(options, context): elif (pose_bone.rotation_mode == "AXIS_ANGLE"): # go through all animation frames for j in range(options.first_frame, options.anim_length): - # get the og data + # get the og data, if there is no fcurve, get the rest pose values for k in range(4): - og_rot_values[k] = foreign_fcurves[k].evaluate(j) + if (og_rot_values[k] != None): + og_rot_values[k] = foreign_fcurves[k].evaluate(j) + else: + og_rot_values[k] = rest_mat.to_quaternion().to_axis_angle()[k] # compile into a matrix, get the desired angles from it in the new euler order tmp = mathutils.Matrix.Rotation(og_rot_values[0], 3, og_rot_values[1:]).to_euler(options.euler_mode) # assign the respective points to the temp fcurves @@ -149,13 +171,8 @@ def export_bck_func(options, context): # all the fcurves with the correct units were selected # generate all the new animation points, interpolation stuff will be done later - - # get the rest pose matrix - rest_mat = data_bone.matrix_local.copy() - if (pose_bone.parent != None): - rest_mat = data_bone.parent.matrix_local.copy().inverted() * rest_mat.copy() - else: - rest_mat = mathutils.Matrix.Identity(4) + print("huh?!") + print(temp_fcurves) # get the points on all frames, only the points for j in range(bck_anim.anim_length): @@ -219,7 +236,7 @@ def export_bck_func(options, context): bck_anim.anim_data[i].comp[j].in_slope = [None] bck_anim.anim_data[i].comp[j].out_slope = [None] - print(bck_anim) + # ~ print(bck_anim) # keep all the samples intact and calculate the slopes # using linear interpolation between consecutive frames @@ -307,11 +324,11 @@ def export_bck_func(options, context): bck_anim.anim_data[i].comp[j].out_slope = interp_result.out_slope # hopefully everything went okay - print(bck_anim) + # ~ print(bck_anim) # create a raw bck struct and write the BCK file raw = bck_funcs.create_smg_bck_raw(bck_anim) - print(raw) + # ~ print(raw) endian_ch = ">" # big endian character for struct.unpack() if (options.endian == "OPT_B"): # little character endian_ch = "<" -- cgit v1.2.3-70-g09d2