From 20e799dadc2172fa1fcb230a0c5d731666a176cc Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Fri, 3 Mar 2023 21:28:00 +0300 Subject: [PATCH] Use Rig/MorphGeometry state for its child geometry Cherry-pick of ed44095cdc0d33cadb7e27ffa0695932b535aa55 from 0.48 branch --- components/sceneutil/morphgeometry.cpp | 13 +++++++++++++ components/sceneutil/riggeometry.cpp | 16 +++++++++++++++- .../sceneutil/riggeometryosgaextension.cpp | 12 ++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/components/sceneutil/morphgeometry.cpp b/components/sceneutil/morphgeometry.cpp index e521c92dc9..a0202175e2 100644 --- a/components/sceneutil/morphgeometry.cpp +++ b/components/sceneutil/morphgeometry.cpp @@ -1,5 +1,7 @@ #include "morphgeometry.hpp" +#include + #include #include @@ -89,7 +91,18 @@ namespace SceneUtil 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 a3f0925b71..b940fb60ec 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" @@ -393,7 +396,18 @@ namespace SceneUtil 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 f8bc06e3e4..4c6cd10c08 100644 --- a/components/sceneutil/riggeometryosgaextension.cpp +++ b/components/sceneutil/riggeometryosgaextension.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include @@ -236,6 +238,13 @@ namespace SceneUtil 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) { @@ -273,6 +282,9 @@ namespace SceneUtil nv.apply(geom); nv.popFromNodePath(); } + + if (stateset) + cv->popStateSet(); } else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) {