]> git.localhorst.tv Git - blank.git/blob - src/model/Part.hpp
load models from assets
[blank.git] / src / model / Part.hpp
1 #ifndef BLAMK_MODEL_PART_HPP_
2 #define BLAMK_MODEL_PART_HPP_
3
4 #include "geometry.hpp"
5
6 #include <cstdint>
7 #include <list>
8 #include <memory>
9 #include <vector>
10 #include <glm/glm.hpp>
11 #include <glm/gtc/quaternion.hpp>
12
13
14 namespace blank {
15
16 class DirectionalLighting;
17 class EntityMesh;
18 class Instance;
19 class Model;
20 class Shape;
21 class ShapeRegistry;
22 class TextureIndex;
23 class TokenStreamReader;
24
25 struct Part {
26
27 public:
28         struct State {
29                 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
30                 glm::quat orientation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
31         };
32
33         Part();
34         ~Part();
35
36         void Read(TokenStreamReader &, TextureIndex &, const ShapeRegistry &);
37
38         Part &AddChild();
39         const std::list<Part> &Children() const noexcept { return children; }
40
41         std::uint16_t Enumerate(std::uint16_t) noexcept;
42         void Index(std::vector<Part *> &) noexcept;
43
44         glm::mat4 LocalTransform(const Instance &) const noexcept;
45         glm::mat4 GlobalTransform(const Instance &) const noexcept;
46
47         void Render(
48                 const glm::mat4 &,
49                 const Instance &,
50                 DirectionalLighting &) const;
51
52 private:
53         const Part *parent;
54         const Shape *shape;
55         std::list<Part> children;
56         std::vector<float> tex_map;
57         mutable std::unique_ptr<EntityMesh> mesh;
58         State initial;
59         glm::vec3 hsl_mod;
60         glm::vec3 rgb_mod;
61         std::uint16_t id;
62
63 };
64
65 }
66
67 #endif