From dc14ae07a6e9a5b700504c5b114c205525f5efeb Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 28 Feb 2022 10:53:39 +0100 Subject: [PATCH] Fixed incorrect handling of 3rd party 3MFs in SLA mode (#6100 and others) --- src/libslic3r/SLAPrint.cpp | 9 ++++++--- src/slic3r/GUI/GLCanvas3D.cpp | 8 +++++++- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 9 +++++---- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 14 +++++++------- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 55acd384650..408ad7e36c9 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -1173,7 +1173,8 @@ sla::SupportPoints SLAPrintObject::transformed_support_points() const { assert(m_model_object != nullptr); auto spts = m_model_object->sla_support_points; - auto tr = trafo().cast(); + const Transform3d& vol_trafo = m_model_object->volumes.front()->get_transformation().get_matrix(); + const Transform3f& tr = (trafo() * vol_trafo).cast(); for (sla::SupportPoint& suppt : spts) { suppt.pos = tr * suppt.pos; } @@ -1185,8 +1186,10 @@ sla::DrainHoles SLAPrintObject::transformed_drainhole_points() const { assert(m_model_object != nullptr); auto pts = m_model_object->sla_drain_holes; - auto tr = trafo().cast(); - auto sc = m_model_object->instances.front()->get_scaling_factor().cast(); + const Transform3d& vol_trafo = m_model_object->volumes.front()->get_transformation().get_matrix(); + const Geometry::Transformation trans(trafo() * vol_trafo); + const Transform3f& tr = trans.get_matrix().cast(); + const Vec3f sc = trans.get_scaling_factor().cast(); for (sla::DrainHole &hl : pts) { hl.pos = tr * hl.pos; hl.normal = tr * hl.normal - tr.translation(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b0026735d14..1a102c5d960 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1955,7 +1955,13 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re if (state.step[istep].state == PrintStateBase::DONE) { TriangleMesh mesh = print_object->get_mesh(slaposDrillHoles); assert(! mesh.empty()); - mesh.transform(sla_print->sla_trafo(*m_model->objects[volume.object_idx()]).inverse()); + + // sla_trafo does not contain volume trafo. To get a mesh to create + // a new volume from, we have to apply vol trafo inverse separately. + const ModelObject& mo = *m_model->objects[volume.object_idx()]; + Transform3d trafo = sla_print->sla_trafo(mo) + * mo.volumes.front()->get_transformation().get_matrix(); + mesh.transform(trafo.inverse()); #if ENABLE_SMOOTH_NORMALS volume.indexed_vertex_array.load_mesh(mesh, true); #else diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 8070cf27b2f..7c985b2375e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -107,8 +107,9 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); - const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); + Geometry::Transformation trafo = vol->get_instance_transformation() * vol->get_volume_transformation(); + const Transform3d& instance_scaling_matrix_inverse = trafo.get_matrix(true, true, false, true).inverse(); + const Transform3d& instance_matrix = trafo.get_matrix(); glsafe(::glPushMatrix()); glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); @@ -187,7 +188,7 @@ bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const auto sel_info = m_c->selection_info(); int active_inst = m_c->selection_info()->get_active_instance(); const ModelInstance* mi = sel_info->model_object()->instances[active_inst]; - const Transform3d& trafo = mi->get_transformation().get_matrix(); + const Transform3d& trafo = mi->get_transformation().get_matrix() * sel_info->model_object()->volumes.front()->get_matrix(); Vec3d transformed_point = trafo * point; transformed_point(2) += sel_info->get_sla_shift(); @@ -206,7 +207,7 @@ bool GLGizmoHollow::unproject_on_mesh(const Vec2d& mouse_pos, std::pairget_camera(); const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); - Geometry::Transformation trafo = volume->get_instance_transformation(); + Geometry::Transformation trafo = volume->get_instance_transformation() * volume->get_volume_transformation(); trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_c->selection_info()->get_sla_shift())); double clp_dist = m_c->object_clipper()->get_position(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index ab35cec9be6..e3044dfc76b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -129,10 +129,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) }); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); - const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); - float z_shift = m_c->selection_info()->get_sla_shift(); - + Geometry::Transformation transformation(vol->get_instance_transformation().get_matrix() * vol->get_volume_transformation().get_matrix()); + const Transform3d& instance_scaling_matrix_inverse = transformation.get_matrix(true, true, false, true).inverse(); + const Transform3d& instance_matrix = transformation.get_matrix(); + const float z_shift = m_c->selection_info()->get_sla_shift(); glsafe(::glPushMatrix()); glsafe(::glTranslated(0.0, 0.0, z_shift)); glsafe(::glMultMatrixd(instance_matrix.data())); @@ -269,7 +269,7 @@ bool GLGizmoSlaSupports::is_mesh_point_clipped(const Vec3d& point) const auto sel_info = m_c->selection_info(); int active_inst = m_c->selection_info()->get_active_instance(); const ModelInstance* mi = sel_info->model_object()->instances[active_inst]; - const Transform3d& trafo = mi->get_transformation().get_matrix(); + const Transform3d& trafo = mi->get_transformation().get_matrix() * sel_info->model_object()->volumes.front()->get_matrix(); Vec3d transformed_point = trafo * point; transformed_point(2) += sel_info->get_sla_shift(); @@ -288,7 +288,7 @@ bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pairget_camera(); const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); - Geometry::Transformation trafo = volume->get_instance_transformation(); + Geometry::Transformation trafo = volume->get_instance_transformation() * volume->get_volume_transformation(); trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_c->selection_info()->get_sla_shift())); double clp_dist = m_c->object_clipper()->get_position(); @@ -1110,7 +1110,7 @@ void GLGizmoSlaSupports::get_data_from_backend() if (po->model_object()->id() == mo->id()) { m_normal_cache.clear(); const std::vector& points = po->get_support_points(); - auto mat = po->trafo().inverse().cast(); + auto mat = (po->trafo() * po->model_object()->volumes.front()->get_transformation().get_matrix()).inverse().cast(); for (unsigned int i=0; iget_mesh_to_slice(); if (! backend_mesh.empty()) { m_hollowed_mesh_transformed.reset(new TriangleMesh(backend_mesh)); - Transform3d trafo_inv = canvas->sla_print()->sla_trafo(*mo).inverse(); + Transform3d trafo_inv = (canvas->sla_print()->sla_trafo(*mo) * print_object->model_object()->volumes.front()->get_transformation().get_matrix()).inverse(); m_hollowed_mesh_transformed->transform(trafo_inv); m_drainholes = print_object->model_object()->sla_drain_holes; m_old_hollowing_timestamp = timestamp;