]> git.localhorst.tv Git - blank.git/blobdiff - src/model/model.cpp
save a little bandwidth
[blank.git] / src / model / model.cpp
index 63187b863033569af1da8f1e446ac3ec54607d69..ed443138e23e0d5746a551c25fd7e1f6956cf198 100644 (file)
@@ -5,10 +5,10 @@
 
 #include "Shape.hpp"
 #include "ShapeRegistry.hpp"
-#include "../app/TextureIndex.hpp"
 #include "../io/TokenStreamReader.hpp"
 #include "../graphics/DirectionalLighting.hpp"
 #include "../graphics/EntityMesh.hpp"
+#include "../shared/ResourceIndex.hpp"
 
 #include <iostream>
 #include <glm/gtx/quaternion.hpp>
@@ -27,6 +27,22 @@ Instance::~Instance() {
 
 }
 
+Part::State &Instance::BodyState() noexcept {
+       return state[model->GetBodyPart().ID()];
+}
+
+glm::mat4 Instance::BodyTransform() const noexcept {
+       return model->GetBodyPart().GlobalTransform(*this);
+}
+
+Part::State &Instance::EyesState() noexcept {
+       return state[model->GetEyesPart().ID()];
+}
+
+glm::mat4 Instance::EyesTransform() const noexcept {
+       return model->GetEyesPart().GlobalTransform(*this);
+}
+
 void Instance::Render(const glm::mat4 &M, DirectionalLighting &prog) {
        model->RootPart().Render(M, *this, prog);
 }
@@ -35,7 +51,9 @@ void Instance::Render(const glm::mat4 &M, DirectionalLighting &prog) {
 Model::Model()
 : id(0)
 , root()
-, part() {
+, part()
+, body_id(0)
+, eyes_id(0) {
 
 }
 
@@ -91,8 +109,8 @@ Part::Part()
 , tex_map()
 , mesh()
 , initial()
-, hsl_mod(0.0f, 1.0f, 1.0f)
-, rgb_mod(1.0f, 1.0f, 1.0f)
+, hsl_mod(0, 255, 255)
+, rgb_mod(255, 255, 255)
 , id(0) {
 
 }
@@ -101,10 +119,11 @@ Part::~Part() {
 
 }
 
-void Part::Read(TokenStreamReader &in, TextureIndex &tex_index, const ShapeRegistry &shapes) {
+void Part::Read(TokenStreamReader &in, ResourceIndex &tex_index, const ShapeRegistry &shapes) {
        std::string name;
        std::string shape_name;
        std::string tex_name;
+       glm::vec3 color_conv;
        in.Skip(Token::ANGLE_BRACKET_OPEN);
        while (in.HasMore() && in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
                in.ReadIdentifier(name);
@@ -117,9 +136,11 @@ void Part::Read(TokenStreamReader &in, TextureIndex &tex_index, const ShapeRegis
                } else if (name == "orientation") {
                        in.ReadQuat(initial.orientation);
                } else if (name == "hsl_mod") {
-                       in.ReadVec(hsl_mod);
+                       in.ReadVec(color_conv);
+                       hsl_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "rgb_mod") {
-                       in.ReadVec(rgb_mod);
+                       in.ReadVec(color_conv);
+                       rgb_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "textures") {
                        in.Skip(Token::BRACKET_OPEN);
                        while (in.HasMore() && in.Peek().type != Token::BRACKET_CLOSE) {