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++
20 #include <osg/ref_ptr>
21 #include <osg/AlphaFunc>
23 #include <osg/Material>
25 #include <osg/NodeCallback>
26 #include <osg/NodeVisitor>
27 #include <osg/StateSet>
28 #include <osg/Texture2D>
31 #include <simgear/props/props.hxx>
32 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/math/interpolater.hxx>
35 #include <simgear/scene/model/persparam.hxx>
36 #include <simgear/scene/util/SGNodeMasks.hxx>
42 // Don't pull in the headers, since we don't need them here.
46 // Has anyone done anything *really* stupid, like making min and max macros?
56 //////////////////////////////////////////////////////////////////////
57 // Helper classes, FIXME: factor out
58 //////////////////////////////////////////////////////////////////////
60 class SGDoubleValue : public SGReferenced {
62 virtual ~SGDoubleValue() {}
63 virtual double getValue() const = 0;
67 //////////////////////////////////////////////////////////////////////
68 // Base class for animation installers
69 //////////////////////////////////////////////////////////////////////
71 class SGAnimation : protected osg::NodeVisitor {
73 SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
74 virtual ~SGAnimation();
76 static bool animate(osg::Node* node, const SGPropertyNode* configNode,
77 SGPropertyNode* modelRoot);
80 void apply(osg::Node* node);
82 virtual void install(osg::Node& node);
83 virtual osg::Group* createAnimationGroup(osg::Group& parent);
85 virtual void apply(osg::Group& group);
87 void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
88 void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
89 void removeTextureMode(osg::Node& node, unsigned unit,
90 osg::StateAttribute::GLMode mode);
91 void removeTextureAttribute(osg::Node& node, unsigned unit,
92 osg::StateAttribute::Type type);
93 void setRenderBinToInherit(osg::Node& node);
94 void cloneDrawables(osg::Node& node);
96 std::string getType() const
97 { return std::string(_configNode->getStringValue("type", "")); }
99 const SGPropertyNode* getConfig() const
100 { return _configNode; }
101 SGPropertyNode* getModelRoot() const
102 { return _modelRoot; }
104 const SGCondition* getCondition() const;
107 void installInGroup(const std::string& name, osg::Group& group,
108 osg::ref_ptr<osg::Group>& animationGroup);
110 class RemoveModeVisitor;
111 class RemoveAttributeVisitor;
112 class RemoveTextureModeVisitor;
113 class RemoveTextureAttributeVisitor;
114 class BinToInheritVisitor;
115 class DrawableCloneVisitor;
119 SGSharedPtr<SGPropertyNode const> _configNode;
120 SGPropertyNode* _modelRoot;
121 std::list<std::string> _objectNames;
122 std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
128 //////////////////////////////////////////////////////////////////////
129 // Null animation installer
130 //////////////////////////////////////////////////////////////////////
132 class SGGroupAnimation : public SGAnimation {
134 SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
135 virtual osg::Group* createAnimationGroup(osg::Group& parent);
139 //////////////////////////////////////////////////////////////////////
140 // Translate animation installer
141 //////////////////////////////////////////////////////////////////////
143 class SGTranslateAnimation : public SGAnimation {
145 SGTranslateAnimation(const SGPropertyNode* configNode,
146 SGPropertyNode* modelRoot);
147 virtual osg::Group* createAnimationGroup(osg::Group& parent);
149 class UpdateCallback;
150 SGSharedPtr<const SGCondition> _condition;
151 SGSharedPtr<const SGDoubleValue> _animationValue;
153 double _initialValue;
157 //////////////////////////////////////////////////////////////////////
158 // Rotate/Spin animation installer
159 //////////////////////////////////////////////////////////////////////
161 class SGRotateAnimation : public SGAnimation {
163 SGRotateAnimation(const SGPropertyNode* configNode,
164 SGPropertyNode* modelRoot);
165 virtual osg::Group* createAnimationGroup(osg::Group& parent);
167 class UpdateCallback;
168 class SpinUpdateCallback;
169 SGSharedPtr<const SGCondition> _condition;
170 SGSharedPtr<const SGDoubleValue> _animationValue;
173 double _initialValue;
178 //////////////////////////////////////////////////////////////////////
179 // Scale animation installer
180 //////////////////////////////////////////////////////////////////////
182 class SGScaleAnimation : public SGAnimation {
184 SGScaleAnimation(const SGPropertyNode* configNode,
185 SGPropertyNode* modelRoot);
186 virtual osg::Group* createAnimationGroup(osg::Group& parent);
188 class UpdateCallback;
189 SGSharedPtr<const SGCondition> _condition;
190 SGSharedPtr<const SGDoubleValue> _animationValue[3];
191 SGVec3d _initialValue;
196 //////////////////////////////////////////////////////////////////////
197 // dist scale animation installer
198 //////////////////////////////////////////////////////////////////////
200 class SGDistScaleAnimation : public SGAnimation {
202 SGDistScaleAnimation(const SGPropertyNode* configNode,
203 SGPropertyNode* modelRoot);
204 virtual osg::Group* createAnimationGroup(osg::Group& parent);
210 //////////////////////////////////////////////////////////////////////
211 // dist scale animation installer
212 //////////////////////////////////////////////////////////////////////
214 class SGFlashAnimation : public SGAnimation {
216 SGFlashAnimation(const SGPropertyNode* configNode,
217 SGPropertyNode* modelRoot);
218 virtual osg::Group* createAnimationGroup(osg::Group& parent);
224 //////////////////////////////////////////////////////////////////////
225 // dist scale animation installer
226 //////////////////////////////////////////////////////////////////////
228 class SGBillboardAnimation : public SGAnimation {
230 SGBillboardAnimation(const SGPropertyNode* configNode,
231 SGPropertyNode* modelRoot);
232 virtual osg::Group* createAnimationGroup(osg::Group& parent);
238 //////////////////////////////////////////////////////////////////////
239 // Range animation installer
240 //////////////////////////////////////////////////////////////////////
242 class SGRangeAnimation : public SGAnimation {
244 SGRangeAnimation(const SGPropertyNode* configNode,
245 SGPropertyNode* modelRoot);
246 virtual osg::Group* createAnimationGroup(osg::Group& parent);
248 class UpdateCallback;
249 SGSharedPtr<const SGCondition> _condition;
250 SGSharedPtr<const SGDoubleValue> _minAnimationValue;
251 SGSharedPtr<const SGDoubleValue> _maxAnimationValue;
252 SGVec2d _initialValue;
256 //////////////////////////////////////////////////////////////////////
257 // Select animation installer
258 //////////////////////////////////////////////////////////////////////
260 class SGSelectAnimation : public SGAnimation {
262 SGSelectAnimation(const SGPropertyNode* configNode,
263 SGPropertyNode* modelRoot);
264 virtual osg::Group* createAnimationGroup(osg::Group& parent);
266 class UpdateCallback;
270 //////////////////////////////////////////////////////////////////////
271 // Alpha test animation installer
272 //////////////////////////////////////////////////////////////////////
274 class SGAlphaTestAnimation : public SGAnimation {
276 SGAlphaTestAnimation(const SGPropertyNode* configNode,
277 SGPropertyNode* modelRoot);
278 virtual void install(osg::Node& node);
282 //////////////////////////////////////////////////////////////////////
283 // Blend animation installer
284 //////////////////////////////////////////////////////////////////////
286 class SGBlendAnimation : public SGAnimation {
288 SGBlendAnimation(const SGPropertyNode* configNode,
289 SGPropertyNode* modelRoot);
290 virtual osg::Group* createAnimationGroup(osg::Group& parent);
291 virtual void install(osg::Node& node);
294 class UpdateCallback;
295 SGSharedPtr<SGDoubleValue> _animationValue;
299 //////////////////////////////////////////////////////////////////////
300 // Timed animation installer
301 //////////////////////////////////////////////////////////////////////
303 class SGTimedAnimation : public SGAnimation {
305 SGTimedAnimation(const SGPropertyNode* configNode,
306 SGPropertyNode* modelRoot);
307 virtual osg::Group* createAnimationGroup(osg::Group& parent);
309 class UpdateCallback;
313 //////////////////////////////////////////////////////////////////////
314 // Shadow animation installer
315 //////////////////////////////////////////////////////////////////////
317 class SGShadowAnimation : public SGAnimation {
319 SGShadowAnimation(const SGPropertyNode* configNode,
320 SGPropertyNode* modelRoot);
321 virtual osg::Group* createAnimationGroup(osg::Group& parent);
323 class UpdateCallback;
327 //////////////////////////////////////////////////////////////////////
328 // TextureTransform animation
329 //////////////////////////////////////////////////////////////////////
331 class SGTexTransformAnimation : public SGAnimation {
333 SGTexTransformAnimation(const SGPropertyNode* configNode,
334 SGPropertyNode* modelRoot);
335 virtual osg::Group* createAnimationGroup(osg::Group& parent);
340 class UpdateCallback;
341 void appendTexTranslate(const SGPropertyNode* config,
342 UpdateCallback* updateCallback);
343 void appendTexRotate(const SGPropertyNode* config,
344 UpdateCallback* updateCallback);
348 //////////////////////////////////////////////////////////////////////
350 //////////////////////////////////////////////////////////////////////
352 class SGShaderAnimation : public SGAnimation {
354 SGShaderAnimation(const SGPropertyNode* configNode,
355 SGPropertyNode* modelRoot);
356 virtual osg::Group* createAnimationGroup(osg::Group& parent);
358 class UpdateCallback;
359 osg::ref_ptr<osg::Texture2D> _effect_texture;
363 //////////////////////////////////////////////////////////////////////
365 //////////////////////////////////////////////////////////////////////
367 class SGPickAnimation : public SGAnimation {
369 SGPickAnimation(const SGPropertyNode* configNode,
370 SGPropertyNode* modelRoot);
371 virtual osg::Group* createAnimationGroup(osg::Group& parent);
376 #endif // _SG_ANIMATION_HXX