mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-12 03:27:55 +00:00
Tech ENABLE_GLBEGIN_GLEND_REMOVAL - Refactoring of GLModel to:
1) allow for custom vertex data layout 2) allow for custom index data format 3) allow for any OpenGL primitive type (cherry picked from commit prusa3d/PrusaSlicer@afcac6e2ea)
This commit is contained in:
committed by
Noisyfox
parent
7e04448b7a
commit
354f8e20fb
@@ -27,30 +27,12 @@ const int c_connectors_group_id = 4;
|
||||
const float UndefFloat = -999.f;
|
||||
|
||||
// connector colors
|
||||
|
||||
static const ColorRGBA BLACK() { return {0.0f, 0.0f, 0.0f, 1.0f}; }
|
||||
static const ColorRGBA BLUE() { return {0.0f, 0.0f, 1.0f, 1.0f}; }
|
||||
static const ColorRGBA BLUEISH() { return {0.5f, 0.5f, 1.0f, 1.0f}; }
|
||||
static const ColorRGBA CYAN() { return {0.0f, 1.0f, 1.0f, 1.0f}; }
|
||||
static const ColorRGBA DARK_GRAY() { return {0.25f, 0.25f, 0.25f, 1.0f}; }
|
||||
static const ColorRGBA DARK_YELLOW() { return {0.5f, 0.5f, 0.0f, 1.0f}; }
|
||||
static const ColorRGBA GRAY() { return {0.5f, 0.5f, 0.5f, 1.0f}; }
|
||||
static const ColorRGBA GREEN() { return {0.0f, 1.0f, 0.0f, 1.0f}; }
|
||||
static const ColorRGBA GREENISH() { return {0.5f, 1.0f, 0.5f, 1.0f}; }
|
||||
static const ColorRGBA LIGHT_GRAY() { return {0.75f, 0.75f, 0.75f, 1.0f}; }
|
||||
static const ColorRGBA MAGENTA() { return {1.0f, 0.0f, 1.0f, 1.0f}; }
|
||||
static const ColorRGBA ORANGE() { return {0.923f, 0.504f, 0.264f, 1.0f}; }
|
||||
static const ColorRGBA RED() { return {1.0f, 0.0f, 0.0f, 1.0f}; }
|
||||
static const ColorRGBA REDISH() { return {1.0f, 0.5f, 0.5f, 1.0f}; }
|
||||
static const ColorRGBA YELLOW() { return {1.0f, 1.0f, 0.0f, 1.0f}; }
|
||||
static const ColorRGBA WHITE() { return {1.0f, 1.0f, 1.0f, 1.0f}; }
|
||||
|
||||
static const ColorRGBA PLAG_COLOR = YELLOW();
|
||||
static const ColorRGBA DOWEL_COLOR = DARK_YELLOW();
|
||||
static const ColorRGBA HOVERED_PLAG_COLOR = CYAN();
|
||||
static const ColorRGBA PLAG_COLOR = ColorRGBA::YELLOW();
|
||||
static const ColorRGBA DOWEL_COLOR = ColorRGBA::DARK_YELLOW();
|
||||
static const ColorRGBA HOVERED_PLAG_COLOR = ColorRGBA::CYAN();
|
||||
static const ColorRGBA HOVERED_DOWEL_COLOR = {0.0f, 0.5f, 0.5f, 1.0f};
|
||||
static const ColorRGBA SELECTED_PLAG_COLOR = GRAY();
|
||||
static const ColorRGBA SELECTED_DOWEL_COLOR = GRAY(); // DARK_GRAY();
|
||||
static const ColorRGBA SELECTED_PLAG_COLOR = ColorRGBA::GRAY();
|
||||
static const ColorRGBA SELECTED_DOWEL_COLOR = ColorRGBA::GRAY(); // DARK_GRAY();
|
||||
static const ColorRGBA CONNECTOR_DEF_COLOR = {1.0f, 1.0f, 1.0f, 0.5f};
|
||||
static const ColorRGBA CONNECTOR_ERR_COLOR = {1.0f, 0.3f, 0.3f, 0.5f};
|
||||
static const ColorRGBA HOVERED_ERR_COLOR = {1.0f, 0.3f, 0.3f, 1.0f};
|
||||
@@ -516,6 +498,8 @@ void GLGizmoAdvancedCut::on_render_for_picking()
|
||||
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
|
||||
BoundingBoxf3 box = m_parent.get_selection().get_bounding_box();
|
||||
#if ENABLE_FIXED_GRABBER
|
||||
float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize);
|
||||
@@ -523,8 +507,17 @@ void GLGizmoAdvancedCut::on_render_for_picking()
|
||||
float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0);
|
||||
#endif
|
||||
|
||||
m_move_grabber.color = picking_color_component(0);
|
||||
m_move_grabber.render_for_picking(mean_size);
|
||||
m_move_grabber.color = picking_color_component(0);
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
|
||||
m_move_grabber.render_for_picking(mean_size);
|
||||
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
auto inst_id = m_c->selection_info()->get_active_instance();
|
||||
@@ -876,67 +869,112 @@ void GLGizmoAdvancedCut::render_cut_plane_and_grabbers()
|
||||
point += object_offset;
|
||||
}
|
||||
|
||||
// draw plane
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
glsafe(::glDisable(GL_CULL_FACE));
|
||||
glsafe(::glEnable(GL_BLEND));
|
||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
|
||||
::glBegin(GL_QUADS);
|
||||
::glColor4f(0.8f, 0.8f, 0.8f, 0.5f);
|
||||
for (const Vec3d& point : plane_points_rot) {
|
||||
::glVertex3f(point(0), point(1), point(2));
|
||||
}
|
||||
glsafe(::glEnd());
|
||||
// draw plane
|
||||
{
|
||||
m_plane.reset();
|
||||
|
||||
glsafe(::glEnable(GL_CULL_FACE));
|
||||
glsafe(::glDisable(GL_BLEND));
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f };
|
||||
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// Draw the grabber and the connecting line
|
||||
Vec3d plane_center_rot = calc_plane_center(plane_points_rot);
|
||||
m_move_grabber.center = plane_center_rot + plane_normal_rot * Offset;
|
||||
// m_move_grabber.angles = m_current_base_rotation + m_rotation;
|
||||
// vertices
|
||||
for (const Vec3d &point : plane_points_rot) {
|
||||
init_data.add_vertex((Vec3f)point.cast<float>());
|
||||
}
|
||||
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
|
||||
glsafe(::glColor3f(1.0, 1.0, 0.0));
|
||||
glLineStipple(1, 0x0FFF);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
::glBegin(GL_LINES);
|
||||
::glVertex3dv(plane_center_rot.data());
|
||||
::glVertex3dv(m_move_grabber.center.data());
|
||||
glsafe(::glEnd());
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
// indices
|
||||
init_data.add_ushort_triangle(0, 1, 2);
|
||||
init_data.add_ushort_triangle(2, 3, 0);
|
||||
|
||||
// std::copy(std::begin(GrabberColor), std::end(GrabberColor), m_move_grabber.color);
|
||||
// m_move_grabber.color = GrabberColor;
|
||||
// m_move_grabber.hover_color = GrabberHoverColor;
|
||||
// m_move_grabber.render(m_hover_id == get_group_id(), (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0));
|
||||
bool hover = (m_hover_id == get_group_id());
|
||||
ColorRGBA render_color;
|
||||
if (hover) {
|
||||
render_color = GrabberHoverColor;
|
||||
}
|
||||
else
|
||||
render_color = GrabberColor;
|
||||
m_plane.init_from(std::move(init_data));
|
||||
}
|
||||
m_plane.render();
|
||||
|
||||
const GLModel &cube = m_move_grabber.get_cube();
|
||||
// BBS set to fixed size grabber
|
||||
// float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
||||
float fullsize = 8.0f;
|
||||
if (GLGizmoBase::INV_ZOOM > 0) {
|
||||
fullsize = m_move_grabber.FixedGrabberSize * GLGizmoBase::INV_ZOOM;
|
||||
glsafe(::glEnable(GL_CULL_FACE));
|
||||
glsafe(::glDisable(GL_BLEND));
|
||||
|
||||
// Draw the grabber and the connecting line
|
||||
Vec3d plane_center_rot = calc_plane_center(plane_points_rot);
|
||||
m_move_grabber.center = plane_center_rot + plane_normal_rot * Offset;
|
||||
// m_move_grabber.angles = m_current_base_rotation + m_rotation;
|
||||
|
||||
{
|
||||
m_grabber_connection.reset();
|
||||
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.color = ColorRGBA::YELLOW();
|
||||
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices
|
||||
init_data.add_vertex((Vec3f)plane_center_rot.cast<float>());
|
||||
init_data.add_vertex((Vec3f)m_move_grabber.center.cast<float>());
|
||||
|
||||
// indices
|
||||
init_data.add_ushort_line(0, 1);
|
||||
|
||||
m_grabber_connection.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
|
||||
glLineStipple(1, 0x0FFF);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
m_grabber_connection.render();
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
const_cast<GLModel*>(&cube)->set_color(-1, render_color);
|
||||
{
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light");
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
// std::copy(std::begin(GrabberColor), std::end(GrabberColor), m_move_grabber.color);
|
||||
// m_move_grabber.color = GrabberColor;
|
||||
// m_move_grabber.hover_color = GrabberHoverColor;
|
||||
// m_move_grabber.render(m_hover_id == get_group_id(), (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0));
|
||||
bool hover = (m_hover_id == get_group_id());
|
||||
ColorRGBA render_color;
|
||||
if (hover) {
|
||||
render_color = GrabberHoverColor;
|
||||
}
|
||||
else
|
||||
render_color = GrabberColor;
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_move_grabber.center.x(), m_move_grabber.center.y(), m_move_grabber.center.z()));
|
||||
glsafe(::glMultMatrixd(m_rotate_matrix.data()));
|
||||
GLModel &cube = m_move_grabber.get_cube();
|
||||
// BBS set to fixed size grabber
|
||||
// float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
||||
float fullsize = 8.0f;
|
||||
if (GLGizmoBase::INV_ZOOM > 0) {
|
||||
fullsize = m_move_grabber.FixedGrabberSize * GLGizmoBase::INV_ZOOM;
|
||||
}
|
||||
|
||||
glsafe(::glScaled(fullsize, fullsize, fullsize));
|
||||
cube.render();
|
||||
glsafe(::glPopMatrix());
|
||||
cube.set_color(render_color);
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_move_grabber.center.x(), m_move_grabber.center.y(), m_move_grabber.center.z()));
|
||||
glsafe(::glMultMatrixd(m_rotate_matrix.data()));
|
||||
|
||||
glsafe(::glScaled(fullsize, fullsize, fullsize));
|
||||
cube.render();
|
||||
glsafe(::glPopMatrix());
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
// Should be placed at last, because GLGizmoRotate3D clears depth buffer
|
||||
set_center(m_cut_plane_center);
|
||||
@@ -1043,7 +1081,7 @@ void GLGizmoAdvancedCut::render_connector_model(GLModel &model, const ColorRGBA
|
||||
|
||||
glsafe(::glMultMatrixd(view_model_matrix.data()));
|
||||
|
||||
model.set_color(-1, color);
|
||||
model.set_color(color);
|
||||
model.render();
|
||||
|
||||
shader->stop_using();
|
||||
|
||||
@@ -53,6 +53,8 @@ private:
|
||||
bool m_place_on_cut_lower{false};
|
||||
bool m_rotate_upper{false};
|
||||
bool m_rotate_lower{false};
|
||||
GLModel m_plane;
|
||||
GLModel m_grabber_connection;
|
||||
|
||||
bool m_do_segment;
|
||||
double m_segment_smoothing_alpha;
|
||||
|
||||
@@ -68,26 +68,9 @@ void GLGizmoBase::load_render_colors()
|
||||
RenderColor::colors[RenderCol_Flatten_Plane_Hover] = ImGuiWrapper::to_ImVec4(GLGizmoBase::FLATTEN_HOVER_COLOR);
|
||||
}
|
||||
|
||||
GLGizmoBase::Grabber::Grabber()
|
||||
: center(Vec3d::Zero())
|
||||
, angles(Vec3d::Zero())
|
||||
, dragging(false)
|
||||
, enabled(true)
|
||||
void GLGizmoBase::Grabber::render(bool hover, float size)
|
||||
{
|
||||
color = GRABBER_NORMAL_COL;
|
||||
hover_color = GRABBER_HOVER_COL;
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render(bool hover, float size) const
|
||||
{
|
||||
ColorRGBA render_color;
|
||||
if (hover) {
|
||||
render_color = hover_color;
|
||||
}
|
||||
else
|
||||
render_color = color;
|
||||
|
||||
render(size, render_color, false);
|
||||
render(size, hover ? hover_color : color, false);
|
||||
}
|
||||
|
||||
float GLGizmoBase::Grabber::get_half_size(float size) const
|
||||
@@ -100,28 +83,26 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const
|
||||
return get_half_size(size) * DraggingScaleFactor;
|
||||
}
|
||||
|
||||
const GLModel& GLGizmoBase::Grabber::get_cube() const
|
||||
GLModel& GLGizmoBase::Grabber::get_cube()
|
||||
{
|
||||
if (! cube_initialized) {
|
||||
if (!m_cube.is_initialized()) {
|
||||
// This cannot be done in constructor, OpenGL is not yet
|
||||
// initialized at that point (on Linux at least).
|
||||
indexed_triangle_set mesh = its_make_cube(1., 1., 1.);
|
||||
its_translate(mesh, Vec3f(-0.5, -0.5, -0.5));
|
||||
const_cast<GLModel&>(cube).init_from(mesh, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } });
|
||||
const_cast<bool&>(cube_initialized) = true;
|
||||
indexed_triangle_set its = its_make_cube(1., 1., 1.);
|
||||
its_translate(its, Vec3f(-0.5, -0.5, -0.5));
|
||||
m_cube.init_from(its);
|
||||
}
|
||||
return cube;
|
||||
return m_cube;
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking) const
|
||||
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking)
|
||||
{
|
||||
if (! cube_initialized) {
|
||||
if (!m_cube.is_initialized()) {
|
||||
// This cannot be done in constructor, OpenGL is not yet
|
||||
// initialized at that point (on Linux at least).
|
||||
indexed_triangle_set mesh = its_make_cube(1., 1., 1.);
|
||||
its_translate(mesh, Vec3f(-0.5, -0.5, -0.5));
|
||||
const_cast<GLModel&>(cube).init_from(mesh, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } });
|
||||
const_cast<bool&>(cube_initialized) = true;
|
||||
indexed_triangle_set its = its_make_cube(1., 1., 1.);
|
||||
its_translate(its, Vec3f(-0.5, -0.5, -0.5));
|
||||
m_cube.init_from(its);
|
||||
}
|
||||
|
||||
//BBS set to fixed size grabber
|
||||
@@ -132,7 +113,7 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
|
||||
}
|
||||
|
||||
|
||||
const_cast<GLModel*>(&cube)->set_color(-1, render_color);
|
||||
m_cube.set_color(render_color);
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(center.x(), center.y(), center.z()));
|
||||
@@ -140,11 +121,10 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
|
||||
glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0));
|
||||
glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0));
|
||||
glsafe(::glScaled(fullsize, fullsize, fullsize));
|
||||
cube.render();
|
||||
m_cube.render();
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
|
||||
GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
|
||||
: m_parent(parent)
|
||||
, m_group_id(-1)
|
||||
@@ -292,17 +272,23 @@ void GLGizmoBase::render_grabbers(float size) const
|
||||
|
||||
void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
|
||||
#if ENABLE_FIXED_GRABBER
|
||||
float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize);
|
||||
const float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize);
|
||||
#else
|
||||
float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0);
|
||||
const float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0);
|
||||
#endif
|
||||
|
||||
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) {
|
||||
if (m_grabbers[i].enabled) {
|
||||
m_grabbers[i].color = picking_color_component(i);
|
||||
m_grabbers[i].render_for_picking(mean_size);
|
||||
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) {
|
||||
if (m_grabbers[i].enabled) {
|
||||
m_grabbers[i].color = picking_color_component(i);
|
||||
m_grabbers[i].render_for_picking(mean_size);
|
||||
}
|
||||
}
|
||||
shader->stop_using();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,27 +64,26 @@ protected:
|
||||
static const float FixedGrabberSize;
|
||||
static const float FixedRadiusSize;
|
||||
|
||||
Vec3d center;
|
||||
Vec3d angles;
|
||||
ColorRGBA color;
|
||||
ColorRGBA hover_color;
|
||||
bool enabled;
|
||||
bool dragging;
|
||||
bool enabled{ true };
|
||||
bool dragging{ false };
|
||||
Vec3d center{ Vec3d::Zero() };
|
||||
Vec3d angles{ Vec3d::Zero() };
|
||||
ColorRGBA color{GRABBER_NORMAL_COL};
|
||||
ColorRGBA hover_color{GRABBER_HOVER_COL};
|
||||
|
||||
Grabber();
|
||||
Grabber() = default;
|
||||
|
||||
void render(bool hover, float size) const;
|
||||
void render_for_picking(float size) const { render(size, color, true); }
|
||||
void render(bool hover, float size);
|
||||
void render_for_picking(float size) { render(size, color, true); }
|
||||
|
||||
float get_half_size(float size) const;
|
||||
float get_dragging_half_size(float size) const;
|
||||
const GLModel& get_cube() const;
|
||||
GLModel& get_cube();
|
||||
|
||||
private:
|
||||
void render(float size, const ColorRGBA& render_color, bool picking) const;
|
||||
void render(float size, const ColorRGBA& render_color, bool picking);
|
||||
|
||||
GLModel cube;
|
||||
bool cube_initialized = false;
|
||||
GLModel m_cube;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace GUI {
|
||||
GLGizmoHollow::GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
{
|
||||
m_vbo_cylinder.init_from(its_make_cylinder(1., 1.));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +62,9 @@ void GLGizmoHollow::set_sla_support_data(ModelObject*, const Selection&)
|
||||
|
||||
void GLGizmoHollow::on_render()
|
||||
{
|
||||
if (!m_cylinder.is_initialized())
|
||||
m_cylinder.init_from(its_make_cylinder(1.0, 1.0));
|
||||
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
const CommonGizmosDataObjects::SelectionInfo* sel_info = m_c->selection_info();
|
||||
|
||||
@@ -99,12 +101,14 @@ void GLGizmoHollow::on_render_for_picking()
|
||||
render_points(selection, true);
|
||||
}
|
||||
|
||||
void GLGizmoHollow::render_points(const Selection& selection, bool picking) const
|
||||
void GLGizmoHollow::render_points(const Selection& selection, bool picking)
|
||||
{
|
||||
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light");
|
||||
if (shader)
|
||||
shader->start_using();
|
||||
ScopeGuard guard([shader]() { if (shader) shader->stop_using(); });
|
||||
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light");
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
shader->start_using();
|
||||
ScopeGuard guard([shader]() { shader->stop_using(); });
|
||||
|
||||
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
|
||||
@@ -126,28 +130,25 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
|
||||
continue;
|
||||
|
||||
// First decide about the color of the point.
|
||||
if (picking) {
|
||||
if (picking)
|
||||
render_color = picking_color_component(i);
|
||||
}
|
||||
else {
|
||||
if (size_t(m_hover_id) == i) {
|
||||
render_color = {0.f, 1.f, 1.f, 1.f};
|
||||
}
|
||||
if (size_t(m_hover_id) == i)
|
||||
render_color = ColorRGBA::CYAN();
|
||||
else if (m_c->hollowed_mesh() &&
|
||||
i < m_c->hollowed_mesh()->get_drainholes().size() &&
|
||||
m_c->hollowed_mesh()->get_drainholes()[i].failed) {
|
||||
render_color = {1.f, 0.f, 0.f, .5f};
|
||||
render_color = { 1.0f, 0.0f, 0.0f, 0.5f };
|
||||
}
|
||||
else { // neigher hover nor picking
|
||||
else // neither hover nor picking
|
||||
render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
const_cast<GLModel*>(&m_vbo_cylinder)->set_color(-1, render_color);
|
||||
m_cylinder.set_color(render_color);
|
||||
|
||||
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslatef(drain_hole.pos(0), drain_hole.pos(1), drain_hole.pos(2)));
|
||||
glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z()));
|
||||
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
|
||||
|
||||
if (vol->is_left_handed())
|
||||
@@ -155,13 +156,13 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
|
||||
|
||||
// Matrices set, we can render the point mark now.
|
||||
Eigen::Quaterniond q;
|
||||
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
|
||||
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
|
||||
Eigen::AngleAxisd aa(q);
|
||||
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2)));
|
||||
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(0., 0., -drain_hole.height));
|
||||
glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
|
||||
m_vbo_cylinder.render();
|
||||
m_cylinder.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
if (vol->is_left_handed())
|
||||
@@ -172,8 +173,6 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const
|
||||
{
|
||||
if (m_c->object_clipper()->get_position() == 0.)
|
||||
|
||||
@@ -42,13 +42,14 @@ private:
|
||||
void on_render() override;
|
||||
void on_render_for_picking() override;
|
||||
|
||||
void render_points(const Selection& selection, bool picking = false) const;
|
||||
void render_points(const Selection& selection, bool picking = false);
|
||||
void hollow_mesh(bool postpone_error_messages = false);
|
||||
bool unsaved_changes() const;
|
||||
|
||||
ObjectID m_old_mo_id = -1;
|
||||
|
||||
GLModel m_vbo_cylinder;
|
||||
GLModel m_cylinder;
|
||||
|
||||
float m_new_hole_radius = 2.f; // Size of a new hole.
|
||||
float m_new_hole_height = 6.f;
|
||||
mutable std::vector<bool> m_selected; // which holes are currently selected
|
||||
|
||||
@@ -25,9 +25,7 @@ GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filenam
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
//BBS: GUI refactor: add obj manipulation
|
||||
, m_object_manipulation(obj_manipulation)
|
||||
{
|
||||
m_vbo_cone.init_from(its_make_cone(1., 1., 2*PI/36));
|
||||
}
|
||||
{}
|
||||
|
||||
std::string GLGizmoMove3D::get_tooltip() const
|
||||
{
|
||||
@@ -95,6 +93,9 @@ void GLGizmoMove3D::on_update(const UpdateData& data)
|
||||
|
||||
void GLGizmoMove3D::on_render()
|
||||
{
|
||||
if (!m_cone.is_initialized())
|
||||
m_cone.init_from(its_make_cone(1.0, 1.0, double(PI) / 18.0));
|
||||
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||
@@ -138,25 +139,20 @@ void GLGizmoMove3D::on_render()
|
||||
m_grabber_connections[id].old_center = center;
|
||||
m_grabber_connections[id].model.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GUI::GLModel::InitializationData::Entity entity;
|
||||
entity.type = GUI::GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2);
|
||||
entity.positions.emplace_back(center.cast<float>());
|
||||
entity.positions.emplace_back(m_grabbers[id].center.cast<float>());
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.color = AXES_COLOR[id];
|
||||
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
entity.normals.reserve(2);
|
||||
for (size_t j = 0; j < 2; ++j) {
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
}
|
||||
// vertices
|
||||
init_data.add_vertex((Vec3f)center.cast<float>());
|
||||
init_data.add_vertex((Vec3f)m_grabbers[id].center.cast<float>());
|
||||
|
||||
entity.indices.reserve(2);
|
||||
entity.indices.emplace_back(0);
|
||||
entity.indices.emplace_back(1);
|
||||
// indices
|
||||
init_data.add_ushort_line(0, 1);
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_grabber_connections[id].model.init_from(init_data);
|
||||
m_grabber_connections[id].model.set_color(-1, AXES_COLOR[id]);
|
||||
m_grabber_connections[id].model.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
glLineStipple(1, 0x0FFF);
|
||||
@@ -241,7 +237,7 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const
|
||||
return projection;
|
||||
}
|
||||
|
||||
void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) const
|
||||
void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking)
|
||||
{
|
||||
#if ENABLE_FIXED_GRABBER
|
||||
float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize);
|
||||
@@ -258,15 +254,13 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
||||
}
|
||||
}
|
||||
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
|
||||
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
const_cast<GLModel*>(&m_vbo_cone)->set_color(-1, color);
|
||||
if (!picking) {
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
}
|
||||
m_cone.set_color(color);
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));
|
||||
@@ -277,11 +271,10 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
||||
|
||||
//glsafe(::glTranslated(0.0, 0.0, 2.0 * size));
|
||||
glsafe(::glScaled(0.75 * size, 0.75 * size, 2.0 * size));
|
||||
m_vbo_cone.render();
|
||||
m_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
if (! picking)
|
||||
shader->stop_using();
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class GLGizmoMove3D : public GLGizmoBase
|
||||
Vec3d m_starting_box_center{ Vec3d::Zero() };
|
||||
Vec3d m_starting_box_bottom_center{ Vec3d::Zero() };
|
||||
|
||||
GLModel m_vbo_cone;
|
||||
GLModel m_cone;
|
||||
struct GrabberConnection
|
||||
{
|
||||
GLModel model;
|
||||
@@ -59,7 +59,7 @@ protected:
|
||||
|
||||
private:
|
||||
double calc_projection(const UpdateData& data) const;
|
||||
void render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) const;
|
||||
void render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -194,23 +194,22 @@ void GLGizmoPainterBase::render_cursor_circle()
|
||||
m_old_cursor_radius = m_cursor_radius;
|
||||
m_circle.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::LineLoop;
|
||||
GLModel::Geometry init_data;
|
||||
static const unsigned int StepsCount = 32;
|
||||
static const float StepSize = 2.0f * float(PI) / float(StepsCount);
|
||||
entity.positions.reserve(StepsCount);
|
||||
entity.normals.reserve(StepsCount);
|
||||
entity.indices.reserve(StepsCount);
|
||||
for (unsigned int i = 0; i < StepsCount; ++i) {
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f };
|
||||
init_data.vertices.reserve(StepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(StepsCount * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices + indices
|
||||
for (unsigned short i = 0; i < StepsCount; ++i) {
|
||||
const float angle = float(i * StepSize);
|
||||
entity.positions.emplace_back(center.x() + ::cos(angle) * m_cursor_radius, center.y() + ::sin(angle) * m_cursor_radius, 0.0f);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.emplace_back(i);
|
||||
init_data.add_vertex(Vec3f(center.x() + ::cos(angle) * m_cursor_radius, center.y() + ::sin(angle) * m_cursor_radius, 0.0f));
|
||||
init_data.add_ushort_index(i);
|
||||
}
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_circle.init_from(init_data);
|
||||
m_circle.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
// BBS
|
||||
@@ -220,8 +219,14 @@ void GLGizmoPainterBase::render_cursor_circle()
|
||||
else if (m_button_down == Button::Right)
|
||||
render_color = this->get_cursor_sphere_right_button_color();
|
||||
|
||||
m_circle.set_color(-1, render_color);
|
||||
m_circle.render();
|
||||
m_circle.set_color(render_color);
|
||||
|
||||
GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
m_circle.render();
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
glsafe(::glPopAttrib());
|
||||
glsafe(::glPopMatrix());
|
||||
@@ -337,7 +342,7 @@ void GLGizmoPainterBase::update_contours(const TriangleMesh& vol_mesh, float cur
|
||||
const Polygons polys = slice_mesh(m_cut_contours.mesh.its, cursor_z, slicing_params);
|
||||
if (!polys.empty()) {
|
||||
m_cut_contours.contours.init_from(polys, static_cast<float>(cursor_z));
|
||||
m_cut_contours.contours.set_color(-1, { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
m_cut_contours.contours.set_color({ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||
}
|
||||
}
|
||||
else if (box.center() != m_cut_contours.position) {
|
||||
|
||||
@@ -228,24 +228,22 @@ void GLGizmoRotate::render_circle(const ColorRGBA& color, bool radius_changed)
|
||||
if (!m_circle.is_initialized() || radius_changed) {
|
||||
m_circle.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::LineLoop;
|
||||
entity.positions.reserve(ScaleStepsCount);
|
||||
entity.normals.reserve(ScaleStepsCount);
|
||||
entity.indices.reserve(ScaleStepsCount);
|
||||
for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices + indices
|
||||
for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
|
||||
const float angle = float(i * ScaleStepRad);
|
||||
entity.positions.emplace_back(::cos(angle) * m_radius, ::sin(angle) * m_radius, 0.0f);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.emplace_back(i);
|
||||
init_data.add_vertex(Vec3f(::cos(angle) * m_radius, ::sin(angle) * m_radius, 0.0f));
|
||||
init_data.add_ushort_index(i);
|
||||
}
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_circle.init_from(init_data);
|
||||
m_circle.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_circle.set_color(-1, color);
|
||||
m_circle.set_color(color);
|
||||
m_circle.render();
|
||||
}
|
||||
|
||||
@@ -257,13 +255,13 @@ void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed)
|
||||
if (!m_scale.is_initialized() || radius_changed) {
|
||||
m_scale.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2 * ScaleStepsCount);
|
||||
entity.normals.reserve(2 * ScaleStepsCount);
|
||||
entity.indices.reserve(2 * ScaleStepsCount);
|
||||
for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(2 * ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices + indices
|
||||
for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
|
||||
const float angle = float(i * ScaleStepRad);
|
||||
const float cosa = ::cos(angle);
|
||||
const float sina = ::sin(angle);
|
||||
@@ -272,19 +270,16 @@ void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed)
|
||||
const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short;
|
||||
const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short;
|
||||
|
||||
entity.positions.emplace_back(in_x, in_y, 0.0f);
|
||||
entity.positions.emplace_back(out_x, out_y, 0.0f);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.emplace_back(i * 2 + 0);
|
||||
entity.indices.emplace_back(i * 2 + 1);
|
||||
init_data.add_vertex(Vec3f(in_x, in_y, 0.0f));
|
||||
init_data.add_vertex(Vec3f(out_x, out_y, 0.0f));
|
||||
init_data.add_ushort_index(i * 2);
|
||||
init_data.add_ushort_index(i * 2 + 1);
|
||||
}
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_scale.init_from(init_data);
|
||||
}
|
||||
m_scale.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_scale.set_color(-1, color);
|
||||
m_scale.set_color(color);
|
||||
m_scale.render();
|
||||
}
|
||||
|
||||
@@ -297,13 +292,13 @@ void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_change
|
||||
if (!m_snap_radii.is_initialized() || radius_changed) {
|
||||
m_snap_radii.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2 * ScaleStepsCount);
|
||||
entity.normals.reserve(2 * ScaleStepsCount);
|
||||
entity.indices.reserve(2 * ScaleStepsCount);
|
||||
for (unsigned int i = 0; i < ScaleStepsCount; ++i) {
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(2 * ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices + indices
|
||||
for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
|
||||
const float angle = float(i * step);
|
||||
const float cosa = ::cos(angle);
|
||||
const float sina = ::sin(angle);
|
||||
@@ -312,19 +307,16 @@ void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_change
|
||||
const float out_x = cosa * out_radius;
|
||||
const float out_y = sina * out_radius;
|
||||
|
||||
entity.positions.emplace_back(in_x, in_y, 0.0f);
|
||||
entity.positions.emplace_back(out_x, out_y, 0.0f);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.emplace_back(i * 2 + 0);
|
||||
entity.indices.emplace_back(i * 2 + 1);
|
||||
init_data.add_vertex(Vec3f(in_x, in_y, 0.0f));
|
||||
init_data.add_vertex(Vec3f(out_x, out_y, 0.0f));
|
||||
init_data.add_ushort_index(i * 2);
|
||||
init_data.add_ushort_index(i * 2 + 1);
|
||||
}
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_snap_radii.init_from(init_data);
|
||||
m_snap_radii.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_snap_radii.set_color(-1, color);
|
||||
m_snap_radii.set_color(color);
|
||||
m_snap_radii.render();
|
||||
}
|
||||
|
||||
@@ -333,24 +325,22 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_
|
||||
if (!m_reference_radius.is_initialized() || radius_changed) {
|
||||
m_reference_radius.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2);
|
||||
entity.positions.emplace_back(0.0f, 0.0f, 0.0f);
|
||||
entity.positions.emplace_back(m_radius * (1.0f + GrabberOffset), 0.0f, 0.0f);
|
||||
entity.normals.reserve(2);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.reserve(2);
|
||||
entity.indices.emplace_back(0);
|
||||
entity.indices.emplace_back(1);
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_reference_radius.init_from(init_data);
|
||||
// vertices
|
||||
init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f));
|
||||
init_data.add_vertex(Vec3f(m_radius * (1.0f + GrabberOffset), 0.0f, 0.0f));
|
||||
|
||||
// indices
|
||||
init_data.add_ushort_line(0, 1);
|
||||
|
||||
m_reference_radius.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_reference_radius.set_color(-1, color);
|
||||
m_reference_radius.set_color(color);
|
||||
m_reference_radius.render();
|
||||
}
|
||||
|
||||
@@ -362,24 +352,22 @@ void GLGizmoRotate::render_angle_arc(const ColorRGBA& color, bool radius_changed
|
||||
if (!m_angle_arc.is_initialized() || radius_changed) {
|
||||
m_angle_arc.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::LineStrip;
|
||||
entity.positions.reserve(1 + AngleResolution);
|
||||
entity.normals.reserve(1 + AngleResolution);
|
||||
entity.indices.reserve(1 + AngleResolution);
|
||||
for (unsigned int i = 0; i <= AngleResolution; ++i) {
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve((1 + AngleResolution) * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve((1 + AngleResolution) * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
// vertices + indices
|
||||
for (unsigned short i = 0; i <= AngleResolution; ++i) {
|
||||
const float angle = float(i) * step_angle;
|
||||
entity.positions.emplace_back(::cos(angle) * ex_radius, ::sin(angle) * ex_radius, 0.0f);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.emplace_back(i);
|
||||
init_data.add_vertex(Vec3f(::cos(angle) * ex_radius, ::sin(angle) * ex_radius, 0.0f));
|
||||
init_data.add_ushort_index(i);
|
||||
}
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_angle_arc.init_from(init_data);
|
||||
m_angle_arc.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_angle_arc.set_color(-1, color);
|
||||
m_angle_arc.set_color(color);
|
||||
m_angle_arc.render();
|
||||
}
|
||||
|
||||
@@ -389,28 +377,26 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu
|
||||
m_grabber_connection.model.reset();
|
||||
m_grabber_connection.old_center = m_grabbers.front().center;
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2);
|
||||
entity.positions.emplace_back(0.0f, 0.0f, 0.0f);
|
||||
entity.positions.emplace_back(m_grabbers.front().center.cast<float>());
|
||||
entity.normals.reserve(2);
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
entity.indices.reserve(2);
|
||||
entity.indices.emplace_back(0);
|
||||
entity.indices.emplace_back(1);
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_grabber_connection.model.init_from(init_data);
|
||||
// vertices
|
||||
init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f));
|
||||
init_data.add_vertex((Vec3f)m_grabbers.front().center.cast<float>());
|
||||
|
||||
// indices
|
||||
init_data.add_ushort_line(0, 1);
|
||||
|
||||
m_grabber_connection.model.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_grabber_connection.model.set_color(-1, color);
|
||||
m_grabber_connection.model.set_color(color);
|
||||
m_grabber_connection.model.render();
|
||||
}
|
||||
|
||||
void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
|
||||
void GLGizmoRotate::render_grabber(const BoundingBoxf3& box)
|
||||
{
|
||||
m_grabbers.front().color = m_highlight_color;
|
||||
render_grabbers(box);
|
||||
@@ -418,7 +404,7 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
|
||||
|
||||
void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool picking)
|
||||
{
|
||||
double size = 0.75 * GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM;
|
||||
const double size = 0.75 * GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM;
|
||||
//float mean_size = (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0);
|
||||
//double size = m_dragging ? (double)m_grabbers[0].get_dragging_half_size(mean_size) : (double)m_grabbers[0].get_half_size(mean_size);
|
||||
|
||||
@@ -426,15 +412,13 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||
if (!picking && m_hover_id != -1)
|
||||
color = m_grabbers.front().hover_color;
|
||||
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
|
||||
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
m_cone.set_color(-1, color);
|
||||
if (!picking) {
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
}
|
||||
m_cone.set_color(color);
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
|
||||
const Vec3d& center = m_grabbers.front().center;
|
||||
|
||||
@@ -455,13 +439,12 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||
m_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
if (! picking)
|
||||
shader->stop_using();
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
void GLGizmoRotate::transform_to_local(const Selection& selection) const
|
||||
{
|
||||
glsafe(::glTranslated(m_center(0), m_center(1), m_center(2)));
|
||||
glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z()));
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes()) {
|
||||
const Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true);
|
||||
|
||||
@@ -82,7 +82,7 @@ private:
|
||||
void render_reference_radius(const ColorRGBA& color, bool radius_changed);
|
||||
void render_angle_arc(const ColorRGBA& color, bool radius_changed);
|
||||
void render_grabber_connection(const ColorRGBA& color, bool radius_changed);
|
||||
void render_grabber(const BoundingBoxf3& box) const;
|
||||
void render_grabber(const BoundingBoxf3& box);
|
||||
void render_grabber_extension(const BoundingBoxf3& box, bool picking);
|
||||
|
||||
void transform_to_local(const Selection& selection) const;
|
||||
|
||||
@@ -267,7 +267,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
|
||||
return -1;
|
||||
};
|
||||
|
||||
int id = grabber_connection(id_1, id_2);
|
||||
const int id = grabber_connection(id_1, id_2);
|
||||
if (id == -1)
|
||||
return;
|
||||
|
||||
@@ -278,27 +278,22 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
|
||||
m_grabber_connections[id].old_v2 = m_grabbers[id_2].center;
|
||||
m_grabber_connections[id].model.reset();
|
||||
|
||||
GLModel::InitializationData init_data;
|
||||
GUI::GLModel::InitializationData::Entity entity;
|
||||
entity.type = GUI::GLModel::PrimitiveType::Lines;
|
||||
entity.positions.reserve(2);
|
||||
entity.positions.emplace_back(m_grabbers[id_1].center.cast<float>());
|
||||
entity.positions.emplace_back(m_grabbers[id_2].center.cast<float>());
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT };
|
||||
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format));
|
||||
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format));
|
||||
|
||||
entity.normals.reserve(2);
|
||||
for (size_t j = 0; j < 2; ++j) {
|
||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||
}
|
||||
// vertices
|
||||
init_data.add_vertex((Vec3f)m_grabbers[id_1].center.cast<float>());
|
||||
init_data.add_vertex((Vec3f)m_grabbers[id_2].center.cast<float>());
|
||||
|
||||
entity.indices.reserve(2);
|
||||
entity.indices.emplace_back(0);
|
||||
entity.indices.emplace_back(1);
|
||||
// indices
|
||||
init_data.add_ushort_line(0, 1);
|
||||
|
||||
init_data.entities.emplace_back(entity);
|
||||
m_grabber_connections[id].model.init_from(init_data);
|
||||
m_grabber_connections[id].model.init_from(std::move(init_data));
|
||||
}
|
||||
|
||||
m_grabber_connections[id].model.set_color(-1, color);
|
||||
m_grabber_connections[id].model.set_color(color);
|
||||
glLineStipple(1, 0x0FFF);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
m_grabber_connections[id].model.render();
|
||||
|
||||
@@ -622,7 +622,7 @@ void GLGizmoSimplify::init_model(const indexed_triangle_set& its)
|
||||
m_c->selection_info()->get_active_instance(), m_volume);
|
||||
|
||||
if (const Selection&sel = m_parent.get_selection(); sel.get_volume_idxs().size() == 1)
|
||||
m_glmodel.set_color(-1, sel.get_volume(*sel.get_volume_idxs().begin())->color);
|
||||
m_glmodel.set_color(sel.get_volume(*sel.get_volume_idxs().begin())->color);
|
||||
m_triangle_count = its.indices.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ namespace GUI {
|
||||
|
||||
GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GLGizmoSlaSupports::on_init()
|
||||
{
|
||||
@@ -46,10 +48,6 @@ bool GLGizmoSlaSupports::on_init()
|
||||
m_desc["manual_editing"] = _L("Manual editing");
|
||||
m_desc["clipping_of_view"] = _L("Clipping of view")+ ": ";
|
||||
m_desc["reset_direction"] = _L("Reset direction");
|
||||
|
||||
m_cone.init_from(its_make_cone(1., 1., 2 * PI / 24));
|
||||
m_cylinder.init_from(its_make_cylinder(1., 1., 2 * PI / 24.));
|
||||
m_sphere.init_from(its_make_sphere(1., (2 * M_PI) / 24.));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -79,6 +77,13 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S
|
||||
|
||||
void GLGizmoSlaSupports::on_render()
|
||||
{
|
||||
if (!m_cone.is_initialized())
|
||||
m_cone.init_from(its_make_cone(1.0, 1.0, double(PI) / 12.0));
|
||||
if (!m_sphere.is_initialized())
|
||||
m_sphere.init_from(its_make_sphere(1.0, double(PI) / 12.0));
|
||||
if (!m_cylinder.is_initialized())
|
||||
m_cylinder.init_from(its_make_cylinder(1.0, 1.0, double(PI) / 12.0));
|
||||
|
||||
ModelObject* mo = m_c->selection_info()->model_object();
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
@@ -111,7 +116,7 @@ void GLGizmoSlaSupports::on_render_for_picking()
|
||||
render_points(selection, true);
|
||||
}
|
||||
|
||||
void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const
|
||||
void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
||||
{
|
||||
size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size();
|
||||
|
||||
@@ -169,8 +174,8 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
||||
}
|
||||
}
|
||||
|
||||
const_cast<GLModel*>(&m_cone)->set_color(-1, render_color);
|
||||
const_cast<GLModel*>(&m_sphere)->set_color(-1, render_color);
|
||||
m_cone.set_color(render_color);
|
||||
m_sphere.set_color(render_color);
|
||||
if (shader && !picking)
|
||||
shader->set_uniform("emission_factor", 0.5f);
|
||||
|
||||
@@ -222,7 +227,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
||||
// Now render the drain holes:
|
||||
if (has_holes && ! picking) {
|
||||
render_color = { 0.7f, 0.7f, 0.7f, 0.7f };
|
||||
const_cast<GLModel*>(&m_cylinder)->set_color(-1, render_color);
|
||||
m_cylinder.set_color(render_color);
|
||||
if (shader)
|
||||
shader->set_uniform("emission_factor", 0.5f);
|
||||
for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) {
|
||||
|
||||
@@ -77,13 +77,9 @@ private:
|
||||
void on_render() override;
|
||||
void on_render_for_picking() override;
|
||||
|
||||
void render_points(const Selection& selection, bool picking = false) const;
|
||||
void render_points(const Selection& selection, bool picking = false);
|
||||
bool unsaved_changes() const;
|
||||
|
||||
GLModel m_cone;
|
||||
GLModel m_cylinder;
|
||||
GLModel m_sphere;
|
||||
|
||||
bool m_lock_unique_islands = false;
|
||||
bool m_editing_mode = false; // Is editing mode active?
|
||||
float m_new_point_head_diameter; // Size of a new point.
|
||||
@@ -95,6 +91,10 @@ private:
|
||||
std::vector<sla::SupportPoint> m_normal_cache; // to restore after discarding changes or undo/redo
|
||||
ObjectID m_old_mo_id;
|
||||
|
||||
GLModel m_cone;
|
||||
GLModel m_cylinder;
|
||||
GLModel m_sphere;
|
||||
|
||||
// This map holds all translated description texts, so they can be easily referenced during layout calculations
|
||||
// etc. When language changes, GUI is recreated and this class constructed again, so the change takes effect.
|
||||
std::map<std::string, wxString> m_desc;
|
||||
|
||||
@@ -447,7 +447,14 @@ void GLGizmoText::on_render()
|
||||
m_grabbers[0].enabled = true;
|
||||
ColorRGBA color = picking_color_component(0);
|
||||
m_grabbers[0].color = color;
|
||||
m_grabbers[0].render_for_picking(mean_size);
|
||||
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
m_grabbers[0].render_for_picking(mean_size);
|
||||
|
||||
shader->stop_using();
|
||||
}
|
||||
}
|
||||
|
||||
delete_temp_preview_text_volume();
|
||||
@@ -492,7 +499,16 @@ void GLGizmoText::on_render_for_picking()
|
||||
m_grabbers[0].enabled = true;
|
||||
ColorRGBA color = picking_color_component(0);
|
||||
m_grabbers[0].color = color;
|
||||
m_grabbers[0].render_for_picking(mean_size);
|
||||
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||
if (shader != nullptr) {
|
||||
glsafe(::glPushMatrix());
|
||||
shader->start_using();
|
||||
m_grabbers[0].render_for_picking(mean_size);
|
||||
|
||||
shader->stop_using();
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user