diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2019-06-14 11:38:09 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2019-06-14 11:38:09 +0300 |
commit | 1a91add2e60f3a4d22cdd6c8a10e57dc8095e0a2 (patch) | |
tree | 711eca9fdaeb3e304ba91667f00eaad21bab61a3 /src/slic3r/GUI/3DBed.cpp | |
parent | a99466ef1df99d52277a5f78a4fbb5481d2dd584 (diff) |
Tighter camera frustrum to reduce z-fighting
Diffstat (limited to 'src/slic3r/GUI/3DBed.cpp')
-rw-r--r-- | src/slic3r/GUI/3DBed.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 8392e534a..c82b34f49 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -273,6 +273,7 @@ void Bed3D::Axes::render_axis(double length) const Bed3D::Bed3D() : m_type(Custom) + , m_extended_bounding_box_dirty(true) #if ENABLE_TEXTURES_FROM_SVG , m_vbo_id(0) #endif // ENABLE_TEXTURES_FROM_SVG @@ -290,7 +291,7 @@ bool Bed3D::set_shape(const Pointfs& shape) m_shape = shape; m_type = new_type; - calc_bounding_box(); + calc_bounding_boxes(); ExPolygon poly; for (const Vec2d& p : m_shape) @@ -311,7 +312,9 @@ bool Bed3D::set_shape(const Pointfs& shape) // Set the origin and size for painting of the coordinate system axes. m_axes.origin = Vec3d(0.0, 0.0, (double)GROUND_Z); - m_axes.length = 0.1 * get_bounding_box().max_size() * Vec3d::Ones(); + m_axes.length = 0.1 * m_bounding_box.max_size() * Vec3d::Ones(); + + m_extended_bounding_box_dirty = true; // Let the calee to update the UI. return true; @@ -400,13 +403,27 @@ void Bed3D::render_axes() const m_axes.render(); } -void Bed3D::calc_bounding_box() +void Bed3D::calc_bounding_boxes() const { m_bounding_box = BoundingBoxf3(); for (const Vec2d& p : m_shape) { m_bounding_box.merge(Vec3d(p(0), p(1), 0.0)); } + + m_extended_bounding_box = m_bounding_box; + + if (m_extended_bounding_box_dirty) + { + // extend to contain Z axis + m_extended_bounding_box.merge(0.1 * m_bounding_box.max_size() * Vec3d::UnitZ()); + + if (!m_model.get_filename().empty()) + // extend to contain model + m_extended_bounding_box.merge(m_model.get_bounding_box()); + + m_extended_bounding_box_dirty = false; + } } void Bed3D::calc_triangles(const ExPolygon& poly) @@ -539,6 +556,9 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const offset += Vec3d(0.0, 0.0, -0.03); m_model.center_around(offset); + + // update extended bounding box + calc_bounding_boxes(); } if (!m_model.get_filename().empty()) |