PrusaSlicer-NonPlainar/src/libslic3r/Format/STL.cpp
Vojtech Bubnik 8a2a9dba2f Eradicated admesh from TriangleMesh:
TriangleMesh newly only holds indexed_triangle_set and
TriangleMeshStats. TriangleMeshStats contains an excerpt of stl_stats.
TriangleMeshStats are updated when initializing with indexed_triangle_set.

Admesh triangle mesh fixing is newly only used when loading an STL.
AMF / 3MF / OBJ file formats are already indexed triangle sets, thus
they are no more converted to admesh stl_file format, nor fixed
through admesh repair machinery. When importing AMF / 3MF / OBJ files,
volume is calculated and if negative, all faces are flipped. Also
a bounding box and number of open edges is calculated.

Implemented its_number_of_patches(), its_num_open_edges()
Optimized its_split(), its_is_splittable() using a visitor pattern.

Reworked QHull integration into TriangleMesh:
    1) Face normals were not right.
    2) Indexed triangle set is newly emitted instead of duplicating
       vertices for each face.

Fixed cut_mesh(): Orient the triangulated faces correctly.
2021-09-20 17:12:22 +02:00

63 lines
1.4 KiB
C++

#include "../libslic3r.h"
#include "../Model.hpp"
#include "../TriangleMesh.hpp"
#include "STL.hpp"
#include <string>
#ifdef _WIN32
#define DIR_SEPARATOR '\\'
#else
#define DIR_SEPARATOR '/'
#endif
namespace Slic3r {
bool load_stl(const char *path, Model *model, const char *object_name_in)
{
TriangleMesh mesh;
if (! mesh.ReadSTLFile(path)) {
// die "Failed to open $file\n" if !-e $path;
return false;
}
if (mesh.empty()) {
// die "This STL file couldn't be read because it's empty.\n"
return false;
}
std::string object_name;
if (object_name_in == nullptr) {
const char *last_slash = strrchr(path, DIR_SEPARATOR);
object_name.assign((last_slash == nullptr) ? path : last_slash + 1);
} else
object_name.assign(object_name_in);
model->add_object(object_name.c_str(), path, std::move(mesh));
return true;
}
bool store_stl(const char *path, TriangleMesh *mesh, bool binary)
{
if (binary)
mesh->write_binary(path);
else
mesh->write_ascii(path);
//FIXME returning false even if write failed.
return true;
}
bool store_stl(const char *path, ModelObject *model_object, bool binary)
{
TriangleMesh mesh = model_object->mesh();
return store_stl(path, &mesh, binary);
}
bool store_stl(const char *path, Model *model, bool binary)
{
TriangleMesh mesh = model->mesh();
return store_stl(path, &mesh, binary);
}
}; // namespace Slic3r