Lay flat - rotation is now done in one go directly about the necessary axis

This commit is contained in:
Lukas Matena 2018-08-21 15:40:11 +02:00
parent d197a5149a
commit 86b67bbd42
8 changed files with 62 additions and 27 deletions

View file

@ -725,7 +725,7 @@ void ModelObject::scale(const Pointf3 &versor)
this->invalidate_bounding_box();
}
void ModelObject::rotate(float angle, const Axis &axis)
void ModelObject::rotate(float angle, const Pointf3& axis)
{
for (ModelVolume *v : this->volumes)
{

View file

@ -120,7 +120,7 @@ public:
void translate(const Vectorf3 &vector) { this->translate(vector.x, vector.y, vector.z); }
void translate(coordf_t x, coordf_t y, coordf_t z);
void scale(const Pointf3 &versor);
void rotate(float angle, const Axis &axis);
void rotate(float angle, const Pointf3& axis);
void transform(const float* matrix3x4);
void mirror(const Axis &axis);
size_t materials_count() const;

View file

@ -324,6 +324,17 @@ void TriangleMesh::translate(float x, float y, float z)
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate(float angle, Pointf3 axis)
{
if (angle == 0.f)
return;
axis = normalize(axis);
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
m.rotate(Eigen::AngleAxisf(angle, Eigen::Vector3f(axis.x, axis.y, axis.z)));
stl_transform(&stl, (float*)m.data());
}
void TriangleMesh::rotate(float angle, const Axis &axis)
{
if (angle == 0.f)

View file

@ -40,6 +40,7 @@ public:
void scale(const Pointf3 &versor);
void translate(float x, float y, float z);
void rotate(float angle, const Axis &axis);
void rotate(float angle, Pointf3 axis);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);

View file

@ -2805,9 +2805,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// Rotate the object so the normal points downward:
Pointf3 normal = m_gizmos.get_flattening_normal();
if (normal.x != 0.f || normal.y != 0.f || normal.z != 0.f) {
float angle_z = -atan2(normal.y, normal.x);
float angle_y = M_PI - atan2(normal.x*cos(angle_z)-normal.y*sin(angle_z), normal.z);
m_on_gizmo_rotate_callback.call((double)angle_z, (double)angle_y);
Pointf3 axis = normal.z > 0.999f ? Pointf3(1, 0, 0) : cross(normal, Pointf3(0.f, 0.f, -1.f));
float angle = -acos(-normal.z);
m_on_gizmo_rotate_callback.call(angle, axis.x, axis.y, axis.z);
}
}
}
@ -3093,7 +3093,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
}
case Gizmos::Rotate:
{
m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z(), 0.);
m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z());
break;
}
default:

View file

@ -706,12 +706,14 @@ void GLGizmoFlatten::update_planes()
}
polygon = Slic3r::Geometry::convex_hull(polygon); // To remove the inner points
// Calculate area of the polygon and discard ones that are too small
// We will calculate area of the polygon and discard ones that are too small
// The limit is more forgiving in case the normal is in the direction of the coordinate axes
const float minimal_area = (std::abs(normal.x) > 0.999f || std::abs(normal.y) > 0.999f || std::abs(normal.z) > 0.999f) ? 1.f : 20.f;
float area = 0.f;
for (unsigned int i = 0; i < polygon.size(); i++) // Shoelace formula
area += polygon[i].x*polygon[i+1 < polygon.size() ? i+1 : 0 ].y - polygon[i+1 < polygon.size() ? i+1 : 0].x*polygon[i].y;
area = std::abs(area/2.f);
if (area < 20.f) {
if (area < minimal_area) {
m_planes.erase(m_planes.begin()+(polygon_id--));
continue;
}

View file

@ -301,7 +301,8 @@ ModelMaterial::attributes()
void translate(double x, double y, double z);
void scale_xyz(Pointf3* versor)
%code{% THIS->scale(*versor); %};
void rotate(float angle, Axis axis);
void rotate(float angle, Pointf3* axis)
%code{% THIS->rotate(angle, *axis); %};
void mirror(Axis axis);
Model* cut(double z)