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::ReaderWriter::Options* options);
52 void apply(osg::Node* node);
54 virtual void install(osg::Node& node);
55 virtual osg::Group* createAnimationGroup(osg::Group& parent);
57 virtual void apply(osg::Group& group);
59 void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
60 void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
61 void removeTextureMode(osg::Node& node, unsigned unit,
62 osg::StateAttribute::GLMode mode);
63 void removeTextureAttribute(osg::Node& node, unsigned unit,
64 osg::StateAttribute::Type type);
65 void setRenderBinToInherit(osg::Node& node);
66 void cloneDrawables(osg::Node& node);
68 std::string getType() const
69 { return std::string(_configNode->getStringValue("type", "")); }
71 const SGPropertyNode* getConfig() const
72 { return _configNode; }
73 SGPropertyNode* getModelRoot() const
74 { return _modelRoot; }
76 const SGCondition* getCondition() const;
79 void installInGroup(const std::string& name, osg::Group& group,
80 osg::ref_ptr<osg::Group>& animationGroup);
82 class RemoveModeVisitor;
83 class RemoveAttributeVisitor;
84 class RemoveTextureModeVisitor;
85 class RemoveTextureAttributeVisitor;
86 class BinToInheritVisitor;
87 class DrawableCloneVisitor;
91 SGSharedPtr<SGPropertyNode const> _configNode;
92 SGPropertyNode* _modelRoot;
93 std::list<std::string> _objectNames;
94 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 class UpdateCallback;
140 class SpinUpdateCallback;
141 SGSharedPtr<const SGCondition> _condition;
142 SGSharedPtr<const SGExpressiond> _animationValue;
145 double _initialValue;
150 //////////////////////////////////////////////////////////////////////
151 // Scale animation installer
152 //////////////////////////////////////////////////////////////////////
154 class SGScaleAnimation : public SGAnimation {
156 SGScaleAnimation(const SGPropertyNode* configNode,
157 SGPropertyNode* modelRoot);
158 virtual osg::Group* createAnimationGroup(osg::Group& parent);
160 class UpdateCallback;
161 SGSharedPtr<const SGCondition> _condition;
162 SGSharedPtr<const SGExpressiond> _animationValue[3];
163 SGVec3d _initialValue;
168 //////////////////////////////////////////////////////////////////////
169 // dist scale animation installer
170 //////////////////////////////////////////////////////////////////////
172 class SGDistScaleAnimation : public SGAnimation {
174 SGDistScaleAnimation(const SGPropertyNode* configNode,
175 SGPropertyNode* modelRoot);
176 virtual osg::Group* createAnimationGroup(osg::Group& parent);
181 //////////////////////////////////////////////////////////////////////
182 // dist scale animation installer
183 //////////////////////////////////////////////////////////////////////
185 class SGFlashAnimation : public SGAnimation {
187 SGFlashAnimation(const SGPropertyNode* configNode,
188 SGPropertyNode* modelRoot);
189 virtual osg::Group* createAnimationGroup(osg::Group& parent);
195 //////////////////////////////////////////////////////////////////////
196 // dist scale animation installer
197 //////////////////////////////////////////////////////////////////////
199 class SGBillboardAnimation : public SGAnimation {
201 SGBillboardAnimation(const SGPropertyNode* configNode,
202 SGPropertyNode* modelRoot);
203 virtual osg::Group* createAnimationGroup(osg::Group& parent);
208 //////////////////////////////////////////////////////////////////////
209 // Range animation installer
210 //////////////////////////////////////////////////////////////////////
212 class SGRangeAnimation : public SGAnimation {
214 SGRangeAnimation(const SGPropertyNode* configNode,
215 SGPropertyNode* modelRoot);
216 virtual osg::Group* createAnimationGroup(osg::Group& parent);
218 class UpdateCallback;
219 SGSharedPtr<const SGCondition> _condition;
220 SGSharedPtr<const SGExpressiond> _minAnimationValue;
221 SGSharedPtr<const SGExpressiond> _maxAnimationValue;
222 SGVec2d _initialValue;
226 //////////////////////////////////////////////////////////////////////
227 // Select animation installer
228 //////////////////////////////////////////////////////////////////////
230 class SGSelectAnimation : public SGAnimation {
232 SGSelectAnimation(const SGPropertyNode* configNode,
233 SGPropertyNode* modelRoot);
234 virtual osg::Group* createAnimationGroup(osg::Group& parent);
236 class UpdateCallback;
240 //////////////////////////////////////////////////////////////////////
241 // Alpha test animation installer
242 //////////////////////////////////////////////////////////////////////
244 class SGAlphaTestAnimation : public SGAnimation {
246 SGAlphaTestAnimation(const SGPropertyNode* configNode,
247 SGPropertyNode* modelRoot);
248 virtual void install(osg::Node& node);
252 //////////////////////////////////////////////////////////////////////
253 // Blend animation installer
254 //////////////////////////////////////////////////////////////////////
256 class SGBlendAnimation : public SGAnimation {
258 SGBlendAnimation(const SGPropertyNode* configNode,
259 SGPropertyNode* modelRoot);
260 virtual osg::Group* createAnimationGroup(osg::Group& parent);
261 virtual void install(osg::Node& node);
264 class UpdateCallback;
265 SGSharedPtr<SGExpressiond> _animationValue;
269 //////////////////////////////////////////////////////////////////////
270 // Timed animation installer
271 //////////////////////////////////////////////////////////////////////
273 class SGTimedAnimation : public SGAnimation {
275 SGTimedAnimation(const SGPropertyNode* configNode,
276 SGPropertyNode* modelRoot);
277 virtual osg::Group* createAnimationGroup(osg::Group& parent);
279 class UpdateCallback;
283 //////////////////////////////////////////////////////////////////////
284 // Shadow animation installer
285 //////////////////////////////////////////////////////////////////////
287 class SGShadowAnimation : public SGAnimation {
289 SGShadowAnimation(const SGPropertyNode* configNode,
290 SGPropertyNode* modelRoot);
291 virtual osg::Group* createAnimationGroup(osg::Group& parent);
293 class UpdateCallback;
297 //////////////////////////////////////////////////////////////////////
298 // TextureTransform animation
299 //////////////////////////////////////////////////////////////////////
301 class SGTexTransformAnimation : public SGAnimation {
303 SGTexTransformAnimation(const SGPropertyNode* configNode,
304 SGPropertyNode* modelRoot);
305 virtual osg::Group* createAnimationGroup(osg::Group& parent);
310 class UpdateCallback;
311 void appendTexTranslate(const SGPropertyNode* config,
312 UpdateCallback* updateCallback);
313 void appendTexRotate(const SGPropertyNode* config,
314 UpdateCallback* updateCallback);
318 //////////////////////////////////////////////////////////////////////
320 //////////////////////////////////////////////////////////////////////
322 class SGShaderAnimation : public SGAnimation {
324 SGShaderAnimation(const SGPropertyNode* configNode,
325 SGPropertyNode* modelRoot,
326 const osgDB::ReaderWriter::Options* options);
327 virtual osg::Group* createAnimationGroup(osg::Group& parent);
329 class UpdateCallback;
330 osg::ref_ptr<osg::Texture2D> _effect_texture;
334 //////////////////////////////////////////////////////////////////////
336 //////////////////////////////////////////////////////////////////////
338 class SGPickAnimation : public SGAnimation {
340 SGPickAnimation(const SGPropertyNode* configNode,
341 SGPropertyNode* modelRoot);
342 virtual osg::Group* createAnimationGroup(osg::Group& parent);
348 #endif // _SG_ANIMATION_HXX