floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
7.07k stars 494 forks source link

Animating gltf2 models #490

Closed supercranky closed 3 years ago

supercranky commented 3 years ago

Hello!

First of all - I just love the sokol headers! I'm tinkering with a small game runtime combining sokol with the equally excellent QuickJS javascript engine and it works like a charm!

Now I'm trying to figure out how to support skinned mesh animation with sokol_gfx. The gltf sample is a great start, and I'm guessing I could add the vertex skinning part of the Khronos gltf viewer reference pretty easily but I'm struggling a bit with finding the best approach to do the actual bone animation. Using something like the ozz-animation library could work but seems a bit overkill?

Surely @floooh or someone have messed with skinned animations in the past? 😀

floooh commented 3 years ago

Yeah I did, but actually not yet with sokol-gfx.

TBH I would actually use ozz-animation these days, but if you want to do it yourself you can have a look at my Oryol-samples. However the character animation-system and renderer is a bit more complex then usual because it renders characters optionally via instancing and pulls the bone animation data from a texture. It doesn't use GLTF as file format though, but a custom binary format.

Here are the relevant demos:

The skinning shader is here:

The toplevel C++ code:

...and the important part is this character-animation module (this is the main part that would be replaced by ozz-animation):

...oh, and this Dungeon-Crawler demo also seems to have skinned characters:

...maybe worth looking at the source code:

Cheers!

supercranky commented 3 years ago

Oooh, awesome stuff! Animating instanced characters is really interesting.

I also noticed raylib recently added support for GLTF animations, I'm going to check that out as well. With all these great resources I'm sure I'll get something working (famous last words 😀 )

Thank you for taking the time to answer this!