VulkanEngine 0.1
Graphics engine using Vulkan
Loading...
Searching...
No Matches
OBJMesh.h
1// Copyright (c) 2024 Michael Carlie. All Rights Reserved.
2//
3// This software is released under the MIT License.
4// https://opensource.org/licenses/MIT
5
6#ifndef INCLUDE_VULKANENGINE_OBJMESH_H_
7#define INCLUDE_VULKANENGINE_OBJMESH_H_
8
9#include <VulkanEngine/BoundingBox.h>
10#include <VulkanEngine/GraphicsPipeline.h>
11#include <VulkanEngine/MeshBase.h>
12#include <VulkanEngine/SceneObject.h>
13#include <VulkanEngine/UniformBuffer.h>
14
15#include <array>
16#include <filesystem> // NOLINT(build/c++17)
17#include <memory>
18#include <string>
19#include <unordered_map>
20#include <vector>
21
22#include "GraphicsPipeline.h"
23
24namespace VulkanEngine {
25
27class OBJMesh : public SceneObject {
28 public:
32 OBJMesh(std::filesystem::path obj_file, std::filesystem::path mtl_path = "",
33 const std::shared_ptr<Shader> _shader = std::shared_ptr<Shader>());
34
36 virtual ~OBJMesh();
37
40
41 private:
42#pragma pack(push, 1)
43 struct MvpUbo {
44 Eigen::Matrix4f model;
45 Eigen::Matrix4f view;
46 Eigen::Matrix4f projection;
47 };
48
49 struct Material {
50 std::array<float, 4> ambient = {0.8, 0.8, 0.8, 0.0};
51 std::array<float, 4> diffuse = {1.0, 1.0, 1.0, 0.0};
52 std::array<float, 4> specular = {1.0, 1.0, 1.0, 0.0};
53 };
54#pragma pack(pop)
55
58 void update(std::shared_ptr<SceneState> scene_state) override;
59
63 void loadOBJ(const char* obj_path, const char* mtl_path);
64
67 const std::string getVertexShaderString() const;
68
71 const std::string getFragmentShaderString(bool has_texture) const;
72
74 std::vector<std::shared_ptr<MeshBase>> meshes;
75
77 std::vector<std::shared_ptr<Shader>> shaders;
78
79 std::vector<std::shared_ptr<GraphicsPipeline>> graphics_pipelines;
80
82 std::vector<std::shared_ptr<UniformBuffer<MvpUbo>>> mvp_buffers;
83
84 std::vector<std::vector<std::shared_ptr<UniformBuffer<Material>>>>
85 material_buffers;
86
88 std::unordered_map<std::string, std::shared_ptr<Descriptor>> textures;
89
91 bool graphics_pipeline_updated;
92
95};
96
97} // namespace VulkanEngine
98
99#endif // INCLUDE_VULKANENGINE_OBJMESH_H_
A SceneObject which represents an OBJMesh.
Definition: OBJMesh.h:27
virtual ~OBJMesh()
Destructor.
Definition: OBJMesh.cpp:259
const BoundingBox< Eigen::Vector3f > & getBoundingBox() const
Definition: OBJMesh.cpp:261
Represents an object in a scene.
Definition: SceneObject.h:17
TODO development of this class is in progress.
Definition: Attribute.h:13
Definition: BoundingBox.h:15