1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | Based on the FS Import classes:
|
---|
7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | @file FCDAnimationCurve.h
|
---|
14 | This file contains the FCDAnimationCurve class.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef _FCD_ANIMATION_CURVE_H_
|
---|
18 | #define _FCD_ANIMATION_CURVE_H_
|
---|
19 |
|
---|
20 | #include "FUtils/FUDaeEnum.h"
|
---|
21 | #include "FCDocument/FCDObject.h"
|
---|
22 |
|
---|
23 | class FCDAnimationClip;
|
---|
24 | class FCDAnimationChannel;
|
---|
25 |
|
---|
26 | typedef vector<FCDAnimationClip*> FCDAnimationClipList; /**< A dynamically-sized array of animation clips. */
|
---|
27 | typedef float (*FCDConversionFunction)(float v); /**< A simple conversion function. */
|
---|
28 |
|
---|
29 | /**
|
---|
30 | A COLLADA single-dimensional animation curve.
|
---|
31 | An animation curve holds the keyframes necessary
|
---|
32 | to animate an animatable floating-point value.
|
---|
33 |
|
---|
34 | There are multiple interpolation mechanisms supported by COLLADA.
|
---|
35 | FCollada supports the CONSTANT, LINEAR and BEZIER interpolations.
|
---|
36 |
|
---|
37 | @see FUDaeInterpolation FUDaeInfinity
|
---|
38 | @ingroup FCDocument
|
---|
39 | */
|
---|
40 | class FCOLLADA_EXPORT FCDAnimationCurve : public FCDObject
|
---|
41 | {
|
---|
42 | private:
|
---|
43 | DeclareObjectType;
|
---|
44 | FCDAnimationChannel* parent;
|
---|
45 |
|
---|
46 | // Targeting information
|
---|
47 | int32 targetElement;
|
---|
48 | string targetQualifier;
|
---|
49 |
|
---|
50 | // Input information
|
---|
51 | FloatList keys, keyValues;
|
---|
52 | FloatList inTangents, outTangents;
|
---|
53 | FloatList inTangentWeights, outTangentWeights;
|
---|
54 | bool isWeightedCurve;
|
---|
55 | FUDaeInfinity::Infinity preInfinity;
|
---|
56 | FUDaeInfinity::Infinity postInfinity;
|
---|
57 |
|
---|
58 | // Driver information
|
---|
59 | const float* inputDriver;
|
---|
60 | string driverPointer;
|
---|
61 |
|
---|
62 | // The interpolation values follow the FUDaeInterpolation enum (FUDaeEnum.h)
|
---|
63 | UInt32List interpolations;
|
---|
64 |
|
---|
65 | // Animation clips that depend on this curve
|
---|
66 | FCDAnimationClipList clips;
|
---|
67 |
|
---|
68 | public:
|
---|
69 | /** Constructor: do not use directly.
|
---|
70 | Instead, use the FCDAnimationChannel::AddCurve function.
|
---|
71 | You should also attach the new curve to an animated
|
---|
72 | element using the FCDAnimated::SetCurve function.
|
---|
73 | @param document The COLLADA document that owns the animation curve.
|
---|
74 | @param parent The animation channel that contains the curve. */
|
---|
75 | FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* parent);
|
---|
76 |
|
---|
77 | /** Destructor: do not release directly.
|
---|
78 | Instead, use the FCDAnimationChannel::ReleaseCurve function. */
|
---|
79 | virtual ~FCDAnimationCurve();
|
---|
80 |
|
---|
81 | /** Retrieves the animation channel that contains this animation curve.
|
---|
82 | @return The parent animation channel. */
|
---|
83 | inline FCDAnimationChannel* GetParent() { return parent; }
|
---|
84 | inline const FCDAnimationChannel* GetParent() const { return parent; } /**< See above. */
|
---|
85 |
|
---|
86 | /** Retrieves the list of key inputs for the animation curve.
|
---|
87 | @return The list of key inputs. */
|
---|
88 | inline FloatList& GetKeys() { return keys; }
|
---|
89 | inline const FloatList& GetKeys() const { return keys; } /**< See above. */
|
---|
90 |
|
---|
91 | /** Retrieves the list of key outputs for the animation curve.
|
---|
92 | @return The list of key outputs. */
|
---|
93 | inline FloatList& GetKeyValues() { return keyValues; }
|
---|
94 | inline const FloatList& GetKeyValues() const { return keyValues; } /**< See above. */
|
---|
95 |
|
---|
96 | /** Retrieves the list of interpolation type for the segments of the animation curve.
|
---|
97 | There is always one interpolation type for each key in the curve. The interpolation type
|
---|
98 | of a segment of the curve is set at the key at which begins the segment.
|
---|
99 | @see FUDaeInterpolation
|
---|
100 | @return The list of interpolation types. */
|
---|
101 | inline UInt32List& GetInterpolations() { return interpolations; }
|
---|
102 | inline const UInt32List& GetInterpolations() const { return interpolations; } /**< See above. */
|
---|
103 |
|
---|
104 | /** Retrieves the list of key in-tangent values for the animation curve.
|
---|
105 | This list has data only for curves that include segments with the bezier interpolation.
|
---|
106 | @return The list of in-tangent values. */
|
---|
107 | inline FloatList& GetInTangents() { return inTangents; }
|
---|
108 | inline const FloatList& GetInTangents() const { return inTangents; } /**< See above. */
|
---|
109 |
|
---|
110 | /** Retrieves the list of key out-tangent values for the animation curve.
|
---|
111 | This list has data only for curves that include segments with the bezier interpolation.
|
---|
112 | @return The list of out-tangent values. */
|
---|
113 | inline FloatList& GetOutTangents() { return outTangents; }
|
---|
114 | inline const FloatList& GetOutTangents() const { return outTangents; } /**< See above. */
|
---|
115 |
|
---|
116 | /** Retrieves the list of key in-tangent weights for the animation curve.
|
---|
117 | This list has data only for curves that are weighted
|
---|
118 | and include segments with the bezier interpolation.
|
---|
119 | @see IsWeightedCurve
|
---|
120 | @return The list of in-tangent weights. */
|
---|
121 | inline FloatList& GetInTangentWeights() { return inTangentWeights; }
|
---|
122 | inline const FloatList& GetInTangentWeights() const { return inTangentWeights; } /**< See above. */
|
---|
123 |
|
---|
124 | /** Retrieves the list of key out-tangent weights for the animation curve.
|
---|
125 | This list has data only for curves that are weighted
|
---|
126 | and include segments with the bezier interpolation.
|
---|
127 | @see IsWeightedCurve
|
---|
128 | @return The list of out-tangent weights. */
|
---|
129 | inline FloatList& GetOutTangentWeights() { return outTangentWeights; }
|
---|
130 | inline const FloatList& GetOutTangentWeights() const { return outTangentWeights; } /**< See above. */
|
---|
131 |
|
---|
132 | /** Retrieves whether this curve has weighted tangents. Tangent weights
|
---|
133 | give you access to 2D tangents by providing the length of the tangent.
|
---|
134 | @return Whether this curve has weighted tangents. */
|
---|
135 | inline bool IsWeightedCurve() const { return isWeightedCurve; }
|
---|
136 |
|
---|
137 | /** Sets whether this curve has weighted tangents. Tangent weights
|
---|
138 | give you access to 2D tangents by providing the length of the tangent.
|
---|
139 | @param _isWeightedCurve Whether this curve has weighted tangents. */
|
---|
140 | inline void SetWeightedCurveFlag(bool _isWeightedCurve) { isWeightedCurve = _isWeightedCurve; }
|
---|
141 |
|
---|
142 | /** Retrieves the type of behavior for the curve if the input value is
|
---|
143 | outside the input interval defined by the curve keys and less than any key input value.
|
---|
144 | @see FUDaeInfinity
|
---|
145 | @return The pre-infinity behavior of the curve. */
|
---|
146 | inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; }
|
---|
147 |
|
---|
148 | /** Sets the behavior of the curve if the input value is
|
---|
149 | outside the input interval defined by the curve keys and less than any key input value.
|
---|
150 | @see FUDaeInfinity
|
---|
151 | @param infinity The pre-infinity behavior of the curve. */
|
---|
152 | inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; }
|
---|
153 |
|
---|
154 | /** Retrieves the type of behavior for the curve if the input value is
|
---|
155 | outside the input interval defined by the curve keys and greater than any key input value.
|
---|
156 | @see FUDaeInfinity
|
---|
157 | @return The post-infinity behavior of the curve. */
|
---|
158 | inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; }
|
---|
159 |
|
---|
160 | /** Sets the behavior of the curve if the input value is
|
---|
161 | outside the input interval defined by the curve keys and greater than any key input value.
|
---|
162 | @see FUDaeInfinity
|
---|
163 | @param infinity The post-infinity behavior of the curve. */
|
---|
164 | inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; }
|
---|
165 |
|
---|
166 | /** Retrieves the value pointer that drives this animation curve.
|
---|
167 | @return The driver value pointer. This pointer will be NULL to indicate
|
---|
168 | that time drives the animation curve. */
|
---|
169 | inline const float* GetDriver() const { return inputDriver; }
|
---|
170 |
|
---|
171 | /** Sets the value pointer that drives the animation curve.
|
---|
172 | @param driver The driver value pointer. Set this pointer to NULL
|
---|
173 | to indicate that time drives the animation curve. */
|
---|
174 | inline void SetDriver(const float* driver) { inputDriver = driver; }
|
---|
175 |
|
---|
176 | /** Retrieves the list of animation clips that use this animation curve.
|
---|
177 | @return The list of animation clips. */
|
---|
178 | inline FCDAnimationClipList& GetClips() { return clips; }
|
---|
179 | inline const FCDAnimationClipList& GetClips() const { return clips; } /**< See above. */
|
---|
180 |
|
---|
181 | /** Readies this curve for evaluation.
|
---|
182 | This will create the tangents and the tangent weights, if necessary. */
|
---|
183 | void Ready();
|
---|
184 |
|
---|
185 | /** Clones the animation curve.
|
---|
186 | @return The cloned animation curve. */
|
---|
187 | FCDAnimationCurve* Clone();
|
---|
188 |
|
---|
189 | /** Applies a conversion function to the keys output values of the animation curve.
|
---|
190 | @param valueConversion The conversion function to use on the key outputs.
|
---|
191 | @param tangentConversion The conversion function to use on the key tangents. */
|
---|
192 | void ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion);
|
---|
193 |
|
---|
194 | /** Applies a conversion function to the keys input values of the animation curve.
|
---|
195 | @param timeConversion The conversion function to use on the key inputs.
|
---|
196 | @param tangentWeightConversion The conversion function to use on the key tangent weights. */
|
---|
197 | void ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion);
|
---|
198 |
|
---|
199 | /** Evaluates the animation curve.
|
---|
200 | @param input An input value.
|
---|
201 | @return The sampled value of the curve at the given input value. */
|
---|
202 | float Evaluate(float input) const;
|
---|
203 |
|
---|
204 | /** [INTERNAL] Adds an animation clip to the list of animation clips that use this curve.
|
---|
205 | @param clip An animation clip. */
|
---|
206 | inline void RegisterAnimationClip(FCDAnimationClip* clip) { clips.push_back(clip); }
|
---|
207 |
|
---|
208 | /** [INTERNAL] Writes out the data sources necessary to import the animation curve
|
---|
209 | to a given XML tree node.
|
---|
210 | @param parentNode The XML tree node in which to create the data sources.
|
---|
211 | @param baseId A COLLADA Id prefix to use when generating the source ids. */
|
---|
212 | void WriteSourceToXML(xmlNode* parentNode, const string& baseId) const;
|
---|
213 |
|
---|
214 | /** [INTERNAL] Writes out the sampler that puts together the data sources
|
---|
215 | and generates a sampling function.
|
---|
216 | @param parentNode The XML tree node in which to create the sampler.
|
---|
217 | @param baseId The COLLADA id prefix used when generating the source ids.
|
---|
218 | This prefix is also used to generate the sampler COLLADA id.
|
---|
219 | @return The created XML tree node. */
|
---|
220 | xmlNode* WriteSamplerToXML(xmlNode* parentNode, const string& baseId) const;
|
---|
221 |
|
---|
222 | /** [INTERNAL] Writes out the animation channel that attaches the sampling function
|
---|
223 | to the animatable value.
|
---|
224 | @param parentNode The XML tree node in which to create the sampler.
|
---|
225 | @param baseId The COLLADA Id prefix used when generating the source ids
|
---|
226 | and the sampler id.
|
---|
227 | @param targetPointer The target pointer prefix for the targeted animated element.
|
---|
228 | @return The created XML tree node. */
|
---|
229 | xmlNode* WriteChannelToXML(xmlNode* parentNode, const string& baseId, const char* targetPointer) const;
|
---|
230 |
|
---|
231 | /** [INTERNAL] Retrieves the target element suffix for the curve.
|
---|
232 | This will be -1 if the animated element does not belong to an
|
---|
233 | animated element list.
|
---|
234 | @return The target element suffix. */
|
---|
235 | inline int32 GetTargetElement() const { return targetElement; }
|
---|
236 |
|
---|
237 | /** [INTERNAL] Retrieves the target qualifier for the curve.
|
---|
238 | This will be the empty string if that the curve affects
|
---|
239 | a one-dimensional animated element.
|
---|
240 | @return The target qualifier. */
|
---|
241 | inline const string& GetTargetQualifier() const { return targetQualifier; }
|
---|
242 |
|
---|
243 | /** [INTERNAL] Sets the target element suffix for the curve.
|
---|
244 | @param e The target element suffix. Set to value to -1
|
---|
245 | if the animated element does not belong to an animated element list. */
|
---|
246 | inline void SetTargetElement(int32 e) { targetElement = e; }
|
---|
247 |
|
---|
248 | /** [INTERNAL] Sets the target qualifier for the curve.
|
---|
249 | @param q The target qualifier. You may sets this string to the empty string
|
---|
250 | only if that the curve affects a one-dimensional animated element. */
|
---|
251 | inline void SetTargetQualifier(const string& q) { targetQualifier = q; }
|
---|
252 |
|
---|
253 | /** [INTERNAL] Retrieves the target pointer prefix of the driver.
|
---|
254 | @return The driver's target pointer prefix. */
|
---|
255 | inline const string& GetDriverPointer() const { return driverPointer; }
|
---|
256 |
|
---|
257 | /** [INTERNAL] Sets the target pointer prefix of the driver.
|
---|
258 | @param p The driver's target pointer prefix. Set this string to the
|
---|
259 | empty string if the input of the animation curve is the time. */
|
---|
260 | inline void SetDriverPointer(const string& p) { driverPointer = p; }
|
---|
261 | };
|
---|
262 |
|
---|
263 | #endif // _FCD_ANIMATION_CURVE_H_
|
---|