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 //////////////////////////////////////////////////////////////////////
36 // Base class for animation installers
37 //////////////////////////////////////////////////////////////////////
39 class SGAnimation : protected osg::NodeVisitor {
41 SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
42 virtual ~SGAnimation();
44 static bool animate(osg::Node* node, const SGPropertyNode* configNode,
45 SGPropertyNode* modelRoot,
46 const osgDB::ReaderWriter::Options* options);
49 void apply(osg::Node* node);
51 virtual void install(osg::Node& node);
52 virtual osg::Group* createAnimationGroup(osg::Group& parent);
54 virtual void apply(osg::Group& group);
56 void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
57 void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
58 void removeTextureMode(osg::Node& node, unsigned unit,
59 osg::StateAttribute::GLMode mode);
60 void removeTextureAttribute(osg::Node& node, unsigned unit,
61 osg::StateAttribute::Type type);
62 void setRenderBinToInherit(osg::Node& node);
63 void cloneDrawables(osg::Node& node);
65 std::string getType() const
66 { return std::string(_configNode->getStringValue("type", "")); }
68 const SGPropertyNode* getConfig() const
69 { return _configNode; }
70 SGPropertyNode* getModelRoot() const
71 { return _modelRoot; }
73 const SGCondition* getCondition() const;
76 void installInGroup(const std::string& name, osg::Group& group,
77 osg::ref_ptr<osg::Group>& animationGroup);
79 class RemoveModeVisitor;
80 class RemoveAttributeVisitor;
81 class RemoveTextureModeVisitor;
82 class RemoveTextureAttributeVisitor;
83 class BinToInheritVisitor;
84 class DrawableCloneVisitor;
88 SGSharedPtr<SGPropertyNode const> _configNode;
89 SGPropertyNode* _modelRoot;
90 std::list<std::string> _objectNames;
91 std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
97 //////////////////////////////////////////////////////////////////////
98 // Null animation installer
99 //////////////////////////////////////////////////////////////////////
101 class SGGroupAnimation : public SGAnimation {
103 SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
104 virtual osg::Group* createAnimationGroup(osg::Group& parent);
108 //////////////////////////////////////////////////////////////////////
109 // Translate animation installer
110 //////////////////////////////////////////////////////////////////////
112 class SGTranslateAnimation : public SGAnimation {
114 SGTranslateAnimation(const SGPropertyNode* configNode,
115 SGPropertyNode* modelRoot);
116 virtual osg::Group* createAnimationGroup(osg::Group& parent);
118 class UpdateCallback;
119 SGSharedPtr<const SGCondition> _condition;
120 SGSharedPtr<const SGExpressiond> _animationValue;
122 double _initialValue;
126 //////////////////////////////////////////////////////////////////////
127 // Rotate/Spin animation installer
128 //////////////////////////////////////////////////////////////////////
130 class SGRotateAnimation : public SGAnimation {
132 SGRotateAnimation(const SGPropertyNode* configNode,
133 SGPropertyNode* modelRoot);
134 virtual osg::Group* createAnimationGroup(osg::Group& parent);
136 class UpdateCallback;
137 class SpinUpdateCallback;
138 SGSharedPtr<const SGCondition> _condition;
139 SGSharedPtr<const SGExpressiond> _animationValue;
142 double _initialValue;
147 //////////////////////////////////////////////////////////////////////
148 // Scale animation installer
149 //////////////////////////////////////////////////////////////////////
151 class SGScaleAnimation : public SGAnimation {
153 SGScaleAnimation(const SGPropertyNode* configNode,
154 SGPropertyNode* modelRoot);
155 virtual osg::Group* createAnimationGroup(osg::Group& parent);
157 class UpdateCallback;
158 SGSharedPtr<const SGCondition> _condition;
159 SGSharedPtr<const SGExpressiond> _animationValue[3];
160 SGVec3d _initialValue;
165 //////////////////////////////////////////////////////////////////////
166 // dist scale animation installer
167 //////////////////////////////////////////////////////////////////////
169 class SGDistScaleAnimation : public SGAnimation {
171 SGDistScaleAnimation(const SGPropertyNode* configNode,
172 SGPropertyNode* modelRoot);
173 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);
207 //////////////////////////////////////////////////////////////////////
208 // Range animation installer
209 //////////////////////////////////////////////////////////////////////
211 class SGRangeAnimation : public SGAnimation {
213 SGRangeAnimation(const SGPropertyNode* configNode,
214 SGPropertyNode* modelRoot);
215 virtual osg::Group* createAnimationGroup(osg::Group& parent);
217 class UpdateCallback;
218 SGSharedPtr<const SGCondition> _condition;
219 SGSharedPtr<const SGExpressiond> _minAnimationValue;
220 SGSharedPtr<const SGExpressiond> _maxAnimationValue;
221 SGVec2d _initialValue;
225 //////////////////////////////////////////////////////////////////////
226 // Select animation installer
227 //////////////////////////////////////////////////////////////////////
229 class SGSelectAnimation : public SGAnimation {
231 SGSelectAnimation(const SGPropertyNode* configNode,
232 SGPropertyNode* modelRoot);
233 virtual osg::Group* createAnimationGroup(osg::Group& parent);
235 class UpdateCallback;
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::ReaderWriter::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);
346 #endif // _SG_ANIMATION_HXX