Unravel Engine C++ Reference
Loading...
Searching...
No Matches
merge_mesh.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_MERGEMESH_HPP
2#define GENERATOR_MERGEMESH_HPP
3
4#include "empty_mesh.hpp"
5#include "mesh_vertex.hpp"
6#include "utils.hpp"
7
8namespace generator
9{
10
12template<typename... Mesh>
13class merge_mesh_t; // undefined
14
15template<>
16class merge_mesh_t<> : public empty_mesh
17{
18};
19
20template<typename Head, typename... Tail>
21class merge_mesh_t<Head, Tail...>
22{
23public:
25 {
26 public:
28 {
29 if(!head_.done())
30 return head_.generate();
31
32 triangle_t triangle = tail_.generate();
33 triangle.vertices += head_vertex_count_;
34 return triangle;
35 }
36
37 bool done() const noexcept
38 {
39 return all_done_;
40 }
41
42 void next()
43 {
44 if(!head_.done())
45 head_.next();
46 else
47 tail_.next();
48
49 all_done_ = tail_.done() && head_.done();
50 }
51
52 private:
54 typename triangle_generator_type<merge_mesh_t<Tail...>>::type tail_;
55
56 int head_vertex_count_;
57
58 bool all_done_;
59
60 explicit triangles_t(const merge_mesh_t& mesh)
61 : head_{mesh.head_.triangles()}
62 , tail_(mesh.tail_.triangles())
63 , head_vertex_count_{count(mesh.head_.vertices())}
64 , all_done_{tail_.done() && head_.done()}
65 {
66 }
67
68 friend class merge_mesh_t<Head, Tail...>;
69 };
70
72 {
73 public:
75 {
76 if(!head_.done())
77 return head_.generate();
78 return tail_.generate();
79 }
80
81 bool done() const noexcept
82 {
83 return all_done_;
84 }
85
86 void next()
87 {
88 if(!head_.done())
89 head_.next();
90 else
91 tail_.next();
92
93 all_done_ = tail_.done() && head_.done();
94 }
95
96 private:
98 typename vertex_generator_type<merge_mesh_t<Tail...>>::type tail_;
99
100 bool all_done_;
101
102 explicit vertices_t(const merge_mesh_t& mesh)
103 : head_{mesh.head_.vertices()}
104 , tail_(mesh.tail_.vertices())
105 , all_done_{tail_.done() && head_.done()}
106 {
107 }
108
109 friend class merge_mesh_t<Head, Tail...>;
110 };
111
112 merge_mesh_t(Head head, Tail... tail) : head_{std::move(head)}, tail_{std::move(tail)...}
113 {
114 }
115
116 triangles_t triangles() const noexcept
117 {
118 return triangles_t{*this};
119 }
120
121 vertices_t vertices() const noexcept
122 {
123 return vertices_t{*this};
124 }
125
126private:
127 Head head_;
128 merge_mesh_t<Tail...> tail_;
129};
130
131template<typename... Mesh>
132merge_mesh_t<Mesh...> merge_mesh(Mesh... meshes)
133{
134 return merge_mesh_t<Mesh...>{std::move(meshes)...};
135}
136} // namespace generator
137
138#endif
manifold_type type
Empty Mesh with zero vertices and triangles.
vertices_t vertices() const noexcept
triangles_t triangles() const noexcept
merge_mesh_t(Head head, Tail... tail)
Merges (concatenates) multiple meshes to to together.
gml::ivec3 vertices
Zero based indices of the triangle vertices in counterclockwise order.
Definition triangle.hpp:13
int count(const generator_t &generator) noexcept
Counts the number of steps left in the generator.
Definition utils.hpp:70
merge_mesh_t< Mesh... > merge_mesh(Mesh... meshes)