diff --git a/wrap/io_trimesh/import_obj.h b/wrap/io_trimesh/import_obj.h index 0a3a6347..5b8ab94d 100644 --- a/wrap/io_trimesh/import_obj.h +++ b/wrap/io_trimesh/import_obj.h @@ -985,20 +985,16 @@ public: currentMaterial.illum = 2; bool first = true; - while (!stream.eof()) - { + while (!stream.eof()) { tokens.clear(); TokenizeNextLine(stream, tokens, line, 0); - if (tokens.size() > 0) - { + if (tokens.size() > 0) { header.clear(); header = tokens[0]; - if (header.compare("newmtl")==0) - { - if (!first) - { + if (header.compare("newmtl")==0) { + if (!first) { materials.push_back(currentMaterial); currentMaterial = Material(); currentMaterial.index = (unsigned int)(-1); @@ -1013,43 +1009,39 @@ public: else currentMaterial.materialName = line.substr(7); //space in the name, get everything after "newmtl " } - else if (header.compare("Ka")==0) - { - if (tokens.size() < 4) return false; - currentMaterial.Ka = Point3fFrom3Tokens(tokens,1); + else if (header.compare("Ka")==0) { + if (tokens.size() < 4) { + currentMaterial.Ka = Point3fFrom3Tokens(tokens,1); + } } - else if (header.compare("Kd")==0) - { - if (tokens.size() < 4) return false; - currentMaterial.Kd = Point3fFrom3Tokens(tokens,1); + else if (header.compare("Kd")==0) { + if (tokens.size() < 4) { + currentMaterial.Kd = Point3fFrom3Tokens(tokens,1); + } } - else if (header.compare("Ks")==0) - { - if (tokens.size() < 4) return false; - currentMaterial.Ks = Point3fFrom3Tokens(tokens,1); + else if (header.compare("Ks")==0) { + if (tokens.size() < 4) { + currentMaterial.Ks = Point3fFrom3Tokens(tokens,1); + } } - else if ( (header.compare("d")==0) || - (header.compare("Tr")==0) ) // alpha - { - if (tokens.size() < 2) return false; - currentMaterial.Tr = (float) atof(tokens[1].c_str()); + else if ((header.compare("d")==0) || (header.compare("Tr")==0)) { // alpha + if (tokens.size() < 2) { + currentMaterial.Tr = (float) atof(tokens[1].c_str()); + } } - else if (header.compare("Ns")==0) // shininess - { - if (tokens.size() < 2) return false; - currentMaterial.Ns = float(atoi(tokens[1].c_str())); + else if (header.compare("Ns")==0) { // shininess + if (tokens.size() < 2) { + currentMaterial.Ns = float(atoi(tokens[1].c_str())); + } } - else if (header.compare("illum")==0) // specular illumination on/off - { - if (tokens.size() < 2) return false; - currentMaterial.illum = atoi(tokens[1].c_str());; + else if (header.compare("illum")==0) { // specular illumination on/off + if (tokens.size() < 2) { + currentMaterial.illum = atoi(tokens[1].c_str()); + } } - else if(header.compare("map_Kd")==0) // texture name - { + else if(header.compare("map_Kd")==0) { // texture name std::string textureName; - if (tokens.size() < 2) - return false; - else { + if (tokens.size() == 2) { //the tex name is the last one (after any option) textureName = tokens[tokens.size()-1]; } @@ -1074,19 +1066,15 @@ public: stream.close(); // Sometimes some materials have texture and no texture // in this case for sake of uniformity we just use the first texture. - if(!textures.empty()) - { - for(size_t i=0;i