Clean up the code to be not everything in hpp files.
This commit is contained in:
parent
a1c8208b47
commit
6d21b7f163
6 changed files with 308 additions and 264 deletions
|
|
@ -7,8 +7,6 @@
|
|||
#include <functional>
|
||||
#include "animdata.hpp"
|
||||
#include "bone.hpp"
|
||||
#include "model.hpp"
|
||||
#include "assimp_glm_helpers.hpp"
|
||||
|
||||
struct Bone;
|
||||
|
||||
|
|
@ -28,88 +26,21 @@ struct Animation {
|
|||
|
||||
Animation() = default;
|
||||
|
||||
Animation(const std::string& animationPath, Model *model) {
|
||||
Assimp::Importer importer;
|
||||
Animation(const std::string& animationPath, Model *model);
|
||||
|
||||
const aiScene* scene = importer.ReadFile(animationPath, aiProcess_Triangulate);
|
||||
dbc::check(scene != nullptr, $F("Scene for animation {} failed to load.", animationPath));
|
||||
dbc::check(scene->mRootNode, $F("Scene {} doesn't have a root node.", animationPath));
|
||||
~Animation() {}
|
||||
|
||||
auto animation = scene->mAnimations[0];
|
||||
$duration = animation->mDuration;
|
||||
$ticks_per_sec = animation->mTicksPerSecond;
|
||||
aiMatrix4x4 globalTransformation = scene->mRootNode->mTransformation;
|
||||
globalTransformation = globalTransformation.Inverse();
|
||||
ReadHierarchyData($root_node, scene->mRootNode);
|
||||
ReadMissingBones(animation, *model);
|
||||
}
|
||||
Bone* FindBone(const std::string& name);
|
||||
|
||||
~Animation() {
|
||||
}
|
||||
float GetTicksPerSecond();
|
||||
|
||||
float GetDuration();
|
||||
|
||||
Bone* FindBone(const std::string& name) {
|
||||
auto iter = std::find_if($bones.begin(), $bones.end(),
|
||||
[&](const auto& bone) {
|
||||
return bone.GetBoneName() == name;
|
||||
}
|
||||
);
|
||||
const AssimpNodeData& GetRootNode();
|
||||
|
||||
return iter == $bones.end() ? nullptr : &(*iter);
|
||||
}
|
||||
const std::unordered_map<std::string, BoneInfo>& GetBoneIDMap();
|
||||
|
||||
float GetTicksPerSecond() {
|
||||
return $ticks_per_sec;
|
||||
}
|
||||
void ReadMissingBones(const aiAnimation* animation, Model& model);
|
||||
|
||||
float GetDuration() {
|
||||
return $duration;
|
||||
}
|
||||
|
||||
const AssimpNodeData& GetRootNode() {
|
||||
return $root_node;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, BoneInfo>& GetBoneIDMap()
|
||||
{
|
||||
return $bone_info_map;
|
||||
}
|
||||
|
||||
void ReadMissingBones(const aiAnimation* animation, Model& model) {
|
||||
// this code is weird as hell
|
||||
int size = animation->mNumChannels;
|
||||
auto& boneInfoMap = model.bone_info_map;
|
||||
int& boneCount = model.bone_counter;
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
auto channel = animation->mChannels[i];
|
||||
std::string boneName = channel->mNodeName.data;
|
||||
|
||||
if(!boneInfoMap.contains(boneName)) {
|
||||
boneInfoMap[boneName].id = boneCount;
|
||||
boneCount++;
|
||||
}
|
||||
|
||||
dbc::check(boneCount < MAX_BONES, "Too many bones!");
|
||||
|
||||
$bones.emplace_back(boneName,
|
||||
boneInfoMap[boneName].id, channel);
|
||||
}
|
||||
|
||||
$bone_info_map = boneInfoMap;
|
||||
}
|
||||
|
||||
void ReadHierarchyData(AssimpNodeData& dest, const aiNode* src) {
|
||||
dbc::check(src != nullptr, "aiNode src is null?!");
|
||||
|
||||
dest.name = src->mName.data;
|
||||
dest.transformation = AssimpGLMHelpers::ConvertMatrixToGLMFormat(src->mTransformation);
|
||||
dest.children_count = src->mNumChildren;
|
||||
|
||||
for(size_t i = 0; i < src->mNumChildren; i++) {
|
||||
AssimpNodeData newData;
|
||||
ReadHierarchyData(newData, src->mChildren[i]);
|
||||
dest.children.push_back(newData);
|
||||
}
|
||||
}
|
||||
void ReadHierarchyData(AssimpNodeData& dest, const aiNode* src);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue