简体   繁体   中英

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. 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.

It sounds like your bottleneck is the transfer of the image onto the GPU. So how about preloading it? Instantiate the material before you need it. Then swap it out upon user action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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