Skip to content
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

[models] Add GLTF animation support #2844

Merged
merged 9 commits into from
Jan 2, 2023
Merged

Conversation

charles-l
Copy link
Contributor

@charles-l charles-l commented Dec 30, 2022

I needed GLTF animation support for my project, but I noticed that Raylib has added and removed support for it in the past. If this isn't really in the scope for the project, I'd be happy to pull this out into a plugin or helper library (but I figured I'd submit a PR in case there was interest in including it).

Caveats:

  • Only supports 1 armature per file, and skips loading it if there are multiple armatures. I could update this to load the first one by default. It prints a warning in either case.
  • I only added support for linear interpolation (which is the default interpolation method in blender when you check Always Sample Animations when exporting a GLTF file). I could add additional interpolation methods pretty easily though.
  • I only added translation/rotation/scale animation channel.path support. I skipped weights (i.e. morph targets).

src/rmodels.c Outdated Show resolved Hide resolved
@charles-l
Copy link
Contributor Author

charles-l commented Dec 30, 2022

Oh, I should also add an example for this. I'll update examples/models/models_loading_gltf to include animation since the model already has animation in it. Just realized that example is breaking with my patch so I'll have to take a look at it anyway :P

Updated the .blend file to use weights rather than bone parents so it
fits into the framework. Exported with weights to the .glb file.
@charles-l
Copy link
Contributor Author

Updated the models/models_loading_gltf.c example to play back the gltf animation in the example file.

@charles-l charles-l changed the title Add GLTF animation support [models] Add GLTF animation support Dec 31, 2022
@raysan5
Copy link
Owner

raysan5 commented Dec 31, 2022

@charles-l Hey! This is an amazing addition, waiting for it for some time! I like the implementation, quite self-contained, just let me know when you think it's final and I'll merge and review it properly. Thanks for this great improvement!

@charles-l
Copy link
Contributor Author

Great, sounds good! I made a few final small tweaks, and it should be ready to go now. Let me know if there are any improvements or changes I should make!

BTW, I had a lot of fun working on this codebase. It's so easy to get started when there aren't layers upon layers of abstractions concealing what's really going on. I haven't written much in this style of C before (spartan data structure choice, pre-allocation as much as possible, etc), but really enjoyed it. Kudos on an awesome framework :)

@raysan5
Copy link
Owner

raysan5 commented Jan 1, 2023

@charles-l Please, could you review code formating to follow raylib coding conventions?

@charles-l
Copy link
Contributor Author

ok! Updated the PR with fixed formatting.

examples/models/models_loading_gltf.c Outdated Show resolved Hide resolved
examples/models/models_loading_gltf.c Outdated Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
src/rmodels.c Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
src/rmodels.c Outdated Show resolved Hide resolved
@raysan5
Copy link
Owner

raysan5 commented Jan 2, 2023

@charles-l Just reviewed the code and there are still some formatting issues, please, could you review them?

@charles-l
Copy link
Contributor Author

Fixed brace alignment and removed asserts.

@raysan5 raysan5 merged commit f2e3d6e into raysan5:master Jan 2, 2023
@raysan5
Copy link
Owner

raysan5 commented Jan 2, 2023

@charles-l Merged! Thank you very much for this nice improvement! 😄

raysan5 added a commit that referenced this pull request Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants