2015-04-10 21:16:17 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_SCENEUTIL_VISITOR_H
|
|
|
|
#define OPENMW_COMPONENTS_SCENEUTIL_VISITOR_H
|
|
|
|
|
2018-07-14 02:48:59 +00:00
|
|
|
#include <osg/MatrixTransform>
|
2015-04-10 21:16:17 +00:00
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
|
|
|
|
// Commonly used scene graph visitors
|
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
|
2015-11-02 22:49:22 +00:00
|
|
|
// Find a Group by name, case-insensitive
|
2018-10-09 06:21:12 +00:00
|
|
|
// If not found, mFoundNode will be nullptr
|
2015-04-10 21:16:17 +00:00
|
|
|
class FindByNameVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FindByNameVisitor(const std::string& nameToFind)
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
, mNameToFind(nameToFind)
|
2018-10-09 06:21:12 +00:00
|
|
|
, mFoundNode(nullptr)
|
2015-04-10 21:16:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-02 22:49:22 +00:00
|
|
|
virtual void apply(osg::Group& group);
|
2017-02-04 01:15:55 +00:00
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
virtual void apply(osg::Geometry& node);
|
|
|
|
|
|
|
|
bool checkGroup(osg::Group& group);
|
|
|
|
|
2015-04-19 12:25:36 +00:00
|
|
|
std::string mNameToFind;
|
2015-04-10 21:16:17 +00:00
|
|
|
osg::Group* mFoundNode;
|
|
|
|
};
|
|
|
|
|
2017-10-04 20:29:59 +00: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 10:56:03 +00:00
|
|
|
std::vector<osg::Node *> mFoundNodes;
|
2017-10-04 20:29:59 +00:00
|
|
|
};
|
|
|
|
|
2015-11-02 22:49:22 +00:00
|
|
|
// Disable freezeOnCull for all visited particlesystems
|
|
|
|
class DisableFreezeOnCullVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisableFreezeOnCullVisitor()
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-04 01:15:55 +00:00
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
|
2015-11-10 17:21:56 +00:00
|
|
|
virtual void apply(osg::Drawable& drw);
|
2015-11-02 22:49:22 +00:00
|
|
|
};
|
|
|
|
|
2018-07-14 02:48:59 +00: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)
|
2018-07-18 02:28:05 +00:00
|
|
|
{
|
|
|
|
}
|
2018-07-14 02:48:59 +00:00
|
|
|
|
|
|
|
void apply(osg::MatrixTransform& trans);
|
|
|
|
|
|
|
|
private:
|
|
|
|
NodeMap& mMap;
|
|
|
|
};
|
|
|
|
|
2018-07-18 02:28:05 +00:00
|
|
|
/// @brief Base class for visitors that remove nodes from a scene graph.
|
|
|
|
/// Subclasses need to fill the mToRemove vector.
|
|
|
|
/// To use, node->accept(removeVisitor); removeVisitor.remove();
|
|
|
|
class RemoveVisitor : public osg::NodeVisitor
|
2018-07-14 02:48:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-07-18 02:28:05 +00:00
|
|
|
RemoveVisitor()
|
2018-07-14 02:48:59 +00:00
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-18 02:28:05 +00:00
|
|
|
void remove();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// <node to remove, parent node to remove it from>
|
|
|
|
typedef std::vector<std::pair<osg::Node*, osg::Group*> > RemoveVec;
|
|
|
|
std::vector<std::pair<osg::Node*, osg::Group*> > mToRemove;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Removes all drawables from a graph.
|
|
|
|
class CleanObjectRootVisitor : public RemoveVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void apply(osg::Drawable& drw);
|
|
|
|
virtual void apply(osg::Group& node);
|
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
virtual void apply(osg::Node& node);
|
|
|
|
|
|
|
|
void applyNode(osg::Node& node);
|
|
|
|
void applyDrawable(osg::Node& node);
|
2018-07-14 02:48:59 +00:00
|
|
|
};
|
|
|
|
|
2018-07-18 02:28:05 +00:00
|
|
|
class RemoveTriBipVisitor : public RemoveVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void apply(osg::Drawable& drw);
|
|
|
|
virtual void apply(osg::Group& node);
|
|
|
|
virtual void apply(osg::MatrixTransform& node);
|
|
|
|
|
|
|
|
void applyImpl(osg::Node& node);
|
|
|
|
};
|
2015-04-10 21:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|