From Kristofer Tingdahl,"we have a bunch of classes that inherit osg::Node, and they create their own, internal geometry which is passed into the render bucket at the cull-traversal. Last week, we realised that these classes are not accounted for when doing an ComputeBoundVisitor- traversal, as there is no specialization in ComputeBoundVisitor for them.

One solution is naturally to create a new class that would inherit the osg::ComputeBoundVisitor, and use that. I don't like that idea as the ComputeBoundVisitor does actually have what I need - it is only hidden in a protected function.

I am therefor suggesting a slight generalization of the ComputeBoundVisitor with the attached patch, which is tested.

The patch has two parts:
we add applyBBox() so that one can use that in a customized traverse-function and add a bbox to the visitor. I considered calling this function expandByBBox(), but I though  applyBBox was better.
The MatrixStack is made available to the outside world. That enables a traverse-function to do whatever it wishes.
I do actually only need one of the two, as I can implement what I wish either way, but adding getMatrixStack() will make more generic expansions possible.
"

From Robert Osfield, changed the name of the new applyBBox(..) method to applyBoundingBox(..) to keep it's naming more consistent with the rest of the OSG.
This commit is contained in:
Robert Osfield
2014-01-23 16:48:29 +00:00
parent a96ad565c7
commit d8482ef1ba
2 changed files with 20 additions and 16 deletions

View File

@@ -48,10 +48,13 @@ public:
void applyDrawable(osg::Drawable* drawable);
protected:
void applyBoundingBox(const osg::BoundingBox&);
typedef std::vector<osg::Matrix> MatrixStack;
const MatrixStack& getMatrixStack() const { return _matrixStack; }
protected:
MatrixStack _matrixStack;
osg::BoundingBox _bb;
};

View File

@@ -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);
}
}