diff --git a/ReflexToQ3/includes/brushdef.cpp b/ReflexToQ3/includes/brushdef.cpp index 721d003..121e74a 100644 --- a/ReflexToQ3/includes/brushdef.cpp +++ b/ReflexToQ3/includes/brushdef.cpp @@ -1,5 +1,7 @@ #include "brushdef.hpp" #include "libraries.h" +#include +#include using namespace std; // e.g GTK Radiant or older level editors. @@ -25,6 +27,41 @@ void brushdef_gtk(std::stringstream &x, const vector &y) { } } +std::string texdef_net(const TPlanePoints &b) { +// Reflex's material files haven't been reversed so there isn't actually a texture file to make use of +#define REFLEX_TEXRES_PLACEHOLDER 64 +#define MIN_PRECISION 6 + float inverse_xscale = 0; + if (b.hscale != 0) { + inverse_xscale = 1 / (b.hscale * REFLEX_TEXRES_PLACEHOLDER); // WIDTH + } + float inverse_yscale = 0; + if (b.vscale != 0) { + inverse_yscale = 1 / (b.vscale * -REFLEX_TEXRES_PLACEHOLDER); // HEIGHT + } + // a lot of reflex's values for rotation are 0.0 or 1.0 + // likely values are stored in radians. + float c = cos(b.rotation); + float s = sin(b.rotation); + + // horizontal values for texture definition + float h1, h2, h3; + h1 = c * inverse_xscale; + h2 = s * inverse_yscale; + h3 = b.hshift / REFLEX_TEXRES_PLACEHOLDER; // WIDTH + + float v1, v2, v3; + v1 = -s * inverse_xscale; + v2 = c * inverse_yscale; + v3 = -b.vshift / -REFLEX_TEXRES_PLACEHOLDER; // HEIGHT + + std::stringstream ss; + ss << std::setprecision(6) + << "( " << h1 << ' ' << h2 << ' ' << h3 << " ) " + << "( " << v1 << ' ' << v2 << ' ' << v3 << " )"; + return ss.str(); +} + // e.g Net Radiant and anything else based on it. void brushdef_net(std::stringstream &x, const vector &y) { if (y.size()) { @@ -37,9 +74,9 @@ void brushdef_net(std::stringstream &x, const vector &y) { x << "( " << z.m_C[X] << " " << z.m_C[Z] << " " << z.m_C[Y] << " ) "; if (z.m_material.length()) { // placeholder values, for now only concerned with geometry - x << " ( ( 0 0 0 ) ( 0 0 0 ) ) " << z.m_material << " 0 0 0" << std::endl; + x << " ( " << texdef_net(z) << " ) " << z.m_material << " 0 0 0" << std::endl; } else { - x << " ( ( 0 0 0 ) ( 0 0 0 ) ) common/caulk 0 0 0" << std::endl; + x << " ( " << texdef_net(z) << " ) common/caulk 0 0 0" << std::endl; } } x << "}" << std::endl; diff --git a/ReflexToQ3/includes/brushdef.hpp b/ReflexToQ3/includes/brushdef.hpp index 699a98e..1345ec4 100644 --- a/ReflexToQ3/includes/brushdef.hpp +++ b/ReflexToQ3/includes/brushdef.hpp @@ -7,6 +7,8 @@ #include "worldspawn.h" #include "planes.h" +std::string texdef_net(const TPlanePoints&); + void brushdef_gtk(std::stringstream&, const std::vector&); void brushdef_net(std::stringstream&, const std::vector&); diff --git a/ReflexToQ3/includes/planes.cpp b/ReflexToQ3/includes/planes.cpp index 87dd031..ddb6a7e 100644 --- a/ReflexToQ3/includes/planes.cpp +++ b/ReflexToQ3/includes/planes.cpp @@ -90,11 +90,15 @@ std::vector GetBrushPlanes(const TBrush& _krBrush) } TPlanePoints PP = GetPlanePoints(Verts.data(), Verts.size()); PP.m_material = krFace.m_Material; - if (!krFace.hex.empty()) { + if (!krFace.hex.empty() && !krFace.m_Material.empty()) { PP.m_material.append("+" + krFace.hex); } + PP.hscale = krFace.m_fXScale; + PP.hshift = krFace.m_fXOffset; + PP.vscale = krFace.m_fYScale; + PP.vshift = krFace.m_fYOffset; + PP.rotation = krFace.m_fRotation; Planes.push_back(PP); } - return(Planes); } diff --git a/ReflexToQ3/includes/planes.h b/ReflexToQ3/includes/planes.h index aee9dc1..0fe3f26 100644 --- a/ReflexToQ3/includes/planes.h +++ b/ReflexToQ3/includes/planes.h @@ -10,6 +10,9 @@ struct TPlanePoints { Eigen::Vector3f m_B; Eigen::Vector3f m_C; std::string m_material; + float hscale, hshift; // horizontal + float vscale, vshift; // vertical + float rotation; }; Eigen::Vector3f get_polygon_normal(const Eigen::Vector3f*, const size_t);