mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 20:46:01 +08:00
Rendering of extruder model in Preview
This commit is contained in:
parent
8c49efbf67
commit
c6cee75ee3
@ -38,7 +38,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"printer_notes_regex": ".*PRINTER_MODEL_MK3.*",
|
"printer_notes_regex": ".*PRINTER_MODEL_MK3.*",
|
||||||
"gantry_model_filename": "prusa3d_mk3_gantry.stl",
|
"gantry_model_filename": "prusa3d_mk3s_gantry.stl",
|
||||||
"slices": [
|
"slices": [
|
||||||
{
|
{
|
||||||
"height": "0",
|
"height": "0",
|
||||||
|
BIN
resources/data/printer_gantries/prusa3d_coreone_gantry.stl
Normal file
BIN
resources/data/printer_gantries/prusa3d_coreone_gantry.stl
Normal file
Binary file not shown.
BIN
resources/data/printer_gantries/prusa3d_mini_gantry.stl
Normal file
BIN
resources/data/printer_gantries/prusa3d_mini_gantry.stl
Normal file
Binary file not shown.
BIN
resources/data/printer_gantries/prusa3d_mk3s_gantry.stl
Normal file
BIN
resources/data/printer_gantries/prusa3d_mk3s_gantry.stl
Normal file
Binary file not shown.
BIN
resources/data/printer_gantries/prusa3d_mk4_gantry.stl
Normal file
BIN
resources/data/printer_gantries/prusa3d_mk4_gantry.stl
Normal file
Binary file not shown.
BIN
resources/data/printer_gantries/prusa3d_xl_gantry.stl
Normal file
BIN
resources/data/printer_gantries/prusa3d_xl_gantry.stl
Normal file
Binary file not shown.
@ -217,9 +217,20 @@ int GCodeViewer::SequentialView::ActualSpeedImguiWidget::plot(const char* label,
|
|||||||
}
|
}
|
||||||
#endif // ENABLE_ACTUAL_SPEED_DEBUG
|
#endif // ENABLE_ACTUAL_SPEED_DEBUG
|
||||||
|
|
||||||
void GCodeViewer::SequentialView::Marker::init()
|
void GCodeViewer::SequentialView::Marker::init(std::optional<std::unique_ptr<GLModel>>& model_opt)
|
||||||
{
|
{
|
||||||
m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f));
|
if (! model_opt.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_model.reset();
|
||||||
|
|
||||||
|
m_generic_marker = (model_opt->get() == nullptr);
|
||||||
|
if (m_generic_marker)
|
||||||
|
m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f));
|
||||||
|
else
|
||||||
|
m_model = **model_opt;
|
||||||
|
model_opt.reset();
|
||||||
|
|
||||||
m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f });
|
m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,9 +256,11 @@ void GCodeViewer::SequentialView::Marker::render()
|
|||||||
float scale_factor = m_scale_factor;
|
float scale_factor = m_scale_factor;
|
||||||
if (m_fixed_screen_size)
|
if (m_fixed_screen_size)
|
||||||
scale_factor *= 10.0f * camera.get_inv_zoom();
|
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<double>()) *
|
const Transform3d model_matrix = m_generic_marker
|
||||||
Geometry::translation_transform(scale_factor * m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })) *
|
? (Geometry::translation_transform((m_world_position + m_model_z_offset * Vec3f::UnitZ()).cast<double>()) *
|
||||||
Geometry::scale_transform(scale_factor);
|
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)
|
||||||
|
: Geometry::translation_transform(m_world_position.cast<double>());
|
||||||
shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
|
shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
|
||||||
shader->set_uniform("projection_matrix", camera.get_projection_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();
|
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||||
@ -842,9 +855,6 @@ void GCodeViewer::init()
|
|||||||
if (m_gl_data_initialized)
|
if (m_gl_data_initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// initializes tool marker
|
|
||||||
m_sequential_view.marker.init();
|
|
||||||
|
|
||||||
m_gl_data_initialized = true;
|
m_gl_data_initialized = true;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -1166,6 +1176,11 @@ void GCodeViewer::render()
|
|||||||
const libvgcode::PathVertex& curr_vertex = m_viewer.get_current_vertex();
|
const libvgcode::PathVertex& curr_vertex = m_viewer.get_current_vertex();
|
||||||
m_sequential_view.marker.set_world_position(libvgcode::convert(curr_vertex.position));
|
m_sequential_view.marker.set_world_position(libvgcode::convert(curr_vertex.position));
|
||||||
m_sequential_view.marker.set_z_offset(m_z_offset);
|
m_sequential_view.marker.set_z_offset(m_z_offset);
|
||||||
|
|
||||||
|
// Following just makes sure that the shown marker is correct.
|
||||||
|
auto marker_model_opt = wxGetApp().plater()->get_current_canvas3D()->get_current_marker_model();
|
||||||
|
m_sequential_view.marker.init(marker_model_opt);
|
||||||
|
|
||||||
m_sequential_view.render(legend_height, &m_viewer, curr_vertex.gcode_id);
|
m_sequential_view.render(legend_height, &m_viewer, curr_vertex.gcode_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,12 +127,13 @@ public:
|
|||||||
bool m_visible{ true };
|
bool m_visible{ true };
|
||||||
bool m_fixed_screen_size{ false };
|
bool m_fixed_screen_size{ false };
|
||||||
float m_scale_factor{ 1.0f };
|
float m_scale_factor{ 1.0f };
|
||||||
|
bool m_generic_marker{ true };
|
||||||
#if ENABLE_ACTUAL_SPEED_DEBUG
|
#if ENABLE_ACTUAL_SPEED_DEBUG
|
||||||
ActualSpeedImguiWidget m_actual_speed_imgui_widget;
|
ActualSpeedImguiWidget m_actual_speed_imgui_widget;
|
||||||
#endif // ENABLE_ACTUAL_SPEED_DEBUG
|
#endif // ENABLE_ACTUAL_SPEED_DEBUG
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init();
|
void init(std::optional<std::unique_ptr<GLModel>>& model_opt);
|
||||||
|
|
||||||
const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); }
|
const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); }
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@
|
|||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/crc.hpp>
|
#include <boost/crc.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
@ -154,6 +155,68 @@ void GLCanvas3D::select_bed(int i, bool triggered_by_user)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns extruder model to visualize in the GCodeViewer:
|
||||||
|
// - nullopt = same as before
|
||||||
|
// - nullptr = none available, use generic
|
||||||
|
// - GLModel = the model to use
|
||||||
|
std::optional<std::unique_ptr<GLModel>> GLCanvas3D::get_current_marker_model() const
|
||||||
|
{
|
||||||
|
std::optional<std::unique_ptr<GLModel>> out;
|
||||||
|
|
||||||
|
static std::string last_printer_notes;
|
||||||
|
static double old_r = 0.;
|
||||||
|
static double old_h = 0.;
|
||||||
|
static bool old_seq = false;
|
||||||
|
|
||||||
|
std::string printer_notes = m_config->opt_string("printer_notes");
|
||||||
|
double r = m_config->opt_float("extruder_clearance_radius");
|
||||||
|
double h = m_config->opt_float("extruder_clearance_height");
|
||||||
|
bool seq = m_config->opt_bool("complete_objects");
|
||||||
|
|
||||||
|
if (last_printer_notes != printer_notes || r != old_r || h != old_h || seq != old_seq) {
|
||||||
|
out = std::make_optional(nullptr);
|
||||||
|
if (! seq)
|
||||||
|
return out;
|
||||||
|
try {
|
||||||
|
std::ifstream in(resources_dir() + "/data/printer_gantries/geometries.txt");
|
||||||
|
boost::property_tree::ptree pt;
|
||||||
|
boost::property_tree::read_json(in, pt);
|
||||||
|
for (const auto& printer : pt.get_child("printers")) {
|
||||||
|
std::string printer_notes_match = printer.second.get<std::string>("printer_notes_regex");
|
||||||
|
boost::regex rgx(printer_notes_match);
|
||||||
|
if (boost::regex_match(printer_notes, rgx)) {
|
||||||
|
std::string filename = resources_dir() + "/data/printer_gantries/" + printer.second.get<std::string>("gantry_model_filename");
|
||||||
|
if (boost::filesystem::exists(filename)) {
|
||||||
|
std::unique_ptr<GLModel> m = std::make_unique<GLModel>();
|
||||||
|
if (m->init_from_file(filename))
|
||||||
|
out = std::make_optional(std::move(m));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
// Whatever happened, ignore it. We will return nullptr.
|
||||||
|
}
|
||||||
|
if (*out == nullptr && seq) {
|
||||||
|
// Generic sequential extruder model.
|
||||||
|
double gantry_height = 10;
|
||||||
|
auto mesh = its_make_cylinder(r, h + gantry_height - 0.001);
|
||||||
|
double d = 3 * wxGetApp().plater()->build_volume().bounding_volume2d().size().x();
|
||||||
|
auto mesh2 = its_make_cube(d,2*r, gantry_height);
|
||||||
|
its_translate(mesh2, Vec3f(-d/2, -r, h));
|
||||||
|
its_merge(mesh, mesh2);
|
||||||
|
std::unique_ptr<GLModel> m = std::make_unique<GLModel>();
|
||||||
|
m->init_from(mesh);
|
||||||
|
out = std::make_optional(std::move(m));
|
||||||
|
}
|
||||||
|
last_printer_notes = printer_notes;
|
||||||
|
old_r = r;
|
||||||
|
old_h = h;
|
||||||
|
old_seq = seq;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __WXGTK3__
|
#ifdef __WXGTK3__
|
||||||
// wxGTK3 seems to simulate OSX behavior in regard to HiDPI scaling support.
|
// wxGTK3 seems to simulate OSX behavior in regard to HiDPI scaling support.
|
||||||
RetinaHelper::RetinaHelper(wxWindow* window) : m_window(window), m_self(nullptr) {}
|
RetinaHelper::RetinaHelper(wxWindow* window) : m_window(window), m_self(nullptr) {}
|
||||||
|
@ -756,6 +756,8 @@ public:
|
|||||||
const libvgcode::Interval& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); }
|
const libvgcode::Interval& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); }
|
||||||
const libvgcode::PathVertex& get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); }
|
const libvgcode::PathVertex& get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); }
|
||||||
|
|
||||||
|
std::optional<std::unique_ptr<GLModel>> get_current_marker_model() const;
|
||||||
|
|
||||||
void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1);
|
void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1);
|
||||||
void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1, const ModelVolume* mv = nullptr);
|
void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1, const ModelVolume* mv = nullptr);
|
||||||
void update_instance_printable_state_for_object(size_t obj_idx);
|
void update_instance_printable_state_for_object(size_t obj_idx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user