mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Add print info to mod converter.
This commit is contained in:
parent
e7db9bc5c1
commit
ea7282f3d1
14 changed files with 128 additions and 10 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include <primitives/executor.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <buffer.h>
|
||||
#include <types.h>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#define IOS_REF (*(pManager->GetIOSettings()))
|
||||
#endif
|
||||
|
||||
bool CreateScene(model &m, const std::string &name, FbxManager* pSdkManager, FbxScene* pScene);
|
||||
bool CreateScene(const model &m, const std::string &name, FbxManager* pSdkManager, FbxScene* pScene);
|
||||
|
||||
void InitializeSdkObjects(FbxManager*& pManager, FbxScene*& pScene)
|
||||
{
|
||||
|
|
@ -202,7 +202,7 @@ bool LoadScene(FbxManager* pManager, FbxDocument* pScene, const char* pFilename)
|
|||
return lStatus;
|
||||
}
|
||||
|
||||
void model::printFbx(const std::string &fn)
|
||||
void model::printFbx(const std::string &fn) const
|
||||
{
|
||||
FbxManager* lSdkManager = NULL;
|
||||
FbxScene* lScene = NULL;
|
||||
|
|
@ -221,7 +221,7 @@ void model::printFbx(const std::string &fn)
|
|||
DestroySdkObjects(lSdkManager, true);
|
||||
}
|
||||
|
||||
bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager, FbxScene* pScene)
|
||||
bool CreateScene(const model &model, const std::string &name, FbxManager* pSdkManager, FbxScene* pScene)
|
||||
{
|
||||
static const char* gDiffuseElementName = "DiffuseUV";
|
||||
static const char* gAmbientElementName = "AmbientUV";
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
#include <primitives/yaml.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
|
@ -37,9 +39,13 @@ using namespace std;
|
|||
// options
|
||||
bool silent = false;
|
||||
bool printMaxPolygonBlock = false;
|
||||
|
||||
cl::opt<path> p(cl::Positional, cl::desc("<MOD_ file or directory with MOD_ files>"), cl::value_desc("file or directory"), cl::Required);
|
||||
|
||||
void convert_model(const path &fn)
|
||||
yaml root;
|
||||
cl::opt<bool> stats("i", cl::desc("Gather information from (models)"));
|
||||
|
||||
auto read_model(const path &fn)
|
||||
{
|
||||
buffer b(read_file(fn));
|
||||
model m;
|
||||
|
|
@ -52,12 +58,30 @@ void convert_model(const path &fn)
|
|||
throw std::logic_error(ss.str());
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void convert_model(const model &m, const path &fn)
|
||||
{
|
||||
// write all
|
||||
if (all_formats)
|
||||
m.print(fn.string());
|
||||
m.printFbx(fn.string());
|
||||
}
|
||||
|
||||
void convert_model(const path &fn)
|
||||
{
|
||||
auto m = read_model(fn);
|
||||
|
||||
if (stats)
|
||||
{
|
||||
m.save(root[fn.filename().string()]);
|
||||
return;
|
||||
}
|
||||
|
||||
convert_model(m, fn);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
cl::opt<bool> af("a", cl::desc("All formats"));
|
||||
|
|
@ -75,7 +99,7 @@ int main(int argc, char *argv[])
|
|||
else if (fs::is_directory(p))
|
||||
{
|
||||
auto files = enumerate_files(p, false);
|
||||
for (auto &f : files)
|
||||
for (auto &f : FilesSorted(files.begin(), files.end()))
|
||||
{
|
||||
if (f.has_extension())
|
||||
continue;
|
||||
|
|
@ -92,5 +116,11 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else
|
||||
throw std::runtime_error("Bad fs object");
|
||||
|
||||
if (stats)
|
||||
{
|
||||
write_file((fs::is_regular_file(p) ? path(p) += ".txt" : (p / "model_information.yml")) , YAML::Dump(root));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
|
|
|||
|
|
@ -511,6 +511,44 @@ bool block::canPrint() const
|
|||
return false;
|
||||
}
|
||||
|
||||
block::block_info block::save(yaml &root) const
|
||||
{
|
||||
aim_vector4 min{ 1e6, 1e6, 1e6, 1e6 }, max{ -1e6, -1e6, -1e6, -1e6 };
|
||||
for (auto &v : vertices)
|
||||
{
|
||||
auto mm = [&v](auto &m, auto f)
|
||||
{
|
||||
m.x = f(m.x, v.coordinates.x);
|
||||
m.y = f(m.y, v.coordinates.y);
|
||||
m.z = f(m.z, v.coordinates.z);
|
||||
};
|
||||
|
||||
mm(min, [](auto x, auto y) {return std::min(x,y); });
|
||||
mm(max, [](auto x, auto y) {return std::max(x,y); });
|
||||
}
|
||||
|
||||
root["xlen"] = max.x - min.x;
|
||||
root["ylen"] = max.y - min.y;
|
||||
root["zlen"] = max.z - min.z;
|
||||
|
||||
// convex hull length
|
||||
/*float len = 0;
|
||||
for (auto &v1 : vertices)
|
||||
{
|
||||
for (auto &v2 : vertices)
|
||||
{
|
||||
len = std::max(len, sqrt(
|
||||
pow(v2.coordinates.x - v1.coordinates.x, 2) +
|
||||
pow(v2.coordinates.y - v1.coordinates.y, 2) +
|
||||
pow(v2.coordinates.z - v1.coordinates.z, 2)
|
||||
));
|
||||
}
|
||||
}
|
||||
root["len"] = len;*/
|
||||
|
||||
return {min,max};
|
||||
}
|
||||
|
||||
void model::load(const buffer &b)
|
||||
{
|
||||
int n_blocks;
|
||||
|
|
@ -524,7 +562,7 @@ void model::load(const buffer &b)
|
|||
f.load(b);
|
||||
}
|
||||
|
||||
void model::print(const std::string &fn)
|
||||
void model::print(const std::string &fn) const
|
||||
{
|
||||
auto title = [](auto &o)
|
||||
{
|
||||
|
|
@ -560,3 +598,31 @@ void model::print(const std::string &fn)
|
|||
print_obj(fn + "_fbx.obj");
|
||||
print_obj(fn + "_ue4.obj", true);
|
||||
}
|
||||
|
||||
void model::save(yaml &root) const
|
||||
{
|
||||
aim_vector4 min{ 1e6, 1e6, 1e6, 1e6 }, max{ -1e6, -1e6, -1e6, -1e6 };
|
||||
|
||||
for (auto &b : blocks)
|
||||
{
|
||||
if (!b.canPrint())
|
||||
continue;
|
||||
|
||||
auto [bmin, bmax] = b.save(root["lods"][b.h.name]);
|
||||
|
||||
auto mm = [](auto &v, auto &m, auto f)
|
||||
{
|
||||
m.x = f(m.x, v.x);
|
||||
m.y = f(m.y, v.y);
|
||||
m.z = f(m.z, v.z);
|
||||
};
|
||||
|
||||
mm(bmin, min, [](auto x, auto y) {return std::min(x,y); });
|
||||
mm(bmax, max, [](auto x, auto y) {return std::max(x,y); });
|
||||
}
|
||||
|
||||
root["full"]["xlen"] = max.x - min.x;
|
||||
root["full"]["ylen"] = max.y - min.y;
|
||||
root["full"]["zlen"] = max.z - min.z;
|
||||
//root["full"]["len"] = sqrt(pow(max.x - min.x, 2) + pow(max.y - min.y, 2) + pow(max.z - min.z, 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
#include <primitives/yaml.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
@ -236,6 +238,13 @@ struct block
|
|||
void load(const buffer &b);
|
||||
};
|
||||
|
||||
// for save
|
||||
struct block_info
|
||||
{
|
||||
aim_vector4 min;
|
||||
aim_vector4 max;
|
||||
};
|
||||
|
||||
header h;
|
||||
|
||||
// data
|
||||
|
|
@ -268,8 +277,10 @@ struct block
|
|||
|
||||
void load(const buffer &b);
|
||||
void loadPayload(const buffer &b);
|
||||
|
||||
std::string printMtl() const;
|
||||
std::string printObj(int group_offset, bool rotate_x_90 = false) const;
|
||||
block_info save(yaml &root) const;
|
||||
|
||||
bool canPrint() const;
|
||||
bool isEngineFx() const;
|
||||
|
|
@ -280,6 +291,8 @@ struct model
|
|||
std::vector<block> blocks;
|
||||
|
||||
void load(const buffer &b);
|
||||
void print(const std::string &fn);
|
||||
void printFbx(const std::string &fn);
|
||||
|
||||
void print(const std::string &fn) const;
|
||||
void printFbx(const std::string &fn) const;
|
||||
void save(yaml &root) const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <primitives/filesystem.h>
|
||||
#include <primitives/sw/main.h>
|
||||
#include <primitives/sw/settings.h>
|
||||
#include <primitives/sw/cl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
|
|
|||
4
sw.cpp
4
sw.cpp
|
|
@ -3,7 +3,7 @@
|
|||
void build(Solution &s)
|
||||
{
|
||||
auto &tools = s.addProject("Polygon4.Tools", "master");
|
||||
DataManager += Git("https://github.com/aimrebirth/tools", "", "{v}");
|
||||
tools += Git("https://github.com/aimrebirth/tools", "", "{v}");
|
||||
|
||||
auto &common = tools.addStaticLibrary("common");
|
||||
common.CPPVersion = CPPLanguageStandard::CPP17;
|
||||
|
|
@ -68,5 +68,5 @@ void build(Solution &s)
|
|||
String arch = "x64";
|
||||
if (s.Settings.TargetOS.Arch == ArchType::x86)
|
||||
arch = "x86";
|
||||
mod_converter += LinkLibrary(sdk / ("lib/vs2015/" + arch + "/" + cfg + "/libfbxsdk-md.lib"));
|
||||
mod_converter += sw::LinkLibrary(sdk / ("lib/vs2015/" + arch + "/" + cfg + "/libfbxsdk-md.lib"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue