From d3f2b4412097d6b8c7e8edf8a620de9a66ccd027 Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Fri, 8 Dec 2017 02:19:59 +0300 Subject: [PATCH] Initial attempt on adding sockets to models. --- CMakeLists.txt | 5 +- src/db_add_language/db_add_language.cpp | 76 ++++++++++-- src/db_extractor/db.cpp | 6 +- src/db_extractor/db.h | 14 +-- src/db_extractor/db_extractor.cpp | 26 ++-- src/mmp_extractor/mmp.cpp | 3 +- src/mod_converter/fbx.cpp | 67 ++++++++-- src/mod_converter/model.cpp | 157 +++++++++++++----------- src/mod_converter/model.h | 1 + 9 files changed, 235 insertions(+), 120 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac15596..0260f20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,14 +21,15 @@ find_package(Git) if (MSVC) set(disable_msvc_warnings "/W1 /wd4996") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP ${disable_msvc_warnings}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings} /std:c++17") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++17") endif(MSVC) add_definitions(-DPOLYGON4_TOOLS=1) add_definitions(-DPOLYGON4_STATIC=1) +set(CPPAN_BUILD_SHARED_LIBS 0) add_subdirectory(.cppan) if (Git_FOUND) diff --git a/src/db_add_language/db_add_language.cpp b/src/db_add_language/db_add_language.cpp index 767b687..696433b 100644 --- a/src/db_add_language/db_add_language.cpp +++ b/src/db_add_language/db_add_language.cpp @@ -24,13 +24,12 @@ #include #include +#include #include #include +#include #include -using namespace polygon4; -using namespace polygon4::detail; - // MultiByteToWideChar: https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx // code pages: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx const std::map code_pages @@ -51,7 +50,7 @@ int get_cp(const std::string &cp) struct string_index { std::wstring s; - IdType i = -1; + polygon4::detail::IdType i = -1; void setString(const std::string &rhs, int cp) { @@ -59,8 +58,8 @@ struct string_index } }; -using AimKV = std::unordered_map; -using AimKVResolved = std::unordered_map; +using AimKV = std::map; +using AimKVResolved = std::unordered_map; AimKVResolved kv_resolved; template @@ -137,7 +136,7 @@ AimKV get_kv(const db &db, int cp) return kv; } -AimKVResolved get_kv_resolved(const path &d, const Storage &storage) +AimKVResolved get_kv_resolved(const path &d, const polygon4::Storage &storage) { static const auto fn = "kv.resolved"; @@ -146,7 +145,7 @@ AimKVResolved get_kv_resolved(const path &d, const Storage &storage) { std::ifstream f(fn); std::string s; - IdType i; + polygon4::detail::IdType i; while (f) { f >> std::quoted(s); @@ -174,7 +173,7 @@ AimKVResolved get_kv_resolved(const path &d, const Storage &storage) e.push([&storage, &i, &sz, &kv]() { std::cout << "total kvs: " << ++i << "/" << sz << "\n"; - std::map m; + std::map m; for (auto &s : storage.strings) m[levenshtein_distance(kv.second.s, s.second->string.ru)] = s.first; if (m.empty()) @@ -191,10 +190,19 @@ AimKVResolved get_kv_resolved(const path &d, const Storage &storage) f << std::quoted(kv.first) << " " << kv.second.i << "\n"; } } + + // make unique ids + std::unordered_map u; + for (auto &kv : mres) + u[kv.second] = kv.first; + mres.clear(); + for (auto &kv : u) + mres[kv.second] = kv.first; + return mres; } -void process_lang(Storage &s, const path &p, polygon4::String polygon4::LocalizedString::*field) +void process_lang(polygon4::Storage &s, const path &p, polygon4::String polygon4::LocalizedString::*field) { auto db1 = open(p); auto db2 = open(p / "aim1"); @@ -214,15 +222,38 @@ void process_lang(Storage &s, const path &p, polygon4::String polygon4::Localize get_kv(db2); get_kv(db3); - std::string str; + std::multimap dist; + std::multimap dist2; for (auto &kv : kvm) { + auto i = kv_resolved.find(kv.first); + if (i == kv_resolved.end()) + continue; + auto &sold = s.strings[i->second]->string.*field; + auto d = levenshtein_distance(sold, kv.second.s); + dist.insert({ d, kv.first }); + //if (d == 0) + // continue; + auto len_diff = abs((int)sold.size() - (int)kv.second.s.size()); + auto min_len = (sold.size() + kv.second.s.size()) / 2.0; + //d -= len_diff; + //if (d == 0) + // continue; + dist2.insert({ d / double(min_len), kv.first }); + } + + std::string str; + for (auto &d2 : dist2) + { + auto &kv = *kvm.find(d2.second); auto i = kv_resolved.find(kv.first); if (i == kv_resolved.end()) continue; auto &sold = s.strings[i->second]->string.*field; //sold = kv.second.s; - str += "id: " + std::to_string(i->second) + "\n\n"; + str += "id: " + std::to_string(i->second) + "\n"; + str += "kd: " + std::to_string(d2.first) + "\n"; + str += "key: " + i->first + "\n\n"; str += "old:\n"; str += wstring2string(sold) + "\n"; str += "\n"; @@ -230,6 +261,22 @@ void process_lang(Storage &s, const path &p, polygon4::String polygon4::Localize str += wstring2string(kv.second.s) + "\n"; str += "\n================================================\n\n"; } + /*for (auto &kv : kvm) + { + auto i = kv_resolved.find(kv.first); + if (i == kv_resolved.end()) + continue; + auto &sold = s.strings[i->second]->string.*field; + //sold = kv.second.s; + str += "id: " + std::to_string(i->second) + "\n"; + str += "key: " + i->first + "\n\n"; + str += "old:\n"; + str += wstring2string(sold) + "\n"; + str += "\n"; + str += "new:\n"; + str += wstring2string(kv.second.s) + "\n"; + str += "\n================================================\n\n"; + }*/ write_file(p / (p.filename().string() + "_diff.txt"), str); } @@ -243,10 +290,13 @@ try } path d = argv[2]; - auto storage = initStorage(argv[1]); + auto storage = polygon4::initStorage(argv[1]); storage->load(); kv_resolved = get_kv_resolved(d, *storage.get()); + // to check correctness + process_lang(*storage.get(), d / "ru", &polygon4::LocalizedString::ru); + for (auto &f : boost::make_iterator_range(fs::directory_iterator(d), {})) { if (!fs::is_directory(f)) diff --git a/src/db_extractor/db.cpp b/src/db_extractor/db.cpp index c7971c8..a0ed7bd 100644 --- a/src/db_extractor/db.cpp +++ b/src/db_extractor/db.cpp @@ -22,7 +22,7 @@ #include -string getSqlType(FieldType type) +std::string getSqlType(FieldType type) { switch (type) { @@ -171,10 +171,10 @@ std::wstring str2utf16(const std::string &codepage_str, int cp) int size; std::wstring utf16_str; - size = MultiByteToWideChar(cp, MB_COMPOSITE, codepage_str.c_str(), + size = MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(), codepage_str.length(), nullptr, 0); utf16_str = std::wstring(size, '\0'); - MultiByteToWideChar(cp, MB_COMPOSITE, codepage_str.c_str(), + MultiByteToWideChar(cp, MB_PRECOMPOSED, codepage_str.c_str(), codepage_str.length(), &utf16_str[0], size); return utf16_str; diff --git a/src/db_extractor/db.h b/src/db_extractor/db.h index 7b3fb80..c9e8d86 100644 --- a/src/db_extractor/db.h +++ b/src/db_extractor/db.h @@ -28,15 +28,13 @@ #include #include -using namespace std; - enum class FieldType : uint32_t { String, Integer, Float, }; -string getSqlType(FieldType type); +std::string getSqlType(FieldType type); struct table { @@ -62,8 +60,8 @@ struct tab uint32_t number_of_tables; uint32_t number_of_fields; - map tables; - map fields; + std::map tables; + std::map fields; void load(const buffer &b); }; @@ -75,7 +73,7 @@ struct field_value int i = 0; float f = 0.f; - string s; + std::string s; }; struct value @@ -84,7 +82,7 @@ struct value std::string name; uint32_t offset; uint32_t data_size; - vector fields; + std::vector fields; void load_index(const buffer &b); void load_fields(const tab &tab, buffer &b); @@ -95,7 +93,7 @@ struct db uint32_t number_of_values = 0; tab t; - vector values; + std::vector values; void load(const buffer &b); void open(const path &p); diff --git a/src/db_extractor/db_extractor.cpp b/src/db_extractor/db_extractor.cpp index a424331..7b69cab 100644 --- a/src/db_extractor/db_extractor.cpp +++ b/src/db_extractor/db_extractor.cpp @@ -22,15 +22,15 @@ #include -void create_sql(string path, const db &db) +void create_sql(std::string path, const db &db) { - ofstream ofile(path + ".sql"); + std::ofstream ofile(path + ".sql"); if (!ofile) return; - string master_table_name = "DB_TABLE_LIST"; - const string id = "ID"; - const string row_type = "TEXT_ID"; + std::string master_table_name = "DB_TABLE_LIST"; + const std::string id = "ID"; + const std::string row_type = "TEXT_ID"; // db master table ofile << "drop table if exists " << master_table_name << ";\n"; @@ -45,11 +45,11 @@ void create_sql(string path, const db &db) for (auto &table : db.t.tables) { auto &t = table.second; - string name = str2utf8(t.name); + std::string name = str2utf8(t.name); ofile << "drop table if exists " << name << ";\n"; ofile << "create table \"" << name << "\"\n"; ofile << "(\n"; - string s; + std::string s; s += " \"" + str2utf8(id) + "\" INTEGER,\n"; s += " \"" + str2utf8(row_type) + "\" TEXT,\n"; for (auto &f : db.t.fields) @@ -75,14 +75,14 @@ void create_sql(string path, const db &db) } // db tables - map idx; + std::map idx; for (auto &v : db.values) { auto tbl = db.t.tables.find(v.table_id); if (tbl == db.t.tables.end()) continue; ofile << "insert into \"" << str2utf8(tbl->second.name) << "\" ("; - string s; + std::string s; s += "'" + str2utf8(id) + "', "; s += "'" + str2utf8(row_type) + "', "; for (auto &f : v.fields) @@ -93,7 +93,7 @@ void create_sql(string path, const db &db) s.resize(s.size() - 2); ofile << s << ") values ("; s.clear(); - s += "'" + to_string(idx[v.table_id]++) + "', "; + s += "'" + std::to_string(idx[v.table_id]++) + "', "; s += "'" + str2utf8(v.name) + "', "; for (auto &f : v.fields) { @@ -105,10 +105,10 @@ void create_sql(string path, const db &db) s += str2utf8(f.s.c_str()); break; case FieldType::Integer: - s += to_string(f.i); + s += std::to_string(f.i); break; case FieldType::Float: - s += to_string(f.f); + s += std::to_string(f.f); break; default: assert(false); @@ -125,7 +125,7 @@ try { if (argc != 2) { - cout << "Usage:\n" << argv[0] << " path/to/aim_game/data/db" << "\n" << argv[0] << " path/to/aim_game/data/quest" << "\n"; + std::cout << "Usage:\n" << argv[0] << " path/to/aim_game/data/db" << "\n" << argv[0] << " path/to/aim_game/data/quest" << "\n"; return 1; } path p = argv[1]; diff --git a/src/mmp_extractor/mmp.cpp b/src/mmp_extractor/mmp.cpp index ac1a565..136ffa8 100644 --- a/src/mmp_extractor/mmp.cpp +++ b/src/mmp_extractor/mmp.cpp @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +#define NOMINMAX + #include "mmp.h" #include @@ -313,4 +315,3 @@ void mmp::writeColorMap() auto fn = filename + ".colormap.bmp"; write_mat_bmp(fn, colormap); } - diff --git a/src/mod_converter/fbx.cpp b/src/mod_converter/fbx.cpp index 075bffe..5410ad8 100644 --- a/src/mod_converter/fbx.cpp +++ b/src/mod_converter/fbx.cpp @@ -30,7 +30,7 @@ void InitializeSdkObjects(FbxManager*& pManager, FbxScene*& pScene) pManager->LoadPluginsDirectory(lPath.Buffer()); //Create an FBX scene. This object holds most objects imported/exported from/to files. - pScene = FbxScene::Create(pManager, "My Scene"); + pScene = FbxScene::Create(pManager, "myScene"); if (!pScene) { FBXSDK_printf("Error: Unable to create FBX scene!\n"); @@ -41,12 +41,13 @@ void InitializeSdkObjects(FbxManager*& pManager, FbxScene*& pScene) void DestroySdkObjects(FbxManager* pManager, bool pExitStatus) { //Delete the FBX Manager. All the objects that have been allocated using the FBX Manager and that haven't been explicitly destroyed are also automatically destroyed. - if (pManager) pManager->Destroy(); + if (pManager) + pManager->Destroy(); if (!pExitStatus) FBXSDK_printf("Error: Unable to destroy FBX Manager!\n"); } -bool SaveScene(FbxManager* pManager, FbxDocument* pScene, const char* pFilename, bool pEmbedMedia, bool blender = false) +bool SaveScene(FbxManager* pManager, FbxDocument* pScene, const char* pFilename, bool blender = false) { int lMajor, lMinor, lRevision; bool lStatus = true; @@ -60,13 +61,13 @@ bool SaveScene(FbxManager* pManager, FbxDocument* pScene, const char* pFilename, // Set the export states. By default, the export states are always set to // true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below // shows how to change these states. - IOS_REF.SetBoolProp(EXP_FBX_MATERIAL, true); + /*IOS_REF.SetBoolProp(EXP_FBX_MATERIAL, true); IOS_REF.SetBoolProp(EXP_FBX_TEXTURE, true); IOS_REF.SetBoolProp(EXP_FBX_EMBEDDED, pEmbedMedia); IOS_REF.SetBoolProp(EXP_FBX_SHAPE, true); IOS_REF.SetBoolProp(EXP_FBX_GOBO, true); IOS_REF.SetBoolProp(EXP_FBX_ANIMATION, true); - IOS_REF.SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true); + IOS_REF.SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true);*/ // Initialize the exporter by providing a filename. if (lExporter->Initialize(pFilename, pFileFormat, pManager->GetIOSettings()) == false) @@ -212,9 +213,22 @@ void model::printFbx(const std::string &fn) // Create the scene. CreateScene(*this, fn, lSdkManager, lScene); - SaveScene(lSdkManager, lScene, (fn + "_ue4.fbx").c_str(), true); + SaveScene(lSdkManager, lScene, (fn + "_ue4.fbx").c_str()); if (all_formats) - SaveScene(lSdkManager, lScene, (fn + "_blender.fbx").c_str(), true, true); + SaveScene(lSdkManager, lScene, (fn + "_blender.fbx").c_str(), true); + + // Destroy all objects created by the FBX SDK. + DestroySdkObjects(lSdkManager, true); + + + + // Prepare the FBX SDK. + InitializeSdkObjects(lSdkManager, lScene); + + // Create the scene. + LoadScene(lSdkManager, lScene, "h:\\Games\\Steam\\steamapps\\common\\AIM2\\Data\\tex.pak\\DATA\\TM\\m.fbx"); + + SaveScene(lSdkManager, lScene, (fn + "_ue42.fbx").c_str()); // Destroy all objects created by the FBX SDK. DestroySdkObjects(lSdkManager, true); @@ -226,12 +240,47 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager, static const char* gAmbientElementName = "AmbientUV"; static const char* gSpecularElementName = "SpecularUV"; + //std::mapSetNodeAttribute(m); + sock->SetGeometricTranslation(FbxNode::EPivotSet::eSourcePivot, { 0,0,0,1 }); + pScene->GetRootNode()->AddChild(sock); + }*/ + + { + FbxNode *sock2 = FbxNode::Create(pScene, std::string("SOCKET_MOD_GL_M1_B_BASE_ue4_00").c_str()); + //sock2->SetGeometricTranslation(FbxNode::EPivotSet::eDestinationPivot, { 0,0,1,1 }); + pScene->GetRootNode()->AddChild(sock2); + } + + { + FbxNode *sock2 = FbxNode::Create(pScene, std::string("SOCKET_LOD0_00").c_str()); + //sock2->SetNodeAttribute(nullptr); + sock2->LclTranslation.Set({1,2,3}); + sock2->EvaluateGlobalTransform(); + sock2->EvaluateLocalTransform(); + sock2->AddNodeAttribute(nullptr); + //sock2->SetGeometricTranslation(FbxNode::EPivotSet::eDestinationPivot, { 0,0,1,1 }); + pScene->GetRootNode()->AddChild(sock2); + } + + //pScene->GetRootNode()->AddChild(node); + continue; + } + + //auto block_name = name + "/" + b.h.name; + const auto block_name = b.h.name; // mesh auto m = FbxMesh::Create(pSdkManager, block_name.c_str()); @@ -292,7 +341,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager, // mats auto lMaterial = node->GetSrcObject(0); - if (lMaterial == NULL) + if (!lMaterial) { FbxString lMaterialName = block_name.c_str(); FbxString lShadingName = "Phong"; diff --git a/src/mod_converter/model.cpp b/src/mod_converter/model.cpp index 1c8caab..4d73469 100644 --- a/src/mod_converter/model.cpp +++ b/src/mod_converter/model.cpp @@ -39,73 +39,73 @@ const std::string texture_extension = ".TM.bmp"; const map transliteration = { - { '',"a" }, - { '',"b" }, - { '',"v" }, - { '',"g" }, - { '',"d" }, - { '',"e" }, - { '',"yo" }, - { '',"zh" }, - { '',"z" }, - { '',"i" }, - { '',"y" }, - { '',"k" }, - { '',"l" }, - { '',"m" }, - { '',"n" }, - { '',"o" }, - { '',"p" }, - { '',"r" }, - { '',"s" }, - { '',"t" }, - { '',"u" }, - { '',"f" }, - { '',"kh" }, - { '',"ts" }, - { '',"ch" }, - { '',"sh" }, - { '',"shch" }, - { '',"_" }, - { '',"y" }, - { '',"_" }, - { '',"e" }, - { '',"yu" }, - { '',"ya" }, + { 'а',"a" }, + { 'б',"b" }, + { 'в',"v" }, + { 'г',"g" }, + { 'д',"d" }, + { 'е',"e" }, + { 'ё',"yo" }, + { 'ж',"zh" }, + { 'з',"z" }, + { 'и',"i" }, + { 'й',"y" }, + { 'к',"k" }, + { 'л',"l" }, + { 'м',"m" }, + { 'н',"n" }, + { 'о',"o" }, + { 'п',"p" }, + { 'р',"r" }, + { 'с',"s" }, + { 'т',"t" }, + { 'у',"u" }, + { 'ф',"f" }, + { 'х',"kh" }, + { 'ц',"ts" }, + { 'ч',"ch" }, + { 'ш',"sh" }, + { 'щ',"shch" }, + { 'ъ',"_" }, + { 'ы',"y" }, + { 'ь',"_" }, + { 'э',"e" }, + { 'ю',"yu" }, + { 'я',"ya" }, - { '',"A" }, - { '',"B" }, - { '',"V" }, - { '',"G" }, - { '',"D" }, - { '',"E" }, - { '',"Yo" }, - { '',"Zh" }, - { '',"Z" }, - { '',"I" }, - { '',"Y" }, - { '',"K" }, - { '',"L" }, - { '',"M" }, - { '',"N" }, - { '',"O" }, - { '',"P" }, - { '',"R" }, - { '',"S" }, - { '',"T" }, - { '',"U" }, - { '',"F" }, - { '',"Kh" }, - { '',"Ts" }, - { '',"Ch" }, - { '',"Sh" }, - { '',"Shch" }, - { '',"_" }, - { '',"Y" }, - { '',"_" }, - { '',"E" }, - { '',"Yu" }, - { '',"Ya" }, + { 'А',"A" }, + { 'Б',"B" }, + { 'В',"V" }, + { 'Г',"G" }, + { 'Д',"D" }, + { 'Е',"E" }, + { 'Ё',"Yo" }, + { 'Ж',"Zh" }, + { 'З',"Z" }, + { 'И',"I" }, + { 'Й',"Y" }, + { 'К',"K" }, + { 'Л',"L" }, + { 'М',"M" }, + { 'Н',"N" }, + { 'О',"O" }, + { 'П',"P" }, + { 'Р',"R" }, + { 'С',"S" }, + { 'Т',"T" }, + { 'У',"U" }, + { 'Ф',"F" }, + { 'Х',"Kh" }, + { 'Ц',"Ts" }, + { 'Ч',"Ch" }, + { 'Ш',"Sh" }, + { 'Щ',"Shch" }, + { 'Ъ',"_" }, + { 'Ы',"Y" }, + { 'Ь',"_" }, + { 'Э',"E" }, + { 'Ю',"Yu" }, + { 'Я',"Ya" }, { ' ',"_" }, } @@ -457,15 +457,30 @@ void block::loadPayload(const buffer &data) throw std::logic_error(s); } +bool block::isEngineFx() const +{ + return h.type == BlockType::HelperObject && h.name.find("FIRE") == 0; +} + bool block::canPrint() const { - if (h.type == BlockType::ParticleEmitter) - return false; - if (h.type != BlockType::VisibleObject) - return false; + // block all lods except 0 if (!(h.all_lods == 15 || h.LODs.lod1)) return false; - return true; + + // lods + if (h.type == BlockType::VisibleObject) + return true; + + if (isEngineFx()) + return true; + + // particles + if (h.type == BlockType::ParticleEmitter) + return false; + + // default + return false; } void model::load(const buffer &b) diff --git a/src/mod_converter/model.h b/src/mod_converter/model.h index 590622e..f5833b8 100644 --- a/src/mod_converter/model.h +++ b/src/mod_converter/model.h @@ -254,6 +254,7 @@ struct block std::string printObj(int group_offset, bool rotate_x_90 = false) const; bool canPrint() const; + bool isEngineFx() const; }; struct model