ufbx / ufbx

Single source file FBX loader
Other
734 stars 48 forks source link

What are ufbx_bake_anim()'s returned transformations exactly? #106

Closed TJYSunset closed 3 months ago

TJYSunset commented 4 months ago

Is it correct to assert ufbx_bake_anim() returns the effective node_to_parents at each specific keyframe, that already haven taken space conversions into account?

Sorry for my stupidity, but I'm getting Lovecraftian deities for my skeletal animation playback (while getting the correct T-pose when using the original node_to_parent), and would appreciate some concrete info on how this library works to narrow down the cause.

bqqbarbhg commented 4 months ago

Yeah sounds about right, or more precisely it should return the components for the ufbx_node.local_transform, which you can of course convert to a matrix using ufbx_transform_to_matrix() (or manually for that matter).

Sorry for the lack of documentation, this is quite a new feature I've added. I wrote some initial descriptions but didn't have time to merge them yet:

https://github.com/ufbx/ufbx/blob/edb6c505e50d5aed13740add09c8026c2c49c2fe/ufbx.h#L4210-L4285

I haven't encountered the issue you're seeing yet myself though, and there's not that much that can go wrong. I'd recommend double checking that you're not mixing up element_id (refers to ufbx_scene.elements[]) and typed_id (refers to ufbx_scene.nodes[]). The dual ID setup is a bit confusing, but I'm not sure how it could be improved.

Another thing you can try is seeing if ufbx_evaluate_transform() returns reasonable values, or even ufbx_evaluate_scene(), in case the animations in the file itself are broken. Let me know if you find anything, otherwise I'd need more context to tell what could be going wrong.

TJYSunset commented 4 months ago

Turns out it's yet another exporter problem...

Changing the exporter settings and constructing bone matrices using ufbx_skin_cluster.geometry_to_bone instead of ufbx_node.node_to_world solved my particular issue. Ironic how FBX is still the exchange format with the least compatibility problems.

Working export settings for others using Auto-Rig Pro ![Rig Panel](https://github.com/ufbx/ufbx/assets/12986688/42421bfc-49a5-4056-854f-2b8d4f9f920c) ![Misc Panel](https://github.com/ufbx/ufbx/assets/12986688/7e0e2ecc-869b-4b44-9da8-37d4a0849152)

I could provide a sample of funny FBX later if you're interested. (By "later" I mean I have to make a new dummy model, because I sculpted my own "production" model and I'm not proud enough of how ugly it looks to share publicly.)

bqqbarbhg commented 4 months ago

Interesting, thanks for the update! I try to mitigate the FBX issues as much as I can but the format/exporters always finds a way to surprise.. Using geometry_to_bone is the correct thing to do for skinning, hopefully it'll be more clear when I get the real documentation done.

As for funny FBXs, I'm always interested, more cursed the better :D If you don't want to share models publicly you can also send them to bqqbarbhg gmail.com and I can put it in my private dataset. However, if you're feeling extra generous and can share it as CC-BY (or CC0), I can add it to the public dataset that gets run on CI. No pressure about the file though, no need to spend too much time on it.

TJYSunset commented 4 months ago

Here's a dummy mesh generated with Skinify Rig on Auto-Rig Pro 3.69.13*'s default human armature, with a linear IK interpolation from T-Pose to a random pose, exported with all default presets and two whacky configurations.

* Not the latest version (3.69.43) available, I haven't updated for a while while working on my engine.

ArpDummy.zip

Public Domain / CC0, if this thing is actually copyrightable.

Not tested in my engine to not work, because the engine is currently a multi-part dumpster fire that doesn't accept arbitrary meshes, not yet committed to Git because that whole submodules crap... If these all look normal, I'll try generating something backed by code.

Feel free to close this issue if deemed appropriate (apparently the last time I closed too arbitrarily...)

bqqbarbhg commented 4 months ago

Thanks, I'll take a look at it when I have time!

And no sweat about closing issues, etc. I just have a habit of following up on resolved issues just in case there's an angle that can be used to improve ufbx in the future. I'll keep this one open until I can check the file in case there's something actually off with ufbx.

bqqbarbhg commented 3 months ago

Thanks a ton again for the files, finally managed to get them to the dataset tests! (upgraded the physical machine from RPI4 to RPI5 yesterday and added some threading, runtime went from 24min to ~3min)

Seems like the files work just fine using check_fbx.c, which is used to compare it to a reference .obj file exported from Maya in this case. Ran the tests both with ufbx_bake_anim() and without.

Dataset CI logs for the files ``` == 'ArpDummy' by 'TYJSunset' (CC0) == source url: https://github.com/ufbx/ufbx/issues/106#issuecomment-2003779213 .json url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid.json -- issue/106/arp-humanoid/ArpWhatWasntWorkingForMe.fbx [frame 7] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe_frame7.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe_frame7.obj.gz --frame 7 Loaded in 37.71ms: File 656.3kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.18e-07, max 3.26e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpWhatWasntWorkingForMe_frame7.obj.gz --frame 7 --bake Loaded in 52.10ms: File 656.3kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.18e-07, max 3.26e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpHumanoidUnity.fbx [frame 2] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidUnity.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidUnity_frame2.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnity.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnity_frame2.obj.gz --frame 2 Loaded in 23.79ms: File 595.2kB, temp 949.8kB (61 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.34e-07, max 3.26e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnity.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnity_frame2.obj.gz --frame 2 --bake Loaded in 16.17ms: File 595.2kB, temp 949.8kB (61 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.34e-07, max 3.26e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpHumanoidGodot.fbx [frame 1] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidGodot.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidGodot_frame1.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidGodot.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidGodot_frame1.obj.gz --frame 1 Loaded in 16.88ms: File 639.5kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.8e-07, max 3.13e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidGodot.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidGodot_frame1.obj.gz --frame 1 --bake Loaded in 17.12ms: File 639.5kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.8e-07, max 3.13e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpHumanoidUnreal.fbx [frame 3] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidUnreal.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpHumanoidUnreal_frame3.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnreal.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnreal_frame3.obj.gz --frame 3 Loaded in 17.07ms: File 655.4kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.14e-07, max 3.25e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnreal.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpHumanoidUnreal_frame3.obj.gz --frame 3 --bake Loaded in 17.28ms: File 655.4kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.14e-07, max 3.25e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpUniversalGodot.fbx [frame 4] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalGodot.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalGodot_frame4.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalGodot.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalGodot_frame4.obj.gz --frame 4 Loaded in 17.75ms: File 639.5kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.93e-07, max 3.1e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalGodot.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalGodot_frame4.obj.gz --frame 4 --bake Loaded in 16.71ms: File 639.5kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.93e-07, max 3.1e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpUniversalUnreal.fbx [frame 6] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalUnreal.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalUnreal_frame6.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnreal.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnreal_frame6.obj.gz --frame 6 Loaded in 17.46ms: File 650.6kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.22e-07, max 3.26e-06 (36672 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnreal.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnreal_frame6.obj.gz --frame 6 --bake Loaded in 17.59ms: File 650.6kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.22e-07, max 3.26e-06 (36672 tests) -- PASS -- -- issue/106/arp-humanoid/ArpAllSwitchesInverted.fbx [frame 0] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpAllSwitchesInverted.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpAllSwitchesInverted_frame0.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpAllSwitchesInverted.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpAllSwitchesInverted_frame0.obj.gz --frame 0 Loaded in 23.72ms: File 676.4kB, temp 1120.9kB (61 allocs), result 2466.0kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.51e-07, max 1.02e-06 (55008 tests) -- PASS -- $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpAllSwitchesInverted.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpAllSwitchesInverted_frame0.obj.gz --frame 0 --bake Loaded in 30.07ms: File 676.4kB, temp 1120.9kB (61 allocs), result 2466.0kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.51e-07, max 1.02e-06 (55008 tests) -- PASS -- -- issue/106/arp-humanoid/ArpUniversalUnity.fbx [frame 5] -- .fbx url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalUnity.fbx .obj url: https://ufbx-dataset.b-cdn.net/issue/106/arp-humanoid/ArpUniversalUnity_frame5.obj.gz $ build/check_fbx /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnity.fbx --obj /mnt/fbx-files/issue/106/arp-humanoid/ArpUniversalUnity_frame5.obj.gz --frame 5 Loaded in 23.64ms: File 650.6kB, temp 972.5kB (64 allocs), result 2311.4kB (11 allocs) FBX 7400 binary via Blender Binary 1.0.0 (Blender (stable FBX IO)) Absolute diff: avg 2.2e-07, max 3.26e-06 (36672 tests) -- PASS -- ```