2011-12-12 03:40:00 +00:00
|
|
|
#include "creatureanimation.hpp"
|
2012-07-03 13:32:38 +00:00
|
|
|
|
|
|
|
#include <OgreEntity.h>
|
|
|
|
#include <OgreSceneManager.h>
|
|
|
|
#include <OgreSubEntity.h>
|
|
|
|
|
2012-04-03 13:13:47 +00:00
|
|
|
#include "renderconst.hpp"
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2011-12-12 03:40:00 +00:00
|
|
|
|
|
|
|
using namespace Ogre;
|
|
|
|
using namespace NifOgre;
|
|
|
|
namespace MWRender{
|
2011-12-12 04:42:39 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
CreatureAnimation::~CreatureAnimation()
|
|
|
|
{
|
|
|
|
}
|
2011-12-12 04:42:39 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend): Animation(_rend)
|
|
|
|
{
|
|
|
|
mInsert = ptr.getRefData().getBaseNode();
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2012-01-17 14:10:53 +00:00
|
|
|
assert (ref->base != NULL);
|
2012-07-13 10:51:58 +00:00
|
|
|
if(!ref->base->model.empty())
|
|
|
|
{
|
2011-12-12 03:40:00 +00:00
|
|
|
const std::string &mesh = "meshes\\" + ref->base->model;
|
2011-12-17 06:29:08 +00:00
|
|
|
std::string meshNumbered = mesh + getUniqueID(mesh) + ">|";
|
|
|
|
NifOgre::NIFLoader::load(meshNumbered);
|
2012-07-13 10:51:58 +00:00
|
|
|
mBase = mRend.getScene()->createEntity(meshNumbered);
|
|
|
|
mBase->setVisibilityFlags(RV_Actors);
|
2012-04-04 16:53:40 +00:00
|
|
|
|
|
|
|
bool transparent = false;
|
2012-07-13 10:51:58 +00:00
|
|
|
for (unsigned int i=0; i < mBase->getNumSubEntities(); ++i)
|
2012-04-04 16:53:40 +00:00
|
|
|
{
|
2012-07-13 10:51:58 +00:00
|
|
|
Ogre::MaterialPtr mat = mBase->getSubEntity(i)->getMaterial();
|
2012-04-04 16:53:40 +00: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 10:51:58 +00:00
|
|
|
mBase->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
2012-04-04 16:53:40 +00:00
|
|
|
|
2011-12-17 06:29:08 +00:00
|
|
|
std::string meshZero = mesh + "0000>|";
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
if((mTransformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero)))
|
|
|
|
{
|
|
|
|
for(std::size_t init = 0; init < mTransformations->size(); init++)
|
|
|
|
{
|
|
|
|
mRindexI.push_back(0);
|
|
|
|
mTindexI.push_back(0);
|
|
|
|
}
|
|
|
|
mStopTime = mTransformations->begin()->getStopTime();
|
|
|
|
mStartTime = mTransformations->begin()->getStartTime();
|
|
|
|
mShapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero);
|
2012-01-06 05:55:02 +00:00
|
|
|
}
|
2012-07-13 10:51:58 +00:00
|
|
|
mTextmappings = NIFLoader::getSingletonPtr()->getTextIndices(meshZero);
|
|
|
|
mInsert->attachObject(mBase);
|
2011-12-12 03:40:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-26 03:37:26 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
void CreatureAnimation::runAnimation(float timepassed)
|
|
|
|
{
|
|
|
|
mVecRotPos.clear();
|
|
|
|
if(mAnimate > 0)
|
|
|
|
{
|
|
|
|
//Add the amount of time passed to time
|
2011-12-26 03:37:26 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
//Handle the animation transforms dependent on time
|
2011-12-26 03:37:26 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
//Handle the shapes dependent on animation transforms
|
|
|
|
mTime += timepassed;
|
|
|
|
if(mTime >= mStopTime)
|
|
|
|
{
|
|
|
|
mAnimate--;
|
2011-12-29 02:52:05 +00:00
|
|
|
//std::cout << "Stopping the animation\n";
|
2012-07-13 10:51:58 +00:00
|
|
|
if(mAnimate == 0)
|
|
|
|
mTime = mStopTime;
|
2011-12-29 02:52:05 +00:00
|
|
|
else
|
2012-07-13 10:51:58 +00:00
|
|
|
mTime = mStartTime + (mTime - mStopTime);
|
2011-12-28 22:34:47 +00:00
|
|
|
}
|
2012-01-17 14:10:53 +00:00
|
|
|
|
2011-12-28 03:35:22 +00:00
|
|
|
handleAnimationTransforms();
|
2012-07-13 10:51:58 +00:00
|
|
|
handleShapes(mShapes, mBase, mBase->getSkeleton());
|
2011-12-26 03:37:26 +00:00
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
}
|
2011-12-26 03:37:26 +00:00
|
|
|
}
|
2012-07-13 10:51:58 +00:00
|
|
|
|
2012-01-17 14:10:53 +00:00
|
|
|
}
|