Method Transformation::reset_rotation() modified to use SVD decomposition of transformation matrix and object manipulator reset button set to use it

This commit is contained in:
enricoturri1966 2023-02-02 12:40:28 +01:00
parent f2b986af57
commit d98fd64534
3 changed files with 24 additions and 7 deletions

View File

@ -720,6 +720,13 @@ void Transformation::reset()
} }
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
void Transformation::reset_rotation()
{
const Geometry::TransformationSVD svd(*this);
const Transform3d mirror = is_left_handed() ? Geometry::scale_transform({ -1.0, 1.0, 1.0 }) : Transform3d::Identity();
m_matrix = get_offset_matrix() * mirror * Transform3d(svd.v * svd.s * svd.v.transpose());
}
void Transformation::reset_scaling_factor() void Transformation::reset_scaling_factor()
{ {
const Geometry::TransformationSVD svd(*this); const Geometry::TransformationSVD svd(*this);

View File

@ -492,7 +492,7 @@ public:
void reset(); void reset();
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
void reset_offset() { set_offset(Vec3d::Zero()); } void reset_offset() { set_offset(Vec3d::Zero()); }
void reset_rotation() { set_rotation(Vec3d::Zero()); } void reset_rotation();
void reset_scaling_factor(); void reset_scaling_factor();
void reset_mirror() { set_mirror(Vec3d::Ones()); } void reset_mirror() { set_mirror(Vec3d::Ones()); }
void reset_skew(); void reset_skew();

View File

@ -448,14 +448,21 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
Selection& selection = canvas->get_selection(); Selection& selection = canvas->get_selection();
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
if (selection.is_single_volume_or_modifier()) if (selection.is_single_volume_or_modifier()) {
GLVolume* vol = const_cast<GLVolume*>(selection.get_first_volume());
Geometry::Transformation trafo = vol->get_volume_transformation();
trafo.reset_rotation();
vol->set_volume_transformation(trafo);
}
#else #else
if (selection.is_single_volume() || selection.is_single_modifier()) if (selection.is_single_volume() || selection.is_single_modifier())
#endif // ENABLE_WORLD_COORDINATE
const_cast<GLVolume*>(selection.get_first_volume())->set_volume_rotation(Vec3d::Zero()); const_cast<GLVolume*>(selection.get_first_volume())->set_volume_rotation(Vec3d::Zero());
#endif // ENABLE_WORLD_COORDINATE
else if (selection.is_single_full_instance()) { else if (selection.is_single_full_instance()) {
Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation();
trafo.reset_rotation();
for (unsigned int idx : selection.get_volume_idxs()) { for (unsigned int idx : selection.get_volume_idxs()) {
const_cast<GLVolume*>(selection.get_volume(idx))->set_instance_rotation(Vec3d::Zero()); const_cast<GLVolume*>(selection.get_volume(idx))->set_instance_transformation(trafo);
} }
} }
else else
@ -484,14 +491,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
Selection& selection = canvas->get_selection(); Selection& selection = canvas->get_selection();
if (selection.is_single_volume_or_modifier()) { if (selection.is_single_volume_or_modifier()) {
Geometry::Transformation trafo = selection.get_first_volume()->get_volume_transformation(); GLVolume* vol = const_cast<GLVolume*>(selection.get_first_volume());
Geometry::Transformation trafo = vol->get_volume_transformation();
trafo.reset_scaling_factor(); trafo.reset_scaling_factor();
const_cast<GLVolume*>(selection.get_first_volume())->set_volume_transformation(trafo); vol->set_volume_transformation(trafo);
} }
else if (selection.is_single_full_instance()) { else if (selection.is_single_full_instance()) {
Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation();
trafo.reset_scaling_factor(); trafo.reset_scaling_factor();
const_cast<GLVolume*>(selection.get_first_volume())->set_instance_transformation(trafo); for (unsigned int idx : selection.get_volume_idxs()) {
const_cast<GLVolume*>(selection.get_volume(idx))->set_instance_transformation(trafo);
}
} }
else else
return; return;