Gogo123
Gogo123

Reputation: 655

RealityKit : Camera Anchor Transform is not updating

I've got a realitykit app. I know that with arkit I can get the camera transform from frame.camera.transform.

I just can't understand why the transform of the camera anchor below is not updated. I would expect this transform to change as I move my device.

var cameraAnchor : AnchorEntity!
...

override func viewDidLoad()
{
    super.viewDidLoad()
    arView.session.delegate = self
...

override func viewDidAppear(_ animated: Bool)
{
    super.viewDidAppear(animated)
    cameraAnchor = AnchorEntity(.camera)
    arView.scene.addAnchor(cameraAnchor)

...

func session(_ session: ARSession, didUpdate frame: ARFrame)
{
   print(cameraAnchor.transform)
...

result : Transform(scale: SIMD3(1.0, 1.0, 1.0), rotation: simd_quatf(real: 1.0, imag: SIMD3(0.0, 0.0, 0.0)), translation: SIMD3(0.0, 0.0, 0.0))

Upvotes: 1

Views: 752

Answers (2)

maxxfrazer
maxxfrazer

Reputation: 1263

The cameraAnchor you added will always have the same transform. The cameraAnchor's transform relative to the world origin is what you really want.
Try instead:

print(cameraAnchor.position(relativeTo: nil))

That will update the position and tell you where your camera is relative to the starting point - world position [0, 0, 0]. Same can be done with .transformMatrix(relativeTo: nil).

Weirdly there's no way to directly get the whole Transform object, other than cameraAnchor.convert(transform: cameraAnchor.transform, to: nil); which seems convoluted.

Docs:

Upvotes: 3

arthurschiller
arthurschiller

Reputation: 368

I'm quite sure that when using cameraMode == .ar your custom camera anchor will get overridden by RealityKit as it's gonna use it's own camera anchor which then get's updated with data supplied by ARKit.

If you want to access the current camera transform you can use https://developer.apple.com/documentation/realitykit/arview/cameratransform or https://developer.apple.com/documentation/arkit/arframe/2867980-camera

Upvotes: 0

Related Questions