Refactor NiKeyframeController and NiTransformInterpolator

macos_ci_fix
Alexei Kotov 1 year ago
parent 735a948452
commit 6d82f8b00d

@ -292,6 +292,7 @@ namespace Nif
void NiKeyframeController::read(NIFStream* nif) void NiKeyframeController::read(NIFStream* nif)
{ {
NiSingleInterpController::read(nif); NiSingleInterpController::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 103)) if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 103))
mData.read(nif); mData.read(nif);
} }
@ -299,6 +300,7 @@ namespace Nif
void NiKeyframeController::post(Reader& nif) void NiKeyframeController::post(Reader& nif)
{ {
NiSingleInterpController::post(nif); NiSingleInterpController::post(nif);
mData.post(nif); mData.post(nif);
} }
@ -503,24 +505,13 @@ namespace Nif
void NiTransformInterpolator::read(NIFStream* nif) void NiTransformInterpolator::read(NIFStream* nif)
{ {
defaultPos = nif->getVector3(); nif->read(mDefaultTransform);
nif->read(defaultRot); mData.read(nif);
defaultScale = nif->getFloat();
if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 109))
{
if (!nif->getBoolean())
defaultPos = osg::Vec3f();
if (!nif->getBoolean())
defaultRot = osg::Quat();
if (!nif->getBoolean())
defaultScale = 1.f;
}
data.read(nif);
} }
void NiTransformInterpolator::post(Reader& nif) void NiTransformInterpolator::post(Reader& nif)
{ {
data.post(nif); mData.post(nif);
} }
void NiColorInterpolator::read(NIFStream* nif) void NiColorInterpolator::read(NIFStream* nif)

@ -344,10 +344,8 @@ namespace Nif
struct NiTransformInterpolator : public NiInterpolator struct NiTransformInterpolator : public NiInterpolator
{ {
osg::Vec3f defaultPos; NiQuatTransform mDefaultTransform;
osg::Quat defaultRot; NiKeyframeDataPtr mData;
float defaultScale;
NiKeyframeDataPtr data;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
void post(Reader& nif) override; void post(Reader& nif) override;

@ -90,21 +90,23 @@ namespace NifOsg
{ {
const Nif::NiTransformInterpolator* interp const Nif::NiTransformInterpolator* interp
= static_cast<const Nif::NiTransformInterpolator*>(keyctrl->mInterpolator.getPtr()); = static_cast<const Nif::NiTransformInterpolator*>(keyctrl->mInterpolator.getPtr());
if (!interp->data.empty()) const Nif::NiQuatTransform& defaultTransform = interp->mDefaultTransform;
if (!interp->mData.empty())
{ {
mRotations = QuaternionInterpolator(interp->data->mRotations, interp->defaultRot); mRotations = QuaternionInterpolator(interp->mData->mRotations, defaultTransform.mRotation);
mXRotations = FloatInterpolator(interp->data->mXRotations); mXRotations = FloatInterpolator(interp->mData->mXRotations);
mYRotations = FloatInterpolator(interp->data->mYRotations); mYRotations = FloatInterpolator(interp->mData->mYRotations);
mZRotations = FloatInterpolator(interp->data->mZRotations); mZRotations = FloatInterpolator(interp->mData->mZRotations);
mTranslations = Vec3Interpolator(interp->data->mTranslations, interp->defaultPos); mTranslations = Vec3Interpolator(interp->mData->mTranslations, defaultTransform.mTranslation);
mScales = FloatInterpolator(interp->data->mScales, interp->defaultScale); mScales = FloatInterpolator(interp->mData->mScales, defaultTransform.mScale);
mAxisOrder = interp->data->mAxisOrder;
mAxisOrder = interp->mData->mAxisOrder;
} }
else else
{ {
mRotations = QuaternionInterpolator(Nif::QuaternionKeyMapPtr(), interp->defaultRot); mRotations = QuaternionInterpolator(Nif::QuaternionKeyMapPtr(), defaultTransform.mRotation);
mTranslations = Vec3Interpolator(Nif::Vector3KeyMapPtr(), interp->defaultPos); mTranslations = Vec3Interpolator(Nif::Vector3KeyMapPtr(), defaultTransform.mTranslation);
mScales = FloatInterpolator(Nif::FloatKeyMapPtr(), interp->defaultScale); mScales = FloatInterpolator(Nif::FloatKeyMapPtr(), defaultTransform.mScale);
} }
} }
} }
@ -117,6 +119,7 @@ namespace NifOsg
mZRotations = FloatInterpolator(keydata->mZRotations); mZRotations = FloatInterpolator(keydata->mZRotations);
mTranslations = Vec3Interpolator(keydata->mTranslations); mTranslations = Vec3Interpolator(keydata->mTranslations);
mScales = FloatInterpolator(keydata->mScales, 1.f); mScales = FloatInterpolator(keydata->mScales, 1.f);
mAxisOrder = keydata->mAxisOrder; mAxisOrder = keydata->mAxisOrder;
} }
} }
@ -177,11 +180,12 @@ namespace NifOsg
else else
node->setRotation(node->mRotationScale); node->setRotation(node->mRotationScale);
if (!mTranslations.empty())
node->setTranslation(mTranslations.interpKey(time));
if (!mScales.empty()) if (!mScales.empty())
node->setScale(mScales.interpKey(time)); node->setScale(mScales.interpKey(time));
if (!mTranslations.empty())
node->setTranslation(mTranslations.interpKey(time));
} }
traverse(node, nv); traverse(node, nv);

Loading…
Cancel
Save