diff --git a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp index 0120a8a04..058bc409a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp @@ -228,13 +228,6 @@ bool GLGizmoText::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_posit const ModelInstance *mi = mo->instances[selection.get_instance_idx()]; const Camera & camera = wxGetApp().plater()->get_camera(); - // Precalculate transformations of individual meshes. - std::vector trafo_matrices; - for (const ModelVolume *mv : mo->volumes) { - if (mv->is_model_part()) { - trafo_matrices.emplace_back(mi->get_transformation().get_matrix() * mv->get_matrix()); - } - } if (action == SLAGizmoEventType::Moving) { if (shift_down && !alt_down && !control_down) { float angle = m_rotate_angle + 0.5 * (m_mouse_position - mouse_position).y(); @@ -265,6 +258,23 @@ bool GLGizmoText::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_posit if (m_is_modify) return true; + Plater *plater = wxGetApp().plater(); + if (!plater) + return true; + + ModelObject *model_object = selection.get_model()->objects[m_object_idx]; + if (m_preview_text_volume_id > 0) { + model_object->delete_volume(m_preview_text_volume_id); + plater->update(); + m_preview_text_volume_id = -1; + } + + // Precalculate transformations of individual meshes. + std::vector trafo_matrices; + for (const ModelVolume *mv : mo->volumes) { + if (mv->is_model_part()) { trafo_matrices.emplace_back(mi->get_transformation().get_matrix() * mv->get_matrix()); } + } + Vec3f normal = Vec3f::Zero(); Vec3f hit = Vec3f::Zero(); size_t facet = 0; @@ -275,9 +285,6 @@ bool GLGizmoText::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_posit // Cast a ray on all meshes, pick the closest hit and save it for the respective mesh for (int mesh_id = 0; mesh_id < int(trafo_matrices.size()); ++mesh_id) { - if (mesh_id == m_preview_text_volume_id) - continue; - MeshRaycaster mesh_raycaster = MeshRaycaster(mo->volumes[mesh_id]->mesh()); if (mesh_raycaster.unproject_on_mesh(mouse_position, trafo_matrices[mesh_id], camera, hit, normal, @@ -302,17 +309,6 @@ bool GLGizmoText::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_posit m_rr = {mouse_position, closest_hit_mesh_id, closest_hit, closest_normal}; - Plater *plater = wxGetApp().plater(); - if (!plater) - return true; - - ModelObject *model_object = selection.get_model()->objects[m_object_idx]; - if (m_preview_text_volume_id > 0) { - model_object->delete_volume(m_preview_text_volume_id); - plater->update(); - m_preview_text_volume_id = -1; - } - m_is_modify = true; generate_text_volume(false); plater->update(); @@ -978,20 +974,25 @@ bool GLGizmoText::update_text_positions(const std::vector& texts) TriangleMesh slice_meshs; int mesh_index = 0; + int volume_index = 0; for (int i = 0; i < mo->volumes.size(); ++i) { + // skip the editing text volume + if (m_is_modify && m_volume_idx == i) + continue; + ModelVolume *mv = mo->volumes[i]; if (mv->is_model_part()) { if (mesh_index == m_rr.mesh_id) { - TriangleMesh vol_mesh(mv->mesh()); - vol_mesh.transform(mv->get_matrix()); - slice_meshs = vol_mesh; - break; + volume_index = i; } + TriangleMesh vol_mesh(mv->mesh()); + vol_mesh.transform(mv->get_matrix()); + slice_meshs.merge(vol_mesh); mesh_index++; } } - ModelVolume* volume = mo->volumes[mesh_index]; + ModelVolume* volume = mo->volumes[volume_index]; Vec3d temp_position = m_mouse_position_world; Vec3d temp_normal = m_mouse_normal_world; @@ -1093,7 +1094,7 @@ bool GLGizmoText::update_text_positions(const std::vector& texts) // for debug //export_regions_to_svg(Point(m_mouse_position_world.x(), m_mouse_position_world.y()), temp_polys); - Polygons polys = temp_polys; + Polygons polys = union_(temp_polys); auto point_in_line_rectange = [](const Line &line, const Point &point, double& distance) { distance = abs((point.x() - line.a.x()) * (line.b.y() - line.a.y()) - (line.b.x() - line.a.x()) * (point.y() - line.a.y()));