1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-06 09:39:49 +00:00

lua - use loaded node when possible when calculating bounding box

This commit is contained in:
Cody Glassman 2024-07-03 13:28:49 -07:00
parent 7d884747fa
commit 45cb3eb081
2 changed files with 25 additions and 17 deletions

View File

@ -1658,18 +1658,25 @@ namespace MWRender
}
osg::BoundingBox RenderingManager::getCullSafeBoundingBox(const MWWorld::Ptr& ptr) const
{
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> rootNode = ptr.getRefData().getBaseNode();
// Recalculate bounds on the ptr's template when the object is not loaded or is loaded but paged
MWWorld::Scene* worldScene = MWBase::Environment::get().getWorldScene();
if (!rootNode || worldScene->isPagedRef(ptr))
{
const std::string model = ptr.getClass().getCorrectedModel(ptr);
if (model.empty())
return {};
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> rootNode = new SceneUtil::PositionAttitudeTransform;
rootNode = new SceneUtil::PositionAttitudeTransform;
// 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()));
const float refScale = ptr.getCellRef().getScale();
rootNode->setScale({ refScale, refScale, refScale });
rootNode->setPosition(osg::Vec3(0, 0, 0));
rootNode->setPosition(ptr.getCellRef().getPosition().asVec3());
osg::ref_ptr<Animation> animation = nullptr;
@ -1678,6 +1685,7 @@ namespace MWRender
rootNode->setNodeMask(Mask_Actor);
animation = new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(rootNode), mResourceSystem);
}
}
SceneUtil::CullSafeBoundsVisitor computeBounds;
computeBounds.setTraversalMask(~(MWRender::Mask_ParticleSystem | MWRender::Mask_Effect));

View File

@ -277,7 +277,7 @@
-- money:split(50):moveInto(types.Container.content(cont))
---
-- The axis aligned bounding box in local coordinates.
-- The axis aligned bounding box in world coordinates.
-- @function [parent=#GameObject] getBoundingBox
-- @param self
-- @return openmw.util#Box