5

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?

q9f
  • 703
  • 2
  • 8
  • 22

2 Answers2

4

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,..."
    }
},
ratchet freak
  • 5,950
  • 16
  • 28
2

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==
q9f
  • 703
  • 2
  • 8
  • 22