]> git.mxchange.org Git - simgear.git/commitdiff
Restructure to avoid ordering issues.
authorJames Turner <zakalawe@mac.com>
Sat, 13 Apr 2013 13:40:55 +0000 (14:40 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 13 Apr 2013 13:40:55 +0000 (14:40 +0100)
Create a pick group for each object, instead of a single one. This
can be optimised in the future but this structure is backwards-
compatible with existing usage, which is more important.

simgear/scene/model/SGPickAnimation.cxx

index da3921f40057db08d2098d40a23d7fa0e5b193e4..ddc41030d55ddaf53d3591e65adeb33b057e4d23 100644 (file)
@@ -361,13 +361,11 @@ osg::StateSet* sharedHighlightStateSet()
 void
 SGPickAnimation::apply(osg::Group& group)
 {
-  if (_objectNames.empty()) {
+  if (_objectNames.empty() && _proxyNames.empty()) {
     return;
   }
   
-  osg::ref_ptr<osg::Group> renderGroup, proxyGroup, pickGroup;
   group.traverse(*this);
-  SGSceneUserData* ud = NULL;
   
   // iterate over all group children
   int i = group.getNumChildren() - 1;
@@ -382,37 +380,26 @@ SGPickAnimation::apply(osg::Group& group)
       _objectNames.erase(it);
       install(*child);
       
-//////
-      if (!pickGroup) {
-        osg::Group* mainGroup = createMainGroup(&group);
-        mainGroup->setName(child->getName());
-        
-        if (getConfig()->getBoolValue("visible", true)) {
-            renderGroup = new osg::Group;
-            renderGroup->setName("pick render group");
-            mainGroup->addChild(renderGroup);
-        }
-        
-        pickGroup = new osg::Group;
-        pickGroup->setName("pick highlight group");
-        pickGroup->setNodeMask(simgear::PICK_BIT);
-        pickGroup->setStateSet(sharedHighlightStateSet());
-        mainGroup->addChild(pickGroup);
-          
-        if (!ud) {
-          ud = SGSceneUserData::getOrCreateSceneUserData(pickGroup);
-          setupCallbacks(ud, &group);
-        } else {
-          pickGroup->setUserData(ud);
-        }
-      } // of pick group setup
+      osg::ref_ptr<osg::Group> renderGroup, pickGroup;      
+      osg::Group* mainGroup = createMainGroup(&group);
+      mainGroup->setName(child->getName());
+      child->setName(""); // don't apply other animations twice
       
-////////
-      child->setName("");
-      if (renderGroup.valid()) {
-        renderGroup->addChild(child);
+      if (getConfig()->getBoolValue("visible", true)) {
+          renderGroup = new osg::Group;
+          renderGroup->setName("pick render group");
+          renderGroup->addChild(child);
+          mainGroup->addChild(renderGroup);
       }
       
+      pickGroup = new osg::Group;
+      pickGroup->setName("pick highlight group");
+      pickGroup->setNodeMask(simgear::PICK_BIT);
+      pickGroup->setStateSet(sharedHighlightStateSet());
+      mainGroup->addChild(pickGroup);
+      
+      setupCallbacks(SGSceneUserData::getOrCreateSceneUserData(pickGroup), mainGroup);
+
       pickGroup->addChild(child);
       group.removeChild(child);
       continue;
@@ -424,20 +411,12 @@ SGPickAnimation::apply(osg::Group& group)
     }
     
     _proxyNames.erase(j);
-    if (!proxyGroup) {
-      proxyGroup = new osg::Group;
-      group.addChild(proxyGroup);
-      proxyGroup->setStateSet(sharedHighlightStateSet());
-      proxyGroup->setNodeMask(simgear::PICK_BIT);
+    osg::ref_ptr<osg::Group> proxyGroup = new osg::Group;
+    group.addChild(proxyGroup);
+    proxyGroup->setStateSet(sharedHighlightStateSet());
+    proxyGroup->setNodeMask(simgear::PICK_BIT);
       
-      if (!ud) {
-        ud = SGSceneUserData::getOrCreateSceneUserData(proxyGroup);
-        setupCallbacks(ud, &group);
-      } else {
-        proxyGroup->setUserData(ud);
-      }
-    } // of proxy group setup
-
+    setupCallbacks(SGSceneUserData::getOrCreateSceneUserData(proxyGroup), proxyGroup);
     proxyGroup->addChild(child);
     group.removeChild(child);
   } // of group children iteration