mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Flatten and SlaSupports gizmos - grabbers rendered correctly when object is dragged
This commit is contained in:
		
							parent
							
								
									fc82aaaa2e
								
							
						
					
					
						commit
						10393ba834
					
				
					 2 changed files with 34 additions and 16 deletions
				
			
		|  | @ -1246,9 +1246,9 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const | ||||||
|     // the dragged_offset is a vector measuring where was the object moved
 |     // the dragged_offset is a vector measuring where was the object moved
 | ||||||
|     // with the gizmo being on. This is reset in set_flattening_data and
 |     // with the gizmo being on. This is reset in set_flattening_data and
 | ||||||
|     // does not work correctly when there are multiple copies.
 |     // does not work correctly when there are multiple copies.
 | ||||||
|     Vec3d dragged_offset(Vec3d::Zero()); |     if (m_starting_center == Vec3d::Zero()) | ||||||
|     if (m_dragging) |         m_starting_center = box.center(); | ||||||
|         dragged_offset = box.center() - m_starting_center; |     Vec3d dragged_offset(box.center() - m_starting_center); | ||||||
| 
 | 
 | ||||||
|     ::glEnable(GL_BLEND); |     ::glEnable(GL_BLEND); | ||||||
|     ::glEnable(GL_DEPTH_TEST); |     ::glEnable(GL_DEPTH_TEST); | ||||||
|  | @ -1309,6 +1309,7 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const | ||||||
| 
 | 
 | ||||||
| void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) | void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) | ||||||
| { | { | ||||||
|  |     m_starting_center = Vec3d::Zero(); | ||||||
|     m_model_object = model_object; |     m_model_object = model_object; | ||||||
| 
 | 
 | ||||||
|     // ...and save the updated positions of the object instances:
 |     // ...and save the updated positions of the object instances:
 | ||||||
|  | @ -1565,7 +1566,7 @@ Vec3d GLGizmoFlatten::get_flattening_normal() const { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent) | GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent) | ||||||
|     : GLGizmoBase(parent) |     : GLGizmoBase(parent), m_starting_center(Vec3d::Zero()) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1588,18 +1589,33 @@ bool GLGizmoSlaSupports::on_init() | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void GLGizmoSlaSupports::set_model_object_ptr(ModelObject* model_object) | ||||||
|  | { | ||||||
|  |     m_starting_center = Vec3d::Zero(); | ||||||
|  |     m_model_object = model_object; | ||||||
|  |     if (is_mesh_update_necessary()) | ||||||
|  |         update_mesh(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const | void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const | ||||||
| { | { | ||||||
|     ::glEnable(GL_BLEND); |     ::glEnable(GL_BLEND); | ||||||
|     ::glEnable(GL_DEPTH_TEST); |     ::glEnable(GL_DEPTH_TEST); | ||||||
| 
 | 
 | ||||||
|  |     // the dragged_offset is a vector measuring where was the object moved
 | ||||||
|  |     // with the gizmo being on. This is reset in set_flattening_data and
 | ||||||
|  |     // does not work correctly when there are multiple copies.
 | ||||||
|  |     if (m_starting_center == Vec3d::Zero()) | ||||||
|  |         m_starting_center = box.center(); | ||||||
|  |     Vec3d dragged_offset(box.center() - m_starting_center); | ||||||
|  | 
 | ||||||
|     for (auto& g : m_grabbers) { |     for (auto& g : m_grabbers) { | ||||||
|         g.color[0] = 1.f; |         g.color[0] = 1.f; | ||||||
|         g.color[1] = 0.f; |         g.color[1] = 0.f; | ||||||
|         g.color[2] = 0.f; |         g.color[2] = 0.f; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     render_grabbers(); |     render_grabbers(dragged_offset); | ||||||
|     render_tooltip_texture(); |     render_tooltip_texture(); | ||||||
| 
 | 
 | ||||||
|     ::glDisable(GL_BLEND); |     ::glDisable(GL_BLEND); | ||||||
|  | @ -1613,10 +1629,10 @@ void GLGizmoSlaSupports::on_render_for_picking(const BoundingBoxf3& box) const | ||||||
|         m_grabbers[i].color[1] = 1.0f; |         m_grabbers[i].color[1] = 1.0f; | ||||||
|         m_grabbers[i].color[2] = picking_color_component(i); |         m_grabbers[i].color[2] = picking_color_component(i); | ||||||
|     } |     } | ||||||
|     render_grabbers(true); |     render_grabbers(Vec3d::Zero(), true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GLGizmoSlaSupports::render_grabbers(bool picking) const | void GLGizmoSlaSupports::render_grabbers(const Vec3d& dragged_offset, bool picking) const | ||||||
| { | { | ||||||
|     for (int i = 0; i < (int)m_grabbers.size(); ++i) |     for (int i = 0; i < (int)m_grabbers.size(); ++i) | ||||||
|     { |     { | ||||||
|  | @ -1635,7 +1651,7 @@ void GLGizmoSlaSupports::render_grabbers(bool picking) const | ||||||
|             ::glEnable(GL_LIGHTING); |             ::glEnable(GL_LIGHTING); | ||||||
|         ::glColor3f((GLfloat)render_color[0], (GLfloat)render_color[1], (GLfloat)render_color[2]); |         ::glColor3f((GLfloat)render_color[0], (GLfloat)render_color[1], (GLfloat)render_color[2]); | ||||||
|         ::glPushMatrix(); |         ::glPushMatrix(); | ||||||
|         Vec3d center = m_model_object->instances.front()->world_matrix() * m_grabbers[i].center; |         Vec3d center = m_model_object->instances.front()->world_matrix() * m_grabbers[i].center + dragged_offset; | ||||||
|         ::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2)); |         ::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2)); | ||||||
|         GLUquadricObj *quadric; |         GLUquadricObj *quadric; | ||||||
|         quadric = ::gluNewQuadric(); |         quadric = ::gluNewQuadric(); | ||||||
|  | @ -1653,7 +1669,7 @@ bool GLGizmoSlaSupports::is_mesh_update_necessary() const | ||||||
|     if (m_state != On || !m_model_object || m_model_object->instances.empty()) |     if (m_state != On || !m_model_object || m_model_object->instances.empty()) | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
| #if ENABLE_MODELINSTANCE_3D_ROTATION | #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM | ||||||
|     if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size() |     if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size() | ||||||
|      || (m_model_object->instances.front()->world_matrix() * m_source_data.matrix.inverse() * Vec3d(1., 1., 1.) - Vec3d(1., 1., 1.)).norm() > 0.001 ) |      || (m_model_object->instances.front()->world_matrix() * m_source_data.matrix.inverse() * Vec3d(1., 1., 1.) - Vec3d(1., 1., 1.)).norm() > 0.001 ) | ||||||
| #else | #else | ||||||
|  | @ -1706,12 +1722,12 @@ void GLGizmoSlaSupports::update_mesh() | ||||||
|     m_source_data.bounding_boxes.clear(); |     m_source_data.bounding_boxes.clear(); | ||||||
|     for (const auto& vol : m_model_object->volumes) |     for (const auto& vol : m_model_object->volumes) | ||||||
|         m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); |         m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); | ||||||
| #if !ENABLE_MODELINSTANCE_3D_ROTATION | #if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM | ||||||
|     m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor; |     m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor; | ||||||
|     m_source_data.rotation = m_model_object->instances.front()->rotation; |     m_source_data.rotation = m_model_object->instances.front()->rotation; | ||||||
| #else | #else | ||||||
|     m_source_data.matrix = m_model_object->instances.front()->world_matrix(); |     m_source_data.matrix = m_model_object->instances.front()->world_matrix(); | ||||||
| #endif // !ENABLE_MODELINSTANCE_3D_ROTATION
 | #endif | ||||||
|     const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); |     const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); | ||||||
|     m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]); |     m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -375,7 +375,7 @@ private: | ||||||
| #else | #else | ||||||
|     std::vector<Vec2d> m_instances_positions; |     std::vector<Vec2d> m_instances_positions; | ||||||
| #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
 | ||||||
|     Vec3d m_starting_center; |     mutable Vec3d m_starting_center; | ||||||
|     const ModelObject* m_model_object = nullptr; |     const ModelObject* m_model_object = nullptr; | ||||||
| 
 | 
 | ||||||
|     void update_planes(); |     void update_planes(); | ||||||
|  | @ -414,21 +414,23 @@ private: | ||||||
|     Eigen::MatrixXi m_F; // facets indices
 |     Eigen::MatrixXi m_F; // facets indices
 | ||||||
|     struct SourceDataSummary { |     struct SourceDataSummary { | ||||||
|         std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
 |         std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
 | ||||||
| #if !ENABLE_MODELINSTANCE_3D_ROTATION | #if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM | ||||||
|         float scaling_factor; |         float scaling_factor; | ||||||
|         float rotation; |         float rotation; | ||||||
| #else | #else | ||||||
|         Transform3d matrix; |         Transform3d matrix; | ||||||
| #endif // !ENABLE_MODELINSTANCE_3D_ROTATION
 | #endif | ||||||
|         Vec3d mesh_first_point; |         Vec3d mesh_first_point; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     // This holds information to decide whether recalculation is necessary:
 |     // This holds information to decide whether recalculation is necessary:
 | ||||||
|     SourceDataSummary m_source_data; |     SourceDataSummary m_source_data; | ||||||
| 
 | 
 | ||||||
|  |     mutable Vec3d m_starting_center; | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
|     explicit GLGizmoSlaSupports(GLCanvas3D& parent); |     explicit GLGizmoSlaSupports(GLCanvas3D& parent); | ||||||
|     void set_model_object_ptr(ModelObject* model_object) { m_model_object = model_object; if (is_mesh_update_necessary()) update_mesh(); } |     void set_model_object_ptr(ModelObject* model_object); | ||||||
|     void clicked_on_object(const Vec2d& mouse_position); |     void clicked_on_object(const Vec2d& mouse_position); | ||||||
|     void delete_current_grabber(bool delete_all); |     void delete_current_grabber(bool delete_all); | ||||||
| 
 | 
 | ||||||
|  | @ -437,7 +439,7 @@ private: | ||||||
|     void on_update(const Linef3& mouse_ray, const Point* mouse_pos); |     void on_update(const Linef3& mouse_ray, const Point* mouse_pos); | ||||||
|     void on_render(const BoundingBoxf3& box) const; |     void on_render(const BoundingBoxf3& box) const; | ||||||
|     void on_render_for_picking(const BoundingBoxf3& box) const; |     void on_render_for_picking(const BoundingBoxf3& box) const; | ||||||
|     void render_grabbers(bool picking = false) const; |     void render_grabbers(const Vec3d& dragged_offset, bool picking = false) const; | ||||||
|     void render_tooltip_texture() const; |     void render_tooltip_texture() const; | ||||||
|     bool is_mesh_update_necessary() const; |     bool is_mesh_update_necessary() const; | ||||||
|     void update_mesh(); |     void update_mesh(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena