Missing API: MeshData.indexCount

There should be a way to get the total number of indices in MeshData.

Right now the only two options are:

  1. GetIndexData
var indexData = meshData.GetIndexData()
var indexCount = indexData.length;
  1. Add up all the submeshes
int indexCount = 0;
for (int i = 0; i < meshData.subMeshCount; i++)
{
    var subMesh = meshData.GetSubMesh(i);
    indexCount += subMesh.indexCount;
}

The former is not ideal because it allocates a native array. The latter is not ideal because the indices in the submeshes could potentially overlap or have gaps in-between.

MeshData should just have an indexCount property which returns the length of the index data array without allocating it.

I’m just wondering why do you need the total number of indices? Also while theoretically possible to have gaps or overlaps, this would be a rare case. Anyways, to get the max used index, you just have to find the submesh with the highest “last index+1 count”. That index would be indexStart + indexCount. This should give you the total number of “used” indices. Of course it would not account for any unused indices at the end of the index buffer.

So this should work:

int indexCount = 0;
for (int i = 0; i < meshData.subMeshCount; i++)
{
    var subMesh = meshData.GetSubMesh(i);
    int count = subMesh.indexStart + subMesh.indexCount;
    if (count > indexCount)
        indexCount = count;
}