mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 13:45:59 +08:00
Cut: Implemented update_clipper()
This commit is contained in:
parent
1e5d5ae2f5
commit
af03bed094
@ -126,6 +126,35 @@ void GLGizmoCut3D::shift_cut_z(double delta)
|
||||
set_center(new_cut_center);
|
||||
}
|
||||
|
||||
void GLGizmoCut3D::update_clipper()
|
||||
{
|
||||
const Vec3d& angles = m_rotation_gizmo.get_rotation();
|
||||
Matrix3d m;
|
||||
m = Eigen::AngleAxisd(angles[X], Vec3d::UnitX())
|
||||
* Eigen::AngleAxisd(angles[Y], Vec3d::UnitY())
|
||||
* Eigen::AngleAxisd(angles[Z], Vec3d::UnitZ());
|
||||
|
||||
Vec3d plane_center = m_move_gizmo.get_center();
|
||||
BoundingBoxf3 box = m_move_gizmo.bounding_box();
|
||||
|
||||
Vec3d min, max = min = plane_center = m_move_gizmo.get_center();
|
||||
min[Z] = box.min.z();
|
||||
max[Z] = box.max.z();
|
||||
|
||||
min -= plane_center;
|
||||
max -= plane_center;
|
||||
|
||||
Vec3d beg = m * min;
|
||||
Vec3d end = m * max;
|
||||
|
||||
beg += plane_center;
|
||||
end += plane_center;
|
||||
|
||||
double dist = (plane_center - beg).norm();
|
||||
|
||||
m_c->object_clipper()->set_range_and_pos(beg, end, dist);
|
||||
}
|
||||
|
||||
void GLGizmoCut3D::set_center(const Vec3d& center)
|
||||
{
|
||||
m_move_gizmo.set_center_pos(center);
|
||||
@ -216,7 +245,7 @@ void GLGizmoCut3D::render_rotation_input(int axis)
|
||||
ImGui::SameLine();
|
||||
|
||||
Vec3d rotation = m_rotation_gizmo.get_rotation();
|
||||
double value = rotation[axis] * (180. / M_PI);
|
||||
double value = Geometry::rad2deg(rotation[axis]);
|
||||
if (value > 360)
|
||||
value -= 360;
|
||||
|
||||
@ -224,7 +253,7 @@ void GLGizmoCut3D::render_rotation_input(int axis)
|
||||
ImGui::InputDouble(("##rotate_" + m_axis_names[axis]).c_str(), &value, 0.0f, 0.0f, "%.2f", ImGuiInputTextFlags_CharsDecimal);
|
||||
ImGui::SameLine();
|
||||
|
||||
rotation[axis] = (M_PI / 180.) * value;
|
||||
rotation[axis] = Geometry::deg2rad(value);
|
||||
m_rotation_gizmo.set_rotation(rotation);
|
||||
}
|
||||
|
||||
@ -248,7 +277,7 @@ void GLGizmoCut3D::render_cut_plane()
|
||||
{
|
||||
const BoundingBoxf3 box = m_move_gizmo.bounding_box();
|
||||
Vec3d plane_center = m_move_gizmo.get_center();// == Vec3d::Zero() ? box.center() : m_move_gizmo.get_center();
|
||||
// update_contours();
|
||||
|
||||
m_c->object_clipper()->render_cut();
|
||||
|
||||
const float min_x = box.min.x() - GLGizmoCenterMove::Margin - plane_center.x();
|
||||
@ -383,6 +412,7 @@ void GLGizmoCut3D::on_update(const UpdateData& data)
|
||||
|
||||
void GLGizmoCut3D::on_render()
|
||||
{
|
||||
update_clipper();
|
||||
render_cut_plane();
|
||||
if (m_mode == CutMode::cutPlanar) {
|
||||
int move_group_id = m_move_gizmo.get_group_id();
|
||||
@ -435,7 +465,7 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
ImGui::SameLine(m_label_width);
|
||||
for (Axis axis : {X, Y, Z})
|
||||
render_rotation_input(axis);
|
||||
m_imgui->text(_L("°"));
|
||||
m_imgui->text(_L("°"));
|
||||
}
|
||||
else {
|
||||
ImGui::AlignTextToFramePadding();
|
||||
@ -510,12 +540,6 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
bool GLGizmoCut3D::can_perform_cut() const
|
||||
{
|
||||
return true;
|
||||
|
||||
const BoundingBoxf3 box = bounding_box();
|
||||
Vec3d plane_center = box.center();
|
||||
plane_center.z() = 0;
|
||||
m_c->object_clipper()->set_range_and_pos(plane_center,
|
||||
plane_center + m_max_z * Vec3d::UnitZ(), m_cut_z);
|
||||
}
|
||||
|
||||
void GLGizmoCut3D::perform_cut(const Selection& selection)
|
||||
|
@ -113,16 +113,14 @@ public:
|
||||
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
|
||||
|
||||
void shift_cut_z(double delta);
|
||||
void update_clipper();
|
||||
|
||||
protected:
|
||||
bool on_init() override;
|
||||
void on_load(cereal::BinaryInputArchive& ar) override { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); }
|
||||
void on_save(cereal::BinaryOutputArchive& ar) const override { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); }
|
||||
void on_load(cereal::BinaryInputArchive& ar) override { ar(/*m_cut_z, */m_keep_upper, m_keep_lower, m_rotate_lower); }
|
||||
void on_save(cereal::BinaryOutputArchive& ar) const override { ar(/*m_cut_z, */m_keep_upper, m_keep_lower, m_rotate_lower); }
|
||||
std::string on_get_name() const override;
|
||||
void on_set_state() override;
|
||||
bool on_is_activable() const override;
|
||||
void on_start_dragging() override;
|
||||
void on_update(const UpdateData& data) override;
|
||||
CommonGizmosDataID on_get_requirements() const override;
|
||||
void on_set_hover_id() override;
|
||||
void on_enable_grabber(unsigned int id) override;
|
||||
|
@ -458,9 +458,15 @@ void ObjectClipper::set_position_by_ratio(double pos, bool keep_normal)
|
||||
|
||||
void ObjectClipper::set_range_and_pos(const Vec3d& origin, const Vec3d& end, double pos)
|
||||
{
|
||||
std::cout << "origin:\t"<< origin.x() << "\t" << origin.y() << "\t"<< origin.z() << "\n";
|
||||
std::cout << "end:\t" << end.x() << "\t" << end.y() << "\t"<< end.z() << "\n";
|
||||
|
||||
Vec3d normal = end-origin;
|
||||
double norm = normal.norm();
|
||||
pos = std::clamp(pos, 0.0001, norm);
|
||||
|
||||
std::cout << "NORM:\t" << norm << "\tPOS:\t" << pos << "\n\n";
|
||||
|
||||
m_clp.reset(new ClippingPlane(normal, pos));
|
||||
m_clp_ratio = pos/norm;
|
||||
get_pool()->get_canvas()->set_as_dirty();
|
||||
|
@ -446,7 +446,7 @@ bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_p
|
||||
else if (m_current == MmuSegmentation)
|
||||
return dynamic_cast<GLGizmoMmuSegmentation*>(m_gizmos[MmuSegmentation].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
else if (m_current == Cut)
|
||||
return dynamic_cast<GLGizmoCut*>(m_gizmos[Cut].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
return dynamic_cast<GLGizmoCut3D*>(m_gizmos[Cut].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user