gpt4 book ai didi

swift - ARKit – 将场景保存为 USDZ?

转载 作者:搜寻专家 更新时间:2023-11-01 05:33:02 28 4
gpt4 key购买 nike

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

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

但是否可以将场景保存为 USDZ 文件并加载回来?

最佳答案

首先,阅读以下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 11/12/13/14 中,您可以通过命令行将几种流行的输入格式转换为 USDZ:obj, gltffbxabcusd(x)

usdzconvert file.gltf

在Xcode 10中,只有OBJ-to-USDZ,单帧ABC-to-USDZ USD(x)-to-USDZ 可通过命令行进行转换:

xcrun usdz_converter file.obj file.usdz 

为 RealityKit 准备文件

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

当然,您可以使用 Autodesk Maya 2020 | 2022 | 年2023 与 Maya USD plugin .

关于swift - ARKit – 将场景保存为 USDZ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51059875/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com