cgltf icon indicating copy to clipboard operation
cgltf copied to clipboard

Add functionality for writing glb files

Open dov opened this issue 4 years ago • 3 comments

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.

dov avatar Feb 22 '21 16:02 dov

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).

prideout avatar Feb 22 '21 20:02 prideout

That should indeed be very straight-forward. As we already support reading GLB, writing it as well would make sense.

jkuhlmann avatar Mar 22 '21 20:03 jkuhlmann

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.

WickedSmoke avatar Mar 13 '24 13:03 WickedSmoke