mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-07-31 16:22:07 +08:00
Partially ported Format::STL and Format::OBJ to XS
This commit is contained in:
parent
2230652218
commit
36231347f9
@ -38,6 +38,8 @@ src/libslic3r/GCodeWriter.cpp
|
||||
src/libslic3r/GCodeWriter.hpp
|
||||
src/libslic3r/Geometry.cpp
|
||||
src/libslic3r/Geometry.hpp
|
||||
src/libslic3r/IO.cpp
|
||||
src/libslic3r/IO.hpp
|
||||
src/libslic3r/Layer.cpp
|
||||
src/libslic3r/Layer.hpp
|
||||
src/libslic3r/LayerRegion.cpp
|
||||
|
@ -234,7 +234,7 @@ stl_write_vrml(stl_file *stl, char *file) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void stl_write_obj (stl_file *stl, char *file) {
|
||||
void stl_write_obj (stl_file *stl, const char *file) {
|
||||
int i;
|
||||
FILE* fp;
|
||||
|
||||
|
@ -135,7 +135,7 @@ typedef struct {
|
||||
} stl_file;
|
||||
|
||||
|
||||
extern void stl_open(stl_file *stl, char *file);
|
||||
extern void stl_open(stl_file *stl, const char *file);
|
||||
extern void stl_close(stl_file *stl);
|
||||
extern void stl_stats_out(stl_file *stl, FILE *file, char *input_file);
|
||||
extern void stl_print_edges(stl_file *stl, FILE *file);
|
||||
@ -171,7 +171,7 @@ extern void stl_mirror_xz(stl_file *stl);
|
||||
extern void stl_open_merge(stl_file *stl, char *file);
|
||||
extern void stl_invalidate_shared_vertices(stl_file *stl);
|
||||
extern void stl_generate_shared_vertices(stl_file *stl);
|
||||
extern void stl_write_obj(stl_file *stl, char *file);
|
||||
extern void stl_write_obj(stl_file *stl, const char *file);
|
||||
extern void stl_write_off(stl_file *stl, char *file);
|
||||
extern void stl_write_dxf(stl_file *stl, char *file, char *label);
|
||||
extern void stl_write_vrml(stl_file *stl, char *file);
|
||||
@ -182,7 +182,7 @@ extern void stl_calculate_volume(stl_file *stl);
|
||||
extern void stl_repair(stl_file *stl, int fixall_flag, int exact_flag, int tolerance_flag, float tolerance, int increment_flag, float increment, int nearby_flag, int iterations, int remove_unconnected_flag, int fill_holes_flag, int normal_directions_flag, int normal_values_flag, int reverse_all_flag, int verbose_flag);
|
||||
|
||||
extern void stl_initialize(stl_file *stl);
|
||||
extern void stl_count_facets(stl_file *stl, char *file);
|
||||
extern void stl_count_facets(stl_file *stl, const char *file);
|
||||
extern void stl_allocate(stl_file *stl);
|
||||
extern void stl_read(stl_file *stl, int first_facet, int first);
|
||||
extern void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
||||
|
@ -34,7 +34,7 @@
|
||||
#endif
|
||||
|
||||
void
|
||||
stl_open(stl_file *stl, char *file) {
|
||||
stl_open(stl_file *stl, const char *file) {
|
||||
stl_initialize(stl);
|
||||
stl_count_facets(stl, file);
|
||||
stl_allocate(stl);
|
||||
@ -65,7 +65,7 @@ stl_initialize(stl_file *stl) {
|
||||
}
|
||||
|
||||
void
|
||||
stl_count_facets(stl_file *stl, char *file) {
|
||||
stl_count_facets(stl_file *stl, const char *file) {
|
||||
long file_size;
|
||||
int header_num_facets;
|
||||
int num_facets;
|
||||
|
47
xs/src/libslic3r/IO.cpp
Normal file
47
xs/src/libslic3r/IO.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "IO.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Slic3r { namespace IO {
|
||||
|
||||
bool
|
||||
STL::read_file(std::string input_file, Model* model)
|
||||
{
|
||||
// TODO: encode file name
|
||||
// TODO: check that file exists
|
||||
|
||||
TriangleMesh mesh;
|
||||
mesh.ReadSTLFile(input_file);
|
||||
mesh.repair();
|
||||
|
||||
if (mesh.facets_count() == 0)
|
||||
throw std::runtime_error("This STL file couldn't be read because it's empty.");
|
||||
|
||||
ModelObject* object = model->add_object();
|
||||
object->name = input_file; // TODO: use basename()
|
||||
object->input_file = input_file;
|
||||
|
||||
ModelVolume* volume = object->add_volume(mesh);
|
||||
volume->name = input_file; // TODO: use basename()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
STL::write(TriangleMesh& mesh, std::string output_file, bool binary)
|
||||
{
|
||||
if (binary) {
|
||||
mesh.write_binary(output_file);
|
||||
} else {
|
||||
mesh.write_ascii(output_file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
OBJ::write(TriangleMesh& mesh, std::string output_file)
|
||||
{
|
||||
mesh.WriteOBJFile(output_file);
|
||||
return true;
|
||||
}
|
||||
|
||||
} }
|
26
xs/src/libslic3r/IO.hpp
Normal file
26
xs/src/libslic3r/IO.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef slic3r_IO_hpp_
|
||||
#define slic3r_IO_hpp_
|
||||
|
||||
#include "libslic3r.h"
|
||||
#include "Model.hpp"
|
||||
#include "TriangleMesh.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Slic3r { namespace IO {
|
||||
|
||||
class STL
|
||||
{
|
||||
public:
|
||||
bool read_file(std::string input_file, Model* model);
|
||||
bool write(TriangleMesh& mesh, std::string output_file, bool binary = true);
|
||||
};
|
||||
|
||||
class OBJ
|
||||
{
|
||||
public:
|
||||
bool write(TriangleMesh& mesh, std::string output_file);
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
@ -70,20 +70,20 @@ TriangleMesh::~TriangleMesh() {
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::ReadSTLFile(char* input_file) {
|
||||
stl_open(&stl, input_file);
|
||||
TriangleMesh::ReadSTLFile(const std::string &input_file) {
|
||||
stl_open(&stl, input_file.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::write_ascii(char* output_file)
|
||||
TriangleMesh::write_ascii(const std::string &output_file)
|
||||
{
|
||||
stl_write_ascii(&this->stl, output_file, "");
|
||||
stl_write_ascii(&this->stl, output_file.c_str(), "");
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::write_binary(char* output_file)
|
||||
TriangleMesh::write_binary(const std::string &output_file)
|
||||
{
|
||||
stl_write_binary(&this->stl, output_file, "");
|
||||
stl_write_binary(&this->stl, output_file.c_str(), "");
|
||||
}
|
||||
|
||||
void
|
||||
@ -173,9 +173,9 @@ TriangleMesh::facets_count() const
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::WriteOBJFile(char* output_file) {
|
||||
TriangleMesh::WriteOBJFile(const std::string &output_file) {
|
||||
stl_generate_shared_vertices(&stl);
|
||||
stl_write_obj(&stl, output_file);
|
||||
stl_write_obj(&stl, output_file.c_str());
|
||||
}
|
||||
|
||||
void TriangleMesh::scale(float factor)
|
||||
|
@ -24,11 +24,11 @@ class TriangleMesh
|
||||
TriangleMesh& operator= (TriangleMesh other);
|
||||
void swap(TriangleMesh &other);
|
||||
~TriangleMesh();
|
||||
void ReadSTLFile(char* input_file);
|
||||
void write_ascii(char* output_file);
|
||||
void write_binary(char* output_file);
|
||||
void ReadSTLFile(const std::string &input_file);
|
||||
void write_ascii(const std::string &output_file);
|
||||
void write_binary(const std::string &output_file);
|
||||
void repair();
|
||||
void WriteOBJFile(char* output_file);
|
||||
void WriteOBJFile(const std::string &output_file);
|
||||
void scale(float factor);
|
||||
void scale(const Pointf3 &versor);
|
||||
void translate(float x, float y, float z);
|
||||
|
@ -10,11 +10,11 @@
|
||||
~TriangleMesh();
|
||||
Clone<TriangleMesh> clone()
|
||||
%code{% RETVAL = THIS; %};
|
||||
void ReadSTLFile(char* input_file);
|
||||
void write_ascii(char* output_file);
|
||||
void write_binary(char* output_file);
|
||||
void ReadSTLFile(std::string input_file);
|
||||
void write_ascii(std::string output_file);
|
||||
void write_binary(std::string output_file);
|
||||
void repair();
|
||||
void WriteOBJFile(char* output_file);
|
||||
void WriteOBJFile(std::string output_file);
|
||||
void scale(float factor);
|
||||
void scale_xyz(Pointf3* versor)
|
||||
%code{% THIS->scale(*versor); %};
|
||||
|
Loading…
x
Reference in New Issue
Block a user