-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rmodels] Initial work to correctly handle the node hierarchy in a glTF file #4037
Conversation
Static meshes seem to work fine in my tests. Haven't tried anything animated yet, but it's almost certainly broken.
@paulmelis Thank you very much for working on this feature! It's a nice addition to the library! About glTF animation, I did not implemented it but you can check No GPU-skinning is supported due to limitations on some platforms supported by raylib. |
Am I reading Lines 5513 to 5519 in e1379af
animVertices and animNormals are always allocated, regardless if any animation is present? That potentially doubles memory usage for mesh vertices and normals.
|
@paulmelis Mmmh... it seem so... |
changes to vertex/normal/tangent data
I updated the animation data part as well. The robot animation in |
Nice! Thanks for the review! Just let me know when this improvement is ready for review and merge! |
I've tested it with a few glTF models, including with more complex hierarchies. I saw no weird behaviour. I'd say it's ready for going into "beta testing" state |
Hey @paulmelis great work on this! I noticed that using this model https://github.com/KhronosGroup/glTF-Sample-Models/blob/main/2.0/CesiumMan/glTF-Binary/CesiumMan.glb we have some issues! I had no time to debug this one, but I think it might be useful to report it here :) |
It looks like this is an issue with
Edit: dug a bit deeper (in the fork for this pull request, hence the different line numbers), and it seems
|
@paulmelis Afair, animation names support was added quite recently in a PR, probably not extensively tested. EDIT: Just pushed a quick fix for this issue. |
Hey yeah I saw this one but I just bypassed with NULL check! I was referring to the wrong animation. I think we are having a problem with the worldMatrix we are using to transform the vertices, if you set this matrix to identity the animation is OK. In the original code the animation for the this model looks good! |
Do you have more details (or a code snippet) to show what you mean, as it's not entirely clear to me which worldMatrix and in which context you refer to? |
Hey @paulmelis sure! I was using the example 'shaders_shadowmap.c'! Just change the path supplied to LoadModel and LoadModelAnimation from Same thing for LoadModelAnimation change it from run the example and you can see that the animation is wrong. Screen.Recording.2024-06-10.at.09.16.26.movRegarding the worldMatrix I am referring to the matrix we are using at line 5104 file rmodels.c `cgltf_float worldTransform[16];
I tried to set this matrix to identity and the animation comes back to the correct behavior! Screen.Recording.2024-06-10.at.09.29.17.mov |
So I'm still not sure if what you're seeing is fully caused by my changes to the glTF handling. When I re-export CesiumMan.glb from Blender and load it into current raylib (so without my patches for glTF) I'm seeing the same distortions and weird movement. And similar for some other models (e.g. https://sketchfab.com/3d-models/model-47a-loggerhead-sea-turtle-c438e81e796d41d9a6ae4cc147ef8d4f). There's also different aspects that influence each other:
I'm actually wondering if it is even possible to correctly support models with complex hierarchies and having animation data, without some form of node hierarchy. |
Ah OK! I see, and thank you for the explanation :) |
AMAZING WORK! |
@paulmelis Is this PR ready for merge (despite the current limitations with nodes-hierarchy)? |
Hi @raysan5, I'd say it's a definite improvement for importing glTF models, as you no longer need to flatten the hierarchy in the file. I don't fully know about the impact on animated models, but I suspect current support isn't perfect either (i.e. #4055). So I would suggest indeed merging this and then we can look at improving animation support on top of it later. |
@paulmelis Merged! Thank you very much for all the effort put on this improvement! |
Having to use glTF files without node hierarchies and without transformations applied to the meshes is really a big limitation. Also, the current handling is not really correct, as it completely ignores the node hierarchy and thus might lead to meshes not getting instanced more than once.
This patch adds using the nodes in the glTF file to drive the process of creating meshes, instead of only processing the list of meshes and ignoring the node hierarchy. Transforms defined in the nodes (including parent-child effects) are applied to the vertices/normals/tangents of the meshes in the leafs. A separate raylib Mesh is generated for each leaf node (and still generates one Mesh per primitive in a glTF mesh).
Static meshes with more complex hierarchy in terms of parenting and object transforms seem to work fine in my tests.
Haven't tried any glTF files with animations yet, but those are almost certainly broken. It's also the part where I don't know off-hand how to handle that, so any tips on what is currently going on with respect to bones and animation are appreciated.
Btw, scenes in the glTF files are also ignored (which can contain subsets of nodes, and thus meshes), but that's something I ignore here as well.