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