adding a lot of custom nodes to scene takes a long time to load(将大量自定义节点添加到场景需要很长时间才能加载)
本文介绍了将大量自定义节点添加到场景需要很长时间才能加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个scenekit应用程序,但我遇到了一些更精细的细节问题。我创建了一个scene,我正在向它添加自定义几何体,它工作得很好,直到节点数量达到大约100个。向场景中添加大量节点是理想的,是否有更干净的方法?
for i in 0..<modelArr!.count {
let model = modelArr![i]
let pos: [SCNVector3] = Parser.loadPosition(model)
let norm:[SCNVector3] = Parser.loadNormals(model)
let ind:[CInt] = Parser.loadIndices(model)
let src = SCNGeometrySource(vertices: pos, count: pos.count)
let norSrc = SCNGeometrySource(normals: norm, count: norm.count)
//let indexData = NSData(bytes: ind, length: sizeof(CInt) * ind.count)
let indexData = NSData(bytes: Array<CInt>(0..<CInt(ind.count)),
length: ind.count * sizeof(Float))
let element = SCNGeometryElement(data: indexData,
primitiveType: .Triangles,
primitiveCount: pos.count / 3,
bytesPerIndex: sizeof(Float))
let geo = SCNGeometry(sources: [src, norSrc], elements: [element])
let material = SCNMaterial()
material.diffuse.contents = UIColor.redColor()
material.specular.contents = UIColor.whiteColor()
let cubeNode = SCNNode(geometry: geo)
cubeNode.geometry?.firstMaterial = material
emptyNode.addChildNode(cubeNode)
}
scn.rootNode.addChildNode(emptyNode)
}
我有大量的指数、法线和位置。
推荐答案
您可以做的一件事是使用Grand Central Dispatch和dispatch_apply(分发计算)和一个串行调度队列(使用每个新cubeNode更新emptyNode)来拆分负载。可以找到此方法的详细解释(使用不同的问题空间,但仍在尝试加快代价高昂的操作)in this answer。
这篇关于将大量自定义节点添加到场景需要很长时间才能加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:将大量自定义节点添加到场景需要很长时间才能加载
基础教程推荐
猜你喜欢
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
