Tech ENABLE_COLOR_CLASSES - 1st installment -> Introduction of classes ColorRGB and ColorRGBA to unify color data definition and manipulation
This commit is contained in:
parent
48098fbaff
commit
cd4094743e
53 changed files with 1810 additions and 60 deletions
|
@ -72,11 +72,18 @@
|
|||
|
||||
static constexpr const float TRACKBALLSIZE = 0.8f;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
static const Slic3r::ColorRGB DEFAULT_BG_DARK_COLOR = { 0.478f, 0.478f, 0.478f };
|
||||
static const Slic3r::ColorRGB DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f };
|
||||
static const Slic3r::ColorRGB ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f };
|
||||
static const Slic3r::ColorRGB ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f };
|
||||
#else
|
||||
static constexpr const float DEFAULT_BG_DARK_COLOR[3] = { 0.478f, 0.478f, 0.478f };
|
||||
static constexpr const float DEFAULT_BG_LIGHT_COLOR[3] = { 0.753f, 0.753f, 0.753f };
|
||||
static constexpr const float ERROR_BG_DARK_COLOR[3] = { 0.478f, 0.192f, 0.039f };
|
||||
static constexpr const float ERROR_BG_LIGHT_COLOR[3] = { 0.753f, 0.192f, 0.039f };
|
||||
//static constexpr const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
// Number of floats
|
||||
static constexpr const size_t MAX_VERTEX_BUFFER_SIZE = 131072 * 6; // 3.15MB
|
||||
|
@ -859,8 +866,13 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons
|
|||
|
||||
void GLCanvas3D::SequentialPrintClearance::render()
|
||||
{
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const ColorRGBA FILL_COLOR = { 1.0f, 0.0f, 0.0f, 0.5f };
|
||||
const ColorRGBA NO_FILL_COLOR = { 1.0f, 1.0f, 1.0f, 0.75f };
|
||||
#else
|
||||
std::array<float, 4> FILL_COLOR = { 1.0f, 0.0f, 0.0f, 0.5f };
|
||||
std::array<float, 4> NO_FILL_COLOR = { 1.0f, 1.0f, 1.0f, 0.75f };
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
|
||||
if (shader == nullptr)
|
||||
|
@ -4119,8 +4131,10 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const
|
|||
return ret;
|
||||
};
|
||||
|
||||
#if !ENABLE_COLOR_CLASSES
|
||||
static const std::array<float, 4> orange = { 0.923f, 0.504f, 0.264f, 1.0f };
|
||||
static const std::array<float, 4> gray = { 0.64f, 0.64f, 0.64f, 1.0f };
|
||||
#endif // !ENABLE_COLOR_CLASSES
|
||||
|
||||
GLVolumePtrs visible_volumes;
|
||||
|
||||
|
@ -4176,7 +4190,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const
|
|||
shader->set_uniform("emission_factor", 0.0f);
|
||||
|
||||
for (GLVolume* vol : visible_volumes) {
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY());
|
||||
#else
|
||||
shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : orange) : gray);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
// the volume may have been deactivated by an active gizmo
|
||||
bool is_active = vol->is_active;
|
||||
vol->is_active = true;
|
||||
|
@ -4907,19 +4925,34 @@ void GLCanvas3D::_picking_pass()
|
|||
int volume_id = -1;
|
||||
int gizmo_id = -1;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
std::array<GLubyte, 4> color = { 0, 0, 0, 0 };
|
||||
#else
|
||||
GLubyte color[4] = { 0, 0, 0, 0 };
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
const Size& cnv_size = get_canvas_size();
|
||||
bool inside = 0 <= m_mouse.position(0) && m_mouse.position(0) < cnv_size.get_width() && 0 <= m_mouse.position(1) && m_mouse.position(1) < cnv_size.get_height();
|
||||
if (inside) {
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
glsafe(::glReadPixels(m_mouse.position(0), cnv_size.get_height() - m_mouse.position.y() - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color.data()));
|
||||
#else
|
||||
glsafe(::glReadPixels(m_mouse.position(0), cnv_size.get_height() - m_mouse.position(1) - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color));
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
if (picking_checksum_alpha_channel(color[0], color[1], color[2]) == color[3]) {
|
||||
// Only non-interpolated colors are valid, those have their lowest three bits zeroed.
|
||||
// we reserve color = (0,0,0) for occluders (as the printbed)
|
||||
// volumes' id are shifted by 1
|
||||
// see: _render_volumes_for_picking()
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
unsigned int id = picking_encode(color[0], color[1], color[2]);
|
||||
volume_id = id - 1;
|
||||
// gizmos' id are instead properly encoded by the color
|
||||
gizmo_id = id;
|
||||
#else
|
||||
volume_id = color[0] + (color[1] << 8) + (color[2] << 16) - 1;
|
||||
// gizmos' id are instead properly encoded by the color
|
||||
gizmo_id = color[0] + (color[1] << 8) + (color[2] << 16);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
}
|
||||
}
|
||||
if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) {
|
||||
|
@ -5035,18 +5068,26 @@ void GLCanvas3D::_render_background() const
|
|||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
|
||||
::glBegin(GL_QUADS);
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
::glColor3fv(use_error_color ? ERROR_BG_DARK_COLOR.data(): DEFAULT_BG_DARK_COLOR.data());
|
||||
#else
|
||||
if (use_error_color)
|
||||
::glColor3fv(ERROR_BG_DARK_COLOR);
|
||||
else
|
||||
::glColor3fv(DEFAULT_BG_DARK_COLOR);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
::glVertex2f(-1.0f, -1.0f);
|
||||
::glVertex2f(1.0f, -1.0f);
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
::glColor3fv(use_error_color ? ERROR_BG_LIGHT_COLOR.data() : DEFAULT_BG_LIGHT_COLOR.data());
|
||||
#else
|
||||
if (use_error_color)
|
||||
::glColor3fv(ERROR_BG_LIGHT_COLOR);
|
||||
else
|
||||
::glColor3fv(DEFAULT_BG_LIGHT_COLOR);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
::glVertex2f(1.0f, 1.0f);
|
||||
::glVertex2f(-1.0f, 1.0f);
|
||||
|
@ -5346,13 +5387,18 @@ void GLCanvas3D::_render_volumes_for_picking() const
|
|||
// Object picking mode. Render the object with a color encoding the object index.
|
||||
// we reserve color = (0,0,0) for occluders (as the printbed)
|
||||
// so we shift volumes' id by 1 to get the proper color
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const unsigned int id = 1 + volume.second.first;
|
||||
glsafe(::glColor4fv(picking_decode(id).data()));
|
||||
#else
|
||||
unsigned int id = 1 + volume.second.first;
|
||||
unsigned int r = (id & (0x000000FF << 0)) << 0;
|
||||
unsigned int g = (id & (0x000000FF << 8)) >> 8;
|
||||
unsigned int b = (id & (0x000000FF << 16)) >> 16;
|
||||
unsigned int a = picking_checksum_alpha_channel(r, g, b);
|
||||
glsafe(::glColor4f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255, (GLfloat)a * INV_255));
|
||||
volume.first->render();
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
volume.first->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5771,7 +5817,11 @@ void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume)
|
|||
if (!print->has_skirt() && !print->has_brim())
|
||||
return;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const ColorRGBA color = ColorRGBA::GREENISH();
|
||||
#else
|
||||
const std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
// number of skirt layers
|
||||
size_t total_layer_count = 0;
|
||||
|
@ -5818,7 +5868,12 @@ void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume)
|
|||
|
||||
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const BuildVolume& build_volume, const std::vector<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& color_print_values)
|
||||
{
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
std::vector<ColorRGBA> tool_colors;
|
||||
decode_colors(str_tool_colors, tool_colors);
|
||||
#else
|
||||
std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
struct Ctxt
|
||||
{
|
||||
|
@ -5827,20 +5882,35 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
bool has_perimeters;
|
||||
bool has_infill;
|
||||
bool has_support;
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const std::vector<ColorRGBA>* tool_colors;
|
||||
#else
|
||||
const std::vector<std::array<float, 4>>* tool_colors;
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
bool is_single_material_print;
|
||||
int extruders_cnt;
|
||||
const std::vector<CustomGCode::Item>* color_print_values;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
static ColorRGBA color_perimeters() { return ColorRGBA::YELLOW(); }
|
||||
static ColorRGBA color_infill() { return ColorRGBA::REDISH(); }
|
||||
static ColorRGBA color_support() { return ColorRGBA::GREENISH(); }
|
||||
static ColorRGBA color_pause_or_custom_code() { return ColorRGBA::GRAY(); }
|
||||
#else
|
||||
static const std::array<float, 4>& color_perimeters() { static std::array<float, 4> color = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow
|
||||
static const std::array<float, 4>& color_infill() { static std::array<float, 4> color = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish
|
||||
static const std::array<float, 4>& color_support() { static std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
|
||||
static const std::array<float, 4>& color_pause_or_custom_code() { static std::array<float, 4> color = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
// For cloring by a tool, return a parsed color.
|
||||
bool color_by_tool() const { return tool_colors != nullptr; }
|
||||
size_t number_tools() const { return color_by_tool() ? tool_colors->size() : 0; }
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const ColorRGBA& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
#else
|
||||
const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
// For coloring by a color_print(M600), return a parsed color.
|
||||
bool color_by_color_print() const { return color_print_values!=nullptr; }
|
||||
|
@ -5980,7 +6050,11 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
//FIXME Improve the heuristics for a grain size.
|
||||
size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1));
|
||||
tbb::spin_mutex new_volume_mutex;
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) {
|
||||
#else
|
||||
auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
// Allocate the volume before locking.
|
||||
GLVolume *volume = new GLVolume(color);
|
||||
volume->is_extrusion_path = true;
|
||||
|
@ -6121,21 +6195,38 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con
|
|||
if (!print->is_step_done(psWipeTower))
|
||||
return;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
std::vector<ColorRGBA> tool_colors;
|
||||
decode_colors(str_tool_colors, tool_colors);
|
||||
#else
|
||||
std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
struct Ctxt
|
||||
{
|
||||
const Print *print;
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const std::vector<ColorRGBA>* tool_colors;
|
||||
#else
|
||||
const std::vector<std::array<float, 4>>* tool_colors;
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
Vec2f wipe_tower_pos;
|
||||
float wipe_tower_angle;
|
||||
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
static ColorRGBA color_support() { return ColorRGBA::GREENISH(); }
|
||||
#else
|
||||
static const std::array<float, 4>& color_support() { static std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
|
||||
// For cloring by a tool, return a parsed color.
|
||||
bool color_by_tool() const { return tool_colors != nullptr; }
|
||||
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() : 0; }
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const ColorRGBA& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
#else
|
||||
const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
int volume_idx(int tool, int feature) const {
|
||||
return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(tool, 0)) : feature;
|
||||
}
|
||||
|
@ -6167,7 +6258,11 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con
|
|||
size_t n_items = print->wipe_tower_data().tool_changes.size() + (ctxt.priming.empty() ? 0 : 1);
|
||||
size_t grain_size = std::max(n_items / 128, size_t(1));
|
||||
tbb::spin_mutex new_volume_mutex;
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) {
|
||||
#else
|
||||
auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
auto *volume = new GLVolume(color);
|
||||
volume->is_extrusion_path = true;
|
||||
tbb::spin_mutex::scoped_lock lock;
|
||||
|
@ -6286,7 +6381,11 @@ void GLCanvas3D::_load_sla_shells()
|
|||
return;
|
||||
|
||||
auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance,
|
||||
#if ENABLE_COLOR_CLASSES
|
||||
const TriangleMesh& mesh, const ColorRGBA& color, bool outside_printer_detection_enabled) {
|
||||
#else
|
||||
const TriangleMesh& mesh, const std::array<float, 4>& color, bool outside_printer_detection_enabled) {
|
||||
#endif // ENABLE_COLOR_CLASSES
|
||||
m_volumes.volumes.emplace_back(new GLVolume(color));
|
||||
GLVolume& v = *m_volumes.volumes.back();
|
||||
#if ENABLE_SMOOTH_NORMALS
|
||||
|
@ -6348,6 +6447,7 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning)
|
|||
_set_warning_notification(warning, show);
|
||||
}
|
||||
|
||||
#if !ENABLE_COLOR_CLASSES
|
||||
std::vector<std::array<float, 4>> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||
{
|
||||
static const float INV_255 = 1.0f / 255.0f;
|
||||
|
@ -6369,6 +6469,7 @@ std::vector<std::array<float, 4>> GLCanvas3D::_parse_colors(const std::vector<st
|
|||
}
|
||||
return output;
|
||||
}
|
||||
#endif // !ENABLE_COLOR_CLASSES
|
||||
|
||||
void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue