[英]How to use DAE file with different Scene Graphs in iOS SceneKit
I have an .dae file and want to use the model in SceneKit. 我有一个.dae文件,想在SceneKit中使用该模型。 The problem is that the .dae file has different Scene Graphs in it:
问题在于.dae文件中具有不同的场景图:
In my ViewController.swift I have this code: 在我的ViewController.swift中,我有以下代码:
let scene = SCNScene(named: "art.scnassets/Edward_Kenway.dae")!
self.baumNode = scene.rootNode.childNode(withName: "???", recursively: true)
What do I have to use in the childNode withName? 我必须在childNode withName中使用什么? If I select the first Scene graph (EdwardKenwayNecklace) and put the name of the Geometry (EdwardKenwayNecklaceMesh) in my code the application crashes.
如果选择第一个“场景”图(EdwardKenwayNecklace)并将几何名称(EdwardKenwayNecklaceMesh)放入代码中,则应用程序将崩溃。
You can loop through the child nodes of the scene and then add them all to a new node that you have made. 您可以遍历场景的子节点,然后将它们全部添加到您创建的新节点中。
Something like this might work, assuming that this is what you are looking for. 假设这就是您要寻找的东西,则可能会起作用。
func loadModel() {
let virtualObjectScene = SCNScene(named: path)
let wrapperNode = SCNNode()
for child: SCNNode in virtualObjectScene?.rootNode?.childNodes {
wrapperNode.addChildNode(child)
}
addChildNode(wrapperNode)
}
where the path is the name of your scene. 路径是场景的名称。 This function is run after initializing an object of type SCNNode, and then calling loadModel on this object.
初始化类型为SCNNode的对象,然后在该对象上调用loadModel后,将运行此函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.