14{
15 struct MeshFacetRange {
16 MeshFacetRange(TriangleMesh* tm, uint32_t facet_begin, uint32_t facet_end) :
17 tm(tm), facet_begin(facet_begin), facet_end(facet_end) {}
18 MeshFacetRange() : tm(nullptr), facet_begin(0), facet_end(0) {}
19 TriangleMesh* tm;
20 uint32_t facet_begin;
21 uint32_t facet_end;
22 };
23
24 TriangleMesh object_mesh;
25 std::vector<MeshFacetRange> volume_facet_ranges;
26 for (
int i = 0; i <
m_meshes.size(); i++) {
28 volume_facet_ranges.emplace_back(&
m_meshes[i], object_mesh.stats().number_of_facets, object_mesh.stats().number_of_facets + vol_mesh.stats().number_of_facets);
29
31 object_mesh.merge(std::move(vol_mesh));
32 }
33
34 sla::IndexedMesh indexed_mesh(object_mesh);
35 BoundingBoxf3 bbox = object_mesh.bounding_box();
37
38 std::unordered_set<size_t> hit_face_indices;
39
40
43 auto hit_result = indexed_mesh.query_ray_hit({ bbox.min.x(), y, z }, { 1.0, 0.0, 0.0 });
44 if (hit_result.is_hit())
45 hit_face_indices.insert(hit_result.face());
46
47 hit_result = indexed_mesh.query_ray_hit({ bbox.max.x(), y, z }, { -1.0, 0.0, 0.0 });
48 if (hit_result.is_hit())
49 hit_face_indices.insert(hit_result.face());
50 }
51 }
52
53
56 auto hit_result = indexed_mesh.query_ray_hit({ x, bbox.min.y(), z }, { 0.0, 1.0, 0.0 });
57 if (hit_result.is_hit())
58 hit_face_indices.insert(hit_result.face());
59
60 hit_result = indexed_mesh.query_ray_hit({ x, bbox.max.y(), z }, { 0.0, -1.0, 0.0 });
61 if (hit_result.is_hit())
62 hit_face_indices.insert(hit_result.face());
63 }
64 }
65
66
69 auto hit_result = indexed_mesh.query_ray_hit({ x, y, bbox.min.z() }, { 0.0, 0.0, 1.0 });
70 if (hit_result.is_hit())
71 hit_face_indices.insert(hit_result.face());
72
73 hit_result = indexed_mesh.query_ray_hit({ x, y, bbox.max.z() }, { 0.0, 0.0, -1.0 });
74 if (hit_result.is_hit())
75 hit_face_indices.insert(hit_result.face());
76 }
77 }
78
79 for (size_t facet_idx : hit_face_indices) {
80 TriangleMesh* tm = nullptr;
81 uint32_t vol_facet_idx = 0;
82 for (
auto range : volume_facet_ranges) {
83 if (facet_idx >=
range.facet_begin && facet_idx <
range.facet_end) {
85 vol_facet_idx = facet_idx -
range.facet_begin;
86 break;
87 }
88 }
89
90 tm->its.get_property(vol_facet_idx).type = EnumFaceTypes::eExteriorAppearance;
91 }
92}
static const double BBOX_OFFSET
Definition FaceDetector.cpp:12
auto range(Cont &&cont)
Definition libslic3r.h:405