|
|
|
@ -48,93 +48,72 @@ struct KeyMapT {
|
|
|
|
|
using ValueType = T;
|
|
|
|
|
using KeyType = KeyT<T>;
|
|
|
|
|
|
|
|
|
|
unsigned int mInterpolationType = InterpolationType_Linear;
|
|
|
|
|
unsigned int mInterpolationType = InterpolationType_Unknown;
|
|
|
|
|
MapType mKeys;
|
|
|
|
|
|
|
|
|
|
//Read in a KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html)
|
|
|
|
|
void read(NIFStream *nif, bool force = false, bool morph = false)
|
|
|
|
|
void read(NIFStream *nif, bool morph = false)
|
|
|
|
|
{
|
|
|
|
|
assert(nif);
|
|
|
|
|
|
|
|
|
|
mInterpolationType = InterpolationType_Unknown;
|
|
|
|
|
|
|
|
|
|
if (morph && nif->getVersion() >= NIFStream::generateVersion(10,1,0,106))
|
|
|
|
|
nif->getString(); // Frame name
|
|
|
|
|
|
|
|
|
|
size_t count = nif->getUInt();
|
|
|
|
|
if (count == 0 && !force && !morph)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (morph && nif->getVersion() > NIFStream::generateVersion(10,1,0,0))
|
|
|
|
|
{
|
|
|
|
|
if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,104) &&
|
|
|
|
|
nif->getVersion() <= NIFStream::generateVersion(20,1,0,2) && nif->getBethVersion() < 10)
|
|
|
|
|
nif->getFloat(); // Legacy weight
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mKeys.clear();
|
|
|
|
|
|
|
|
|
|
mInterpolationType = nif->getUInt();
|
|
|
|
|
if (count != 0 || morph)
|
|
|
|
|
mInterpolationType = nif->getUInt();
|
|
|
|
|
|
|
|
|
|
KeyType key = {};
|
|
|
|
|
NIFStream &nifReference = *nif;
|
|
|
|
|
|
|
|
|
|
if (mInterpolationType == InterpolationType_Linear
|
|
|
|
|
|| mInterpolationType == InterpolationType_Constant)
|
|
|
|
|
if (mInterpolationType == InterpolationType_Linear || mInterpolationType == InterpolationType_Constant)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
for (size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
float time = nif->getFloat();
|
|
|
|
|
readValue(nifReference, key);
|
|
|
|
|
readValue(*nif, key);
|
|
|
|
|
mKeys[time] = key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mInterpolationType == InterpolationType_Quadratic)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
for (size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
float time = nif->getFloat();
|
|
|
|
|
readQuadratic(nifReference, key);
|
|
|
|
|
readQuadratic(*nif, key);
|
|
|
|
|
mKeys[time] = key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mInterpolationType == InterpolationType_TBC)
|
|
|
|
|
{
|
|
|
|
|
for(size_t i = 0;i < count;i++)
|
|
|
|
|
for (size_t i = 0;i < count;i++)
|
|
|
|
|
{
|
|
|
|
|
float time = nif->getFloat();
|
|
|
|
|
readTBC(nifReference, key);
|
|
|
|
|
readTBC(*nif, key);
|
|
|
|
|
mKeys[time] = key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//XYZ keys aren't actually read here.
|
|
|
|
|
//data.hpp sees that the last type read was InterpolationType_XYZ and:
|
|
|
|
|
// Eats a floating point number, then
|
|
|
|
|
// Re-runs the read function 3 more times.
|
|
|
|
|
// When it does that it's reading in a bunch of InterpolationType_Linear keys, not InterpolationType_XYZ.
|
|
|
|
|
else if(mInterpolationType == InterpolationType_XYZ)
|
|
|
|
|
{
|
|
|
|
|
//Don't try to read XYZ keys into the wrong part
|
|
|
|
|
if ( count != 1 )
|
|
|
|
|
{
|
|
|
|
|
std::stringstream error;
|
|
|
|
|
error << "XYZ_ROTATION_KEY count should always be '1' . Retrieved Value: "
|
|
|
|
|
<< count;
|
|
|
|
|
nif->file->fail(error.str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mInterpolationType == InterpolationType_Unknown)
|
|
|
|
|
else if (mInterpolationType == InterpolationType_XYZ)
|
|
|
|
|
{
|
|
|
|
|
if (count != 0)
|
|
|
|
|
nif->file->fail("Interpolation type 0 doesn't work with keys");
|
|
|
|
|
//XYZ keys aren't actually read here.
|
|
|
|
|
//data.cpp sees that the last type read was InterpolationType_XYZ and:
|
|
|
|
|
// Eats a floating point number, then
|
|
|
|
|
// Re-runs the read function 3 more times.
|
|
|
|
|
// When it does that it's reading in a bunch of InterpolationType_Linear keys, not InterpolationType_XYZ.
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if (count != 0 || morph)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream error;
|
|
|
|
|
error << "Unhandled interpolation type: " << mInterpolationType;
|
|
|
|
|
nif->file->fail(error.str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (morph && nif->getVersion() > NIFStream::generateVersion(10,1,0,0))
|
|
|
|
|
{
|
|
|
|
|
if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,104) &&
|
|
|
|
|
nif->getVersion() <= NIFStream::generateVersion(20,1,0,2) && nif->getBethVersion() < 10)
|
|
|
|
|
nif->getFloat(); // Legacy weight
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|