From Cedric Pinson and Robert Osfield, addition of NodeCallbacks to osg::CopyOp and osg::Node copy constructor.

This commit is contained in:
Robert Osfield 2009-06-18 10:01:39 +00:00
parent 1e45b24a7f
commit 1523032d2b
3 changed files with 25 additions and 2 deletions

View File

@ -30,6 +30,7 @@ class Drawable;
class Array;
class PrimitiveSet;
class Shape;
class NodeCallback;
/** Copy Op(erator) used to control whether shallow or deep copy is used
* during copy construction and clone operation.*/
@ -52,6 +53,7 @@ class OSG_EXPORT CopyOp
DEEP_COPY_PRIMITIVES = 1<<8,
DEEP_COPY_SHAPES = 1<<9,
DEEP_COPY_UNIFORMS = 1<<10,
DEEP_COPY_NODECALLBACKS = 1<<11,
DEEP_COPY_ALL = 0x7FFFFFFF
};
@ -72,6 +74,7 @@ class OSG_EXPORT CopyOp
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
virtual Shape* operator() (const Shape* shape) const;
virtual Uniform* operator() (const Uniform* shape) const;
virtual NodeCallback* operator() (const NodeCallback* nodecallback) const;
protected:

View File

@ -65,3 +65,23 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
}
NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
{
if (nc && _flags&DEEP_COPY_NODECALLBACKS)
{
// deep copy the full chain of callback
osg::NodeCallback* first = dynamic_cast<osg::NodeCallback*>(nc->clone(*this));
first->setNestedCallback(0);
nc = nc->getNestedCallback();
while (nc)
{
osg::NodeCallback* ucb = dynamic_cast<osg::NodeCallback*>(nc->clone(*this));
ucb->setNestedCallback(0);
first->addNestedCallback(ucb);
nc = nc->getNestedCallback();
}
return first;
}
else
return const_cast<NodeCallback*>(nc);
}

View File

@ -74,10 +74,10 @@ Node::Node(const Node& node,const CopyOp& copyop):
_boundingSphere(node._boundingSphere),
_boundingSphereComputed(node._boundingSphereComputed),
_parents(), // leave empty as parentList is managed by Group.
_updateCallback(node._updateCallback),
_updateCallback(copyop(node._updateCallback.get())),
_numChildrenRequiringUpdateTraversal(0), // assume no children yet.
_numChildrenRequiringEventTraversal(0), // assume no children yet.
_cullCallback(node._cullCallback),
_cullCallback(copyop(node._cullCallback.get())),
_cullingActive(node._cullingActive),
_numChildrenWithCullingDisabled(0), // assume no children yet.
_numChildrenWithOccluderNodes(0),