3
$\begingroup$

The GL Transmission Format comes along with a JSON styled main file which basicly describes the scene and binary files which contain the buffers.

gltf basic structure

I'm currently writing a WebGL library and I need to work alot with the vertex and index buffers. So, my question now is:

Would it be possible to store plain text array buffers in the gltf (e.g., as JSON) instead of generating binary blobs always when the buffers are adjusted?

$\endgroup$
3
$\begingroup$

Embedding human readable data is not supported. However you can put the data into a data uri to store the data inline in base64 format.

"buffers": {
    "a-buffer-id": {
        "byteLength": 1024,
        "type": "arraybuffer",
        "uri"="data:application/octet-stream;base64,..."
    }
},
| improve this answer | |
$\endgroup$
1
$\begingroup$

It's not possible to store the plain text array buffers in gltf, however, here is the code I use to generate buffers in JavaScript:

let vtx = [
  0.0857, 0.0759,
  0.0367, 0.9726,
  0.9678, 0.0318,
  0.9754, 0.9327
];

let idx = [
  0, 2,
  2, 4,
  4, 0,
  0, 1,
  1, 4
];

let buf = new ArrayBuffer(52);
let dat = new DataView(buf, 0, 52);

for (var i = 0; i < 20; i += 2) {
  dat.setUint16(i, idx[i / 2], true);
}

for (var v = 20; v < 52; v += 4) {
  dat.setFloat32(v, vtx[(v - 20) / 4], true);
}

let b64 = btoa(String.fromCharCode(...new Uint8Array(buf)));

window.console.log("data:application/octet-stream;base64," + b64);

Where buf contains the binary data in a JavaScript ArrayBuffer object and b64 finally a base64 encoded string:

data:application/octet-stream;base64,AAACAAIABAAEAAAAAAABAAEABAB7g689dnGbPb1SFj1Q/Hg/vsF3P7hAAj3Qs3k/bcVuPw==
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.