Ios ARKIT:在一个SCNNode与另一个SCNNode之间画线时,观察滞后

Ios ARKIT:在一个SCNNode与另一个SCNNode之间画线时,观察滞后,ios,swift,xcode,augmented-reality,arkit,Ios,Swift,Xcode,Augmented Reality,Arkit,我画了线,并创建了一个具有尺寸的长方体。在iPhone8及以上版本上面临滞后问题,但在iPhone7上运行平稳 用于更新行: fileprivate func updateLine(_ line: SCNNode, from position: SCNVector3, distance: Float, axis: SCNVector3.Axis) { guard let box = line.geometry as? SCNBox else { fatal

我画了线,并创建了一个具有尺寸的长方体。在iPhone8及以上版本上面临滞后问题,但在iPhone7上运行平稳

用于更新行:

fileprivate func updateLine(_ line: SCNNode, from position: SCNVector3, distance: Float, axis: SCNVector3.Axis) {
        guard let box = line.geometry as? SCNBox else {
            fatalError("Tried to update something that is not a line")
        }
        
        let absDistance = CGFloat(abs(distance))
        let offset = distance * 0.5
        switch axis {
        case .x:
            box.width = absDistance
            line.position = position + SCNVector3(x: offset, y: 0, z: 0)
        case .y:
            box.height = absDistance
            line.position = position + SCNVector3(x: 0, y: offset, z: 0)
        case .z:
            box.length = absDistance
            line.position = position + SCNVector3(x: 0, y: 0, z: offset)
        }
    }

iphone7:

fileprivate func updateLine(_ line: SCNNode, from position: SCNVector3, distance: Float, axis: SCNVector3.Axis) {
        guard let box = line.geometry as? SCNBox else {
            fatalError("Tried to update something that is not a line")
        }
        
        let absDistance = CGFloat(abs(distance))
        let offset = distance * 0.5
        switch axis {
        case .x:
            box.width = absDistance
            line.position = position + SCNVector3(x: offset, y: 0, z: 0)
        case .y:
            box.height = absDistance
            line.position = position + SCNVector3(x: 0, y: offset, z: 0)
        case .z:
            box.length = absDistance
            line.position = position + SCNVector3(x: 0, y: 0, z: offset)
        }
    }
中央处理器:48%

内存:199MB

FPS:60

帧渲染时间:1.9毫秒

iPhone 8 Plus: 中央处理器:48%

内存:236MB

GPU:4.5

FPS:60

帧渲染时间:16.6毫秒


项目中没有内存泄漏。

我在iPhone8 plus和更高版本上遇到了滞后问题,但在iPhone7上绘制的线条工作顺利,所以我实现了

 // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
为了比较iPhone7和iPhone8 plus之间的差异,我注意到iPhone8 plus和更高版本需要18ms帧渲染时间,而iPhone7的帧渲染时间仅为1ms因此我将FPS从默认值60FPS减少

sceneView.preferredFramesPerSecond = 40
现在滞后的问题解决了