Brenta Engine 1.2
Loading...
Searching...
No Matches
model.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/renderer/mesh.hpp>
9#include <brenta/renderer/material.hpp>
10#include <brenta/transform.hpp>
11
12#include <glad/glad.h>
13
14#include <tenno/vector.hpp>
15#include <tenno/memory.hpp>
16
17#include <string>
18#include <filesystem>
19
20#include <tiny_obj_loader.h>
21
22namespace brenta
23{
24
25class Model
26{
27public:
28
29 Transform transform;
30 tenno::shared_ptr<Material> material;
31
32 struct Config;
33 class Builder;
34
35 Model() = default;
36 Model(Config &conf);
37 Model(Builder &builder);
38 ~Model();
39
40 Model(const Model&) = delete;
41 Model& operator=(const Model&) = delete;
42
43 Model(Model&&) noexcept = default;
44 Model& operator=(Model&&) noexcept = default;
45
46 void draw() const;
47
48private:
49
50 std::filesystem::path path;
51 std::string directory;
52
53 tenno::vector<Mesh> meshes;
54 tenno::vector<tenno::shared_ptr<Texture>> textures_loaded;
55
56 void load(const Texture::Properties &props);
57
58 void process_shape(const tinyobj::attrib_t& attrib,
59 const tinyobj::shape_t& shape,
60 const tenno::vector<tinyobj::material_t>& materials,
61 const Texture::Properties &props);
62 tenno::vector<tenno::shared_ptr<Texture>>
63 load_tiny_material(const tinyobj::material_t& mat,
64 const Texture::Properties &props);
65
66};
67
69{
70 Transform transform = {};
71 tenno::shared_ptr<Material> material = {};
72 std::filesystem::path model_path = "";
73 Texture::Properties texture_props = {};
74 tenno::vector<Mesh::Builder> meshes = {};
75};
76
78{
79public:
80
81 Builder &transform(const Transform& transform);
82 Builder &material(tenno::shared_ptr<Material> material);
83 Builder &material(Material&& material);
84 Builder &path(const std::filesystem::path &path);
85 Builder &texture_props(const Texture::Properties &props);
86 Builder &mesh(const Mesh::Builder &mesh);
87 Builder &mesh(Mesh::Builder &&mesh);
88 Builder &meshes(const tenno::vector<Mesh::Builder> &meshes);
89 Builder &meshes(tenno::vector<Mesh::Builder> &&meshes);
90
91 // Add path to be watched for hot-reloading
92 Builder &watch(const std::filesystem::path &path);
93
94 Model build();
95 tenno::vector<std::filesystem::path> get_watch_paths() const;
96
97private:
98
99 Model::Config conf = {};
100 tenno::vector<std::filesystem::path> watch_paths = {};
101
102};
103
104} // namespace brenta