dugla dugla - 10 months ago 49
Swift Question

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

Although documented the following

class methods do not exist in the

+ assetWithSCNScene:bufferAllocator:

+ assetWithSCNScene:

So, currently there is no way to read in a
.scn file and create an

What is the work around?


I am importing these:

import SceneKit
import ModelIO
import MetalKit
import GLKit

In my renderer I attempt to instantiate an
from an

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

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

I get this error

enter image description here

Indicating the category cannot be found. What have I missed here?

Answer Source

These are defined as a category on MDLAsset by SceneKit (which is necessary, because that's where SCNScene is defined). You need to @import SceneKit as well as @import ModelIO.

You'd listed the signatures in ObjC; didn't note that you'd tagged it Swift. In Swift, you need to import the relevant submodule:

import SceneKit.ModelIO

That's actually a bit strange IMO, and probably shouldn't be necessary. I'd open a radar (bugreport.apple.com). At the very least, the docs need to be clearer.