#pragma once #include "matrix.h" class Tesselator { public: typedef std::vector VertexList; typedef std::unordered_map VertexIndexMap; struct PolyVertex { size_t vertexIndex; Vec3 normalizedUV; }; struct Polygon { std::vector 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 tesselateFace(const face_t* face); static Matrix4x4 buildTextureSpaceTransform(const texinfo_t* texinfo, const miptex_t* miptex, const plane_t* plane); static Matrix4x4 buildLightmapTransform(const texinfo_t* texinfo, const plane_t* plane); private: const world_t* world; VertexList vertices; VertexIndexMap vertexIndices; };