Fix scale for embossed SVG loaded from 3mf - fix matrix

Fix storing © message for texts
This commit is contained in:
Filip Sykala - NTB T15p 2023-09-13 21:46:20 +02:00
parent 03d61932a7
commit 7ae0a40a7c
4 changed files with 49 additions and 17 deletions

View File

@ -3833,18 +3833,16 @@ Transform3d create_fix(const std::optional<Transform3d> &prev, const ModelVolume
} }
bool to_xml(std::stringstream &stream, const EmbossShape::SvgFile &svg, const ModelVolume &volume, mz_zip_archive &archive){ 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()) 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()) if (!svg.path.empty())
stream << SVG_FILE_PATH_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(svg.path) << "\" "; 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) << "\" "; 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; 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 mz_zip_writer_add_mem(&archive, svg.path_in_3mf.c_str(),
return false; (const void *) file_data.c_str(), file_data.size(), MZ_DEFAULT_COMPRESSION);
return true;
} }
} // namespace } // namespace

View File

@ -1106,24 +1106,40 @@ void GLGizmoSVG::reset_volume()
m_filename_preview.clear(); m_filename_preview.clear();
m_shape_warnings.clear(); m_shape_warnings.clear();
// delete texture after finish imgui draw // 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() { 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<Transform3d> &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 to_world_linear = to_world.linear();
auto calc = [&to_world_linear](const Vec3d &axe, std::optional<float>& scale)->bool { auto calc = [&to_world_linear](const Vec3d &axe, std::optional<float>& scale) {
Vec3d axe_world = to_world_linear * axe; Vec3d axe_world = to_world_linear * axe;
double norm_sq = axe_world.squaredNorm(); double norm_sq = axe_world.squaredNorm();
if (is_approx(norm_sq, 1.)) { if (is_approx(norm_sq, 1.)) {
if (scale.has_value()) if (!scale.has_value())
scale.reset(); return;
else scale.reset();
return false;
} else { } else {
scale = sqrt(norm_sq); scale = sqrt(norm_sq);
} }
return true;
}; };
calc(Vec3d::UnitX(), m_scale_width); calc(Vec3d::UnitX(), m_scale_width);
@ -1622,7 +1638,22 @@ void GLGizmoSVG::draw_size()
TransformationType type = m_volume->is_the_only_one_part() ? TransformationType type = m_volume->is_the_only_one_part() ?
TransformationType::Instance_Relative_Independent : TransformationType::Instance_Relative_Independent :
TransformationType::Local_Relative_Independent; TransformationType::Local_Relative_Independent;
const std::optional<Transform3d> &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); 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")); m_parent.do_scale(L("Resize"));
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
// should be the almost same // should be the almost same

View File

@ -269,6 +269,7 @@ auto was_canceled(const Job::Ctl &ctl, const DataBase &base){
void Slic3r::GUI::Emboss::DataBase::write(ModelVolume &volume) const{ void Slic3r::GUI::Emboss::DataBase::write(ModelVolume &volume) const{
volume.name = volume_name; volume.name = volume_name;
volume.emboss_shape = shape; volume.emboss_shape = shape;
volume.emboss_shape->fix_3mf_tr.reset();
} }
///////////////// /////////////////

View File

@ -6779,8 +6779,10 @@ void publish(Model &model) {
for (ModelVolume *volume : object->volumes) { for (ModelVolume *volume : object->volumes) {
if (!volume->emboss_shape.has_value()) if (!volume->emboss_shape.has_value())
continue; 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()) if (svg->path_in_3mf.empty())
exist_new = true; exist_new = true;
svgfiles.push_back(svg); svgfiles.push_back(svg);