Ported some Model methods to XS
This commit is contained in:
parent
f06566dd3a
commit
b10917806a
@ -384,14 +384,6 @@ sub add_instance {
|
||||
}
|
||||
}
|
||||
|
||||
sub raw_mesh {
|
||||
my $self = shift;
|
||||
|
||||
my $mesh = Slic3r::TriangleMesh->new;
|
||||
$mesh->merge($_->mesh) for grep !$_->modifier, @{ $self->volumes };
|
||||
return $mesh;
|
||||
}
|
||||
|
||||
sub raw_bounding_box {
|
||||
my $self = shift;
|
||||
|
||||
@ -635,32 +627,4 @@ sub cut {
|
||||
return ($model, $upper, $lower);
|
||||
}
|
||||
|
||||
package Slic3r::Model::Volume;
|
||||
|
||||
sub assign_unique_material {
|
||||
my ($self) = @_;
|
||||
|
||||
my $model = $self->object->model;
|
||||
my $material_id = 1 + $model->material_count;
|
||||
$self->material_id($material_id);
|
||||
return $model->set_material($material_id);
|
||||
}
|
||||
|
||||
package Slic3r::Model::Instance;
|
||||
|
||||
sub transform_mesh {
|
||||
my ($self, $mesh, $dont_translate) = @_;
|
||||
|
||||
$mesh->rotate($self->rotation, Slic3r::Point->new(0,0)); # rotate around mesh origin
|
||||
$mesh->scale($self->scaling_factor); # scale around mesh origin
|
||||
$mesh->translate(@{$self->offset}, 0) unless $dont_translate;
|
||||
}
|
||||
|
||||
sub transform_polygon {
|
||||
my ($self, $polygon) = @_;
|
||||
|
||||
$polygon->rotate($self->rotation, Slic3r::Point->new(0,0)); # rotate around origin
|
||||
$polygon->scale($self->scaling_factor); # scale around origin
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -312,6 +312,15 @@ ModelObject::invalidate_bounding_box()
|
||||
this->_bounding_box_valid = false;
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::raw_mesh(TriangleMesh* mesh) const
|
||||
{
|
||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||
if ((*v)->modifier) continue;
|
||||
mesh->merge((*v)->mesh);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelObject, "Model::Object");
|
||||
#endif
|
||||
@ -349,6 +358,15 @@ ModelVolume::material() const
|
||||
return this->object->get_model()->get_material(this->_material_id);
|
||||
}
|
||||
|
||||
ModelMaterial*
|
||||
ModelVolume::assign_unique_material()
|
||||
{
|
||||
Model* model = this->get_object()->get_model();
|
||||
|
||||
this->_material_id = 1 + model->materials.size();
|
||||
return model->add_material(this->_material_id);
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelVolume, "Model::Volume");
|
||||
#endif
|
||||
@ -362,6 +380,22 @@ ModelInstance::ModelInstance(ModelObject *object, const ModelInstance &other)
|
||||
: object(object), rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset)
|
||||
{}
|
||||
|
||||
void
|
||||
ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->rotate_z(this->rotation); // rotate around mesh origin
|
||||
mesh->scale(this->scaling_factor); // scale around mesh origin
|
||||
if (!dont_translate)
|
||||
mesh->translate(this->offset.x, this->offset.y, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ModelInstance::transform_polygon(Polygon* polygon) const
|
||||
{
|
||||
polygon->rotate(this->rotation, Point(0,0)); // rotate around polygon origin
|
||||
polygon->scale(this->scaling_factor); // scale around polygon origin
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelInstance, "Model::Instance");
|
||||
#endif
|
||||
|
@ -114,7 +114,7 @@ class ModelObject
|
||||
|
||||
void invalidate_bounding_box();
|
||||
|
||||
//void raw_mesh(TriangleMesh* mesh) const;
|
||||
void raw_mesh(TriangleMesh* mesh) const;
|
||||
//void mesh(TriangleMesh* mesh) const;
|
||||
//void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
|
||||
//void center_around_origin();
|
||||
@ -149,6 +149,8 @@ class ModelVolume
|
||||
void material_id(t_model_material_id material_id);
|
||||
ModelMaterial* material() const;
|
||||
|
||||
ModelMaterial* assign_unique_material();
|
||||
|
||||
private:
|
||||
ModelObject* object;
|
||||
t_model_material_id _material_id;
|
||||
@ -166,7 +168,7 @@ class ModelInstance
|
||||
Pointf offset; // in unscaled coordinates
|
||||
|
||||
ModelObject* get_object() const { return this->object; };
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
|
||||
private:
|
||||
|
@ -277,7 +277,7 @@ TriangleMesh::split() const
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::merge(const TriangleMesh* mesh)
|
||||
TriangleMesh::merge(const TriangleMesh &mesh)
|
||||
{
|
||||
// reset stats and metadata
|
||||
int number_of_facets = this->stl.stats.number_of_facets;
|
||||
@ -285,13 +285,13 @@ TriangleMesh::merge(const TriangleMesh* mesh)
|
||||
this->repaired = false;
|
||||
|
||||
// update facet count and allocate more memory
|
||||
this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets;
|
||||
this->stl.stats.number_of_facets = number_of_facets + mesh.stl.stats.number_of_facets;
|
||||
this->stl.stats.original_num_facets = this->stl.stats.number_of_facets;
|
||||
stl_reallocate(&this->stl);
|
||||
|
||||
// copy facets
|
||||
for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) {
|
||||
this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i];
|
||||
for (int i = 0; i < mesh.stl.stats.number_of_facets; i++) {
|
||||
this->stl.facet_start[number_of_facets + i] = mesh.stl.facet_start[i];
|
||||
}
|
||||
|
||||
// update size
|
||||
|
@ -40,7 +40,7 @@ class TriangleMesh
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split() const;
|
||||
void merge(const TriangleMesh* mesh);
|
||||
void merge(const TriangleMesh &mesh);
|
||||
void horizontal_projection(ExPolygons &retval) const;
|
||||
void convex_hull(Polygon* hull);
|
||||
void bounding_box(BoundingBoxf3* bb) const;
|
||||
|
@ -107,6 +107,8 @@ ModelMaterial::attributes()
|
||||
%code%{ RETVAL = &THIS->instances; %};
|
||||
|
||||
void invalidate_bounding_box();
|
||||
TriangleMesh* raw_mesh()
|
||||
%code%{ RETVAL = new TriangleMesh(); THIS->raw_mesh(RETVAL); %};
|
||||
|
||||
Ref<BoundingBoxf3> _bounding_box(BoundingBoxf3* new_bbox = NULL)
|
||||
%code{%
|
||||
@ -186,6 +188,8 @@ ModelMaterial::attributes()
|
||||
%code%{ RETVAL = THIS->modifier; %};
|
||||
void set_modifier(bool modifier)
|
||||
%code%{ THIS->modifier = modifier; %};
|
||||
|
||||
ModelMaterial* assign_unique_material();
|
||||
};
|
||||
|
||||
|
||||
@ -206,4 +210,7 @@ ModelMaterial::attributes()
|
||||
%code%{ THIS->scaling_factor = val; %};
|
||||
void set_offset(Pointf *offset)
|
||||
%code%{ THIS->offset = *offset; %};
|
||||
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
};
|
||||
|
@ -29,7 +29,8 @@
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split();
|
||||
void merge(TriangleMesh* mesh);
|
||||
void merge(TriangleMesh* mesh)
|
||||
%code{% THIS->merge(*mesh); %};
|
||||
ExPolygons horizontal_projection()
|
||||
%code{% THIS->horizontal_projection(RETVAL); %};
|
||||
BoundingBoxf3* bounding_box()
|
||||
|
Loading…
Reference in New Issue
Block a user