diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index b045d378f..9d7ebddba 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -978,34 +978,42 @@ osg::Group* ConvertFromFLT::visitSwitch(osg::Group& osgParent, SwitchRecord* rec osgSwitch->setName(pSSwitch->szIdent); visitAncillary(osgParent, *osgSwitch, rec)->addChild( osgSwitch ); - visitPrimaryNode(*osgSwitch, (PrimNodeRecord*)rec); - + osg::ref_ptr allChildrenGroup = new osg::Group; + visitPrimaryNode(*allChildrenGroup, (PrimNodeRecord*)rec); unsigned int totalNumChildren = (unsigned int)rec->getNumChildren(); - if (totalNumChildren!=osgSwitch->getNumChildren()) + if (totalNumChildren!=allChildrenGroup->getNumChildren()) { // only convert the children we agree on, // however, there could be a chance that ordering of children might // be different if there a children that hanvn't mapped across... - if (totalNumChildren>osgSwitch->getNumChildren()) totalNumChildren=osgSwitch->getNumChildren(); - - + if (totalNumChildren>allChildrenGroup->getNumChildren()) totalNumChildren=allChildrenGroup->getNumChildren(); osg::notify(osg::INFO)<<"Warning::OpenFlight loader has come across an incorrectly handled switch."<getNumChildren()<<") "<getNumChildren()<<")"<getNumChildren()<<")"<nMasks; ++itMask) { - unsigned int nMaskBit = nChild % 32; - unsigned int nMaskWord = pSSwitch->nCurrentMask * pSSwitch->nWordsInMask + nChild / 32; - - if (nChildgetNumChildren()) + // create a osg group node + osg::ref_ptr group = new osg::Group; + osgSwitch->addChild( group.get() ); + // for each child in the FLT Switch node + for (unsigned itChild=0; itChildsetValue(nChild,(pSSwitch->aMask[nMaskWord] & (uint32(1) << nMaskBit))!=0); + // test if this child is active in the current mask (itMask) + unsigned int nMaskBit = itChild % 32; + unsigned int nMaskWord = itMask * pSSwitch->nWordsInMask + itChild / 32; + if ( (pSSwitch->aMask[nMaskWord] & (uint32(1) << nMaskBit))!=0 ) + { + // add this child in the group + group->addChild( allChildrenGroup->getChild(itChild) ); + } } + // now the group contain all the childrens that are active in the current mask (itMask) } - + osgSwitch->setSingleChildOn(pSSwitch->nCurrentMask); return osgSwitch; }