Cut: Sanitize Z when switching selections
This commit is contained in:
parent
ef1d43c711
commit
be9ba936e9
2 changed files with 21 additions and 6 deletions
|
@ -2001,6 +2001,7 @@ const std::array<float, 3> GLGizmoCut::GrabberColor = { 1.0, 0.5, 0.0 };
|
||||||
GLGizmoCut::GLGizmoCut(GLCanvas3D& parent)
|
GLGizmoCut::GLGizmoCut(GLCanvas3D& parent)
|
||||||
: GLGizmoBase(parent)
|
: GLGizmoBase(parent)
|
||||||
, m_cut_z(0.0)
|
, m_cut_z(0.0)
|
||||||
|
, m_max_z(0.0)
|
||||||
#if !ENABLE_IMGUI
|
#if !ENABLE_IMGUI
|
||||||
, m_panel(nullptr)
|
, m_panel(nullptr)
|
||||||
#endif // not ENABLE_IMGUI
|
#endif // not ENABLE_IMGUI
|
||||||
|
@ -2087,7 +2088,7 @@ void GLGizmoCut::on_start_dragging(const GLCanvas3D::Selection& selection)
|
||||||
|
|
||||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||||
m_start_z = m_cut_z;
|
m_start_z = m_cut_z;
|
||||||
m_max_z = box.size()(2);
|
update_max_z(selection);
|
||||||
m_drag_pos = m_grabbers[m_hover_id].center;
|
m_drag_pos = m_grabbers[m_hover_id].center;
|
||||||
m_drag_center = box.center();
|
m_drag_center = box.center();
|
||||||
m_drag_center(2) = m_cut_z;
|
m_drag_center(2) = m_cut_z;
|
||||||
|
@ -2096,9 +2097,7 @@ void GLGizmoCut::on_start_dragging(const GLCanvas3D::Selection& selection)
|
||||||
void GLGizmoCut::on_update(const UpdateData& data)
|
void GLGizmoCut::on_update(const UpdateData& data)
|
||||||
{
|
{
|
||||||
if (m_hover_id != -1) {
|
if (m_hover_id != -1) {
|
||||||
// Clamp the plane to the object's bounding box
|
set_cut_z(m_start_z + calc_projection(data.mouse_ray));
|
||||||
const double new_z = m_start_z + calc_projection(data.mouse_ray);
|
|
||||||
m_cut_z = std::max(0.0, std::min(m_max_z, new_z));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2108,6 +2107,8 @@ void GLGizmoCut::on_render(const GLCanvas3D::Selection& selection) const
|
||||||
set_tooltip("Z: " + format(m_cut_z, 2));
|
set_tooltip("Z: " + format(m_cut_z, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_max_z(selection);
|
||||||
|
|
||||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||||
Vec3d plane_center = box.center();
|
Vec3d plane_center = box.center();
|
||||||
plane_center(2) = m_cut_z;
|
plane_center(2) = m_cut_z;
|
||||||
|
@ -2182,6 +2183,18 @@ void GLGizmoCut::on_render_input_window(float x, float y, const GLCanvas3D::Sele
|
||||||
}
|
}
|
||||||
#endif // ENABLE_IMGUI
|
#endif // ENABLE_IMGUI
|
||||||
|
|
||||||
|
void GLGizmoCut::update_max_z(const GLCanvas3D::Selection& selection) const
|
||||||
|
{
|
||||||
|
m_max_z = selection.get_bounding_box().size()(2);
|
||||||
|
set_cut_z(m_cut_z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLGizmoCut::set_cut_z(double cut_z) const
|
||||||
|
{
|
||||||
|
// Clamp the plane to the object's bounding box
|
||||||
|
m_cut_z = std::max(0.0, std::min(m_max_z, cut_z));
|
||||||
|
}
|
||||||
|
|
||||||
void GLGizmoCut::perform_cut(const GLCanvas3D::Selection& selection)
|
void GLGizmoCut::perform_cut(const GLCanvas3D::Selection& selection)
|
||||||
{
|
{
|
||||||
const auto instance_idx = selection.get_instance_idx();
|
const auto instance_idx = selection.get_instance_idx();
|
||||||
|
|
|
@ -519,9 +519,9 @@ class GLGizmoCut : public GLGizmoBase
|
||||||
static const double Margin;
|
static const double Margin;
|
||||||
static const std::array<float, 3> GrabberColor;
|
static const std::array<float, 3> GrabberColor;
|
||||||
|
|
||||||
double m_cut_z;
|
mutable double m_cut_z;
|
||||||
double m_start_z;
|
double m_start_z;
|
||||||
double m_max_z;
|
mutable double m_max_z;
|
||||||
Vec3d m_drag_pos;
|
Vec3d m_drag_pos;
|
||||||
Vec3d m_drag_center;
|
Vec3d m_drag_center;
|
||||||
bool m_keep_upper;
|
bool m_keep_upper;
|
||||||
|
@ -554,6 +554,8 @@ protected:
|
||||||
virtual void on_render_input_window(float x, float y, const GLCanvas3D::Selection& selection);
|
virtual void on_render_input_window(float x, float y, const GLCanvas3D::Selection& selection);
|
||||||
#endif // ENABLE_IMGUI
|
#endif // ENABLE_IMGUI
|
||||||
private:
|
private:
|
||||||
|
void update_max_z(const GLCanvas3D::Selection& selection) const;
|
||||||
|
void set_cut_z(double cut_z) const;
|
||||||
void perform_cut(const GLCanvas3D::Selection& selection);
|
void perform_cut(const GLCanvas3D::Selection& selection);
|
||||||
double calc_projection(const Linef3& mouse_ray) const;
|
double calc_projection(const Linef3& mouse_ray) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue