Search code examples
iosscenekitarkit

How to cover eyes and mouth in face occlusion mask in ARKit


Apple's ARKit has an easy way to create a face occlusion mask: you can get an ARFaceGeometry (a mesh in other words) from ARFaceAnchor, make it transparent and render it before anything else, that way parts of other models on the scene that are behind the occlusion mask are hidden. The problem is that the geometry that comes from ARFaceAnchor has "holes" for the eyes and the mouth. That is useful for other purposes but for the occlusion mask it's not, other objects can be seen through those holes which looks weird. I'm trying to find a way to "cover" those holes. The geometry from ARFaceAnchor has a fixed structure so, in theory, I could find the exact vertices around the eyes and the mouth and manually add edges to the mesh to cover them. It looks like there should be a better way though. Is there an easy way to cover those holes for the eyes and the mouth to create a better face occlusion mask?


Solution

  • Create your face mesh like this:

    let faceMesh = ARSCNFaceGeometry(device: device, fillMesh: true)

    The key being fillMesh: true