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.
54 lines
991 B
54 lines
991 B
#pragma once
|
|
|
|
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);
|
|
|
|
private:
|
|
const world_t* world;
|
|
|
|
VertexList vertices;
|
|
VertexIndexMap vertexIndices;
|
|
};
|