Ported ModelObject::rotate() and ModelObject::flip() to XS, as well as axes constants
This commit is contained in:
parent
be2f46ca68
commit
5eb3bc52ef
11 changed files with 84 additions and 46 deletions
|
@ -27,9 +27,6 @@ our @EXPORT_OK = qw(
|
||||||
use constant PI => 4 * atan2(1, 1);
|
use constant PI => 4 * atan2(1, 1);
|
||||||
use constant A => 0;
|
use constant A => 0;
|
||||||
use constant B => 1;
|
use constant B => 1;
|
||||||
use constant X => 0;
|
|
||||||
use constant Y => 1;
|
|
||||||
use constant Z => 2;
|
|
||||||
use constant X1 => 0;
|
use constant X1 => 0;
|
||||||
use constant Y1 => 1;
|
use constant Y1 => 1;
|
||||||
use constant X2 => 2;
|
use constant X2 => 2;
|
||||||
|
|
|
@ -262,37 +262,6 @@ sub add_instance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rotate {
|
|
||||||
my ($self, $angle, $axis) = @_;
|
|
||||||
|
|
||||||
# we accept angle in radians but mesh currently uses degrees
|
|
||||||
$angle = rad2deg($angle);
|
|
||||||
|
|
||||||
if ($axis == X) {
|
|
||||||
$_->mesh->rotate_x($angle) for @{$self->volumes};
|
|
||||||
} elsif ($axis == Y) {
|
|
||||||
$_->mesh->rotate_y($angle) for @{$self->volumes};
|
|
||||||
} elsif ($axis == Z) {
|
|
||||||
$_->mesh->rotate_z($angle) for @{$self->volumes};
|
|
||||||
}
|
|
||||||
$self->set_origin_translation(Slic3r::Pointf3->new(0,0,0));
|
|
||||||
$self->invalidate_bounding_box;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub flip {
|
|
||||||
my ($self, $axis) = @_;
|
|
||||||
|
|
||||||
if ($axis == X) {
|
|
||||||
$_->mesh->flip_x for @{$self->volumes};
|
|
||||||
} elsif ($axis == Y) {
|
|
||||||
$_->mesh->flip_y for @{$self->volumes};
|
|
||||||
} elsif ($axis == Z) {
|
|
||||||
$_->mesh->flip_z for @{$self->volumes};
|
|
||||||
}
|
|
||||||
$self->set_origin_translation(Slic3r::Pointf3->new(0,0,0));
|
|
||||||
$self->invalidate_bounding_box;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub mesh_stats {
|
sub mesh_stats {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "Model.hpp"
|
#include "Model.hpp"
|
||||||
|
#include "Geometry.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
@ -514,6 +515,29 @@ ModelObject::scale(const Pointf3 &versor)
|
||||||
this->invalidate_bounding_box();
|
this->invalidate_bounding_box();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModelObject::rotate(float angle, const Axis &axis)
|
||||||
|
{
|
||||||
|
// we accept angle in radians but mesh currently uses degrees
|
||||||
|
angle = Slic3r::Geometry::rad2deg(angle);
|
||||||
|
|
||||||
|
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||||
|
(*v)->mesh.rotate(angle, axis);
|
||||||
|
}
|
||||||
|
this->origin_translation = Pointf3(0,0,0);
|
||||||
|
this->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModelObject::flip(const Axis &axis)
|
||||||
|
{
|
||||||
|
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||||
|
(*v)->mesh.flip(axis);
|
||||||
|
}
|
||||||
|
this->origin_translation = Pointf3(0,0,0);
|
||||||
|
this->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ModelObject::materials_count() const
|
ModelObject::materials_count() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -129,6 +129,8 @@ class ModelObject
|
||||||
void translate(const Vectorf3 &vector);
|
void translate(const Vectorf3 &vector);
|
||||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||||
void scale(const Pointf3 &versor);
|
void scale(const Pointf3 &versor);
|
||||||
|
void rotate(float angle, const Axis &axis);
|
||||||
|
void flip(const Axis &axis);
|
||||||
size_t materials_count() const;
|
size_t materials_count() const;
|
||||||
size_t facets_count() const;
|
size_t facets_count() const;
|
||||||
bool needed_repair() const;
|
bool needed_repair() const;
|
||||||
|
|
|
@ -200,40 +200,58 @@ void TriangleMesh::translate(float x, float y, float z)
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
stl_invalidate_shared_vertices(&this->stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TriangleMesh::rotate(float angle, const Axis &axis)
|
||||||
|
{
|
||||||
|
if (axis == X) {
|
||||||
|
stl_rotate_x(&(this->stl), angle);
|
||||||
|
} else if (axis == Y) {
|
||||||
|
stl_rotate_y(&(this->stl), angle);
|
||||||
|
} else if (axis == Z) {
|
||||||
|
stl_rotate_z(&(this->stl), angle);
|
||||||
|
}
|
||||||
|
stl_invalidate_shared_vertices(&this->stl);
|
||||||
|
}
|
||||||
|
|
||||||
void TriangleMesh::rotate_x(float angle)
|
void TriangleMesh::rotate_x(float angle)
|
||||||
{
|
{
|
||||||
stl_rotate_x(&(this->stl), angle);
|
this->rotate(angle, X);
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::rotate_y(float angle)
|
void TriangleMesh::rotate_y(float angle)
|
||||||
{
|
{
|
||||||
stl_rotate_y(&(this->stl), angle);
|
this->rotate(angle, Y);
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::rotate_z(float angle)
|
void TriangleMesh::rotate_z(float angle)
|
||||||
{
|
{
|
||||||
stl_rotate_z(&(this->stl), angle);
|
this->rotate(angle, Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TriangleMesh::flip(const Axis &axis)
|
||||||
|
{
|
||||||
|
if (axis == X) {
|
||||||
|
stl_mirror_yz(&this->stl);
|
||||||
|
} else if (axis == Y) {
|
||||||
|
stl_mirror_xz(&this->stl);
|
||||||
|
} else if (axis == Z) {
|
||||||
|
stl_mirror_xy(&this->stl);
|
||||||
|
}
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
stl_invalidate_shared_vertices(&this->stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::flip_x()
|
void TriangleMesh::flip_x()
|
||||||
{
|
{
|
||||||
stl_mirror_yz(&this->stl);
|
this->flip(X);
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::flip_y()
|
void TriangleMesh::flip_y()
|
||||||
{
|
{
|
||||||
stl_mirror_xz(&this->stl);
|
this->flip(Y);
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::flip_z()
|
void TriangleMesh::flip_z()
|
||||||
{
|
{
|
||||||
stl_mirror_xy(&this->stl);
|
this->flip(Z);
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriangleMesh::align_to_origin()
|
void TriangleMesh::align_to_origin()
|
||||||
|
|
|
@ -32,9 +32,11 @@ class TriangleMesh
|
||||||
void scale(float factor);
|
void scale(float factor);
|
||||||
void scale(const Pointf3 &versor);
|
void scale(const Pointf3 &versor);
|
||||||
void translate(float x, float y, float z);
|
void translate(float x, float y, float z);
|
||||||
|
void rotate(float angle, const Axis &axis);
|
||||||
void rotate_x(float angle);
|
void rotate_x(float angle);
|
||||||
void rotate_y(float angle);
|
void rotate_y(float angle);
|
||||||
void rotate_z(float angle);
|
void rotate_z(float angle);
|
||||||
|
void flip(const Axis &axis);
|
||||||
void flip_x();
|
void flip_x();
|
||||||
void flip_y();
|
void flip_y();
|
||||||
void flip_z();
|
void flip_z();
|
||||||
|
|
|
@ -17,7 +17,12 @@
|
||||||
typedef long coord_t;
|
typedef long coord_t;
|
||||||
typedef double coordf_t;
|
typedef double coordf_t;
|
||||||
|
|
||||||
namespace Slic3r {}
|
namespace Slic3r {
|
||||||
|
|
||||||
|
// TODO: make sure X = 0
|
||||||
|
enum Axis { X, Y, Z };
|
||||||
|
|
||||||
|
}
|
||||||
using namespace Slic3r;
|
using namespace Slic3r;
|
||||||
|
|
||||||
/* Implementation of CONFESS("foo"): */
|
/* Implementation of CONFESS("foo"): */
|
||||||
|
|
|
@ -87,4 +87,16 @@ simplify_polygons(polygons, tolerance)
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
IV
|
||||||
|
_constant()
|
||||||
|
ALIAS:
|
||||||
|
X = X
|
||||||
|
Y = Y
|
||||||
|
Z = Z
|
||||||
|
PROTOTYPE:
|
||||||
|
CODE:
|
||||||
|
RETVAL = ix;
|
||||||
|
OUTPUT: RETVAL
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,8 @@ ModelMaterial::attributes()
|
||||||
void translate(double x, double y, double z);
|
void translate(double x, double y, double z);
|
||||||
void scale_xyz(Pointf3* versor)
|
void scale_xyz(Pointf3* versor)
|
||||||
%code{% THIS->scale(*versor); %};
|
%code{% THIS->scale(*versor); %};
|
||||||
|
void rotate(float angle, Axis axis);
|
||||||
|
void flip(Axis axis);
|
||||||
|
|
||||||
Model* cut(double z)
|
Model* cut(double z)
|
||||||
%code%{
|
%code%{
|
||||||
|
|
|
@ -184,6 +184,7 @@ Clone<BridgeDetector> O_OBJECT_SLIC3R_T
|
||||||
|
|
||||||
GLVertexArray* O_OBJECT_SLIC3R
|
GLVertexArray* O_OBJECT_SLIC3R
|
||||||
|
|
||||||
|
Axis T_UV
|
||||||
ExtrusionLoopRole T_UV
|
ExtrusionLoopRole T_UV
|
||||||
ExtrusionRole T_UV
|
ExtrusionRole T_UV
|
||||||
FlowRole T_UV
|
FlowRole T_UV
|
||||||
|
|
|
@ -173,6 +173,12 @@
|
||||||
%typemap{SupportLayerPtrs*};
|
%typemap{SupportLayerPtrs*};
|
||||||
|
|
||||||
|
|
||||||
|
%typemap{Axis}{parsed}{
|
||||||
|
%cpp_type{Axis};
|
||||||
|
%precall_code{%
|
||||||
|
$CVar = (Axis)SvUV($PerlVar);
|
||||||
|
%};
|
||||||
|
};
|
||||||
%typemap{SurfaceType}{parsed}{
|
%typemap{SurfaceType}{parsed}{
|
||||||
%cpp_type{SurfaceType};
|
%cpp_type{SurfaceType};
|
||||||
%precall_code{%
|
%precall_code{%
|
||||||
|
|
Loading…
Reference in a new issue