Reputation: 1956
So I am using ARKit
and ARAnchors
in an ARImageTrackingConfiguration()
. I am using multiple versions of the same ARAnchor
with different colored backgrounds. I would like to be able to get the background color of the ARAnchor
being recognized (because if I register them all as ARAnchors
it mixes them up even if they have different backgrounds). The way I was thinking of doing this was to get the position of the ARAnchor
in 2D space and then obtaining the color of a pixel within the frame like this.
The problem is I can't find a way to get the ARAnchor
's position in 2D space. I am using a setup like below. If you have any idea how I can translate the coordinates or a better way to do this please let me know.
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let imageAnchor = anchor as? ARImageAnchor {
if (anchor.name == "EXAMPLE MARKER") {
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = UIImage(named: "EXAMPLE")
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
node.addChildNode(planeNode)
// HOW TO CONVERT ANY OF THESE COORDINATE SYSTEMS TO GRECT? CGPOINT?
}
}
return node
}
I've tried to get the position as follows but it always comes out as all zeros
print(anchor.accessibilityFrame)
print(imageAnchor.accessibilityFrame)
print(node.frame)
print(node.boundingBox.max,node.boundingBox.min)
Results
(0.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0)
SCNVector3(x: 0.0, y: 0.0, z: 0.0) SCNVector3(x: 0.0, y: 0.0, z: 0.0)
Upvotes: 1
Views: 385