简体   繁体   English

在iOS SceneKit中更新几何表面的正确方法是什么?

[英]What is the proper way to update a Geometry surface in iOS SceneKit?

I am aware that you can set the surface of a sphere or a plane as an image by doing something like this when you first add it to the scene. 我知道你可以在第一次将球体或平面添加到场景时通过这样的方式将球体或平面的表面设置为图像。

            UIImage image = UIImage.FromFile("firstimage.jpg");
            Sphere.FirstMaterial.Diffuse.Contents = image;

But what about when you want to update it on user action... like say on button click. 但是,当您想要在用户操作上更新它时...就像点击按钮一样。 Right now I do something like this. 现在我做这样的事情。

            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;

But this seems kind of messy and actually takes about 2 or 3 seconds to complete. 但这看起来有点乱,实际上需要2到3秒才能完成。 I'm not particularly worried about the array index hardcode. 我并不特别担心数组索引硬编码。

Is there a more efficient way to go about this kind of update? 有没有更有效的方式来进行这种更新?

PS I apologize for some funny looking lines of code, this is actually being written in Xamarin.iOS, but feel free to answer in Swift or C and I'll do the translation. PS我为一些有趣的代码行道歉,这实际上是用Xamarin.iOS编写的,但是可以随意在Swift或C中回答,我会做翻译。

It sounds like your bottleneck is the transfer of the image onto the GPU. 听起来你的瓶颈是将图像传输到GPU上。 So how about preloading it? 那么预加载怎么样? Instantiate the material before you need it. 在需要之前实例化材料。 Then swap it out upon user action. 然后在用户操作时将其交换出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM