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