Skip to content

Commit

Permalink
reinstate direct mesh manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oekn5w authored and lordofhyphens committed Dec 2, 2019
1 parent 65f34b8 commit ad7a169
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 8 deletions.
129 changes: 123 additions & 6 deletions xs/src/libslic3r/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,129 @@ TriangleMesh::WriteOBJFile(const std::string &output_file) const {
#endif
}

void TriangleMesh::scale(float factor)
{
stl_scale(&(this->stl), factor);
stl_invalidate_shared_vertices(&this->stl);
}

void TriangleMesh::scale(const Pointf3 &versor)
{
float fversor[3];
fversor[0] = versor.x;
fversor[1] = versor.y;
fversor[2] = versor.z;
stl_scale_versor(&this->stl, fversor);
stl_invalidate_shared_vertices(&this->stl);
}

void TriangleMesh::translate(float x, float y, float z)
{
stl_translate_relative(&(this->stl), x, y, z);
stl_invalidate_shared_vertices(&this->stl);
}

void TriangleMesh::translate(Pointf3 vec) {
this->translate(
static_cast<float>(vec.x),
static_cast<float>(vec.y),
static_cast<float>(vec.z)
);
}

void TriangleMesh::rotate(float angle, const Axis &axis)
{
// admesh uses degrees
angle = Slic3r::Geometry::rad2deg(angle);

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)
{
this->rotate(angle, X);
}

void TriangleMesh::rotate_y(float angle)
{
this->rotate(angle, Y);
}

void TriangleMesh::rotate_z(float angle)
{
this->rotate(angle, Z);
}

void TriangleMesh::mirror(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);
}

void TriangleMesh::mirror_x()
{
this->mirror(X);
}

void TriangleMesh::mirror_y()
{
this->mirror(Y);
}

void TriangleMesh::mirror_z()
{
this->mirror(Z);
}

void TriangleMesh::align_to_origin()
{
this->translate(
-(this->stl.stats.min.x),
-(this->stl.stats.min.y),
-(this->stl.stats.min.z)
);
}

void TriangleMesh::center_around_origin()
{
this->align_to_origin();
this->translate(
-(this->stl.stats.size.x/2),
-(this->stl.stats.size.y/2),
-(this->stl.stats.size.z/2)
);
}

void TriangleMesh::rotate(double angle, Point* center)
{
this->rotate(angle, *center);
}
void TriangleMesh::rotate(double angle, const Point& center)
{
this->translate(-center.x, -center.y, 0);
stl_rotate_z(&(this->stl), (float)angle);
this->translate(+center.x, +center.y, 0);
}

void TriangleMesh::align_to_bed()
{
stl_translate_relative(&(this->stl), 0.0f, 0.0f, -this->stl.stats.min.z);
stl_invalidate_shared_vertices(&this->stl);
}

TriangleMesh TriangleMesh::get_transformed_mesh(TransformationMatrix const & trafo) const
{
TriangleMesh mesh;
Expand All @@ -296,12 +419,6 @@ void TriangleMesh::transform(TransformationMatrix const & trafo)
stl_invalidate_shared_vertices(&(this->stl));
}

void TriangleMesh::align_to_bed()
{
stl_translate_relative(&(this->stl), 0.0f, 0.0f, -this->stl.stats.min.z);
stl_invalidate_shared_vertices(&this->stl);
}

Pointf3s TriangleMesh::vertices()
{
Pointf3s tmp {};
Expand Down
34 changes: 32 additions & 2 deletions xs/src/libslic3r/TriangleMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,42 @@ class TriangleMesh
bool is_manifold() const;
void WriteOBJFile(const std::string &output_file) const;

TriangleMesh get_transformed_mesh(TransformationMatrix const & trafo) const;
/// Direct manipulators

void scale(float factor);
void scale(const Pointf3 &versor);

/// Translate the mesh to a new location.
void translate(float x, float y, float z);

/// Translate the mesh to a new location.
void translate(Pointf3 vec);


void rotate(float angle, const Axis &axis);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
void mirror(const Axis &axis);
void mirror_x();
void mirror_y();
void mirror_z();
void align_to_origin();
void center_around_origin();

/// Rotate angle around a specified point.
void rotate(double angle, const Point& center);
void rotate(double angle, Point* center);

void transform(TransformationMatrix const & trafo);

void align_to_bed();


/// Matrix manipulators
TriangleMesh get_transformed_mesh(TransformationMatrix const & trafo) const;
void transform(TransformationMatrix const & trafo);


TriangleMeshPtrs split() const;
TriangleMeshPtrs cut_by_grid(const Pointf &grid) const;
void merge(const TriangleMesh &mesh);
Expand Down
15 changes: 15 additions & 0 deletions xs/xsp/TriangleMesh.xsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@
void repair();
float volume();
void WriteOBJFile(std::string output_file);

void scale(float factor);
void scale_xyz(Pointf3* versor)
%code{% THIS->scale(*versor); %};
void translate(float x, float y, float z);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
void mirror_x();
void mirror_y();
void mirror_z();
void align_to_origin();
void rotate(double angle, Point* center);
void align_to_bed();

void transform(TransformationMatrix* trafo)
%code{% THIS->transform(*trafo); %};
Clone<TriangleMesh> get_transformed_mesh(TransformationMatrix* trafo)
%code{% RETVAL=THIS->get_transformed_mesh(*trafo); %};

TriangleMeshPtrs split();
TriangleMeshPtrs cut_by_grid(Pointf* grid)
%code{% RETVAL = THIS->cut_by_grid(*grid); %};
Expand Down

0 comments on commit ad7a169

Please sign in to comment.