MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / loadUdimTexture

Method loadUdimTexture

Source/Falcor/Utils/Image/TextureManager.cpp:108–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108TextureManager::CpuTextureHandle TextureManager::loadUdimTexture(
109 const std::filesystem::path& path,
110 bool generateMipLevels,
111 bool loadAsSRGB,
112 ResourceBindFlags bindFlags,
113 bool async,
114 Bitmap::ImportFlags importFlags,
115 const AssetResolver* assetResolver,
116 size_t* loadedTextureCount
117)
118{
119 std::string filename = path.filename().string();
120
121 // Search UDIMS based on mip0
122 auto mipPos = filename.find("<MIP>");
123 if (mipPos != std::string::npos)
124 filename.replace(mipPos, 5, "mip0");
125
126 auto pos = filename.find("<UDIM>");
127 if (pos == std::string::npos)
128 return loadTexture(path, generateMipLevels, loadAsSRGB, bindFlags, async, importFlags, assetResolver, loadedTextureCount);
129
130 std::filesystem::path dirpath = path.parent_path();
131 filename.replace(pos, 6, "[1-9][0-9][0-9][0-9]");
132 std::regex udimRegex(filename);
133 std::vector<std::filesystem::path> texturePaths;
134 // Find the first directory containing the pattern, in case the UDIM set lives in multiple available directories
135 if (assetResolver)
136 texturePaths = assetResolver->resolvePathPattern(dirpath, filename, true /* firstMatchOnly */);
137 else
138 texturePaths = globFilesInDirectory(dirpath, udimRegex, true /* firstMatchOnly */);
139
140 // Nothing found, return an invalid handle
141 if (texturePaths.empty())
142 {
143 logWarning("Can't find UDIM texture files '{}'.", path);
144 if (loadedTextureCount)
145 *loadedTextureCount = 0;
146 return CpuTextureHandle();
147 }
148
149 // Now load all the files from that directory
150 std::filesystem::path loadedDir = texturePaths[0].parent_path();
151 texturePaths = globFilesInDirectory(loadedDir, udimRegex);
152
153 if (loadedTextureCount)
154 *loadedTextureCount = texturePaths.size();
155
156 std::vector<size_t> udimIndices;
157 std::vector<CpuTextureHandle> handles;
158 size_t maxIndex = 0;
159 for (auto& it : texturePaths)
160 {
161 std::string textureFilename = it.filename().string();
162 std::string udimStr = textureFilename.substr(pos, 4); // the 4 digits
163 // Insert the udim number into the original filename (before potentially stripping <MIP>)
164 std::string srcStr = path.filename().string();
165 std::string newFilename = srcStr.replace(srcStr.find("<UDIM>"), 6, udimStr);

Callers

nothing calls this directly

Calls 11

globFilesInDirectoryFunction · 0.85
CpuTextureHandleClass · 0.85
filenameMethod · 0.80
resolvePathPatternMethod · 0.80
getIDMethod · 0.80
logWarningFunction · 0.50
stringMethod · 0.45
replaceMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected