0

I'm trying to retrieve the mouse location after a user clicks on a specific SCNNode. I eventually want to perform a hit test to determine which SCNNode was clicked. I have the following code but once I run the project I get an assertion error stating: "Cannot get locationInView: for this type of NSTouch". Any help would be appreciated.

override func touchesBegan(with event: NSEvent) {
    let touch = event.touches(for: self.view)
    if #available(OSX 10.12.2, *) {
        let location = touch.first?.location(in: self.view)
        let hitResults = sceneView.hitTest(location!, options: nil)

    } else {
        // Fallback on earlier versions
    }
}
mnuages
  • 13,049
  • 2
  • 23
  • 40

1 Answers1

0

-locationInView: will only work for touches of type NSTouchTypeDirect. If you have a Mac with a Touch Bar, pressing it will lead to an event with a touch of type NSTouchTypeIndirect which has no location on the screen.

mnuages
  • 13,049
  • 2
  • 23
  • 40