2015-04-10 23:16:17 +02:00
|
|
|
#ifndef OPENMW_COMPONENTS_SCENEUTIL_VISITOR_H
|
|
|
|
#define OPENMW_COMPONENTS_SCENEUTIL_VISITOR_H
|
|
|
|
|
2018-07-13 21:48:59 -05:00
|
|
|
#include <osg/MatrixTransform>
|
2015-04-10 23:16:17 +02:00
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
|
|
|
|
// Commonly used scene graph visitors
|
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
|
2015-11-02 23:49:22 +01:00
|
|
|
// Find a Group by name, case-insensitive
|
|
|
|
// If not found, mFoundNode will be NULL
|
2015-04-10 23:16:17 +02:00
|
|
|
class FindByNameVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FindByNameVisitor(const std::string& nameToFind)
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
, mNameToFind(nameToFind)
|
|
|
|
, mFoundNode(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:49:22 +01:00
|
|
|
virtual void apply(osg::Group& group);
|
2017-02-04 02:15:55 +01:00
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
virtual void apply(osg::Geometry& node);
|
|
|
|
|
|
|
|
bool checkGroup(osg::Group& group);
|
|
|
|
|
2015-04-19 14:25:36 +02:00
|
|
|
std::string mNameToFind;
|
2015-04-10 23:16:17 +02:00
|
|
|
osg::Group* mFoundNode;
|
|
|
|
};
|
|
|
|
|
2017-10-04 22:29:59 +02:00
|
|
|
class FindByClassVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FindByClassVisitor(const std::string& nameToFind)
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
, mNameToFind(nameToFind)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(osg::Node &node);
|
|
|
|
|
|
|
|
std::string mNameToFind;
|
2017-10-12 12:56:03 +02:00
|
|
|
std::vector<osg::Node *> mFoundNodes;
|
2017-10-04 22:29:59 +02:00
|
|
|
};
|
|
|
|
|
2015-11-02 23:49:22 +01:00
|
|
|
// Disable freezeOnCull for all visited particlesystems
|
|
|
|
class DisableFreezeOnCullVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisableFreezeOnCullVisitor()
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-04 02:15:55 +01:00
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
|
2015-11-10 18:21:56 +01:00
|
|
|
virtual void apply(osg::Drawable& drw);
|
2015-11-02 23:49:22 +01:00
|
|
|
};
|
|
|
|
|
2018-07-13 21:48:59 -05:00
|
|
|
/// Maps names to nodes
|
|
|
|
class NodeMapVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::map<std::string, osg::ref_ptr<osg::MatrixTransform> > NodeMap;
|
|
|
|
|
|
|
|
NodeMapVisitor(NodeMap& map)
|
|
|
|
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
|
|
|
|
, mMap(map)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void apply(osg::MatrixTransform& trans);
|
|
|
|
|
|
|
|
private:
|
|
|
|
NodeMap& mMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Hides all attached drawables
|
|
|
|
class HideDrawablesVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HideDrawablesVisitor()
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(osg::Drawable& drawable) override;
|
|
|
|
};
|
|
|
|
|
2015-04-10 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|