Above solution does not work. It gives different values
func realWorldPosition(for originalVertex: SCNVector3, point: CGPoint, faceAnchor: ARFaceAnchor) -> (CGPoint?, SCNVector3?)? {
let firstVertex = originalVertex
print("\n\n\nOriginal position: ", firstVertex)
let localPosition = SIMD4(firstVertex.x, firstVertex.y, firstVertex.z, 1)
let col = SIMD4<Float>(SCNVector4())
let worldPosition = faceAnchor.transform * simd_float4x4(col, col, col, localPosition)
let projectedPosition = sceneView.projectPoint(worldPosition.position)
print("projectedPosition: ", projectedPosition)
let unprojectedPosition = sceneView.unprojectPoint(projectedPosition)
print("unprojectedPosition: ", unprojectedPosition)
let vec = SCNVector3(x: unprojectedPosition.x, y: unprojectedPosition.y, z: unprojectedPosition.z)
let p = CGPoint(x: CGFloat(projectedPosition.x), y: CGFloat(projectedPosition.y))
return (p, vec)
}
Original position: SCNVector3(x: 0.015014233, y: 0.01659775, z: 0.04286898)
projectedPosition: SCNVector3(x: 405.9854, y: 609.32275, z: 0.9972021)
unprojectedPosition: SCNVector3(x: -0.0027770074, y: 0.101203665, z: -0.3426712)