mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-21 03:44:05 +00:00
Enumerate interpolation types properly
This commit is contained in:
parent
c61f64ae86
commit
32caab663f
3 changed files with 23 additions and 22 deletions
|
@ -265,7 +265,7 @@ void NiKeyframeData::read(NIFStream *nif)
|
||||||
{
|
{
|
||||||
mRotations = std::make_shared<QuaternionKeyMap>();
|
mRotations = std::make_shared<QuaternionKeyMap>();
|
||||||
mRotations->read(nif);
|
mRotations->read(nif);
|
||||||
if(mRotations->mInterpolationType == Vector3KeyMap::XYZ)
|
if(mRotations->mInterpolationType == InterpolationType_XYZ)
|
||||||
{
|
{
|
||||||
//Chomp unused float
|
//Chomp unused float
|
||||||
nif->getFloat();
|
nif->getFloat();
|
||||||
|
|
|
@ -13,6 +13,16 @@
|
||||||
namespace Nif
|
namespace Nif
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum InterpolationType
|
||||||
|
{
|
||||||
|
InterpolationType_Unknown = 0,
|
||||||
|
InterpolationType_Linear = 1,
|
||||||
|
InterpolationType_Quadratic = 2,
|
||||||
|
InterpolationType_TBC = 3,
|
||||||
|
InterpolationType_XYZ = 4,
|
||||||
|
InterpolationType_Constant = 5
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct KeyT {
|
struct KeyT {
|
||||||
T mValue;
|
T mValue;
|
||||||
|
@ -38,17 +48,7 @@ struct KeyMapT {
|
||||||
using ValueType = T;
|
using ValueType = T;
|
||||||
using KeyType = KeyT<T>;
|
using KeyType = KeyT<T>;
|
||||||
|
|
||||||
enum InterpolationType
|
unsigned int mInterpolationType = InterpolationType_Linear;
|
||||||
{
|
|
||||||
Unknown = 0,
|
|
||||||
Linear = 1,
|
|
||||||
Quadratic = 2,
|
|
||||||
TBC = 3,
|
|
||||||
XYZ = 4,
|
|
||||||
Constant = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
unsigned int mInterpolationType = Linear;
|
|
||||||
MapType mKeys;
|
MapType mKeys;
|
||||||
|
|
||||||
//Read in a KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html)
|
//Read in a KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html)
|
||||||
|
@ -56,7 +56,7 @@ struct KeyMapT {
|
||||||
{
|
{
|
||||||
assert(nif);
|
assert(nif);
|
||||||
|
|
||||||
mInterpolationType = Unknown;
|
mInterpolationType = InterpolationType_Unknown;
|
||||||
|
|
||||||
size_t count = nif->getUInt();
|
size_t count = nif->getUInt();
|
||||||
if(count == 0 && !force)
|
if(count == 0 && !force)
|
||||||
|
@ -69,7 +69,8 @@ struct KeyMapT {
|
||||||
KeyT<T> key;
|
KeyT<T> key;
|
||||||
NIFStream &nifReference = *nif;
|
NIFStream &nifReference = *nif;
|
||||||
|
|
||||||
if (mInterpolationType == Linear || mInterpolationType == Constant)
|
if (mInterpolationType == InterpolationType_Linear
|
||||||
|
|| mInterpolationType == InterpolationType_Constant)
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < count;i++)
|
for(size_t i = 0;i < count;i++)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +79,7 @@ struct KeyMapT {
|
||||||
mKeys[time] = key;
|
mKeys[time] = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mInterpolationType == Quadratic)
|
else if (mInterpolationType == InterpolationType_Quadratic)
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < count;i++)
|
for(size_t i = 0;i < count;i++)
|
||||||
{
|
{
|
||||||
|
@ -87,7 +88,7 @@ struct KeyMapT {
|
||||||
mKeys[time] = key;
|
mKeys[time] = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mInterpolationType == TBC)
|
else if (mInterpolationType == InterpolationType_TBC)
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < count;i++)
|
for(size_t i = 0;i < count;i++)
|
||||||
{
|
{
|
||||||
|
@ -97,11 +98,11 @@ struct KeyMapT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//XYZ keys aren't actually read here.
|
//XYZ keys aren't actually read here.
|
||||||
//data.hpp sees that the last type read was sXYZInterpolation and:
|
//data.hpp sees that the last type read was InterpolationType_XYZ and:
|
||||||
// Eats a floating point number, then
|
// Eats a floating point number, then
|
||||||
// Re-runs the read function 3 more times.
|
// Re-runs the read function 3 more times.
|
||||||
// When it does that it's reading in a bunch of sLinearInterpolation keys, not sXYZInterpolation.
|
// When it does that it's reading in a bunch of InterpolationType_Linear keys, not InterpolationType_XYZ.
|
||||||
else if(mInterpolationType == XYZ)
|
else if(mInterpolationType == InterpolationType_XYZ)
|
||||||
{
|
{
|
||||||
//Don't try to read XYZ keys into the wrong part
|
//Don't try to read XYZ keys into the wrong part
|
||||||
if ( count != 1 )
|
if ( count != 1 )
|
||||||
|
@ -112,7 +113,7 @@ struct KeyMapT {
|
||||||
nif->file->fail(error.str());
|
nif->file->fail(error.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mInterpolationType == Unknown)
|
else if (mInterpolationType == InterpolationType_Unknown)
|
||||||
{
|
{
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
nif->file->fail("Interpolation type 0 doesn't work with keys");
|
nif->file->fail("Interpolation type 0 doesn't work with keys");
|
||||||
|
|
|
@ -111,7 +111,7 @@ namespace NifOsg
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case 5:
|
case Nif::InterpolationType_Constant:
|
||||||
return fraction > 0.5f ? b.mValue : a.mValue;
|
return fraction > 0.5f ? b.mValue : a.mValue;
|
||||||
default:
|
default:
|
||||||
return a.mValue + ((b.mValue - a.mValue) * fraction);
|
return a.mValue + ((b.mValue - a.mValue) * fraction);
|
||||||
|
@ -121,7 +121,7 @@ namespace NifOsg
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case 5:
|
case Nif::InterpolationType_Constant:
|
||||||
return fraction > 0.5f ? b.mValue : a.mValue;
|
return fraction > 0.5f ? b.mValue : a.mValue;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue