如何从.usdz创建SCNNode? [英] How to create a SCNNode from a .usdz?
本文介绍了如何从.usdz创建SCNNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经下载了Apple提供的.usdz模型: https://developer.apple.com/arkit/gallery/
I have downloaded the .usdz models provided by Apple: https://developer.apple.com/arkit/gallery/
但是现在,我想使用这些模型之一创建一个SCNNode,所以我这样做是为了获得该节点:
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:
为什么没有纹理?
我将下载的.usdz文件保存到项目目录中的文件夹中,如您所见:
I have the downloaded .usdz files into a folder in my project directory as you can see:
推荐答案
添加.USDZ对象的正确方法实际上是使用文件的URL创建场景:
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()
这篇关于如何从.usdz创建SCNNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文