1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxanimcurvebase.h
13#ifndef _FBXSDK_SCENE_ANIMATION_CURVE_BASE_H_
14#define _FBXSDK_SCENE_ANIMATION_CURVE_BASE_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/fbxobject.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22class FbxIO;
23
24/** This is the base class interface for the FBX animation curve keys.
25 * \nosubgrouping
26 *
27 * \remarks For an example of implemented class, please see FbxAnimCurveKey.
28 */
29class FBXSDK_DLL FbxAnimCurveKeyBase
30{
31public:
32 /** Data member representing time value.
33 */
34 FbxTime mTime;
35
36 /** Constructor.
37 */
38 FbxAnimCurveKeyBase()
39 {
40 mTime = FBXSDK_TIME_ZERO;
41 }
42
43 /** Destructor.
44 */
45 virtual ~FbxAnimCurveKeyBase() {};
46
47 /** Get time value.
48 * \return Time value.
49 */
50 virtual FbxTime GetTime() const
51 {
52 return mTime;
53 }
54
55 /** Set time value.
56 * \param pTime Time value to set.
57 */
58 virtual void SetTime(const FbxTime& pTime) {
59 mTime = pTime;
60 }
61};
62
63/** This is the base class for implementing animation curves.
64 * \nosubgrouping
65 * It is a pure virtual class that defines the general interface to animation
66 * key management and manipulation.
67 *
68 * \see FbxAnimCurve for fully implemented class.
69 */
70class FBXSDK_DLL FbxAnimCurveBase : public FbxObject
71{
72 FBXSDK_ABSTRACT_OBJECT_DECLARE(FbxAnimCurveBase, FbxObject);
73
74public:
75 /**
76 * \name Key management.
77 *
78 */
79 //@{
80 //! Remove all the keys and free buffer memory.
81 virtual void KeyClear () = 0;
82
83 //! Get the number of keys.
84 virtual int KeyGetCount () const = 0;
85
86 /** Add a key at given time.
87 * \param pTime Time to add the key.
88 * \param pKey Key to add.
89 * \param pLast Index of the last processed key to speed up search. If this
90 * function is called in a loop, initialize this value to 0 and let it
91 * be updated by each call.
92 * \return Index of the key at given time, no matter if it was added
93 * or already present.
94 */
95 virtual int KeyAdd (FbxTime pTime, FbxAnimCurveKeyBase& pKey, int* pLast = NULL) = 0;
96
97 /** Set key at given index.
98 * \param pIndex Index of where the key should be set.
99 * \param pKey The key to set.
100 * \return \c true if key time is superior to previous key and inferior
101 * to next key, \c false otherwise.
102 * \remarks Result is undetermined if function curve has no key or index
103 * is out of bounds.
104 */
105 virtual bool KeySet(int pIndex, FbxAnimCurveKeyBase& pKey) = 0;
106
107 /** Remove key at given index.
108 * \param pIndex Index of key to remove.
109 * \return \c true on success, \c false otherwise.
110 */
111 virtual bool KeyRemove(int pIndex) = 0;
112
113 /** Remove all the keys in the given range.
114 * \param pStartIndex Index of the first key to remove (inclusive).
115 * \param pEndIndex Index of the last key to remove (inclusive).
116 * \return \c true on success, \c false otherwise.
117 */
118 virtual bool KeyRemove(int pStartIndex, int pEndIndex) = 0;
119
120 //@}
121
122 /**
123 * \name Key Time Manipulation
124 */
125 //@{
126 /** Get key time.
127 * \param pKeyIndex Key index.
128 * \return Key time (time at which this key is occurring).
129 */
130 virtual FbxTime KeyGetTime(int /*pKeyIndex*/) const { return FBXSDK_TIME_INFINITE; }
131
132 /** Set key time.
133 * \param pKeyIndex Key index.
134 * \param pTime Key time (time at which this key is occurring).
135 */
136 virtual void KeySetTime(int pKeyIndex, FbxTime pTime) = 0;
137
138 //@}
139
140 /**
141 * \name Extrapolation
142 * Extrapolation defines the function curve value before and after the keys.
143 * Pre-extrapolation defines the function curve value before first key.
144 * Post-extrapolation defines the function curve value after last key.
145 * <ul><li>CONSTANT means a constant value matching the first/last key.
146 * <li>REPETITION means the entire function curve is looped.
147 * <li>MIRROR_REPETITION means the entire function curve is looped once backward, once forward and so on.
148 * <li>KEEP_SLOPE means a linear function with a slope matching the first/last key.</ul>
149 */
150 //@{
151 enum EExtrapolationType
152 {
153 eConstant = 1,
154 eRepetition = 2,
155 eMirrorRepetition = 3,
156 eKeepSlope = 4
157 } ;
158
159 /** Set pre-extrapolation mode.
160 * \param pExtrapolation The pre-extrapolation mode to set.
161 */
162 void SetPreExtrapolation(EExtrapolationType pExtrapolation);
163
164 /** Get pre-extrapolation mode.
165 * \return The current pre-extrapolation mode.
166 */
167 EExtrapolationType GetPreExtrapolation() const { return mPreExtrapolation; }
168
169 /** Set pre-extrapolation count.
170 * \param pCount Number of repetitions if pre-extrapolation mode is
171 * REPETITION or MIRROR_REPETITION.
172 */
173 void SetPreExtrapolationCount(unsigned long pCount);
174
175 /** Get pre-extrapolation count.
176 * \return Number of repetitions if pre-extrapolation mode is
177 * REPETITION or MIRROR_REPETITION.
178 */
179 unsigned long GetPreExtrapolationCount() const { return mPreExtrapolationCount; }
180
181 /** Set post-extrapolation mode.
182 * \param pExtrapolation The post-extrapolation mode to set.
183 */
184 void SetPostExtrapolation(EExtrapolationType pExtrapolation);
185
186 /** Get post-extrapolation mode.
187 * \return The current post-extrapolation mode.
188 */
189 EExtrapolationType GetPostExtrapolation() const { return mPostExtrapolation; }
190
191 /** Set post-extrapolation count.
192 * \param pCount Number of repetitions if post-extrapolation mode is
193 * REPETITION or MIRROR_REPETITION.
194 */
195 void SetPostExtrapolationCount(unsigned long pCount);
196
197 /** Get post-extrapolation count.
198 * \return Number of repetitions if post-extrapolation mode is
199 * REPETITION or MIRROR_REPETITION.
200 */
201 unsigned long GetPostExtrapolationCount() const { return mPostExtrapolationCount; }
202 //@}
203
204 /**
205 * \name Evaluation and Analysis
206 */
207 //@{
208 /** Evaluate curve value at a given time.
209 * \param pTime Time of evaluation.
210 * \param pLast Index of the last processed key to speed up search. If this
211 * function is called in a loop, initialize this value to 0 and let it
212 * be updated by each call.
213 * \return Evaluated curve value.
214 * \remarks This function take extrapolation into account.
215 */
216 virtual float Evaluate (FbxTime pTime, int* pLast = NULL) = 0;
217
218 /** Evaluate curve value at the given key index.
219 * \param pIndex Any value from 0 to KeyGetCount() - 1.
220 * If this index falls between keys, the curve value will
221 * be interpolated based on the surrounding keys.
222 * \return Evaluated curve value.
223 */
224 virtual float EvaluateIndex( double pIndex) = 0;
225 //@}
226
227 /**
228 * \name Utility functions.
229 *
230 */
231 //@{
232 /** Find out start and end time of the animation curve.
233 * This function retrieves the Curve's time span.
234 * \param pTimeInterval Reference to receive start time and end time.
235 * \return \c true on success, \c false otherwise.
236 */
237 virtual bool GetTimeInterval(FbxTimeSpan& pTimeInterval);
238 //@}
239
240/*****************************************************************************************************************************
241** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
242*****************************************************************************************************************************/
243#ifndef DOXYGEN_SHOULD_SKIP_THIS
244 virtual FbxObject& Copy(const FbxObject& pObject);
245 virtual bool Store(FbxIO* pFileObject, bool pLegacyVersion=false) = 0;
246 virtual bool Retrieve(FbxIO* pFileObject) = 0;
247 virtual void ExtrapolationSyncCallback() = 0;
248
249protected:
250 virtual void Construct(const FbxObject* pFrom);
251
252private:
253 EExtrapolationType mPreExtrapolation;
254 unsigned long mPreExtrapolationCount;
255 EExtrapolationType mPostExtrapolation;
256 unsigned long mPostExtrapolationCount;
257#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
258};
259
260#include <fbxsdk/fbxsdk_nsend.h>
261
262#endif // FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEBASE_H
263