diff --git a/src/libslic3r/Format/OBJ.cpp b/src/libslic3r/Format/OBJ.cpp index 0433e917c..abaae3692 100644 --- a/src/libslic3r/Format/OBJ.cpp +++ b/src/libslic3r/Format/OBJ.cpp @@ -36,12 +36,25 @@ bool load_obj(const char *path, TriangleMesh *meshptr, ObjInfo& obj_info, std::s bool exist_mtl = false; if (data.mtllibs.size() > 0) { // read mtl for (auto mtl_name : data.mtllibs) { - boost::filesystem::path full_path(path); - std::string dir = full_path.parent_path().string(); - auto mtl_file = dir + "/" + mtl_name; - boost::filesystem::path mtl_path(mtl_file); - auto _mtl_path = mtl_path.string().c_str(); - if (boost::filesystem::exists(mtl_path)) { + if (mtl_name.size() == 0){ + continue; + } + exist_mtl = true; + bool mtl_name_is_path = false; + boost::filesystem::path mtl_abs_path(mtl_name); + if (boost::filesystem::exists(mtl_abs_path)) { + mtl_name_is_path = true; + } + boost::filesystem::path mtl_path; + if (!mtl_name_is_path) { + boost::filesystem::path full_path(path); + std::string dir = full_path.parent_path().string(); + auto mtl_file = dir + "/" + mtl_name; + boost::filesystem::path temp_mtl_path(mtl_file); + mtl_path = temp_mtl_path; + } + auto _mtl_path = mtl_name_is_path ? mtl_abs_path.string().c_str() : mtl_path.string().c_str(); + if (boost::filesystem::exists(mtl_name_is_path ? mtl_abs_path : mtl_path)) { if (!ObjParser::mtlparse(_mtl_path, mtl_data)) { BOOST_LOG_TRIVIAL(error) << "load_obj:load_mtl: failed to parse " << _mtl_path; message = _L("load mtl in obj: failed to parse"); @@ -52,7 +65,6 @@ bool load_obj(const char *path, TriangleMesh *meshptr, ObjInfo& obj_info, std::s BOOST_LOG_TRIVIAL(error) << "load_obj: failed to load mtl_path:" << _mtl_path; } } - exist_mtl = true; } // Count the faces and verify, that all faces are triangular. size_t num_faces = 0; diff --git a/src/libslic3r/Format/objparser.cpp b/src/libslic3r/Format/objparser.cpp index c56d6930c..82bf2b496 100644 --- a/src/libslic3r/Format/objparser.cpp +++ b/src/libslic3r/Format/objparser.cpp @@ -237,7 +237,7 @@ static bool obj_parseline(const char *line, ObjData &data) } } if (vertex.coordIdx < 0) - vertex.coordIdx += (int)data.coordinates.size() / 4; + vertex.coordIdx += (int) data.coordinates.size() / OBJ_VERTEX_LENGTH; else -- vertex.coordIdx; if (vertex.normalIdx < 0) @@ -604,9 +604,6 @@ bool objparse(const char *path, ObjData &data) BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory"; } ::fclose(pFile); - - // printf("vertices: %d\r\n", data.vertices.size() / 4); - // printf("coords: %d\r\n", data.coordinates.size()); return true; } @@ -646,9 +643,6 @@ bool mtlparse(const char *path, MtlData &data) BOOST_LOG_TRIVIAL(error) << "MtlParser: Out of memory"; } ::fclose(pFile); - - // printf("vertices: %d\r\n", data.vertices.size() / 4); - // printf("coords: %d\r\n", data.coordinates.size()); return true; }