vpenades / SharpGLTF

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

Buffer data embedding option #76

Open NoOverflow opened 3 years ago

NoOverflow commented 3 years ago

Hi, after some research I can't find any option to embed the buffer data into the .gltf file (and not in a separate .bin file)

Following the glTF reference guide this is fully possible : https://www.khronos.org/files/gltf20-reference-guide.pdf

I even tried it by modifying the "url" property of the buffer in the JSON from "*.bin" to "data:application/gltf-buffer;base64,..." and it worked perfectly.

I was expecting Schema2.WriteSettings to contain such an option (Something like .BufferWriting = SharpGLTF.Schema2.ResourceWriteMode.Embedded) but maybe it is somewhere else. If it is indeed missing I'll gladly add it with a pull request.

Thanks

vpenades commented 3 years ago

The library does not support embedding the buffers into the json when writing.

Given you can also write files in GLB format, I didn't consider it useful, because embedded buffers are encoded in base64 and are very inefficient.

Is there a particular reason why you need embedding the buffers into the json?

NoOverflow commented 3 years ago

I'm sending small 3D objects to a local web interface (then displayed using google model viewer), so size doesn't matter and I may need to access glTF json data at some point, that's why I wanted to use embedded buffers (I could also use binary format and then parse it but as size and efficiency are not really critical factors I just didn't bother).

vpenades commented 3 years ago

I understand... well, writing embedded buffers support is a non trivial change, I'll look into it, but don't expect a solution soon... it will probably be added for the next release

NoOverflow commented 3 years ago

I'll take a look at it to see if I can help. Don't worry about it too much though, I'll stick to binary for now and figure another way. Anyway thanks for your time !

vpenades commented 3 years ago

As you guessed, it needs another buffer write settings mode in the writer function, and this flag to be dealt with in the appropiate places, without interfering with all other features... it's this last issue what makes it non trivial.

NoOverflow commented 3 years ago

Yes I'm taking a look at the code. I made a fork to try some things and see how that works out, I've got a bit of time on my hands so I might as well try something out. And even if I don't manage to get something working I'll be more familiar with the library so win-win anyway