Print two variants for ue4 and usual fbx.

This commit is contained in:
lzwdgc 2017-07-27 00:34:21 +03:00
parent 91c0463604
commit 26f276ff94
4 changed files with 74 additions and 30 deletions

View file

@ -1,4 +1,5 @@
local_settings:
dependencies:
- pvt.lzwdgc.polygon4.data_manager.data_manager: master
- pvt.cppan.demo.eigen: 3

View file

@ -23,7 +23,10 @@ target_link_libraries(mmp_extractor common)
file(GLOB mod_converter_src "mod_converter/*")
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/*")
add_executable(mpj_loader ${mpj_loader_src})

View file

@ -23,9 +23,13 @@
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <buffer.h>
//#include <Eigen/Core>
//#include <Eigen/Dense>
#include <iostream>
using namespace std;
@ -150,15 +154,36 @@ void vertex::load(const buffer &b, uint32_t flags)
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;
s = "v " +
to_string(-coordinates.x) + " " +
to_string(coordinates.y) + " " +
to_string(-coordinates.z) + " " +
to_string(coordinates.w)
;
if (rotate_x_90)
{
// that rotation is really equivalent to exchanging y and z and z sign
s = "v " +
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;
}
@ -267,7 +292,7 @@ std::string block::printMtl() const
return s;
}
std::string block::printObj(int group_offset) const
std::string block::printObj(int group_offset, bool rotate_x_90) const
{
string s;
s += "usemtl " + name + "\n";
@ -277,7 +302,7 @@ std::string block::printObj(int group_offset) const
s += "\n";
for (auto &v : vertices)
s += v.printVertex() + "\n";
s += v.printVertex(rotate_x_90) + "\n";
s += "\n";
for (auto &v : vertices)
s += v.printNormal() + "\n";
@ -390,6 +415,17 @@ void block::load(const buffer &b)
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)
{
READ(b, n_blocks);
@ -411,27 +447,29 @@ void model::print(const std::string &fn)
o << "\n";
};
auto obj_fn = fn + ".obj";
ofstream o(obj_fn);
title(o);
o << "mtllib " + fn + ".mtl\n\n";
o << "o " << fn << "\n\n";
auto print_obj = [&](const auto &n, bool rotate_x_90 = false)
{
ofstream o(n);
title(o);
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";
ofstream m(mtl_fn);
title(m);
int n_vert = 0;
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";
n_vert += b.n_vertex;
}
print_obj(fn + "_fbx.obj");
print_obj(fn + "_ue4.obj", true);
}

View file

@ -26,7 +26,7 @@ class buffer;
enum
{
F_USE_W_COORDINATE = 0x4,
F_USE_W_COORDINATE = 0x4, // F_USE_QUANTERNION?
};
enum class AdditionalParameter : uint32_t
@ -97,7 +97,7 @@ struct vertex
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 printTex() const;
};
@ -236,7 +236,9 @@ struct block
void load(const buffer &b);
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