diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 4985e412b..36aa84db9 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1001,7 +1001,7 @@ sub repaint { # draw skirt if (@{$parent->{object_previews}} && $parent->{config}->skirts) { - my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour->pp}, map @{$_->[2]}, @{$parent->{object_previews}} ])}); + my $convex_hull = convex_hull([ map @{$_->contour}, map @{$_->[2]}, @{$parent->{object_previews}} ]); ($convex_hull) = @{offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)}; $dc->SetPen($parent->{skirt_pen}); $dc->SetBrush($parent->{transparent_brush}); @@ -1289,7 +1289,7 @@ sub _trigger_model_object { my $mesh = $model_object->mesh; $mesh->repair; - $self->convex_hull(Slic3r::Geometry::convex_hull($mesh->vertices)); + $self->convex_hull($mesh->convex_hull); $self->facets($mesh->facets_count); $self->vertices(scalar @{$mesh->vertices}); $self->materials($model_object->materials_count); diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index 7c554b7e7..689bb7407 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -1,5 +1,6 @@ #include "TriangleMesh.hpp" #include "ClipperUtils.hpp" +#include "Geometry.hpp" #include #include #include @@ -598,6 +599,19 @@ TriangleMesh::horizontal_projection(ExPolygons &retval) const union_(pp, retval, true); } +void +TriangleMesh::convex_hull(Polygon &hull) +{ + if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl)); + Points pp; + pp.reserve(this->stl.stats.shared_vertices); + for (int i = 0; i < this->stl.stats.shared_vertices; i++) { + stl_vertex* v = this->stl.v_shared; + pp.push_back(Point(v->x / SCALING_FACTOR, v->y / SCALING_FACTOR)); + } + Slic3r::Geometry::convex_hull(pp, hull); +} + #ifdef SLIC3RXS SV* TriangleMesh::to_SV() { diff --git a/xs/src/TriangleMesh.hpp b/xs/src/TriangleMesh.hpp index 74f1605c8..06ecca273 100644 --- a/xs/src/TriangleMesh.hpp +++ b/xs/src/TriangleMesh.hpp @@ -33,6 +33,7 @@ class TriangleMesh TriangleMeshPtrs split() const; void merge(const TriangleMesh* mesh); void horizontal_projection(ExPolygons &retval) const; + void convex_hull(Polygon &hull); stl_file stl; bool repaired; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index abee1f4ec..db98a633e 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -161,6 +161,16 @@ TriangleMesh::bb3() OUTPUT: RETVAL +Polygon* +TriangleMesh::convex_hull() + PREINIT: + const char* CLASS = "Slic3r::Polygon"; + CODE: + RETVAL = new Polygon (); + THIS->convex_hull(*RETVAL); + OUTPUT: + RETVAL + %} };