Draco compressed embeded gltf to gltf+bin files

Hi,

There is a C++ framework named Open Cascade that is unable to read Draco-compressed embedded GLTF files due to an internal issue with Open Cascade itself.

As we know the structure of Draco-compressed embedded GLTF and Draco-compressed GLTF+BIN structures:

  1. Draco-compressed embedded GLTF buffer URI:
    “buffers”:[
    {
    “byteLength”:840,
    “uri”:“data:application/octet-stream;base64,AACAPwAAgD8AAIC/AACAPwAAgD8AAIC/AACAPwAAgD8AAIC/AACAPwAAgL8AAIC/AACAPwAAgL8AAIC/AACAPwAAgL8AAIC/AACAPwAAgD8AAIA/AACAPwAAgD8AAIA/AACAPwAAgD8AAIA/AACAPwAAgL8AAIA/AACAPwAAgL8AAIA/AACAPwAAgL8AAIA/AACAvwAAgD8AAIC/AACAvwAAgD8AAIC/AACAvwAAgD8AAIC/AACAvwAAgL8AAIC/AACAvwAAgL8AAIC/AACAvwAAgL8AAIC/AACAvwAAgD8AAIA/AACAvwAAgD8AAIA/AACAvwAAgD8AAIA/AACAvwAAgL8AAIA/AACAvwAAgL8AAIA/AACAvwAAgL8AAIA/AAAgPwAAAD8AACA/AAAAPwAAID8AAAA/AADAPgAAAD8AAMA+AAAAPwAAwD4AAAA/AAAgPwAAgD4AACA/AACAPgAAID8AAIA+AADAPgAAgD4AAMA+AACAPgAAwD4AAIA+AAAgPwAAQD8AACA/AABAPwAAYD8AAAA/AAAAPgAAAD8AAMA+AABAPwAAwD4AAEA/AAAgPwAAAAAAACA/AACAPwAAYD8AAIA+AAAAPgAAgD4AAMA+AAAAAAAAwD4AAIA/AAAAAAAAAAAAAIC/AAAAAAAAgD8AAACAAACAPwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIC/AACAPwAAAAAAAACAAAAAAAAAAAAAAIA/AAAAAAAAgD8AAACAAACAPwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIA/AACAPwAAAAAAAACAAACAvwAAAAAAAACAAAAAAAAAAAAAAIC/AAAAAAAAgD8AAACAAAAAAAAAgL8AAACAAACAvwAAAAAAAACAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIA/AACAvwAAAAAAAACAAAAAAAAAgD8AAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIA/AACAvwAAAAAAAACAAQAOABQAAQAUAAcACgAGABIACgASABYAFwATAAwAFwAMABAADwADAAkADwAJABUABQACAAgABQAIAAsAEQANAAAAEQAAAAQA”
    }

  2. Draco-compressed GLTF+BIN file buffers URI structure:
    “buffers”:[
    {
    “byteLength”:840,
    “uri”:“cube%28with_bin%29.bin”
    }

Since Open Cascade is unable to read Draco-compressed embedded GLTF files, I wanted to convert Draco-compressed embedded GLTF to GLTF+BIN structure.

I tried to extract the Base64 data from the Draco-compressed embedded GLTF to convert it into a GLTF+BIN file. However, despite using online converters and some C++ libraries, I was not able to convert the data properly.

Could anyone please suggest how to achieve this conversion?

One option on the CLI, requiring Node.js, would be:

npm install --global @gltf-transform/cli

gltf-transform cp input.gltf output.gltf

You’ll see a warning in the logs, mentioning that Draco compression was removed. This tool will always create external .bin files unless you select .glb output.

Or you can open the model on https://gltf.report/, select Format → “JSON” and Compression → “Uncompressed” in the dropdowns on the right, and export.

I wanted to read the compressed embedded GLTF in C++ itself. Since we are not able to do it in OpenCASCADE,
I wanted to extract the base64 data from the embedded GLTF and, after converting it to binary, save it as a .bin file by using any c++ libraries.
This will create a separate compressed GLTF+BIN structure. I don’t want to uncompress it; I just want to separate it.

Oops, I see. In that case it is mainly a matter of decoding JSON, decoding the Data URIs within that JSON, writing each resource to a .bin file, and replacing the original JSON. You should not need to interact with any other glTF-specific data.

If you haven’t tried cgltf yet, that is a solid library and automatically decodes Data URIs. But it should be possible to do this with any C/C++ JSON decoder, you don’t necessarily need a glTF-specific library for it.

1 Like