【问题标题】:renderer didUpdate for node function in ARKit not being executedARKit 中节点函数的渲染器 didUpdate 未执行
【发布时间】: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 的文本根本没有改变,并且平面从未添加到视图中。课堂是公开的。可能是什么原因?我该如何解决? 请帮忙。

谢谢。

【问题讨论】:

    标签: ios swift arkit


    【解决方案1】:

    这里的问题是您在完全设置配置之前运行了会话。任何会话配置代码都应该在运行会话之前完成。试试这个:

    override public func viewDidLoad() {
    
        sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
    
        view.addSubview(sceneView)
    
        sceneView.delegate = self
        sceneView.session.delegate = self
    
        // setup the plane detection FIRST
        configuration.planeDetection = .horizontal
    
        // then run the session
        sceneView.session.run(configuration)
    
        //Setup constraints
        setupConstraints()
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 2017-06-02
      • 1970-01-01
      • 2020-11-29
      • 2021-07-17
      • 1970-01-01
      • 2022-10-15
      • 2023-04-01
      • 2021-05-26
      相关资源
      最近更新 更多