// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#if COMPILE_WITH_MODEL_TOOL && USE_EDITOR
#include "Engine/Core/Config.h"
#include "Engine/Core/Types/BaseTypes.h"
#include "Engine/Platform/Platform.h"
///
/// The VertexTriangleAdjacency class computes a vertex-triangle adjacency map from a given index buffer.
///
class VertexTriangleAdjacency
{
public:
///
/// Construction from an existing index buffer
///
/// The index buffer.
/// The number of triangles in the buffer.
/// The number of referenced vertices. This value is computed automatically if 0 is specified.
/// If you want the class to compute a list containing the number of referenced triangles per vertex per vertex - pass true.
VertexTriangleAdjacency(uint32* indices, int32 indicesCount, uint32 vertexCount = 0, bool computeNumTriangles = true);
///
/// Destructor
///
~VertexTriangleAdjacency();
public:
///
/// The offset table
///
uint32* OffsetTable;
///
/// The adjacency table.
///
uint32* AdjacencyTable;
///
/// The table containing the number of referenced triangles per vertex.
///
uint32* LiveTriangles;
///
/// The total number of referenced vertices.
///
uint32 NumVertices;
public:
///
/// Gets all triangles adjacent to a vertex.
///
/// The index of the vertex.
/// A pointer to the adjacency list.
uint32* GetAdjacentTriangles(uint32 vertexIndex) const
{
ASSERT(vertexIndex >= 0 && vertexIndex < NumVertices);
return &AdjacencyTable[OffsetTable[vertexIndex]];
}
///
/// Gets the number of triangles that are referenced by a vertex. This function returns a reference that can be modified.
///
/// The index of the vertex.
/// The number of referenced triangles
uint32& GetNumTrianglesPtr(uint32 vertexIndex) const
{
ASSERT(vertexIndex >= 0 && vertexIndex < NumVertices);
ASSERT(nullptr != LiveTriangles);
return LiveTriangles[vertexIndex];
}
};
#endif