Correctly export object angles.

This commit is contained in:
lzwdgc 2017-12-10 04:00:54 +03:00
parent ce1ba32d58
commit eb834c0d44
15 changed files with 136 additions and 112 deletions

View file

@ -4,3 +4,4 @@ local_settings:
- pvt.cppan.demo.eigen: 3 - pvt.cppan.demo.eigen: 3
- pvt.egorpugin.primitives.filesystem: master - pvt.egorpugin.primitives.filesystem: master
- pvt.egorpugin.primitives.executor: master - pvt.egorpugin.primitives.executor: master
- pvt.cppan.demo.unicode.icu.i18n: "*"

View file

@ -41,11 +41,20 @@ file(GLOB mmp_extractor_src "mmp_extractor/*")
add_executable(mmp_extractor ${mmp_extractor_src}) add_executable(mmp_extractor ${mmp_extractor_src})
target_link_libraries(mmp_extractor common) target_link_libraries(mmp_extractor common)
file(GLOB model_src "model/*")
add_library(model ${model_src})
target_link_libraries(model
common
pvt.cppan.demo.unicode.icu.i18n
)
target_include_directories(model PUBLIC model)
if (DEFINED FBX_SDK_ROOT) if (DEFINED FBX_SDK_ROOT)
file(GLOB mod_converter_src "mod_converter/*") file(GLOB mod_converter_src "mod_converter/*")
add_executable(mod_converter ${mod_converter_src}) add_executable(mod_converter ${mod_converter_src})
target_link_libraries(mod_converter target_link_libraries(mod_converter
common common
model
#pvt.cppan.demo.eigen #pvt.cppan.demo.eigen
debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib" debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib"
optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib" optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib"
@ -58,8 +67,8 @@ else()
endif() endif()
file(GLOB mod_reader_src "mod_reader/*") file(GLOB mod_reader_src "mod_reader/*")
add_executable(mod_reader ${mod_reader_src} mod_converter/model.cpp) add_executable(mod_reader ${mod_reader_src})
target_link_libraries(mod_reader common) target_link_libraries(mod_reader model)
file(GLOB mpj_loader_src "mpj_loader/*") file(GLOB mpj_loader_src "mpj_loader/*")
add_executable(mpj_loader ${mpj_loader_src}) add_executable(mpj_loader ${mpj_loader_src})

View file

@ -18,8 +18,12 @@
#include "buffer.h" #include "buffer.h"
#include "common.h"
#include <stdio.h> #include <stdio.h>
#include <Windows.h>
const int build_version = const int build_version =
#include <version.h.in> #include <version.h.in>
; ;
@ -187,3 +191,30 @@ const std::vector<uint8_t> &buffer::buf() const
throw std::logic_error("buffer: not initialized"); throw std::logic_error("buffer: not initialized");
return *buf_; return *buf_;
} }
std::string str2utf8(const std::string &codepage_str, int cp)
{
auto utf16_str = str2utf16(codepage_str, cp);
int utf8_size = WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), nullptr, 0,
nullptr, nullptr);
std::string utf8_str(utf8_size, '\0');
WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), &utf8_str[0], utf8_size,
nullptr, nullptr);
return utf8_str;
}
std::wstring str2utf16(const std::string &codepage_str, int cp)
{
int size;
std::wstring utf16_str;
size = MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(),
codepage_str.length(), nullptr, 0);
utf16_str = std::wstring(size, '\0');
MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(),
codepage_str.length(), &utf16_str[0], size);
return utf16_str;
}

View file

@ -20,21 +20,5 @@
#include <primitives/filesystem.h> #include <primitives/filesystem.h>
template <typename T> std::string str2utf8(const std::string &codepage_str, int cp = 0);
bool replace_all(T &str, const T &from, const T &to) std::wstring str2utf16(const std::string &codepage_str, int cp = 0);
{
bool replaced = false;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != T::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
replaced = true;
}
return replaced;
}
inline bool replace_all(std::string &str, const std::string &from, const std::string &to)
{
return replace_all<std::string>(str, from, to);
}

View file

@ -18,6 +18,8 @@
#include "../db_extractor/db.h" #include "../db_extractor/db.h"
#include <common.h>
#include <Polygon4/DataManager/Localization.h> #include <Polygon4/DataManager/Localization.h>
#include <Polygon4/DataManager/Storage.h> #include <Polygon4/DataManager/Storage.h>
#include <Polygon4/DataManager/Types.h> #include <Polygon4/DataManager/Types.h>

View file

@ -20,8 +20,6 @@
#include <buffer.h> #include <buffer.h>
#include <Windows.h>
std::string getSqlType(FieldType type) std::string getSqlType(FieldType type)
{ {
switch (type) switch (type)
@ -152,30 +150,3 @@ void db::open(const path &p)
for (auto &v : values) for (auto &v : values)
v.load_fields(t, b); v.load_fields(t, b);
} }
std::string str2utf8(const std::string &codepage_str, int cp)
{
auto utf16_str = str2utf16(codepage_str, cp);
int utf8_size = WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), nullptr, 0,
nullptr, nullptr);
std::string utf8_str(utf8_size, '\0');
WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), &utf8_str[0], utf8_size,
nullptr, nullptr);
return utf8_str;
}
std::wstring str2utf16(const std::string &codepage_str, int cp)
{
int size;
std::wstring utf16_str;
size = MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(),
codepage_str.length(), nullptr, 0);
utf16_str = std::wstring(size, '\0');
MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(),
codepage_str.length(), &utf16_str[0], size);
return utf16_str;
}

View file

@ -98,6 +98,3 @@ struct db
void load(const buffer &b); void load(const buffer &b);
void open(const path &p); void open(const path &p);
}; };
std::string str2utf8(const std::string &codepage_str, int cp = 0);
std::wstring str2utf16(const std::string &codepage_str, int cp = 0);

View file

@ -21,6 +21,7 @@
#include <fstream> #include <fstream>
#include <buffer.h> #include <buffer.h>
#include <common.h>
void create_sql(std::string path, const db &db) void create_sql(std::string path, const db &db)
{ {

View file

@ -120,26 +120,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
auto this_map = storage->maps[map_id]; auto this_map = storage->maps[map_id];
auto check_val = [](auto &v) auto calc_yaw = [](auto &v)
{ {
if (v > 1) auto yaw = atan2(v[1].x / v[2].z, v[0].x / v[2].z);
{
v = v - floor(v);
std::cerr << /*object->name2 << */": yaw > 1\n";
}
if (v < -1)
{
v = v - ceil(v);
std::cerr << /*object->name2 << */": yaw < -1\n";
}
};
auto calc_yaw = [&check_val](auto &v)
{
//check_val(v[0].x);
//check_val(v[1].x);
auto yaw = atan2(v[1].x, v[0].x);
yaw = RAD2GRAD(yaw); yaw = RAD2GRAD(yaw);
return -(yaw - 90); return -(yaw - 90);
}; };
@ -148,8 +131,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
int exist = 0; int exist = 0;
for (auto &seg : s.objects.segments) for (auto &seg : s.objects.segments)
{ {
if (seg->segment_type == ObjectType::BUILDING || if (seg->segment_type == ObjectType::BUILDING ||
seg->segment_type == ObjectType::TOWER) seg->segment_type == ObjectType::TOWER ||
0)
{ {
SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg; SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg;
std::set<std::string> objs; std::set<std::string> objs;
@ -175,6 +159,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
{ {
// protect against nans
object->m_rotate_z[2].z = ASSIGN(object->m_rotate_z[2].z, 1);
MapBuilding mb; MapBuilding mb;
mb.text_id = object->name2; mb.text_id = object->name2;
mb.building = storage->buildings[bld_ids[object->name1]]; mb.building = storage->buildings[bld_ids[object->name1]];
@ -184,29 +171,13 @@ void write_mmo(Storage *storage, const mmo_storage &s)
mb.z = ASSIGN(object->position.z, 0); mb.z = ASSIGN(object->position.z, 0);
mb.roll = 0; mb.roll = 0;
mb.pitch = 0; mb.pitch = 0;
/*auto yaw = ASSIGN(object->m_rotate_z[0].x, 0);
if (yaw > 1)
{
yaw = yaw - floor(yaw);
std::cerr << object->name2 << ": yaw > 1\n";
}
if (yaw < -1)
{
yaw = yaw - ceil(yaw);
std::cerr << object->name2 << ": yaw < -1\n";
}
mb.yaw = acos(yaw);
RAD2GRAD(mb.yaw);
// wrong 1
/*if (mb.yaw < 90)
mb.yaw += 90;
else
{
mb.yaw -= 90;
mb.yaw = -mb.yaw;
}*/
mb.yaw = calc_yaw(object->m_rotate_z); mb.yaw = calc_yaw(object->m_rotate_z);
mb.scale = ASSIGN(object->m_rotate_z[2].z, 1); mb.scale = ASSIGN(object->m_rotate_z[2].z, 1);
if (mb.scale != 1)
{
int a = 5;
a++;
}
auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const auto &p) auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const auto &p)
{ {
return *p.second == mb; return *p.second == mb;
@ -228,7 +199,8 @@ void write_mmo(Storage *storage, const mmo_storage &s)
if (seg->segment_type == ObjectType::TREE || if (seg->segment_type == ObjectType::TREE ||
seg->segment_type == ObjectType::STONE || seg->segment_type == ObjectType::STONE ||
seg->segment_type == ObjectType::LAMP || seg->segment_type == ObjectType::LAMP ||
seg->segment_type == ObjectType::BOUNDARY) seg->segment_type == ObjectType::BOUNDARY ||
0)
{ {
SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg; SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg;
std::set<std::string> objs; std::set<std::string> objs;
@ -252,6 +224,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
{ {
// protect against nans
object->m_rotate_z[2].z = ASSIGN(object->m_rotate_z[2].z, 1);
detail::MapObject mb; detail::MapObject mb;
mb.text_id = object->name2; mb.text_id = object->name2;
mb.map = this_map; mb.map = this_map;
@ -261,8 +236,13 @@ void write_mmo(Storage *storage, const mmo_storage &s)
mb.z = ASSIGN(object->position.z, 0); mb.z = ASSIGN(object->position.z, 0);
mb.roll = 0; mb.roll = 0;
mb.pitch = 0; mb.pitch = 0;
mb.yaw = calc_yaw(object->m_rotate_z) - 90; mb.yaw = calc_yaw(object->m_rotate_z);
mb.scale = ASSIGN(object->m_rotate_z[2].z, 1); mb.scale = ASSIGN(object->m_rotate_z[2].z, 1);
if (mb.scale != 1)
{
int a = 5;
a++;
}
auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const auto &p) auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const auto &p)
{ {
return *p.second == mb; return *p.second == mb;

View file

@ -298,7 +298,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
// node // node
FbxNode *node = FbxNode::Create(pScene, block_name.c_str()); FbxNode *node = FbxNode::Create(pScene, block_name.c_str());
node->SetNodeAttribute(m); node->SetNodeAttribute(m);
node->SetShadingMode(FbxNode::eTextureShading); // change?! was texture sh //node->SetShadingMode(FbxNode::eTextureShading); // change?! was texture sh
// vertices // vertices
m->InitControlPoints(b.vertices.size()); m->InitControlPoints(b.vertices.size());

View file

@ -76,7 +76,14 @@ try
if (f.has_extension()) if (f.has_extension())
continue; continue;
std::cout << "processing: " << f << "\n"; std::cout << "processing: " << f << "\n";
convert_model(f); try
{
convert_model(f);
}
catch (std::exception &e)
{
std::cout << "error: " << e.what() << "\n";
}
} }
} }
else else

View file

@ -25,7 +25,7 @@
#include <string> #include <string>
#include <buffer.h> #include <buffer.h>
#include "../mod_converter/model.h" #include <model.h>
#include <primitives/filesystem.h> #include <primitives/filesystem.h>

View file

@ -30,8 +30,30 @@
//#include <Eigen/Core> //#include <Eigen/Core>
//#include <Eigen/Dense> //#include <Eigen/Dense>
#include <unicode/translit.h>
#include <unicode/errorcode.h>
#include <iostream> #include <iostream>
template <typename T>
inline bool replace_all(T &str, const T &from, const T &to)
{
bool replaced = false;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != T::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
replaced = true;
}
return replaced;
}
inline bool replace_all(std::string &str, const std::string &from, const std::string &to)
{
return replace_all<std::string>(str, from, to);
}
using namespace std; using namespace std;
const float scale_mult = 30.0f; const float scale_mult = 30.0f;
@ -116,16 +138,16 @@ std::string version();
// UE does not recognize russian strings in .obj // UE does not recognize russian strings in .obj
string translate(const string &s) string translate(const string &s)
{ {
string o; UErrorCode ec = UErrorCode::U_ZERO_ERROR;
for (auto c : s) auto tr = icu::Transliterator::createInstance("Latin-Cyrillic", UTransDirection::UTRANS_REVERSE, ec);
{ if (!tr || ec)
auto i = transliteration.find(c); throw std::runtime_error("Cannot create translator, ec = " + std::to_string(ec));
if (i == transliteration.end()) icu::UnicodeString s2(s.c_str());
o += c; tr->transliterate(s2);
else string s3;
o += i->second; s2.toUTF8String<std::string>(s3);
} replace_all(s3, " ", "");
return o; return s3;
} }
template <typename T> template <typename T>
@ -438,11 +460,11 @@ void block::loadPayload(const buffer &data)
dm.load(data); dm.load(data);
string s = "extraction error: block #" + std::string(h.name); string s = "extraction error: block #" + std::string(h.name);
if (!data.eof()) /*if (!data.eof())
{ {
cerr << s << "\n"; cerr << s << "\n";
return; return;
} }*/
// unknown how to proceed // unknown how to proceed
if (!data.eof() && triangles_mult_7) if (!data.eof() && triangles_mult_7)

View file

@ -23,6 +23,25 @@
#include <buffer.h> #include <buffer.h>
#include <common.h> #include <common.h>
template <typename T>
inline bool replace_all(T &str, const T &from, const T &to)
{
bool replaced = false;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != T::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
replaced = true;
}
return replaced;
}
inline bool replace_all(std::string &str, const std::string &from, const std::string &to)
{
return replace_all<std::string>(str, from, to);
}
struct script struct script
{ {
uint32_t file_size; uint32_t file_size;
@ -55,7 +74,7 @@ struct script
ss << std::hex << b.index() << " != " << std::hex << b.size(); ss << std::hex << b.index() << " != " << std::hex << b.size();
throw std::logic_error(ss.str()); throw std::logic_error(ss.str());
} }
fix_text(); fix_text();
} }