Unravel Engine C++ Reference
Loading...
Searching...
No Matches
axis_flip_mesh.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_AXISFLIPMESH_HPP
2#define GENERATOR_AXISFLIPMESH_HPP
3
4#include "transform_mesh.hpp"
5#include "triangle.hpp"
6
7namespace generator
8{
9
13template<typename mesh_t>
15{
16private:
18 impl_t transform_mesh_;
19
20public:
22 {
23 public:
25 {
26 triangle_t triangle = triangles_.generate();
27 if(mesh_->flip_)
28 std::swap(triangle.vertices[0], triangle.vertices[2]);
29 return triangle;
30 }
31
32 bool done() const noexcept
33 {
34 return triangles_.done();
35 }
36
37 void next()
38 {
39 triangles_.next();
40 }
41
42 private:
43 const axis_flip_mesh_t* mesh_;
44
46
47 explicit triangles_t(const axis_flip_mesh_t& mesh) : mesh_{&mesh}, triangles_{mesh.transform_mesh_.triangles()}
48 {
49 }
50
51 friend class axis_flip_mesh_t;
52 };
53
58 axis_flip_mesh_t(mesh_t mesh, bool x, bool y, bool z)
59 : transform_mesh_{std::move(mesh),
60 [x, y, z](mesh_vertex_t& vertex)
61 {
62 if(x)
63 {
64 vertex.position[0] *= -1.0;
65 vertex.normal[0] *= -1.0;
66 }
67
68 if(y)
69 {
70 vertex.position[1] *= -1.0;
71 vertex.normal[1] *= -1.0;
72 }
73
74 if(z)
75 {
76 vertex.position[2] *= -1.0;
77 vertex.normal[2] *= -1.0;
78 }
79 }}
80 , flip_{false}
81 {
82 if(x)
83 flip_ = !flip_;
84 if(y)
85 flip_ = !flip_;
86 if(z)
87 flip_ = !flip_;
88 }
89
90 triangles_t triangles() const noexcept
91 {
92 return triangles_t{*this};
93 }
94
96
97 vertices_t vertices() const noexcept
98 {
99 return transform_mesh_.vertices();
100 }
101
102private:
103 bool flip_ = false;
104};
105
106template<typename mesh_t>
107axis_flip_mesh_t<mesh_t> axis_flip_mesh(mesh_t mesh, bool x, bool y, bool z)
108{
109 return axis_flip_mesh_t<mesh_t>{std::move(mesh), x, y, z};
110}
111} // namespace generator
112
113#endif
manifold_type type
axis_flip_mesh_t(mesh_t mesh, bool x, bool y, bool z)
triangles_t triangles() const noexcept
vertices_t vertices() const noexcept
typename impl_t::vertices_t vertices_t
Apply a mutator function to each vertex.
gml::ivec3 vertices
Zero based indices of the triangle vertices in counterclockwise order.
Definition triangle.hpp:13
axis_flip_mesh_t< mesh_t > axis_flip_mesh(mesh_t mesh, bool x, bool y, bool z)
float y
float x
float z