Number of vertices in a Shape Key

I’m working on exporting Shape Key info to a file, and I’m a bit confused that the number of vertices in a key doesn’t seem to match the number of vertices in the mesh itself.

e.g.:


meshVertices = self.countVertices(mesh)

for block in mesh.key.getBlocks():
    if block.name != "Basis":
        keyVertices = len(block.getData())

def countVertices(self, mesh):
    numvert = 0
    for face in mesh.faces:
        numvert = numvert + len(face.v)
    return numvert

then meshVertices != keyVertices.

I wondered if the data in each block only corresponds to a subset of the vertices (the ones that have actually been moved?). The API documentation says that the results of block.getData ought to be a list of NMVert objects, in which case I could check out the ‘index’ property and find out which ones I was seeing. But in reality it returns simple Vector objects that don’t contain any such information.

Any ideas? Is there another way of finding out which mesh vertex each vertex in the shape key corresponds to?

The answer, in case anybody was wondering, is that countVertices counts lots of duplicates when two faces reuse the same vertex, whereas the shape key data blocks obviously only have entries for each unique vertex.