NoJobEngine 2.0.7
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1
6#pragma once
7#include <cstdint>
8#include <memory>
9#include <vector>
10#include <filesystem>
11#include <glm/glm.hpp>
12
13namespace NoJob
14{
15 class VertexArray;
16 class VertexBuffer;
17 class IndexBuffer;
18
20 {
21 glm::vec3 Position{ 0.0f };
22 glm::vec3 Normal{ 0.0f, 1.0f, 0.0f };
23 glm::vec2 TexCoord{ 0.0f };
24 // Up to four skeletal influences. IDs are stored as floats to keep the
25 // current renderer vertex-layout API simple; shaders cast them to ints.
26 glm::vec4 BoneIDs{ 0.0f };
27 glm::vec4 BoneWeights{ 0.0f };
28 };
29
30 struct Submesh
31 {
32 std::uint32_t IndexOffset = 0;
33 std::uint32_t IndexCount = 0;
34 std::uint32_t MaterialIndex = 0;
35 };
36
37 class Mesh
38 {
39 public:
40 Mesh(const std::vector<MeshVertex>& vertices,
41 const std::vector<std::uint32_t>& indices);
42
43 const std::shared_ptr<VertexArray>& GetVertexArray() const
44 {
45 return m_VertexArray;
46 }
47
48 static std::shared_ptr<Mesh> CreateCube();
49 static std::shared_ptr<Mesh> LoadOBJ(const std::filesystem::path& path);
50 static std::shared_ptr<Mesh> LoadModel(const std::filesystem::path& path);
51
52 const std::vector<Submesh>& GetSubmeshes() const { return m_Submeshes; }
53 void SetSubmeshes(std::vector<Submesh> submeshes) { m_Submeshes = std::move(submeshes); }
54 bool HasSkinning() const { return m_HasSkinning; }
55 void SetHasSkinning(bool value) { m_HasSkinning = value; }
56
57 private:
58 std::shared_ptr<VertexArray> m_VertexArray;
59 std::shared_ptr<VertexBuffer> m_VertexBuffer;
60 std::shared_ptr<IndexBuffer> m_IndexBuffer;
61 std::vector<Submesh> m_Submeshes;
62 bool m_HasSkinning = false;
63 };
64}
static std::shared_ptr< Mesh > CreateCube()
Definition Mesh.cpp:167
const std::shared_ptr< VertexArray > & GetVertexArray() const
Definition Mesh.h:43
static std::shared_ptr< Mesh > LoadOBJ(const std::filesystem::path &path)
Definition Mesh.cpp:57
Mesh(const std::vector< MeshVertex > &vertices, const std::vector< std::uint32_t > &indices)
Definition Mesh.cpp:17
void SetHasSkinning(bool value)
Definition Mesh.h:55
static std::shared_ptr< Mesh > LoadModel(const std::filesystem::path &path)
Definition Mesh.cpp:73
void SetSubmeshes(std::vector< Submesh > submeshes)
Definition Mesh.h:53
bool HasSkinning() const
Definition Mesh.h:54
const std::vector< Submesh > & GetSubmeshes() const
Definition Mesh.h:52
glm::vec3 Normal
Definition Mesh.h:22
glm::vec2 TexCoord
Definition Mesh.h:23
glm::vec4 BoneIDs
Definition Mesh.h:26
glm::vec3 Position
Definition Mesh.h:21
glm::vec4 BoneWeights
Definition Mesh.h:27
std::uint32_t IndexCount
Definition Mesh.h:33
std::uint32_t MaterialIndex
Definition Mesh.h:34
std::uint32_t IndexOffset
Definition Mesh.h:32