Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_custom_bed
This commit is contained in:
commit
1e796b82e1
4 changed files with 130 additions and 50 deletions
|
@ -1,6 +1,7 @@
|
||||||
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
||||||
#include "GLGizmoFlatten.hpp"
|
#include "GLGizmoFlatten.hpp"
|
||||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||||
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
|
@ -23,6 +24,22 @@ bool GLGizmoFlatten::on_init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLGizmoFlatten::on_set_state()
|
||||||
|
{
|
||||||
|
// m_model_object pointer can be invalid (for instance because of undo/redo action),
|
||||||
|
// we should recover it from the object id
|
||||||
|
m_model_object = nullptr;
|
||||||
|
for (const auto mo : *wxGetApp().model_objects()) {
|
||||||
|
if (mo->id() == m_model_object_id) {
|
||||||
|
m_model_object = mo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_state == On && is_plane_update_necessary())
|
||||||
|
update_planes();
|
||||||
|
}
|
||||||
|
|
||||||
std::string GLGizmoFlatten::on_get_name() const
|
std::string GLGizmoFlatten::on_get_name() const
|
||||||
{
|
{
|
||||||
return (_(L("Place on face")) + " [F]").ToUTF8().data();
|
return (_(L("Place on face")) + " [F]").ToUTF8().data();
|
||||||
|
@ -120,6 +137,7 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
||||||
m_planes_valid = false;
|
m_planes_valid = false;
|
||||||
}
|
}
|
||||||
m_model_object = model_object;
|
m_model_object = model_object;
|
||||||
|
m_model_object_id = model_object ? model_object->id() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoFlatten::update_planes()
|
void GLGizmoFlatten::update_planes()
|
||||||
|
|
|
@ -31,6 +31,7 @@ private:
|
||||||
bool m_planes_valid = false;
|
bool m_planes_valid = false;
|
||||||
mutable Vec3d m_starting_center;
|
mutable Vec3d m_starting_center;
|
||||||
const ModelObject* m_model_object = nullptr;
|
const ModelObject* m_model_object = nullptr;
|
||||||
|
ObjectID m_model_object_id = 0;
|
||||||
std::vector<const Transform3d*> instances_matrices;
|
std::vector<const Transform3d*> instances_matrices;
|
||||||
|
|
||||||
void update_planes();
|
void update_planes();
|
||||||
|
@ -49,11 +50,7 @@ protected:
|
||||||
virtual void on_start_dragging();
|
virtual void on_start_dragging();
|
||||||
virtual void on_render() const;
|
virtual void on_render() const;
|
||||||
virtual void on_render_for_picking() const;
|
virtual void on_render_for_picking() const;
|
||||||
virtual void on_set_state()
|
virtual void on_set_state() override;
|
||||||
{
|
|
||||||
if (m_state == On && is_plane_update_necessary())
|
|
||||||
update_planes();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
|
|
|
@ -106,6 +106,9 @@ void GLGizmoSlaSupports::on_render() const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! m_its || ! m_mesh)
|
||||||
|
const_cast<GLGizmoSlaSupports*>(this)->update_mesh();
|
||||||
|
|
||||||
glsafe(::glEnable(GL_BLEND));
|
glsafe(::glEnable(GL_BLEND));
|
||||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||||
|
|
||||||
|
@ -387,18 +390,26 @@ bool GLGizmoSlaSupports::is_mesh_update_necessary() const
|
||||||
|
|
||||||
void GLGizmoSlaSupports::update_mesh()
|
void GLGizmoSlaSupports::update_mesh()
|
||||||
{
|
{
|
||||||
|
if (! m_model_object)
|
||||||
|
return;
|
||||||
|
|
||||||
wxBusyCursor wait;
|
wxBusyCursor wait;
|
||||||
// this way we can use that mesh directly.
|
// this way we can use that mesh directly.
|
||||||
// This mesh does not account for the possible Z up SLA offset.
|
// This mesh does not account for the possible Z up SLA offset.
|
||||||
m_mesh = &m_model_object->volumes.front()->mesh();
|
m_mesh = &m_model_object->volumes.front()->mesh();
|
||||||
m_its = &m_mesh->its;
|
m_its = &m_mesh->its;
|
||||||
m_current_mesh_object_id = m_model_object->id();
|
|
||||||
m_editing_mode = false;
|
|
||||||
|
|
||||||
|
// If this is different mesh than last time or if the AABB tree is uninitialized, recalculate it.
|
||||||
|
if (m_current_mesh_object_id != m_model_object->id() || (m_AABB.m_left == NULL && m_AABB.m_right == NULL))
|
||||||
|
{
|
||||||
m_AABB.deinit();
|
m_AABB.deinit();
|
||||||
m_AABB.init(
|
m_AABB.init(
|
||||||
MapMatrixXfUnaligned(m_its->vertices.front().data(), m_its->vertices.size(), 3),
|
MapMatrixXfUnaligned(m_its->vertices.front().data(), m_its->vertices.size(), 3),
|
||||||
MapMatrixXiUnaligned(m_its->indices.front().data(), m_its->indices.size(), 3));
|
MapMatrixXiUnaligned(m_its->indices.front().data(), m_its->indices.size(), 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_current_mesh_object_id = m_model_object->id();
|
||||||
|
m_editing_mode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unprojects the mouse position on the mesh and return the hit point and normal of the facet.
|
// Unprojects the mouse position on the mesh and return the hit point and normal of the facet.
|
||||||
|
@ -1034,6 +1045,25 @@ std::string GLGizmoSlaSupports::on_get_name() const
|
||||||
|
|
||||||
void GLGizmoSlaSupports::on_set_state()
|
void GLGizmoSlaSupports::on_set_state()
|
||||||
{
|
{
|
||||||
|
// m_model_object pointer can be invalid (for instance because of undo/redo action),
|
||||||
|
// we should recover it from the object id
|
||||||
|
const ModelObject* old_model_object = m_model_object;
|
||||||
|
m_model_object = nullptr;
|
||||||
|
for (const auto mo : *wxGetApp().model_objects()) {
|
||||||
|
if (mo->id() == m_current_mesh_object_id) {
|
||||||
|
m_model_object = mo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If ModelObject pointer really changed, invalidate mesh and do everything
|
||||||
|
// as if the gizmo was switched from Off state
|
||||||
|
if (m_model_object == nullptr || old_model_object != m_model_object) {
|
||||||
|
m_mesh = nullptr;
|
||||||
|
m_its = nullptr;
|
||||||
|
m_old_state = Off;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_state == On && m_old_state != On) { // the gizmo was just turned on
|
if (m_state == On && m_old_state != On) { // the gizmo was just turned on
|
||||||
if (is_mesh_update_necessary())
|
if (is_mesh_update_necessary())
|
||||||
update_mesh();
|
update_mesh();
|
||||||
|
@ -1090,6 +1120,26 @@ void GLGizmoSlaSupports::on_start_dragging()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void GLGizmoSlaSupports::on_load(cereal::BinaryInputArchive& ar)
|
||||||
|
{
|
||||||
|
ar(m_clipping_plane_distance,
|
||||||
|
m_clipping_plane_normal,
|
||||||
|
m_current_mesh_object_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void GLGizmoSlaSupports::on_save(cereal::BinaryOutputArchive& ar) const
|
||||||
|
{
|
||||||
|
ar(m_clipping_plane_distance,
|
||||||
|
m_clipping_plane_normal,
|
||||||
|
m_current_mesh_object_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GLGizmoSlaSupports::select_point(int i)
|
void GLGizmoSlaSupports::select_point(int i)
|
||||||
{
|
{
|
||||||
if (i == AllPoints || i == NoPoints) {
|
if (i == AllPoints || i == NoPoints) {
|
||||||
|
@ -1146,6 +1196,7 @@ void GLGizmoSlaSupports::editing_mode_apply_changes()
|
||||||
// If there are no changes, don't touch the front-end. The data in the cache could have been
|
// If there are no changes, don't touch the front-end. The data in the cache could have been
|
||||||
// taken from the backend and copying them to ModelObject would needlessly invalidate them.
|
// taken from the backend and copying them to ModelObject would needlessly invalidate them.
|
||||||
if (m_unsaved_changes) {
|
if (m_unsaved_changes) {
|
||||||
|
wxGetApp().plater()->take_snapshot(_(L("Support points edit")));
|
||||||
m_model_object->sla_points_status = sla::PointsStatus::UserModified;
|
m_model_object->sla_points_status = sla::PointsStatus::UserModified;
|
||||||
m_model_object->sla_support_points.clear();
|
m_model_object->sla_support_points.clear();
|
||||||
for (const CacheEntry& cache_entry : m_editing_mode_cache)
|
for (const CacheEntry& cache_entry : m_editing_mode_cache)
|
||||||
|
@ -1204,6 +1255,7 @@ void GLGizmoSlaSupports::auto_generate()
|
||||||
)), _(L("Warning")), wxICON_WARNING | wxYES | wxNO);
|
)), _(L("Warning")), wxICON_WARNING | wxYES | wxNO);
|
||||||
|
|
||||||
if (m_model_object->sla_points_status != sla::PointsStatus::UserModified || m_editing_mode_cache.empty() || dlg.ShowModal() == wxID_YES) {
|
if (m_model_object->sla_points_status != sla::PointsStatus::UserModified || m_editing_mode_cache.empty() || dlg.ShowModal() == wxID_YES) {
|
||||||
|
wxGetApp().plater()->take_snapshot(_(L("Autogenerate support points")));
|
||||||
m_model_object->sla_support_points.clear();
|
m_model_object->sla_support_points.clear();
|
||||||
m_model_object->sla_points_status = sla::PointsStatus::Generating;
|
m_model_object->sla_points_status = sla::PointsStatus::Generating;
|
||||||
m_editing_mode_cache.clear();
|
m_editing_mode_cache.clear();
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "libslic3r/SLAPrint.hpp"
|
#include "libslic3r/SLAPrint.hpp"
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
|
|
||||||
|
#include <cereal/types/vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -49,12 +51,21 @@ private:
|
||||||
|
|
||||||
class CacheEntry {
|
class CacheEntry {
|
||||||
public:
|
public:
|
||||||
|
CacheEntry() :
|
||||||
|
support_point(sla::SupportPoint()), selected(false), normal(Vec3f::Zero()) {}
|
||||||
|
|
||||||
CacheEntry(const sla::SupportPoint& point, bool sel, const Vec3f& norm = Vec3f::Zero()) :
|
CacheEntry(const sla::SupportPoint& point, bool sel, const Vec3f& norm = Vec3f::Zero()) :
|
||||||
support_point(point), selected(sel), normal(norm) {}
|
support_point(point), selected(sel), normal(norm) {}
|
||||||
|
|
||||||
sla::SupportPoint support_point;
|
sla::SupportPoint support_point;
|
||||||
bool selected; // whether the point is selected
|
bool selected; // whether the point is selected
|
||||||
Vec3f normal;
|
Vec3f normal;
|
||||||
|
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive & ar)
|
||||||
|
{
|
||||||
|
ar(support_point, selected, normal);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -139,6 +150,8 @@ protected:
|
||||||
virtual std::string on_get_name() const;
|
virtual std::string on_get_name() const;
|
||||||
virtual bool on_is_activable() const;
|
virtual bool on_is_activable() const;
|
||||||
virtual bool on_is_selectable() const;
|
virtual bool on_is_selectable() const;
|
||||||
|
virtual void on_load(cereal::BinaryInputArchive& ar) override;
|
||||||
|
virtual void on_save(cereal::BinaryOutputArchive& ar) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue