add tiled edges option for heightmap image import
- allows importing heightmaps from 256x256 images (e.g. without duplicate edges)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include <external/tracy/Tracy.hpp>
|
||||
#include <util/CurrentFunction.hpp>
|
||||
|
||||
|
||||
#include <noggit/World.inl>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <cassert>
|
||||
@@ -1203,10 +1203,9 @@ QImage MapTile::getAlphamapImage(std::string const& filename)
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode)
|
||||
void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode, bool tiledEdges)
|
||||
{
|
||||
unsigned const LONG{9}, SHORT{8}, SUM{LONG + SHORT}, DSUM{SUM * 2};
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
for (int l = 0; l < 16; ++l)
|
||||
@@ -1229,6 +1228,11 @@ void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode)
|
||||
bool const erp = plain % DSUM / SUM;
|
||||
unsigned const idx {(plain - (is_virtual ? (erp ? SUM : 1) : 0)) / 2};
|
||||
|
||||
if (tiledEdges && ((y == 16 && l == 15) || (x == 16 && k == 15)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (image.depth())
|
||||
{
|
||||
case 8:
|
||||
@@ -1287,6 +1291,66 @@ void MapTile::setHeightmapImage(QImage const& image, float multiplier, int mode)
|
||||
registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
}
|
||||
}
|
||||
|
||||
if (tiledEdges) // resize + fit
|
||||
{
|
||||
if (index.z > 0)
|
||||
{
|
||||
getWorld()->for_tile_at(TileIndex{ index.x, index.z-1}
|
||||
, [&](MapTile* tile)
|
||||
{
|
||||
for (int chunk_x = 0; chunk_x < 16; ++chunk_x)
|
||||
{
|
||||
MapChunk* targetChunk = tile->getChunk(chunk_x, 15);
|
||||
MapChunk* sourceChunk = this->getChunk(chunk_x, 0);
|
||||
targetChunk->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
for (int vert_x = 0; vert_x < 9; ++vert_x)
|
||||
{
|
||||
int target_vert = 136 + vert_x;
|
||||
int source_vert = vert_x;
|
||||
targetChunk->getHeightmap()[target_vert].y = sourceChunk->getHeightmap()[source_vert].y;
|
||||
}
|
||||
}
|
||||
tile->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (index.x > 1)
|
||||
{
|
||||
getWorld()->for_tile_at(TileIndex{ index.x-1, index.z}
|
||||
, [&](MapTile* tile)
|
||||
{
|
||||
for (int chunk_y = 0; chunk_y < 16; ++chunk_y)
|
||||
{
|
||||
MapChunk* targetChunk = tile->getChunk(15, chunk_y);
|
||||
MapChunk* sourceChunk = this->getChunk(0, chunk_y);
|
||||
targetChunk->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
for (int vert_y = 0; vert_y < 9; ++vert_y)
|
||||
{
|
||||
int target_vert = vert_y * 17 + 8;
|
||||
int source_vert = vert_y * 17;
|
||||
targetChunk->getHeightmap()[target_vert].y = sourceChunk->getHeightmap()[source_vert].y;
|
||||
}
|
||||
}
|
||||
tile->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (index.x > 1 && index.z > 1)
|
||||
{
|
||||
getWorld()->for_tile_at(TileIndex { index.x-1, index.z-1 }
|
||||
, [&] (MapTile* tile)
|
||||
{
|
||||
MapChunk* targetChunk = tile->getChunk(15, 15);
|
||||
targetChunk->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
tile->getChunk(15,15)->getHeightmap()[144].y = this->getChunk(0,0)->getHeightmap()[0].y;
|
||||
tile->registerChunkUpdate(ChunkUpdateFlags::VERTEX);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapTile::setAlphaImage(QImage const& image, unsigned layer)
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
QImage getAlphamapImage(std::string const& filename);
|
||||
QImage getVertexColorsImage();
|
||||
QImage getNormalmapImage();
|
||||
void setHeightmapImage(QImage const& image, float multiplier, int mode);
|
||||
void setHeightmapImage(QImage const& image, float multiplier, int mode, bool tiledEdges);
|
||||
void setAlphaImage(QImage const& image, unsigned layer);
|
||||
void setVertexColorImage(QImage const& image, int mode);
|
||||
void registerChunkUpdate(unsigned flags) { _chunk_update_flags |= flags; };
|
||||
|
||||
@@ -1540,7 +1540,10 @@ void MapView::setupAssistMenu()
|
||||
adt_import_height_params_layout->addWidget(new QLabel("Mode:", adt_import_height_params));
|
||||
QComboBox* adt_import_height_params_mode = new QComboBox(adt_import_height_params);
|
||||
adt_import_height_params_layout->addWidget(adt_import_height_params_mode);
|
||||
adt_import_height_params_mode->addItems({"Set", "Add", "Subtract", "Multiply"});
|
||||
adt_import_height_params_mode->addItems({"Set", "Add", "Subtract", "Multiply" });
|
||||
|
||||
QCheckBox* adt_import_height_tiled_edges = new QCheckBox("Tiled Edges", adt_import_height_params);
|
||||
adt_import_height_params_layout->addWidget(adt_import_height_tiled_edges);
|
||||
|
||||
QPushButton* adt_import_height_params_okay = new QPushButton("Okay", adt_import_height_params);
|
||||
adt_import_height_params_layout->addWidget(adt_import_height_params_okay);
|
||||
@@ -1576,7 +1579,7 @@ void MapView::setupAssistMenu()
|
||||
|
||||
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_TERRAIN);
|
||||
_world->importADTHeightmap(_camera.position, img, adt_import_height_params_multiplier->value(),
|
||||
adt_import_height_params_mode->currentIndex());
|
||||
adt_import_height_params_mode->currentIndex(), adt_import_height_tiled_edges->isChecked());
|
||||
NOGGIT_ACTION_MGR->endAction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1834,22 +1834,23 @@ void World::importADTAlphamap(glm::vec3 const& pos)
|
||||
);
|
||||
}
|
||||
|
||||
void World::importADTHeightmap(glm::vec3 const& pos, QImage const& image, float multiplier, unsigned mode)
|
||||
void World::importADTHeightmap(glm::vec3 const& pos, QImage const& image, float multiplier, unsigned mode, bool tiledEdges)
|
||||
{
|
||||
ZoneScoped;
|
||||
int desired_dimensions = tiledEdges ? 256 : 257;
|
||||
for_all_chunks_on_tile(pos, [](MapChunk* chunk)
|
||||
{
|
||||
NOGGIT_CUR_ACTION->registerChunkTerrainChange(chunk);
|
||||
});
|
||||
|
||||
if (image.width() != 257 || image.height() != 257)
|
||||
if (image.width() != desired_dimensions || image.height() != desired_dimensions)
|
||||
{
|
||||
QImage scaled = image.scaled(257, 257, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||
QImage scaled = image.scaled(desired_dimensions, desired_dimensions, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||
|
||||
for_tile_at ( pos
|
||||
, [&] (MapTile* tile)
|
||||
{
|
||||
tile->setHeightmapImage(scaled, multiplier, mode);
|
||||
tile->setHeightmapImage(scaled, multiplier, mode, tiledEdges);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1859,7 +1860,7 @@ void World::importADTHeightmap(glm::vec3 const& pos, QImage const& image, float
|
||||
for_tile_at ( pos
|
||||
, [&] (MapTile* tile)
|
||||
{
|
||||
tile->setHeightmapImage(image, multiplier, mode);
|
||||
tile->setHeightmapImage(image, multiplier, mode, tiledEdges);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1896,7 +1897,7 @@ void World::importADTHeightmap(glm::vec3 const& pos, float multiplier, unsigned
|
||||
if (img.width() != 257 || img.height() != 257)
|
||||
img = img.scaled(257, 257, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||
|
||||
tile->setHeightmapImage(img, multiplier, mode);
|
||||
tile->setHeightmapImage(img, multiplier, mode, false);
|
||||
|
||||
}
|
||||
);
|
||||
@@ -2839,11 +2840,11 @@ void World::importAllADTsHeightmaps(float multiplier, unsigned int mode)
|
||||
if (img.width() != 257 || img.height() != 257)
|
||||
{
|
||||
QImage scaled = img.scaled(257, 257, Qt::IgnoreAspectRatio);
|
||||
mTile->setHeightmapImage(scaled, multiplier, mode);
|
||||
mTile->setHeightmapImage(scaled, multiplier, mode, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTile->setHeightmapImage(img, multiplier, mode);
|
||||
mTile->setHeightmapImage(img, multiplier, mode, false);
|
||||
}
|
||||
|
||||
mTile->saveTile(this);
|
||||
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
|
||||
void importADTAlphamap(glm::vec3 const& pos, QImage const& image, unsigned layer);
|
||||
void importADTAlphamap(glm::vec3 const& pos);
|
||||
void importADTHeightmap(glm::vec3 const& pos, QImage const& image, float multiplier, unsigned mode);
|
||||
void importADTHeightmap(glm::vec3 const& pos, QImage const& image, float multiplier, unsigned mode, bool tiledEdges);
|
||||
void importADTHeightmap(glm::vec3 const& pos, float multiplier, unsigned mode);
|
||||
void importADTVertexColorMap(glm::vec3 const& pos, int mode);
|
||||
void importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, int mode);
|
||||
|
||||
@@ -59,7 +59,7 @@ void TileSetHeightmapImageNode::compute()
|
||||
return;
|
||||
}
|
||||
|
||||
tile->setHeightmapImage(*image_to_use, static_cast<float>(multiplier), _operation->currentIndex());
|
||||
tile->setHeightmapImage(*image_to_use, static_cast<float>(multiplier), _operation->currentIndex(), false);
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
_node->onDataUpdated(0);
|
||||
|
||||
Reference in New Issue
Block a user