Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graphite/engine/assets/include/skeleton.hpp

68 lines
1.3 KiB
C++
Raw Normal View History

2024-01-03 16:05:02 -05:00
#pragma once
#include <vector>
#include <map>
#include <array>
#include <asset.hpp>
#include <glm/glm.hpp>
constexpr int MAX_BONES_PER_VERTEX = 4;
struct VertexBoneData
{
std::array<uint32_t, MAX_BONES_PER_VERTEX> ids;
std::array<float, MAX_BONES_PER_VERTEX> weights;
// Ad bone weighting to vertex info
void add(uint32_t boneID, float weight)
{
for(uint32_t i = 0; i < MAX_BONES_PER_VERTEX; i++)
{
if(weights[i] == 0.0f)
{
ids[i] = boneID;
weights[i] = weight;
return;
}
}
}
};
struct BoneInfo
{
glm::mat4 offset, final;
};
struct aiNode;
struct aiScene;
class Skeleton : public Asset
{
public:
Skeleton(int i)
{
index = i;
}
void Load(Renderer* renderer) override;
void Unload(Renderer* renderer) override;
std::type_index GetType() override
{
return typeid(Skeleton);
}
void UpdateSkeletalNodes(aiNode* pNode, const glm::mat4& parentTransformation);
std::vector<VertexBoneData> vertex_bones;
std::map<std::string, uint32_t> mapping;
std::vector<BoneInfo> bone_info;
glm::mat4 globalInverse;
aiScene* animScene;
float animTime = 0.0f;
int index;
};