How can I load multiple objects in SceneKit?

妖精的绣舞 提交于 2019-12-23 04:57:11

问题


I've made a scn file called arrowsign.scn which contains a arrow like the picture below:

I wrote a piece of code to load the arrow object:

SCNNode *node = [SCNNode node];
SCNNode *a[10];
for (int i = 0;i<10;i++){
    a[i] = [scene.rootNode childNodeWithName:@"arrowsign" recursively:NO];//just one arrow in arrowsign.scn
    a[i].scale = SCNVector3Make(0.15f, 0.15f, 0.15f);
    a[i].position = SCNVector3Make(1+i, 0, 0);
    [node addChildNode:a[i]];
}
[scene.rootNode addChildNode:node];

Ideally there will be a row of arrows displaying in the screen. However, there is just one arrow displaying. How can I achieve my goal?


回答1:


I think you can simply clone node

let sphereNode2 = sphereNode.clone()
sphereNode2.position = SCNVector3(x: 0, y: 0, z: -20)
scene.rootNode.addChildNode(sphereNode2)



回答2:


Instead of creating new SCNNode instances, create SCNReferenceNode instances in order to load your .scn file into them.



来源:https://stackoverflow.com/questions/42020392/how-can-i-load-multiple-objects-in-scenekit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!