diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index a4169d8612..368ffb40b6 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -224,7 +224,7 @@ void GCodeViewer::COG::render() glsafe(::glDisable(GL_DEPTH_TEST)); const Camera& camera = wxGetApp().plater()->get_camera(); - Transform3d model_matrix = Geometry::translation_transform(cog()); + Transform3d model_matrix = Geometry::translation_transform(cog()) * Geometry::scale_transform(m_scale_factor); //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS if (fixed_screen_size) { @@ -334,13 +334,6 @@ void GCodeViewer::SequentialView::Marker::init() m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); } -void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position) -{ - m_world_position = position; - m_world_transform = (Geometry::translation_transform((position + m_model_z_offset * Vec3f::UnitZ()).cast()) * - Geometry::translation_transform(m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })).cast(); -} - void GCodeViewer::SequentialView::Marker::render() { if (!m_visible) @@ -357,7 +350,12 @@ void GCodeViewer::SequentialView::Marker::render() shader->set_uniform("emission_factor", 0.0f); const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); - const Transform3d model_matrix = m_world_transform.cast(); + float scale_factor = m_scale_factor; + if (m_fixed_screen_size) + scale_factor *= 10.0f * camera.get_inv_zoom(); + const Transform3d model_matrix = (Geometry::translation_transform((m_world_position + m_model_z_offset * Vec3f::UnitZ()).cast()) * + Geometry::translation_transform(scale_factor * m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })) * + Geometry::scale_transform(scale_factor); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); @@ -1230,6 +1228,7 @@ void GCodeViewer::render() std::memcpy(converted_tool_marker_position.data(), m_sequential_view.current_position.data(), 3 * sizeof(float)); m_new_viewer.set_cog_marker_scale_factor(m_cog_marker_fixed_screen_size ? 10.0f * m_cog_marker_size * camera.get_inv_zoom() : m_cog_marker_size); + m_new_viewer.enable_tool_marker(m_sequential_view.current.last != m_sequential_view.endpoints.last); m_new_viewer.set_tool_marker_position(converted_tool_marker_position); m_new_viewer.set_tool_marker_scale_factor(m_tool_marker_fixed_screen_size ? 10.0f * m_tool_marker_size * camera.get_inv_zoom() : m_tool_marker_size); #endif // !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index ff9eda3402..f26b72c3f4 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -404,6 +404,7 @@ class GCodeViewer //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + float m_scale_factor{ 1.0f }; double m_total_mass{ 0.0 }; Vec3d m_total_position{ Vec3d::Zero() }; @@ -711,7 +712,6 @@ public: { GLModel m_model; Vec3f m_world_position; - Transform3f m_world_transform; // For seams, the position of the marker is on the last endpoint of the toolpath containing it. // This offset is used to show the correct value of tool position in the "ToolPosition" window. // See implementation of render() method @@ -721,13 +721,15 @@ public: // z offset of the model float m_model_z_offset{ 0.5f }; bool m_visible{ true }; + bool m_fixed_screen_size{ false }; + float m_scale_factor{ 1.0f }; public: void init(); const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); } - void set_world_position(const Vec3f& position); + void set_world_position(const Vec3f& position) { m_world_position = position; } void set_world_offset(const Vec3f& offset) { m_world_offset = offset; } void set_z_offset(float z_offset) { m_z_offset = z_offset; } diff --git a/src/slic3r/GUI/LibVGCode/ToolMarker.cpp b/src/slic3r/GUI/LibVGCode/ToolMarker.cpp index 3a727f2177..9db5e53110 100644 --- a/src/slic3r/GUI/LibVGCode/ToolMarker.cpp +++ b/src/slic3r/GUI/LibVGCode/ToolMarker.cpp @@ -164,6 +164,16 @@ void ToolMarker::render() glsafe(glBindVertexArray(curr_vertex_array)); } +bool ToolMarker::is_enabled() const +{ + return m_enabled; +} + +void ToolMarker::enable(bool value) +{ + m_enabled = value; +} + const Vec3f& ToolMarker::get_position() const { return m_position; diff --git a/src/slic3r/GUI/LibVGCode/ToolMarker.hpp b/src/slic3r/GUI/LibVGCode/ToolMarker.hpp index 2b1f2648a6..1ef95fe1de 100644 --- a/src/slic3r/GUI/LibVGCode/ToolMarker.hpp +++ b/src/slic3r/GUI/LibVGCode/ToolMarker.hpp @@ -27,6 +27,9 @@ public: void init(uint16_t resolution, float tip_radius, float tip_height, float stem_radius, float stem_height); void render(); + bool is_enabled() const; + void enable(bool value); + const Vec3f& get_position() const; void set_position(const Vec3f& position); @@ -40,6 +43,7 @@ public: void set_alpha(float alpha); private: + bool m_enabled{ false }; Vec3f m_position{ 0.0f, 0.0f, 0.0f }; float m_offset_z{ 0.5f }; Color m_color{ 1.0f, 1.0f, 1.0f }; diff --git a/src/slic3r/GUI/LibVGCode/Viewer.cpp b/src/slic3r/GUI/LibVGCode/Viewer.cpp index ae4ab573b7..f878de79ac 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.cpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.cpp @@ -134,6 +134,16 @@ void Viewer::set_cog_marker_scale_factor(float factor) m_impl.set_cog_marker_scale_factor(factor); } +bool Viewer::is_tool_marker_enabled() const +{ + return m_impl.is_tool_marker_enabled(); +} + +void Viewer::enable_tool_marker(bool value) +{ + m_impl.enable_tool_marker(value); +} + const Vec3f& Viewer::get_tool_marker_position() const { return m_impl.get_tool_marker_position(); diff --git a/src/slic3r/GUI/LibVGCode/Viewer.hpp b/src/slic3r/GUI/LibVGCode/Viewer.hpp index 39dee54c15..19f7080f61 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.hpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.hpp @@ -80,6 +80,9 @@ public: float get_cog_marker_scale_factor() const; void set_cog_marker_scale_factor(float factor); + bool is_tool_marker_enabled() const; + void enable_tool_marker(bool value); + const Vec3f& get_tool_marker_position() const; void set_tool_marker_position(const Vec3f& position); diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp index 41239f3667..7ce4c6f53e 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp @@ -1056,6 +1056,11 @@ float ViewerImpl::get_cog_marker_scale_factor() const return m_cog_marker_scale_factor; } +bool ViewerImpl::is_tool_marker_enabled() const +{ + return m_tool_marker.is_enabled(); +} + const Vec3f& ViewerImpl::get_tool_marker_position() const { return m_tool_marker.get_position(); @@ -1086,6 +1091,11 @@ void ViewerImpl::set_cog_marker_scale_factor(float factor) m_cog_marker_scale_factor = std::max(factor, 0.001f); } +void ViewerImpl::enable_tool_marker(bool value) +{ + m_tool_marker.enable(value); +} + void ViewerImpl::set_tool_marker_position(const Vec3f& position) { m_tool_marker.set_position(position); @@ -1449,6 +1459,9 @@ void ViewerImpl::render_tool_marker(const Mat4x4f& view_matrix, const Mat4x4f& p if (m_tool_marker_shader_id == 0) return; + if (!m_tool_marker.is_enabled()) + return; + int curr_shader; glsafe(glGetIntegerv(GL_CURRENT_PROGRAM, &curr_shader)); const bool curr_cull_face = glIsEnabled(GL_CULL_FACE); diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp index 1815f88ef7..e252690813 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp @@ -110,6 +110,7 @@ public: #if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS Vec3f get_cog_marker_position() const; float get_cog_marker_scale_factor() const; + bool is_tool_marker_enabled() const; const Vec3f& get_tool_marker_position() const; float get_tool_marker_offset_z() const; float get_tool_marker_scale_factor() const; @@ -122,6 +123,7 @@ public: // #if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS void set_cog_marker_scale_factor(float factor); + void enable_tool_marker(bool value); void set_tool_marker_position(const Vec3f& position); void set_tool_marker_offset_z(float offset_z); void set_tool_marker_scale_factor(float factor);