From faf3226a1bff9268eec0cf8de6e554cf1d31e035 Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Tue, 25 Jul 2017 04:23:05 +0300 Subject: [PATCH] Some clarifications. --- cppan.yml | 2 +- src/mod_converter/mod_converter.cpp | 2 +- src/mod_converter/model.cpp | 49 ++++++++++++++++++----------- src/mod_converter/model.h | 31 ++++++++++++------ 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/cppan.yml b/cppan.yml index d5298ac..ad18700 100644 --- a/cppan.yml +++ b/cppan.yml @@ -1,4 +1,4 @@ local_settings: dependencies: - - pvt.lzwdgc.polygon4.data_manager: master + - pvt.lzwdgc.polygon4.data_manager.data_manager: master diff --git a/src/mod_converter/mod_converter.cpp b/src/mod_converter/mod_converter.cpp index ff73fae..4358c7d 100644 --- a/src/mod_converter/mod_converter.cpp +++ b/src/mod_converter/mod_converter.cpp @@ -39,7 +39,7 @@ void print(const block &b, const std::string &fn) { if (b.type == BlockType::ParticleEmitter) return; - + auto obj_fn = fn; if (!printMaxPolygonBlock) obj_fn += string(".") + b.name; diff --git a/src/mod_converter/model.cpp b/src/mod_converter/model.cpp index 6398398..4b2cd54 100644 --- a/src/mod_converter/model.cpp +++ b/src/mod_converter/model.cpp @@ -25,6 +25,8 @@ #include +#include + using namespace std; std::string version(); @@ -77,20 +79,20 @@ std::string vertex::printTex() const void damage_model::load(const buffer &b) { READ(b, n_polygons); - polygons.resize(n_polygons); + model_polygons.resize(n_polygons); READ(b, unk8); READ(b, name); - for (auto &t : polygons) + for (auto &t : model_polygons) READ(b, t); READ(b, unk6); READ(b, flags); READ(b, n_vertex); vertices.resize(n_vertex); READ(b, n_triangles); - triangles.resize(n_triangles); + damage_triangles.resize(n_triangles / 3); for (auto &v : vertices) v.load(b, flags); - for (auto &t : triangles) + for (auto &t : damage_triangles) READ(b, t); } @@ -100,7 +102,7 @@ void animation::load(const buffer &b) READ(b, name); for (auto &s : segments) s.loadHeader(b); - if (segments[0].n) + //if (segments[0].n) for (auto &s : segments) s.loadData(b); } @@ -118,8 +120,8 @@ void animation::segment::loadData(const buffer &b) return; if (unk0) { - triangles.resize(n); - for (auto &t : triangles) + model_polygons.resize(n); + for (auto &t : model_polygons) READ(b, t); } unk2.resize(n); @@ -174,15 +176,17 @@ std::string block::printObj(const std::string &mtl_name) const s += "\n"; if (n_triangles) - for (int i = 0; i <= n_triangles - 3; i += 3) { - auto x = to_string(triangles[i] + 1); - auto y = to_string(triangles[i + 2] + 1); - auto z = to_string(triangles[i + 1] + 1); - x += "/" + x; - y += "/" + y; - z += "/" + z; - s += "f " + x + " " + y + " " + z + "\n"; + for (auto &t : triangles) + { + auto x = to_string(t.x + 1); + auto y = to_string(t.y + 1); + auto z = to_string(t.z + 1); + x += "/" + x; + y += "/" + y; + z += "/" + z; + s += "f " + x + " " + y + " " + z + "\n"; + } } s += "\n"; @@ -200,7 +204,6 @@ void block::load(const buffer &b) READ_STRING(b, tex3); READ_STRING(b, tex4); READ(b, LODs); - READ(b, unk1); READ(b, unk2); READ(b, unk3); READ(b, size); @@ -221,7 +224,7 @@ void block::load(const buffer &b) READ(data, material); // unk - READ(data, unk_flags0); + READ(data, effect); READ(data, unk7); READ(data, unk9); READ(data, unk10); @@ -243,7 +246,7 @@ void block::load(const buffer &b) READ(data, n_triangles); if (triangles_mult_7 && (flags & F_UNK0) && !unk11) n_triangles *= 7; - triangles.resize(n_triangles); + triangles.resize(n_triangles / 3); for (auto &v : vertices) v.load(data, flags); for (auto &t : triangles) @@ -255,6 +258,14 @@ void block::load(const buffer &b) for (auto &dm : damage_models) dm.load(data); + string s = "extraction error: block #" + std::string(name); + if (!data.eof()) + { + cerr << s << "\n"; + return; + } + + // unknown how to proceed if (!data.eof() && triangles_mult_7) { // unknown end of block @@ -264,7 +275,7 @@ void block::load(const buffer &b) READ(data, t); } if (!data.eof()) - throw std::logic_error("extraction error: block #" + std::string(name)); + throw std::logic_error(s); } void model::load(const buffer &b) diff --git a/src/mod_converter/model.h b/src/mod_converter/model.h index c6b5753..c8df78e 100644 --- a/src/mod_converter/model.h +++ b/src/mod_converter/model.h @@ -52,6 +52,15 @@ enum class BlockType : uint32_t ParticleEmitter }; +enum class EffectType : uint32_t +{ + Texture = 0x0, + TextureWithGlareMap = 0x1, + TextureWithGlareMapAndMask = 0x32, + AlphaTextureDoubleSided = 0x6, + MaterialOnly = 0x14, +}; + struct Vector4 { float x; @@ -84,7 +93,12 @@ struct vertex std::string printTex() const; }; -typedef uint16_t triangle; +struct triangle +{ + uint16_t x; + uint16_t y; + uint16_t z; +}; struct animation { @@ -100,7 +114,7 @@ struct animation uint32_t unk0; uint32_t unk1; - std::vector triangles; + std::vector model_polygons; std::vector unk2; void loadHeader(const buffer &b); @@ -119,21 +133,21 @@ struct damage_model uint32_t n_polygons; float unk8[3]; char name[0x3C]; - std::vector polygons; + std::vector model_polygons; uint8_t unk6; uint32_t flags; uint32_t n_vertex; uint32_t n_triangles; std::vector vertices; - std::vector triangles; + std::vector damage_triangles; virtual void load(const buffer &b); }; struct material { - Vector4 ambient; Vector4 diffuse; + Vector4 ambient; Vector4 specular; Vector4 emissive; float power; @@ -176,8 +190,7 @@ struct block } _; uint32_t LODs; }; - uint32_t unk1; - uint32_t unk2[2]; + uint32_t unk2[3]; uint32_t unk3; uint32_t size; uint32_t unk4[10]; @@ -187,7 +200,7 @@ struct block material material; //unk (anim + transform settings?) - uint32_t unk_flags0; + EffectType effect; uint32_t unk7; float unk9; uint32_t unk10; @@ -206,7 +219,7 @@ struct block uint32_t n_vertex; uint32_t n_triangles; std::vector vertices; - std::vector triangles; + std::vector triangles; // animations std::vector animations;