Added name to AnimationResource.

This commit is contained in:
Martin Felis 2025-04-11 13:05:50 +02:00
parent d32c247cc0
commit f6f7e92cea
4 changed files with 26 additions and 5 deletions

View File

@ -32,11 +32,29 @@ struct AnimDataRef {
Pose* ptr = nullptr; Pose* ptr = nullptr;
}; };
struct AnimationFileResource { struct AnimationResource {
std::string m_name;
ozz::animation::Animation* m_animation; ozz::animation::Animation* m_animation;
SyncTrack m_sync_track; SyncTrack m_sync_track;
}; };
inline void to_json(
nlohmann::json& j,
const AnimationResource& animation_resource) {
j["type"] = "AnimationResource";
j["synctrack"] = animation_resource.m_sync_track;
j["name"] = animation_resource.m_name;
}
inline void from_json(
const nlohmann::json& j,
AnimationResource& animation_resource) {
assert(j["type"] == "AnimationResource");
animation_resource.m_sync_track = j["synctrack"];
animation_resource.m_name = j["name"];
}
struct AnimDataAllocator { struct AnimDataAllocator {
struct PoseList { struct PoseList {
Pose* m_anim_data = nullptr; Pose* m_anim_data = nullptr;
@ -108,7 +126,7 @@ struct AnimGraphContext {
AnimGraph* m_graph = nullptr; AnimGraph* m_graph = nullptr;
ozz::animation::Skeleton* m_skeleton = nullptr; ozz::animation::Skeleton* m_skeleton = nullptr;
typedef std::map<std::string, AnimationFileResource> AnimationFileMap; typedef std::map<std::string, AnimationResource> AnimationFileMap;
AnimationFileMap m_animation_map; AnimationFileMap m_animation_map;
void freeAnimations() { void freeAnimations() {

View File

@ -151,7 +151,10 @@ bool AnimSamplerNode::Init(AnimGraphContext& context) {
archive >> *m_animation; archive >> *m_animation;
context.m_animation_map[m_filename] = {m_animation, SyncTrack()}; context.m_animation_map[m_filename] = {
m_filename,
m_animation,
SyncTrack()};
} }
assert(context.m_skeleton != nullptr); assert(context.m_skeleton != nullptr);

View File

@ -109,5 +109,3 @@ void SkinnedMeshResource::createInstance(SkinnedMesh& skinnedMesh) const {
skinnedMesh.m_animation_sync_track.back() = m_sync_tracks[i]; skinnedMesh.m_animation_sync_track.back() = m_sync_tracks[i];
} }
} }

View File

@ -199,9 +199,11 @@ TEST_CASE_METHOD(
AnimGraphContext graph_context; AnimGraphContext graph_context;
graph_context.m_skeleton = skeleton.get(); graph_context.m_skeleton = skeleton.get();
graph_context.m_animation_map["trans_x"] = { graph_context.m_animation_map["trans_x"] = {
"trans_x",
animation_translate_x.get(), animation_translate_x.get(),
animation_translate_x_sync_track}; animation_translate_x_sync_track};
graph_context.m_animation_map["trans_y"] = { graph_context.m_animation_map["trans_y"] = {
"trans_y",
animation_translate_y.get(), animation_translate_y.get(),
animation_translate_y_sync_track}; animation_translate_y_sync_track};