2 // animation.hxx - classes to manage model animation.
3 // Written by David Megginson, started 2002.
5 // This file is in the Public Domain, and comes with no warranty.
7 #ifndef _SG_ANIMATION_HXX
8 #define _SG_ANIMATION_HXX 1
11 # error This library requires C++
14 #include <osg/ref_ptr>
17 #include <osg/NodeVisitor>
18 #include <osg/Texture2D>
19 #include <osgDB/ReaderWriter>
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>
26 // Has anyone done anything *really* stupid, like making min and max macros?
35 read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot,
36 const char* unit, double defMin, double defMax);
38 //////////////////////////////////////////////////////////////////////
39 // Base class for animation installers
40 //////////////////////////////////////////////////////////////////////
42 class SGAnimation : protected osg::NodeVisitor {
44 SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
45 virtual ~SGAnimation();
47 static bool animate(osg::Node* node, const SGPropertyNode* configNode,
48 SGPropertyNode* modelRoot,
49 const osgDB::Options* options,
50 const string &path, int i);
53 void apply(osg::Node* node);
55 virtual void install(osg::Node& node);
56 virtual osg::Group* createAnimationGroup(osg::Group& parent);
58 virtual void apply(osg::Group& group);
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);
69 std::string getType() const
70 { return std::string(_configNode->getStringValue("type", "")); }
72 const SGPropertyNode* getConfig() const
73 { return _configNode; }
74 SGPropertyNode* getModelRoot() const
75 { return _modelRoot; }
77 const SGCondition* getCondition() const;
80 void installInGroup(const std::string& name, osg::Group& group,
81 osg::ref_ptr<osg::Group>& animationGroup);
83 class RemoveModeVisitor;
84 class RemoveAttributeVisitor;
85 class RemoveTextureModeVisitor;
86 class RemoveTextureAttributeVisitor;
87 class BinToInheritVisitor;
88 class DrawableCloneVisitor;
92 SGSharedPtr<SGPropertyNode const> _configNode;
93 SGPropertyNode* _modelRoot;
94 std::list<std::string> _objectNames;
95 std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
101 //////////////////////////////////////////////////////////////////////
102 // Null animation installer
103 //////////////////////////////////////////////////////////////////////
105 class SGGroupAnimation : public SGAnimation {
107 SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
108 virtual osg::Group* createAnimationGroup(osg::Group& parent);
112 //////////////////////////////////////////////////////////////////////
113 // Translate animation installer
114 //////////////////////////////////////////////////////////////////////
116 class SGTranslateAnimation : public SGAnimation {
118 SGTranslateAnimation(const SGPropertyNode* configNode,
119 SGPropertyNode* modelRoot);
120 virtual osg::Group* createAnimationGroup(osg::Group& parent);
122 class UpdateCallback;
123 SGSharedPtr<const SGCondition> _condition;
124 SGSharedPtr<const SGExpressiond> _animationValue;
126 double _initialValue;
130 //////////////////////////////////////////////////////////////////////
131 // Rotate/Spin animation installer
132 //////////////////////////////////////////////////////////////////////
134 class SGRotateAnimation : public SGAnimation {
136 SGRotateAnimation(const SGPropertyNode* configNode,
137 SGPropertyNode* modelRoot);
138 virtual osg::Group* createAnimationGroup(osg::Group& parent);
140 class UpdateCallback;
141 class SpinUpdateCallback;
142 SGSharedPtr<const SGCondition> _condition;
143 SGSharedPtr<const SGExpressiond> _animationValue;
146 double _initialValue;
151 //////////////////////////////////////////////////////////////////////
152 // Scale animation installer
153 //////////////////////////////////////////////////////////////////////
155 class SGScaleAnimation : public SGAnimation {
157 SGScaleAnimation(const SGPropertyNode* configNode,
158 SGPropertyNode* modelRoot);
159 virtual osg::Group* createAnimationGroup(osg::Group& parent);
161 class UpdateCallback;
162 SGSharedPtr<const SGCondition> _condition;
163 SGSharedPtr<const SGExpressiond> _animationValue[3];
164 SGVec3d _initialValue;
169 //////////////////////////////////////////////////////////////////////
170 // dist scale animation installer
171 //////////////////////////////////////////////////////////////////////
173 class SGDistScaleAnimation : public SGAnimation {
175 SGDistScaleAnimation(const SGPropertyNode* configNode,
176 SGPropertyNode* modelRoot);
177 virtual osg::Group* createAnimationGroup(osg::Group& parent);
182 //////////////////////////////////////////////////////////////////////
183 // dist scale animation installer
184 //////////////////////////////////////////////////////////////////////
186 class SGFlashAnimation : public SGAnimation {
188 SGFlashAnimation(const SGPropertyNode* configNode,
189 SGPropertyNode* modelRoot);
190 virtual osg::Group* createAnimationGroup(osg::Group& parent);
196 //////////////////////////////////////////////////////////////////////
197 // dist scale animation installer
198 //////////////////////////////////////////////////////////////////////
200 class SGBillboardAnimation : public SGAnimation {
202 SGBillboardAnimation(const SGPropertyNode* configNode,
203 SGPropertyNode* modelRoot);
204 virtual osg::Group* createAnimationGroup(osg::Group& parent);
209 //////////////////////////////////////////////////////////////////////
210 // Range animation installer
211 //////////////////////////////////////////////////////////////////////
213 class SGRangeAnimation : public SGAnimation {
215 SGRangeAnimation(const SGPropertyNode* configNode,
216 SGPropertyNode* modelRoot);
217 virtual osg::Group* createAnimationGroup(osg::Group& parent);
219 class UpdateCallback;
220 SGSharedPtr<const SGCondition> _condition;
221 SGSharedPtr<const SGExpressiond> _minAnimationValue;
222 SGSharedPtr<const SGExpressiond> _maxAnimationValue;
223 SGVec2d _initialValue;
227 //////////////////////////////////////////////////////////////////////
228 // Select animation installer
229 //////////////////////////////////////////////////////////////////////
231 class SGSelectAnimation : public SGAnimation {
233 SGSelectAnimation(const SGPropertyNode* configNode,
234 SGPropertyNode* modelRoot);
235 virtual osg::Group* createAnimationGroup(osg::Group& parent);
239 //////////////////////////////////////////////////////////////////////
240 // Alpha test animation installer
241 //////////////////////////////////////////////////////////////////////
243 class SGAlphaTestAnimation : public SGAnimation {
245 SGAlphaTestAnimation(const SGPropertyNode* configNode,
246 SGPropertyNode* modelRoot);
247 virtual void install(osg::Node& node);
251 //////////////////////////////////////////////////////////////////////
252 // Blend animation installer
253 //////////////////////////////////////////////////////////////////////
255 class SGBlendAnimation : public SGAnimation {
257 SGBlendAnimation(const SGPropertyNode* configNode,
258 SGPropertyNode* modelRoot);
259 virtual osg::Group* createAnimationGroup(osg::Group& parent);
260 virtual void install(osg::Node& node);
263 class UpdateCallback;
264 SGSharedPtr<SGExpressiond> _animationValue;
268 //////////////////////////////////////////////////////////////////////
269 // Timed animation installer
270 //////////////////////////////////////////////////////////////////////
272 class SGTimedAnimation : public SGAnimation {
274 SGTimedAnimation(const SGPropertyNode* configNode,
275 SGPropertyNode* modelRoot);
276 virtual osg::Group* createAnimationGroup(osg::Group& parent);
278 class UpdateCallback;
282 //////////////////////////////////////////////////////////////////////
283 // Shadow animation installer
284 //////////////////////////////////////////////////////////////////////
286 class SGShadowAnimation : public SGAnimation {
288 SGShadowAnimation(const SGPropertyNode* configNode,
289 SGPropertyNode* modelRoot);
290 virtual osg::Group* createAnimationGroup(osg::Group& parent);
292 class UpdateCallback;
296 //////////////////////////////////////////////////////////////////////
297 // TextureTransform animation
298 //////////////////////////////////////////////////////////////////////
300 class SGTexTransformAnimation : public SGAnimation {
302 SGTexTransformAnimation(const SGPropertyNode* configNode,
303 SGPropertyNode* modelRoot);
304 virtual osg::Group* createAnimationGroup(osg::Group& parent);
309 class UpdateCallback;
310 void appendTexTranslate(const SGPropertyNode* config,
311 UpdateCallback* updateCallback);
312 void appendTexRotate(const SGPropertyNode* config,
313 UpdateCallback* updateCallback);
317 //////////////////////////////////////////////////////////////////////
319 //////////////////////////////////////////////////////////////////////
321 class SGShaderAnimation : public SGAnimation {
323 SGShaderAnimation(const SGPropertyNode* configNode,
324 SGPropertyNode* modelRoot,
325 const osgDB::Options* options);
326 virtual osg::Group* createAnimationGroup(osg::Group& parent);
328 class UpdateCallback;
329 osg::ref_ptr<osg::Texture2D> _effect_texture;
333 //////////////////////////////////////////////////////////////////////
335 //////////////////////////////////////////////////////////////////////
337 class SGPickAnimation : public SGAnimation {
339 SGPickAnimation(const SGPropertyNode* configNode,
340 SGPropertyNode* modelRoot);
341 virtual osg::Group* createAnimationGroup(osg::Group& parent);
348 //////////////////////////////////////////////////////////////////////
350 //////////////////////////////////////////////////////////////////////
352 class SGLightAnimation : public SGAnimation {
354 SGLightAnimation(const SGPropertyNode* configNode,
355 SGPropertyNode* modelRoot,
356 const string &path, int i);
357 virtual osg::Group* createAnimationGroup(osg::Group& parent);
358 virtual void install(osg::Node& node);
366 SGVec3d _attenuation;
372 class UpdateCallback;
373 friend class UpdateCallback;
374 SGSharedPtr<SGExpressiond> _animationValue;
377 #endif // _SG_ANIMATION_HXX