Created
August 24, 2016 08:37
-
-
Save serhatsezer/0e5cc823328c2b061e1f95ba8c7d0f27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add a tap gesture recognizer | |
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) | |
scnView.addGestureRecognizer(tapGesture)` | |
func handleTap(gestureRecognize: UIGestureRecognizer) { | |
// retrieve the SCNView | |
let scnView = self.view as! SCNView | |
// check what nodes are tapped | |
let p = gestureRecognize.locationInView(scnView) | |
let hitResults = scnView.hitTest(p, options: nil) | |
// check that we clicked on at least one object | |
if hitResults.count > 0 { | |
// retrieved the first clicked object | |
let result: AnyObject! = hitResults[0] | |
// get its material | |
let material = result.node!.geometry!.firstMaterial! | |
// highlight it | |
SCNTransaction.begin() | |
SCNTransaction.setAnimationDuration(0.5) | |
// on completion - unhighlight | |
SCNTransaction.setCompletionBlock { | |
SCNTransaction.begin() | |
SCNTransaction.setAnimationDuration(0.5) | |
material.emission.contents = UIColor.blackColor() | |
SCNTransaction.commit() | |
} | |
material.emission.contents = UIColor.redColor() | |
SCNTransaction.commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment