don't copy existing texture files

metadata
Wenzel Jakob 2010-08-24 12:07:30 +02:00
parent 378833cefd
commit fa452311f8
2 changed files with 41 additions and 34 deletions

View File

@ -629,13 +629,15 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const std::string &text
fileToId[filename] = image.getId(); fileToId[filename] = image.getId();
boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native); boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native);
ref<FileResolver> fRes = FileResolver::getInstance(); std::string targetPath = textureDir + path.leaf();
std::string resolved = fRes->resolve(path.leaf());
if (endsWith(resolved, ".rgb")) if (endsWith(filename, ".rgb"))
SLog(EWarn, "Maya RGB images must be converted to PNG, EXR or JPEG! The 'imgcvt' " SLog(EWarn, "Maya RGB images must be converted to PNG, EXR or JPEG! The 'imgcvt' "
"utility found in the Maya binary directory can be used to do this."); "utility found in the Maya binary directory can be used to do this.");
if (!FileStream::exists(targetPath)) {
ref<FileResolver> fRes = FileResolver::getInstance();
std::string resolved = fRes->resolve(path.leaf());
if (!FileStream::exists(filename)) { if (!FileStream::exists(filename)) {
if (!FileStream::exists(resolved)) { if (!FileStream::exists(resolved)) {
SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.c_str()); SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.c_str());
@ -646,10 +648,12 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const std::string &text
filename = resolved; filename = resolved;
} }
} }
ref<FileStream> input = new FileStream(filename, FileStream::EReadOnly); ref<FileStream> input = new FileStream(filename, FileStream::EReadOnly);
ref<FileStream> output = new FileStream(textureDir + path.leaf(), FileStream::ETruncReadWrite); ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
input->copyTo(output); input->copyTo(output);
input->close();
output->close();
}
os << "\t<texture id=\"" << image.getId() << "\" type=\"ldrtexture\">" << endl; os << "\t<texture id=\"" << image.getId() << "\" type=\"ldrtexture\">" << endl;
os << "\t\t<string name=\"filename\" value=\"" << textureDir + path.leaf() << "\"/>" << endl; os << "\t\t<string name=\"filename\" value=\"" << textureDir + path.leaf() << "\"/>" << endl;

View File

@ -11,6 +11,7 @@
std::string copyTexture(GeometryConverter *cvt, const std::string &textureDir, std::string filename) { std::string copyTexture(GeometryConverter *cvt, const std::string &textureDir, std::string filename) {
SLog(EInfo, "Copying texture \"%s\" ..", filename.c_str()); SLog(EInfo, "Copying texture \"%s\" ..", filename.c_str());
#if defined(WIN32) #if defined(WIN32)
for (size_t i=0; i<filename.length(); ++i) for (size_t i=0; i<filename.length(); ++i)
if (filename[i] == '/') if (filename[i] == '/')
@ -20,7 +21,11 @@ std::string copyTexture(GeometryConverter *cvt, const std::string &textureDir, s
if (filename[i] == '\\') if (filename[i] == '\\')
filename[i] = '/'; filename[i] = '/';
#endif #endif
boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native); boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native);
std::string targetPath = textureDir + path.leaf();
if (!FileStream::exists(targetPath)) {
ref<FileResolver> fRes = FileResolver::getInstance(); ref<FileResolver> fRes = FileResolver::getInstance();
std::string resolved = fRes->resolve(path.leaf()); std::string resolved = fRes->resolve(path.leaf());
if (!FileStream::exists(filename)) { if (!FileStream::exists(filename)) {
@ -34,14 +39,12 @@ std::string copyTexture(GeometryConverter *cvt, const std::string &textureDir, s
} }
} }
std::string targetPath = textureDir + path.leaf();
ref<FileStream> input = new FileStream(filename, FileStream::EReadOnly); ref<FileStream> input = new FileStream(filename, FileStream::EReadOnly);
ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite); ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
input->copyTo(output); input->copyTo(output);
output->close(); output->close();
input->close(); input->close();
}
return targetPath; return targetPath;
} }