如何在 SceneKit 中加载多个对象? [英] How can I load multiple objects in SceneKit?

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

问题描述

我制作了一个名为 arrowsign.scn 的 scn 文件,其中包含一个如下图所示的箭头:

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?

推荐答案

我认为你可以简单地克隆节点

I think you can simply clone node

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

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

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