-/**
- * Splice a branch in between all child nodes and their parents.
- */
-static void
-splice_branch(osg::Group* group, osg::Node* child)
-{
- osg::Node::ParentList parents = child->getParents();
- group->addChild(child);
- osg::Node::ParentList::iterator i;
- for (i = parents.begin(); i != parents.end(); ++i)
- (*i)->replaceChild(child, group);
-}
-
-void
-sgMakeAnimation( osg::Node * model,
- const char * name,
- vector<SGPropertyNode_ptr> &name_nodes,
- SGPropertyNode *prop_root,
- SGPropertyNode_ptr node,
- double sim_time_sec,
- SGPath &texture_path,
- set<osg::Node*> &ignore_branches )
-{
- bool ignore = false;
- SGAnimation * animation = 0;
- const char * type = node->getStringValue("type", "none");
- if (!strcmp("none", type)) {
- animation = new SGNullAnimation(node);
- } else if (!strcmp("range", type)) {
- animation = new SGRangeAnimation(prop_root, node);
- } else if (!strcmp("billboard", type)) {
- animation = new SGBillboardAnimation(node);
- } else if (!strcmp("select", type)) {
- animation = new SGSelectAnimation(prop_root, node);
- } else if (!strcmp("spin", type)) {
- animation = new SGSpinAnimation(prop_root, node, sim_time_sec );
- } else if (!strcmp("timed", type)) {
- animation = new SGTimedAnimation(node);
- } else if (!strcmp("rotate", type)) {
- animation = new SGRotateAnimation(prop_root, node);
- } else if (!strcmp("translate", type)) {
- animation = new SGTranslateAnimation(prop_root, node);
- } else if (!strcmp("scale", type)) {
- animation = new SGScaleAnimation(prop_root, node);
- } else if (!strcmp("texrotate", type)) {
- animation = new SGTexRotateAnimation(prop_root, node);
- } else if (!strcmp("textranslate", type)) {
- animation = new SGTexTranslateAnimation(prop_root, node);
- } else if (!strcmp("texmultiple", type)) {
- animation = new SGTexMultipleAnimation(prop_root, node);
- } else if (!strcmp("blend", type)) {
- animation = new SGBlendAnimation(prop_root, node);
- ignore = true;
- } else if (!strcmp("alpha-test", type)) {
- animation = new SGAlphaTestAnimation(node);
- } else if (!strcmp("material", type)) {
- animation = new SGMaterialAnimation(prop_root, node, texture_path);
- } else if (!strcmp("flash", type)) {
- animation = new SGFlashAnimation(node);
- } else if (!strcmp("dist-scale", type)) {
- animation = new SGDistScaleAnimation(node);
- } else if (!strcmp("noshadow", type)) {
- animation = new SGShadowAnimation(prop_root, node);
- } else if (!strcmp("shader", type)) {
- animation = new SGShaderAnimation(prop_root, node);
- } else {
- animation = new SGNullAnimation(node);
- SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
- }
-
- if (name != 0)
- animation->setName(name);
-
- osg::Node * object = 0;
- if (!name_nodes.empty()) {
- const char * name = name_nodes[0]->getStringValue();
- NodeFinder nodeFinder(name);
- model->accept(nodeFinder);
- object = nodeFinder.getNode();
- if (object == 0) {
- SG_LOG(SG_INPUT, SG_ALERT, "Object " << name << " not found");
- delete animation;
- animation = 0;
- }
- } else {
- object = model;
- }
-
- if ( animation == 0 )
- return;
-
- osg::Group* branch = animation->getBranch();
- splice_branch(branch, object);
-
- for (unsigned int i = 1; i < name_nodes.size(); i++) {
- const char * name = name_nodes[i]->getStringValue();
- NodeFinder nodeFinder(name);
- model->accept(nodeFinder);
- object = nodeFinder.getNode();
- if (object == 0) {
- SG_LOG(SG_INPUT, SG_ALERT, "Object " << name << " not found");
- delete animation;
- animation = 0;
- } else {
- osg::Group* oldParent = object->getParent(0);
- branch->addChild(object);
- oldParent->removeChild(object);
- }
- }
-
- if ( animation != 0 ) {
- animation->init();
- branch->setUpdateCallback(animation);
- if ( ignore ) {
- ignore_branches.insert( branch );
- }
- }
-}
-