1

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
}
Asperi
  • 228,894
  • 20
  • 464
  • 690
Mc.Lover
  • 4,813
  • 9
  • 46
  • 80

2 Answers2

0

Preamble for others who stumble over this question: Depending on your use case, consider making your View an ARSCNView, and adopt the ARSCNViewDelegate protocol, which has a scene of the correct type, see https://developer.apple.com/documentation/arkit/arscnview

Conversion of Scenes

Regarding conversion of .scn to USDZ, a roundtrip through collada helps. Note, that the .scn format can contain several items that are specific to SceneKit, such as physics bodies and fields, constraints, and particle systems. These not transferrable that way.

That said, on the Mac SCNScene.write(to:options:delegate:progressHandler:) allows to export your scene to Collada/.dae format. Unfortunately, the Collada option is not available on iOS. For details, see https://developer.apple.com/documentation/scenekit/scnscene/1523577-write

Converting Collada to .usdz you have numerous viable options, depending on the content and the intended information workflow.

DatBlaueHus
  • 266
  • 1
  • 5
0

There are free tools for converting to USDZ. The converter tool by Apple works only with the latest version of macOS. You can use a tool like this that it's working online (no need to download):

https://www.vectary.com/

I'm not connected to this site.

Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117