Currently I'm working on AR Based project which has the functionality of duplicating the AR Object , the problem Im having is when i use .clone() method to clone SCNNode ... it creates same instances and when i change name of duplicated SCNNode , it change name of all nodes .. How can i clone the SCNNode with having different name,modelName etc properties ?
Basically i want specific property of every cloned Virtual Object to delete the object ..
Code for placing Object
func placeVirtualObject(_ virtualObject: VirtualObject) {
guard let cameraTransform = session.currentFrame?.camera.transform,
let focusSquarePosition = focusSquare.lastPosition else {
statusViewController.showMessage("CANNOT PLACE OBJECT\nTry moving left or right.")
return
}
Api.Params.selectedModel = virtualObject
virtualObject.name = String(Api.Params.inputPreviewId)
virtualObject.scale = SCNVector3Make(0.01, 0.01, 0.01)
virtualObject.setPosition(focusSquarePosition, relativeTo: cameraTransform, smoothMovement: false)
updateQueue.async {
self.sceneView.scene.rootNode.addChildNode(virtualObject)
}
}
for duplicating node
func placeDuplicateVirtualObject(_ virtualObject: VirtualObject) {
guard let cameraTransform = session.currentFrame?.camera.transform,
let focusSquarePosition = focusSquare.lastPosition else {
statusViewController.showMessage("CANNOT PLACE OBJECT\nTry moving left or right.")
return
}
Api.Params.selectedModel = virtualObject
let duplicate = virtualObject.clone()
duplicate.name = String(Api.Params.inputPreviewId)
duplicate.scale = SCNVector3Make(0.01, 0.01, 0.01)
duplicate.setPosition(focusSquarePosition, relativeTo: cameraTransform, smoothMovement: false)
updateQueue.async {
self.sceneView.scene.rootNode.addChildNode(duplicate)
}
}