From 8516aee6e0a69d59569218dff74808b83b5e3418 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 16 Jun 2018 10:18:04 +0400 Subject: [PATCH] Implement getHalfExtents() for non-actor objects --- apps/openmw/mwrender/renderingmanager.cpp | 24 +++++++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 2 ++ apps/openmw/mwworld/worldimp.cpp | 10 +++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index e17fe3191..ce0a41c9a 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -49,6 +49,7 @@ #include #include "../mwworld/cellstore.hpp" +#include "../mwworld/class.hpp" #include "../mwgui/loadingscreen.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -1321,6 +1322,29 @@ namespace MWRender } } + osg::Vec3f RenderingManager::getHalfExtents(const MWWorld::ConstPtr& object) const + { + osg::Vec3f halfExtents(0, 0, 0); + std::string modelName = object.getClass().getModel(object); + if (modelName.empty()) + return halfExtents; + + osg::ref_ptr node = mResourceSystem->getSceneManager()->getTemplate(modelName); + osg::ComputeBoundsVisitor computeBoundsVisitor; + computeBoundsVisitor.setTraversalMask(~(MWRender::Mask_ParticleSystem|MWRender::Mask_Effect)); + const_cast(node.get())->accept(computeBoundsVisitor); + osg::BoundingBox bounds = computeBoundsVisitor.getBoundingBox(); + + if (bounds.valid()) + { + halfExtents[0] = std::abs(bounds.xMax() - bounds.xMin()) / 2.f; + halfExtents[1] = std::abs(bounds.yMax() - bounds.yMin()) / 2.f; + halfExtents[2] = std::abs(bounds.zMax() - bounds.zMin()) / 2.f; + } + + return halfExtents; + } + void RenderingManager::resetFieldOfView() { if (mFieldOfViewOverridden == true) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index f8e7ba8bc..b4473c3b4 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -203,6 +203,8 @@ namespace MWRender /// reset a previous overrideFieldOfView() call, i.e. revert to field of view specified in the settings file. void resetFieldOfView(); + osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& object) const; + void exportSceneGraph(const MWWorld::Ptr& ptr, const std::string& filename, const std::string& format); LandManager* getLandManager() const; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index bf829225a..f9237761d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -3339,12 +3339,16 @@ namespace MWWorld return mRendering->getTerrainHeightAt(worldPos); } - osg::Vec3f World::getHalfExtents(const ConstPtr& actor, bool rendering) const + osg::Vec3f World::getHalfExtents(const ConstPtr& object, bool rendering) const { + if (!object.getClass().isActor()) + return mRendering->getHalfExtents(object); + + // Handle actors separately because of bodyparts if (rendering) - return mPhysics->getRenderingHalfExtents(actor); + return mPhysics->getRenderingHalfExtents(object); else - return mPhysics->getHalfExtents(actor); + return mPhysics->getHalfExtents(object); } std::string World::exportSceneGraph(const Ptr &ptr)