我想知道哪个节点被击中,但我的方法仅适用于具有 SCNBox 和 SCNFloor 等几何形状的节点,但不适用于 DAE 模型:
- (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
}
}
}
这就是我制作 .dae 节点(heroNode)的方式:
SCNScene *heroScene = [SCNScene sceneNamed:@"hero" inDirectory:nil options:nil];
heroNode = [heroScene.rootNode childNodeWithName:@"root" recursively:YES];
[scene.rootNode addChildNode:heroNode];
问题出在哪里?