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
|
/// Convert a string to lower case
|
||||||
extern MTS_EXPORT_CORE std::string toLowerCase(const std::string &string);
|
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
|
/// 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);
|
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 meshesDirectory = "meshes";
|
||||||
std::string outputFile = sceneName;
|
std::string outputFile = sceneName;
|
||||||
|
|
||||||
#ifndef WIN32
|
#if !defined(WIN32)
|
||||||
if (outputDirectory != "") {
|
if (outputDirectory != "") {
|
||||||
textureDirectory = outputDirectory + "/textures";
|
textureDirectory = outputDirectory + "/textures";
|
||||||
meshesDirectory = outputDirectory + "/meshes";
|
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);
|
int status = mkdir(textureDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
if (status != 0 && errno != EEXIST)
|
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);
|
status = mkdir(meshesDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
if (status != 0 && errno != EEXIST)
|
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 += "/";
|
textureDirectory += "/";
|
||||||
meshesDirectory += "/";
|
meshesDirectory += "/";
|
||||||
#else
|
#else
|
||||||
if (outputDirectory != "") {
|
if (outputDirectory != "") {
|
||||||
textureDirectory = textureDirectory + "\\textures";
|
textureDirectory = outputDirectory + "\\textures";
|
||||||
meshesDirectory = meshesDirectory + "\\meshes";
|
meshesDirectory = outputDirectory + "\\meshes";
|
||||||
outputFile = outputDirectory + std::string("\\") + sceneName;
|
outputFile = outputDirectory + std::string("\\") + sceneName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = CreateDirectory(textureDirectory.c_str(), NULL);
|
int status = CreateDirectory(textureDirectory.c_str(), NULL);
|
||||||
if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS)
|
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);
|
status = CreateDirectory(meshesDirectory.c_str(), NULL);
|
||||||
if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS)
|
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 += "\\";
|
textureDirectory += "\\";
|
||||||
meshesDirectory += "\\";
|
meshesDirectory += "\\";
|
||||||
|
|
|
@ -100,7 +100,7 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string
|
||||||
if (buf == "newmtl") {
|
if (buf == "newmtl") {
|
||||||
addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap);
|
addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap);
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
mtlName = line.substr(1, line.length()-2);
|
mtlName = trim(line.substr(1, line.length()-1));
|
||||||
diffuse = Spectrum(0.0f);
|
diffuse = Spectrum(0.0f);
|
||||||
diffuseMap = "";
|
diffuseMap = "";
|
||||||
maskMap = "";
|
maskMap = "";
|
||||||
|
@ -113,10 +113,10 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string
|
||||||
diffuse.fromLinearRGB(r, g, b);
|
diffuse.fromLinearRGB(r, g, b);
|
||||||
} else if (buf == "map_Kd") {
|
} else if (buf == "map_Kd") {
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
diffuseMap = line.substr(1, line.length()-2);
|
diffuseMap = trim(line.substr(1, line.length()-1));
|
||||||
} else if (buf == "map_d") {
|
} else if (buf == "map_d") {
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
maskMap = line.substr(1, line.length()-2);
|
maskMap = trim(line.substr(1, line.length()-1));
|
||||||
} else {
|
} else {
|
||||||
/* Ignore */
|
/* Ignore */
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
|
@ -145,7 +145,7 @@ void GeometryConverter::convertOBJ(const std::string &inputFile,
|
||||||
while (is >> buf) {
|
while (is >> buf) {
|
||||||
if (buf == "mtllib") {
|
if (buf == "mtllib") {
|
||||||
std::getline(is, 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();
|
ref<FileResolver> fRes = FileResolver::getInstance()->clone();
|
||||||
fRes->addPathFromFile(fRes->resolveAbsolute(inputFile));
|
fRes->addPathFromFile(fRes->resolveAbsolute(inputFile));
|
||||||
std::string fullMtlName = fRes->resolve(mtlName);
|
std::string fullMtlName = fRes->resolve(mtlName);
|
||||||
|
|
|
@ -122,12 +122,31 @@ std::vector<std::string> tokenize(const std::string &string, const std::string &
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toLowerCase(const std::string &pString) {
|
std::string trim(const std::string& str) {
|
||||||
std::string result;
|
std::string::size_type
|
||||||
result.reserve(pString.length());
|
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++)
|
return str.substr(start == std::string::npos ? 0 : start,
|
||||||
result += std::tolower(pString[i]);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,13 +64,13 @@ public:
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
if (line.length() > 2) {
|
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());
|
Log(EInfo, "Loading geometry \"%s\"", name.c_str());
|
||||||
}
|
}
|
||||||
} else if (buf == "usemtl") {
|
} else if (buf == "usemtl") {
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(is, 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())
|
if (m_materials.find(materialName) != m_materials.end())
|
||||||
currentMaterial = m_materials[materialName];
|
currentMaterial = m_materials[materialName];
|
||||||
else
|
else
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
} else if (buf == "mtllib") {
|
} else if (buf == "mtllib") {
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(is, 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();
|
ref<FileResolver> fRes = FileResolver::getInstance()->clone();
|
||||||
fRes->addPathFromFile(fRes->resolveAbsolute(props.getString("filename")));
|
fRes->addPathFromFile(fRes->resolveAbsolute(props.getString("filename")));
|
||||||
std::string fullMtlName = fRes->resolve(mtlName);
|
std::string fullMtlName = fRes->resolve(mtlName);
|
||||||
|
@ -159,7 +159,7 @@ public:
|
||||||
|
|
||||||
std::string line, tmp;
|
std::string line, tmp;
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
mtlName = line.substr(1, line.length()-2);
|
mtlName = trim(line.substr(1, line.length()-1));
|
||||||
} else if (buf == "Kd") {
|
} else if (buf == "Kd") {
|
||||||
Float r, g, b;
|
Float r, g, b;
|
||||||
is >> r >> g >> b;
|
is >> r >> g >> b;
|
||||||
|
|
Loading…
Reference in New Issue