Polyphase Game Engine
Loading...
Searching...
No Matches
SkeletalAnimationAsset.h
Go to the documentation of this file.
1#pragma once
2
3#include "Asset.h"
4#include "Factory.h"
6
7#include <string>
8#include <vector>
9
10class SkeletalMesh;
11
12// Bone-animation channel keyed by source bone NAME (not bone index).
13// The bound runtime resolves the name into a target-mesh bone index once
14// per (asset, target-mesh) pair and caches the result on SkeletalMesh3D —
15// see BoundSkeletalAnimation.
17{
18 std::string mBoneName;
19 int32_t mSourceBoneIndex = -1;
20 std::vector<PositionKey> mPositionKeys;
21 std::vector<RotationKey> mRotationKeys;
22 std::vector<ScaleKey> mScaleKeys;
23};
24
26{
27public:
28
30
33
34 virtual void LoadStream(Stream& stream, Platform platform) override;
35 virtual void SaveStream(Stream& stream, Platform platform) override;
36 virtual void Create() override;
37 virtual void Destroy() override;
38
39 virtual void GatherProperties(std::vector<Property>& outProps) override;
40 virtual glm::vec4 GetTypeColor() override;
41 virtual const char* GetTypeName() override;
42
43 const std::string& GetClipName() const { return mClipName; }
44 void SetClipName(const std::string& name) { mClipName = name; }
45
46 float GetDuration() const { return mDuration; }
47 float GetTicksPerSecond() const { return mTicksPerSecond; }
48 float GetDurationSeconds() const;
49 void SetDuration(float duration) { mDuration = duration; }
50 void SetTicksPerSecond(float tps) { mTicksPerSecond = tps; }
51
52 const std::vector<SkeletalAnimationChannel>& GetChannels() const { return mChannels; }
53 std::vector<SkeletalAnimationChannel>& GetChannelsMutable() { return mChannels; }
54
55 const std::vector<AnimEventTrack>& GetEventTracks() const { return mEventTracks; }
56 std::vector<AnimEventTrack>& GetEventTracksMutable() { return mEventTracks; }
57
58 const std::string& GetSourceRigName() const { return mSourceRigName; }
59 void SetSourceRigName(const std::string& name) { mSourceRigName = name; }
60
61 const std::vector<std::string>& GetSourceBoneNames() const { return mSourceBoneNames; }
62 std::vector<std::string>& GetSourceBoneNamesMutable() { return mSourceBoneNames; }
63
64 const std::vector<int32_t>& GetSourceParentIndices() const { return mSourceParentIndices; }
65 std::vector<int32_t>& GetSourceParentIndicesMutable() { return mSourceParentIndices; }
66
67 const std::vector<glm::mat4>& GetSourceBindPose() const { return mSourceBindPose; }
68 std::vector<glm::mat4>& GetSourceBindPoseMutable() { return mSourceBindPose; }
69
70 // Editor-time helper. Copies an embedded Animation off a SkeletalMesh into
71 // this asset, converting channel mBoneIndex into bone names + capturing
72 // the source skeleton metadata for later retargeting work.
73 void CopyFromEmbedded(const Animation& embedded, const SkeletalMesh* sourceMesh);
74
75#if EDITOR
76 // Static convenience: parse animations from an .fbx/.glb/.gltf/.dae file
77 // without requiring a render mesh, producing one SkeletalAnimationAsset
78 // descriptor per aiAnimation in the scene. The caller decides whether to
79 // register each result as an asset (see ActionManager::ImportAnimations).
80 // Returns the number of clips populated into outAssets (matches outNames).
81 static uint32_t ParseAnimationsFromFile(
82 const std::string& path,
83 std::vector<SkeletalAnimationAsset>& outAssets,
84 std::vector<std::string>& outNames);
85
86 enum class RetargetMode : uint8_t
87 {
88 // Tier 1: pass keyframes through verbatim, just rename the channel's
89 // bone from src avatar's slot name to the target avatar's. Works for
90 // same/similar skeletons that only differ in naming convention
91 // (Mixamo-to-Mixamo, ARP-to-ARP-but-renamed).
92 NameRemap,
93
94 // Tier 2: rotations are projected through (source bind, target bind)
95 // so the resulting clip reproduces the source motion on a differently-
96 // proportioned target rig. Requires both avatars to have a reference
97 // mesh with a real bind pose; falls back to NameRemap behaviour for
98 // slots where bind pose isn't available.
99 ReferencePose,
100 };
101
102 // Bake a target-compatible clip from a source clip and a humanoid avatar
103 // pair. The returned clip is fully populated but NOT registered with
104 // AssetManager — caller does that. Pass nullptr for the optional outErr
105 // string if you don't need diagnostics.
106 static SkeletalAnimationAsset Retarget(
107 const SkeletalAnimationAsset& srcClip,
108 const class HumanoidAvatarAsset& srcAvatar,
109 const class HumanoidAvatarAsset& dstAvatar,
110 RetargetMode mode,
111 std::string* outDiagnostics = nullptr);
112#endif
113
114protected:
115
116 std::string mClipName;
117 float mDuration = 0.0f;
118 float mTicksPerSecond = 1000.0f;
119
120 std::vector<SkeletalAnimationChannel> mChannels;
121 std::vector<AnimEventTrack> mEventTracks;
122
123 // Source skeleton metadata. Populated when the asset is extracted from a
124 // SkeletalMesh import; used by humanoid retargeting in later PRs and by
125 // the bound-channel resolver as a sanity reference. Optional for clips
126 // imported from animation-only files where no rig is available.
127 std::string mSourceRigName;
128 std::vector<std::string> mSourceBoneNames;
129 std::vector<int32_t> mSourceParentIndices;
130 std::vector<glm::mat4> mSourceBindPose;
131};
Platform
Definition EngineTypes.h:31
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition Asset.h:119
virtual void Create()
Definition Asset.cpp:77
virtual void SaveStream(Stream &stream, Platform platform)
Definition Asset.cpp:284
virtual glm::vec4 GetTypeColor()
Definition Asset.cpp:302
virtual const char * GetTypeName()
Definition Asset.cpp:307
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Asset.cpp:297
virtual void LoadStream(Stream &stream, Platform platform)
Definition Asset.cpp:270
virtual void Destroy()
Definition Asset.cpp:92
Definition HumanoidAvatarAsset.h:45
Definition SkeletalAnimationAsset.h:26
void SetSourceRigName(const std::string &name)
Definition SkeletalAnimationAsset.h:59
DECLARE_ASSET(SkeletalAnimationAsset, Asset)
const std::vector< std::string > & GetSourceBoneNames() const
Definition SkeletalAnimationAsset.h:61
std::string mSourceRigName
Definition SkeletalAnimationAsset.h:127
std::vector< glm::mat4 > & GetSourceBindPoseMutable()
Definition SkeletalAnimationAsset.h:68
float GetTicksPerSecond() const
Definition SkeletalAnimationAsset.h:47
const std::string & GetSourceRigName() const
Definition SkeletalAnimationAsset.h:58
const std::string & GetClipName() const
Definition SkeletalAnimationAsset.h:43
const std::vector< SkeletalAnimationChannel > & GetChannels() const
Definition SkeletalAnimationAsset.h:52
std::vector< SkeletalAnimationChannel > & GetChannelsMutable()
Definition SkeletalAnimationAsset.h:53
std::vector< int32_t > mSourceParentIndices
Definition SkeletalAnimationAsset.h:129
std::vector< AnimEventTrack > mEventTracks
Definition SkeletalAnimationAsset.h:121
std::vector< int32_t > & GetSourceParentIndicesMutable()
Definition SkeletalAnimationAsset.h:65
std::string mClipName
Definition SkeletalAnimationAsset.h:116
const std::vector< int32_t > & GetSourceParentIndices() const
Definition SkeletalAnimationAsset.h:64
std::vector< std::string > & GetSourceBoneNamesMutable()
Definition SkeletalAnimationAsset.h:62
void SetClipName(const std::string &name)
Definition SkeletalAnimationAsset.h:44
std::vector< AnimEventTrack > & GetEventTracksMutable()
Definition SkeletalAnimationAsset.h:56
const std::vector< glm::mat4 > & GetSourceBindPose() const
Definition SkeletalAnimationAsset.h:67
void SetDuration(float duration)
Definition SkeletalAnimationAsset.h:49
std::vector< SkeletalAnimationChannel > mChannels
Definition SkeletalAnimationAsset.h:120
std::vector< std::string > mSourceBoneNames
Definition SkeletalAnimationAsset.h:128
const std::vector< AnimEventTrack > & GetEventTracks() const
Definition SkeletalAnimationAsset.h:55
void SetTicksPerSecond(float tps)
Definition SkeletalAnimationAsset.h:50
float GetDuration() const
Definition SkeletalAnimationAsset.h:46
std::vector< glm::mat4 > mSourceBindPose
Definition SkeletalAnimationAsset.h:130
Definition SkeletalMesh.h:99
Definition Stream.h:21
Definition SkeletalMesh.h:77
Definition SkeletalAnimationAsset.h:17
std::vector< RotationKey > mRotationKeys
Definition SkeletalAnimationAsset.h:21
std::string mBoneName
Definition SkeletalAnimationAsset.h:18
int32_t mSourceBoneIndex
Definition SkeletalAnimationAsset.h:19
std::vector< ScaleKey > mScaleKeys
Definition SkeletalAnimationAsset.h:22
std::vector< PositionKey > mPositionKeys
Definition SkeletalAnimationAsset.h:20