0

My program creates two nodes:

let scene1 = SCNScene(named: "wheelbarrow.usdz")!
let scene2 = SCNScene(named: "tv_retro.usdz")!

let firstNode = scene1.rootNode.childNode(withName: "wheelbarrow", recursively: true)!
firstNode.position.x = -100
let secondNode = scene2.rootNode.childNode(withName: "tv_retro", recursively: true)!
secondNode.position.x = 100
        
sceneView.scene?.rootNode.addChildNode(firstNode)
sceneView.scene?.rootNode.addChildNode(secondNode)

How do I add a drag and drop gesture for each node?

0-1
  • 702
  • 1
  • 10
  • 30
  • There is no such thing as a "Drag and Drop" Gesture. I assume, you want to be able to "pick-up" an object like with you finger touching the screen and when the Finger gets released the Object stays at it's new place. You can use i.Ex. a Pan Gesture Handler, that performs a hitTest on Touches Began, if the object is found you modify the position during Touches Changed Sequence and released on Touches ended event. Note, you will have to add some location point unprojection, because you are in 3D Space. Search for tutorials how to do this stuff. Good luck! – ZAY Jan 25 '21 at 09:03
  • I know all this, but when I write the drag-and-drop code, the panning gesture is disabled. I would like to see an example code with a coordinator – Novol_vlad Jan 25 '21 at 15:58
  • Maybe this can help you, it's for ARKit. You can try to make a SceneKit only implementation: https://stackoverflow.com/questions/50131675/arkit-move-object-with-pangesture-the-right-way/56236958#56236958 – ZAY Jan 25 '21 at 16:49
  • It uses VirtualObject () instead of SCNNode. This example didn't give me any implementation ideas – Novol_vlad Jan 25 '21 at 17:23

0 Answers0