swiftcamerascenekitarkitrealitykit

SceneKit's "allowsCameraControl" equivalent in RealityKit


In SceneKit SDK to allow controlling a camera movement you need to set a parameter called .allowsCameraControl to true.

var scnView = SCNView(frame: .zero)
scnView.allowsCameraControl = true

What parameter for controlling a camera (dolly in, dolly out) is used in RealityKit?

var arView = ARView(frame: .zero)
// ???

Any help appreciated.


Solution

  • RealityKit 4.0

    Starting from iOS 18.0 and macOS 15.0, RealityKit AR/VR developers can now use the realityViewCameraControls(_:) modifier when working with RealityView.

    import SwiftUI
    import RealityKit
    
    struct ContentView : View {
        var body: some View {
            RealityView { rvc in
                let model = try! await Entity(named: "model")
                rvc.add(model)
            }
            .ignoresSafeArea()
            .realityViewCameraControls(.dolly)
        }
    }
    

    RealityKit 3.0 / 2.0 / 1.0

    Earlier versions of RealityKit have no SceneKit's equivalent called .allowsCameraControl for ARView that allow you move and rotate virtual camera. Cupertino engineers considered that there was no need to have such a control because RealityKit is rather the AR-centric framework than VR-centric one.

    For further details, look at this post.