Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding that brief 'Empty Screen' using SceneKit

I'm making a scene kit app and it all works very nicely indeed. My only annoyance is that for a brief second after loading, my SCNView object is completely blank. I presume that this is because the scene hasn't loaded or rendered yet, but I'd like to avoid it if possible.

I tried putting a masking view mimicking the app's loading screen in front of the SCNView and fading it out once rendering began using renderer:didRenderScene:atTime but alas, the animation for fading out the masking view doesn't happen (it just flashes off immediately instead of fading out). So I put the masking view in the app's main window as an experiment and gave it a short delay. However, even with the delay before removing that mask, the SCNView was still entirely blank for a split second before the scene appeared.

Can anyone tell me how to avoid this annoying graphical artefact?

like image 613
Ash Avatar asked Jan 08 '23 17:01

Ash


1 Answers

As usual there is a simple fix that I just failed to find until now. After your scene has been completely set up, simply do:

sceneView.prepareObject(scene, shouldAbortBlock:nil)

...and bingo! No delay. It's caused because scenes, like all objects in a SCNView, are lazily loaded. Calling prepareObject lets you cache them in advance.

like image 80
Ash Avatar answered Jan 20 '23 03:01

Ash