| 146 | }; |
| 147 | |
| 148 | OBJLoader::OBJLoader(const FileName &fileName, const bool subdivMode, const bool combineIntoSingleObject) |
| 149 | : group(new SceneGraph::GroupNode), path(fileName.path()), subdivMode(subdivMode) |
| 150 | { |
| 151 | /* open file */ |
| 152 | std::ifstream cin; |
| 153 | cin.open(fileName.c_str()); |
| 154 | if (!cin.is_open()) { |
| 155 | THROW_RUNTIME_ERROR("cannot open " + fileName.str()); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | /* generate default material */ |
| 160 | Ref<SceneGraph::MaterialNode> defaultMaterial = new OBJMaterial("default"); |
| 161 | curMaterialName = "default"; |
| 162 | curMaterial = defaultMaterial; |
| 163 | |
| 164 | while (cin.peek() != -1) |
| 165 | { |
| 166 | /* load next multiline */ |
| 167 | std::string line; std::getline(cin,line); |
| 168 | while (!line.empty() && line[line.size()-1] == '\\') { |
| 169 | line[line.size()-1] = ' '; |
| 170 | std::string next_line; std::getline(cin,next_line); |
| 171 | if (next_line.empty()) break; |
| 172 | line += next_line; |
| 173 | } |
| 174 | const char* token = trimEnd(line.c_str() + strspn(line.c_str(), " \t")); |
| 175 | if (token[0] == 0) continue; |
| 176 | |
| 177 | /*! parse position */ |
| 178 | if (token[0] == 'v' && isSep(token[1])) { |
| 179 | v.push_back(getVec3f(token += 2)); continue; |
| 180 | } |
| 181 | |
| 182 | /* parse normal */ |
| 183 | if (token[0] == 'v' && token[1] == 'n' && isSep(token[2])) { |
| 184 | vn.push_back(getVec3f(token += 3)); |
| 185 | continue; |
| 186 | } |
| 187 | |
| 188 | /* parse texcoord */ |
| 189 | if (token[0] == 'v' && token[1] == 't' && isSep(token[2])) { vt.push_back(getVec2f(token += 3)); continue; } |
| 190 | |
| 191 | /*! parse face */ |
| 192 | if (token[0] == 'f' && isSep(token[1])) |
| 193 | { |
| 194 | parseSep(token += 1); |
| 195 | |
| 196 | std::vector<Vertex> face; |
| 197 | while (token[0]) { |
| 198 | Vertex vtx = getUInt3(token); |
| 199 | face.push_back(vtx); |
| 200 | parseSepOpt(token); |
| 201 | } |
| 202 | curGroup.emplace_back(face); |
| 203 | continue; |
| 204 | } |
| 205 |
nothing calls this directly
no test coverage detected