2012-03-22 01:36:20 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2003-01-20 20:41:15 +08:00
*
2012-03-22 01:36:20 +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-20 20:41:15 +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.
2012-03-22 01:36:20 +08:00
*
2003-01-20 20:41:15 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-03-22 01:36:20 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2003-01-20 20:41:15 +08:00
* OpenSceneGraph Public License for more details.
*/
2002-12-16 21:40:58 +08:00
2001-10-04 23:12:57 +08:00
2001-01-11 00:32:10 +08:00
#ifndef OSG_NODE
#define OSG_NODE 1
#include <osg/Object>
2001-09-20 05:08:56 +08:00
#include <osg/StateSet>
2001-01-11 00:32:10 +08:00
#include <osg/BoundingSphere>
2014-05-14 18:19:43 +08:00
#include <osg/BoundingBox>
2001-09-22 10:42:08 +08:00
#include <osg/NodeCallback>
2001-01-11 00:32:10 +08:00
#include <string>
#include <vector>
2011-01-13 03:29:24 +08:00
// forward declare osgTerrrain::Terrain to enable declaration of asTerrain() method.
namespace osgTerrain {
class Terrain;
}
2001-01-11 00:32:10 +08:00
namespace osg {
2011-01-13 03:29:24 +08:00
// forcing declare classes to enable declaration of as*() methods.
2001-01-11 00:32:10 +08:00
class NodeVisitor;
2014-05-15 17:26:59 +08:00
class Drawable;
class Geometry;
2001-01-11 00:32:10 +08:00
class Group;
2002-09-12 23:34:31 +08:00
class Transform;
2005-12-07 23:29:29 +08:00
class Node;
2008-12-09 17:24:47 +08:00
class Switch;
class Geode;
2011-09-14 18:22:04 +08:00
class Camera;
2005-12-07 23:29:29 +08:00
/** A vector of Nodes pointers which is used to describe the path from a root node to a descendant.*/
typedef std::vector< Node* > NodePath;
/** A vector of NodePath, typically used to describe all the paths from a node to the potential root nodes it has.*/
typedef std::vector< NodePath > NodePathList;
2006-02-28 03:48:34 +08:00
/** A vector of NodePath, typically used to describe all the paths from a node to the potential root nodes it has.*/
typedef std::vector< Matrix > MatrixList;
2001-01-11 00:32:10 +08:00
2014-05-14 18:19:43 +08:00
#ifdef OSG_USE_BOUND
struct Bound
{
Bound():
bb(0),
bs(0) {}
Bound(const osg::BoundingSphere& bs):
bb(0),
bs(&bs) {}
Bound(const osg::BoundingBox& bb):
bb(&bb),
bs(0) {}
Bound(const osg::BoundingSphere& bs, const osg::BoundingBox& bb):
bb(&bb),
bs(&bs) {}
const osg::BoundingBox* bb;
const osg::BoundingSphere* bs;
bool valid() const { return bs ? bs->valid() : false; }
const osg::Vec3& center() const { return bs->center(); }
float radius() const { return bs->radius(); }
float xMin() const { return bb->xMin(); }
float yMin() const { return bb->yMin(); }
float zMin() const { return bb->zMin(); }
float xMax() const { return bb->xMax(); }
float yMax() const { return bb->yMax(); }
float zMax() const { return bb->zMax(); }
operator const osg::BoundingBox& () const { return *bb; }
operator const osg::BoundingSphere& () const { return *bs; }
};
#endif
2001-09-22 10:42:08 +08:00
/** META_Node macro define the standard clone, isSameKindAs, className
* and accept methods. Use when subclassing from Node to make it
2004-09-03 03:10:33 +08:00
* more convenient to define the required pure virtual methods.*/
2002-06-06 21:25:36 +08:00
#define META_Node(library,name) \
2002-12-16 21:40:58 +08:00
virtual osg::Object* cloneType() const { return new name (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
2001-11-03 04:11:37 +08:00
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
2001-09-22 10:42:08 +08:00
virtual const char* className() const { return #name; } \
2002-06-06 21:25:36 +08:00
virtual const char* libraryName() const { return #library; } \
2002-02-06 05:54:46 +08:00
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } } \
2012-03-22 01:36:20 +08:00
2001-09-22 10:42:08 +08:00
2001-01-11 00:32:10 +08:00
/** Base class for all internal nodes in the scene graph.
Provides interface for most common node operations (Composite Pattern).
*/
2005-04-12 01:14:17 +08:00
class OSG_EXPORT Node : public Object
2001-01-11 00:32:10 +08:00
{
public:
/** Construct a node.
2012-03-22 01:36:20 +08:00
Initialize the parent list to empty, node name to "" and
2001-01-11 00:32:10 +08:00
bounding sphere dirty flag to true.*/
Node();
2002-01-29 22:04:06 +08:00
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Node(const Node&,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
2004-09-03 03:10:33 +08:00
/** clone an object of the same type as the node.*/
2002-12-16 21:40:58 +08:00
virtual Object* cloneType() const { return new Node(); }
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
/** return a clone of a node, with Object* return type.*/
2002-12-16 21:40:58 +08:00
virtual Object* clone(const CopyOp& copyop) const { return new Node(*this,copyop); }
2001-01-11 00:32:10 +08:00
/** return true if this and obj are of the same kind of object.*/
2001-09-20 05:08:56 +08:00
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Node*>(obj)!=NULL; }
2001-01-11 00:32:10 +08:00
2002-06-06 21:25:36 +08:00
/** return the name of the node's library.*/
virtual const char* libraryName() const { return "osg"; }
2001-01-11 00:32:10 +08:00
/** return the name of the node's class type.*/
virtual const char* className() const { return "Node"; }
2014-05-15 17:26:59 +08:00
/** convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Drawable* asDrawable() { return 0; }
/** convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Drawable* asDrawable() const { return 0; }
/** convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Geometry* asGeometry() { return 0; }
/** convert 'const this' into a const Geometry pointer if Node is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Geometry* asGeometry() const { return 0; }
2002-09-12 23:34:31 +08:00
/** convert 'this' into a Group pointer if Node is a Group, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Group* asGroup() { return 0; }
/** convert 'const this' into a const Group pointer if Node is a Group, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Group* asGroup() const { return 0; }
2004-09-03 03:10:33 +08:00
/** Convert 'this' into a Transform pointer if Node is a Transform, otherwise return 0.
2002-09-12 23:34:31 +08:00
* Equivalent to dynamic_cast<Transform*>(this).*/
virtual Transform* asTransform() { return 0; }
2006-02-28 03:48:34 +08:00
2002-09-12 23:34:31 +08:00
/** convert 'const this' into a const Transform pointer if Node is a Transform, otherwise return 0.
* Equivalent to dynamic_cast<const Transform*>(this).*/
virtual const Transform* asTransform() const { return 0; }
2011-09-14 18:02:11 +08:00
/** Convert 'this' into a Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<Camera*>(this).*/
virtual Camera* asCamera() { return 0; }
/** convert 'const this' into a const Camera pointer if Node is a Camera, otherwise return 0.
* Equivalent to dynamic_cast<const Camera*>(this).*/
virtual const Camera* asCamera() const { return 0; }
2008-12-09 17:24:47 +08:00
/** Convert 'this' into a Switch pointer if Node is a Switch, otherwise return 0.
* Equivalent to dynamic_cast<Switch*>(this).*/
virtual Switch* asSwitch() { return 0; }
/** convert 'const this' into a const Switch pointer if Node is a Switch, otherwise return 0.
* Equivalent to dynamic_cast<const Switch*>(this).*/
virtual const Switch* asSwitch() const { return 0; }
/** Convert 'this' into a Geode pointer if Node is a Geode, otherwise return 0.
* Equivalent to dynamic_cast<Geode*>(this).*/
virtual Geode* asGeode() { return 0; }
/** convert 'const this' into a const Geode pointer if Node is a Geode, otherwise return 0.
* Equivalent to dynamic_cast<const Geode*>(this).*/
virtual const Geode* asGeode() const { return 0; }
2011-01-13 03:29:24 +08:00
/** Convert 'this' into a Transform pointer if Node is a Terrain, otherwise return 0.
* Equivalent to dynamic_cast<Terrrain*>(this).*/
virtual osgTerrain::Terrain* asTerrain() { return 0; }
/** convert 'const this' into a const Terrain pointer if Node is a Terrain, otherwise return 0.
* Equivalent to dynamic_cast<const Terrain*>(this).*/
virtual const osgTerrain::Terrain* asTerrain() const { return 0; }
2001-01-11 00:32:10 +08:00
/** Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.*/
virtual void accept(NodeVisitor& nv);
/** Traverse upwards : calls parents' accept method with NodeVisitor.*/
virtual void ascend(NodeVisitor& nv);
/** Traverse downwards : calls children's accept method with NodeVisitor.*/
2012-03-22 01:36:20 +08:00
virtual void traverse(NodeVisitor& /*nv*/) {}
2001-01-11 00:32:10 +08:00
/** A vector of osg::Group pointers which is used to store the parent(s) of node.*/
2014-05-13 16:43:07 +08:00
typedef std::vector<Node*> ParentList;
2001-01-11 00:32:10 +08:00
/** Get the parent list of node. */
2001-09-20 05:08:56 +08:00
inline const ParentList& getParents() const { return _parents; }
2012-03-22 01:36:20 +08:00
/** Get the a copy of parent list of node. A copy is returned to
2001-09-22 10:42:08 +08:00
* prevent modification of the parent list.*/
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
inline ParentList getParents() { return _parents; }
2001-09-20 05:08:56 +08:00
2014-05-13 16:43:07 +08:00
inline Node* getParent(unsigned int i) { return _parents[i]; }
2005-12-07 23:29:29 +08:00
2001-01-11 00:32:10 +08:00
/**
2001-09-20 05:08:56 +08:00
* Get a single const parent of node.
2001-01-11 00:32:10 +08:00
* @param i index of the parent to get.
* @return the parent i.
*/
2014-05-13 16:43:07 +08:00
inline const Node* getParent(unsigned int i) const { return _parents[i]; }
2001-09-20 05:08:56 +08:00
2001-01-11 00:32:10 +08:00
/**
* Get the number of parents of node.
* @return the number of parents of this node.
*/
2009-01-30 18:55:28 +08:00
inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
2001-01-11 00:32:10 +08:00
2014-05-13 16:43:07 +08:00
/** Provide interface for Composite like Group nodes to implement.*/
virtual unsigned int getNumChildren() const { return 0; }
/** Provide interface for Composite like Group nodes to implement.*/
virtual bool addChild( Node* /*child*/ ) { return false; }
/** Provide interface for Composite like Group nodes to implement.*/
virtual bool removeChild( Node* /*child*/ ) { return false; }
/** Provide interface for Composite like Group nodes to implement.*/
virtual bool replaceChild( Node* /*origChild*/, Node* /*newChild*/ ) { return false; }
2005-12-07 23:29:29 +08:00
/** Get the list of node paths parent paths.
* The optional Node* haltTraversalAtNode allows the user to prevent traversal beyond a specifed node. */
NodePathList getParentalNodePaths(osg::Node* haltTraversalAtNode=0) const;
2006-02-28 03:48:34 +08:00
/** Get the list of matrices that transform this node from local coordinates to world coordinates.
* The optional Node* haltTraversalAtNode allows the user to prevent traversal beyond a specifed node. */
2008-09-18 18:38:18 +08:00
MatrixList getWorldMatrices(const osg::Node* haltTraversalAtNode=0) const;
2012-03-22 01:36:20 +08:00
2001-01-11 00:32:10 +08:00
2002-12-19 23:55:40 +08:00
/** Set update node callback, called during update traversal. */
void setUpdateCallback(NodeCallback* nc);
2001-09-22 10:42:08 +08:00
2002-12-19 23:55:40 +08:00
/** Get update node callback, called during update traversal. */
inline NodeCallback* getUpdateCallback() { return _updateCallback.get(); }
2001-09-22 10:42:08 +08:00
2002-12-19 23:55:40 +08:00
/** Get const update node callback, called during update traversal. */
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
2008-12-03 22:13:59 +08:00
/** Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the existing one. */
2008-12-10 00:43:38 +08:00
inline void addUpdateCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL) {
if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc);
else setUpdateCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
2008-12-10 00:43:38 +08:00
inline void removeUpdateCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL && _updateCallback.valid()) {
2013-10-18 16:37:18 +08:00
if (_updateCallback == nc)
{
setUpdateCallback(nc->getNestedCallback()); // replace the callback by the nested one
nc->setNestedCallback(0);
}
2009-02-02 17:23:28 +08:00
else _updateCallback->removeNestedCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
2005-04-23 06:45:39 +08:00
/** Get the number of Children of this node which require Update traversal,
* since they have an Update Callback attached to them or their children.*/
2002-12-19 23:55:40 +08:00
inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
2001-09-22 10:42:08 +08:00
2001-10-19 20:56:37 +08:00
2008-12-03 22:13:59 +08:00
/** Set event node callback, called during event traversal. */
2004-10-24 21:51:44 +08:00
void setEventCallback(NodeCallback* nc);
2008-12-03 22:13:59 +08:00
/** Get event node callback, called during event traversal. */
2004-10-24 21:51:44 +08:00
inline NodeCallback* getEventCallback() { return _eventCallback.get(); }
2008-12-03 22:13:59 +08:00
/** Get const event node callback, called during event traversal. */
2004-10-24 21:51:44 +08:00
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
2008-12-03 22:13:59 +08:00
/** Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the existing one. */
2008-12-10 00:43:38 +08:00
inline void addEventCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL) {
if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc);
else setEventCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
2008-12-10 00:43:38 +08:00
inline void removeEventCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL && _eventCallback.valid()) {
2013-10-18 16:37:18 +08:00
if (_eventCallback == nc)
{
setEventCallback(nc->getNestedCallback()); // replace the callback by the nested one
nc->setNestedCallback(0);
}
2009-02-02 17:23:28 +08:00
else _eventCallback->removeNestedCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
2005-04-23 06:45:39 +08:00
/** Get the number of Children of this node which require Event traversal,
* since they have an Event Callback attached to them or their children.*/
2004-10-24 21:51:44 +08:00
inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
2002-04-15 21:15:48 +08:00
/** Set cull node callback, called during cull traversal. */
void setCullCallback(NodeCallback* nc) { _cullCallback = nc; }
2002-11-11 16:04:40 +08:00
/** Get cull node callback, called during cull traversal. */
2002-04-15 21:15:48 +08:00
inline NodeCallback* getCullCallback() { return _cullCallback.get(); }
2002-11-11 16:04:40 +08:00
/** Get const cull node callback, called during cull traversal. */
2002-04-15 21:15:48 +08:00
inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); }
2008-12-03 22:13:59 +08:00
/** Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the existing one. */
2008-12-10 00:43:38 +08:00
inline void addCullCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL) {
if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc);
else setCullCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
2008-12-10 00:43:38 +08:00
inline void removeCullCallback(NodeCallback* nc) {
2009-02-02 17:23:28 +08:00
if (nc != NULL && _cullCallback.valid()) {
2013-10-18 16:37:18 +08:00
if (_cullCallback == nc)
{
setCullCallback(nc->getNestedCallback()); // replace the callback by the nested one
nc->setNestedCallback(0);
}
2009-02-02 17:23:28 +08:00
else _cullCallback->removeNestedCallback(nc);
}
2008-12-03 22:13:59 +08:00
}
2001-10-19 20:56:37 +08:00
/** Set the view frustum/small feature culling of this node to be active or inactive.
2004-09-03 03:10:33 +08:00
* The default value is true for _cullingActive. Used as a guide
2001-10-19 20:56:37 +08:00
* to the cull traversal.*/
2002-09-02 20:31:35 +08:00
void setCullingActive(bool active);
2001-10-19 20:56:37 +08:00
2004-09-03 03:10:33 +08:00
/** Get the view frustum/small feature _cullingActive flag for this node. Used as a guide
2001-10-19 20:56:37 +08:00
* to the cull traversal.*/
2002-09-02 20:31:35 +08:00
inline bool getCullingActive() const { return _cullingActive; }
2001-10-19 20:56:37 +08:00
/** Get the number of Children of this node which have culling disabled.*/
2002-09-02 20:31:35 +08:00
inline unsigned int getNumChildrenWithCullingDisabled() const { return _numChildrenWithCullingDisabled; }
2001-10-19 20:56:37 +08:00
2002-06-03 23:39:41 +08:00
/** Return true if this node can be culled by view frustum, occlusion or small feature culling during the cull traversal.
2004-09-03 03:10:33 +08:00
* Note, returns true only if no children have culling disabled, and the local _cullingActive flag is true.*/
2002-11-11 16:52:24 +08:00
inline bool isCullingActive() const { return _numChildrenWithCullingDisabled==0 && _cullingActive && getBound().valid(); }
2002-06-03 23:39:41 +08:00
2002-06-10 21:50:25 +08:00
/** Get the number of Children of this node which are or have OccluderNode's.*/
2002-09-02 20:31:35 +08:00
inline unsigned int getNumChildrenWithOccluderNodes() const { return _numChildrenWithOccluderNodes; }
2002-06-10 21:50:25 +08:00
2012-03-22 01:36:20 +08:00
2002-06-10 21:50:25 +08:00
/** return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.*/
2002-09-02 20:31:35 +08:00
bool containsOccluderNodes() const;
2001-10-19 20:56:37 +08:00
2001-01-11 00:32:10 +08:00
2009-07-24 23:30:13 +08:00
/**
* This is a set of bits (flags) that represent the Node.
* The default value is 0xffffffff (all bits set).
*
* The most common use of these is during traversal of the scene graph.
2009-07-28 14:00:23 +08:00
* For instance, when traversing the scene graph the osg::NodeVisitor does a bitwise
2011-12-24 00:14:51 +08:00
* AND of its TraversalMask with the Node's NodeMask to
2009-07-24 23:30:13 +08:00
* determine if the Node should be processed/traversed.
*
2009-07-28 14:00:23 +08:00
* For example, if a Node has a NodeMask value of 0x02 (only 2nd bit set)
* and the osg::Camera has a CullMask of 0x4 (2nd bit not set) then during cull traversal,
* which takes it's TraversalMask from the Camera's CullMask, the node and any children
* would be ignored and thereby treated as "culled" and thus not rendered.
* Conversely, if the osg::Camera CullMask were 0x3 (2nd bit set) then the node
2009-07-24 23:30:13 +08:00
* would be processed and child Nodes would be examined.
*/
2001-01-11 00:32:10 +08:00
typedef unsigned int NodeMask;
2004-06-15 03:17:32 +08:00
/** Set the node mask.*/
2002-09-02 20:31:35 +08:00
inline void setNodeMask(NodeMask nm) { _nodeMask = nm; }
2004-06-15 03:17:32 +08:00
/** Get the node Mask.*/
2002-09-02 20:31:35 +08:00
inline NodeMask getNodeMask() const { return _nodeMask; }
2001-01-11 00:32:10 +08:00
2004-09-03 03:10:33 +08:00
/** Set the node's StateSet.*/
2005-04-25 05:04:54 +08:00
void setStateSet(osg::StateSet* stateset);
2001-09-20 05:08:56 +08:00
2002-05-04 06:47:57 +08:00
/** return the node's StateSet, if one does not already exist create it
* set the node and return the newly created StateSet. This ensures
* that a valid StateSet is always returned and can be used directly.*/
2002-09-02 20:31:35 +08:00
osg::StateSet* getOrCreateStateSet();
2002-05-04 06:47:57 +08:00
2004-09-03 03:10:33 +08:00
/** Return the node's StateSet. returns NULL if a stateset is not attached.*/
2002-09-02 20:31:35 +08:00
inline osg::StateSet* getStateSet() { return _stateset.get(); }
2001-09-20 05:08:56 +08:00
2005-05-12 22:03:22 +08:00
/** Return the node's const StateSet. Returns NULL if a stateset is not attached.*/
2002-09-02 20:31:35 +08:00
inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
2001-09-20 05:08:56 +08:00
2011-06-09 20:57:14 +08:00
/** A vector of std::string's which are used to describe the object.*/
typedef std::vector<std::string> DescriptionList;
/** Set the list of string descriptions.*/
void setDescriptions(const DescriptionList& descriptions);
/** Get the description list of the node.*/
DescriptionList& getDescriptions();
/** Get the const description list of the const node.*/
const DescriptionList& getDescriptions() const;
/** Get a single const description of the const node.*/
const std::string& getDescription(unsigned int i) const;
/** Get a single description of the node.*/
std::string& getDescription(unsigned int i);
/** Get the number of descriptions of the node.*/
unsigned int getNumDescriptions() const;
/** Add a description string to the node.*/
void addDescription(const std::string& desc);
2012-03-22 01:36:20 +08:00
2011-06-09 20:57:14 +08:00
2007-12-11 01:30:18 +08:00
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
2005-05-12 22:03:22 +08:00
void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); }
2007-12-11 01:30:18 +08:00
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
2005-05-12 22:03:22 +08:00
const BoundingSphere& getInitialBound() const { return _initialBound; }
/** Mark this node's bounding sphere dirty.
Forcing it to be computed on the next call to getBound().*/
void dirtyBound();
/** Get the bounding sphere of node.
2001-01-11 00:32:10 +08:00
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
2014-05-14 18:19:43 +08:00
#ifdef OSG_USE_BOUND
2014-05-15 00:01:40 +08:00
virtual Bound getBound() const
2001-09-20 05:08:56 +08:00
{
2005-05-12 22:03:22 +08:00
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
2012-03-22 01:36:20 +08:00
if (_computeBoundCallback.valid())
2005-05-12 22:03:22 +08:00
_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());
2012-03-22 01:36:20 +08:00
2005-05-12 22:03:22 +08:00
_boundingSphereComputed = true;
}
2014-05-14 18:19:43 +08:00
return Bound(_boundingSphere);
2001-09-20 05:08:56 +08:00
}
2014-05-14 18:19:43 +08:00
#else
2014-05-15 00:01:40 +08:00
inline const BoundingSphere& getBound() const
2014-05-14 18:19:43 +08:00
{
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
if (_computeBoundCallback.valid())
_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());
2001-09-20 05:08:56 +08:00
2014-05-14 18:19:43 +08:00
_boundingSphereComputed = true;
}
return _boundingSphere;
}
#endif
2001-01-11 00:32:10 +08:00
2005-05-12 22:03:22 +08:00
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding
sphere has been marked dirty via dirtyBound().*/
virtual BoundingSphere computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
2005-05-12 22:48:56 +08:00
struct ComputeBoundingSphereCallback : public osg::Object
2005-05-12 22:03:22 +08:00
{
2005-05-12 22:48:56 +08:00
ComputeBoundingSphereCallback() {}
ComputeBoundingSphereCallback(const ComputeBoundingSphereCallback&,const CopyOp&) {}
META_Object(osg,ComputeBoundingSphereCallback);
virtual BoundingSphere computeBound(const osg::Node&) const { return BoundingSphere(); }
2005-05-12 22:03:22 +08:00
};
/** Set the compute bound callback to override the default computeBound.*/
2005-05-12 22:48:56 +08:00
void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback* callback) { _computeBoundCallback = callback; }
2005-05-12 22:03:22 +08:00
/** Get the compute bound callback.*/
2005-05-12 22:48:56 +08:00
ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() { return _computeBoundCallback.get(); }
2005-05-12 22:03:22 +08:00
/** Get the const compute bound callback.*/
2005-05-12 22:48:56 +08:00
const ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() const { return _computeBoundCallback.get(); }
2001-01-11 00:32:10 +08:00
2007-01-05 00:49:58 +08:00
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
2007-01-04 22:11:51 +08:00
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/);
2001-01-11 00:32:10 +08:00
2005-05-08 04:47:09 +08:00
/** If State is non-zero, this function releases any associated OpenGL objects for
2007-12-11 01:30:18 +08:00
* the specified graphics context. Otherwise, releases OpenGL objects
2005-05-08 04:47:09 +08:00
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
2001-01-11 00:32:10 +08:00
protected:
/** Node destructor. Note, is protected so that Nodes cannot
be deleted other than by being dereferenced and the reference
count being zero (see osg::Referenced), preventing the deletion
of nodes which are still in use. This also means that
2004-09-03 03:10:33 +08:00
Nodes cannot be created on stack i.e Node node will not compile,
2001-01-11 00:32:10 +08:00
forcing all nodes to be created on the heap i.e Node* node
= new Node().*/
virtual ~Node();
2005-05-12 22:48:56 +08:00
BoundingSphere _initialBound;
ref_ptr<ComputeBoundingSphereCallback> _computeBoundCallback;
mutable BoundingSphere _boundingSphere;
mutable bool _boundingSphereComputed;
2001-01-11 00:32:10 +08:00
2014-05-13 16:43:07 +08:00
void addParent(osg::Node* node);
void removeParent(osg::Node* node);
2002-02-09 06:55:21 +08:00
2001-01-11 00:32:10 +08:00
ParentList _parents;
2002-01-19 06:34:07 +08:00
friend class osg::Group;
2002-07-10 23:35:47 +08:00
friend class osg::Drawable;
2005-04-25 21:37:12 +08:00
friend class osg::StateSet;
2001-01-11 00:32:10 +08:00
2002-12-19 23:55:40 +08:00
ref_ptr<NodeCallback> _updateCallback;
unsigned int _numChildrenRequiringUpdateTraversal;
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
2001-09-22 10:42:08 +08:00
2004-10-24 21:51:44 +08:00
ref_ptr<NodeCallback> _eventCallback;
unsigned int _numChildrenRequiringEventTraversal;
void setNumChildrenRequiringEventTraversal(unsigned int num);
2002-04-15 21:15:48 +08:00
ref_ptr<NodeCallback> _cullCallback;
2001-10-19 20:56:37 +08:00
bool _cullingActive;
2012-03-22 01:36:20 +08:00
unsigned int _numChildrenWithCullingDisabled;
2002-09-02 20:31:35 +08:00
void setNumChildrenWithCullingDisabled(unsigned int num);
2001-10-19 20:56:37 +08:00
2012-03-22 01:36:20 +08:00
unsigned int _numChildrenWithOccluderNodes;
2002-09-02 20:31:35 +08:00
void setNumChildrenWithOccluderNodes(unsigned int num);
2002-06-10 21:50:25 +08:00
2001-01-11 00:32:10 +08:00
NodeMask _nodeMask;
2002-09-02 20:31:35 +08:00
ref_ptr<StateSet> _stateset;
2001-09-20 05:08:56 +08:00
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