Merge branch 'nif' into 'master'

Some NIF cleanup

See merge request OpenMW/openmw!1473
pull/3225/head
psi29a 3 years ago
commit 6c866f4980

@ -82,34 +82,37 @@ KeyframeController::KeyframeController(const KeyframeController &copy, const osg
{
}
KeyframeController::KeyframeController(const Nif::NiKeyframeData *data)
: mRotations(data->mRotations)
, mXRotations(data->mXRotations, 0.f)
, mYRotations(data->mYRotations, 0.f)
, mZRotations(data->mZRotations, 0.f)
, mTranslations(data->mTranslations, osg::Vec3f())
, mScales(data->mScales, 1.f)
{
}
KeyframeController::KeyframeController(const Nif::NiTransformInterpolator* interpolator)
: mRotations(interpolator->data->mRotations, interpolator->defaultRot)
, mXRotations(interpolator->data->mXRotations, 0.f)
, mYRotations(interpolator->data->mYRotations, 0.f)
, mZRotations(interpolator->data->mZRotations, 0.f)
, mTranslations(interpolator->data->mTranslations, interpolator->defaultPos)
, mScales(interpolator->data->mScales, interpolator->defaultScale)
{
}
KeyframeController::KeyframeController(const float scale, const osg::Vec3f& pos, const osg::Quat& rot)
: mRotations(Nif::QuaternionKeyMapPtr(), rot)
, mXRotations(Nif::FloatKeyMapPtr(), 0.f)
, mYRotations(Nif::FloatKeyMapPtr(), 0.f)
, mZRotations(Nif::FloatKeyMapPtr(), 0.f)
, mTranslations(Nif::Vector3KeyMapPtr(), pos)
, mScales(Nif::FloatKeyMapPtr(), scale)
KeyframeController::KeyframeController(const Nif::NiKeyframeController *keyctrl)
{
if (!keyctrl->interpolator.empty())
{
const Nif::NiTransformInterpolator* interp = keyctrl->interpolator.getPtr();
if (!interp->data.empty())
{
mRotations = QuaternionInterpolator(interp->data->mRotations, interp->defaultRot);
mXRotations = FloatInterpolator(interp->data->mXRotations);
mYRotations = FloatInterpolator(interp->data->mYRotations);
mZRotations = FloatInterpolator(interp->data->mZRotations);
mTranslations = Vec3Interpolator(interp->data->mTranslations, interp->defaultPos);
mScales = FloatInterpolator(interp->data->mScales, interp->defaultScale);
}
else
{
mRotations = QuaternionInterpolator(Nif::QuaternionKeyMapPtr(), interp->defaultRot);
mTranslations = Vec3Interpolator(Nif::Vector3KeyMapPtr(), interp->defaultPos);
mScales = FloatInterpolator(Nif::FloatKeyMapPtr(), interp->defaultScale);
}
}
else if (!keyctrl->data.empty())
{
const Nif::NiKeyframeData* keydata = keyctrl->data.getPtr();
mRotations = QuaternionInterpolator(keydata->mRotations);
mXRotations = FloatInterpolator(keydata->mXRotations);
mYRotations = FloatInterpolator(keydata->mYRotations);
mZRotations = FloatInterpolator(keydata->mZRotations);
mTranslations = Vec3Interpolator(keydata->mTranslations);
mScales = FloatInterpolator(keydata->mScales, 1.f);
}
}
osg::Quat KeyframeController::getXYZRotation(float time) const

@ -234,16 +234,9 @@ namespace NifOsg
class KeyframeController : public SceneUtil::KeyframeController, public SceneUtil::NodeCallback<KeyframeController, NifOsg::MatrixTransform*>
{
public:
// This is used if there's no interpolator but there is data (Morrowind meshes).
KeyframeController(const Nif::NiKeyframeData *data);
// This is used if the interpolator has data.
KeyframeController(const Nif::NiTransformInterpolator* interpolator);
// This is used if there are default values available (e.g. from a data-less interpolator).
// If there's neither keyframe data nor an interpolator a KeyframeController must not be created.
KeyframeController(const float scale, const osg::Vec3f& pos, const osg::Quat& rot);
KeyframeController();
KeyframeController(const KeyframeController& copy, const osg::CopyOp& copyop);
KeyframeController(const Nif::NiKeyframeController *keyctrl);
META_Object(NifOsg, KeyframeController)

@ -270,8 +270,8 @@ namespace NifOsg
if (key->data.empty() && key->interpolator.empty())
continue;
osg::ref_ptr<SceneUtil::KeyframeController> callback(handleKeyframeController(key));
callback->setFunction(std::shared_ptr<NifOsg::ControllerFunction>(new NifOsg::ControllerFunction(key)));
osg::ref_ptr<SceneUtil::KeyframeController> callback = new NifOsg::KeyframeController(key);
setupController(key, callback, /*animflags*/0);
if (!target.mKeyframeControllers.emplace(strdata->string, callback).second)
Log(Debug::Verbose) << "Controller " << strdata->string << " present more than once in " << nif->getFilename() << ", ignoring later version";
@ -359,7 +359,7 @@ namespace NifOsg
handleProperty(geometry->shaderprop.getPtr(), applyTo, composite, imageManager, boundTextures, animflags);
}
void setupController(const Nif::Controller* ctrl, SceneUtil::Controller* toSetup, int animflags)
static void setupController(const Nif::Controller* ctrl, SceneUtil::Controller* toSetup, int animflags)
{
bool autoPlay = animflags & Nif::NiNode::AnimFlag_AutoPlay;
if (autoPlay)
@ -368,7 +368,7 @@ namespace NifOsg
toSetup->setFunction(std::shared_ptr<ControllerFunction>(new ControllerFunction(ctrl)));
}
osg::ref_ptr<osg::LOD> handleLodNode(const Nif::NiLODNode* niLodNode)
static osg::ref_ptr<osg::LOD> handleLodNode(const Nif::NiLODNode* niLodNode)
{
osg::ref_ptr<osg::LOD> lod (new osg::LOD);
lod->setName(niLodNode->name);
@ -383,7 +383,7 @@ namespace NifOsg
return lod;
}
osg::ref_ptr<osg::Switch> handleSwitchNode(const Nif::NiSwitchNode* niSwitchNode)
static osg::ref_ptr<osg::Switch> handleSwitchNode(const Nif::NiSwitchNode* niSwitchNode)
{
osg::ref_ptr<osg::Switch> switchNode (new osg::Switch);
switchNode->setName(niSwitchNode->name);
@ -718,24 +718,6 @@ namespace NifOsg
}
}
static osg::ref_ptr<KeyframeController> handleKeyframeController(const Nif::NiKeyframeController* keyctrl)
{
osg::ref_ptr<NifOsg::KeyframeController> ctrl;
if (!keyctrl->interpolator.empty())
{
const Nif::NiTransformInterpolator* interp = keyctrl->interpolator.getPtr();
if (!interp->data.empty())
ctrl = new NifOsg::KeyframeController(interp);
else
ctrl = new NifOsg::KeyframeController(interp->defaultScale, interp->defaultPos, interp->defaultRot);
}
else if (!keyctrl->data.empty())
{
ctrl = new NifOsg::KeyframeController(keyctrl->data.getPtr());
}
return ctrl;
}
void handleNodeControllers(const Nif::Node* nifNode, osg::Node* node, int animflags, bool& isAnimated)
{
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
@ -747,7 +729,7 @@ namespace NifOsg
const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr());
if (key->data.empty() && key->interpolator.empty())
continue;
osg::ref_ptr<KeyframeController> callback(handleKeyframeController(key));
osg::ref_ptr<KeyframeController> callback = new KeyframeController(key);
setupController(key, callback, animflags);
node->addUpdateCallback(callback);
isAnimated = true;
@ -1615,6 +1597,9 @@ namespace NifOsg
}
else if (i == Nif::NiTexturingProperty::DecalTexture)
{
// This is only an inaccurate imitation of the original implementation,
// see https://github.com/niftools/nifskope/issues/184
osg::TexEnvCombine* texEnv = new osg::TexEnvCombine;
// Interpolate to the decal texture's colour...
texEnv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);

Loading…
Cancel
Save