Reputation: 35953
This is my problem. I have create an object on maya that have the following hierarchy:
bigButton
|
|-- redDome
| |
| |-- polySurface1
| |__ polySurface2
|
|-- greenDome
|
|-- polySurface3
|__ polySurface4
I convert that to DAE and import it on SceneKit. Two more nodes are added to the hierarchy by Xcode. The hierarchy is now:
bitButton Reference
|
|_ referenceRoot
|
|
|__ bigButton
|
|-- redDome
| |
| |-- polySurface1
| |__ polySurface2
|
|-- greenDome
|
|-- polySurface3
|__ polySurface4
Now I touch the button and I am trying to determine if the button was tapped. The only node that matters to me is bigButton
. WHen I tap the object and use this method:
- (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){
// retrieved the first clicked object
SCNHitTestResult *result = [hitResults objectAtIndex:0];
result.node
tells me that the node touched was polySurface1
or polySurface2
whatever. It will never tell me that bigButton
was tapped because that is just a node, not a surface.
OK, I can use parentNode
to detect the parent's node but this is stupid because result.node
can be on different hierarchy levels above or below bigButton
. Is this the only lame mode to do that? To transverse the hierarchy searching for the correct node or is is there a beautiful way?
thanks.
Upvotes: 3
Views: 1737
Reputation: 13462
The only node that matters to me is
bigButton
.
If by that you mean that you'll never be interested in knowing that any other node was hit, then you should take a look at the SCNHitTestRootNodeKey
hit-testing option.
Specifying bigButton
as the root node implies that getting any hit-test result means that bigButton
was hit, without having to do any check.
Upvotes: 2