.map file workable for NetRadiant

This commit is contained in:
2017-04-11 08:27:10 -07:00
parent 697cce13ef
commit 00e9f3b50e
6 changed files with 93 additions and 51 deletions

View File

@ -5,17 +5,20 @@ CFLAGS=-std=c++11 -I"includes" -I"/usr/include/eigen3"
all: v6 v8 all: v6 v8
v6: planes.o mapparser.o v6: planes.o brushdef.o mapparser.o
$(CC) $^ main.cpp $(CFLAGS) -o $(EXV6) 2>error6.log $(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 $(CC) $^ main.cpp $(CFLAGS) -o $(EXV8) 2>error8.log
mapparser.o: mapparser.o: includes/mapparser.cpp
$(CC) -c includes/mapparser.cpp $(CFLAGS) $(CC) -c $^ $(CFLAGS)
v8mapparser.o: v8mapparser.o: includes/v8mapparser.cpp
$(CC) -c includes/v8mapparser.cpp $(CFLAGS) $(CC) -c $^ $(CFLAGS)
planes.o: brushdef.o: planes.o includes/brushdef.cpp
$(CC) -c includes/planes.cpp $(CFLAGS) $(CC) -c $^ $(CFLAGS)
planes.o: includes/planes.cpp
$(CC) -c $^ $(CFLAGS)

View File

@ -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<TPlanePoints> &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<TPlanePoints> &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<TPlanePoints> &))
{
std::vector<TPlanePoints> Planes = GetBrushPlanes(_krBrush);
std::stringstream ssOutput;
f(ssOutput, Planes);
return(ssOutput.str());
}

View File

@ -0,0 +1,17 @@
#ifndef BRUSHDEF_HPP
#define BRUSHDEF_HPP
#include <string>
#include <vector>
#include <sstream>
#include "worldspawn.h"
#include "planes.h"
void brushdef_gtk(std::stringstream&, const std::vector<TPlanePoints>&);
void brushdef_net(std::stringstream&, const std::vector<TPlanePoints>&);
std::string GetBrushString(const TBrush&,
void (*f) (std::stringstream &, const std::vector<TPlanePoints> &));
#endif

View File

@ -95,31 +95,3 @@ std::vector<TPlanePoints> GetBrushPlanes(const TBrush& _krBrush)
return(Planes); return(Planes);
} }
std::string GetBrushString(const TBrush& _krBrush)
{
std::vector<TPlanePoints> 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());
}

View File

@ -1,10 +1,10 @@
#ifndef __PLANES_H__
#define __PLANES_H__
#include "worldspawn.h" #include "worldspawn.h"
#include <Eigen/Core> #include <Eigen/Core>
#include <Eigen/Geometry> #include <Eigen/Geometry>
#ifndef __PLANES_H__
#define __PLANES_H__
struct TPlanePoints { struct TPlanePoints {
Eigen::Vector3f m_A; Eigen::Vector3f m_A;
Eigen::Vector3f m_B; Eigen::Vector3f m_B;
@ -26,6 +26,4 @@ TPlanePoints GetPlanePoints(const Eigen::Vector3f*, const size_t);
std::vector<TPlanePoints> GetBrushPlanes(const TBrush&); std::vector<TPlanePoints> GetBrushPlanes(const TBrush&);
std::string GetBrushString(const TBrush&);
#endif #endif

View File

@ -7,12 +7,13 @@
#include "libraries.h" #include "libraries.h"
// Local Includes // Local Includes
#include "mapparser.h" #include "mapparser.h"
#include "planes.h" #include "brushdef.hpp"
using namespace std; using namespace std;
// .map files for GTKRadiant // .map files for GTKRadiant
bool brushdef_legacy(const TWorldSpawn &x, const char *fn) { bool writemap(const TWorldSpawn &x,
cout << fn << endl; const char *fn,
void (*f) (std::stringstream &, const vector<TPlanePoints> &)) {
ofstream OutFile; ofstream OutFile;
OutFile.open(fn); OutFile.open(fn);
if(!OutFile.is_open()) if(!OutFile.is_open())
@ -25,18 +26,13 @@ bool brushdef_legacy(const TWorldSpawn &x, const char *fn) {
for(const TBrush& krBrush : x.m_Brushes) for(const TBrush& krBrush : x.m_Brushes)
{ {
OutFile << GetBrushString(krBrush); OutFile << GetBrushString(krBrush, f);
} }
OutFile << "}" << std::endl; OutFile << "}" << std::endl;
return true; return true;
} }
// .map files for NetRadiant
void brushdef(const TWorldSpawn &x, const char *fn) {
}
int main(const int _kiArgC, const char** _kppcArgv) int main(const int _kiArgC, const char** _kppcArgv)
{ {
// Check we have correct number of parameters // Check we have correct number of parameters
@ -54,7 +50,7 @@ int main(const int _kiArgC, const char** _kppcArgv)
} }
else else
{ {
if (brushdef_legacy(Parser.m_WorldSpawn,_kppcArgv[2])) { if (writemap(Parser.m_WorldSpawn, _kppcArgv[2], &brushdef_net)) {
cout << "Successfully exported map." << endl; cout << "Successfully exported map." << endl;
} else { } else {
cout << "Failed to write output file." << endl; cout << "Failed to write output file." << endl;