Tools for preprocessing data files from Quake to make them suitable for use on PS1 hardware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

#pragma once
#include "matrix.h"
class Tesselator
{
public:
typedef std::vector<Vec3> VertexList;
typedef std::unordered_map<Vec3, size_t> VertexIndexMap;
struct PolyVertex
{
size_t vertexIndex;
Vec3 normalizedUV;
};
struct Polygon
{
std::vector<PolyVertex> polyVertices;
};
Tesselator(const world_t* world) : world(world)
{
}
const VertexList& getVertices() const { return vertices; }
const VertexIndexMap& getVertexIndices() const { return vertexIndices; }
size_t addVertex(const Vec3& vert)
{
size_t vertexIndex;
// Make sure we don't store duplicate vertices
auto vertIter = vertexIndices.find(vert);
if (vertIter != vertexIndices.end())
{
vertexIndex = vertIter->second;
}
else
{
vertexIndex = vertices.size();
vertexIndices[vert] = vertexIndex;
vertices.push_back(vert);
}
return vertexIndex;
}
std::vector<Polygon> tesselateFace(const face_t* face);
static Matrix4x4 buildTextureSpaceTransform(const texinfo_t* texinfo, const miptex_t* miptex, const plane_t* plane);
private:
const world_t* world;
VertexList vertices;
VertexIndexMap vertexIndices;
};