mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-25 23:57:42 +08:00
GCodeViewer -> Coloring of travel paths
This commit is contained in:
parent
90d5cf1735
commit
81a29169ae
@ -582,7 +582,8 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
|
||||
MoveVertex vertex;
|
||||
vertex.type = type;
|
||||
vertex.extrusion_role = m_extrusion_role;
|
||||
vertex.position = Vec3f(m_end_position[0], m_end_position[1], m_end_position[2]) + m_extruder_offsets[m_extruder_id];
|
||||
vertex.position = Vec3f(m_end_position[X], m_end_position[Y], m_end_position[Z]) + m_extruder_offsets[m_extruder_id];
|
||||
vertex.delta_extruder = m_end_position[E] - m_start_position[E];
|
||||
vertex.feedrate = m_feedrate;
|
||||
vertex.width = m_width;
|
||||
vertex.height = m_height;
|
||||
|
@ -76,6 +76,7 @@ namespace Slic3r {
|
||||
unsigned char extruder_id{ 0 };
|
||||
unsigned char cp_color_id{ 0 };
|
||||
Vec3f position{ Vec3f::Zero() }; // mm
|
||||
float delta_extruder{ 0.0f }; // mm
|
||||
float feedrate{ 0.0f }; // mm/s
|
||||
float width{ 0.0f }; // mm
|
||||
float height{ 0.0f }; // mm
|
||||
|
@ -94,7 +94,7 @@ bool GCodeViewer::IBuffer::init_shader(const std::string& vertex_shader_src, con
|
||||
void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move)
|
||||
{
|
||||
unsigned int id = static_cast<unsigned int>(data.size());
|
||||
paths.push_back({ move.type, move.extrusion_role, id, id, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
|
||||
paths.push_back({ move.type, move.extrusion_role, id, id, move.delta_extruder, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
|
||||
}
|
||||
|
||||
std::array<float, 3> GCodeViewer::Extrusions::Range::get_color_at(float value) const
|
||||
@ -138,6 +138,12 @@ const std::vector<std::array<float, 3>> GCodeViewer::Extrusion_Role_Colors {{
|
||||
{ 0.00f, 0.00f, 0.00f } // erMixed
|
||||
}};
|
||||
|
||||
const std::vector<std::array<float, 3>> GCodeViewer::Travel_Colors {{
|
||||
{ 0.0f, 0.0f, 0.5f }, // Move
|
||||
{ 0.0f, 0.5f, 0.0f }, // Extrude
|
||||
{ 0.5f, 0.0f, 0.0f } // Retract
|
||||
}};
|
||||
|
||||
const std::vector<std::array<float, 3>> GCodeViewer::Range_Colors {{
|
||||
{ 0.043f, 0.173f, 0.478f }, // bluish
|
||||
{ 0.075f, 0.349f, 0.522f },
|
||||
@ -186,14 +192,17 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std:
|
||||
switch (curr.type)
|
||||
{
|
||||
case GCodeProcessor::EMoveType::Extrude:
|
||||
{
|
||||
m_extrusions.ranges.height.update_from(curr.height);
|
||||
m_extrusions.ranges.width.update_from(curr.width);
|
||||
m_extrusions.ranges.fan_speed.update_from(curr.fan_speed);
|
||||
m_extrusions.ranges.volumetric_rate.update_from(curr.volumetric_rate());
|
||||
[[fallthrough]];
|
||||
}
|
||||
case GCodeProcessor::EMoveType::Travel:
|
||||
{
|
||||
if (m_buffers[buffer_id(curr.type)].visible) {
|
||||
m_extrusions.ranges.height.update_from(curr.height);
|
||||
m_extrusions.ranges.width.update_from(curr.width);
|
||||
m_extrusions.ranges.feedrate.update_from(curr.feedrate);
|
||||
m_extrusions.ranges.fan_speed.update_from(curr.fan_speed);
|
||||
m_extrusions.ranges.volumetric_rate.update_from(curr.volumetric_rate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -465,6 +474,12 @@ void GCodeViewer::render_toolpaths() const
|
||||
return color;
|
||||
};
|
||||
|
||||
auto travel_color = [this](const Path& path) {
|
||||
return (path.delta_extruder < 0.0f) ? Travel_Colors[2] /* Retract */ :
|
||||
((path.delta_extruder > 0.0f) ? Travel_Colors[1] /* Extrude */ :
|
||||
Travel_Colors[0] /* Move */);
|
||||
};
|
||||
|
||||
auto set_color = [](GLint current_program_id, const std::array<float, 3>& color) {
|
||||
if (current_program_id > 0) {
|
||||
GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1;
|
||||
@ -577,9 +592,8 @@ void GCodeViewer::render_toolpaths() const
|
||||
}
|
||||
case GCodeProcessor::EMoveType::Travel:
|
||||
{
|
||||
std::array<float, 3> color = { 1.0f, 1.0f, 0.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
set_color(current_program_id, (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path));
|
||||
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint))));
|
||||
}
|
||||
break;
|
||||
|
@ -16,6 +16,7 @@ namespace GUI {
|
||||
class GCodeViewer
|
||||
{
|
||||
static const std::vector<std::array<float, 3>> Extrusion_Role_Colors;
|
||||
static const std::vector<std::array<float, 3>> Travel_Colors;
|
||||
static const std::vector<std::array<float, 3>> Range_Colors;
|
||||
|
||||
// buffer containing vertices data
|
||||
@ -39,6 +40,7 @@ class GCodeViewer
|
||||
ExtrusionRole role{ erNone };
|
||||
unsigned int first{ 0 };
|
||||
unsigned int last{ 0 };
|
||||
float delta_extruder{ 0.0f };
|
||||
float height{ 0.0f };
|
||||
float width{ 0.0f };
|
||||
float feedrate{ 0.0f };
|
||||
|
Loading…
x
Reference in New Issue
Block a user