mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 21:45:36 +00:00
lua - fix bounding box once and for all
This commit is contained in:
parent
8a33edd64a
commit
a659d2eaeb
2 changed files with 12 additions and 24 deletions
|
@ -1536,36 +1536,22 @@ namespace MWRender
|
||||||
// Hack even used by osg internally, osg's NodeVisitor won't accept const qualified nodes
|
// Hack even used by osg internally, osg's NodeVisitor won't accept const qualified nodes
|
||||||
rootNode->addChild(const_cast<osg::Node*>(mResourceSystem->getSceneManager()->getTemplate(model).get()));
|
rootNode->addChild(const_cast<osg::Node*>(mResourceSystem->getSceneManager()->getTemplate(model).get()));
|
||||||
|
|
||||||
const SceneUtil::PositionAttitudeTransform* baseNode = ptr.getRefData().getBaseNode();
|
|
||||||
if (baseNode)
|
|
||||||
{
|
|
||||||
rootNode->setPosition(baseNode->getPosition());
|
|
||||||
rootNode->setAttitude(baseNode->getAttitude());
|
|
||||||
rootNode->setScale(baseNode->getScale());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rootNode->setPosition(ptr.getRefData().getPosition().asVec3());
|
|
||||||
osg::Vec3f rot = ptr.getRefData().getPosition().asRotationVec3();
|
|
||||||
rootNode->setAttitude(osg::Quat(rot[2], osg::Vec3f(0, 0, -1)) * osg::Quat(rot[1], osg::Vec3f(0, -1, 0))
|
|
||||||
* osg::Quat(rot[0], osg::Vec3f(-1, 0, 0)));
|
|
||||||
const float refScale = ptr.getCellRef().getScale();
|
const float refScale = ptr.getCellRef().getScale();
|
||||||
rootNode->setScale({ refScale, refScale, refScale });
|
rootNode->setScale({ refScale, refScale, refScale });
|
||||||
|
rootNode->setPosition(osg::Vec3(0, 0, 0));
|
||||||
|
|
||||||
|
osg::ref_ptr<Animation> animation = nullptr;
|
||||||
|
|
||||||
|
if (ptr.getClass().isNpc())
|
||||||
|
{
|
||||||
|
rootNode->setNodeMask(Mask_Actor);
|
||||||
|
animation = new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(rootNode), mResourceSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneUtil::CullSafeBoundsVisitor computeBounds;
|
SceneUtil::CullSafeBoundsVisitor computeBounds;
|
||||||
computeBounds.setTraversalMask(~(MWRender::Mask_ParticleSystem | MWRender::Mask_Effect));
|
computeBounds.setTraversalMask(~(MWRender::Mask_ParticleSystem | MWRender::Mask_Effect));
|
||||||
rootNode->accept(computeBounds);
|
rootNode->accept(computeBounds);
|
||||||
|
|
||||||
const osg::Vec3f& scale = rootNode->getScale();
|
|
||||||
|
|
||||||
computeBounds.mBoundingBox.xMin() *= scale.x();
|
|
||||||
computeBounds.mBoundingBox.xMax() *= scale.x();
|
|
||||||
computeBounds.mBoundingBox.yMin() *= scale.y();
|
|
||||||
computeBounds.mBoundingBox.yMax() *= scale.y();
|
|
||||||
computeBounds.mBoundingBox.zMin() *= scale.z();
|
|
||||||
computeBounds.mBoundingBox.zMax() *= scale.z();
|
|
||||||
|
|
||||||
return computeBounds.mBoundingBox;
|
return computeBounds.mBoundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
// Computes local bounding box of a node without dirtying itself or any of its children
|
// Computes bounding box of a node without dirtying it or any of its children
|
||||||
struct CullSafeBoundsVisitor : osg::NodeVisitor
|
struct CullSafeBoundsVisitor : osg::NodeVisitor
|
||||||
{
|
{
|
||||||
CullSafeBoundsVisitor(osg::NodeVisitor::TraversalMode traversalMode = TRAVERSE_ALL_CHILDREN)
|
CullSafeBoundsVisitor(osg::NodeVisitor::TraversalMode traversalMode = TRAVERSE_ALL_CHILDREN)
|
||||||
|
@ -39,6 +39,8 @@ namespace SceneUtil
|
||||||
if (!mMatrixStack.empty())
|
if (!mMatrixStack.empty())
|
||||||
matrix = mMatrixStack.back();
|
matrix = mMatrixStack.back();
|
||||||
|
|
||||||
|
transform.computeLocalToWorldMatrix(matrix, this);
|
||||||
|
|
||||||
mMatrixStack.push_back(matrix);
|
mMatrixStack.push_back(matrix);
|
||||||
traverse(transform);
|
traverse(transform);
|
||||||
mMatrixStack.pop_back();
|
mMatrixStack.pop_back();
|
||||||
|
|
Loading…
Reference in a new issue