mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
Cleanup in preparation for animation port
Scrapped previous idea for multiple animation sources, better approach incoming.
This commit is contained in:
parent
148c041a43
commit
cd7808fc11
5 changed files with 7 additions and 95 deletions
|
@ -27,7 +27,7 @@ ControllerFunction::ControllerFunction(const Nif::Controller *ctrl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
float ControllerFunction::calculate(float value)
|
float ControllerFunction::calculate(float value) const
|
||||||
{
|
{
|
||||||
float time = mFrequency * value + mPhase;
|
float time = mFrequency * value + mPhase;
|
||||||
if (time >= mStartTime && time <= mStopTime)
|
if (time >= mStartTime && time <= mStopTime)
|
||||||
|
@ -451,34 +451,4 @@ void ParticleSystemController::operator() (osg::Node* node, osg::NodeVisitor* nv
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
SourcedKeyframeController::SourcedKeyframeController(const Nif::NiKeyframeData *data)
|
|
||||||
: KeyframeController(data)
|
|
||||||
, mEnabled(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SourcedKeyframeController::SourcedKeyframeController()
|
|
||||||
: mEnabled(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SourcedKeyframeController::SourcedKeyframeController(const SourcedKeyframeController ©, const osg::CopyOp ©op)
|
|
||||||
: KeyframeController(copy, copyop)
|
|
||||||
, mEnabled(copy.mEnabled)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourcedKeyframeController::setEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
mEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourcedKeyframeController::operator ()(osg::Node* node, osg::NodeVisitor* nv)
|
|
||||||
{
|
|
||||||
if (mEnabled)
|
|
||||||
KeyframeController::operator()(node, nv); // calls traverse
|
|
||||||
else
|
|
||||||
traverse(node, nv);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ namespace NifOsg
|
||||||
public:
|
public:
|
||||||
ControllerFunction(const Nif::Controller *ctrl);
|
ControllerFunction(const Nif::Controller *ctrl);
|
||||||
|
|
||||||
float calculate(float value);
|
float calculate(float value) const;
|
||||||
|
|
||||||
virtual float getMaximum() const;
|
virtual float getMaximum() const;
|
||||||
};
|
};
|
||||||
|
@ -144,26 +144,6 @@ namespace NifOsg
|
||||||
osg::Quat getXYZRotation(float time) const;
|
osg::Quat getXYZRotation(float time) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialization that can be enabled/disabled. Used for multiple animation sources support, i.e. .kf files.
|
|
||||||
// A SourcedKeyframeController is disabled by default and should be manually enabled when playing an animation from
|
|
||||||
// the relevant animation source.
|
|
||||||
class SourcedKeyframeController : public KeyframeController
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SourcedKeyframeController(const Nif::NiKeyframeData* data);
|
|
||||||
SourcedKeyframeController();
|
|
||||||
SourcedKeyframeController(const SourcedKeyframeController& copy, const osg::CopyOp& copyop);
|
|
||||||
|
|
||||||
META_Object(NifOsg, SourcedKeyframeController)
|
|
||||||
|
|
||||||
virtual void operator() (osg::Node*, osg::NodeVisitor*);
|
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool mEnabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller, public ValueInterpolator
|
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -253,44 +253,6 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// NodeVisitor that adds keyframe controllers to an existing scene graph, used when loading .kf files
|
|
||||||
/*
|
|
||||||
class LoadKfVisitor : public osg::NodeVisitor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LoadKfVisitor(std::map<std::string, const Nif::NiKeyframeController*> map, int sourceIndex)
|
|
||||||
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
||||||
, mMap(map)
|
|
||||||
, mSourceIndex(sourceIndex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply(osg::Node &node)
|
|
||||||
{
|
|
||||||
std::map<std::string, const Nif::NiKeyframeController*>::const_iterator found = mMap.find(node.getName());
|
|
||||||
if (node.asTransform() && found != mMap.end())
|
|
||||||
{
|
|
||||||
const Nif::NiKeyframeController* keyframectrl = found->second;
|
|
||||||
|
|
||||||
osg::ref_ptr<NifOsg::SourcedKeyframeController> callback(new NifOsg::SourcedKeyframeController(keyframectrl->data.getPtr(), mSourceIndex));
|
|
||||||
callback->mFunction = boost::shared_ptr<NifOsg::ControllerFunction>(new NifOsg::ControllerFunction(keyframectrl));
|
|
||||||
|
|
||||||
// Insert in front of the callback list, to make sure UpdateBone is last.
|
|
||||||
// The order of SourcedKeyframeControllers doesn't matter since only one of them should be enabled at a time.
|
|
||||||
osg::ref_ptr<osg::NodeCallback> old = node.getUpdateCallback();
|
|
||||||
node.setUpdateCallback(callback);
|
|
||||||
callback->setNestedCallback(old);
|
|
||||||
}
|
|
||||||
|
|
||||||
traverse(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<std::string, const Nif::NiKeyframeController*> mMap;
|
|
||||||
int mSourceIndex;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct UpdateMorphGeometry : public osg::Drawable::CullCallback
|
struct UpdateMorphGeometry : public osg::Drawable::CullCallback
|
||||||
{
|
{
|
||||||
UpdateMorphGeometry()
|
UpdateMorphGeometry()
|
||||||
|
@ -450,7 +412,7 @@ namespace NifOsg
|
||||||
if(key->data.empty())
|
if(key->data.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
osg::ref_ptr<NifOsg::SourcedKeyframeController> callback(new NifOsg::SourcedKeyframeController(key->data.getPtr()));
|
osg::ref_ptr<NifOsg::KeyframeController> callback(new NifOsg::KeyframeController(key->data.getPtr()));
|
||||||
callback->mFunction = boost::shared_ptr<NifOsg::ControllerFunction>(new NifOsg::ControllerFunction(key));
|
callback->mFunction = boost::shared_ptr<NifOsg::ControllerFunction>(new NifOsg::ControllerFunction(key));
|
||||||
|
|
||||||
target.mKeyframeControllers[strdata->string] = callback;
|
target.mKeyframeControllers[strdata->string] = callback;
|
||||||
|
@ -1007,7 +969,6 @@ namespace NifOsg
|
||||||
geometry = new osg::Geometry;
|
geometry = new osg::Geometry;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
|
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
|
||||||
geode->setName(triShape->name); // name will be used for part filtering
|
|
||||||
triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags);
|
triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags);
|
||||||
|
|
||||||
geode->addDrawable(geometry);
|
geode->addDrawable(geometry);
|
||||||
|
@ -1103,7 +1064,7 @@ namespace NifOsg
|
||||||
static void handleSkinnedTriShape(const Nif::NiTriShape *triShape, osg::Group *parentNode, const std::map<int, int>& boundTextures, int animflags)
|
static void handleSkinnedTriShape(const Nif::NiTriShape *triShape, osg::Group *parentNode, const std::map<int, int>& boundTextures, int animflags)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
|
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
|
||||||
geode->setName(triShape->name); // name will be used for part filtering
|
|
||||||
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
|
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
|
||||||
triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags);
|
triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace NifOsg
|
||||||
public:
|
public:
|
||||||
TextKeyMap mTextKeys;
|
TextKeyMap mTextKeys;
|
||||||
|
|
||||||
std::map<std::string, osg::ref_ptr<const SourcedKeyframeController> > mKeyframeControllers;
|
std::map<std::string, osg::ref_ptr<KeyframeController> > mKeyframeControllers;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The main class responsible for loading NIF files into an OSG-Scenegraph.
|
/// The main class responsible for loading NIF files into an OSG-Scenegraph.
|
||||||
|
|
|
@ -21,10 +21,11 @@ namespace SceneUtil
|
||||||
virtual float getValue(osg::NodeVisitor* nv);
|
virtual float getValue(osg::NodeVisitor* nv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @note ControllerFunctions may be shared - you should not hold any state in it. That is why all its methods are declared const.
|
||||||
class ControllerFunction
|
class ControllerFunction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual float calculate(float input) = 0;
|
virtual float calculate(float input) const = 0;
|
||||||
|
|
||||||
/// Get the "stop time" of the controller function, typically the maximum of the calculate() function.
|
/// Get the "stop time" of the controller function, typically the maximum of the calculate() function.
|
||||||
/// May not be meaningful for all types of controller functions.
|
/// May not be meaningful for all types of controller functions.
|
||||||
|
|
Loading…
Reference in a new issue