无法调用初始值设定项(ARKit)

时间:2017-07-25 20:18:20

标签: swift scenekit arkit

尝试在此处学习本教程 https://www.youtube.com/watch?v=tgPV_cRf2hA&feature=youtu.be&t=272

但在行上获得以下编译错误

  

让cubeNode = SCNNode(geometry:...

     

无法为类型' SCNBox'调用初始化程序。参数列表   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.
    }
}

2 个答案:

答案 0 :(得分:0)

SCNBox没有初始化程序,只需要宽度,高度和倒角半径。它有one that takes width, height, length, and chamfer radius

答案 1 :(得分:0)

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

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

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

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

也许更好的方法是在SCNNode的构造函数中使用它之前使对象保持不变并使用intellisense:

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

let cubeNode = SCNNode(geometry: box)