diff --git a/include/osg/Group b/include/osg/Group index 9851f6390..92a72c6da 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -50,6 +50,13 @@ class SG_EXPORT Group : public Node */ virtual bool addChild( Node *child ); + /** Insert Node to Group at specific location. + * The new child node is inserted into the child list + * before the node at the specified index. No nodes + * are removed from the group with this operation. + */ + virtual bool insertChild( unsigned int index, Node *child ); + /** Remove Node from Group. * If Node is contained in Group then remove it from the child * list, decrement its reference count, and dirty the diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 5305ca106..229fc9e09 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -65,6 +65,11 @@ void Group::traverse(NodeVisitor& nv) bool Group::addChild( Node *child ) +{ + return Group::insertChild( _children.size(), child ); +} + +bool Group::insertChild( unsigned int index, Node *child ) { if (!child) return false; @@ -79,7 +84,14 @@ bool Group::addChild( Node *child ) if (child) { // note ref_ptr<> automatically handles incrementing child's reference count. - _children.push_back(child); + if (index >= _children.size()) + { + _children.push_back(child); + } + else + { + _children.insert(_children.begin()+index, child); + } // register as parent of child. child->addParent(this);