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

房东的猫 提交于 2019-12-10 17:13:49

问题


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:


回答1:


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:



来源:https://stackoverflow.com/questions/29491483/scenekit-adding-a-new-scnnode-to-the-scene-causes-severe-lag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!