Using a bundle to load object file for MDLAsset

771 views Asked by At

I'm trying to load an .obj file to create an MDLAsset object in a macOS Swift app. Originally, I was creating the asset like so:

   let myAsset = URL(fileURLWithPath: "/Users/me/Development/MyProject/MyApp/Assets.xcassets/arrow.dataset/arrow.obj")
    arrowMdl = MDLAsset(url:arrow).object(at: 0)

Obviously that won't work when the app is in production - so, based off this SO answer, I tried adding the .obj file to a bundle, and then load it, like so:

    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)
    }

However, I keep getting the following error:

Error Domain=NSCocoaErrorDomain Code=257 "The file “Arrow.bundle” couldn’t be opened because you don’t have permission to view it." 

I made sure to set the permissions to read/write for everyone.

What am I doing wrong? Or, is there another way to load this asset? It looks as though MDLAsset requires a URL to for it to be initialized: https://developer.apple.com/documentation/modelio/mdlasset

0

There are 0 answers