From Farshid Lashkari, "As discussed, I've added the ability to handle Drawable objects within the NodeVisitor class. Here is an overview of the changes:

- Added apply(Drawable) and apply(Geometry) to NodeVisitor

- Added accept(NodeVisitor) method to Drawable/Geometry

- Added traverse(NodeVisitor) to Geode which calls accept(NodeVisitor) on all Drawables

- Updated CullVisitor to use new apply(Drawable) to handle drawables. The apply(Billboard) method still manually handles the drawables since it is depends on the billboard settings. I needed to disable the traverse within billboard to prevent duplicate traversal of drawables.

- Update other osgUtil node visitors (GLObjectsVisitor, IncrementalCompileOperation, ..) to use new apply(Drawable) method.
"
This commit is contained in:
Robert Osfield
2014-05-12 12:10:35 +00:00
parent ead92353fe
commit b2c7bacfe9
13 changed files with 130 additions and 118 deletions

View File

@@ -115,6 +115,8 @@ class OSG_EXPORT Drawable : public Object
* Equivalent to dynamic_cast<const Geometry*>(this).*/
virtual const Geometry* asGeometry() const { return 0; }
/** Visitor Pattern : calls the apply method of a NodeVisitor with this drawable's type.*/
virtual void accept(NodeVisitor& nv);
/** Compute the DataVariance based on an assessment of callback etc.*/
virtual void computeDataVariance();

View File

@@ -41,6 +41,8 @@ class OSG_EXPORT Geode : public Node
virtual Geode* asGeode() { return this; }
virtual const Geode* asGeode() const { return this; }
virtual void traverse(NodeVisitor& nv);
/** Add a \c Drawable to the \c Geode.
* If \c drawable is not \c NULL and is not contained in the \c Geode
* then increment its reference count, add it to the drawables list and

View File

@@ -44,6 +44,8 @@ class OSG_EXPORT Geometry : public Drawable
virtual Geometry* asGeometry() { return this; }
virtual const Geometry* asGeometry() const { return this; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
bool empty() const;
typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;

View File

@@ -41,6 +41,8 @@ class TexGenNode;
class Transform;
class Camera;
class CameraView;
class Drawable;
class Geometry;
const unsigned int UNINITIALIZED_FRAME_NUMBER=0xffffffff;
@@ -89,7 +91,7 @@ class OSG_EXPORT NodeVisitor : public virtual Object
NodeVisitor(const NodeVisitor& nv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
virtual ~NodeVisitor();
virtual ~NodeVisitor();
META_Object(osg, NodeVisitor)
@@ -237,6 +239,8 @@ class OSG_EXPORT NodeVisitor : public virtual Object
* If the getDistanceToViewPoint(pos) is not implemented then a default value of 0.0 is returned.*/
virtual float getDistanceToViewPoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; }
virtual void apply(Drawable& drawable);
virtual void apply(Geometry& drawable);
virtual void apply(Node& node);

View File

@@ -90,6 +90,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
virtual void apply(osg::Node&);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Drawable& drawable);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::LightSource& node);
virtual void apply(osg::ClipNode& node);

View File

@@ -44,7 +44,6 @@ class OSGUTIL_EXPORT StateToCompile : public osg::NodeVisitor
bool empty() const { return _textures.empty() && _programs.empty() && _drawables.empty(); }
virtual void apply(osg::Node& node);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Drawable& drawable);
virtual void apply(osg::StateSet& stateset);