00001
00002
00003
00004
00005
00006
00007 #ifndef _SG_ANIMATION_HXX
00008 #define _SG_ANIMATION_HXX 1
00009
00010 #ifndef __cplusplus
00011 # error This library requires C++
00012 #endif
00013
00014 #include <osg/ref_ptr>
00015 #include <osg/Group>
00016 #include <osg/Node>
00017 #include <osg/NodeVisitor>
00018 #include <osg/Texture2D>
00019 #include <osgDB/ReaderWriter>
00020
00021 #include <simgear/scene/util/SGNodeMasks.hxx>
00022 #include <simgear/props/props.hxx>
00023 #include <simgear/props/condition.hxx>
00024 #include <simgear/structure/SGExpression.hxx>
00025
00026
00027 #ifdef min
00028 #undef min
00029 #endif
00030 #ifdef max
00031 #undef max
00032 #endif
00033
00034 SGExpressiond*
00035 read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot,
00036 const char* unit, double defMin, double defMax);
00037
00039
00041
00042 class SGAnimation : protected osg::NodeVisitor {
00043 public:
00044 SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot);
00045 virtual ~SGAnimation();
00046
00047 static bool animate(osg::Node* node, const SGPropertyNode* configNode,
00048 SGPropertyNode* modelRoot,
00049 const osgDB::ReaderWriter::Options* options);
00050
00051 protected:
00052 void apply(osg::Node* node);
00053
00054 virtual void install(osg::Node& node);
00055 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00056
00057 virtual void apply(osg::Group& group);
00058
00059 void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode);
00060 void removeAttribute(osg::Node& node, osg::StateAttribute::Type type);
00061 void removeTextureMode(osg::Node& node, unsigned unit,
00062 osg::StateAttribute::GLMode mode);
00063 void removeTextureAttribute(osg::Node& node, unsigned unit,
00064 osg::StateAttribute::Type type);
00065 void setRenderBinToInherit(osg::Node& node);
00066 void cloneDrawables(osg::Node& node);
00067
00068 std::string getType() const
00069 { return std::string(_configNode->getStringValue("type", "")); }
00070
00071 const SGPropertyNode* getConfig() const
00072 { return _configNode; }
00073 SGPropertyNode* getModelRoot() const
00074 { return _modelRoot; }
00075
00076 const SGCondition* getCondition() const;
00077
00078 private:
00079 void installInGroup(const std::string& name, osg::Group& group,
00080 osg::ref_ptr<osg::Group>& animationGroup);
00081
00082 class RemoveModeVisitor;
00083 class RemoveAttributeVisitor;
00084 class RemoveTextureModeVisitor;
00085 class RemoveTextureAttributeVisitor;
00086 class BinToInheritVisitor;
00087 class DrawableCloneVisitor;
00088
00089 bool _found;
00090 std::string _name;
00091 SGSharedPtr<SGPropertyNode const> _configNode;
00092 SGPropertyNode* _modelRoot;
00093 std::list<std::string> _objectNames;
00094 std::list<osg::ref_ptr<osg::Node> > _installedAnimations;
00095 bool _enableHOT;
00096 bool _disableShadow;
00097 };
00098
00099
00101
00103
00104 class SGGroupAnimation : public SGAnimation {
00105 public:
00106 SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*);
00107 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00108 };
00109
00110
00112
00114
00115 class SGTranslateAnimation : public SGAnimation {
00116 public:
00117 SGTranslateAnimation(const SGPropertyNode* configNode,
00118 SGPropertyNode* modelRoot);
00119 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00120 private:
00121 class UpdateCallback;
00122 SGSharedPtr<const SGCondition> _condition;
00123 SGSharedPtr<const SGExpressiond> _animationValue;
00124 SGVec3d _axis;
00125 double _initialValue;
00126 };
00127
00128
00130
00132
00133 class SGRotateAnimation : public SGAnimation {
00134 public:
00135 SGRotateAnimation(const SGPropertyNode* configNode,
00136 SGPropertyNode* modelRoot);
00137 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00138 private:
00139 class UpdateCallback;
00140 class SpinUpdateCallback;
00141 SGSharedPtr<const SGCondition> _condition;
00142 SGSharedPtr<const SGExpressiond> _animationValue;
00143 SGVec3d _axis;
00144 SGVec3d _center;
00145 double _initialValue;
00146 bool _isSpin;
00147 };
00148
00149
00151
00153
00154 class SGScaleAnimation : public SGAnimation {
00155 public:
00156 SGScaleAnimation(const SGPropertyNode* configNode,
00157 SGPropertyNode* modelRoot);
00158 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00159 private:
00160 class UpdateCallback;
00161 SGSharedPtr<const SGCondition> _condition;
00162 SGSharedPtr<const SGExpressiond> _animationValue[3];
00163 SGVec3d _initialValue;
00164 SGVec3d _center;
00165 };
00166
00167
00169
00171
00172 class SGDistScaleAnimation : public SGAnimation {
00173 public:
00174 SGDistScaleAnimation(const SGPropertyNode* configNode,
00175 SGPropertyNode* modelRoot);
00176 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00177 class Transform;
00178 };
00179
00180
00182
00184
00185 class SGFlashAnimation : public SGAnimation {
00186 public:
00187 SGFlashAnimation(const SGPropertyNode* configNode,
00188 SGPropertyNode* modelRoot);
00189 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00190 public:
00191 class Transform;
00192 };
00193
00194
00196
00198
00199 class SGBillboardAnimation : public SGAnimation {
00200 public:
00201 SGBillboardAnimation(const SGPropertyNode* configNode,
00202 SGPropertyNode* modelRoot);
00203 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00204 class Transform;
00205 };
00206
00207
00209
00211
00212 class SGRangeAnimation : public SGAnimation {
00213 public:
00214 SGRangeAnimation(const SGPropertyNode* configNode,
00215 SGPropertyNode* modelRoot);
00216 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00217 private:
00218 class UpdateCallback;
00219 SGSharedPtr<const SGCondition> _condition;
00220 SGSharedPtr<const SGExpressiond> _minAnimationValue;
00221 SGSharedPtr<const SGExpressiond> _maxAnimationValue;
00222 SGVec2d _initialValue;
00223 };
00224
00225
00227
00229
00230 class SGSelectAnimation : public SGAnimation {
00231 public:
00232 SGSelectAnimation(const SGPropertyNode* configNode,
00233 SGPropertyNode* modelRoot);
00234 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00235 private:
00236 class UpdateCallback;
00237 };
00238
00239
00241
00243
00244 class SGAlphaTestAnimation : public SGAnimation {
00245 public:
00246 SGAlphaTestAnimation(const SGPropertyNode* configNode,
00247 SGPropertyNode* modelRoot);
00248 virtual void install(osg::Node& node);
00249 };
00250
00251
00253
00255
00256 class SGBlendAnimation : public SGAnimation {
00257 public:
00258 SGBlendAnimation(const SGPropertyNode* configNode,
00259 SGPropertyNode* modelRoot);
00260 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00261 virtual void install(osg::Node& node);
00262 private:
00263 class BlendVisitor;
00264 class UpdateCallback;
00265 SGSharedPtr<SGExpressiond> _animationValue;
00266 };
00267
00268
00270
00272
00273 class SGTimedAnimation : public SGAnimation {
00274 public:
00275 SGTimedAnimation(const SGPropertyNode* configNode,
00276 SGPropertyNode* modelRoot);
00277 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00278 private:
00279 class UpdateCallback;
00280 };
00281
00282
00284
00286
00287 class SGShadowAnimation : public SGAnimation {
00288 public:
00289 SGShadowAnimation(const SGPropertyNode* configNode,
00290 SGPropertyNode* modelRoot);
00291 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00292 private:
00293 class UpdateCallback;
00294 };
00295
00296
00298
00300
00301 class SGTexTransformAnimation : public SGAnimation {
00302 public:
00303 SGTexTransformAnimation(const SGPropertyNode* configNode,
00304 SGPropertyNode* modelRoot);
00305 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00306 private:
00307 class Transform;
00308 class Translation;
00309 class Rotation;
00310 class UpdateCallback;
00311 void appendTexTranslate(const SGPropertyNode* config,
00312 UpdateCallback* updateCallback);
00313 void appendTexRotate(const SGPropertyNode* config,
00314 UpdateCallback* updateCallback);
00315 };
00316
00317
00319
00321
00322 class SGShaderAnimation : public SGAnimation {
00323 public:
00324 SGShaderAnimation(const SGPropertyNode* configNode,
00325 SGPropertyNode* modelRoot,
00326 const osgDB::ReaderWriter::Options* options);
00327 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00328 private:
00329 class UpdateCallback;
00330 osg::ref_ptr<osg::Texture2D> _effect_texture;
00331 };
00332
00333
00335
00337
00338 class SGPickAnimation : public SGAnimation {
00339 public:
00340 SGPickAnimation(const SGPropertyNode* configNode,
00341 SGPropertyNode* modelRoot);
00342 virtual osg::Group* createAnimationGroup(osg::Group& parent);
00343 private:
00344 class PickCallback;
00345 };
00346
00347 #endif // _SG_ANIMATION_HXX