4

Right now I can save what I created in ARKit as a scene file, and load it back later.

sceneView.scene.write(to: path, options: nil, delegate: nil, progressHandler: nil)

But is it possible to save the scene as USDZ file and load it back?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88

1 Answers1

4

First of all, read the following SO post that is very helpful.

Creating USDZ from SCN programmatically

In SceneKit, there's the write(to:options:delegate:progressHandler:) instance method that does the trick (the only thing you have to do is to assign a file format for URL).

let path = FileManager.default.urls(for: .documentDirectory,
                                     in: .userDomainMask)[0]
                                         .appendingPathComponent("model.usdz")
    
sceneView.scene.write(to: path)

Converting OBJ to USDZ using SceneKit.ModelIO

However, if you need to convert OBJ model into USDZ, you have to import SceneKit.ModelIO module at first. Then use the following code:

let objAsset = MDLAsset(url: objFileUrl)
let destinationFileUrl = URL(fileURLWithPath: "path/Scene.usdz")
objAsset.exportToUSDZ(destinationFileUrl: destinationFileUrl)

Terminal approach

In Xcode 15/14/13/12/11, you can convert several popular input formats into USDZ via command line: obj, gltf, fbx, abc, usd(x).

usdzconvert file.gltf

In Xcode 10, only OBJ-to-USDZ, single-frame ABC-to-USDZ and USD(x)-to-USDZ conversion is available via command line:

xcrun usdz_converter file.obj file.usdz 

Preparing files for RealityKit

In Xcode 15+ you can use a Reality Composer Pro software for converting any RCP scene into usdz file format (right from UI). Also, there's a Reality Converter standalone app.

And, of course, you can use Autodesk Maya 2024 with Maya USD plugin.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220