错误“OBJ文件没有面孔”
我想用ARKit和SceneKit放置一个obj-3D模型。
这就是我正在使用的模型: 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文件的编码。 特别是,问题是回车差异。
在终端会话中,运行以下命令:file testcube.obj(其中test cube是您的模型名称)
导致您提到的错误的文件的结果是:testcube.obj: 带有CR行终止符的ASCII文本
删除CR行终止符后,file命令的结果为:testcube.obj: ASCII文本
后者在XCode和Scenekit和Model IO中正确打开。
我只是复制了一个空的新行并用手动替换了新行,但是看看如何使用mac2unix命令代码如下: https ://stackoverflow.com/a/14080318/7426374