summaryrefslogtreecommitdiff
path: root/bck_export.py
diff options
context:
space:
mode:
Diffstat (limited to 'bck_export.py')
-rw-r--r--bck_export.py77
1 files changed, 44 insertions, 33 deletions
diff --git a/bck_export.py b/bck_export.py
index 9ba4427..8d838ce 100644
--- a/bck_export.py
+++ b/bck_export.py
@@ -105,14 +105,16 @@ def export_bck_func(options, context):
value = None
# check which is the component to get
if (k == 0 or k == 3 or k == 6):
- value = new_mat.to_scale()[int((k - 0) / 3)]
+ value = round(new_mat.to_scale()[int((k - 0) / 3)], options.rounding_vec[0])
elif (k == 1 or k == 4 or k == 7):
- value = new_mat.to_euler("XYZ")[int((k - 1) / 3)]
+ value = round(new_mat.to_euler("XYZ")[int((k - 1) / 3)], options.rounding_vec[1])
elif (k == 2 or k == 5 or k == 8):
- value = 100 * new_mat.to_translation()[int((k - 2) / 3)] # conversion from blenxy's coordinates
+ value = round(100 * new_mat.to_translation()[int((k - 2) / 3)], options.rounding_vec[2])
+ # 100 times because of blenxy's coordinates
bck_anim.anim_data[i].comp[k].value.append(value)
# got all the animation points
+
# delete constant value animation tracks
for i in range(bck_anim.bone_count):
for j in range(9):
@@ -121,13 +123,7 @@ def export_bck_func(options, context):
if (k == 0):
continue
# check if the whole animation track is the same
- comp_min_dif = options.min_dif # min difference (radians)
- if (j == 0 or j == 3 or j == 6): # scale
- comp_min_dif = options.min_dif / 3
- elif (j == 2 or j == 5 or j == 8): # translation
- comp_min_dif = options.min_dif * 1000
- if (abs(bck_anim.anim_data[i].comp[j].value[k - 1]
- - bck_anim.anim_data[i].comp[j].value[k]) > comp_min_dif):
+ if (bck_anim.anim_data[i].comp[j].value[k - 1] != bck_anim.anim_data[i].comp[j].value[k]):
anim_track_constant = False
break
if (anim_track_constant == True):
@@ -160,8 +156,14 @@ def export_bck_func(options, context):
in_slope = bck_anim.anim_data[i].comp[j].value[k] - bck_anim.anim_data[i].comp[j].value[k - 1]
if (k < bck_anim.anim_length - 1):
out_slope = bck_anim.anim_data[i].comp[j].value[k + 1] - bck_anim.anim_data[i].comp[j].value[k]
- bck_anim.anim_data[i].comp[j].in_slope.append(in_slope)
- bck_anim.anim_data[i].comp[j].out_slope.append(out_slope)
+ # set the rounding digit
+ rounding = options.rounding_vec[0] # scale
+ if (j == 1 or j == 4 or j == 7): # rotation
+ rounding = options.rounding_vec[1]
+ elif (j == 2 or j == 5 or j == 8): # translation
+ rounding = options.rounding_vec[2]
+ bck_anim.anim_data[i].comp[j].in_slope.append(round(in_slope, rounding))
+ bck_anim.anim_data[i].comp[j].out_slope.append(round(out_slope, rounding))
# find "best" interpolator fits for the samples
elif (options.export_type == "OPT_B"):
@@ -176,20 +178,28 @@ def export_bck_func(options, context):
# get the best fit interpolation result
interp_result = math_funcs.find_best_cubic_hermite_spline_fit(options.first_frame,
bck_anim.anim_data[i].comp[j].value,
- options.angle_limit)
-
+ options.angle_limit)
+ # set the rounding digit
+ rounding = options.rounding_vec[0] # scale
+ if (j == 1 or j == 4 or j == 7): # rotation
+ rounding = options.rounding_vec[1]
+ elif (j == 2 or j == 5 or j == 8): # translation
+ rounding = options.rounding_vec[2]
+ # round all the values returned by the interpolation fit
+ for k in range(interp_result.kf_count):
+ interp_result.value[k] = round(interp_result.value[k], rounding)
+ if (k > 0):
+ interp_result.in_slope[k] = round(interp_result.in_slope[k], rounding)
+ if (k < interp_result.kf_count - 1):
+ interp_result.out_slope[k] = round(interp_result.out_slope[k], rounding)
+
# check if the fit can be made in interpolation mode == 0 (in_slope = out_slope)
# assign the best fit for each animation component
can_use_smooth_interp = True
- comp_min_dif = options.min_dif # min difference (radians)
- if (j == 0 or j == 3 or j == 6): # scale
- comp_min_dif = options.min_dif / 3
- elif (j == 2 or j == 5 or j == 8): # translation
- comp_min_dif = options.min_dif * 1000
for k in range(interp_result.kf_count):
if (k == 0 or k == interp_result.kf_count - 1):
continue
- if (abs(interp_result.in_slope[k] - interp_result.out_slope[k]) > comp_min_dif):
+ if (interp_result.in_slope[k] != interp_result.out_slope[k]):
can_use_smooth_interp = False
break
@@ -230,7 +240,7 @@ def export_bck_func(options, context):
# of the importer to work plus some setting stuff
# comes from a Blender importer template
from bpy_extras.io_utils import ExportHelper
-from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty, IntProperty
+from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty, IntProperty, IntVectorProperty
from bpy.types import Operator
# export_bck class
@@ -261,12 +271,12 @@ class export_bck(Operator, ExportHelper):
)
first_frame = IntProperty(
name = "First frame",
- description = "Value used to specify the first frame of the animation.",
+ description = "Value used to specify the first frame of the animation",
default = 0,
)
anim_length = IntProperty(
name = "Animation length",
- description = "Value used to specify the number of frames of the BCK animation after the first frame specified.",
+ description = "Value used to specify the number of frames of the BCK animation after the first frame specified",
default = 30,
)
loop_mode = EnumProperty(
@@ -274,11 +284,11 @@ class export_bck(Operator, ExportHelper):
description = "Way in which the animation be played in-game",
default = "OPT_C",
items = (
- ("OPT_A", "Play once - Stop at last frame", "Animation will start playing forwards and, when the animation data finishes, the last frame will be kept loaded into the model."),
- ("OPT_B", "Play once - Stop at first frame", "Animation will start playing forwards and, when the animation data finishes, the first frame will be kept loaded into the model."),
- ("OPT_C", "Repeat - Play forwards always", "Animation will start playing forwards and, when the animation data finishes, will play again from the beginning forwards."),
- ("OPT_D", "Play once - First forwards then backwards", "Animation will start playing forwards and, when the animation data finishes, the animation will be played backwards. This occurs only once."),
- ("OPT_E", "Repeat - Play forwards then backwards always", "Animation will start playing forwards and, when the animation data finishes, the animation will be played backwards. This repeats infinitely.")
+ ("OPT_A", "Play once - Stop at last frame", "Animation will start playing forwards and, when the animation data finishes, the last frame will be kept loaded into the model"),
+ ("OPT_B", "Play once - Stop at first frame", "Animation will start playing forwards and, when the animation data finishes, the first frame will be kept loaded into the model"),
+ ("OPT_C", "Repeat - Play forwards always", "Animation will start playing forwards and, when the animation data finishes, will play again from the beginning forwards"),
+ ("OPT_D", "Play once - First forwards then backwards", "Animation will start playing forwards and, when the animation data finishes, the animation will be played backwards. This occurs only once"),
+ ("OPT_E", "Repeat - Play forwards then backwards always", "Animation will start playing forwards and, when the animation data finishes, the animation will be played backwards. This repeats infinitely")
)
)
endian = EnumProperty(
@@ -290,11 +300,12 @@ class export_bck(Operator, ExportHelper):
("OPT_B", "Little", "Write data in the little endian byte ordering")
)
)
- min_dif = FloatProperty(
- name = "Minimum difference",
- description = "Minimum difference at which 2 numbers can be considered the same. For reference, this value is linked to randians magnitude",
- default = 0.001,
- min = 1e-9,
+ rounding_vec = IntVectorProperty(
+ name = "Round SRT to digit",
+ description = "Round the scale, rotation and translation values (in that order) to the specified decimal position",
+ default = (3, 5, 1),
+ min = 0,
+ max = 9
)
# what the importer actually does
def execute(self, context):