iosswiftarkitscnnodeusdz

How to create a SCNNode from a .usdz?


I have downloaded the .usdz models provided by Apple: https://developer.apple.com/arkit/gallery/

But now, I want to create a SCNNode with one of these models, so I am doing this to obtain the node:

guard let urlPath = Bundle.main.url(forResource: "retrotv", withExtension: "usdz") else {
    return
}
let mdlAsset = MDLAsset(url: urlPath)
let modelRootNode = SCNScene(mdlAsset: mdlAsset).rootNode

Then I add it to the scene and the result is this:

enter image description here

Why does it have no textures?

I have the downloaded .usdz files into a folder in my project directory as you can see:

enter image description here


Solution

  • The correct way to add the .USDZ object is actually creating the scene with the file's URL:

     let scene = try! SCNScene(url: usdzURL, options: [.checkConsistency: true])
    

    Or even creating via Reference Node:

     let referenceNode = SCNReferenceNode(url: usdzURL)
     referenceNode.load()