Follow-up of e3cc3be9ab - Fixes some extra use case where volumes were not rotated as rigid body

This commit is contained in:
enricoturri1966 2023-02-15 12:48:41 +01:00
parent 9510c4b4fa
commit a9ce511304
2 changed files with 27 additions and 8 deletions

View file

@ -1024,18 +1024,37 @@ void Selection::rotate(const Vec3d& rotation, TransformationType transformation_
}
else {
if (transformation_type.instance()) {
// ensure that the volume rotates as a rigid body
const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
const Transform3d cached_vol_rotation_matrix = vol_trafo.get_rotation_matrix();
if ((inst_trafo * vol_trafo).is_left_handed() && !rotation.normalized().isApprox(Vec3d::UnitX()))
const Geometry::Transformation world_trafo = inst_trafo * vol_trafo;
// ensure proper sign of rotation for mirrored objects
if (world_trafo.is_left_handed() && !rotation.normalized().isApprox(Vec3d::UnitX()))
rotation_matrix = rotation_matrix.inverse();
v.set_volume_transformation(vol_trafo.get_matrix() * cached_vol_rotation_matrix.inverse() * rotation_matrix * cached_vol_rotation_matrix);
// ensure that the volume rotates as a rigid body
const Geometry::TransformationSVD world_svd(world_trafo);
if (world_svd.anisotropic_scale) {
const Transform3d vol_scale_matrix = vol_trafo.get_scaling_factor_matrix();
rotation_matrix = vol_scale_matrix.inverse() * rotation_matrix * vol_scale_matrix;
}
const Transform3d vol_rotation_matrix = vol_trafo.get_rotation_matrix();
rotation_matrix = vol_rotation_matrix.inverse() * rotation_matrix * vol_rotation_matrix;
v.set_volume_transformation(vol_trafo.get_matrix() * rotation_matrix);
}
else {
if (transformation_type.local()) {
const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform();
if ((inst_trafo * vol_trafo).is_left_handed() && !rotation.normalized().isApprox(Vec3d::UnitX()))
const Geometry::Transformation world_trafo = inst_trafo * vol_trafo;
// ensure proper sign of rotation for mirrored objects
if (world_trafo.is_left_handed() && !rotation.normalized().isApprox(Vec3d::UnitX()))
rotation_matrix = rotation_matrix.inverse();
// ensure that the volume rotates as a rigid body
const Geometry::TransformationSVD svd(world_trafo);
if (svd.anisotropic_scale) {
const Transform3d vol_scale_matrix = vol_trafo.get_scaling_factor_matrix();
rotation_matrix = vol_scale_matrix.inverse() * rotation_matrix * vol_scale_matrix;
}
}
transform_volume_relative(v, volume_data, transformation_type, rotation_matrix, m_cache.dragging_center);
}