mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-01 17:34:33 +00:00
Merge branch 'revert-9347fe5c' into 'master'
Unimplement TCB interpolation (!4539) Closes #8621 See merge request OpenMW/openmw!4782
This commit is contained in:
commit
b53cb085c9
2 changed files with 23 additions and 71 deletions
|
|
@ -3,9 +3,7 @@
|
||||||
#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
||||||
#define OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
#define OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "exception.hpp"
|
#include "exception.hpp"
|
||||||
#include "niffile.hpp"
|
#include "niffile.hpp"
|
||||||
|
|
@ -19,7 +17,7 @@ namespace Nif
|
||||||
InterpolationType_Unknown = 0,
|
InterpolationType_Unknown = 0,
|
||||||
InterpolationType_Linear = 1,
|
InterpolationType_Linear = 1,
|
||||||
InterpolationType_Quadratic = 2,
|
InterpolationType_Quadratic = 2,
|
||||||
InterpolationType_TCB = 3,
|
InterpolationType_TBC = 3,
|
||||||
InterpolationType_XYZ = 4,
|
InterpolationType_XYZ = 4,
|
||||||
InterpolationType_Constant = 5
|
InterpolationType_Constant = 5
|
||||||
};
|
};
|
||||||
|
|
@ -30,19 +28,18 @@ namespace Nif
|
||||||
T mValue;
|
T mValue;
|
||||||
T mInTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
T mInTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
||||||
T mOutTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
T mOutTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
// FIXME: Implement TBC interpolation
|
||||||
struct TCBKey
|
/*
|
||||||
{
|
float mTension; // Only for TBC interpolation
|
||||||
float mTime;
|
float mBias; // Only for TBC interpolation
|
||||||
T mValue{};
|
float mContinuity; // Only for TBC interpolation
|
||||||
T mInTan{};
|
*/
|
||||||
T mOutTan{};
|
|
||||||
float mTension;
|
|
||||||
float mContinuity;
|
|
||||||
float mBias;
|
|
||||||
};
|
};
|
||||||
|
using FloatKey = KeyT<float>;
|
||||||
|
using Vector3Key = KeyT<osg::Vec3f>;
|
||||||
|
using Vector4Key = KeyT<osg::Vec4f>;
|
||||||
|
using QuaternionKey = KeyT<osg::Quat>;
|
||||||
|
|
||||||
template <typename T, T (NIFStream::*getValue)()>
|
template <typename T, T (NIFStream::*getValue)()>
|
||||||
struct KeyMapT
|
struct KeyMapT
|
||||||
|
|
@ -104,20 +101,15 @@ namespace Nif
|
||||||
mKeys[time] = key;
|
mKeys[time] = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mInterpolationType == InterpolationType_TCB)
|
else if (mInterpolationType == InterpolationType_TBC)
|
||||||
{
|
{
|
||||||
std::vector<TCBKey<T>> tcbKeys(count);
|
for (size_t i = 0; i < count; i++)
|
||||||
for (TCBKey<T>& key : tcbKeys)
|
|
||||||
{
|
{
|
||||||
nif->read(key.mTime);
|
float time;
|
||||||
key.mValue = ((*nif).*getValue)();
|
nif->read(time);
|
||||||
nif->read(key.mTension);
|
readTBC(*nif, key);
|
||||||
nif->read(key.mContinuity);
|
mKeys[time] = key;
|
||||||
nif->read(key.mBias);
|
|
||||||
}
|
}
|
||||||
generateTCBTangents(tcbKeys);
|
|
||||||
for (TCBKey<T>& key : tcbKeys)
|
|
||||||
mKeys[key.mTime] = KeyType{ std::move(key.mValue), std::move(key.mInTan), std::move(key.mOutTan) };
|
|
||||||
}
|
}
|
||||||
else if (mInterpolationType == InterpolationType_XYZ)
|
else if (mInterpolationType == InterpolationType_XYZ)
|
||||||
{
|
{
|
||||||
|
|
@ -148,52 +140,12 @@ namespace Nif
|
||||||
|
|
||||||
static void readQuadratic(NIFStream& nif, KeyT<osg::Quat>& key) { readValue(nif, key); }
|
static void readQuadratic(NIFStream& nif, KeyT<osg::Quat>& key) { readValue(nif, key); }
|
||||||
|
|
||||||
template <typename U>
|
static void readTBC(NIFStream& nif, KeyT<T>& key)
|
||||||
static void generateTCBTangents(std::vector<TCBKey<U>>& keys)
|
|
||||||
{
|
{
|
||||||
if (keys.size() <= 1)
|
readValue(nif, key);
|
||||||
return;
|
/*key.mTension = */ nif.get<float>();
|
||||||
|
/*key.mBias = */ nif.get<float>();
|
||||||
std::sort(keys.begin(), keys.end(), [](const auto& a, const auto& b) { return a.mTime < b.mTime; });
|
/*key.mContinuity = */ nif.get<float>();
|
||||||
for (size_t i = 0; i < keys.size(); ++i)
|
|
||||||
{
|
|
||||||
TCBKey<U>& curr = keys[i];
|
|
||||||
const TCBKey<U>& prev = (i == 0) ? curr : keys[i - 1];
|
|
||||||
const TCBKey<U>& next = (i == keys.size() - 1) ? curr : keys[i + 1];
|
|
||||||
const float prevLen = curr.mTime - prev.mTime;
|
|
||||||
const float nextLen = next.mTime - curr.mTime;
|
|
||||||
if (prevLen + nextLen <= 0.f)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const U prevDelta = curr.mValue - prev.mValue;
|
|
||||||
const U nextDelta = next.mValue - curr.mValue;
|
|
||||||
const float t = curr.mTension;
|
|
||||||
const float c = curr.mContinuity;
|
|
||||||
const float b = curr.mBias;
|
|
||||||
|
|
||||||
U x{}, y{}, z{}, w{};
|
|
||||||
if (prevLen > 0.f)
|
|
||||||
x = prevDelta / prevLen * (1 - t) * (1 - c) * (1 + b);
|
|
||||||
if (nextLen > 0.f)
|
|
||||||
y = nextDelta / nextLen * (1 - t) * (1 + c) * (1 - b);
|
|
||||||
if (prevLen > 0.f)
|
|
||||||
z = prevDelta / prevLen * (1 - t) * (1 + c) * (1 + b);
|
|
||||||
if (nextLen > 0.f)
|
|
||||||
w = nextDelta / nextLen * (1 - t) * (1 - c) * (1 - b);
|
|
||||||
|
|
||||||
curr.mInTan = (x + y) * prevLen / (prevLen + nextLen);
|
|
||||||
curr.mOutTan = (z + w) * nextLen / (prevLen + nextLen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void generateTCBTangents(std::vector<TCBKey<bool>>& keys)
|
|
||||||
{
|
|
||||||
// TODO: is this even legal?
|
|
||||||
}
|
|
||||||
|
|
||||||
static void generateTCBTangents(std::vector<TCBKey<osg::Quat>>& keys)
|
|
||||||
{
|
|
||||||
// TODO: implement TCB interpolation for quaternions
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using FloatKeyMap = KeyMapT<float, &NIFStream::get<float>>;
|
using FloatKeyMap = KeyMapT<float, &NIFStream::get<float>>;
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,6 @@ namespace NifOsg
|
||||||
case Nif::InterpolationType_Constant:
|
case Nif::InterpolationType_Constant:
|
||||||
return fraction > 0.5f ? b.mValue : a.mValue;
|
return fraction > 0.5f ? b.mValue : a.mValue;
|
||||||
case Nif::InterpolationType_Quadratic:
|
case Nif::InterpolationType_Quadratic:
|
||||||
case Nif::InterpolationType_TCB:
|
|
||||||
{
|
{
|
||||||
// Using a cubic Hermite spline.
|
// Using a cubic Hermite spline.
|
||||||
// b1(t) = 2t^3 - 3t^2 + 1
|
// b1(t) = 2t^3 - 3t^2 + 1
|
||||||
|
|
@ -148,6 +147,7 @@ namespace NifOsg
|
||||||
const float b4 = t3 - t2;
|
const float b4 = t3 - t2;
|
||||||
return a.mValue * b1 + b.mValue * b2 + a.mOutTan * b3 + b.mInTan * b4;
|
return a.mValue * b1 + b.mValue * b2 + a.mOutTan * b3 + b.mInTan * b4;
|
||||||
}
|
}
|
||||||
|
// TODO: Implement TBC interpolation
|
||||||
default:
|
default:
|
||||||
return a.mValue + ((b.mValue - a.mValue) * fraction);
|
return a.mValue + ((b.mValue - a.mValue) * fraction);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue