glTF-SDK icon indicating copy to clipboard operation
glTF-SDK copied to clipboard

Add `ResourceWriter::Write` overload with a buffer id parameter instead of a buffer view

Open docEdub opened this issue 1 year ago • 0 comments

When writing GLB chunk data it would be useful to have an overload of ResourceWriter::Write that allows writing to the magic "binary_glTF" buffer without having to create a temporary buffer view. The overload signature could use a const char* or a const std::string& for the buffer id parameter, e.g. ResourceWriter::Write(const char* bufferId, const std::vector<T>& data).

The only way to do this right now is:

std::vector< uint8_t > data = ...
      
glTF::BufferView tmpBufferView {};
tmpBufferView.bufferId = glTF::GLB_BUFFER_ID;
tmpBufferView.byteOffset = currentByteOffset;
tmpBufferView.byteLength = data.size();
pResourceWriter->Write( tmpBufferView, data );

With the requested ResourceWriter::Write(const char* bufferId, const std::vector<T>& data) overload, the temporary buffer view is not needed:

std::vector< uint8_t > data = ... 
pResourceWriter->Write( glTF::GLB_BUFFER_ID, data );

This should be trivial to implement since ResourceWriter::WriterImpl currently only uses the given buffer view's buffer id.

docEdub avatar Feb 07 '24 22:02 docEdub