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;
100 //////////////////////////////////////////////////////////////////////
101 // Null animation installer
102 //////////////////////////////////////////////////////////////////////
104 class SGGroupAnimation : public SGAnimation {
106 SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
107 virtual osg::Group* createAnimationGroup(osg::Group& parent);
111 //////////////////////////////////////////////////////////////////////
112 // Translate animation installer
113 //////////////////////////////////////////////////////////////////////
115 class SGTranslateAnimation : public SGAnimation {
117 SGTranslateAnimation(const SGPropertyNode* configNode,
118 SGPropertyNode* modelRoot);
119 virtual osg::Group* createAnimationGroup(osg::Group& parent);
121 class UpdateCallback;
122 SGSharedPtr<const SGCondition> _condition;
123 SGSharedPtr<const SGExpressiond> _animationValue;
125 double _initialValue;
129 //////////////////////////////////////////////////////////////////////
130 // Rotate/Spin animation installer
131 //////////////////////////////////////////////////////////////////////
133 class SGRotateAnimation : public SGAnimation {
135 SGRotateAnimation(const SGPropertyNode* configNode,
136 SGPropertyNode* modelRoot);
137 virtual osg::Group* createAnimationGroup(osg::Group& parent);
139 SGSharedPtr<const SGCondition> _condition;
140 SGSharedPtr<const SGExpressiond> _animationValue;
143 double _initialValue;
148 //////////////////////////////////////////////////////////////////////
149 // Scale animation installer
150 //////////////////////////////////////////////////////////////////////
152 class SGScaleAnimation : public SGAnimation {
154 SGScaleAnimation(const SGPropertyNode* configNode,
155 SGPropertyNode* modelRoot);
156 virtual osg::Group* createAnimationGroup(osg::Group& parent);
158 class UpdateCallback;
159 SGSharedPtr<const SGCondition> _condition;
160 SGSharedPtr<const SGExpressiond> _animationValue[3];
161 SGVec3d _initialValue;
166 //////////////////////////////////////////////////////////////////////
167 // dist scale animation installer
168 //////////////////////////////////////////////////////////////////////
170 class SGDistScaleAnimation : public SGAnimation {
172 SGDistScaleAnimation(const SGPropertyNode* configNode,
173 SGPropertyNode* modelRoot);
174 virtual osg::Group* createAnimationGroup(osg::Group& parent);
179 //////////////////////////////////////////////////////////////////////
180 // dist scale animation installer
181 //////////////////////////////////////////////////////////////////////
183 class SGFlashAnimation : public SGAnimation {
185 SGFlashAnimation(const SGPropertyNode* configNode,
186 SGPropertyNode* modelRoot);
187 virtual osg::Group* createAnimationGroup(osg::Group& parent);
193 //////////////////////////////////////////////////////////////////////
194 // dist scale animation installer
195 //////////////////////////////////////////////////////////////////////
197 class SGBillboardAnimation : public SGAnimation {
199 SGBillboardAnimation(const SGPropertyNode* configNode,
200 SGPropertyNode* modelRoot);
201 virtual osg::Group* createAnimationGroup(osg::Group& parent);
206 //////////////////////////////////////////////////////////////////////
207 // Range animation installer
208 //////////////////////////////////////////////////////////////////////
210 class SGRangeAnimation : public SGAnimation {
212 SGRangeAnimation(const SGPropertyNode* configNode,
213 SGPropertyNode* modelRoot);
214 virtual osg::Group* createAnimationGroup(osg::Group& parent);
216 class UpdateCallback;
217 SGSharedPtr<const SGCondition> _condition;
218 SGSharedPtr<const SGExpressiond> _minAnimationValue;
219 SGSharedPtr<const SGExpressiond> _maxAnimationValue;
220 SGVec2d _initialValue;
224 //////////////////////////////////////////////////////////////////////
225 // Select animation installer
226 //////////////////////////////////////////////////////////////////////
228 class SGSelectAnimation : public SGAnimation {
230 SGSelectAnimation(const SGPropertyNode* configNode,
231 SGPropertyNode* modelRoot);
232 virtual osg::Group* createAnimationGroup(osg::Group& parent);
236 //////////////////////////////////////////////////////////////////////
237 // Alpha test animation installer
238 //////////////////////////////////////////////////////////////////////
240 class SGAlphaTestAnimation : public SGAnimation {
242 SGAlphaTestAnimation(const SGPropertyNode* configNode,
243 SGPropertyNode* modelRoot);
244 virtual void install(osg::Node& node);
248 //////////////////////////////////////////////////////////////////////
249 // Blend animation installer
250 //////////////////////////////////////////////////////////////////////
252 class SGBlendAnimation : public SGAnimation {
254 SGBlendAnimation(const SGPropertyNode* configNode,
255 SGPropertyNode* modelRoot);
256 virtual osg::Group* createAnimationGroup(osg::Group& parent);
257 virtual void install(osg::Node& node);
260 class UpdateCallback;
261 SGSharedPtr<SGExpressiond> _animationValue;
265 //////////////////////////////////////////////////////////////////////
266 // Timed animation installer
267 //////////////////////////////////////////////////////////////////////
269 class SGTimedAnimation : public SGAnimation {
271 SGTimedAnimation(const SGPropertyNode* configNode,
272 SGPropertyNode* modelRoot);
273 virtual osg::Group* createAnimationGroup(osg::Group& parent);
275 class UpdateCallback;
279 //////////////////////////////////////////////////////////////////////
280 // Shadow animation installer
281 //////////////////////////////////////////////////////////////////////
283 class SGShadowAnimation : public SGAnimation {
285 SGShadowAnimation(const SGPropertyNode* configNode,
286 SGPropertyNode* modelRoot);
287 virtual osg::Group* createAnimationGroup(osg::Group& parent);
289 class UpdateCallback;
293 //////////////////////////////////////////////////////////////////////
294 // TextureTransform animation
295 //////////////////////////////////////////////////////////////////////
297 class SGTexTransformAnimation : public SGAnimation {
299 SGTexTransformAnimation(const SGPropertyNode* configNode,
300 SGPropertyNode* modelRoot);
301 virtual osg::Group* createAnimationGroup(osg::Group& parent);
306 class UpdateCallback;
307 void appendTexTranslate(const SGPropertyNode* config,
308 UpdateCallback* updateCallback);
309 void appendTexRotate(const SGPropertyNode* config,
310 UpdateCallback* updateCallback);
314 //////////////////////////////////////////////////////////////////////
316 //////////////////////////////////////////////////////////////////////
318 class SGShaderAnimation : public SGAnimation {
320 SGShaderAnimation(const SGPropertyNode* configNode,
321 SGPropertyNode* modelRoot,
322 const osgDB::Options* options);
323 virtual osg::Group* createAnimationGroup(osg::Group& parent);
325 class UpdateCallback;
326 osg::ref_ptr<osg::Texture2D> _effect_texture;
330 //////////////////////////////////////////////////////////////////////
332 //////////////////////////////////////////////////////////////////////
334 class SGPickAnimation : public SGAnimation {
336 SGPickAnimation(const SGPropertyNode* configNode,
337 SGPropertyNode* modelRoot);
338 virtual osg::Group* createAnimationGroup(osg::Group& parent);
345 //////////////////////////////////////////////////////////////////////
347 //////////////////////////////////////////////////////////////////////
349 class SGLightAnimation : public SGAnimation {
351 SGLightAnimation(const SGPropertyNode* configNode,
352 SGPropertyNode* modelRoot,
353 const osgDB::Options* options,
354 const string &path, int i);
355 virtual osg::Group* createAnimationGroup(osg::Group& parent);
356 virtual void install(osg::Node& node);
364 SGVec3d _attenuation;
370 class UpdateCallback;
371 friend class UpdateCallback;
372 SGSharedPtr<SGExpressiond> _animationValue;
373 osg::ref_ptr<const osgDB::Options> _options;
376 #endif // _SG_ANIMATION_HXX