Tech ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES - Volumes scaling in all reference systems using Scale gizmo and part manipulator fields
This commit is contained in:
parent
6fe7a78cc5
commit
a1079b14dc
@ -788,10 +788,35 @@ void ObjectManipulation::update_if_dirty()
|
||||
update(m_cache.rotation, m_cache.rotation_rounded, meRotation, m_new_rotation);
|
||||
}
|
||||
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
Selection::EUniformScaleRequiredReason reason;
|
||||
if (selection.requires_uniform_scale(&reason)) {
|
||||
#else
|
||||
if (selection.requires_uniform_scale()) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
m_lock_bnt->SetLock(true);
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
wxString tooltip;
|
||||
if (selection.is_single_volume_or_modifier()) {
|
||||
if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance)
|
||||
tooltip = _L("You cannot use non-uniform scaling mode for parts non aligned with the instance local axes");
|
||||
else if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_World)
|
||||
tooltip = _L("You cannot use non-uniform scaling mode for parts non aligned with the printer axes");
|
||||
}
|
||||
else if (selection.is_single_full_instance()) {
|
||||
if (reason == Selection::EUniformScaleRequiredReason::InstanceNotAxisAligned_World)
|
||||
tooltip = _L("You cannot use non-uniform scaling mode for instances non aligned with the printer axes");
|
||||
else if (reason == Selection::EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance)
|
||||
tooltip = _L("You cannot use non-uniform scaling mode for instances containing non locally axis-aligned parts");
|
||||
}
|
||||
else
|
||||
tooltip = _L("You cannot use non-uniform scaling mode for multiple objects/parts selection");
|
||||
|
||||
m_lock_bnt->SetToolTip(tooltip);
|
||||
#else
|
||||
m_lock_bnt->SetToolTip(_L("You cannot use non-uniform scaling mode for multiple objects/parts selection or non axis-aligned objects/parts"));
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
#else
|
||||
m_lock_bnt->SetToolTip(_L("You cannot use non-uniform scaling mode for multiple objects/parts selection"));
|
||||
#endif // ENABLE_WORLD_COORDINATE
|
||||
|
@ -74,9 +74,9 @@ void GLGizmoMove3D::on_start_dragging()
|
||||
if (m_hover_id != -1) {
|
||||
m_displacement = Vec3d::Zero();
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type();
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
if (coordinates_type == ECoordinatesType::World)
|
||||
#else
|
||||
if (wxGetApp().obj_manipul()->get_world_coordinates())
|
||||
|
@ -136,11 +136,11 @@ void GLGizmoScale3D::on_render()
|
||||
m_center = Vec3d::Zero();
|
||||
m_instance_center = Vec3d::Zero();
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
bool world_coordinates = wxGetApp().obj_manipul()->is_world_coordinates();
|
||||
if (selection.is_single_full_instance() && !wxGetApp().obj_manipul()->is_world_coordinates()) {
|
||||
#else
|
||||
bool world_coordinates = wxGetApp().obj_manipul()->get_world_coordinates();
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_full_instance() && !world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
#else
|
||||
m_transform = Transform3d::Identity();
|
||||
// Transforms grabbers' offsets to world refefence system
|
||||
@ -182,19 +182,39 @@ void GLGizmoScale3D::on_render()
|
||||
#endif // ENABLE_WORLD_COORDINATE
|
||||
}
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
else if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_instance_coordinates()) {
|
||||
#else
|
||||
else if (selection.is_single_volume_or_modifier() && !world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
#else
|
||||
else if (selection.is_single_modifier() || selection.is_single_volume()) {
|
||||
#endif // ENABLE_WORLD_COORDINATE
|
||||
const GLVolume& v = *selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
m_bounding_box.merge(v.transformed_convex_hull_bounding_box(v.get_instance_transformation().get_matrix(true, true, false, true) * v.get_volume_transformation().get_matrix(true, false, false, true)));
|
||||
Geometry::Transformation trafo(v.get_instance_transformation().get_matrix(true, false, true, true));
|
||||
#else
|
||||
m_bounding_box.merge(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)));
|
||||
Geometry::Transformation trafo(v.get_instance_transformation().get_matrix(true, false, true) * v.get_volume_transformation().get_matrix(true, false, true));
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
trafo.set_offset(v.world_matrix().translation());
|
||||
m_grabbers_transform = trafo.get_matrix();
|
||||
m_center = v.world_matrix() * m_bounding_box.center();
|
||||
m_instance_center = m_center;
|
||||
}
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
else if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates()) {
|
||||
const GLVolume& v = *selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
m_bounding_box.merge(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)));
|
||||
Geometry::Transformation trafo(v.get_instance_transformation().get_matrix(true, false, true, true) * v.get_volume_transformation().get_matrix(true, false, true, true));
|
||||
trafo.set_offset(v.world_matrix().translation());
|
||||
m_grabbers_transform = trafo.get_matrix();
|
||||
m_center = v.world_matrix() * m_bounding_box.center();
|
||||
m_instance_center = m_center;
|
||||
}
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
else {
|
||||
m_bounding_box = selection.get_bounding_box();
|
||||
m_grabbers_transform = Geometry::assemble_transform(m_bounding_box.center());
|
||||
@ -422,11 +442,12 @@ void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
|
||||
Vec3d starting_scale = m_starting.scale;
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const bool world_coordinates = wxGetApp().obj_manipul()->is_world_coordinates();
|
||||
const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type();
|
||||
if (coordinates_type == ECoordinatesType::World) {
|
||||
#else
|
||||
const bool world_coordinates = wxGetApp().obj_manipul()->get_world_coordinates();
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_full_instance()) {
|
||||
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();
|
||||
@ -443,7 +464,11 @@ void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
|
||||
|
||||
curr_scale(axis) = starting_scale(axis) * ratio;
|
||||
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (coordinates_type == ECoordinatesType::World) {
|
||||
#else
|
||||
if (world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_full_instance())
|
||||
m_scale = (Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse() * curr_scale).cwiseAbs();
|
||||
else if (selection.is_single_volume_or_modifier()) {
|
||||
@ -473,7 +498,11 @@ void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
|
||||
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
Vec3d center_offset = m_starting.instance_center - m_starting.center;
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_full_instance() && coordinates_type != ECoordinatesType::World) {
|
||||
#else
|
||||
if (selection.is_single_full_instance() && !world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse();
|
||||
center_offset = m * center_offset;
|
||||
}
|
||||
@ -488,11 +517,13 @@ void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data)
|
||||
default: { m_offset = Vec3d::Zero(); break; }
|
||||
}
|
||||
|
||||
#if !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_volume_or_modifier() && !world_coordinates) {
|
||||
const Transform3d mv = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_rotation());
|
||||
const Transform3d mi = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor()).inverse();
|
||||
m_offset = mv * mi * m_offset;
|
||||
}
|
||||
#endif // !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
#else
|
||||
Vec3d local_offset_vec;
|
||||
switch (axis)
|
||||
@ -526,25 +557,29 @@ void GLGizmoScale3D::do_scale_uniform(const UpdateData& data)
|
||||
m_offset.y() *= -1.0;
|
||||
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const bool world_coordinates = wxGetApp().obj_manipul()->is_world_coordinates();
|
||||
#else
|
||||
#if !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const bool world_coordinates = wxGetApp().obj_manipul()->get_world_coordinates();
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
#endif // !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
Vec3d center_offset = m_starting.instance_center - m_starting.center;
|
||||
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_full_instance() && !wxGetApp().obj_manipul()->is_world_coordinates()) {
|
||||
#else
|
||||
if (selection.is_single_full_instance() && !world_coordinates) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
const Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_rotation()).inverse();
|
||||
center_offset = m * center_offset;
|
||||
}
|
||||
|
||||
m_offset += (ratio - 1.0) * center_offset;
|
||||
|
||||
#if !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_volume_or_modifier() && !world_coordinates) {
|
||||
const Transform3d mv = Geometry::assemble_transform(Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_rotation());
|
||||
const Transform3d mi = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor()).inverse();
|
||||
m_offset = mv * mi * m_offset;
|
||||
}
|
||||
#endif // !ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
}
|
||||
else
|
||||
#endif // ENABLE_WORLD_COORDINATE
|
||||
@ -598,7 +633,11 @@ void GLGizmoScale3D::transform_to_local(const Selection& selection) const
|
||||
if (!wxGetApp().obj_manipul()->get_world_coordinates()) {
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true);
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates())
|
||||
#else
|
||||
if (selection.is_single_volume_or_modifier())
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
orient_matrix = orient_matrix * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_transformation().get_matrix(true, false, true, true);
|
||||
glsafe(::glMultMatrixd(orient_matrix.data()));
|
||||
}
|
||||
|
@ -601,18 +601,74 @@ bool Selection::matches(const std::vector<unsigned int>& volume_idxs) const
|
||||
return count == (unsigned int)m_list.size();
|
||||
}
|
||||
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
bool Selection::requires_uniform_scale(EUniformScaleRequiredReason* reason) const
|
||||
#else
|
||||
bool Selection::requires_uniform_scale() const
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
{
|
||||
#if ENABLE_WORLD_COORDINATE
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
ECoordinatesType coord_type = wxGetApp().obj_manipul()->get_coordinates_type();
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
if (is_single_volume_or_modifier())
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
{
|
||||
if (coord_type == ECoordinatesType::World) {
|
||||
if (!Geometry::is_rotation_ninety_degrees(Geometry::Transformation(get_volume(*m_list.begin())->world_matrix()).get_rotation())) {
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::VolumeNotAxisAligned_World;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (coord_type == ECoordinatesType::Instance) {
|
||||
if (!Geometry::is_rotation_ninety_degrees(get_volume(*m_list.begin())->get_volume_rotation())) {
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return !Geometry::is_rotation_ninety_degrees(Geometry::Transformation(get_volume(*m_list.begin())->world_matrix()).get_rotation());
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
else if (is_single_full_instance())
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
return wxGetApp().obj_manipul()->is_world_coordinates() ?
|
||||
if (coord_type == ECoordinatesType::World) {
|
||||
if (!Geometry::is_rotation_ninety_degrees(get_volume(*m_list.begin())->get_instance_rotation())) {
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::InstanceNotAxisAligned_World;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
for (unsigned int i : m_list) {
|
||||
if (!Geometry::is_rotation_ninety_degrees((*m_volumes)[i]->get_volume_rotation())) {
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
for (unsigned int i : m_list) {
|
||||
if (!Geometry::is_rotation_ninety_degrees((*m_volumes)[i]->get_volume_rotation())) {
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::VolumeNotAxisAligned_Instance;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reason != nullptr)
|
||||
*reason = EUniformScaleRequiredReason::MultipleSelection;
|
||||
#else
|
||||
return wxGetApp().obj_manipul()->get_world_coordinates() ?
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
!Geometry::is_rotation_ninety_degrees(get_volume(*m_list.begin())->get_instance_rotation()) : false;
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
|
||||
return true;
|
||||
#else
|
||||
@ -737,7 +793,7 @@ void Selection::translate(const Vec3d& displacement, bool local)
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
else if (type == ECoordinatesType::Local) {
|
||||
const VolumeCache& volume_data = m_cache.volumes_data[i];
|
||||
const Vec3d local_displacement = (volume_data.get_volume_rotation_matrix() * volume_data.get_volume_scale_matrix() * volume_data.get_volume_mirror_matrix()) * displacement;
|
||||
const Vec3d local_displacement = (volume_data.get_volume_rotation_matrix() * volume_data.get_volume_mirror_matrix()) * displacement;
|
||||
v.set_volume_offset(volume_data.get_volume_position() + local_displacement);
|
||||
}
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
|
@ -301,7 +301,19 @@ public:
|
||||
// returns true if the selection contains all and only the given indices
|
||||
bool matches(const std::vector<unsigned int>& volume_idxs) const;
|
||||
|
||||
#if ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
enum class EUniformScaleRequiredReason : unsigned char
|
||||
{
|
||||
NotRequired,
|
||||
InstanceNotAxisAligned_World,
|
||||
VolumeNotAxisAligned_World,
|
||||
VolumeNotAxisAligned_Instance,
|
||||
MultipleSelection,
|
||||
};
|
||||
bool requires_uniform_scale(EUniformScaleRequiredReason* reason = nullptr) const;
|
||||
#else
|
||||
bool requires_uniform_scale() const;
|
||||
#endif // ENABLE_INSTANCE_COORDINATES_FOR_VOLUMES
|
||||
|
||||
// Returns the the object id if the selection is from a single object, otherwise is -1
|
||||
int get_object_idx() const;
|
||||
|
Loading…
Reference in New Issue
Block a user