syoyo / tinygltf

Header only C++11 tiny glTF 2.0 library
MIT License
1.94k stars 395 forks source link

GLTF/GLB write operations always use FS despite TINYGLTF_NO_FS #488

Open W4RH4WK opened 3 weeks ago

W4RH4WK commented 3 weeks ago

For reading GLTF/GLB file system access can be controlled by defining TINYGLTF_NO_FS and providing the necessary callback functions.

Writing GLTF/GLB files seems to be missing this functionality. Even when TINYGLTF_NO_FS is defined, certain functions using std::ofstream are still active (e.g. WriteGltfFile).

Side note: if TINYGLTF_NO_FS is defined, <fstream> is not included. However, it still compiles on most platforms successfully as std::ofstream is pulled in transitively.

syoyo commented 3 weeks ago

TINYGLTF_NO_FS is primarily for reading glTF. It is not well considered in the writer.

To make TINYGLTF_NO_FS effective for the writer(no <fstream>, <cstdio> dependency), we need to introduce WriteGltfSceneToMemory API, something like:

   bool WriteGltfSceneToStream(const Model *model, std::vector<uint8_t> &output,
                                bool prettyPrint, bool writeBinary);