Files
OrcaSlicer/src/libslic3r/TriangleMeshDeal.cpp
Ian Bassi 68fdfcf0eb BBS Port: Mesh Subdivision (#12150)
Ported from BBS
You can now right-click a part and choose Subdivide Part to apply Loop subdivision with multiple iterations. This is useful for models with low original mesh resolution.

> [!NOTE]
> 1. Only meshes without non-manifold edges are supported.
> 2. Color attributes will be lost after subdivision. We recommend subdividing first, then painting and applying colors.

Not perfect and it can break some features but a nice to have and we can improve it.
https://github.com/user-attachments/assets/33f10e49-f6dc-44d3-8c21-9e12e1fe23dc

Best case scenario a sphere:
Each picture is a Mesh subdivision step over the other
<img width="541" height="495" alt="260202_164257_orca-slicer" src="https://github.com/user-attachments/assets/e62b3f4d-ee6b-4451-95a4-40a154d3a405" />
<img width="541" height="495" alt="260202_164302_%pn" src="https://github.com/user-attachments/assets/f7399457-be8d-45e7-b93f-f42064dadd64" />
<img width="541" height="495" alt="260202_164306_%pn" src="https://github.com/user-attachments/assets/55370035-219f-4b7f-94f4-9b31733820d6" />
<img width="541" height="495" alt="260202_164310_%pn" src="https://github.com/user-attachments/assets/3be8c904-cc6f-4efe-b4f8-f390b50d310c" />
2026-02-12 08:42:01 +08:00

56 lines
2.2 KiB
C++

#include "TriangleMeshDeal.hpp"
#include <igl/read_triangle_mesh.h>
#include <igl/loop.h>
#include <igl/upsample.h>
#include <igl/false_barycentric_subdivision.h>
namespace Slic3r {
TriangleMesh TriangleMeshDeal::smooth_triangle_mesh(const TriangleMesh &mesh, bool &ok)
{
{
using namespace std;
using namespace igl;
Eigen::MatrixXi OF, F;
Eigen::MatrixXd OV, V;
auto vertices_count = mesh.its.vertices.size();
OV = Eigen::MatrixXd(vertices_count, 3);
for (int i = 0; i < vertices_count; i++) {
auto v = mesh.its.vertices[i];
OV.row(i) << v[0], v[1], v[2];
}
auto indices_count = mesh.its.indices.size();
OF = Eigen::MatrixXi(indices_count, 3);
for (int i = 0; i < indices_count; i++) {
auto face = mesh.its.indices[i];
OF.row(i) << face[0], face[1], face[2];
}
//igl:: read_triangle_mesh( "E:/Download/libigl-2.6.0/out/build/x64-Debug/_deps/libigl_tutorial_data-src/decimated-knight.off", OV, OF);
V = OV;
F = OF;
//igl::upsample(Eigen::MatrixXd(V), Eigen::MatrixXi(F), V, F);
ok = true;
if (!igl::loop(Eigen::MatrixXd(V), Eigen::MatrixXi(F), V, F)) {
ok = false;
return TriangleMesh();
}
//igl::false_barycentric_subdivision(Eigen::MatrixXd(V), Eigen::MatrixXi(F), V, F);
indexed_triangle_set its;
int vertex_count = V.rows();
its.vertices.resize(vertex_count);
for (int i = 0; i < vertex_count; i++) {
its.vertices[i] = V.row(i).cast<float>();
}
int indice_count = F.rows();
its.indices.resize(indice_count);
for (int i = 0; i < indice_count; i++) {
auto cur = F.row(i);
its.indices[i] = Slic3r::Vec3i32(cur[0], cur[1], cur[2]);
}
TriangleMesh result_mesh(its);
return result_mesh;
}
}
} // namespace Slic3r