尝试在此处https://www.youtube.com/watch?v=tgPV_cRf2hA&feature=youtu.be&t=272遵循本教程
但是在行上出现以下编译错误
让 cubeNode = SCNNode(geometry:...
无法为类型为'(width:Double,height:Double,chamferRadius:Int)'的参数列表调用'SCNBox'类型的初始化程序
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 回答
根据 Apple 文档,SCNBox 对象的构造函数具有 4 个参数:
因此,您只需要向构造函数添加 lenght 参数,请参阅 API 参考:
https://developer.apple.com/documentation/scenekit/scnbox
也许更好的方法是在将对象用于 SCNNode 的构造函数中并使用 intellisense 之前,使对象成为常量。
SCNBox
没有仅包含宽度,高度和倒角半径的初始化程序。它有需要宽度,高度,长度和倒角半径的一个。