| 2394 | } |
| 2395 | |
| 2396 | bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes, |
| 2397 | std::vector<material_t> *materials, std::string *warn, |
| 2398 | std::string *err, const char *filename, const char *mtl_basedir, |
| 2399 | bool triangulate, bool default_vcols_fallback) { |
| 2400 | attrib->vertices.clear(); |
| 2401 | attrib->normals.clear(); |
| 2402 | attrib->texcoords.clear(); |
| 2403 | attrib->colors.clear(); |
| 2404 | shapes->clear(); |
| 2405 | |
| 2406 | std::stringstream errss; |
| 2407 | |
| 2408 | std::ifstream ifs(filename); |
| 2409 | if (!ifs) { |
| 2410 | errss << "Cannot open file [" << filename << "]\n"; |
| 2411 | if (err) { |
| 2412 | (*err) = errss.str(); |
| 2413 | } |
| 2414 | return false; |
| 2415 | } |
| 2416 | |
| 2417 | std::string baseDir = mtl_basedir ? mtl_basedir : ""; |
| 2418 | if (!baseDir.empty()) { |
| 2419 | #ifndef _WIN32 |
| 2420 | const char dirsep = '/'; |
| 2421 | #else |
| 2422 | const char dirsep = '\\'; |
| 2423 | #endif |
| 2424 | if (baseDir[baseDir.length() - 1] != dirsep) baseDir += dirsep; |
| 2425 | } |
| 2426 | MaterialFileReader matFileReader(baseDir); |
| 2427 | |
| 2428 | return LoadObj(attrib, shapes, materials, warn, err, &ifs, &matFileReader, |
| 2429 | triangulate, default_vcols_fallback); |
| 2430 | } |
| 2431 | |
| 2432 | bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes, |
| 2433 | std::vector<material_t> *materials, std::string *warn, |