diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 499a74d95..27665b6c6 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -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; if (time >= mStartTime && time <= mStopTime) @@ -451,34 +451,4 @@ void ParticleSystemController::operator() (osg::Node* node, osg::NodeVisitor* 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); -} - } diff --git a/components/nifosg/controller.hpp b/components/nifosg/controller.hpp index e480f4c13..d32c9f977 100644 --- a/components/nifosg/controller.hpp +++ b/components/nifosg/controller.hpp @@ -94,7 +94,7 @@ namespace NifOsg public: ControllerFunction(const Nif::Controller *ctrl); - float calculate(float value); + float calculate(float value) const; virtual float getMaximum() const; }; @@ -144,26 +144,6 @@ namespace NifOsg 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 { public: diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 63a3ee887..3b3ae4b2c 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -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 map, int sourceIndex) - : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) - , mMap(map) - , mSourceIndex(sourceIndex) - { - } - - void apply(osg::Node &node) - { - std::map::const_iterator found = mMap.find(node.getName()); - if (node.asTransform() && found != mMap.end()) - { - const Nif::NiKeyframeController* keyframectrl = found->second; - - osg::ref_ptr callback(new NifOsg::SourcedKeyframeController(keyframectrl->data.getPtr(), mSourceIndex)); - callback->mFunction = boost::shared_ptr(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 old = node.getUpdateCallback(); - node.setUpdateCallback(callback); - callback->setNestedCallback(old); - } - - traverse(node); - } - - private: - std::map mMap; - int mSourceIndex; - }; - */ - struct UpdateMorphGeometry : public osg::Drawable::CullCallback { UpdateMorphGeometry() @@ -450,7 +412,7 @@ namespace NifOsg if(key->data.empty()) continue; - osg::ref_ptr callback(new NifOsg::SourcedKeyframeController(key->data.getPtr())); + osg::ref_ptr callback(new NifOsg::KeyframeController(key->data.getPtr())); callback->mFunction = boost::shared_ptr(new NifOsg::ControllerFunction(key)); target.mKeyframeControllers[strdata->string] = callback; @@ -1007,7 +969,6 @@ namespace NifOsg geometry = new osg::Geometry; osg::ref_ptr geode (new osg::Geode); - geode->setName(triShape->name); // name will be used for part filtering triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags); geode->addDrawable(geometry); @@ -1103,7 +1064,7 @@ namespace NifOsg static void handleSkinnedTriShape(const Nif::NiTriShape *triShape, osg::Group *parentNode, const std::map& boundTextures, int animflags) { osg::ref_ptr geode (new osg::Geode); - geode->setName(triShape->name); // name will be used for part filtering + osg::ref_ptr geometry (new osg::Geometry); triShapeToGeometry(triShape, geometry, geode, boundTextures, animflags); diff --git a/components/nifosg/nifloader.hpp b/components/nifosg/nifloader.hpp index 678b8cc64..b6e9b1c8f 100644 --- a/components/nifosg/nifloader.hpp +++ b/components/nifosg/nifloader.hpp @@ -44,7 +44,7 @@ namespace NifOsg public: TextKeyMap mTextKeys; - std::map > mKeyframeControllers; + std::map > mKeyframeControllers; }; /// The main class responsible for loading NIF files into an OSG-Scenegraph. diff --git a/components/sceneutil/controller.hpp b/components/sceneutil/controller.hpp index a4e209e8c..378837ad7 100644 --- a/components/sceneutil/controller.hpp +++ b/components/sceneutil/controller.hpp @@ -21,10 +21,11 @@ namespace SceneUtil 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 { 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. /// May not be meaningful for all types of controller functions.