From d20a56517b3a5ad2843d5f14e16e926fbbb0d39d Mon Sep 17 00:00:00 2001 From: Sebastian Fieber Date: Wed, 23 Jul 2025 23:48:54 +0200 Subject: [PATCH] add getCurrentSunLightDirection --- apps/openmw/mwbase/world.hpp | 1 + apps/openmw/mwlua/weatherbindings.cpp | 14 ++++++++------ apps/openmw/mwrender/renderingmanager.hpp | 1 + apps/openmw/mwworld/worldimp.cpp | 6 +++++- apps/openmw/mwworld/worldimp.hpp | 1 + files/lua_api/openmw/core.lua | 5 +++++ 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 4b7fbaea8e..b0486b40a2 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -487,6 +487,7 @@ namespace MWBase // Allow NPCs to use torches? virtual bool useTorches() const = 0; + virtual const osg::Vec4f& getSunLightPosition() const = 0; virtual float getSunVisibility() const = 0; virtual float getSunPercentage() const = 0; diff --git a/apps/openmw/mwlua/weatherbindings.cpp b/apps/openmw/mwlua/weatherbindings.cpp index ebf185c515..e2a75a2c0b 100644 --- a/apps/openmw/mwlua/weatherbindings.cpp +++ b/apps/openmw/mwlua/weatherbindings.cpp @@ -117,12 +117,8 @@ namespace MWLua weatherT["recordId"] = sol::readonly_property([](const MWWorld::Weather& w) { return w.mId.serializeText(); }); api["getCurrent"] = []() { return MWBase::Environment::get().getWorld()->getCurrentWeather(); }; - api["getNext"] = []() -> sol::optional { - auto next = MWBase::Environment::get().getWorld()->getNextWeather(); - if (next != nullptr) - return *next; - return sol::nullopt; - }; + api["getNext"] + = []() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); }; api["getTransition"] = []() { return MWBase::Environment::get().getWorld()->getWeatherTransition(); }; api["changeWeather"] = [](std::string_view regionId, const MWWorld::Weather& weather) { @@ -151,6 +147,12 @@ namespace MWLua // Provide access to the store. api["records"] = WeatherStore{}; + api["getCurrentSunLightDirection"] = []() { + osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition(); + sunPos.normalize(); + + return sunPos; + }; api["getCurrentSunVisibility"] = []() { return MWBase::Environment::get().getWorld()->getSunVisibility(); }; api["getCurrentSunPercentage"] = []() { return MWBase::Environment::get().getWorld()->getSunPercentage(); }; api["getCurrentWindSpeed"] = []() { return MWBase::Environment::get().getWorld()->getWindSpeed(); }; diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 2e573f8276..4723c59b8a 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -139,6 +139,7 @@ namespace MWRender int skyGetSecundaPhase() const; void skySetMoonColour(bool red); + const osg::Vec4f& getSunLightPosition() const { return mSunLight->getPosition(); } void setSunDirection(const osg::Vec3f& direction); void setSunColour(const osg::Vec4f& diffuse, const osg::Vec4f& specular, float sunVis); void setNight(bool isNight) { mNight = isNight; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 24e4049fc9..057456abe4 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1,7 +1,6 @@ #include "worldimp.hpp" #include -#include #include #include @@ -3154,6 +3153,11 @@ namespace MWWorld } } + const osg::Vec4f& World::getSunLightPosition() const + { + return mRendering->getSunLightPosition(); + } + float World::getSunVisibility() const { return mWeatherManager->getSunVisibility(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 1501ca4ddc..d7c05a0191 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -579,6 +579,7 @@ namespace MWWorld // Allow NPCs to use torches? bool useTorches() const override; + const osg::Vec4f& getSunLightPosition() const override; float getSunVisibility() const override; float getSunPercentage() const override; diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index a0cd2790b8..668c1c0fd0 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -1235,6 +1235,11 @@ -- @param #string regionId -- @param #WeatherData The weather to change to +--- +-- Get the current direction of the light of the sun. +-- @function [parent=#Weather] getCurrentSunLightDirection +-- @return openmw.util#Vector4 + --- -- Get the current sun visibility taking weather transition into account. -- @function [parent=#Weather] getCurrentSunVisibility