# Detect and fix holes in an object (not mesh holes)

I have a complex mesh that I have imported from a .obj file. I would like to check whether it is genus-0, i.e. whether there are any holes in the object. If there are such holes I need to fix them. I have tried searching by eye but it appears there must be rather small holes that are not obvious on inspection.

When I search for things like "Blender fill holes" the results appear to relate to holes in the mesh itself, i.e. involving edges that only have a single adjacent face. This is not what I am trying to do. For example, the standard mesh "Torus" has no holes in its mesh, but it has a big hole in the object itself, which is the kind of thing that I need to be able to fix.

• I would consider a "remesh" under object data properties, depend on resolution (voxel size) you set it will fill the holes that are too small. But it will will completely ruin the topology.
– Fowl
Mar 10 '20 at 14:13
• That can be about finding features points on a mesh, eventually finding the skeleton so that the topological structure can be found. But this is (i think) still research projects. Or your case is particular? Could you provide an example? Mar 10 '20 at 19:14

Assuming you do have a closed, clean, manifold surface, and you're looking for the number of genuine topological holes, you could use the surface's Euler Characteristic? (You'd better get Math SE to check me up on that one) .. anyway...

Object mode, select the object, run this snippet..

import bpy

ob = bpy.context.object
me = ob.data
v = len(me.vertices)
e = len(me.edges)
f = len (me.polygons)
g =  1 - ((v - e + f)/2)

print(g)


.. and the genus is returned in g.

• This is a very helpful start, thank you! Although ideally it would be great to know where the holes are located, this will presumably just tell me how many there are. Mar 10 '20 at 18:08
• @user2390246 at first sight, a strict solution to finding the holes seems a bit of a job Mar 10 '20 at 18:55
• @RobinBetts, yes... commented in the same way below the question... but would be something great to have!! Mar 10 '20 at 19:15
• @lemon ... can imagine a few (not strict) divide-and conquer strategies.. as you commented, a characteristic shape would help. Mar 10 '20 at 19:29
• @RobinBetts, a tesselation? That can do, but still complex I think. But I you have some idea about it, please go!! Man, if we had that, it can be included to blender core code, I think... many applications. Mar 10 '20 at 19:33