Hi
If you just want to pause animation when it played to end you can use
path->setLoopMode(osg::AnimationPath::NO_LOOPING);
inside your visitor apply(...) method, and animation will stay on last
keypoint, there's no need to traverse graph each frame.
If you want to restart animation - use apc->reset();
Here is visitor i'm using:
class AnimationVisitor : public osg::NodeVisitor
{
public:
enum LoopMode {CURRENT, LOOP, NO_LOOPING, SWING};
private:
LoopMode m_Looping;
bool m_Reset;
bool m_Pause;
public:
AnimationVisitor(bool reset = true, bool pause = false, LoopMode
looping = CURRENT);
void apply( osg::Node & aNode );
};
AnimationVisitor::AnimationVisitor(bool reset, bool pause, LoopMode looping)
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
m_Looping(looping),
m_Reset(reset),
m_Pause(pause)
{
setTraversalMask(~0x0);
setNodeMaskOverride(~0x0);
}
void AnimationVisitor::apply( osg::Node & aNode )
{
for (osg::NodeCallback* sNodeCallback = aNode.getUpdateCallback();
sNodeCallback;
sNodeCallback = sNodeCallback->getNestedCallback())
{
if (osg::AnimationPathCallback* callback =
dynamic_cast<osg::AnimationPathCallback*>(sNodeCallback))
{
if (m_Reset)
callback->reset();
callback->setPause(m_Pause);
switch (m_Looping)
{
case LOOP:
callback->getAnimationPath()->setLoopMode(osg::AnimationPath::LOOP);break;
case NO_LOOPING:
callback->getAnimationPath()->setLoopMode(osg::AnimationPath::NO_LOOPING);
break;
case SWING:
callback->getAnimationPath()->setLoopMode(osg::AnimationPath::SWING); break;
default: break;
}
}
}
traverse(aNode);
}
20.07.2012, 11:04, "Koduri Lakshmi" <[email protected]>:
> Hi hybr,
>
> Thank you very much for your help.
>
> I completed it and here I am giving complete code.
>
> Code:
> class ACPNodeVisitor : public osg::NodeVisitor
> {
> public:
>
> ACPNodeVisitor( )
> {
> setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
>
> }
>
> virtual void apply( osg::Transform& tranform );
>
> protected:
>
> };
>
> void ACPNodeVisitor::apply( osg::Transform& transform )
> {
>
> osg::AnimationPathCallback* apc =
> dynamic_cast<osg::AnimationPathCallback*>(transform.getUpdateCallback());
>
> if (apc)
> {
> osg::AnimationPath *path= apc->getAnimationPath();
>
> int CuraniTime=apc->getAnimationTime();
> int AniTime=path->getPeriod();
>
> if(CuraniTime<=AniTime-1)
> {
> std::cout<<path->getPeriod()<<std::endl;
> std::cout<<path->getFirstTime()<<std::endl;
> std::cout<<path->getLastTime()<<std::endl;
> std::cout<<apc->getAnimationTime()<<std::endl;
> std::cout<<"-------------"<<std::endl;
> apc->setPause(false);
> }
> else
> {
> apc->setPause(true);
> }
>
> }
>
> traverse( transform );
> }
>
> void main()
> {
> osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( "test.osg");
>
> osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
> mt->addChild( model.get() );
>
> osg::ref_ptr<osg::Group> root = new osg::Group;
> root->addChild( mt.get() );
>
> osgViewer::Viewer viewer;
> viewer.setUpViewInWindow (200, 200, 512, 512);
> viewer.setCameraManipulator( new osgGA::TrackballManipulator );
>
> viewer.setSceneData( root.get() );
>
> while(!viewer.done())
> {
> ACPNodeVisitor ftv;
>
> mt->accept( ftv );
>
> viewer.frame();
>
> }
>
> }
>
> Is it the way of doing? If wrong can you please suggest the correct way of
> doing it.
>
> ...
>
> Thank you!
>
> Cheers,
> Koduri
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=48945#48945
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org