Removed immediate OpenGL mode calls in place on face gizmo
This commit is contained in:
parent
6e597bb1ee
commit
9c365da828
@ -1,7 +1,6 @@
|
||||
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
||||
#include "GLGizmoFlatten.hpp"
|
||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp"
|
||||
|
||||
#include <numeric>
|
||||
@ -80,12 +79,7 @@ void GLGizmoFlatten::on_render() const
|
||||
else
|
||||
glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.5f));
|
||||
|
||||
::glBegin(GL_POLYGON);
|
||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||
{
|
||||
::glVertex3dv(vertex.data());
|
||||
}
|
||||
glsafe(::glEnd());
|
||||
m_planes[i].vbo.render();
|
||||
}
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
@ -112,12 +106,7 @@ void GLGizmoFlatten::on_render_for_picking() const
|
||||
for (int i = 0; i < (int)m_planes.size(); ++i)
|
||||
{
|
||||
glsafe(::glColor4fv(picking_color_component(i).data()));
|
||||
::glBegin(GL_POLYGON);
|
||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||
{
|
||||
::glVertex3dv(vertex.data());
|
||||
}
|
||||
glsafe(::glEnd());
|
||||
m_planes[i].vbo.render();
|
||||
}
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
@ -181,7 +170,7 @@ void GLGizmoFlatten::update_planes()
|
||||
if (std::abs(this_normal(0) - (*normal_ptr)(0)) < 0.001 && std::abs(this_normal(1) - (*normal_ptr)(1)) < 0.001 && std::abs(this_normal(2) - (*normal_ptr)(2)) < 0.001) {
|
||||
stl_vertex* first_vertex = ch.stl.facet_start[facet_idx].vertex;
|
||||
for (int j=0; j<3; ++j)
|
||||
m_planes.back().vertices.emplace_back((double)first_vertex[j](0), (double)first_vertex[j](1), (double)first_vertex[j](2));
|
||||
m_planes.back().vertices.emplace_back(first_vertex[j].cast<double>());
|
||||
|
||||
facet_visited[facet_idx] = true;
|
||||
for (int j = 0; j < 3; ++ j) {
|
||||
@ -193,15 +182,16 @@ void GLGizmoFlatten::update_planes()
|
||||
}
|
||||
m_planes.back().normal = normal_ptr->cast<double>();
|
||||
|
||||
Pointf3s& verts = m_planes.back().vertices;
|
||||
// Now we'll transform all the points into world coordinates, so that the areas, angles and distances
|
||||
// make real sense.
|
||||
m_planes.back().vertices = transform(m_planes.back().vertices, inst_matrix);
|
||||
verts = transform(verts, inst_matrix);
|
||||
|
||||
// if this is a just a very small triangle, remove it to speed up further calculations (it would be rejected later anyway):
|
||||
if (m_planes.back().vertices.size() == 3 &&
|
||||
((m_planes.back().vertices[0] - m_planes.back().vertices[1]).norm() < minimal_side
|
||||
|| (m_planes.back().vertices[0] - m_planes.back().vertices[2]).norm() < minimal_side
|
||||
|| (m_planes.back().vertices[1] - m_planes.back().vertices[2]).norm() < minimal_side))
|
||||
if (verts.size() == 3 &&
|
||||
((verts[0] - verts[1]).norm() < minimal_side
|
||||
|| (verts[0] - verts[2]).norm() < minimal_side
|
||||
|| (verts[1] - verts[2]).norm() < minimal_side))
|
||||
m_planes.pop_back();
|
||||
}
|
||||
|
||||
@ -246,7 +236,7 @@ void GLGizmoFlatten::update_planes()
|
||||
discard = true;
|
||||
else {
|
||||
// We also check the inner angles and discard polygons with angles smaller than the following threshold
|
||||
const double angle_threshold = ::cos(10.0 * (double)PI / 180.0);
|
||||
constexpr double angle_threshold = ::cos(10.0 * (double)PI / 180.0);
|
||||
|
||||
for (unsigned int i = 0; i < polygon.size(); ++i) {
|
||||
const Vec3d& prec = polygon[(i == 0) ? polygon.size() - 1 : i - 1];
|
||||
@ -334,6 +324,21 @@ void GLGizmoFlatten::update_planes()
|
||||
m_first_instance_mirror = mo->instances.front()->get_mirror();
|
||||
m_old_model_object = mo;
|
||||
|
||||
// And finally create respective VBOs. The polygon is convex with
|
||||
// the vertices in order, so triangulation is trivial.
|
||||
for (auto& plane : m_planes) {
|
||||
plane.vbo.reserve(plane.vertices.size());
|
||||
for (const auto& vert : plane.vertices)
|
||||
plane.vbo.push_geometry(vert, plane.normal);
|
||||
for (size_t i=1; i<plane.vertices.size()-1; ++i)
|
||||
plane.vbo.push_triangle(0, i, i+1); // triangle fan
|
||||
plane.vbo.finalize_geometry(true);
|
||||
// FIXME: vertices should really be local, they need not
|
||||
// persist now when we use VBOs
|
||||
plane.vertices.clear();
|
||||
plane.vertices.shrink_to_fit();
|
||||
}
|
||||
|
||||
m_planes_valid = true;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ private:
|
||||
mutable Vec3d m_normal;
|
||||
|
||||
struct PlaneData {
|
||||
std::vector<Vec3d> vertices;
|
||||
std::vector<Vec3d> vertices; // should be in fact local in update_planes()
|
||||
GLIndexedVertexArray vbo;
|
||||
Vec3d normal;
|
||||
float area;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user