diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e9d6710be2..f5ab9e8c59 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -335,8 +335,9 @@ namespace MWRender{ } - void Animation::handleAnimationTransforms(Ogre::Entity* entity){ - Ogre::SkeletonInstance* skel = entity->getSkeleton(); + void Animation::handleAnimationTransforms(){ + Ogre::SkeletonInstance* skel = base->getSkeleton(); + Ogre::Bone* b = skel->getRootBone(); b->setOrientation(.3,.3,.3,.3); //This is a trick @@ -344,9 +345,23 @@ namespace MWRender{ skel->_updateTransforms(); skel->_notifyManualBonesDirty(); - entity->getAllAnimationStates()->_notifyDirty(); - entity->_updateAnimation(); - entity->_notifyMoved(); + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); + + for(int i = 0; i < entityparts.size(); i++){ + Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); + + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + entityparts[i]->getAllAnimationStates()->_notifyDirty(); + entityparts[i]->_updateAnimation(); + entityparts[i]->_notifyMoved(); + } std::vector::iterator iter; int slot = 0; @@ -360,10 +375,7 @@ namespace MWRender{ } - if(skel->hasBone(iter->getBonename())){ - Ogre::Bone* bone = skel->getBone(iter->getBonename()); - - float x; + float x; float x2; std::vector quats = iter->getQuat(); @@ -382,32 +394,53 @@ namespace MWRender{ timeIndex(time, ttime, tindexI[slot], tindexJ, x); //std::cout << "X: " << x << " X2: " << x2 << "\n"; - - - if(translist1.size() > 0){ + Ogre::Vector3 t; + Ogre::Quaternion r; + + bool bTrans = translist1.size() > 0; + if(bTrans){ Ogre::Vector3 v1 = translist1[tindexI[slot]]; Ogre::Vector3 v2 = translist1[tindexJ]; - Ogre::Vector3 t = v1 + (v2 - v1) * x; - bone->setPosition(t); + t = (v1 + (v2 - v1) * x); + } - if(quats.size() > 0){ - Ogre::Quaternion r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); - bone->setOrientation(r); + bool bQuats = quats.size() > 0; + if(bQuats){ + r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); + //bone->setOrientation(r); } + skel = base->getSkeleton(); - + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + if(bTrans) + bone->setPosition(t); + if(bQuats) + bone->setOrientation(r); skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); - - - - - entity->getAllAnimationStates()->_notifyDirty(); - entity->_updateAnimation(); - entity->_notifyMoved(); + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); } + for(int i = 0; i < entityparts.size(); i++){ + skel = entityparts[i]->getSkeleton(); + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + if(bTrans) + bone->setPosition(t); + if(bQuats) + bone->setOrientation(r); + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + entityparts[i]->getAllAnimationStates()->_notifyDirty(); + entityparts[i]->_updateAnimation(); + entityparts[i]->_notifyMoved(); + } + } slot++; } } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index eb0acd5754..d97ccbe299 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -35,6 +35,7 @@ class Animation{ //Ogre::SkeletonInstance* skel; std::vector* shapes; //All the NiTriShapeData for this creature + std::vector entityparts; @@ -43,7 +44,7 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); - void handleAnimationTransforms(Ogre::Entity* model); + void handleAnimationTransforms(); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 033e0f7df6..868561ca87 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -50,7 +50,7 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms time += timepassed; - handleAnimationTransforms(base); + handleAnimationTransforms(); handleShapes(shapes, base, base->getSkeleton()); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index cb78c664cd..c1c3ea680b 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -231,7 +231,7 @@ void NpcAnimation::runAnimation(float timepassed){ - handleAnimationTransforms(base); + handleAnimationTransforms(); // handleAnimationTransforms(base); //handleAnimationTransforms(hand); // @@ -244,7 +244,7 @@ void NpcAnimation::runAnimation(float timepassed){ //insert-> //insert->detachObject(hand->getName()); Ogre::Entity* theentity = *entitypartsiter; - handleAnimationTransforms(theentity); + // handleAnimationTransforms(theentity); handleShapes(shapes, theentity, theentity->getSkeleton()); //insert->attachObject(hand); //std::cout << "Shape part size" << shapes->size() << "\n"; diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 9dcbce9a33..ef9bef29ff 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -15,8 +15,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ - std::vector entityparts; - Ogre::Entity* hand; + Ogre::SceneNode* insert; std::vector* > shapeparts; //All the NiTriShape data that we need for animating this particular npc public: