SceneKit ModelIO broken?

I am trying to create ModelIO Meshes from SceneKit data. As a simple example, I see in the documentation for MDLMesh that:


"

Objects from SceneKit


init(scnGeometry: SCNGeometry, bufferAllocator: MDLMeshBufferAllocator?)

Creates a mesh from the specified SceneKit geometry, using the specified allocator.


init(scnGeometry: SCNGeometry)

Creates a mesh from the specified SceneKit geometry.

"


So I am at a loss as to why the following code doesn't work:

import Foundation
import ModelIO
import SceneKit
import MetalKit

class WhyNotWorking {
    init() {
        let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0.0)
        let mesh = MDLMesh(scnGeometry: box, bufferAllocator: nil)
    }
}

This gives me an error that:

Expression type 'MDLMesh' is ambiguous without more context. Looking into the MDLMesh.h file I don't see any referene to the initializer noted in the documentation.


Am I missing something here?

Accepted Reply

Hello,


You need to import SceneKit.ModelIO to use that convenience initializer 🙂


import Foundation
import ModelIO
import SceneKit
import MetalKit
import SceneKit.ModelIO
 
class WhyNotWorking {
    init() {
        let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0.0)
        let mesh = MDLMesh(scnGeometry: box, bufferAllocator: nil)
    }
}

Replies

Hello,


You need to import SceneKit.ModelIO to use that convenience initializer 🙂


import Foundation
import ModelIO
import SceneKit
import MetalKit
import SceneKit.ModelIO
 
class WhyNotWorking {
    init() {
        let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0.0)
        let mesh = MDLMesh(scnGeometry: box, bufferAllocator: nil)
    }
}