cgltf
cgltf copied to clipboard
Add functionality for writing glb files
When generating my own mesh, I'd like to save the result together with the meta data in a glb file. That is currently not possible with cgltf.
Yeah when I wrote cgltf_write I figured I could use an external tool to convert to glb, so I made it low priority.
However I think this is a good feature request. The GLB exporter could re-use what we already did for JSON, and it would not incur any additional dependencies (e.g. no compression library is required).
That should indeed be very straight-forward. As we already support reading GLB, writing it as well would make sense.
I spent some time trying to use cgltf_writer.h, but found it was easier to just write my own JSON code. Knitting together the C structures that match JSON 1-to-1 was very tedious and ended up being more verbose.
Instead, I put together some GLB utility functions to handle the chunk writing and determine the min/max vec3 bounds. There's a UNIT_TEST in glb.c which serves as an example of how to use the glb_* functions.
This method of writing GLB files adds less than 4% of the code required by cgltf to a project, and can avoid the gltf_validator TARGET warning caused by issue #193.