]> git.localhorst.tv Git - blank.git/blob - src/model/Part.hpp
save a little bandwidth
[blank.git] / src / model / Part.hpp
1 #ifndef BLAMK_MODEL_PART_HPP_
2 #define BLAMK_MODEL_PART_HPP_
3
4 #include <cstdint>
5 #include <list>
6 #include <memory>
7 #include <vector>
8 #include <glm/glm.hpp>
9 #include <glm/gtc/quaternion.hpp>
10
11
12 namespace blank {
13
14 class DirectionalLighting;
15 class EntityMesh;
16 class Instance;
17 class Model;
18 class ResourceIndex;
19 class Shape;
20 class ShapeRegistry;
21 class TokenStreamReader;
22
23 struct Part {
24
25 public:
26         struct State {
27                 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
28                 glm::quat orientation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
29         };
30
31         Part();
32         ~Part();
33
34         void Read(TokenStreamReader &, ResourceIndex &, const ShapeRegistry &);
35
36         Part &AddChild();
37         const std::list<Part> &Children() const noexcept { return children; }
38
39         std::uint16_t Enumerate(std::uint16_t) noexcept;
40         void Index(std::vector<Part *> &) noexcept;
41
42         std::uint16_t ID() const noexcept { return id; }
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::tvec3<unsigned char> hsl_mod;
60         glm::tvec3<unsigned char> rgb_mod;
61         std::uint16_t id;
62
63 };
64
65 }
66
67 #endif