-properly export missing texture from chunk as black instead of white

-separate implementation of layer 0 and missing texture
-properly export layer 0 as (255-sum(MCAL[1]...MCAL[3]) ) instead of full white chunks
This commit is contained in:
T1ti
2023-01-21 22:20:13 +01:00
parent 9adc98b3a7
commit 6ec6fdf093

View File

@@ -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;
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,14 +1191,31 @@ 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)
{
int value = alpha_layer.getAlpha(64 * l + k);
image.setPixelColor((i * 64) + k, (j * 64) + l, QColor(value, value, value, 255));
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));
}
}
}
}