Invert x axis for the left hand ue4 xyz system. Print r32 heightmap.

This commit is contained in:
lzwdgc 2019-03-06 23:01:04 +03:00
parent ea7282f3d1
commit f9c4071b3f
4 changed files with 27 additions and 9 deletions

View file

@ -174,6 +174,7 @@ void mmp::process()
// merge
heightmap = decltype(heightmap)(h.width, h.length);
heightmap32 = decltype(heightmap32)(h.width, h.length);
//heightmap_segmented = decltype(heightmap)(segment::len, h.length);
texmap = decltype(texmap)(h.width, h.length);
texmap_colored = decltype(texmap_colored)(h.width, h.length);
@ -225,7 +226,7 @@ void mmp::process()
alpha_maps.erase(0);
scale16 = 0xffff / (h_max - h_min);
const int unreal_koef = 51300;
const int unreal_koef = 51200; // 51300?
const int aim_koef = 10;
const double diff = h_max - h_min;
scale = aim_koef * diff / unreal_koef;
@ -247,6 +248,8 @@ void mmp::process()
for (int x = 0; x1 < x2; x1++, x++)
{
auto height = s.d.Heightmap[y * dx + x];
heightmap32(y1, x1) = height; // dunno what is right
heightmap32(y1, x1) = height - h_min; // dunno what is right
auto val = (height - h_min) * scale16 * scale;
auto &old_height = heightmap(y1, x1);
old_height = val;
@ -296,13 +299,19 @@ void mmp::writeTexturesList()
void mmp::writeHeightMap()
{
auto fn = filename;
fn += ".heightmap16.r16";
auto f = primitives::filesystem::fopen(fn, "wb");
if (f == nullptr)
return;
fwrite(&heightmap(0, 0), heightmap.size() * sizeof(decltype(heightmap)::type), 1, f);
fclose(f);
auto write_hm = [this](const String &name, const auto &v, auto sz)
{
auto fn = filename;
fn += name;
auto f = primitives::filesystem::fopen(fn, "wb");
if (f == nullptr)
return;
fwrite(&v(0, 0), v.size() * sz, 1, f);
fclose(f);
};
write_hm(".heightmap16.r16", heightmap, sizeof(decltype(heightmap)::type));
write_hm(".heightmap32.r32", heightmap32, sizeof(decltype(heightmap32)::type));
}
void mmp::writeHeightMapSegmented()

View file

@ -180,6 +180,7 @@ struct mmp
double scale16 = 0;
double scale = 0;
mat<uint16_t> heightmap;
mat<float> heightmap32;
//mat<uint16_t> heightmap_segmented;
mat<uint32_t> texmap;
mat<uint32_t> texmap_colored;

View file

@ -81,8 +81,16 @@ template <typename T>
void aim_vector3<T>::load(const buffer &b)
{
READ(b, base::x);
x = -x; // fix ue4 left hand coordinate system
READ(b, base::z);
READ(b, base::y);
/*
// direction will match to m viewer
READ(b, base::y);
READ(b, base::x);
READ(b, base::z);
*/
}
void aim_vector4::load(const buffer &b, uint32_t flags)

2
sw.cpp
View file

@ -68,5 +68,5 @@ void build(Solution &s)
String arch = "x64";
if (s.Settings.TargetOS.Arch == ArchType::x86)
arch = "x86";
mod_converter += sw::LinkLibrary(sdk / ("lib/vs2015/" + arch + "/" + cfg + "/libfbxsdk-md.lib"));
mod_converter += LinkLibrary(sdk / ("lib/vs2015/" + arch + "/" + cfg + "/libfbxsdk-md.lib"));
}