I am trying to convert a glTF file into multiple BIN files. I came across an SDK called glTF Transform. I achieved this using the command-line API, and now I want to do the same using the scripting API.
I found the following code:
However, in the command-line API, we can pass the name of the meshes.
How can we pass the name of the meshes to the scripting API?
In another case, sometimes the glTF file doesn’t contain any mesh names, or they may be empty. How can we still convert such a glTF file into a glTF file with multiple BIN files?
In another case, sometimes the glTF file doesn’t contain any mesh names, or they may be empty. How can we still convert such a glTF file into a glTF file with multiple BIN files?
In order to have external BIN files, the glTF document must contain at least some binary data. If there are no meshes and no animations, then it’s unclear what would go into those BIN files.
Is it possible to create separate .bin files for animations and images/textures using gltf-transform?
While exploring gltf-transform, I learned that to create multiple .bin files, the --meshes command is used. Is it possible to export based on nodes instead?
The CLI supports changing where the base .gltf is saved, but doesn’t customize locations of texture and .bin resources. To do these customizations you’d need to use the scripting API, and methods like buffer.setURI('path/to/buffer.bin') and texture.setURI. See Buffer | glTF Transform.
Is it possible to create separate .bin files for animations and images/textures using gltf-transform?
glTF Transform writes images to separate files, and does not embed them in a .bin.
While exploring gltf-transform, I learned that to create multiple .bin files, the --meshes command is used. Is it possible to export based on nodes instead?
Not through the CLI – You may find it helpful to see how the per-mesh partitioning is implemented in the scripting interface, as you could customize this further to group binary data into buffers however you prefer:
I recently discovered that when using the optimize method via the CLI in gltf-transform, it optimizes the GLTF file by internally invoking the following methods:
dedup
instance
palette
flatten
join
weld
simplify
resample
prune
sparse
textureCompress
draco
I would like to examine the internal algorithm of the optimize function. Could you please provide the link to that function’s source code if it’s available on GitHub?
Actually, I’m currently trying to create multiple bins for a single GLTF file, but I noticed that the number of bins differs between the CLI and the JavaScript API. This is why I’m interested in reviewing the optimize function’s algorithm (since the optimize function isn’t available in the JavaScript API).
Hi @swapnil.vikhe — you can find the implementation of the optimize() command here:
Each of the transform functions you list are implemented separately as functions from the @gltf-transform/functions model, you can find the individual function implementations at:
The full source code is what you see there, at the link. The partition command can also accept a boolean, partition({meshes: true}), to put each mesh in a separate .bin. Any defaults not in the “optimize” implementation are probably the defaults of the individual commands, in their source files.