Skip to content

Commit

Permalink
Fixed incorrect handling of 3rd party 3MFs in SLA mode (#6100 and oth…
Browse files Browse the repository at this point in the history
…ers)
  • Loading branch information
lukasmatena committed Mar 23, 2022
1 parent 92a40d3 commit dc14ae0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/libslic3r/SLAPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>();
const Transform3d& vol_trafo = m_model_object->volumes.front()->get_transformation().get_matrix();
const Transform3f& tr = (trafo() * vol_trafo).cast<float>();
for (sla::SupportPoint& suppt : spts) {
suppt.pos = tr * suppt.pos;
}
Expand All @@ -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<float>();
auto sc = m_model_object->instances.front()->get_scaling_factor().cast<float>();
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<float>();
const Vec3f sc = trans.get_scaling_factor().cast<float>();
for (sla::DrainHole &hl : pts) {
hl.pos = tr * hl.pos;
hl.normal = tr * hl.normal - tr.translation();
Expand Down
8 changes: 7 additions & 1 deletion src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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();
Expand All @@ -206,7 +207,7 @@ bool GLGizmoHollow::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, V
const Camera& camera = wxGetApp().plater()->get_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();
Expand Down
14 changes: 7 additions & 7 deletions src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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();
Expand All @@ -288,7 +288,7 @@ bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec
const Camera& camera = wxGetApp().plater()->get_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();
Expand Down Expand Up @@ -1110,7 +1110,7 @@ void GLGizmoSlaSupports::get_data_from_backend()
if (po->model_object()->id() == mo->id()) {
m_normal_cache.clear();
const std::vector<sla::SupportPoint>& points = po->get_support_points();
auto mat = po->trafo().inverse().cast<float>();
auto mat = (po->trafo() * po->model_object()->volumes.front()->get_transformation().get_matrix()).inverse().cast<float>();
for (unsigned int i=0; i<points.size();++i)
m_normal_cache.emplace_back(sla::SupportPoint(mat * points[i].pos, points[i].head_front_radius, points[i].is_new_island));

Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void HollowedMesh::on_update()
const TriangleMesh& backend_mesh = print_object->get_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;
Expand Down

0 comments on commit dc14ae0

Please sign in to comment.