1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-24 16:00:54 +00:00

Merge pull request #7 from Diject/background_color

Add background color export to map info files
This commit is contained in:
Diject 2026-01-02 20:46:31 +03:00 committed by GitHub
commit af5a8246a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 7 deletions

View file

@ -182,6 +182,8 @@ namespace OMW
return;
}
osg::Vec3f bgColor = mGlobalMap->getBackgroundColor();
file << "width: " << width << "\n";
file << "height: " << height << "\n";
file << "pixelsPerCell: 32\n";
@ -192,6 +194,7 @@ namespace OMW
file << " min: " << minY << "\n";
file << " max: " << maxY << "\n";
file << "file: \"map.png\"\n";
file << "bColor: [" << bgColor.x() << ", " << bgColor.y() << ", " << bgColor.z() << "]\n";
file.close();

View file

@ -199,12 +199,11 @@ namespace MWRender
int texelX = (x - mMinX) * mCellSize + cellX;
int texelY = (y - mMinY) * mCellSize + cellY;
int lutIndex = 0;
osg::Vec4 color = mColorLut->getColor(lutIndex, 0);
osg::Vec4 color = mColorLut->getColor(0, 0);
image->setColor(color, texelX, texelY);
// Set alpha based on lutIndex threshold
osg::Vec4 alpha(0.0f, 0.0f, 0.0f, lutIndex < 128 ? 0.0f : 1.0f);
osg::Vec4 alpha(0.0f, 0.0f, 0.0f, 0.0f);
alphaImage->setColor(alpha, texelX, texelY);
}
}
@ -319,17 +318,17 @@ namespace MWRender
// Load color LUT texture
constexpr VFS::Path::NormalizedView colorLutPath("textures/omw_map_color_palette.dds");
auto resourceSystem = MWBase::Environment::get().getResourceSystem();
osg::ref_ptr<osg::Image> colorLut = resourceSystem->getImageManager()->getImage(colorLutPath);
mColorLut = resourceSystem->getImageManager()->getImage(colorLutPath);
// Validate LUT dimensions
if (!colorLut || colorLut->s() != 256 || colorLut->t() != 1)
if (!mColorLut || mColorLut->s() != 256 || mColorLut->t() != 1)
{
throw std::runtime_error("Global map color LUT must be 256x1 pixels, got "
+ std::to_string(colorLut ? colorLut->s() : 0) + "x" + std::to_string(colorLut ? colorLut->t() : 0));
+ std::to_string(mColorLut ? mColorLut->s() : 0) + "x" + std::to_string(mColorLut ? mColorLut->t() : 0));
}
mWorkItem = new CreateMapWorkItem(
mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, cellSize, esmStore.get<ESM::Land>(), colorLut);
mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, cellSize, esmStore.get<ESM::Land>(), mColorLut);
mWorkQueue->addWorkItem(mWorkItem);
}
@ -674,4 +673,14 @@ namespace MWRender
mWritePng = new WritePng(new osg::Image(*mOverlayImage, osg::CopyOp::DEEP_COPY_ALL));
mWorkQueue->addWorkItem(mWritePng, /*front=*/true);
}
osg::Vec3f GlobalMap::getBackgroundColor() const
{
if (mColorLut)
{
osg::Vec4 color = mColorLut->getColor(0, 0);
return osg::Vec3f(color.r(), color.g(), color.b());
}
return osg::Vec3f(0.0f, 0.0f, 0.0f);
}
}

View file

@ -74,6 +74,8 @@ namespace MWRender
void asyncWritePng();
osg::Vec3f getBackgroundColor() const;
private:
struct WritePng;
@ -121,6 +123,8 @@ namespace MWRender
// CPU copy of overlay
osg::ref_ptr<osg::Image> mOverlayImage;
osg::ref_ptr<osg::Image> mColorLut;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
osg::ref_ptr<CreateMapWorkItem> mWorkItem;
osg::ref_ptr<WritePng> mWritePng;

View file

@ -4159,6 +4159,8 @@ namespace MWWorld
infoFile << " min: " << minY << "\n";
infoFile << " max: " << maxY << "\n";
infoFile << "file: \"tilemap.png\"\n";
infoFile << "bColor: [" << backgroundColor.x() << ", " << backgroundColor.y() << ", " << backgroundColor.z()
<< "]\n";
infoFile.close();