diff --git a/src/basic.h b/src/basic.h index ebbb9ff..9584820 100644 --- a/src/basic.h +++ b/src/basic.h @@ -1,7 +1,10 @@ #pragma once +#define GLM_ENABLE_EXPERIMENTAL + #include #include +#include typedef unsigned char u8; typedef unsigned short u16; @@ -25,4 +28,5 @@ typedef std::string string; using Vector2 = glm::vec2; using Vector3 = glm::vec3; using Matrix4 = glm::mat4; +using Quaternion = glm::quat; diff --git a/src/model.cpp b/src/model.cpp index 3e244ab..c8a16e8 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -38,6 +38,11 @@ bool load_model(Model *model, Render_Data *render_data, string model_filepath, s glBindVertexArray(0); + + s32 root_node_id = model->gltf_model->scenes.at(0).nodes.at(0); + create_root(model->root_node, root_node_id); + + render_data->triangle_count = get_model_triangle_count(model); return true; diff --git a/src/model.h b/src/model.h index a3cf0bb..f15a1e3 100644 --- a/src/model.h +++ b/src/model.h @@ -7,6 +7,7 @@ #include #include "texture.h" #include "render_data.h" +#include "node.h" struct Model { tinygltf::Model* gltf_model = nullptr; @@ -15,6 +16,7 @@ struct Model { u32 index_vbo = 0; std::map attributes = {{"POSITION", 0}, {"NORMAL", 1}, {"TEXCOORD_0", 2}}; Texture texture; + Node* root_node = nullptr; }; diff --git a/src/node.cpp b/src/node.cpp new file mode 100644 index 0000000..7cbba5e --- /dev/null +++ b/src/node.cpp @@ -0,0 +1,14 @@ +#include "node.h" + +void calculate_local_trs_matrix(Node *node) { + Matrix4 scale_matrix = glm::scale(Matrix4(1.0f), node->scale); + Matrix4 rotation_matrix = glm::mat4_cast(node->rotation); + Matrix4 translation_matrix = glm::translate(Matrix4(1.0f), node->translation); + + node->local_trs_matrix = translation_matrix * rotation_matrix * scale_matrix; +} + +void create_root_node(Node *node, s32 root_node_id) { + +} + diff --git a/src/node.h b/src/node.h new file mode 100644 index 0000000..468c6b1 --- /dev/null +++ b/src/node.h @@ -0,0 +1,16 @@ +#include "basic.h" +#include + +struct Node { + std::vector children; + Vector3 scale = Vector3(1.0f); + Vector3 translation = Vector3(0.0f); + Quaternion rotation = Quaternion(1.0f, 0.0f, 0.0f, 0.0f); + + Matrix4 local_trs_matrix = Matrix4(1.0f); + Matrix4 node_matrix = Matrix4(1.0f); + Matrix4 inverse_bind_matrix = Matrix4(1.0f); +}; + +void calculate_local_trs_matrix(Node *node); +void create_root_node(Node *node, s32 root_node_id);