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