Skip to content

Commit

Permalink
revert id behavior
Browse files Browse the repository at this point in the history
id is now matched against existing ids
  • Loading branch information
macrozone committed Nov 13, 2017
1 parent 97ba3aa commit 9a2df0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
65 changes: 34 additions & 31 deletions ios/RCTARKitNodes.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,32 +161,32 @@ - (NSMutableArray *) mapHitResultsWithSceneResults: (NSArray<SCNHitTestResult *>
SCNHitTestResult *result = (SCNHitTestResult *) obj;
SCNNode * node = result.node;


NSArray *ids = [self getIdHierarchy:node];

SCNVector3 point = result.worldCoordinates;
SCNVector3 normal = result.worldNormal;
float distance = [self getCameraDistanceToPoint:point];

[resultsMapped addObject:(@{
@"id": ids.count > 0 ? ids[0] : @"",
@"ids": ids,
@"distance": @(distance),
@"point": @{
@"x": @(point.x),
@"y": @(point.y),
@"z": @(point.z)
},
@"normal": @{
@"x": @(normal.x),
@"y": @(normal.y),
@"z": @(normal.z)

}
} )];

NSString * nodeId = [self findNodeId:node];
if(nodeId) {

SCNVector3 point = result.worldCoordinates;
SCNVector3 normal = result.worldNormal;
float distance = [self getCameraDistanceToPoint:point];

[resultsMapped addObject:(@{
@"id": nodeId,
@"distance": @(distance),
@"point": @{
@"x": @(point.x),
@"y": @(point.y),
@"z": @(point.z)
},
@"normal": @{
@"x": @(normal.x),
@"y": @(normal.y),
@"z": @(normal.z)

}
} )];
}

}];

return resultsMapped;

}
Expand All @@ -201,18 +201,21 @@ - (void)registerNode:(SCNNode *)node forKey:(NSString *)key {
}
}

- (NSArray *) getIdHierarchy:(SCNNode *) node {
NSMutableArray * ids = [NSMutableArray new];
SCNNode* _node = node;

- (NSString *) findNodeId:(SCNNode *)nodeWithParents {

SCNNode* _node = nodeWithParents;
while(_node) {
if(_node.name)
[ids addObject:_node.name];
if(_node.name && [self.nodes objectForKey:_node.name]) {
return _node.name;
}
_node = _node.parentNode;
}
return ids;
return nil;

}


- (SCNNode *)nodeForKey:(NSString *)key {
return [self.nodes objectForKey:key];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/HippoAR/react-native-arkit.git"
},
"version": "0.4.4",
"version": "0.4.5",
"description": "React Native binding for iOS ARKit",
"author": "Zehao Li <[email protected]>",
"license": "MIT",
Expand Down

0 comments on commit 9a2df0d

Please sign in to comment.