gpt4 book ai didi

ios - 从场景加载节点后应用程序卡住

转载 作者:行者123 更新时间:2023-11-28 07:30:53 25 4
gpt4 key购买 nike

我正在使用 ARKit 创建一个应用程序,它运行良好。我遇到的唯一问题是,如果我想显示某个节点,应用程序会卡住大约一秒钟。我想不出解决问题的办法。对相同的对象尝试了相同的代码,只是纹理较少,它没有卡住。

场景是 4.2mb,但有很多纹理。在 iOS 12.1.0 iPhone Xs Max 上测试。

   guard let scene = SCNScene(named: "myScene.scn") else { return }

if let nodeToDisplay = scene.rootNode.childNode(withName: "nameOfNode", recursively: true) {

self.sceneView.scene.rootNode.addChildNode(nodeToDisplay)
}

最佳答案

尝试使用 prepare(_:completionHandler:)添加您的节点。

By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. SceneKit uses a secondary thread to prepare content asynchronously.

所以你的代码应该是这样的:

self.sceneView.prepare(nodeToDisplay) { (success) in
self.sceneView.scene.rootNode.addChildNode(nodeToDisplay)
}

关于ios - 从场景加载节点后应用程序卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54744540/

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