# What defines matching topology?

In a previous question it was shown that a mesh that was duplicated and deformed separately can be used to define a shape key in the original mesh. If the vertex count doesn't match then you get an error message saying "Selected meshes must have equal number of vertices".

As a test I subdivided a cube and merged some vertices to get a vertex count of 507 to match the count in a default suzanne mesh. After joining as a shape key I see a small resemblance to the suzanne shape but really have nothing more than a collection of randomly joined vertices.

So what defines a matching topology in the context of using a mesh to generate a shape key?

Several things matter:

• The vertex count must be the same. = (v0...v19)
• The edge list must have the same vertex indices to build each edge. That is, the same vertices must be connected. = [[v0,v1],...[v10,v11],[v18,v19]]
• The polygon list must have the same vertex indices to build each face. That is, each face must be formed by the same vertices, in the same order. = [[v14,v15,v7,v4],...[v7,v6,v18,v19]]

Basically, you can move the vertices all you like, but you can't change how they connect.

Here is an image to demonstrate a deformation:

Shape keys only store the vertex positions, so a matching number is all that's required.

If you run bpy.app.debug = True in the python console, you'll get a Indices option in the Mesh Display panel of the Properties shelf. With it enabled you can see the index numbers of vertices — these are what's used to find the corresponding point to move to.

That is the vertices are numbered pretty much in order of creation. When performing a join as shapekey, vertex 1 will be moved to the position of vertex 1 in the target shape, vertex 5 will move to the position of vertex 5 and so on. If the target shape has an edge from vertex 3 to 6 and the base shape has an edge from 3 to 12 then you end up with a bit of a mess in the new shapekey.

So the topology that needs to match in this scenario is the order that the vertices are created and joined together needs to match up for the join as shapekey to work well.

The general rule would be that a mesh that is duplicated and modified would have a matching topology and be a good candidate for Join as shapekey. Two meshes created from scratch will most likely not join very well.