Fix transformation of embossed full instance

This commit is contained in:
Filip Sykala - NTB T15p 2023-10-31 09:53:42 +01:00
parent 9c04671954
commit 1d89f1ad52
2 changed files with 18 additions and 16 deletions

View File

@ -378,16 +378,14 @@ std::string GLGizmoSVG::on_get_name() const { return _u8L("SVG"); }
void GLGizmoSVG::on_render() {
// no volume selected
const Selection &selection = m_parent.get_selection();
if (m_volume == nullptr ||
get_model_volume(m_volume_id, m_parent.get_selection().get_model()->objects) == nullptr)
get_model_volume(m_volume_id, selection.get_model()->objects) == nullptr)
return;
Selection &selection = m_parent.get_selection();
if (selection.is_empty()) return;
if (!selection.volumes_count() != 1)
return;
// prevent get local coordinate system on multi volumes
if (!selection.is_single_volume_or_modifier() &&
!selection.is_single_volume_instance()) return;
bool is_surface_dragging = m_surface_drag.has_value();
bool is_parent_dragging = m_parent.is_mouse_dragging();
// Do NOT render rotation grabbers when dragging object

View File

@ -52,6 +52,10 @@ Transform3d get_volume_transformation(
// initial rotation in Z axis
std::optional<float> current_angle = {},
const std::optional<double> &up_limit = {});
// distinguish between transformation of volume inside object
// and object(single full instance with one volume)
bool is_embossed_object(const Selection &selection);
}
namespace Slic3r::GUI {
@ -346,7 +350,7 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co
Transform3d new_volume_tr = get_volume_transformation(world_tr, wanted_direction, world_position,
fix, instance_tr_inv, current_angle, wanted_up_limit);
if (canvas.get_selection().is_single_full_object()) {
if (is_embossed_object(canvas.get_selection())) {
// transform instance instead of volume
Transform3d new_instance_tr = instance_tr * new_volume_tr * volume.get_matrix().inverse();
instance.set_transformation(Geometry::Transformation(new_instance_tr));
@ -379,7 +383,7 @@ void do_local_z_rotate(GLCanvas3D &canvas, double relative_angle)
bool is_mirrored = false;
const GLVolume* gl_volume = selection.get_first_volume();
if (gl_volume != nullptr) {
if (selection.is_single_full_object()) {
if (is_embossed_object(selection)) {
const ModelInstance *instance = get_model_instance(*gl_volume, selection.get_model()->objects);
if (instance != nullptr)
is_mirrored = has_reflection(instance->get_matrix());
@ -392,14 +396,9 @@ void do_local_z_rotate(GLCanvas3D &canvas, double relative_angle)
if (is_mirrored)
relative_angle *= -1;
selection.setup_cache();
auto selection_rotate_fnc = [&selection, &relative_angle](){
TransformationType transformation_type = selection.is_single_full_object() ?
TransformationType::Instance_Relative_Independent:
TransformationType::Local_Relative_Independent;
selection.rotate(Vec3d(0., 0., relative_angle), transformation_type);
selection.rotate(Vec3d(0., 0., relative_angle), get_drag_transformation_type(selection));
};
selection_transform(selection, selection_rotate_fnc);
@ -432,8 +431,7 @@ void do_local_z_move(GLCanvas3D &canvas, double relative_move) {
TransformationType get_drag_transformation_type(const Selection &selection)
{
assert(selection.volumes_count() == 1);
return selection.is_single_full_object() ?
return is_embossed_object(selection) ?
TransformationType::Instance_Relative_Joint :
TransformationType::Local_Relative_Joint;
}
@ -643,4 +641,10 @@ bool dragging(const Vec2d &mouse_pos,
return true;
}
bool is_embossed_object(const Selection &selection)
{
assert(selection.volumes_count() == 1);
return selection.is_single_full_object() || selection.is_single_full_instance();
}
} // namespace