vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
457 stars 72 forks source link

Save methods overloads with Stream input #113

Closed electro-logic closed 2 years ago

electro-logic commented 2 years ago

Hello,

Would be very handy to have some additional overloads for SaveGLB() and SaveGLTF() that accept a Stream as input, to enable additional scenarios. In UWP for example you need to request a permission to get a workable Stream for files and without these override only the LocalApp path is easily usable.

As a temporary workaround I'm using this code

var context = WriteContext.CreateFromStream(stream).WithBinarySettings().WithSettingsFrom(null); context.WriteBinarySchema2("model", model);

to "emulate" a model.SaveGLB(stream)

Thank you, Leonardo

vpenades commented 2 years ago

There's already a method to write a GLB to a a stream.

Notice there's no counterpart for glTF because an open glTF file writes multiple files, and those cannot be written to a single stream.

For advanced scenarios, you can check the example that writes glTFs to a ZIP file (which is a stream)

electro-logic commented 2 years ago

Thanks a lot for the quick reply, I missed that because of the different name.

Why not moving (or adding) it to an overload of the SaveGLB method? Would be an easier API.

Thanks again

vpenades commented 2 years ago

It's a personal naming convention. I use Load/Save for system files, and Read/Write for streams, arrays, and essentially anything that is not a file.

electro-logic commented 2 years ago

Make sense, thanks again