Show
Ignore:
Timestamp:
08/03/09 11:48:12 (5 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson, Add UpdateMaterial? callback to animate material\nUpdate LinkVisitor? to traverse stateset\nUpdate ReaderWriter? to read osgAnimation::UpdateMaterial? Callback\nUpdate nathan.osg data file to demonstrate the MaterialAnimation?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp

    r10498 r10518  
    1616#include <osgAnimation/UpdateCallback> 
    1717#include <osg/Notify> 
     18#include <osg/Geode> 
    1819 
    1920using namespace osgAnimation; 
     
    3334    return _animations; 
    3435} 
     36void 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 
     47void 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} 
    3560 
    3661void LinkVisitor::apply(osg::Node& node) 
    3762{ 
    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) 
    4069    { 
    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(); 
    4874    } 
    4975    traverse(node); 
    5076} 
     77 
     78void 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}