mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 13:47:59 -06:00
3DScene layer height profile rendering moved to c++
This commit is contained in:
parent
f31c55ceed
commit
70664122af
8 changed files with 112 additions and 51 deletions
|
@ -1874,7 +1874,7 @@ sub draw_active_object_annotations {
|
||||||
$self->{layer_height_edit_shader}->disable;
|
$self->{layer_height_edit_shader}->disable;
|
||||||
|
|
||||||
#==============================================================================================================================
|
#==============================================================================================================================
|
||||||
Slic3r::GUI::_3DScene::render_layer_editing_textures($self);
|
Slic3r::GUI::_3DScene::render_layer_editing_textures($self, $print_object);
|
||||||
|
|
||||||
# # Paint the tooltip.
|
# # Paint the tooltip.
|
||||||
# if ($self->_variable_layer_thickness_load_overlay_image)
|
# if ($self->_variable_layer_thickness_load_overlay_image)
|
||||||
|
@ -1887,43 +1887,43 @@ sub draw_active_object_annotations {
|
||||||
# if ($self->_variable_layer_thickness_load_reset_image) {
|
# if ($self->_variable_layer_thickness_load_reset_image) {
|
||||||
# $self->_render_image($self->{layer_preview_reset_image}, $reset_left, $reset_right, $reset_bottom, $reset_top);
|
# $self->_render_image($self->{layer_preview_reset_image}, $reset_left, $reset_right, $reset_bottom, $reset_top);
|
||||||
# }
|
# }
|
||||||
|
#
|
||||||
|
# # Paint the graph.
|
||||||
|
# #FIXME show some kind of legend.
|
||||||
|
# my $max_z = unscale($print_object->size->z);
|
||||||
|
# my $profile = $print_object->model_object->layer_height_profile;
|
||||||
|
# my $layer_height = $print_object->config->get('layer_height');
|
||||||
|
# my $layer_height_max = 10000000000.;
|
||||||
|
# {
|
||||||
|
# # Get a maximum layer height value.
|
||||||
|
# #FIXME This is a duplicate code of Slicing.cpp.
|
||||||
|
# my $nozzle_diameters = $print_object->print->config->get('nozzle_diameter');
|
||||||
|
# my $layer_heights_min = $print_object->print->config->get('min_layer_height');
|
||||||
|
# my $layer_heights_max = $print_object->print->config->get('max_layer_height');
|
||||||
|
# for (my $i = 0; $i < scalar(@{$nozzle_diameters}); $i += 1) {
|
||||||
|
# my $lh_min = ($layer_heights_min->[$i] == 0.) ? 0.07 : max(0.01, $layer_heights_min->[$i]);
|
||||||
|
# my $lh_max = ($layer_heights_max->[$i] == 0.) ? (0.75 * $nozzle_diameters->[$i]) : $layer_heights_max->[$i];
|
||||||
|
# $layer_height_max = min($layer_height_max, max($lh_min, $lh_max));
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# # Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region.
|
||||||
|
# $layer_height_max *= 1.12;
|
||||||
|
# # Baseline
|
||||||
|
# glColor3f(0., 0., 0.);
|
||||||
|
# glBegin(GL_LINE_STRIP);
|
||||||
|
# glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom);
|
||||||
|
# glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_top);
|
||||||
|
# glEnd();
|
||||||
|
# # Curve
|
||||||
|
# glColor3f(0., 0., 1.);
|
||||||
|
# glBegin(GL_LINE_STRIP);
|
||||||
|
# for (my $i = 0; $i < int(@{$profile}); $i += 2) {
|
||||||
|
# my $z = $profile->[$i];
|
||||||
|
# my $h = $profile->[$i+1];
|
||||||
|
# glVertex3f($bar_left + $h * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom + $z * ($bar_top - $bar_bottom) / $max_z, $z);
|
||||||
|
# }
|
||||||
|
# glEnd();
|
||||||
#==============================================================================================================================
|
#==============================================================================================================================
|
||||||
|
|
||||||
# Paint the graph.
|
|
||||||
#FIXME show some kind of legend.
|
|
||||||
my $max_z = unscale($print_object->size->z);
|
|
||||||
my $profile = $print_object->model_object->layer_height_profile;
|
|
||||||
my $layer_height = $print_object->config->get('layer_height');
|
|
||||||
my $layer_height_max = 10000000000.;
|
|
||||||
{
|
|
||||||
# Get a maximum layer height value.
|
|
||||||
#FIXME This is a duplicate code of Slicing.cpp.
|
|
||||||
my $nozzle_diameters = $print_object->print->config->get('nozzle_diameter');
|
|
||||||
my $layer_heights_min = $print_object->print->config->get('min_layer_height');
|
|
||||||
my $layer_heights_max = $print_object->print->config->get('max_layer_height');
|
|
||||||
for (my $i = 0; $i < scalar(@{$nozzle_diameters}); $i += 1) {
|
|
||||||
my $lh_min = ($layer_heights_min->[$i] == 0.) ? 0.07 : max(0.01, $layer_heights_min->[$i]);
|
|
||||||
my $lh_max = ($layer_heights_max->[$i] == 0.) ? (0.75 * $nozzle_diameters->[$i]) : $layer_heights_max->[$i];
|
|
||||||
$layer_height_max = min($layer_height_max, max($lh_min, $lh_max));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region.
|
|
||||||
$layer_height_max *= 1.12;
|
|
||||||
# Baseline
|
|
||||||
glColor3f(0., 0., 0.);
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom);
|
|
||||||
glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_top);
|
|
||||||
glEnd();
|
|
||||||
# Curve
|
|
||||||
glColor3f(0., 0., 1.);
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
for (my $i = 0; $i < int(@{$profile}); $i += 2) {
|
|
||||||
my $z = $profile->[$i];
|
|
||||||
my $h = $profile->[$i+1];
|
|
||||||
glVertex3f($bar_left + $h * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom + $z * ($bar_top - $bar_bottom) / $max_z, $z);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
# Revert the matrices.
|
# Revert the matrices.
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
|
@ -2065,9 +2065,10 @@ void _3DScene::render_legend_texture(wxGLCanvas* canvas)
|
||||||
s_canvas_mgr.render_legend_texture(canvas);
|
s_canvas_mgr.render_legend_texture(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _3DScene::render_layer_editing_textures(wxGLCanvas* canvas)
|
void _3DScene::render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject* print_object)
|
||||||
{
|
{
|
||||||
s_canvas_mgr.render_layer_editing_textures(canvas);
|
if (print_object != nullptr)
|
||||||
|
s_canvas_mgr.render_layer_editing_textures(canvas, *print_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _3DScene::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
|
void _3DScene::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
|
||||||
|
|
|
@ -631,7 +631,7 @@ public:
|
||||||
static void render_cutting_plane(wxGLCanvas* canvas);
|
static void render_cutting_plane(wxGLCanvas* canvas);
|
||||||
static void render_warning_texture(wxGLCanvas* canvas);
|
static void render_warning_texture(wxGLCanvas* canvas);
|
||||||
static void render_legend_texture(wxGLCanvas* canvas);
|
static void render_legend_texture(wxGLCanvas* canvas);
|
||||||
static void render_layer_editing_textures(wxGLCanvas* canvas);
|
static void render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject* print_object);
|
||||||
|
|
||||||
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
|
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../../slic3r/GUI/GLShader.hpp"
|
#include "../../slic3r/GUI/GLShader.hpp"
|
||||||
#include "../../libslic3r/ClipperUtils.hpp"
|
#include "../../libslic3r/ClipperUtils.hpp"
|
||||||
#include "../../libslic3r/PrintConfig.hpp"
|
#include "../../libslic3r/PrintConfig.hpp"
|
||||||
|
#include "../../libslic3r/Print.hpp"
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
@ -538,12 +539,13 @@ bool GLCanvas3D::LayersEditing::is_enabled() const
|
||||||
return m_enabled;
|
return m_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3D::LayersEditing::render(const GLCanvas3D& canvas) const
|
void GLCanvas3D::LayersEditing::render(const GLCanvas3D& canvas, const PrintObject& print_object) const
|
||||||
{
|
{
|
||||||
const Rect& bar_rect = _get_bar_rect_viewport(canvas);
|
const Rect& bar_rect = _get_bar_rect_viewport(canvas);
|
||||||
const Rect& reset_rect = _get_reset_rect_viewport(canvas);
|
const Rect& reset_rect = _get_reset_rect_viewport(canvas);
|
||||||
_render_tooltip_texture(canvas, bar_rect, reset_rect);
|
_render_tooltip_texture(canvas, bar_rect, reset_rect);
|
||||||
_render_reset_texture(canvas, reset_rect);
|
_render_reset_texture(canvas, reset_rect);
|
||||||
|
_render_profile(print_object, bar_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLCanvas3D::LayersEditing::GLTextureData GLCanvas3D::LayersEditing::_load_texture_from_file(const std::string& filename) const
|
GLCanvas3D::LayersEditing::GLTextureData GLCanvas3D::LayersEditing::_load_texture_from_file(const std::string& filename) const
|
||||||
|
@ -629,6 +631,61 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const GLCanvas3D& canvas,
|
||||||
canvas.render_texture(m_reset_texture.id, reset_rect.get_left(), reset_rect.get_right(), reset_rect.get_bottom(), reset_rect.get_top());
|
canvas.render_texture(m_reset_texture.id, reset_rect.get_left(), reset_rect.get_right(), reset_rect.get_bottom(), reset_rect.get_top());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, const Rect& bar_rect) const
|
||||||
|
{
|
||||||
|
// FIXME show some kind of legend.
|
||||||
|
|
||||||
|
// Get a maximum layer height value.
|
||||||
|
// FIXME This is a duplicate code of Slicing.cpp.
|
||||||
|
double layer_height_max = DBL_MAX;
|
||||||
|
const PrintConfig& print_config = print_object.print()->config;
|
||||||
|
const std::vector<double>& nozzle_diameters = dynamic_cast<const ConfigOptionFloats*>(print_config.option("nozzle_diameter"))->values;
|
||||||
|
const std::vector<double>& layer_heights_min = dynamic_cast<const ConfigOptionFloats*>(print_config.option("min_layer_height"))->values;
|
||||||
|
const std::vector<double>& layer_heights_max = dynamic_cast<const ConfigOptionFloats*>(print_config.option("max_layer_height"))->values;
|
||||||
|
for (unsigned int i = 0; i < (unsigned int)nozzle_diameters.size(); ++i)
|
||||||
|
{
|
||||||
|
double lh_min = (layer_heights_min[i] == 0.0) ? 0.07 : std::max(0.01, layer_heights_min[i]);
|
||||||
|
double lh_max = (layer_heights_max[i] == 0.0) ? (0.75 * nozzle_diameters[i]) : layer_heights_max[i];
|
||||||
|
layer_height_max = std::min(layer_height_max, std::max(lh_min, lh_max));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region.
|
||||||
|
layer_height_max *= 1.12;
|
||||||
|
|
||||||
|
coordf_t max_z = unscale(print_object.size.z);
|
||||||
|
double layer_height = dynamic_cast<const ConfigOptionFloat*>(print_object.config.option("layer_height"))->value;
|
||||||
|
float l = bar_rect.get_left();
|
||||||
|
float w = bar_rect.get_right() - l;
|
||||||
|
float b = bar_rect.get_bottom();
|
||||||
|
float t = bar_rect.get_top();
|
||||||
|
float h = t - b;
|
||||||
|
float scale_x = w / (float)layer_height_max;
|
||||||
|
float scale_y = h / (float)max_z;
|
||||||
|
float x = l + (float)layer_height * scale_x;
|
||||||
|
|
||||||
|
// Baseline
|
||||||
|
::glColor3f(0.0f, 0.0f, 0.0f);
|
||||||
|
::glBegin(GL_LINE_STRIP);
|
||||||
|
::glVertex2f(x, b);
|
||||||
|
::glVertex2f(x, t);
|
||||||
|
::glEnd();
|
||||||
|
|
||||||
|
// Curve
|
||||||
|
const ModelObject* model_object = print_object.model_object();
|
||||||
|
if (model_object->layer_height_profile_valid)
|
||||||
|
{
|
||||||
|
const std::vector<coordf_t>& profile = model_object->layer_height_profile;
|
||||||
|
|
||||||
|
::glColor3f(0.0f, 0.0f, 1.0f);
|
||||||
|
::glBegin(GL_LINE_STRIP);
|
||||||
|
for (unsigned int i = 0; i < profile.size(); i += 2)
|
||||||
|
{
|
||||||
|
::glVertex2f(l + (float)profile[i + 1] * scale_x, b + (float)profile[i] * scale_y);
|
||||||
|
}
|
||||||
|
::glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) const
|
Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) const
|
||||||
{
|
{
|
||||||
const Size& cnv_size = canvas.get_canvas_size();
|
const Size& cnv_size = canvas.get_canvas_size();
|
||||||
|
@ -1478,9 +1535,9 @@ void GLCanvas3D::render_legend_texture() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3D::render_layer_editing_textures() const
|
void GLCanvas3D::render_layer_editing_textures(const PrintObject& print_object) const
|
||||||
{
|
{
|
||||||
m_layers_editing.render(*this);
|
m_layers_editing.render(*this, print_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const
|
void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const
|
||||||
|
|
|
@ -17,6 +17,7 @@ class GLVolumeCollection;
|
||||||
class DynamicPrintConfig;
|
class DynamicPrintConfig;
|
||||||
class GLShader;
|
class GLShader;
|
||||||
class ExPolygon;
|
class ExPolygon;
|
||||||
|
class PrintObject;
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -195,12 +196,13 @@ public:
|
||||||
|
|
||||||
bool is_enabled() const;
|
bool is_enabled() const;
|
||||||
|
|
||||||
void render(const GLCanvas3D& canvas) const;
|
void render(const GLCanvas3D& canvas, const PrintObject& print_object) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLTextureData _load_texture_from_file(const std::string& filename) const;
|
GLTextureData _load_texture_from_file(const std::string& filename) const;
|
||||||
void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const;
|
void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const;
|
||||||
void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const;
|
void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const;
|
||||||
|
void _render_profile(const PrintObject& print_object, const Rect& bar_rect) const;
|
||||||
Rect _get_bar_rect_screen(const GLCanvas3D& canvas) const;
|
Rect _get_bar_rect_screen(const GLCanvas3D& canvas) const;
|
||||||
Rect _get_reset_rect_screen(const GLCanvas3D& canvas) const;
|
Rect _get_reset_rect_screen(const GLCanvas3D& canvas) const;
|
||||||
Rect _get_bar_rect_viewport(const GLCanvas3D& canvas) const;
|
Rect _get_bar_rect_viewport(const GLCanvas3D& canvas) const;
|
||||||
|
@ -363,7 +365,7 @@ public:
|
||||||
void render_cutting_plane() const;
|
void render_cutting_plane() const;
|
||||||
void render_warning_texture() const;
|
void render_warning_texture() const;
|
||||||
void render_legend_texture() const;
|
void render_legend_texture() const;
|
||||||
void render_layer_editing_textures() const;
|
void render_layer_editing_textures(const PrintObject& print_object) const;
|
||||||
|
|
||||||
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const;
|
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const;
|
||||||
|
|
||||||
|
|
|
@ -560,11 +560,11 @@ void GLCanvas3DManager::render_legend_texture(wxGLCanvas* canvas) const
|
||||||
it->second->render_legend_texture();
|
it->second->render_legend_texture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3DManager::render_layer_editing_textures(wxGLCanvas* canvas) const
|
void GLCanvas3DManager::render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject& print_object) const
|
||||||
{
|
{
|
||||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||||
if (it != m_canvases.end())
|
if (it != m_canvases.end())
|
||||||
it->second->render_layer_editing_textures();
|
it->second->render_layer_editing_textures(print_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3DManager::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const
|
void GLCanvas3DManager::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const
|
||||||
|
|
|
@ -139,7 +139,7 @@ public:
|
||||||
void render_cutting_plane(wxGLCanvas* canvas) const;
|
void render_cutting_plane(wxGLCanvas* canvas) const;
|
||||||
void render_warning_texture(wxGLCanvas* canvas) const;
|
void render_warning_texture(wxGLCanvas* canvas) const;
|
||||||
void render_legend_texture(wxGLCanvas* canvas) const;
|
void render_legend_texture(wxGLCanvas* canvas) const;
|
||||||
void render_layer_editing_textures(wxGLCanvas* canvas) const;
|
void render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject& print_object) const;
|
||||||
|
|
||||||
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const;
|
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const;
|
||||||
|
|
||||||
|
|
|
@ -633,10 +633,11 @@ render_legend_texture(canvas)
|
||||||
_3DScene::render_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
|
_3DScene::render_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
|
||||||
|
|
||||||
void
|
void
|
||||||
render_layer_editing_textures(canvas)
|
render_layer_editing_textures(canvas, print_object)
|
||||||
SV *canvas;
|
SV *canvas;
|
||||||
|
PrintObject *print_object;
|
||||||
CODE:
|
CODE:
|
||||||
_3DScene::render_layer_editing_textures((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
|
_3DScene::render_layer_editing_textures((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), print_object);
|
||||||
|
|
||||||
void
|
void
|
||||||
render_texture(canvas, tex_id, left, right, bottom, top)
|
render_texture(canvas, tex_id, left, right, bottom, top)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue