-
Notifications
You must be signed in to change notification settings - Fork 112
Add support for KFA files import/export (DAOC) #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DigitalBox98
wants to merge
5
commits into
niftools:master
Choose a base branch
from
DigitalBox98:import_kfa
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,118 @@ | ||
"""This script imports Netimmerse/Gamebryo nif files to Blender.""" | ||
|
||
# ***** BEGIN LICENSE BLOCK ***** | ||
# | ||
# Copyright © 2019, NIF File Format Library and Tools contributors. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following | ||
# disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# | ||
# * Neither the name of the NIF File Format Library and Tools | ||
# project nor the names of its contributors may be used to endorse | ||
# or promote products derived from this software without specific | ||
# prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# ***** END LICENSE BLOCK ***** | ||
|
||
import os | ||
import bpy | ||
|
||
import pyffi.spells.nif.fix | ||
|
||
from io_scene_niftools.file_io.kf import KFFile | ||
from io_scene_niftools.modules.nif_export import armature | ||
from io_scene_niftools.modules.nif_export.animation.transform import TransformAnimation | ||
from io_scene_niftools.nif_common import NifCommon | ||
from io_scene_niftools.utils import math | ||
from io_scene_niftools.utils.singleton import NifOp, NifData | ||
from io_scene_niftools.utils.logging import NifLog, NifError | ||
from io_scene_niftools.modules.nif_export import scene | ||
from io_scene_niftools.modules.nif_export.block_registry import block_store | ||
|
||
|
||
class KfaExport(NifCommon): | ||
|
||
def __init__(self, operator, context): | ||
NifCommon.__init__(self, operator, context) | ||
|
||
# Helper systems | ||
self.transform_anim = TransformAnimation() | ||
|
||
def execute(self): | ||
"""Main export function.""" | ||
|
||
NifLog.info(f"Exporting {NifOp.props.filepath}") | ||
|
||
# extract directory, base name, extension | ||
directory = os.path.dirname(NifOp.props.filepath) | ||
filebase, fileext = os.path.splitext(os.path.basename(NifOp.props.filepath)) | ||
|
||
if bpy.context.scene.niftools_scene.game == 'NONE': | ||
raise NifError("You have not selected a game. Please select a game in the scene tab.") | ||
|
||
prefix = "" | ||
self.version, data = scene.get_version_data() | ||
NifData.init(data) | ||
|
||
b_armature = math.get_armature() | ||
# some scenes may not have an armature, so nothing to do here | ||
if b_armature: | ||
math.set_bone_orientation(b_armature.data.niftools.axis_forward, b_armature.data.niftools.axis_up) | ||
|
||
NifLog.info("Creating keyframe tree") | ||
kfa_root = self.transform_anim.export_kfa_root(b_armature) | ||
|
||
# write kfa | ||
ext = ".kfa" | ||
NifLog.info(f"Writing {prefix}{ext} file") | ||
|
||
data.roots = [] | ||
# first NiNode | ||
data.roots.append(kfa_root) | ||
|
||
# remaining NiNodes : corresponding to first bone position computed via NiKeyframeController | ||
kfc = kfa_root.controller | ||
|
||
while kfc != None: | ||
node_root = block_store.create_block("NiNode") | ||
# TODO : rotation | ||
# node_root.rotation = compute from kfc.data.quaternion_keys[0].value | ||
node_root.translation = kfc.data.translations.keys[0].value*NifOp.props.scale_correction | ||
# scale to improve | ||
node_root.scale = 1.0 | ||
data.roots.append(node_root) | ||
kfc = kfc.next_controller | ||
|
||
# scale correction for the skeleton | ||
self.apply_scale(data, round(1 / NifOp.props.scale_correction)) | ||
|
||
kfafile = os.path.join(directory, prefix + filebase + ext) | ||
with open(kfafile, "wb") as stream: | ||
data.write(stream) | ||
|
||
NifLog.info("Finished successfully") | ||
return {'FINISHED'} | ||
|
This file contains hidden or 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,91 @@ | ||
"""This script imports Netimmerse/Gamebryo nif files to Blender.""" | ||
|
||
# ***** BEGIN LICENSE BLOCK ***** | ||
# | ||
# Copyright © 2019, NIF File Format Library and Tools contributors. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following | ||
# disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# | ||
# * Neither the name of the NIF File Format Library and Tools | ||
# project nor the names of its contributors may be used to endorse | ||
# or promote products derived from this software without specific | ||
# prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# ***** END LICENSE BLOCK ***** | ||
|
||
import os | ||
|
||
import pyffi.spells.nif.fix | ||
|
||
from io_scene_niftools.file_io.kf import KFFile | ||
from io_scene_niftools.modules.nif_export import armature | ||
from io_scene_niftools.modules.nif_import.animation.transform import TransformAnimation | ||
from io_scene_niftools.nif_common import NifCommon | ||
from io_scene_niftools.utils import math | ||
from io_scene_niftools.utils.singleton import NifOp | ||
from io_scene_niftools.utils.logging import NifLog, NifError | ||
|
||
|
||
class KfaImport(NifCommon): | ||
|
||
def __init__(self, operator, context): | ||
NifCommon.__init__(self, operator, context) | ||
|
||
# Helper systems | ||
self.transform_anim = TransformAnimation() | ||
|
||
def execute(self): | ||
"""Main import function.""" | ||
|
||
try: | ||
dirname = os.path.dirname(NifOp.props.filepath) | ||
kfa_files = [os.path.join(dirname, file.name) for file in NifOp.props.files if file.name.lower().endswith(".kfa")] | ||
# if an armature is present, prepare the bones for all actions | ||
b_armature = math.get_armature() | ||
if b_armature: | ||
# the axes used for bone correction depend on the armature in our scene | ||
math.set_bone_orientation(b_armature.data.niftools.axis_forward, b_armature.data.niftools.axis_up) | ||
# get nif space bind pose of armature here for all anims | ||
self.transform_anim.get_bind_data(b_armature) | ||
for kfa_file in kfa_files: | ||
kfadata = KFFile.load_kf(kfa_file) | ||
|
||
self.apply_scale(kfadata, NifOp.props.scale_correction) | ||
|
||
# calculate and set frames per second | ||
self.transform_anim.set_frames_per_second(kfadata.roots) | ||
# verify if NiNodes are present | ||
if len(kfadata.roots)>0 : | ||
kfa_root=kfadata.roots[0] | ||
# no usage identified for others NiNode, so taking care only of the first one | ||
self.transform_anim.import_kfa_root(kfa_root, b_armature) | ||
|
||
except NifError: | ||
return {'CANCELLED'} | ||
|
||
NifLog.info("Finished successfully") | ||
return {'FINISHED'} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just the same as the bone_names mapped to their indices in
io_scene_niftools/modules/nif_import/animation/transform.py
? If so, it would probably be best to store it as one object (either list or dict) and obtain the other object from there, rather than hardcoding it twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, a new BonesMapper class has been added to handle this