From 41cbf9a45eb9b72ee05a6eb0258d96f8dae8b65b Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 20 Jan 2017 22:43:58 +0100 Subject: [PATCH] FlattenStaticTransformsVisitor: fix handling of Drawables that are directly in the scene graph not attached to a Geode --- include/osgUtil/Optimizer | 2 +- src/osgUtil/Optimizer.cpp | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index d0a1937b5..665eafb91 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -275,7 +275,7 @@ class OSGUTIL_EXPORT Optimizer BaseOptimizerVisitor(optimizer, FLATTEN_STATIC_TRANSFORMS) {} virtual void apply(osg::Node& geode); - virtual void apply(osg::Geode& geode); + virtual void apply(osg::Drawable& drawable); virtual void apply(osg::Billboard& geode); virtual void apply(osg::ProxyNode& node); virtual void apply(osg::PagedLOD& node); diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 9c7d525ac..ddacb8800 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1173,26 +1173,19 @@ void Optimizer::FlattenStaticTransformsVisitor::apply(osg::PagedLOD& node) traverse(node); } - -void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Geode& geode) +void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Drawable& drawable) { - if (!_transformStack.empty()) + osg::Geometry *geometry = drawable.asGeometry(); + if((geometry) && (isOperationPermissibleForObject(&drawable))) { - for(unsigned int i=0;iasGeometry(); - if((geometry) && (isOperationPermissibleForObject(&geode)) && (isOperationPermissibleForObject(geometry))) - { - if(geometry->getVertexArray() && geometry->getVertexArray()->referenceCount() > 1) { - geometry->setVertexArray(dynamic_cast(geometry->getVertexArray()->clone(osg::CopyOp::DEEP_COPY_ALL))); - } - if(geometry->getNormalArray() && geometry->getNormalArray()->referenceCount() > 1) { - geometry->setNormalArray(dynamic_cast(geometry->getNormalArray()->clone(osg::CopyOp::DEEP_COPY_ALL))); - } - } - _drawableSet.insert(geode.getDrawable(i)); + if(geometry->getVertexArray() && geometry->getVertexArray()->referenceCount() > 1) { + geometry->setVertexArray(dynamic_cast(geometry->getVertexArray()->clone(osg::CopyOp::DEEP_COPY_ALL))); + } + if(geometry->getNormalArray() && geometry->getNormalArray()->referenceCount() > 1) { + geometry->setNormalArray(dynamic_cast(geometry->getNormalArray()->clone(osg::CopyOp::DEEP_COPY_ALL))); } } + _drawableSet.insert(&drawable); } void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Billboard& billboard)