Reputation: 227
I am using AVFoundation for front camera View. From the Front camera, I'm detecting the Face from each frame using vision framework. From that, I'm able to get CGPoints of nose. Now, I want to add a 3D object on one of the nose points using sceneKit view and I want to convert those Nose CGPoint to SCNVector3 so that I can give the position to the 3D object.
Upvotes: 2
Views: 1414
Reputation: 707
Convert CGPoint to SCNVector in SceneKit either by hitTest or raycast method,
let touchPoint = CGPoint(x: 34, y: 298) // for hitTest example
let hitTestResult : [ARHitTestResult] = sceneView.hitTest(touchPoint, types: .featurePoint)
guard let hitResult = hitTestResult.first else {
return
}
let vector = SCNVector3((hitResult.worldTransform.columns.3.x), (hitResult.worldTransform.columns.3.y), (hitResult.worldTransform.columns.3.z))
print(vector) // returns somewhat like this SCNVector3(x: -0.2502137, y: 0.15422173, z: -0.17789307)
Upvotes: 1