2

I'm trying to display a 3d model from a usdz file at a particular location. Here's the code I came up with:

class ViewController: UIViewController, ARSessionDelegate {

    @IBOutlet var arView: ARView!
    var geoAnchor: ARGeoAnchor? = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        arView.session.delegate = self
        let config = ARGeoTrackingConfiguration()
        arView.session.run(config)

        let coordinate = CLLocationCoordinate2DMake(0.0, -100.0) // coordinates omitted
        let geoAnchor = ARGeoAnchor(coordinate: coordinate)
        self.geoAnchor = geoAnchor
        arView.session.add(anchor: geoAnchor)
    }

    func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
        
        guard let geoAnchor = geoAnchor else { return }
        
        guard let usdzPath = Bundle.main.url(forResource: "myModelFile", withExtension: "usdz") else { 
            return 
        }
        let modelEntity = try! Entity.loadModel(contentsOf: usdzPath)
        let anchorEntity = AnchorEntity(anchor: geoAnchor)
        anchorEntity.addChild(modelEntity)
        
        arView.scene.addAnchor(anchorEntity)
    }
}

When I go out on the street, I'm asked for location/camera permissions and approve. After that, I get nothing as I face my camera towards the location. Note: I'm in one of the supported cities for ARGeoTrackingConfiguration to work—I've also logged statements confirming its availability both on my device and in my city.

I checked ARGeoTrackingStatus and the status is localized, so that isn't the issue.

Any help is greatly appreciated!

Eman Harout
  • 536
  • 7
  • 21
  • Did you ever get this working? I'm struggling with the same thing. – Josh Jan 19 '22 at 17:02
  • @EmanHarout, read my posts please. Perhaps you'll find something important there. – https://stackoverflow.com/questions/71800039/realitykit-adding-modelentity-to-an-argeoanchor/71801799#71801799 – Andy Jazz May 17 '22 at 11:17

0 Answers0