How do you convert Wavefront OBJ file to SCNNode using model I / O

I imported the Wavefront OBJ file from the URL, and now I would like to paste it into my scene (SceneKit) in my iOS 9 application (in Swift). What i have done so far:

let asset = MDLAsset(URL: localFileUrl) print("count = \(asset.count)") // 1 

Any help converting this to SCNNode would be greatly appreciated. According to Apple docs:

The I / O model can share data buffers with the MetalKit, GLKit, and SceneKit frameworks to efficiently load, process, and render 3D assets.

But I'm not sure how to get the buffer from MDLAsset to SCNNode.

+5
source share
1 answer

Turns out it's pretty easy, since many of the ModelIO classes are already connected. I did import ModelIO , which gave me access to all ModelIO classes, as well as import SceneKit , which gave me SceneKit classes, but I missed import SceneKit.ModelIO to support SceneKit support for ModelIO.

 let url = NSURL(string: "url-to-your-obj-here") let asset = MDLAsset(URL: url!) let object = asset.objectAtIndex(0) let node = SCNNode(MDLObject: object) 

Easy as it is ...

+7
source

Source: https://habr.com/ru/post/1240135/


All Articles