OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::Bed3D Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/3DBed.hpp>

Collaboration diagram for Slic3r::GUI::Bed3D:

Classes

class  Axes

Public Types

enum class  Type : unsigned char { System , Custom }

Public Member Functions

 Bed3D ()=default
 ~Bed3D ()=default
bool set_shape (const Pointfs &printable_area, const double printable_height, std::vector< Pointfs > extruder_areas, std::vector< double > extruder_heights, const std::string &custom_model, bool force_as_custom=false, const Vec2d position=Vec2d::Zero(), bool with_reset=true)
void set_position (Vec2d &position)
void set_axes_mode (bool origin)
void set_axes_origin (const Vec3d &origin)
const Vec2d & get_position () const
const BuildVolume & build_volume () const
BuildVolume & build_volume ()
Type get_type () const
bool is_custom () const
BuildVolume_Type get_build_volume_type () const
const BoundingBoxf3 & extended_bounding_box () const
const BoundingBoxf3 & printable_bounding_box () const
bool contains (const Point &point) const
Point point_projection (const Point &point) const
void render (GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom, float scale_factor, bool show_axes)
void on_change_color_mode (bool is_dark)

Static Public Member Functions

static void update_render_colors ()
static void load_render_colors ()

Static Public Attributes

static ColorRGBA DEFAULT_MODEL_COLOR = { 0.3255f, 0.337f, 0.337f, 1.0f }
static ColorRGBA DEFAULT_MODEL_COLOR_DARK = { 0.255f, 0.255f, 0.283f, 1.0f }
static ColorRGBA DEFAULT_SOLID_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 1.0f }
static ColorRGBA DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 0.6f }
static ColorRGBA AXIS_X_COLOR = ColorRGBA::X()
static ColorRGBA AXIS_Y_COLOR = ColorRGBA::Y()
static ColorRGBA AXIS_Z_COLOR = ColorRGBA::Z()

Private Member Functions

BoundingBoxf3 calc_printable_bounding_box () const
BoundingBoxf3 calc_extended_bounding_box () const
void update_model_offset ()
void update_bed_triangles ()
void render_internal (GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom, float scale_factor, bool show_axes)
void render_axes ()
void render_system (GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom)
void render_model (const Transform3d &view_matrix, const Transform3d &projection_matrix)
void render_custom (GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom)
void render_default (bool bottom, const Transform3d &view_matrix, const Transform3d &projection_matrix)
void render_gravity_arrow (const Transform3d &view_matrix, const Transform3d &projection_matrix)

Static Private Member Functions

static std::tuple< Type, std::string, std::string > detect_type (const Pointfs &shape)

Private Attributes

BuildVolume m_build_volume
Type m_type { Type::System }
std::string m_model_filename
BoundingBoxf3 m_extended_bounding_box
BoundingBoxf3 m_printable_bounding_box
GLModel m_triangles
GLModel m_model
Vec3d m_model_offset { Vec3d::Zero() }
GLModel m_gravity_arrow
float m_gravity_arrow_length { 0.f }
Axes m_axes
float m_scale_factor { 1.0f }
Vec2d m_position { Vec2d::Zero() }
std::vector< Vec2d > m_bed_shape
std::vector< std::vector< Vec2d > > m_extruder_shapes
std::vector< double > m_extruder_heights
bool m_is_dark = false

Detailed Description

Member Enumeration Documentation

◆ Type

enum class Slic3r::GUI::Bed3D::Type : unsigned char
strong
Enumerator
System 
Custom 
94 {
95 // The print bed model and texture are available from some printer preset.
96 System,
97 // The print bed model is unknown, thus it is rendered procedurally.
98 Custom
99 };
@ Custom
Definition CustomGCode.hpp:23

Constructor & Destructor Documentation

◆ Bed3D()

Slic3r::GUI::Bed3D::Bed3D ( )
default

◆ ~Bed3D()

Slic3r::GUI::Bed3D::~Bed3D ( )
default

References Slic3r::printable_area(), and Slic3r::printable_height().

Here is the call graph for this function:

Member Function Documentation

◆ build_volume() [1/2]

BuildVolume & Slic3r::GUI::Bed3D::build_volume ( )
inline
149{ return m_build_volume; }
BuildVolume m_build_volume
Definition 3DBed.hpp:102

References m_build_volume.

◆ build_volume() [2/2]

const BuildVolume & Slic3r::GUI::Bed3D::build_volume ( ) const
inline
148{ return m_build_volume; }

References m_build_volume.

Referenced by Slic3r::GUI::Plater::priv::load_files(), Slic3r::GUI::Plater::priv::load_model_objects(), Slic3r::GUI::Plater::priv::scale_selection_to_fit_print_volume(), Slic3r::GUI::Plater::priv::update(), and update_bed_triangles().

Here is the caller graph for this function:

◆ calc_extended_bounding_box()

BoundingBoxf3 Slic3r::GUI::Bed3D::calc_extended_bounding_box ( ) const
private
444{
445 BoundingBoxf3 out;
446 out.merge(m_printable_bounding_box);
447 BoundingBoxf3 model_bb = m_model.get_bounding_box();
448 if (model_bb.defined) {
449 model_bb.translate(m_model_offset);
450 out.merge(model_bb);
451 }
452 return out;
453}
GLModel m_model
Definition 3DBed.hpp:116
BoundingBoxf3 m_printable_bounding_box
Definition 3DBed.hpp:108
Vec3d m_model_offset
Definition 3DBed.hpp:117

References Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::defined, m_model, m_model_offset, m_printable_bounding_box, Slic3r::BoundingBox3Base< PointType >::merge(), and Slic3r::BoundingBox3Base< PointType >::translate().

Referenced by update_bed_triangles(), and update_model_offset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_printable_bounding_box()

BoundingBoxf3 Slic3r::GUI::Bed3D::calc_printable_bounding_box ( ) const
private
424{
425 BoundingBoxf3 out{m_build_volume.bounding_volume()};
426
427 const Vec3d size = out.size();
428 // ensures that the bounding box is set as defined or the following calls to merge() will not work as intented
429 if (size.x() > 0.0 && size.y() > 0.0 && !out.defined)
430 out.defined = true;
431 // Reset the build volume Z, we don't want to zoom to the top of the build volume if it is empty.
432 out.min.z() = 0.0;
433 out.max.z() = 0.0;
434 // extend to contain axes
435 // BBS: add part plate related logic.
436 Vec3d offset{m_position.x(), m_position.y(), 0.f};
437 // out.merge(m_axes.get_origin() + offset + m_axes.get_total_length() * Vec3d::Ones());
438 out.merge(Vec3d(0.f, 0.f, GROUND_Z) + offset + m_axes.get_total_length() * Vec3d::Ones());
439 out.merge(out.min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, out.max.z()));
440 return out;
441}
static const float GROUND_Z
Definition 3DBed.cpp:49
static const float DefaultTipRadius
Definition 3DBed.hpp:73
Axes m_axes
Definition 3DBed.hpp:120
Vec2d m_position
Definition 3DBed.hpp:124
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582

References Slic3r::GUI::Bed3D::Axes::DefaultTipRadius, Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::defined, GROUND_Z, m_axes, m_build_volume, m_position, Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::max, Slic3r::BoundingBox3Base< PointType >::merge(), Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::min, Slic3r::offset(), and Slic3r::BoundingBox3Base< PointType >::size().

Referenced by update_bed_triangles(), and update_model_offset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains()

bool Slic3r::GUI::Bed3D::contains ( const Point & point) const

◆ detect_type()

std::tuple< Bed3D::Type, std::string, std::string > Slic3r::GUI::Bed3D::detect_type ( const Pointfs & shape)
staticprivate
458{
459 auto bundle = wxGetApp().preset_bundle;
460 if (bundle != nullptr) {
461 const Preset* curr = &bundle->printers.get_selected_preset();
462 while (curr != nullptr) {
463 if (curr->config.has("printable_area")) {
464 std::string texture_filename, model_filename;
465 if (shape == make_counter_clockwise(dynamic_cast<const ConfigOptionPoints*>(curr->config.option("printable_area"))->values)) {
466 if (curr->is_system)
468 else {
469 auto *printer_model = curr->config.opt<ConfigOptionString>("printer_model");
470 if (printer_model != nullptr && ! printer_model->value.empty()) {
471 model_filename = bundle->get_stl_model_for_printer_model(printer_model->value);
472 }
473 }
474 //std::string model_filename = PresetUtils::system_printer_bed_model(*curr);
475 //std::string texture_filename = PresetUtils::system_printer_bed_texture(*curr);
476 if (!model_filename.empty())
477 return { Type::System, model_filename, texture_filename };
478 }
479 }
480
481 curr = bundle->printers.get_preset_parent(*curr);
482 }
483 }
484
485 return { Type::Custom, {}, {} };
486}
@ Custom
Definition 3DBed.hpp:98
@ System
Definition 3DBed.hpp:96
static const std::string model_filename
Definition CalibUtils.cpp:82
std::string system_printer_bed_model(const Preset &preset)
Definition Preset.cpp:5095
Pointfs make_counter_clockwise(const Pointfs &pointfs)
Definition ClipperUtils.cpp:1568
@ Preset
Definition calib.hpp:39
zaa_minimize_perimeter_height ConfigOptionString
Definition PrintConfig.hpp:1702

References Slic3r::Preset::config, Custom, Slic3r::ConfigOptionResolver::has(), Slic3r::Preset::is_system, Slic3r::make_counter_clockwise(), Slic3r::GUI::model_filename, Slic3r::DynamicConfig::opt(), Slic3r::ConfigBase::option(), System, Slic3r::PresetUtils::system_printer_bed_model(), and Slic3r::ConfigOptionVector< T >::values.

Referenced by set_shape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extended_bounding_box()

const BoundingBoxf3 & Slic3r::GUI::Bed3D::extended_bounding_box ( ) const
inline
160{ return m_extended_bounding_box; }
BoundingBoxf3 m_extended_bounding_box
Definition 3DBed.hpp:107

References m_extended_bounding_box.

◆ get_build_volume_type()

BuildVolume_Type Slic3r::GUI::Bed3D::get_build_volume_type ( ) const
inline
157{ return m_build_volume.type(); }

References m_build_volume.

◆ get_position()

const Vec2d & Slic3r::GUI::Bed3D::get_position ( ) const
inline
145{ return m_position; }

References m_position.

◆ get_type()

Type Slic3r::GUI::Bed3D::get_type ( ) const
inline
152{ return m_type; }
Type m_type
Definition 3DBed.hpp:103

References m_type.

◆ is_custom()

bool Slic3r::GUI::Bed3D::is_custom ( ) const
inline
154{ return m_type == Type::Custom; }

References Custom, and m_type.

◆ load_render_colors()

void Slic3r::GUI::Bed3D::load_render_colors ( )
static
221{
225}
@ RenderCol_Axis_X
Definition GUI_Colors.hpp:23
@ RenderCol_Axis_Y
Definition GUI_Colors.hpp:24
@ RenderCol_Axis_Z
Definition GUI_Colors.hpp:25
static ColorRGBA AXIS_Z_COLOR
Definition 3DBed.hpp:63
static ColorRGBA AXIS_X_COLOR
Definition 3DBed.hpp:61
static ColorRGBA AXIS_Y_COLOR
Definition 3DBed.hpp:62
static ImVec4 to_ImVec4(const ColorRGB &color)
Definition ImGuiWrapper.cpp:1053
static ImVec4 colors[RenderCol_Count]
Definition GUI_Colors.hpp:40

References AXIS_X_COLOR, AXIS_Y_COLOR, AXIS_Z_COLOR, Slic3r::RenderColor::colors, RenderCol_Axis_X, RenderCol_Axis_Y, RenderCol_Axis_Z, and Slic3r::GUI::ImGuiWrapper::to_ImVec4().

Referenced by Slic3r::GUI::GLCanvas3D::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_change_color_mode()

void Slic3r::GUI::Bed3D::on_change_color_mode ( bool is_dark)
388{
390}
static bool is_dark()
Definition TextureImportDialog.cpp:85
bool m_is_dark
Definition 3DBed.hpp:128

References is_dark(), and m_is_dark.

Here is the call graph for this function:

◆ point_projection()

Point Slic3r::GUI::Bed3D::point_projection ( const Point & point) const

References is_dark().

Here is the call graph for this function:

◆ printable_bounding_box()

const BoundingBoxf3 & Slic3r::GUI::Bed3D::printable_bounding_box ( ) const
inline

◆ render()

void Slic3r::GUI::Bed3D::render ( GLCanvas3D & canvas,
const Transform3d & view_matrix,
const Transform3d & projection_matrix,
bool bottom,
float scale_factor,
bool show_axes )
393{
394 render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes);
395}
void render_internal(GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom, float scale_factor, bool show_axes)
Definition 3DBed.cpp:397

References render_internal().

Here is the call graph for this function:

◆ render_axes()

void Slic3r::GUI::Bed3D::render_axes ( )
private
489{
490 if (m_build_volume.valid())
491 m_axes.render();
492}

References m_axes, and m_build_volume.

Referenced by render_internal().

Here is the caller graph for this function:

◆ render_custom()

void Slic3r::GUI::Bed3D::render_custom ( GLCanvas3D & canvas,
const Transform3d & view_matrix,
const Transform3d & projection_matrix,
bool bottom )
private
748{
749 if (m_model_filename.empty()) {
750 render_default(bottom, view_matrix, projection_matrix);
751 return;
752 }
753
754 if (!bottom)
755 render_model(view_matrix, projection_matrix);
756
757 /*if (show_texture)
758 render_texture(bottom, canvas);*/
759}
std::string m_model_filename
Definition 3DBed.hpp:105
void render_model(const Transform3d &view_matrix, const Transform3d &projection_matrix)
Definition 3DBed.cpp:700
void render_default(bool bottom, const Transform3d &view_matrix, const Transform3d &projection_matrix)
Definition 3DBed.cpp:814

References m_model_filename, render_default(), and render_model().

Referenced by render_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_default()

void Slic3r::GUI::Bed3D::render_default ( bool bottom,
const Transform3d & view_matrix,
const Transform3d & projection_matrix )
private
815{
816 // m_texture.reset();
817
819
820 GLShaderProgram* shader = wxGetApp().get_shader("flat");
821 if (shader != nullptr) {
822 shader->start_using();
823
824 shader->set_uniform("view_model_matrix", view_matrix);
825 shader->set_uniform("projection_matrix", projection_matrix);
826
830
831 if (m_model.get_filename().empty() && !bottom) {
832 // draw background
834 ColorRGBA color = m_is_dark ? DEFAULT_MODEL_COLOR_DARK : DEFAULT_MODEL_COLOR; // ORCA add dark mode support
835 color = ColorRGBA(color[0] * 0.8f, color[1] * 0.8f,color[2] * 0.8f, color[3]); // ORCA shift color a darker tone to fix difference between flat / gouraud_light shader
836 m_triangles.set_color(color);
837 m_triangles.render();
839 }
840
841 /*if (!picking) {
842 // draw grid
843 glsafe(::glLineWidth(1.5f * m_scale_factor));
844 m_gridlines.set_color(picking ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR);
845 m_gridlines.render();
846 }*/
847
849
850 shader->stop_using();
851 }
852}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
static ColorRGBA DEFAULT_MODEL_COLOR_DARK
Definition 3DBed.hpp:57
static ColorRGBA DEFAULT_MODEL_COLOR
Definition 3DBed.hpp:56
void update_bed_triangles()
Definition 3DBed.cpp:663
GLModel m_triangles
Definition 3DBed.hpp:111
#define GL_TRUE
Definition gl.h:1892
#define glEnable
Definition gl.h:3667
#define GL_DEPTH_TEST
Definition gl.h:574
#define GL_SRC_ALPHA
Definition gl.h:1621
#define glDepthMask
Definition gl.h:3595
#define GL_BLEND
Definition gl.h:275
#define GL_ONE_MINUS_SRC_ALPHA
Definition gl.h:1239
#define GL_FALSE
Definition gl.h:648
#define glDisable
Definition gl.h:3607
#define glBlendFunc
Definition gl.h:3325

References DEFAULT_MODEL_COLOR, DEFAULT_MODEL_COLOR_DARK, GL_BLEND, GL_DEPTH_TEST, GL_FALSE, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_TRUE, glBlendFunc, glDepthMask, glDisable, glEnable, glsafe, m_is_dark, m_model, m_triangles, Slic3r::GLShaderProgram::set_uniform(), Slic3r::GLShaderProgram::start_using(), Slic3r::GLShaderProgram::stop_using(), and update_bed_triangles().

Referenced by render_custom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_gravity_arrow()

void Slic3r::GUI::Bed3D::render_gravity_arrow ( const Transform3d & view_matrix,
const Transform3d & projection_matrix )
private
762{
763 // build_plate_tilt_{x,y} are kept in sync with the belt tilt (see TabPrinter), so
764 // reading them here covers both belt and non-belt tilted printers.
765 const Vec3d up_dir = build_plate_tilt_up_direction();
766 if (up_dir == Vec3d::UnitZ()) {
767 m_gravity_arrow.reset();
768 return;
769 }
770
771 // A plain line along the tilted "up" direction -- the way the layers lean, i.e.
772 // the gantry -- drawn like the bed axes (no tip: the other direction is not
773 // possible) and shorter than them, so it reads as a hint inside the YZ corner.
774 const float length = 0.6f * m_axes.get_total_length();
775 if (!m_gravity_arrow.is_initialized() || m_gravity_arrow_length != length) {
776 m_gravity_arrow.reset();
777 m_gravity_arrow.init_from(smooth_cylinder(16, /*Radius*/ length / 75.f, length));
779 }
780
781 // The cylinder model points along +Z. Compute the rotation that aligns it with
782 // up_dir: rotation axis = cross(+Z, up_dir), angle = acos(dot(+Z, up_dir)).
783 Vec3d from = Vec3d::UnitZ();
784 Vec3d to = up_dir;
785 double dot = from.dot(to);
786 Transform3d rot = Transform3d::Identity();
787 if (dot < -0.9999) {
788 // Nearly opposite -- rotate 180 degrees around X
789 rot = Eigen::AngleAxisd(M_PI, Vec3d::UnitX()) * rot;
790 } else if (dot < 0.9999) {
791 Vec3d axis = from.cross(to).normalized();
792 double angle = std::acos(std::clamp(dot, -1.0, 1.0));
793 rot = Eigen::AngleAxisd(angle, axis) * rot;
794 }
795
796 GLShaderProgram* shader = wxGetApp().get_shader("flat");
797 if (shader == nullptr)
798 return;
799
801 shader->start_using();
802
803 const Camera& camera = wxGetApp().plater()->get_camera();
804 Transform3d model_matrix = Eigen::Translation3d(m_axes.get_origin()) * rot;
805 shader->set_uniform("view_model_matrix", camera.get_view_matrix() * model_matrix);
806 shader->set_uniform("projection_matrix", camera.get_projection_matrix());
807
808 m_gravity_arrow.set_color({ 1.0f, 0.85f, 0.0f, 1.0f }); // yellow
809 m_gravity_arrow.render();
810
811 shader->stop_using();
812}
#define M_PI
Definition ExtrusionSimulator.cpp:31
float m_gravity_arrow_length
Definition 3DBed.hpp:119
GLModel m_gravity_arrow
Definition 3DBed.hpp:118
@ Camera
Definition Shortcuts.hpp:72
Vec3d build_plate_tilt_up_direction()
Definition GUI_App.cpp:10519
GLModel::Geometry smooth_cylinder(unsigned int resolution, float radius, float height)
Definition GLModel.cpp:1356
double length(const Points &pts)
Definition MultiPoint.hpp:181
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:96
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:138
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:154

References Slic3r::angle(), Slic3r::GUI::build_plate_tilt_up_direction(), Slic3r::dot(), Slic3r::GUI::Camera::get_projection_matrix(), Slic3r::GUI::Camera::get_view_matrix(), GL_DEPTH_TEST, glEnable, glsafe, Slic3r::length(), m_axes, m_gravity_arrow, m_gravity_arrow_length, M_PI, Slic3r::GLShaderProgram::set_uniform(), Slic3r::GUI::smooth_cylinder(), Slic3r::GLShaderProgram::start_using(), and Slic3r::GLShaderProgram::stop_using().

Referenced by render_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_internal()

void Slic3r::GUI::Bed3D::render_internal ( GLCanvas3D & canvas,
const Transform3d & view_matrix,
const Transform3d & projection_matrix,
bool bottom,
float scale_factor,
bool show_axes )
private
399{
400 m_scale_factor = scale_factor;
401
402 if (show_axes)
403 render_axes();
404
406
408
409 switch (m_type)
410 {
411 case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom); break; }
412 default:
413 case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom); break; }
414 }
415
416 render_gravity_arrow(view_matrix, projection_matrix);
417
419}
void render_system(GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom)
Definition 3DBed.cpp:494
void render_custom(GLCanvas3D &canvas, const Transform3d &view_matrix, const Transform3d &projection_matrix, bool bottom)
Definition 3DBed.cpp:747
void render_gravity_arrow(const Transform3d &view_matrix, const Transform3d &projection_matrix)
Definition 3DBed.cpp:761
void render_axes()
Definition 3DBed.cpp:488
float m_scale_factor
Definition 3DBed.hpp:122

References Custom, DEFAULT_MODEL_COLOR, DEFAULT_MODEL_COLOR_DARK, GL_DEPTH_TEST, glDisable, glEnable, glsafe, m_is_dark, m_model, m_scale_factor, m_type, render_axes(), render_custom(), render_gravity_arrow(), render_system(), and System.

Referenced by render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_model()

void Slic3r::GUI::Bed3D::render_model ( const Transform3d & view_matrix,
const Transform3d & projection_matrix )
private
701{
702 if (m_model_filename.empty())
703 return;
704
705 if (m_model.get_filename() != m_model_filename && m_model.init_from_file(m_model_filename)) {
707
709
710 // BBS: remove the bed picking logic
711 //register_raycasters_for_picking(m_model.model.get_geometry(), Geometry::assemble_transform(m_model_offset));
712 }
713
714 if (!m_model.get_filename().empty()) {
715 const Camera & camera = wxGetApp().plater()->get_camera();
716 const Transform3d &view_matrix = camera.get_view_matrix();
717 const Transform3d &projection_matrix = camera.get_projection_matrix();
718 GLShaderProgram* shader = wxGetApp().get_shader("hotbed");
719 if (shader != nullptr) {
720 shader->start_using();
721 shader->set_uniform("emission_factor", 0.0f);
723 shader->set_uniform("volume_world_matrix", model_matrix);
724 shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
725 shader->set_uniform("projection_matrix", projection_matrix);
726 const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
727 shader->set_uniform("view_normal_matrix", view_normal_matrix);
728 if (m_build_volume.get_extruder_area_count() > 0) {
729 const BuildVolume::BuildSharedVolume& shared_volume = m_build_volume.get_shared_volume();
730 std::array<float, 4> xy_data = shared_volume.data;
731 shader->set_uniform("print_volume.type", shared_volume.type);
732 shader->set_uniform("print_volume.xy_data", xy_data);
733 std::array<float, 2> zs = shared_volume.zs;
734 zs[0] = -1;
735 shader->set_uniform("print_volume.z_data", zs);
736 }
737 else {
738 //use -1 ad a invalid type
739 shader->set_uniform("print_volume.type", -1);
740 }
741 m_model.render();
742 shader->stop_using();
743 }
744 }
745}
void update_model_offset()
Definition 3DBed.cpp:642
void assemble_transform(Transform3d &transform, const Vec3d &translation, const Vec3d &rotation, const Vec3d &scale, const Vec3d &mirror)
Definition Geometry.cpp:319
Eigen::Matrix< double, 3, 3, Eigen::DontAlign > Matrix3d
Definition Point.hpp:86

References Slic3r::Geometry::assemble_transform(), Slic3r::BuildVolume::BuildSharedVolume::data, DEFAULT_MODEL_COLOR, DEFAULT_MODEL_COLOR_DARK, Slic3r::GUI::Camera::get_projection_matrix(), Slic3r::GUI::Camera::get_view_matrix(), m_build_volume, m_is_dark, m_model, m_model_filename, m_model_offset, Slic3r::GLShaderProgram::set_uniform(), Slic3r::GLShaderProgram::start_using(), Slic3r::GLShaderProgram::stop_using(), Slic3r::BuildVolume::BuildSharedVolume::type, update_model_offset(), and Slic3r::BuildVolume::BuildSharedVolume::zs.

Referenced by render_custom(), and render_system().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_system()

void Slic3r::GUI::Bed3D::render_system ( GLCanvas3D & canvas,
const Transform3d & view_matrix,
const Transform3d & projection_matrix,
bool bottom )
private
495{
496 if (!bottom)
497 render_model(view_matrix, projection_matrix);
498
499 /*if (show_texture)
500 render_texture(bottom, canvas);*/
501}

References render_model().

Referenced by render_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_axes_mode()

void Slic3r::GUI::Bed3D::set_axes_mode ( bool origin)
368{
369 if (origin) {
370 m_axes.set_origin({ 0.0, 0.0, static_cast<double>(GROUND_Z) });
371 }
372 else {
373 m_axes.set_origin({ m_position.x(), m_position.y(), static_cast<double>(GROUND_Z) });
374 }
375}

References GROUND_Z, m_axes, and m_position.

◆ set_axes_origin()

void Slic3r::GUI::Bed3D::set_axes_origin ( const Vec3d & origin)
inline
144{ m_axes.set_origin(origin); } // Design tab: triad at bed centre

References m_axes.

◆ set_position()

void Slic3r::GUI::Bed3D::set_position ( Vec2d & position)
363{
364 set_shape(m_bed_shape, m_build_volume.printable_height(), m_extruder_shapes, m_extruder_heights, m_model_filename, false, position, false);
365}
std::vector< double > m_extruder_heights
Definition 3DBed.hpp:127
std::vector< std::vector< Vec2d > > m_extruder_shapes
Definition 3DBed.hpp:126
bool set_shape(const Pointfs &printable_area, const double printable_height, std::vector< Pointfs > extruder_areas, std::vector< double > extruder_heights, const std::string &custom_model, bool force_as_custom=false, const Vec2d position=Vec2d::Zero(), bool with_reset=true)
Definition 3DBed.cpp:270
std::vector< Vec2d > m_bed_shape
Definition 3DBed.hpp:125

References m_bed_shape, m_build_volume, m_extruder_heights, m_extruder_shapes, m_model_filename, and set_shape().

Here is the call graph for this function:

◆ set_shape()

bool Slic3r::GUI::Bed3D::set_shape ( const Pointfs & printable_area,
const double printable_height,
std::vector< Pointfs > extruder_areas,
std::vector< double > extruder_heights,
const std::string & custom_model,
bool force_as_custom = false,
const Vec2d position = Vec2d::Zero(),
bool with_reset = true )
272{
273 /*auto check_texture = [](const std::string& texture) {
274 boost::system::error_code ec; // so the exists call does not throw (e.g. after a permission problem)
275 return !texture.empty() && (boost::algorithm::iends_with(texture, ".png") || boost::algorithm::iends_with(texture, ".svg")) && boost::filesystem::exists(texture, ec);
276 };*/
277
278 auto check_model = [](const std::string& model) {
279 boost::system::error_code ec;
280 return !model.empty() && boost::algorithm::iends_with(model, ".stl") && boost::filesystem::exists(model, ec);
281 };
282
283 Type type;
284 std::string model;
285 std::string texture;
286 if (force_as_custom)
287 type = Type::Custom;
288 else {
289 auto [new_type, system_model, system_texture] = detect_type(printable_area);
290 type = new_type;
291 model = system_model;
292 texture = system_texture;
293 }
294
295 /*std::string texture_filename = custom_texture.empty() ? texture : custom_texture;
296 if (! texture_filename.empty() && ! check_texture(texture_filename)) {
297 BOOST_LOG_TRIVIAL(error) << "Unable to load bed texture: " << texture_filename;
298 texture_filename.clear();
299 }*/
300
301 std::string model_filename = custom_model.empty() ? model : custom_model;
302 if (! model_filename.empty() && ! check_model(model_filename)) {
303 BOOST_LOG_TRIVIAL(error) << "Unable to load bed model: " << model_filename;
304 model_filename.clear();
305 }
306
307 //BBS: add position related logic
308 if (m_bed_shape == printable_area && m_build_volume.printable_height() == printable_height && m_type == type && m_model_filename == model_filename && position == m_position && m_extruder_shapes == extruder_areas && m_extruder_heights == extruder_heights)
309 // No change, no need to update the UI.
310 return false;
311
312 //BBS: add part plate logic, apply position to bed shape
313 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":current position {%1%,%2%}, new position {%3%, %4%}") % m_position.x() % m_position.y() % position.x() % position.y();
314 m_position = position;
316 m_extruder_shapes = extruder_areas;
317 m_extruder_heights = extruder_heights;
318 if ((position(0) != 0) || (position(1) != 0)) {
319 Pointfs new_bed_shape;
320 for (const Vec2d& p : m_bed_shape) {
321 Vec2d point(p(0) + m_position.x(), p(1) + m_position.y());
322 new_bed_shape.push_back(point);
323 }
324 std::vector<Pointfs> new_extruder_shapes;
325 for (const std::vector<Vec2d>& shape : m_extruder_shapes) {
326 std::vector<Vec2d> new_extruder_shape;
327 for (const Vec2d& p : shape) {
328 Vec2d point(p(0) + m_position.x(), p(1) + m_position.y());
329 new_extruder_shape.push_back(point);
330 }
331 new_extruder_shapes.push_back(new_extruder_shape);
332 }
333 m_build_volume = BuildVolume { new_bed_shape, printable_height, new_extruder_shapes, m_extruder_heights };
334 }
335 else
337 m_type = type;
338 //m_texture_filename = texture_filename;
340 //BBS add default bed
341 m_triangles.reset();
342 if (with_reset) {
343 //m_texture.reset();
344 m_model.reset();
345 }
346 //BBS: add part plate logic, always update model offset
347 update_model_offset();//include m_extended_bounding_box = this->calc_extended_bounding_box();
348
349 // Set the origin and size for rendering the coordinate system axes.
350 m_axes.set_origin({ 0.0, 0.0, static_cast<double>(GROUND_Z) });
351 m_axes.set_stem_length(0.1f * static_cast<float>(m_build_volume.bounding_volume().max_size()));
352
353 // unregister from picking
354 // BBS: remove the bed picking logic
355 // wxGetApp().plater()->canvas3D()->remove_raycasters_for_picking(SceneRaycaster::EType::Bed);
356
357 // Let the calee to update the UI.
358 return true;
359}
Type
Definition 3DBed.hpp:94
static std::tuple< Type, std::string, std::string > detect_type(const Pointfs &shape)
Definition 3DBed.cpp:457
zaa_minimize_perimeter_height printable_area((ConfigOptionPointsGroups, extruder_printable_area))((ConfigOptionBool
std::vector< Vec2d > Pointfs
Definition Point.hpp:77
zaa_minimize_perimeter_height printable_height((ConfigOptionFloatsNullable, extruder_printable_height))((ConfigOptionPoint
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References Custom, detect_type(), GROUND_Z, m_axes, m_bed_shape, m_build_volume, m_extruder_heights, m_extruder_shapes, m_model, m_model_filename, m_position, m_triangles, m_type, Slic3r::GUI::model_filename, Slic3r::printable_area(), Slic3r::printable_height(), and update_model_offset().

Referenced by set_position().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_bed_triangles()

void Slic3r::GUI::Bed3D::update_bed_triangles ( )
private
664{
665 if (m_triangles.is_initialized()) {
666 return;
667 }
668
669 Vec3d shift = m_extended_bounding_box.center();
670 shift(2) = -0.03;
671 Vec3d* model_offset_ptr = const_cast<Vec3d*>(&m_model_offset);
672 *model_offset_ptr = shift;
673 //BBS: TODO: hack for default bed
674 BoundingBoxf3 build_volume;
675
676 if (!m_build_volume.valid()) return;
677 auto bed_ext = get_extents(m_bed_shape);
678 (*model_offset_ptr)(0) = m_build_volume.bounding_volume2d().min.x() - bed_ext.min.x();
679 (*model_offset_ptr)(1) = m_build_volume.bounding_volume2d().min.y() - bed_ext.min.y();
680 (*model_offset_ptr)(2) = -0.41 + GROUND_Z;
681
682 std::vector<Vec2d> origin_bed_shape;
683 for (size_t i = 0; i < m_bed_shape.size(); i++) {
684 origin_bed_shape.push_back(m_bed_shape[i]);
685 }
686 std::vector<Vec2d> new_bed_shape; // offset to correct origin
687 for (auto point : origin_bed_shape) {
688 Vec2d new_point(point.x() + model_offset_ptr->x(), point.y() + model_offset_ptr->y());
689 new_bed_shape.push_back(new_point);
690 }
691 ExPolygon poly{ Polygon::new_scale(new_bed_shape) };
693 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to update plate triangles\n";
694 }
695 // update extended bounding box
696 const_cast<BoundingBoxf3 &>(m_printable_bounding_box) = calc_printable_bounding_box();
697 const_cast<BoundingBoxf3 &>(m_extended_bounding_box) = calc_extended_bounding_box();
698}
BoundingBoxf3 calc_printable_bounding_box() const
Definition 3DBed.cpp:423
BoundingBoxf3 calc_extended_bounding_box() const
Definition 3DBed.cpp:443
const BuildVolume & build_volume() const
Definition 3DBed.hpp:148
static Polygon new_scale(const std::vector< Vec2d > &points)
Definition Polygon.hpp:38
void poly(std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
Definition DesignSketchTool.cpp:7751
bool init_model_from_poly(GLModel &model, const ExPolygon &poly, float z)
Definition 3DBed.cpp:54
BoundingBox get_extents(const ExPolygonsWithIds &e)
Definition Emboss.cpp:1374

References build_volume(), calc_extended_bounding_box(), calc_printable_bounding_box(), Slic3r::get_extents(), GROUND_Z, Slic3r::GUI::init_model_from_poly(), m_bed_shape, m_build_volume, m_extended_bounding_box, m_model_offset, m_printable_bounding_box, m_triangles, and Slic3r::Polygon::new_scale().

Referenced by render_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_model_offset()

void Slic3r::GUI::Bed3D::update_model_offset ( )
private
643{
644 // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad
645 Vec3d shift = m_build_volume.bounding_volume().center();
646 shift(2) = -0.03;
647 Vec3d* model_offset_ptr = const_cast<Vec3d*>(&m_model_offset);
648 *model_offset_ptr = shift;
649 //BBS: TODO: hack for current stl for BBL printer
650 if (std::string::npos != m_model_filename.find("bbl-3dp-"))
651 {
652 (*model_offset_ptr)(0) -= m_bed_shape[2].x() / 2.0f;
653 (*model_offset_ptr)(1) -= m_bed_shape[2].y() / 2.0f;
654 }
655 (*model_offset_ptr)(2) = -0.41 + GROUND_Z;
656
657 // update extended bounding box
658 const_cast<BoundingBoxf3 &>(m_printable_bounding_box) = calc_printable_bounding_box();
659 const_cast<BoundingBoxf3 &>(m_extended_bounding_box) = calc_extended_bounding_box();
660 m_triangles.reset();
661}

References calc_extended_bounding_box(), calc_printable_bounding_box(), GROUND_Z, m_bed_shape, m_build_volume, m_extended_bounding_box, m_model_filename, m_model_offset, m_printable_bounding_box, and m_triangles.

Referenced by render_model(), and set_shape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_render_colors()

void Slic3r::GUI::Bed3D::update_render_colors ( )
static

References AXIS_X_COLOR, AXIS_Y_COLOR, AXIS_Z_COLOR, Slic3r::RenderColor::colors, Slic3r::GUI::ImGuiWrapper::from_ImVec4(), RenderCol_Axis_X, RenderCol_Axis_Y, and RenderCol_Axis_Z.

Referenced by Slic3r::GUI::GLCanvas3D::_render_style_editor().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ AXIS_X_COLOR

ColorRGBA Slic3r::GUI::Bed3D::AXIS_X_COLOR = ColorRGBA::X()
static

◆ AXIS_Y_COLOR

ColorRGBA Slic3r::GUI::Bed3D::AXIS_Y_COLOR = ColorRGBA::Y()
static

◆ AXIS_Z_COLOR

ColorRGBA Slic3r::GUI::Bed3D::AXIS_Z_COLOR = ColorRGBA::Z()
static

◆ DEFAULT_MODEL_COLOR

ColorRGBA Slic3r::GUI::Bed3D::DEFAULT_MODEL_COLOR = { 0.3255f, 0.337f, 0.337f, 1.0f }
static

◆ DEFAULT_MODEL_COLOR_DARK

ColorRGBA Slic3r::GUI::Bed3D::DEFAULT_MODEL_COLOR_DARK = { 0.255f, 0.255f, 0.283f, 1.0f }
static

◆ DEFAULT_SOLID_GRID_COLOR

ColorRGBA Slic3r::GUI::Bed3D::DEFAULT_SOLID_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 1.0f }
static

◆ DEFAULT_TRANSPARENT_GRID_COLOR

ColorRGBA Slic3r::GUI::Bed3D::DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 0.6f }
static

◆ m_axes

◆ m_bed_shape

std::vector<Vec2d> Slic3r::GUI::Bed3D::m_bed_shape
private

◆ m_build_volume

◆ m_extended_bounding_box

BoundingBoxf3 Slic3r::GUI::Bed3D::m_extended_bounding_box
private

◆ m_extruder_heights

std::vector<double> Slic3r::GUI::Bed3D::m_extruder_heights
private

Referenced by set_position(), and set_shape().

◆ m_extruder_shapes

std::vector<std::vector<Vec2d> > Slic3r::GUI::Bed3D::m_extruder_shapes
private

Referenced by set_position(), and set_shape().

◆ m_gravity_arrow

GLModel Slic3r::GUI::Bed3D::m_gravity_arrow
private

Referenced by render_gravity_arrow().

◆ m_gravity_arrow_length

float Slic3r::GUI::Bed3D::m_gravity_arrow_length { 0.f }
private
119{ 0.f };

Referenced by render_gravity_arrow().

◆ m_is_dark

bool Slic3r::GUI::Bed3D::m_is_dark = false
private

◆ m_model

GLModel Slic3r::GUI::Bed3D::m_model
private

◆ m_model_filename

std::string Slic3r::GUI::Bed3D::m_model_filename
private

◆ m_model_offset

Vec3d Slic3r::GUI::Bed3D::m_model_offset { Vec3d::Zero() }
private

◆ m_position

Vec2d Slic3r::GUI::Bed3D::m_position { Vec2d::Zero() }
private
124{ Vec2d::Zero() };

Referenced by calc_printable_bounding_box(), get_position(), set_axes_mode(), and set_shape().

◆ m_printable_bounding_box

BoundingBoxf3 Slic3r::GUI::Bed3D::m_printable_bounding_box
private

◆ m_scale_factor

float Slic3r::GUI::Bed3D::m_scale_factor { 1.0f }
private
122{ 1.0f };

Referenced by render_internal().

◆ m_triangles

GLModel Slic3r::GUI::Bed3D::m_triangles
private

◆ m_type

Type Slic3r::GUI::Bed3D::m_type { Type::System }
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/3DBed.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/3DBed.cpp