2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Notify>
|
2002-06-10 21:50:25 +08:00
|
|
|
#include <osg/OccluderNode>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
Node::Node()
|
|
|
|
{
|
|
|
|
_bsphere_computed = false;
|
|
|
|
_nodeMask = 0xffffffff;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
_numChildrenRequiringUpdateTraversal = 0;
|
2001-10-19 20:56:37 +08:00
|
|
|
|
2004-10-24 21:51:44 +08:00
|
|
|
_numChildrenRequiringEventTraversal = 0;
|
|
|
|
|
2001-10-19 20:56:37 +08:00
|
|
|
_cullingActive = true;
|
|
|
|
_numChildrenWithCullingDisabled = 0;
|
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
_numChildrenWithOccluderNodes = 0;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
Node::Node(const Node& node,const CopyOp& copyop):
|
|
|
|
Object(node,copyop),
|
2004-10-02 06:05:40 +08:00
|
|
|
_bsphere(node._bsphere),
|
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
|
|
|
_bsphere_computed(node._bsphere_computed),
|
|
|
|
_name(node._name),
|
|
|
|
_parents(), // leave empty as parentList is managed by Group.
|
2002-12-19 23:55:40 +08:00
|
|
|
_updateCallback(node._updateCallback),
|
|
|
|
_numChildrenRequiringUpdateTraversal(0), // assume no children yet.
|
2004-10-24 21:51:44 +08:00
|
|
|
_numChildrenRequiringEventTraversal(0), // assume no children yet.
|
2002-04-15 21:15:48 +08:00
|
|
|
_cullCallback(node._cullCallback),
|
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
|
|
|
_cullingActive(node._cullingActive),
|
2002-01-29 20:52:04 +08:00
|
|
|
_numChildrenWithCullingDisabled(0), // assume no children yet.
|
2002-06-10 21:50:25 +08:00
|
|
|
_numChildrenWithOccluderNodes(0),
|
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
|
|
|
_nodeMask(node._nodeMask),
|
|
|
|
_descriptions(node._descriptions),
|
2002-09-02 20:31:35 +08:00
|
|
|
_stateset(copyop(node._stateset.get()))
|
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
|
|
|
{
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
Node::~Node()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
void Node::addParent(osg::Group* node)
|
|
|
|
{
|
|
|
|
_parents.push_back(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::removeParent(osg::Group* node)
|
|
|
|
{
|
|
|
|
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
|
|
|
|
if (pitr!=_parents.end()) _parents.erase(pitr);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
void Node::accept(NodeVisitor& nv)
|
|
|
|
{
|
2002-02-06 05:54:46 +08:00
|
|
|
if (nv.validNodeMask(*this))
|
|
|
|
{
|
|
|
|
nv.pushOntoNodePath(this);
|
|
|
|
nv.apply(*this);
|
|
|
|
nv.popFromNodePath();
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
void Node::ascend(NodeVisitor& nv)
|
|
|
|
{
|
|
|
|
std::for_each(_parents.begin(),_parents.end(),NodeAcceptOp(nv));
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
osg::StateSet* Node::getOrCreateStateSet()
|
2002-05-04 06:47:57 +08:00
|
|
|
{
|
2002-12-16 21:40:58 +08:00
|
|
|
if (!_stateset) _stateset = new StateSet;
|
2002-09-02 20:31:35 +08:00
|
|
|
return _stateset.get();
|
2002-05-04 06:47:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
void Node::setUpdateCallback(NodeCallback* nc)
|
2001-09-22 10:42:08 +08:00
|
|
|
{
|
|
|
|
// if no changes just return.
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_updateCallback==nc) return;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
// app callback has been changed, will need to update
|
2002-12-19 23:55:40 +08:00
|
|
|
// both _updateCallback and possibly the numChildrenRequiringAppTraversal
|
2001-09-22 10:42:08 +08:00
|
|
|
// if the number of callbacks changes.
|
|
|
|
|
|
|
|
|
|
|
|
// update the parents numChildrenRequiringAppTraversal
|
2002-12-19 23:55:40 +08:00
|
|
|
// note, if _numChildrenRequiringUpdateTraversal!=0 then the
|
2001-09-22 10:42:08 +08:00
|
|
|
// parents won't be affected by any app callback change,
|
|
|
|
// so no need to inform them.
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_numChildrenRequiringUpdateTraversal==0 && !_parents.empty())
|
2001-09-22 10:42:08 +08:00
|
|
|
{
|
|
|
|
int delta = 0;
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_updateCallback.valid()) --delta;
|
2001-09-22 10:42:08 +08:00
|
|
|
if (nc) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
(*itr)->setNumChildrenRequiringUpdateTraversal(
|
|
|
|
(*itr)->getNumChildrenRequiringUpdateTraversal()+delta );
|
2001-09-22 10:42:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the app callback itself.
|
2002-12-19 23:55:40 +08:00
|
|
|
_updateCallback = nc;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
void Node::setNumChildrenRequiringUpdateTraversal(unsigned int num)
|
2001-09-22 10:42:08 +08:00
|
|
|
{
|
|
|
|
// if no changes just return.
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_numChildrenRequiringUpdateTraversal==num) return;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
// note, if _updateCallback is set then the
|
2001-09-22 10:42:08 +08:00
|
|
|
// parents won't be affected by any changes to
|
2002-12-19 23:55:40 +08:00
|
|
|
// _numChildrenRequiringUpdateTraversal so no need to inform them.
|
|
|
|
if (!_updateCallback && !_parents.empty())
|
2001-09-22 10:42:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
// need to pass on changes to parents.
|
|
|
|
int delta = 0;
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_numChildrenRequiringUpdateTraversal>0) --delta;
|
2001-09-22 10:42:08 +08:00
|
|
|
if (num>0) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
(*itr)->setNumChildrenRequiringUpdateTraversal(
|
|
|
|
(*itr)->getNumChildrenRequiringUpdateTraversal()+delta
|
2001-09-22 10:42:08 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally update this objects value.
|
2002-12-19 23:55:40 +08:00
|
|
|
_numChildrenRequiringUpdateTraversal=num;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-10-24 21:51:44 +08:00
|
|
|
|
|
|
|
void Node::setEventCallback(NodeCallback* nc)
|
|
|
|
{
|
|
|
|
// if no changes just return.
|
|
|
|
if (_eventCallback==nc) return;
|
|
|
|
|
|
|
|
// app callback has been changed, will need to Event
|
|
|
|
// both _EventCallback and possibly the numChildrenRequiringAppTraversal
|
|
|
|
// if the number of callbacks changes.
|
|
|
|
|
|
|
|
|
|
|
|
// Event the parents numChildrenRequiringAppTraversal
|
|
|
|
// note, if _numChildrenRequiringEventTraversal!=0 then the
|
|
|
|
// parents won't be affected by any app callback change,
|
|
|
|
// so no need to inform them.
|
|
|
|
if (_numChildrenRequiringEventTraversal==0 && !_parents.empty())
|
|
|
|
{
|
|
|
|
int delta = 0;
|
|
|
|
if (_eventCallback.valid()) --delta;
|
|
|
|
if (nc) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setNumChildrenRequiringEventTraversal(
|
|
|
|
(*itr)->getNumChildrenRequiringEventTraversal()+delta );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the app callback itself.
|
|
|
|
_eventCallback = nc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setNumChildrenRequiringEventTraversal(unsigned int num)
|
|
|
|
{
|
|
|
|
// if no changes just return.
|
|
|
|
if (_numChildrenRequiringEventTraversal==num) return;
|
|
|
|
|
|
|
|
// note, if _EventCallback is set then the
|
|
|
|
// parents won't be affected by any changes to
|
|
|
|
// _numChildrenRequiringEventTraversal so no need to inform them.
|
|
|
|
if (!_eventCallback && !_parents.empty())
|
|
|
|
{
|
|
|
|
|
|
|
|
// need to pass on changes to parents.
|
|
|
|
int delta = 0;
|
|
|
|
if (_numChildrenRequiringEventTraversal>0) --delta;
|
|
|
|
if (num>0) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setNumChildrenRequiringEventTraversal(
|
|
|
|
(*itr)->getNumChildrenRequiringEventTraversal()+delta
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally Event this objects value.
|
|
|
|
_numChildrenRequiringEventTraversal=num;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void Node::setCullingActive(bool active)
|
2001-10-19 20:56:37 +08:00
|
|
|
{
|
|
|
|
// if no changes just return.
|
|
|
|
if (_cullingActive == active) return;
|
|
|
|
|
|
|
|
// culling active has been changed, will need to update
|
|
|
|
// both _cullActive and possibly the parents numChildrenWithCullingDisabled
|
|
|
|
// if culling disabled changes.
|
|
|
|
|
|
|
|
// update the parents _numChildrenWithCullingDisabled
|
|
|
|
// note, if _numChildrenWithCullingDisabled!=0 then the
|
|
|
|
// parents won't be affected by any app callback change,
|
|
|
|
// so no need to inform them.
|
|
|
|
if (_numChildrenWithCullingDisabled==0 && !_parents.empty())
|
|
|
|
{
|
|
|
|
int delta = 0;
|
|
|
|
if (!_cullingActive) --delta;
|
|
|
|
if (!active) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setNumChildrenWithCullingDisabled(
|
|
|
|
(*itr)->getNumChildrenWithCullingDisabled()+delta );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the cullingActive itself.
|
|
|
|
_cullingActive = active;
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void Node::setNumChildrenWithCullingDisabled(unsigned int num)
|
2001-10-19 20:56:37 +08:00
|
|
|
{
|
|
|
|
// if no changes just return.
|
|
|
|
if (_numChildrenWithCullingDisabled==num) return;
|
|
|
|
|
|
|
|
// note, if _cullingActive is false then the
|
|
|
|
// parents won't be affected by any changes to
|
|
|
|
// _numChildrenWithCullingDisabled so no need to inform them.
|
|
|
|
if (_cullingActive && !_parents.empty())
|
|
|
|
{
|
|
|
|
|
|
|
|
// need to pass on changes to parents.
|
|
|
|
int delta = 0;
|
|
|
|
if (_numChildrenWithCullingDisabled>0) --delta;
|
|
|
|
if (num>0) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setNumChildrenWithCullingDisabled(
|
|
|
|
(*itr)->getNumChildrenWithCullingDisabled()+delta
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally update this objects value.
|
|
|
|
_numChildrenWithCullingDisabled=num;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void Node::setNumChildrenWithOccluderNodes(unsigned int num)
|
2002-06-10 21:50:25 +08:00
|
|
|
{
|
|
|
|
// if no changes just return.
|
|
|
|
if (_numChildrenWithOccluderNodes==num) return;
|
|
|
|
|
|
|
|
// note, if this node is a OccluderNode then the
|
|
|
|
// parents won't be affected by any changes to
|
|
|
|
// _numChildrenWithOccluderNodes so no need to inform them.
|
|
|
|
if (!dynamic_cast<OccluderNode*>(this) && !_parents.empty())
|
|
|
|
{
|
|
|
|
|
|
|
|
// need to pass on changes to parents.
|
|
|
|
int delta = 0;
|
|
|
|
if (_numChildrenWithOccluderNodes>0) --delta;
|
|
|
|
if (num>0) ++delta;
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
// the number of callbacks has changed, need to pass this
|
|
|
|
// on to parents so they know whether app traversal is
|
|
|
|
// reqired on this subgraph.
|
|
|
|
for(ParentList::iterator itr =_parents.begin();
|
|
|
|
itr != _parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setNumChildrenWithOccluderNodes(
|
|
|
|
(*itr)->getNumChildrenWithOccluderNodes()+delta
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally update this objects value.
|
|
|
|
_numChildrenWithOccluderNodes=num;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Node::containsOccluderNodes() const
|
2002-06-10 21:50:25 +08:00
|
|
|
{
|
|
|
|
return _numChildrenWithOccluderNodes>0 || dynamic_cast<const OccluderNode*>(this);
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Node::computeBound() const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
_bsphere.init();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Node::dirtyBound()
|
|
|
|
{
|
|
|
|
if (_bsphere_computed)
|
|
|
|
{
|
|
|
|
_bsphere_computed = false;
|
|
|
|
|
|
|
|
// dirty parent bounding sphere's to ensure that all are valid.
|
|
|
|
for(ParentList::iterator itr=_parents.begin();
|
2001-09-20 05:08:56 +08:00
|
|
|
itr!=_parents.end();
|
|
|
|
++itr)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
(*itr)->dirtyBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|