diff --git a/src/noggit/MapChunk.cpp b/src/noggit/MapChunk.cpp index 02bb5dff..63a25bda 100755 --- a/src/noggit/MapChunk.cpp +++ b/src/noggit/MapChunk.cpp @@ -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; diff --git a/src/noggit/MapChunk.h b/src/noggit/MapChunk.h index 96fe1b97..70287022 100755 --- a/src/noggit/MapChunk.h +++ b/src/noggit/MapChunk.h @@ -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; } diff --git a/src/noggit/MapTile.cpp b/src/noggit/MapTile.cpp index 9dbd8b3a..f0a5b81c 100755 --- a/src/noggit/MapTile.cpp +++ b/src/noggit/MapTile.cpp @@ -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);