+SGAnimation::SGAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot) :
+ osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
+ _found(false),
+ _configNode(configNode),
+ _modelRoot(modelRoot)
+{
+ _name = configNode->getStringValue("name", "");
+ _enableHOT = configNode->getBoolValue("enable-hot", true);
+ _disableShadow = configNode->getBoolValue("disable-shadow", false);
+ std::vector<SGPropertyNode_ptr> objectNames =
+ configNode->getChildren("object-name");
+ for (unsigned i = 0; i < objectNames.size(); ++i)
+ _objectNames.push_back(objectNames[i]->getStringValue());
+}
+
+SGAnimation::~SGAnimation()
+{
+ if (_found)
+ return;
+
+ SG_LOG(SG_IO, SG_ALERT, "Could not find at least one of the following"
+ " objects for animation:\n");
+ std::list<std::string>::const_iterator i;
+ for (i = _objectNames.begin(); i != _objectNames.end(); ++i)
+ SG_LOG(SG_IO, SG_ALERT, *i << "\n");
+}
+
+bool
+SGAnimation::animate(osg::Node* node, const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot,
+ const osgDB::ReaderWriter::Options* options)
+{
+ std::string type = configNode->getStringValue("type", "none");
+ if (type == "alpha-test") {
+ SGAlphaTestAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "billboard") {
+ SGBillboardAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "blend") {
+ SGBlendAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "dist-scale") {
+ SGDistScaleAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "flash") {
+ SGFlashAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "interaction") {
+ SGInteractionAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "material") {
+ SGMaterialAnimation animInst(configNode, modelRoot, options);
+ animInst.apply(node);
+ } else if (type == "noshadow") {
+ SGShadowAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "pick") {
+ SGPickAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "range") {
+ SGRangeAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "rotate" || type == "spin") {
+ SGRotateAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "scale") {
+ SGScaleAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "select") {
+ SGSelectAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "shader") {
+ SGShaderAnimation animInst(configNode, modelRoot, options);
+ animInst.apply(node);
+ } else if (type == "textranslate" || type == "texrotate" ||
+ type == "texmultiple") {
+ SGTexTransformAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "timed") {
+ SGTimedAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "translate") {
+ SGTranslateAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else if (type == "null" || type == "none" || type.empty()) {
+ SGGroupAnimation animInst(configNode, modelRoot);
+ animInst.apply(node);
+ } else
+ return false;
+
+ return true;