win32 importer bugfixes
parent
37a5def9b4
commit
b49340d02a
|
@ -30,6 +30,12 @@ extern MTS_EXPORT_CORE std::string timeToString(Float time);
|
|||
/// Convert a string to lower case
|
||||
extern MTS_EXPORT_CORE std::string toLowerCase(const std::string &string);
|
||||
|
||||
/// Convert a string to upper case
|
||||
extern MTS_EXPORT_CORE std::string toUpperCase(const std::string &string);
|
||||
|
||||
/// Trim spaces (' ', '\n', '\r', '\t') from the ends of a string
|
||||
extern MTS_EXPORT_CORE std::string trim(const std::string& str);
|
||||
|
||||
/// Determines whether a string ends with the string given as second parameter
|
||||
extern MTS_EXPORT_CORE bool endsWith(const std::string& str, const std::string& end);
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ void GeometryConverter::convert(const std::string &inputFile,
|
|||
std::string meshesDirectory = "meshes";
|
||||
std::string outputFile = sceneName;
|
||||
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32)
|
||||
if (outputDirectory != "") {
|
||||
textureDirectory = outputDirectory + "/textures";
|
||||
meshesDirectory = outputDirectory + "/meshes";
|
||||
|
@ -127,26 +127,26 @@ void GeometryConverter::convert(const std::string &inputFile,
|
|||
|
||||
int status = mkdir(textureDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (status != 0 && errno != EEXIST)
|
||||
SLog(EError, "Could not create the directory \"textures\"");
|
||||
SLog(EError, "Could not create the directory \"%s\"", textureDirectory.c_str());
|
||||
status = mkdir(meshesDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (status != 0 && errno != EEXIST)
|
||||
SLog(EError, "Could not create the directory \"meshes\"");
|
||||
SLog(EError, "Could not create the directory \"%s\"", meshesDirectory.c_str());
|
||||
|
||||
textureDirectory += "/";
|
||||
meshesDirectory += "/";
|
||||
#else
|
||||
if (outputDirectory != "") {
|
||||
textureDirectory = textureDirectory + "\\textures";
|
||||
meshesDirectory = meshesDirectory + "\\meshes";
|
||||
textureDirectory = outputDirectory + "\\textures";
|
||||
meshesDirectory = outputDirectory + "\\meshes";
|
||||
outputFile = outputDirectory + std::string("\\") + sceneName;
|
||||
}
|
||||
|
||||
int status = CreateDirectory(textureDirectory.c_str(), NULL);
|
||||
if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
SLog(EError, "Could not create the directory \"textures\"");
|
||||
SLog(EError, "Could not create the directory \"%s\"", textureDirectory.c_str());
|
||||
status = CreateDirectory(meshesDirectory.c_str(), NULL);
|
||||
if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
SLog(EError, "Could not create the directory \"meshes\"");
|
||||
SLog(EError, "Could not create the directory \"%s\"", meshesDirectory.c_str());
|
||||
|
||||
textureDirectory += "\\";
|
||||
meshesDirectory += "\\";
|
||||
|
|
|
@ -100,7 +100,7 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string
|
|||
if (buf == "newmtl") {
|
||||
addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap);
|
||||
std::getline(is, line);
|
||||
mtlName = line.substr(1, line.length()-2);
|
||||
mtlName = trim(line.substr(1, line.length()-1));
|
||||
diffuse = Spectrum(0.0f);
|
||||
diffuseMap = "";
|
||||
maskMap = "";
|
||||
|
@ -113,10 +113,10 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string
|
|||
diffuse.fromLinearRGB(r, g, b);
|
||||
} else if (buf == "map_Kd") {
|
||||
std::getline(is, line);
|
||||
diffuseMap = line.substr(1, line.length()-2);
|
||||
diffuseMap = trim(line.substr(1, line.length()-1));
|
||||
} else if (buf == "map_d") {
|
||||
std::getline(is, line);
|
||||
maskMap = line.substr(1, line.length()-2);
|
||||
maskMap = trim(line.substr(1, line.length()-1));
|
||||
} else {
|
||||
/* Ignore */
|
||||
std::getline(is, line);
|
||||
|
@ -145,7 +145,7 @@ void GeometryConverter::convertOBJ(const std::string &inputFile,
|
|||
while (is >> buf) {
|
||||
if (buf == "mtllib") {
|
||||
std::getline(is, line);
|
||||
std::string mtlName = line.substr(1, line.length()-2);
|
||||
std::string mtlName = trim(line.substr(1, line.length()-1));
|
||||
ref<FileResolver> fRes = FileResolver::getInstance()->clone();
|
||||
fRes->addPathFromFile(fRes->resolveAbsolute(inputFile));
|
||||
std::string fullMtlName = fRes->resolve(mtlName);
|
||||
|
|
|
@ -122,12 +122,31 @@ std::vector<std::string> tokenize(const std::string &string, const std::string &
|
|||
return tokens;
|
||||
}
|
||||
|
||||
std::string toLowerCase(const std::string &pString) {
|
||||
std::string result;
|
||||
result.reserve(pString.length());
|
||||
std::string trim(const std::string& str) {
|
||||
std::string::size_type
|
||||
start = str.find_first_not_of(" \t\r\n"),
|
||||
end = str.find_last_not_of(" \t\r\n");
|
||||
|
||||
for (unsigned int i=0; i<pString.length(); i++)
|
||||
result += std::tolower(pString[i]);
|
||||
return str.substr(start == std::string::npos ? 0 : start,
|
||||
end == std::string::npos ? str.length() - 1 : end - start + 1);
|
||||
}
|
||||
|
||||
std::string toLowerCase(const std::string &string) {
|
||||
std::string result;
|
||||
result.reserve(string.length());
|
||||
|
||||
for (unsigned int i=0; i<string.length(); i++)
|
||||
result += std::tolower(string[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string toUpperCase(const std::string &string) {
|
||||
std::string result;
|
||||
result.reserve(string.length());
|
||||
|
||||
for (unsigned int i=0; i<string.length(); i++)
|
||||
result += toupper(string[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -64,13 +64,13 @@ public:
|
|||
std::string line;
|
||||
std::getline(is, line);
|
||||
if (line.length() > 2) {
|
||||
name = line.substr(1, line.length()-2);
|
||||
name = trim(line.substr(1, line.length()-1));
|
||||
Log(EInfo, "Loading geometry \"%s\"", name.c_str());
|
||||
}
|
||||
} else if (buf == "usemtl") {
|
||||
std::string line;
|
||||
std::getline(is, line);
|
||||
std::string materialName = line.substr(1, line.length()-2);
|
||||
std::string materialName = trim(line.substr(1, line.length()-1));
|
||||
if (m_materials.find(materialName) != m_materials.end())
|
||||
currentMaterial = m_materials[materialName];
|
||||
else
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
} else if (buf == "mtllib") {
|
||||
std::string line;
|
||||
std::getline(is, line);
|
||||
std::string mtlName = line.substr(1, line.length()-2);
|
||||
std::string mtlName = trim(line.substr(1, line.length()-1));
|
||||
ref<FileResolver> fRes = FileResolver::getInstance()->clone();
|
||||
fRes->addPathFromFile(fRes->resolveAbsolute(props.getString("filename")));
|
||||
std::string fullMtlName = fRes->resolve(mtlName);
|
||||
|
@ -159,7 +159,7 @@ public:
|
|||
|
||||
std::string line, tmp;
|
||||
std::getline(is, line);
|
||||
mtlName = line.substr(1, line.length()-2);
|
||||
mtlName = trim(line.substr(1, line.length()-1));
|
||||
} else if (buf == "Kd") {
|
||||
Float r, g, b;
|
||||
is >> r >> g >> b;
|
||||
|
|
Loading…
Reference in New Issue