How to create a SCNNode from a .usdz?

耗尽温柔 提交于 2019-12-13 15:27:15

问题


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:

Why does it have no textures?

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


回答1:


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()


来源:https://stackoverflow.com/questions/53317392/how-to-create-a-scnnode-from-a-usdz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!