From 9a2df0d905c37593126e848894c22ec771561c2d Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 13 Nov 2017 01:07:25 +0100 Subject: [PATCH] revert id behavior id is now matched against existing ids --- ios/RCTARKitNodes.m | 65 ++++++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/ios/RCTARKitNodes.m b/ios/RCTARKitNodes.m index cc28d32..469d3dc 100644 --- a/ios/RCTARKitNodes.m +++ b/ios/RCTARKitNodes.m @@ -161,32 +161,32 @@ - (NSMutableArray *) mapHitResultsWithSceneResults: (NSArray 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; } @@ -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]; } diff --git a/package.json b/package.json index fbbff25..234a653 100644 --- a/package.json +++ b/package.json @@ -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 ", "license": "MIT",