Tech ENABLE_WORLD_COORDINATE - Fixed scaling using the Part Manipulation fields in world coordinates for volumes

This commit is contained in:
enricoturri1966 2021-10-21 14:05:56 +02:00
parent a31594b562
commit 47994f33ba
2 changed files with 20 additions and 6 deletions

View File

@ -626,13 +626,12 @@ void ObjectManipulation::update_settings_value(const Selection& selection)
const Vec3d& offset = trafo.get_offset();
const Vec3d& rotation = trafo.get_rotation();
#endif // ENABLE_WORLD_COORDINATE_VOLUMES_LOCAL_OFFSET
const Vec3d& scaling_factor = trafo.get_scaling_factor();
// const Vec3d& mirror = trafo.get_mirror();
m_new_position = offset;
m_new_rotation = Vec3d::Zero();
m_new_scale = scaling_factor * 100.0;
m_new_size = volume->bounding_box().size().cwiseProduct(scaling_factor);
m_new_size = volume->transformed_convex_hull_bounding_box(trafo.get_matrix()).size();
m_new_scale = m_new_size.cwiseProduct(volume->transformed_convex_hull_bounding_box(volume->get_instance_transformation().get_matrix() * volume->get_volume_transformation().get_matrix(false, false, true, false)).size().cwiseInverse()) * 100.0;
}
else {
#endif // ENABLE_WORLD_COORDINATE
@ -1016,12 +1015,27 @@ void ObjectManipulation::change_size_value(int axis, double value)
void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const
{
Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
#if !ENABLE_WORLD_COORDINATE
Vec3d scaling_factor = scale;
#endif // !ENABLE_WORLD_COORDINATE
#if ENABLE_WORLD_COORDINATE
TransformationType transformation_type;
if (!m_world_coordinates)
transformation_type.set_local();
bool uniform_scale = m_uniform_scale || selection.requires_uniform_scale();
Vec3d scaling_factor = uniform_scale ? scale(axis) * Vec3d::Ones() : scale;
if (!uniform_scale && m_world_coordinates) {
if (selection.is_single_full_instance())
scaling_factor = (Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse() * scaling_factor).cwiseAbs();
else if (selection.is_single_volume() || selection.is_single_modifier()) {
const Transform3d mi = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse();
const Transform3d mv = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_rotation()).inverse();
scaling_factor = (mv * mi * scaling_factor).cwiseAbs();
}
}
#else
TransformationType transformation_type(TransformationType::World_Relative_Joint);
if (selection.is_single_full_instance()) {
@ -1029,10 +1043,10 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const
if (! m_world_coordinates)
transformation_type.set_local();
}
#endif // ENABLE_WORLD_COORDINATE
if (m_uniform_scale || selection.requires_uniform_scale())
scaling_factor = scale(axis) * Vec3d::Ones();
#endif // ENABLE_WORLD_COORDINATE
selection.start_dragging();
selection.scale(scaling_factor, transformation_type);

View File

@ -609,7 +609,7 @@ bool Selection::requires_uniform_scale() const
else if (is_single_full_instance() && wxGetApp().obj_manipul()->get_world_coordinates())
return !Geometry::is_rotation_ninety_degrees(get_volume(*m_list.begin())->get_instance_rotation());
return false;
return true;
#else
if (is_single_full_instance() || is_single_modifier() || is_single_volume())
return false;
@ -688,7 +688,7 @@ const BoundingBoxf3& Selection::get_scaled_instance_bounding_box() const
const GLVolume& volume = *(*m_volumes)[i];
if (volume.is_modifier)
continue;
Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix();
Transform3d trafo = volume.get_instance_transformation().get_matrix() * volume.get_volume_transformation().get_matrix();
trafo.translation().z() += volume.get_sla_shift_z();
(*bbox)->merge(volume.transformed_convex_hull_bounding_box(trafo));
}