Accessing Camera Position for Each Frame

When interacting with a RealityKit scene (built in RealityKit Composer), how do you access the camera position for each rendered frame?


// In ARView
var cameraTransform: Transform { get }


I see the cameraTransform propery, but how can I get a callback or event for when each frame is about to be rendered? I'd like to alter some objects based on the position of the camera, but more than can be done with triggers in RKC.


Did the SwiftStrike demo at WWDC need to do that ? Or did they just have the camera impart a force on the ball as the player went near it?


Thanks,

MF

Replies

Answering part of my own question. Unlke SceneKit, there isn't a delegate for getting updates, it's done through a pub/sub call. There is an event type for scene update:


struct SceneEvents.Update
// An event triggered once per frame interval that you can use to execute custom logic for each frame.


I'll give that a go and see what happens.

It seems like you've figured this out already, but in case you haven't, you could do something like this:


arView.scene.subscribe(to: SceneEvents.Update.self) { (event) in
                // Do your custom scene logic here
}