Hi, everyone
I am new in OSG and have a problem. I wrote the code that plays animation in
.fbx models, but I can't play animation in .osgb(.osgt, .ive) models. Please
see the attached file and help me.
P.S. Sorry for the clumsy English(
Thank you!
Cheers,
Maxim Voloshin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56536#56536
#include "stdafx.h"
#include <osgAnimation/BasicAnimationManager>
#include <osgViewer/Viewer>
#include <osgDB/ConvertUTF>
#include <osgDB/ReadFile>
#include <osg/Node>
#define KEY_Space 0x20
struct AnimationManagerFinder : public osg::NodeVisitor
{
osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;
AnimationManagerFinder()
{
setTraversalMode(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
}
void apply(osg::Node& node)
{
if (_am.valid()) return;
if (node.getUpdateCallback())
{
_am =
dynamic_cast<osgAnimation::BasicAnimationManager*>(node.getUpdateCallback());
return;
}
traverse(node);
}
};
class myKeyboardEventHandler : public osgGA::GUIEventHandler
{
public:
osg::Group *e_root;
virtual bool handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter&);
virtual void accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
};
};
void play(osg::Group *root)
{
AnimationManagerFinder finder;
root->accept(finder);
const osgAnimation::AnimationList& animations =
finder._am->getAnimationList();
animations[0]->setPlayMode(osgAnimation::Animation::STAY);
finder._am->playAnimation(animations[0].get());
std::cout << "name is: " << animations[0]->getName() <<
std::endl;
}
bool myKeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa)
{
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
switch(ea.getKey())
{
case KEY_Space:
std::cout << "Animation
started, ";
play(e_root);
return false;
break;
default:
return false;
}
}
default:
return false;
}
}
void _tmain(int argc, _TCHAR* argv[])
{
osg::Node *node = NULL;
node =
osgDB::readNodeFile(osgDB::convertStringFromCurrentCodePageToUTF8("C:/Straight_AB.osgb"));
osg::Group* root = new osg::Group();
root->addChild(node);
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(32, 32, 512, 512);
viewer.setSceneData(root);
myKeyboardEventHandler *myFirstEventHandler = new
myKeyboardEventHandler();
myFirstEventHandler->e_root = root;
viewer.addEventHandler(myFirstEventHandler);
viewer.run();
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org