Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Skeleton.h
Go to the documentation of this file.
1/**
2 * @file Skeleton.h
3 * @ingroup mnd_animation
4 * @brief Bone hierarchy + bind/offset matrices for GPU-skinned meshes.
5 */
6
7#pragma once
8
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13#include <glm/gtc/quaternion.hpp>
14#include <glm/mat4x4.hpp>
15#include <glm/vec3.hpp>
16
17#include "Types.h"
18
19namespace mnd
20{
21
22struct Bone
23{
24 std::string name;
25 i32 parentIndex = -1; ///< Index into Skeleton::bones, or -1 for the root.
26 glm::mat4 localBind = glm::mat4(1); ///< Local bind transform (relative to parent).
27 glm::mat4 offsetMatrix = glm::mat4(1); ///< Inverse bind matrix in mesh space (Assimp `aiBone::mOffsetMatrix`).
28
29 /// Bind decomposition (filled by `Skeleton::AddBone`). Used by `EvaluatePose`
30 /// as a fallback when an animation track omits a TRS channel — without this
31 /// a track that only animates rotation would zero out the bone's bind offset.
32 glm::vec3 bindPos = glm::vec3(0.0f);
33 glm::quat bindRot = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
34 glm::vec3 bindScale = glm::vec3(1.0f);
35};
36
38{
39public:
40 void AddBone(const Bone &bone);
41 i32 FindBoneIndex(const std::string &name) const;
42 usize Size() const { return m_bones.size(); }
43
44 const std::vector<Bone> &GetBones() const { return m_bones; }
45 std::vector<Bone> &GetBones() { return m_bones; }
46
47private:
48 std::vector<Bone> m_bones;
49 std::unordered_map<std::string, size_t> m_nameToIndex;
50};
51
52} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
i32 FindBoneIndex(const std::string &name) const
Definition Skeleton.cpp:21
const std::vector< Bone > & GetBones() const
Definition Skeleton.h:44
std::vector< Bone > & GetBones()
Definition Skeleton.h:45
void AddBone(const Bone &bone)
Definition Skeleton.cpp:9
usize Size() const
Definition Skeleton.h:42
int32_t i32
Signed 32-bit integer — used for GL enums and sizes.
Definition Types.h:37
size_t usize
Platform-native unsigned size type.
Definition Types.h:43
i32 parentIndex
Index into Skeleton::bones, or -1 for the root.
Definition Skeleton.h:25
glm::vec3 bindPos
Definition Skeleton.h:32
glm::quat bindRot
Definition Skeleton.h:33
std::string name
Definition Skeleton.h:24
glm::mat4 localBind
Local bind transform (relative to parent).
Definition Skeleton.h:26
glm::vec3 bindScale
Definition Skeleton.h:34
glm::mat4 offsetMatrix
Inverse bind matrix in mesh space (Assimp aiBone::mOffsetMatrix).
Definition Skeleton.h:27