我正在尝试加载 .obj 文件以MDLAsset
在 macOS Swift 应用程序中创建对象。最初,我是这样创建资产的:
let myAsset = URL(fileURLWithPath: "/Users/me/Development/MyProject/MyApp/Assets.xcassets/arrow.dataset/arrow.obj")
arrowMdl = MDLAsset(url:arrow).object(at: 0)
显然,当应用程序处于生产状态时,这将不起作用 - 因此,根据这个SO 答案,我尝试将 .obj 文件添加到包中,然后加载它,如下所示:
let path: String = Bundle.main.path(forResource: "Arrow", ofType: "bundle")!
do {
let arrowPath = try String(contentsOfFile: path)
}
catch let error as NSError {
print(error.description)
}
但是,我不断收到以下错误:
Error Domain=NSCocoaErrorDomain Code=257 "The file “Arrow.bundle” couldn’t be opened because you don’t have permission to view it."
我确保为每个人设置读/写权限。
我究竟做错了什么?或者,是否有另一种方式来加载此资产?看起来好像MDLAsset
需要一个 URL 才能对其进行初始化:https ://developer.apple.com/documentation/modelio/mdlasset