21 static_assert(
Iterations > 0,
"Iterations must be greater than zero!");
57 [[nodiscard]]
bool done() const noexcept {
return mTriangles.done(); }
61 triangle_ = mTriangles.generate();
64 return Triangle{{vertexFromEdge(triangle_.vertices[0], triangle_.vertices[1]), vertexFromEdge(triangle_.vertices[1], triangle_.vertices[2]),
65 vertexFromEdge(triangle_.vertices[2], triangle_.vertices[0])}};
68 const int j = (i_ + 1) % 3;
69 const int k = (i_ + 2) % 3;
70 return Triangle{{triangle_.
vertices[i_], vertexFromEdge(triangle_.vertices[i_], triangle_.vertices[j]),
71 vertexFromEdge(triangle_.vertices[k], triangle_.vertices[i_])}};
96 return static_cast<int>(mMesh->mVertexCache.size()) + mMesh->edgeMap_.at({a, b});
104 [[nodiscard]]
bool done() const noexcept {
return vertexIndex_ == mMesh->mVertexCache.size() && edgeIndex_ == mMesh->edgeCache_.size(); }
107 if(vertexIndex_ < mMesh->mVertexCache.size())
108 return mMesh->mVertexCache[vertexIndex_];
110 const MeshVertex& v1 = mMesh->mVertexCache[mMesh->edgeCache_[edgeIndex_].vertices[0]];
111 const MeshVertex& v2 = mMesh->mVertexCache[mMesh->edgeCache_[edgeIndex_].vertices[1]];
121 if(vertexIndex_ < mMesh->mVertexCache.size())
139 for(
const MeshVertex& vertex : mMesh.vertices()) {
140 mVertexCache.push_back(vertex);
143 for(
const Triangle& triangle : mMesh.triangles()) {
144 for(
int i = 0; i < 3; ++i) {
145 const int j = (i + 1) % 3;
147 Edge e{{triangle.vertices[i], triangle.vertices[j]}};
148 if(e.vertices[0] > e.vertices[1])
149 std::swap(e.vertices[0], e.vertices[1]);
151 if(edgeMap_.find(e.vertices) == edgeMap_.end()) {
152 edgeMap_[e.vertices] =
static_cast<int>(edgeCache_.size());
153 edgeCache_.push_back(e);
159 [[nodiscard]] Triangles
triangles() const noexcept {
return *
this; }
161 [[nodiscard]] Vertices
vertices() const noexcept {
return *
this; }
Definition MeshVertex.hpp:14
Vector3 normal
Unit vector perpendicular to the surface.
Definition MeshVertex.hpp:19
Vector2 texCoord
UV texture coordinates.
Definition MeshVertex.hpp:22
Vector3 position
Definition MeshVertex.hpp:16
Vertices vertices() const noexcept
Definition SubdivideMesh.hpp:49
typename Impl::Vertices Vertices
Definition SubdivideMesh.hpp:48
Impl mMesh
Definition SubdivideMesh.hpp:40
typename Impl::Triangles Triangles
Definition SubdivideMesh.hpp:45
Triangles triangles() const noexcept
Definition SubdivideMesh.hpp:46
SubdivideMesh(Mesh mesh)
Definition SubdivideMesh.hpp:43
const SubdivideMesh * mMesh
Definition SubdivideMesh.hpp:83
void next()
Definition SubdivideMesh.hpp:74
TriangleGeneratorType< Mesh >::Type mTriangles
Definition SubdivideMesh.hpp:87
int i_
Definition SubdivideMesh.hpp:85
Triangle triangle_
Definition SubdivideMesh.hpp:89
int vertexFromEdge(int a, int b) const
Definition SubdivideMesh.hpp:93
Triangles(const SubdivideMesh &mesh)
Definition SubdivideMesh.hpp:91
Triangle generate() const
Definition SubdivideMesh.hpp:59
bool done() const noexcept
Definition SubdivideMesh.hpp:57
const SubdivideMesh * mMesh
Definition SubdivideMesh.hpp:128
Vertices(const SubdivideMesh &mesh)
Definition SubdivideMesh.hpp:133
void next()
Definition SubdivideMesh.hpp:120
int edgeIndex_
Definition SubdivideMesh.hpp:130
MeshVertex generate() const
Definition SubdivideMesh.hpp:106
int vertexIndex_
Definition SubdivideMesh.hpp:131
bool done() const noexcept
Definition SubdivideMesh.hpp:104
SubdivideMesh(Mesh mesh)
Definition SubdivideMesh.hpp:138
Triangles triangles() const noexcept
Definition SubdivideMesh.hpp:159
Mesh mMesh
Definition SubdivideMesh.hpp:164
Map< Vector2i, int > edgeMap_
Definition SubdivideMesh.hpp:168
Vector< Edge > edgeCache_
Definition SubdivideMesh.hpp:166
Vertices vertices() const noexcept
Definition SubdivideMesh.hpp:161
Vector< MeshVertex > mVertexCache
Definition SubdivideMesh.hpp:170
Definition SubdivideMesh.hpp:20
SubdivideMesh(Mesh mesh)
Definition SubdivideMesh.hpp:28
Vertices vertices() const noexcept
Definition SubdivideMesh.hpp:34
typename Impl::Triangles Triangles
Definition SubdivideMesh.hpp:30
Impl mSubdivideMesh
Definition SubdivideMesh.hpp:25
typename Impl::Vertices Vertices
Definition SubdivideMesh.hpp:33
Triangles triangles() const noexcept
Definition SubdivideMesh.hpp:31
decltype(std::declval< const Primitive * >() ->triangles()) Type
Definition Utility.hpp:32
Definition Triangle.hpp:14
Vector3i vertices
Zero based indices of the triangle vertices in counterclockwise order.
Definition Triangle.hpp:17
A base class for all mesh implementations.
Definition Mesh.hpp:112
Definition AnyGenerator.hpp:12
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24