我正在使用 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/