<p>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:</p>

<pre><code>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 &lt; 20; i += 2) {
  dat.setUint16(i, idx[i / 2], true);
}

for (var v = 20; v &lt; 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);
</code></pre>

<p>Where <code>buf</code> contains the binary data in a JavaScript ArrayBuffer object and <code>b64</code> finally a base64 encoded string:</p>

<pre><code>data:application/octet-stream;base64,AAACAAIABAAEAAAAAAABAAEABAB7g689dnGbPb1SFj1Q/Hg/vsF3P7hAAj3Qs3k/bcVuPw==
</code></pre>

CC BY-SA 4.0
2022-11-07T21:44:04.297Z
check out [this answer](https://computergraphics.stackexchange.com/a/3623/19180) to know how to decode the buffer data after encoding it using above method.
Gangula
CC BY-SA 3.0
2016-06-15T18:57:12.357Z
2016-06-15T18:57:12.357Z
q9f
<p>Embedding human readable data is not supported. However you can put the data into a <a href="https://www.rfc-editor.org/rfc/rfc2397" rel="nofollow noreferrer">data uri</a> to store the data inline in base64 format.</p>
<pre><code>&quot;buffers&quot;: {
    &quot;a-buffer-id&quot;: {
        &quot;byteLength&quot;: 1024,
        &quot;type&quot;: &quot;arraybuffer&quot;,
        &quot;uri&quot;=&quot;data:application/octet-stream;base64,...&quot;
    }
},
</code></pre>

CC BY-SA 3.0
2016-04-19T09:40:01.340Z
2016-04-19T09:40:01.340Z
2021-10-07T07:34:52.683Z
ratchet freak
<p>The GL Transmission Format comes along with a JSON styled main file which basically describes the scene and binary files which contain the buffers.</p>
<p><a href="https://i.sstatic.net/RtFrg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RtFrg.png" alt="GLTF basic structure" /></a></p>
<p>I'm currently writing a WebGL library and I need to work a lot with the vertex and index buffers. So, my question now is:</p>
<p>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?</p>

<webgl><data-structure><vertex-buffer-object><gltf>
Is it possible to store the plain buffer data in GLTF files?
q9f
# Is it possible to store the plain buffer data in GLTF files?

(Asked by: username_0 on 2016-04-19)

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

[![GLTF basic structure](https://i.sstatic.net/RtFrg.png)](https://i.sstatic.net/RtFrg.png)

I'm currently writing a WebGL library and I need to work a lot 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?

**Tags:** webgl, data-structure, vertex-buffer-object, gltf


---

## 2 answers

### Answer by username_0 on 2016-06-15. Score: 2 | Accepted answer

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==

```

> **Comments:**
> **username_1**: check out [this answer](https://computergraphics.stackexchange.com/a/3623/19180) to know how to decode the buffer data after encoding it using above method.  

---

### Answer by username_2 on 2016-04-19. Score: 4

Embedding human readable data is not supported. However you can put the data into a [data uri](https://www.rfc-editor.org/rfc/rfc2397) to store the data inline in base64 format.

```
"buffers": {
    "a-buffer-id": {
        "byteLength": 1024,
        "type": "arraybuffer",
        "uri"="data:application/octet-stream;base64,..."
    }
},

```


---

