mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
Npc Optimization
This commit is contained in:
parent
cef2f5e927
commit
8c3127367a
5 changed files with 64 additions and 31 deletions
|
@ -335,8 +335,9 @@ namespace MWRender{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::handleAnimationTransforms(Ogre::Entity* entity){
|
void Animation::handleAnimationTransforms(){
|
||||||
Ogre::SkeletonInstance* skel = entity->getSkeleton();
|
Ogre::SkeletonInstance* skel = base->getSkeleton();
|
||||||
|
|
||||||
|
|
||||||
Ogre::Bone* b = skel->getRootBone();
|
Ogre::Bone* b = skel->getRootBone();
|
||||||
b->setOrientation(.3,.3,.3,.3); //This is a trick
|
b->setOrientation(.3,.3,.3,.3); //This is a trick
|
||||||
|
@ -344,9 +345,23 @@ namespace MWRender{
|
||||||
skel->_updateTransforms();
|
skel->_updateTransforms();
|
||||||
skel->_notifyManualBonesDirty();
|
skel->_notifyManualBonesDirty();
|
||||||
|
|
||||||
entity->getAllAnimationStates()->_notifyDirty();
|
base->getAllAnimationStates()->_notifyDirty();
|
||||||
entity->_updateAnimation();
|
base->_updateAnimation();
|
||||||
entity->_notifyMoved();
|
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<Nif::NiKeyframeData>::iterator iter;
|
std::vector<Nif::NiKeyframeData>::iterator iter;
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
|
@ -360,9 +375,6 @@ namespace MWRender{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(skel->hasBone(iter->getBonename())){
|
|
||||||
Ogre::Bone* bone = skel->getBone(iter->getBonename());
|
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float x2;
|
float x2;
|
||||||
|
|
||||||
|
@ -382,31 +394,52 @@ namespace MWRender{
|
||||||
timeIndex(time, ttime, tindexI[slot], tindexJ, x);
|
timeIndex(time, ttime, tindexI[slot], tindexJ, x);
|
||||||
|
|
||||||
//std::cout << "X: " << x << " X2: " << x2 << "\n";
|
//std::cout << "X: " << x << " X2: " << x2 << "\n";
|
||||||
|
Ogre::Vector3 t;
|
||||||
|
Ogre::Quaternion r;
|
||||||
|
|
||||||
|
bool bTrans = translist1.size() > 0;
|
||||||
if(translist1.size() > 0){
|
if(bTrans){
|
||||||
Ogre::Vector3 v1 = translist1[tindexI[slot]];
|
Ogre::Vector3 v1 = translist1[tindexI[slot]];
|
||||||
Ogre::Vector3 v2 = translist1[tindexJ];
|
Ogre::Vector3 v2 = translist1[tindexJ];
|
||||||
Ogre::Vector3 t = v1 + (v2 - v1) * x;
|
t = (v1 + (v2 - v1) * x);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
bone->setPosition(t);
|
||||||
}
|
if(bQuats)
|
||||||
|
|
||||||
if(quats.size() > 0){
|
|
||||||
Ogre::Quaternion r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true);
|
|
||||||
bone->setOrientation(r);
|
bone->setOrientation(r);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
skel->getManualBonesDirty();
|
skel->getManualBonesDirty();
|
||||||
skel->_updateTransforms();
|
skel->_updateTransforms();
|
||||||
skel->_notifyManualBonesDirty();
|
skel->_notifyManualBonesDirty();
|
||||||
|
base->getAllAnimationStates()->_notifyDirty();
|
||||||
|
base->_updateAnimation();
|
||||||
|
base->_notifyMoved();
|
||||||
|
}
|
||||||
entity->getAllAnimationStates()->_notifyDirty();
|
for(int i = 0; i < entityparts.size(); i++){
|
||||||
entity->_updateAnimation();
|
skel = entityparts[i]->getSkeleton();
|
||||||
entity->_notifyMoved();
|
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++;
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Animation{
|
||||||
|
|
||||||
//Ogre::SkeletonInstance* skel;
|
//Ogre::SkeletonInstance* skel;
|
||||||
std::vector<Nif::NiTriShapeCopy>* shapes; //All the NiTriShapeData for this creature
|
std::vector<Nif::NiTriShapeCopy>* shapes; //All the NiTriShapeData for this creature
|
||||||
|
std::vector<Ogre::Entity*> entityparts;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ class Animation{
|
||||||
std::map<std::string,float> textmappings;
|
std::map<std::string,float> textmappings;
|
||||||
Ogre::Entity* base;
|
Ogre::Entity* base;
|
||||||
void handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel);
|
void handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel);
|
||||||
void handleAnimationTransforms(Ogre::Entity* model);
|
void handleAnimationTransforms();
|
||||||
bool timeIndex( float time, std::vector<float> times, int & i, int & j, float & x );
|
bool timeIndex( float time, std::vector<float> times, int & i, int & j, float & x );
|
||||||
std::string getUniqueID(std::string mesh);
|
std::string getUniqueID(std::string mesh);
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ void CreatureAnimation::runAnimation(float timepassed){
|
||||||
//Handle the shapes dependent on animation transforms
|
//Handle the shapes dependent on animation transforms
|
||||||
time += timepassed;
|
time += timepassed;
|
||||||
|
|
||||||
handleAnimationTransforms(base);
|
handleAnimationTransforms();
|
||||||
handleShapes(shapes, base, base->getSkeleton());
|
handleShapes(shapes, base, base->getSkeleton());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ void NpcAnimation::runAnimation(float timepassed){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handleAnimationTransforms(base);
|
handleAnimationTransforms();
|
||||||
// handleAnimationTransforms(base);
|
// handleAnimationTransforms(base);
|
||||||
//handleAnimationTransforms(hand);
|
//handleAnimationTransforms(hand);
|
||||||
//
|
//
|
||||||
|
@ -244,7 +244,7 @@ void NpcAnimation::runAnimation(float timepassed){
|
||||||
//insert->
|
//insert->
|
||||||
//insert->detachObject(hand->getName());
|
//insert->detachObject(hand->getName());
|
||||||
Ogre::Entity* theentity = *entitypartsiter;
|
Ogre::Entity* theentity = *entitypartsiter;
|
||||||
handleAnimationTransforms(theentity);
|
// handleAnimationTransforms(theentity);
|
||||||
handleShapes(shapes, theentity, theentity->getSkeleton());
|
handleShapes(shapes, theentity, theentity->getSkeleton());
|
||||||
//insert->attachObject(hand);
|
//insert->attachObject(hand);
|
||||||
//std::cout << "Shape part size" << shapes->size() << "\n";
|
//std::cout << "Shape part size" << shapes->size() << "\n";
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
namespace MWRender{
|
namespace MWRender{
|
||||||
|
|
||||||
class NpcAnimation: public Animation{
|
class NpcAnimation: public Animation{
|
||||||
std::vector<Ogre::Entity*> entityparts;
|
|
||||||
Ogre::Entity* hand;
|
|
||||||
Ogre::SceneNode* insert;
|
Ogre::SceneNode* insert;
|
||||||
std::vector<std::vector<Nif::NiTriShapeCopy>* > shapeparts; //All the NiTriShape data that we need for animating this particular npc
|
std::vector<std::vector<Nif::NiTriShapeCopy>* > shapeparts; //All the NiTriShape data that we need for animating this particular npc
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue