diff --git a/include/osg/CopyOp b/include/osg/CopyOp index e24dce44c..d96445404 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -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: diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index c3d876414..b71dcd9f4 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -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(nc->clone(*this)); + first->setNestedCallback(0); + nc = nc->getNestedCallback(); + while (nc) + { + osg::NodeCallback* ucb = dynamic_cast(nc->clone(*this)); + ucb->setNestedCallback(0); + first->addNestedCallback(ucb); + nc = nc->getNestedCallback(); + } + return first; + } + else + return const_cast(nc); +} diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index 45b5555dc..a4d3f8dac 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -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),