2011-12-11 22:40:00 -05:00
|
|
|
#include "creatureanimation.hpp"
|
2012-07-03 15:32:38 +02:00
|
|
|
|
|
|
|
#include <OgreEntity.h>
|
|
|
|
#include <OgreSceneManager.h>
|
|
|
|
#include <OgreSubEntity.h>
|
|
|
|
|
2012-04-03 15:13:47 +02:00
|
|
|
#include "renderconst.hpp"
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2011-12-11 22:40:00 -05:00
|
|
|
|
|
|
|
using namespace Ogre;
|
|
|
|
using namespace NifOgre;
|
|
|
|
namespace MWRender{
|
2011-12-11 23:42:39 -05:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
CreatureAnimation::~CreatureAnimation()
|
|
|
|
{
|
2011-12-11 23:42:39 -05:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
|
|
|
|
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend): Animation(_rend)
|
|
|
|
{
|
2012-07-13 03:51:58 -07:00
|
|
|
mInsert = ptr.getRefData().getBaseNode();
|
2012-07-12 20:12:18 -07:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2012-01-17 15:10:53 +01:00
|
|
|
assert (ref->base != NULL);
|
2012-07-12 20:12:18 -07:00
|
|
|
if(!ref->base->model.empty())
|
|
|
|
{
|
|
|
|
std::string mesh = "meshes\\" + ref->base->model;
|
|
|
|
|
2012-07-13 18:25:35 -07:00
|
|
|
// FIXME: There can be more than one!
|
|
|
|
NifOgre::MeshPairList meshes = NifOgre::NIFLoader::load(mesh);
|
2012-07-17 10:57:15 -07:00
|
|
|
mBase = mRend.getScene()->createEntity(meshes[0].first->getName());
|
2012-07-13 03:51:58 -07:00
|
|
|
mBase->setVisibilityFlags(RV_Actors);
|
2012-04-04 18:53:40 +02:00
|
|
|
|
|
|
|
bool transparent = false;
|
2012-07-13 03:51:58 -07:00
|
|
|
for (unsigned int i=0; i < mBase->getNumSubEntities(); ++i)
|
2012-04-04 18:53:40 +02:00
|
|
|
{
|
2012-07-13 03:51:58 -07:00
|
|
|
Ogre::MaterialPtr mat = mBase->getSubEntity(i)->getMaterial();
|
2012-04-04 18:53:40 +02:00
|
|
|
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
|
|
|
while (techIt.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::Technique* tech = techIt.getNext();
|
|
|
|
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
|
|
|
|
while (passIt.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::Pass* pass = passIt.getNext();
|
|
|
|
|
|
|
|
if (pass->getDepthWriteEnabled() == false)
|
|
|
|
transparent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 03:51:58 -07:00
|
|
|
mBase->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
2012-04-04 18:53:40 +02:00
|
|
|
|
2012-07-13 03:51:58 -07:00
|
|
|
mInsert->attachObject(mBase);
|
2011-12-11 22:40:00 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-25 22:37:26 -05:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
void CreatureAnimation::runAnimation(float timepassed)
|
|
|
|
{
|
2012-07-13 03:51:58 -07:00
|
|
|
if(mAnimate > 0)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
|
|
|
//Add the amount of time passed to time
|
2011-12-25 22:37:26 -05:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
//Handle the animation transforms dependent on time
|
2011-12-25 22:37:26 -05:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
//Handle the shapes dependent on animation transforms
|
2012-07-13 03:51:58 -07:00
|
|
|
mTime += timepassed;
|
|
|
|
if(mTime >= mStopTime)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2012-07-13 03:51:58 -07:00
|
|
|
mAnimate--;
|
2011-12-28 21:52:05 -05:00
|
|
|
//std::cout << "Stopping the animation\n";
|
2012-07-13 03:51:58 -07:00
|
|
|
if(mAnimate == 0)
|
|
|
|
mTime = mStopTime;
|
2011-12-28 21:52:05 -05:00
|
|
|
else
|
2012-07-13 03:51:58 -07:00
|
|
|
mTime = mStartTime + (mTime - mStopTime);
|
2011-12-28 17:34:47 -05:00
|
|
|
}
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2011-12-27 22:35:22 -05:00
|
|
|
handleAnimationTransforms();
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2011-12-25 22:37:26 -05:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
|
2012-01-17 15:10:53 +01:00
|
|
|
}
|