Skip to content

Commit

Permalink
add new hierarchy array on ids, fix again cleaning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozone committed Nov 12, 2017
1 parent 39896c8 commit 97ba3aa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion ARKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TRACKING_STATES_COLOR = ['red', 'orange', 'green'];

// clear scene on start (not on mount)
// this is only needed if you reload the app (in dev mode)
ARKitManager.clearScene();
let firstMount = false;

class ARKit extends Component {
state = {
Expand All @@ -43,6 +43,11 @@ class ARKit extends Component {

componentDidMount() {
ARKitManager.resume();
if (!firstMount) {
ARKitManager.clearScene();
} else {
firstMount = true;
}
}

componentWillUnmount() {
Expand Down
2 changes: 1 addition & 1 deletion components/ARText.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { NativeModules } from 'react-native';
import createArComponent from './lib/createArComponent';

const ARText = createArComponent(
{ mount: NativeModules.ARTextManager.mount, pick: ['text', 'font'] },
{ mount: NativeModules.ARTextManager.mount, pick: ['id', 'text', 'font'] },
{
text: PropTypes.string,
font: PropTypes.shape({
Expand Down
2 changes: 1 addition & 1 deletion ios/RCTARKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forA
// });

if (self.onPlaneDetected) {
self.onPlaneDetected(@{
self.onPlaneDetected(@{
@"id": planeAnchor.identifier.UUIDString,
@"alignment": @(planeAnchor.alignment),
@"node": @{ @"x": @(node.position.x), @"y": @(node.position.y), @"z": @(node.position.z) },
Expand Down
19 changes: 17 additions & 2 deletions ios/RCTARKitNodes.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,16 @@ - (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;
NSString * nodeId = node.name;
float distance = [self getCameraDistanceToPoint:point];

[resultsMapped addObject:(@{
@"id": nodeId,
@"id": ids.count > 0 ? ids[0] : @"",
@"ids": ids,
@"distance": @(distance),
@"point": @{
@"x": @(point.x),
Expand Down Expand Up @@ -198,6 +201,18 @@ - (void)registerNode:(SCNNode *)node forKey:(NSString *)key {
}
}

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

SCNNode* _node = node;
while(_node) {
if(_node.name)
[ids addObject:_node.name];
_node = _node.parentNode;
}
return ids;

}
- (SCNNode *)nodeForKey:(NSString *)key {
return [self.nodes objectForKey:key];
}
Expand Down
5 changes: 4 additions & 1 deletion ios/RCTConvert+ARKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ + (SCNTextNode *)SCNTextNode:(id)json {

// SCNTextNode
SCNTextNode *textNode = [SCNNode nodeWithGeometry:scnText];
textNode.scale = SCNVector3Make(size, size, size);
textNode.name = [NSString stringWithFormat:@"%@", json[@"id"]];


textNode.scale = SCNVector3Make(size, size, size);

// position textNode
SCNVector3 min = SCNVector3Zero;
SCNVector3 max = SCNVector3Zero;
Expand Down

0 comments on commit 97ba3aa

Please sign in to comment.