From f9c4071b3fffdefa77ce4f5653bd42ed5c03a7cd Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Wed, 6 Mar 2019 23:01:04 +0300 Subject: [PATCH] Invert x axis for the left hand ue4 xyz system. Print r32 heightmap. --- src/mmp_extractor/mmp.cpp | 25 +++++++++++++++++-------- src/mmp_extractor/mmp.h | 1 + src/model/model.cpp | 8 ++++++++ sw.cpp | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/mmp_extractor/mmp.cpp b/src/mmp_extractor/mmp.cpp index fe65c2b..e3351d9 100644 --- a/src/mmp_extractor/mmp.cpp +++ b/src/mmp_extractor/mmp.cpp @@ -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() diff --git a/src/mmp_extractor/mmp.h b/src/mmp_extractor/mmp.h index 5b7a02e..b62f210 100644 --- a/src/mmp_extractor/mmp.h +++ b/src/mmp_extractor/mmp.h @@ -180,6 +180,7 @@ struct mmp double scale16 = 0; double scale = 0; mat heightmap; + mat heightmap32; //mat heightmap_segmented; mat texmap; mat texmap_colored; diff --git a/src/model/model.cpp b/src/model/model.cpp index 948369d..f187ab3 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -81,8 +81,16 @@ template void aim_vector3::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) diff --git a/sw.cpp b/sw.cpp index 037abdc..fcef4b6 100644 --- a/sw.cpp +++ b/sw.cpp @@ -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")); }