Skip to content

Commit

Permalink
UfbxImporter: Add fromWindowsSeparators()
Browse files Browse the repository at this point in the history
We need to convert Windows paths from the file even on non-Windows
  • Loading branch information
bqqbarbhg committed Sep 22, 2023
1 parent 7864d23 commit 6522e39
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/MagnumPlugins/UfbxImporter/UfbxImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,18 @@ Containers::Optional<TextureData> UfbxImporter::doTexture(UnsignedInt id) {
fileTexture.fileTextureIndex};
}

namespace {

Containers::String fromWindowsSeparators(Containers::String path)
{
/* Windows implementation of Utility::Path::fromNativeSeparators() */
if(!path.isSmall() && path.deleter()) path = Containers::String{path};
for(char& c: path) if(c == '\\') c = '/';
return path;
}

}

AbstractImporter* UfbxImporter::setupOrReuseImporterForImage(UnsignedInt id, const char* errorPrefix) {
const ufbx_texture_file& file = _state->scene->texture_files[id];

Expand Down Expand Up @@ -1472,15 +1484,15 @@ AbstractImporter* UfbxImporter::setupOrReuseImporterForImage(UnsignedInt id, con
const UnsignedInt imageSearchDepth = unboundedIfNegative(configuration().value<Int>("imageSearchDepth"));
if(imageSearchDepth > 0) {
bool found = false;
Containers::String path = Utility::Path::fromNativeSeparators(filename);
Containers::String path = fromWindowsSeparators(filename);
if (!path.isEmpty() && Utility::Path::exists(path)) {
found = true;
} else {
const Containers::String root = Utility::Path::fromNativeSeparators(_state->scene->metadata.relative_root);
const Containers::String root = fromWindowsSeparators(_state->scene->metadata.relative_root);
/* Resolve path manually from either relative or absolute filename,
do not use filename here as it already includes the relative
path of the FBX file. */
path = Utility::Path::fromNativeSeparators(file.relative_filename.length > 0 ? file.relative_filename : file.absolute_filename);
path = fromWindowsSeparators(file.relative_filename.length > 0 ? file.relative_filename : file.absolute_filename);

/* Try to find files with increasing amount of directories,
for /root/sub/dir/file.png we would try in order:
Expand Down

0 comments on commit 6522e39

Please sign in to comment.