1

Although documented the following MDLAsset class methods do not exist in the ModelIO library:

+ assetWithSCNScene:bufferAllocator:



+ assetWithSCNScene:

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

What is the work around?

UPDATE 0

I am importing these:

import SceneKit
import ModelIO
import MetalKit
import GLKit

In my renderer I attempt to instantiate an MDLAsset from an SCNScene:

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?

dugla
  • 12,774
  • 26
  • 88
  • 136

2 Answers2

1

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.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
1

You're mixing and matching three different frameworks, that's why the category isn't working.

MTKMeshBufferAllocator is part of MetalKit, and SceneKit won't know what to do with the allocation.

Just leave off the bufferAllocator and you should be fine.

let asset = MDLAsset(scnScene:scene)

On the question of importing,

import SceneKit.ModelIO

gives you the bridging API's. It's purpose is to allow you to construct SCN objects from MDL objects.

  • This was answered a year ago. What new value does your answer bring? – Maciej Jureczko Sep 01 '17 at 18:24
  • 1
    The new value is in correcting Rob's statement that importing the file shouldn't be necessary. Importing SceneKit.ModelIO is necessary in order to move a Model IO asset into SceneKit. (FWIW I architected ModelIO and the SceneKit bridge.) – Nick Porcino Oct 03 '17 at 17:19
  • Well it could probably be added as a comment to his answer then, but alright, fair enough, it provides useful information about what was asked. – Maciej Jureczko Oct 03 '17 at 18:51
  • That's what I had intended :) I'm a stackoverflow n00b... I will pay attention to that workflow in the future. I should also point out that there is also the bufferAllocator issue not addressed in Rob's statement, I'm hoping that will be useful to others in future visits to this question. – Nick Porcino Oct 03 '17 at 22:58