niftools / blender_niftools_addon

The Blender Niftools Addon is a Blender add-on to enable import and export of NetImmese File Formats including .nif, .kf, .egm.
http://www.niftools.org
Other
379 stars 103 forks source link

.kf export ignores IK and other bone constraints #501

Open arcusmaximus opened 2 years ago

arcusmaximus commented 2 years ago

Issue Overview

When exporting a skeletal animation to .kf, the addon appears to only look at bone transformation keyframes, disregarding the effects of bone constraints. This means it's not possible to use IK - you have to manually rotate each bone in the chain, which of course takes much more time.

If you're just creating a static pose, this is relatively easy to work around by selecting all bones, running Blender's "Apply Visual Transform To Pose" feature, and creating Rotation keyframes to store the result. If you're creating an animation, however, you'd have to do this for every frame, which might be even more time-consuming than not using IK.

Version Information

Blender Niftools Addon Version Info

0.0.13

Blender Version Info

2.93.1

Platform information

Windows 10

Context

Trying to create a dragon animation for Skyrim.

Steps to Reproduce

These steps are based on the Dragon.blend attached below. It consists of the standard Skyrim dragon mesh parented to the standard dragon skeleton, with two changes:

Reproduction steps:

  1. Open the .blend file and note the dragon's pose: wings raised (through manual bone rotation) and neck bent downwards (through IK).
  2. Export the scene to .kf
  3. Delete the IK constraint from the yellow "NPC Neck5" bone (neck returns to rest state).
  4. Select all bones and run Pose -> Clear Transform -> All (wings return to rest state).
  5. Import the .kf you just exported.

Expected Result

Both the wings and the neck return to their original pose.

Actual Result

The wings return to their original pose, but the neck stays in the rest state.

Logs and Files

Blend File

Dragon.zip

Possible Fix

One easy fix might be to check if the armature contains any bones with constraints, and if so, apply the workaround described above: for each frame of the scene, set it as the current frame, run "Apply Visual Transform", and create keyframes which can then be read by the conversion code. Of course, these keyframes would ideally be cleaned up again afterwards to avoid leaving a mess for the user.

Another possibility would be to refactor the conversion code to work like the Animation Tools N3+ Blender file by Anton and tktk. The script there also loops through each frame of the scene, but then directly retrieves each bone's matrix_local rather than going through F-curves.

Similar Known Issues

None I could find.

HENDRIX-ZT2 commented 2 years ago

The animations have to be baked. Blender can do that automatically. I have a system that handles constraints etc for another plugin. Just a matter of how we want to implement it, how much control we give to the user. It could happen completely on the fly

arcusmaximus commented 2 years ago

Aha, didn't know baking worked for this (I assumed it was only for physics simulations). That makes for a nice and easy workaround for animations too then - thanks for the tip.