MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / bsp_to_raw

Function bsp_to_raw

tools/Boolean/BSP/BSPEngine.cpp:51–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 void bsp_to_raw(const BSPPtr bsp, MatrixFr& vertices, MatrixIr& faces) {
52 const auto convex_polys = bsp->GetBoundary();
53 std::vector<BSPlib::MetricPolygon> metric_polys(convex_polys.size());
54 std::transform(convex_polys.begin(), convex_polys.end(),
55 metric_polys.begin(), [](const BSPlib::ConvexPolygon& p) {
56 return BSPlib::Approximate(p); });
57 PLYmesh mesh;
58 Metric2Ply(metric_polys, mesh);
59 Write("out.ply", mesh);
60
61 const size_t num_vertices = mesh.vertices.size() / 3;
62 assert(mesh.vertices.size() % 3 == 0);
63 vertices.resize(num_vertices, 3);
64 std::copy(mesh.vertices.begin(), mesh.vertices.end(),
65 vertices.data());
66
67 const size_t num_faces = mesh.faces.size();
68 std::vector<int> triangles;
69 for (size_t i=0; i<num_faces; i++) {
70 const auto f = mesh.faces[i];
71 if (f.size() == 3) {
72 triangles.insert(triangles.end(), f.begin(), f.end());
73 } else if (f.size() == 4) {
74 triangles.push_back(f[0]);
75 triangles.push_back(f[1]);
76 triangles.push_back(f[2]);
77
78 triangles.push_back(f[0]);
79 triangles.push_back(f[2]);
80 triangles.push_back(f[3]);
81 } else {
82 const size_t vertex_per_face = f.size();
83 for (size_t vid=2; vid<vertex_per_face; vid++) {
84 triangles.push_back(f[0]);
85 triangles.push_back(f[vid-1]);
86 triangles.push_back(f[vid]);
87 }
88 }
89 }
90 faces.resize(triangles.size()/3, 3);
91 std::copy(triangles.begin(), triangles.end(), faces.data());
92 }
93}
94
95using namespace BSPEngineHelper;

Callers 4

compute_unionMethod · 0.85
compute_intersectionMethod · 0.85
compute_differenceMethod · 0.85

Calls 5

WriteFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected