diff --git a/include/osg/ComputeBoundsVisitor b/include/osg/ComputeBoundsVisitor index 1efd859c2..c5b2cd6a8 100644 --- a/include/osg/ComputeBoundsVisitor +++ b/include/osg/ComputeBoundsVisitor @@ -48,10 +48,13 @@ public: void applyDrawable(osg::Drawable* drawable); -protected: + void applyBoundingBox(const osg::BoundingBox&); typedef std::vector MatrixStack; + const MatrixStack& getMatrixStack() const { return _matrixStack; } + +protected: MatrixStack _matrixStack; osg::BoundingBox _bb; }; diff --git a/src/osg/ComputeBoundsVisitor.cpp b/src/osg/ComputeBoundsVisitor.cpp index d9c1624cb..871a09ffb 100644 --- a/src/osg/ComputeBoundsVisitor.cpp +++ b/src/osg/ComputeBoundsVisitor.cpp @@ -77,21 +77,22 @@ void ComputeBoundsVisitor::apply(osg::Geode& geode) void ComputeBoundsVisitor::applyDrawable(osg::Drawable* drawable) { - if (_matrixStack.empty()) _bb.expandBy(drawable->getBound()); - else + applyBoundingBox(drawable->getBound()); +} + +void ComputeBoundsVisitor::applyBoundingBox(const osg::BoundingBox& bbox) +{ + if (_matrixStack.empty()) _bb.expandBy(bbox); + else if (bbox.valid()) { - osg::Matrix& matrix = _matrixStack.back(); - const osg::BoundingBox& dbb = drawable->getBound(); - if (dbb.valid()) - { - _bb.expandBy(dbb.corner(0) * matrix); - _bb.expandBy(dbb.corner(1) * matrix); - _bb.expandBy(dbb.corner(2) * matrix); - _bb.expandBy(dbb.corner(3) * matrix); - _bb.expandBy(dbb.corner(4) * matrix); - _bb.expandBy(dbb.corner(5) * matrix); - _bb.expandBy(dbb.corner(6) * matrix); - _bb.expandBy(dbb.corner(7) * matrix); - } + const osg::Matrix& matrix = _matrixStack.back(); + _bb.expandBy(bbox.corner(0) * matrix); + _bb.expandBy(bbox.corner(1) * matrix); + _bb.expandBy(bbox.corner(2) * matrix); + _bb.expandBy(bbox.corner(3) * matrix); + _bb.expandBy(bbox.corner(4) * matrix); + _bb.expandBy(bbox.corner(5) * matrix); + _bb.expandBy(bbox.corner(6) * matrix); + _bb.expandBy(bbox.corner(7) * matrix); } }