mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-20 01:29:04 +08:00
Tech ENABLE_TRANSFORMATIONS_BY_MATRICES - Reworked method void Selection::flattening_rotate(const Vec3d& normal) to use matrix multiplication
Fixed conflicts during rebase with master
This commit is contained in:
parent
0e3490620e
commit
f9f7e6e759
@ -1158,6 +1158,13 @@ void Selection::flattening_rotate(const Vec3d& normal)
|
|||||||
for (unsigned int i : m_list) {
|
for (unsigned int i : m_list) {
|
||||||
GLVolume& v = *(*m_volumes)[i];
|
GLVolume& v = *(*m_volumes)[i];
|
||||||
// Normal transformed from the object coordinate space to the world coordinate space.
|
// Normal transformed from the object coordinate space to the world coordinate space.
|
||||||
|
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
|
const Geometry::Transformation& old_inst_trafo = v.get_instance_transformation();
|
||||||
|
const Vec3d tnormal = old_inst_trafo.get_matrix().matrix().block(0, 0, 3, 3).inverse().transpose() * normal;
|
||||||
|
// Additional rotation to align tnormal with the down vector in the world coordinate space.
|
||||||
|
const Transform3d rotation_matrix = Transform3d(Eigen::Quaterniond().setFromTwoVectors(tnormal, -Vec3d::UnitZ()));
|
||||||
|
v.set_instance_transformation(old_inst_trafo.get_offset_matrix() * rotation_matrix * old_inst_trafo.get_matrix_no_offset());
|
||||||
|
#else
|
||||||
const auto& voldata = m_cache.volumes_data[i];
|
const auto& voldata = m_cache.volumes_data[i];
|
||||||
Vec3d tnormal = (Geometry::assemble_transform(
|
Vec3d tnormal = (Geometry::assemble_transform(
|
||||||
Vec3d::Zero(), voldata.get_instance_rotation(),
|
Vec3d::Zero(), voldata.get_instance_rotation(),
|
||||||
@ -1165,6 +1172,7 @@ void Selection::flattening_rotate(const Vec3d& normal)
|
|||||||
// Additional rotation to align tnormal with the down vector in the world coordinate space.
|
// Additional rotation to align tnormal with the down vector in the world coordinate space.
|
||||||
auto extra_rotation = Eigen::Quaterniond().setFromTwoVectors(tnormal, -Vec3d::UnitZ());
|
auto extra_rotation = Eigen::Quaterniond().setFromTwoVectors(tnormal, -Vec3d::UnitZ());
|
||||||
v.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()));
|
||||||
|
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !DISABLE_INSTANCES_SYNCH
|
#if !DISABLE_INSTANCES_SYNCH
|
||||||
@ -1648,12 +1656,11 @@ void Selection::render(float scale_factor)
|
|||||||
else if (coordinates_type == ECoordinatesType::Local && is_single_volume_or_modifier()) {
|
else if (coordinates_type == ECoordinatesType::Local && is_single_volume_or_modifier()) {
|
||||||
const GLVolume& v = *get_first_volume();
|
const GLVolume& v = *get_first_volume();
|
||||||
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
const Geometry::Transformation inst_trafo = get_first_volume()->get_instance_transformation();
|
box = v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_scaling_factor_matrix());
|
||||||
box = box.transformed(inst_trafo.get_scaling_factor_matrix());
|
trafo = v.get_instance_transformation().get_matrix() * v.get_volume_transformation().get_matrix_no_scaling_factor();
|
||||||
trafo = inst_trafo.get_matrix_no_scaling_factor();
|
|
||||||
#else
|
#else
|
||||||
box = box.transformed(get_first_volume()->get_instance_transformation().get_matrix(true, true, false, true));
|
box = v.transformed_convex_hull_bounding_box(v.get_instance_transformation().get_matrix(true, true, false, true) * v.get_volume_transformation().get_matrix(true, true, false, true));
|
||||||
trafo = get_first_volume()->get_instance_transformation().get_matrix(false, false, true, false);
|
trafo = v.get_instance_transformation().get_matrix(false, false, true, false) * v.get_volume_transformation().get_matrix(false, false, true, false);
|
||||||
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1663,11 +1670,12 @@ void Selection::render(float scale_factor)
|
|||||||
box.merge(v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_matrix()));
|
box.merge(v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_matrix()));
|
||||||
}
|
}
|
||||||
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
box = box.transformed(get_volume(*ids.begin())->get_instance_transformation().get_scaling_factor_matrix());
|
const Geometry::Transformation inst_trafo = get_first_volume()->get_instance_transformation();
|
||||||
trafo = get_volume(*ids.begin())->get_instance_transformation().get_matrix_no_scaling_factor();
|
box = box.transformed(inst_trafo.get_scaling_factor_matrix());
|
||||||
|
trafo = inst_trafo.get_matrix_no_scaling_factor();
|
||||||
#else
|
#else
|
||||||
box = box.transformed(get_volume(*ids.begin())->get_instance_transformation().get_matrix(true, true, false, true));
|
box = box.transformed(get_first_volume()->get_instance_transformation().get_matrix(true, true, false, true));
|
||||||
trafo = get_volume(*ids.begin())->get_instance_transformation().get_matrix(false, false, true, false);
|
trafo = get_first_volume()->get_instance_transformation().get_matrix(false, false, true, false);
|
||||||
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user