mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
Ensure RigGeometry child geometries have sensible bounds without actually computing them.
This commit is contained in:
parent
586ac2d12d
commit
6286f5a1d4
@ -41,6 +41,8 @@ void RigGeometry::setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeometry)
|
||||
to.setSupportsDisplayList(false);
|
||||
to.setUseVertexBufferObjects(true);
|
||||
to.setCullingActive(false); // make sure to disable culling since that's handled by this class
|
||||
to.setComputeBoundingBoxCallback(new CopyBoundingBoxCallback());
|
||||
to.setComputeBoundingSphereCallback(new CopyBoundingSphereCallback());
|
||||
|
||||
// vertices and normals are modified every frame, so we need to deep copy them.
|
||||
// assign a dedicated VBO to make sure that modifications don't interfere with source geometry's VBO.
|
||||
@ -273,6 +275,14 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv)
|
||||
_boundingSphereComputed = true;
|
||||
for (unsigned int i=0; i<getNumParents(); ++i)
|
||||
getParent(i)->dirtyBound();
|
||||
|
||||
for (unsigned int i = 0; i < 2; ++i)
|
||||
{
|
||||
osg::Geometry& geom = *mGeometry[i];
|
||||
static_cast<CopyBoundingBoxCallback*>(geom.getComputeBoundingBoxCallback())->boundingBox = _boundingBox;
|
||||
static_cast<CopyBoundingSphereCallback*>(geom.getComputeBoundingSphereCallback())->boundingSphere = _boundingSphere;
|
||||
geom.dirtyBound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,20 @@ namespace SceneUtil
|
||||
virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
|
||||
virtual void accept(osg::PrimitiveFunctor&) const;
|
||||
|
||||
struct CopyBoundingBoxCallback : osg::Drawable::ComputeBoundingBoxCallback
|
||||
{
|
||||
osg::BoundingBox boundingBox;
|
||||
|
||||
virtual osg::BoundingBox computeBound(const osg::Drawable&) const override { return boundingBox; }
|
||||
};
|
||||
|
||||
struct CopyBoundingSphereCallback : osg::Node::ComputeBoundingSphereCallback
|
||||
{
|
||||
osg::BoundingSphere boundingSphere;
|
||||
|
||||
virtual osg::BoundingSphere computeBound(const osg::Node&) const override { return boundingSphere; }
|
||||
};
|
||||
|
||||
private:
|
||||
void cull(osg::NodeVisitor* nv);
|
||||
void updateBounds(osg::NodeVisitor* nv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user