Add basic node for model
This commit is contained in:
parent
9d0c832f3c
commit
302c1a8af2
@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <tiny_gltf/tiny_gltf.h>
|
||||
#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<string, s32> attributes = {{"POSITION", 0}, {"NORMAL", 1}, {"TEXCOORD_0", 2}};
|
||||
Texture texture;
|
||||
Node* root_node = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
14
src/node.cpp
Normal file
14
src/node.cpp
Normal file
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
16
src/node.h
Normal file
16
src/node.h
Normal file
@ -0,0 +1,16 @@
|
||||
#include "basic.h"
|
||||
#include <vector>
|
||||
|
||||
struct Node {
|
||||
std::vector<Node*> 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);
|
||||
Loading…
x
Reference in New Issue
Block a user