Tech ENABLE_WORLD_COORDINATE - Fixed constrained non-uniform scaling in world coordinates for rotated instances

Fixed conflicts during rebase with master
This commit is contained in:
enricoturri1966 2021-10-21 08:23:13 +02:00
parent d5a02e617a
commit d7753fc476
2 changed files with 25 additions and 4 deletions

View File

@ -616,11 +616,28 @@ void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
{ {
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
double ratio = calc_ratio(data); double ratio = calc_ratio(data);
if (ratio > 0.0) {
Vec3d curr_scale = m_scale;
Vec3d starting_scale = m_starting.scale;
const Selection& selection = m_parent.get_selection();
const bool world_coordinates = wxGetApp().obj_manipul()->get_world_coordinates();
if (selection.is_single_full_instance() && world_coordinates) {
const Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation());
curr_scale = (m * curr_scale).cwiseAbs();
starting_scale = (m * starting_scale).cwiseAbs();
}
curr_scale(axis) = starting_scale(axis) * ratio;
if (selection.is_single_full_instance() && world_coordinates)
m_scale = (Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse() * curr_scale).cwiseAbs();
else
m_scale = curr_scale;
#else #else
const double ratio = calc_ratio(data); const double ratio = calc_ratio(data);
#endif // ENABLE_WORLD_COORDINATE
if (ratio > 0.0) { if (ratio > 0.0) {
m_scale(axis) = m_starting.scale(axis) * ratio; m_scale(axis) = m_starting.scale(axis) * ratio;
#endif // ENABLE_WORLD_COORDINATE
if (m_starting.ctrl_down) { if (m_starting.ctrl_down) {
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
const double len_starting_vec = std::abs(m_starting.box.center()(axis) - m_starting.pivots[m_hover_id](axis)); const double len_starting_vec = std::abs(m_starting.box.center()(axis) - m_starting.pivots[m_hover_id](axis));

View File

@ -945,16 +945,19 @@ void Selection::scale(const Vec3d& scale, TransformationType transformation_type
GLVolume &v = *(*m_volumes)[i]; GLVolume &v = *(*m_volumes)[i];
if (is_single_full_instance()) { if (is_single_full_instance()) {
if (transformation_type.relative()) { if (transformation_type.relative()) {
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), scale); const Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), scale);
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_instance_scale_matrix()).matrix().block(0, 0, 3, 3); const Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_instance_scale_matrix()).matrix().block(0, 0, 3, 3);
// extracts scaling factors from the composed transformation // extracts scaling factors from the composed transformation
Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm()); const Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm());
if (transformation_type.joint()) if (transformation_type.joint())
v.set_instance_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_instance_position() - m_cache.dragging_center)); v.set_instance_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_instance_position() - m_cache.dragging_center));
v.set_instance_scaling_factor(new_scale); v.set_instance_scaling_factor(new_scale);
} }
else { else {
#if ENABLE_WORLD_COORDINATE
v.set_instance_scaling_factor(scale);
#else
if (transformation_type.world() && (std::abs(scale.x() - scale.y()) > EPSILON || std::abs(scale.x() - scale.z()) > EPSILON)) { if (transformation_type.world() && (std::abs(scale.x() - scale.y()) > EPSILON || std::abs(scale.x() - scale.z()) > EPSILON)) {
// Non-uniform scaling. Transform the scaling factors into the local coordinate system. // Non-uniform scaling. Transform the scaling factors into the local coordinate system.
// This is only possible, if the instance rotation is mulitples of ninety degrees. // This is only possible, if the instance rotation is mulitples of ninety degrees.
@ -963,6 +966,7 @@ void Selection::scale(const Vec3d& scale, TransformationType transformation_type
} }
else else
v.set_instance_scaling_factor(scale); v.set_instance_scaling_factor(scale);
#endif // ENABLE_WORLD_COORDINATE
} }
} }
else if (is_single_volume() || is_single_modifier()) else if (is_single_volume() || is_single_modifier())