Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Mesh.hpp
1/*
2Copyright (C) 2016-2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_MESH_H
17#define AEONGAMES_MESH_H
18#include <cstdint>
19#include <string>
20#include <memory>
21#include <vector>
22#include "aeongames/AABB.hpp"
23#include "aeongames/CRC.hpp"
24#include "aeongames/Resource.hpp"
25
26namespace AeonGames
27{
28 class MeshMsg;
30 class Mesh final : public Resource
31 {
32 public:
34 enum AttributeSemantic : uint32_t
35 {
36 POSITION = "VertexPosition"_crc32,
37 NORMAL = "VertexNormal"_crc32,
38 TANGENT = "VertexTangent"_crc32,
39 BITANGENT = "VertexBitangent"_crc32,
40 TEXCOORD = "VertexUV"_crc32,
41 WEIGHT_INDEX = "VertexWeightIndices"_crc32,
42 WEIGHT_VALUE = "VertexWeights"_crc32,
43 COLOR = "VertexColor"_crc32,
44 };
45
47 enum AttributeType : uint8_t
48 {
49 BYTE = 0,
51 SHORT = 2,
54 INT = 5,
56 FLOAT = 7,
57 FIXED = 8,
58 DOUBLE = 9,
59 };
60
62 enum AttributeFlag : uint8_t
63 {
64 NORMALIZED = 0b00000001,
65 INTEGER = 0b00000010,
66 };
67
69 enum BindingLocations : uint32_t
70 {
71 MATRICES = "Matrices"_crc32,
72 MATERIAL = "Material"_crc32,
73 SKELETON = "Skeleton"_crc32,
74 SAMPLERS = "Samplers"_crc32,
75 };
76
78 using AttributeSize = uint8_t;
80 using AttributeFlags = uint8_t;
82 using AttributeTuple = std::tuple<AttributeSemantic, AttributeSize, AttributeType, AttributeFlags>;
84 DLL Mesh();
86 DLL ~Mesh() final;
90 DLL void LoadFromPBMsg ( const MeshMsg& aMeshMsg );
95 DLL void LoadFromMemory ( const void* aBuffer, size_t aBufferSize ) final;
97 DLL void Unload() final;
101 DLL const std::vector<AttributeTuple>& GetAttributes() const;
105 DLL uint32_t GetIndexSize() const;
109 DLL uint32_t GetIndexCount() const;
113 DLL uint32_t GetVertexCount() const;
117 DLL const std::vector<uint8_t>& GetVertexBuffer() const;
121 DLL const std::vector<uint8_t>& GetIndexBuffer() const;
125 DLL const AABB& GetAABB() const;
129 DLL size_t GetStride() const;
130 private:
131 AABB mAABB{};
132 std::vector<uint8_t> mVertexBuffer{};
133 std::vector<uint8_t> mIndexBuffer{};
134 std::vector<AttributeTuple> mAttributes{};
135 uint32_t mVertexCount{};
136 uint32_t mIndexSize{};
137 uint32_t mIndexCount{};
138 };
139
143 DLL size_t GetAttributeTotalSize ( const Mesh::AttributeTuple& aAttributeTuple );
144}
145#endif
Header for the axis aligned bounding box class.
Axis Aligned Bounding Box class.
Definition AABB.hpp:34
DLL void LoadFromMemory(const void *aBuffer, size_t aBufferSize) final
Load mesh data from a raw memory buffer.
Definition Mesh.cpp:108
DLL void Unload() final
Unload mesh data and release resources.
Definition Mesh.cpp:151
DLL size_t GetStride() const
Get the stride (bytes per vertex) for the vertex buffer.
Definition Mesh.cpp:98
AttributeSemantic
Semantic meaning of a vertex attribute, identified by CRC32 of its name.
Definition Mesh.hpp:35
@ WEIGHT_INDEX
Bone weight indices.
Definition Mesh.hpp:41
@ TANGENT
Vertex tangent.
Definition Mesh.hpp:38
@ TEXCOORD
Texture coordinate.
Definition Mesh.hpp:40
@ NORMAL
Vertex normal.
Definition Mesh.hpp:37
@ COLOR
Vertex color.
Definition Mesh.hpp:43
@ BITANGENT
Vertex bitangent.
Definition Mesh.hpp:39
@ POSITION
Vertex position.
Definition Mesh.hpp:36
@ WEIGHT_VALUE
Bone weight values.
Definition Mesh.hpp:42
BindingLocations
CRC32-based binding location identifiers for descriptor sets.
Definition Mesh.hpp:70
@ MATRICES
Matrices binding.
Definition Mesh.hpp:71
@ SKELETON
Skeleton binding.
Definition Mesh.hpp:73
@ SAMPLERS
Samplers binding.
Definition Mesh.hpp:74
@ MATERIAL
Material binding.
Definition Mesh.hpp:72
DLL uint32_t GetIndexSize() const
Get the size in bytes of a single index.
Definition Mesh.cpp:43
DLL ~Mesh() final
Destructor.
Definition Mesh.cpp:33
DLL void LoadFromPBMsg(const MeshMsg &aMeshMsg)
Load mesh data from a protobuf message.
Definition Mesh.cpp:113
AttributeType
Data type of a vertex attribute component.
Definition Mesh.hpp:48
@ UNSIGNED_SHORT
Unsigned 16-bit integer.
Definition Mesh.hpp:52
@ HALF_FLOAT
16-bit floating point.
Definition Mesh.hpp:53
@ BYTE
Signed 8-bit integer.
Definition Mesh.hpp:49
@ DOUBLE
64-bit floating point.
Definition Mesh.hpp:58
@ SHORT
Signed 16-bit integer.
Definition Mesh.hpp:51
@ UNSIGNED_BYTE
Unsigned 8-bit integer.
Definition Mesh.hpp:50
@ FLOAT
32-bit floating point.
Definition Mesh.hpp:56
@ FIXED
Fixed-point.
Definition Mesh.hpp:57
@ INT
Signed 32-bit integer.
Definition Mesh.hpp:54
@ UNSIGNED_INT
Unsigned 32-bit integer.
Definition Mesh.hpp:55
uint8_t AttributeSize
Type alias for the number of components in a vertex attribute.
Definition Mesh.hpp:78
std::tuple< AttributeSemantic, AttributeSize, AttributeType, AttributeFlags > AttributeTuple
Tuple describing a single vertex attribute (semantic, component count, type, flags).
Definition Mesh.hpp:82
AttributeFlag
Flags that modify how a vertex attribute is interpreted.
Definition Mesh.hpp:63
@ INTEGER
Values are passed as integers (no conversion).
Definition Mesh.hpp:65
@ NORMALIZED
Values are normalized to [0,1] or [-1,1].
Definition Mesh.hpp:64
DLL const AABB & GetAABB() const
Get the axis-aligned bounding box of the mesh.
Definition Mesh.cpp:68
DLL uint32_t GetIndexCount() const
Get the total number of indices.
Definition Mesh.cpp:48
uint8_t AttributeFlags
Type alias for vertex attribute flag bits.
Definition Mesh.hpp:80
DLL const std::vector< uint8_t > & GetIndexBuffer() const
Get the raw index data buffer.
Definition Mesh.cpp:63
DLL const std::vector< uint8_t > & GetVertexBuffer() const
Get the raw vertex data buffer.
Definition Mesh.cpp:58
DLL const std::vector< AttributeTuple > & GetAttributes() const
Get the list of vertex attributes.
Definition Mesh.cpp:38
DLL uint32_t GetVertexCount() const
Get the total number of vertices.
Definition Mesh.cpp:53
DLL Mesh()
Default constructor.
Base class for loadable engine resources.
Definition Resource.hpp:33
<- This is here just for the literals
Definition AABB.hpp:31
DLL size_t GetAttributeTotalSize(const Mesh::AttributeTuple &aAttributeTuple)
Compute the total byte size of a single vertex attribute.
Definition Mesh.cpp:73
STL namespace.