I am trying to develop AR app with SwiftUI using FocusEntity to show placing object indicator. My objects are not in USDZ
format they are in .scn
and there is no way to convert them (at least I did not find). Now I am trying to load my objecst using SCNScene
and I cannot find a way to load ARView's scene
with SCNScene
Here is my code that handles tap gesture to place the object:
class ARCoordinator: NSObject, ARSessionDelegate {
weak var view: ARView?
var focusEntity: FocusEntity?
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
guard let view = self.view else { return }
debugPrint("Anchors added to the scene: ", anchors)
self.focusEntity = FocusEntity(on: view, style: .classic(color: .yellow))
}
@objc func handleTap() {
guard let view = self.view, let focusEntity = self.focusEntity else { return }
let scene = SCNScene(named: "art.scnassets/object.scn")!
let node = scene.rootNode.childNodes.first!
node.position = SCNVector3(focusEntity.position.x, focusEntity.position.y, focusEntity.position.z)
view.scene = scene //here is the problem
}