From 567b3670613f0b695df8f783d973c53a4b6aae84 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 4 Jan 2019 16:48:41 +0100 Subject: [PATCH 1/6] Disabled the print bed mesh temporarily, bumped up the build version to alpha2, fixed one minor issue in G-code generator --- src/libslic3r/GCode.cpp | 2 +- src/libslic3r/Technologies.hpp | 2 +- version.inc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index b13c38742..1134b383f 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -791,7 +791,7 @@ void GCode::_do_export(Print &print, FILE *file) } } else { for (const std::string &start_gcode : print.config().start_filament_gcode.values) - _writeln(file, this->placeholder_parser_process("start_gcode", start_gcode, (unsigned int)(&start_gcode - &print.config().start_filament_gcode.values.front()))); + _writeln(file, this->placeholder_parser_process("start_filament_gcode", start_gcode, (unsigned int)(&start_gcode - &print.config().start_filament_gcode.values.front()))); } this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, true); print.throw_if_canceled(); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index dc6a2041c..bab7f3b73 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -45,7 +45,7 @@ // Improves navigation between sidebar fields #define ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION (1 && ENABLE_1_42_0_ALPHA2) // Adds print bed models to 3D scene -#define ENABLE_PRINT_BED_MODELS (1 && ENABLE_1_42_0_ALPHA2) +#define ENABLE_PRINT_BED_MODELS (0 && ENABLE_1_42_0_ALPHA2) #endif // _technologies_h_ diff --git a/version.inc b/version.inc index d648bc48b..3cdadcbb6 100644 --- a/version.inc +++ b/version.inc @@ -2,7 +2,7 @@ # (the version numbers are generated by the build script from the git current label) set(SLIC3R_FORK_NAME "Slic3r Prusa Edition") -set(SLIC3R_VERSION "1.42.0-alpha1") +set(SLIC3R_VERSION "1.42.0-alpha2") set(SLIC3R_BUILD "${SLIC3R_VERSION}+UNKNOWN") set(SLIC3R_BUILD_ID "${SLIC3R_BUILD_ID}") set(SLIC3R_RC_VERSION "1,42,0,0") From 7ef10e9663a0836115171add6f668164384a9782 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 4 Jan 2019 17:47:08 +0100 Subject: [PATCH 2/6] Fix of place to bed function This reverts commit 86e9cb604ac09318e503408947fbc5838448eddf and also contains a fix. --- src/slic3r/GUI/GLGizmo.cpp | 123 ++++++++++++++++++++++--------------- src/slic3r/GUI/GLGizmo.hpp | 2 + 2 files changed, 76 insertions(+), 49 deletions(-) diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 7de065065..5908044f9 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1519,13 +1519,15 @@ void GLGizmoFlatten::update_planes() } ch = ch.convex_hull_3d(); - - const Vec3d& bb_size = ch.bounding_box().size(); - double min_bb_face_area = std::min(bb_size(0) * bb_size(1), std::min(bb_size(0) * bb_size(2), bb_size(1) * bb_size(2))); - m_planes.clear(); + const Transform3d& inst_matrix = m_model_object->instances.front()->get_matrix(); - // Now we'll go through all the facets and append Points of facets sharing the same normal: + // Following constants are used for discarding too small polygons. + const float minimal_area = 20.f; // in square mm (world coordinates) + const float minimal_side = 1.f; // mm + + // Now we'll go through all the facets and append Points of facets sharing the same normal. + // This part is still performed in mesh coordinate system. const int num_of_facets = ch.stl.stats.number_of_facets; std::vector facet_queue(num_of_facets, 0); std::vector facet_visited(num_of_facets, false); @@ -1548,7 +1550,7 @@ void GLGizmoFlatten::update_planes() while (facet_queue_cnt > 0) { int facet_idx = facet_queue[-- facet_queue_cnt]; const stl_normal& this_normal = ch.stl.facet_start[facet_idx].normal; - if (std::abs(this_normal(0) - (*normal_ptr)(0)) < 0.001 && std::abs(this_normal(1) - (*normal_ptr)(1)) < 0.001 && std::abs(this_normal(2) - (*normal_ptr)(2)) < 0.001) { + if (this_normal.isApprox(*normal_ptr)) { stl_vertex* first_vertex = ch.stl.facet_start[facet_idx].vertex; for (int j=0; j<3; ++j) m_planes.back().vertices.emplace_back((double)first_vertex[j](0), (double)first_vertex[j](1), (double)first_vertex[j](2)); @@ -1561,63 +1563,74 @@ void GLGizmoFlatten::update_planes() } } } - m_planes.back().normal = Vec3d((double)(*normal_ptr)(0), (double)(*normal_ptr)(1), (double)(*normal_ptr)(2)); + m_planes.back().normal = normal_ptr->cast(); - // if this is a just a very small triangle, remove it to speed up further calculations (it would be rejected anyway): + // Now we'll transform all the points into world coordinates, so that the areas, angles and distances + // make real sense. + m_planes.back().vertices = transform(m_planes.back().vertices, inst_matrix); + + // if this is a just a very small triangle, remove it to speed up further calculations (it would be rejected later anyway): if (m_planes.back().vertices.size() == 3 && - ((m_planes.back().vertices[0] - m_planes.back().vertices[1]).norm() < 1.0 - || (m_planes.back().vertices[0] - m_planes.back().vertices[2]).norm() < 1.0 - || (m_planes.back().vertices[1] - m_planes.back().vertices[2]).norm() < 1.0)) + ((m_planes.back().vertices[0] - m_planes.back().vertices[1]).norm() < minimal_side + || (m_planes.back().vertices[0] - m_planes.back().vertices[2]).norm() < minimal_side + || (m_planes.back().vertices[1] - m_planes.back().vertices[2]).norm() < minimal_side)) m_planes.pop_back(); } - const float minimal_area = 0.01f * (float)min_bb_face_area; - // Now we'll go through all the polygons, transform the points into xy plane to process them: for (unsigned int polygon_id=0; polygon_id < m_planes.size(); ++polygon_id) { Pointf3s& polygon = m_planes[polygon_id].vertices; const Vec3d& normal = m_planes[polygon_id].normal; + // let's transform the normal accodring to the instance matrix: + Geometry::Transformation t(inst_matrix); + Vec3d scaling = t.get_scaling_factor(); + t.set_scaling_factor(Vec3d(1./(scaling(0)*scaling(0)), 1./(scaling(0)*scaling(0)), 1./(scaling(0)*scaling(0)))); + Vec3d normal_transformed = t.get_matrix() * normal; + // We are going to rotate about z and y to flatten the plane Eigen::Quaterniond q; Transform3d m = Transform3d::Identity(); - m.matrix().block(0, 0, 3, 3) = q.setFromTwoVectors(normal, Vec3d::UnitZ()).toRotationMatrix(); + m.matrix().block(0, 0, 3, 3) = q.setFromTwoVectors(normal_transformed, Vec3d::UnitZ()).toRotationMatrix(); polygon = transform(polygon, m); - polygon = Slic3r::Geometry::convex_hull(polygon); // To remove the inner points + // Now to remove the inner points. We'll misuse Geometry::convex_hull for that, but since + // it works in fixed point representation, we will rescale the polygon to avoid overflows. + // And yes, it is a nasty thing to do. Whoever has time is free to refactor. + Vec3d bb_size = BoundingBoxf3(polygon).size(); + float sf = std::min(1./bb_size(0), 1./bb_size(1)); + Transform3d tr = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), Vec3d(sf, sf, 1.f)); + polygon = transform(polygon, tr); + polygon = Slic3r::Geometry::convex_hull(polygon); + polygon = transform(polygon, tr.inverse()); - // We will calculate area of the polygons and discard ones that are too small - // The limit is more forgiving in case the normal is in the direction of the coordinate axes - float area_threshold = (std::abs(normal(0)) > 0.999f || std::abs(normal(1)) > 0.999f || std::abs(normal(2)) > 0.999f) ? minimal_area : 10.0f * minimal_area; + // Calculate area of the polygons and discard ones that are too small float& area = m_planes[polygon_id].area; area = 0.f; for (unsigned int i = 0; i < polygon.size(); i++) // Shoelace formula area += polygon[i](0)*polygon[i + 1 < polygon.size() ? i + 1 : 0](1) - polygon[i + 1 < polygon.size() ? i + 1 : 0](0)*polygon[i](1); area = 0.5f * std::abs(area); - if (area < area_threshold) { - m_planes.erase(m_planes.begin()+(polygon_id--)); - continue; - } - // We check the inner angles and discard polygons with angles smaller than the following threshold - const double angle_threshold = ::cos(10.0 * (double)PI / 180.0); bool discard = false; + if (area < minimal_area) + discard = true; + else { + // We also check the inner angles and discard polygons with angles smaller than the following threshold + const double angle_threshold = ::cos(10.0 * (double)PI / 180.0); - for (unsigned int i = 0; i < polygon.size(); ++i) - { - const Vec3d& prec = polygon[(i == 0) ? polygon.size() - 1 : i - 1]; - const Vec3d& curr = polygon[i]; - const Vec3d& next = polygon[(i == polygon.size() - 1) ? 0 : i + 1]; + for (unsigned int i = 0; i < polygon.size(); ++i) { + const Vec3d& prec = polygon[(i == 0) ? polygon.size() - 1 : i - 1]; + const Vec3d& curr = polygon[i]; + const Vec3d& next = polygon[(i == polygon.size() - 1) ? 0 : i + 1]; - if ((prec - curr).normalized().dot((next - curr).normalized()) > angle_threshold) - { - discard = true; - break; + if ((prec - curr).normalized().dot((next - curr).normalized()) > angle_threshold) { + discard = true; + break; + } } } - if (discard) - { + if (discard) { m_planes.erase(m_planes.begin() + (polygon_id--)); continue; } @@ -1667,13 +1680,17 @@ void GLGizmoFlatten::update_planes() polygon = points_out; // replace the coarse polygon with the smooth one that we just created } - // Transform back to 3D; - for (auto& b : polygon) { - b(2) += 0.1f; // raise a bit above the object surface to avoid flickering - } - m = m.inverse(); - polygon = transform(polygon, m); + // Raise a bit above the object surface to avoid flickering: + for (auto& b : polygon) + b(2) += 0.1f; + + // Transform back to 3D (and also back to mesh coordinates) + polygon = transform(polygon, inst_matrix.inverse() * m.inverse()); + + // make sure the points are in correct order: + if ( ((inst_matrix.inverse() * m.inverse()) * Vec3d(0., 0., 1.)).dot(normal) > 0.) + std::reverse(polygon.begin(),polygon.end()); } // We'll sort the planes by area and only keep the 254 largest ones (because of the picking pass limitations): @@ -1682,12 +1699,15 @@ void GLGizmoFlatten::update_planes() // Planes are finished - let's save what we calculated it from: m_volumes_matrices.clear(); - for (const ModelVolume* vol : m_model_object->volumes) + m_volumes_types.clear(); + for (const ModelVolume* vol : m_model_object->volumes) { m_volumes_matrices.push_back(vol->get_matrix()); + m_volumes_types.push_back(vol->type()); + } + m_first_instance_scale = m_model_object->instances.front()->get_scaling_factor(); } -// Check if the bounding boxes of each volume's convex hull is the same as before -// and that scaling and rotation has not changed. In that case we don't have to recalculate it. + bool GLGizmoFlatten::is_plane_update_necessary() const { if (m_state != On || !m_model_object || m_model_object->instances.empty()) @@ -1696,8 +1716,13 @@ bool GLGizmoFlatten::is_plane_update_necessary() const if (m_model_object->volumes.size() != m_volumes_matrices.size()) return true; + // We want to recalculate when the scale changes - some planes could (dis)appear. + if (! m_model_object->instances.front()->get_scaling_factor().isApprox(m_first_instance_scale)) + return true; + for (unsigned int i=0; i < m_model_object->volumes.size(); ++i) - if (! m_model_object->volumes[i]->get_matrix().isApprox(m_volumes_matrices[i])) + if (! m_model_object->volumes[i]->get_matrix().isApprox(m_volumes_matrices[i]) + || m_model_object->volumes[i]->type() != m_volumes_types[i]) return true; return false; @@ -1723,7 +1748,7 @@ GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent) if (m_quadric != nullptr) // using GLU_FILL does not work when the instance's transformation // contains mirroring (normals are reverted) - ::gluQuadricDrawStyle(m_quadric, GLU_SILHOUETTE); + ::gluQuadricDrawStyle(m_quadric, GLU_FILL); #endif // ENABLE_SLA_SUPPORT_GIZMO_MOD } @@ -1895,8 +1920,8 @@ void GLGizmoSlaSupports::render_grabbers(const GLCanvas3D::Selection& selection, ::glPushMatrix(); ::glLoadIdentity(); ::glTranslated(grabber_world_position(0), grabber_world_position(1), grabber_world_position(2) + z_shift); - ::gluQuadricDrawStyle(m_quadric, GLU_SILHOUETTE); - ::gluSphere(m_quadric, 0.75, 64, 36); + const float diameter = 0.8f; + ::gluSphere(m_quadric, diameter/2.f, 64, 36); ::glPopMatrix(); } @@ -1945,7 +1970,7 @@ void GLGizmoSlaSupports::render_grabbers(bool picking) const GLUquadricObj *quadric; quadric = ::gluNewQuadric(); ::gluQuadricDrawStyle(quadric, GLU_FILL ); - ::gluSphere( quadric , 0.75f, 64 , 32 ); + ::gluSphere( quadric , 0.4, 64 , 32 ); ::gluDeleteQuadric(quadric); ::glPopMatrix(); if (!picking) diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 2588080b2..d10efa966 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -403,6 +403,8 @@ private: // This holds information to decide whether recalculation is necessary: std::vector m_volumes_matrices; + std::vector m_volumes_types; + Vec3d m_first_instance_scale; std::vector m_planes; mutable Vec3d m_starting_center; From 60926e7be3673916c8fbadc08653d7adcde0321b Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 4 Jan 2019 21:34:25 +0100 Subject: [PATCH 3/6] Place to bed now rotates all instances the same way, regardless of which one was selected --- src/slic3r/GUI/GLCanvas3D.cpp | 9 +++++---- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 91b4a2855..2d57d5eb7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1700,8 +1700,10 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal) } #if !DISABLE_INSTANCES_SYNCH + // we want to synchronize z-rotation as well, otherwise the flattening behaves funny + // when applied on one of several identical instances if (m_mode == Instance) - _synchronize_unselected_instances(); + _synchronize_unselected_instances(true); #endif // !DISABLE_INSTANCES_SYNCH m_bounding_box_dirty = true; @@ -1911,7 +1913,6 @@ void GLCanvas3D::Selection::erase() { items.emplace_back(ItemType::itInstance, i.first, i.second); } - wxGetApp().obj_list()->delete_from_model_and_list(items); } else if (is_mixed()) @@ -2573,7 +2574,7 @@ void GLCanvas3D::Selection::_render_sidebar_size_hint(Axis axis, double length) } #endif // ENABLE_SIDEBAR_VISUAL_HINTS -void GLCanvas3D::Selection::_synchronize_unselected_instances() +void GLCanvas3D::Selection::_synchronize_unselected_instances(bool including_z) { std::set done; // prevent processing volumes twice done.insert(m_list.begin(), m_list.end()); @@ -2606,7 +2607,7 @@ void GLCanvas3D::Selection::_synchronize_unselected_instances() if ((v->object_idx() != object_idx) || (v->instance_idx() == instance_idx)) continue; - v->set_instance_rotation(Vec3d(rotation(0), rotation(1), v->get_instance_rotation()(2))); + v->set_instance_rotation(Vec3d(rotation(0), rotation(1), including_z ? rotation(2) : v->get_instance_rotation()(2))); v->set_instance_scaling_factor(scaling_factor); v->set_instance_mirror(mirror); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index c2f2074c1..63a4edbef 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -597,7 +597,7 @@ public: void _render_sidebar_scale_hint(Axis axis) const; void _render_sidebar_size_hint(Axis axis, double length) const; #endif // ENABLE_SIDEBAR_VISUAL_HINTS - void _synchronize_unselected_instances(); + void _synchronize_unselected_instances(bool including_z = false); void _synchronize_unselected_volumes(); #if ENABLE_ENSURE_ON_BED_WHILE_SCALING void _ensure_on_bed(); From bdf4d5f41fcdd090422ba2f3d2d500cf89ffd580 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 4 Jan 2019 21:36:58 +0100 Subject: [PATCH 4/6] Fixed a crash when deleting several instances of one object --- src/slic3r/GUI/GLCanvas3D.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 2d57d5eb7..f81bec3b8 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1894,8 +1894,6 @@ void GLCanvas3D::Selection::erase() } wxGetApp().obj_list()->delete_from_model_and_list(items); } - else if (is_single_full_instance()) - wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx()); else if (is_multiple_full_instance()) { std::set> instances_idxs; @@ -1915,6 +1913,8 @@ void GLCanvas3D::Selection::erase() } wxGetApp().obj_list()->delete_from_model_and_list(items); } + else if (is_single_full_instance()) + wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx()); else if (is_mixed()) { std::set items_set; From a2bc7e166024a80a221d71043dfe9ccd092b659e Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 7 Jan 2019 09:15:31 +0100 Subject: [PATCH 5/6] Fix of #1596 --- src/slic3r/GUI/GLCanvas3D.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f81bec3b8..8cd80ad7d 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4952,7 +4952,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } m_mouse.set_start_position_2D_as_invalid(); - m_mouse.set_start_position_3D_as_invalid(); #endif } else if (evt.Leaving()) @@ -4964,6 +4963,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (evt.LeftDClick() && (toolbar_contains_mouse != -1)) { m_toolbar_action_running = true; + m_mouse.set_start_position_3D_as_invalid(); m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this); } else if (evt.LeftDClick() && (m_gizmos.get_current_type() != Gizmos::Undefined)) @@ -5041,6 +5041,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (toolbar_contains_mouse != -1) { m_toolbar_action_running = true; + m_mouse.set_start_position_3D_as_invalid(); m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this); m_mouse.left_down = false; } From 3bd2db8ba6bc8dcdd96cba6cf51c5882fdca6121 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 7 Jan 2019 09:37:51 +0100 Subject: [PATCH 6/6] Fix of #1598, #1601, #1604, #1612 The text fields were not causing config value updates, broken with 8d1b854acbbb1686d92cd38a696dab2a97dec00d Replaced all wxString.ToStdString() with wxString.ToUTF8().data() to be sure that the strings are correctly converted to UTF8. --- src/slic3r/GUI/Field.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 81a90cfbd..928a6236e 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -188,7 +188,7 @@ void Field::get_value_by_opt_type(wxString& str) } } - m_value = str.ToUTF8().data(); + m_value = std::string(str.ToUTF8().data()); break; } default: break;