Changeset 10518 for OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp
- Timestamp:
- 08/03/09 11:48:12 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp
r10498 r10518 16 16 #include <osgAnimation/UpdateCallback> 17 17 #include <osg/Notify> 18 #include <osg/Geode> 18 19 19 20 using namespace osgAnimation; … … 33 34 return _animations; 34 35 } 36 void LinkVisitor::link(osgAnimation::AnimationUpdateCallbackBase* cb) 37 { 38 int result = 0; 39 for (int i = 0; i < (int)_animations.size(); i++) 40 { 41 result += cb->link(_animations[i].get()); 42 _nbLinkedTarget += result; 43 } 44 osg::notify(osg::NOTICE) << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl; 45 } 46 47 void LinkVisitor::handle_stateset(osg::StateSet* stateset) 48 { 49 if (!stateset) 50 return; 51 osg::StateSet::AttributeList& attr = stateset->getAttributeList(); 52 for (osg::StateSet::AttributeList::iterator it = attr.begin(); it != attr.end(); it++) 53 { 54 osg::StateAttribute* sattr = it->second.first.get(); 55 osgAnimation::AnimationUpdateCallbackBase* cb = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(sattr->getUpdateCallback()); 56 if (cb) 57 link(cb); 58 } 59 } 35 60 36 61 void LinkVisitor::apply(osg::Node& node) 37 62 { 38 osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback()); 39 if (cb) 63 osg::StateSet* st = node.getStateSet(); 64 if (st) 65 handle_stateset(st); 66 67 osg::NodeCallback* cb = node.getUpdateCallback(); 68 while (cb) 40 69 { 41 int result = 0; 42 for (int i = 0; i < (int)_animations.size(); i++) 43 { 44 result += cb->link(_animations[i].get()); 45 _nbLinkedTarget += result; 46 } 47 osg::notify(osg::NOTICE) << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl; 70 osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb); 71 if (cba) 72 link(cba); 73 cb = cb->getNestedCallback(); 48 74 } 49 75 traverse(node); 50 76 } 77 78 void LinkVisitor::apply(osg::Geode& node) 79 { 80 for (unsigned int i = 0; i < node.getNumDrawables(); i++) 81 { 82 osg::Drawable* drawable = node.getDrawable(i); 83 if (drawable && drawable->getStateSet()) 84 handle_stateset(drawable->getStateSet()); 85 } 86 apply(static_cast<osg::Node&>(node)); 87 }
