This commit is contained in:
Vojtech Bubnik 2020-10-15 13:35:53 +02:00
commit d30808c36c
3 changed files with 61 additions and 69 deletions

View file

@ -288,55 +288,10 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Range_Colors {{
{ 0.581f, 0.149f, 0.087f } // reddish
}};
bool GCodeViewer::init()
{
for (size_t i = 0; i < m_buffers.size(); ++i) {
TBuffer& buffer = m_buffers[i];
switch (buffer_type(i))
{
default: { break; }
case EMoveType::Tool_change:
case EMoveType::Color_change:
case EMoveType::Pause_Print:
case EMoveType::Custom_GCode:
case EMoveType::Retract:
case EMoveType::Unretract:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point;
buffer.vertices.format = VBuffer::EFormat::Position;
buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110";
break;
}
case EMoveType::Extrude:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
buffer.shader = "gouraud_light";
break;
}
case EMoveType::Travel:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line;
buffer.vertices.format = VBuffer::EFormat::PositionNormal1;
buffer.shader = "toolpaths_lines";
break;
}
}
}
set_toolpath_move_type_visible(EMoveType::Extrude, true);
m_sequential_view.marker.init();
m_sequential_view.skip_invisible_moves = true;
std::array<int, 2> point_sizes;
::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data());
m_detected_point_sizes = { static_cast<float>(point_sizes[0]), static_cast<float>(point_sizes[1]) };
return true;
}
void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized)
{
init();
// avoid processing if called with the same gcode_result
if (m_last_result_id == gcode_result.id)
return;
@ -898,6 +853,56 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
fclose(fp);
}
void GCodeViewer::init()
{
if (m_initialized)
return;
for (size_t i = 0; i < m_buffers.size(); ++i) {
TBuffer& buffer = m_buffers[i];
switch (buffer_type(i))
{
default: { break; }
case EMoveType::Tool_change:
case EMoveType::Color_change:
case EMoveType::Pause_Print:
case EMoveType::Custom_GCode:
case EMoveType::Retract:
case EMoveType::Unretract:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point;
buffer.vertices.format = VBuffer::EFormat::Position;
buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110";
break;
}
case EMoveType::Extrude:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
buffer.shader = "gouraud_light";
break;
}
case EMoveType::Travel:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line;
buffer.vertices.format = VBuffer::EFormat::PositionNormal1;
buffer.shader = "toolpaths_lines";
break;
}
}
}
set_toolpath_move_type_visible(EMoveType::Extrude, true);
m_sequential_view.marker.init();
m_sequential_view.skip_invisible_moves = true;
std::array<int, 2> point_sizes;
::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data());
m_detected_point_sizes = { static_cast<float>(point_sizes[0]), static_cast<float>(point_sizes[1]) };
m_initialized = true;
}
void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
{
#if ENABLE_GCODE_VIEWER_STATISTICS

View file

@ -387,6 +387,7 @@ public:
};
private:
bool m_initialized{ false };
unsigned int m_last_result_id{ 0 };
size_t m_moves_count{ 0 };
mutable std::vector<TBuffer> m_buffers{ static_cast<size_t>(EMoveType::Extrude) };
@ -415,8 +416,6 @@ public:
GCodeViewer() = default;
~GCodeViewer() { reset(); }
bool init();
// extract rendering data from the given parameters
void load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized);
// recalculate ranges in dependence of what is visible and sets tool/print colors
@ -456,6 +455,7 @@ public:
void export_toolpaths_to_obj(const char* filename) const;
private:
void init();
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
void load_shells(const Print& print, bool initialized);
void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;

View file

@ -1580,13 +1580,6 @@ bool GLCanvas3D::init()
if (m_main_toolbar.is_enabled())
m_layers_editing.init();
#if ENABLE_GCODE_VIEWER
if (!m_main_toolbar.is_enabled()) {
if (!m_gcode_viewer.init())
return false;
}
#endif // ENABLE_GCODE_VIEWER
// on linux the gl context is not valid until the canvas is not shown on screen
// we defer the geometry finalization of volumes until the first call to render()
m_volumes.finalize_geometry(true);
@ -4472,8 +4465,7 @@ static void debug_output_thumbnail(const ThumbnailData& thumbnail_data)
void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const
{
auto is_visible = [](const GLVolume& v) -> bool
{
auto is_visible = [](const GLVolume& v) {
bool ret = v.printable;
ret &= (!v.shader_outside_printer_detection_enabled || !v.is_outside);
return ret;
@ -4484,10 +4476,8 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
GLVolumePtrs visible_volumes;
for (GLVolume* vol : m_volumes.volumes)
{
if (!vol->is_modifier && !vol->is_wipe_tower && (!parts_only || (vol->composite_id.volume_id >= 0)))
{
for (GLVolume* vol : m_volumes.volumes) {
if (!vol->is_modifier && !vol->is_wipe_tower && (!parts_only || (vol->composite_id.volume_id >= 0))) {
if (!printable_only || is_visible(*vol))
visible_volumes.emplace_back(vol);
}
@ -4497,8 +4487,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
return;
BoundingBoxf3 box;
for (const GLVolume* vol : visible_volumes)
{
for (const GLVolume* vol : visible_volumes) {
box.merge(vol->transformed_bounding_box());
}
@ -4512,8 +4501,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
double near_z = -1.0;
double far_z = -1.0;
if (show_bed)
{
if (show_bed) {
// extends the near and far z of the frustrum to avoid the bed being clipped
// box in eye space
@ -4524,7 +4512,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
camera.apply_projection(box, near_z, far_z);
GLShaderProgram* shader = wxGetApp().get_shader("gouraud");
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
if (shader == nullptr)
return;
@ -4537,8 +4525,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
shader->start_using();
shader->set_uniform("print_box.volume_detection", 0);
for (const GLVolume* vol : visible_volumes)
{
for (const GLVolume* vol : visible_volumes) {
shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? orange : gray);
vol->render();
}