jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.46k stars 136 forks source link

Add support for KHR_draco_mesh_compression #106

Closed romainguy closed 4 years ago

romainguy commented 4 years ago

This change adds support to read and write glTF files that use the KHR_draco_mesh_compression extension. The extension can be specified per primitive, which is why cgltf_primitive now has 2 new fields: has_draco_mesh_compression and draco_mesh_compression. draco_mesh_compression contains a buffer view and a list of attributes.

It is important to note that the extension may or may not be required. A primitive can specify both compressed and uncompressed data. While this doesn't affect the parsing, it does affect the writing since the proper extensionsUsed/Required needs to be specified. To achieve this, this change adds support for required extensions in cgltf_write.h (see required_extensions_flag in cgltf_context). The extension is deemed required when a primitive has no attributes or no indices.

Please refer to the extension spec.

jkuhlmann commented 4 years ago

To be clear, one would have to decompress the actual vertex data after parsing the file with cgltf, correct? If so, should we add a comment about that and maybe a link to the Draco lib?

romainguy commented 4 years ago

That is correct, decompression is still up to the client app. Where would you like me to document this?

romainguy commented 4 years ago

I forgot to mention that I tested the change with test_write on official gltf samples that use Draco compression.

prideout commented 4 years ago

This all looks good to me except for a few spots where spaces were used instead of tabs :)

romainguy commented 4 years ago

Done!

jkuhlmann commented 4 years ago

Actually, I think we should have a list of supported extensions at the top of cgltf.h. We could also mention the Draco limitation there. I'll take care of that after merging.

romainguy commented 4 years ago

Thank you!