diff --git a/components/sceneutil/attach.cpp b/components/sceneutil/attach.cpp index e61b8a6e0..1385f771e 100644 --- a/components/sceneutil/attach.cpp +++ b/components/sceneutil/attach.cpp @@ -81,14 +81,23 @@ namespace SceneUtil std::string mFilter2; }; + void mergeUserData(osg::UserDataContainer* source, osg::Object* target) + { + if (!target->getUserDataContainer()) + target->setUserDataContainer(source); + else + { + for (unsigned int i=0; igetNumUserObjects(); ++i) + target->getUserDataContainer()->addUserObject(source->getUserObject(i)); + } + } + osg::ref_ptr attach(osg::ref_ptr toAttach, osg::Node *master, const std::string &filter, osg::Group* attachNode) { if (dynamic_cast(toAttach.get())) { osg::ref_ptr handle = new osg::Group; - osg::UserDataContainer* udc = toAttach->getUserDataContainer(); - CopyRigVisitor copyVisitor(handle, filter); toAttach->accept(copyVisitor); copyVisitor.doCopy(); @@ -98,13 +107,13 @@ namespace SceneUtil osg::ref_ptr newHandle = handle->getChild(0); handle->removeChild(newHandle); master->asGroup()->addChild(newHandle); - newHandle->setUserDataContainer(udc); + mergeUserData(toAttach->getUserDataContainer(), newHandle); return newHandle; } else { master->asGroup()->addChild(handle); - handle->setUserDataContainer(udc); + handle->setUserDataContainer(toAttach->getUserDataContainer()); return handle; } }