[SOLVED] Difference between renderer and session methods in ARKit


I checked the following two sample codes: https://developer.apple.com/documentation/arkit/capturing_body_motion_in_3d

func session(_ session: ARSession, didUpdate anchors: [ARAnchor])
    for anchor in anchors        
        guard let bodyAnchor = anchor as? ARBodyAnchor else { continue }
        let skeleton = bodyAnchor.skeleton

and: https://developer.apple.com/documentation/arkit/tracking_and_visualizing_faces 

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor)
    guard let faceAnchor = anchor as? ARFaceAnchor else { return }
    let blendShapes = faceAnchor.blendShapes    

The code to extract the BlendShape of the face uses “renderer” to get the value of the BlendShape.

However, the code that detects body movement uses “session” to get the value.

Both of the two codes seem to be for getting values that are updated from ARAnchor.

What’s the difference between “renderer” and “session”?

How do I use the two codes at different times?


Both renderer(_:didUpdate:for:) and session(_:didUpdate:) instance methods update AR content (camera/model position or some specific data like face expressions) at 60 fps. They work almost identically but they have different purposes. For five renderer(...) instance methods you have to implement ARSCNViewDelegate protocol. For four session(...) instance methods you have to implement ARSessionDelegate protocol.

An official documentation says:

ARSCNViewDelegate’s methods provide the automatic synchronization of SceneKit content with an AR session. And ARSessionDelegate’s methods work directly with ARFrame objects.

The main difference is:

  • you must use renderer(_:didUpdate:for:) instance method for ARKit+SceneKit copula, because it works with ARSCNView object.

  • also, you can use session(_:didUpdate:) method for ARKit+SceneKit copula, because it also works with ARSCNView object.

  • and you must use session(_:didUpdate:) method for ARKit+RealityKit copula, because it works with ARView object.

Answered By – Andy Jazz

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *