1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASAXFWL_LIBRARYANIMATIONSLOADER_H__
12 #define __COLLADASAXFWL_LIBRARYANIMATIONSLOADER_H__
13 
14 #include "COLLADASaxFWLPrerequisites.h"
15 #include "COLLADASaxFWLSourceArrayLoader.h"
16 
17 namespace COLLADAFW
18 {
19     class AnimationCurve;
20     class AnimationList;
21 }
22 
23 
24 namespace COLLADASaxFWL
25 {
26 
27     /** Loads all the animations the the library animations */
28 	class LibraryAnimationsLoader : public SourceArrayLoader
29 	{
30 	private:
31 
32 		/** Maps strings to unique ids.*/
33 		typedef std::map< String /*samplerId*/,AnimationInfo > StringAnimationInfoMap;
34 
35 	private:
36 
37         /**
38         * The original object id, if it in the original file format exist.
39         */
40         String mOriginalId;
41 
42         /** Pretty-print name for this animation. Optional. */
43         String mName;
44 
45         /** The animation curve currently being filled. Is not null only inside a sampler element.*/
46 		COLLADAFW::AnimationCurve* mCurrentAnimationCurve;
47 
48 		/** Maps the id of sampler to the unique id of the frame work animation created for this sampler.*/
49 		StringAnimationInfoMap mSamplerIdAnimationInfoMap;
50 
51 		/** True, if the array currently parsed is an IDREF_array, supposed to contain the interpolation data.*/
52 		bool mCurrentlyParsingInterpolationArray;
53 
54 		/** The animation info of the currently being parsed sampler.*/
55 		AnimationInfo* mCurrentAnimationInfo;
56 
57 		/** True, if at least one interpolation type of the current animation curve is bezier or hermite,
58 		false otherwise. Use this to decide if we can clear the tangents. Is set to true when starting
59 		to parse a sampler. This allows to not store tangents, if set to false.*/
60 		bool mCurrentAnimationCurveRequiresTangents;
61 
62 		/** Used to control if validate function should report errors
63 		or do its job silently */
64 		bool mVerboseValidate;
65 
66         /* internal count of animation processed, used to build up a default id */
67         size_t mProcessedCount;
68 	public:
69 
70         /** Constructor. */
71 		LibraryAnimationsLoader( IFilePartLoader* callingFilePartLoader );
72 
73         /** Destructor. */
74 		virtual ~LibraryAnimationsLoader();
75 
76         /** Returns the unique id of the current parsed object. */
77         virtual const COLLADAFW::UniqueId& getUniqueId();
78 
79 		/** Searches for the animation info of animation created for the COLLADA sampler with id @a samplerId.
80 		If it could not be found, an invalid Unique id is returned.*/
81 		AnimationInfo* getAnimationInfoBySamplerId( const String& samplerId);
82 
83         /** Determines the interpolation with @a name.*/
84         static COLLADAFW::AnimationCurve::InterpolationType getInterpolationTypeByString( const ParserString& string);
85 
86 		/** Cleans up everything and gives control to calling file part loader.*/
87 		bool end__library_animations();
88 
89 		bool begin__source( const source__AttributeData& attributes );
90 
91 		bool end__source();
92 
93 		/** .*/
94 		bool begin__animation( const animation__AttributeData& attributeData );
95 
96 		/** .*/
97 		bool end__animation();
98 
99 		/** Create new animation.*/
100 		bool begin__sampler( const sampler__AttributeData& attributeData );
101 
102 		/** .*/
103 		bool end__sampler();
104 
105 		virtual bool begin__channel( const channel__AttributeData& attributeData );
106 
107 		virtual bool end__channel();
108 
109 		/** Evaluate the semantic and assign the corresponding sources to the current animation curve.*/
110 		bool begin__input____InputLocal( const input____InputLocal__AttributeData& attributeData );
111 
112 		/** We don't need to do anything here.*/
end__input____InputLocal()113 		bool end__input____InputLocal() {return true;}
114 
115 		virtual bool begin__Name_array( const Name_array__AttributeData& attributeData );
116 		virtual bool end__Name_array();
117 		virtual bool data__Name_array( const ParserString* data, size_t length );
118 
119 	private:
120 
121         /**
122         * The original object id, if it in the original file format exist.
123         */
getOriginalId()124         const COLLADAFW::String& getOriginalId () const { return mOriginalId; }
125 
126         /**
127         * The original object id, if it in the original file format exist.
128         */
setOriginalId(const COLLADAFW::String & val)129         void setOriginalId ( const COLLADAFW::String& val ) { mOriginalId = val; }
130 
131         /** Pretty-print name for this animation. Optional. */
getName()132         const COLLADAFW::String& getName () const { return mName; }
133 
134         /** Pretty-print name for this animation. Optional. */
setName(const COLLADAFW::String & val)135         void setName ( const COLLADAFW::String& val ) { mName = val; }
136 
137         /** Disable default copy ctor. */
138 		LibraryAnimationsLoader( const LibraryAnimationsLoader& pre );
139 
140         /** Disable default assignment operator. */
141 		const LibraryAnimationsLoader& operator= ( const LibraryAnimationsLoader& pre );
142 	};
143 
144 } // namespace COLLADASAXFWL
145 
146 #endif // __COLLADASAXFWL_LIBRARYANIMATIONSLOADER_H__
147