Skip to content

Commit a50a7bc

Browse files
HnMeshUtils: added GetTotalIndexCount function
1 parent 1bf2873 commit a50a7bc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Hydrogent/include/HnMeshUtils.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "pxr/imaging/hd/types.h"
3030
#include "pxr/imaging/hd/meshTopology.h"
31+
#include "FlagEnum.h"
3132

3233
namespace Diligent
3334
{
@@ -65,6 +66,17 @@ class HnMeshUtils final
6566
size_t GetNumEdges(size_t* NumFaces = nullptr) const;
6667

6768

69+
enum GET_TOTAL_INDEX_COUNT_FLAGS : uint32_t
70+
{
71+
GET_TOTAL_INDEX_COUNT_FLAG_NONE = 0u,
72+
GET_TOTAL_INDEX_COUNT_FLAG_TRIANGLES = 1u << 0u,
73+
GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST = 1u << 1u,
74+
GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP = 1u << 2u,
75+
GET_TOTAL_INDEX_COUNT_FLAG_POINTS = 1u << 3u,
76+
};
77+
/// Returns the total number of indices (triangles + edges + points)
78+
size_t GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAGS Flags) const;
79+
6880
/// Triangulates the mesh and returns the triangle indices and the start of each subset.
6981
///
7082
/// \param[in] UseFaceVertexIndices - Whether to use face vertex indices.
@@ -207,6 +219,7 @@ class HnMeshUtils final
207219
const pxr::HdMeshTopology& m_Topology;
208220
const pxr::SdfPath& m_MeshId;
209221
};
222+
DEFINE_FLAG_ENUM_OPERATORS(HnMeshUtils::GET_TOTAL_INDEX_COUNT_FLAGS);
210223

211224
} // namespace USD
212225

Hydrogent/src/HnMeshUtils.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void HnMeshUtils::Triangulate(bool UseFaceVertexIndices,
105105

106106
// Count the number of triangles
107107
const size_t NumTriangles = GetNumTriangles();
108+
VERIFY_EXPR(NumTriangles * 3 == GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAG_TRIANGLES));
108109

109110
// Triangulate faces
110111
TriangleIndices.reserve(NumTriangles);
@@ -296,6 +297,7 @@ pxr::VtIntArray HnMeshUtils::ComputeEdgeIndices(bool UseFaceVertexIndices, bool
296297
});
297298
VERIFY_EXPR(EdgeIndices.size() == NumEdges * 2);
298299
}
300+
VERIFY_EXPR(EdgeIndices.size() == GetTotalIndexCount(UseLineStrip ? GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP : GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST));
299301

300302
if (UseFaceVertexIndices)
301303
{
@@ -352,10 +354,38 @@ pxr::VtIntArray HnMeshUtils::ComputePointIndices(bool ConvertToFaceVarying) cons
352354
for (int i = 0; i < NumPoints; ++i)
353355
PointIndices[i] = i;
354356
}
357+
VERIFY_EXPR(PointIndices.size() == GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAG_POINTS));
355358

356359
return PointIndices;
357360
}
358361

362+
size_t HnMeshUtils::GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAGS Flags) const
363+
{
364+
VERIFY((Flags & (GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST | GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP)) != (GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST | GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP),
365+
"COUNT_EDGES_LIST and COUNT_EDGES_STRIP flags are mutually exclusive");
366+
367+
size_t NumIndices = 0;
368+
if (Flags & GET_TOTAL_INDEX_COUNT_FLAG_TRIANGLES)
369+
{
370+
size_t NumTriangles = GetNumTriangles();
371+
NumIndices += NumTriangles * 3;
372+
}
373+
374+
if (Flags & (GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST | GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP))
375+
{
376+
size_t NumFaces = 0;
377+
size_t NumEdges = GetNumEdges(&NumFaces);
378+
NumIndices += (Flags & GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP) ? NumEdges + NumFaces * 2 : NumEdges * 2;
379+
}
380+
381+
if (Flags & GET_TOTAL_INDEX_COUNT_FLAG_POINTS)
382+
{
383+
NumIndices += m_Topology.GetNumPoints();
384+
}
385+
386+
return NumIndices;
387+
}
388+
359389
template <typename T>
360390
pxr::VtValue ConvertVertexArrayToFaceVaryingArray(const pxr::VtIntArray& FaceVertexIndices, const pxr::VtArray<T>& VertexArray, size_t ValuesPerVertex)
361391
{

0 commit comments

Comments
 (0)