Ported some more methods to C++
This commit is contained in:
parent
678112b926
commit
5a96bad8c2
@ -71,7 +71,6 @@ use Slic3r::Print::Object;
|
||||
use Slic3r::Print::Simple;
|
||||
use Slic3r::Print::SupportMaterial;
|
||||
use Slic3r::Surface;
|
||||
use Slic3r::TriangleMesh;
|
||||
our $build = eval "use Slic3r::Build; 1";
|
||||
use Thread::Semaphore;
|
||||
|
||||
|
@ -158,21 +158,6 @@ sub _arrange {
|
||||
);
|
||||
}
|
||||
|
||||
# makes sure all objects have at least one instance
|
||||
sub add_default_instances {
|
||||
my ($self) = @_;
|
||||
|
||||
# apply a default position to all objects not having one
|
||||
my $added = 0;
|
||||
foreach my $object (@{$self->objects}) {
|
||||
if ($object->instances_count == 0) {
|
||||
$object->add_instance(offset => Slic3r::Pointf->new(0,0));
|
||||
$added = 1;
|
||||
}
|
||||
}
|
||||
return $added;
|
||||
}
|
||||
|
||||
# this returns the bounding box of the *transformed* instances
|
||||
sub bounding_box {
|
||||
my $self = shift;
|
||||
@ -535,16 +520,6 @@ sub unique_materials {
|
||||
return sort keys %materials;
|
||||
}
|
||||
|
||||
sub facets_count {
|
||||
my $self = shift;
|
||||
return sum(map $_->mesh->facets_count, grep !$_->modifier, @{$self->volumes});
|
||||
}
|
||||
|
||||
sub needed_repair {
|
||||
my $self = shift;
|
||||
return (first { !$_->mesh->needed_repair } grep !$_->modifier, @{$self->volumes}) ? 0 : 1;
|
||||
}
|
||||
|
||||
sub mesh_stats {
|
||||
my $self = shift;
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
package Slic3r::TriangleMesh;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r::Geometry qw(X Y);
|
||||
use Slic3r::Geometry::Clipper qw(union_ex offset);
|
||||
|
||||
sub needed_repair {
|
||||
my $self = shift;
|
||||
|
||||
my $stats = $self->stats;
|
||||
return (first { $stats->{$_} > 0 }
|
||||
qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub center {
|
||||
my $self = shift;
|
||||
return $self->bounding_box->center;
|
||||
}
|
||||
|
||||
1;
|
@ -158,6 +158,21 @@ Model::has_objects_with_no_instances() const
|
||||
return false;
|
||||
}
|
||||
|
||||
// makes sure all objects have at least one instance
|
||||
bool
|
||||
Model::add_default_instances()
|
||||
{
|
||||
bool added = false;
|
||||
// apply a default position to all objects not having one
|
||||
for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) {
|
||||
if ((*o)->instances.empty()) {
|
||||
(*o)->add_instance();
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Model, "Model");
|
||||
#endif
|
||||
@ -321,6 +336,27 @@ ModelObject::raw_mesh(TriangleMesh* mesh) const
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
ModelObject::facets_count() const
|
||||
{
|
||||
size_t num = 0;
|
||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||
if ((*v)->modifier) continue;
|
||||
num += (*v)->mesh.stl.stats.number_of_facets;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
bool
|
||||
ModelObject::needed_repair() const
|
||||
{
|
||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||
if ((*v)->modifier) continue;
|
||||
if ((*v)->mesh.needed_repair()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelObject, "Model::Object");
|
||||
#endif
|
||||
|
@ -53,6 +53,7 @@ class Model
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
bool add_default_instances();
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void align_to_origin();
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
@ -121,8 +122,8 @@ class ModelObject
|
||||
//void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
//size_t materials_count() const;
|
||||
//void unique_materials(std::vector<t_model_material_id>* materials) const;
|
||||
//size_t facets_count() const;
|
||||
//bool needed_repair() const;
|
||||
size_t facets_count() const;
|
||||
bool needed_repair() const;
|
||||
|
||||
private:
|
||||
Model* model;
|
||||
|
@ -153,6 +153,17 @@ TriangleMesh::reset_repair_stats() {
|
||||
this->stl.stats.normals_fixed = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
TriangleMesh::needed_repair() const
|
||||
{
|
||||
return this->stl.stats.degenerate_facets > 0
|
||||
|| this->stl.stats.edges_fixed > 0
|
||||
|| this->stl.stats.facets_removed > 0
|
||||
|| this->stl.stats.facets_added > 0
|
||||
|| this->stl.stats.facets_reversed > 0
|
||||
|| this->stl.stats.backwards_edges > 0;
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::WriteOBJFile(char* output_file) {
|
||||
stl_generate_shared_vertices(&stl);
|
||||
|
@ -45,6 +45,7 @@ class TriangleMesh
|
||||
void convex_hull(Polygon* hull);
|
||||
void bounding_box(BoundingBoxf3* bb) const;
|
||||
void reset_repair_stats();
|
||||
bool needed_repair() const;
|
||||
stl_file stl;
|
||||
bool repaired;
|
||||
|
||||
|
@ -56,6 +56,7 @@
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
bool add_default_instances();
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
// void align_instances_to_origin();
|
||||
@ -163,6 +164,9 @@ ModelMaterial::attributes()
|
||||
%code%{ RETVAL = &THIS->origin_translation; %};
|
||||
void set_origin_translation(Pointf* point)
|
||||
%code%{ THIS->origin_translation = *point; %};
|
||||
|
||||
bool needed_repair() const;
|
||||
int facets_count();
|
||||
};
|
||||
|
||||
|
||||
|
@ -38,6 +38,12 @@
|
||||
RETVAL = new BoundingBoxf3();
|
||||
THIS->bounding_box(RETVAL);
|
||||
%};
|
||||
Pointf3* center()
|
||||
%code{%
|
||||
BoundingBoxf3 bb;
|
||||
THIS->bounding_box(&bb);
|
||||
RETVAL = new Pointf3(bb.center());
|
||||
%};
|
||||
int facets_count()
|
||||
%code{% RETVAL = THIS->stl.stats.number_of_facets; %};
|
||||
void reset_repair_stats();
|
||||
|
Loading…
Reference in New Issue
Block a user