Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
SkinAsset.h
1#pragma once
2
3#include "Engine/Core/Asset.h"
4#include "Engine/Files/AssetPath.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:
36
40 [[nodiscard]] uint32_t getBoneCount() const { return static_cast<uint32_t>(joints_.size()); }
41
45 [[nodiscard]] const Joint& getJoint(uint32_t index) const { return joints_[index]; }
46
50 [[nodiscard]] const std::vector<Joint>& getJoints() const { return joints_; }
51
55 [[nodiscard]] int32_t getSkeletonRootIndex() const { return skeletonRootIndex_; }
56
61 [[nodiscard]] int32_t findJointByName(const std::string& name) const {
62 auto it = jointNameMap_.find(name);
63 return it != jointNameMap_.end() ? it->second : -1;
64 }
65
70 jointNameMap_.clear();
71 jointNameMap_.reserve(joints_.size());
72 for (uint32_t i = 0; i < joints_.size(); ++i) {
73 jointNameMap_[joints_[i].name] = static_cast<int32_t>(i);
74 }
75 }
76
77 // TODO: These variables should be private as indicated by the underscore in the naming. No need for them to be publicly visible
78 std::vector<Joint> joints_;
79 int32_t skeletonRootIndex_ = -1;
80 glm::mat4 armatureTransform_ = glm::mat4(1.0f);
81
82 private:
83 std::unordered_map<std::string, int32_t> jointNameMap_;
84 };
85
92 class SkinAssetManager : public Asset::AssetManager<Asset::MeshPath, Skin>
93 {
94 public:
98 SkinAssetManager() = default;
99 };
100}
Base class for asset wrappers. The data is stored in the private member variable 'data' in form of en...
Definition Asset.h:297
A manager which is used to look up existing assets and their loading state.
Definition Asset.h:358
SkinAssetManager()=default
Creates an empty skin asset manager.
std::unordered_map< std::string, int32_t > jointNameMap_
Definition SkinAsset.h:83
void buildNameIndex()
Rebuilds the name-to-index lookup table.
Definition SkinAsset.h:69
const Joint & getJoint(uint32_t index) const
Getter.
Definition SkinAsset.h:45
glm::mat4 armatureTransform_
Transform applied by the source armature node.
Definition SkinAsset.h:80
int32_t getSkeletonRootIndex() const
Getter.
Definition SkinAsset.h:55
int32_t findJointByName(const std::string &name) const
Finds joint index by name.
Definition SkinAsset.h:61
int32_t skeletonRootIndex_
Root joint index, or -1 when no root is assigned.
Definition SkinAsset.h:79
std::vector< Joint > joints_
Joint hierarchy and bind-pose data.
Definition SkinAsset.h:78
Skin()
Creates a loaded skin with no joints.
const std::vector< Joint > & getJoints() const
Getter.
Definition SkinAsset.h:50
uint32_t getBoneCount() const
Getter.
Definition SkinAsset.h:40
A single joint in a skeleton hierarchy.
Definition SkinAsset.h:18
glm::vec3 restScale
Rest-pose local scale.
Definition SkinAsset.h:24
int32_t parentIndex
Parent joint index, or -1 for a root joint.
Definition SkinAsset.h:19
glm::quat restRotation
Rest-pose local rotation.
Definition SkinAsset.h:23
glm::mat4 inverseBindMatrix
Inverse bind matrix from the source skin.
Definition SkinAsset.h:20
glm::vec3 restTranslation
Rest-pose local translation.
Definition SkinAsset.h:22
std::string name
Joint name from the source asset.
Definition SkinAsset.h:21