/** * Main function: load and display collada file. */ int main(int argc, char** argv) { //----------------- Define program arguments -------------------// osg::ArgumentParser* OSGArguments = defineProgramArguments(&argc, argv); //----------------- Display help and quit -------------------// if (OSGArguments->read("-h") || OSGArguments->read("--help") || OSGArguments->argc()<=1 ) { OSGArguments->getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } //----------------- Get arguments -------------------// ArgContainer* userArgs = getUserArguments(OSGArguments); //----------------- Load data in dae file -------------------// osg::Group* rootGroup = new osg::Group(); osg::Node* fileNode = osgDB::readNodeFile(userArgs->daeFile); if(!fileNode) { std::cout << OSGArguments->getApplicationName() <<": No data loaded" << std::endl; return 1; } rootGroup->addChild(fileNode); parse(fileNode, "", userArgs->verbose); //----------------- Modifiy fileNode to set the UP vector along Z -------------------// defineUpAxisInScene(fileNode, userArgs); //----------------- Create Viewer and interface -------------------// osgViewer::ViewerExt viewer; viewer.setRunMaxFrameRate(userArgs->fps); viewer.addEventHandler(new KeyEventHandler()); if (userArgs->communicationWithSocket) { SOCKET sock = OpenPort(userArgs->host.c_str(), userArgs->port); fileNode->setUpdateCallback(new SocketCallback(fileNode, sock)); } else { //----------------- Check animation data -------------------// AnimationManagerFinder finder; fileNode->accept(finder); if (finder._animManager.valid()) { userArgs->hasAnAnimation = true; fileNode->setUpdateCallback(finder._animManager.get()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, userArgs->width, userArgs->height, finder._animManager.get(), userArgs->extension_type); //interface osg::Camera* camera = gui->createParentOrthoCamera(); rootGroup->addChild(camera); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); } else { osg::notify(osg::WARN) << "no animation found in the subgraph"<<std::endl; } } viewer.setSceneData(rootGroup); //------------------- Init and Start Viewer -----------------------// initViewer(&viewer, userArgs); //------------------- What to do... -----------------------// if (userArgs->takeSnapShot) { return takeOneSnapShotAndQuit(&viewer, userArgs); } if (userArgs->recordAnimation && userArgs->hasAnAnimation) { return recordAnimationAndQuit(&viewer, userArgs); } return viewer.run(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an example for viewing osgAnimation animations."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); arguments.getApplicationUsage()->addCommandLineOption("--drawbone","draw helps to display bones."); if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } bool drawBone = false; if (arguments.read("--drawbone")) drawBone = true; osgViewer::Viewer viewer(arguments); osg::ref_ptr<osg::Group> group = new osg::Group(); osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFiles(arguments)); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1])); if(!node) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } // Set our Singleton's model. AnimationManagerFinder finder; node->accept(finder); if (finder._am.valid()) { std::string playModeOpt; if (arguments.read("--play-mode", playModeOpt)) { osgAnimation::Animation::PlayMode playMode = osgAnimation::Animation::LOOP; if (osgDB::equalCaseInsensitive(playModeOpt, "ONCE")) playMode = osgAnimation::Animation::ONCE; else if (osgDB::equalCaseInsensitive(playModeOpt, "STAY")) playMode = osgAnimation::Animation::STAY; else if (osgDB::equalCaseInsensitive(playModeOpt, "LOOP")) playMode = osgAnimation::Animation::LOOP; else if (osgDB::equalCaseInsensitive(playModeOpt, "PPONG")) playMode = osgAnimation::Animation::PPONG; for (osgAnimation::AnimationList::const_iterator animIter = finder._am->getAnimationList().begin(); animIter != finder._am->getAnimationList().end(); ++animIter) { (*animIter)->setPlayMode(playMode); } } node->setUpdateCallback(finder._am.get()); AnimtkViewerModelController::setModel(finder._am.get()); } else { osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl; } if (drawBone) { osg::notify(osg::INFO) << "Add Bones Helper" << std::endl; AddHelperBone addHelper; node->accept(addHelper); } node->addChild(createAxis()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234); osg::Camera* camera = gui->createParentOrthoCamera(); node->setNodeMask(0x0001); group->addChild(node); group->addChild(camera); viewer.addEventHandler(new AnimtkKeyEventHandler()); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::KeyboardHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); viewer.setSceneData(group.get()); viewer.setUpViewInWindow(40, 40, WIDTH, HEIGHT); return viewer.run(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an example for viewing osgAnimation animations."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); arguments.getApplicationUsage()->addCommandLineOption("--drawbone","draw helps to display bones."); if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } //if (arguments.argc()<=1) //{ // arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); // return 1; //} bool drawBone = true; if (arguments.read("--drawbone")) drawBone = true; osgViewer::Viewer viewer(arguments); osg::ref_ptr<osg::Group> group = new osg::Group(); osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFile("C:/Matej/test_1.osg")); //dynamic_cast<osg::Group*>(osgDB::readNodeFiles(arguments)); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1])); if(!node) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } cutSimulation(node); // Set our Singleton's model. AnimationManagerFinder finder; node->accept(finder); if (finder._am.valid()) { node->setUpdateCallback(finder._am.get()); AnimtkViewerModelController::setModel(finder._am.get()); osgAnimation::BasicAnimationManager* model = finder._am.get(); const osgAnimation::AnimationList & lstAnimation = model->getAnimationList(); const osg::ref_ptr<osgAnimation::Animation> & canim = *(lstAnimation.begin()); osg::ref_ptr<osgAnimation::Animation> & anim = const_cast<osg::ref_ptr<osgAnimation::Animation> &>(canim); } else { osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl; } if (drawBone) { osg::notify(osg::INFO) << "Add Bones Helper" << std::endl; AddHelperBone addHelper; node->accept(addHelper); } node->addChild(createAxis()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234); osg::Camera* camera = gui->createParentOrthoCamera(); node->setNodeMask(0x0001); group->addChild(node); group->addChild(camera); viewer.addEventHandler(new AnimtkKeyEventHandler()); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::KeyboardHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); //viewer.setSceneData(group.get()); viewer.setUpViewInWindow(40, 40, WIDTH, HEIGHT); // Create the root node Group. osg::ref_ptr<osg::Group> root = new osg::Group; // Read the object //osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile( "D:/Programs64/OSG/Data/OpenSceneGraph-Data-3.0.0/cow.osg" ); // Define a matrix transform osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; // Set scene graph mt->addChild(group); root->addChild(mt); // Create animation path osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath; // Define control points osg::AnimationPath::ControlPoint CP0(osg::Vec3( 0.f, 5.f, 0.f )); osg::AnimationPath::ControlPoint CP1(osg::Vec3( -2.5f, -2.5f, 0.f ),osg::Quat(-osg::PI/4,osg::Vec3( 0.f, 0.f, 1.f )) ); //osg::AnimationPath::ControlPoint CP2 (osg::Vec3( -2.f, -1.f, 0.f ),osg::Quat(-osg::PI*2/6,osg::Vec3( 0.f, 0.f, 1.f )),osg::Vec3( 0.5f, 0.5f, 0.5f )); //osg::AnimationPath::ControlPoint CP3 (osg::Vec3( 2.f, -1.f, 0.f ),osg::Quat(-osg::PI*3/6,osg::Vec3( 0.f, 0.f, 1.f ))); //osg::AnimationPath::ControlPoint CP4 (osg::Vec3( 2.f, 1.f, 0.f )); // Insert them to the path path->insert( 0.0f, CP0 ); // time, point path->insert( 1.0f, CP1 ); //path->insert( 2.0f, CP2 ); //path->insert( 3.0f, CP3 ); //path->insert( 4.0f, CP4 ); //path->setLoopMode(osg::AnimationPath::LoopMode::SWING); // Define animation path callback osg::ref_ptr<osg::AnimationPathCallback> APCallback = new osg::AnimationPathCallback(path.get() ); // Update the matrix transform mt->setUpdateCallback( APCallback.get() ); viewer.setSceneData(root.get()); return viewer.run(); }