1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwrender/creatureanimation.cpp

87 lines
2.8 KiB
C++
Raw Normal View History

#include "creatureanimation.hpp"
2012-04-03 13:13:47 +00:00
#include "renderconst.hpp"
#include "../mwworld/world.hpp"
using namespace Ogre;
using namespace NifOgre;
namespace MWRender{
2011-12-12 04:42:39 +00:00
CreatureAnimation::~CreatureAnimation(){
}
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRenderer& _rend): Animation(_rend){
2012-01-06 02:45:17 +00:00
insert = ptr.getRefData().getBaseNode();
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
ptr.get<ESM::Creature>();
2012-01-17 14:10:53 +00:00
assert (ref->base != NULL);
if(!ref->base->model.empty()){
const std::string &mesh = "meshes\\" + ref->base->model;
std::string meshNumbered = mesh + getUniqueID(mesh) + ">|";
NifOgre::NIFLoader::load(meshNumbered);
base = mRend.getScene()->createEntity(meshNumbered);
2012-04-03 13:13:47 +00:00
base->setVisibilityFlags(RV_Actors);
2012-04-04 16:53:40 +00:00
bool transparent = false;
for (unsigned int i=0; i<base->getNumSubEntities(); ++i)
{
Ogre::MaterialPtr mat = base->getSubEntity(i)->getMaterial();
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;
}
}
}
base->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
std::string meshZero = mesh + "0000>|";
2012-01-17 14:10:53 +00:00
if((transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero))){
2011-12-15 05:33:10 +00:00
2012-01-17 14:10:53 +00:00
for(std::size_t init = 0; init < transformations->size(); init++){
2011-12-15 05:33:10 +00:00
rindexI.push_back(0);
tindexI.push_back(0);
}
stopTime = transformations->begin()->getStopTime();
2012-01-06 02:45:17 +00:00
startTime = transformations->begin()->getStartTime();
shapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero);
2012-01-06 05:55:02 +00:00
}
textmappings = NIFLoader::getSingletonPtr()->getTextIndices(meshZero);
insert->attachObject(base);
}
}
void CreatureAnimation::runAnimation(float timepassed){
vecRotPos.clear();
if(animate > 0){
//Add the amount of time passed to time
//Handle the animation transforms dependent on time
//Handle the shapes dependent on animation transforms
2011-12-27 00:23:46 +00:00
time += timepassed;
2012-01-10 07:00:04 +00:00
if(time >= stopTime){
animate--;
//std::cout << "Stopping the animation\n";
if(animate == 0)
time = stopTime;
else
time = startTime + (time - stopTime);
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();
2011-12-27 05:20:14 +00:00
handleShapes(shapes, base, base->getSkeleton());
}
}
2012-01-17 14:10:53 +00:00
}