najadojo / gltf-import-export

Convert between GLB and GLTF files.
MIT License
204 stars 31 forks source link

Allow images (and shaders) to reuse buffers #3

Closed emackey closed 6 years ago

emackey commented 6 years ago

Hey @najadojo, I get to send you a PR for a change.

This one fixes AnalyticalGraphicsInc/gltf-vscode#80. In that issue, @zellski has a model where multiple image blocks in a GLB refer to the same internal buffer. I'm not sure that's good practice in general, as one could more easily re-use the same image index number. But, it doesn't appear to be forbidden by glTF, and it's fixable here.

This change makes a list of image blocks that all reference a given bufferView index, and will adapt all of them to use the newly created filesystem file. There's a baked-in assumption that the first reference to a bufferView will have the correct MIME type and that all following references to the same bufferView will have the same type (because how could they not? It's the same data). Hopefully this doesn't decrease the readability here, let me know.

najadojo commented 6 years ago

This has been published. Thanks for the changes!