Tech ENABLE_COLOR_CLASSES - 1st installment -> Introduction of classes ColorRGB and ColorRGBA to unify color data definition and manipulation

This commit is contained in:
enricoturri1966 2021-12-22 10:45:35 +01:00
parent 48098fbaff
commit cd4094743e
53 changed files with 1810 additions and 60 deletions

View file

@ -7,6 +7,9 @@
#include "libslic3r/TriangleMesh.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Geometry.hpp"
#if ENABLE_COLOR_CLASSES
#include "libslic3r/Color.hpp"
#endif // ENABLE_COLOR_CLASSES
#include "GLModel.hpp"
@ -43,7 +46,11 @@ class ModelVolume;
enum ModelInstanceEPrintVolumeState : unsigned char;
// Return appropriate color based on the ModelVolume.
#if ENABLE_COLOR_CLASSES
extern ColorRGBA color_from_model_volume(const ModelVolume& model_volume);
#else
std::array<float, 4> color_from_model_volume(const ModelVolume& model_volume);
#endif // ENABLE_COLOR_CLASSES
// A container for interleaved arrays of 3D vertices and normals,
// possibly indexed by triangles and / or quads.
@ -248,6 +255,18 @@ private:
class GLVolume {
public:
#if ENABLE_COLOR_CLASSES
static const ColorRGBA SELECTED_COLOR;
static const ColorRGBA HOVER_SELECT_COLOR;
static const ColorRGBA HOVER_DESELECT_COLOR;
static const ColorRGBA OUTSIDE_COLOR;
static const ColorRGBA SELECTED_OUTSIDE_COLOR;
static const ColorRGBA DISABLED_COLOR;
static const ColorRGBA SLA_SUPPORT_COLOR;
static const ColorRGBA SLA_PAD_COLOR;
static const ColorRGBA NEUTRAL_COLOR;
static const std::array<ColorRGBA, 4> MODEL_COLOR;
#else
static const std::array<float, 4> SELECTED_COLOR;
static const std::array<float, 4> HOVER_SELECT_COLOR;
static const std::array<float, 4> HOVER_DESELECT_COLOR;
@ -258,6 +277,7 @@ public:
static const std::array<float, 4> SLA_PAD_COLOR;
static const std::array<float, 4> NEUTRAL_COLOR;
static const std::array<std::array<float, 4>, 4> MODEL_COLOR;
#endif // ENABLE_COLOR_CLASSES
enum EHoverState : unsigned char
{
@ -267,8 +287,12 @@ public:
HS_Deselect
};
GLVolume(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f);
GLVolume(float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f);
#if ENABLE_COLOR_CLASSES
GLVolume(const ColorRGBA& color) : GLVolume(color.r(), color.g(), color.b(), color.a()) {}
#else
GLVolume(const std::array<float, 4>& rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {}
#endif // ENABLE_COLOR_CLASSES
private:
Geometry::Transformation m_instance_transformation;
@ -304,10 +328,17 @@ private:
SinkingContours m_sinking_contours;
public:
#if ENABLE_COLOR_CLASSES
// Color of the triangles / quads held by this volume.
ColorRGBA color;
// Color used to render this volume.
ColorRGBA render_color;
#else
// Color of the triangles / quads held by this volume.
std::array<float, 4> color;
// Color used to render this volume.
std::array<float, 4> render_color;
#endif // ENABLE_COLOR_CLASSES
struct CompositeID {
CompositeID(int object_id, int volume_id, int instance_id) : object_id(object_id), volume_id(volume_id), instance_id(instance_id) {}
@ -393,9 +424,14 @@ public:
return out;
}
#if ENABLE_COLOR_CLASSES
void set_color(const ColorRGBA& rgba) { color = rgba; }
void set_render_color(const ColorRGBA& rgba) { render_color = rgba; }
#else
void set_color(const std::array<float, 4>& rgba);
void set_render_color(float r, float g, float b, float a);
void set_render_color(const std::array<float, 4>& rgba);
#endif // ENABLE_COLOR_CLASSES
// Sets render color in dependence of current state
void set_render_color();
// set color according to model volume
@ -595,8 +631,13 @@ public:
int load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized);
#if ENABLE_COLOR_CLASSES
GLVolume* new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0);
GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0);
#else
GLVolume* new_toolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats = 0);
GLVolume* new_nontoolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats = 0);
#endif // ENABLE_COLOR_CLASSES
// Render the volumes by OpenGL.
void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;