Skip to content

Commit ed04eda

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

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-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: 31 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);
@@ -280,6 +281,7 @@ pxr::VtIntArray HnMeshUtils::ComputeEdgeIndices(bool UseFaceVertexIndices, bool
280281
EdgeIndices.push_back(-1);
281282
});
282283
VERIFY_EXPR(EdgeIndices.size() == NumEdges + NumFaces * 2);
284+
VERIFY_EXPR(EdgeIndices.size() == GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAG_EDGES_STRIP));
283285
}
284286
else
285287
{
@@ -295,6 +297,7 @@ pxr::VtIntArray HnMeshUtils::ComputeEdgeIndices(bool UseFaceVertexIndices, bool
295297
EdgeIndices.push_back(StartVertex);
296298
});
297299
VERIFY_EXPR(EdgeIndices.size() == NumEdges * 2);
300+
VERIFY_EXPR(EdgeIndices.size() == GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAG_EDGES_LIST));
298301
}
299302

300303
if (UseFaceVertexIndices)
@@ -320,6 +323,7 @@ pxr::VtIntArray HnMeshUtils::ComputePointIndices(bool ConvertToFaceVarying) cons
320323

321324
pxr::VtIntArray PointIndices;
322325
PointIndices.reserve(NumPoints);
326+
VERIFY_EXPR(static_cast<size_t>(NumPoints) == GetTotalIndexCount(GET_TOTAL_INDEX_COUNT_FLAG_POINTS));
323327
if (ConvertToFaceVarying)
324328
{
325329
const int* FaceVertexIndices = m_Topology.GetFaceVertexIndices().cdata();
@@ -356,6 +360,33 @@ pxr::VtIntArray HnMeshUtils::ComputePointIndices(bool ConvertToFaceVarying) cons
356360
return PointIndices;
357361
}
358362

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

0 commit comments

Comments
 (0)