错误 "OBJ file has no faces"

Error "OBJ file has no faces"

我想用 ARKit 和 SceneKit 放置一个 obj-3D-Model。

这是我正在使用的模型:https://free3d.com/3d-model/chest-50529.html

我正在使用以下代码:

private func createChestFromScene(_ position: SCNVector3) -> SCNNode? {
    guard let url = Bundle.main.url(forResource: "art.scnassets/Models/chest", withExtension: "obj") else {
        NSLog("Could not find door scene")
        return nil
    }
    guard let node = SCNReferenceNode(url: url) else { return nil }

    node.load()

    // Position scene
    node.position = position

    return node
}

但是,我收到以下错误:OBJ file has no faces

为什么? - 谢谢。

问题出在obj文件的编码上。特别是,问题是马车 return 差异。

在终端会话中,运行以下命令: 文件 testcube.obj(其中 test cube 是您的模型名称)

导致您提到的错误的文件的结果是: testcube.obj:ASCII 文本,带有 CR 行终止符

删除 CR 行终止符后,文件命令的结果是: testcube.obj: ASCII 文本

后者在 XCode 以及 Scenekit 和 Model IO 中正确打开。

我只是复制了一个空的新行并手动用新行替换了 CR,但请参阅以下关于如何使用 mac2unix 命令的答案: