我希望显示相同的SCNGeometry
1000次,但是使用特定的动画(例如旋转,移动的SCNActions ......)和不同的图像作为漫反射材质.
在检查文档和漂亮的WWDC演示文稿后,我发现创建一个节点的最佳方法是(因此它被称为1000次)
//self is a SCNNode //helper.getStar3D() is a SCNNode template which has been flattened //the geometry is light (36 triangles according to scenekit statistic) //need to copy the geometry and material so it is not shared by all nodes self.geometry=helper.getStar3D().geometry.copy() as SCNGeometry self.geometry.firstMaterial = helper.getStar3D().geometry.firstMaterial.copy() as SCNMaterial // texture has been extracted from a SKTextureAtlas self.geometry.firstMaterial.diffuse.contents=allTextures.firstObject as SKTexture
然而在iPad Air上,我只能达到40fps(当使用更新firstMaterial.diffuse.contents的块通过SCNAction动画纹理时为27 fps)
我认为使用SKTextureAtlas(因此所有图像都在相同的纹理上)并使用相同的几何体(显然当你复制几何体时,数据是共享的 - 参见使用sceneKit构建游戏),我会得到更多的fps,因为它应该允许OpenGL优化.我尝试使用SceneKit的很多参数但没有成功.
对于通知:SceneKit统计信息告诉我有1000个绘制调用,Xcode中的Graphics stats是:cpu 18ms,GPU是22ms,tiler 18%,渲染器80%,设备88%(不能等待新的SceneKit统计Xcode中的模块!)
所以我的问题是:你认为这是正常的表现还是有办法优化我想在SceneKit做什么?谢谢!
编辑:实际上SKTextureAtlas似乎并没有优化渲染,但似乎降低了帧速率.如果我使用UIImage代替来自SKTextureAtlas的SKTexture,我的性能提高了25%(50fps).动画纹理(每0.2秒更新每个对象的纹理)实际上是使用SKTextureAtlas或UIImages来消除性能(20fps).我想我在这里遗漏了一些东西,因为SKTextureAtlas通常用于优化.