I am developing an AR app about human anatomy. I setup AR and place detection and everything works fine. I need to change or replace the current model with something else. For example, the first model is the human body and then I need to change it with a button to a skeleton. I tried different ways for example if I change SCNNode
only it doesn't replace with the exact position. So what is the best way to replace a scene or node in AR? here is my code:
override func viewDidLoad() {
super.viewDidLoad()
sceneView = ARSCNView(frame: view.frame)
sceneView.delegate = self
ARView.addSubview(sceneView)
// Create a new scene
bodyScene = SCNScene(named: "art.scnassets/test.dae")!
bodyNode = bodyScene.rootNode.childNode(withName: "Cube", recursively: true)
let scale:Float = 0.1
bodyNode.scale = SCNVector3(x: scale, y: scale, z: scale)
bodyNode.isHidden = true
sceneView.scene = bodyScene
sceneView.autoenablesDefaultLighting = true
sceneView.automaticallyUpdatesLighting = true
ARView.addSubview(ARGuideView)
//Foucus
setupFocusSquare()
}
You have to use Remove the bodyNode, if you want to add any other node in the scene By adding this line you can remove bodyNode:
And if you want just want to replact the bodyNode then simply declare your bodyNode as global and change reinitialize when you want to change/replace it.