The first time you install the APP, the camera will get stuck a moment during loading ModelEntity.
Thank you in advance for your help!
Thank you in advance for your help!
Code Block class ViewController: UIViewController { @IBOutlet var arView: ARView! fileprivate var configuration: ARWorldTrackingConfiguration! fileprivate var rootAnchor: AnchorEntity! // MARK: === viewWillAppear override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) configuration = ARWorldTrackingConfiguration() configuration.planeDetection = [.horizontal] arView.session.run(configuration) } // MARK: === viewDidLoad override func viewDidLoad() { super.viewDidLoad() arView.session.delegate = self } } // MARK: === ARSessionDelegate extension ViewController: ARSessionDelegate { func session(_ session: ARSession, didAdd anchors: [ARAnchor]) { anchors.compactMap { $0 as? ARPlaneAnchor }.forEach { rootAnchor = AnchorEntity() rootAnchor.transform.matrix = $0.transform arView.scene.addAnchor(rootAnchor) add() } } // MARK: === add fileprivate func add() { guard let path = Bundle.main.path(forResource: "cupandsaucer", ofType: "usdz") else { return } var cancellable: AnyCancellable? = nil cancellable = ModelEntity.loadModelAsync(contentsOf: URL(fileURLWithPath: path)).sink(receiveCompletion: { error in cancellable?.cancel() }, receiveValue: { [self] modelEy in rootAnchor.addChild(modelEy) cancellable?.cancel() }) } }