Merge branch 'ground_effects_editor' into 'noggit-shadowlands'
fix update flags for imports + more See merge request prophecy-rp/noggit-red!33
This commit is contained in:
@@ -1280,10 +1280,13 @@ int MapChunk::addTexture(scoped_blp_texture_reference texture)
|
||||
return texture_set->addTexture(std::move (texture));
|
||||
}
|
||||
|
||||
void MapChunk::switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture)
|
||||
bool MapChunk::switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture)
|
||||
{
|
||||
texture_set->replace_texture(oldTexture, std::move (newTexture));
|
||||
bool changed = texture_set->replace_texture(oldTexture, std::move (newTexture));
|
||||
if (changed)
|
||||
registerChunkUpdate(ChunkUpdateFlags::ALPHAMAP);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool MapChunk::paintTexture(glm::vec3 const& pos, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture)
|
||||
|
||||
@@ -160,7 +160,7 @@ public:
|
||||
bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk = false);
|
||||
bool canPaintTexture(scoped_blp_texture_reference texture);
|
||||
int addTexture(scoped_blp_texture_reference texture);
|
||||
void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);
|
||||
bool switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);
|
||||
void eraseTextures();
|
||||
void eraseTexture(scoped_blp_texture_reference const& tex);
|
||||
void change_texture_flag(scoped_blp_texture_reference const& tex, std::size_t flag, bool add);
|
||||
|
||||
@@ -1049,7 +1049,7 @@ void MapTile::initEmptyChunks()
|
||||
|
||||
QImage MapTile::getHeightmapImage(float min_height, float max_height)
|
||||
{
|
||||
QImage image(257, 257, QImage::Format_RGBA64);
|
||||
QImage image(257, 257, QImage::Format_Grayscale16);
|
||||
|
||||
unsigned const LONG{9}, SHORT{8}, SUM{LONG + SHORT}, DSUM{SUM * 2};
|
||||
|
||||
@@ -1121,7 +1121,7 @@ QImage MapTile::getNormalmapImage()
|
||||
|
||||
QImage MapTile::getAlphamapImage(unsigned layer)
|
||||
{
|
||||
QImage image(1024, 1024, QImage::Format_RGBA8888);
|
||||
QImage image(1024, 1024, QImage::Format_Grayscale8);
|
||||
image.fill(Qt::black);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
@@ -1154,7 +1154,7 @@ QImage MapTile::getAlphamapImage(unsigned layer)
|
||||
|
||||
QImage MapTile::getAlphamapImage(std::string const& filename)
|
||||
{
|
||||
QImage image(1024, 1024, QImage::Format_RGBA8888);
|
||||
QImage image(1024, 1024, QImage::Format_Grayscale8);
|
||||
image.fill(Qt::black);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
@@ -1164,20 +1164,25 @@ QImage MapTile::getAlphamapImage(std::string const& filename)
|
||||
MapChunk *chunk = getChunk(i, j);
|
||||
|
||||
unsigned layer = 0;
|
||||
bool chunk_has_texture = false;
|
||||
|
||||
for (int k = 0; k < chunk->texture_set->num(); ++k)
|
||||
{
|
||||
if (chunk->texture_set->filename(k) == filename)
|
||||
{
|
||||
layer = k;
|
||||
chunk_has_texture = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!layer)
|
||||
if (!chunk_has_texture)
|
||||
{
|
||||
for (int k = 0; k < 64; ++k)
|
||||
{
|
||||
for (int l = 0; l < 64; ++l)
|
||||
{
|
||||
image.setPixelColor((i * 64) + k, (j * 64) + l, QColor(255, 255, 255, 255));
|
||||
// if texture is not in the chunk, set chunk to black
|
||||
image.setPixelColor((i * 64) + k, (j * 64) + l, QColor(0, 0, 0, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1186,12 +1191,28 @@ QImage MapTile::getAlphamapImage(std::string const& filename)
|
||||
chunk->texture_set->apply_alpha_changes();
|
||||
auto alphamaps = chunk->texture_set->getAlphamaps();
|
||||
|
||||
auto alpha_layer = alphamaps->at(layer - 1).value();
|
||||
|
||||
for (int k = 0; k < 64; ++k)
|
||||
{
|
||||
for (int l = 0; l < 64; ++l)
|
||||
{
|
||||
if (layer == 0) // titi test
|
||||
{
|
||||
// WoW calculates layer 0 as 255 - sum(Layer[1]...Layer[3])
|
||||
int layers_sum = 0;
|
||||
if (alphamaps->at(0).has_value())
|
||||
layers_sum += alphamaps->at(0).value().getAlpha(64 * l + k);
|
||||
if (alphamaps->at(1).has_value())
|
||||
layers_sum += alphamaps->at(1).value().getAlpha(64 * l + k);
|
||||
if (alphamaps->at(2).has_value())
|
||||
layers_sum += alphamaps->at(2).value().getAlpha(64 * l + k);
|
||||
|
||||
int value = std::clamp((255 - layers_sum), 0, 255);
|
||||
image.setPixelColor((i * 64) + k, (j * 64) + l, QColor(value, value, value, 255));
|
||||
}
|
||||
else // layer 1-3
|
||||
{
|
||||
auto alpha_layer = alphamaps->at(layer - 1).value();
|
||||
|
||||
int value = alpha_layer.getAlpha(64 * l + k);
|
||||
image.setPixelColor((i * 64) + k, (j * 64) + l, QColor(value, value, value, 255));
|
||||
}
|
||||
@@ -1199,12 +1220,15 @@ QImage MapTile::getAlphamapImage(std::string const& filename)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode, bool tiledEdges)
|
||||
void MapTile::setHeightmapImage(QImage const& baseimage, float multiplier, int mode, bool tiledEdges) // image
|
||||
{
|
||||
auto image = baseimage.convertToFormat(QImage::Format_Grayscale16);
|
||||
|
||||
unsigned const LONG{9}, SHORT{8}, SUM{LONG + SHORT}, DSUM{SUM * 2};
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
@@ -1353,8 +1377,10 @@ void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode,
|
||||
}
|
||||
}
|
||||
|
||||
void MapTile::setAlphaImage(QImage const& image, unsigned layer)
|
||||
void MapTile::setAlphaImage(QImage const& baseimage, unsigned layer)
|
||||
{
|
||||
auto image = baseimage.convertToFormat(QImage::Format_Grayscale8);
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
for (int l = 0; l < 16; ++l)
|
||||
@@ -1364,6 +1390,8 @@ void MapTile::setAlphaImage(QImage const& image, unsigned layer)
|
||||
if (layer >= chunk->texture_set->num())
|
||||
continue;
|
||||
|
||||
chunk->registerChunkUpdate(ChunkUpdateFlags::ALPHAMAP);
|
||||
|
||||
chunk->texture_set->create_temporary_alphamaps_if_needed();
|
||||
auto& temp_alphamaps = chunk->texture_set->getTempAlphamaps()->value();
|
||||
|
||||
@@ -1420,8 +1448,10 @@ QImage MapTile::getVertexColorsImage()
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
void MapTile::setVertexColorImage(QImage const& image, int mode, bool tiledEdges)
|
||||
void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledEdges)
|
||||
{
|
||||
QImage image = baseimage.convertToFormat(QImage::Format_RGBA8888);
|
||||
|
||||
unsigned const LONG{9}, SHORT{8}, SUM{LONG + SHORT}, DSUM{SUM * 2};
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
@@ -1430,6 +1460,8 @@ void MapTile::setVertexColorImage(QImage const& image, int mode, bool tiledEdges
|
||||
{
|
||||
MapChunk* chunk = getChunk(k, l);
|
||||
|
||||
chunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
|
||||
|
||||
glm::vec3* colors = chunk->getVertexColors();
|
||||
|
||||
for (unsigned y = 0; y < SUM; ++y)
|
||||
@@ -1554,9 +1586,6 @@ void MapTile::setVertexColorImage(QImage const& image, int mode, bool tiledEdges
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MapTile::recalcExtents()
|
||||
{
|
||||
if (!_extents_dirty)
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
QImage getAlphamapImage(std::string const& filename);
|
||||
QImage getVertexColorsImage();
|
||||
QImage getNormalmapImage();
|
||||
void setHeightmapImage(QImage const& image, float multiplier, int mode, bool tiledEdges);
|
||||
void setHeightmapImage(QImage const& baseimage, float multiplier, int mode, bool tiledEdges);
|
||||
void setAlphaImage(QImage const& image, unsigned layer);
|
||||
void setVertexColorImage(QImage const& image, int mode, bool tiledEdges);
|
||||
void registerChunkUpdate(unsigned flags) { _chunk_update_flags |= flags; };
|
||||
|
||||
@@ -1826,7 +1826,7 @@ void MapView::setupAssistMenu()
|
||||
(
|
||||
makeCurrent();
|
||||
OpenGL::context::scoped_setter const _(::gl, context());
|
||||
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_TEXTURE);
|
||||
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_TERRAIN);
|
||||
_world->importAllADTsHeightmaps(adt_import_height_params_multiplier->value(), adt_import_height_params_mode->currentIndex(), adt_import_height_tiled_edges->isChecked());
|
||||
NOGGIT_ACTION_MGR->endAction();
|
||||
)
|
||||
@@ -1845,7 +1845,7 @@ void MapView::setupAssistMenu()
|
||||
(
|
||||
makeCurrent();
|
||||
OpenGL::context::scoped_setter const _(::gl, context());
|
||||
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_TEXTURE);
|
||||
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_VERTEX_COLOR);
|
||||
_world->importAllADTVertexColorMaps(adt_import_vcol_params_mode->currentIndex(), adt_import_vcol_params_mode_tiled_edges->isChecked());
|
||||
NOGGIT_ACTION_MGR->endAction();
|
||||
)
|
||||
|
||||
@@ -2278,6 +2278,51 @@ void World::swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex)
|
||||
}
|
||||
}
|
||||
|
||||
void World::swapTextureGlobal(scoped_blp_texture_reference tex)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (!!Noggit::Ui::selected_texture::get())
|
||||
{
|
||||
|
||||
for (size_t z = 0; z < 64; z++)
|
||||
{
|
||||
for (size_t x = 0; x < 64; x++)
|
||||
{
|
||||
TileIndex tile(x, z);
|
||||
|
||||
bool unload = !mapIndex.tileLoaded(tile) && !mapIndex.tileAwaitingLoading(tile);
|
||||
MapTile* mTile = mapIndex.loadTile(tile);
|
||||
|
||||
if (mTile)
|
||||
{
|
||||
mTile->wait_until_loaded();
|
||||
|
||||
bool tile_changed = false;
|
||||
for_all_chunks_on_tile(mTile, [&](MapChunk* chunk)
|
||||
{
|
||||
// NOGGIT_CUR_ACTION->registerChunkTextureChange(chunk);
|
||||
bool swapped = chunk->switchTexture(tex, *Noggit::Ui::selected_texture::get());
|
||||
if (swapped)
|
||||
tile_changed = true;
|
||||
});
|
||||
|
||||
if (tile_changed)
|
||||
{
|
||||
mTile->saveTile(this);
|
||||
mapIndex.markOnDisc(tile, true);
|
||||
mapIndex.unsetChanged(tile);
|
||||
}
|
||||
|
||||
if (unload)
|
||||
{
|
||||
mapIndex.unloadTile(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
@@ -197,6 +197,9 @@ public:
|
||||
template<typename Fun>
|
||||
void for_all_chunks_on_tile (glm::vec3 const& pos, Fun&&);
|
||||
|
||||
template<typename Fun>
|
||||
void for_all_chunks_on_tile(MapTile* tile, Fun&& fun);
|
||||
|
||||
template<typename Fun>
|
||||
void for_chunk_at(glm::vec3 const& pos, Fun&& fun);
|
||||
template<typename Fun>
|
||||
@@ -228,6 +231,7 @@ public:
|
||||
void clear_shadows(glm::vec3 const& pos);
|
||||
void clearTextures(glm::vec3 const& pos);
|
||||
void swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex);
|
||||
void swapTextureGlobal(scoped_blp_texture_reference tex);
|
||||
void removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex);
|
||||
void removeTexDuplicateOnADT(glm::vec3 const& pos);
|
||||
void change_texture_flag(glm::vec3 const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add);
|
||||
|
||||
@@ -25,6 +25,23 @@ void World::for_all_chunks_on_tile (glm::vec3 const& pos, Fun&& fun)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Fun>
|
||||
void World::for_all_chunks_on_tile(MapTile* tile, Fun&& fun)
|
||||
{
|
||||
if (tile && tile->finishedLoading())
|
||||
{
|
||||
mapIndex.setChanged(tile);
|
||||
|
||||
for (size_t ty = 0; ty < 16; ++ty)
|
||||
{
|
||||
for (size_t tx = 0; tx < 16; ++tx)
|
||||
{
|
||||
fun(tile->getChunk(ty, tx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Fun>
|
||||
void World::for_chunk_at(glm::vec3 const& pos, Fun&& fun)
|
||||
{
|
||||
|
||||
@@ -189,7 +189,8 @@ map_horizon::map_horizon(const std::string& basename, const MapIndex * const ind
|
||||
wdl_file.read(_tiles[y][x]->height_17, 17 * 17 * sizeof(int16_t));
|
||||
wdl_file.read(_tiles[y][x]->height_16, 16 * 16 * sizeof(int16_t));
|
||||
|
||||
|
||||
if (wdl_file.getPos() < wdl_file.getSize())
|
||||
{
|
||||
wdl_file.read(&fourcc, 4);
|
||||
if (fourcc == 'MAHO')
|
||||
{
|
||||
@@ -197,6 +198,7 @@ map_horizon::map_horizon(const std::string& basename, const MapIndex * const ind
|
||||
assert(size == 0x20);
|
||||
wdl_file.read(_tiles[y][x]->holes, 16 * sizeof(int16_t));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1098,6 +1098,13 @@ void MapIndex::loadMinimapMD5translate()
|
||||
|
||||
QStringList line_split = line.split(QRegExp("[\t]"));
|
||||
|
||||
if (line_split.length() < 2)
|
||||
{
|
||||
std::string text = "Failed to read md5translate.trs.\nLine \"" + line.toStdString() + "\n has no tab spacing. Spacing must be only a tab character and not spaces.";
|
||||
LogError << text << std::endl;
|
||||
throw std::logic_error(text);
|
||||
}
|
||||
|
||||
if (cur_dir.length())
|
||||
{
|
||||
_minimap_md5translate[cur_dir.toStdString()][line_split[0].toStdString()] = line_split[1].toStdString();
|
||||
|
||||
@@ -87,7 +87,7 @@ int TextureSet::addTexture (scoped_blp_texture_reference texture)
|
||||
return texLevel;
|
||||
}
|
||||
|
||||
void TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture)
|
||||
bool TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture)
|
||||
{
|
||||
int texture_to_replace_level = -1, replacement_texture_level = -1;
|
||||
|
||||
@@ -122,6 +122,11 @@ void TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to
|
||||
// merge_layers(texture_to_replace_level, replacement_texture_level);
|
||||
}
|
||||
}
|
||||
|
||||
if (texture_to_replace_level != -1 || replacement_texture_level != -1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextureSet::swap_layers(int layer_1, int layer_2)
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
// return true if at least 1 texture has been erased
|
||||
bool eraseUnusedTextures();
|
||||
void swap_layers(int layer_1, int layer_2);
|
||||
void replace_texture(scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture);
|
||||
bool replace_texture(scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture);
|
||||
bool paintTexture(float xbase, float zbase, float x, float z, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture);
|
||||
bool stampTexture(float xbase, float zbase, float x, float z, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* image, bool paint);
|
||||
bool replace_texture( float xbase
|
||||
|
||||
@@ -36,12 +36,14 @@ namespace Noggit
|
||||
|
||||
QPushButton* select = new QPushButton("Select", this);
|
||||
QPushButton* swap_adt = new QPushButton("Swap ADT", this);
|
||||
QPushButton* swap_global = new QPushButton("Swap Global(All ADTs)", this);
|
||||
QPushButton* remove_text_adt = new QPushButton(tr("Remove this texture from ADT"), this);
|
||||
|
||||
layout->addRow(new QLabel("Texture to swap"));
|
||||
layout->addRow(_texture_to_swap_display);
|
||||
layout->addRow(select);
|
||||
layout->addRow(swap_adt);
|
||||
layout->addRow(swap_global);
|
||||
layout->addRow(remove_text_adt);
|
||||
|
||||
_brush_mode_group = new QGroupBox("Brush mode", this);
|
||||
@@ -89,6 +91,14 @@ namespace Noggit
|
||||
}
|
||||
});
|
||||
|
||||
connect(swap_global, &QPushButton::clicked, [this, camera_pos, map_view]() {
|
||||
if (_texture_to_swap)
|
||||
{
|
||||
// TODO : action manager
|
||||
_world->swapTextureGlobal(_texture_to_swap.value());
|
||||
}
|
||||
});
|
||||
|
||||
connect(remove_text_adt, &QPushButton::clicked, [this, camera_pos, map_view]() {
|
||||
if (_texture_to_swap)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user