2011-12-12 04:42:39 +00:00
|
|
|
#include "animation.hpp"
|
|
|
|
|
2013-01-05 12:01:11 +00:00
|
|
|
#include <OgreSkeletonManager.h>
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <OgreSkeletonInstance.h>
|
|
|
|
#include <OgreEntity.h>
|
2013-04-19 09:01:50 +00:00
|
|
|
#include <OgreSubEntity.h>
|
|
|
|
#include <OgreParticleSystem.h>
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <OgreBone.h>
|
|
|
|
#include <OgreSubMesh.h>
|
2012-07-18 07:17:39 +00:00
|
|
|
#include <OgreSceneManager.h>
|
2011-12-17 06:29:08 +00:00
|
|
|
|
2013-01-07 05:18:48 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2013-02-23 22:15:11 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2013-01-07 05:18:48 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2013-01-16 21:09:21 +00:00
|
|
|
#include "../mwmechanics/character.hpp"
|
|
|
|
|
2012-07-13 10:51:58 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2012-07-13 03:12:18 +00:00
|
|
|
|
2013-04-23 06:35:50 +00:00
|
|
|
Ogre::Real Animation::AnimationValue::getValue() const
|
|
|
|
{
|
2013-05-10 23:33:13 +00:00
|
|
|
AnimStateMap::const_iterator iter = mAnimation->mStates.find(mAnimationName);
|
2013-05-10 11:01:30 +00:00
|
|
|
if(iter != mAnimation->mStates.end())
|
2013-05-10 10:08:07 +00:00
|
|
|
return iter->second.mTime;
|
2013-04-23 06:35:50 +00:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
void Animation::AnimationValue::setValue(Ogre::Real)
|
2013-04-23 06:35:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-07 19:41:27 +00:00
|
|
|
void Animation::destroyObjectList(Ogre::SceneManager *sceneMgr, NifOgre::ObjectList &objects)
|
|
|
|
{
|
|
|
|
for(size_t i = 0;i < objects.mParticles.size();i++)
|
|
|
|
sceneMgr->destroyParticleSystem(objects.mParticles[i]);
|
|
|
|
for(size_t i = 0;i < objects.mEntities.size();i++)
|
|
|
|
sceneMgr->destroyEntity(objects.mEntities[i]);
|
|
|
|
objects.mControllers.clear();
|
|
|
|
objects.mParticles.clear();
|
|
|
|
objects.mEntities.clear();
|
|
|
|
objects.mSkelBase = NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:05:48 +00:00
|
|
|
Animation::Animation(const MWWorld::Ptr &ptr)
|
2013-04-24 11:41:52 +00:00
|
|
|
: mPtr(ptr)
|
2013-07-13 19:39:06 +00:00
|
|
|
, mCamera(NULL)
|
2013-01-07 01:05:48 +00:00
|
|
|
, mInsert(NULL)
|
2013-04-14 23:56:35 +00:00
|
|
|
, mSkelBase(NULL)
|
2013-01-07 05:18:48 +00:00
|
|
|
, mAccumRoot(NULL)
|
2013-01-07 01:31:53 +00:00
|
|
|
, mNonAccumRoot(NULL)
|
2013-04-24 14:10:41 +00:00
|
|
|
, mNonAccumCtrl(NULL)
|
2013-04-16 01:55:28 +00:00
|
|
|
, mAccumulate(0.0f)
|
2013-02-15 10:15:39 +00:00
|
|
|
, mAnimVelocity(0.0f)
|
2013-01-19 05:40:47 +00:00
|
|
|
, mAnimSpeedMult(1.0f)
|
2012-07-13 03:12:18 +00:00
|
|
|
{
|
2013-05-10 23:33:13 +00:00
|
|
|
for(size_t i = 0;i < sNumGroups;i++)
|
|
|
|
mAnimationValuePtr[i].bind(OGRE_NEW AnimationValue(this));
|
2011-12-17 06:29:08 +00:00
|
|
|
}
|
2012-02-20 13:02:24 +00:00
|
|
|
|
2012-07-13 03:12:18 +00:00
|
|
|
Animation::~Animation()
|
|
|
|
{
|
2013-01-05 07:19:48 +00:00
|
|
|
if(mInsert)
|
|
|
|
{
|
2013-05-07 23:59:32 +00:00
|
|
|
mAnimSources.clear();
|
|
|
|
|
2013-01-05 07:19:48 +00:00
|
|
|
Ogre::SceneManager *sceneMgr = mInsert->getCreator();
|
2013-05-07 06:11:26 +00:00
|
|
|
destroyObjectList(sceneMgr, mObjectRoot);
|
2013-01-05 07:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-07 06:11:26 +00:00
|
|
|
void Animation::setObjectRoot(Ogre::SceneNode *node, const std::string &model, bool baseonly)
|
2013-02-06 00:29:51 +00:00
|
|
|
{
|
2013-07-14 12:59:24 +00:00
|
|
|
OgreAssert(mAnimSources.size() == 0, "Setting object root while animation sources are set!");
|
2013-07-09 01:59:51 +00:00
|
|
|
if(!mInsert)
|
|
|
|
mInsert = node->createChildSceneNode();
|
2013-04-15 00:58:21 +00:00
|
|
|
|
2013-05-07 23:59:32 +00:00
|
|
|
std::string mdlname = Misc::StringUtils::lowerCase(model);
|
|
|
|
std::string::size_type p = mdlname.rfind('\\');
|
|
|
|
if(p == std::string::npos)
|
|
|
|
p = mdlname.rfind('/');
|
|
|
|
if(p != std::string::npos)
|
|
|
|
mdlname.insert(mdlname.begin()+p+1, 'x');
|
|
|
|
else
|
|
|
|
mdlname.insert(mdlname.begin(), 'x');
|
|
|
|
if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(mdlname))
|
|
|
|
{
|
|
|
|
mdlname = model;
|
|
|
|
Misc::StringUtils::toLower(mdlname);
|
|
|
|
}
|
|
|
|
|
2013-07-09 01:59:51 +00:00
|
|
|
mSkelBase = NULL;
|
|
|
|
destroyObjectList(mInsert->getCreator(), mObjectRoot);
|
|
|
|
|
2013-05-07 23:59:32 +00:00
|
|
|
mObjectRoot = (!baseonly ? NifOgre::Loader::createObjects(mInsert, mdlname) :
|
|
|
|
NifOgre::Loader::createObjectBase(mInsert, mdlname));
|
2013-05-07 06:11:26 +00:00
|
|
|
if(mObjectRoot.mSkelBase)
|
2013-02-06 00:29:51 +00:00
|
|
|
{
|
2013-05-07 06:11:26 +00:00
|
|
|
mSkelBase = mObjectRoot.mSkelBase;
|
2013-04-07 20:46:29 +00:00
|
|
|
|
2013-05-07 06:11:26 +00:00
|
|
|
Ogre::AnimationStateSet *aset = mObjectRoot.mSkelBase->getAllAnimationStates();
|
2013-04-15 00:58:21 +00:00
|
|
|
Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
|
|
|
|
while(asiter.hasMoreElements())
|
2013-04-07 20:46:29 +00:00
|
|
|
{
|
2013-04-15 00:58:21 +00:00
|
|
|
Ogre::AnimationState *state = asiter.getNext();
|
|
|
|
state->setEnabled(false);
|
|
|
|
state->setLoop(false);
|
2013-04-07 20:46:29 +00:00
|
|
|
}
|
2013-02-06 00:29:51 +00:00
|
|
|
|
2013-04-15 00:58:21 +00:00
|
|
|
// Set the bones as manually controlled since we're applying the
|
2013-05-10 06:07:50 +00:00
|
|
|
// transformations manually
|
2013-05-07 06:11:26 +00:00
|
|
|
Ogre::SkeletonInstance *skelinst = mObjectRoot.mSkelBase->getSkeleton();
|
2013-04-15 00:58:21 +00:00
|
|
|
Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
|
|
|
|
while(boneiter.hasMoreElements())
|
|
|
|
boneiter.getNext()->setManuallyControlled(true);
|
2013-07-13 23:12:38 +00:00
|
|
|
|
|
|
|
// Reattach any objects that have been attached to this one
|
|
|
|
ObjectAttachMap::iterator iter = mAttachedObjects.begin();
|
|
|
|
while(iter != mAttachedObjects.end())
|
|
|
|
{
|
|
|
|
if(!skelinst->hasBone(iter->second))
|
|
|
|
mAttachedObjects.erase(iter++);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSkelBase->attachObjectToBone(iter->second, iter->first);
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 00:29:51 +00:00
|
|
|
}
|
2013-07-13 23:12:38 +00:00
|
|
|
else
|
|
|
|
mAttachedObjects.clear();
|
|
|
|
|
2013-05-07 06:11:26 +00:00
|
|
|
for(size_t i = 0;i < mObjectRoot.mControllers.size();i++)
|
2013-04-06 16:44:10 +00:00
|
|
|
{
|
2013-05-07 06:11:26 +00:00
|
|
|
if(mObjectRoot.mControllers[i].getSource().isNull())
|
2013-05-10 23:33:13 +00:00
|
|
|
mObjectRoot.mControllers[i].setSource(mAnimationValuePtr[0]);
|
2013-04-06 16:44:10 +00:00
|
|
|
}
|
2012-07-13 03:12:18 +00:00
|
|
|
}
|
2012-01-07 03:52:15 +00:00
|
|
|
|
2013-04-19 09:01:50 +00:00
|
|
|
void Animation::setRenderProperties(const NifOgre::ObjectList &objlist, Ogre::uint32 visflags, Ogre::uint8 solidqueue, Ogre::uint8 transqueue)
|
|
|
|
{
|
|
|
|
for(size_t i = 0;i < objlist.mEntities.size();i++)
|
|
|
|
{
|
|
|
|
Ogre::Entity *ent = objlist.mEntities[i];
|
|
|
|
if(visflags != 0)
|
|
|
|
ent->setVisibilityFlags(visflags);
|
|
|
|
|
|
|
|
for(unsigned int j = 0;j < ent->getNumSubEntities();++j)
|
|
|
|
{
|
|
|
|
Ogre::SubEntity* subEnt = ent->getSubEntity(j);
|
|
|
|
subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? transqueue : solidqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(size_t i = 0;i < objlist.mParticles.size();i++)
|
|
|
|
{
|
|
|
|
Ogre::ParticleSystem *part = objlist.mParticles[i];
|
|
|
|
if(visflags != 0)
|
|
|
|
part->setVisibilityFlags(visflags);
|
|
|
|
// TODO: Check particle material for actual transparency
|
|
|
|
part->setRenderQueueGroup(transqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 20:51:48 +00:00
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
size_t Animation::detectAnimGroup(const Ogre::Node *node)
|
|
|
|
{
|
2013-05-11 03:45:09 +00:00
|
|
|
static const char sGroupRoots[sNumGroups][32] = {
|
|
|
|
"", /* Lower body / character root */
|
2013-05-13 08:58:13 +00:00
|
|
|
"Bip01 Spine1", /* Torso */
|
2013-05-11 03:45:09 +00:00
|
|
|
"Bip01 L Clavicle", /* Left arm */
|
2013-05-13 08:58:13 +00:00
|
|
|
"Bip01 R Clavicle", /* Right arm */
|
2013-05-11 03:45:09 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
while(node)
|
|
|
|
{
|
|
|
|
const Ogre::String &name = node->getName();
|
2013-05-11 03:45:09 +00:00
|
|
|
for(size_t i = 1;i < sNumGroups;i++)
|
|
|
|
{
|
|
|
|
if(name == sGroupRoots[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
node = node->getParent();
|
|
|
|
}
|
2013-05-11 03:45:09 +00:00
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-07 23:59:32 +00:00
|
|
|
void Animation::addAnimSource(const std::string &model)
|
|
|
|
{
|
|
|
|
OgreAssert(mInsert, "Object is missing a root!");
|
|
|
|
if(!mSkelBase)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string kfname = Misc::StringUtils::lowerCase(model);
|
|
|
|
std::string::size_type p = kfname.rfind('\\');
|
|
|
|
if(p == std::string::npos)
|
|
|
|
p = kfname.rfind('/');
|
|
|
|
if(p != std::string::npos)
|
|
|
|
kfname.insert(kfname.begin()+p+1, 'x');
|
|
|
|
else
|
|
|
|
kfname.insert(kfname.begin(), 'x');
|
|
|
|
|
|
|
|
if(kfname.size() > 4 && kfname.compare(kfname.size()-4, 4, ".nif") == 0)
|
|
|
|
kfname.replace(kfname.size()-4, 4, ".kf");
|
|
|
|
|
|
|
|
if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(kfname))
|
|
|
|
return;
|
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
std::vector<Ogre::Controller<Ogre::Real> > ctrls;
|
2013-05-12 02:38:23 +00:00
|
|
|
Ogre::SharedPtr<AnimSource> animsrc(OGRE_NEW AnimSource);
|
|
|
|
NifOgre::Loader::createKfControllers(mSkelBase, kfname, animsrc->mTextKeys, ctrls);
|
|
|
|
if(animsrc->mTextKeys.size() == 0 || ctrls.size() == 0)
|
2013-05-07 23:59:32 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-12 02:38:23 +00:00
|
|
|
mAnimSources.push_back(animsrc);
|
2013-05-07 23:59:32 +00:00
|
|
|
|
2013-05-12 02:38:23 +00:00
|
|
|
std::vector<Ogre::Controller<Ogre::Real> > *grpctrls = animsrc->mControllers;
|
2013-05-07 23:59:32 +00:00
|
|
|
for(size_t i = 0;i < ctrls.size();i++)
|
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
NifOgre::NodeTargetValue<Ogre::Real> *dstval;
|
2013-05-07 23:59:32 +00:00
|
|
|
dstval = static_cast<NifOgre::NodeTargetValue<Ogre::Real>*>(ctrls[i].getDestination().getPointer());
|
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
size_t grp = detectAnimGroup(dstval->getNode());
|
|
|
|
|
|
|
|
if(!mAccumRoot && grp == 0)
|
2013-05-07 23:59:32 +00:00
|
|
|
{
|
|
|
|
mAccumRoot = mInsert;
|
|
|
|
mNonAccumRoot = dstval->getNode();
|
|
|
|
}
|
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
ctrls[i].setSource(mAnimationValuePtr[grp]);
|
|
|
|
grpctrls[grp].push_back(ctrls[i]);
|
2013-05-07 23:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::clearAnimSources()
|
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
mStates.clear();
|
2013-05-10 10:08:07 +00:00
|
|
|
|
2013-05-10 23:33:13 +00:00
|
|
|
for(size_t i = 0;i < sNumGroups;i++)
|
|
|
|
mAnimationValuePtr[i]->setAnimName(std::string());
|
2013-05-10 10:08:07 +00:00
|
|
|
|
2013-05-07 23:59:32 +00:00
|
|
|
mNonAccumCtrl = NULL;
|
|
|
|
mAnimVelocity = 0.0f;
|
|
|
|
|
|
|
|
mAccumRoot = NULL;
|
|
|
|
mNonAccumRoot = NULL;
|
|
|
|
|
|
|
|
mAnimSources.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-08 12:48:52 +00:00
|
|
|
Ogre::Node *Animation::getNode(const std::string &name)
|
|
|
|
{
|
2013-04-14 23:56:35 +00:00
|
|
|
if(mSkelBase)
|
2013-04-08 12:48:52 +00:00
|
|
|
{
|
2013-04-14 23:56:35 +00:00
|
|
|
Ogre::SkeletonInstance *skel = mSkelBase->getSkeleton();
|
2013-04-08 12:48:52 +00:00
|
|
|
if(skel->hasBone(name))
|
|
|
|
return skel->getBone(name);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 03:59:55 +00:00
|
|
|
NifOgre::TextKeyMap::const_iterator Animation::findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname)
|
|
|
|
{
|
|
|
|
NifOgre::TextKeyMap::const_iterator iter(keys.begin());
|
|
|
|
for(;iter != keys.end();iter++)
|
|
|
|
{
|
|
|
|
if(iter->second.compare(0, groupname.size(), groupname) == 0 &&
|
|
|
|
iter->second.compare(groupname.size(), 2, ": ") == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-20 05:55:04 +00:00
|
|
|
bool Animation::hasAnimation(const std::string &anim)
|
2013-01-16 23:00:06 +00:00
|
|
|
{
|
2013-05-07 23:59:32 +00:00
|
|
|
AnimSourceList::const_iterator iter(mAnimSources.begin());
|
|
|
|
for(;iter != mAnimSources.end();iter++)
|
2013-02-06 00:29:51 +00:00
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
const NifOgre::TextKeyMap &keys = (*iter)->mTextKeys;
|
2013-04-23 03:59:55 +00:00
|
|
|
if(findGroupStart(keys, anim) != keys.end())
|
2013-02-06 00:29:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-05-07 06:11:26 +00:00
|
|
|
|
2013-02-06 00:29:51 +00:00
|
|
|
return false;
|
2013-01-16 23:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-18 22:25:32 +00:00
|
|
|
void Animation::setAccumulation(const Ogre::Vector3 &accum)
|
|
|
|
{
|
|
|
|
mAccumulate = accum;
|
|
|
|
}
|
|
|
|
|
2013-02-15 10:15:39 +00:00
|
|
|
void Animation::setSpeed(float speed)
|
|
|
|
{
|
|
|
|
mAnimSpeedMult = 1.0f;
|
2013-05-12 11:29:42 +00:00
|
|
|
if(speed > 0.0f && mAnimVelocity > 1.0f)
|
2013-02-15 10:15:39 +00:00
|
|
|
mAnimSpeedMult = speed / mAnimVelocity;
|
|
|
|
}
|
|
|
|
|
2013-02-19 12:01:33 +00:00
|
|
|
|
2013-02-23 18:12:36 +00:00
|
|
|
void Animation::updatePtr(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
|
|
|
mPtr = ptr;
|
|
|
|
}
|
|
|
|
|
2013-01-18 22:25:32 +00:00
|
|
|
|
2013-04-25 05:45:43 +00:00
|
|
|
float Animation::calcAnimVelocity(const NifOgre::TextKeyMap &keys, NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl, const Ogre::Vector3 &accum, const std::string &groupname)
|
2013-02-22 17:22:06 +00:00
|
|
|
{
|
2013-04-23 04:34:39 +00:00
|
|
|
const std::string start = groupname+": start";
|
2013-04-22 11:10:46 +00:00
|
|
|
const std::string loopstart = groupname+": loop start";
|
|
|
|
const std::string loopstop = groupname+": loop stop";
|
2013-04-23 04:34:39 +00:00
|
|
|
const std::string stop = groupname+": stop";
|
|
|
|
float starttime = std::numeric_limits<float>::max();
|
|
|
|
float stoptime = 0.0f;
|
|
|
|
NifOgre::TextKeyMap::const_iterator keyiter(keys.begin());
|
2013-04-23 03:41:54 +00:00
|
|
|
while(keyiter != keys.end())
|
2013-02-22 17:22:06 +00:00
|
|
|
{
|
2013-04-23 04:34:39 +00:00
|
|
|
if(keyiter->second == start || keyiter->second == loopstart)
|
|
|
|
starttime = keyiter->first;
|
|
|
|
else if(keyiter->second == loopstop || keyiter->second == stop)
|
2013-02-22 17:22:06 +00:00
|
|
|
{
|
2013-04-23 04:34:39 +00:00
|
|
|
stoptime = keyiter->first;
|
2013-04-22 11:10:46 +00:00
|
|
|
break;
|
2013-02-22 17:22:06 +00:00
|
|
|
}
|
2013-04-22 11:10:46 +00:00
|
|
|
keyiter++;
|
|
|
|
}
|
2013-02-22 17:22:06 +00:00
|
|
|
|
2013-04-23 04:34:39 +00:00
|
|
|
if(stoptime > starttime)
|
2013-04-22 11:10:46 +00:00
|
|
|
{
|
2013-04-25 05:45:43 +00:00
|
|
|
Ogre::Vector3 startpos = nonaccumctrl->getTranslation(starttime) * accum;
|
|
|
|
Ogre::Vector3 endpos = nonaccumctrl->getTranslation(stoptime) * accum;
|
2013-02-22 17:22:06 +00:00
|
|
|
|
2013-05-12 11:29:42 +00:00
|
|
|
return startpos.distance(endpos) / (stoptime - starttime);
|
2013-02-22 17:22:06 +00:00
|
|
|
}
|
2013-04-22 08:40:41 +00:00
|
|
|
|
|
|
|
return 0.0f;
|
2013-02-22 17:22:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-20 10:32:48 +00:00
|
|
|
static void updateBoneTree(const Ogre::SkeletonInstance *skelsrc, Ogre::Bone *bone)
|
2013-01-30 17:29:16 +00:00
|
|
|
{
|
2013-02-20 10:32:48 +00:00
|
|
|
if(skelsrc->hasBone(bone->getName()))
|
2013-01-30 17:29:16 +00:00
|
|
|
{
|
|
|
|
Ogre::Bone *srcbone = skelsrc->getBone(bone->getName());
|
2013-02-20 10:32:48 +00:00
|
|
|
if(!srcbone->getParent() || !bone->getParent())
|
|
|
|
{
|
|
|
|
bone->setOrientation(srcbone->getOrientation());
|
|
|
|
bone->setPosition(srcbone->getPosition());
|
|
|
|
bone->setScale(srcbone->getScale());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bone->_setDerivedOrientation(srcbone->_getDerivedOrientation());
|
|
|
|
bone->_setDerivedPosition(srcbone->_getDerivedPosition());
|
|
|
|
bone->setScale(Ogre::Vector3::UNIT_SCALE);
|
|
|
|
}
|
2013-01-30 17:29:16 +00:00
|
|
|
}
|
2013-02-20 10:32:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// No matching bone in the source. Make sure it stays properly offset
|
|
|
|
// from its parent.
|
|
|
|
bone->resetToInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Node::ChildNodeIterator boneiter = bone->getChildIterator();
|
|
|
|
while(boneiter.hasMoreElements())
|
|
|
|
updateBoneTree(skelsrc, static_cast<Ogre::Bone*>(boneiter.getNext()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel)
|
|
|
|
{
|
|
|
|
Ogre::Skeleton::BoneIterator boneiter = skel->getRootBoneIterator();
|
|
|
|
while(boneiter.hasMoreElements())
|
|
|
|
updateBoneTree(skelsrc, boneiter.getNext());
|
2013-01-30 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 15:04:18 +00:00
|
|
|
|
2013-05-11 01:58:14 +00:00
|
|
|
void Animation::updatePosition(float oldtime, float newtime, Ogre::Vector3 &position)
|
2013-01-07 05:18:48 +00:00
|
|
|
{
|
2013-04-24 08:57:51 +00:00
|
|
|
/* Get the non-accumulation root's difference from the last update, and move the position
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2013-05-11 01:58:14 +00:00
|
|
|
Ogre::Vector3 off = mNonAccumCtrl->getTranslation(newtime)*mAccumulate;
|
|
|
|
position += off - mNonAccumCtrl->getTranslation(oldtime)*mAccumulate;
|
2013-04-07 23:21:45 +00:00
|
|
|
|
|
|
|
/* Translate the accumulation root back to compensate for the move. */
|
2013-05-11 01:58:14 +00:00
|
|
|
mAccumRoot->setPosition(-off);
|
2013-01-07 05:18:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint)
|
2013-01-07 05:18:48 +00:00
|
|
|
{
|
2013-04-23 03:41:54 +00:00
|
|
|
std::string tag = groupname+": "+start;
|
|
|
|
NifOgre::TextKeyMap::const_iterator startkey(keys.begin());
|
|
|
|
while(startkey != keys.end() && startkey->second != tag)
|
|
|
|
startkey++;
|
2013-04-24 07:40:58 +00:00
|
|
|
if(startkey == keys.end() && start == "loop start")
|
2013-01-09 11:30:55 +00:00
|
|
|
{
|
2013-04-23 03:41:54 +00:00
|
|
|
tag = groupname+": start";
|
|
|
|
startkey = keys.begin();
|
|
|
|
while(startkey != keys.end() && startkey->second != tag)
|
|
|
|
startkey++;
|
2013-01-09 11:30:55 +00:00
|
|
|
}
|
2013-04-23 03:41:54 +00:00
|
|
|
if(startkey == keys.end())
|
|
|
|
return false;
|
2013-04-22 12:08:52 +00:00
|
|
|
|
2013-04-23 03:41:54 +00:00
|
|
|
tag = groupname+": "+stop;
|
|
|
|
NifOgre::TextKeyMap::const_iterator stopkey(startkey);
|
|
|
|
while(stopkey != keys.end() && stopkey->second != tag)
|
|
|
|
stopkey++;
|
|
|
|
if(stopkey == keys.end())
|
|
|
|
return false;
|
2013-04-22 12:08:52 +00:00
|
|
|
|
2013-04-23 03:41:54 +00:00
|
|
|
if(startkey == stopkey)
|
|
|
|
return false;
|
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mStartKey = startkey;
|
|
|
|
state.mLoopStartKey = startkey;
|
|
|
|
state.mStopKey = stopkey;
|
|
|
|
state.mNextKey = startkey;
|
2013-01-09 11:30:55 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mTime = state.mStartKey->first + ((state.mStopKey->first - state.mStartKey->first) * startpoint);
|
2013-04-25 02:09:36 +00:00
|
|
|
|
|
|
|
tag = groupname+": loop start";
|
2013-05-10 11:01:30 +00:00
|
|
|
while(state.mNextKey->first <= state.mTime && state.mNextKey != state.mStopKey)
|
2013-04-25 02:09:36 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
if(state.mNextKey->second == tag)
|
|
|
|
state.mLoopStartKey = state.mNextKey;
|
|
|
|
state.mNextKey++;
|
2013-04-25 02:09:36 +00:00
|
|
|
}
|
2013-04-23 03:41:54 +00:00
|
|
|
|
|
|
|
return true;
|
2013-04-22 12:08:52 +00:00
|
|
|
}
|
2013-02-23 13:15:10 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
bool Animation::doLoop(AnimState &state)
|
2013-04-22 12:08:52 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
if(state.mLoopCount == 0)
|
2013-04-24 11:56:39 +00:00
|
|
|
return false;
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mLoopCount--;
|
2013-04-24 11:56:39 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mTime = state.mLoopStartKey->first;
|
|
|
|
state.mNextKey = state.mLoopStartKey;
|
|
|
|
state.mNextKey++;
|
|
|
|
state.mPlaying = true;
|
2013-04-24 11:56:39 +00:00
|
|
|
|
|
|
|
return true;
|
2012-07-24 20:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
bool Animation::handleTextKey(AnimState &state, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key)
|
2013-02-23 22:39:01 +00:00
|
|
|
{
|
2013-04-22 12:08:52 +00:00
|
|
|
float time = key->first;
|
|
|
|
const std::string &evt = key->second;
|
|
|
|
|
2013-02-23 22:39:01 +00:00
|
|
|
if(evt.compare(0, 7, "sound: ") == 0)
|
|
|
|
{
|
|
|
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
|
|
|
sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(evt.compare(0, 10, "soundgen: ") == 0)
|
|
|
|
{
|
|
|
|
// FIXME: Lookup the SoundGen (SNDG) for the specified sound that corresponds
|
|
|
|
// to this actor type
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-10 10:08:07 +00:00
|
|
|
if(evt.compare(0, groupname.size(), groupname) != 0 ||
|
|
|
|
evt.compare(groupname.size(), 2, ": ") != 0)
|
2013-04-22 05:13:49 +00:00
|
|
|
{
|
2013-04-23 06:35:50 +00:00
|
|
|
// Not ours, skip it
|
2013-04-22 05:13:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-05-10 10:08:07 +00:00
|
|
|
size_t off = groupname.size()+2;
|
2013-04-22 05:13:49 +00:00
|
|
|
size_t len = evt.size() - off;
|
|
|
|
|
|
|
|
if(evt.compare(off, len, "start") == 0 || evt.compare(off, len, "loop start") == 0)
|
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mLoopStartKey = key;
|
2013-04-22 05:13:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:48:34 +00:00
|
|
|
if(evt.compare(off, len, "loop stop") == 0 || evt.compare(off, len, "stop") == 0)
|
2013-04-24 13:32:11 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
if(doLoop(state))
|
2013-04-24 13:32:11 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
if(state.mTime >= time)
|
2013-04-24 13:32:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-24 13:48:34 +00:00
|
|
|
|
2013-05-13 10:32:00 +00:00
|
|
|
if(evt.compare(off, len, "equip attach") == 0)
|
|
|
|
{
|
|
|
|
showWeapons(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(evt.compare(off, len, "unequip detach") == 0)
|
|
|
|
{
|
|
|
|
showWeapons(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-13 08:58:13 +00:00
|
|
|
/* Nothing to do for these */
|
|
|
|
if(evt.compare(off, len, "equip start") == 0 || evt.compare(off, len, "equip stop") == 0 ||
|
|
|
|
evt.compare(off, len, "unequip start") == 0 || evt.compare(off, len, "unequip stop") == 0)
|
|
|
|
return true;
|
|
|
|
|
2013-04-24 13:48:34 +00:00
|
|
|
std::cerr<< "Unhandled animation textkey: "<<evt <<std::endl;
|
2013-02-23 22:39:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-16 07:43:31 +00:00
|
|
|
void Animation::play(const std::string &groupname, int priority, int groups, bool autodisable, float speedmult, const std::string &start, const std::string &stop, float startpoint, size_t loops)
|
2012-07-13 03:12:18 +00:00
|
|
|
{
|
2013-05-11 01:37:44 +00:00
|
|
|
if(!mSkelBase)
|
2013-05-12 11:29:42 +00:00
|
|
|
return;
|
2013-04-25 07:52:26 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
if(groupname.empty())
|
2013-05-12 11:29:42 +00:00
|
|
|
{
|
|
|
|
resetActiveGroups();
|
|
|
|
return;
|
|
|
|
}
|
2013-05-11 01:37:44 +00:00
|
|
|
|
2013-05-13 07:54:44 +00:00
|
|
|
priority = std::max(0, priority);
|
|
|
|
|
2013-05-11 03:45:09 +00:00
|
|
|
AnimStateMap::iterator stateiter = mStates.begin();
|
|
|
|
while(stateiter != mStates.end())
|
|
|
|
{
|
|
|
|
if(stateiter->second.mPriority == priority)
|
|
|
|
mStates.erase(stateiter++);
|
|
|
|
else
|
|
|
|
stateiter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
stateiter = mStates.find(groupname);
|
2013-05-10 11:01:30 +00:00
|
|
|
if(stateiter != mStates.end())
|
2013-05-11 01:37:44 +00:00
|
|
|
{
|
|
|
|
stateiter->second.mPriority = priority;
|
2013-05-12 11:29:42 +00:00
|
|
|
resetActiveGroups();
|
|
|
|
return;
|
2013-05-11 01:37:44 +00:00
|
|
|
}
|
2013-05-01 02:26:41 +00:00
|
|
|
|
2013-04-23 10:42:00 +00:00
|
|
|
/* Look in reverse; last-inserted source has priority. */
|
2013-05-07 23:59:32 +00:00
|
|
|
AnimSourceList::reverse_iterator iter(mAnimSources.rbegin());
|
|
|
|
for(;iter != mAnimSources.rend();iter++)
|
|
|
|
{
|
2013-05-11 01:37:44 +00:00
|
|
|
AnimState state;
|
2013-05-12 02:38:23 +00:00
|
|
|
if(reset(state, (*iter)->mTextKeys, groupname, start, stop, startpoint))
|
2013-02-06 00:29:51 +00:00
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
state.mSource = *iter;
|
2013-07-16 07:43:31 +00:00
|
|
|
state.mSpeedMult = speedmult;
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mLoopCount = loops;
|
|
|
|
state.mPlaying = true;
|
2013-05-11 01:37:44 +00:00
|
|
|
state.mPriority = priority;
|
2013-05-11 03:05:09 +00:00
|
|
|
state.mGroups = groups;
|
2013-05-11 05:22:39 +00:00
|
|
|
state.mAutoDisable = autodisable;
|
2013-05-10 11:01:30 +00:00
|
|
|
mStates[groupname] = state;
|
2013-04-23 03:41:54 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(iter == mAnimSources.rend())
|
|
|
|
std::cerr<< "Failed to find animation "<<groupname <<std::endl;
|
2013-04-22 11:10:46 +00:00
|
|
|
|
2013-05-12 11:29:42 +00:00
|
|
|
resetActiveGroups();
|
2013-05-11 01:37:44 +00:00
|
|
|
}
|
2013-04-25 05:45:43 +00:00
|
|
|
|
2013-05-12 12:08:01 +00:00
|
|
|
bool Animation::isPlaying(const std::string &groupname) const
|
|
|
|
{
|
|
|
|
AnimStateMap::const_iterator state(mStates.find(groupname));
|
|
|
|
if(state != mStates.end())
|
|
|
|
return state->second.mPlaying;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-12 11:29:42 +00:00
|
|
|
void Animation::resetActiveGroups()
|
2013-05-11 01:37:44 +00:00
|
|
|
{
|
|
|
|
for(size_t grp = 0;grp < sNumGroups;grp++)
|
|
|
|
{
|
|
|
|
AnimStateMap::const_iterator active = mStates.end();
|
|
|
|
|
|
|
|
AnimStateMap::const_iterator state = mStates.begin();
|
|
|
|
for(;state != mStates.end();state++)
|
|
|
|
{
|
|
|
|
if(!(state->second.mGroups&(1<<grp)))
|
|
|
|
continue;
|
2013-05-11 03:05:09 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
if(active == mStates.end() || active->second.mPriority < state->second.mPriority)
|
|
|
|
active = state;
|
2013-04-23 10:42:00 +00:00
|
|
|
}
|
2013-04-22 08:40:41 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
mAnimationValuePtr[grp]->setAnimName((active == mStates.end()) ?
|
|
|
|
std::string() : active->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
mNonAccumCtrl = NULL;
|
|
|
|
mAnimVelocity = 0.0f;
|
2013-04-22 08:40:41 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
if(!mNonAccumRoot || mAccumulate == Ogre::Vector3(0.0f))
|
2013-05-12 11:29:42 +00:00
|
|
|
return;
|
2013-05-11 01:37:44 +00:00
|
|
|
|
|
|
|
AnimStateMap::const_iterator state = mStates.find(mAnimationValuePtr[0]->getAnimName());
|
|
|
|
if(state == mStates.end())
|
2013-05-12 11:29:42 +00:00
|
|
|
return;
|
2013-05-11 01:37:44 +00:00
|
|
|
|
2013-05-12 02:38:23 +00:00
|
|
|
const Ogre::SharedPtr<AnimSource> &animsrc = state->second.mSource;
|
2013-05-11 02:31:33 +00:00
|
|
|
const NifOgre::TextKeyMap &keys = animsrc->mTextKeys;
|
|
|
|
const std::vector<Ogre::Controller<Ogre::Real> >&ctrls = animsrc->mControllers[0];
|
2013-05-11 01:37:44 +00:00
|
|
|
for(size_t i = 0;i < ctrls.size();i++)
|
|
|
|
{
|
|
|
|
NifOgre::NodeTargetValue<Ogre::Real> *dstval;
|
|
|
|
dstval = static_cast<NifOgre::NodeTargetValue<Ogre::Real>*>(ctrls[i].getDestination().getPointer());
|
|
|
|
if(dstval->getNode() == mNonAccumRoot)
|
2013-04-25 05:45:43 +00:00
|
|
|
{
|
2013-05-11 01:37:44 +00:00
|
|
|
mAnimVelocity = calcAnimVelocity(keys, dstval, mAccumulate, state->first);
|
|
|
|
mNonAccumCtrl = dstval;
|
2013-04-25 05:45:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-07 23:59:32 +00:00
|
|
|
}
|
2013-04-23 10:42:00 +00:00
|
|
|
|
2013-05-11 02:31:33 +00:00
|
|
|
// If there's no velocity, keep looking
|
2013-05-12 02:38:23 +00:00
|
|
|
if(!(mAnimVelocity > 1.0f))
|
2013-05-11 02:31:33 +00:00
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
AnimSourceList::const_reverse_iterator animiter = mAnimSources.rbegin();
|
|
|
|
while(*animiter != animsrc)
|
|
|
|
++animiter;
|
|
|
|
|
|
|
|
while(!(mAnimVelocity > 1.0f) && ++animiter != mAnimSources.rend())
|
2013-05-11 02:31:33 +00:00
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
const NifOgre::TextKeyMap &keys = (*animiter)->mTextKeys;
|
|
|
|
const std::vector<Ogre::Controller<Ogre::Real> >&ctrls = (*animiter)->mControllers[0];
|
|
|
|
for(size_t i = 0;i < ctrls.size();i++)
|
2013-05-11 02:31:33 +00:00
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
NifOgre::NodeTargetValue<Ogre::Real> *dstval;
|
|
|
|
dstval = static_cast<NifOgre::NodeTargetValue<Ogre::Real>*>(ctrls[i].getDestination().getPointer());
|
|
|
|
if(dstval->getNode() == mNonAccumRoot)
|
|
|
|
{
|
|
|
|
mAnimVelocity = calcAnimVelocity(keys, dstval, mAccumulate, state->first);
|
|
|
|
break;
|
|
|
|
}
|
2013-05-11 02:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-24 20:51:48 +00:00
|
|
|
}
|
2011-12-15 05:33:10 +00:00
|
|
|
|
2013-05-11 01:37:44 +00:00
|
|
|
|
2013-07-16 07:43:31 +00:00
|
|
|
bool Animation::getInfo(const std::string &groupname, float *complete, float *speedmult, std::string *start, std::string *stop) const
|
2013-04-25 07:03:27 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
AnimStateMap::const_iterator iter = mStates.find(groupname);
|
|
|
|
if(iter == mStates.end())
|
2013-04-25 07:03:27 +00:00
|
|
|
{
|
|
|
|
if(complete) *complete = 0.0f;
|
2013-07-16 07:43:31 +00:00
|
|
|
if(speedmult) *speedmult = 0.0f;
|
2013-04-25 07:03:27 +00:00
|
|
|
if(start) *start = "";
|
|
|
|
if(stop) *stop = "";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-10 10:08:07 +00:00
|
|
|
if(complete) *complete = (iter->second.mTime - iter->second.mStartKey->first) /
|
|
|
|
(iter->second.mStopKey->first - iter->second.mStartKey->first);
|
2013-07-16 07:43:31 +00:00
|
|
|
if(speedmult) *speedmult = iter->second.mSpeedMult;
|
2013-05-10 10:08:07 +00:00
|
|
|
if(start) *start = iter->second.mStartKey->second.substr(groupname.size()+2);
|
|
|
|
if(stop) *stop = iter->second.mStopKey->second.substr(groupname.size()+2);
|
2013-04-25 07:03:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-12 11:29:42 +00:00
|
|
|
void Animation::disable(const std::string &groupname)
|
2013-05-11 05:22:39 +00:00
|
|
|
{
|
|
|
|
AnimStateMap::iterator iter = mStates.find(groupname);
|
|
|
|
if(iter != mStates.end())
|
|
|
|
mStates.erase(iter);
|
2013-05-12 11:29:42 +00:00
|
|
|
resetActiveGroups();
|
2013-05-11 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 06:35:50 +00:00
|
|
|
Ogre::Vector3 Animation::runAnimation(float duration)
|
2012-07-21 21:41:26 +00:00
|
|
|
{
|
2013-04-09 22:10:14 +00:00
|
|
|
Ogre::Vector3 movement(0.0f);
|
2013-01-30 15:04:18 +00:00
|
|
|
|
2013-04-23 06:35:50 +00:00
|
|
|
duration *= mAnimSpeedMult;
|
2013-05-10 11:01:30 +00:00
|
|
|
AnimStateMap::iterator stateiter = mStates.begin();
|
2013-05-11 05:22:39 +00:00
|
|
|
while(stateiter != mStates.end())
|
2012-07-21 21:41:26 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
AnimState &state = stateiter->second;
|
2013-07-16 07:43:31 +00:00
|
|
|
float timepassed = duration * state.mSpeedMult;
|
2013-05-10 11:01:30 +00:00
|
|
|
while(state.mPlaying)
|
2012-07-24 20:51:48 +00:00
|
|
|
{
|
2013-05-10 11:01:30 +00:00
|
|
|
float targetTime = state.mTime + timepassed;
|
|
|
|
if(state.mNextKey->first > targetTime)
|
2013-04-23 06:35:50 +00:00
|
|
|
{
|
2013-05-11 01:37:44 +00:00
|
|
|
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
2013-05-11 01:58:14 +00:00
|
|
|
updatePosition(state.mTime, targetTime, movement);
|
|
|
|
state.mTime = targetTime;
|
2013-04-23 06:35:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-21 21:41:26 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
NifOgre::TextKeyMap::const_iterator key(state.mNextKey++);
|
2013-05-11 01:37:44 +00:00
|
|
|
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
2013-05-11 01:58:14 +00:00
|
|
|
updatePosition(state.mTime, key->first, movement);
|
|
|
|
state.mTime = key->first;
|
2013-04-16 03:37:10 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
state.mPlaying = (key != state.mStopKey);
|
|
|
|
timepassed = targetTime - state.mTime;
|
2013-01-18 22:50:55 +00:00
|
|
|
|
2013-05-10 11:01:30 +00:00
|
|
|
if(!handleTextKey(state, stateiter->first, key))
|
2013-04-23 06:35:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-11 05:22:39 +00:00
|
|
|
|
|
|
|
if(!state.mPlaying && state.mAutoDisable)
|
2013-05-12 11:34:37 +00:00
|
|
|
{
|
2013-05-11 05:22:39 +00:00
|
|
|
mStates.erase(stateiter++);
|
2013-05-12 11:34:37 +00:00
|
|
|
resetActiveGroups();
|
|
|
|
}
|
2013-05-11 05:22:39 +00:00
|
|
|
else
|
|
|
|
stateiter++;
|
2012-07-21 21:41:26 +00:00
|
|
|
}
|
2013-04-16 01:55:28 +00:00
|
|
|
|
2013-05-07 06:11:26 +00:00
|
|
|
for(size_t i = 0;i < mObjectRoot.mControllers.size();i++)
|
|
|
|
mObjectRoot.mControllers[i].update();
|
2013-05-10 23:33:13 +00:00
|
|
|
|
|
|
|
// Apply group controllers
|
|
|
|
for(size_t grp = 0;grp < sNumGroups;grp++)
|
2013-05-07 23:59:32 +00:00
|
|
|
{
|
2013-05-10 23:33:13 +00:00
|
|
|
const std::string &name = mAnimationValuePtr[grp]->getAnimName();
|
|
|
|
if(!name.empty() && (stateiter=mStates.find(name)) != mStates.end())
|
|
|
|
{
|
2013-05-12 02:38:23 +00:00
|
|
|
const Ogre::SharedPtr<AnimSource> &src = stateiter->second.mSource;
|
2013-05-10 23:33:13 +00:00
|
|
|
for(size_t i = 0;i < src->mControllers[grp].size();i++)
|
|
|
|
src->mControllers[grp][i].update();
|
|
|
|
}
|
2013-05-07 23:59:32 +00:00
|
|
|
}
|
2013-04-23 10:42:00 +00:00
|
|
|
|
2013-04-14 23:56:35 +00:00
|
|
|
if(mSkelBase)
|
2013-04-07 23:21:45 +00:00
|
|
|
{
|
2013-05-07 06:11:26 +00:00
|
|
|
// HACK: Dirty the animation state set so that Ogre will apply the
|
|
|
|
// transformations to entities this skeleton instance is shared with.
|
|
|
|
mSkelBase->getAllAnimationStates()->_notifyDirty();
|
2013-04-07 23:21:45 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 00:21:29 +00:00
|
|
|
return movement;
|
2012-07-21 21:41:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 06:11:26 +00:00
|
|
|
void Animation::showWeapons(bool showWeapon)
|
|
|
|
{
|
|
|
|
}
|
2013-04-28 10:41:01 +00:00
|
|
|
|
2013-05-19 16:40:37 +00:00
|
|
|
bool Animation::isPriorityActive(int priority) const
|
|
|
|
{
|
|
|
|
for (AnimStateMap::const_iterator it = mStates.begin(); it != mStates.end(); ++it)
|
|
|
|
if (it->second.mPriority == priority)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-13 23:12:38 +00:00
|
|
|
Ogre::TagPoint *Animation::attachObjectToBone(const Ogre::String &bonename, Ogre::MovableObject *obj)
|
|
|
|
{
|
|
|
|
Ogre::TagPoint *tag = NULL;
|
|
|
|
Ogre::SkeletonInstance *skel = (mSkelBase ? mSkelBase->getSkeleton() : NULL);
|
|
|
|
if(skel && skel->hasBone(bonename))
|
|
|
|
{
|
|
|
|
tag = mSkelBase->attachObjectToBone(bonename, obj);
|
|
|
|
mAttachedObjects[obj] = bonename;
|
|
|
|
}
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::detachObjectFromBone(Ogre::MovableObject *obj)
|
|
|
|
{
|
|
|
|
ObjectAttachMap::iterator iter = mAttachedObjects.find(obj);
|
|
|
|
if(iter != mAttachedObjects.end())
|
|
|
|
mAttachedObjects.erase(iter);
|
|
|
|
mSkelBase->detachObjectFromBone(obj);
|
|
|
|
}
|
|
|
|
|
2012-02-20 13:02:24 +00:00
|
|
|
}
|