我知道,当你第一次将它添加到场景中时,你可以通过做这样的事情来将球体或飞机的表面设置为图像。在iOS SceneKit中更新几何表面的正确方法是什么?
UIImage image = UIImage.FromFile("firstimage.jpg");
Sphere.FirstMaterial.Diffuse.Contents = image;
但是,当你想要在用户操作中更新它...喜欢说按钮点击。现在我做这样的事情。
UIImage newImage = UIImage.FromFile("secondimage.jpg");
//digs through the scnview and the scene, into it's child nodes, finds the geometry and replaces the image
mySCNView.Scene.RootNode.ChildNodes[0].Geometry.FirstMaterial.Diffuse.Contents = newImage;
但是,这似乎有点混乱,实际上需要大约2或3秒才能完成。我并不特别担心数组索引硬编码。
有没有更有效的方法来进行这种更新?
P.S.我为一些有趣的代码行道歉,这实际上是用Xamarin.iOS编写的,但可以在Swift或C中自由地回答,我会进行翻译。
哪部分速度慢?加载图像,查找节点或更新材料? –
更新素材 –