]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation.hxx
Don't modify OSG Registry with file path
[simgear.git] / simgear / scene / model / animation.hxx
1
2 // animation.hxx - classes to manage model animation.
3 // Written by David Megginson, started 2002.
4 //
5 // This file is in the Public Domain, and comes with no warranty.
6
7 #ifndef _SG_ANIMATION_HXX
8 #define _SG_ANIMATION_HXX 1
9
10 #ifndef __cplusplus
11 # error This library requires C++
12 #endif
13
14 #include <vector>
15 #include <map>
16
17 #include <osg/Vec3>
18 #include <osg/Vec4>
19
20 #include <osg/ref_ptr>
21 #include <osg/AlphaFunc>
22 #include <osg/Group>
23 #include <osg/Material>
24 #include <osg/Node>
25 #include <osg/NodeCallback>
26 #include <osg/NodeVisitor>
27 #include <osg/StateSet>
28 #include <osg/Texture2D>
29 #include <osg/TexMat>
30
31 #include <osgDB/ReaderWriter>
32 #include <simgear/props/props.hxx>
33 #include <simgear/misc/sg_path.hxx>
34
35 #include <simgear/math/interpolater.hxx>
36 #include <simgear/scene/model/persparam.hxx>
37 #include <simgear/scene/util/SGNodeMasks.hxx>
38
39
40 SG_USING_STD(vector);
41 SG_USING_STD(map);
42
43 // Don't pull in the headers, since we don't need them here.
44 class SGInterpTable;
45 class SGCondition;
46
47 // Has anyone done anything *really* stupid, like making min and max macros?
48 #ifdef min
49 #undef min
50 #endif
51 #ifdef max
52 #undef max
53 #endif
54
55
56 \f
57 //////////////////////////////////////////////////////////////////////
58 // Helper classes, FIXME: factor out
59 //////////////////////////////////////////////////////////////////////
60
61 class SGDoubleValue : public SGReferenced {
62 public:
63   virtual ~SGDoubleValue() {}
64   virtual double getValue() const = 0;
65 };
66
67 \f
68 //////////////////////////////////////////////////////////////////////
69 // Base class for animation installers
70 //////////////////////////////////////////////////////////////////////
71
72 class SGAnimation : protected osg::NodeVisitor {
73 public:
74   SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
75   virtual ~SGAnimation();
76
77   static bool animate(osg::Node* node, const SGPropertyNode* configNode,
78                       SGPropertyNode* modelRoot,
79                       const osgDB::ReaderWriter::Options* options);
80
81 protected:
82   void apply(osg::Node* node);
83
84   virtual void install(osg::Node& node);
85   virtual osg::Group* createAnimationGroup(osg::Group& parent);
86
87   virtual void apply(osg::Group& group);
88
89   void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
90   void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
91   void removeTextureMode(osg::Node& node, unsigned unit,
92                          osg::StateAttribute::GLMode mode);
93   void removeTextureAttribute(osg::Node& node, unsigned unit,
94                               osg::StateAttribute::Type type);
95   void setRenderBinToInherit(osg::Node& node);
96   void cloneDrawables(osg::Node& node);
97
98   std::string getType() const
99   { return std::string(_configNode->getStringValue("type", "")); }
100
101   const SGPropertyNode* getConfig() const
102   { return _configNode; }
103   SGPropertyNode* getModelRoot() const
104   { return _modelRoot; }
105
106   const SGCondition* getCondition() const;
107
108 private:
109   void installInGroup(const std::string& name, osg::Group& group,
110                       osg::ref_ptr<osg::Group>& animationGroup);
111
112   class RemoveModeVisitor;
113   class RemoveAttributeVisitor;
114   class RemoveTextureModeVisitor;
115   class RemoveTextureAttributeVisitor;
116   class BinToInheritVisitor;
117   class DrawableCloneVisitor;
118
119   bool _found;
120   std::string _name;
121   SGSharedPtr<SGPropertyNode const> _configNode;
122   SGPropertyNode* _modelRoot;
123   std::list<std::string> _objectNames;
124   std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
125   bool _enableHOT;
126   bool _disableShadow;
127 };
128
129 \f
130 //////////////////////////////////////////////////////////////////////
131 // Null animation installer
132 //////////////////////////////////////////////////////////////////////
133
134 class SGGroupAnimation : public SGAnimation {
135 public:
136   SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
137   virtual osg::Group* createAnimationGroup(osg::Group& parent);
138 };
139
140 \f
141 //////////////////////////////////////////////////////////////////////
142 // Translate animation installer
143 //////////////////////////////////////////////////////////////////////
144
145 class SGTranslateAnimation : public SGAnimation {
146 public:
147   SGTranslateAnimation(const SGPropertyNode* configNode,
148                        SGPropertyNode* modelRoot);
149   virtual osg::Group* createAnimationGroup(osg::Group& parent);
150 private:
151   class UpdateCallback;
152   SGSharedPtr<const SGCondition> _condition;
153   SGSharedPtr<const SGDoubleValue> _animationValue;
154   SGVec3d _axis;
155   double _initialValue;
156 };
157
158 \f
159 //////////////////////////////////////////////////////////////////////
160 // Rotate/Spin animation installer
161 //////////////////////////////////////////////////////////////////////
162
163 class SGRotateAnimation : public SGAnimation {
164 public:
165   SGRotateAnimation(const SGPropertyNode* configNode,
166                     SGPropertyNode* modelRoot);
167   virtual osg::Group* createAnimationGroup(osg::Group& parent);
168 private:
169   class UpdateCallback;
170   class SpinUpdateCallback;
171   SGSharedPtr<const SGCondition> _condition;
172   SGSharedPtr<const SGDoubleValue> _animationValue;
173   SGVec3d _axis;
174   SGVec3d _center;
175   double _initialValue;
176   bool _isSpin;
177 };
178
179 \f
180 //////////////////////////////////////////////////////////////////////
181 // Scale animation installer
182 //////////////////////////////////////////////////////////////////////
183
184 class SGScaleAnimation : public SGAnimation {
185 public:
186   SGScaleAnimation(const SGPropertyNode* configNode,
187                    SGPropertyNode* modelRoot);
188   virtual osg::Group* createAnimationGroup(osg::Group& parent);
189 private:
190   class UpdateCallback;
191   SGSharedPtr<const SGCondition> _condition;
192   SGSharedPtr<const SGDoubleValue> _animationValue[3];
193   SGVec3d _initialValue;
194   SGVec3d _center;
195 };
196
197 \f
198 //////////////////////////////////////////////////////////////////////
199 // dist scale animation installer
200 //////////////////////////////////////////////////////////////////////
201
202 class SGDistScaleAnimation : public SGAnimation {
203 public:
204   SGDistScaleAnimation(const SGPropertyNode* configNode,
205                        SGPropertyNode* modelRoot);
206   virtual osg::Group* createAnimationGroup(osg::Group& parent);
207 private:
208   class Transform;
209 };
210
211 \f
212 //////////////////////////////////////////////////////////////////////
213 // dist scale animation installer
214 //////////////////////////////////////////////////////////////////////
215
216 class SGFlashAnimation : public SGAnimation {
217 public:
218   SGFlashAnimation(const SGPropertyNode* configNode,
219                    SGPropertyNode* modelRoot);
220   virtual osg::Group* createAnimationGroup(osg::Group& parent);
221 private:
222   class Transform;
223 };
224
225 \f
226 //////////////////////////////////////////////////////////////////////
227 // dist scale animation installer
228 //////////////////////////////////////////////////////////////////////
229
230 class SGBillboardAnimation : public SGAnimation {
231 public:
232   SGBillboardAnimation(const SGPropertyNode* configNode,
233                        SGPropertyNode* modelRoot);
234   virtual osg::Group* createAnimationGroup(osg::Group& parent);
235 private:
236   class Transform;
237 };
238
239 \f
240 //////////////////////////////////////////////////////////////////////
241 // Range animation installer
242 //////////////////////////////////////////////////////////////////////
243
244 class SGRangeAnimation : public SGAnimation {
245 public:
246   SGRangeAnimation(const SGPropertyNode* configNode,
247                    SGPropertyNode* modelRoot);
248   virtual osg::Group* createAnimationGroup(osg::Group& parent);
249 private:
250   class UpdateCallback;
251   SGSharedPtr<const SGCondition> _condition;
252   SGSharedPtr<const SGDoubleValue> _minAnimationValue;
253   SGSharedPtr<const SGDoubleValue> _maxAnimationValue;
254   SGVec2d _initialValue;
255 };
256
257 \f
258 //////////////////////////////////////////////////////////////////////
259 // Select animation installer
260 //////////////////////////////////////////////////////////////////////
261
262 class SGSelectAnimation : public SGAnimation {
263 public:
264   SGSelectAnimation(const SGPropertyNode* configNode,
265                     SGPropertyNode* modelRoot);
266   virtual osg::Group* createAnimationGroup(osg::Group& parent);
267 private:
268   class UpdateCallback;
269 };
270
271 \f
272 //////////////////////////////////////////////////////////////////////
273 // Alpha test animation installer
274 //////////////////////////////////////////////////////////////////////
275
276 class SGAlphaTestAnimation : public SGAnimation {
277 public:
278   SGAlphaTestAnimation(const SGPropertyNode* configNode,
279                        SGPropertyNode* modelRoot);
280   virtual void install(osg::Node& node);
281 };
282
283 \f
284 //////////////////////////////////////////////////////////////////////
285 // Blend animation installer
286 //////////////////////////////////////////////////////////////////////
287
288 class SGBlendAnimation : public SGAnimation {
289 public:
290   SGBlendAnimation(const SGPropertyNode* configNode,
291                    SGPropertyNode* modelRoot);
292   virtual osg::Group* createAnimationGroup(osg::Group& parent);
293   virtual void install(osg::Node& node);
294 private:
295   class BlendVisitor;
296   class UpdateCallback;
297   SGSharedPtr<SGDoubleValue> _animationValue;
298 };
299
300 \f
301 //////////////////////////////////////////////////////////////////////
302 // Timed animation installer
303 //////////////////////////////////////////////////////////////////////
304
305 class SGTimedAnimation : public SGAnimation {
306 public:
307   SGTimedAnimation(const SGPropertyNode* configNode,
308                    SGPropertyNode* modelRoot);
309   virtual osg::Group* createAnimationGroup(osg::Group& parent);
310 private:
311   class UpdateCallback;
312 };
313
314 \f
315 //////////////////////////////////////////////////////////////////////
316 // Shadow animation installer
317 //////////////////////////////////////////////////////////////////////
318
319 class SGShadowAnimation : public SGAnimation {
320 public:
321   SGShadowAnimation(const SGPropertyNode* configNode,
322                     SGPropertyNode* modelRoot);
323   virtual osg::Group* createAnimationGroup(osg::Group& parent);
324 private:
325   class UpdateCallback;
326 };
327
328 \f
329 //////////////////////////////////////////////////////////////////////
330 // TextureTransform animation
331 //////////////////////////////////////////////////////////////////////
332
333 class SGTexTransformAnimation : public SGAnimation {
334 public:
335   SGTexTransformAnimation(const SGPropertyNode* configNode,
336                           SGPropertyNode* modelRoot);
337   virtual osg::Group* createAnimationGroup(osg::Group& parent);
338 private:
339   class Transform;
340   class Translation;
341   class Rotation;
342   class UpdateCallback;
343   void appendTexTranslate(const SGPropertyNode* config,
344                           UpdateCallback* updateCallback);
345   void appendTexRotate(const SGPropertyNode* config,
346                        UpdateCallback* updateCallback);
347 };
348
349 \f
350 //////////////////////////////////////////////////////////////////////
351 // Shader animation
352 //////////////////////////////////////////////////////////////////////
353
354 class SGShaderAnimation : public SGAnimation {
355 public:
356   SGShaderAnimation(const SGPropertyNode* configNode,
357                     SGPropertyNode* modelRoot,
358                     const osgDB::ReaderWriter::Options* options);
359   virtual osg::Group* createAnimationGroup(osg::Group& parent);
360 private:
361   class UpdateCallback;
362   osg::ref_ptr<osg::Texture2D> _effect_texture;
363 };
364
365 \f
366 //////////////////////////////////////////////////////////////////////
367 // Pick animation
368 //////////////////////////////////////////////////////////////////////
369
370 class SGPickAnimation : public SGAnimation {
371 public:
372   SGPickAnimation(const SGPropertyNode* configNode,
373                   SGPropertyNode* modelRoot);
374   virtual osg::Group* createAnimationGroup(osg::Group& parent);
375 private:
376   class PickCallback;
377 };
378
379 #endif // _SG_ANIMATION_HXX