MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / resolveImagePath

Method resolveImagePath

Engine/source/ts/collada/colladaUtils.cpp:175–228  ·  view source on GitHub ↗

Resolve image path into something we can use.

Source from the content-addressed store, hash-verified

173
174// Resolve image path into something we can use.
175String ColladaUtils::resolveImagePath(const domImage* image)
176{
177 // 1. If the URI string contains an absolute path, use it if
178 // it is inside the Torque folder, otherwise force textures
179 // to be in the same folder as the shape.
180 // 2. If the URI string contains a relative path, append it
181 // to the shape path (since materials.cs cannot handle
182 // relative paths).
183
184 Torque::Path imagePath;
185 String imageStr(image->getInit_from()->getValue().originalStr().c_str());
186
187 // Trim leading "file://"
188 if (imageStr.compare("file://", 7) == 0)
189 imageStr.erase(0, 7);
190
191 // Trim leading slash from absolute windows paths. eg. /D:/
192 if ((imageStr.compare("/", 1) == 0) && (imageStr.find(':') == 2))
193 imageStr.erase(0, 1);
194
195 // Replace %20 with space
196 imageStr.replace("%20", " ");
197
198 if (Platform::isFullPath(imageStr))
199 {
200 // Absolute path => check for outside the Torque game folder
201 imagePath = String( Platform::makeRelativePathName(imageStr, Platform::getMainDotCsDir()) );
202 if ( !imagePath.getRoot().isEmpty() || // different drive (eg. C:/ vs D:/)
203 (imagePath.getPath().find("/") == 0) || // different OS (eg. /home vs C:/home)
204 (imagePath.getPath().find("../") == 0) ) // same drive, outside Torque game folder
205 {
206 // Force these to the shape folder
207 imagePath.setRoot("");
208 imagePath.setPath("");
209 }
210 }
211 else
212 {
213 // Relative path => prepend with shape path
214 Torque::Path tempPath(imageStr);
215 imagePath = TSShapeLoader::getShapePath();
216 imagePath.appendPath(tempPath);
217 imagePath.setFileName(tempPath.getFileName());
218 }
219
220 // No need to specify the path if it is in the same folder as the model
221 if (imagePath.getPath() == TSShapeLoader::getShapePath().getPath())
222 imagePath.setPath("");
223
224 // Don't care about the extension
225 imagePath.setExtension("");
226
227 return imagePath.getFullPath();
228}
229
230//-----------------------------------------------------------------------------
231// Construct the appropriate child class

Callers

nothing calls this directly

Calls 15

getInit_fromMethod · 0.80
replaceMethod · 0.80
appendPathMethod · 0.80
getFileNameMethod · 0.80
StringClass · 0.50
c_strMethod · 0.45
getValueMethod · 0.45
compareMethod · 0.45
eraseMethod · 0.45
findMethod · 0.45
isEmptyMethod · 0.45
getRootMethod · 0.45

Tested by

no test coverage detected