From d4817a95d797493eac8796f9cccd07e8e5f8b968 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Aug 2021 10:22:26 +0200 Subject: [PATCH] Add `MapTrack` to SceneAnimationPlayer --- .../SceneAnimations/SceneAnimationPlayer.cpp | 35 +++++++++++++++++++ .../SceneAnimations/SceneAnimationPlayer.h | 7 ++++ 2 files changed, 42 insertions(+) diff --git a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp index 7e92f9313..98498aab1 100644 --- a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp +++ b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp @@ -220,6 +220,41 @@ void SceneAnimationPlayer::MapObject(const Guid& from, const Guid& to) _objectsMapping[from] = to; } +void SceneAnimationPlayer::MapTrack(const StringView& from, const Guid& to) +{ + SceneAnimation* anim = Animation.Get(); + if (!anim || !anim->IsLoaded()) + return; + for (int32 j = 0; j < anim->Tracks.Count(); j++) + { + const auto& track = anim->Tracks[j]; + if (track.Name != from) + continue; + switch (track.Type) + { + case SceneAnimation::Track::Types::Actor: + { + const auto trackData = track.GetData(); + _objectsMapping[trackData->ID] = to; + break; + } + case SceneAnimation::Track::Types::Script: + { + const auto trackData = track.GetData(); + _objectsMapping[trackData->ID] = to; + break; + } + case SceneAnimation::Track::Types::CameraCut: + { + const auto trackData = track.GetData(); + _objectsMapping[trackData->ID] = to; + break; + } + default: ; + } + } +} + void SceneAnimationPlayer::Restore(SceneAnimation* anim, int32 stateIndexOffset) { // Restore all tracks diff --git a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.h b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.h index c63877c2d..76b94056d 100644 --- a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.h +++ b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.h @@ -198,6 +198,13 @@ public: /// The destination object to animate. API_FUNCTION() void MapObject(const Guid& from, const Guid& to); + /// + /// Adds an object mapping for the object track. The track name `from` will be redirected to the specified object `to`. Can be used to reuse the same animation for different objects. + /// + /// The source track name from the scene animation asset to replace. + /// The destination object to animate. + API_FUNCTION() void MapTrack(const StringView& from, const Guid& to); + private: void Restore(SceneAnimation* anim, int32 stateIndexOffset);