Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SceneKit - Adding a new SCNNode to the scene causes severe lag

I found out that adding SCNNodes (with SCNGeometry) to the scene causes a severe lag spike.

According to the Time Profiler it has to generate the geometry (at least the functions/methods are called like that). It does that at the time when the node is added to the scene, not when the node is created. Hence, creating a pool with SCNNodes will not work.

Is there a way to get rid of this lag? I'd like to be able to add nodes to the scene without any FPS drop.

The only idea I have so far is adding everything to the scene already and then hiding / un-hiding it, though this is not really a clean solution.

Here's a shot from Time Profiler:

enter image description here

like image 468
Max Avatar asked Apr 07 '15 12:04

Max


1 Answers

looks like your are adding a node with an SCNShape or SCNText attached to it and these kinds of geometries are expensive to create (you have to discretize and triangulate the Bézier curve, and eventually have to compute and offset curve for the chamfer).

You can try to preload the following methods from SCNSceneRenderer : -prepareObject:shouldAbortBlock:, -prepareObjects:withCompletionHandler:

like image 93
mnuages Avatar answered Sep 18 '22 00:09

mnuages