From e0f7d3241af56751fa8e70922c1a17511aeb16cc Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 24 Feb 2017 01:05:57 +0100 Subject: [PATCH] Fix MergeGeometryVisitor to work with a Group instead of Geode --- include/osgUtil/Optimizer | 4 +-- src/osgUtil/Optimizer.cpp | 55 ++++++++++++--------------------------- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index 6a6f09305..a4c52ccd2 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -532,10 +532,10 @@ class OSGUTIL_EXPORT Optimizer return _targetMaximumNumberOfVertices; } - virtual void apply(osg::Geode& geode) { mergeGeode(geode); } + virtual void apply(osg::Group& group) { mergeGroup(group); traverse(group); } virtual void apply(osg::Billboard&) { /* don't do anything*/ } - bool mergeGeode(osg::Geode& geode); + bool mergeGroup(osg::Group& group); static bool geometryContainsSharedArrays(osg::Geometry& geom); diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index beb38209c..f4ea29fde 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1782,15 +1782,13 @@ bool isAbleToMerge(const osg::Geometry& g1, const osg::Geometry& g2) return true; } -bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) +bool Optimizer::MergeGeometryVisitor::mergeGroup(osg::Group& group) { - if (!isOperationPermissibleForObject(&geode)) return false; + if (!isOperationPermissibleForObject(&group)) return false; - if (geode.getNumDrawables()>=2) + if (group.getNumChildren()>=2) { - // OSG_NOTICE<<"Before "< DuplicateList; typedef std::vector< osg::ref_ptr > DrawableList; typedef std::map GeometryDuplicateMap; @@ -1801,9 +1799,9 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) DrawableList standardDrawables; unsigned int i; - for(i=0;iasDrawable(); if (drawable) { osg::Geometry* geom = drawable->asGeometry(); @@ -1945,26 +1943,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) if (needToDoMerge) { - // first take a reference to all the drawables to prevent them being deleted prematurely - DrawableList keepDrawables; - keepDrawables.resize(geode.getNumDrawables()); - for(i=0; iget()); - } - // now do the merging of geometries for(MergeList::iterator mitr = mergeList.begin(); mitr != mergeList.end(); @@ -1974,18 +1952,15 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) if (duplicateList.size()>1) { osg::Geometry* lhs = duplicateList.front(); - geode.addDrawable(lhs); for(DuplicateList::iterator ditr = duplicateList.begin()+1; ditr != duplicateList.end(); ++ditr) { mergeGeometry(*lhs,**ditr); + + group.removeChild(*ditr); } } - else if (duplicateList.size()>0) - { - geode.addDrawable(duplicateList.front()); - } } } @@ -2035,16 +2010,17 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) } #endif - // OSG_NOTICE<<"After "<asGeometry(); + osg::Drawable* drawable = group.getChild(i)->asDrawable(); + if (!drawable) + continue; + osg::Geometry* geom = drawable->asGeometry(); if (geom) { osg::Geometry::PrimitiveSetList& primitives = geom->getPrimitiveSetList(); @@ -2069,9 +2045,12 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) } // now merge any compatible primitives. - for(i=0;iasGeometry(); + osg::Drawable* drawable = group.getChild(i)->asDrawable(); + if (!drawable) + continue; + osg::Geometry* geom = drawable->asGeometry(); if (geom) { if (geom->getNumPrimitiveSets()>0 &&