How to build a GLTF base64 string of bin file

Normally, the file references in GLTF are stored in JSON

“buffers”: [
{
“byteLength”: 132768,
“uri”: “Ellipe.bin”
}
]

In GLTF specification there is the possibility to embed the buffers via a base64 like this sample:

“buffers” : [
{
“uri” : “data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=”,
“byteLength” : 44
}
],

As far as I understand, the base64 is mirroring the contents of the file referenced (here Ellipse.bin).

Because I want to load the model in one step via WebSocket I have to build a data representation of the model in one data stream, so I have to embed any binary files into the GLTF file.

But when I’m reading the binary file and convert it by WIN32 function

CryptBinaryToString with flags CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF

(which I normally use to make base64 of png’s) and replace the value of uri by data:application/octet-stream;base64,[b64string]

the model is always invalid and cannot be loaded.

So please give me some informations to properly build the base64 uri from bin file. Do I have to call a Babylon function to make it work?

ping @bghgary for GLTF.

What error message are you seeing? Base64 encoded data should work.

You should also consider using a glTF-Binary (.glb) file which will be more efficient as a single file than a Base64 encoded file. See glTF/specification/2.0 at master · KhronosGroup/glTF · GitHub

I know it’s quite late to reply, but it may be helpful for somebody else. I figured out the issue with your base64 encoded data. Removing “application/octet-stream;” from your base64 data would work since it denotes the data header and not the actual data.

This shouldn’t be necessary. Specifying the mime type shouldn’t cause a problem. Do you have repro @Megha_Gupta? All the embedded models in the sample models repo (example) has the mime type and they load fine (example).