CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AnyMesh.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 "AnyGenerator.hpp"
11#include "MeshVertex.hpp"
12#include "Triangle.hpp"
13
15
17
19 class AnyMesh {
20 public:
21 template<typename Mesh> AnyMesh(Mesh mesh) : mBase{new Derived<Mesh>{std::move(mesh)}} {}
22
25
26 AnyMesh(AnyMesh&&) = default;
27 AnyMesh& operator=(AnyMesh&&) = default;
28
31
32 private:
34 public:
35 virtual ~Base();
36 [[nodiscard]] virtual UPtr<Base> clone() const = 0;
39 };
40
41 template<typename Mesh> class Derived : public Base {
42 public:
43 Derived(Mesh mesh) : mMesh(std::move(mesh)) {}
44
45 [[nodiscard]] virtual UPtr<Base> clone() const override { return UPtr<Base>{new Derived{mMesh}}; }
46 [[nodiscard]] virtual AnyGenerator<Triangle> triangles() const override { return mMesh.triangles(); }
47 [[nodiscard]] virtual AnyGenerator<MeshVertex> vertices() const override { return mMesh.vertices(); }
48
50 };
51
53 };
54
55} // namespace CeresEngine::MeshGenerator
A type erasing container that can store any generator that generates type T.
Definition AnyGenerator.hpp:16
virtual AnyGenerator< MeshVertex > vertices() const =0
virtual AnyGenerator< Triangle > triangles() const =0
virtual UPtr< Base > clone() const =0
virtual UPtr< Base > clone() const override
Definition AnyMesh.hpp:45
virtual AnyGenerator< Triangle > triangles() const override
Definition AnyMesh.hpp:46
virtual AnyGenerator< MeshVertex > vertices() const override
Definition AnyMesh.hpp:47
Mesh mMesh
Definition AnyMesh.hpp:49
Derived(Mesh mesh)
Definition AnyMesh.hpp:43
A type erasing container that can store any mesh.
Definition AnyMesh.hpp:19
AnyMesh(Mesh mesh)
Definition AnyMesh.hpp:21
UPtr< Base > mBase
Definition AnyMesh.hpp:52
AnyMesh & operator=(AnyMesh &&)=default
AnyMesh & operator=(const AnyMesh &that)
AnyGenerator< Triangle > triangles() const noexcept
Definition MeshVertex.hpp:14
A base class for all mesh implementations.
Definition Mesh.hpp:112
Definition AnyGenerator.hpp:12
std::unique_ptr< T, Deleter > UPtr
UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that o...
Definition SmartPtr.hpp:28
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
Definition Span.hpp:668