From 42e7ff9b131a25755f1e75d04b7bf917bbcda7d6 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 28 Dec 2011 21:52:05 -0500 Subject: [PATCH] Introducing loops; SkipAnim; Skeleton reset bug fixed --- apps/openmw/mwrender/actors.cpp | 3 ++- apps/openmw/mwrender/animation.cpp | 5 ++++- apps/openmw/mwrender/animation.hpp | 6 ++++-- apps/openmw/mwrender/creatureanimation.cpp | 13 ++++++++----- apps/openmw/mwrender/npcanimation.cpp | 14 ++++++++++++-- apps/openmw/mwrender/npcanimation.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 1 + 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 937bf96b0..3b94b19f7 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -118,7 +118,8 @@ void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& gro mAllActors[ptr]->startScript(groupName, mode, number); } void Actors::skipAnimation (const MWWorld::Ptr& ptr){ - + if(mAllActors.find(ptr) != mAllActors.end()) + mAllActors[ptr]->stopScript(); } void Actors::addTime(){ //std::cout << "Adding time in actors\n"; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 93025ae09..7f59bc7d1 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -30,11 +30,14 @@ namespace MWRender{ //Set the start time and stop time //How many times to loop if(groupname == "all"){ - animate = true; + animate = loops; time = startTime; } } + void Animation::stopScript(){ + animate = 0; + } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ shapeNumber = 0; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d97ccbe29..65f872e0a 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -18,12 +18,13 @@ class Animation{ OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; static std::map mUniqueIDs; + std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc float time; float startTime; float stopTime; bool loop; - bool animate; + int animate; //Represents a rotation index for each bone std::vectorrindexI; //Represents a translation index for each bone @@ -49,9 +50,10 @@ class Animation{ std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(false){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(0){}; virtual void runAnimation(float timepassed) = 0; void startScript(std::string groupname, int mode, int loops); + void stopScript(); ~Animation(); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 2829c7ea1..fe717a9f3 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -42,17 +42,20 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme } void CreatureAnimation::runAnimation(float timepassed){ - if(animate){ + 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 time += timepassed; - if(time > transformations->begin()->getStopTime()){ - animate = false; - std::cout << "Stopping the animation\n"; - return; + if(time > stopTime){ + animate--; + //std::cout << "Stopping the animation\n"; + if(animate == 0) + time = stopTime; + else + time = startTime + (time - stopTime); } handleAnimationTransforms(); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c1c3ea680..297aa2484 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -56,6 +56,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O NifOgre::NIFLoader::load(smodel); base = mRend.getScene()->createEntity(smodel); + base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones + //stay in the same place when we skipanim, or open a gui window if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ @@ -226,10 +228,17 @@ void NpcAnimation::runAnimation(float timepassed){ //Handle the animation transforms dependent on time //Handle the shapes dependent on animation transforms - if(animate){ + if(animate > 0){ time += timepassed; - + if(time > stopTime){ + animate--; + //std::cout << "Stopping the animation\n"; + if(animate == 0) + time = stopTime; + else + time = startTime + (time - stopTime); + } handleAnimationTransforms(); // handleAnimationTransforms(base); @@ -252,5 +261,6 @@ void NpcAnimation::runAnimation(float timepassed){ entitypartsiter++; } } + } } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index ef9bef29f..edc0648ef 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -17,7 +17,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ Ogre::SceneNode* insert; - std::vector* > shapeparts; //All the NiTriShape data that we need for animating this particular npc + public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); ~NpcAnimation(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 235606b5c..ae2e0f791 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -240,6 +240,7 @@ std::cout<<"play animation " << groupName << ", " << mode << ", " << number << s void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { std::cout<<"skip animation"<