1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00
OpenMW/apps/openmw/mwrender/creatureanimation.cpp

83 lines
2.3 KiB
C++
Raw Normal View History

#include "creatureanimation.hpp"
#include <OgreEntity.h>
#include <OgreSceneManager.h>
#include <OgreSubEntity.h>
2012-04-03 15:13:47 +02:00
#include "renderconst.hpp"
#include "../mwbase/world.hpp"
using namespace Ogre;
using namespace NifOgre;
namespace MWRender{
2011-12-11 23:42:39 -05:00
CreatureAnimation::~CreatureAnimation()
{
2011-12-11 23:42:39 -05: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>();
2012-01-17 15:10:53 +01:00
assert (ref->base != NULL);
if(!ref->base->model.empty())
{
std::string mesh = "meshes\\" + ref->base->model;
// FIXME: There can be more than one!
NifOgre::MeshPairList meshes = NifOgre::NIFLoader::load(mesh);
mBase = mRend.getScene()->createEntity(meshes[0].first->getName());
mBase->setVisibilityFlags(RV_Actors);
2012-04-04 18:53:40 +02:00
bool transparent = false;
for (unsigned int i=0; i < mBase->getNumSubEntities(); ++i)
2012-04-04 18:53:40 +02: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;
}
}
}
mBase->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
2012-04-04 18:53:40 +02:00
mInsert->attachObject(mBase);
}
}
void CreatureAnimation::runAnimation(float timepassed)
{
if(mAnimate > 0)
{
//Add the amount of time passed to time
//Handle the animation transforms dependent on time
//Handle the shapes dependent on animation transforms
mTime += timepassed;
if(mTime >= mStopTime)
{
mAnimate--;
//std::cout << "Stopping the animation\n";
if(mAnimate == 0)
mTime = mStopTime;
else
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-01-17 15:10:53 +01:00
}