I was looking at this post Face texture to print the x and y vertices:
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard anchor == currentFaceAnchor,
let contentNode = selectedContentController.contentNode,
contentNode.parent == node
else { return }
let vertices = currentFaceAnchor!.geometry.vertices
for (index, vertex) in vertices.enumerated() {
let vertex = sceneView.projectPoint(node.convertPosition(SCNVector3(vertex), to: nil))
let xVertex = CGFloat(vertex.x)
let yVertex = CGFloat(vertex.y)
let newPosition = CGPoint(x: xVertex, y: yVertex)
print(newPosition)
}
}
I am able to print the newPosition like so. For example:
(391.0479431152344, 577.9422607421875)
(379.6573791503906, 579.8109741210938)
(369.43145751953125, 583.1146240234375)
(362.12176513671875, 587.81787109375)...
The goal is I want to save newPosition in a UIbutton click.
@IBAction private func stopPressed() {
do {
fpsTimer.invalidate() //turn off the timer
let capturedData = captureData.map{$0.stringRepresentation}.joined(separator:"\(newPosition)>")
let dir: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last! as URL
let url = dir.appendingPathComponent("testing.txt")
try capturedData.appendLineToURL(fileURL: url as URL)
}
catch {
print("Could not write to file")
}
}
But I can't access newPosition directly like so in the captureData: Use of unresolved identifier 'newPosition'
Can anyone direct me on how to access the renderer and be called in the UIbutton so I can save the vertices?
Thanks!