summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwl <isaclien9752@gmail.com>2025-08-28 18:38:44 -0400
committerOwl <isaclien9752@gmail.com>2025-08-28 18:38:44 -0400
commit022c1f7529a364929b9595a80229cb5bf95b43fe (patch)
treed65c329ac925d164e694ae1437953998b6a024c5
parentf4ff299e4e073b71495a3e2a385fa96d65fb6f80 (diff)
downloadblenxy-022c1f7529a364929b9595a80229cb5bf95b43fe.tar.gz
blenxy-022c1f7529a364929b9595a80229cb5bf95b43fe.zip
fixed a few things with rotations/superbmd collada exporting
-rw-r--r--__init__.py14
-rw-r--r--basic_settings.py2
-rw-r--r--bck_export.py51
-rw-r--r--collada_superbmd_export.py41
4 files changed, 74 insertions, 34 deletions
diff --git a/__init__.py b/__init__.py
index 3eebb3f..7379f82 100644
--- a/__init__.py
+++ b/__init__.py
@@ -23,13 +23,13 @@ def new_mod_check(mod_names):
# skip numpy if the numpy_bad folder was created
if (mod_name == "numpy"):
for path in site.getsitepackages():
- if ("2.79" in path):
- numpy_path = path + "/numpy"
- numpy_bad_path = path + "/numpy_bad"
- # rename the existing numpy folder to numpy bad and install newer numpy
- if (file_ops.f_exists(numpy_bad_path) == False):
- file_ops.rename(numpy_path, numpy_bad_path)
- rtn.append("numpy")
+ numpy_path = path + "/numpy"
+ numpy_bad_path = path + "/numpy_bad"
+ # rename the existing numpy folder to numpy bad and install newer numpy
+ if (("2.79" in path) and ("site-packages" in path)
+ and (file_ops.f_exists(numpy_bad_path) == False)):
+ file_ops.rename(numpy_path, numpy_bad_path)
+ rtn.append("numpy")
break
continue
diff --git a/basic_settings.py b/basic_settings.py
index 49df15f..c1036ef 100644
--- a/basic_settings.py
+++ b/basic_settings.py
@@ -84,7 +84,7 @@ def register(dummy):
scene.frame_preview_start = 0
scene.frame_current = 0
scene.frame_preview_end = 100
- bpy.context.user_preferences.view.use_mouse_depth_navigate = True
+ # ~ bpy.context.user_preferences.view.use_mouse_depth_navigate = True
# ~ bpy.context.user_preferences.view.use_zoom_to_mouse = True
print("Done with the basic settings!\n")
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 = "<"
diff --git a/collada_superbmd_export.py b/collada_superbmd_export.py
index f66085c..2f92fa3 100644
--- a/collada_superbmd_export.py
+++ b/collada_superbmd_export.py
@@ -53,19 +53,42 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
# vertex groups if none of those are just create them,
# I don't think it is bad to automate that
for mesh in armature.children:
- if("Armature" not in mesh.modifiers):
+ # check if all meshes have an armature modifier
+ has_armature_modifier = False
+ has_multiple_armature_modifiers = False
+ armature_modifier = None
+
+ # iterate over the mesh modifiers
+ i = 0
+ while (i < len(mesh.modifiers)):
+ # check the existance of an armature modifier
+ if (mesh.modifiers[i].type == "ARMATURE"):
+ if (has_armature_modifier == False):
+ has_armature_modifier = True
+ armature_modifier = mesh.modifiers[i] # save current armature modifier
+ else: # 2 armature modifiers? (remove duplicates)
+ has_multiple_armature_modifiers = True
+ mesh.modifiers.remove(mesh.modifiers[i])
+ i -= 1
+ i += 1
+
+ # notify the user about duplicate armature modifiers
+ if (has_multiple_armature_modifiers == True):
+ blender_funcs.disp_msg("\"%s\": has two or armature modifiers. Removing duplicates..." % (mesh.name))
+
+ # check if there is actually an armature modifier
+ if (has_armature_modifier == False):
blender_funcs.disp_msg("\"%s\": has no armature modifier. Adding one..." % (mesh.name))
- blender_funcs.select_obj(mesh, False, "OBJECT")
- bpy.ops.object.modifier_add(type = "ARMATURE")
- mesh.modifiers["Armature"].object = armature
- mesh.modifiers["Armature"].use_vertex_groups = True
+ armature_modifier = mesh.modifiers.new(name = armature.name, type = "ARMATURE")
+ armature_modifier.object = armature
+ armature_modifier.use_vertex_groups = True
else: # ensure bind is to a vertex group and that the bind is to the actual parent armature
- if (mesh.modifiers["Armature"].use_vertex_groups == False):
+ if (armature_modifier.use_vertex_groups == False):
blender_funcs.disp_msg("\"%s\": armature modifier wasn't binded to vertex groups" % (mesh.name))
- mesh.modifiers["Armature"].use_vertex_groups = True
- if (mesh.modifiers["Armature"].object != armature):
+ armature_modifier.use_vertex_groups = True
+ if (armature_modifier.object != armature):
blender_funcs.disp_msg("\"%s\": armature modifier was binded to another armature object" % (mesh.name))
- mesh.modifiers["Armature"].object = armature;
+ armature_modifier.object = armature;
# check if all the vertex groups in each mesh correspond to the name of a skeleton bone
bone_name_list = []