From 00e9f3b50e529ed45d75857fa01bfee14aee0389 Mon Sep 17 00:00:00 2001 From: <> Date: Tue, 11 Apr 2017 08:27:10 -0700 Subject: [PATCH] .map file workable for NetRadiant --- ReflexToQ3/Makefile | 19 ++++++----- ReflexToQ3/includes/brushdef.cpp | 56 ++++++++++++++++++++++++++++++++ ReflexToQ3/includes/brushdef.hpp | 17 ++++++++++ ReflexToQ3/includes/planes.cpp | 28 ---------------- ReflexToQ3/includes/planes.h | 8 ++--- ReflexToQ3/main.cpp | 16 ++++----- 6 files changed, 93 insertions(+), 51 deletions(-) create mode 100644 ReflexToQ3/includes/brushdef.cpp create mode 100644 ReflexToQ3/includes/brushdef.hpp diff --git a/ReflexToQ3/Makefile b/ReflexToQ3/Makefile index 0cd680a..33d992d 100644 --- a/ReflexToQ3/Makefile +++ b/ReflexToQ3/Makefile @@ -5,17 +5,20 @@ CFLAGS=-std=c++11 -I"includes" -I"/usr/include/eigen3" all: v6 v8 -v6: planes.o mapparser.o +v6: planes.o brushdef.o mapparser.o $(CC) $^ main.cpp $(CFLAGS) -o $(EXV6) 2>error6.log -v8: planes.o v8mapparser.o +v8: planes.o brushdef.o v8mapparser.o $(CC) $^ main.cpp $(CFLAGS) -o $(EXV8) 2>error8.log -mapparser.o: - $(CC) -c includes/mapparser.cpp $(CFLAGS) +mapparser.o: includes/mapparser.cpp + $(CC) -c $^ $(CFLAGS) -v8mapparser.o: - $(CC) -c includes/v8mapparser.cpp $(CFLAGS) +v8mapparser.o: includes/v8mapparser.cpp + $(CC) -c $^ $(CFLAGS) -planes.o: - $(CC) -c includes/planes.cpp $(CFLAGS) \ No newline at end of file +brushdef.o: planes.o includes/brushdef.cpp + $(CC) -c $^ $(CFLAGS) + +planes.o: includes/planes.cpp + $(CC) -c $^ $(CFLAGS) diff --git a/ReflexToQ3/includes/brushdef.cpp b/ReflexToQ3/includes/brushdef.cpp new file mode 100644 index 0000000..9c49a48 --- /dev/null +++ b/ReflexToQ3/includes/brushdef.cpp @@ -0,0 +1,56 @@ +#include "brushdef.hpp" + +using namespace std; +// e.g GTK Radiant or older level editors. +void brushdef_gtk(std::stringstream &x, const vector &y) { + if(y.size()) + { + x << "{" << std::endl; + for(const TPlanePoints& krPlane : y) + { + x << "( " << krPlane.m_A[X] << " " << krPlane.m_A[Z] << " " << krPlane.m_A[Y] << " ) "; + x << "( " << krPlane.m_B[X] << " " << krPlane.m_B[Z] << " " << krPlane.m_B[Y] << " ) "; + x << "( " << krPlane.m_C[X] << " " << krPlane.m_C[Z] << " " << krPlane.m_C[Y] << " ) "; + if(krPlane.m_material.length()) + { + x << krPlane.m_material << " 0 0 0 0.500000 0.500000" << std::endl; + } + else + { + x << "common/caulk 0 0 0 0.500000 0.500000" << std::endl; + } + } + x << "}" << std::endl; + } +} + +// e.g Net Radiant and anything else based on it. +void brushdef_net(std::stringstream &x, const vector &y) { + if (y.size()) { + x << "{" << std::endl; + x << "brushDef" << std::endl; + x << "{" << std::endl; + for (const TPlanePoints& z : y) { + x << "( " << z.m_A[X] << " " << z.m_A[Z] << " " << z.m_A[Y] << " ) "; + x << "( " << z.m_B[X] << " " << z.m_B[Z] << " " << z.m_B[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; + } else { + x << " ( ( 0 0 0 ) ( 0 0 0 ) ) common/caulk 0 0 0" << std::endl; + } + } + x << "}" << std::endl; + x << "}" << std::endl; + } +} + +std::string GetBrushString(const TBrush& _krBrush, + void (*f) (std::stringstream &, const vector &)) +{ + std::vector Planes = GetBrushPlanes(_krBrush); + std::stringstream ssOutput; + f(ssOutput, Planes); + return(ssOutput.str()); +} diff --git a/ReflexToQ3/includes/brushdef.hpp b/ReflexToQ3/includes/brushdef.hpp new file mode 100644 index 0000000..699a98e --- /dev/null +++ b/ReflexToQ3/includes/brushdef.hpp @@ -0,0 +1,17 @@ +#ifndef BRUSHDEF_HPP +#define BRUSHDEF_HPP + +#include +#include +#include +#include "worldspawn.h" +#include "planes.h" + +void brushdef_gtk(std::stringstream&, const std::vector&); + +void brushdef_net(std::stringstream&, const std::vector&); + +std::string GetBrushString(const TBrush&, + void (*f) (std::stringstream &, const std::vector &)); + +#endif \ No newline at end of file diff --git a/ReflexToQ3/includes/planes.cpp b/ReflexToQ3/includes/planes.cpp index 96db707..c586af1 100644 --- a/ReflexToQ3/includes/planes.cpp +++ b/ReflexToQ3/includes/planes.cpp @@ -95,31 +95,3 @@ std::vector GetBrushPlanes(const TBrush& _krBrush) return(Planes); } - -std::string GetBrushString(const TBrush& _krBrush) -{ - std::vector Planes = GetBrushPlanes(_krBrush); - std::stringstream ssOutput; - - if(Planes.size()) - { - ssOutput << "{" << std::endl; - for(const TPlanePoints& krPlane : Planes) - { - ssOutput << "( " << krPlane.m_A[X] << " " << krPlane.m_A[Z] << " " << krPlane.m_A[Y] << " ) "; - ssOutput << "( " << krPlane.m_B[X] << " " << krPlane.m_B[Z] << " " << krPlane.m_B[Y] << " ) "; - ssOutput << "( " << krPlane.m_C[X] << " " << krPlane.m_C[Z] << " " << krPlane.m_C[Y] << " ) "; - if(krPlane.m_material.length()) - { - ssOutput << krPlane.m_material << " 0 0 0 0.500000 0.500000" << std::endl; - } - else - { - ssOutput << "common/caulk 0 0 0 0.500000 0.500000" << std::endl; - } - } - ssOutput << "}" << std::endl; - } - - return(ssOutput.str()); -} diff --git a/ReflexToQ3/includes/planes.h b/ReflexToQ3/includes/planes.h index 90fa61b..aee9dc1 100644 --- a/ReflexToQ3/includes/planes.h +++ b/ReflexToQ3/includes/planes.h @@ -1,10 +1,10 @@ +#ifndef __PLANES_H__ +#define __PLANES_H__ + #include "worldspawn.h" #include #include -#ifndef __PLANES_H__ -#define __PLANES_H__ - struct TPlanePoints { Eigen::Vector3f m_A; Eigen::Vector3f m_B; @@ -26,6 +26,4 @@ TPlanePoints GetPlanePoints(const Eigen::Vector3f*, const size_t); std::vector GetBrushPlanes(const TBrush&); -std::string GetBrushString(const TBrush&); - #endif \ No newline at end of file diff --git a/ReflexToQ3/main.cpp b/ReflexToQ3/main.cpp index 39f3af1..b7c6fda 100644 --- a/ReflexToQ3/main.cpp +++ b/ReflexToQ3/main.cpp @@ -7,12 +7,13 @@ #include "libraries.h" // Local Includes #include "mapparser.h" -#include "planes.h" +#include "brushdef.hpp" using namespace std; // .map files for GTKRadiant -bool brushdef_legacy(const TWorldSpawn &x, const char *fn) { - cout << fn << endl; +bool writemap(const TWorldSpawn &x, + const char *fn, + void (*f) (std::stringstream &, const vector &)) { ofstream OutFile; OutFile.open(fn); if(!OutFile.is_open()) @@ -25,18 +26,13 @@ bool brushdef_legacy(const TWorldSpawn &x, const char *fn) { for(const TBrush& krBrush : x.m_Brushes) { - OutFile << GetBrushString(krBrush); + OutFile << GetBrushString(krBrush, f); } OutFile << "}" << std::endl; return true; } -// .map files for NetRadiant -void brushdef(const TWorldSpawn &x, const char *fn) { - -} - int main(const int _kiArgC, const char** _kppcArgv) { // Check we have correct number of parameters @@ -54,7 +50,7 @@ int main(const int _kiArgC, const char** _kppcArgv) } else { - if (brushdef_legacy(Parser.m_WorldSpawn,_kppcArgv[2])) { + if (writemap(Parser.m_WorldSpawn, _kppcArgv[2], &brushdef_net)) { cout << "Successfully exported map." << endl; } else { cout << "Failed to write output file." << endl;