Small refactoring in Selection

This commit is contained in:
enricoturri1966 2021-07-20 13:26:12 +02:00
parent fd5cf8d0cc
commit bda128c166

View File

@ -658,20 +658,21 @@ void Selection::translate(const Vec3d& displacement, bool local)
EMode translation_type = m_mode;
for (unsigned int i : m_list) {
if (m_mode == Volume || (*m_volumes)[i]->is_wipe_tower) {
GLVolume& v = *(*m_volumes)[i];
if (m_mode == Volume || v.is_wipe_tower) {
if (local)
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + displacement);
v.set_volume_offset(m_cache.volumes_data[i].get_volume_position() + displacement);
else {
const Vec3d local_displacement = (m_cache.volumes_data[i].get_instance_rotation_matrix() * m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_instance_mirror_matrix()).inverse() * displacement;
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
v.set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
}
}
else if (m_mode == Instance) {
if (is_from_fully_selected_instance(i))
(*m_volumes)[i]->set_instance_offset(m_cache.volumes_data[i].get_instance_position() + displacement);
v.set_instance_offset(m_cache.volumes_data[i].get_instance_position() + displacement);
else {
const Vec3d local_displacement = (m_cache.volumes_data[i].get_instance_rotation_matrix() * m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_instance_mirror_matrix()).inverse() * displacement;
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
v.set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
translation_type = Volume;
}
}
@ -811,6 +812,7 @@ void Selection::flattening_rotate(const Vec3d& normal)
return;
for (unsigned int i : m_list) {
GLVolume& v = *(*m_volumes)[i];
// Normal transformed from the object coordinate space to the world coordinate space.
const auto &voldata = m_cache.volumes_data[i];
Vec3d tnormal = (Geometry::assemble_transform(
@ -818,7 +820,7 @@ void Selection::flattening_rotate(const Vec3d& normal)
voldata.get_instance_scaling_factor().cwiseInverse(), voldata.get_instance_mirror()) * normal).normalized();
// Additional rotation to align tnormal with the down vector in the world coordinate space.
auto extra_rotation = Eigen::Quaterniond().setFromTwoVectors(tnormal, - Vec3d::UnitZ());
(*m_volumes)[i]->set_instance_rotation(Geometry::extract_euler_angles(extra_rotation.toRotationMatrix() * m_cache.volumes_data[i].get_instance_rotation_matrix()));
v.set_instance_rotation(Geometry::extract_euler_angles(extra_rotation.toRotationMatrix() * m_cache.volumes_data[i].get_instance_rotation_matrix()));
}
#if !DISABLE_INSTANCES_SYNCH
@ -952,10 +954,11 @@ void Selection::mirror(Axis axis)
bool single_full_instance = is_single_full_instance();
for (unsigned int i : m_list) {
GLVolume& v = *(*m_volumes)[i];
if (single_full_instance)
(*m_volumes)[i]->set_instance_mirror(axis, -(*m_volumes)[i]->get_instance_mirror(axis));
v.set_instance_mirror(axis, -(*m_volumes)[i]->get_instance_mirror(axis));
else if (m_mode == Volume)
(*m_volumes)[i]->set_volume_mirror(axis, -(*m_volumes)[i]->get_volume_mirror(axis));
v.set_volume_mirror(axis, -(*m_volumes)[i]->get_volume_mirror(axis));
}
#if !DISABLE_INSTANCES_SYNCH
@ -974,9 +977,9 @@ void Selection::translate(unsigned int object_idx, const Vec3d& displacement)
return;
for (unsigned int i : m_list) {
GLVolume* v = (*m_volumes)[i];
if (v->object_idx() == (int)object_idx)
v->set_instance_offset(v->get_instance_offset() + displacement);
GLVolume& v = *(*m_volumes)[i];
if (v.object_idx() == (int)object_idx)
v.set_instance_offset(v.get_instance_offset() + displacement);
}
std::set<unsigned int> done; // prevent processing volumes twice
@ -998,11 +1001,11 @@ void Selection::translate(unsigned int object_idx, const Vec3d& displacement)
if (done.find(j) != done.end())
continue;
GLVolume* v = (*m_volumes)[j];
if (v->object_idx() != object_idx)
GLVolume& v = *(*m_volumes)[j];
if (v.object_idx() != object_idx)
continue;
v->set_instance_offset(v->get_instance_offset() + displacement);
v.set_instance_offset(v.get_instance_offset() + displacement);
done.insert(j);
}
}
@ -1016,9 +1019,9 @@ void Selection::translate(unsigned int object_idx, unsigned int instance_idx, co
return;
for (unsigned int i : m_list) {
GLVolume* v = (*m_volumes)[i];
if (v->object_idx() == (int)object_idx && v->instance_idx() == (int)instance_idx)
v->set_instance_offset(v->get_instance_offset() + displacement);
GLVolume& v = *(*m_volumes)[i];
if (v.object_idx() == (int)object_idx && v.instance_idx() == (int)instance_idx)
v.set_instance_offset(v.get_instance_offset() + displacement);
}
std::set<unsigned int> done; // prevent processing volumes twice
@ -1040,11 +1043,11 @@ void Selection::translate(unsigned int object_idx, unsigned int instance_idx, co
if (done.find(j) != done.end())
continue;
GLVolume* v = (*m_volumes)[j];
if (v->object_idx() != object_idx || v->instance_idx() != (int)instance_idx)
GLVolume& v = *(*m_volumes)[j];
if (v.object_idx() != object_idx || v.instance_idx() != (int)instance_idx)
continue;
v->set_instance_offset(v->get_instance_offset() + displacement);
v.set_instance_offset(v.get_instance_offset() + displacement);
done.insert(j);
}
}