From fbde79896800cd37a94e9deb688a2df3ba75f5e5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 21 Jun 2012 19:02:20 -0400 Subject: [PATCH 1/5] merge --- components/nifogre/ogre_nif_loader.cpp | 29 +++++++++++--------------- components/nifogre/ogre_nif_loader.hpp | 2 +- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 331701c2a4..8882bebcda 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1067,11 +1067,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, if(mOutputAnimFiles){ std::string cut = ""; - for(unsigned int i = 0; i < name.length(); i++) + for(unsigned int i = 0; i < resourcename.length(); i++) { - if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) + if(!(resourcename.at(i) == '\\' || resourcename.at(i) == '/' || resourcename.at(i) == '>' || resourcename.at(i) == '<' || resourcename.at(i) == '?' || resourcename.at(i) == '*' || resourcename.at(i) == '|' || resourcename.at(i) == ':' || resourcename.at(i) == '"')) { - cut += name.at(i); + cut += resourcename.at(i); } } @@ -1210,14 +1210,14 @@ void NIFLoader::loadResource(Resource *resource) mesh = 0; mSkel.setNull(); flip = false; - name = resource->getName(); - char suffix = name.at(name.length() - 2); + resourcename = resource->getName(); + char suffix = resourcename.at(resourcename.length() - 2); bool addAnim = true; bool hasAnim = false; bool linkSkeleton = true; //bool baddin = false; bNiTri = true; - if(name == "meshes\\base_anim.nif" || name == "meshes\\base_animkna.nif") + if(resourcename == "meshes\\base_anim.nif" || resourcename == "meshes\\base_animkna.nif") { bNiTri = false; } @@ -1239,7 +1239,7 @@ void NIFLoader::loadResource(Resource *resource) { //baddin = true; bNiTri = true; - std::string sub = name.substr(name.length() - 6, 4); + std::string sub = resourcename.substr(resourcename.length() - 6, 4); if(sub.compare("0000") != 0) addAnim = false; @@ -1250,14 +1250,14 @@ void NIFLoader::loadResource(Resource *resource) //baddin = true; linkSkeleton = false; bNiTri = true; - std::string sub = name.substr(name.length() - 6, 4); + std::string sub = resourcename.substr(resourcename.length() - 6, 4); if(sub.compare("0000") != 0) addAnim = false; } - switch(name.at(name.length() - 1)) + switch(resourcename.at(resourcename.length() - 1)) { case '"': triname = "tri chest"; @@ -1366,12 +1366,12 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBoundingSphereRadius(bounds.getRadius()); } if(hasAnim && addAnim){ - allanimmap[name] = allanim; - alltextmappings[name] = textmappings; + allanimmap[resourcename] = allanim; + alltextmappings[resourcename] = textmappings; } if(!mSkel.isNull() && shapes.size() > 0 && addAnim) { - allshapesmap[name] = shapes; + allshapesmap[resourcename] = shapes; } @@ -1421,11 +1421,6 @@ MeshPtr NIFLoader::load(const std::string &name, return themesh; } -/* -This function shares much of the same code handleShapes() in MWRender::Animation -This function also creates new position and normal buffers for submeshes. -This function points to existing texture and IndexData buffers -*/ std::vector* NIFLoader::getAnim(std::string lowername){ diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 794459e469..c6d7e7286d 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -181,7 +181,7 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::SkeletonPtr mSkel; Ogre::Vector3 vector; std::vector shapes; - std::string name; + std::string resourcename; std::string triname; std::vector allanim; From cc776810e24ed3dd3c1ed7b4ac41a4bff52c46cd Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 17 Aug 2012 17:10:21 -0400 Subject: [PATCH 2/5] smoother animations --- components/nifogre/ogre_nif_loader.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 74b8ea8f32..07f1bf6220 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -274,15 +274,26 @@ void loadResource(Ogre::Resource *resource) if(scaleiter != scalekeys.mKeys.end()) lastscale = curscale = Ogre::Vector3(scaleiter->mValue) / startscale; bool didlast = false; + //The times are right while(!didlast) { float curtime = kfc->timeStop; - if(quatiter != quatkeys.mKeys.end()) + if(quatiter != quatkeys.mKeys.end()){ curtime = std::min(curtime, quatiter->mTime); - if(traniter != trankeys.mKeys.end()) + lastquat = curquat; + curquat = startquat.Inverse() * quatiter->mValue; + + } + if(traniter != trankeys.mKeys.end()){ curtime = std::min(curtime, traniter->mTime); - if(scaleiter != scalekeys.mKeys.end()) + lasttrans = curtrans; + curtrans = traniter->mValue - starttrans; + } + if(scaleiter != scalekeys.mKeys.end()){ curtime = std::min(curtime, scaleiter->mTime); + lastscale = curscale; + curscale = Ogre::Vector3(scaleiter->mValue) / startscale; + } curtime = std::max(curtime, kfc->timeStart); if(curtime >= kfc->timeStop) @@ -295,20 +306,14 @@ void loadResource(Ogre::Resource *resource) // current time while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) { - lastquat = curquat; - curquat = startquat.Inverse() * quatiter->mValue; quatiter++; } while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) { - lasttrans = curtrans; - curtrans = traniter->mValue - starttrans; traniter++; } while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) { - lastscale = curscale; - curscale = Ogre::Vector3(scaleiter->mValue) / startscale; scaleiter++; } @@ -320,7 +325,7 @@ void loadResource(Ogre::Resource *resource) { QuaternionKeyList::VecType::const_iterator last = quatiter-1; float diff = (curtime-last->mTime) / (quatiter->mTime-last->mTime); - kframe->setRotation(Ogre::Quaternion::nlerp(diff, lastquat, curquat)); + kframe->setRotation(Ogre::Quaternion::Slerp(diff, lastquat, curquat, true)); } if(traniter == trankeys.mKeys.end() || traniter == trankeys.mKeys.begin() || (traniter-1)->mTime == curtime) kframe->setTranslate(curtrans); From f21df64808da8d6028e62119450d8428d302e644 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 18 Aug 2012 14:48:18 -0400 Subject: [PATCH 3/5] changing a few things around --- components/nifogre/ogre_nif_loader.cpp | 49 +++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 07f1bf6220..a0c64398af 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -274,14 +274,18 @@ void loadResource(Ogre::Resource *resource) if(scaleiter != scalekeys.mKeys.end()) lastscale = curscale = Ogre::Vector3(scaleiter->mValue) / startscale; bool didlast = false; - //The times are right + while(!didlast) { float curtime = kfc->timeStop; + // Get the latest quaternion, translation, and scale for the + // current time + + //Get latest time if(quatiter != quatkeys.mKeys.end()){ curtime = std::min(curtime, quatiter->mTime); lastquat = curquat; - curquat = startquat.Inverse() * quatiter->mValue; + curquat = startquat.Inverse() * quatiter->mValue ; } if(traniter != trankeys.mKeys.end()){ @@ -302,32 +306,23 @@ void loadResource(Ogre::Resource *resource) curtime = kfc->timeStop; } - // Get the latest quaternion, translation, and scale for the - // current time - while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) - { - quatiter++; - } - while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) - { - traniter++; - } - while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) - { - scaleiter++; - } + bool rinterpolate = quatiter != quatkeys.mKeys.end() && quatiter != quatkeys.mKeys.begin() && curtime != quatiter->mTime; + bool tinterpolate = traniter != trankeys.mKeys.end() && traniter != trankeys.mKeys.begin() && curtime != traniter->mTime; + bool sinterpolate = scaleiter != scalekeys.mKeys.end() && scaleiter != scalekeys.mKeys.begin() && curtime != scaleiter->mTime; + + Ogre::TransformKeyFrame *kframe; kframe = nodetrack->createNodeKeyFrame(curtime); - if(quatiter == quatkeys.mKeys.end() || quatiter == quatkeys.mKeys.begin() || (quatiter-1)->mTime == curtime) + if(!rinterpolate) kframe->setRotation(curquat); else { QuaternionKeyList::VecType::const_iterator last = quatiter-1; float diff = (curtime-last->mTime) / (quatiter->mTime-last->mTime); - kframe->setRotation(Ogre::Quaternion::Slerp(diff, lastquat, curquat, true)); + kframe->setRotation(Ogre::Quaternion::nlerp(diff, lastquat, curquat)); } - if(traniter == trankeys.mKeys.end() || traniter == trankeys.mKeys.begin() || (traniter-1)->mTime == curtime) + if(!tinterpolate) kframe->setTranslate(curtrans); else { @@ -335,7 +330,7 @@ void loadResource(Ogre::Resource *resource) float diff = (curtime-last->mTime) / (traniter->mTime-last->mTime); kframe->setTranslate(lasttrans + ((curtrans-lasttrans)*diff)); } - if(scaleiter == scalekeys.mKeys.end() || scaleiter == scalekeys.mKeys.begin() || (scaleiter-1)->mTime == curtime) + if(!sinterpolate) kframe->setScale(curscale); else { @@ -343,6 +338,20 @@ void loadResource(Ogre::Resource *resource) float diff = (curtime-last->mTime) / (scaleiter->mTime-last->mTime); kframe->setScale(lastscale + ((curscale-lastscale)*diff)); } + + while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) + { + quatiter++; + } + while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) + { + traniter++; + } + while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) + { + scaleiter++; + } + } } anim->optimise(); From 4a219404fc48aac4fafe6c1afa934f452b1751c8 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 18 Aug 2012 15:21:43 -0400 Subject: [PATCH 4/5] Super smooth animations; 100 PERCENT COMPLETE --- components/nifogre/ogre_nif_loader.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index a0c64398af..2557a260ab 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -284,19 +284,13 @@ void loadResource(Ogre::Resource *resource) //Get latest time if(quatiter != quatkeys.mKeys.end()){ curtime = std::min(curtime, quatiter->mTime); - lastquat = curquat; - curquat = startquat.Inverse() * quatiter->mValue ; - } if(traniter != trankeys.mKeys.end()){ curtime = std::min(curtime, traniter->mTime); - lasttrans = curtrans; - curtrans = traniter->mValue - starttrans; + } if(scaleiter != scalekeys.mKeys.end()){ curtime = std::min(curtime, scaleiter->mTime); - lastscale = curscale; - curscale = Ogre::Vector3(scaleiter->mValue) / startscale; } curtime = std::max(curtime, kfc->timeStart); @@ -342,14 +336,23 @@ void loadResource(Ogre::Resource *resource) while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) { quatiter++; + lastquat = curquat; + if(quatiter != quatkeys.mKeys.end()) + curquat = startquat.Inverse() * quatiter->mValue ; } while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) { traniter++; + lasttrans = curtrans; + if(traniter != trankeys.mKeys.end()) + curtrans = traniter->mValue - starttrans; } while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) { scaleiter++; + lastscale = curscale; + if(scaleiter != scalekeys.mKeys.end()) + curscale = Ogre::Vector3(scaleiter->mValue) / startscale; } } From 5202b11235cb6a95b9e1467704ed1272f6e29d24 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 18 Aug 2012 15:31:54 -0400 Subject: [PATCH 5/5] just moving a comment --- components/nifogre/ogre_nif_loader.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 2557a260ab..660ca09ae4 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -278,8 +278,7 @@ void loadResource(Ogre::Resource *resource) while(!didlast) { float curtime = kfc->timeStop; - // Get the latest quaternion, translation, and scale for the - // current time + //Get latest time if(quatiter != quatkeys.mKeys.end()){ @@ -333,6 +332,8 @@ void loadResource(Ogre::Resource *resource) kframe->setScale(lastscale + ((curscale-lastscale)*diff)); } + // Get the latest quaternion, translation, and scale for the + // current time while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) { quatiter++;