I want to know which Node is hit, but my method works only for nodes with geometry like SCNBox and SCNFloor but doesn't work with DAE models:
- (void) handleTap:(UIGestureRecognizer*)gestureRecognize {
// retrieve the SCNView
SCNView *scnView = (SCNView *)self.view;
// check what nodes are tapped
CGPoint p = [gestureRecognize locationInView:scnView];
NSArray *hitResults = [scnView hitTest:p options:nil];
// check that we clicked on at least one object
if([hitResults count] > 0) {
SCNNode *hitNode = ((SCNHitTestResult*)[hitResults objectAtIndex:0]).node;
if(hitNode == boxNode) {
NSLog(@"box hit"); //works
}
if(hitNode == floorNode) {
NSLog(@"floor hit"); //works
}
if(hitNode == heroNode) {
NSLog(@"heroNode from .dae hit"); //doesn't work
}
}
}
and this is how I make a .dae Node (heroNode):
SCNScene *heroScene = [SCNScene sceneNamed:@"hero" inDirectory:nil options:nil];
heroNode = [heroScene.rootNode childNodeWithName:@"root" recursively:YES];
[scene.rootNode addChildNode:heroNode];
Where is the problem?