diff --git a/LearnOpenGL/ResourceLoader.cpp b/LearnOpenGL/ResourceLoader.cpp index 1d33f2a3989a8b97ca076a248f167e36e02c4a29..032467c876f5df79f90499e03d8a156df7e6e831 100644 --- a/LearnOpenGL/ResourceLoader.cpp +++ b/LearnOpenGL/ResourceLoader.cpp @@ -50,7 +50,7 @@ bool openObj(const std::string fileName, std::vector<glm::vec3> &vertices, std:: int charPos = 0; while (std::getline(ifs, line)) { - if (line[0] == NULL || line[0] == '\n' || line[0] == '#' || line[0] == '!' || line[0] == '$') continue; + if (line[0] == NULL || line[0] == '\n' || line[0] == '#' || line[0] == '!' || line[0] == '$' || line[0] == 'o' || line[0] == 'm' || line[0] == 'u') continue; sscanf_s(line.c_str(), "%s", op, sizeof(op)); @@ -89,8 +89,47 @@ bool openObj(const std::string fileName, std::vector<glm::vec3> &vertices, std:: charPos = 0; while ((charPos = line.find(' ')) != std::string::npos) { - sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-/]%d%*[-/]%d", &vIndex, &uvIndex, &vnIndex); - line.erase(0, charPos + 1); + if (line.find("//") == std::string::npos) + { + sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-/]%d%*[-/]%d", &vIndex, &uvIndex, &vnIndex); + line.erase(0, charPos + 1); + } + else + { + uvIndex = 0; + + sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-//]%d", &vIndex, &vnIndex); + line.erase(0, charPos + 1); + } + + if (vIndex >= 1) + { + faceVertexIndicies.push_back(vIndex - 1); + } + if (uvIndex >= 1) + { + faceVertexTexCoordIndicies.push_back(uvIndex - 1); + } + if (vnIndex >= 1) + { + faceVertexNormalIndicies.push_back(vnIndex - 1); + } + } + + if (line.size() > 0) + { + if (line.find("//") == std::string::npos) + { + sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-/]%d%*[-/]%d", &vIndex, &uvIndex, &vnIndex); + line.erase(0, charPos + 1); + } + else + { + uvIndex = 0; + + sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-//]%d", &vIndex, &vnIndex); + line.erase(0, charPos + 1); + } if (vIndex >= 1) { diff --git a/LearnOpenGL/Source.cpp b/LearnOpenGL/Source.cpp index 1333b7fe06cf070ec4dfbb237a25f1a859fa973d..da4f6a29dbb112122cb83df599ad30e9ea9a9a1a 100644 --- a/LearnOpenGL/Source.cpp +++ b/LearnOpenGL/Source.cpp @@ -71,7 +71,7 @@ int main() auto defaultMaterial = new Material(lightmap, orange, transparent); auto cubeMaterial = new Material(lightmap, container_diffuse, container_specular); - auto planeMaterial = new Material(lightmap, container_diffuse, transparent); + auto planeMaterial = new Material(lightmap, magenta, transparent); auto teapot = make_render_object(make_mesh("teapot.obj")); {