Unravel Engine C++ Reference
Loading...
Searching...
No Matches
axis_swap_mesh.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_AXISSWAPMESH_HPP
2#define GENERATOR_AXISSWAPMESH_HPP
3
4#include "axis.hpp"
5#include "transform_mesh.hpp"
6#include "triangle.hpp"
7
8namespace generator
9{
10
12template<typename mesh_t>
14{
15private:
17 impl_t transform_mesh_;
18
19public:
21 {
22 public:
24 {
25 triangle_t triangle = triangles_.generate();
26 if(mesh_->flip_)
27 std::swap(triangle.vertices[0], triangle.vertices[2]);
28 return triangle;
29 }
30
31 bool done() const noexcept
32 {
33 return triangles_.done();
34 }
35
36 void next()
37 {
38 triangles_.next();
39 }
40
41 private:
42 const axis_swap_mesh_t* mesh_;
43
45
46 explicit triangles_t(const axis_swap_mesh_t& mesh) : mesh_{&mesh}, triangles_{mesh.transform_mesh_.triangles()}
47 {
48 }
49
50 friend class axis_swap_mesh_t;
51 };
52
58 : transform_mesh_{std::move(mesh),
59 [x, y, z](mesh_vertex_t& vertex)
60 {
61 vertex.position = gml::dvec3{vertex.position[static_cast<int>(x)],
62 vertex.position[static_cast<int>(y)],
63 vertex.position[static_cast<int>(z)]};
64 vertex.normal = gml::dvec3{vertex.normal[static_cast<int>(x)],
65 vertex.normal[static_cast<int>(y)],
66 vertex.normal[static_cast<int>(z)]};
67 }}
68 , flip_{true}
69 {
70 if(x != axis_t::X)
71 flip_ = !flip_;
72 if(y != axis_t::Y)
73 flip_ = !flip_;
74 if(z != axis_t::Z)
75 flip_ = !flip_;
76 }
77
78 triangles_t triangles() const noexcept
79 {
80 return triangles_t{*this};
81 }
82
84
85 vertices_t vertices() const noexcept
86 {
87 return transform_mesh_.vertices();
88 }
89
90private:
91 bool flip_;
92};
93
94template<typename mesh_t>
96{
97 return axis_swap_mesh_t<mesh_t>{std::move(mesh), x, y, z};
98}
99} // namespace generator
100
101#endif
manifold_type type
Swaps any number of axis in the mesh.
vertices_t vertices() const noexcept
axis_swap_mesh_t(mesh_t mesh, axis_t x, axis_t y, axis_t z)
typename impl_t::vertices_t vertices_t
triangles_t triangles() const noexcept
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_swap_mesh_t< mesh_t > axis_swap_mesh(mesh_t mesh, axis_t x, axis_t y, axis_t z)
float y
float x
float z