spnda / fastgltf

A modern C++17 glTF 2.0 library focused on speed, correctness, and usability

Home Page:https://fastgltf.readthedocs.io/v0.8.x/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Textures are not created on disk if the destination directory does not exist

Cyphall opened this issue · comments

When exporting as GLTF, the FileExporter does not write the texture files (probably buffer files too, not tested) on disk if the destination directory does not already exist.
This is probably due to std::ofstream not being able to open a file if the file's directory doesn't exist on disk.

commented

I think this was intentional behaviour as I think the caller should be the one who manages the creation of the directories. I do this in the tests, too. Call std::filesystem::create_directory with the path you pass to setImagePath.

Or do you think the FileExporter should also always handle creating directories?

Since the FileExporter is responsible for creating the files on disk, I believe it should also be responsible for creating any required folder for these files.

It would be a bit weird for the FileExporter to be allowed to create files but not folders.

On that note, image and buffer names should probably be validated and escaped before being concatenated with the base path to create the final file path.
This would avoid cases where these names contain relative paths that would put them outside their corresponding base folder. (eg. an image called "../test" would not be created in the image folder but in the parent folder)