blob: 99e2ff1935a36ca820ad3ff26b6800d49fa2698a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#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;
mesh.ReadSTLFile(path);
if (mesh.stl.error) {
// die "Failed to open $file\n" if !-e $path;
return false;
}
mesh.repair();
if (mesh.facets_count() == 0) {
// 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);
}
}; // namespace Slic3r
|