diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 469d71fc4f..eefdd64528 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -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 rootNode = new SceneUtil::PositionAttitudeTransform; - // Hack even used by osg internally, osg's NodeVisitor won't accept const qualified nodes - rootNode->addChild(const_cast(mResourceSystem->getSceneManager()->getTemplate(model).get())); + osg::ref_ptr 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 = 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(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(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 = nullptr; + + if (ptr.getClass().isNpc()) + { + rootNode->setNodeMask(Mask_Actor); + animation = new NpcAnimation(ptr, osg::ref_ptr(rootNode), mResourceSystem); + } } SceneUtil::CullSafeBoundsVisitor computeBounds; diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 3813ebd4f1..9fce8e70a8 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -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