fix vertex colors image import

This commit is contained in:
T1ti
2024-04-24 07:18:17 +02:00
parent 9852bbe0cd
commit d4d69ca5c7
3 changed files with 42 additions and 18 deletions

View File

@@ -860,16 +860,8 @@ bool MapChunk::ChangeMCCV(glm::vec3 const& pos, glm::vec4 const& color, float ch
if (!hasMCCV)
{
for (int i = 0; i < mapbufsize; ++i)
{
mccv[i].x = 1.0f; // set default shaders
mccv[i].y = 1.0f;
mccv[i].z = 1.0f;
}
initMCCV();
changed = true;
header_flags.flags.has_mccv = 1;
hasMCCV = true;
}
for (int i = 0; i < mapbufsize; ++i)
@@ -913,16 +905,8 @@ bool MapChunk::stampMCCV(glm::vec3 const& pos, glm::vec4 const& color, float cha
if (!hasMCCV)
{
for (int i = 0; i < mapbufsize; ++i)
{
mccv[i].x = 1.0f; // set default shaders
mccv[i].y = 1.0f;
mccv[i].z = 1.0f;
}
initMCCV();
changed = true;
header_flags.flags.has_mccv = 1;
hasMCCV = true;
}
for (int i = 0; i < mapbufsize; ++i)
@@ -2046,6 +2030,22 @@ void MapChunk::setVertexColorImage(const QImage &image)
registerChunkUpdate(ChunkUpdateFlags::MCCV);
}
void MapChunk::initMCCV()
{
if (!hasMCCV)
{
for (int i = 0; i < mapbufsize; ++i)
{
mccv[i].x = 1.0f; // set default shaders
mccv[i].y = 1.0f;
mccv[i].z = 1.0f;
}
header_flags.flags.has_mccv = 1;
hasMCCV = true;
}
}
void MapChunk::registerChunkUpdate(unsigned flags)
{
_chunk_update_flags |= flags;

View File

@@ -215,6 +215,7 @@ public:
void setHeightmapImage(QImage const& image, float multiplier, int mode);
void setAlphamapImage(QImage const& image, unsigned layer);
void setVertexColorImage(QImage const& image);
void initMCCV();
void registerChunkUpdate(unsigned flags);
void endChunkUpdates() { _chunk_update_flags = 0; }

View File

@@ -1465,6 +1465,11 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE
{
MapChunk* chunk = getChunk(k, l);
if (!chunk->hasColors())
{
chunk->initMCCV();
}
chunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
glm::vec3* colors = chunk->getVertexColors();
@@ -1540,6 +1545,12 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE
{
MapChunk* targetChunk = tile->getChunk(chunk_x, 15);
MapChunk* sourceChunk = this->getChunk(chunk_x, 0);
if (!targetChunk->hasColors())
{
targetChunk->initMCCV();
}
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
for (int vert_x = 0; vert_x < 9; ++vert_x)
{
@@ -1563,6 +1574,12 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE
{
MapChunk* targetChunk = tile->getChunk(15, chunk_y);
MapChunk* sourceChunk = this->getChunk(0, chunk_y);
if (!targetChunk->hasColors())
{
targetChunk->initMCCV();
}
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
for (int vert_y = 0; vert_y < 9; ++vert_y)
{
@@ -1582,6 +1599,12 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE
, [&] (MapTile* tile)
{
MapChunk* targetChunk = tile->getChunk(15, 15);
if (!targetChunk->hasColors())
{
targetChunk->initMCCV();
}
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
tile->getChunk(15,15)->getVertexColors()[144] = this->getChunk(0,0)->getVertexColors()[0];
tile->registerChunkUpdate(ChunkUpdateFlags::MCCV);