How can I make an image anchor only place an object?

Context, I want to make a very basic ar app using an image anchor, I have achieved this using Reality Composer and it works great.


The issue is if I tried to zoom into an object in a way where the image anchor isn't clearly visible it disappears, which I understand is expected.

My question is is there a way to have my objects stay in place so I can walk around and zoom in and out.


So the ar object will appear when the image anchor is placed and if the image anchor is visible stay on it (allowing me to move and rotate the image anchor) but if not visible stay in the place it was last in.


I don't know how to program but I'm learning as I follow tutorials and bits and pieces. I have linked the code that I have slightly modified in the view controller

import UIKit 
import RealityKit

class ViewController: UIViewController {

@IBOutlet var arView: ARView!
var mapAnchor: Experience.Map! 

override funcviewDidLoad() { 
     super.viewDidLoad()

     mapAnchor = try! Experience.loadMap()
     arView.scene.anchors.append(mapAnchor)
     }
}

Replies

I'm also looking for an answer to this, the default behaviour of the ar quick view does exactly what I need. I'm just needing to know how to do that in xcode.


As said above, when the image is no longer visible it should keep the last known location in the scene and remain visible.\

Thanks

I have exactly the same problem.

Same issue but for AR Quick Look. Reality Composer plays scene correctly but usdz / . Reality files show this behavior

+1 how to retain it after losing it.. :- )

You can achieve this using ARKit API in two ways:

  1. In your ARWorldTrackingConfiguration, set maximumNumberOfTrackedImages to 0. This will disable image tracking, i.e., your ARImageAnchors won't receive any updates once they have been added to the session. Hence, your model won't be removed even if you lose sight of the anchor.

  2. Alternatively, you can monitor the session:didUpdateAnchors: callback and decide on your own how to react when the image anchor is updated. For example, you could only update your content based on the anchor's position component and keep the rotation constant, or apply any other custom logic how to use the anchor's transform.

  • Yeah, I'm also struggling with this, here's an example of what I'm trying to do. I'm afraid I don't know swift and all these iOS APIs very well... here's an example of something I tried that did not work. Am I close?

    import SwiftUI import RealityKit import ARKit struct ArAnchorController: UIViewRepresentable {   func makeUIView(context: Context) -> ARView {     let arView = ARView(frame: .zero)     MyRealityComposerProject.loadASceneAsync{ result in       switch result {       case .success(let anchor):         arView.scene.anchors.append(anchor)       case .failure(_):         break       }     }     return arView   }   func updateUIView(_ uiView: ARView, context: Context) { // Is this the place to set up the ARWorldTrackingConfiguration ?? let configuration = ARWorldTrackingConfiguration() configuration.maximumNumberOfTrackedImages = 0 uiView.session.run(configuration)   } }
Add a Comment