在模型 I/O 中,提供的库中缺少记录的 API。解决方法是什么?

In Model I/O documented API is missing in the provided libraries. What is the work around?

尽管记录了以下 MDLAsset class 方法在 ModelIO 库中不存在:

+ assetWithSCNScene:bufferAllocator:



+ assetWithSCNScene:

因此,目前无法读取 SceneKit .scn 文件并创建 MDLAsset.

解决方法是什么?

更新 0

我正在导入这些:

import SceneKit
import ModelIO
import MetalKit
import GLKit

在我的渲染器中,我尝试从 SCNScene:

实例化 MDLAsset
guard let scene = SCNScene(named:"ball.scn") else {
    fatalError("Error: Can not create scene")
}

let asset = MDLAsset(scnScene:scene, bufferAllocator:MTKMeshBufferAllocator(device: device))

我收到这个错误

表示找不到类别。我在这里错过了什么?

这些被 SceneKit 定义为 MDLAsset 上的类别(这是必要的,因为那是定义 SCNScene 的地方)。您需要 @import SceneKit 以及 @import ModelIO


您已经在 ObjC 中列出了签名;没有注意到您标记了它 Swift。 Swift中需要导入相关子模块:

import SceneKit.ModelIO

在我看来,这实际上有点奇怪,可能没有必要。我会打开雷达 (bugreport.apple.com)。至少,文档需要更清晰。

您正在混合和匹配三个不同的框架,这就是该类别不起作用的原因。

MTKMeshBufferAllocator 是 MetalKit 的一部分,SceneKit 不知道如何处理分配。

只要离开 bufferAllocator 就可以了。

let asset = MDLAsset(scnScene:scene)

关于导入的问题,

import SceneKit.ModelIO

为您提供 API 的桥梁。它的目的是允许您从 MDL 对象构造 SCN 对象。