vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
467 stars 75 forks source link

Separate JSON and Binary #50

Closed raffdp closed 4 years ago

raffdp commented 4 years ago

Is it possible to save a scene as separate files where the scene graph that defines each mesh instance is saved in single gltf JSON and each mesh vertices, normals etc. are saved in separate binary files, one for each mesh?

vpenades commented 4 years ago

First of all, keep in mind that glTF files are inherently hard to edit, specially loaded once.

Then, the first part, selecting individual mesh instances is also described in issue #49, I'm already writing a unit test as an example.

Finally, when you have your mesh instance as a new SceneBuilder, you can save it as glTF (json+bin) or GLB.

Now, when saving to glTF (json+bin) , SharpGLTF embeds all the binary blobs into a single .BIN file when you save it to glTF, so for every gltf file, you will get a single bin file.

If what you want is to write a .bin file for every vertex attribute of every mesh, right now SharpGLTF can't do that and it would require extensive reworking of the library.

raffdp commented 4 years ago

Thanks for the info.

I should have probably said I was looking to create the glTF scene from a CAD application as opposed to editing existing glTF data, so I would be creating the glTF from scratch from MCAD data. I was looking to see if I could keep the Assembly files and Part files as separate glTF files where the Assembly files would contain primarily nodes with transformation information and buffers would point to external url's for the Part files that would contain geometry in a bin file. I am only just starting to learn about glTF so this sort of file separation my not even be possible on glTF as concept. It may be that every Assembly needs to be self contained and standalone with a full definition of every Part and Sub Assembly is contains, either as a single glB or as a json+bin pair.

raffdp commented 4 years ago

Looks like it has come up on the glTF board at the end of this thread

https://github.com/KhronosGroup/glTF/issues/1051 https://github.com/KhronosGroup/glTF/issues/37

vpenades commented 4 years ago

Yes, glTF is a self contained document and cannot reference other glTFs. Think of it as a "final render" of your scene.

glTF is a last mile format and although it can be used as an interchange format, it's not really well suited for it. It's like comparing an Adobe PSD document, that can contain layers, vectors, etc, and a JPG, where you get the final render, but you loose the layer information.

I guess it is possible to add the referencing features with glTF extensions, but I don't think the khronos board would like to add such an extension, because it would mean drifting away from the primary purpose of glTF format.

I think this answer your question, so I'll close this issue... feel free to open new ones whenever you need it!