Skip to content

Commit

Permalink
Merge branch 'bounding_box' into 'master'
Browse files Browse the repository at this point in the history
lua - use loaded node when possible when calculating bounding box (#7580)

Closes #7580

See merge request OpenMW/openmw!4073
  • Loading branch information
psi29a committed Jul 21, 2024
2 parents 7026bfd + 8105c62 commit 376e8a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
// 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);

osg::ref_ptr<Animation> animation = nullptr;
if (model.empty())
return {};

if (ptr.getClass().isNpc())
{
rootNode->setNodeMask(Mask_Actor);
animation = new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(rootNode), mResourceSystem);
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;
Expand Down
2 changes: 1 addition & 1 deletion files/lua_api/openmw/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 376e8a6

Please sign in to comment.