CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MergeMesh.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "EmptyMesh.hpp"
11#include "MeshVertex.hpp"
12#include "Utility.hpp"
13
15
17 template<typename... Mesh> class MergeMesh; // undefined
18
19 template<> class MergeMesh<> : public EmptyMesh {};
20
21 template<typename Head, typename... Tail> class MergeMesh<Head, Tail...> {
22 public:
23 class Triangles {
24 public:
25 [[nodiscard]] Triangle generate() const {
26 if(!mHead.done())
27 return mHead.generate();
28
29 Triangle triangle = mTail.generate();
30 triangle.vertices += mHeadVertexCount;
31 return triangle;
32 }
33
34 [[nodiscard]] bool done() const noexcept { return mAllDone; }
35
36 void next() {
37 if(!mHead.done())
38 mHead.next();
39 else
40 mTail.next();
41
42 mAllDone = mTail.done() && mHead.done();
43 }
44
45 private:
47 typename TriangleGeneratorType<MergeMesh<Tail...>>::Type mTail;
48
51
52 Triangles(const MergeMesh& mesh)
53 : mHead{mesh.mHead.triangles()},
54 mTail(mesh.mTail.triangles()), mHeadVertexCount{count(mesh.mHead.vertices())}, mAllDone{mTail.done() && mHead.done()} {}
55
56 friend class MergeMesh<Head, Tail...>;
57 };
58
59 class Vertices {
60 public:
61 [[nodiscard]] MeshVertex generate() const {
62 if(!mHead.done())
63 return mHead.generate();
64 return mTail.generate();
65 }
66
67 [[nodiscard]] bool done() const noexcept { return mAllDone; }
68
69 void next() {
70 if(!mHead.done())
71 mHead.next();
72 else
73 mTail.next();
74
75 mAllDone = mTail.done() && mHead.done();
76 }
77
78 private:
80 typename VertexGeneratorType<MergeMesh<Tail...>>::Type mTail;
81
83
84 Vertices(const MergeMesh& mesh) : mHead{mesh.mHead.vertices()}, mTail(mesh.mTail.vertices()), mAllDone{mTail.done() && mHead.done()} {}
85
86 friend class MergeMesh<Head, Tail...>;
87 };
88
89 MergeMesh(Head head, Tail... tail) : mHead{std::move(head)}, mTail{std::move(tail)...} {}
90
91 [[nodiscard]] Triangles triangles() const noexcept { return *this; }
92
93 [[nodiscard]] Vertices vertices() const noexcept { return *this; }
94
95 private:
96 Head mHead;
97 MergeMesh<Tail...> mTail;
98 };
99
100 template<typename... Mesh> MergeMesh<Mesh...> mergeMesh(Mesh... meshes) { return MergeMesh<Mesh...>{std::move(meshes)...}; }
101
102} // namespace CeresEngine::MeshGenerator
Empty Mesh with zero vertices and triangles.
Definition EmptyMesh.hpp:17
Triangle generate() const
Definition MergeMesh.hpp:25
bool done() const noexcept
Definition MergeMesh.hpp:34
TriangleGeneratorType< MergeMesh< Tail... > >::Type mTail
Definition MergeMesh.hpp:47
TriangleGeneratorType< Head >::Type mHead
Definition MergeMesh.hpp:46
bool done() const noexcept
Definition MergeMesh.hpp:67
VertexGeneratorType< MergeMesh< Tail... > >::Type mTail
Definition MergeMesh.hpp:80
VertexGeneratorType< Head >::Type mHead
Definition MergeMesh.hpp:79
MeshVertex generate() const
Definition MergeMesh.hpp:61
Triangles triangles() const noexcept
Definition MergeMesh.hpp:91
MergeMesh< Tail... > mTail
Definition MergeMesh.hpp:97
Vertices vertices() const noexcept
Definition MergeMesh.hpp:93
MergeMesh(Head head, Tail... tail)
Definition MergeMesh.hpp:89
Merges (concatenates) multiple meshes to to together.
Definition MergeMesh.hpp:17
Definition MeshVertex.hpp:14
Will have a type named "Type" that has same type as value returned by method triangles() for type Pri...
Definition Utility.hpp:30
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
Will have a type named "Type" that has same type as value returned by method vertices() for type Prim...
Definition Utility.hpp:37
decltype(std::declval< const Primitive * >() ->vertices()) Type
Definition Utility.hpp:39
A base class for all mesh implementations.
Definition Mesh.hpp:112
Definition AnyGenerator.hpp:12
MergeMesh< Mesh... > mergeMesh(Mesh... meshes)
Definition MergeMesh.hpp:100
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668