My SceneKit project uses an imported .OBJ file, which contains only one node with a huge image. Image comprises different objects or parts. I need to tap on a foot, or image specific part, and have it highlighted. This is code to import .obj File
sceneView = SCNView(frame: self.view.frame)
self.view.addSubview(sceneView)
let scene = SCNScene(named: "OBJ.obj")!
print("\(scene.rootNode.childNodes.first?.geometry?.materials.count)")
sceneView.scene = scene
and here I am using tap gesture recognizer
// add a tap gesture recognizer
let doubleTapRecognizer = UITapGestureRecognizer(target: self, action : #selector(self.tapGesture(sender:)));
doubleTapRecognizer.numberOfTapsRequired = 1;
doubleTapRecognizer.numberOfTouchesRequired = 1;
sceneView.addGestureRecognizer(doubleTapRecognizer);
func tapGesture(sender: UITapGestureRecognizer){
let hitResult : SCNHitTestResult
// check what nodes are tapped
let p = sender.location(in: sceneView)
let hitResults = sceneView.hitTest(p, options: nil)
}
I have 3D Model with different parts like left foot right foot and floor needed to be tapped and show different color on them. The problem is that all of these are in single node.
Your
SCNHitTestResult
will give you the index of the triangle that was tapped. But you'll still have to work out the logic of going from a single triangle to recognizing "that was the left arm".I think your best bet is to go back to your 3D modeling software and break the object into smaller, logical components.