Fixed incorrect handling of 3rd party 3MFs in SLA mode (#6100 and others)

This commit is contained in:
Lukas Matena 2022-02-28 10:53:39 +01:00
parent 92a40d32ff
commit dc14ae07a6
5 changed files with 26 additions and 16 deletions

View File

@ -1173,7 +1173,8 @@ sla::SupportPoints SLAPrintObject::transformed_support_points() const
{ {
assert(m_model_object != nullptr); assert(m_model_object != nullptr);
auto spts = m_model_object->sla_support_points; 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) { for (sla::SupportPoint& suppt : spts) {
suppt.pos = tr * suppt.pos; suppt.pos = tr * suppt.pos;
} }
@ -1185,8 +1186,10 @@ sla::DrainHoles SLAPrintObject::transformed_drainhole_points() const
{ {
assert(m_model_object != nullptr); assert(m_model_object != nullptr);
auto pts = m_model_object->sla_drain_holes; auto pts = m_model_object->sla_drain_holes;
auto tr = trafo().cast<float>(); const Transform3d& vol_trafo = m_model_object->volumes.front()->get_transformation().get_matrix();
auto sc = m_model_object->instances.front()->get_scaling_factor().cast<float>(); 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) { for (sla::DrainHole &hl : pts) {
hl.pos = tr * hl.pos; hl.pos = tr * hl.pos;
hl.normal = tr * hl.normal - tr.translation(); hl.normal = tr * hl.normal - tr.translation();

View File

@ -1955,7 +1955,13 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
if (state.step[istep].state == PrintStateBase::DONE) { if (state.step[istep].state == PrintStateBase::DONE) {
TriangleMesh mesh = print_object->get_mesh(slaposDrillHoles); TriangleMesh mesh = print_object->get_mesh(slaposDrillHoles);
assert(! mesh.empty()); 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 #if ENABLE_SMOOTH_NORMALS
volume.indexed_vertex_array.load_mesh(mesh, true); volume.indexed_vertex_array.load_mesh(mesh, true);
#else #else

View File

@ -107,8 +107,9 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); ScopeGuard guard([shader]() { if (shader) shader->stop_using(); });
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); 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(); Geometry::Transformation trafo = vol->get_instance_transformation() * vol->get_volume_transformation();
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); const Transform3d& instance_scaling_matrix_inverse = trafo.get_matrix(true, true, false, true).inverse();
const Transform3d& instance_matrix = trafo.get_matrix();
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); 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(); auto sel_info = m_c->selection_info();
int active_inst = m_c->selection_info()->get_active_instance(); int active_inst = m_c->selection_info()->get_active_instance();
const ModelInstance* mi = sel_info->model_object()->instances[active_inst]; 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; Vec3d transformed_point = trafo * point;
transformed_point(2) += sel_info->get_sla_shift(); transformed_point(2) += sel_info->get_sla_shift();
@ -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 Camera& camera = wxGetApp().plater()->get_camera();
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); 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())); 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(); double clp_dist = m_c->object_clipper()->get_position();

View File

@ -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 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(); Geometry::Transformation transformation(vol->get_instance_transformation().get_matrix() * vol->get_volume_transformation().get_matrix());
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); const Transform3d& instance_scaling_matrix_inverse = transformation.get_matrix(true, true, false, true).inverse();
float z_shift = m_c->selection_info()->get_sla_shift(); const Transform3d& instance_matrix = transformation.get_matrix();
const float z_shift = m_c->selection_info()->get_sla_shift();
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, z_shift)); glsafe(::glTranslated(0.0, 0.0, z_shift));
glsafe(::glMultMatrixd(instance_matrix.data())); 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(); auto sel_info = m_c->selection_info();
int active_inst = m_c->selection_info()->get_active_instance(); int active_inst = m_c->selection_info()->get_active_instance();
const ModelInstance* mi = sel_info->model_object()->instances[active_inst]; 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; Vec3d transformed_point = trafo * point;
transformed_point(2) += sel_info->get_sla_shift(); transformed_point(2) += sel_info->get_sla_shift();
@ -288,7 +288,7 @@ bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); 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())); 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(); 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()) { if (po->model_object()->id() == mo->id()) {
m_normal_cache.clear(); m_normal_cache.clear();
const std::vector<sla::SupportPoint>& points = po->get_support_points(); 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) 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)); m_normal_cache.emplace_back(sla::SupportPoint(mat * points[i].pos, points[i].head_front_radius, points[i].is_new_island));

View File

@ -265,7 +265,7 @@ void HollowedMesh::on_update()
const TriangleMesh& backend_mesh = print_object->get_mesh_to_slice(); const TriangleMesh& backend_mesh = print_object->get_mesh_to_slice();
if (! backend_mesh.empty()) { if (! backend_mesh.empty()) {
m_hollowed_mesh_transformed.reset(new TriangleMesh(backend_mesh)); 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_hollowed_mesh_transformed->transform(trafo_inv);
m_drainholes = print_object->model_object()->sla_drain_holes; m_drainholes = print_object->model_object()->sla_drain_holes;
m_old_hollowing_timestamp = timestamp; m_old_hollowing_timestamp = timestamp;