From 7ae0a40a7c921a0b5d3426f9ab7ce2e86c395a9d Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 13 Sep 2023 21:46:20 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20scale=20for=20embossed=20SVG=20loaded=20f?= =?UTF-8?q?rom=203mf=20-=20fix=20matrix=20Fix=20storing=20=C2=A9=20message?= =?UTF-8?q?=20for=20texts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libslic3r/Format/3mf.cpp | 8 ++--- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 51 ++++++++++++++++++++++------ src/slic3r/GUI/Jobs/EmbossJob.cpp | 1 + src/slic3r/GUI/Plater.cpp | 6 ++-- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 026204ee57..a6377f67cf 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -3833,18 +3833,16 @@ Transform3d create_fix(const std::optional &prev, const ModelVolume } bool to_xml(std::stringstream &stream, const EmbossShape::SvgFile &svg, const ModelVolume &volume, mz_zip_archive &archive){ - assert(!svg.path_in_3mf.empty()); if (svg.path_in_3mf.empty()) - return false; // unwanted store .svg file into .3mf (protection of copyRight) + return true; // EmbossedText OR unwanted store .svg file into .3mf (protection of copyRight) if (!svg.path.empty()) stream << SVG_FILE_PATH_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(svg.path) << "\" "; stream << SVG_FILE_PATH_IN_3MF_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(svg.path_in_3mf) << "\" "; const std::string &file_data = *svg.file_data; - if (!mz_zip_writer_add_mem(&archive, svg.path_in_3mf.c_str(), (const void *) file_data.c_str(), file_data.size(), MZ_DEFAULT_COMPRESSION)) - return false; - return true; + return mz_zip_writer_add_mem(&archive, svg.path_in_3mf.c_str(), + (const void *) file_data.c_str(), file_data.size(), MZ_DEFAULT_COMPRESSION); } } // namespace diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 1e3ee93ab9..156ef18a60 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -1106,24 +1106,40 @@ void GLGizmoSVG::reset_volume() m_filename_preview.clear(); m_shape_warnings.clear(); // delete texture after finish imgui draw - wxGetApp().plater()->CallAfter([&]() { delete_texture(m_texture); }); + wxGetApp().plater()->CallAfter([&texture = m_texture]() { delete_texture(texture); }); } void GLGizmoSVG::calculate_scale() { - Transform3d to_world = m_parent.get_selection().get_first_volume()->world_matrix(); + // be carefull m_volume is not set yet + const Selection &selection = m_parent.get_selection(); + const GLVolume *gl_volume = selection.get_first_volume(); + if (gl_volume == nullptr) + return; + + Transform3d to_world = gl_volume->world_matrix(); + + const ModelVolume *volume_ptr = get_model_volume(*gl_volume, selection.get_model()->objects); + assert(volume_ptr != nullptr); + assert(volume_ptr->emboss_shape.has_value()); + // Fix for volume loaded from 3mf + if (volume_ptr != nullptr && + volume_ptr->emboss_shape.has_value()) { + const std::optional &fix_tr = volume_ptr->emboss_shape->fix_3mf_tr; + if (fix_tr.has_value()) + to_world = to_world * (fix_tr->inverse()); + } + auto to_world_linear = to_world.linear(); - auto calc = [&to_world_linear](const Vec3d &axe, std::optional& scale)->bool { - Vec3d axe_world = to_world_linear * axe; - double norm_sq = axe_world.squaredNorm(); + auto calc = [&to_world_linear](const Vec3d &axe, std::optional& scale) { + Vec3d axe_world = to_world_linear * axe; + double norm_sq = axe_world.squaredNorm(); if (is_approx(norm_sq, 1.)) { - if (scale.has_value()) - scale.reset(); - else - return false; + if (!scale.has_value()) + return; + scale.reset(); } else { scale = sqrt(norm_sq); } - return true; }; calc(Vec3d::UnitX(), m_scale_width); @@ -1622,7 +1638,22 @@ void GLGizmoSVG::draw_size() TransformationType type = m_volume->is_the_only_one_part() ? TransformationType::Instance_Relative_Independent : TransformationType::Local_Relative_Independent; + + const std::optional &fix_tr = m_volume->emboss_shape->fix_3mf_tr; + if (fix_tr.has_value()){ + GLVolume* gl_volume = selection.get_volume(*selection.get_volume_idxs().begin()); + gl_volume->set_volume_transformation(gl_volume->get_volume_transformation().get_matrix() * fix_tr->inverse()); + selection.setup_cache(); + } + selection.scale(*new_relative_scale, type); + + if (fix_tr.has_value()) { + GLVolume *gl_volume = selection.get_volume(*selection.get_volume_idxs().begin()); + gl_volume->set_volume_transformation(gl_volume->get_volume_transformation().get_matrix() * (*fix_tr)); + selection.setup_cache(); + } + m_parent.do_scale(L("Resize")); wxGetApp().obj_manipul()->set_dirty(); // should be the almost same diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 3a205e58f2..36544c26f6 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -269,6 +269,7 @@ auto was_canceled(const Job::Ctl &ctl, const DataBase &base){ void Slic3r::GUI::Emboss::DataBase::write(ModelVolume &volume) const{ volume.name = volume_name; volume.emboss_shape = shape; + volume.emboss_shape->fix_3mf_tr.reset(); } ///////////////// diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 3d1806c36e..ebdba2f255 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6779,8 +6779,10 @@ void publish(Model &model) { for (ModelVolume *volume : object->volumes) { if (!volume->emboss_shape.has_value()) continue; - SvgFile* svg = &volume->emboss_shape->svg_file; - + if (volume->text_configuration.has_value()) + continue; // text dosen't have svg path + + SvgFile* svg = &volume->emboss_shape->svg_file; if (svg->path_in_3mf.empty()) exist_new = true; svgfiles.push_back(svg);