mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 20:51:12 -06:00 
			
		
		
		
	Shared data for SLA gizmos have been removed from GLGizmoBase
This commit introduces no functional changes, only code-shuffling
This commit is contained in:
		
							parent
							
								
									a3869736ba
								
							
						
					
					
						commit
						5a2da9597b
					
				
					 8 changed files with 213 additions and 200 deletions
				
			
		|  | @ -5,10 +5,6 @@ | |||
| 
 | ||||
| #include "slic3r/GUI/GUI_App.hpp" | ||||
| #include "slic3r/GUI/GLCanvas3D.hpp" | ||||
| #include "libslic3r/SLAPrint.hpp" | ||||
| #include "slic3r/GUI/MeshUtils.hpp" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | @ -138,7 +134,7 @@ void GLGizmoBase::Grabber::render_face(float half_size) const | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, CommonGizmosData* common_data_ptr) | ||||
| GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) | ||||
|     : m_parent(parent) | ||||
|     , m_group_id(-1) | ||||
|     , m_state(Off) | ||||
|  | @ -149,7 +145,6 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, u | |||
|     , m_dragging(false) | ||||
|     , m_imgui(wxGetApp().imgui()) | ||||
|     , m_first_input_window_render(true) | ||||
|     , m_c(common_data_ptr) | ||||
| { | ||||
|     ::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 4 * sizeof(float)); | ||||
|     ::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 4 * sizeof(float)); | ||||
|  | @ -306,119 +301,5 @@ unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char gr | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* model_object) | ||||
| { | ||||
|     recent_update = false; | ||||
|     bool object_changed = false; | ||||
| 
 | ||||
|     if (m_model_object != model_object | ||||
|     || (model_object && m_model_object_id != model_object->id())) { | ||||
|         m_model_object = model_object; | ||||
|         m_print_object_idx = -1; | ||||
|         m_mesh_raycaster.reset(); | ||||
|         m_object_clipper.reset(); | ||||
|         m_supports_clipper.reset(); | ||||
|         m_old_mesh = nullptr; | ||||
|         m_mesh = nullptr; | ||||
|         m_backend_mesh_transformed.clear(); | ||||
| 
 | ||||
|         object_changed = true; | ||||
|         recent_update = true; | ||||
|     } | ||||
| 
 | ||||
|     if (m_model_object) { | ||||
|         int active_inst = canvas.get_selection().get_instance_idx(); | ||||
|         if (m_active_instance != active_inst) { | ||||
|             m_active_instance = active_inst; | ||||
|             m_active_instance_bb_radius = m_model_object->instance_bounding_box(m_active_instance).radius(); | ||||
|             recent_update = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     if (! m_model_object || ! canvas.get_selection().is_from_single_instance()) | ||||
|         return false; | ||||
| 
 | ||||
|     int old_po_idx = m_print_object_idx; | ||||
| 
 | ||||
|     // First we need a pointer to the respective SLAPrintObject. The index into objects vector is
 | ||||
|     // cached so we don't have todo it on each render. We only search for the po if needed:
 | ||||
|     if (m_print_object_idx < 0 || (int)canvas.sla_print()->objects().size() != m_print_objects_count) { | ||||
|         m_print_objects_count = canvas.sla_print()->objects().size(); | ||||
|         m_print_object_idx = -1; | ||||
|         for (const SLAPrintObject* po : canvas.sla_print()->objects()) { | ||||
|             ++m_print_object_idx; | ||||
|             if (po->model_object()->id() == m_model_object->id()) | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     bool mesh_exchanged = false; | ||||
|     m_mesh = nullptr; | ||||
|     // Load either the model_object mesh, or one provided by the backend
 | ||||
|     // This mesh does not account for the possible Z up SLA offset.
 | ||||
|     // The backend mesh needs to be transformed and because a pointer to it is
 | ||||
|     // saved, a copy is stored as a member (FIXME)
 | ||||
|     if (m_print_object_idx >=0) { | ||||
|         const SLAPrintObject* po = canvas.sla_print()->objects()[m_print_object_idx]; | ||||
|         if (po->is_step_done(slaposDrillHoles)) { | ||||
|             m_backend_mesh_transformed = po->get_mesh_to_print(); | ||||
|             m_backend_mesh_transformed.transform(canvas.sla_print()->sla_trafo(*m_model_object).inverse()); | ||||
|             m_mesh = &m_backend_mesh_transformed; | ||||
|             m_has_drilled_mesh = true; | ||||
|             mesh_exchanged = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if (! m_mesh) { | ||||
|         m_mesh = &m_model_object->volumes.front()->mesh(); | ||||
|         m_backend_mesh_transformed.clear(); | ||||
|         m_has_drilled_mesh = false; | ||||
|     } | ||||
| 
 | ||||
|     m_model_object_id = m_model_object->id(); | ||||
| 
 | ||||
|     if (m_mesh != m_old_mesh) { | ||||
|         // Update clipping plane position.
 | ||||
|         float new_clp_pos = m_clipping_plane_distance; | ||||
|         if (object_changed) { | ||||
|             new_clp_pos = 0.f; | ||||
|             m_clipping_plane_was_moved = false; | ||||
|         } else { | ||||
|             // After we got a drilled mesh, move the cp to 25% (if not used already)
 | ||||
|             if (m_clipping_plane_distance == 0.f && mesh_exchanged && m_has_drilled_mesh) { | ||||
|                 new_clp_pos = 0.25f; | ||||
|                 m_clipping_plane_was_moved = false; // so it uses current camera direction
 | ||||
|             } | ||||
|         } | ||||
|         m_clipping_plane_distance = new_clp_pos; | ||||
|         m_clipping_plane_distance_stash = new_clp_pos; | ||||
| 
 | ||||
|         m_schedule_aabb_calculation = true; | ||||
|         recent_update = true; | ||||
|         return true; | ||||
|     } | ||||
|     if (! recent_update) | ||||
|         recent_update = m_print_object_idx < 0 && old_po_idx >= 0; | ||||
| 
 | ||||
|     return recent_update; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void CommonGizmosData::build_AABB_if_needed() | ||||
| { | ||||
|     if (! m_schedule_aabb_calculation) | ||||
|         return; | ||||
| 
 | ||||
|     wxBusyCursor wait; | ||||
|     m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh)); | ||||
|     m_object_clipper.reset(); | ||||
|     m_supports_clipper.reset(); | ||||
|     m_old_mesh = m_mesh; | ||||
|     m_schedule_aabb_calculation = false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
| } // namespace Slic3r
 | ||||
|  |  | |||
|  | @ -30,7 +30,6 @@ static const float CONSTRAINED_COLOR[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; | |||
| 
 | ||||
| 
 | ||||
| class ImGuiWrapper; | ||||
| class CommonGizmosData; | ||||
| class GLCanvas3D; | ||||
| class ClippingPlane; | ||||
| 
 | ||||
|  | @ -101,13 +100,11 @@ protected: | |||
|     mutable std::vector<Grabber> m_grabbers; | ||||
|     ImGuiWrapper* m_imgui; | ||||
|     bool m_first_input_window_render; | ||||
|     CommonGizmosData* m_c = nullptr; | ||||
| 
 | ||||
| public: | ||||
|     GLGizmoBase(GLCanvas3D& parent, | ||||
|                 const std::string& icon_filename, | ||||
|                 unsigned int sprite_id, | ||||
|                 CommonGizmosData* common_data = nullptr); | ||||
|                 unsigned int sprite_id); | ||||
|     virtual ~GLGizmoBase() {} | ||||
| 
 | ||||
|     bool init() { return on_init(); } | ||||
|  | @ -185,63 +182,6 @@ protected: | |||
| // were not interpolated by alpha blending or multi sampling.
 | ||||
| extern unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char green, unsigned char blue); | ||||
| 
 | ||||
| class MeshRaycaster; | ||||
| class MeshClipper; | ||||
| 
 | ||||
| class CommonGizmosData { | ||||
| public: | ||||
|     const TriangleMesh* mesh() const { | ||||
|         return (! m_mesh ? nullptr : m_mesh); //(m_cavity_mesh ? m_cavity_mesh.get() : m_mesh));
 | ||||
|     } | ||||
| 
 | ||||
|     bool update_from_backend(GLCanvas3D& canvas, ModelObject* model_object); | ||||
| 
 | ||||
|     bool recent_update = false; | ||||
| 
 | ||||
|     static constexpr float HoleStickOutLength = 1.f; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     ModelObject* m_model_object = nullptr; | ||||
|     const TriangleMesh* m_mesh; | ||||
|     std::unique_ptr<MeshRaycaster> m_mesh_raycaster; | ||||
|     std::unique_ptr<MeshClipper> m_object_clipper; | ||||
|     std::unique_ptr<MeshClipper> m_supports_clipper; | ||||
| 
 | ||||
|     //std::unique_ptr<TriangleMesh> m_cavity_mesh;
 | ||||
|     //std::unique_ptr<GLVolume> m_volume_with_cavity;
 | ||||
| 
 | ||||
|     int m_active_instance = -1; | ||||
|     float m_active_instance_bb_radius = 0; | ||||
|     ObjectID m_model_object_id = 0; | ||||
|     int m_print_object_idx = -1; | ||||
|     int m_print_objects_count = -1; | ||||
|     int m_old_timestamp = -1; | ||||
| 
 | ||||
|     float m_clipping_plane_distance = 0.f; | ||||
|     std::unique_ptr<ClippingPlane> m_clipping_plane; | ||||
|     bool m_clipping_plane_was_moved = false; | ||||
| 
 | ||||
|     void stash_clipping_plane() { | ||||
|         m_clipping_plane_distance_stash = m_clipping_plane_distance; | ||||
|     } | ||||
| 
 | ||||
|     void unstash_clipping_plane() { | ||||
|         m_clipping_plane_distance = m_clipping_plane_distance_stash; | ||||
|     } | ||||
| 
 | ||||
|     bool has_drilled_mesh() const { return m_has_drilled_mesh; } | ||||
| 
 | ||||
|     void build_AABB_if_needed(); | ||||
| 
 | ||||
| private: | ||||
|     const TriangleMesh* m_old_mesh; | ||||
|     TriangleMesh m_backend_mesh_transformed; | ||||
|     float m_clipping_plane_distance_stash = 0.f; | ||||
|     bool m_has_drilled_mesh = false; | ||||
|     bool m_schedule_aabb_calculation = false; | ||||
| }; | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,11 +17,10 @@ | |||
| namespace Slic3r { | ||||
| namespace GUI { | ||||
| 
 | ||||
| GLGizmoHollow::GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, CommonGizmosData* cd) | ||||
|     : GLGizmoBase(parent, icon_filename, sprite_id, cd) | ||||
| GLGizmoHollow::GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) | ||||
|     : GLGizmoBase(parent, icon_filename, sprite_id) | ||||
|     , m_quadric(nullptr) | ||||
| { | ||||
|     m_c->m_clipping_plane.reset(new ClippingPlane(Vec3d::Zero(), 0.)); | ||||
|     m_quadric = ::gluNewQuadric(); | ||||
|     if (m_quadric != nullptr) | ||||
|         // using GLU_FILL does not work when the instance's transformation
 | ||||
|  | @ -1147,6 +1146,13 @@ void GLGizmoHollow::update_clipping_plane(bool keep_normal) const | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| void GLGizmoHollow::on_set_hover_id() | ||||
| { | ||||
|     if (int(m_c->m_model_object->sla_drain_holes.size()) <= m_hover_id) | ||||
|         m_hover_id = -1; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ namespace GUI { | |||
| class ClippingPlane; | ||||
| class MeshClipper; | ||||
| class MeshRaycaster; | ||||
| class CommonGizmosData; | ||||
| enum class SLAGizmoEventType : unsigned char; | ||||
| 
 | ||||
| class GLGizmoHollow : public GLGizmoBase | ||||
|  | @ -28,7 +29,7 @@ private: | |||
| 
 | ||||
| 
 | ||||
| public: | ||||
|     GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, CommonGizmosData* cd); | ||||
|     GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); | ||||
|     ~GLGizmoHollow() override; | ||||
|     void set_sla_support_data(ModelObject* model_object, const Selection& selection); | ||||
|     bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); | ||||
|  | @ -42,6 +43,7 @@ public: | |||
| 
 | ||||
|     bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); } | ||||
|     void update_clipping_plane(bool keep_normal = false) const; | ||||
|     void set_common_data_ptr(CommonGizmosData* ptr) { m_c = ptr; } | ||||
| 
 | ||||
| private: | ||||
|     bool on_init() override; | ||||
|  | @ -72,6 +74,8 @@ private: | |||
| 
 | ||||
|     sla::DrainHoles m_holes_stash; | ||||
| 
 | ||||
|     CommonGizmosData* m_c = nullptr; | ||||
| 
 | ||||
|     //std::unique_ptr<ClippingPlane> m_clipping_plane;
 | ||||
|      | ||||
|     // This map holds all translated description texts, so they can be easily referenced during layout calculations
 | ||||
|  | @ -99,12 +103,7 @@ private: | |||
| 
 | ||||
| protected: | ||||
|     void on_set_state() override; | ||||
|     void on_set_hover_id() override | ||||
| 
 | ||||
|     { | ||||
|         if (int(m_c->m_model_object->sla_drain_holes.size()) <= m_hover_id) | ||||
|             m_hover_id = -1; | ||||
|     } | ||||
|     void on_set_hover_id() override; | ||||
|     void on_start_dragging() override; | ||||
|     void on_stop_dragging() override; | ||||
|     void on_render_input_window(float x, float y, float bottom_limit) override; | ||||
|  |  | |||
|  | @ -22,12 +22,11 @@ | |||
| namespace Slic3r { | ||||
| namespace GUI { | ||||
| 
 | ||||
| GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, CommonGizmosData* cd) | ||||
|     : GLGizmoBase(parent, icon_filename, sprite_id, cd) | ||||
| GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) | ||||
|     : GLGizmoBase(parent, icon_filename, sprite_id) | ||||
|     , m_quadric(nullptr) | ||||
|     , m_its(nullptr) | ||||
| { | ||||
|     m_c->m_clipping_plane.reset(new ClippingPlane(Vec3d::Zero(), 0.)); | ||||
| {     | ||||
|     m_quadric = ::gluNewQuadric(); | ||||
|     if (m_quadric != nullptr) | ||||
|         // using GLU_FILL does not work when the instance's transformation
 | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ namespace GUI { | |||
| class ClippingPlane; | ||||
| class MeshClipper; | ||||
| class MeshRaycaster; | ||||
| class CommonGizmosData; | ||||
| enum class SLAGizmoEventType : unsigned char; | ||||
| 
 | ||||
| class GLGizmoSlaSupports : public GLGizmoBase | ||||
|  | @ -69,7 +70,7 @@ private: | |||
|     }; | ||||
| 
 | ||||
| public: | ||||
|     GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, CommonGizmosData* cd); | ||||
|     GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); | ||||
|     ~GLGizmoSlaSupports() override; | ||||
|     void set_sla_support_data(ModelObject* model_object, const Selection& selection); | ||||
|     bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); | ||||
|  | @ -81,6 +82,7 @@ public: | |||
|     bool has_backend_supports() const; | ||||
|     void reslice_SLA_supports(bool postpone_error_messages = false) const; | ||||
|     void update_clipping_plane(bool keep_normal = false) const; | ||||
|     void set_common_data_ptr(CommonGizmosData* ptr) { m_c = ptr; } | ||||
| 
 | ||||
| private: | ||||
|     bool on_init() override; | ||||
|  | @ -116,6 +118,8 @@ private: | |||
|     bool m_selection_empty = true; | ||||
|     EState m_old_state = Off; // to be able to see that the gizmo has just been closed (see on_set_state)
 | ||||
| 
 | ||||
|     CommonGizmosData* m_c = nullptr; | ||||
| 
 | ||||
|     //mutable std::unique_ptr<MeshClipper> m_object_clipper;
 | ||||
|     //mutable std::unique_ptr<MeshClipper> m_supports_clipper;
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,6 +6,8 @@ | |||
| #include "slic3r/GUI/GUI_ObjectManipulation.hpp" | ||||
| #include "slic3r/GUI/PresetBundle.hpp" | ||||
| #include "slic3r/Utils/UndoRedo.hpp" | ||||
| #include "libslic3r/SLAPrint.hpp" | ||||
| #include "slic3r/GUI/MeshUtils.hpp" | ||||
| 
 | ||||
| #include <GL/glew.h> | ||||
| #include <wx/glcanvas.h> | ||||
|  | @ -83,16 +85,18 @@ bool GLGizmosManager::init() | |||
|             return false; | ||||
|     } | ||||
| 
 | ||||
|     m_common_gizmos_data.reset(new CommonGizmosData()); | ||||
| 
 | ||||
|     // Order of gizmos in the vector must match order in EType!
 | ||||
|     m_gizmos.emplace_back(new GLGizmoMove3D(m_parent, "move.svg", 0)); | ||||
|     m_gizmos.emplace_back(new GLGizmoScale3D(m_parent, "scale.svg", 1)); | ||||
|     m_gizmos.emplace_back(new GLGizmoRotate3D(m_parent, "rotate.svg", 2)); | ||||
|     m_gizmos.emplace_back(new GLGizmoFlatten(m_parent, "place.svg", 3)); | ||||
|     m_gizmos.emplace_back(new GLGizmoCut(m_parent, "cut.svg", 4)); | ||||
|     m_gizmos.emplace_back(new GLGizmoHollow(m_parent, "hollow.svg", 5, m_common_gizmos_data.get())); | ||||
|     m_gizmos.emplace_back(new GLGizmoSlaSupports(m_parent, "sla_supports.svg", 6, m_common_gizmos_data.get())); | ||||
|     m_gizmos.emplace_back(new GLGizmoHollow(m_parent, "hollow.svg", 5)); | ||||
|     m_gizmos.emplace_back(new GLGizmoSlaSupports(m_parent, "sla_supports.svg", 6)); | ||||
| 
 | ||||
|     m_common_gizmos_data.reset(new CommonGizmosData()); | ||||
|     dynamic_cast<GLGizmoHollow*>(m_gizmos[Hollow].get())->set_common_data_ptr(m_common_gizmos_data.get()); | ||||
|     dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->set_common_data_ptr(m_common_gizmos_data.get()); | ||||
| 
 | ||||
|     for (auto& gizmo : m_gizmos) { | ||||
|         if (! gizmo->init()) { | ||||
|  | @ -1051,5 +1055,126 @@ bool GLGizmosManager::grabber_contains_mouse() const | |||
|     return (curr != nullptr) ? (curr->get_hover_id() != -1) : false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| CommonGizmosData::CommonGizmosData() | ||||
| { | ||||
|     m_clipping_plane.reset(new ClippingPlane(Vec3d::Zero(), 0.)); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* model_object) | ||||
| { | ||||
|     recent_update = false; | ||||
|     bool object_changed = false; | ||||
| 
 | ||||
|     if (m_model_object != model_object | ||||
|     || (model_object && m_model_object_id != model_object->id())) { | ||||
|         m_model_object = model_object; | ||||
|         m_print_object_idx = -1; | ||||
|         m_mesh_raycaster.reset(); | ||||
|         m_object_clipper.reset(); | ||||
|         m_supports_clipper.reset(); | ||||
|         m_old_mesh = nullptr; | ||||
|         m_mesh = nullptr; | ||||
|         m_backend_mesh_transformed.clear(); | ||||
| 
 | ||||
|         object_changed = true; | ||||
|         recent_update = true; | ||||
|     } | ||||
| 
 | ||||
|     if (m_model_object) { | ||||
|         int active_inst = canvas.get_selection().get_instance_idx(); | ||||
|         if (m_active_instance != active_inst) { | ||||
|             m_active_instance = active_inst; | ||||
|             m_active_instance_bb_radius = m_model_object->instance_bounding_box(m_active_instance).radius(); | ||||
|             recent_update = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     if (! m_model_object || ! canvas.get_selection().is_from_single_instance()) | ||||
|         return false; | ||||
| 
 | ||||
|     int old_po_idx = m_print_object_idx; | ||||
| 
 | ||||
|     // First we need a pointer to the respective SLAPrintObject. The index into objects vector is
 | ||||
|     // cached so we don't have todo it on each render. We only search for the po if needed:
 | ||||
|     if (m_print_object_idx < 0 || (int)canvas.sla_print()->objects().size() != m_print_objects_count) { | ||||
|         m_print_objects_count = canvas.sla_print()->objects().size(); | ||||
|         m_print_object_idx = -1; | ||||
|         for (const SLAPrintObject* po : canvas.sla_print()->objects()) { | ||||
|             ++m_print_object_idx; | ||||
|             if (po->model_object()->id() == m_model_object->id()) | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     bool mesh_exchanged = false; | ||||
|     m_mesh = nullptr; | ||||
|     // Load either the model_object mesh, or one provided by the backend
 | ||||
|     // This mesh does not account for the possible Z up SLA offset.
 | ||||
|     // The backend mesh needs to be transformed and because a pointer to it is
 | ||||
|     // saved, a copy is stored as a member (FIXME)
 | ||||
|     if (m_print_object_idx >=0) { | ||||
|         const SLAPrintObject* po = canvas.sla_print()->objects()[m_print_object_idx]; | ||||
|         if (po->is_step_done(slaposDrillHoles)) { | ||||
|             m_backend_mesh_transformed = po->get_mesh_to_print(); | ||||
|             m_backend_mesh_transformed.transform(canvas.sla_print()->sla_trafo(*m_model_object).inverse()); | ||||
|             m_mesh = &m_backend_mesh_transformed; | ||||
|             m_has_drilled_mesh = true; | ||||
|             mesh_exchanged = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if (! m_mesh) { | ||||
|         m_mesh = &m_model_object->volumes.front()->mesh(); | ||||
|         m_backend_mesh_transformed.clear(); | ||||
|         m_has_drilled_mesh = false; | ||||
|     } | ||||
| 
 | ||||
|     m_model_object_id = m_model_object->id(); | ||||
| 
 | ||||
|     if (m_mesh != m_old_mesh) { | ||||
|         // Update clipping plane position.
 | ||||
|         float new_clp_pos = m_clipping_plane_distance; | ||||
|         if (object_changed) { | ||||
|             new_clp_pos = 0.f; | ||||
|             m_clipping_plane_was_moved = false; | ||||
|         } else { | ||||
|             // After we got a drilled mesh, move the cp to 25% (if not used already)
 | ||||
|             if (m_clipping_plane_distance == 0.f && mesh_exchanged && m_has_drilled_mesh) { | ||||
|                 new_clp_pos = 0.25f; | ||||
|                 m_clipping_plane_was_moved = false; // so it uses current camera direction
 | ||||
|             } | ||||
|         } | ||||
|         m_clipping_plane_distance = new_clp_pos; | ||||
|         m_clipping_plane_distance_stash = new_clp_pos; | ||||
| 
 | ||||
|         m_schedule_aabb_calculation = true; | ||||
|         recent_update = true; | ||||
|         return true; | ||||
|     } | ||||
|     if (! recent_update) | ||||
|         recent_update = m_print_object_idx < 0 && old_po_idx >= 0; | ||||
| 
 | ||||
|     return recent_update; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void CommonGizmosData::build_AABB_if_needed() | ||||
| { | ||||
|     if (! m_schedule_aabb_calculation) | ||||
|         return; | ||||
| 
 | ||||
|     wxBusyCursor wait; | ||||
|     m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh)); | ||||
|     m_object_clipper.reset(); | ||||
|     m_supports_clipper.reset(); | ||||
|     m_old_mesh = m_mesh; | ||||
|     m_schedule_aabb_calculation = false; | ||||
| } | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
| } // namespace Slic3r
 | ||||
|  |  | |||
|  | @ -227,6 +227,65 @@ private: | |||
|     bool grabber_contains_mouse() const; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class MeshRaycaster; | ||||
| class MeshClipper; | ||||
| 
 | ||||
| // This class is only for sharing SLA related data between SLA gizmos
 | ||||
| // and its synchronization with backend data. It should not be misused
 | ||||
| // for anything else.
 | ||||
| class CommonGizmosData { | ||||
| public: | ||||
|     CommonGizmosData(); | ||||
|     const TriangleMesh* mesh() const { | ||||
|         return (! m_mesh ? nullptr : m_mesh); //(m_cavity_mesh ? m_cavity_mesh.get() : m_mesh));
 | ||||
|     } | ||||
| 
 | ||||
|     bool update_from_backend(GLCanvas3D& canvas, ModelObject* model_object); | ||||
|     bool recent_update = false; | ||||
|     static constexpr float HoleStickOutLength = 1.f; | ||||
| 
 | ||||
|     ModelObject* m_model_object = nullptr; | ||||
|     const TriangleMesh* m_mesh; | ||||
|     std::unique_ptr<MeshRaycaster> m_mesh_raycaster; | ||||
|     std::unique_ptr<MeshClipper> m_object_clipper; | ||||
|     std::unique_ptr<MeshClipper> m_supports_clipper; | ||||
| 
 | ||||
|     //std::unique_ptr<TriangleMesh> m_cavity_mesh;
 | ||||
|     //std::unique_ptr<GLVolume> m_volume_with_cavity;
 | ||||
| 
 | ||||
|     int m_active_instance = -1; | ||||
|     float m_active_instance_bb_radius = 0; | ||||
|     ObjectID m_model_object_id = 0; | ||||
|     int m_print_object_idx = -1; | ||||
|     int m_print_objects_count = -1; | ||||
|     int m_old_timestamp = -1; | ||||
| 
 | ||||
|     float m_clipping_plane_distance = 0.f; | ||||
|     std::unique_ptr<ClippingPlane> m_clipping_plane; | ||||
|     bool m_clipping_plane_was_moved = false; | ||||
| 
 | ||||
|     void stash_clipping_plane() { | ||||
|         m_clipping_plane_distance_stash = m_clipping_plane_distance; | ||||
|     } | ||||
| 
 | ||||
|     void unstash_clipping_plane() { | ||||
|         m_clipping_plane_distance = m_clipping_plane_distance_stash; | ||||
|     } | ||||
| 
 | ||||
|     bool has_drilled_mesh() const { return m_has_drilled_mesh; } | ||||
| 
 | ||||
|     void build_AABB_if_needed(); | ||||
| 
 | ||||
| private: | ||||
|     const TriangleMesh* m_old_mesh; | ||||
|     TriangleMesh m_backend_mesh_transformed; | ||||
|     float m_clipping_plane_distance_stash = 0.f; | ||||
|     bool m_has_drilled_mesh = false; | ||||
|     bool m_schedule_aabb_calculation = false; | ||||
| }; | ||||
| 
 | ||||
| } // namespace GUI
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena