I dont undestand how I can calculate SCNNode position on my ARSCNView with using Vision object. I have a detected face (VNFaceObservation) in ARSCNView, load node from .scn file. And I want that node was moving with face position.
I calculate 2D position of face bounding box with method:
private func faceFrameFrom(_ box: CGRect) -> CGRect {
let origin = CGPoint(x: box.minX * sceneView.bounds.width, y: (1 - box.maxY) * sceneView.bounds.height)
let size = CGSize(width: box.width * sceneView.bounds.width, height: box.height * sceneView.bounds.height)
return CGRect(origin: origin, size: size)
}
and display UIView as sceneView subview with returned rect. It frame matches with face position.
After I load node from file, add node to scene.
I try calculate new position of node in method of scene session delegate:
func session(_ session: ARSession, didUpdate frame: ARFrame)
But I dont understand how I should modify SCNNode position and create new SCNVector3. I think, that I should using sceneView.pointOfView?.simdWorld* properties for calculate offset, when device is moving or human with detected face is moving. But I dont sure that is true way
Any idea or algorithm for this calculation?