mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 08:39:45 +00:00
Slightly improve bounding box for skinned meshes
This commit is contained in:
parent
c53a56ed6e
commit
111e3eb6db
2 changed files with 15 additions and 27 deletions
|
@ -1196,28 +1196,24 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
rig->setInfluenceMap(map);
|
rig->setInfluenceMap(map);
|
||||||
|
|
||||||
rig->setComputeBoundingBoxCallback(new StaticBoundingBoxCallback(geometry->getBound()));
|
// Compute the bounding box
|
||||||
|
osg::BoundingBox boundingBox;
|
||||||
|
|
||||||
|
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);
|
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 );
|
|
||||||
|
|
||||||
|
|
||||||
// Add a copy, we will alternate between the two copies every other frame using the FrameSwitch
|
// 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
|
// This is so we can set the DataVariance as STATIC, giving a huge performance boost
|
||||||
/*
|
|
||||||
rig->setDataVariance(osg::Object::STATIC);
|
rig->setDataVariance(osg::Object::STATIC);
|
||||||
osg::Geode* geode2 = static_cast<osg::Geode*>(osg::clone(geode.get(), osg::CopyOp::DEEP_COPY_NODES|
|
osg::Geode* geode2 = static_cast<osg::Geode*>(osg::clone(geode.get(), osg::CopyOp::DEEP_COPY_NODES|
|
||||||
osg::CopyOp::DEEP_COPY_DRAWABLES));
|
osg::CopyOp::DEEP_COPY_DRAWABLES));
|
||||||
|
@ -1226,11 +1222,7 @@ namespace NifOsg
|
||||||
frameswitch->addChild(geode);
|
frameswitch->addChild(geode);
|
||||||
frameswitch->addChild(geode2);
|
frameswitch->addChild(geode2);
|
||||||
|
|
||||||
trans->addChild(frameswitch);
|
parentNode->addChild(frameswitch);
|
||||||
*/
|
|
||||||
|
|
||||||
parentNode->addChild(geode);
|
|
||||||
parentNode->addChild(boundingBoxNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,8 @@ RigGeometry::RigGeometry()
|
||||||
RigGeometry::RigGeometry(const RigGeometry ©, const osg::CopyOp ©op)
|
RigGeometry::RigGeometry(const RigGeometry ©, const osg::CopyOp ©op)
|
||||||
: osg::Geometry(copy, copyop)
|
: osg::Geometry(copy, copyop)
|
||||||
, mInfluenceMap(copy.mInfluenceMap)
|
, mInfluenceMap(copy.mInfluenceMap)
|
||||||
, mSourceGeometry(copy.mSourceGeometry)
|
|
||||||
{
|
{
|
||||||
//setVertexArray(dynamic_cast<osg::Array*>(from.getVertexArray()->clone(osg::CopyOp::DEEP_COPY_ALL)));
|
setSourceGeometry(copy.mSourceGeometry);
|
||||||
//setNormalArray(dynamic_cast<osg::Array*>(from.getNormalArray()->clone(osg::CopyOp::DEEP_COPY_ALL)), osg::Array::BIND_PER_VERTEX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigGeometry::setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeometry)
|
void RigGeometry::setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeometry)
|
||||||
|
@ -110,8 +108,6 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// geometryToSkel = nv->getNodePath()...
|
|
||||||
|
|
||||||
if (!mInfluenceMap)
|
if (!mInfluenceMap)
|
||||||
{
|
{
|
||||||
std::cerr << "No InfluenceMap set on RigGeometry" << std::endl;
|
std::cerr << "No InfluenceMap set on RigGeometry" << std::endl;
|
||||||
|
|
Loading…
Reference in a new issue