mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-14 17:33:25 +00:00
[mmp_extractor] Fix ue4 z scales and heightmap values. Required Z scale for the map is printed into the info file.
This commit is contained in:
parent
aea765a7b2
commit
ea250f11ea
2 changed files with 31 additions and 17 deletions
|
|
@ -278,13 +278,31 @@ void mmp::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
alpha_maps.erase(0);
|
alpha_maps.erase(0);
|
||||||
scale16 = 0xffff / (h_max - h_min);
|
|
||||||
// 51300 = -25600..25600? or 51200 = -25500..25600
|
// heightmap calculations
|
||||||
// seems like 51300
|
|
||||||
const int unreal_koef = 51300;
|
// https://docs.unrealengine.com/en-US/BuildingWorlds/Landscape/TechnicalGuide/index.html
|
||||||
const int aim_koef = 10;
|
// "Unreal Engine 4 calculates your heightmap's height by using values between -256 to 255.992 and stored with 16 bit precision."
|
||||||
const double diff = h_max - h_min;
|
|
||||||
scale = aim_koef * diff / unreal_koef;
|
const auto _2pow15 = 1 << 15;
|
||||||
|
const auto ue4_zero_level = _2pow15 - 1;
|
||||||
|
|
||||||
|
static const auto min_ue4_heightmap_height_units = 256;
|
||||||
|
static const auto ue4_height_per_i16_tick = float(min_ue4_heightmap_height_units) / _2pow15;
|
||||||
|
static const auto ue4_max_plus_height_level_units = _2pow15 * ue4_height_per_i16_tick;
|
||||||
|
static const auto ue4_max_minus_height_level_units = (_2pow15 - 1) * ue4_height_per_i16_tick;
|
||||||
|
|
||||||
|
bool calc_by_plus = std::fabs(h_max) > std::fabs(h_min);
|
||||||
|
const auto number_of_height_levels = calc_by_plus ? _2pow15 - 1 : _2pow15;
|
||||||
|
const auto ue4_max_height_level_units = calc_by_plus ? ue4_max_plus_height_level_units : ue4_max_minus_height_level_units;
|
||||||
|
|
||||||
|
const auto absmaxheight = std::max(std::fabs(h_max), std::fabs(h_min));
|
||||||
|
this->ue4_z_scale = absmaxheight / ue4_max_height_level_units;
|
||||||
|
|
||||||
|
auto aim_height_to_ue4_heightmap = [&number_of_height_levels](float h, float hmax)
|
||||||
|
{
|
||||||
|
return h * number_of_height_levels / hmax;
|
||||||
|
};
|
||||||
|
|
||||||
// make heightmap
|
// make heightmap
|
||||||
for (auto &s : segments)
|
for (auto &s : segments)
|
||||||
|
|
@ -303,11 +321,9 @@ void mmp::process()
|
||||||
for (int x = 0; x1 < x2; x1++, x++)
|
for (int x = 0; x1 < x2; x1++, x++)
|
||||||
{
|
{
|
||||||
auto height = s.d.Heightmap[y * dx + x];
|
auto height = s.d.Heightmap[y * dx + x];
|
||||||
heightmap32(y1, x1) = height; // dunno what is right
|
//heightmap32(y1, x1) = height; // dunno what is right
|
||||||
heightmap32(y1, x1) = height - h_min; // dunno what is right
|
//heightmap32(y1, x1) = height - h_min; // dunno what is right
|
||||||
auto val = (height - h_min) * scale16 * scale;
|
heightmap(y1, x1) = ue4_zero_level + aim_height_to_ue4_heightmap(height, absmaxheight);
|
||||||
auto &old_height = heightmap(y1, x1);
|
|
||||||
old_height = val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -326,8 +342,7 @@ void mmp::writeFileInfo()
|
||||||
ofile << "h_min: " << h_min << "\n";
|
ofile << "h_min: " << h_min << "\n";
|
||||||
ofile << "h_max: " << h_max << "\n";
|
ofile << "h_max: " << h_max << "\n";
|
||||||
ofile << "h_diff: " << h_max - h_min << "\n";
|
ofile << "h_diff: " << h_max - h_min << "\n";
|
||||||
ofile << "scale16: " << scale16 << "\n";
|
ofile << "ue4_z_scale: " << std::setprecision(10) << ue4_z_scale << "\n";
|
||||||
ofile << "scale: " << scale * 100 << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmp::writeTexturesList()
|
void mmp::writeTexturesList()
|
||||||
|
|
@ -402,7 +417,7 @@ void mmp::writeHeightMap()
|
||||||
cv::imwrite((const char *)to_path_string(path(filename) += ".heightmap16.png").c_str(), toCvMat(heightmap));
|
cv::imwrite((const char *)to_path_string(path(filename) += ".heightmap16.png").c_str(), toCvMat(heightmap));
|
||||||
|
|
||||||
write_hm(".heightmap16.r16", heightmap, sizeof(decltype(heightmap)::type));
|
write_hm(".heightmap16.r16", heightmap, sizeof(decltype(heightmap)::type));
|
||||||
write_hm(".heightmap32.r32", heightmap32, sizeof(decltype(heightmap32)::type));
|
//write_hm(".heightmap32.r32", heightmap32, sizeof(decltype(heightmap32)::type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmp::writeHeightMapSegmented()
|
void mmp::writeHeightMapSegmented()
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,7 @@ struct mmp
|
||||||
std::map<int, std::string> textures_names;
|
std::map<int, std::string> textures_names;
|
||||||
Height h_min = 0;
|
Height h_min = 0;
|
||||||
Height h_max = 0;
|
Height h_max = 0;
|
||||||
double scale16 = 0;
|
double ue4_z_scale = 0;
|
||||||
double scale = 0;
|
|
||||||
mat<uint16_t> heightmap;
|
mat<uint16_t> heightmap;
|
||||||
mat<float> heightmap32;
|
mat<float> heightmap32;
|
||||||
//mat<uint16_t> heightmap_segmented;
|
//mat<uint16_t> heightmap_segmented;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue