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 '/'
#endif
//Translation
#include "I18N.hpp"
#define _L(s) Slic3r::I18N::translate(s)
namespace Slic3r {
bool load_obj(const char *path, TriangleMesh *meshptr)
bool load_obj(const char *path, TriangleMesh *meshptr, std::string &message)
{
if (meshptr == nullptr)
return false;
@ -26,6 +30,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
ObjParser::ObjData data;
if (! ObjParser::objparse(path, data)) {
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path;
message = _L("load_obj: failed to parse");
return false;
}
@ -40,10 +45,12 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
if (num_face_vertices > 4) {
// 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.";
message = _L("The file contains polygons with more than 4 vertices.");
return false;
} else if (num_face_vertices < 3) {
// 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.";
message = _L("The file contains polygons with less than 2 vertices.");
return false;
}
if (num_face_vertices == 4)
@ -75,6 +82,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
assert(cnt < 4);
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.";
message = _L("The file contains invalid vertex index.");
return false;
}
indices[cnt ++] = vertex.coordIdx;
@ -91,6 +99,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
*meshptr = TriangleMesh(std::move(its));
if (meshptr->empty()) {
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;
}
if (meshptr->volume() < 0)
@ -98,11 +107,11 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
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;
bool ret = load_obj(path, &mesh);
bool ret = load_obj(path, &mesh, message);
if (ret) {
std::string object_name;

View file

@ -8,8 +8,8 @@ class Model;
class ModelObject;
// Load an OBJ file into a provided model.
extern bool load_obj(const char *path, TriangleMesh *mesh);
extern bool load_obj(const char *path, Model *model, const char *object_name = nullptr);
extern bool load_obj(const char *path, TriangleMesh *mesh, std::string &message);
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, 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"))
result = load_stl(input_file.c_str(), &model, nullptr, stlFn);
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"))
result = load_svg(input_file.c_str(), &model, message);
//BBS: remove the old .amf.xml files