DatasmithAnimationElementsImpl.h
1 // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
2 #pragma once
3 
4 #include "DatasmithAnimationElements.h"
5 #include "DatasmithSceneElementsImpl.h"
6 
7 #include "Containers/Array.h"
8 #include "Templates/SharedPointer.h"
9 
10 class FDatasmithLevelSequenceElementImpl : public FDatasmithElementImpl< IDatasmithLevelSequenceElement >
11 {
12 public:
13  explicit FDatasmithLevelSequenceElementImpl(const TCHAR* InName);
14 
15  virtual const TCHAR* GetFile() const override { return *File; }
16  virtual void SetFile(const TCHAR* InFile) override { File = InFile; };
17 
18  virtual FMD5Hash GetFileHash() const override { return FileHash; }
19  virtual void SetFileHash(FMD5Hash Hash) override { FileHash = Hash; }
20 
21  virtual float GetFrameRate() const override { return FrameRate; }
22  virtual void SetFrameRate(float FramePerSecs) override { FrameRate = FramePerSecs; }
23 
24  virtual void AddAnimation(const TSharedRef< IDatasmithBaseAnimationElement >& InAnimation) override { Animations.Add(InAnimation); }
25  virtual int32 GetAnimationsCount() const override { return Animations.Num(); }
26 
27  virtual TSharedPtr< IDatasmithBaseAnimationElement > GetAnimation(int32 InIndex) override
28  {
29  return Animations.IsValidIndex(InIndex) ? Animations[InIndex] : TSharedPtr< IDatasmithBaseAnimationElement >();
30  }
31 
32  virtual void RemoveAnimation(const TSharedRef< IDatasmithBaseAnimationElement >& InAnimation) override { Animations.Remove(InAnimation); }
33 
34 private:
35  FString File;
36  FMD5Hash FileHash;
37  TArray< TSharedRef< IDatasmithBaseAnimationElement > > Animations;
38  float FrameRate;
39 };
40 
41 template< typename InterfaceType >
43 {
44 public:
45  explicit FDatasmithBaseAnimationElementImpl(const TCHAR* InName, EDatasmithElementType ChildType, EDatasmithElementAnimationSubType InSubtype = EDatasmithElementAnimationSubType::BaseAnimation);
46 
47  virtual void SetCompletionMode(EDatasmithCompletionMode InCompletionMode) override
48  {
49  CompletionMode = InCompletionMode;
50  }
51 
52  virtual EDatasmithCompletionMode GetCompletionMode() const override
53  {
54  return CompletionMode;
55  }
56 
57 private:
58  EDatasmithCompletionMode CompletionMode;
59 };
60 
61 template< typename T >
62 inline FDatasmithBaseAnimationElementImpl<T>::FDatasmithBaseAnimationElementImpl(const TCHAR* InName, EDatasmithElementType ChildType, EDatasmithElementAnimationSubType InSubtype)
63  : FDatasmithElementImpl<T>(InName, EDatasmithElementType::Animation | ChildType, (uint64)InSubtype)
64  , CompletionMode(EDatasmithCompletionMode::ProjectDefault)
65 {
66 }
67 
68 class FDatasmithTransformAnimationElementImpl : public FDatasmithBaseAnimationElementImpl< IDatasmithTransformAnimationElement >
69 {
70 public:
71  explicit FDatasmithTransformAnimationElementImpl(const TCHAR* InName);
72 
73  virtual void AddFrame(EDatasmithTransformType TransformType, const FDatasmithTransformFrameInfo& FrameInfo) override { Frames[(uint8)TransformType].Add(FrameInfo); }
74  virtual int32 GetFramesCount(EDatasmithTransformType TransformType) const override { return Frames[(uint8)TransformType].Num(); }
75 
76  virtual void SetCurveInterpMode(EDatasmithTransformType TransformType, EDatasmithCurveInterpMode CurveInterpMode) override
77  {
78  TransformCurveInterpMode[(uint32) TransformType] = CurveInterpMode;
79  }
80 
81  virtual EDatasmithCurveInterpMode GetCurveInterpMode(EDatasmithTransformType TransformType) const override
82  {
83  return TransformCurveInterpMode[(uint32) TransformType];
84  }
85 
86  virtual const FDatasmithTransformFrameInfo& GetFrame(EDatasmithTransformType TransformType, int32 Index) const override
87  {
88  return Frames[(uint8)TransformType].IsValidIndex(Index) ? Frames[(uint8)TransformType][Index] : FDatasmithTransformFrameInfo::InvalidFrameInfo;
89  }
90 
91  virtual void RemoveFrame(EDatasmithTransformType TransformType, int32 Index) override
92  {
93  if (Frames[(uint8)TransformType].IsValidIndex(Index))
94  {
95  Frames[(uint8)TransformType].RemoveAt(Index);
96  }
97  }
98 
99  virtual EDatasmithTransformChannels GetEnabledTransformChannels() const override
100  {
101  return EnabledChannels;
102  }
103 
104  virtual void SetEnabledTransformChannels(EDatasmithTransformChannels Channels) override
105  {
106  EnabledChannels = Channels;
107  }
108 
109 private:
110  TArray< FDatasmithTransformFrameInfo > Frames[(uint8) EDatasmithTransformType::Count];
111  EDatasmithCurveInterpMode TransformCurveInterpMode[(uint8) EDatasmithTransformType::Count];
112  EDatasmithTransformChannels EnabledChannels;
113 };
114 
115 class FDatasmithVisibilityAnimationElementImpl : public FDatasmithBaseAnimationElementImpl< IDatasmithVisibilityAnimationElement >
116 {
117 public:
118  explicit FDatasmithVisibilityAnimationElementImpl(const TCHAR* InName);
119 
120  virtual void AddFrame(const FDatasmithVisibilityFrameInfo& FrameInfo) override { Frames.Add(FrameInfo); }
121  virtual int32 GetFramesCount() const override { return Frames.Num(); }
122 
123  virtual void SetCurveInterpMode(EDatasmithCurveInterpMode InCurveInterpMode) override
124  {
125  CurveInterpMode = InCurveInterpMode;
126  }
127 
128  virtual EDatasmithCurveInterpMode GetCurveInterpMode() const override
129  {
130  return CurveInterpMode;
131  }
132 
133  virtual const FDatasmithVisibilityFrameInfo& GetFrame(int32 Index) const override
134  {
135  return Frames.IsValidIndex(Index) ? Frames[Index] : FDatasmithVisibilityFrameInfo::InvalidFrameInfo;
136  }
137 
138  virtual void RemoveFrame(int32 Index) override
139  {
140  if (Frames.IsValidIndex(Index))
141  {
142  Frames.RemoveAt(Index);
143  }
144  }
145 
146 private:
147  TArray<FDatasmithVisibilityFrameInfo> Frames;
148  EDatasmithCurveInterpMode CurveInterpMode;
149 };
150 
151 class FDatasmithSubsequenceAnimationElementImpl : public FDatasmithBaseAnimationElementImpl< IDatasmithSubsequenceAnimationElement >
152 {
153 public:
154  explicit FDatasmithSubsequenceAnimationElementImpl(const TCHAR* InName);
155 
156  virtual FFrameNumber GetStartTime() const override
157  {
158  return StartTime;
159  }
160 
161  virtual void SetStartTime(FFrameNumber InStartTime) override
162  {
163  StartTime = InStartTime;
164  }
165 
166  virtual int32 GetDuration() const override
167  {
168  return Duration;
169  }
170 
171  virtual void SetDuration(int32 InDuration) override
172  {
173  Duration = InDuration;
174  }
175 
176  virtual float GetTimeScale() const override
177  {
178  return TimeScale;
179  }
180 
181  virtual void SetTimeScale(float InTimeScale) override
182  {
183  TimeScale = InTimeScale;
184  }
185 
186  virtual TWeakPtr<IDatasmithLevelSequenceElement> GetSubsequence() const override
187  {
188  return Subsequence;
189  }
190 
191  virtual void SetSubsequence(TWeakPtr<IDatasmithLevelSequenceElement> InSubsequence) override
192  {
193  Subsequence = InSubsequence;
194  }
195 
196 private:
197  FFrameNumber StartTime;
198  int32 Duration;
199  float TimeScale;
200  TWeakPtr<IDatasmithLevelSequenceElement> Subsequence;
201 };
FDatasmithSubsequenceAnimationElementImpl::SetStartTime
virtual void SetStartTime(FFrameNumber InStartTime) override
Set the frame where the subsequence starts.
Definition: DatasmithAnimationElementsImpl.h:161
FDatasmithLevelSequenceElementImpl
Definition: DatasmithAnimationElementsImpl.h:10
FDatasmithTransformAnimationElementImpl::SetEnabledTransformChannels
virtual void SetEnabledTransformChannels(EDatasmithTransformChannels Channels) override
Sets which channels of this animation will be moved to the animation assets or serialized.
Definition: DatasmithAnimationElementsImpl.h:104
FDatasmithBaseAnimationElementImpl
Definition: DatasmithAnimationElementsImpl.h:42
FDatasmithVisibilityFrameInfo
FDatasmithVisibilityFrameInfo holds the visibility value for a frame.
Definition: DatasmithTypes.h:132
FDatasmithVisibilityAnimationElementImpl::GetFramesCount
virtual int32 GetFramesCount() const override
Return the number of frames of the animation.
Definition: DatasmithAnimationElementsImpl.h:121
FDatasmithVisibilityAnimationElementImpl::AddFrame
virtual void AddFrame(const FDatasmithVisibilityFrameInfo &FrameInfo) override
Add a frame to the animation.
Definition: DatasmithAnimationElementsImpl.h:120
FDatasmithTransformAnimationElementImpl::AddFrame
virtual void AddFrame(EDatasmithTransformType TransformType, const FDatasmithTransformFrameInfo &FrameInfo) override
Add a frame of the given transform type to the animation.
Definition: DatasmithAnimationElementsImpl.h:73
FDatasmithElementImpl
Definition: DatasmithSceneElementsImpl.h:15
FDatasmithSubsequenceAnimationElementImpl::GetStartTime
virtual FFrameNumber GetStartTime() const override
Get the frame where the subsequence starts.
Definition: DatasmithAnimationElementsImpl.h:156
FDatasmithLevelSequenceElementImpl::AddAnimation
virtual void AddAnimation(const TSharedRef< IDatasmithBaseAnimationElement > &InAnimation) override
Adds an animation to the level sequence.
Definition: DatasmithAnimationElementsImpl.h:24
FDatasmithLevelSequenceElementImpl::GetFile
virtual const TCHAR * GetFile() const override
Get the output filename, it can be absolute or relative to the scene file.
Definition: DatasmithAnimationElementsImpl.h:15
FDatasmithTransformFrameInfo
FDatasmithTransformFrameInfo holds the data for the transform values of a frame The transform values ...
Definition: DatasmithTypes.h:90
FDatasmithLevelSequenceElementImpl::GetAnimation
virtual TSharedPtr< IDatasmithBaseAnimationElement > GetAnimation(int32 InIndex) override
Returns the animation using this index.
Definition: DatasmithAnimationElementsImpl.h:27
FDatasmithTransformAnimationElementImpl::GetFramesCount
virtual int32 GetFramesCount(EDatasmithTransformType TransformType) const override
Return the number of frames of the given transform type in the animation.
Definition: DatasmithAnimationElementsImpl.h:74
FDatasmithLevelSequenceElementImpl::GetFileHash
virtual FMD5Hash GetFileHash() const override
Return a MD5 hash of the content of the Level Sequence Element.
Definition: DatasmithAnimationElementsImpl.h:18
FDatasmithSubsequenceAnimationElementImpl::GetDuration
virtual int32 GetDuration() const override
Get the subsequence duration in number of frames.
Definition: DatasmithAnimationElementsImpl.h:166
FDatasmithTransformAnimationElementImpl::SetCurveInterpMode
virtual void SetCurveInterpMode(EDatasmithTransformType TransformType, EDatasmithCurveInterpMode CurveInterpMode) override
Set the interpolation mode of the given transform type in the animation.
Definition: DatasmithAnimationElementsImpl.h:76
FDatasmithVisibilityAnimationElementImpl::GetCurveInterpMode
virtual EDatasmithCurveInterpMode GetCurveInterpMode() const override
Get the interpolation mode of the animation.
Definition: DatasmithAnimationElementsImpl.h:128
FDatasmithVisibilityAnimationElementImpl::SetCurveInterpMode
virtual void SetCurveInterpMode(EDatasmithCurveInterpMode InCurveInterpMode) override
Set the interpolation mode of the animation.
Definition: DatasmithAnimationElementsImpl.h:123
FDatasmithTransformAnimationElementImpl::GetCurveInterpMode
virtual EDatasmithCurveInterpMode GetCurveInterpMode(EDatasmithTransformType TransformType) const override
Get the interpolation mode of the given transform type in the animation.
Definition: DatasmithAnimationElementsImpl.h:81
FDatasmithVisibilityAnimationElementImpl::GetFrame
virtual const FDatasmithVisibilityFrameInfo & GetFrame(int32 Index) const override
Return the frame of the animation at the given index or an invalid frame if the index was out of boun...
Definition: DatasmithAnimationElementsImpl.h:133
FDatasmithSubsequenceAnimationElementImpl::SetTimeScale
virtual void SetTimeScale(float InTimeScale) override
Set the time scale used for the subsequence.
Definition: DatasmithAnimationElementsImpl.h:181
FDatasmithTransformAnimationElementImpl::GetFrame
virtual const FDatasmithTransformFrameInfo & GetFrame(EDatasmithTransformType TransformType, int32 Index) const override
Return the frame of the given transform type at the given index or an invalid frame if the index was ...
Definition: DatasmithAnimationElementsImpl.h:86
FDatasmithSubsequenceAnimationElementImpl::GetTimeScale
virtual float GetTimeScale() const override
Get the time scale used for the subsequence.
Definition: DatasmithAnimationElementsImpl.h:176
FDatasmithTransformAnimationElementImpl::RemoveFrame
virtual void RemoveFrame(EDatasmithTransformType TransformType, int32 Index) override
Remove the frame of the given transform type at the given index from the animation.
Definition: DatasmithAnimationElementsImpl.h:91
FDatasmithTransformAnimationElementImpl::GetEnabledTransformChannels
virtual EDatasmithTransformChannels GetEnabledTransformChannels() const override
Gets which channels of this animation will be moved to the animation assets or serialized.
Definition: DatasmithAnimationElementsImpl.h:99
FDatasmithVisibilityAnimationElementImpl::RemoveFrame
virtual void RemoveFrame(int32 Index) override
Remove the frame at the given index from the animation.
Definition: DatasmithAnimationElementsImpl.h:138
FDatasmithLevelSequenceElementImpl::RemoveAnimation
virtual void RemoveAnimation(const TSharedRef< IDatasmithBaseAnimationElement > &InAnimation) override
Removes an animation from the level sequence.
Definition: DatasmithAnimationElementsImpl.h:32
FDatasmithLevelSequenceElementImpl::SetFileHash
virtual void SetFileHash(FMD5Hash Hash) override
Set the MD5 hash of the Level Sequence file.
Definition: DatasmithAnimationElementsImpl.h:19
FDatasmithVisibilityAnimationElementImpl
Definition: DatasmithAnimationElementsImpl.h:115
FDatasmithTransformAnimationElementImpl
Definition: DatasmithAnimationElementsImpl.h:68
FDatasmithSubsequenceAnimationElementImpl::SetSubsequence
virtual void SetSubsequence(TWeakPtr< IDatasmithLevelSequenceElement > InSubsequence) override
Set the subsequence that this element references.
Definition: DatasmithAnimationElementsImpl.h:191
FDatasmithSubsequenceAnimationElementImpl
Definition: DatasmithAnimationElementsImpl.h:151
FDatasmithSubsequenceAnimationElementImpl::GetSubsequence
virtual TWeakPtr< IDatasmithLevelSequenceElement > GetSubsequence() const override
Get a pointer to the subsequence that this element references.
Definition: DatasmithAnimationElementsImpl.h:186
FDatasmithLevelSequenceElementImpl::SetFile
virtual void SetFile(const TCHAR *InFile) override
Set the output filename, it can be absolute or relative to the scene file.
Definition: DatasmithAnimationElementsImpl.h:16
FDatasmithLevelSequenceElementImpl::GetAnimationsCount
virtual int32 GetAnimationsCount() const override
Returns the number of animations in the level sequence.
Definition: DatasmithAnimationElementsImpl.h:25
FDatasmithSubsequenceAnimationElementImpl::SetDuration
virtual void SetDuration(int32 InDuration) override
Set the subsequence duration in number of frames.
Definition: DatasmithAnimationElementsImpl.h:171