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

Merge branch 'bounding_box' into 'master'

lua - use loaded node when possible when calculating bounding box (#7580)

Closes #7580

See merge request OpenMW/openmw!4073
This commit is contained in:
psi29a 2024-07-21 09:31:22 +00:00
commit 376e8a6e1f
2 changed files with 26 additions and 15 deletions

View File

@ -1659,24 +1659,35 @@ namespace MWRender
osg::BoundingBox RenderingManager::getCullSafeBoundingBox(const MWWorld::Ptr& ptr) const
{
const std::string model = ptr.getClass().getCorrectedModel(ptr);
if (model.empty())
if (ptr.isEmpty())
return {};
osg::ref_ptr<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()));
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> rootNode = ptr.getRefData().getBaseNode();
const float refScale = ptr.getCellRef().getScale();
rootNode->setScale({ refScale, refScale, refScale });
rootNode->setPosition(osg::Vec3(0, 0, 0));
osg::ref_ptr<Animation> animation = nullptr;
if (ptr.getClass().isNpc())
// 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))
{
rootNode->setNodeMask(Mask_Actor);
animation = new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(rootNode), mResourceSystem);
const std::string model = ptr.getClass().getCorrectedModel(ptr);
if (model.empty())
return {};
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(ptr.getCellRef().getPosition().asVec3());
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;

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