【问题标题】:adding a lot of custom nodes to scene takes a long time to load向场景中添加大量自定义节点需要很长时间才能加载
【发布时间】:2016-08-15 08:10:57
【问题描述】:

我正在构建一个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)        
}

我有大量的索引、法线和位置。

【问题讨论】:

    标签: ios swift scenekit scnnode


    【解决方案1】:

    您可以做的一件事是使用 Grand Central Dispatch、dispatch_apply(分配计算)和串行调度队列(使用每个新的 cubeNode 更新 emptyNode 来拆分负载。对这种方法(使用不同的问题空间,但仍试图加快代价高昂的操作)可以在in this answer 找到。

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

    【讨论】:

      猜你喜欢
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 2014-08-15
      相关资源
      最近更新 更多