mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-20 13:33:15 +08:00
ENH:update render code in PartPlate
jira: STUDIO-5985 most of code from OrcaSlicer,thanks for OrcaSlicer and enricoturri1966 commit 28d0147d0988917a8b9d85441b8836453e0f222e Author: enricoturri1966 <enricoturri@seznam.cz> Date: Fri Oct 20 15:41:26 2023 +0800 Introduction of classes ColorRGB and ColorRGBA to unify color data definition and manipulation Change-Id: I94ff38d9a03b4b91183b150617d6407a8ffa279e
This commit is contained in:
parent
0ec49c3588
commit
8c852bc925
8
resources/shaders/110/flat.fs
Normal file
8
resources/shaders/110/flat.fs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#version 110
|
||||||
|
|
||||||
|
uniform vec4 uniform_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = uniform_color;
|
||||||
|
}
|
11
resources/shaders/110/flat.vs
Normal file
11
resources/shaders/110/flat.vs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 110
|
||||||
|
|
||||||
|
uniform mat4 view_model_matrix;
|
||||||
|
uniform mat4 projection_matrix;
|
||||||
|
|
||||||
|
attribute vec3 v_position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||||
|
}
|
@ -1,21 +1,21 @@
|
|||||||
#version 110
|
#version 110
|
||||||
|
|
||||||
const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
|
const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
|
||||||
const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
|
const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform bool transparent_background;
|
uniform bool transparent_background;
|
||||||
uniform bool svg_source;
|
uniform bool svg_source;
|
||||||
|
|
||||||
varying vec2 tex_coords;
|
varying vec2 tex_coord;
|
||||||
|
|
||||||
vec4 svg_color()
|
vec4 svg_color()
|
||||||
{
|
{
|
||||||
// takes foreground from texture
|
// takes foreground from texture
|
||||||
vec4 fore_color = texture2D(texture, tex_coords);
|
vec4 fore_color = texture2D(texture, tex_coord);
|
||||||
|
|
||||||
// calculates radial gradient
|
// calculates radial gradient
|
||||||
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coords.xy) - vec2(0.5)))));
|
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5)))));
|
||||||
|
|
||||||
// blends foreground with background
|
// blends foreground with background
|
||||||
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
|
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
|
||||||
@ -24,7 +24,7 @@ vec4 svg_color()
|
|||||||
vec4 non_svg_color()
|
vec4 non_svg_color()
|
||||||
{
|
{
|
||||||
// takes foreground from texture
|
// takes foreground from texture
|
||||||
vec4 color = texture2D(texture, tex_coords);
|
vec4 color = texture2D(texture, tex_coord);
|
||||||
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
|
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
|
||||||
}
|
}
|
||||||
|
|
15
resources/shaders/110/printbed.vs
Normal file
15
resources/shaders/110/printbed.vs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#version 110
|
||||||
|
|
||||||
|
uniform mat4 view_model_matrix;
|
||||||
|
uniform mat4 projection_matrix;
|
||||||
|
|
||||||
|
attribute vec3 v_position;
|
||||||
|
attribute vec2 v_tex_coord;
|
||||||
|
|
||||||
|
varying vec2 tex_coord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
tex_coord = v_tex_coord;
|
||||||
|
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
#version 110
|
|
||||||
|
|
||||||
attribute vec3 v_position;
|
|
||||||
attribute vec2 v_tex_coords;
|
|
||||||
|
|
||||||
varying vec2 tex_coords;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position.x, v_position.y, v_position.z, 1.0);
|
|
||||||
// the following line leads to crash on some Intel graphics card
|
|
||||||
//gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position, 1.0);
|
|
||||||
tex_coords = v_tex_coords;
|
|
||||||
}
|
|
@ -320,8 +320,14 @@ void Bed3D::on_change_color_mode(bool is_dark)
|
|||||||
m_is_dark = is_dark;
|
m_is_dark = is_dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes)
|
BoundingBoxf3 Bed3D::get_cur_bed_model_box()
|
||||||
{
|
{
|
||||||
|
BoundingBoxf3 model_bb = m_model.get_bounding_box();
|
||||||
|
model_bb.translate(m_model_offset);
|
||||||
|
return model_bb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bed3D::render(GLCanvas3D &canvas, bool bottom, float scale_factor, bool show_axes) {
|
||||||
render_internal(canvas, bottom, scale_factor, show_axes);
|
render_internal(canvas, bottom, scale_factor, show_axes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,7 +564,7 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom) const
|
|||||||
unsigned int stride = m_triangles.get_vertex_data_size();
|
unsigned int stride = m_triangles.get_vertex_data_size();
|
||||||
|
|
||||||
GLint position_id = shader->get_attrib_location("v_position");
|
GLint position_id = shader->get_attrib_location("v_position");
|
||||||
GLint tex_coords_id = shader->get_attrib_location("v_tex_coords");
|
GLint tex_coords_id = shader->get_attrib_location("v_tex_coord");
|
||||||
|
|
||||||
// show the temporary texture while no compressed data is available
|
// show the temporary texture while no compressed data is available
|
||||||
GLuint tex_id = (GLuint)temp_texture->get_id();
|
GLuint tex_id = (GLuint)temp_texture->get_id();
|
||||||
|
@ -133,6 +133,7 @@ public:
|
|||||||
|
|
||||||
// Bounding box around the print bed, axes and model, for rendering.
|
// Bounding box around the print bed, axes and model, for rendering.
|
||||||
const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; }
|
const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; }
|
||||||
|
BoundingBoxf3 get_cur_bed_model_box();
|
||||||
const std::string & get_model_filename() { return m_model_filename; }
|
const std::string & get_model_filename() { return m_model_filename; }
|
||||||
const GLModel & get_model() { return m_model; }
|
const GLModel & get_model() { return m_model; }
|
||||||
// Check against an expanded 2d bounding box.
|
// Check against an expanded 2d bounding box.
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
// BBS
|
// BBS
|
||||||
#include "libslic3r/ObjectID.hpp"
|
#include "libslic3r/ObjectID.hpp"
|
||||||
|
|
||||||
#include "GLModel.hpp"
|
#include "MeshUtils.hpp"
|
||||||
#include "GLShader.hpp"
|
#include "GLShader.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -474,6 +474,7 @@ void GLModel::init_from(Geometry &&data, bool generate_mesh)
|
|||||||
m_render_data.clear();
|
m_render_data.clear();
|
||||||
m_render_data.push_back(RenderData());
|
m_render_data.push_back(RenderData());
|
||||||
m_render_data.back().indices_count = data.indices.size();
|
m_render_data.back().indices_count = data.indices.size();
|
||||||
|
m_render_data.back().vertices_count = data.vertices.size();
|
||||||
m_render_data.back().type = data.format.type;
|
m_render_data.back().type = data.format.type;
|
||||||
m_render_data.back().color = data.color.get_data();
|
m_render_data.back().color = data.color.get_data();
|
||||||
if (generate_mesh) {
|
if (generate_mesh) {
|
||||||
@ -623,14 +624,92 @@ bool GLModel::init_from_file(const std::string& filename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GLModel::init_model_from_poly(const std::vector<Vec2f> &triangles, float z, bool generate_mesh)
|
||||||
|
{
|
||||||
|
if (triangles.empty() || triangles.size() % 3 != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
GLModel::Geometry init_data;
|
||||||
|
init_data.format = {GLModel::PrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2};
|
||||||
|
init_data.reserve_vertices(triangles.size());
|
||||||
|
init_data.reserve_indices(triangles.size() / 3);
|
||||||
|
|
||||||
|
Vec2f min = triangles.front();
|
||||||
|
Vec2f max = min;
|
||||||
|
for (const Vec2f &v : triangles) {
|
||||||
|
min = min.cwiseMin(v).eval();
|
||||||
|
max = max.cwiseMax(v).eval();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vec2f size = max - min;
|
||||||
|
if (size.x() <= 0.0f || size.y() <= 0.0f)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Vec2f inv_size = size.cwiseInverse();
|
||||||
|
inv_size.y() *= -1.0f;
|
||||||
|
|
||||||
|
// vertices + indices
|
||||||
|
unsigned int vertices_counter = 0;
|
||||||
|
for (const Vec2f &v : triangles) {
|
||||||
|
const Vec3f p = {v.x(), v.y(), z};
|
||||||
|
init_data.add_vertex(p, (Vec2f) (v - min).cwiseProduct(inv_size).eval());
|
||||||
|
++vertices_counter;
|
||||||
|
if (vertices_counter % 3 == 0)
|
||||||
|
init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
|
||||||
|
}
|
||||||
|
init_from(std::move(init_data), generate_mesh);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLModel::init_model_from_lines(const Lines &lines, float z, bool generate_mesh)
|
||||||
|
{
|
||||||
|
GLModel::Geometry init_data;
|
||||||
|
init_data.format = {GLModel::PrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3};
|
||||||
|
init_data.reserve_vertices(2 * lines.size());
|
||||||
|
init_data.reserve_indices(2 * lines.size());
|
||||||
|
|
||||||
|
for (const auto &l : lines) {
|
||||||
|
init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), z));
|
||||||
|
init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), z));
|
||||||
|
const unsigned int vertices_counter = (unsigned int) init_data.vertices_count();
|
||||||
|
init_data.add_line(vertices_counter - 2, vertices_counter - 1);
|
||||||
|
}
|
||||||
|
init_from(std::move(init_data), generate_mesh);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLModel::init_model_from_lines(const Lines3 &lines, bool generate_mesh)
|
||||||
|
{
|
||||||
|
GLModel::Geometry init_data;
|
||||||
|
init_data.format = {GLModel::PrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3};
|
||||||
|
init_data.reserve_vertices(2 * lines.size());
|
||||||
|
init_data.reserve_indices(2 * lines.size());
|
||||||
|
|
||||||
|
for (const auto &l : lines) {
|
||||||
|
init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), unscale<float>(l.a.z())));
|
||||||
|
init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), unscale<float>(l.b.z())));
|
||||||
|
const unsigned int vertices_counter = (unsigned int) init_data.vertices_count();
|
||||||
|
init_data.add_line(vertices_counter - 2, vertices_counter - 1);
|
||||||
|
}
|
||||||
|
init_from(std::move(init_data), generate_mesh);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GLModel::set_color(int entity_id, const std::array<float, 4>& color)
|
void GLModel::set_color(int entity_id, const std::array<float, 4>& color)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_render_data.size(); ++i) {
|
for (size_t i = 0; i < m_render_data.size(); ++i) {
|
||||||
if (entity_id == -1 || static_cast<int>(i) == entity_id)
|
if (entity_id == -1 || static_cast<int>(i) == entity_id) {
|
||||||
m_render_data[i].color = color;
|
m_render_data[i].color = color;
|
||||||
|
m_render_data[i].geometry.color = color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLModel::set_color(const ColorRGBA &color) {
|
||||||
|
set_color(-1,color.get_data());
|
||||||
|
}
|
||||||
|
|
||||||
void GLModel::reset()
|
void GLModel::reset()
|
||||||
{
|
{
|
||||||
for (RenderData& data : m_render_data) {
|
for (RenderData& data : m_render_data) {
|
||||||
@ -646,6 +725,50 @@ void GLModel::reset()
|
|||||||
m_filename = std::string();
|
m_filename = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLenum get_primitive_mode(const GLModel::Geometry::Format &format)
|
||||||
|
{
|
||||||
|
switch (format.type) {
|
||||||
|
case GLModel::PrimitiveType::Points: {
|
||||||
|
return GL_POINTS;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
case GLModel::PrimitiveType::Triangles: {
|
||||||
|
return GL_TRIANGLES;
|
||||||
|
}
|
||||||
|
case GLModel::PrimitiveType::TriangleStrip: {
|
||||||
|
return GL_TRIANGLE_STRIP;
|
||||||
|
}
|
||||||
|
case GLModel::PrimitiveType::TriangleFan: {
|
||||||
|
return GL_TRIANGLE_FAN;
|
||||||
|
}
|
||||||
|
case GLModel::PrimitiveType::Lines: {
|
||||||
|
return GL_LINES;
|
||||||
|
}
|
||||||
|
case GLModel::PrimitiveType::LineStrip: {
|
||||||
|
return GL_LINE_STRIP;
|
||||||
|
}
|
||||||
|
case GLModel::PrimitiveType::LineLoop: {
|
||||||
|
return GL_LINE_LOOP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GLenum get_index_type(const GLModel::Geometry &data)
|
||||||
|
{
|
||||||
|
switch (data.index_type) {
|
||||||
|
default:
|
||||||
|
case GLModel::Geometry::EIndexType::UINT: {
|
||||||
|
return GL_UNSIGNED_INT;
|
||||||
|
}
|
||||||
|
case GLModel::Geometry::EIndexType::USHORT: {
|
||||||
|
return GL_UNSIGNED_SHORT;
|
||||||
|
}
|
||||||
|
case GLModel::Geometry::EIndexType::UBYTE: {
|
||||||
|
return GL_UNSIGNED_BYTE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GLModel::render() const
|
void GLModel::render() const
|
||||||
{
|
{
|
||||||
GLShaderProgram* shader = wxGetApp().get_current_shader();
|
GLShaderProgram* shader = wxGetApp().get_current_shader();
|
||||||
@ -701,6 +824,79 @@ void GLModel::render() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLModel::render_geometry() {
|
||||||
|
render_geometry(0,std::make_pair<size_t, size_t>(0, indices_count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLModel::render_geometry(int i,const std::pair<size_t, size_t> &range)
|
||||||
|
{
|
||||||
|
if (range.second == range.first) return;
|
||||||
|
|
||||||
|
GLShaderProgram *shader = wxGetApp().get_current_shader();
|
||||||
|
if (shader == nullptr) return;
|
||||||
|
|
||||||
|
auto &render_data = m_render_data[i];
|
||||||
|
// sends data to gpu if not done yet
|
||||||
|
if (render_data.vbo_id == 0 || render_data.ibo_id == 0) {
|
||||||
|
if (render_data.geometry.vertices_count() > 0 && render_data.geometry.indices_count() > 0 &&
|
||||||
|
!send_to_gpu(render_data, render_data.geometry.vertices, render_data.geometry.indices))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const Geometry &data = render_data.geometry;
|
||||||
|
|
||||||
|
|
||||||
|
const GLenum mode = get_primitive_mode(data.format);
|
||||||
|
const GLenum index_type = get_index_type(data);
|
||||||
|
|
||||||
|
const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format);
|
||||||
|
const bool position = Geometry::has_position(data.format);
|
||||||
|
const bool normal = Geometry::has_normal(data.format);
|
||||||
|
const bool tex_coord = Geometry::has_tex_coord(data.format);
|
||||||
|
|
||||||
|
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, render_data.vbo_id));
|
||||||
|
|
||||||
|
int position_id = -1;
|
||||||
|
int normal_id = -1;
|
||||||
|
int tex_coord_id = -1;
|
||||||
|
|
||||||
|
if (position) {
|
||||||
|
position_id = shader->get_attrib_location("v_position");
|
||||||
|
if (position_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes,
|
||||||
|
(const void *) Geometry::position_offset_bytes(data.format)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(position_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (normal) {
|
||||||
|
normal_id = shader->get_attrib_location("v_normal");
|
||||||
|
if (normal_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes,
|
||||||
|
(const void *) Geometry::normal_offset_bytes(data.format)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(normal_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tex_coord) {
|
||||||
|
tex_coord_id = shader->get_attrib_location("v_tex_coord");
|
||||||
|
if (tex_coord_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(tex_coord_id, Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes,
|
||||||
|
(const void *) Geometry::tex_coord_offset_bytes(data.format)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(tex_coord_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shader->set_uniform("uniform_color", data.color.get_data());
|
||||||
|
|
||||||
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, render_data.ibo_id));
|
||||||
|
glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void *) (range.first * Geometry::index_stride_bytes(data))));
|
||||||
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
|
|
||||||
|
if (tex_coord_id != -1) glsafe(::glDisableVertexAttribArray(tex_coord_id));
|
||||||
|
if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id));
|
||||||
|
if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id));
|
||||||
|
|
||||||
|
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||||
|
}
|
||||||
|
|
||||||
void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) const
|
void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) const
|
||||||
{
|
{
|
||||||
if (instances_vbo == 0)
|
if (instances_vbo == 0)
|
||||||
@ -801,6 +997,7 @@ bool GLModel::send_to_gpu(RenderData& data, const std::vector<float>& vertices,
|
|||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id));
|
||||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW));
|
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW));
|
||||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,10 @@ namespace GUI {
|
|||||||
public:
|
public:
|
||||||
enum class PrimitiveType : unsigned char
|
enum class PrimitiveType : unsigned char
|
||||||
{
|
{
|
||||||
|
Points,
|
||||||
Triangles,
|
Triangles,
|
||||||
|
TriangleStrip,
|
||||||
|
TriangleFan,
|
||||||
Lines,
|
Lines,
|
||||||
LineStrip,
|
LineStrip,
|
||||||
LineLoop
|
LineLoop
|
||||||
@ -130,6 +133,7 @@ namespace GUI {
|
|||||||
PrimitiveType type;
|
PrimitiveType type;
|
||||||
unsigned int vbo_id{0};
|
unsigned int vbo_id{0};
|
||||||
unsigned int ibo_id{0};
|
unsigned int ibo_id{0};
|
||||||
|
size_t vertices_count{0};
|
||||||
size_t indices_count{0};
|
size_t indices_count{0};
|
||||||
std::array<float, 4> color{1.0f, 1.0f, 1.0f, 1.0f};
|
std::array<float, 4> color{1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
};
|
};
|
||||||
@ -165,6 +169,12 @@ namespace GUI {
|
|||||||
GLModel() = default;
|
GLModel() = default;
|
||||||
virtual ~GLModel();
|
virtual ~GLModel();
|
||||||
|
|
||||||
|
size_t vertices_count(int i = 0) const {
|
||||||
|
return m_render_data[i].vertices_count > 0 ? m_render_data[i].vertices_count : m_render_data[i].geometry.vertices_count();
|
||||||
|
}
|
||||||
|
size_t indices_count(int i = 0) const {
|
||||||
|
return m_render_data[i].indices_count > 0 ? m_render_data[i].indices_count : m_render_data[i].geometry.indices_count(); }
|
||||||
|
|
||||||
TriangleMesh *mesh{nullptr};
|
TriangleMesh *mesh{nullptr};
|
||||||
|
|
||||||
void init_from(Geometry &&data, bool generate_mesh = false);
|
void init_from(Geometry &&data, bool generate_mesh = false);
|
||||||
@ -173,12 +183,17 @@ namespace GUI {
|
|||||||
void init_from(const indexed_triangle_set& its);
|
void init_from(const indexed_triangle_set& its);
|
||||||
void init_from(const Polygons& polygons, float z);
|
void init_from(const Polygons& polygons, float z);
|
||||||
bool init_from_file(const std::string& filename);
|
bool init_from_file(const std::string& filename);
|
||||||
|
bool init_model_from_poly(const std::vector<Vec2f> &triangles, float z, bool generate_mesh = false);
|
||||||
|
bool init_model_from_lines(const Lines &lines, float z, bool generate_mesh = false);
|
||||||
|
bool init_model_from_lines(const Lines3 &lines, bool generate_mesh = false);
|
||||||
// if entity_id == -1 set the color of all entities
|
// if entity_id == -1 set the color of all entities
|
||||||
void set_color(int entity_id, const std::array<float, 4>& color);
|
void set_color(int entity_id, const std::array<float, 4>& color);
|
||||||
|
void set_color(const ColorRGBA &color);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void render() const;
|
void render() const;
|
||||||
|
void render_geometry();
|
||||||
|
void render_geometry(int i,const std::pair<size_t, size_t> &range);
|
||||||
void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const;
|
void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const;
|
||||||
|
|
||||||
bool is_initialized() const { return !m_render_data.empty(); }
|
bool is_initialized() const { return !m_render_data.empty(); }
|
||||||
|
@ -41,7 +41,7 @@ std::pair<bool, std::string> GLShadersManager::init()
|
|||||||
valid &= append_shader("cali", { "cali.vs", "cali.fs"});
|
valid &= append_shader("cali", { "cali.vs", "cali.fs"});
|
||||||
valid &= append_shader("flat", {"flat.vs", "flat.fs"});
|
valid &= append_shader("flat", {"flat.vs", "flat.fs"});
|
||||||
// used to render printbed
|
// used to render printbed
|
||||||
valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" });
|
valid &= append_shader("printbed", {"110/printbed.vs", "110/printbed.fs"});
|
||||||
// used to render options in gcode preview
|
// used to render options in gcode preview
|
||||||
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3))
|
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3))
|
||||||
valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" });
|
valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" });
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
#include "libslic3r/Color.hpp"
|
#include "libslic3r/Color.hpp"
|
||||||
|
|
||||||
#include "slic3r/GUI/I18N.hpp"
|
#include "slic3r/GUI/I18N.hpp"
|
||||||
#include "slic3r/GUI/GLModel.hpp"
|
#include "slic3r/GUI/3DScene.hpp"
|
||||||
#include "slic3r/GUI/MeshUtils.hpp"
|
|
||||||
|
|
||||||
#include <cereal/archives/binary.hpp>
|
#include <cereal/archives/binary.hpp>
|
||||||
|
|
||||||
|
@ -4,14 +4,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "libslic3r/Model.hpp"
|
||||||
#include "slic3r/GUI/MeshUtils.hpp"
|
#include "slic3r/GUI/MeshUtils.hpp"
|
||||||
#include "libslic3r/SLA/Hollowing.hpp"
|
#include "libslic3r/SLA/Hollowing.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class ModelObject;
|
|
||||||
|
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class GLCanvas3D;
|
class GLCanvas3D;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "libslic3r/SLA/IndexedMesh.hpp"
|
#include "libslic3r/SLA/IndexedMesh.hpp"
|
||||||
#include "admesh/stl.h"
|
#include "admesh/stl.h"
|
||||||
|
|
||||||
#include "slic3r/GUI/3DScene.hpp"
|
#include "slic3r/GUI/GLModel.hpp"
|
||||||
|
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
|
@ -346,14 +346,20 @@ void PartPlate::calc_bounding_boxes() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_triangles(const ExPolygon& poly) {
|
void PartPlate::calc_triangles(const ExPolygon& poly)
|
||||||
if (!m_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z))
|
{
|
||||||
|
auto triangles =triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
|
m_triangles.reset();
|
||||||
|
if (!m_triangles.init_model_from_poly(triangles, GROUND_Z))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_exclude_triangles(const ExPolygon& poly) {
|
void PartPlate::calc_exclude_triangles(const ExPolygon& poly) {
|
||||||
if (!m_exclude_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z))
|
if (poly.empty()) { return; }
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create exclude triangles\n";
|
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
|
m_exclude_triangles.reset();
|
||||||
|
if (!m_exclude_triangles.init_model_from_poly(triangles, GROUND_Z))
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox) {
|
void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox) {
|
||||||
@ -392,10 +398,11 @@ void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox
|
|||||||
Lines contour_lines = to_lines(poly);
|
Lines contour_lines = to_lines(poly);
|
||||||
std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines));
|
std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines));
|
||||||
|
|
||||||
if (!m_gridlines.set_from_lines(gridlines, GROUND_Z))
|
m_gridlines.reset();
|
||||||
|
if (!m_gridlines.init_model_from_lines(gridlines, GROUND_Z))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
|
||||||
|
m_gridlines_bolder.reset();
|
||||||
if (!m_gridlines_bolder.set_from_lines(gridlines_bolder, GROUND_Z))
|
if (!m_gridlines_bolder.init_model_from_lines(gridlines_bolder, GROUND_Z))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,18 +437,18 @@ void PartPlate::calc_height_limit() {
|
|||||||
}
|
}
|
||||||
//std::copy(bottom_lines.begin(), bottom_lines.end(), std::back_inserter(bottom_h_lines));
|
//std::copy(bottom_lines.begin(), bottom_lines.end(), std::back_inserter(bottom_h_lines));
|
||||||
std::copy(top_lines.begin(), top_lines.end(), std::back_inserter(top_h_lines));
|
std::copy(top_lines.begin(), top_lines.end(), std::back_inserter(top_h_lines));
|
||||||
|
m_height_limit_common.reset();
|
||||||
if (!m_height_limit_common.set_from_3d_Lines(common_lines))
|
if (!m_height_limit_common.init_model_from_lines(common_lines))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n";
|
||||||
|
m_height_limit_bottom.reset();
|
||||||
if (!m_height_limit_bottom.set_from_3d_Lines(bottom_h_lines))
|
if (!m_height_limit_bottom.init_model_from_lines(bottom_h_lines))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n";
|
||||||
|
m_height_limit_top.reset();
|
||||||
if (!m_height_limit_top.set_from_3d_Lines(top_h_lines))
|
if (!m_height_limit_top.init_model_from_lines(top_h_lines))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit top lines\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit top lines\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_vertex_for_number(int index, bool one_number, GeometryBuffer &buffer)
|
void PartPlate::calc_vertex_for_number(int index, bool one_number, GLModel &gl_model)
|
||||||
{
|
{
|
||||||
ExPolygon poly;
|
ExPolygon poly;
|
||||||
#if 0 //in the up area
|
#if 0 //in the up area
|
||||||
@ -462,11 +469,12 @@ void PartPlate::calc_vertex_for_number(int index, bool one_number, GeometryBuffe
|
|||||||
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) + PARTPLATE_ICON_SIZE - PARTPLATE_TEXT_OFFSET_Y) });
|
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) + PARTPLATE_ICON_SIZE - PARTPLATE_TEXT_OFFSET_Y) });
|
||||||
#endif
|
#endif
|
||||||
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
if (!buffer.set_from_triangles(triangles, GROUND_Z))
|
gl_model.reset();
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
if (!gl_model.init_model_from_poly(triangles, GROUND_Z))
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &buffer)
|
void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GLModel &gl_model)
|
||||||
{
|
{
|
||||||
if (texture.get_width() > 0 && texture.get_height()) {
|
if (texture.get_width() > 0 && texture.get_height()) {
|
||||||
wxCoord w, h;
|
wxCoord w, h;
|
||||||
@ -483,12 +491,15 @@ void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &b
|
|||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )});
|
||||||
|
|
||||||
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
if (!buffer.set_from_triangles(triangles, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
gl_model.reset();
|
||||||
|
if (!gl_model.init_model_from_poly(triangles, GROUND_Z))
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer) {
|
void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GLModel &gl_model)
|
||||||
|
{
|
||||||
auto bed_ext = get_extents(m_shape);
|
auto bed_ext = get_extents(m_shape);
|
||||||
auto factor = bed_ext.size()(1) / 200.0;
|
auto factor = bed_ext.size()(1) / 200.0;
|
||||||
wxCoord w, h;
|
wxCoord w, h;
|
||||||
@ -498,6 +509,7 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind
|
|||||||
float offset_x = 1;
|
float offset_x = 1;
|
||||||
h = PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE;
|
h = PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE;
|
||||||
p += Vec2d(0, PARTPLATE_PLATENAME_OFFSET_Y + h);
|
p += Vec2d(0, PARTPLATE_PLATENAME_OFFSET_Y + h);
|
||||||
|
std::vector<Vec2f> triangles;
|
||||||
if (texture && texture->get_width() > 0 && texture->get_height()) {
|
if (texture && texture->get_width() > 0 && texture->get_height()) {
|
||||||
w = int(factor * (texture->get_original_width() * 16) / texture->get_height()) + 1;
|
w = int(factor * (texture->get_original_width() * 16) / texture->get_height()) + 1;
|
||||||
|
|
||||||
@ -506,9 +518,7 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind
|
|||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))});
|
||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) )});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) )});
|
||||||
|
|
||||||
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
if (!buffer.set_from_triangles(triangles, GROUND_Z))
|
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x ), scale_(p(1) - h )});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x ), scale_(p(1) - h )});
|
||||||
@ -516,13 +526,14 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind
|
|||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))});
|
||||||
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )});
|
poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )});
|
||||||
|
|
||||||
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
if (!buffer.set_from_triangles(triangles, GROUND_Z))
|
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
|
||||||
}
|
}
|
||||||
|
gl_model.reset();
|
||||||
|
if (!gl_model.init_model_from_poly(triangles, GROUND_Z))
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer)
|
void PartPlate::calc_vertex_for_icons(int index, GLModel &gl_model)
|
||||||
{
|
{
|
||||||
ExPolygon poly;
|
ExPolygon poly;
|
||||||
Vec2d& p = m_shape[2];
|
Vec2d& p = m_shape[2];
|
||||||
@ -533,7 +544,8 @@ void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer)
|
|||||||
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT), scale_(p(1) - index * (PARTPLATE_ICON_SIZE + PARTPLATE_ICON_GAP_Y)- PARTPLATE_ICON_GAP_TOP) });
|
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT), scale_(p(1) - index * (PARTPLATE_ICON_SIZE + PARTPLATE_ICON_GAP_Y)- PARTPLATE_ICON_GAP_TOP) });
|
||||||
|
|
||||||
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
|
||||||
if (!buffer.set_from_triangles(triangles, GROUND_Z))
|
gl_model.reset();
|
||||||
|
if (!gl_model.init_model_from_poly(triangles, GROUND_Z))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,33 +564,30 @@ void PartPlate::calc_vertex_for_icons_background(int icon_count, GeometryBuffer
|
|||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_background(bool force_default_color) const {
|
void PartPlate::render_background(bool force_default_color) {
|
||||||
unsigned int triangles_vcount = m_triangles.get_vertices_count();
|
|
||||||
|
|
||||||
//return directly for current plate
|
//return directly for current plate
|
||||||
if (m_selected && !force_default_color) return;
|
if (m_selected && !force_default_color) return;
|
||||||
|
|
||||||
// draw background
|
// draw background
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
glsafe(::glDepthMask(GL_FALSE));
|
||||||
|
ColorRGBA color;
|
||||||
if (!force_default_color) {
|
if (!force_default_color) {
|
||||||
if (m_selected) {
|
if (m_selected) {
|
||||||
glsafe(::glColor4fv(PartPlate::SELECT_COLOR.data()));
|
color = PartPlate::SELECT_COLOR;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(PartPlate::UNSELECT_DARK_COLOR.data()) : ::glColor4fv(PartPlate::UNSELECT_COLOR.data()));
|
color = m_partplate_list->m_is_dark ? PartPlate::UNSELECT_DARK_COLOR : PartPlate::UNSELECT_COLOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glsafe(::glColor4fv(PartPlate::DEFAULT_COLOR.data()));
|
color = PartPlate::DEFAULT_COLOR;
|
||||||
}
|
}
|
||||||
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
|
m_triangles.set_color(color);
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data()));
|
m_triangles.render_geometry();
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount));
|
glsafe(::glDepthMask(GL_TRUE));
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffer& logo_buffer, bool bottom, unsigned int vbo_id) const
|
void PartPlate::render_logo_texture(GLTexture &logo_texture, GLModel &logo_buffer, bool bottom)
|
||||||
{
|
{
|
||||||
//check valid
|
//check valid
|
||||||
if (logo_texture.unsent_compressed_data_available()) {
|
if (logo_texture.unsent_compressed_data_available()) {
|
||||||
@ -586,57 +595,18 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe
|
|||||||
logo_texture.send_compressed_data_to_gpu();
|
logo_texture.send_compressed_data_to_gpu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logo_buffer.get_vertices_count() > 0) {
|
if (logo_buffer.is_initialized()) {
|
||||||
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
|
|
||||||
if (shader != nullptr) {
|
|
||||||
shader->start_using();
|
|
||||||
shader->set_uniform("transparent_background", 0);
|
|
||||||
shader->set_uniform("svg_source", 0);
|
|
||||||
|
|
||||||
//glsafe(::glEnable(GL_DEPTH_TEST));
|
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
|
||||||
if (bottom)
|
if (bottom)
|
||||||
glsafe(::glFrontFace(GL_CW));
|
glsafe(::glFrontFace(GL_CW));
|
||||||
|
|
||||||
unsigned int stride = logo_buffer.get_vertex_data_size();
|
|
||||||
|
|
||||||
GLint position_id = shader->get_attrib_location("v_position");
|
|
||||||
GLint tex_coords_id = shader->get_attrib_location("v_tex_coords");
|
|
||||||
if (position_id != -1) {
|
|
||||||
glsafe(::glEnableVertexAttribArray(position_id));
|
|
||||||
}
|
|
||||||
if (tex_coords_id != -1) {
|
|
||||||
glsafe(::glEnableVertexAttribArray(tex_coords_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// show the temporary texture while no compressed data is available
|
// show the temporary texture while no compressed data is available
|
||||||
GLuint tex_id = (GLuint)logo_texture.get_id();
|
GLuint tex_id = (GLuint)logo_texture.get_id();
|
||||||
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id));
|
logo_buffer.render_geometry();
|
||||||
|
|
||||||
if (position_id != -1)
|
|
||||||
glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)logo_buffer.get_position_offset()));
|
|
||||||
if (tex_coords_id != -1)
|
|
||||||
glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)logo_buffer.get_tex_coords_offset()));
|
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)logo_buffer.get_vertices_count()));
|
|
||||||
|
|
||||||
if (tex_coords_id != -1)
|
|
||||||
glsafe(::glDisableVertexAttribArray(tex_coords_id));
|
|
||||||
|
|
||||||
if (position_id != -1)
|
|
||||||
glsafe(::glDisableVertexAttribArray(position_id));
|
|
||||||
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
|
|
||||||
if (bottom)
|
if (bottom)
|
||||||
glsafe(::glFrontFace(GL_CCW));
|
glsafe(::glFrontFace(GL_CCW));
|
||||||
|
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
|
|
||||||
shader->stop_using();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -650,17 +620,6 @@ void PartPlate::render_logo(bool bottom, bool render_cali)
|
|||||||
m_partplate_list->m_logo_texture.reset();
|
m_partplate_list->m_logo_texture.reset();
|
||||||
|
|
||||||
if (boost::algorithm::iends_with(m_partplate_list->m_logo_texture_filename, ".svg")) {
|
if (boost::algorithm::iends_with(m_partplate_list->m_logo_texture_filename, ".svg")) {
|
||||||
/*// use higher resolution images if graphic card and opengl version allow
|
|
||||||
GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size();
|
|
||||||
if (temp_texture->get_id() == 0 || temp_texture->get_source() != m_texture_filename) {
|
|
||||||
// generate a temporary lower resolution texture to show while no main texture levels have been compressed
|
|
||||||
if (!temp_texture->load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) {
|
|
||||||
render_default(bottom, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
canvas.request_extra_frame();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// starts generating the main texture, compression will run asynchronously
|
// starts generating the main texture, compression will run asynchronously
|
||||||
GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size();
|
GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size();
|
||||||
GLint logo_tex_size = (max_tex_size < 2048) ? max_tex_size : 2048;
|
GLint logo_tex_size = (max_tex_size < 2048) ? max_tex_size : 2048;
|
||||||
@ -699,23 +658,15 @@ void PartPlate::render_logo(bool bottom, bool render_cali)
|
|||||||
// canvas.request_extra_frame();
|
// canvas.request_extra_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_vbo_id == 0) {
|
|
||||||
unsigned int *vbo_id_ptr = const_cast<unsigned int *>(&m_vbo_id);
|
|
||||||
glsafe(::glGenBuffers(1, vbo_id_ptr));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id_ptr));
|
|
||||||
glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr) m_logo_triangles.get_vertices_data_size(), (const GLvoid *) m_logo_triangles.get_vertices_data(),
|
|
||||||
GL_STATIC_DRAW));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
}
|
|
||||||
if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) {
|
if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) {
|
||||||
auto cur_bed = m_partplate_list->m_bed3d;
|
auto cur_bed = m_partplate_list->m_bed3d;
|
||||||
auto cur_box = cur_bed->get_model().get_bounding_box().transformed(Geometry::translation_transform(m_origin));
|
auto cur_box = cur_bed->get_cur_bed_model_box();
|
||||||
if ((m_cur_bed_boundingbox.center() - cur_box.center()).norm() > 1.0f) {
|
if ((m_cur_bed_boundingbox.center() - cur_box.center()).norm() > 1.0f) {
|
||||||
set_logo_box_by_bed(cur_box);
|
set_logo_box_by_bed(cur_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_vbo_id != 0 && m_logo_triangles.get_vertices_count() > 0) {
|
if (m_logo_triangles.is_initialized()) {
|
||||||
render_logo_texture(m_partplate_list->m_logo_texture, m_logo_triangles, bottom, m_vbo_id);
|
render_logo_texture(m_partplate_list->m_logo_texture, m_logo_triangles, bottom);
|
||||||
}
|
}
|
||||||
if (!m_partplate_list->render_bedtype_logo) {
|
if (!m_partplate_list->render_bedtype_logo) {
|
||||||
return;
|
return;
|
||||||
@ -736,7 +687,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali)
|
|||||||
// render bed textures
|
// render bed textures
|
||||||
for (auto &part : m_partplate_list->bed_texture_info[bed_type_idx].parts) {
|
for (auto &part : m_partplate_list->bed_texture_info[bed_type_idx].parts) {
|
||||||
if (part.texture) {
|
if (part.texture) {
|
||||||
if (part.buffer && part.buffer->get_vertices_count() > 0
|
if (part.buffer && part.buffer->is_initialized()
|
||||||
//&& part.vbo_id != 0
|
//&& part.vbo_id != 0
|
||||||
) {
|
) {
|
||||||
if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) {
|
if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) {
|
||||||
@ -745,8 +696,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali)
|
|||||||
}
|
}
|
||||||
render_logo_texture(*(part.texture),
|
render_logo_texture(*(part.texture),
|
||||||
*(part.buffer),
|
*(part.buffer),
|
||||||
bottom,
|
bottom);
|
||||||
part.vbo_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -755,322 +705,169 @@ void PartPlate::render_logo(bool bottom, bool render_cali)
|
|||||||
if (render_cali) {
|
if (render_cali) {
|
||||||
for (auto& part : m_partplate_list->cali_texture_info.parts) {
|
for (auto& part : m_partplate_list->cali_texture_info.parts) {
|
||||||
if (part.texture) {
|
if (part.texture) {
|
||||||
if (part.buffer && part.buffer->get_vertices_count() > 0) {
|
if (part.buffer && part.buffer->is_initialized()) {
|
||||||
if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) {
|
if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) {
|
||||||
part.offset = Vec2d(m_origin.x(), m_origin.y());
|
part.offset = Vec2d(m_origin.x(), m_origin.y());
|
||||||
part.update_buffer();
|
part.update_buffer();
|
||||||
}
|
}
|
||||||
render_logo_texture(*(part.texture),
|
render_logo_texture(*(part.texture),
|
||||||
*(part.buffer),
|
*(part.buffer),
|
||||||
bottom,
|
bottom);
|
||||||
part.vbo_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_exclude_area(bool force_default_color) const {
|
void PartPlate::render_exclude_area(bool force_default_color)
|
||||||
if (force_default_color) //for thumbnail case
|
{
|
||||||
|
if (force_default_color || !m_exclude_triangles.is_initialized()) // for thumbnail case
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned int triangles_vcount = m_exclude_triangles.get_vertices_count();
|
ColorRGBA select_color{0.765f, 0.7686f, 0.7686f, 1.0f};
|
||||||
std::array<float, 4> select_color{ 0.765f, 0.7686f, 0.7686f, 1.0f };
|
ColorRGBA unselect_color{0.9f, 0.9f, 0.9f, 1.0f};
|
||||||
std::array<float, 4> unselect_color{ 0.9f, 0.9f, 0.9f, 1.0f };
|
//std::array<float, 4> default_color{ 0.9f, 0.9f, 0.9f, 1.0f };
|
||||||
std::array<float, 4> default_color{ 0.9f, 0.9f, 0.9f, 1.0f };
|
|
||||||
|
|
||||||
// draw exclude area
|
// draw exclude area
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
glsafe(::glDepthMask(GL_FALSE));
|
||||||
|
m_exclude_triangles.set_color(m_selected ? select_color : unselect_color);
|
||||||
if (m_selected) {
|
m_exclude_triangles.render_geometry();
|
||||||
glsafe(::glColor4fv(select_color.data()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
glsafe(::glColor4fv(unselect_color.data()));
|
|
||||||
}
|
|
||||||
|
|
||||||
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
|
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_exclude_triangles.get_vertex_data_size(), (GLvoid*)m_exclude_triangles.get_vertices_data()));
|
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount));
|
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
glsafe(::glDepthMask(GL_TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartPlate::render_grid(bool bottom) {
|
||||||
/*void PartPlate::render_background_for_picking(const float* render_color) const
|
|
||||||
{
|
|
||||||
unsigned int triangles_vcount = m_triangles.get_vertices_count();
|
|
||||||
|
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
|
||||||
glsafe(::glColor4fv(render_color));
|
|
||||||
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
|
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data()));
|
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount));
|
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void PartPlate::render_grid(bool bottom) const {
|
|
||||||
//glsafe(::glEnable(GL_MULTISAMPLE));
|
//glsafe(::glEnable(GL_MULTISAMPLE));
|
||||||
// draw grid
|
// draw grid
|
||||||
glsafe(::glLineWidth(1.0f * m_scale_factor));
|
glsafe(::glLineWidth(1.0f * m_scale_factor));
|
||||||
|
ColorRGBA color;
|
||||||
if (bottom)
|
if (bottom)
|
||||||
glsafe(::glColor4fv(LINE_BOTTOM_COLOR.data()));
|
color = LINE_BOTTOM_COLOR;
|
||||||
else {
|
else {
|
||||||
if (m_selected)
|
if (m_selected)
|
||||||
glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(LINE_TOP_SEL_DARK_COLOR.data()) : ::glColor4fv(LINE_TOP_SEL_COLOR.data()));
|
color = m_partplate_list->m_is_dark ? LINE_TOP_SEL_DARK_COLOR : LINE_TOP_SEL_COLOR;
|
||||||
else
|
else
|
||||||
glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(LINE_TOP_DARK_COLOR.data()) : ::glColor4fv(LINE_TOP_COLOR.data()));
|
color = m_partplate_list->m_is_dark ? LINE_TOP_DARK_COLOR : LINE_TOP_COLOR;
|
||||||
}
|
}
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data()));
|
m_gridlines.set_color(color);
|
||||||
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count()));
|
m_gridlines.render_geometry();
|
||||||
|
|
||||||
glsafe(::glLineWidth(2.0f * m_scale_factor));
|
glsafe(::glLineWidth(2.0f * m_scale_factor));
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_bolder.get_vertex_data_size(), (GLvoid*)m_gridlines_bolder.get_vertices_data()));
|
m_gridlines_bolder.set_color(color);
|
||||||
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_bolder.get_vertices_count()));
|
m_gridlines_bolder.render_geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_height_limit(PartPlate::HeightLimitMode mode) const
|
void PartPlate::render_height_limit(PartPlate::HeightLimitMode mode)
|
||||||
{
|
{
|
||||||
if (m_print && m_print->config().print_sequence == PrintSequence::ByObject && mode != HEIGHT_LIMIT_NONE)
|
if (m_print && m_print->config().print_sequence == PrintSequence::ByObject && mode != HEIGHT_LIMIT_NONE)
|
||||||
{
|
{
|
||||||
// draw lower limit
|
// draw lower limit
|
||||||
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
||||||
glsafe(::glColor4fv(HEIGHT_LIMIT_BOTTOM_COLOR.data()));
|
m_height_limit_common.set_color(HEIGHT_LIMIT_BOTTOM_COLOR);
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_common.get_vertex_data_size(), (GLvoid*)m_height_limit_common.get_vertices_data()));
|
m_height_limit_common.render_geometry();
|
||||||
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_common.get_vertices_count()));
|
|
||||||
|
|
||||||
if ((mode == HEIGHT_LIMIT_BOTTOM) || (mode == HEIGHT_LIMIT_BOTH)) {
|
if ((mode == HEIGHT_LIMIT_BOTTOM) || (mode == HEIGHT_LIMIT_BOTH)) {
|
||||||
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
||||||
glsafe(::glColor4fv(HEIGHT_LIMIT_BOTTOM_COLOR.data()));
|
m_height_limit_bottom.set_color(HEIGHT_LIMIT_BOTTOM_COLOR);
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_bottom.get_vertex_data_size(), (GLvoid*)m_height_limit_bottom.get_vertices_data()));
|
m_height_limit_bottom.render_geometry();
|
||||||
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_bottom.get_vertices_count()));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// draw upper limit
|
// draw upper limit
|
||||||
if ((mode == HEIGHT_LIMIT_TOP) || (mode == HEIGHT_LIMIT_BOTH)){
|
if ((mode == HEIGHT_LIMIT_TOP) || (mode == HEIGHT_LIMIT_BOTH)){
|
||||||
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
glsafe(::glLineWidth(3.0f * m_scale_factor));
|
||||||
glsafe(::glColor4fv(HEIGHT_LIMIT_TOP_COLOR.data()));
|
m_height_limit_top.set_color(HEIGHT_LIMIT_TOP_COLOR);
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_top.get_vertex_data_size(), (GLvoid*)m_height_limit_top.get_vertices_data()));
|
m_height_limit_top.render_geometry();
|
||||||
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_top.get_vertices_count()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PartPlate::render_icon_texture(int position_id, int tex_coords_id, const GeometryBuffer &buffer, GLTexture &texture, unsigned int &vbo_id) const
|
void PartPlate::render_icon_texture(GLModel &icon, GLTexture &texture)
|
||||||
{
|
{
|
||||||
if (vbo_id == 0) {
|
GLuint tex_id = (GLuint) texture.get_id();
|
||||||
glsafe(::glGenBuffers(1, &vbo_id));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id));
|
|
||||||
glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)buffer.get_vertices_data_size(), (const GLvoid*)buffer.get_vertices_data(), GL_STATIC_DRAW));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int stride = buffer.get_vertex_data_size();
|
|
||||||
GLuint tex_id = (GLuint)texture.get_id();
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id));
|
|
||||||
if (position_id != -1)
|
|
||||||
glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)buffer.get_position_offset()));
|
|
||||||
if (tex_coords_id != -1)
|
|
||||||
glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)buffer.get_tex_coords_offset()));
|
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)buffer.get_vertices_count()));
|
|
||||||
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PartPlate::render_plate_name_texture(int position_id, int tex_coords_id)
|
|
||||||
{
|
|
||||||
if (m_name_change) {
|
|
||||||
m_name_change = false;
|
|
||||||
if (m_plate_name_vbo_id > 0) {
|
|
||||||
glsafe(::glDeleteBuffers(1, &m_plate_name_vbo_id));
|
|
||||||
m_plate_name_vbo_id = 0;
|
|
||||||
}
|
|
||||||
if (m_plate_name_edit_vbo_id > 0) {
|
|
||||||
glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id));
|
|
||||||
m_plate_name_edit_vbo_id = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_plate_name_vbo_id==0) {
|
|
||||||
if (generate_plate_name_texture()) {
|
|
||||||
calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon);
|
|
||||||
if (m_plate_name_edit_vbo_id > 0) { //for redo
|
|
||||||
glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id));
|
|
||||||
m_plate_name_edit_vbo_id = 0;
|
|
||||||
}
|
|
||||||
calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (m_plate_name_edit_vbo_id==0) {
|
|
||||||
calc_vertex_for_plate_name_edit_icon(nullptr, 0, m_plate_name_edit_icon);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_plate_name_vbo_id == 0 && m_plate_name_icon.get_vertices_data_size() > 0) {
|
|
||||||
glsafe(::glGenBuffers(1, &m_plate_name_vbo_id));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_plate_name_vbo_id));
|
|
||||||
glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr) m_plate_name_icon.get_vertices_data_size(), (const GLvoid *) m_plate_name_icon.get_vertices_data(), GL_STATIC_DRAW));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int stride = m_plate_name_icon.get_vertex_data_size();
|
|
||||||
GLuint tex_id = (GLuint) m_name_texture.get_id();
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_plate_name_vbo_id));
|
icon.render_geometry();
|
||||||
if (position_id != -1) glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid *) (intptr_t) m_plate_name_icon.get_position_offset()));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
if (tex_coords_id != -1) glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid *) (intptr_t) m_plate_name_icon.get_tex_coords_offset()));
|
}
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei) m_plate_name_icon.get_vertices_count()));
|
|
||||||
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
void PartPlate::render_plate_name_texture()
|
||||||
|
{
|
||||||
|
if (m_name_change) {
|
||||||
|
m_name_change = false;
|
||||||
|
generate_plate_name_texture();
|
||||||
|
}
|
||||||
|
if (m_name_texture.get_id() == 0)
|
||||||
|
generate_plate_name_texture();
|
||||||
|
if (!m_plate_name_icon.is_initialized()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GLuint tex_id = (GLuint) m_name_texture.get_id();
|
||||||
|
glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id));
|
||||||
|
m_plate_name_icon.render_geometry();
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_icons(bool bottom, bool only_body, int hover_id)
|
void PartPlate::render_icons(bool bottom, bool only_body, int hover_id)
|
||||||
{
|
{
|
||||||
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
|
if (!only_body) {
|
||||||
if (shader != nullptr) {
|
if (hover_id == 1)
|
||||||
shader->start_using();
|
render_icon_texture(m_del_icon, m_partplate_list->m_del_hovered_texture);
|
||||||
shader->set_uniform("transparent_background", bottom);
|
else
|
||||||
//shader->set_uniform("svg_source", boost::algorithm::iends_with(m_partplate_list->m_del_texture.get_source(), ".svg"));
|
render_icon_texture(m_del_icon, m_partplate_list->m_del_texture);
|
||||||
shader->set_uniform("svg_source", 0);
|
|
||||||
|
|
||||||
//if (bottom)
|
if (hover_id == 2)
|
||||||
// glsafe(::glFrontFace(GL_CW));
|
render_icon_texture(m_orient_icon, m_partplate_list->m_orient_hovered_texture);
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
else
|
||||||
|
render_icon_texture(m_orient_icon, m_partplate_list->m_orient_texture);
|
||||||
|
|
||||||
GLint position_id = shader->get_attrib_location("v_position");
|
if (hover_id == 3)
|
||||||
GLint tex_coords_id = shader->get_attrib_location("v_tex_coords");
|
render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_hovered_texture);
|
||||||
if (position_id != -1) {
|
else
|
||||||
glsafe(::glEnableVertexAttribArray(position_id));
|
render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_texture);
|
||||||
|
|
||||||
|
if (hover_id == 4) {
|
||||||
|
if (this->is_locked())
|
||||||
|
render_icon_texture(m_lock_icon, m_partplate_list->m_locked_hovered_texture);
|
||||||
|
else
|
||||||
|
render_icon_texture(m_lock_icon, m_partplate_list->m_lockopen_hovered_texture);
|
||||||
|
} else {
|
||||||
|
if (this->is_locked())
|
||||||
|
render_icon_texture(m_lock_icon, m_partplate_list->m_locked_texture);
|
||||||
|
else
|
||||||
|
render_icon_texture(m_lock_icon, m_partplate_list->m_lockopen_texture);
|
||||||
}
|
}
|
||||||
if (tex_coords_id != -1) {
|
|
||||||
glsafe(::glEnableVertexAttribArray(tex_coords_id));
|
|
||||||
}
|
|
||||||
render_plate_name_texture(position_id, tex_coords_id);
|
|
||||||
if (!only_body) {
|
|
||||||
if (hover_id == 1)
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_del_icon, m_partplate_list->m_del_hovered_texture, m_del_vbo_id);
|
|
||||||
else
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_del_icon, m_partplate_list->m_del_texture, m_del_vbo_id);
|
|
||||||
|
|
||||||
if (hover_id == 2)
|
if (hover_id == PLATE_NAME_ID)
|
||||||
render_icon_texture(position_id, tex_coords_id, m_orient_icon, m_partplate_list->m_orient_hovered_texture, m_orient_vbo_id);
|
render_icon_texture(m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_hovered_texture);
|
||||||
else
|
else
|
||||||
render_icon_texture(position_id, tex_coords_id, m_orient_icon, m_partplate_list->m_orient_texture, m_orient_vbo_id);
|
render_icon_texture(m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture);
|
||||||
|
|
||||||
if (hover_id == 3)
|
if (m_partplate_list->render_plate_settings) {
|
||||||
render_icon_texture(position_id, tex_coords_id, m_arrange_icon, m_partplate_list->m_arrange_hovered_texture, m_arrange_vbo_id);
|
bool has_plate_settings = get_bed_type() != BedType::btDefault || get_print_seq() != PrintSequence::ByDefault || !get_first_layer_print_sequence().empty() ||
|
||||||
else
|
!get_other_layers_print_sequence().empty() || has_spiral_mode_config();
|
||||||
render_icon_texture(position_id, tex_coords_id, m_arrange_icon, m_partplate_list->m_arrange_texture, m_arrange_vbo_id);
|
if (hover_id == 5) {
|
||||||
|
if (!has_plate_settings)
|
||||||
if (hover_id == 4) {
|
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture);
|
||||||
if (this->is_locked())
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_locked_hovered_texture, m_lock_vbo_id);
|
|
||||||
else
|
else
|
||||||
render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_hovered_texture, m_lock_vbo_id);
|
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture);
|
||||||
} else {
|
} else {
|
||||||
if (this->is_locked())
|
if (!has_plate_settings)
|
||||||
render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_locked_texture, m_lock_vbo_id);
|
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_texture);
|
||||||
else
|
else
|
||||||
render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_texture, m_lock_vbo_id);
|
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture);
|
||||||
}
|
|
||||||
|
|
||||||
if (hover_id == 6)
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_hovered_texture, m_plate_name_edit_vbo_id);
|
|
||||||
else
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture, m_plate_name_edit_vbo_id);
|
|
||||||
|
|
||||||
if (m_partplate_list->render_plate_settings) {
|
|
||||||
bool has_plate_settings = get_bed_type() != BedType::btDefault || get_print_seq() != PrintSequence::ByDefault || !get_first_layer_print_sequence().empty() || !get_other_layers_print_sequence().empty() || has_spiral_mode_config();
|
|
||||||
if (hover_id == 5) {
|
|
||||||
if (!has_plate_settings)
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture, m_plate_settings_vbo_id);
|
|
||||||
else
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture,
|
|
||||||
m_plate_settings_vbo_id);
|
|
||||||
} else {
|
|
||||||
if (!has_plate_settings)
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_texture, m_plate_settings_vbo_id);
|
|
||||||
else
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture, m_plate_settings_vbo_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_plate_index >= 0 && m_plate_index < MAX_PLATE_COUNT) {
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index], m_plate_idx_vbo_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tex_coords_id != -1)
|
|
||||||
glsafe(::glDisableVertexAttribArray(tex_coords_id));
|
|
||||||
|
|
||||||
if (position_id != -1)
|
if (m_plate_index >= 0 && m_plate_index < MAX_PLATE_COUNT) { render_icon_texture(m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]); }
|
||||||
glsafe(::glDisableVertexAttribArray(position_id));
|
|
||||||
|
|
||||||
//if (bottom)
|
|
||||||
// glsafe(::glFrontFace(GL_CCW));
|
|
||||||
|
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
shader->stop_using();
|
|
||||||
}
|
}
|
||||||
|
render_plate_name_texture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_only_numbers(bool bottom) const
|
void PartPlate::render_only_numbers(bool bottom)
|
||||||
{
|
{
|
||||||
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
|
if (m_plate_index >=0 && m_plate_index < MAX_PLATE_COUNT) {
|
||||||
if (shader != nullptr) {
|
render_icon_texture(m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]);
|
||||||
shader->start_using();
|
|
||||||
shader->set_uniform("transparent_background", bottom);
|
|
||||||
//shader->set_uniform("svg_source", boost::algorithm::iends_with(m_partplate_list->m_del_texture.get_source(), ".svg"));
|
|
||||||
shader->set_uniform("svg_source", 0);
|
|
||||||
|
|
||||||
//if (bottom)
|
|
||||||
// glsafe(::glFrontFace(GL_CW));
|
|
||||||
glsafe(::glDepthMask(GL_FALSE));
|
|
||||||
|
|
||||||
GLint position_id = shader->get_attrib_location("v_position");
|
|
||||||
GLint tex_coords_id = shader->get_attrib_location("v_tex_coords");
|
|
||||||
if (position_id != -1) {
|
|
||||||
glsafe(::glEnableVertexAttribArray(position_id));
|
|
||||||
}
|
|
||||||
if (tex_coords_id != -1) {
|
|
||||||
glsafe(::glEnableVertexAttribArray(tex_coords_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_plate_index >=0 && m_plate_index < MAX_PLATE_COUNT) {
|
|
||||||
render_icon_texture(position_id, tex_coords_id, m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index], m_plate_idx_vbo_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tex_coords_id != -1)
|
|
||||||
glsafe(::glDisableVertexAttribArray(tex_coords_id));
|
|
||||||
|
|
||||||
if (position_id != -1)
|
|
||||||
glsafe(::glDisableVertexAttribArray(position_id));
|
|
||||||
|
|
||||||
//if (bottom)
|
|
||||||
// glsafe(::glFrontFace(GL_CCW));
|
|
||||||
|
|
||||||
glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
shader->stop_using();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::render_rectangle_for_picking(const GeometryBuffer &buffer, const float* render_color) const
|
|
||||||
{
|
|
||||||
unsigned int triangles_vcount = buffer.get_vertices_count();
|
|
||||||
|
|
||||||
//glsafe(::glDepthMask(GL_FALSE));
|
|
||||||
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
|
|
||||||
glsafe(::glColor4fv(render_color));
|
|
||||||
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
|
|
||||||
glsafe(::glVertexPointer(3, GL_FLOAT, buffer.get_vertex_data_size(), (GLvoid*)buffer.get_vertices_data()));
|
|
||||||
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount));
|
|
||||||
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
|
|
||||||
//glsafe(::glDepthMask(GL_TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PartPlate::render_label(GLCanvas3D& canvas) const {
|
void PartPlate::render_label(GLCanvas3D& canvas) const {
|
||||||
std::string label = (boost::format("Plate %1%") % (m_plate_index + 1)).str();
|
std::string label = (boost::format("Plate %1%") % (m_plate_index + 1)).str();
|
||||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||||
@ -1287,62 +1084,25 @@ void PartPlate::render_right_arrow(const float* render_color, bool use_lighting)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPlate::on_render_for_picking() const {
|
void PartPlate::on_render_for_picking() {
|
||||||
//glsafe(::glDisable(GL_DEPTH_TEST));
|
//glsafe(::glDisable(GL_DEPTH_TEST));
|
||||||
int hover_id = 0;
|
const Camera &camera = wxGetApp().plater()->get_camera();
|
||||||
std::array<float, 4> color = picking_color_component(hover_id);
|
auto view_mat = camera.get_view_matrix();
|
||||||
m_grabber_color[0] = color[0];
|
auto proj_mat = camera.get_projection_matrix();
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||||
m_grabber_color[3] = color[3];
|
shader->start_using();
|
||||||
//render_grabber(m_grabber_color, false);
|
shader->set_uniform("view_model_matrix", view_mat);
|
||||||
render_rectangle_for_picking(m_triangles, m_grabber_color);
|
shader->set_uniform("projection_matrix", proj_mat);
|
||||||
hover_id = 1;
|
std::vector<GLModel *> gl_models = {&m_triangles, &m_del_icon, &m_orient_icon, &m_arrange_icon, &m_lock_icon, &m_plate_settings_icon,
|
||||||
color = picking_color_component(hover_id);
|
&m_plate_name_edit_icon};
|
||||||
m_grabber_color[0] = color[0];
|
for (size_t i = 0; i < gl_models.size(); i++) {
|
||||||
m_grabber_color[1] = color[1];
|
int hover_id = i;
|
||||||
m_grabber_color[2] = color[2];
|
std::array<float, 4> color = picking_color_component(hover_id);
|
||||||
m_grabber_color[3] = color[3];
|
gl_models[i]->set_color(-1, color);
|
||||||
//render_left_arrow(m_grabber_color, false);
|
gl_models[i]->render_geometry();
|
||||||
render_rectangle_for_picking(m_del_icon, m_grabber_color);
|
}
|
||||||
hover_id = 2;
|
shader->stop_using();
|
||||||
color = picking_color_component(hover_id);
|
|
||||||
m_grabber_color[0] = color[0];
|
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
|
||||||
m_grabber_color[3] = color[3];
|
|
||||||
render_rectangle_for_picking(m_orient_icon, m_grabber_color);
|
|
||||||
hover_id = 3;
|
|
||||||
color = picking_color_component(hover_id);
|
|
||||||
m_grabber_color[0] = color[0];
|
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
|
||||||
m_grabber_color[3] = color[3];
|
|
||||||
render_rectangle_for_picking(m_arrange_icon, m_grabber_color);
|
|
||||||
hover_id = 4;
|
|
||||||
color = picking_color_component(hover_id);
|
|
||||||
m_grabber_color[0] = color[0];
|
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
|
||||||
m_grabber_color[3] = color[3];
|
|
||||||
//render_right_arrow(m_grabber_color, false);
|
|
||||||
render_rectangle_for_picking(m_lock_icon, m_grabber_color);
|
|
||||||
hover_id = 5;
|
|
||||||
color = picking_color_component(hover_id);
|
|
||||||
m_grabber_color[0] = color[0];
|
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
|
||||||
m_grabber_color[3] = color[3];
|
|
||||||
if (m_partplate_list->render_plate_settings)
|
|
||||||
render_rectangle_for_picking(m_plate_settings_icon, m_grabber_color);
|
|
||||||
hover_id = 6;
|
|
||||||
color = picking_color_component(hover_id);
|
|
||||||
m_grabber_color[0] = color[0];
|
|
||||||
m_grabber_color[1] = color[1];
|
|
||||||
m_grabber_color[2] = color[2];
|
|
||||||
m_grabber_color[3] = color[3];
|
|
||||||
// render_left_arrow(m_grabber_color, false);
|
|
||||||
render_rectangle_for_picking(m_plate_name_edit_icon, m_grabber_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<float, 4> PartPlate::picking_color_component(int idx) const
|
std::array<float, 4> PartPlate::picking_color_component(int idx) const
|
||||||
@ -1902,6 +1662,8 @@ bool PartPlate::generate_plate_name_texture()
|
|||||||
BOOST_LOG_TRIVIAL(error) << "PartPlate::generate_plate_name_texture(): generate_from_text_string() failed";
|
BOOST_LOG_TRIVIAL(error) << "PartPlate::generate_plate_name_texture(): generate_from_text_string() failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon);
|
||||||
|
calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2549,7 +2311,9 @@ void PartPlate::set_logo_box_by_bed(const BoundingBoxf3& box)
|
|||||||
m_cur_bed_boundingbox = box;
|
m_cur_bed_boundingbox = box;
|
||||||
ExPolygon logo_poly;
|
ExPolygon logo_poly;
|
||||||
generate_logo_polygon(logo_poly, box);
|
generate_logo_polygon(logo_poly, box);
|
||||||
if (!m_logo_triangles.set_from_triangles(triangulate_expolygon_2f(logo_poly, NORMALS_UP), GROUND_Z + 0.02f)) {
|
auto triangles = triangulate_expolygon_2f(logo_poly, NORMALS_UP);
|
||||||
|
m_logo_triangles.reset();
|
||||||
|
if (!m_logo_triangles.init_model_from_poly(triangles, GROUND_Z + 0.01f)) {
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":error :Unable to create logo triangles in set_logo_box_by_bed\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":error :Unable to create logo triangles in set_logo_box_by_bed\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2722,14 +2486,16 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve
|
|||||||
|
|
||||||
ExPolygon logo_poly;
|
ExPolygon logo_poly;
|
||||||
generate_logo_polygon(logo_poly);
|
generate_logo_polygon(logo_poly);
|
||||||
if (!m_logo_triangles.set_from_triangles(triangulate_expolygon_2f(logo_poly, NORMALS_UP), GROUND_Z+0.02f))
|
auto triangles = triangulate_expolygon_2f(logo_poly, NORMALS_UP);
|
||||||
|
m_logo_triangles.reset();
|
||||||
|
if (!m_logo_triangles.init_model_from_poly(triangles, GROUND_Z + 0.01f))
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create logo triangles\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create logo triangles\n";
|
||||||
else {
|
else {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) {
|
if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) {
|
||||||
auto cur_bed = m_partplate_list->m_bed3d;
|
auto cur_bed = m_partplate_list->m_bed3d;
|
||||||
set_logo_box_by_bed(cur_bed->get_model().get_bounding_box().transformed(Geometry::translation_transform(m_origin)));
|
set_logo_box_by_bed(cur_bed->get_cur_bed_model_box());
|
||||||
}
|
}
|
||||||
|
|
||||||
ExPolygon poly;
|
ExPolygon poly;
|
||||||
@ -2811,35 +2577,53 @@ bool PartPlate::intersects(const BoundingBoxf3& bb) const
|
|||||||
|
|
||||||
void PartPlate::render(bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id, bool render_cali)
|
void PartPlate::render(bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id, bool render_cali)
|
||||||
{
|
{
|
||||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||||
glsafe(::glEnable(GL_BLEND));
|
glsafe(::glEnable(GL_BLEND));
|
||||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||||
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
|
glsafe(::glDepthMask(GL_FALSE));
|
||||||
|
const Camera &camera = wxGetApp().plater()->get_camera();
|
||||||
|
auto view_mat = camera.get_view_matrix();
|
||||||
|
auto proj_mat = camera.get_projection_matrix();
|
||||||
|
{
|
||||||
|
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||||
|
shader->start_using();
|
||||||
|
shader->set_uniform("view_model_matrix", view_mat);
|
||||||
|
shader->set_uniform("projection_matrix", proj_mat);
|
||||||
|
|
||||||
if (!bottom) {
|
if (!bottom) {
|
||||||
// draw background
|
// draw background
|
||||||
render_background(force_background_color);
|
render_background(force_background_color);
|
||||||
|
render_exclude_area(force_background_color);
|
||||||
|
}
|
||||||
|
render_grid(bottom);
|
||||||
|
render_height_limit(mode);
|
||||||
|
|
||||||
render_exclude_area(force_background_color);
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
render_grid(bottom);
|
GLShaderProgram *shader = wxGetApp().get_shader("printbed");
|
||||||
|
shader->start_using();
|
||||||
if (!bottom && m_selected && !force_background_color) {
|
shader->set_uniform("view_model_matrix", view_mat);
|
||||||
if (m_partplate_list)
|
shader->set_uniform("projection_matrix", proj_mat);
|
||||||
render_logo(bottom, m_partplate_list->render_cali_logo && render_cali);
|
shader->set_uniform("svg_source", 0);
|
||||||
else
|
shader->set_uniform("transparent_background", 0);
|
||||||
render_logo(bottom);
|
if (!bottom && m_selected && !force_background_color) {//bed all icon
|
||||||
}
|
if (m_partplate_list)
|
||||||
|
render_logo(bottom, m_partplate_list->render_cali_logo && render_cali);
|
||||||
render_height_limit(mode);
|
else
|
||||||
|
render_logo(bottom);
|
||||||
render_icons(bottom, only_body, hover_id);
|
}
|
||||||
if (!force_background_color){
|
{
|
||||||
render_only_numbers(bottom);
|
shader->set_uniform("transparent_background", bottom);
|
||||||
}
|
render_icons(bottom, only_body, hover_id);
|
||||||
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
|
if (!force_background_color) {
|
||||||
glsafe(::glDisable(GL_BLEND));
|
render_only_numbers(bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shader->stop_using();
|
||||||
|
}
|
||||||
|
glsafe(::glDepthMask(GL_TRUE));
|
||||||
|
glsafe(::glDisable(GL_BLEND));
|
||||||
|
|
||||||
//if (with_label) {
|
//if (with_label) {
|
||||||
// render_label(canvas);
|
// render_label(canvas);
|
||||||
@ -5555,17 +5339,9 @@ void PartPlateList::BedTextureInfo::TexturePart::update_buffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer) buffer = new GLModel();
|
||||||
buffer = new GeometryBuffer();
|
buffer->reset();
|
||||||
|
if (!buffer->init_model_from_poly(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z + 0.02f)) {
|
||||||
if (buffer->set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z + 0.02f)) {
|
|
||||||
release_vbo();
|
|
||||||
unsigned int* vbo_id_ptr = const_cast<unsigned int*>(&vbo_id);
|
|
||||||
glsafe(::glGenBuffers(1, vbo_id_ptr));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id_ptr));
|
|
||||||
glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)buffer->get_vertices_data_size(), (const GLvoid*)buffer->get_vertices_data(), GL_STATIC_DRAW));
|
|
||||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
||||||
} else {
|
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create buffer triangles\n";
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create buffer triangles\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,32 +128,34 @@ private:
|
|||||||
Slic3r::Geometry::Transformation position;
|
Slic3r::Geometry::Transformation position;
|
||||||
std::vector<Vec3f> positions;
|
std::vector<Vec3f> positions;
|
||||||
unsigned int m_vbo_id{ 0 };
|
unsigned int m_vbo_id{ 0 };
|
||||||
GeometryBuffer m_triangles;
|
GLModel m_triangles;
|
||||||
GeometryBuffer m_exclude_triangles;
|
GLModel m_exclude_triangles;
|
||||||
GeometryBuffer m_logo_triangles;
|
GLModel m_logo_triangles;
|
||||||
GeometryBuffer m_gridlines;
|
GLModel m_gridlines;
|
||||||
GeometryBuffer m_gridlines_bolder;
|
GLModel m_gridlines_bolder;
|
||||||
GeometryBuffer m_height_limit_common;
|
GLModel m_height_limit_common;
|
||||||
GeometryBuffer m_height_limit_bottom;
|
GLModel m_height_limit_bottom;
|
||||||
GeometryBuffer m_height_limit_top;
|
GLModel m_height_limit_top;
|
||||||
GeometryBuffer m_del_icon;
|
GLModel m_del_icon;
|
||||||
GeometryBuffer m_plate_name_edit_icon;
|
GLModel m_plate_name_edit_icon;
|
||||||
//GeometryBuffer m_del_and_background_icon;
|
//GeometryBuffer m_del_and_background_icon;
|
||||||
mutable unsigned int m_del_vbo_id{ 0 };
|
mutable unsigned int m_del_vbo_id{ 0 };
|
||||||
GeometryBuffer m_arrange_icon;
|
GLModel m_arrange_icon;
|
||||||
mutable unsigned int m_arrange_vbo_id{ 0 };
|
mutable unsigned int m_arrange_vbo_id{ 0 };
|
||||||
GeometryBuffer m_orient_icon;
|
GLModel m_orient_icon;
|
||||||
mutable unsigned int m_orient_vbo_id{ 0 };
|
mutable unsigned int m_orient_vbo_id{ 0 };
|
||||||
GeometryBuffer m_lock_icon;
|
GLModel m_lock_icon;
|
||||||
mutable unsigned int m_lock_vbo_id{ 0 };
|
mutable unsigned int m_lock_vbo_id{ 0 };
|
||||||
GeometryBuffer m_plate_settings_icon;
|
GLModel m_plate_settings_icon;
|
||||||
mutable unsigned int m_plate_settings_vbo_id{ 0 };
|
mutable unsigned int m_plate_settings_vbo_id{ 0 };
|
||||||
GeometryBuffer m_plate_idx_icon;
|
GLModel m_plate_filament_map_icon;
|
||||||
|
mutable unsigned int m_plate_filament_map_vbo_id{0};
|
||||||
|
GLModel m_plate_idx_icon;
|
||||||
|
|
||||||
mutable unsigned int m_plate_idx_vbo_id{ 0 };
|
mutable unsigned int m_plate_idx_vbo_id{ 0 };
|
||||||
mutable unsigned int m_plate_name_edit_vbo_id{0};
|
mutable unsigned int m_plate_name_edit_vbo_id{0};
|
||||||
GLTexture m_texture;
|
GLTexture m_texture;
|
||||||
|
|
||||||
mutable float m_grabber_color[4];
|
|
||||||
float m_scale_factor{ 1.0f };
|
float m_scale_factor{ 1.0f };
|
||||||
GLUquadricObject* m_quadric;
|
GLUquadricObject* m_quadric;
|
||||||
int m_hover_id;
|
int m_hover_id;
|
||||||
@ -166,7 +168,7 @@ private:
|
|||||||
// part plate name
|
// part plate name
|
||||||
std::string m_name; // utf8 string
|
std::string m_name; // utf8 string
|
||||||
bool m_name_change = false;
|
bool m_name_change = false;
|
||||||
GeometryBuffer m_plate_name_icon;
|
GLModel m_plate_name_icon;
|
||||||
mutable unsigned int m_plate_name_vbo_id{0};
|
mutable unsigned int m_plate_name_vbo_id{0};
|
||||||
GLTexture m_name_texture;
|
GLTexture m_name_texture;
|
||||||
|
|
||||||
@ -181,37 +183,42 @@ private:
|
|||||||
void calc_exclude_triangles(const ExPolygon& poly);
|
void calc_exclude_triangles(const ExPolygon& poly);
|
||||||
void calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox);
|
void calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox);
|
||||||
void calc_height_limit();
|
void calc_height_limit();
|
||||||
void calc_vertex_for_number(int index, bool one_number, GeometryBuffer &buffer);
|
|
||||||
void calc_vertex_for_plate_name(GLTexture& texture, GeometryBuffer &buffer);
|
void calc_vertex_for_number(int index, bool one_number, GLModel &gl_model);
|
||||||
void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer);
|
void calc_vertex_for_plate_name(GLTexture &texture, GLModel &buffer);
|
||||||
void calc_vertex_for_icons(int index, GeometryBuffer &buffer);
|
void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GLModel &buffer);
|
||||||
|
void calc_vertex_for_icons(int index, GLModel &gl_model);
|
||||||
void calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer);
|
void calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer);
|
||||||
void render_background(bool force_default_color = false) const;
|
|
||||||
|
void render_background(bool force_default_color = false);
|
||||||
void render_logo(bool bottom, bool render_cali = true);
|
void render_logo(bool bottom, bool render_cali = true);
|
||||||
void render_logo_texture(GLTexture& logo_texture, const GeometryBuffer& logo_buffer, bool bottom, unsigned int vbo_id) const;
|
void render_logo_texture(GLTexture &logo_texture, GLModel &logo_buffer, bool bottom);
|
||||||
void render_exclude_area(bool force_default_color) const;
|
void render_exclude_area(bool force_default_color);
|
||||||
//void render_background_for_picking(const float* render_color) const;
|
//void render_background_for_picking(const float* render_color) const;
|
||||||
void render_grid(bool bottom) const;
|
|
||||||
void render_height_limit(PartPlate::HeightLimitMode mode = HEIGHT_LIMIT_BOTH) const;
|
void render_grid(bool bottom);
|
||||||
|
void render_height_limit(PartPlate::HeightLimitMode mode = HEIGHT_LIMIT_BOTH);
|
||||||
void render_label(GLCanvas3D& canvas) const;
|
void render_label(GLCanvas3D& canvas) const;
|
||||||
void render_grabber(const float* render_color, bool use_lighting) const;
|
void render_grabber(const float* render_color, bool use_lighting) const;
|
||||||
void render_face(float x_size, float y_size) const;
|
void render_face(float x_size, float y_size) const;
|
||||||
void render_arrows(const float* render_color, bool use_lighting) const;
|
void render_arrows(const float* render_color, bool use_lighting) const;
|
||||||
void render_left_arrow(const float* render_color, bool use_lighting) const;
|
void render_left_arrow(const float* render_color, bool use_lighting) const;
|
||||||
void render_right_arrow(const float* render_color, bool use_lighting) const;
|
void render_right_arrow(const float* render_color, bool use_lighting) const;
|
||||||
void render_icon_texture(int position_id, int tex_coords_id, const GeometryBuffer &buffer, GLTexture &texture, unsigned int &vbo_id) const;
|
|
||||||
void render_plate_name_texture(int position_id, int tex_coords_id);
|
void render_icon_texture(GLModel &buffer, GLTexture &texture);
|
||||||
|
void render_plate_name_texture();
|
||||||
void render_icons(bool bottom, bool only_body = false, int hover_id = -1);
|
void render_icons(bool bottom, bool only_body = false, int hover_id = -1);
|
||||||
void render_only_numbers(bool bottom) const;
|
|
||||||
void render_rectangle_for_picking(const GeometryBuffer &buffer, const float* render_color) const;
|
void render_only_numbers(bool bottom);
|
||||||
void on_render_for_picking() const;
|
void on_render_for_picking();
|
||||||
std::array<float, 4> picking_color_component(int idx) const;
|
std::array<float, 4> picking_color_component(int idx) const;
|
||||||
void release_opengl_resource();
|
void release_opengl_resource();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned int PLATE_BASE_ID = 255 * 255 * 253;
|
static const unsigned int PLATE_BASE_ID = 255 * 255 * 253;
|
||||||
static const unsigned int PLATE_NAME_HOVER_ID = 6;
|
//static const unsigned int PLATE_FILAMENT_MAP_ID = 6;//todo
|
||||||
static const unsigned int GRABBER_COUNT = 7;
|
static const unsigned int GRABBER_COUNT = 7;
|
||||||
|
static const unsigned int PLATE_NAME_ID = GRABBER_COUNT-1;
|
||||||
|
|
||||||
static std::array<float, 4> SELECT_COLOR;
|
static std::array<float, 4> SELECT_COLOR;
|
||||||
static std::array<float, 4> UNSELECT_COLOR;
|
static std::array<float, 4> UNSELECT_COLOR;
|
||||||
@ -375,7 +382,7 @@ public:
|
|||||||
bool intersects(const BoundingBoxf3& bb) const;
|
bool intersects(const BoundingBoxf3& bb) const;
|
||||||
|
|
||||||
void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1, bool render_cali = false);
|
void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1, bool render_cali = false);
|
||||||
void render_for_picking() const { on_render_for_picking(); }
|
void render_for_picking() { on_render_for_picking(); }
|
||||||
void set_selected();
|
void set_selected();
|
||||||
void set_unselected();
|
void set_unselected();
|
||||||
void set_hover_id(int id) { m_hover_id = id; }
|
void set_hover_id(int id) { m_hover_id = id; }
|
||||||
@ -619,7 +626,7 @@ public:
|
|||||||
std::string filename;
|
std::string filename;
|
||||||
GLTexture* texture { nullptr };
|
GLTexture* texture { nullptr };
|
||||||
Vec2d offset;
|
Vec2d offset;
|
||||||
GeometryBuffer* buffer { nullptr };
|
GLModel* buffer{nullptr};
|
||||||
TexturePart(float xx, float yy, float ww, float hh, std::string file){
|
TexturePart(float xx, float yy, float ww, float hh, std::string file){
|
||||||
x = xx; y = yy;
|
x = xx; y = yy;
|
||||||
w = ww; h = hh;
|
w = ww; h = hh;
|
||||||
|
@ -13388,7 +13388,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
|
|||||||
int action, plate_index;
|
int action, plate_index;
|
||||||
|
|
||||||
plate_index = hover_id / PartPlate::GRABBER_COUNT;
|
plate_index = hover_id / PartPlate::GRABBER_COUNT;
|
||||||
action = isModidyPlateName ? PartPlate::PLATE_NAME_HOVER_ID : hover_id % PartPlate::GRABBER_COUNT;
|
action = isModidyPlateName ? PartPlate::PLATE_NAME_ID : hover_id % PartPlate::GRABBER_COUNT;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%")%hover_id % plate_index %action;
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%")%hover_id % plate_index %action;
|
||||||
if (action == 0)
|
if (action == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user