Exported animation is not accurate when using DirectX Exporter #44314

Closed
opened 2015-04-08 22:45:12 +02:00 by Dmitry · 15 comments

System Information
Windows 8.1, GeForce GTX 660 Ti

Blender Version
Broken: 2.74 and all previous

When I export an animated character to X file, the exported animation does not match the one in Blender.
There is a subtle but annoying mismatch.
Attached is a Blend file to reproduce this problem. Many other animated models have the same issue.

Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps

  1. Select a bone
  2. Pose -> Animation -> Bake Action -> Invert all 4 check boxes -> OK.
  3. File -> Export -> DirectX
  4. Uncheck Export Materials, check everything from "Export Skin Weights" to "Include Frame Rate"
  5. Export DirectX
  6. Open X file in DirectX Viewer or any other X viewer

Notice that in X file the arms go through the body.
But in Blender the arms don't touch the body.

Please help!
Issue.zip

**System Information** Windows 8.1, GeForce GTX 660 Ti **Blender Version** Broken: 2.74 and all previous When I export an animated character to X file, the exported animation does not match the one in Blender. There is a subtle but annoying mismatch. Attached is a Blend file to reproduce this problem. Many other animated models have the same issue. **Exact steps for others to reproduce the error** Based on a (as simple as possible) attached .blend file with minimum amount of steps 1) Select a bone 2) Pose -> Animation -> Bake Action -> Invert all 4 check boxes -> OK. 3) File -> Export -> DirectX 4) Uncheck Export Materials, check everything from "Export Skin Weights" to "Include Frame Rate" 5) Export DirectX 6) Open X file in DirectX Viewer or any other X viewer Notice that in X file the arms go through the body. But in Blender the arms don't touch the body. Please help! [Issue.zip](https://archive.blender.org/developer/F159931/Issue.zip)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @MakKlaski

Added subscriber: @MakKlaski
Author

Oops... in addition...
After Step 2:
2.1) Change Rig to Object mode
2.2) Select Rig
2.3) Shift+Select the Character. Now model and bones are selected. Go to step 3.

Oops... in addition... After Step 2: 2.1) Change Rig to Object mode 2.2) Select Rig 2.3) Shift+Select the Character. Now model and bones are selected. Go to step 3.
Chris Foster was assigned by Sergey Sharybin 2015-04-14 11:41:38 +02:00

Added subscriber: @Sergey

Added subscriber: @Sergey

Chris, do you mind having a look? Thanks! :)

Chris, do you mind having a look? Thanks! :)
Author

Dear Blender gurus,

I have manage to fix the problems myself by adding some changes to export_x.py.
It works for my particular case. You should probably make it a bit more generic.
OK, so...
You will not get issues by using plain regular bones.
But I'm using Rigify addon, which adds some complexity.
There are 2 problems:

  1. in Rigify the Shoulder bone has a different Rotation Mode, which is YXZ Euler. If you change it to Quaternion the problem with this bone disappears.
    New code in _GenerateBoneKeys after
for Bone, BoneAnimation in zip(ArmatureObject.pose.bones, BoneAnimations):
Bone.rotation_mode = 'QUATERNION'

Changes Rotation Mode of every bone to Quaternion.
2) The dreaded "Inherit Rotation" problem. SlvSpine bone has this mode turned off, but the exporter doesn't check this.
I think I should check for use_inherit_rotation, but I have not found it. So I'm just checking the bone's name.
After

Rotation = ArmatureObject.data.bones[Bone.name] \ ...
if Bone.name.startswith('Slv'):
  Rotation = ArmatureObject.data.bones[Bone.name].matrix.to_quaternion()

It seems that this fixes the problem with SlvSpine bone.

Dear Blender gurus, I have manage to fix the problems myself by adding some changes to export_x.py. It works for my particular case. You should probably make it a bit more generic. OK, so... You will not get issues by using plain regular bones. But I'm using Rigify addon, which adds some complexity. There are 2 problems: 1) in Rigify the Shoulder bone has a different Rotation Mode, which is YXZ Euler. If you change it to Quaternion the problem with this bone disappears. New code in _GenerateBoneKeys after ``` for Bone, BoneAnimation in zip(ArmatureObject.pose.bones, BoneAnimations): Bone.rotation_mode = 'QUATERNION' ``` Changes Rotation Mode of every bone to Quaternion. 2) The dreaded "Inherit Rotation" problem. SlvSpine bone has this mode turned off, but the exporter doesn't check this. I think I should check for use_inherit_rotation, but I have not found it. So I'm just checking the bone's name. After ``` Rotation = ArmatureObject.data.bones[Bone.name] \ ... ``` ``` if Bone.name.startswith('Slv'): Rotation = ArmatureObject.data.bones[Bone.name].matrix.to_quaternion() ``` It seems that this fixes the problem with SlvSpine bone.
Member

Sergey: Thanks for bringing this to my attention!

Dmitry: Thanks a lot for looking into the cause of the problem; that's a big help! I'll take a look at this tonight and see what kind of general solution can be made.

Sergey: Thanks for bringing this to my attention! Dmitry: Thanks a lot for looking into the cause of the problem; that's a big help! I'll take a look at this tonight and see what kind of general solution can be made.
Author

Still having problems, now with the neck.
Because of this part I've added

Rotation = ArmatureObject.data.bones[Bone.name].matrix.to_quaternion()

I don't really understand this code

Rotation = ArmatureObject.data.bones[Bone.name] \
  .matrix.to_quaternion() * \
  Bone.rotation_quaternion

Looks like: take bone's global rotation and multiply it with local rotation or something. Doesn't make sense.
Stuck with this Inherit-Rotation-unchecked thing.
Other people are having problems in other exporters too.
http://blender.stackexchange.com/questions/10913/workaround-for-inherit-rotation-in-armature

Still having problems, now with the neck. Because of this part I've added ``` Rotation = ArmatureObject.data.bones[Bone.name].matrix.to_quaternion() ``` I don't really understand this code ``` Rotation = ArmatureObject.data.bones[Bone.name] \ .matrix.to_quaternion() * \ Bone.rotation_quaternion ``` Looks like: take bone's global rotation and multiply it with local rotation or something. Doesn't make sense. Stuck with this Inherit-Rotation-unchecked thing. Other people are having problems in other exporters too. http://blender.stackexchange.com/questions/10913/workaround-for-inherit-rotation-in-armature
Member

A more robust fix has been pushed for handling bones with different rotation_mode values.

The code you've highlighted takes a bone's Edit mode orientation (local) and applies its Pose mode orientation on top of that (which is local to the Edit mode orientation) to get the posed transformation relative to the bone's parent.

I'll take a look at the Inherit Rotation issue next.

A more robust fix has been pushed for handling bones with different rotation_mode values. The code you've highlighted takes a bone's Edit mode orientation (local) and applies its Pose mode orientation on top of that (which is local to the Edit mode orientation) to get the posed transformation relative to the bone's parent. I'll take a look at the Inherit Rotation issue next.
Member

I've fixed the Inherit Rotation issue, I believe. However, Campbell had an issue with how I resolved the first problem and reverted it, making a different change. I'll push my fix for the second issue when this gets resolved.

I've fixed the Inherit Rotation issue, I believe. However, Campbell had an issue with how I resolved the first problem and reverted it, making a [different change](https://developer.blender.org/rBAf63d9de38b7e85ae5f0c93d419b10e7789b6bd3a). I'll push my fix for the second issue when this gets resolved.
Member

Dmitry: I just pushed changes that should fix all of your problems. Can you confirm this?

Dmitry: I just pushed changes that should fix all of your problems. Can you confirm this?
Author

How can I get the latest version?

How can I get the latest version?
Author

OK, found it.

Works very well! I've made tests with couple of different models/animations.
The movements are exactly the same as in blender! Awesome!
Thank you very much!

OK, found it. Works very well! I've made tests with couple of different models/animations. The movements are exactly the same as in blender! Awesome! Thank you very much!
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Member

Great! Glad to hear it.

Great! Glad to hear it.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#44314
No description provided.