如何在iOS SceneKit中将.dae文件加载到SCNNode中? [英] How do you load a .dae file into an SCNNode in iOS SceneKit?

查看:685
本文介绍了如何在iOS SceneKit中将.dae文件加载到SCNNode中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解如何将 .dae 文件中的几何图形加载到iOS SceneKit场景图中。

I am having trouble understanding how geometry from .dae files should be loaded into an iOS SceneKit scene graph.

我知道您可以将 .dae 文件直接加载到SCNScene中:

I know that you can load .dae files directly into an SCNScene:

// create a new scene
let scene = SCNScene("test.scnassets/test.dae")

我也知道你可以创建一个空的SCNScene并将内置的3D对象作为子节点添加到其中:

I also know that you can create an empty SCNScene and add built-in 3D objects into it as child nodes:

let scene = SCNScene()
var sphereNode = SCNNode()
sphereNode.geometry = SCNSphere(radius: 1.0)
scene.rootNode.addChildNode(sphereNode)

在第二种情况下,您可以加载 .dae 文件进入SCNNode而不是使用内置对象?或者是否需要首先将所有 .dae 文件加载到SCNScene?

In the second case, can you load a .dae file into SCNNode instead of using built in objects? Or is it expected that all .dae files need to be loaded into the SCNScene first?

如果后者为真,那么如何将SCNNode对象放置在SCNScene下的场景图层次结构中的正确位置?编辑#1:

If the latter is true, how then do you place the SCNNode objects into the right place in the scene graph hierarchy under SCNScene?EDIT #1:

现在这对我有用,这是@FlippinFun建议的修改版本。

This is working for me now, which is modified version of what @FlippinFun suggested.

let url = NSBundle.mainBundle().URLForResource("test.scnassets/test", withExtension: "dae")
let source = SCNSceneSource(URL: url, options: nil)
let block = source.entryWithIdentifier("ID10", withClass: SCNGeometry.self) as SCNGeometry
scene.rootNode.addChildNode(SCNNode(geometry: block))

但也许有更好的方法?以上涉及从.dae树手动加载每个标识符。在我的文件中,有一个带有子标识符ID2和ID10的节点SketchUp。此方法不允许您加载根SketchUp。 (我收到运行时错误。)

But perhaps there's a better way? The above involves manually loading each identifier from the .dae tree. In my file, there's a node "SketchUp" with child identifiers "ID2" and "ID10". This method will not let you load the root "SketchUp". (I get a runtime error.)

推荐答案

通常的模式是加载场景并检索您感兴趣的节点其名称使用

The usual pattern is to load your scene and retrieve the node you are interested in with its name using

[scene.rootNode childNodeWithName:aName recursively:YES];

然后你可以将这个节点重新显示到你的主场景。

Then you can reparent this node to your main scene.

这篇关于如何在iOS SceneKit中将.dae文件加载到SCNNode中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆