Scenekit detecting User tapped object

风流意气都作罢 提交于 2019-12-01 11:01:41

See the documentation for the hitTest method. Call that from wherever you're handling touch events to get a list of 3D scene objects/locations "under" a 2D screen point.

An easy way to get sample code that shows the hitTest in action is to create a sample app using the Game template in XCode6. Create a new project, select the "Game" template.

The hitTest code should be there in the implementation of:

- (void) handleTap:(UIGestureRecognizer*)gestureRecognize

Add a tap gesture to the object and check whether it is a SCNNode()

     @objc func tapGetsureRec(sender: UIPanGestureRecognizer? = nil){
            let location: CGPoint = (sender?.location(in: self.view))!
            let hits = self.sceneKitView.hitTest(location, options: nil)
            if let tappedNode : SCNNode = hits.first?.node {
                ...
            }
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!