Error: GLB must have 0–1 buffers. when writing glb #555
-
I'm trying to convert a gltf to glb. The gltf has this specificities:
I keep getting this message:
I don't have control over that gltf and it displays correctly on gltf viewers. I'm not sure why this happens. I would expect the write() to include all .bins into the file. import fetch from 'node-fetch';
import { NodeIO } from '@gltf-transform/core';
import { KHRONOS_EXTENSIONS } from '@gltf-transform/extensions';
const io = new NodeIO(fetch)
.setAllowHTTP(true)
.registerExtensions(KHRONOS_EXTENSIONS);
const doc = await io.read('/tmp/model.gltf');
await io.write('/tmp/model.glb', doc); Am I missing something here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @daniel-gato! By convention a If you add the following code before writing the Document, it will consolidate any extra buffers: const buffer = doc.getRoot().listBuffers()[0];
doc.getRoot().listAccessors()
.forEach((a) => a.setBuffer(buffer));
doc.getRoot().listBuffers()
.forEach((b, index) => (index > 0 ? b.dispose() : null)); EDIT: In more recent versions of the library, this shortcut can be used instead: import { unpartition } from '@gltf-transform/functions';
await document.transform(unpartition()); |
Beta Was this translation helpful? Give feedback.
-
I’m not sure to understand the code. Will that remove the extra buffers or merge them into one? I’m other terms, will the resulting gob be visually the same than the initial gltf?
My understanding was that a gltf contains the binary geometry data into one or several external binary files. While the glob contains all those files and the gltf structure merged into one single binary file.
|
Beta Was this translation helpful? Give feedback.
Hi @daniel-gato! By convention a
.glb
is usually self-contained (i.e. does not reference external.bin
files) and so any buffers need to be consolidated if there are >1. The I/O classes don't currently do that, in order to avoid mutating the original Document during export unintentionally.If you add the following code before writing the Document, it will consolidate any extra buffers:
EDIT: In more recent versions of the library, this shortcut can be used instead: