|
|
|
@ -29,6 +29,8 @@
|
|
|
|
|
#include <OgreVector3.h>
|
|
|
|
|
#include <OgreVector4.h>
|
|
|
|
|
#include <OgreMatrix3.h>
|
|
|
|
|
#include <OgreQuaternion.h>
|
|
|
|
|
#include <OgreStringConverter.h>
|
|
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <vector>
|
|
|
|
@ -98,6 +100,12 @@ public:
|
|
|
|
|
throw std::runtime_error(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void warn(const std::string &msg)
|
|
|
|
|
{
|
|
|
|
|
std::cerr<< "NIFFile Warning: "<<msg <<std::endl
|
|
|
|
|
<< "File: "<<filename <<std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Open a NIF stream. The name is used for error messages.
|
|
|
|
|
NIFFile(const std::string &name)
|
|
|
|
|
: filename(name)
|
|
|
|
@ -158,6 +166,13 @@ public:
|
|
|
|
|
}
|
|
|
|
|
return Ogre::Matrix3(a);
|
|
|
|
|
}
|
|
|
|
|
Ogre::Quaternion getQuaternion()
|
|
|
|
|
{
|
|
|
|
|
float a[4];
|
|
|
|
|
for(size_t i = 0;i < 4;i++)
|
|
|
|
|
a[i] = getFloat();
|
|
|
|
|
return Ogre::Quaternion(a);
|
|
|
|
|
}
|
|
|
|
|
Transformation getTrafo()
|
|
|
|
|
{
|
|
|
|
|
Transformation t;
|
|
|
|
@ -196,5 +211,78 @@ public:
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct KeyT {
|
|
|
|
|
float mTime;
|
|
|
|
|
T mValue;
|
|
|
|
|
T mForwardValue; // Only for Quadratic interpolation
|
|
|
|
|
T mBackwardValue; // Only for Quadratic interpolation
|
|
|
|
|
float mTension; // Only for TBC interpolation
|
|
|
|
|
float mBias; // Only for TBC interpolation
|
|
|
|
|
float mContinuity; // Only for TBC interpolation
|
|
|
|
|
};
|
|
|
|
|
typedef KeyT<float> FloatKey;
|
|
|
|
|
typedef KeyT<Ogre::Vector3> Vector3Key;
|
|
|
|
|
typedef KeyT<Ogre::Quaternion> QuaternionKey;
|
|
|
|
|
|
|
|
|
|
template<typename T, T (NIFFile::*getValue)()>
|
|
|
|
|
struct KeyListT {
|
|
|
|
|
typedef std::vector< KeyT<T> > VecType;
|
|
|
|
|
|
|
|
|
|
static const int sLinearInterpolation = 1;
|
|
|
|
|
static const int sQuadraticInterpolation = 2;
|
|
|
|
|
static const int sTBCInterpolation = 3;
|
|
|
|
|
|
|
|
|
|
int mInterpolationType;
|
|
|
|
|
VecType mKeys;
|
|
|
|
|
|
|
|
|
|
void read(NIFFile *nif)
|
|
|
|
|
{
|
|
|
|
|
size_t count = nif->getInt();
|
|
|
|
|
if(count == 0) return;
|
|
|
|
|
|
|
|
|
|
mInterpolationType = nif->getInt();
|
|
|
|
|
mKeys.resize(count);
|
|
|
|
|
if(mInterpolationType == sLinearInterpolation)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
KeyT<T> &key = mKeys[i];
|
|
|
|
|
key.mTime = nif->getFloat();
|
|
|
|
|
key.mValue = (nif->*getValue)();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(mInterpolationType == sQuadraticInterpolation)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
KeyT<T> &key = mKeys[i];
|
|
|
|
|
key.mTime = nif->getFloat();
|
|
|
|
|
key.mValue = (nif->*getValue)();
|
|
|
|
|
key.mForwardValue = (nif->*getValue)();
|
|
|
|
|
key.mBackwardValue = (nif->*getValue)();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(mInterpolationType == sTBCInterpolation)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
KeyT<T> &key = mKeys[i];
|
|
|
|
|
key.mTime = nif->getFloat();
|
|
|
|
|
key.mValue = (nif->*getValue)();
|
|
|
|
|
key.mTension = nif->getFloat();
|
|
|
|
|
key.mBias = nif->getFloat();
|
|
|
|
|
key.mContinuity = nif->getFloat();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
nif->warn("Unhandled interpolation type: "+Ogre::StringConverter::toString(mInterpolationType));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
typedef KeyListT<float,&NIFFile::getFloat> FloatKeyList;
|
|
|
|
|
typedef KeyListT<Ogre::Vector3,&NIFFile::getVector3> Vector3KeyList;
|
|
|
|
|
typedef KeyListT<Ogre::Quaternion,&NIFFile::getQuaternion> QuaternionKeyList;
|
|
|
|
|
|
|
|
|
|
} // Namespace
|
|
|
|
|
#endif
|
|
|
|
|