diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3ab4993963..5d235b5d1a 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -135,6 +135,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) mEnvironment.mWorld->advanceTime ( mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600); + if (changed) // keep change flag for another frame, if cell changed happend in local script mEnvironment.mWorld->markCellAsUnchanged(); diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 38ed3a2b33..6f479d8778 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -111,4 +111,18 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ } } -} \ No newline at end of file +} + +void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number){ + mAllActors.find(ptr)->second->startScript(groupName, mode, number); +} +void Actors::skipAnimation (const MWWorld::Ptr& ptr){ + +} +void Actors::addTime(){ + //std::cout << "Adding time in actors\n"; + for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++) + { + (iter->second)->runAnimation(mEnvironment.mFrameDuration); + } +} diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 5a26ed9bb0..be6486fd71 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -38,6 +38,20 @@ namespace MWRender{ ///< \return found? void removeCell(MWWorld::Ptr::CellStore* store); + + void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + int number = 1); + ///< Run animation for a MW-reference. Calls to this function for references that are currently not + /// in the rendered scene should be ignored. + /// + /// \param mode: 0 normal, 1 immediate start, 2 immediate loop + /// \param number How offen the animation should be run + + void skipAnimation (const MWWorld::Ptr& ptr); + ///< Skip the animation for the given MW-reference for one frame. Calls to this function for + /// references that are currently not in the rendered scene should be ignored. + + void addTime(); }; } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3b5b58e7f7..9ec88501f3 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -3,8 +3,10 @@ namespace MWRender{ std::map Animation::mUniqueIDs; + Animation::~Animation(){ } + std::string Animation::getUniqueID(std::string mesh){ int counter; if(mUniqueIDs.find(mesh) == mUniqueIDs.end()){ @@ -27,6 +29,11 @@ namespace MWRender{ //If groupname is recognized set animate to true //Set the start time and stop time //How many times to loop + if(groupname == "all"){ + animate = true; + time = startTime; + } + } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ @@ -35,7 +42,7 @@ namespace MWRender{ for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) { - Nif::NiTriShapeCopy copy = *allshapesiter; + Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector allvertices = copy.vertices; std::vector allnormals = copy.normals; @@ -133,6 +140,7 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; + //std::cout << "Vertex" << vertices[verIndex] << "\n"; } @@ -147,6 +155,7 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; + std::cout << "We are actually 2\n"; //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; } @@ -194,8 +203,8 @@ namespace MWRender{ Ogre::Vector3 transmult; Ogre::Quaternion rotmult; float scale; - if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ - Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(*boneSequenceIter); + if(skel->hasBone(*boneSequenceIter)){ + Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); @@ -327,11 +336,7 @@ namespace MWRender{ } void Animation::handleAnimationTransforms(){ - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick - skel->getManualBonesDirty(); - skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + std::vector::iterator iter; int slot = 0; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c9c4d7d167..c97401f73d 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -49,6 +49,19 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the animation transforms dependent on time //Handle the shapes dependent on animation transforms + time += timepassed; + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); + + handleAnimationTransforms(); + handleShapes(shapes, base, skel); } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 405a60c4e9..136a1d2bc8 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -173,7 +173,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - if (chest){ + /*if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); @@ -181,7 +181,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if (handr){ insertFreePart("meshes\\" + handr->model , ">?", insert); - } + }*/ if (handl){ insertFreePart("meshes\\" + handl->model, ">>", insert); @@ -207,25 +207,50 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); - Entity* ent = mRend.getScene()->createEntity(meshNumbered); - insert->attachObject(ent); - entityparts.push_back(ent); + hand = mRend.getScene()->createEntity(meshNumbered); + insert->attachObject(hand); + //entityparts.push_back(ent); std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); if(shapes){ shapeparts.push_back(shapes); - handleShapes(shapes, ent, skel); + handleShapes(shapes, hand, skel); } } + void NpcAnimation::runAnimation(float timepassed){ + //Add the amount of time passed to time + + //Handle the animation transforms dependent on time + + //Handle the shapes dependent on animation transforms if(animate){ - //Add the amount of time passed to time + time += timepassed; + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); - //Handle the animation transforms dependent on time + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); - //Handle the shapes dependent on animation transforms - } + + handleAnimationTransforms(); + std::vector*>::iterator shapepartsiter = shapeparts.begin(); + std::vector::iterator entitypartsiter = entityparts.begin(); + int i = 0; + while(shapepartsiter != shapeparts.end() && entitypartsiter != entityparts.end()) + { + std::vector* shapes = *shapepartsiter; + handleShapes(shapes, *entitypartsiter, skel); + //std::cout << "Shape part size" << shapes->size() << "\n"; + shapepartsiter++; + entitypartsiter++; + } + } } } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 1ce949f3ad..327e4b0e2c 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -16,7 +16,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ std::vector entityparts; - + Ogre::Entity* hand; 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); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fd74c282ff..235606b5c7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -234,13 +234,15 @@ void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::s int mode, int number) { std::cout<<"play animation " << groupName << ", " << mode << ", " << number << std::endl; + mActors.playAnimationGroup(ptr, groupName, mode, number); } void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { std::cout<<"skip animation"< &cell, MWWorld::Environment& environment); + void advanceTime(); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 6f41804c25..a4f1671038 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -348,13 +348,14 @@ namespace MWWorld void World::advanceTime (double hours) { hours += mGlobalVariables->getFloat ("gamehour"); - + setHour (hours); int days = hours / 24; if (days>0) mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed")); + mWorldScene->advanceTime(); } void World::setHour (double hour)