mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Correctly export object angles.
This commit is contained in:
parent
ce1ba32d58
commit
eb834c0d44
15 changed files with 136 additions and 112 deletions
|
|
@ -4,3 +4,4 @@ local_settings:
|
|||
- pvt.cppan.demo.eigen: 3
|
||||
- pvt.egorpugin.primitives.filesystem: master
|
||||
- pvt.egorpugin.primitives.executor: master
|
||||
- pvt.cppan.demo.unicode.icu.i18n: "*"
|
||||
|
|
|
|||
|
|
@ -41,11 +41,20 @@ file(GLOB mmp_extractor_src "mmp_extractor/*")
|
|||
add_executable(mmp_extractor ${mmp_extractor_src})
|
||||
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)
|
||||
file(GLOB mod_converter_src "mod_converter/*")
|
||||
add_executable(mod_converter ${mod_converter_src})
|
||||
target_link_libraries(mod_converter
|
||||
common
|
||||
model
|
||||
#pvt.cppan.demo.eigen
|
||||
debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib"
|
||||
optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib"
|
||||
|
|
@ -58,8 +67,8 @@ else()
|
|||
endif()
|
||||
|
||||
file(GLOB mod_reader_src "mod_reader/*")
|
||||
add_executable(mod_reader ${mod_reader_src} mod_converter/model.cpp)
|
||||
target_link_libraries(mod_reader common)
|
||||
add_executable(mod_reader ${mod_reader_src})
|
||||
target_link_libraries(mod_reader model)
|
||||
|
||||
file(GLOB mpj_loader_src "mpj_loader/*")
|
||||
add_executable(mpj_loader ${mpj_loader_src})
|
||||
|
|
|
|||
|
|
@ -18,8 +18,12 @@
|
|||
|
||||
#include "buffer.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
const int build_version =
|
||||
#include <version.h.in>
|
||||
;
|
||||
|
|
@ -187,3 +191,30 @@ const std::vector<uint8_t> &buffer::buf() const
|
|||
throw std::logic_error("buffer: not initialized");
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,21 +20,5 @@
|
|||
|
||||
#include <primitives/filesystem.h>
|
||||
|
||||
template <typename T>
|
||||
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);
|
||||
}
|
||||
std::string str2utf8(const std::string &codepage_str, int cp = 0);
|
||||
std::wstring str2utf16(const std::string &codepage_str, int cp = 0);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "../db_extractor/db.h"
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#include <Polygon4/DataManager/Localization.h>
|
||||
#include <Polygon4/DataManager/Storage.h>
|
||||
#include <Polygon4/DataManager/Types.h>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include <buffer.h>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
std::string getSqlType(FieldType type)
|
||||
{
|
||||
switch (type)
|
||||
|
|
@ -152,30 +150,3 @@ void db::open(const path &p)
|
|||
for (auto &v : values)
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,3 @@ struct db
|
|||
void load(const buffer &b);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include <fstream>
|
||||
|
||||
#include <buffer.h>
|
||||
#include <common.h>
|
||||
|
||||
void create_sql(std::string path, const db &db)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -120,26 +120,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
|
|||
|
||||
auto this_map = storage->maps[map_id];
|
||||
|
||||
auto check_val = [](auto &v)
|
||||
auto calc_yaw = [](auto &v)
|
||||
{
|
||||
if (v > 1)
|
||||
{
|
||||
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);
|
||||
auto yaw = atan2(v[1].x / v[2].z, v[0].x / v[2].z);
|
||||
yaw = RAD2GRAD(yaw);
|
||||
return -(yaw - 90);
|
||||
};
|
||||
|
|
@ -148,8 +131,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
|
|||
int exist = 0;
|
||||
for (auto &seg : s.objects.segments)
|
||||
{
|
||||
if (seg->segment_type == ObjectType::BUILDING ||
|
||||
seg->segment_type == ObjectType::TOWER)
|
||||
if (seg->segment_type == ObjectType::BUILDING ||
|
||||
seg->segment_type == ObjectType::TOWER ||
|
||||
0)
|
||||
{
|
||||
SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg;
|
||||
std::set<std::string> objs;
|
||||
|
|
@ -175,6 +159,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
|
|||
}
|
||||
for (auto &object : segment->objects)
|
||||
{
|
||||
// protect against nans
|
||||
object->m_rotate_z[2].z = ASSIGN(object->m_rotate_z[2].z, 1);
|
||||
|
||||
MapBuilding mb;
|
||||
mb.text_id = object->name2;
|
||||
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.roll = 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.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)
|
||||
{
|
||||
return *p.second == mb;
|
||||
|
|
@ -228,7 +199,8 @@ void write_mmo(Storage *storage, const mmo_storage &s)
|
|||
if (seg->segment_type == ObjectType::TREE ||
|
||||
seg->segment_type == ObjectType::STONE ||
|
||||
seg->segment_type == ObjectType::LAMP ||
|
||||
seg->segment_type == ObjectType::BOUNDARY)
|
||||
seg->segment_type == ObjectType::BOUNDARY ||
|
||||
0)
|
||||
{
|
||||
SegmentObjects<::MapObject> *segment = (SegmentObjects<::MapObject> *)seg;
|
||||
std::set<std::string> objs;
|
||||
|
|
@ -252,6 +224,9 @@ void write_mmo(Storage *storage, const mmo_storage &s)
|
|||
}
|
||||
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;
|
||||
mb.text_id = object->name2;
|
||||
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.roll = 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);
|
||||
if (mb.scale != 1)
|
||||
{
|
||||
int a = 5;
|
||||
a++;
|
||||
}
|
||||
auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const auto &p)
|
||||
{
|
||||
return *p.second == mb;
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
|
|||
// node
|
||||
FbxNode *node = FbxNode::Create(pScene, block_name.c_str());
|
||||
node->SetNodeAttribute(m);
|
||||
node->SetShadingMode(FbxNode::eTextureShading); // change?! was texture sh
|
||||
//node->SetShadingMode(FbxNode::eTextureShading); // change?! was texture sh
|
||||
|
||||
// vertices
|
||||
m->InitControlPoints(b.vertices.size());
|
||||
|
|
|
|||
|
|
@ -76,7 +76,14 @@ try
|
|||
if (f.has_extension())
|
||||
continue;
|
||||
std::cout << "processing: " << f << "\n";
|
||||
convert_model(f);
|
||||
try
|
||||
{
|
||||
convert_model(f);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
std::cout << "error: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <string>
|
||||
|
||||
#include <buffer.h>
|
||||
#include "../mod_converter/model.h"
|
||||
#include <model.h>
|
||||
|
||||
#include <primitives/filesystem.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,30 @@
|
|||
//#include <Eigen/Core>
|
||||
//#include <Eigen/Dense>
|
||||
|
||||
#include <unicode/translit.h>
|
||||
#include <unicode/errorcode.h>
|
||||
|
||||
#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;
|
||||
|
||||
const float scale_mult = 30.0f;
|
||||
|
|
@ -116,16 +138,16 @@ std::string version();
|
|||
// UE does not recognize russian strings in .obj
|
||||
string translate(const string &s)
|
||||
{
|
||||
string o;
|
||||
for (auto c : s)
|
||||
{
|
||||
auto i = transliteration.find(c);
|
||||
if (i == transliteration.end())
|
||||
o += c;
|
||||
else
|
||||
o += i->second;
|
||||
}
|
||||
return o;
|
||||
UErrorCode ec = UErrorCode::U_ZERO_ERROR;
|
||||
auto tr = icu::Transliterator::createInstance("Latin-Cyrillic", UTransDirection::UTRANS_REVERSE, ec);
|
||||
if (!tr || ec)
|
||||
throw std::runtime_error("Cannot create translator, ec = " + std::to_string(ec));
|
||||
icu::UnicodeString s2(s.c_str());
|
||||
tr->transliterate(s2);
|
||||
string s3;
|
||||
s2.toUTF8String<std::string>(s3);
|
||||
replace_all(s3, " ", "");
|
||||
return s3;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -438,11 +460,11 @@ void block::loadPayload(const buffer &data)
|
|||
dm.load(data);
|
||||
|
||||
string s = "extraction error: block #" + std::string(h.name);
|
||||
if (!data.eof())
|
||||
/*if (!data.eof())
|
||||
{
|
||||
cerr << s << "\n";
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
// unknown how to proceed
|
||||
if (!data.eof() && triangles_mult_7)
|
||||
|
|
@ -23,6 +23,25 @@
|
|||
#include <buffer.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
|
||||
{
|
||||
uint32_t file_size;
|
||||
|
|
@ -55,7 +74,7 @@ struct script
|
|||
ss << std::hex << b.index() << " != " << std::hex << b.size();
|
||||
throw std::logic_error(ss.str());
|
||||
}
|
||||
|
||||
|
||||
fix_text();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue