mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-15 16:11:50 +08:00
Cut gizmo uses the common ObjectClipper to show the cut and contour
This commit is contained in:
parent
389b7ce4bd
commit
7fef26527b
@ -88,9 +88,10 @@ void GLGizmoCut::on_render()
|
|||||||
Vec3d plane_center = box.center();
|
Vec3d plane_center = box.center();
|
||||||
plane_center.z() = m_cut_z;
|
plane_center.z() = m_cut_z;
|
||||||
m_max_z = box.max.z();
|
m_max_z = box.max.z();
|
||||||
set_cut_z(m_cut_z);
|
set_cut_z(m_cut_z); // FIXME: We should not call this during each render loop.
|
||||||
|
|
||||||
update_contours();
|
// update_contours();
|
||||||
|
m_c->object_clipper()->render_cut();
|
||||||
|
|
||||||
const float min_x = box.min.x() - Margin;
|
const float min_x = box.min.x() - Margin;
|
||||||
const float max_x = box.max.x() + Margin;
|
const float max_x = box.max.x() + Margin;
|
||||||
@ -198,20 +199,20 @@ void GLGizmoCut::on_render()
|
|||||||
shader->stop_using();
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #if ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
shader = wxGetApp().get_shader("flat");
|
// shader = wxGetApp().get_shader("flat");
|
||||||
if (shader != nullptr) {
|
// if (shader != nullptr) {
|
||||||
shader->start_using();
|
// shader->start_using();
|
||||||
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
glsafe(::glPushMatrix());
|
// glsafe(::glPushMatrix());
|
||||||
glsafe(::glTranslated(m_cut_contours.shift.x(), m_cut_contours.shift.y(), m_cut_contours.shift.z()));
|
// glsafe(::glTranslated(m_cut_contours.shift.x(), m_cut_contours.shift.y(), m_cut_contours.shift.z()));
|
||||||
glsafe(::glLineWidth(2.0f));
|
// glsafe(::glLineWidth(2.0f));
|
||||||
m_cut_contours.contours.render();
|
// m_cut_contours.contours.render();
|
||||||
glsafe(::glPopMatrix());
|
// glsafe(::glPopMatrix());
|
||||||
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #if ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
shader->stop_using();
|
// shader->stop_using();
|
||||||
}
|
// }
|
||||||
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoCut::on_render_for_picking()
|
void GLGizmoCut::on_render_for_picking()
|
||||||
@ -269,6 +270,16 @@ void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit)
|
|||||||
const bool cut_clicked = m_imgui->button(_L("Perform cut"));
|
const bool cut_clicked = m_imgui->button(_L("Perform cut"));
|
||||||
m_imgui->disabled_end();
|
m_imgui->disabled_end();
|
||||||
|
|
||||||
|
////////
|
||||||
|
static bool hide_clipped = true;
|
||||||
|
static bool fill_cut = true;
|
||||||
|
static float contour_width = 0.;
|
||||||
|
m_imgui->checkbox("hide_clipped", hide_clipped);
|
||||||
|
m_imgui->checkbox("fill_cut", fill_cut);
|
||||||
|
m_imgui->slider_float("contour_width", &contour_width, 0.f, 3.f);
|
||||||
|
m_c->object_clipper()->set_behavior(hide_clipped, fill_cut, contour_width);
|
||||||
|
////////
|
||||||
|
|
||||||
m_imgui->end();
|
m_imgui->end();
|
||||||
|
|
||||||
if (cut_clicked && (m_keep_upper || m_keep_lower))
|
if (cut_clicked && (m_keep_upper || m_keep_lower))
|
||||||
@ -279,6 +290,12 @@ void GLGizmoCut::set_cut_z(double cut_z)
|
|||||||
{
|
{
|
||||||
// Clamp the plane to the object's bounding box
|
// Clamp the plane to the object's bounding box
|
||||||
m_cut_z = std::clamp(cut_z, 0.0, m_max_z);
|
m_cut_z = std::clamp(cut_z, 0.0, m_max_z);
|
||||||
|
|
||||||
|
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 GLGizmoCut::perform_cut(const Selection& selection)
|
void GLGizmoCut::perform_cut(const Selection& selection)
|
||||||
@ -337,52 +354,61 @@ BoundingBoxf3 GLGizmoCut::bounding_box() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoCut::update_contours()
|
// void GLGizmoCut::update_contours()
|
||||||
{
|
// {
|
||||||
const Selection& selection = m_parent.get_selection();
|
// const Selection& selection = m_parent.get_selection();
|
||||||
const GLVolume* first_glvolume = selection.get_volume(*selection.get_volume_idxs().begin());
|
// const GLVolume* first_glvolume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||||
const BoundingBoxf3& box = first_glvolume->transformed_convex_hull_bounding_box();
|
// const BoundingBoxf3& box = first_glvolume->transformed_convex_hull_bounding_box();
|
||||||
|
|
||||||
const ModelObject* model_object = wxGetApp().model().objects[selection.get_object_idx()];
|
// const ModelObject* model_object = wxGetApp().model().objects[selection.get_object_idx()];
|
||||||
const int instance_idx = selection.get_instance_idx();
|
// const int instance_idx = selection.get_instance_idx();
|
||||||
std::vector<ObjectID> volumes_idxs = std::vector<ObjectID>(model_object->volumes.size());
|
// std::vector<ObjectID> volumes_idxs = std::vector<ObjectID>(model_object->volumes.size());
|
||||||
for (size_t i = 0; i < model_object->volumes.size(); ++i) {
|
// for (size_t i = 0; i < model_object->volumes.size(); ++i) {
|
||||||
volumes_idxs[i] = model_object->volumes[i]->id();
|
// volumes_idxs[i] = model_object->volumes[i]->id();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (0.0 < m_cut_z && m_cut_z < m_max_z) {
|
// if (0.0 < m_cut_z && m_cut_z < m_max_z) {
|
||||||
if (m_cut_contours.cut_z != m_cut_z || m_cut_contours.object_id != model_object->id() ||
|
// if (m_cut_contours.cut_z != m_cut_z || m_cut_contours.object_id != model_object->id() ||
|
||||||
m_cut_contours.instance_idx != instance_idx || m_cut_contours.volumes_idxs != volumes_idxs) {
|
// m_cut_contours.instance_idx != instance_idx || m_cut_contours.volumes_idxs != volumes_idxs) {
|
||||||
m_cut_contours.cut_z = m_cut_z;
|
// m_cut_contours.cut_z = m_cut_z;
|
||||||
|
|
||||||
if (m_cut_contours.object_id != model_object->id() || m_cut_contours.volumes_idxs != volumes_idxs)
|
// if (m_cut_contours.object_id != model_object->id() || m_cut_contours.volumes_idxs != volumes_idxs)
|
||||||
m_cut_contours.mesh = model_object->raw_mesh();
|
// m_cut_contours.mesh = model_object->raw_mesh();
|
||||||
|
|
||||||
m_cut_contours.position = box.center();
|
// m_cut_contours.position = box.center();
|
||||||
m_cut_contours.shift = Vec3d::Zero();
|
// m_cut_contours.shift = Vec3d::Zero();
|
||||||
m_cut_contours.object_id = model_object->id();
|
// m_cut_contours.object_id = model_object->id();
|
||||||
m_cut_contours.instance_idx = instance_idx;
|
// m_cut_contours.instance_idx = instance_idx;
|
||||||
m_cut_contours.volumes_idxs = volumes_idxs;
|
// m_cut_contours.volumes_idxs = volumes_idxs;
|
||||||
m_cut_contours.contours.reset();
|
// m_cut_contours.contours.reset();
|
||||||
|
|
||||||
MeshSlicingParams slicing_params;
|
// MeshSlicingParams slicing_params;
|
||||||
slicing_params.trafo = first_glvolume->get_instance_transformation().get_matrix();
|
// slicing_params.trafo = first_glvolume->get_instance_transformation().get_matrix();
|
||||||
const Polygons polys = slice_mesh(m_cut_contours.mesh.its, m_cut_z, slicing_params);
|
// const Polygons polys = slice_mesh(m_cut_contours.mesh.its, m_cut_z, slicing_params);
|
||||||
if (!polys.empty()) {
|
// if (!polys.empty()) {
|
||||||
m_cut_contours.contours.init_from(polys, static_cast<float>(m_cut_z));
|
// m_cut_contours.contours.init_from(polys, static_cast<float>(m_cut_z));
|
||||||
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #if ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
m_cut_contours.contours.set_color(ColorRGBA::WHITE());
|
// m_cut_contours.contours.set_color(ColorRGBA::WHITE());
|
||||||
#else
|
// #else
|
||||||
m_cut_contours.contours.set_color(-1, { 1.0f, 1.0f, 1.0f, 1.0f });
|
// m_cut_contours.contours.set_color(-1, { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
// #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (box.center() != m_cut_contours.position) {
|
// else if (box.center() != m_cut_contours.position) {
|
||||||
m_cut_contours.shift = box.center() - m_cut_contours.position;
|
// m_cut_contours.shift = box.center() - m_cut_contours.position;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
m_cut_contours.contours.reset();
|
// m_cut_contours.contours.reset();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CommonGizmosDataID GLGizmoCut::on_get_requirements() const {
|
||||||
|
return CommonGizmosDataID(
|
||||||
|
int(CommonGizmosDataID::SelectionInfo)
|
||||||
|
| int(CommonGizmosDataID::InstancesHider)
|
||||||
|
| int(CommonGizmosDataID::ObjectClipper));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
|
@ -28,19 +28,19 @@ class GLGizmoCut : public GLGizmoBase
|
|||||||
float m_old_z{ 0.0f };
|
float m_old_z{ 0.0f };
|
||||||
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
|
|
||||||
struct CutContours
|
// struct CutContours
|
||||||
{
|
// {
|
||||||
TriangleMesh mesh;
|
// TriangleMesh mesh;
|
||||||
GLModel contours;
|
// GLModel contours;
|
||||||
double cut_z{ 0.0 };
|
// double cut_z{ 0.0 };
|
||||||
Vec3d position{ Vec3d::Zero() };
|
// Vec3d position{ Vec3d::Zero() };
|
||||||
Vec3d shift{ Vec3d::Zero() };
|
// Vec3d shift{ Vec3d::Zero() };
|
||||||
ObjectID object_id;
|
// ObjectID object_id;
|
||||||
int instance_idx{ -1 };
|
// int instance_idx{ -1 };
|
||||||
std::vector<ObjectID> volumes_idxs;
|
// std::vector<ObjectID> volumes_idxs;
|
||||||
};
|
// };
|
||||||
|
|
||||||
CutContours m_cut_contours;
|
// CutContours m_cut_contours;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
||||||
@ -51,23 +51,25 @@ public:
|
|||||||
std::string get_tooltip() const override;
|
std::string get_tooltip() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool on_init() override;
|
bool on_init() override;
|
||||||
virtual void on_load(cereal::BinaryInputArchive& ar) 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); }
|
||||||
virtual void on_save(cereal::BinaryOutputArchive& ar) const 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); }
|
||||||
virtual std::string on_get_name() const override;
|
std::string on_get_name() const override;
|
||||||
virtual void on_set_state() override;
|
void on_set_state() override;
|
||||||
virtual bool on_is_activable() const override;
|
bool on_is_activable() const override;
|
||||||
virtual void on_start_dragging() override;
|
void on_start_dragging() override;
|
||||||
virtual void on_update(const UpdateData& data) override;
|
void on_update(const UpdateData& data) override;
|
||||||
virtual void on_render() override;
|
void on_render() override;
|
||||||
virtual void on_render_for_picking() override;
|
void on_render_for_picking() override;
|
||||||
virtual void on_render_input_window(float x, float y, float bottom_limit) override;
|
void on_render_input_window(float x, float y, float bottom_limit) override;
|
||||||
|
CommonGizmosDataID on_get_requirements() const override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void perform_cut(const Selection& selection);
|
void perform_cut(const Selection& selection);
|
||||||
double calc_projection(const Linef3& mouse_ray) const;
|
double calc_projection(const Linef3& mouse_ray) const;
|
||||||
BoundingBoxf3 bounding_box() const;
|
BoundingBoxf3 bounding_box() const;
|
||||||
void update_contours();
|
//void update_contours();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user