2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_GEODE
|
|
|
|
#define OSG_GEODE 1
|
|
|
|
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/NodeVisitor>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/Drawable>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Leaf Node for grouping Drawables.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
class SG_EXPORT Geode : public Node
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
typedef std::vector< ref_ptr<Drawable> > DrawableList;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
Geode();
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Geode(const Geode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Node(osg, Geode);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Add Drawable to Geode.
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset is not NULL and is not contained in Geode then increment its
|
2001-09-20 05:08:56 +08:00
|
|
|
* reference count, add it to the drawables list and dirty the bounding
|
2001-01-11 00:32:10 +08:00
|
|
|
* sphere to force it to recompute on next getBound() and return true for success.
|
|
|
|
* Otherwise return false.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool addDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Remove Drawable from Geode.
|
2002-11-21 17:07:11 +08:00
|
|
|
* Equivalent to setDrawabke(getDrawableIndex(orignChild),node),
|
2002-11-19 00:14:00 +08:00
|
|
|
* see docs for setNode for futher details on implementation.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool removeDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-12-08 05:18:12 +08:00
|
|
|
/** Remove drawable(s) from the specified position in Geode's drawable list.*/
|
|
|
|
virtual bool removeDrawable(unsigned int i,unsigned int numDrawablesToRemove=1);
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Replace specified Drawable with another Drawable.
|
2002-11-21 17:07:11 +08:00
|
|
|
* Equivalent to setDrawable(getDrawableIndex(orignChild),node),
|
2002-11-19 00:14:00 +08:00
|
|
|
* see docs for setDrawable for futher details on implementation.*/
|
|
|
|
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
|
|
|
|
|
|
|
|
/** set drawable at position i.
|
|
|
|
* return true if set correctly, false on failure (if node==NULL || i is out of range).
|
2001-01-11 00:32:10 +08:00
|
|
|
* Decrement the reference count origGSet and increments the
|
|
|
|
* reference count of newGset, and dirty the bounding sphere
|
|
|
|
* to force it to recompute on next getBound() and returns true.
|
2001-09-20 05:08:56 +08:00
|
|
|
* If origDrawable is not found then return false and do not
|
2001-01-11 00:32:10 +08:00
|
|
|
* add newGset. If newGset is NULL then return false and do
|
|
|
|
* not remove origGset.
|
|
|
|
*/
|
2002-11-19 00:14:00 +08:00
|
|
|
virtual bool setDrawable( unsigned int i, Drawable* drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-11-19 00:14:00 +08:00
|
|
|
/** return the number of drawable's.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumDrawables() const { return _drawables.size(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-11-19 00:14:00 +08:00
|
|
|
/** return drawable at position i.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline Drawable* getDrawable( unsigned int i ) { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-11-19 00:14:00 +08:00
|
|
|
/** return drawable at position i.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline const Drawable* getDrawable( unsigned int i ) const { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-11-19 00:14:00 +08:00
|
|
|
/** return true if drawable is contained within Geode.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool containsDrawable(const Drawable* gset) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
for (DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->get()==gset) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-11-21 17:07:11 +08:00
|
|
|
/** Get the index number of drawable, return a value between
|
2002-11-19 00:14:00 +08:00
|
|
|
* 0 and _drawables.size()-1 if found, if not found then
|
|
|
|
* return _drawables.size().*/
|
2002-11-21 17:07:11 +08:00
|
|
|
inline unsigned int getDrawableIndex( const Drawable* node ) const
|
2002-11-19 00:14:00 +08:00
|
|
|
{
|
|
|
|
for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum)
|
|
|
|
{
|
|
|
|
if (_drawables[drawableNum]==node) return drawableNum;
|
|
|
|
}
|
|
|
|
return _drawables.size(); // node not found.
|
|
|
|
}
|
|
|
|
|
|
|
|
/** compile OpenGL Display List for each drawable.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void compileDrawables(State& state);
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Geode();
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeBound() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
DrawableList _drawables;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|