diff --git a/components/sceneutil/morphgeometry.cpp b/components/sceneutil/morphgeometry.cpp index 39102b575a..3efccfd6e6 100644 --- a/components/sceneutil/morphgeometry.cpp +++ b/components/sceneutil/morphgeometry.cpp @@ -1,5 +1,7 @@ #include "morphgeometry.hpp" +#include + #include #include @@ -87,7 +89,18 @@ void MorphGeometry::accept(osg::NodeVisitor &nv) nv.pushOntoNodePath(this); if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) + { + // The cull visitor won't be applied to the node itself, + // but we want to use its state to render the child geometry. + osg::StateSet* stateset = getStateSet(); + osgUtil::CullVisitor* cv = static_cast(&nv); + if (stateset) + cv->pushStateSet(stateset); + cull(&nv); + if (stateset) + cv->popStateSet(); + } else nv.apply(*this); diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index 5fca265877..38a35f2a12 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -1,8 +1,11 @@ #include "riggeometry.hpp" +#include + +#include + #include #include -#include #include "skeleton.hpp" #include "util.hpp" @@ -387,7 +390,18 @@ void RigGeometry::accept(osg::NodeVisitor &nv) nv.pushOntoNodePath(this); if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) + { + // The cull visitor won't be applied to the node itself, + // but we want to use its state to render the child geometry. + osg::StateSet* stateset = getStateSet(); + osgUtil::CullVisitor* cv = static_cast(&nv); + if (stateset) + cv->pushStateSet(stateset); + cull(&nv); + if (stateset) + cv->popStateSet(); + } else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) updateBounds(&nv); else diff --git a/components/sceneutil/riggeometryosgaextension.cpp b/components/sceneutil/riggeometryosgaextension.cpp index 8768eb403f..3389a6ba5d 100644 --- a/components/sceneutil/riggeometryosgaextension.cpp +++ b/components/sceneutil/riggeometryosgaextension.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include @@ -220,6 +222,13 @@ void RigGeometryHolder::accept(osg::NodeVisitor &nv) if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR && mSourceRigGeometry.get()) { + // The cull visitor won't be applied to the node itself, + // but we want to use its state to render the child geometry. + osg::StateSet* stateset = getStateSet(); + osgUtil::CullVisitor* cv = static_cast(&nv); + if (stateset) + cv->pushStateSet(stateset); + unsigned int traversalNumber = nv.getTraversalNumber(); if (mLastFrameNumber == traversalNumber) { @@ -255,6 +264,8 @@ void RigGeometryHolder::accept(osg::NodeVisitor &nv) nv.apply(geom); nv.popFromNodePath(); } + if (stateset) + cv->popStateSet(); } else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) {