CesiumGS / gltf-pipeline

Content pipeline tools for optimizing glTF assets. :globe_with_meridians:
Apache License 2.0
1.87k stars 241 forks source link

Consider disambiguating resource names #634

Closed javagl closed 1 year ago

javagl commented 1 year ago

When resources (like external buffer- or image references) are created via the options.separate flag, then their names are assigned automatically. This is happening around writeResources.getName. The names are somewhat generic - something like buffer0.bin. One could consider prefixing these names with the base name of the input file, to disambiguate them. For example, when processing a Duck.glb, the files could be named Duck_buffer0.bin.

(The use case is that one might to batch-process multiple files in one directory, and write the results into one directory. When the input files Duck.glb and Triangle.glb both generate a buffer.bin, then the user has no obvious way to handle this: The separateResources do contain the names like buffer0.bin as the key, but this cannot be changed at the client side - at least not without manually doing some hacky gltf.buffers[i].uri = myNewName).

lilleyse commented 1 year ago

It should already prefix with the base name of the output file. E.g. if I run

node bin/gltf-pipeline.js -i ./specs/data/2.0/box-textured-embedded/box-textured-embedded.gltf -o ~/Desktop/box.gltf --separate

I get three files:

If you're calling processGltf or equivalent programmatically you'll need to pass in options.name for it to get prefixed.

javagl commented 1 year ago

pass in options.name for it to get prefixed.

That was the missing piece.