MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / resolveTexture

Function resolveTexture

apps/tools/Tools/commands/ModelCommand.cpp:34–70  ·  view source on GitHub ↗

Resolve a model's texture reference (e.g. "data\foo.pac") to a file on disk: try the reference relative to each root, then a recursive match on its basename. ` ` / `#default#` placeholders resolve to nothing.

Source from the content-addressed store, hash-verified

32// try the reference relative to each root, then a recursive match on its basename.
33// `<default>` / `#default#` placeholders resolve to nothing.
34static std::filesystem::path resolveTexture(const std::string& texName, const std::filesystem::path& texRoot,
35 const std::filesystem::path& modelDir)
36{
37 namespace fs = std::filesystem;
38 if (texName.empty() || texName.front() == '<' || texName.front() == '#')
39 return {};
40
41 std::string norm = texName;
42 std::replace(norm.begin(), norm.end(), '\\', '/');
43 fs::path rel(norm);
44 fs::path base = rel.filename();
45
46 std::vector<fs::path> roots;
47 if (!texRoot.empty())
48 roots.push_back(texRoot);
49 if (!modelDir.empty())
50 roots.push_back(modelDir);
51
52 for (const auto& root : roots)
53 {
54 std::error_code ec;
55 fs::path direct = root / rel;
56 if (fs::exists(direct, ec))
57 return direct;
58 for (fs::recursive_directory_iterator it(root, fs::directory_options::skip_permission_denied, ec), end;
59 it != end; it.increment(ec))
60 {
61 if (ec)
62 break;
63 if (it->is_regular_file(ec) && it->path().filename() == base)
64 return it->path();
65 }
66 }
67 if (fs::exists(norm))
68 return fs::path(norm);
69 return {};
70}
71
72static void setupModelInspect(CLI::App& model)
73{

Callers 1

setupModelInspectFunction · 0.85

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected