From 427b6ea39aa3f7023f0ac25acf22abce51c1a015 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 18 May 2023 19:51:02 +0200 Subject: [PATCH] fix bug in "fixColour" and "fixNormal" fix issue in vtx texture selection --- components/esm3terrain/storage.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/esm3terrain/storage.cpp b/components/esm3terrain/storage.cpp index 7dfce86ba8..90a9937262 100644 --- a/components/esm3terrain/storage.cpp +++ b/components/esm3terrain/storage.cpp @@ -110,8 +110,6 @@ namespace ESMTerrain osg::Vec3f& normal, ESM::ExteriorCellLocation cellLocation, int col, int row, LandCache& cache) { - const LandObject* land = getLand(cellLocation, cache); - const ESM::LandData* data = land ? land->getData(ESM::Land::DATA_VNML) : nullptr; const int landSize = ESM::getLandSize(cellLocation.mWorldspace); while (col >= landSize - 1) @@ -134,7 +132,8 @@ namespace ESMTerrain --cellLocation.mX; row += landSize - 1; } - + const LandObject* land = getLand(cellLocation, cache); + const ESM::LandData* data = land ? land->getData(ESM::Land::DATA_VNML) : nullptr; if (data) { normal.x() = data->getNormals()[col * landSize * 3 + row * 3]; @@ -161,8 +160,7 @@ namespace ESMTerrain void Storage::fixColour( osg::Vec4ub& color, ESM::ExteriorCellLocation cellLocation, int col, int row, LandCache& cache) { - const LandObject* land = getLand(cellLocation, cache); - const ESM::LandData* data = land ? land->getData(ESM::Land::DATA_VCLR) : nullptr; + const int landSize = ESM::getLandSize(cellLocation.mWorldspace); if (col == landSize - 1) @@ -175,7 +173,8 @@ namespace ESMTerrain ++cellLocation.mX; row = 0; } - + const LandObject* land = getLand(cellLocation, cache); + const ESM::LandData* data = land ? land->getData(ESM::Land::DATA_VCLR) : nullptr; if (data) { color.r() = data->getColors()[col * landSize * 3 + row * 3]; @@ -342,6 +341,7 @@ namespace ESMTerrain // For the first/last row/column, we need to get the texture from the neighbour cell // to get consistent blending at the borders --x; + ESM::ExteriorCellLocation cellLocationIn = cellLocation; if (x < 0) { --cellLocation.mX; @@ -359,6 +359,9 @@ namespace ESMTerrain y -= ESM::Land::LAND_TEXTURE_SIZE; } + if (cellLocation != cellLocationIn) + land = getLand(cellLocation, cache); + assert(x < ESM::Land::LAND_TEXTURE_SIZE); assert(y < ESM::Land::LAND_TEXTURE_SIZE);