source: NonGTP/FCollada/FCDocument/FCDAnimationMultiCurve.h @ 964

Revision 964, 8.1 KB checked in by igarcia, 18 years ago (diff)
RevLine 
[964]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 FCDAnimationMultiCurve.h
14        This file contains the FCDAnimationMultiCurve class.
15*/
16
17#ifndef _FCD_ANIMATION_MULTI_CURVE_H_
18#define _FCD_ANIMATION_MULTI_CURVE_H_
19
20class FCDocument;
21
22#include "FCDocument/FCDObject.h"
23
24typedef float (*FCDConversionFunction)(float v); /**< A simple conversion function. */
25typedef float (*FCDCollapsingFunction)(float* values, uint32 count); /**< A collapsing function. It converts multiple floating-point values into one floating-point value. */
26
27/**
28        A COLLADA multi-dimensional animation curve.
29
30        This is a utility class that is used to convert multiple
31        animation curves into one animation curve that has multiple
32        dimensions, but only one list of key inputs.
33
34        FCollada will never create a multi-dimensional animation curve
35        during the import of a COLLADA document.
36
37        @ingroup FCDocument
38*/
39class FCOLLADA_EXPORT FCDAnimationMultiCurve : public FCDObject
40{
41private:
42        DeclareObjectType;
43
44        // The number of merged curves
45        uint32 dimension;
46
47        // Target information
48        int32 targetElement;
49        string* targetQualifiers;
50
51        // Input information
52        FloatList keys,* keyValues;
53        FloatList* inTangents,* outTangents;
54
55        // The interpolation values follow the FUDaeInterpolation enum (FUDaeEnum.h)
56        UInt32List interpolations;
57
58public:
59        /** Constructor.
60                The number of dimensions will not change in the lifetime of a
61                multi-dimensional curve.
62                @param document The COLLADA document that owns the animation curve.
63                @param dimension The number of dimensions for the animation curve. */
64        FCDAnimationMultiCurve(FCDocument* document, uint32 dimension);
65
66        /** Destructor. */
67        virtual ~FCDAnimationMultiCurve();
68
69        /** Merges multiple single-dimensional animation curves into one
70                multi-dimensional animation curve.
71                For each NULL element found within the 'toMerge' list, the corresponding
72                default value is used. If there are not enough default values provided, zero is assumed.
73                The number of dimensions for the output animation curve is taken as the size of the 'toMerge' list.
74                @param toMerge The list of single-dimensional animation curves to merge. This list may
75                        contain NULL elements, as explained above.
76                @param defaultValues The list of default values to use when a NULL element is encountered.
77                        Default values should be provided even for the elements that are not NULL. */
78        static FCDAnimationMultiCurve* MergeCurves(const vector<FCDAnimationCurve*>& toMerge, const FloatList& defaultValues);
79        static FCDAnimationMultiCurve* MergeCurves(const vector<const FCDAnimationCurve*>& toMerge, const FloatList& defaultValues); /**< See above. */
80
81        /** Retrieves the number of dimensions for the curve.
82                @return The number of dimensions for the curve. */
83        inline uint32 GetDimension() const { return dimension; }
84
85        /** Retrieves the list of key inputs for the animation curve.
86                @return The list of key inputs. */
87        inline FloatList& GetKeys() { return keys; }
88        inline const FloatList& GetKeys() const { return keys; } /**< See above. */
89
90        /** Retrieves the lists of key outputs for the animation curve.
91                There is one separate list of key outputs for each dimension of the curve.
92                @return The lists of key outputs. */
93        inline FloatList* GetKeyValues() { return keyValues; }
94        inline const FloatList* GetKeyValues() const { return keyValues; } /**< See above. */
95
96        /** Retrieves the lists of key in-tangent values for the animation curve.
97                These lists have data only if the curve includes segments with the bezier interpolation.
98                There is one separate list of key in-tangent values for each dimension of the curve.
99                @return The lists of in-tangent values. */
100        inline FloatList* GetInTangents() { return inTangents; }
101        inline const FloatList* GetInTangents() const { return inTangents; } /**< See above. */
102
103        /** Retrieves the lists of key out-tangent values for the animation curve.
104                These lists have data only if the curve includes segments with the bezier interpolation.
105                There is one separate list of key out-tangent values for each dimension of the curve.
106                @return The lists of out-tangent values. */
107        inline FloatList* GetOutTangents() { return outTangents; }
108        inline const FloatList* GetOutTangents() const { return outTangents; } /**< See above. */
109
110        /** Retrieves the list of interpolation type for the segments of the animation curve.
111                There is always one interpolation type for each key in the curve. The interpolation type
112                of a segment of the curve is set at the key at which begins the segment.
113                @see FUDaeInterpolation
114                @return The list of interpolation types. */
115        inline UInt32List& GetInterpolations() { return interpolations; }
116        inline const UInt32List& GetInterpolations() const { return interpolations; } /**< See above. */
117
118        /** Evaluates the animation curve.
119                @param input An input value.
120                @param output An array of floating-point values to fill in with the sampled values. */
121        void Evaluate(float input, float* output) const;
122
123        /** Collapses this multi-dimensional curve into a one-dimensional curve.
124                @param collapse The function to use to collapse multiple floating-point
125                        values into one. Set this to NULL to use the default collapsing
126                        function, which averages all the values.
127                @see Average TakeFirst */
128        FCDAnimationCurve* Collapse(FCDCollapsingFunction collapse=NULL) const;
129
130        /** [INTERNAL] Writes out the data sources necessary to import the animation curve
131                to a given XML tree node.
132                @param parentNode The XML tree node in which to create the data sources.
133                @param baseId A COLLADA Id prefix to use when generating the source ids. */
134        void WriteSourceToXML(xmlNode* parentNode, const string& baseId);
135
136        /** [INTERNAL] Writes out the sampler that puts together the data sources
137                and generates a sampling function.
138                @param parentNode The XML tree node in which to create the sampler.
139                @param baseId The COLLADA id prefix used when generating the source ids.
140                        This prefix is also used to generate the sampler COLLADA id.
141                @return The created XML tree node. */
142        xmlNode* WriteSamplerToXML(xmlNode* parentNode, const string& baseId);
143
144        /** [INTERNAL] Writes out the animation channel that attaches the sampling function
145                to the animatable value.
146                @param parentNode The XML tree node in which to create the sampler.
147                @param baseId The COLLADA Id prefix used when generating the source ids
148                        and the sampler id.
149                @param pointer The target pointer prefix for the targeted animated element.
150                @return The created XML tree node. */
151        xmlNode* WriteChannelToXML(xmlNode* parentNode, const string& baseId, const string& pointer);
152
153        /** [INTERNAL] Retrieves the target element suffix for the curve.
154                This will be -1 if the animated element does not belong to an
155                animated element list.
156                @return The target element suffix. */
157        inline int32 GetTargetElement() const { return targetElement; }
158
159        /** [INTERNAL] Sets the target element suffix for the curve.
160                @param e The target element suffix. Set to value to -1
161                        if the animated element does not belong to an animated element list. */
162        inline void SetTargetElement(int32 e) { targetElement = e; }
163};
164
165/**
166        Retrieves the first floating-point value of a list of floating-point values.
167        This is a typical conversion function.
168        @param values The list of floating-point values.
169        @param count The number of values within the given list.
170*/
171inline float TakeFirst(float* values, uint32 count) { return (count > 0) ? *values : 0.0f; }
172
173/**
174        Retrieves the average value of a list of floating-point values.
175        This is a typical conversion function.
176        @param values The list of floating-point values.
177        @param count The number of values within the given list.
178*/
179inline float Average(float* values, uint32 count) { float v = 0.0f; for (uint32 i = 0; i < count; ++i) v += values[i]; v /= float(count); return v; }
180
181#endif // _FCD_ANIMATION_MULTI_CURVE_H_
Note: See TracBrowser for help on using the repository browser.