Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
SkinAsset.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <glm/mat4x4.hpp>
5#include <glm/gtc/quaternion.hpp>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace Engine::Assets
11{
15 struct Joint {
16 int32_t parentIndex = -1;
17 glm::mat4 inverseBindMatrix = glm::mat4(1.0f);
18 std::string name;
19 glm::vec3 restTranslation = glm::vec3(0.0f);
20 glm::quat restRotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
21 glm::vec3 restScale = glm::vec3(1.0f);
22 };
23
27 class Skin {
28 public:
29 Skin() = default;
30
34 [[nodiscard]] uint32_t getBoneCount() const { return static_cast<uint32_t>(joints_.size()); }
35
39 [[nodiscard]] const Joint& getJoint(uint32_t index) const { return joints_[index]; }
40
44 [[nodiscard]] const std::vector<Joint>& getJoints() const { return joints_; }
45
49 [[nodiscard]] int32_t getSkeletonRootIndex() const { return skeletonRootIndex_; }
50
55 [[nodiscard]] int32_t findJointByName(const std::string& name) const {
56 auto it = jointNameMap_.find(name);
57 return it != jointNameMap_.end() ? it->second : -1;
58 }
59
64 jointNameMap_.clear();
65 jointNameMap_.reserve(joints_.size());
66 for (uint32_t i = 0; i < joints_.size(); ++i) {
67 jointNameMap_[joints_[i].name] = static_cast<int32_t>(i);
68 }
69 }
70
71 // TODO: These variables should be private as indicated by the underscore in the naming. No need for them to be publicly visible
72 std::vector<Joint> joints_;
73 int32_t skeletonRootIndex_ = -1;
74 glm::mat4 armatureTransform_ = glm::mat4(1.0f);
75
76 private:
77 std::unordered_map<std::string, int32_t> jointNameMap_;
78 };
79}
std::unordered_map< std::string, int32_t > jointNameMap_
Definition SkinAsset.h:77
void buildNameIndex()
Rebuilds the name-to-index lookup table.
Definition SkinAsset.h:63
const Joint & getJoint(uint32_t index) const
Getter.
Definition SkinAsset.h:39
glm::mat4 armatureTransform_
Definition SkinAsset.h:74
int32_t getSkeletonRootIndex() const
Getter.
Definition SkinAsset.h:49
int32_t findJointByName(const std::string &name) const
Finds joint index by name.
Definition SkinAsset.h:55
int32_t skeletonRootIndex_
Definition SkinAsset.h:73
std::vector< Joint > joints_
Definition SkinAsset.h:72
const std::vector< Joint > & getJoints() const
Getter.
Definition SkinAsset.h:44
uint32_t getBoneCount() const
Getter.
Definition SkinAsset.h:34
A single joint in a skeleton hierarchy.
Definition SkinAsset.h:15
glm::quat restRotation
Definition SkinAsset.h:20
glm::mat4 inverseBindMatrix
Definition SkinAsset.h:17
glm::vec3 restTranslation
Definition SkinAsset.h:19