2011-12-12 04:42:39 +00:00
|
|
|
#include "animation.hpp"
|
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
#include <components/nifosg/nifloader.hpp>
|
2013-08-06 07:04:39 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
#include <components/resource/scenemanager.hpp>
|
2013-08-07 02:45:07 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
#include <osg/PositionAttitudeTransform>
|
2013-11-19 23:07:26 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2012-07-13 03:12:18 +00:00
|
|
|
|
2015-04-15 20:11:38 +00:00
|
|
|
Animation::Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem)
|
2015-04-12 13:34:50 +00:00
|
|
|
: mPtr(ptr)
|
2015-04-15 20:11:38 +00:00
|
|
|
, mInsert(parentNode)
|
2015-04-12 13:34:50 +00:00
|
|
|
, mResourceSystem(resourceSystem)
|
2013-05-07 23:59:32 +00:00
|
|
|
{
|
2013-04-22 11:10:46 +00:00
|
|
|
|
2014-05-26 18:37:12 +00:00
|
|
|
}
|
2013-05-12 12:08:01 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
Animation::~Animation()
|
2013-05-11 01:37:44 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
if (mObjectRoot)
|
|
|
|
mInsert->removeChild(mObjectRoot);
|
2013-05-11 01:37:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
osg::Vec3f Animation::runAnimation(float duration)
|
2015-01-02 01:27:05 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
return osg::Vec3f();
|
2015-01-02 01:27:05 +00:00
|
|
|
}
|
2013-05-11 01:37:44 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
void Animation::setObjectRoot(const std::string &model)
|
2013-05-11 01:37:44 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
if (mObjectRoot)
|
2013-04-25 05:45:43 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
mObjectRoot->getParent(0)->removeChild(mObjectRoot);
|
2013-04-25 05:45:43 +00:00
|
|
|
}
|
2013-04-25 07:03:27 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
mObjectRoot = mResourceSystem->getSceneManager()->createInstance(model, mInsert);
|
2013-07-23 12:30:37 +00:00
|
|
|
}
|
2013-04-25 07:03:27 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
osg::Group* Animation::getObjectRoot()
|
2014-02-04 02:46:15 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
return static_cast<osg::Group*>(mObjectRoot.get());
|
2014-06-10 20:20:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
osg::Group* Animation::getOrCreateObjectRoot()
|
2014-06-10 20:20:46 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
if (mObjectRoot)
|
|
|
|
return static_cast<osg::Group*>(mObjectRoot.get());
|
2014-06-10 20:20:46 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
mObjectRoot = new osg::Group;
|
|
|
|
mInsert->addChild(mObjectRoot);
|
|
|
|
return static_cast<osg::Group*>(mObjectRoot.get());
|
2014-02-04 02:46:15 +00:00
|
|
|
}
|
2014-06-10 20:20:46 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
// --------------------------------------------------------------------------------
|
2013-05-11 05:22:39 +00:00
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
ObjectAnimation::ObjectAnimation(const MWWorld::Ptr &ptr, const std::string &model, Resource::ResourceSystem* resourceSystem)
|
|
|
|
: Animation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
|
2012-07-21 21:41:26 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
if (!model.empty())
|
2013-05-12 11:34:37 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
setObjectRoot(model);
|
2013-05-12 11:34:37 +00:00
|
|
|
}
|
2013-05-11 05:22:39 +00:00
|
|
|
else
|
2013-08-07 02:45:07 +00:00
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
// No model given. Create an object root anyway, so that lights can be added to it if needed.
|
|
|
|
//mObjectRoot = NifOgre::ObjectScenePtr (new NifOgre::ObjectScene(mInsert->getCreator()));
|
2013-08-07 02:45:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 13:02:24 +00:00
|
|
|
}
|