38 Assimp::Importer importer;
39 const aiScene* scene = importer.ReadFile(animationPath, aiProcess_Triangulate);
40 assert(scene && scene->mRootNode);
41 auto animation = scene->mAnimations[0];
42 m_Duration = animation->mDuration;
43 m_TicksPerSecond = animation->mTicksPerSecond;
44 aiMatrix4x4 globalTransformation = scene->mRootNode->mTransformation;
45 globalTransformation = globalTransformation.Inverse();
46 ReadHierarchyData(m_RootNode, scene->mRootNode);
47 ReadMissingBones(animation, *model);
59 auto iter = std::find_if(m_Bones.begin(), m_Bones.end(),
62 return Bone.GetBoneName() == name;
65 if (iter == m_Bones.end())
return nullptr;
89 void ReadMissingBones(
const aiAnimation* animation,
Model& model)
91 int size = animation->mNumChannels;
97 for (
int i = 0; i < size; i++)
99 auto channel = animation->mChannels[i];
100 std::string boneName = channel->mNodeName.data;
102 if (boneInfoMap.find(boneName) == boneInfoMap.end())
104 boneInfoMap[boneName].id = boneCount;
107 m_Bones.push_back(
Bone(channel->mNodeName.data,
108 boneInfoMap[channel->mNodeName.data].id, channel));
111 m_BoneInfoMap = boneInfoMap;
121 dest.name = src->mName.data;
123 dest.childrenCount = src->mNumChildren;
125 for (
int i = 0; i < src->mNumChildren; i++)
128 ReadHierarchyData(newData, src->mChildren[i]);
129 dest.children.push_back(newData);
133 int m_TicksPerSecond;
134 std::vector<Bone> m_Bones;
136 std::map<std::string, BoneInfo> m_BoneInfoMap;