【发布时间】:2019-08-26 19:12:46
【问题描述】:
我试图在 XCode 中运行以下代码:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
// Checking if the planeAnchor exists
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
// Declaring some variables for future use
let width = CGFloat(planeAnchor.extent.x)
let height = CGFloat(planeAnchor.extent.z)
//The plane(geometry) for the node
let plane = SCNPlane(width: width, height: height)
// The planeNode for the plane anchor
let planeNode = SCNNode(geometry: plane)
//Setting up the plane node
planeNode.geometry?.firstMaterial?.diffuse.contents = UIColor.init(red: 0, green: 0, blue: 1, alpha: 0.4)
planeNode.geometry?.firstMaterial?.isDoubleSided = true
// Some variables for future use
let x = CGFloat(planeAnchor.center.x)
let y = CGFloat(planeAnchor.center.y)
let z = CGFloat(planeAnchor.center.z)
// The plane node's position
planeNode.position = SCNVector3(x,y,z)
// This is done so that the plane node is horizontal
planeNode.eulerAngles.x = -.pi / 2
// Adding the planeNode to the rootNode??
node.addChildNode(planeNode)
// Informing the user that a plane anchor has been found
mainLabel.text = "Found a plane anchor!"
}
这里是 viewDidLoad 函数的代码:
override public func viewDidLoad() {
sceneView.session.run(configuration)
sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
view.addSubview(sceneView)
sceneView.delegate = self
sceneView.session.delegate = self
configuration.planeDetection = .horizontal
//Setup constraints
setupConstraints()
}
由于某种原因,渲染器 didUpdate 节点 forAnchor 函数没有被执行。 mainLabel 的文本根本没有改变,并且平面从未添加到视图中。课堂是公开的。可能是什么原因?我该如何解决? 请帮忙。
谢谢。
【问题讨论】: