Slightly improve bounding box for skinned meshes

c++11
scrawl 10 years ago
parent c53a56ed6e
commit 111e3eb6db

@ -1196,28 +1196,24 @@ namespace NifOsg
}
rig->setInfluenceMap(map);
rig->setComputeBoundingBoxCallback(new StaticBoundingBoxCallback(geometry->getBound()));
// Compute the bounding box
osg::BoundingBox boundingBox;
geode->addDrawable(rig);
// World bounding box callback & node
osg::ref_ptr<BoundingBoxCallback> bbcb = new BoundingBoxCallback;
bbcb->mDrawable = rig;
osg::ref_ptr<osg::Geode> geode2 = new osg::Geode;
geode2->addDrawable( new osg::ShapeDrawable(new osg::Box) );
osg::ref_ptr<osg::MatrixTransform> boundingBoxNode = new osg::MatrixTransform;
boundingBoxNode->addChild( geode2.get() );
boundingBoxNode->addUpdateCallback( bbcb.get() );
boundingBoxNode->getOrCreateStateSet()->setAttributeAndModes(
new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE) );
boundingBoxNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
osg::Matrix worldTrans = getWorldTransform(triShape);
for(size_t i = 0;i < bones.length();i++)
{
osg::BoundingSphere boneSphere (data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius);
osg::Matrix boneWorldTrans(getWorldTransform(bones[i].getPtr()));
osg::Matrix mat = boneWorldTrans * worldTrans.inverse(worldTrans);
SceneUtil::transformBoundingSphere(mat, boneSphere);
boundingBox.expandBy(boneSphere);
}
rig->setComputeBoundingBoxCallback(new StaticBoundingBoxCallback(boundingBox));
geode->addDrawable(rig);
// Add a copy, we will alternate between the two copies every other frame using the FrameSwitch
// This is so we can set the DataVariance as STATIC, giving a huge performance boost
/*
rig->setDataVariance(osg::Object::STATIC);
osg::Geode* geode2 = static_cast<osg::Geode*>(osg::clone(geode.get(), osg::CopyOp::DEEP_COPY_NODES|
osg::CopyOp::DEEP_COPY_DRAWABLES));
@ -1226,11 +1222,7 @@ namespace NifOsg
frameswitch->addChild(geode);
frameswitch->addChild(geode2);
trans->addChild(frameswitch);
*/
parentNode->addChild(geode);
parentNode->addChild(boundingBoxNode);
parentNode->addChild(frameswitch);
}

@ -46,10 +46,8 @@ RigGeometry::RigGeometry()
RigGeometry::RigGeometry(const RigGeometry &copy, const osg::CopyOp &copyop)
: osg::Geometry(copy, copyop)
, mInfluenceMap(copy.mInfluenceMap)
, mSourceGeometry(copy.mSourceGeometry)
{
//setVertexArray(dynamic_cast<osg::Array*>(from.getVertexArray()->clone(osg::CopyOp::DEEP_COPY_ALL)));
//setNormalArray(dynamic_cast<osg::Array*>(from.getNormalArray()->clone(osg::CopyOp::DEEP_COPY_ALL)), osg::Array::BIND_PER_VERTEX);
setSourceGeometry(copy.mSourceGeometry);
}
void RigGeometry::setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeometry)
@ -110,8 +108,6 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
return false;
}
// geometryToSkel = nv->getNodePath()...
if (!mInfluenceMap)
{
std::cerr << "No InfluenceMap set on RigGeometry" << std::endl;

Loading…
Cancel
Save