Skip to content

Error: GLB must have 0–1 buffers. when writing glb #555

Answered by donmccurdy
daniel-gato asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 } f…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by daniel-gato
Comment options

You must be logged in to vote
3 replies
@donmccurdy
Comment options

@mnakaji1-avail

This comment was marked as off-topic.

@donmccurdy

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants
Converted from issue

This discussion was converted from issue #554 on April 13, 2022 13:32.