mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-05 11:17:58 -05:00
Fix the Lay on Face delay when Smooth normals is on (#16846)
This commit is contained in:
1 parent
e2590f7559
commit
09aa0114b4
4 files changed
+281
-45
No files matched your search
@@ -35,45 +35,11 @@
|
||||
#include <cstdlib>
|
||||
#include "libslic3r/Geometry.hpp"
|
||||
|
||||
#if defined(L)
|
||||
#undef L
|
||||
#endif
|
||||
|
||||
#include <igl/per_face_normals.h>
|
||||
#include <igl/per_corner_normals.h>
|
||||
#include <igl/per_vertex_normals.h>
|
||||
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static void smooth_normals_corner(const TriangleMesh& mesh, std::vector<stl_normal>& normals)
|
||||
{
|
||||
using MapMatrixXfUnaligned = Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>>;
|
||||
using MapMatrixXiUnaligned = Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>>;
|
||||
|
||||
std::vector<Vec3f> face_normals = its_face_normals(mesh.its);
|
||||
|
||||
Eigen::MatrixXd vertices = MapMatrixXfUnaligned(mesh.its.vertices.front().data(),
|
||||
Eigen::Index(mesh.its.vertices.size()), 3).cast<double>();
|
||||
Eigen::MatrixXi indices = MapMatrixXiUnaligned(mesh.its.indices.front().data(),
|
||||
Eigen::Index(mesh.its.indices.size()), 3);
|
||||
Eigen::MatrixXd in_normals = MapMatrixXfUnaligned(face_normals.front().data(),
|
||||
Eigen::Index(face_normals.size()), 3).cast<double>();
|
||||
Eigen::MatrixXd out_normals;
|
||||
|
||||
igl::per_corner_normals(vertices, indices, 1.0, out_normals);
|
||||
|
||||
normals = std::vector<stl_normal>(mesh.its.vertices.size());
|
||||
for (size_t i = 0; i < mesh.its.indices.size(); ++i) {
|
||||
for (size_t j = 0; j < 3; ++j) {
|
||||
normals[mesh.its.indices[i][j]] = out_normals.row(i * 3 + j).cast<float>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLModel::Geometry::add_vertex(const Vec2f& position)
|
||||
{
|
||||
assert(format.vertex_layout == EVertexLayout::P2);
|
||||
@@ -482,21 +448,13 @@ void GLModel::init_from(const indexed_triangle_set& its)
|
||||
wxGetApp().app_config->get_bool(SETTING_OPENGL_PHONG_SMOOTH_NORMALS);
|
||||
|
||||
if (smooth_normals_enabled) {
|
||||
// Use per-corner smooth normals (via IGL)
|
||||
using MapMatrixXfUnaligned = Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>>;
|
||||
using MapMatrixXiUnaligned = Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>>;
|
||||
Eigen::MatrixXd vertices = MapMatrixXfUnaligned(its.vertices.front().data(), Eigen::Index(its.vertices.size()), 3).cast<double>();
|
||||
Eigen::MatrixXi indices = MapMatrixXiUnaligned(its.indices.front().data(), Eigen::Index(its.indices.size()), 3);
|
||||
Eigen::MatrixXd corner_normals;
|
||||
igl::per_corner_normals(vertices, indices, 5.0, corner_normals);
|
||||
const std::vector<Vec3f> corner_normals = its_smooth_corner_normals(its, 5.0);
|
||||
|
||||
unsigned int vertices_counter = 0;
|
||||
for (uint32_t i = 0; i < its.indices.size(); ++i) {
|
||||
const stl_triangle_vertex_indices face = its.indices[i];
|
||||
for (size_t j = 0; j < 3; ++j) {
|
||||
const Vec3f normal = corner_normals.row(Eigen::Index(i * 3 + j)).cast<float>();
|
||||
data.add_vertex(its.vertices[face[j]], normal);
|
||||
}
|
||||
for (size_t j = 0; j < 3; ++j)
|
||||
data.add_vertex(its.vertices[face[j]], corner_normals[3 * i + j]);
|
||||
data.add_triangle(vertices_counter, vertices_counter + 1, vertices_counter + 2);
|
||||
vertices_counter += 3;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user