godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.1k stars 21.18k forks source link

Godot seems to apply a rotation to my animated characters root node #18790

Closed jesperkondrup closed 5 years ago

jesperkondrup commented 6 years ago

Godot 3.1, Win10

When Importing my animated character in the Open Collada (dae) format into godot the node Bip001 gets a Rotation of 90 degrees even though it has no rotation. This means that when I play the animation it rotates the character 90 degrees in the first frame.

The model was created in 3ds max using the Biped system and then exported to Blender as Fbx to convert it to a Better Collada file. The Bip001 root node should not have a rotation what so ever.

The dae model looks correct in 3ds max, Blender and Unity. I can see that root node also has a rotation in Unity but the model does not rotate when playing the animation.

An idea: Could it be that Unity has already set the animation when importing an animation object whereas in Godot it does not take the animation into account until you press play on the animation?

Steps to reproduce: Import a rigged character with an animation, possible also with an animation on the root node (Bip001) and hit play animation in Godot, this should "snap" the model to a 90 degree angel.

image

romlok commented 6 years ago

Can you upload a .blend file which exhibits the issue? That would make it easier for others to replicate.

From my own (albeit limited) experience, either the Collada exporter or Godot seems to include transforms for all nodes/bones in animations, even when the action in Blender doesn't have keyframes on those nodes. If you disable the root node in the animation player (the checkbox on the left side), does that fix the issue? (Assuming that the root node isn't supposed to be animated)

jesperkondrup commented 6 years ago

Ok, so I took some time to investigate further and I am not sure I got any wiser. Godot seems to change some values for the imported Collada model (dae). It looks correct in 3ds max, blender and Unity but in Godot the rotation and position does not seem to get imported correct. It only seems to affect the bip001, root node. Also If I make the character jump forward he jumps to the side in Godot.

I have included all the dae files and fbx files below. fbx files are exported from 3ds max. dae files are exported from Blender using Better Collada.

In this image the character should lean to the right, but in godot he does not seem to lean and his foot goes below 0 image

In this image the character jumps to the side in Godot instead of forward: image BipedMaleTest.zip

groud commented 6 years ago

Related / duplicate to #14399

romlok commented 6 years ago

Working from the BipedMaleTestStanding FBX, it seems the root Bip001 has a basic -90° rotation applied to it. I was able to get the orientation correct in Godot by "applying" the rotation on the Bip001 object in Blender (Object->Apply->Rotation) before exporting to dae.

However, due to the base object previously having a rotation, all the animations had been created with rotation keyframes on Bip001 - which means that the animations in Blender (but not in Godot!) will be pointing off in the opposite direction to the original issue after you "apply". I fixed this by selecting and deleting the animation channels for Bip001 itself on both actions (via the Dope sheet->Action editor).

It seems the collada exporter doesn't handle rotation keys on the root node correctly?

jesperkondrup commented 6 years ago

Thanks for looking into this @romlok. I don't think it's a problem in the Collada exporter since the dae file works perfectly in Unity. So I am almost certain that the problem lies in the importer.

glaforte commented 5 years ago

I reproduced the problem, yesterday evening. I've checked the bind-pose matrix and it seems to import fine. In Blender, I've removed the keyframes on the Armature and the export was fixed. My hunch is that when imported in Godot: the first keyframe of the Armature transform is applied as a standard transform, but also added to the animation.

glaforte commented 5 years ago

When I export with the Blender default COLLADA exporter, there are incoherence in the animation targets for the Armature Transforms. The contains a transform, but nine separate animation curves are exported that target nine individual transform components such as location.X, location.Y, location.Z... Godot does not import that animation data, but it does create two keys for the Skeleton node's transform. Since there were animation targets for this COLLADA transform (even if we understood none), keys are taken, using the original transform.

When I export with the Godot's Better COLLADA exporter for Blender, the animation target for the Armature Transform is fine. The matrices in the animation curve, in the COLLADA document, are fine. When imported in Godot, its orientation quaternion is set to the identity (rather than a 90d rotation around the up-axis).

In both cases, the transform keys are analysed and converted into scale/orientation quaternion/position. This includes checking for a singular matrix. This check for a singular matrix is done in float-precision and the reporter's data does include a 0.01x scale. This 0.01x scale gives a determinant of 1e-6, which "is_equal_approx" to zero, so the orientation quaternion remains identity. A scale of 0.01 is pretty common in inter-op with Maya and MotionBuilder, so is there another way to extract that quaternion?

glaforte commented 5 years ago

Looks like my fix for #22848 was part of the issue. I've improved that fix and I'm posting a PR. Otherwise, the animations now import properly with the 0.01 uniform scale.

akien-mga commented 5 years ago

Closing as fixed by 9d411615 as per #24036.