Initial attempt on adding sockets to models.

This commit is contained in:
lzwdgc 2017-12-08 02:19:59 +03:00
parent 13529a1a76
commit d3f2b44120
9 changed files with 235 additions and 120 deletions

View file

@ -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)

View file

@ -24,13 +24,12 @@
#include <primitives/filesystem.h>
#include <primitives/executor.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <numeric>
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<std::string, int> 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<std::string, string_index>;
using AimKVResolved = std::unordered_map<std::string, IdType>;
using AimKV = std::map<std::string, string_index>;
using AimKVResolved = std::unordered_map<std::string, polygon4::detail::IdType>;
AimKVResolved kv_resolved;
template <class T>
@ -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<int, IdType> m;
std::map<int, polygon4::detail::IdType> m;
for (auto &s : storage.strings)
m[levenshtein_distance<std::wstring>(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<AimKVResolved::mapped_type, AimKVResolved::key_type> 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<int, std::string> dist;
std::multimap<double, std::string> 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<std::wstring>(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))

View file

@ -22,7 +22,7 @@
#include <Windows.h>
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;

View file

@ -28,15 +28,13 @@
#include <string>
#include <vector>
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<uint32_t, table> tables;
map<uint32_t, field> fields;
std::map<uint32_t, table> tables;
std::map<uint32_t, field> 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<field_value> fields;
std::vector<field_value> 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<value> values;
std::vector<value> values;
void load(const buffer &b);
void open(const path &p);

View file

@ -22,15 +22,15 @@
#include <buffer.h>
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<int,int> idx;
std::map<int,int> 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];

View file

@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define NOMINMAX
#include "mmp.h"
#include <algorithm>
@ -313,4 +315,3 @@ void mmp::writeColorMap()
auto fn = filename + ".colormap.bmp";
write_mat_bmp(fn, colormap);
}

View file

@ -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::map<std::string,
int socket_id = 0;
for (auto &b : model.blocks)
{
if (!b.canPrint())
continue;
auto block_name = name + "/" + b.h.name;
//
if (b.isEngineFx())
{
/*{
FbxNode *sock = FbxNode::Create(parent, std::string("SOCKET_MOD_GL_M1_B_BASE_ue4_00").c_str());
auto m = FbxMesh::Create(pSdkManager, std::string("SOCKET_MOD_GL_M1_B_BASE_ue4_00").c_str());
sock->SetNodeAttribute(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<FbxSurfacePhong>(0);
if (lMaterial == NULL)
if (!lMaterial)
{
FbxString lMaterialName = block_name.c_str();
FbxString lShadingName = "Phong";

View file

@ -39,73 +39,73 @@ const std::string texture_extension = ".TM.bmp";
const map<char, string> 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)

View file

@ -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