Streamline NiInterpController handling

make_linux_ci_do_zoomies
Alexei Kotov 2 years ago
parent 675c0f9b31
commit 482de23893

@ -29,6 +29,26 @@ namespace Nif
target.post(nif); target.post(nif);
} }
void NiInterpController::read(NIFStream* nif)
{
Controller::read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,104) && nif->getVersion() <= NIFStream::generateVersion(10,1,0,108))
mManagerControlled = nif->getBoolean();
}
void NiSingleInterpController::read(NIFStream* nif)
{
NiInterpController::read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,104))
mInterpolator.read(nif);
}
void NiSingleInterpController::post(NIFFile* nif)
{
NiInterpController::post(nif);
mInterpolator.post(nif);
}
void NiParticleSystemController::read(NIFStream *nif) void NiParticleSystemController::read(NIFStream *nif)
{ {
Controller::read(nif); Controller::read(nif);
@ -93,27 +113,24 @@ namespace Nif
void NiMaterialColorController::read(NIFStream *nif) void NiMaterialColorController::read(NIFStream *nif)
{ {
Controller::read(nif); NiSingleInterpController::read(nif);
if (nif->getVersion() > NIFStream::generateVersion(10,1,0,103))
interpolator.read(nif);
// Two bits that correspond to the controlled material color. // Two bits that correspond to the controlled material color.
// 00: Ambient // 00: Ambient
// 01: Diffuse // 01: Diffuse
// 10: Specular // 10: Specular
// 11: Emissive // 11: Emissive
if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0))
targetColor = nif->getUShort() & 3; mTargetColor = nif->getUShort() & 3;
else else
targetColor = (flags >> 4) & 3; mTargetColor = (flags >> 4) & 3;
if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103)) if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
data.read(nif); mData.read(nif);
} }
void NiMaterialColorController::post(NIFFile *nif) void NiMaterialColorController::post(NIFFile *nif)
{ {
Controller::post(nif); NiSingleInterpController::post(nif);
interpolator.post(nif); mData.post(nif);
data.post(nif);
} }
void NiLookAtController::read(NIFStream *nif) void NiLookAtController::read(NIFStream *nif)
@ -166,23 +183,20 @@ namespace Nif
void NiKeyframeController::read(NIFStream *nif) void NiKeyframeController::read(NIFStream *nif)
{ {
Controller::read(nif); NiSingleInterpController::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103)) if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
data.read(nif); mData.read(nif);
else
interpolator.read(nif);
} }
void NiKeyframeController::post(NIFFile *nif) void NiKeyframeController::post(NIFFile *nif)
{ {
Controller::post(nif); NiSingleInterpController::post(nif);
data.post(nif); mData.post(nif);
interpolator.post(nif);
} }
void NiMultiTargetTransformController::read(NIFStream *nif) void NiMultiTargetTransformController::read(NIFStream *nif)
{ {
Controller::read(nif); NiInterpController::read(nif);
size_t numTargets = nif->getUShort(); size_t numTargets = nif->getUShort();
std::vector<NodePtr> targets; std::vector<NodePtr> targets;
targets.resize(numTargets); targets.resize(numTargets);
@ -193,29 +207,39 @@ namespace Nif
void NiMultiTargetTransformController::post(NIFFile *nif) void NiMultiTargetTransformController::post(NIFFile *nif)
{ {
Controller::post(nif); NiInterpController::post(nif);
mExtraTargets.post(nif); mExtraTargets.post(nif);
} }
void NiFloatInterpController::read(NIFStream *nif) void NiAlphaController::read(NIFStream *nif)
{ {
Controller::read(nif); NiFloatInterpController::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103)) if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
data.read(nif); mData.read(nif);
else
interpolator.read(nif);
} }
void NiFloatInterpController::post(NIFFile *nif) void NiAlphaController::post(NIFFile *nif)
{ {
Controller::post(nif); NiFloatInterpController::post(nif);
data.post(nif); mData.post(nif);
interpolator.post(nif); }
void NiRollController::read(NIFStream *nif)
{
NiSingleInterpController::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
mData.read(nif);
}
void NiRollController::post(NIFFile *nif)
{
NiSingleInterpController::post(nif);
mData.post(nif);
} }
void NiGeomMorpherController::read(NIFStream *nif) void NiGeomMorpherController::read(NIFStream *nif)
{ {
Controller::read(nif); NiInterpController::read(nif);
if (nif->getVersion() >= NIFFile::NIFVersion::VER_OB_OLD) if (nif->getVersion() >= NIFFile::NIFVersion::VER_OB_OLD)
/*bool updateNormals = !!*/nif->getUShort(); /*bool updateNormals = !!*/nif->getUShort();
data.read(nif); data.read(nif);
@ -245,28 +269,27 @@ namespace Nif
void NiGeomMorpherController::post(NIFFile *nif) void NiGeomMorpherController::post(NIFFile *nif)
{ {
Controller::post(nif); NiInterpController::post(nif);
data.post(nif); data.post(nif);
interpolators.post(nif); interpolators.post(nif);
} }
void NiVisController::read(NIFStream *nif) void NiVisController::read(NIFStream *nif)
{ {
Controller::read(nif); NiBoolInterpController::read(nif);
data.read(nif); if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
mData.read(nif);
} }
void NiVisController::post(NIFFile *nif) void NiVisController::post(NIFFile *nif)
{ {
Controller::post(nif); NiBoolInterpController::post(nif);
data.post(nif); mData.post(nif);
} }
void NiFlipController::read(NIFStream *nif) void NiFlipController::read(NIFStream *nif)
{ {
Controller::read(nif); NiFloatInterpController::read(nif);
if (nif->getVersion() >= NIFStream::generateVersion(10,2,0,0))
mInterpolator.read(nif);
mTexSlot = nif->getUInt(); mTexSlot = nif->getUInt();
if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103)) if (nif->getVersion() <= NIFStream::generateVersion(10,1,0,103))
{ {
@ -278,8 +301,7 @@ namespace Nif
void NiFlipController::post(NIFFile *nif) void NiFlipController::post(NIFFile *nif)
{ {
Controller::post(nif); NiFloatInterpController::post(nif);
mInterpolator.post(nif);
mSources.post(nif); mSources.post(nif);
} }

@ -29,6 +29,24 @@
namespace Nif namespace Nif
{ {
// Base class for controllers that use NiInterpolators to animate objects.
struct NiInterpController : public Controller
{
// Usually one of the flags.
bool mManagerControlled{false};
void read(NIFStream* nif) override;
};
// Base class for controllers that use one NiInterpolator.
struct NiSingleInterpController : public NiInterpController
{
NiInterpolatorPtr mInterpolator;
void read(NIFStream* nif) override;
void post(NIFFile* nif) override;
};
struct NiParticleSystemController : public Controller struct NiParticleSystemController : public Controller
{ {
enum BSPArrayController { enum BSPArrayController {
@ -88,11 +106,10 @@ struct NiParticleSystemController : public Controller
}; };
using NiBSPArrayController = NiParticleSystemController; using NiBSPArrayController = NiParticleSystemController;
struct NiMaterialColorController : public Controller struct NiMaterialColorController : public NiSingleInterpController
{ {
NiPoint3InterpolatorPtr interpolator; NiPosDataPtr mData;
NiPosDataPtr data; unsigned int mTargetColor;
unsigned int targetColor;
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
@ -139,16 +156,15 @@ struct NiUVController : public Controller
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiKeyframeController : public Controller struct NiKeyframeController : public NiSingleInterpController
{ {
NiKeyframeDataPtr data; NiKeyframeDataPtr mData;
NiTransformInterpolatorPtr interpolator;
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiMultiTargetTransformController : public Controller struct NiMultiTargetTransformController : public NiInterpController
{ {
NodeList mExtraTargets; NodeList mExtraTargets;
@ -156,19 +172,29 @@ struct NiMultiTargetTransformController : public Controller
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiFloatInterpController : public Controller // Base class for controllers that use a NiFloatInterpolator to animate their target.
struct NiFloatInterpController : public NiSingleInterpController { };
// Ditto for NiBoolInterpolator.
struct NiBoolInterpController : public NiSingleInterpController { };
struct NiAlphaController : public NiFloatInterpController
{ {
NiFloatDataPtr data; NiFloatDataPtr mData;
NiFloatInterpolatorPtr interpolator;
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiAlphaController : public NiFloatInterpController { }; struct NiRollController : public NiSingleInterpController
struct NiRollController : public NiFloatInterpController { }; {
NiFloatDataPtr mData;
void read(NIFStream *nif) override;
void post(NIFFile *nif) override;
};
struct NiGeomMorpherController : public Controller struct NiGeomMorpherController : public NiInterpController
{ {
NiMorphDataPtr data; NiMorphDataPtr data;
NiFloatInterpolatorList interpolators; NiFloatInterpolatorList interpolators;
@ -177,17 +203,16 @@ struct NiGeomMorpherController : public Controller
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiVisController : public Controller struct NiVisController : public NiBoolInterpController
{ {
NiVisDataPtr data; NiVisDataPtr mData;
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiFlipController : public Controller struct NiFlipController : public NiFloatInterpController
{ {
NiFloatInterpolatorPtr mInterpolator;
int mTexSlot; // NiTexturingProperty::TextureType int mTexSlot; // NiTexturingProperty::TextureType
float mDelta; // Time between two flips. delta = (start_time - stop_time) / num_sources float mDelta; // Time between two flips. delta = (start_time - stop_time) / num_sources
NiSourceTextureList mSources; NiSourceTextureList mSources;
@ -207,9 +232,9 @@ struct NiControllerManager : public Controller
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
}; };
struct Interpolator : public Record { }; struct NiInterpolator : public Record { };
struct NiPoint3Interpolator : public Interpolator struct NiPoint3Interpolator : public NiInterpolator
{ {
osg::Vec3f defaultVal; osg::Vec3f defaultVal;
NiPosDataPtr data; NiPosDataPtr data;
@ -217,15 +242,15 @@ struct NiPoint3Interpolator : public Interpolator
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiBoolInterpolator : public Interpolator struct NiBoolInterpolator : public NiInterpolator
{ {
bool defaultVal; char defaultVal;
NiBoolDataPtr data; NiBoolDataPtr data;
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiFloatInterpolator : public Interpolator struct NiFloatInterpolator : public NiInterpolator
{ {
float defaultVal; float defaultVal;
NiFloatDataPtr data; NiFloatDataPtr data;
@ -233,7 +258,7 @@ struct NiFloatInterpolator : public Interpolator
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiTransformInterpolator : public Interpolator struct NiTransformInterpolator : public NiInterpolator
{ {
osg::Vec3f defaultPos; osg::Vec3f defaultPos;
osg::Quat defaultRot; osg::Quat defaultRot;
@ -244,7 +269,7 @@ struct NiTransformInterpolator : public Interpolator
void post(NIFFile *nif) override; void post(NIFFile *nif) override;
}; };
struct NiColorInterpolator : public Interpolator struct NiColorInterpolator : public NiInterpolator
{ {
osg::Vec4f defaultVal; osg::Vec4f defaultVal;
NiColorDataPtr data; NiColorDataPtr data;

@ -141,9 +141,6 @@ struct NiPalette;
struct NiParticleModifier; struct NiParticleModifier;
struct NiBoolData; struct NiBoolData;
struct NiSkinPartition; struct NiSkinPartition;
struct NiFloatInterpolator;
struct NiPoint3Interpolator;
struct NiTransformInterpolator;
struct BSShaderTextureSet; struct BSShaderTextureSet;
struct NiGeometryData; struct NiGeometryData;
struct BSShaderProperty; struct BSShaderProperty;
@ -154,6 +151,8 @@ struct bhkShape;
struct bhkSerializable; struct bhkSerializable;
struct hkPackedNiTriStripsData; struct hkPackedNiTriStripsData;
struct NiAccumulator; struct NiAccumulator;
struct NiInterpolator;
struct NiFloatInterpolator;
using NodePtr = RecordPtrT<Node>; using NodePtr = RecordPtrT<Node>;
using ExtraPtr = RecordPtrT<Extra>; using ExtraPtr = RecordPtrT<Extra>;
@ -174,9 +173,6 @@ using NiPalettePtr = RecordPtrT<NiPalette>;
using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>; using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
using NiBoolDataPtr = RecordPtrT<NiBoolData>; using NiBoolDataPtr = RecordPtrT<NiBoolData>;
using NiSkinPartitionPtr = RecordPtrT<NiSkinPartition>; using NiSkinPartitionPtr = RecordPtrT<NiSkinPartition>;
using NiFloatInterpolatorPtr = RecordPtrT<NiFloatInterpolator>;
using NiPoint3InterpolatorPtr = RecordPtrT<NiPoint3Interpolator>;
using NiTransformInterpolatorPtr = RecordPtrT<NiTransformInterpolator>;
using BSShaderTextureSetPtr = RecordPtrT<BSShaderTextureSet>; using BSShaderTextureSetPtr = RecordPtrT<BSShaderTextureSet>;
using NiGeometryDataPtr = RecordPtrT<NiGeometryData>; using NiGeometryDataPtr = RecordPtrT<NiGeometryData>;
using BSShaderPropertyPtr = RecordPtrT<BSShaderProperty>; using BSShaderPropertyPtr = RecordPtrT<BSShaderProperty>;
@ -186,6 +182,7 @@ using bhkWorldObjectPtr = RecordPtrT<bhkWorldObject>;
using bhkShapePtr = RecordPtrT<bhkShape>; using bhkShapePtr = RecordPtrT<bhkShape>;
using hkPackedNiTriStripsDataPtr = RecordPtrT<hkPackedNiTriStripsData>; using hkPackedNiTriStripsDataPtr = RecordPtrT<hkPackedNiTriStripsData>;
using NiAccumulatorPtr = RecordPtrT<NiAccumulator>; using NiAccumulatorPtr = RecordPtrT<NiAccumulator>;
using NiInterpolatorPtr = RecordPtrT<NiInterpolator>;
using NodeList = RecordListT<Node>; using NodeList = RecordListT<Node>;
using PropertyList = RecordListT<Property>; using PropertyList = RecordListT<Property>;

@ -86,29 +86,32 @@ KeyframeController::KeyframeController(const KeyframeController &copy, const osg
KeyframeController::KeyframeController(const Nif::NiKeyframeController *keyctrl) KeyframeController::KeyframeController(const Nif::NiKeyframeController *keyctrl)
{ {
if (!keyctrl->interpolator.empty()) if (!keyctrl->mInterpolator.empty())
{ {
const Nif::NiTransformInterpolator* interp = keyctrl->interpolator.getPtr(); if (keyctrl->mInterpolator->recType == Nif::RC_NiTransformInterpolator)
if (!interp->data.empty())
{ {
mRotations = QuaternionInterpolator(interp->data->mRotations, interp->defaultRot); const Nif::NiTransformInterpolator* interp = static_cast<const Nif::NiTransformInterpolator*>(keyctrl->mInterpolator.getPtr());
mXRotations = FloatInterpolator(interp->data->mXRotations); if (!interp->data.empty())
mYRotations = FloatInterpolator(interp->data->mYRotations); {
mZRotations = FloatInterpolator(interp->data->mZRotations); mRotations = QuaternionInterpolator(interp->data->mRotations, interp->defaultRot);
mTranslations = Vec3Interpolator(interp->data->mTranslations, interp->defaultPos); mXRotations = FloatInterpolator(interp->data->mXRotations);
mScales = FloatInterpolator(interp->data->mScales, interp->defaultScale); mYRotations = FloatInterpolator(interp->data->mYRotations);
mAxisOrder = interp->data->mAxisOrder; mZRotations = FloatInterpolator(interp->data->mZRotations);
} mTranslations = Vec3Interpolator(interp->data->mTranslations, interp->defaultPos);
else mScales = FloatInterpolator(interp->data->mScales, interp->defaultScale);
{ mAxisOrder = interp->data->mAxisOrder;
mRotations = QuaternionInterpolator(Nif::QuaternionKeyMapPtr(), interp->defaultRot); }
mTranslations = Vec3Interpolator(Nif::Vector3KeyMapPtr(), interp->defaultPos); else
mScales = FloatInterpolator(Nif::FloatKeyMapPtr(), interp->defaultScale); {
mRotations = QuaternionInterpolator(Nif::QuaternionKeyMapPtr(), interp->defaultRot);
mTranslations = Vec3Interpolator(Nif::Vector3KeyMapPtr(), interp->defaultPos);
mScales = FloatInterpolator(Nif::FloatKeyMapPtr(), interp->defaultScale);
}
} }
} }
else if (!keyctrl->data.empty()) else if (!keyctrl->mData.empty())
{ {
const Nif::NiKeyframeData* keydata = keyctrl->data.getPtr(); const Nif::NiKeyframeData* keydata = keyctrl->mData.getPtr();
mRotations = QuaternionInterpolator(keydata->mRotations); mRotations = QuaternionInterpolator(keydata->mRotations);
mXRotations = FloatInterpolator(keydata->mXRotations); mXRotations = FloatInterpolator(keydata->mXRotations);
mYRotations = FloatInterpolator(keydata->mYRotations); mYRotations = FloatInterpolator(keydata->mYRotations);
@ -298,14 +301,20 @@ void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv)
} }
} }
VisController::VisController(const Nif::NiVisData *data, unsigned int mask) VisController::VisController(const Nif::NiVisController *ctrl, unsigned int mask)
: mData(data->mVis) : mMask(mask)
, mMask(mask)
{ {
if (!ctrl->mInterpolator.empty())
{
if (ctrl->mInterpolator->recType == Nif::RC_NiBoolInterpolator)
mInterpolator = ByteInterpolator(static_cast<const Nif::NiBoolInterpolator*>(ctrl->mInterpolator.getPtr()));
}
else if (!ctrl->mData.empty())
mData = ctrl->mData->mVis;
} }
VisController::VisController() VisController::VisController()
: mMask(0)
{ {
} }
@ -313,12 +322,16 @@ VisController::VisController(const VisController &copy, const osg::CopyOp &copyo
: SceneUtil::NodeCallback<VisController>(copy, copyop) : SceneUtil::NodeCallback<VisController>(copy, copyop)
, Controller(copy) , Controller(copy)
, mData(copy.mData) , mData(copy.mData)
, mInterpolator(copy.mInterpolator)
, mMask(copy.mMask) , mMask(copy.mMask)
{ {
} }
bool VisController::calculate(float time) const bool VisController::calculate(float time) const
{ {
if (!mInterpolator.empty())
return mInterpolator.interpKey(time);
if(mData.size() == 0) if(mData.size() == 0)
return true; return true;
@ -340,14 +353,15 @@ void VisController::operator() (osg::Node* node, osg::NodeVisitor* nv)
traverse(node, nv); traverse(node, nv);
} }
RollController::RollController(const Nif::NiFloatData *data) RollController::RollController(const Nif::NiRollController* ctrl)
: mData(data->mKeyList, 1.f)
{
}
RollController::RollController(const Nif::NiFloatInterpolator* interpolator)
: mData(interpolator)
{ {
if (!ctrl->mInterpolator.empty())
{
if (ctrl->mInterpolator->recType == Nif::RC_NiFloatInterpolator)
mData = FloatInterpolator(static_cast<const Nif::NiFloatInterpolator*>(ctrl->mInterpolator.getPtr()));
}
else if (!ctrl->mData.empty())
mData = FloatInterpolator(ctrl->mData->mKeyList, 1.f);
} }
RollController::RollController(const RollController &copy, const osg::CopyOp &copyop) RollController::RollController(const RollController &copy, const osg::CopyOp &copyop)
@ -386,17 +400,16 @@ AlphaController::AlphaController()
{ {
} }
AlphaController::AlphaController(const Nif::NiFloatData *data, const osg::Material* baseMaterial) AlphaController::AlphaController(const Nif::NiAlphaController* ctrl, const osg::Material* baseMaterial)
: mData(data->mKeyList, 1.f) : mBaseMaterial(baseMaterial)
, mBaseMaterial(baseMaterial)
{
}
AlphaController::AlphaController(const Nif::NiFloatInterpolator* interpolator, const osg::Material* baseMaterial)
: mData(interpolator)
, mBaseMaterial(baseMaterial)
{ {
if (!ctrl->mInterpolator.empty())
{
if (ctrl->mInterpolator->recType == Nif::RC_NiFloatInterpolator)
mData = FloatInterpolator(static_cast<const Nif::NiFloatInterpolator*>(ctrl->mInterpolator.getPtr()));
}
else if (!ctrl->mData.empty())
mData = FloatInterpolator(ctrl->mData->mKeyList, 1.f);
} }
AlphaController::AlphaController(const AlphaController &copy, const osg::CopyOp &copyop) AlphaController::AlphaController(const AlphaController &copy, const osg::CopyOp &copyop)
@ -427,18 +440,17 @@ MaterialColorController::MaterialColorController()
{ {
} }
MaterialColorController::MaterialColorController(const Nif::NiPosData *data, TargetColor color, const osg::Material* baseMaterial) MaterialColorController::MaterialColorController(const Nif::NiMaterialColorController* ctrl, const osg::Material* baseMaterial)
: mData(data->mKeyList, osg::Vec3f(1,1,1)) : mTargetColor(static_cast<MaterialColorController::TargetColor>(ctrl->mTargetColor))
, mTargetColor(color)
, mBaseMaterial(baseMaterial)
{
}
MaterialColorController::MaterialColorController(const Nif::NiPoint3Interpolator* interpolator, TargetColor color, const osg::Material* baseMaterial)
: mData(interpolator)
, mTargetColor(color)
, mBaseMaterial(baseMaterial) , mBaseMaterial(baseMaterial)
{ {
if (!ctrl->mInterpolator.empty())
{
if (ctrl->mInterpolator->recType == Nif::RC_NiPoint3Interpolator)
mData = Vec3Interpolator(static_cast<const Nif::NiPoint3Interpolator*>(ctrl->mInterpolator.getPtr()));
}
else if (!ctrl->mData.empty())
mData = Vec3Interpolator(ctrl->mData->mKeyList, osg::Vec3f(1, 1, 1));
} }
MaterialColorController::MaterialColorController(const MaterialColorController &copy, const osg::CopyOp &copyop) MaterialColorController::MaterialColorController(const MaterialColorController &copy, const osg::CopyOp &copyop)
@ -499,8 +511,8 @@ FlipController::FlipController(const Nif::NiFlipController *ctrl, const std::vec
, mDelta(ctrl->mDelta) , mDelta(ctrl->mDelta)
, mTextures(textures) , mTextures(textures)
{ {
if (!ctrl->mInterpolator.empty()) if (!ctrl->mInterpolator.empty() && ctrl->mInterpolator->recType == Nif::RC_NiFloatInterpolator)
mData = ctrl->mInterpolator.getPtr(); mData = static_cast<const Nif::NiFloatInterpolator*>(ctrl->mInterpolator.getPtr());
} }
FlipController::FlipController(int texSlot, float delta, const std::vector<osg::ref_ptr<osg::Texture2D> >& textures) FlipController::FlipController(int texSlot, float delta, const std::vector<osg::ref_ptr<osg::Texture2D> >& textures)

@ -72,7 +72,8 @@ namespace NifOsg
std::is_same<ValueT, float>, std::is_same<ValueT, float>,
std::is_same<ValueT, osg::Vec3f>, std::is_same<ValueT, osg::Vec3f>,
std::is_same<ValueT, bool>, std::is_same<ValueT, bool>,
std::is_same<ValueT, osg::Vec4f> std::is_same<ValueT, osg::Vec4f>,
std::is_same<ValueT, char>
>, >,
std::is_same<decltype(T::defaultVal), ValueT> std::is_same<decltype(T::defaultVal), ValueT>
>, >,
@ -192,6 +193,7 @@ namespace NifOsg
using FloatInterpolator = ValueInterpolator<Nif::FloatKeyMap>; using FloatInterpolator = ValueInterpolator<Nif::FloatKeyMap>;
using Vec3Interpolator = ValueInterpolator<Nif::Vector3KeyMap>; using Vec3Interpolator = ValueInterpolator<Nif::Vector3KeyMap>;
using Vec4Interpolator = ValueInterpolator<Nif::Vector4KeyMap>; using Vec4Interpolator = ValueInterpolator<Nif::Vector4KeyMap>;
using ByteInterpolator = ValueInterpolator<Nif::ByteKeyMap>;
class ControllerFunction : public SceneUtil::ControllerFunction class ControllerFunction : public SceneUtil::ControllerFunction
{ {
@ -289,12 +291,13 @@ namespace NifOsg
{ {
private: private:
std::vector<Nif::NiVisData::VisData> mData; std::vector<Nif::NiVisData::VisData> mData;
unsigned int mMask; ByteInterpolator mInterpolator;
unsigned int mMask{0u};
bool calculate(float time) const; bool calculate(float time) const;
public: public:
VisController(const Nif::NiVisData *data, unsigned int mask); VisController(const Nif::NiVisController* ctrl, unsigned int mask);
VisController(); VisController();
VisController(const VisController& copy, const osg::CopyOp& copyop); VisController(const VisController& copy, const osg::CopyOp& copyop);
@ -310,8 +313,7 @@ namespace NifOsg
double mStartingTime{0}; double mStartingTime{0};
public: public:
RollController(const Nif::NiFloatData *data); RollController(const Nif::NiRollController* interpolator);
RollController(const Nif::NiFloatInterpolator* interpolator);
RollController() = default; RollController() = default;
RollController(const RollController& copy, const osg::CopyOp& copyop); RollController(const RollController& copy, const osg::CopyOp& copyop);
@ -326,8 +328,7 @@ namespace NifOsg
FloatInterpolator mData; FloatInterpolator mData;
osg::ref_ptr<const osg::Material> mBaseMaterial; osg::ref_ptr<const osg::Material> mBaseMaterial;
public: public:
AlphaController(const Nif::NiFloatData *data, const osg::Material* baseMaterial); AlphaController(const Nif::NiAlphaController* ctrl, const osg::Material* baseMaterial);
AlphaController(const Nif::NiFloatInterpolator* interpolator, const osg::Material* baseMaterial);
AlphaController(); AlphaController();
AlphaController(const AlphaController& copy, const osg::CopyOp& copyop); AlphaController(const AlphaController& copy, const osg::CopyOp& copyop);
@ -348,8 +349,7 @@ namespace NifOsg
Specular = 2, Specular = 2,
Emissive = 3 Emissive = 3
}; };
MaterialColorController(const Nif::NiPosData *data, TargetColor color, const osg::Material* baseMaterial); MaterialColorController(const Nif::NiMaterialColorController* ctrl, const osg::Material* baseMaterial);
MaterialColorController(const Nif::NiPoint3Interpolator* interpolator, TargetColor color, const osg::Material* baseMaterial);
MaterialColorController(); MaterialColorController();
MaterialColorController(const MaterialColorController& copy, const osg::CopyOp& copyop); MaterialColorController(const MaterialColorController& copy, const osg::CopyOp& copyop);

@ -246,7 +246,7 @@ namespace NifOsg
// This is used to queue emitters that weren't attached to their node yet. // This is used to queue emitters that weren't attached to their node yet.
std::vector<std::pair<size_t, osg::ref_ptr<Emitter>>> mEmitterQueue; std::vector<std::pair<size_t, osg::ref_ptr<Emitter>>> mEmitterQueue;
static void loadKf(Nif::NIFFilePtr nif, SceneUtil::KeyframeHolder& target) void loadKf(Nif::NIFFilePtr nif, SceneUtil::KeyframeHolder& target) const
{ {
const Nif::NiSequenceStreamHelper *seq = nullptr; const Nif::NiSequenceStreamHelper *seq = nullptr;
const size_t numRoots = nif->numRoots(); const size_t numRoots = nif->numRoots();
@ -292,9 +292,15 @@ namespace NifOsg
const Nif::NiStringExtraData *strdata = static_cast<const Nif::NiStringExtraData*>(extra.getPtr()); const Nif::NiStringExtraData *strdata = static_cast<const Nif::NiStringExtraData*>(extra.getPtr());
const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr()); const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr());
if (key->data.empty() && key->interpolator.empty()) if (key->mData.empty() && key->mInterpolator.empty())
continue; continue;
if (!key->mInterpolator.empty() && key->mInterpolator->recType != Nif::RC_NiTransformInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiKeyframeController " << key->recIndex << " in " << mFilename;
continue;
}
osg::ref_ptr<SceneUtil::KeyframeController> callback = new NifOsg::KeyframeController(key); osg::ref_ptr<SceneUtil::KeyframeController> callback = new NifOsg::KeyframeController(key);
setupController(key, callback, /*animflags*/0); setupController(key, callback, /*animflags*/0);
@ -827,8 +833,13 @@ namespace NifOsg
if (ctrl->recType == Nif::RC_NiKeyframeController) if (ctrl->recType == Nif::RC_NiKeyframeController)
{ {
const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr()); const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr());
if (key->data.empty() && key->interpolator.empty()) if (key->mData.empty() && key->mInterpolator.empty())
continue;
if (!key->mInterpolator.empty() && key->mInterpolator->recType != Nif::RC_NiTransformInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiKeyframeController " << key->recIndex << " in " << mFilename;
continue; continue;
}
osg::ref_ptr<KeyframeController> callback = new KeyframeController(key); osg::ref_ptr<KeyframeController> callback = new KeyframeController(key);
setupController(key, callback, animflags); setupController(key, callback, animflags);
node->addUpdateCallback(callback); node->addUpdateCallback(callback);
@ -847,22 +858,28 @@ namespace NifOsg
else if (ctrl->recType == Nif::RC_NiVisController) else if (ctrl->recType == Nif::RC_NiVisController)
{ {
const Nif::NiVisController *visctrl = static_cast<const Nif::NiVisController*>(ctrl.getPtr()); const Nif::NiVisController *visctrl = static_cast<const Nif::NiVisController*>(ctrl.getPtr());
if (visctrl->data.empty()) if (visctrl->mData.empty() && visctrl->mInterpolator.empty())
continue;
if (!visctrl->mInterpolator.empty() && visctrl->mInterpolator->recType != Nif::RC_NiBoolInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiVisController " << visctrl->recIndex << " in " << mFilename;
continue; continue;
osg::ref_ptr<VisController> callback(new VisController(visctrl->data.getPtr(), Loader::getHiddenNodeMask())); }
osg::ref_ptr<VisController> callback(new VisController(visctrl, Loader::getHiddenNodeMask()));
setupController(visctrl, callback, animflags); setupController(visctrl, callback, animflags);
node->addUpdateCallback(callback); node->addUpdateCallback(callback);
} }
else if (ctrl->recType == Nif::RC_NiRollController) else if (ctrl->recType == Nif::RC_NiRollController)
{ {
const Nif::NiRollController *rollctrl = static_cast<const Nif::NiRollController*>(ctrl.getPtr()); const Nif::NiRollController *rollctrl = static_cast<const Nif::NiRollController*>(ctrl.getPtr());
if (rollctrl->data.empty() && rollctrl->interpolator.empty()) if (rollctrl->mData.empty() && rollctrl->mInterpolator.empty())
continue;
if (!rollctrl->mInterpolator.empty() && rollctrl->mInterpolator->recType != Nif::RC_NiFloatInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiRollController " << rollctrl->recIndex << " in " << mFilename;
continue; continue;
osg::ref_ptr<RollController> callback; }
if (!rollctrl->interpolator.empty()) osg::ref_ptr<RollController> callback = new RollController(rollctrl);
callback = new RollController(rollctrl->interpolator.getPtr());
else // if (!rollctrl->data.empty())
callback = new RollController(rollctrl->data.getPtr());
setupController(rollctrl, callback, animflags); setupController(rollctrl, callback, animflags);
node->addUpdateCallback(callback); node->addUpdateCallback(callback);
isAnimated = true; isAnimated = true;
@ -888,29 +905,31 @@ namespace NifOsg
if (ctrl->recType == Nif::RC_NiAlphaController) if (ctrl->recType == Nif::RC_NiAlphaController)
{ {
const Nif::NiAlphaController* alphactrl = static_cast<const Nif::NiAlphaController*>(ctrl.getPtr()); const Nif::NiAlphaController* alphactrl = static_cast<const Nif::NiAlphaController*>(ctrl.getPtr());
if (alphactrl->data.empty() && alphactrl->interpolator.empty()) if (alphactrl->mData.empty() && alphactrl->mInterpolator.empty())
continue;
if (!alphactrl->mInterpolator.empty() && alphactrl->mInterpolator->recType != Nif::RC_NiFloatInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiAlphaController " << alphactrl->recIndex << " in " << mFilename;
continue; continue;
osg::ref_ptr<AlphaController> osgctrl; }
if (!alphactrl->interpolator.empty()) osg::ref_ptr<AlphaController> osgctrl = new AlphaController(alphactrl, baseMaterial);
osgctrl = new AlphaController(alphactrl->interpolator.getPtr(), baseMaterial);
else // if (!alphactrl->data.empty())
osgctrl = new AlphaController(alphactrl->data.getPtr(), baseMaterial);
setupController(alphactrl, osgctrl, animflags); setupController(alphactrl, osgctrl, animflags);
composite->addController(osgctrl); composite->addController(osgctrl);
} }
else if (ctrl->recType == Nif::RC_NiMaterialColorController) else if (ctrl->recType == Nif::RC_NiMaterialColorController)
{ {
const Nif::NiMaterialColorController* matctrl = static_cast<const Nif::NiMaterialColorController*>(ctrl.getPtr()); const Nif::NiMaterialColorController* matctrl = static_cast<const Nif::NiMaterialColorController*>(ctrl.getPtr());
if (matctrl->data.empty() && matctrl->interpolator.empty()) if (matctrl->mData.empty() && matctrl->mInterpolator.empty())
continue; continue;
auto targetColor = static_cast<MaterialColorController::TargetColor>(matctrl->targetColor); auto targetColor = static_cast<MaterialColorController::TargetColor>(matctrl->mTargetColor);
if (mVersion <= Nif::NIFFile::NIFVersion::VER_MW && targetColor == MaterialColorController::TargetColor::Specular) if (mVersion <= Nif::NIFFile::NIFVersion::VER_MW && targetColor == MaterialColorController::TargetColor::Specular)
continue; continue;
osg::ref_ptr<MaterialColorController> osgctrl; if (!matctrl->mInterpolator.empty() && matctrl->mInterpolator->recType != Nif::RC_NiPoint3Interpolator)
if (!matctrl->interpolator.empty()) {
osgctrl = new MaterialColorController(matctrl->interpolator.getPtr(), targetColor, baseMaterial); Log(Debug::Error) << "Unsupported interpolator type for NiMaterialColorController " << matctrl->recIndex << " in " << mFilename;
else // if (!matctrl->data.empty()) continue;
osgctrl = new MaterialColorController(matctrl->data.getPtr(), targetColor, baseMaterial); }
osg::ref_ptr<MaterialColorController> osgctrl = new MaterialColorController(matctrl, baseMaterial);
setupController(matctrl, osgctrl, animflags); setupController(matctrl, osgctrl, animflags);
composite->addController(osgctrl); composite->addController(osgctrl);
} }
@ -928,6 +947,11 @@ namespace NifOsg
if (ctrl->recType == Nif::RC_NiFlipController) if (ctrl->recType == Nif::RC_NiFlipController)
{ {
const Nif::NiFlipController* flipctrl = static_cast<const Nif::NiFlipController*>(ctrl.getPtr()); const Nif::NiFlipController* flipctrl = static_cast<const Nif::NiFlipController*>(ctrl.getPtr());
if (!flipctrl->mInterpolator.empty() && flipctrl->mInterpolator->recType != Nif::RC_NiFloatInterpolator)
{
Log(Debug::Error) << "Unsupported interpolator type for NiFlipController " << flipctrl->recIndex << " in " << mFilename;
continue;
}
std::vector<osg::ref_ptr<osg::Texture2D> > textures; std::vector<osg::ref_ptr<osg::Texture2D> > textures;
// inherit wrap settings from the target slot // inherit wrap settings from the target slot

Loading…
Cancel
Save