无法调用初始化程序 (ARKit)

cannot invoke initializer (ARKit)

正在尝试按照此处的教程进行操作 https://www.youtube.com/watch?v=tgPV_cRf2hA&feature=youtu.be&t=272

但在

行出现以下编译错误

let cubeNode = SCNNode(geometry:...

Cannot invoke initializer for type 'SCNBox' with an argument list of type '(width: Double, height: Double, chamferRadius: Int)'

import UIKit
import ARKit
import SceneKit


class ViewController: UIViewController {

    @IBOutlet weak var sceneView: ARSCNView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let configuration = ARWorldTrackingSessionConfiguration()
        configuration.planeDetection = .horizontal
        sceneView.session.run(configuration)
    }
    @IBAction func addCube(_ sender: Any) {
        let cubeNode = SCNNode(geometry: SCNBox(width:0.1, height:0.1, chamferRadius:0))
        cubeNode.position = SCNVector3(0,0,-0.2)//This is in metres
        sceneView.scene.rootNode.addChildNode(cubeNode)
    }

    @IBAction func addCup(_ sender: Any) {
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

SCNBox 没有仅采用宽度、高度和倒角半径的初始化程序。它有 one that takes width, height, length, and chamfer radius.

根据 apple 文档,SCNBox 对象的构造函数有 4 个参数:

init(width: CGFloat, height: CGFloat, length: CGFloat, chamferRadius: CGFloat)

所以你只需要在构造函数中添加lenght参数,参见API参考:

https://developer.apple.com/documentation/scenekit/scnbox

也许更好的方法是在 SCNNode 的构造函数中使用它之前将对象设为常量并使用智能感知:

let box = SCNBox(width:0.1, height:0.1,lenght: 0.1, chamferRadius:0)

let cubeNode = SCNNode(geometry: box)