Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created October 21, 2022 13:28
Show Gist options
  • Select an option

  • Save wizard1066/05992a1d4c3d818b023b116b684cbf7a to your computer and use it in GitHub Desktop.

Select an option

Save wizard1066/05992a1d4c3d818b023b116b684cbf7a to your computer and use it in GitHub Desktop.
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
view.addGestureRecognizer(panRecognizer)
@objc func handlePan(_ gestureRecognize: UIPanGestureRecognizer) {
let p = gestureRecognize.location(in: view)
let hitResults = view.hitTest(p, options: [:])
if hitResults.count > 0 {
let result = hitResults[hitResults.count - 1].node as? NewNode
let newPosition = p.scnVector3Value(view: view, depth: Float(result!.position.z))
reassignNode(newNode: result!, newPosition: newPosition)
}
}
func reassignNode(newNode: NewNode, newPosition:SCNVector3) {
let indexOf = nodes.firstIndex { (node) -> Bool in
node.uid == newNode.uid
}
if indexOf != nil {
newNode.position = newPosition
nodes[indexOf!] = newNode
} else {
assert(false,"NeverHappens")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment