ios - 将几何体从一个场景复制到另一个场景

标签 ios objective-c macos swift scenekit

我正在使用 SceneKit 和 Swift(但 Objective-C 中的答案很好)。

我知道如何将 collada 文件加载到场景中。 (可以加载到节点中吗?)

这是我正在使用的 Swift 代码:

    let url = NSBundle.mainBundle().URLForResource("weasel", withExtension: "dae")
    var error: NSErrorPointer? = nil
    let weasel = SCNScene.sceneWithURL(url, options: nil, error: error!)

(我不确定我声明错误的方式有多惯用。请随意启发我。)

这似乎工作正常,但我现在想将此场景(或整个场景,这并不重要)中的某些内容插入到另一个场景中。我已经得到了类似的东西来编译和运行,但它似乎不起作用。

    let weaselNode = SCNNode()
    weaselNode.geometry = SCNNode(geometry: weasel.rootNode.geometry)
    scene.rootNode.addChildNode(weaselNode)

最佳答案

您可以轻松地将 Collada 文件的一部分加载到节点中。我还没有时间探索 Swift,所以这里是 ObjC:

    NSURL *urlToColladaFile = [[NSBundle mainBundle]URLForResource:@"ColladaFileName" withExtension:@"dae"];
    SCNSceneSource *sceneSource = [[SCNSceneSource alloc]initWithURL:urlToColladaFile options:nil]]
    SCNNode *node = [sceneSource entryWithIdentifier:@"uidInColladaFile" withClass:[SCNNode class]];
    [scene.rootNode addChildNode:node];

您可以通过将其插入代码中的某个位置来获取标识符列表:

    NSLog(@"Scene identifiers list: %@", [sceneSource identifiersOfEntriesWithClass:[SCNNode class]);

关于ios - 将几何体从一个场景复制到另一个场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026643/

相关文章:

ios - 在商业应用程序的 iOS 中使用 CorePlot 是否有任何限制?

objective-c - 是否可以有一个仅在该方法尚不存在时才加载的 Objective-C 类别?

objective-c - 按字母顺序OBJ-C识别字符

ios - 替代 iOS 9 的 UIAlertView?

json - 如何从 MacOS 上的 Excel 中的 HTTP 端点检索 JSON 并解析它?

ios - 如何处理多次写入,以便在一次写入失败时不提交数据?

ios - 如何使用 Imageview 实现切换行为,没有 UIButton

ios - opencv2 IOS 框架链接器错误

python - graph_tool osx 中缺少 graph_draw 吗?

macos - 在使用 Applescript 单击之前验证复选框