mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Print two variants for ue4 and usual fbx.
This commit is contained in:
parent
91c0463604
commit
26f276ff94
4 changed files with 74 additions and 30 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
local_settings:
|
local_settings:
|
||||||
dependencies:
|
dependencies:
|
||||||
- pvt.lzwdgc.polygon4.data_manager.data_manager: master
|
- pvt.lzwdgc.polygon4.data_manager.data_manager: master
|
||||||
|
- pvt.cppan.demo.eigen: 3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ target_link_libraries(mmp_extractor common)
|
||||||
|
|
||||||
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 common)
|
target_link_libraries(mod_converter
|
||||||
|
common
|
||||||
|
pvt.cppan.demo.eigen
|
||||||
|
)
|
||||||
|
|
||||||
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})
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,13 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
|
|
||||||
|
//#include <Eigen/Core>
|
||||||
|
//#include <Eigen/Dense>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -150,15 +154,36 @@ void vertex::load(const buffer &b, uint32_t flags)
|
||||||
READ(b, texture_coordinates);
|
READ(b, texture_coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string vertex::printVertex() const
|
std::string vertex::printVertex(bool rotate_x_90) const
|
||||||
{
|
{
|
||||||
|
// rotate by 90 grad over Ox axis
|
||||||
|
/*#define M_PI_2 1.57079632679489661923
|
||||||
|
Eigen::Vector3f x;
|
||||||
|
x << -coordinates.x, coordinates.y, -coordinates.z;
|
||||||
|
|
||||||
|
Eigen::AngleAxis<float> rx(M_PI_2, Eigen::Vector3f(1, 0, 0));
|
||||||
|
auto x2 = rx * x;*/
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
s = "v " +
|
if (rotate_x_90)
|
||||||
to_string(-coordinates.x) + " " +
|
{
|
||||||
to_string(coordinates.y) + " " +
|
// that rotation is really equivalent to exchanging y and z and z sign
|
||||||
to_string(-coordinates.z) + " " +
|
s = "v " +
|
||||||
to_string(coordinates.w)
|
to_string(-coordinates.x) + " " +
|
||||||
;
|
to_string(coordinates.z) + " " +
|
||||||
|
to_string(coordinates.y) + " " +
|
||||||
|
to_string(coordinates.w)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s = "v " +
|
||||||
|
to_string(-coordinates.x) + " " +
|
||||||
|
to_string(coordinates.y) + " " +
|
||||||
|
to_string(-coordinates.z) + " " +
|
||||||
|
to_string(coordinates.w)
|
||||||
|
;
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,7 +292,7 @@ std::string block::printMtl() const
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string block::printObj(int group_offset) const
|
std::string block::printObj(int group_offset, bool rotate_x_90) const
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
s += "usemtl " + name + "\n";
|
s += "usemtl " + name + "\n";
|
||||||
|
|
@ -277,7 +302,7 @@ std::string block::printObj(int group_offset) const
|
||||||
s += "\n";
|
s += "\n";
|
||||||
|
|
||||||
for (auto &v : vertices)
|
for (auto &v : vertices)
|
||||||
s += v.printVertex() + "\n";
|
s += v.printVertex(rotate_x_90) + "\n";
|
||||||
s += "\n";
|
s += "\n";
|
||||||
for (auto &v : vertices)
|
for (auto &v : vertices)
|
||||||
s += v.printNormal() + "\n";
|
s += v.printNormal() + "\n";
|
||||||
|
|
@ -390,6 +415,17 @@ void block::load(const buffer &b)
|
||||||
throw std::logic_error(s);
|
throw std::logic_error(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool block::canPrint() const
|
||||||
|
{
|
||||||
|
if (type == BlockType::ParticleEmitter)
|
||||||
|
return false;
|
||||||
|
if (type != BlockType::VisibleObject)
|
||||||
|
return false;
|
||||||
|
if (!(all_lods == 15 || LODs.lod1))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void model::load(const buffer &b)
|
void model::load(const buffer &b)
|
||||||
{
|
{
|
||||||
READ(b, n_blocks);
|
READ(b, n_blocks);
|
||||||
|
|
@ -411,27 +447,29 @@ void model::print(const std::string &fn)
|
||||||
o << "\n";
|
o << "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
auto obj_fn = fn + ".obj";
|
auto print_obj = [&](const auto &n, bool rotate_x_90 = false)
|
||||||
ofstream o(obj_fn);
|
{
|
||||||
title(o);
|
ofstream o(n);
|
||||||
o << "mtllib " + fn + ".mtl\n\n";
|
title(o);
|
||||||
o << "o " << fn << "\n\n";
|
o << "mtllib " + fn + ".mtl\n\n";
|
||||||
|
o << "o " << fn << "\n\n";
|
||||||
|
int n_vert = 0;
|
||||||
|
for (auto &b : blocks)
|
||||||
|
{
|
||||||
|
if (!b.canPrint())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
o << b.printObj(n_vert, rotate_x_90) << "\n";
|
||||||
|
n_vert += b.n_vertex;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto mtl_fn = fn + ".mtl";
|
auto mtl_fn = fn + ".mtl";
|
||||||
ofstream m(mtl_fn);
|
ofstream m(mtl_fn);
|
||||||
title(m);
|
title(m);
|
||||||
|
|
||||||
int n_vert = 0;
|
|
||||||
for (auto &b : blocks)
|
for (auto &b : blocks)
|
||||||
{
|
|
||||||
if (b.type == BlockType::ParticleEmitter)
|
|
||||||
continue;
|
|
||||||
if (b.type != BlockType::VisibleObject)
|
|
||||||
continue;
|
|
||||||
if (!(b.all_lods == 15 || b.LODs.lod1))
|
|
||||||
continue;
|
|
||||||
o << b.printObj(n_vert) << "\n";
|
|
||||||
m << b.printMtl() << "\n";
|
m << b.printMtl() << "\n";
|
||||||
n_vert += b.n_vertex;
|
|
||||||
}
|
print_obj(fn + "_fbx.obj");
|
||||||
|
print_obj(fn + "_ue4.obj", true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class buffer;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
F_USE_W_COORDINATE = 0x4,
|
F_USE_W_COORDINATE = 0x4, // F_USE_QUANTERNION?
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class AdditionalParameter : uint32_t
|
enum class AdditionalParameter : uint32_t
|
||||||
|
|
@ -97,7 +97,7 @@ struct vertex
|
||||||
|
|
||||||
void load(const buffer &b, uint32_t flags);
|
void load(const buffer &b, uint32_t flags);
|
||||||
|
|
||||||
std::string printVertex() const;
|
std::string printVertex(bool rotate_x_90 = false) const;
|
||||||
std::string printNormal() const;
|
std::string printNormal() const;
|
||||||
std::string printTex() const;
|
std::string printTex() const;
|
||||||
};
|
};
|
||||||
|
|
@ -236,7 +236,9 @@ struct block
|
||||||
|
|
||||||
void load(const buffer &b);
|
void load(const buffer &b);
|
||||||
std::string printMtl() const;
|
std::string printMtl() const;
|
||||||
std::string printObj(int group_offset) const;
|
std::string printObj(int group_offset, bool rotate_x_90 = false) const;
|
||||||
|
|
||||||
|
bool canPrint() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct model
|
struct model
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue