-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
861 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
bl_info = { | ||
"name": "Skyrim hkx format", | ||
"category": "Import-Export"} | ||
|
||
import bpy | ||
from io_anim_hkx import hka_import_op, hka_export_op | ||
|
||
def menu_func_import(self, context): | ||
self.layout.operator(hka_import_op.hkaImportOperator.bl_idname, text="Skyrim hkx (.hkx)") | ||
|
||
def menu_func_export(self, context): | ||
self.layout.operator(hka_export_op.hkaExportOperator.bl_idname, text="Skyrim hkx (.hkx)") | ||
|
||
def register(): | ||
bpy.utils.register_module(__name__) | ||
bpy.types.INFO_MT_file_import.append(menu_func_import) | ||
bpy.types.INFO_MT_file_export.append(menu_func_export) | ||
|
||
def unregister(): | ||
bpy.types.INFO_MT_file_import.remove(menu_func_import) | ||
bpy.types.INFO_MT_file_export.remove(menu_func_export) | ||
bpy.utils.unregister_module(__name__) | ||
|
||
if __name__ == "__main__": | ||
register() | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env python | ||
|
||
"""anim.bin exporter for blender 2.78 | ||
""" | ||
|
||
import os | ||
import bpy | ||
from math import radians | ||
from mathutils import Euler, Matrix, Quaternion, Vector | ||
# import numpy as np | ||
from io_anim_hkx.io.hka import hkaSkeleton, hkaAnimation, hkaPose, Transform | ||
from io_anim_hkx.naming import get_bone_name_for_blender | ||
|
||
|
||
def export_hkaAnimation(anim, skeleton): | ||
|
||
# | ||
# create bone map | ||
# | ||
# map pose_bone name to bone_idx | ||
|
||
bone_indices = {} | ||
|
||
nbones = len(skeleton.bones) | ||
|
||
for i in range(nbones): | ||
bone = skeleton.bones[i] | ||
# blender naming convention | ||
# io_scene_nifに合わせる | ||
p_bone_name = get_bone_name_for_blender(bone.name) | ||
bone_indices[p_bone_name] = i | ||
|
||
def detect_armature(): | ||
found = None | ||
for ob in bpy.context.selected_objects: | ||
if ob.type == 'ARMATURE': | ||
found = ob | ||
break | ||
return found | ||
|
||
def export_pose(): | ||
arm_ob = detect_armature() | ||
arm_ob.select = True | ||
|
||
anim.numOriginalFrames = 1 | ||
anim.duration = 0.033333 | ||
|
||
del anim.pose[:] | ||
pose = hkaPose() | ||
anim.pose.append(pose) | ||
|
||
pose.time = 0.0 | ||
|
||
for bone in skeleton.bones: | ||
t = bone.local.copy() | ||
pose.transforms.append(t) | ||
|
||
for p_bone in arm_ob.pose.bones: | ||
# bone mapに含まれないnameは無視する | ||
if p_bone.name not in bone_indices: | ||
continue | ||
bone_i = bone_indices[p_bone.name] | ||
|
||
pose_local = p_bone.bone.matrix_local * p_bone.matrix_basis | ||
|
||
if p_bone.bone.parent: | ||
m = p_bone.bone.parent.matrix_local.inverted() * pose_local | ||
else: | ||
m = pose_local | ||
|
||
location, rotation, scale = m.decompose() | ||
|
||
t = pose.transforms[bone_i] | ||
t.translation = location | ||
t.rotation = rotation | ||
t.scale = scale.z | ||
|
||
export_pose() | ||
# export_motion() | ||
|
||
|
||
def export_hkafile(skeleton_file, anim_file): | ||
|
||
skeleton = hkaSkeleton() | ||
skeleton.load(skeleton_file) | ||
|
||
anim = hkaAnimation() | ||
export_hkaAnimation(anim, skeleton) | ||
|
||
anim.save(anim_file) | ||
|
||
if __name__ == "__main__": | ||
from time import time | ||
|
||
start_time = time() | ||
|
||
skeleton_file = os.path.join(os.environ['HOME'], "resources/skeleton.bin") | ||
anim_file = "anim.bin" | ||
export_hkafile(skeleton_file, anim_file) | ||
|
||
end_time = time() | ||
print('bin export time:', end_time - start_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
"""hka export operator | ||
""" | ||
|
||
import os | ||
import subprocess | ||
|
||
import bpy | ||
from bpy_extras.io_utils import ExportHelper | ||
from io_anim_hkx.hka_export import export_hkafile | ||
|
||
|
||
class hkaExportOperator(bpy.types.Operator, ExportHelper): | ||
"""Export a hkaAnimationContainer file | ||
""" | ||
bl_idname = "export_anim.hkx" | ||
|
||
bl_label = "Export hkx" | ||
|
||
filename_ext = ".hkx" | ||
filter_glob = bpy.props.StringProperty(default="*.hkx", options={'HIDDEN'}) | ||
|
||
def execute(self, context): | ||
dirname = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
skeleton_file = dirname + "/resources/skeleton.bin" | ||
anim_hkx_file = self.properties.filepath | ||
|
||
basename = os.path.basename(anim_hkx_file) | ||
basename, extension = os.path.splitext(basename) | ||
anim_bin_file = dirname + '/tmp/' + basename + '.bin' | ||
|
||
export_hkafile(skeleton_file, anim_bin_file) | ||
|
||
command = dirname + '/bin/hkconv.exe' | ||
process = subprocess.run([command, '-o', anim_hkx_file, anim_bin_file]) | ||
|
||
return {'FINISHED'} |
Oops, something went wrong.