ARKit - 如何将场景保存为USDZ格式?

4

现在,我可以将我在ARKit中创建的内容保存为场景文件,并在以后加载。

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

但是,是否有可能将场景保存为USDZ文件并重新加载它呢?

1个回答

4
首先,阅读下面的非常有帮助的 SO post

通过编程从SCN创建USDZ

在SceneKit中,有一个write(to:options:delegate:progressHandler:)实例方法可以完成这个任务(你需要做的唯一一件事就是为URL指定文件格式)。

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

使用SceneKit.ModelIO将OBJ转换为USDZ

然而,如果你需要将OBJ模型转换为USDZ,首先要导入SceneKit.ModelIO模块。然后使用以下代码:

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

终端方法

在Xcode 15/14/13/12/11中,您可以通过命令行将几种常见的输入格式转换为USDZobjgltffbxabcusd(x)

usdzconvert file.gltf

在Xcode 10中,只能通过命令行进行OBJ-to-USDZ、单帧ABC-to-USDZUSD(x)-to-USDZ的转换。
xcrun usdz_converter file.obj file.usdz 

为RealityKit准备文件

在Xcode 15+中,您可以使用Reality Composer Pro软件将任何RCP场景转换为usdz文件格式(直接从UI进行转换)。此外,还有一个独立的Reality Converter应用程序。

当然,您也可以使用带有Maya USD插件的Autodesk Maya 2024。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接