diff options
Diffstat (limited to 'xs/xsp/TriangleMesh.xsp')
-rw-r--r-- | xs/xsp/TriangleMesh.xsp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index c4f249f34..c7324f98d 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -1,7 +1,7 @@ %module{Slic3r::XS}; %{ -#include <myinit.h> +#include <xsinit.h> #include "libslic3r/TriangleMesh.hpp" %} @@ -13,7 +13,6 @@ void ReadSTLFile(char* input_file); void write_ascii(char* output_file); void write_binary(char* output_file); - void ReadFromPerl(SV* vertices, SV* facets); void repair(); void WriteOBJFile(char* output_file); void scale(float factor); @@ -40,6 +39,43 @@ void reset_repair_stats(); %{ +void +TriangleMesh::ReadFromPerl(vertices, facets) + SV* vertices + SV* facets + CODE: + stl_file &stl = THIS->stl; + stl.error = 0; + stl.stats.type = inmemory; + + // count facets and allocate memory + AV* facets_av = (AV*)SvRV(facets); + stl.stats.number_of_facets = av_len(facets_av)+1; + stl.stats.original_num_facets = stl.stats.number_of_facets; + stl_allocate(&stl); + + // read geometry + AV* vertices_av = (AV*)SvRV(vertices); + for (int i = 0; i < stl.stats.number_of_facets; i++) { + AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0)); + stl_facet facet; + facet.normal.x = 0; + facet.normal.y = 0; + facet.normal.z = 0; + for (unsigned int v = 0; v <= 2; v++) { + AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0)); + facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0)); + facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0)); + facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0)); + } + facet.extra[0] = 0; + facet.extra[1] = 0; + + stl.facet_start[i] = facet; + } + + stl_get_size(&stl); + SV* TriangleMesh::stats() CODE: |