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 "Engine/Core/Asset.h"
5
6#include <cstdint>
7#include <glm/mat4x4.hpp>
8#include <glm/gtc/quaternion.hpp>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace Engine::Assets
14{
18 struct Joint {
19 int32_t parentIndex = -1;
20 glm::mat4 inverseBindMatrix = glm::mat4(1.0f);
21 std::string name;
22 glm::vec3 restTranslation = glm::vec3(0.0f);
23 glm::quat restRotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
24 glm::vec3 restScale = glm::vec3(1.0f);
25 };
26
30 class Skin : public Asset::AssetBase {
31 public:
33
37 [[nodiscard]] uint32_t getBoneCount() const { return static_cast<uint32_t>(joints_.size()); }
38
42 [[nodiscard]] const Joint& getJoint(uint32_t index) const { return joints_[index]; }
43
47 [[nodiscard]] const std::vector<Joint>& getJoints() const { return joints_; }
48
52 [[nodiscard]] int32_t getSkeletonRootIndex() const { return skeletonRootIndex_; }
53
58 [[nodiscard]] int32_t findJointByName(const std::string& name) const {
59 auto it = jointNameMap_.find(name);
60 return it != jointNameMap_.end() ? it->second : -1;
61 }
62
67 jointNameMap_.clear();
68 jointNameMap_.reserve(joints_.size());
69 for (uint32_t i = 0; i < joints_.size(); ++i) {
70 jointNameMap_[joints_[i].name] = static_cast<int32_t>(i);
71 }
72 }
73
74 // TODO: These variables should be private as indicated by the underscore in the naming. No need for them to be publicly visible
75 std::vector<Joint> joints_;
76 int32_t skeletonRootIndex_ = -1;
77 glm::mat4 armatureTransform_ = glm::mat4(1.0f);
78
79 private:
80 std::unordered_map<std::string, int32_t> jointNameMap_;
81 };
82
83 class SkinAssetManager : public Asset::AssetManager<Asset::MeshPath, Skin>
84 {
85 public:
86 SkinAssetManager() = default;
87 };
88}
Base class for asset wrappers. The data is stored in the private member variable 'data' in form of en...
Definition Asset.h:282
A manager which is used to look up existing assets and their loading state.
Definition Asset.h:332
std::unordered_map< std::string, int32_t > jointNameMap_
Definition SkinAsset.h:80
void buildNameIndex()
Rebuilds the name-to-index lookup table.
Definition SkinAsset.h:66
const Joint & getJoint(uint32_t index) const
Getter.
Definition SkinAsset.h:42
glm::mat4 armatureTransform_
Definition SkinAsset.h:77
int32_t getSkeletonRootIndex() const
Getter.
Definition SkinAsset.h:52
int32_t findJointByName(const std::string &name) const
Finds joint index by name.
Definition SkinAsset.h:58
int32_t skeletonRootIndex_
Definition SkinAsset.h:76
std::vector< Joint > joints_
Definition SkinAsset.h:75
const std::vector< Joint > & getJoints() const
Getter.
Definition SkinAsset.h:47
uint32_t getBoneCount() const
Getter.
Definition SkinAsset.h:37
A single joint in a skeleton hierarchy.
Definition SkinAsset.h:18
glm::quat restRotation
Definition SkinAsset.h:23
glm::mat4 inverseBindMatrix
Definition SkinAsset.h:20
glm::vec3 restTranslation
Definition SkinAsset.h:22