floooh / sokol-samples

Sample code for https://github.com/floooh/sokol
MIT License
591 stars 79 forks source link

Trying to make ozz-skin-sapp.cc example generic, fails to load more complex .ozz animations #144

Open medvednikov opened 4 weeks ago

medvednikov commented 4 weeks ago

Trying to make the amazing ozz-skin-sapp.cc example load any .ozz file. Testing it with ozz-animation/build/samples/skinning/sample_skinning (.ozz files and my ozz-skin-sapp.cc are attached).

ozz-animation/build/samples/skinning/media/skeleton.ozz
ozz-animation/build/samples/skinning/media/animation.ozz
ozz-animation/build/samples/skinning/media/mesh.ozz

First of all, it prints

Unsupported Animation version 7.

So maybe the ozz-animation dependency needs to be updated?

I increased MAX_JOINTS to the upper limit, and the IO buffers:

// IO buffers (we know the max file sizes upfront)
static uint8_t skel_io_buffer[32 * 10240];
static uint8_t anim_io_buffer[96 * 10240];
static uint8_t mesh_io_buffer[3 * 10240 * 10240];

I got assert failures:

603         // assume one mesh and one submesh
604         printf("meshes size=%d, parts.size=%d\n", meshes.size(), meshes[0].parts.size());
605         //assert((meshes.size() == 1) && (meshes[0].parts.size() == 1));
...
614         std::cout<< "num_vertices = " << num_vertices  << " x3 = " << num_vertices * 3 << "; x4 = " << num_vertices * 4 << std::endl;
615         std::cout<< "normals.size = " << meshes[0].parts[0].normals.size()  << std::endl;
616         assert(meshes[0].parts[0].normals.size() == (num_vertices * 3));
617         std::cout<< "joint_indices.size = " << meshes[0].parts[0].joint_indices.size()  << std::endl;
618         //assert(meshes[0].parts[0].joint_indices.size() == (num_vertices * 4));
619         std::cout<< "joint_weights.size = " << meshes[0].parts[0].joint_weights.size()  << std::endl;
620         //assert(meshes[0].parts[0].joint_weights.size() == (num_vertices * 3));
meshes size=10, parts.size=4
num_vertices = 3228; x3 = 9684; x4 = 12912
normals.size = 9684
joint_indices.size = 3228
joint_weights.size = 0

Was the example built just for this demo, or should it be possible to make it handle any .ozz animation?

Thanks

ozz-skin-sapp.zip

floooh commented 4 weeks ago

The example has a lot of hardwired assumptions (like a very low max number of joints in the skeleton). Just increasing the IO buffer size definitely won't be enough. It's probably better to start with one of the official ozz-animation samples and port them back to sokol.

medvednikov commented 3 weeks ago

I did increase the MAX_JOINTS const.

It's unfortunate that it's hardwired. I'm not skilled enough in 3D dev to make it generic, and the ozz-animation renderer is ~5k lines of OpenGL.

medvednikov commented 3 weeks ago

Not entire 5k needs to be translated. As I understand, only DrawSkinnedMesh(), LoadSkeleton(), and LoadAnimation().