- add support for outputting a debug mesh of the entire map

This commit is contained in:
Magnus Norddahl 2018-10-27 02:07:34 +02:00
parent e84795cf99
commit 5a8927506a
3 changed files with 80 additions and 0 deletions

View File

@ -39,6 +39,8 @@
#include "kexlib/binFile.h"
#include "wad.h"
#include "framework/templates.h"
#include <map>
#include <vector>
//#define EXPORT_TEXELS_OBJ
@ -1163,6 +1165,81 @@ void kexLightmapBuilder::WriteTexturesToTGA()
}
}
void kexLightmapBuilder::WriteMeshToOBJ()
{
FILE *f = fopen("mesh.obj", "w");
std::map<int, std::vector<surface_t*>> sortedSurfs;
for (unsigned int i = 0; i < surfaces.Length(); i++)
sortedSurfs[surfaces[i]->lightmapNum].push_back(surfaces[i]);
for (const auto &it : sortedSurfs)
{
for (const auto &s : it.second)
{
for (int j = 0; j < s->numVerts; j++)
{
fprintf(f, "v %f %f %f\n", s->verts[j].x, s->verts[j].z + 100.0f, s->verts[j].y);
}
}
}
for (const auto &it : sortedSurfs)
{
for (const auto &s : it.second)
{
for (int j = 0; j < s->numVerts; j++)
{
fprintf(f, "vt %f %f\n", s->lightmapCoords[j * 2], s->lightmapCoords[j * 2 + 1]);
}
}
}
int voffset = 1;
for (const auto &it : sortedSurfs)
{
int lightmapNum = it.first;
if (lightmapNum != -1)
fprintf(f, "usemtl lightmap_%02d\n", lightmapNum);
else
fprintf(f, "usemtl black\n");
for (const auto &s : it.second)
{
switch (s->type)
{
case ST_FLOOR:
for (int j = 2; j < s->numVerts; j++)
{
fprintf(f, "f %d/%d %d/%d %d/%d\n", voffset + j, voffset + j, voffset + j - 1, voffset + j - 1, voffset, voffset);
}
break;
case ST_CEILING:
for (int j = 2; j < s->numVerts; j++)
{
fprintf(f, "f %d/%d %d/%d %d/%d\n", voffset, voffset, voffset + j - 1, voffset + j - 1, voffset + j, voffset + j);
}
break;
default:
for (int j = 2; j < s->numVerts; j++)
{
if (j % 2 == 0)
fprintf(f, "f %d/%d %d/%d %d/%d\n", voffset + j - 2, voffset + j - 2, voffset + j - 1, voffset + j - 1, voffset + j, voffset + j);
else
fprintf(f, "f %d/%d %d/%d %d/%d\n", voffset + j, voffset + j, voffset + j - 1, voffset + j - 1, voffset + j - 2, voffset + j - 2);
}
break;
}
voffset += s->numVerts;
}
}
fclose(f);
}
//
// kexLightmapBuilder::ExportTexelsToObjFile
//

View File

@ -47,6 +47,7 @@ public:
void LightSurface(const int surfid);
void LightGrid(const int gridid);
void WriteTexturesToTGA();
void WriteMeshToOBJ();
void AddLightGridLump(kexWadFile &wadFile);
void AddLightmapLumps(kexWadFile &wadFile);

View File

@ -80,6 +80,8 @@ int main(int argc, char **argv)
builder.CreateLightmaps(loader.Level);
builder.WriteTexturesToTGA();
builder.WriteMeshToOBJ();
loader.Level.CleanupThingLights();
lump = inwad.LumpAfterMap(lump);