FIX: [STUDIO-2790] OBJ file cannot be opened information

Change-Id: I670c9845e5d8e8ff1b02bbef749a321ee6b81627
This commit is contained in:
maosheng.wei 2023-04-30 11:19:28 +08:00 committed by Lane.Wei
parent 13fae8ddf6
commit a73ff69860
3 changed files with 15 additions and 6 deletions

View file

@ -15,9 +15,13 @@
#define DIR_SEPARATOR '/' #define DIR_SEPARATOR '/'
#endif #endif
//Translation
#include "I18N.hpp"
#define _L(s) Slic3r::I18N::translate(s)
namespace Slic3r { namespace Slic3r {
bool load_obj(const char *path, TriangleMesh *meshptr) bool load_obj(const char *path, TriangleMesh *meshptr, std::string &message)
{ {
if (meshptr == nullptr) if (meshptr == nullptr)
return false; return false;
@ -26,6 +30,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
ObjParser::ObjData data; ObjParser::ObjData data;
if (! ObjParser::objparse(path, data)) { if (! ObjParser::objparse(path, data)) {
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path; BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path;
message = _L("load_obj: failed to parse");
return false; return false;
} }
@ -40,10 +45,12 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
if (num_face_vertices > 4) { if (num_face_vertices > 4) {
// Non-triangular and non-quad faces are not supported as of now. // Non-triangular and non-quad faces are not supported as of now.
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with more than 4 vertices."; BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with more than 4 vertices.";
message = _L("The file contains polygons with more than 4 vertices.");
return false; return false;
} else if (num_face_vertices < 3) { } else if (num_face_vertices < 3) {
// Non-triangular and non-quad faces are not supported as of now. // Non-triangular and non-quad faces are not supported as of now.
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with less than 2 vertices."; BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with less than 2 vertices.";
message = _L("The file contains polygons with less than 2 vertices.");
return false; return false;
} }
if (num_face_vertices == 4) if (num_face_vertices == 4)
@ -75,6 +82,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
assert(cnt < 4); assert(cnt < 4);
if (vertex.coordIdx < 0 || vertex.coordIdx >= int(its.vertices.size())) { if (vertex.coordIdx < 0 || vertex.coordIdx >= int(its.vertices.size())) {
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains invalid vertex index."; BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains invalid vertex index.";
message = _L("The file contains invalid vertex index.");
return false; return false;
} }
indices[cnt ++] = vertex.coordIdx; indices[cnt ++] = vertex.coordIdx;
@ -91,6 +99,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
*meshptr = TriangleMesh(std::move(its)); *meshptr = TriangleMesh(std::move(its));
if (meshptr->empty()) { if (meshptr->empty()) {
BOOST_LOG_TRIVIAL(error) << "load_obj: This OBJ file couldn't be read because it's empty. " << path; BOOST_LOG_TRIVIAL(error) << "load_obj: This OBJ file couldn't be read because it's empty. " << path;
message = _L("This OBJ file couldn't be read because it's empty.");
return false; return false;
} }
if (meshptr->volume() < 0) if (meshptr->volume() < 0)
@ -98,11 +107,11 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
return true; return true;
} }
bool load_obj(const char *path, Model *model, const char *object_name_in) bool load_obj(const char *path, Model *model, std::string &message, const char *object_name_in)
{ {
TriangleMesh mesh; TriangleMesh mesh;
bool ret = load_obj(path, &mesh); bool ret = load_obj(path, &mesh, message);
if (ret) { if (ret) {
std::string object_name; std::string object_name;

View file

@ -8,8 +8,8 @@ class Model;
class ModelObject; class ModelObject;
// Load an OBJ file into a provided model. // Load an OBJ file into a provided model.
extern bool load_obj(const char *path, TriangleMesh *mesh); extern bool load_obj(const char *path, TriangleMesh *mesh, std::string &message);
extern bool load_obj(const char *path, Model *model, const char *object_name = nullptr); extern bool load_obj(const char *path, Model *model, std::string &message, const char *object_name = nullptr);
extern bool store_obj(const char *path, TriangleMesh *mesh); extern bool store_obj(const char *path, TriangleMesh *mesh);
extern bool store_obj(const char *path, ModelObject *model); extern bool store_obj(const char *path, ModelObject *model);

View file

@ -181,7 +181,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
else if (boost::algorithm::iends_with(input_file, ".stl")) else if (boost::algorithm::iends_with(input_file, ".stl"))
result = load_stl(input_file.c_str(), &model, nullptr, stlFn); result = load_stl(input_file.c_str(), &model, nullptr, stlFn);
else if (boost::algorithm::iends_with(input_file, ".obj")) else if (boost::algorithm::iends_with(input_file, ".obj"))
result = load_obj(input_file.c_str(), &model); result = load_obj(input_file.c_str(), &model, message);
else if (boost::algorithm::iends_with(input_file, ".svg")) else if (boost::algorithm::iends_with(input_file, ".svg"))
result = load_svg(input_file.c_str(), &model, message); result = load_svg(input_file.c_str(), &model, message);
//BBS: remove the old .amf.xml files //BBS: remove the old .amf.xml files