godotengine / godot-blender-exporter

Addon for Blender to directly export to a Godot Scene
GNU General Public License v2.0
1.15k stars 132 forks source link

Quaternion works wrong with bone-based (deformation) animation #142

Open RepairUnit3k6 opened 5 years ago

RepairUnit3k6 commented 5 years ago

OS: GNU/Linux Ubuntu

Godot version: Beta 2

Blender version: 2.79b

Issue description: Exporting to newer versions of Godot have destroyed animations. From merge #19193 quat works little different making this plugin unusable. While playing animation, every frame is core/math/quat.cpp:151 - Condition ' !q.is_normalized() ' is true. returned: Quat() or core/math/quat.cpp:150 - Condition ' !is_normalized() ' is true. returned: Quat() added to error log. Animations not dealing with rotation and just moving bones without rotating them are unaffected. Only bones are affected, if I simply rotate whole mesh (which is not possible for deformation animations) bug would not occur.

Minimal reproduction project:

I did as simple as I could. Behold my cube ! just use plugin to export it. Cube.zip

Jason0214 commented 5 years ago

Thanks for the report!

RepairUnit3k6 commented 5 years ago

Sorry, pressed wrong button.

RepairUnit3k6 commented 5 years ago

I found problem is that values inside quaternion are not in range between 0 to 1. I looked on plugin but I'm unable to pinpoint where are you dealing with keyframe rotation. I don't know python but there must be way how to normalize numbers.

Jason0214 commented 5 years ago

I did some investigation the other day, I am not able to reproduce the issue as you described. But I checked some quaternion frames length square, some example I got:

0.9999999890563667
1.000000003439075
1.0000000174107841
1.0000001384144854
0.999999965187933
0.9999999703071332
1.0000000235420325
1.0000000753559002
0.9999999940913824
0.9999999945307865
1.0000002036630926
1.0000000081613516
0.9999999870227114
1.000000011572027
0.9999999808575879
1.0000000076473228

looks like they are all normalized with a reasonable precision.

are you suggesting each value of a quaternion should be in range (0, 1)? that could be where the issue is, because some dimension of the exported quaternion have negative values.


by the way the exporter does quaternion writing here https://github.com/godotengine/godot-blender-exporter/blob/master/io_scene_godot/converters/animation/serializer.py#L319

Jason0214 commented 5 years ago

is it possible to normalize a quaternion to get all the four dimensions to be positive 🤔? could you give a point to where godot does this range (0, 1) check?

RepairUnit3k6 commented 5 years ago

? could you give a point to where godot does this range (0, 1) check?

Sure thing ! It is exactly this commit and this file. Errors I get are created by lines 149 and 150 (150 and 151 in godot, dude, all lines should start by 0) There is is_normalized() call which returns true if all values are in range from 0 to 1, otherwise return false.

is it possible to normalize a quaternion to get all the four dimensions to be positive ?

Yeah, I believe so. If they can make humans fly, everything is possible !

RepairUnit3k6 commented 5 years ago

Alright here is some math.

I also found if you put all four values of quaternion into array you can use this . They all speak in python which is language I don't understand but I still want to help.

Jason0214 commented 5 years ago

But the above 'normalize' is all about normalize the quaternion length to 1, which I think the exporter already did. Besides, the commit you are referring to is quite old commit ( even older than the exporter .. ) I am thinking it might still be some precision problem you are hitting

Jason0214 commented 5 years ago

I am not able to reproduce the issue either on my OSX or ubuntu, so could you give a try #146 ? I add a force normalizing quaternion, maybe it can solve your issue.

RepairUnit3k6 commented 5 years ago

I am not able to reproduce the issue either on my OSX or ubuntu, so could you give a try #146 ? I add a force normalizing quaternion, maybe it can solve your issue.

Does not work. Did you used GoDot 3.1 beta 2 ?I added .zip with desktop record while bug was happening. It works fine in previous versions of GoDot, something must have changed... Maybe, the new animation system is responsible for this ?

cube.zip Inside is .mp4 you can play. It is only 6 sec long but it shows what is happening.

Jason0214 commented 5 years ago

Ah, I am able to reproduce it with the beta2 linux version in your link. (Last time I tested it on a custom build which I pulled the latest master branch. )

Probably this is an bug at Godot side and having been fixed recently.


update: tested on beta2 osx version, problem can not reproduce

RepairUnit3k6 commented 5 years ago

@Jason0214 Just tried offlicial beta 6 Problem is still here. Animation system was reworked so I belive that is where problem is.

Jason0214 commented 5 years ago

well, this time able to reproduce on both linux and osx, I will look into it

Jason0214 commented 5 years ago

Looks like #146 fixes the issue on OSX, I will find sometime to test it on linux. Besides, based on the Godot log (quaternion non-normalized), I think it is the correct fix


update: not fixed on linux

RepairUnit3k6 commented 5 years ago

@Jason0214 I just noticed that if I set keyframe interpolation mode to "nearest" it works just fine (inside godot). Can you please confirm this on linux ? Unfortunately, I'm usually using linear or cubic... Both don't work. Looks like interpolation error which just proving my theory that it is fault of rewritten animation player.

Jason0214 commented 5 years ago

Yeah, it could be quaternion precision not handled very well in the new implementation. Maybe it could a good idea to open an issue in Godot side and link this thread, and I will try to find some time to talk with developers.

RepairUnit3k6 commented 5 years ago

@Jason0214 Issue opened

doyouknowaboutq commented 5 years ago

i'm using blender 2.80 and i tested my model with both of godot 3.0.6 and 3.1 official releases.

up edit: blender animation fps is 60.

here is blender animation with 3 keyframes: blenderanim

here is blender export settings: blenderexport

here is 3.1 animation player: 31anim the animation does not work at linear mode. it only works with nearest mode. and you know there is a lot of quat errors.

here is 3.0.6 animation player: 306anim there is no quat errors. the aniamtion working with nearest and linear mode. but why?

why the plugin is exporting animations with too many keyframes like that? (this problem there was in blender 2.79)

after some testing edit: i realized that if i set 90 the max angle settings in animation import menu, then animation has 3 keyframes as should as be.

omg edit: after setting the max angle to 90, there is no quat error and animation working with linear interpolation in godot 3.1

last edit: i think best option is 360 degree and is not working with "animation as actions" export mode. only working with "scene animation" mode. i think godot's re-importing doesn't effect to child animation players. maybe. i don't know.

phaitonican commented 5 years ago

Have the same bug with Blender 2.8 and latest exporter release .

It seems (like above said) adding ANY Object Constraint in Blender to the object solves the problem for me. Now every animation get's exported without needing to set the keyframe interpolation in Godot to "nearest".

Also it doesn't matter which export mode, "animations as actions" or something else (It can be anything, at least for me. What makes it work is setting any Object Constraint in Blender, for example Rotation Limiter like above said without even needing to set a value)

Bildschirmfoto 2019-05-05 um 14 54 52
RepairUnit3k6 commented 5 years ago

I just found out that XYZ Euler works good. Looks like problem applies only to WXYZ Quaternion. Using XYZ Euler seems to be solution, or at least workaround