| 3173 | } |
| 3174 | |
| 3175 | bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, |
| 3176 | void *user_data /*= NULL*/, |
| 3177 | MaterialReader *readMatFn /*= NULL*/, |
| 3178 | std::string *warn, /* = NULL*/ |
| 3179 | std::string *err /*= NULL*/) { |
| 3180 | std::stringstream errss; |
| 3181 | |
| 3182 | // material |
| 3183 | std::set<std::string> material_filenames; |
| 3184 | std::map<std::string, int> material_map; |
| 3185 | int material_id = -1; // -1 = invalid |
| 3186 | |
| 3187 | std::vector<index_t> indices; |
| 3188 | std::vector<material_t> materials; |
| 3189 | std::vector<std::string> names; |
| 3190 | names.reserve(2); |
| 3191 | std::vector<const char *> names_out; |
| 3192 | |
| 3193 | std::string linebuf; |
| 3194 | while (inStream.peek() != -1) { |
| 3195 | safeGetline(inStream, linebuf); |
| 3196 | |
| 3197 | // Trim newline '\r\n' or '\n' |
| 3198 | if (linebuf.size() > 0) { |
| 3199 | if (linebuf[linebuf.size() - 1] == '\n') |
| 3200 | linebuf.erase(linebuf.size() - 1); |
| 3201 | } |
| 3202 | if (linebuf.size() > 0) { |
| 3203 | if (linebuf[linebuf.size() - 1] == '\r') |
| 3204 | linebuf.erase(linebuf.size() - 1); |
| 3205 | } |
| 3206 | |
| 3207 | // Skip if empty line. |
| 3208 | if (linebuf.empty()) { |
| 3209 | continue; |
| 3210 | } |
| 3211 | |
| 3212 | // Skip leading space. |
| 3213 | const char *token = linebuf.c_str(); |
| 3214 | token += strspn(token, " \t"); |
| 3215 | |
| 3216 | assert(token); |
| 3217 | if (token[0] == '\0') continue; // empty line |
| 3218 | |
| 3219 | if (token[0] == '#') continue; // comment line |
| 3220 | |
| 3221 | // vertex |
| 3222 | if (token[0] == 'v' && IS_SPACE((token[1]))) { |
| 3223 | token += 2; |
| 3224 | real_t x, y, z; |
| 3225 | real_t r, g, b; |
| 3226 | |
| 3227 | int num_components = parseVertexWithColor(&x, &y, &z, &r, &g, &b, &token); |
| 3228 | if (callback.vertex_cb) { |
| 3229 | callback.vertex_cb(user_data, x, y, z, r); // r=w is optional |
| 3230 | } |
| 3231 | if (callback.vertex_color_cb) { |
| 3232 | bool found_color = (num_components == 6); |
nothing calls this directly
no test coverage detected