mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 13:17:54 -06:00
Colors in GLVolume defined as std::array<float, 4>
This commit is contained in:
parent
21abf8d88e
commit
2848ae9c4d
4 changed files with 88 additions and 106 deletions
|
@ -1881,7 +1881,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
|||
volume->extruder_id = extruder_id;
|
||||
|
||||
volume->is_modifier = !mvs->model_volume->is_model_part();
|
||||
volume->set_color_from_model_volume(mvs->model_volume);
|
||||
volume->set_color_from_model_volume(*mvs->model_volume);
|
||||
|
||||
// updates volumes transformations
|
||||
volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation());
|
||||
|
@ -5710,7 +5710,7 @@ void GLCanvas3D::_load_print_toolpaths()
|
|||
if (!print->has_skirt() && !print->has_brim())
|
||||
return;
|
||||
|
||||
const float color[] = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish
|
||||
const std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish
|
||||
|
||||
// number of skirt layers
|
||||
size_t total_layer_count = 0;
|
||||
|
@ -5756,7 +5756,7 @@ void GLCanvas3D::_load_print_toolpaths()
|
|||
|
||||
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& color_print_values)
|
||||
{
|
||||
std::vector<float> tool_colors = _parse_colors(str_tool_colors);
|
||||
std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
|
||||
|
||||
struct Ctxt
|
||||
{
|
||||
|
@ -5765,20 +5765,20 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
bool has_perimeters;
|
||||
bool has_infill;
|
||||
bool has_support;
|
||||
const std::vector<float>* tool_colors;
|
||||
const std::vector<std::array<float, 4>>* tool_colors;
|
||||
bool is_single_material_print;
|
||||
int extruders_cnt;
|
||||
const std::vector<CustomGCode::Item>* color_print_values;
|
||||
|
||||
static const float* color_perimeters() { static float color[4] = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow
|
||||
static const float* color_infill() { static float color[4] = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish
|
||||
static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
|
||||
static const float* color_pause_or_custom_code() { static float color[4] = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray
|
||||
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
|
||||
|
||||
// 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() / 4 : 0; }
|
||||
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
|
||||
size_t number_tools() const { return color_by_tool() ? tool_colors->size() : 0; }
|
||||
const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
|
||||
// For coloring by a color_print(M600), return a parsed color.
|
||||
bool color_by_color_print() const { return color_print_values!=nullptr; }
|
||||
|
@ -5918,8 +5918,8 @@ 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;
|
||||
auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* {
|
||||
// Allocate the volume before locking.
|
||||
auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
|
||||
// Allocate the volume before locking.
|
||||
GLVolume *volume = new GLVolume(color);
|
||||
volume->is_extrusion_path = true;
|
||||
tbb::spin_mutex::scoped_lock lock;
|
||||
|
@ -6056,23 +6056,22 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector<std::string>& str_
|
|||
if (!print->is_step_done(psWipeTower))
|
||||
return;
|
||||
|
||||
std::vector<float> tool_colors = _parse_colors(str_tool_colors);
|
||||
std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
|
||||
|
||||
struct Ctxt
|
||||
{
|
||||
const Print *print;
|
||||
const std::vector<float> *tool_colors;
|
||||
const std::vector<std::array<float, 4>>* tool_colors;
|
||||
Vec2f wipe_tower_pos;
|
||||
float wipe_tower_angle;
|
||||
|
||||
static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
|
||||
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
|
||||
|
||||
// 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() / 4 : 0; }
|
||||
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
|
||||
int volume_idx(int tool, int feature) const
|
||||
{
|
||||
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() : 0; }
|
||||
const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -6103,7 +6102,7 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector<std::string>& str_
|
|||
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;
|
||||
auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* {
|
||||
auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
|
||||
auto *volume = new GLVolume(color);
|
||||
volume->is_extrusion_path = true;
|
||||
tbb::spin_mutex::scoped_lock lock;
|
||||
|
@ -6219,7 +6218,7 @@ void GLCanvas3D::_load_sla_shells()
|
|||
return;
|
||||
|
||||
auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance,
|
||||
const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) {
|
||||
const TriangleMesh& mesh, const std::array<float, 4>& color, bool outside_printer_detection_enabled) {
|
||||
m_volumes.volumes.emplace_back(new GLVolume(color));
|
||||
GLVolume& v = *m_volumes.volumes.back();
|
||||
#if ENABLE_SMOOTH_NORMALS
|
||||
|
@ -6230,8 +6229,8 @@ void GLCanvas3D::_load_sla_shells()
|
|||
v.indexed_vertex_array.finalize_geometry(m_initialized);
|
||||
v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled;
|
||||
v.composite_id.volume_id = volume_id;
|
||||
v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0));
|
||||
v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation));
|
||||
v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0.0));
|
||||
v.set_instance_rotation({ 0.0, 0.0, (double)instance.rotation });
|
||||
v.set_instance_mirror(X, object.is_left_handed() ? -1. : 1.);
|
||||
v.set_convex_hull(mesh.convex_hull_3d());
|
||||
};
|
||||
|
@ -6252,9 +6251,8 @@ void GLCanvas3D::_load_sla_shells()
|
|||
}
|
||||
double shift_z = obj->get_current_elevation();
|
||||
for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) {
|
||||
GLVolume& v = *m_volumes.volumes[i];
|
||||
// apply shift z
|
||||
v.set_sla_shift_z(shift_z);
|
||||
m_volumes.volumes[i]->set_sla_shift_z(shift_z);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6265,7 +6263,7 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state()
|
|||
{
|
||||
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
|
||||
for (GLVolume* volume : m_volumes.volumes) {
|
||||
volume->is_outside = ((test_volume.radius() > 0.0) && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false;
|
||||
volume->is_outside = (test_volume.radius() > 0.0 && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6273,7 +6271,7 @@ void GLCanvas3D::_update_sla_shells_outside_state()
|
|||
{
|
||||
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
|
||||
for (GLVolume* volume : m_volumes.volumes) {
|
||||
volume->is_outside = ((test_volume.radius() > 0.0) && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false;
|
||||
volume->is_outside = (test_volume.radius() > 0.0 && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6294,11 +6292,11 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning)
|
|||
_set_warning_notification(warning, show);
|
||||
}
|
||||
|
||||
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||
std::vector<std::array<float, 4>> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||
{
|
||||
static const float INV_255 = 1.0f / 255.0f;
|
||||
|
||||
std::vector<float> output(colors.size() * 4, 1.0f);
|
||||
std::vector<std::array<float, 4>> output(colors.size(), { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
for (size_t i = 0; i < colors.size(); ++i) {
|
||||
const std::string& color = colors[i];
|
||||
const char* c = color.data() + 1;
|
||||
|
@ -6309,7 +6307,7 @@ std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& col
|
|||
if (digit1 == -1 || digit2 == -1)
|
||||
break;
|
||||
|
||||
output[i * 4 + j] = float(digit1 * 16 + digit2) * INV_255;
|
||||
output[i][j] = float(digit1 * 16 + digit2) * INV_255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue