1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-27 19:11:34 +00:00

no interior cell + make cellOrName mandatory

This commit is contained in:
Sebastian Fieber 2025-01-12 17:26:20 +01:00
parent 5d0986e812
commit 7c76387ffe
2 changed files with 12 additions and 14 deletions

View file

@ -46,21 +46,19 @@ namespace
return { tex, plugin }; return { tex, plugin };
} }
const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName) const ESM::RefId worldspaceAt(sol::object cellOrName)
{ {
ESM::RefId worldspace; const MWWorld::Cell* cell = nullptr;
if (cellOrName.is<MWLua::GCell>()) if (cellOrName.is<MWLua::GCell>())
worldspace = cellOrName.as<MWLua::GCell>().mStore->getCell()->getWorldSpace(); cell = cellOrName.as<MWLua::GCell>().mStore->getCell();
else if (cellOrName.is<std::string_view>() && !cellOrName.as<std::string_view>().empty()) else if (cellOrName.is<std::string_view>() && !cellOrName.as<std::string_view>().empty())
worldspace = MWBase::Environment::get() cell = MWBase::Environment::get().getWorldModel()->getCell(cellOrName.as<std::string_view>()).getCell();
.getWorldModel() if (cell = nullptr)
->getCell(cellOrName.as<std::string_view>()) throw std::runtime_error("Invalid cell");
.getCell() else if (!cell->isExterior())
->getWorldSpace(); throw std::runtime_error("Cell cannot be interior");
else
worldspace = ESM::Cell::sDefaultWorldspaceId;
return worldspace; return cell->getWorldSpace();
} }
bool fillLandData(const MWWorld::Store<ESM::Land>& landStore, const osg::Vec3f& pos, const float cellSize, bool fillLandData(const MWWorld::Store<ESM::Land>& landStore, const osg::Vec3f& pos, const float cellSize,
@ -91,7 +89,7 @@ namespace MWLua
sol::table landApi(lua, sol::create); sol::table landApi(lua, sol::create);
landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) { landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) {
ESM::RefId worldspace = worldspaceAt(pos, cellOrName); ESM::RefId worldspace = worldspaceAt(cellOrName);
return MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos, worldspace); return MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos, worldspace);
}; };
@ -100,7 +98,7 @@ namespace MWLua
MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
const MWWorld::Store<ESM::Land>& landStore = store.get<ESM::Land>(); const MWWorld::Store<ESM::Land>& landStore = store.get<ESM::Land>();
const float cellSize = ESM::getCellSize(worldspaceAt(pos, cellOrName)); const float cellSize = ESM::getCellSize(worldspaceAt(cellOrName));
// We need to read land twice. Once to get the amount of texture samples per cell edge, and the second time // We need to read land twice. Once to get the amount of texture samples per cell edge, and the second time
// to get the actual data // to get the actual data
// This is because the visual land textures are offset with regards to quads that are rendered for terrain. // This is because the visual land textures are offset with regards to quads that are rendered for terrain.

View file

@ -464,7 +464,7 @@
-- Get the terrain texture at a given location. -- Get the terrain texture at a given location.
-- @function [parent=#Land] getTextureAt -- @function [parent=#Land] getTextureAt
-- @param openmw.util#Vector3 position -- @param openmw.util#Vector3 position
-- @param #any cellOrName (optional) cell or cell name in their exterior world space to query -- @param #any cellOrName cell or cell name in their exterior world space to query
-- @return #nil, #string Texture path or nil if one isn't defined -- @return #nil, #string Texture path or nil if one isn't defined
-- @return #nil, #string Plugin name or nil if failed to retrieve the texture -- @return #nil, #string Plugin name or nil if failed to retrieve the texture