Hi Fellow OSG Users,

I'm trying to dynamically insert a Swtich into my scene graph and I'm a little
confused by what is happening.

The graph is like this:

Group1
   Group2
      Child1
      ...
      ChildN

I am trying to make it like this (Group2 and its children moved to under the 
newly inserted switch):

Group1
    Switch
       Group2
          Child1
          ...
          ChildN


But what I end up with is this (Group2 has moved as expected, but its children 
are now under Group1):


Group1
   Switch
      Group2

   Child1
   ...
   ChildN

Could someone please tell me if I am doing something stupid, or missing 
something fundamental.

Here is the code in question.  The parameter node Group2.  

void makeLayer(Node* node)
{
        if (strcmp(node->className(), "Switch") == 0) {
                return;
        }
        ref_ptr<Switch> switchnode = new Switch;
        string name = node->getName();
        switchnode->setName(name);
        switchnode->addChild(node);
        Group* parent = node->getParent(0);
        parent->addChild(switchnode.get());
        ref_ptr<Group> group = new Group;
        switchnode->addChild(group.get());
        parent->removeChild(node);
        node->setName(name + "_old");
}


Many thanks in advance,

Jim.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to