mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Npc Optimization
This commit is contained in:
parent
cef2f5e927
commit
8c3127367a
@ -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<Nif::NiKeyframeData>::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<Ogre::Quaternion> 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++;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class Animation{
|
||||
|
||||
//Ogre::SkeletonInstance* skel;
|
||||
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;
|
||||
Ogre::Entity* base;
|
||||
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 );
|
||||
std::string getUniqueID(std::string mesh);
|
||||
|
||||
|
@ -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());
|
||||
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -15,8 +15,7 @@
|
||||
namespace MWRender{
|
||||
|
||||
class NpcAnimation: public Animation{
|
||||
std::vector<Ogre::Entity*> entityparts;
|
||||
Ogre::Entity* hand;
|
||||
|
||||
Ogre::SceneNode* insert;
|
||||
std::vector<std::vector<Nif::NiTriShapeCopy>* > shapeparts; //All the NiTriShape data that we need for animating this particular npc
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user