GCodeViewer -> Fixed incorrect detection of out of printbed for toolpaths
This commit is contained in:
parent
ab107969db
commit
648ecb47c2
3 changed files with 30 additions and 24 deletions
|
@ -148,7 +148,6 @@ void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& positi
|
|||
{
|
||||
m_world_position = position;
|
||||
m_world_transform = (Geometry::assemble_transform((position + m_z_offset * Vec3f::UnitZ()).cast<double>()) * Geometry::assemble_transform(m_model.get_bounding_box().size()[2] * Vec3d::UnitZ(), { M_PI, 0.0, 0.0 })).cast<float>();
|
||||
m_world_bounding_box = m_model.get_bounding_box().transformed(m_world_transform.cast<double>());
|
||||
}
|
||||
|
||||
void GCodeViewer::SequentialView::Marker::render() const
|
||||
|
@ -288,10 +287,10 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
|
|||
|
||||
#if ENABLE_GCODE_VIEWER_AS_STATE
|
||||
if (wxGetApp().mainframe->get_mode() == MainFrame::EMode::GCodeViewer) {
|
||||
// adjust printbed size
|
||||
// adjust printbed size in dependence of toolpaths bbox
|
||||
const double margin = 10.0;
|
||||
Vec2d min(m_bounding_box.min(0) - margin, m_bounding_box.min(1) - margin);
|
||||
Vec2d max(m_bounding_box.max(0) + margin, m_bounding_box.max(1) + margin);
|
||||
Vec2d min(m_paths_bounding_box.min(0) - margin, m_paths_bounding_box.min(1) - margin);
|
||||
Vec2d max(m_paths_bounding_box.max(0) + margin, m_paths_bounding_box.max(1) + margin);
|
||||
Pointfs bed_shape = { { min(0), min(1) },
|
||||
{ max(0), min(1) },
|
||||
{ max(0), max(1) },
|
||||
|
@ -359,7 +358,8 @@ void GCodeViewer::reset()
|
|||
buffer.reset();
|
||||
}
|
||||
|
||||
m_bounding_box = BoundingBoxf3();
|
||||
m_paths_bounding_box = BoundingBoxf3();
|
||||
m_max_bounding_box = BoundingBoxf3();
|
||||
m_tool_colors = std::vector<Color>();
|
||||
m_extruder_ids = std::vector<unsigned char>();
|
||||
m_extrusions.reset_role_visibility_flags();
|
||||
|
@ -497,18 +497,19 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
const GCodeProcessor::MoveVertex& move = gcode_result.moves[i];
|
||||
#if ENABLE_GCODE_VIEWER_AS_STATE
|
||||
if (wxGetApp().mainframe->get_mode() == MainFrame::EMode::GCodeViewer)
|
||||
m_bounding_box.merge(move.position.cast<double>());
|
||||
// for the gcode viewer we need all moves to correctly size the printbed
|
||||
m_paths_bounding_box.merge(move.position.cast<double>());
|
||||
else {
|
||||
#endif // ENABLE_GCODE_VIEWER_AS_STATE
|
||||
if (move.type == GCodeProcessor::EMoveType::Extrude && move.width != 0.0f && move.height != 0.0f)
|
||||
m_bounding_box.merge(move.position.cast<double>());
|
||||
m_paths_bounding_box.merge(move.position.cast<double>());
|
||||
#if ENABLE_GCODE_VIEWER_AS_STATE
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_AS_STATE
|
||||
::memcpy(static_cast<void*>(&vertices_data[i * 3]), static_cast<const void*>(move.position.data()), 3 * sizeof(float));
|
||||
}
|
||||
|
||||
m_bounding_box.merge(m_bounding_box.max + m_sequential_view.marker.get_bounding_box().max[2] * Vec3d::UnitZ());
|
||||
m_max_bounding_box.merge(m_paths_bounding_box.max + m_sequential_view.marker.get_bounding_box().max[2] * Vec3d::UnitZ());
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
m_statistics.vertices_size = SLIC3R_STDVEC_MEMSIZE(vertices_data, float);
|
||||
|
@ -578,7 +579,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
// indices data -> send data to gpu
|
||||
for (size_t i = 0; i < m_buffers.size(); ++i) {
|
||||
IBuffer& buffer = m_buffers[i];
|
||||
std::vector<unsigned int>& buffer_indices = indices[i];
|
||||
const std::vector<unsigned int>& buffer_indices = indices[i];
|
||||
buffer.indices_count = buffer_indices.size();
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
m_statistics.indices_size += SLIC3R_STDVEC_MEMSIZE(buffer_indices, unsigned int);
|
||||
|
@ -859,7 +860,6 @@ void GCodeViewer::render_toolpaths() const
|
|||
for (const RenderPath& path : buffer.render_paths)
|
||||
{
|
||||
shader.set_uniform("uniform_color", path.color);
|
||||
// glsafe(::glMultiDrawElements(GL_LINES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||
glsafe(::glMultiDrawElements(GL_LINE_STRIP, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.gl_multi_line_strip_calls_count;
|
||||
|
@ -878,8 +878,8 @@ void GCodeViewer::render_toolpaths() const
|
|||
unsigned char end_id = buffer_id(GCodeProcessor::EMoveType::Count);
|
||||
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vertices.vbo_id));
|
||||
glsafe(::glVertexPointer(3, GL_FLOAT, VBuffer::vertex_size_bytes(), (const void*)0));
|
||||
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
|
||||
glsafe(::glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, VBuffer::vertex_size_bytes(), (const void*)0));
|
||||
glsafe(::glEnableVertexAttribArray(0));
|
||||
|
||||
for (unsigned char i = begin_id; i < end_id; ++i) {
|
||||
const IBuffer& buffer = m_buffers[i];
|
||||
|
@ -914,7 +914,7 @@ void GCodeViewer::render_toolpaths() const
|
|||
}
|
||||
}
|
||||
|
||||
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
|
||||
glsafe(::glDisableVertexAttribArray(0));
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ class GCodeViewer
|
|||
|
||||
void reset();
|
||||
|
||||
static size_t vertex_size() { return 3; }
|
||||
static size_t vertex_size_bytes() { return vertex_size() * sizeof(float); }
|
||||
static size_t vertex_size_floats() { return 3; }
|
||||
static size_t vertex_size_bytes() { return vertex_size_floats() * sizeof(float); }
|
||||
};
|
||||
|
||||
// Used to identify different toolpath sub-types inside a IBuffer
|
||||
|
@ -160,11 +160,14 @@ class GCodeViewer
|
|||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
struct Statistics
|
||||
{
|
||||
// times
|
||||
long long load_time{ 0 };
|
||||
long long refresh_time{ 0 };
|
||||
long long refresh_paths_time{ 0 };
|
||||
// opengl calls
|
||||
long long gl_multi_points_calls_count{ 0 };
|
||||
long long gl_multi_line_strip_calls_count{ 0 };
|
||||
// memory
|
||||
long long results_size{ 0 };
|
||||
long long vertices_size{ 0 };
|
||||
long long vertices_gpu_size{ 0 };
|
||||
|
@ -220,7 +223,6 @@ public:
|
|||
GLModel m_model;
|
||||
Vec3f m_world_position;
|
||||
Transform3f m_world_transform;
|
||||
BoundingBoxf3 m_world_bounding_box;
|
||||
float m_z_offset{ 0.5f };
|
||||
std::array<float, 4> m_color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
bool m_visible{ false };
|
||||
|
@ -228,7 +230,7 @@ public:
|
|||
public:
|
||||
void init();
|
||||
|
||||
const BoundingBoxf3& get_bounding_box() const { return m_world_bounding_box; }
|
||||
const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); }
|
||||
|
||||
void set_world_position(const Vec3f& position);
|
||||
void set_color(const std::array<float, 4>& color) { m_color = color; }
|
||||
|
@ -268,7 +270,10 @@ private:
|
|||
unsigned int m_last_result_id{ 0 };
|
||||
VBuffer m_vertices;
|
||||
mutable std::vector<IBuffer> m_buffers{ static_cast<size_t>(GCodeProcessor::EMoveType::Extrude) };
|
||||
BoundingBoxf3 m_bounding_box;
|
||||
// bounding box of toolpaths
|
||||
BoundingBoxf3 m_paths_bounding_box;
|
||||
// bounding box of toolpaths + marker tools
|
||||
BoundingBoxf3 m_max_bounding_box;
|
||||
std::vector<Color> m_tool_colors;
|
||||
std::vector<double> m_layers_zs;
|
||||
std::array<double, 2> m_layers_z_range;
|
||||
|
@ -303,7 +308,8 @@ public:
|
|||
|
||||
bool has_data() const { return !m_roles.empty(); }
|
||||
|
||||
const BoundingBoxf3& get_bounding_box() const { return m_bounding_box; }
|
||||
const BoundingBoxf3& get_paths_bounding_box() const { return m_paths_bounding_box; }
|
||||
const BoundingBoxf3& get_max_bounding_box() const { return m_max_bounding_box; }
|
||||
const std::vector<double>& get_layers_zs() const { return m_layers_zs; };
|
||||
|
||||
const SequentialView& get_sequential_view() const { return m_sequential_view; }
|
||||
|
|
|
@ -1933,7 +1933,7 @@ void GLCanvas3D::zoom_to_selection()
|
|||
#if ENABLE_GCODE_VIEWER_AS_STATE
|
||||
void GLCanvas3D::zoom_to_gcode()
|
||||
{
|
||||
_zoom_to_box(m_gcode_viewer.get_bounding_box(), 1.05);
|
||||
_zoom_to_box(m_gcode_viewer.get_paths_bounding_box(), 1.05);
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_AS_STATE
|
||||
|
||||
|
@ -3108,7 +3108,7 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
|
|||
if (!m_volumes.empty())
|
||||
zoom_to_volumes();
|
||||
else
|
||||
_zoom_to_box(m_gcode_viewer.get_bounding_box());
|
||||
_zoom_to_box(m_gcode_viewer.get_paths_bounding_box());
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -5189,7 +5189,7 @@ BoundingBoxf3 GLCanvas3D::_max_bounding_box(bool include_gizmos, bool include_be
|
|||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
if (!m_main_toolbar.is_enabled())
|
||||
bb.merge(m_gcode_viewer.get_bounding_box());
|
||||
bb.merge(m_gcode_viewer.get_max_bounding_box());
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
return bb;
|
||||
|
@ -5385,7 +5385,7 @@ void GLCanvas3D::_render_background() const
|
|||
use_error_color &= _is_any_volume_outside();
|
||||
else {
|
||||
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
|
||||
use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_bounding_box()) : false;
|
||||
use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_paths_bounding_box()) : false;
|
||||
}
|
||||
#if ENABLE_GCODE_VIEWER_AS_STATE
|
||||
}
|
||||
|
@ -7114,7 +7114,7 @@ void GLCanvas3D::_show_warning_texture_if_needed(WarningTexture::Warning warning
|
|||
if (wxGetApp().mainframe->get_mode() != MainFrame::EMode::GCodeViewer)
|
||||
{
|
||||
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
|
||||
const BoundingBoxf3& paths_volume = m_gcode_viewer.get_bounding_box();
|
||||
const BoundingBoxf3& paths_volume = m_gcode_viewer.get_paths_bounding_box();
|
||||
if (test_volume.radius() > 0.0 && paths_volume.radius() > 0.0)
|
||||
show = !test_volume.contains(paths_volume);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue