mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 23:36:59 -04:00
apply changes requested in the code review
This commit is contained in:
parent
378093791b
commit
c711179b8f
@ -17,13 +17,6 @@ namespace MWLua
|
|||||||
sol::state_view& lua = context.mLua->sol();
|
sol::state_view& lua = context.mLua->sol();
|
||||||
sol::table landApi(lua, sol::create);
|
sol::table landApi(lua, sol::create);
|
||||||
|
|
||||||
// Constants
|
|
||||||
landApi["RANGE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, ESM::RangeType>({
|
|
||||||
{ "Self", ESM::RT_Self },
|
|
||||||
{ "Touch", ESM::RT_Touch },
|
|
||||||
{ "Target", ESM::RT_Target },
|
|
||||||
}));
|
|
||||||
|
|
||||||
landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) {
|
landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) {
|
||||||
ESM::RefId worldspace;
|
ESM::RefId worldspace;
|
||||||
if (cellOrName.is<GCell>())
|
if (cellOrName.is<GCell>())
|
||||||
@ -63,7 +56,7 @@ namespace MWLua
|
|||||||
return ESMTerrain::Storage::getHeightAt(landData->mHeights, landData->sLandSize, pos, cellSize);
|
return ESMTerrain::Storage::getHeightAt(landData->mHeights, landData->sLandSize, pos, cellSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
landApi["getLandTextureAt"] = [lua = context.mLua](const osg::Vec3f& pos, sol::object cellOrName) {
|
landApi["getTextureAt"] = [lua = context.mLua](const osg::Vec3f& pos, sol::object cellOrName) {
|
||||||
sol::variadic_results values;
|
sol::variadic_results values;
|
||||||
ESM::RefId worldspace;
|
ESM::RefId worldspace;
|
||||||
if (cellOrName.is<GCell>())
|
if (cellOrName.is<GCell>())
|
||||||
@ -85,6 +78,11 @@ namespace MWLua
|
|||||||
auto store = MWBase::Environment::get().getESMStore();
|
auto store = MWBase::Environment::get().getESMStore();
|
||||||
// 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.
|
||||||
|
// To properly calculate that offset, we need to know how many texture samples exist per cell edge,
|
||||||
|
// as it differs between tes3 and tes4. It's equal -
|
||||||
|
// Once we know the value, we will calculate the offset and retrieve a sample again, this time
|
||||||
|
// with the offset taken into account.
|
||||||
auto landStore = store->get<ESM::Land>();
|
auto landStore = store->get<ESM::Land>();
|
||||||
auto land = landStore.search(cellX, cellY);
|
auto land = landStore.search(cellX, cellY);
|
||||||
const ESM::Land::LandData* landData = nullptr;
|
const ESM::Land::LandData* landData = nullptr;
|
||||||
@ -105,6 +103,8 @@ namespace MWLua
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use landData to get amount of sampler per cell edge (sLandTextureSize)
|
||||||
|
// and then get the corrected position that will map to the rendered texture
|
||||||
const osg::Vec3f correctedPos
|
const osg::Vec3f correctedPos
|
||||||
= ESMTerrain::Storage::getTextureCorrectedWorldPos(pos, landData->sLandTextureSize, cellSize);
|
= ESMTerrain::Storage::getTextureCorrectedWorldPos(pos, landData->sLandTextureSize, cellSize);
|
||||||
int correctedCellX = static_cast<int>(std::floor(correctedPos.x() / cellSize));
|
int correctedCellX = static_cast<int>(std::floor(correctedPos.x() / cellSize));
|
||||||
@ -128,7 +128,7 @@ namespace MWLua
|
|||||||
|
|
||||||
// We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt
|
// We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt
|
||||||
const ESMTerrain::UniqueTextureId textureId
|
const ESMTerrain::UniqueTextureId textureId
|
||||||
= ESMTerrain::Storage::getLandTextureAt(correctedLandData->mTextures, correctedLand->getPlugin(),
|
= ESMTerrain::Storage::getTextureAt(correctedLandData->mTextures, correctedLand->getPlugin(),
|
||||||
correctedLandData->sLandTextureSize, correctedPos, cellSize);
|
correctedLandData->sLandTextureSize, correctedPos, cellSize);
|
||||||
|
|
||||||
// Need to check for 0, 0 so that we can safely subtract 1 later, as per documentation on UniqueTextureId
|
// Need to check for 0, 0 so that we can safely subtract 1 later, as per documentation on UniqueTextureId
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <osg/Vec3f>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <osg/Image>
|
#include <osg/Image>
|
||||||
#include <osg/Plane>
|
#include <osg/Plane>
|
||||||
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/esm/esmterrain.hpp>
|
#include <components/esm/esmterrain.hpp>
|
||||||
@ -475,6 +475,7 @@ namespace ESMTerrain
|
|||||||
blendmaps.clear(); // If a single texture fills the whole terrain, there is no need to blend
|
blendmaps.clear(); // If a single texture fills the whole terrain, there is no need to blend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a position that can be used to look up a land texture, while taking their offset into account
|
||||||
osg::Vec3f Storage::getTextureCorrectedWorldPos(
|
osg::Vec3f Storage::getTextureCorrectedWorldPos(
|
||||||
const osg::Vec3f& uncorrectedWorldPos, const int textureSize, const float cellSize)
|
const osg::Vec3f& uncorrectedWorldPos, const int textureSize, const float cellSize)
|
||||||
{
|
{
|
||||||
@ -485,7 +486,7 @@ namespace ESMTerrain
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Takes in a corrected world pos to match the visuals.
|
// Takes in a corrected world pos to match the visuals.
|
||||||
UniqueTextureId Storage::getLandTextureAt(const std::span<const std::uint16_t> landData, const int plugin,
|
UniqueTextureId Storage::getTextureAt(const std::span<const std::uint16_t> landData, const int plugin,
|
||||||
const int textureSize, const osg::Vec3f& correctedWorldPos, const float cellSize)
|
const int textureSize, const osg::Vec3f& correctedWorldPos, const float cellSize)
|
||||||
{
|
{
|
||||||
int cellX = static_cast<int>(std::floor(correctedWorldPos.x() / cellSize));
|
int cellX = static_cast<int>(std::floor(correctedWorldPos.x() / cellSize));
|
||||||
|
@ -120,7 +120,7 @@ namespace ESMTerrain
|
|||||||
static osg::Vec3f getTextureCorrectedWorldPos(
|
static osg::Vec3f getTextureCorrectedWorldPos(
|
||||||
const osg::Vec3f& uncorrectedWorldPos, const int textureSize, const float cellSize);
|
const osg::Vec3f& uncorrectedWorldPos, const int textureSize, const float cellSize);
|
||||||
|
|
||||||
static UniqueTextureId getLandTextureAt(const std::span<const std::uint16_t> landData, const int plugin,
|
static UniqueTextureId getTextureAt(const std::span<const std::uint16_t> landData, const int plugin,
|
||||||
const int textureSize, const osg::Vec3f& worldPos, const float cellSize);
|
const int textureSize, const osg::Vec3f& worldPos, const float cellSize);
|
||||||
|
|
||||||
/// Get the transformation factor for mapping cell units to world units.
|
/// Get the transformation factor for mapping cell units to world units.
|
||||||
|
@ -467,10 +467,10 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- Get the terrain texture at a given location.
|
-- Get the terrain texture at a given location.
|
||||||
-- @function [parent=#Land] getLandTextureAt
|
-- @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 (optional) cell or cell name in their exterior world space to query
|
||||||
-- @return #nil, #number Land texture index or nil if failed to retrieve the texture
|
-- @return #nil, #number Land texture index or nil if failed to retrieve the texture. Landscape textures created through editors such as openmw-cs can be assigned an id to differentiate them, that is also used for terrain rendering. The value returned here corresponds to that value. See also LTEX records (https://en.uesp.net/wiki/Morrowind_Mod:Mod_File_Format/LTEX)
|
||||||
-- @return #nil, #number Plugin id or nil if failed to retrieve the texture
|
-- @return #nil, #number Plugin id or nil if failed to retrieve the texture
|
||||||
-- @return #nil, #string Texture path or nil if one isn't defined
|
-- @return #nil, #string Texture path or nil if one isn't defined
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user