2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2005-01-27 21:15:21 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2005-01-27 21:15:21 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-01-27 21:15:21 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
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 {
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** A \c Geode is a "geometry node", that is, a leaf node on the scene graph
|
|
|
|
* that can have "renderable things" attached to it. In OSG, renderable things
|
|
|
|
* are represented by objects from the \c Drawable class, so a \c Geode is a
|
|
|
|
* \c Node whose purpose is grouping <tt>Drawable</tt>s.
|
|
|
|
*/
|
2014-06-03 17:23:24 +08:00
|
|
|
class OSG_EXPORT Geode : public Group
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-12-09 17:24:47 +08:00
|
|
|
virtual Geode* asGeode() { return this; }
|
|
|
|
virtual const Geode* asGeode() const { return this; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** 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
|
|
|
|
* dirty the bounding sphere to force it to be recomputed on the next
|
|
|
|
* call to \c getBound().
|
|
|
|
* @param drawable The \c Drawable to be added to the \c Geode.
|
|
|
|
* @return \c true for success; \c false otherwise.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool addDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> bool addDrawable( const ref_ptr<T>& drawable ) { return addDrawable(drawable.get()); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Remove a \c Drawable from the \c Geode.
|
|
|
|
* Equivalent to <tt>removeDrawable(getDrawableIndex(drawable)</tt>.
|
|
|
|
* @param drawable The drawable to be removed.
|
|
|
|
* @return \c true if at least one \c Drawable was removed. \c false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool removeDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> bool removeDrawable( const ref_ptr<T>& drawable ) { return removeDrawable( drawable.get() ); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Remove <tt>Drawable</tt>(s) from the specified position in
|
|
|
|
* <tt>Geode</tt>'s drawable list.
|
|
|
|
* @param i The index of the first \c Drawable to remove.
|
|
|
|
* @param numDrawablesToRemove The number of <tt>Drawable</tt> to
|
|
|
|
* remove.
|
|
|
|
* @return \c true if at least one \c Drawable was removed. \c false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2006-05-02 17:45:31 +08:00
|
|
|
virtual bool removeDrawables(unsigned int i,unsigned int numDrawablesToRemove=1);
|
2002-12-08 05:18:12 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Replace specified Drawable with another Drawable.
|
2005-01-27 21:15:21 +08:00
|
|
|
* Equivalent to <tt>setDrawable(getDrawableIndex(origDraw),newDraw)</tt>,
|
|
|
|
* see docs for \c setDrawable() for further details on implementation.
|
|
|
|
*/
|
2002-11-19 00:14:00 +08:00
|
|
|
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
|
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T, class R> bool replaceDrawable( const ref_ptr<T>& origDraw, const ref_ptr<R>& newDraw ) { return replaceDrawable(origDraw.get(), newDraw.get()); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Set \c Drawable at position \c i.
|
|
|
|
* 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.
|
|
|
|
* If origDrawable is not found then return false and do not
|
|
|
|
* add newGset. If newGset is NULL then return false and do
|
|
|
|
* not remove origGset.
|
|
|
|
* @return \c true if set correctly, \c false on failure
|
|
|
|
* (if node==NULL || i is out of range).
|
|
|
|
*/
|
2002-11-19 00:14:00 +08:00
|
|
|
virtual bool setDrawable( unsigned int i, Drawable* drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> bool setDrawable( unsigned int i, const ref_ptr<T>& drawable ) { return setDrawable(i, drawable.get()); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the number of <tt>Drawable</tt>s currently attached to the
|
|
|
|
* \c Geode.
|
|
|
|
*/
|
2014-06-03 17:23:24 +08:00
|
|
|
inline unsigned int getNumDrawables() const { return getNumChildren(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the \c Drawable at position \c i.*/
|
2014-06-03 17:23:24 +08:00
|
|
|
inline Drawable* getDrawable( unsigned int i ) { return _children[i].valid() ? _children[i]->asDrawable() : 0; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the \c Drawable at position \c i.*/
|
2014-06-03 17:23:24 +08:00
|
|
|
inline const Drawable* getDrawable( unsigned int i ) const { return _children[i].valid() ? _children[i]->asDrawable() : 0; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return \c true if a given \c Drawable is contained within \c Geode.*/
|
2014-06-03 17:23:24 +08:00
|
|
|
inline bool containsDrawable(const Drawable* drawable) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2014-06-03 17:23:24 +08:00
|
|
|
for (NodeList::const_iterator itr=_children.begin();
|
|
|
|
itr!=_children.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
2014-06-03 17:23:24 +08:00
|
|
|
if (itr->get() == drawable) return true;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> bool containsDrawable(const ref_ptr<T>& drawable) const { return containsDrawable(drawable.get()); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Get the index number of \c drawable.
|
|
|
|
* @return A value between 0 and <tt>getNumDrawables()-1</tt> if
|
|
|
|
* \c drawable is found; if not found, then
|
|
|
|
* <tt>getNumDrawables()</tt> is returned.
|
|
|
|
*/
|
|
|
|
inline unsigned int getDrawableIndex( const Drawable* drawable ) const
|
2002-11-19 00:14:00 +08:00
|
|
|
{
|
2014-06-03 17:23:24 +08:00
|
|
|
return getChildIndex(drawable);
|
2002-11-19 00:14:00 +08:00
|
|
|
}
|
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> unsigned int getDrawableIndex( const ref_ptr<T>& drawable ) const { return getDrawableIndex(drawable.get()); }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Compile OpenGL Display List for each drawable.*/
|
2006-11-14 20:51:31 +08:00
|
|
|
void compileDrawables(RenderInfo& renderInfo);
|
2005-01-27 21:15:21 +08:00
|
|
|
|
|
|
|
/** Return the Geode's bounding box, which is the union of all the
|
2004-04-22 18:47:12 +08:00
|
|
|
* bounding boxes of the geode's drawables.*/
|
|
|
|
inline const BoundingBox& getBoundingBox() const
|
|
|
|
{
|
2005-05-12 22:03:22 +08:00
|
|
|
if(!_boundingSphereComputed) getBound();
|
2004-04-22 18:47:12 +08:00
|
|
|
return _bbox;
|
|
|
|
}
|
2005-01-27 21:15:21 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Geode();
|
|
|
|
|
2004-04-22 18:47:12 +08:00
|
|
|
mutable osg::BoundingBox _bbox;
|
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
|