2016-01-19 19:35:13 +08:00
|
|
|
/* -*-c++-*-
|
2008-11-22 20:14:19 +08:00
|
|
|
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
|
|
|
*
|
2016-01-19 19:35:13 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2008-11-22 20:14:19 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2016-01-19 19:35:13 +08:00
|
|
|
*
|
2008-11-22 20:14:19 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-01-19 19:35:13 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-11-22 20:14:19 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Cedric Pinson <mornifle@plopbyte.net>
|
|
|
|
* jeremy Moles <jeremy@emperorlinux.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ANIMTKVIEWER_H
|
|
|
|
#define ANIMTKVIEWER_H
|
|
|
|
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osgDB/ReadFile>
|
2008-12-17 04:29:00 +08:00
|
|
|
#include <osgAnimation/BasicAnimationManager>
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
class AnimtkViewerModelController
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::vector<std::string> AnimationMapVector;
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
static AnimtkViewerModelController& instance()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
static AnimtkViewerModelController avmc;
|
|
|
|
return avmc;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
static bool setModel(osgAnimation::BasicAnimationManager* model)
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
AnimtkViewerModelController& self = instance();
|
|
|
|
self._model = model;
|
2008-12-17 04:29:00 +08:00
|
|
|
for (osgAnimation::AnimationList::const_iterator it = self._model->getAnimationList().begin(); it != self._model->getAnimationList().end(); it++)
|
|
|
|
self._map[(*it)->getName()] = *it;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
for(osgAnimation::AnimationMap::iterator it = self._map.begin(); it != self._map.end(); it++)
|
|
|
|
self._amv.push_back(it->first);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool list()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
std::cout << "Animation List:" << std::endl;
|
|
|
|
for(osgAnimation::AnimationMap::iterator it = _map.begin(); it != _map.end(); it++)
|
|
|
|
std::cout << it->first << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool play()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
2016-01-19 19:35:13 +08:00
|
|
|
if(_focus < _amv.size())
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
std::cout << "Play " << _amv[_focus] << std::endl;
|
|
|
|
_model->playAnimation(_map[_amv[_focus]].get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool stop()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
2016-01-19 19:35:13 +08:00
|
|
|
if(_focus < _amv.size())
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
std::cout << "Stop " << _amv[_focus] << std::endl;
|
|
|
|
_model->stopAnimation(_map[_amv[_focus]].get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-01-19 19:35:13 +08:00
|
|
|
}
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool next()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
_focus = (_focus + 1) % _map.size();
|
|
|
|
std::cout << "Current now is " << _amv[_focus] << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool previous()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
_focus = (_map.size() + _focus - 1) % _map.size();
|
|
|
|
std::cout << "Current now is " << _amv[_focus] << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
bool playByName(const std::string& name)
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < _amv.size(); i++) if(_amv[i] == name) _focus = i;
|
|
|
|
_model->playAnimation(_map[name].get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
const std::string& getCurrentAnimationName() const
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
return _amv[_focus];
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:35:13 +08:00
|
|
|
const AnimationMapVector& getAnimationMap() const
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
return _amv;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2008-12-17 04:29:00 +08:00
|
|
|
osg::ref_ptr<osgAnimation::BasicAnimationManager> _model;
|
2008-11-22 20:14:19 +08:00
|
|
|
osgAnimation::AnimationMap _map;
|
|
|
|
AnimationMapVector _amv;
|
|
|
|
unsigned int _focus;
|
|
|
|
|
|
|
|
AnimtkViewerModelController():
|
|
|
|
_model(0),
|
|
|
|
_focus(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|