Understanding Anchor transform vs trackedRaycast transform

I'm looking through the ARKitInteraction sample app, and there are a few things I don't really understand about how the trackedRaycast transform and the ARAnchor transform area related.


1. In the trackedRaycast handler, the result of the raycast is assigned to the SCNNode's transform. However, that object is already attached to an ARAnchor, and in the documentation, it says "Adding an anchor to the session helps ARKit to optimize world-tracking accuracy in the area around that anchor, so that virtual objects appear to stay in place relative to the real world. If a virtual object moves, remove the corresponding anchor from the old position and add one at the new position."

Doesn't this mean the Anchor and the trackedRaycast are giving conflicting instructions?


2. In the ARSCNViewDelegate's

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor)

implementation, there's the call

objectAtAnchor.simdPosition = anchor.transform.translation

Doesn't the fact that didUpdate is being called mean that the anchor transform was already set to the object transform? I'm guessing this is to help the trackedRaycast functionality work with the anchor functionality, but I don't see how.

I assume you refer to this sample: https://developer.apple.com/documentation/arkit/world_tracking/placing_objects_and_handling_3d_interaction.
  1. The virtual object is not attached to an ARAnchor - it is added to the scene root (that's done inside setVirtualObject3DPosition when the object has no parent yet). So updating the object's transform from the tracked raycast does not conflict with the anchor.

  2. The fact that renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) is called simply means that an ARAnchor was updated. If the virtual object was a child of the anchor node, your assumption that it automatically gets updated would be correct. However, as mentioned in 1., the object is added at the scene root. Hence, its position needs to be updated manually whenever the anchor updates.

For simple use cases, it's fine to add content to the node generated by ARSCNView and let ARKit handle the rest. In this sample, a virtual object's position may be affected by tracked raycast updates, anchor updates, and user gestures. Therefore, it was chosen to add it to the scene root explicitly, and update its position when needed.
Understanding Anchor transform vs trackedRaycast transform
 
 
Q