forked from mirror/openmw-tes3mp
Move Controller base classes to SceneUtil, add visitor to assign ControllerSources
This commit is contained in:
parent
de2c85e0f8
commit
c516e897ee
11 changed files with 211 additions and 115 deletions
|
@ -74,7 +74,7 @@ protected:
|
||||||
virtual void setValue(Ogre::Real value);
|
virtual void setValue(Ogre::Real value);
|
||||||
};
|
};
|
||||||
|
|
||||||
class NullAnimationTime : public NifOsg::ControllerSource
|
class NullAnimationTime : public SceneUtil::ControllerSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual float getValue(osg::NodeVisitor *nv)
|
virtual float getValue(osg::NodeVisitor *nv)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <components/sceneutil/lightmanager.hpp>
|
#include <components/sceneutil/lightmanager.hpp>
|
||||||
|
|
||||||
#include <components/sceneutil/statesetcontroller.hpp>
|
#include <components/sceneutil/statesetupdater.hpp>
|
||||||
|
|
||||||
#include <components/esm/loadcell.hpp>
|
#include <components/esm/loadcell.hpp>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
class StateUpdater : public SceneUtil::StateSetController
|
class StateUpdater : public SceneUtil::StateSetUpdater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setDefaults(osg::StateSet *stateset)
|
virtual void setDefaults(osg::StateSet *stateset)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <components/vfs/manager.hpp>
|
#include <components/vfs/manager.hpp>
|
||||||
|
|
||||||
#include <components/sceneutil/util.hpp>
|
#include <components/sceneutil/util.hpp>
|
||||||
#include <components/sceneutil/statesetcontroller.hpp>
|
#include <components/sceneutil/statesetupdater.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
@ -37,14 +37,6 @@
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
osg::StateSet* getWritableStateSet(osg::Node* node)
|
|
||||||
{
|
|
||||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
|
||||||
osg::ref_ptr<osg::StateSet> cloned = static_cast<osg::StateSet*>(stateset->clone(osg::CopyOp::SHALLOW_COPY));
|
|
||||||
node->setStateSet(cloned);
|
|
||||||
return cloned;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Material> createAlphaTrackingUnlitMaterial()
|
osg::ref_ptr<osg::Material> createAlphaTrackingUnlitMaterial()
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Material> mat = new osg::Material;
|
osg::ref_ptr<osg::Material> mat = new osg::Material;
|
||||||
|
@ -95,7 +87,7 @@ namespace
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
class AtmosphereUpdater : public SceneUtil::StateSetController
|
class AtmosphereUpdater : public SceneUtil::StateSetUpdater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setEmissionColor(osg::Vec4f emissionColor)
|
void setEmissionColor(osg::Vec4f emissionColor)
|
||||||
|
|
|
@ -39,7 +39,7 @@ add_component_dir (resource
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (sceneutil
|
add_component_dir (sceneutil
|
||||||
clone attach lightmanager visitor util statesetcontroller
|
clone attach lightmanager visitor util statesetupdater controller
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (nif
|
add_component_dir (nif
|
||||||
|
|
|
@ -64,15 +64,6 @@ float ControllerFunction::calculate(float value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameTimeSource::FrameTimeSource()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
float FrameTimeSource::getValue(osg::NodeVisitor *nv)
|
|
||||||
{
|
|
||||||
return nv->getFrameStamp()->getSimulationTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyframeController::KeyframeController()
|
KeyframeController::KeyframeController()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -207,20 +198,6 @@ void KeyframeController::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::Controller()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Controller::hasInput() const
|
|
||||||
{
|
|
||||||
return mSource.get() != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Controller::getInputValue(osg::NodeVisitor* nv)
|
|
||||||
{
|
|
||||||
return mFunction->calculate(mSource->getValue(nv));
|
|
||||||
}
|
|
||||||
|
|
||||||
GeomMorpherController::GeomMorpherController()
|
GeomMorpherController::GeomMorpherController()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -278,7 +255,7 @@ UVController::UVController(const Nif::NiUVData *data, std::set<int> textureUnits
|
||||||
}
|
}
|
||||||
|
|
||||||
UVController::UVController(const UVController& copy, const osg::CopyOp& copyop)
|
UVController::UVController(const UVController& copy, const osg::CopyOp& copyop)
|
||||||
: osg::Object(copy, copyop), StateSetController(copy, copyop), Controller(copy)
|
: osg::Object(copy, copyop), StateSetUpdater(copy, copyop), Controller(copy)
|
||||||
, mUTrans(copy.mUTrans)
|
, mUTrans(copy.mUTrans)
|
||||||
, mVTrans(copy.mVTrans)
|
, mVTrans(copy.mVTrans)
|
||||||
, mUScale(copy.mUScale)
|
, mUScale(copy.mUScale)
|
||||||
|
@ -367,7 +344,7 @@ AlphaController::AlphaController()
|
||||||
}
|
}
|
||||||
|
|
||||||
AlphaController::AlphaController(const AlphaController ©, const osg::CopyOp ©op)
|
AlphaController::AlphaController(const AlphaController ©, const osg::CopyOp ©op)
|
||||||
: StateSetController(copy, copyop), ValueInterpolator(), Controller(copy)
|
: StateSetUpdater(copy, copyop), ValueInterpolator(), Controller(copy)
|
||||||
, mData(copy.mData)
|
, mData(copy.mData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -394,7 +371,7 @@ MaterialColorController::MaterialColorController()
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialColorController::MaterialColorController(const MaterialColorController ©, const osg::CopyOp ©op)
|
MaterialColorController::MaterialColorController(const MaterialColorController ©, const osg::CopyOp ©op)
|
||||||
: StateSetController(copy, copyop), Controller(copy)
|
: StateSetUpdater(copy, copyop), Controller(copy)
|
||||||
, mData(copy.mData)
|
, mData(copy.mData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -423,7 +400,7 @@ FlipController::FlipController()
|
||||||
}
|
}
|
||||||
|
|
||||||
FlipController::FlipController(const FlipController ©, const osg::CopyOp ©op)
|
FlipController::FlipController(const FlipController ©, const osg::CopyOp ©op)
|
||||||
: StateSetController(copy, copyop)
|
: StateSetUpdater(copy, copyop)
|
||||||
, Controller(copy)
|
, Controller(copy)
|
||||||
, mTexSlot(copy.mTexSlot)
|
, mTexSlot(copy.mTexSlot)
|
||||||
, mDelta(copy.mDelta)
|
, mDelta(copy.mDelta)
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
#include <components/nifcache/nifcache.hpp>
|
#include <components/nifcache/nifcache.hpp>
|
||||||
|
|
||||||
#include <components/sceneutil/statesetcontroller.hpp>
|
#include <components/sceneutil/controller.hpp>
|
||||||
|
#include <components/sceneutil/statesetupdater.hpp>
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
@ -43,7 +44,6 @@ namespace osgAnimation
|
||||||
namespace NifOsg
|
namespace NifOsg
|
||||||
{
|
{
|
||||||
|
|
||||||
// FIXME: Should not be here. We might also want to use this for non-NIF model formats
|
|
||||||
class ValueInterpolator
|
class ValueInterpolator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -76,8 +76,7 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: Should not be here. We might also want to use this for non-NIF model formats
|
class ControllerFunction : public SceneUtil::ControllerFunction
|
||||||
class ControllerFunction
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float mFrequency;
|
float mFrequency;
|
||||||
|
@ -98,35 +97,7 @@ namespace NifOsg
|
||||||
float calculate(float value);
|
float calculate(float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControllerSource
|
class GeomMorpherController : public osg::Drawable::UpdateCallback, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual float getValue(osg::NodeVisitor* nv) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FrameTimeSource : public ControllerSource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FrameTimeSource();
|
|
||||||
virtual float getValue(osg::NodeVisitor* nv);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Controller
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Controller();
|
|
||||||
|
|
||||||
bool hasInput() const;
|
|
||||||
|
|
||||||
float getInputValue(osg::NodeVisitor* nv);
|
|
||||||
|
|
||||||
boost::shared_ptr<ControllerSource> mSource;
|
|
||||||
|
|
||||||
// The source value gets passed through this function before it's passed on to the DestValue.
|
|
||||||
boost::shared_ptr<ControllerFunction> mFunction;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GeomMorpherController : public osg::Drawable::UpdateCallback, public Controller, public ValueInterpolator
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeomMorpherController(const Nif::NiMorphData* data);
|
GeomMorpherController(const Nif::NiMorphData* data);
|
||||||
|
@ -141,7 +112,7 @@ namespace NifOsg
|
||||||
std::vector<Nif::FloatKeyMapPtr> mKeyFrames;
|
std::vector<Nif::FloatKeyMapPtr> mKeyFrames;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeyframeController : public osg::NodeCallback, public Controller, public ValueInterpolator
|
class KeyframeController : public osg::NodeCallback, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyframeController(const Nif::NiKeyframeData *data);
|
KeyframeController(const Nif::NiKeyframeData *data);
|
||||||
|
@ -191,7 +162,7 @@ namespace NifOsg
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UVController : public SceneUtil::StateSetController, public Controller, public ValueInterpolator
|
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UVController();
|
UVController();
|
||||||
|
@ -211,7 +182,7 @@ namespace NifOsg
|
||||||
std::set<int> mTextureUnits;
|
std::set<int> mTextureUnits;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VisController : public osg::NodeCallback, public Controller
|
class VisController : public osg::NodeCallback, public SceneUtil::Controller
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<Nif::NiVisData::VisData> mData;
|
std::vector<Nif::NiVisData::VisData> mData;
|
||||||
|
@ -228,7 +199,7 @@ namespace NifOsg
|
||||||
virtual void operator() (osg::Node* node, osg::NodeVisitor* nv);
|
virtual void operator() (osg::Node* node, osg::NodeVisitor* nv);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlphaController : public SceneUtil::StateSetController, public Controller, public ValueInterpolator
|
class AlphaController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Nif::FloatKeyMapPtr mData;
|
Nif::FloatKeyMapPtr mData;
|
||||||
|
@ -243,7 +214,7 @@ namespace NifOsg
|
||||||
META_Object(NifOsg, AlphaController)
|
META_Object(NifOsg, AlphaController)
|
||||||
};
|
};
|
||||||
|
|
||||||
class MaterialColorController : public SceneUtil::StateSetController, public Controller, public ValueInterpolator
|
class MaterialColorController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller, public ValueInterpolator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Nif::Vector3KeyMapPtr mData;
|
Nif::Vector3KeyMapPtr mData;
|
||||||
|
@ -258,7 +229,7 @@ namespace NifOsg
|
||||||
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
|
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FlipController : public SceneUtil::StateSetController, public Controller
|
class FlipController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int mTexSlot;
|
int mTexSlot;
|
||||||
|
@ -275,7 +246,7 @@ namespace NifOsg
|
||||||
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv);
|
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ParticleSystemController : public osg::NodeCallback, public Controller
|
class ParticleSystemController : public osg::NodeCallback, public SceneUtil::Controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ParticleSystemController(const Nif::NiParticleSystemController* ctrl);
|
ParticleSystemController(const Nif::NiParticleSystemController* ctrl);
|
||||||
|
|
|
@ -719,7 +719,7 @@ namespace NifOsg
|
||||||
return skel;
|
return skel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetController* composite, Resource::TextureManager* textureManager, std::map<int, int>& boundTextures, int animflags)
|
static void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::TextureManager* textureManager, std::map<int, int>& boundTextures, int animflags)
|
||||||
{
|
{
|
||||||
const Nif::PropertyList& props = nifNode->props;
|
const Nif::PropertyList& props = nifNode->props;
|
||||||
for (size_t i = 0; i <props.length();++i)
|
for (size_t i = 0; i <props.length();++i)
|
||||||
|
@ -729,12 +729,11 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupController(const Nif::Controller* ctrl, Controller* toSetup, int animflags)
|
static void setupController(const Nif::Controller* ctrl, SceneUtil::Controller* toSetup, int animflags)
|
||||||
{
|
{
|
||||||
// TODO: uncomment this, currently commented for easier testing
|
bool autoPlay = animflags & Nif::NiNode::AnimFlag_AutoPlay;
|
||||||
//bool autoPlay = animflags & Nif::NiNode::AnimFlag_AutoPlay;
|
if (autoPlay)
|
||||||
//if (autoPlay)
|
toSetup->mSource = boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource);
|
||||||
toSetup->mSource = boost::shared_ptr<ControllerSource>(new FrameTimeSource);
|
|
||||||
|
|
||||||
toSetup->mFunction = boost::shared_ptr<ControllerFunction>(new ControllerFunction(ctrl));
|
toSetup->mFunction = boost::shared_ptr<ControllerFunction>(new ControllerFunction(ctrl));
|
||||||
}
|
}
|
||||||
|
@ -825,7 +824,7 @@ namespace NifOsg
|
||||||
transformNode->setNodeMask(0x1);
|
transformNode->setNodeMask(0x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<SceneUtil::CompositeStateSetController> composite = new SceneUtil::CompositeStateSetController;
|
osg::ref_ptr<SceneUtil::CompositeStateSetUpdater> composite = new SceneUtil::CompositeStateSetUpdater;
|
||||||
|
|
||||||
applyNodeProperties(nifNode, transformNode, composite, textureManager, boundTextures, animflags);
|
applyNodeProperties(nifNode, transformNode, composite, textureManager, boundTextures, animflags);
|
||||||
|
|
||||||
|
@ -871,7 +870,7 @@ namespace NifOsg
|
||||||
return transformNode;
|
return transformNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleMeshControllers(const Nif::Node *nifNode, SceneUtil::CompositeStateSetController* composite, const std::map<int, int> &boundTextures, int animflags)
|
static void handleMeshControllers(const Nif::Node *nifNode, SceneUtil::CompositeStateSetUpdater* composite, const std::map<int, int> &boundTextures, int animflags)
|
||||||
{
|
{
|
||||||
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
|
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
|
||||||
{
|
{
|
||||||
|
@ -921,7 +920,7 @@ namespace NifOsg
|
||||||
|
|
||||||
static void handleMaterialControllers(const Nif::Property *materialProperty, osg::Node* node, int animflags)
|
static void handleMaterialControllers(const Nif::Property *materialProperty, osg::Node* node, int animflags)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<SceneUtil::CompositeStateSetController> composite = new SceneUtil::CompositeStateSetController;
|
osg::ref_ptr<SceneUtil::CompositeStateSetUpdater> composite = new SceneUtil::CompositeStateSetUpdater;
|
||||||
for (Nif::ControllerPtr ctrl = materialProperty->controller; !ctrl.empty(); ctrl = ctrl->next)
|
for (Nif::ControllerPtr ctrl = materialProperty->controller; !ctrl.empty(); ctrl = ctrl->next)
|
||||||
{
|
{
|
||||||
if (!(ctrl->flags & Nif::NiNode::ControllerFlag_Active))
|
if (!(ctrl->flags & Nif::NiNode::ControllerFlag_Active))
|
||||||
|
@ -947,7 +946,7 @@ namespace NifOsg
|
||||||
node->addUpdateCallback(composite);
|
node->addUpdateCallback(composite);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleTextureControllers(const Nif::Property *texProperty, SceneUtil::CompositeStateSetController* composite, Resource::TextureManager* textureManager, osg::StateSet *stateset, int animflags)
|
static void handleTextureControllers(const Nif::Property *texProperty, SceneUtil::CompositeStateSetUpdater* composite, Resource::TextureManager* textureManager, osg::StateSet *stateset, int animflags)
|
||||||
{
|
{
|
||||||
for (Nif::ControllerPtr ctrl = texProperty->controller; !ctrl.empty(); ctrl = ctrl->next)
|
for (Nif::ControllerPtr ctrl = texProperty->controller; !ctrl.empty(); ctrl = ctrl->next)
|
||||||
{
|
{
|
||||||
|
@ -1426,7 +1425,7 @@ namespace NifOsg
|
||||||
|
|
||||||
|
|
||||||
static void handleProperty(const Nif::Property *property,
|
static void handleProperty(const Nif::Property *property,
|
||||||
osg::Node *node, SceneUtil::CompositeStateSetController* composite, Resource::TextureManager* textureManager, std::map<int, int>& boundTextures, int animflags)
|
osg::Node *node, SceneUtil::CompositeStateSetUpdater* composite, Resource::TextureManager* textureManager, std::map<int, int>& boundTextures, int animflags)
|
||||||
{
|
{
|
||||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
osg::StateSet* stateset = node->getOrCreateStateSet();
|
||||||
|
|
||||||
|
|
86
components/sceneutil/controller.cpp
Normal file
86
components/sceneutil/controller.cpp
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#include "controller.hpp"
|
||||||
|
|
||||||
|
#include "statesetupdater.hpp"
|
||||||
|
|
||||||
|
#include <osg/Drawable>
|
||||||
|
#include <osg/Geode>
|
||||||
|
|
||||||
|
namespace SceneUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Controller::Controller()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Controller::hasInput() const
|
||||||
|
{
|
||||||
|
return mSource.get() != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Controller::getInputValue(osg::NodeVisitor* nv)
|
||||||
|
{
|
||||||
|
return mFunction->calculate(mSource->getValue(nv));
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameTimeSource::FrameTimeSource()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float FrameTimeSource::getValue(osg::NodeVisitor *nv)
|
||||||
|
{
|
||||||
|
return nv->getFrameStamp()->getSimulationTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignControllerSourcesVisitor::AssignControllerSourcesVisitor()
|
||||||
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignControllerSourcesVisitor::AssignControllerSourcesVisitor(boost::shared_ptr<ControllerSource> toAssign)
|
||||||
|
: mToAssign(toAssign)
|
||||||
|
, osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignControllerSourcesVisitor::apply(osg::Node &node)
|
||||||
|
{
|
||||||
|
osg::NodeCallback* callback = node.getUpdateCallback();
|
||||||
|
while (callback)
|
||||||
|
{
|
||||||
|
if (Controller* ctrl = dynamic_cast<Controller*>(callback))
|
||||||
|
assign(node, *ctrl);
|
||||||
|
if (CompositeStateSetUpdater* composite = dynamic_cast<CompositeStateSetUpdater*>(callback))
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<composite->getNumControllers(); ++i)
|
||||||
|
{
|
||||||
|
StateSetUpdater* statesetcontroller = composite->getController(i);
|
||||||
|
if (Controller* ctrl = dynamic_cast<Controller*>(statesetcontroller))
|
||||||
|
assign(node, *ctrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback = callback->getNestedCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
traverse(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignControllerSourcesVisitor::apply(osg::Geode &geode)
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<geode.getNumDrawables(); ++i)
|
||||||
|
{
|
||||||
|
osg::Drawable* drw = geode.getDrawable(i);
|
||||||
|
osg::Drawable::UpdateCallback* callback = drw->getUpdateCallback();
|
||||||
|
if (Controller* ctrl = dynamic_cast<Controller*>(callback))
|
||||||
|
assign(geode, *ctrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignControllerSourcesVisitor::assign(osg::Node&, Controller &ctrl)
|
||||||
|
{
|
||||||
|
if (!ctrl.mSource.get())
|
||||||
|
ctrl.mSource = mToAssign;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
components/sceneutil/controller.hpp
Normal file
64
components/sceneutil/controller.hpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef OPENMW_COMPONENTS_SCENEUTIL_CONTROLLER_H
|
||||||
|
#define OPENMW_COMPONENTS_SCENEUTIL_CONTROLLER_H
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <osg/NodeVisitor>
|
||||||
|
|
||||||
|
namespace SceneUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
class ControllerSource
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual float getValue(osg::NodeVisitor* nv) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FrameTimeSource : public ControllerSource
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FrameTimeSource();
|
||||||
|
virtual float getValue(osg::NodeVisitor* nv);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ControllerFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual float calculate(float input) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Controller
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Controller();
|
||||||
|
|
||||||
|
bool hasInput() const;
|
||||||
|
|
||||||
|
float getInputValue(osg::NodeVisitor* nv);
|
||||||
|
|
||||||
|
boost::shared_ptr<ControllerSource> mSource;
|
||||||
|
|
||||||
|
// The source value gets passed through this function before it's passed on to the DestValue.
|
||||||
|
boost::shared_ptr<ControllerFunction> mFunction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AssignControllerSourcesVisitor : public osg::NodeVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AssignControllerSourcesVisitor();
|
||||||
|
AssignControllerSourcesVisitor(boost::shared_ptr<ControllerSource> toAssign);
|
||||||
|
|
||||||
|
virtual void apply(osg::Node& node);
|
||||||
|
virtual void apply(osg::Geode& geode);
|
||||||
|
|
||||||
|
/// Assign the wanted ControllerSource. May be overriden in derived classes.
|
||||||
|
/// By default assigns the ControllerSource passed to the constructor of this class if no ControllerSource is assigned to that controller yet.
|
||||||
|
virtual void assign(osg::Node& node, Controller& ctrl);
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::shared_ptr<ControllerSource> mToAssign;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,11 +1,11 @@
|
||||||
#include "statesetcontroller.hpp"
|
#include "statesetupdater.hpp"
|
||||||
|
|
||||||
#include <osg/Node>
|
#include <osg/Node>
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
void StateSetController::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
void StateSetUpdater::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||||
{
|
{
|
||||||
if (!mStateSets[0])
|
if (!mStateSets[0])
|
||||||
{
|
{
|
||||||
|
@ -28,45 +28,51 @@ namespace SceneUtil
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
StateSetController::StateSetController()
|
StateSetUpdater::StateSetUpdater()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
StateSetController::StateSetController(const StateSetController ©, const osg::CopyOp ©op)
|
StateSetUpdater::StateSetUpdater(const StateSetUpdater ©, const osg::CopyOp ©op)
|
||||||
: osg::NodeCallback(copy, copyop)
|
: osg::NodeCallback(copy, copyop)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
void CompositeStateSetController::apply(osg::StateSet *stateset, osg::NodeVisitor *nv)
|
void CompositeStateSetUpdater::apply(osg::StateSet *stateset, osg::NodeVisitor *nv)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
||||||
mCtrls[i]->apply(stateset, nv);
|
mCtrls[i]->apply(stateset, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompositeStateSetController::setDefaults(osg::StateSet *stateset)
|
void CompositeStateSetUpdater::setDefaults(osg::StateSet *stateset)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
||||||
mCtrls[i]->setDefaults(stateset);
|
mCtrls[i]->setDefaults(stateset);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositeStateSetController::CompositeStateSetController()
|
CompositeStateSetUpdater::CompositeStateSetUpdater()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositeStateSetController::CompositeStateSetController(const CompositeStateSetController ©, const osg::CopyOp ©op)
|
CompositeStateSetUpdater::CompositeStateSetUpdater(const CompositeStateSetUpdater ©, const osg::CopyOp ©op)
|
||||||
: StateSetController(copy, copyop)
|
: StateSetUpdater(copy, copyop)
|
||||||
, mCtrls(copy.mCtrls)
|
|
||||||
{
|
{
|
||||||
|
for (unsigned int i=0; i<copy.mCtrls.size(); ++i)
|
||||||
|
mCtrls.push_back(static_cast<StateSetUpdater*>(osg::clone(copy.mCtrls[i].get(), copyop)));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CompositeStateSetController::getNumControllers()
|
unsigned int CompositeStateSetUpdater::getNumControllers()
|
||||||
{
|
{
|
||||||
return mCtrls.size();
|
return mCtrls.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompositeStateSetController::addController(StateSetController *ctrl)
|
StateSetUpdater* CompositeStateSetUpdater::getController(int i)
|
||||||
|
{
|
||||||
|
return mCtrls[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompositeStateSetUpdater::addController(StateSetUpdater *ctrl)
|
||||||
{
|
{
|
||||||
mCtrls.push_back(ctrl);
|
mCtrls.push_back(ctrl);
|
||||||
}
|
}
|
|
@ -15,14 +15,14 @@ namespace SceneUtil
|
||||||
/// the first StateSet is the one we can write to, the second is the one currently in use by the draw traversal of the last frame.
|
/// the first StateSet is the one we can write to, the second is the one currently in use by the draw traversal of the last frame.
|
||||||
/// After a frame is completed the places are swapped.
|
/// After a frame is completed the places are swapped.
|
||||||
/// @par Must be set as UpdateCallback on a Node.
|
/// @par Must be set as UpdateCallback on a Node.
|
||||||
/// @note Do not add multiple StateSetControllers on the same Node as they will conflict - instead use the CompositeStateSetController.
|
/// @note Do not add multiple StateSetControllers on the same Node as they will conflict - instead use the CompositeStateSetUpdater.
|
||||||
class StateSetController : public osg::NodeCallback
|
class StateSetUpdater : public osg::NodeCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StateSetController();
|
StateSetUpdater();
|
||||||
StateSetController(const StateSetController& copy, const osg::CopyOp& copyop);
|
StateSetUpdater(const StateSetUpdater& copy, const osg::CopyOp& copyop);
|
||||||
|
|
||||||
META_Object(SceneUtil, StateSetController)
|
META_Object(SceneUtil, StateSetUpdater)
|
||||||
|
|
||||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||||
|
|
||||||
|
@ -40,17 +40,18 @@ namespace SceneUtil
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief A variant of the StateSetController that can be made up of multiple controllers all controlling the same target.
|
/// @brief A variant of the StateSetController that can be made up of multiple controllers all controlling the same target.
|
||||||
class CompositeStateSetController : public StateSetController
|
class CompositeStateSetUpdater : public StateSetUpdater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompositeStateSetController();
|
CompositeStateSetUpdater();
|
||||||
CompositeStateSetController(const CompositeStateSetController& copy, const osg::CopyOp& copyop);
|
CompositeStateSetUpdater(const CompositeStateSetUpdater& copy, const osg::CopyOp& copyop);
|
||||||
|
|
||||||
META_Object(SceneUtil, CompositeStateSetController)
|
META_Object(SceneUtil, CompositeStateSetUpdater)
|
||||||
|
|
||||||
unsigned int getNumControllers();
|
unsigned int getNumControllers();
|
||||||
|
StateSetUpdater* getController(int i);
|
||||||
|
|
||||||
void addController(StateSetController* ctrl);
|
void addController(StateSetUpdater* ctrl);
|
||||||
|
|
||||||
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
|
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ namespace SceneUtil
|
||||||
|
|
||||||
virtual void setDefaults(osg::StateSet *stateset);
|
virtual void setDefaults(osg::StateSet *stateset);
|
||||||
|
|
||||||
std::vector<osg::ref_ptr<StateSetController> > mCtrls;
|
std::vector<osg::ref_ptr<StateSetUpdater> > mCtrls;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue