CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TransformMesh.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 "MeshVertex.hpp"
11#include "Utility.hpp"
12
14
16
18 template<typename Mesh> class TransformMesh {
19 private:
20 using Impl = Mesh;
22
23 public:
24 class Vertices {
25 public:
27 auto vertex = vertices_.generate();
28 mMesh->mutate_(vertex);
29 return vertex;
30 }
31
32 [[nodiscard]] bool done() const noexcept { return vertices_.done(); }
33
34 void next() { vertices_.next(); }
35
36 private:
38
40
41 explicit Vertices(const TransformMesh& mesh) : mMesh{&mesh}, vertices_{mesh.mMesh.vertices()} {}
42
43 friend class TransformMesh;
44 };
45
48 explicit TransformMesh(Mesh mesh, Function<void(MeshVertex&) const> mutate) : mMesh{std::move(mesh)}, mutate_{std::move(mutate)} {}
49
50 using Triangles = typename Impl::Triangles;
51
52 [[nodiscard]] Triangles triangles() const noexcept { return mMesh.triangles(); }
54
55 private:
57 };
58
59 template<typename Mesh> TransformMesh<Mesh> transformMesh(Mesh mesh, Function<void(MeshVertex&) const> mutate) {
60 return TransformMesh<Mesh>{std::move(mesh), std::move(mutate)};
61 }
62
63} // namespace CeresEngine::MeshGenerator
Definition MeshVertex.hpp:14
MeshVertex generate() const
Definition TransformMesh.hpp:26
bool done() const noexcept
Definition TransformMesh.hpp:32
const TransformMesh * mMesh
Definition TransformMesh.hpp:37
VertexGeneratorType< Mesh >::Type vertices_
Definition TransformMesh.hpp:39
void next()
Definition TransformMesh.hpp:34
Vertices(const TransformMesh &mesh)
Definition TransformMesh.hpp:41
Apply a mutator function to each vertex.
Definition TransformMesh.hpp:18
Impl mMesh
Definition TransformMesh.hpp:21
Vertices vertices() const noexcept
Definition TransformMesh.hpp:53
TransformMesh(Mesh mesh, Function< void(MeshVertex &) const > mutate)
Definition TransformMesh.hpp:48
typename Impl::Triangles Triangles
Definition TransformMesh.hpp:50
Triangles triangles() const noexcept
Definition TransformMesh.hpp:52
Function< void(MeshVertex &) const > mutate_
Definition TransformMesh.hpp:56
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
TransformMesh< Mesh > transformMesh(Mesh mesh, Function< void(MeshVertex &) const > mutate)
Definition TransformMesh.hpp:59
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
FunctionBase< true, true, fu2::capacity_default, true, false, Signatures... > Function
An owning copyable function wrapper for arbitrary callable types.
Definition Function.hpp:54
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668