1

I'm using ARKit with the ARFaceTrackingConfiguration. It detects my face when I look at the camera, which is great. However, when I move out of view of the camera, I don't get renderer:didRemoveNode:forAnchor:.

What I would like to do is detect when the face has gone so that I can reset the session and begin looking for a (potentially) new face.

Edit: Seems I can do something like this:

- (void)renderer:(id<SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time {
  SCNVector3 location = [renderer projectPoint:self.faceNode.position];
  CGPoint point = CGPointMake(round(location.x), round(location.y));
  BOOL isNodeVisible = CGRectContainsPoint(self.view.frame, point);
  // ... do stuff ...
}

Though I'm not sure that's the correct way to do it.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222

1 Answers1

0

I don't have an iPhoneXso can't test this exactly.

But I believe you can use isNodeInsideFrustum:withPointOfView method which:

Returns a Boolean value indicating whether a node might be visible from a specified point of view.

In a simple test I create an SCNNode which I have called faceNode.

Then using the delegate callback:

renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval)

I was able to determine if the node was in view of the camera e.g:

func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

        if let currentPointOfView = augmentedRealityView?.pointOfView{

            let faceIsVisible = augmentedRealityView.isNode(faceNode, insideFrustumOf: currentPointOfView)

            if faceIsVisible{
                print("Face Is In View Of The Camera")
            }else{
                print("Face Is Not In View Of The Camera")

            }

      }
}

Hopefully this will help in your current situation....

BlackMirrorz
  • 7,217
  • 2
  • 20
  • 31
  • I will give this a shot. Thanks. – i_am_jorf Mar 21 '18 at 23:23
  • Hm, doesn't exactly work. `sNode(_, insideFrustrumOf)` does return false when I turn the phone away but then it returns true again. And then it just seems randomly to flip between true and false. – i_am_jorf Mar 22 '18 at 21:12