gpt4 book ai didi

ios - 向场景添加大量自定义节点需要很长时间才能加载

转载 作者:行者123 更新时间:2023-11-28 08:30:33 24 4
gpt4 key购买 nike

我正在构建一个 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(分配计算)和串行调度队列(更新 emptyNode每个新的 cubeNode。可以在 in this answer 中找到对这种方法的详尽解释(使用不同的问题空间,但仍试图加速昂贵的操作)。

在单独的实用程序中进行加载会有很大帮助。创建场景后,将其存档。将该场景嵌入到面向用户的程序中。取消存档场景比从头开始创建要快得多。

关于ios - 向场景添加大量自定义节点需要很长时间才能加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38941570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com