Remove complete .scn instead of individual nodes Swift ARKit

57 views Asked by At

I am attempting to delete the .scn objects I placed down. However, with my current code, it is just deleting individual nodes. Here is how I handle the tap delete.

    
@objc func Erase(sender: UITapGestureRecognizer){
    print("rendering")
    //sharedVM.count = sharedVM.count + 1
    guard let pointOfView = sceneView.pointOfView else {return}

    guard let cameraPosition = getCameraPosition(in: sceneView) else {
       return
    }
       
       
   let location = sender.location(in: view)
   let currentPositionOfCamera = cameraPosition + getRay(for: location, in: sceneView)
       
    DispatchQueue.main.async{
       //guard let location = touches.first?.location(in: sceneView) else { return }
       
       let results = self.sceneView.hitTest(location, options: [SCNHitTestOption.searchMode : 1])
       for result in results {  /// See if the beam hit the cube
           let Node = result.node
           Node.enumerateChildNodes { (node, stop) in
               node.removeFromParentNode() }
           Node.removeFromParentNode()
       }
       
    }
}

Here is how I place the object:

var objecttest = VirtualObject(url: referenceURL)!
                    
//var objecttest = VirtualObject(url: URL(string: "Models.scnassets/cup/cup.scn")!)
objecttest.load()
self.sceneView.scene.rootNode.addChildNode(objecttest)

class VirtualObject: SCNReferenceNode {
...
}

enter image description here

enter image description here

0

There are 0 answers