8 Replies
      Latest reply on Mar 10, 2019 3:37 AM by vasu090
      vasu090 Level 1 Level 1 (0 points)

        Hello, I was making an app which detects a plane and puts a plane over it. But it seems as if the function is not being called. Here's the code:

         

         

            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 function

         

            override public func viewDidLoad() {
                sceneView.session.run(configuration)
                sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
                view.addSubview(sceneView)
                sceneView.delegate = self
                configuration.planeDetection = .horizontal
             
            }

         

        What's wrong? The mainLabel's text never changes...

         

        By the way, the viewDidLoad function is public because my class is a public class.