From 9e554377a0b7dbb7171586fb8b433fb46209f025 Mon Sep 17 00:00:00 2001 From: yw4z Date: Thu, 12 Nov 2026 13:58:16 +0300 Subject: [PATCH] Draw g-code marker tilted for belt printers (#17427) * init * update * fix tilt for decoupled frames --- src/slic3r/GUI/GCodeViewer.cpp | 14 +++++++++++--- src/slic3r/GUI/GCodeViewer.hpp | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index d427d6bce0..0330bcb47e 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -362,9 +362,11 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); float scale_factor = m_scale_factor; - 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); + // ORCA Tilt the model around the nozzle tip + const Transform3d tilt(Eigen::Quaterniond::FromTwoVectors(Vec3d::UnitZ(), m_nozzle_axis)); + const Transform3d model_matrix = Geometry::translation_transform(m_world_position.cast()) * tilt * + Geometry::translation_transform((m_model_z_offset + 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(); @@ -1539,6 +1541,11 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const } libvgcode::GCodeInputData data = libvgcode::convert(gcode_result, str_tool_colors, str_color_print_colors, m_viewer, apply_belt ? &belt_inv : nullptr); + // ORCA Tilt the marker to the layer normal of the designed belt view + Vec3d nozzle_axis = Vec3d::UnitZ(); + if (apply_belt) + nozzle_axis = BeltTransformPipeline::build_rotation_matrix(print.config()).row(2).transpose(); + m_sequential_view.marker.set_nozzle_axis(nozzle_axis); //#define ENABLE_DATA_EXPORT 1 //#if ENABLE_DATA_EXPORT @@ -2379,6 +2386,7 @@ void GCodeViewer::render_markers(int canvas_width, int canvas_height) prim_pos.z() }; m_sequential_view.m_imex_secondary_markers[i].set_world_position(sec_pos); m_sequential_view.m_imex_secondary_markers[i].set_z_offset(m_z_offset + 0.5f); + m_sequential_view.m_imex_secondary_markers[i].set_nozzle_axis(m_sequential_view.marker.get_nozzle_axis()); carriage_box_draws.push_back({ sec_pos, carriage_colors[i + 1], carriage.box_offset_x, carriage.box_offset_y }); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 8f75b087b6..6755fae341 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -88,6 +88,7 @@ public: float m_z_offset{ 0.0f }; // z offset of the model float m_model_z_offset{ 0.5f }; + Vec3d m_nozzle_axis{ Vec3d::UnitZ() }; // ORCA nozzle direction, tilted for belt printers bool m_visible{ true }; bool m_is_dark = false; // the G-code was exported with high_precision_gcode, so positions are shown with one more decimal @@ -107,6 +108,8 @@ public: 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; } + void set_nozzle_axis(const Vec3d& axis) { m_nozzle_axis = axis.normalized(); } // ORCA + const Vec3d& get_nozzle_axis() const { return m_nozzle_axis; } void set_high_precision_gcode(bool high_precision) { m_high_precision_gcode = high_precision; } #if ENABLE_ACTUAL_SPEED_DEBUG