@@ -41,7 +41,7 @@ @implementation RCTARKit
4141+ (instancetype )sharedInstance {
4242 static RCTARKit *instance = nil ;
4343 static dispatch_once_t onceToken;
44-
44+
4545 dispatch_once_on_main_thread (&onceToken, ^{
4646 if (instance == nil ) {
4747 ARSCNView *arView = [[ARSCNView alloc ] init ];
@@ -54,30 +54,30 @@ + (instancetype)sharedInstance {
5454- (instancetype )initWithARView : (ARSCNView *)arView {
5555 if ((self = [super init ])) {
5656 self.arView = arView;
57-
57+
5858 // delegates
5959 arView.delegate = self;
6060 arView.session .delegate = self;
61-
61+
6262 UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (handleTapFrom: )];
6363 tapGestureRecognizer.numberOfTapsRequired = 1 ;
6464 [self .arView addGestureRecognizer: tapGestureRecognizer];
65-
65+
6666 self.touchDelegates = [NSMutableArray array ];
6767 self.rendererDelegates = [NSMutableArray array ];
6868 self.sessionDelegates = [NSMutableArray array ];
69-
69+
7070 // nodeManager
7171 self.nodeManager = [RCTARKitNodes sharedInstance ];
7272 self.nodeManager .arView = arView;
7373 [self .sessionDelegates addObject: self .nodeManager];
74-
74+
7575 // configuration(s)
7676 arView.autoenablesDefaultLighting = YES ;
7777 arView.scene .rootNode .name = @" root" ;
78-
78+
7979 self.planes = [NSMutableDictionary new ];
80-
80+
8181 // start ARKit
8282 [self addSubview: arView];
8383 [self resume ];
@@ -191,7 +191,7 @@ static float getDistance(const SCNVector3 pointA, const SCNVector3 pointB) {
191191 float yd = pointB.y - pointA.y ;
192192 float zd = pointB.z - pointA.z ;
193193 float distance = sqrt (xd * xd + yd * yd + zd * zd);
194-
194+
195195 if (distance < 0 ){
196196 return (distance * -1 );
197197 } else {
@@ -201,7 +201,7 @@ static float getDistance(const SCNVector3 pointA, const SCNVector3 pointB) {
201201
202202- (float )getCameraDistanceToPoint : (SCNVector3)point {
203203 return getDistance (self.nodeManager .cameraOrigin .position , point);
204-
204+
205205}
206206
207207
@@ -212,12 +212,12 @@ -(ARWorldTrackingConfiguration *)configuration {
212212 if (_configuration) {
213213 return _configuration;
214214 }
215-
215+
216216 if (!ARWorldTrackingConfiguration.isSupported ) {}
217-
217+
218218 _configuration = [ARWorldTrackingConfiguration new ];
219219 _configuration.planeDetection = ARPlaneDetectionHorizontal;
220-
220+
221221 return _configuration;
222222}
223223
@@ -226,7 +226,7 @@ -(ARWorldTrackingConfiguration *)configuration {
226226#pragma mark - snapshot methods
227227
228228- (void )hitTestSceneObjects : (const CGPoint)tapPoint resolve : (RCTARKitResolve)resolve reject : (RCTARKitReject)reject {
229-
229+
230230 resolve ([self .nodeManager getSceneObjectsHitResult: tapPoint]);
231231}
232232
@@ -263,7 +263,7 @@ - (UIImage *)getSnaphsotCamera {
263263#pragma mark - plane hit detection
264264
265265- (void )hitTestPlane : (const CGPoint)tapPoint types : (ARHitTestResultType)types resolve : (RCTARKitResolve)resolve reject : (RCTARKitReject)reject {
266-
266+
267267 resolve ([self getPlaneHitResult: tapPoint types: types]);
268268}
269269
@@ -278,7 +278,7 @@ - (void)hitTestPlane:(const CGPoint)tapPoint types:(ARHitTestResultType)types re
278278 @" y" : @(result.worldTransform .columns [3 ].y ),
279279 @" z" : @(result.worldTransform .columns [3 ].z )
280280 }
281-
281+
282282 } )];
283283 }];
284284 return resultsMapped;
@@ -315,7 +315,7 @@ - (void)handleTapFrom: (UITapGestureRecognizer *)recognizer {
315315 NSDictionary * planeHitResult = [self getPlaneHitResult: tapPoint types: ARHitTestResultTypeExistingPlaneUsingExtent];
316316 self.onTapOnPlaneUsingExtent (planeHitResult);
317317 }
318-
318+
319319 if (self.onTapOnPlaneNoExtent ) {
320320 // Take the screen space tap coordinates and pass them to the hitTest method on the ARSCNView instance
321321 NSDictionary * planeHitResult = [self getPlaneHitResult: tapPoint types: ARHitTestResultTypeExistingPlane];
@@ -343,17 +343,18 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didRenderScene:(SCNScene *)scen
343343 }
344344}
345345
346+
346347- (void )renderer : (id <SCNSceneRenderer>)renderer didAddNode : (SCNNode *)node forAnchor : (ARAnchor *)anchor {
347348 if (![anchor isKindOfClass: [ARPlaneAnchor class ]]) {
348349 return ;
349350 }
350-
351+
351352 SCNNode *parent = [node parentNode ];
352353 NSLog (@" plane detected" );
353354 // NSLog(@"%f %f %f", parent.position.x, parent.position.y, parent.position.z);
354-
355+
355356 ARPlaneAnchor *planeAnchor = (ARPlaneAnchor *)anchor;
356-
357+
357358 // NSLog(@"%@", @{
358359 // @"id": planeAnchor.identifier.UUIDString,
359360 // @"alignment": @(planeAnchor.alignment),
@@ -362,7 +363,7 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forA
362363 // @"extent": @{ @"x": @(planeAnchor.extent.x), @"y": @(planeAnchor.extent.y), @"z": @(planeAnchor.extent.z) },
363364 // @"camera": @{ @"x": @(self.cameraOrigin.position.x), @"y": @(self.cameraOrigin.position.y), @"z": @(self.cameraOrigin.position.z) }
364365 // });
365-
366+
366367 if (self.onPlaneDetected ) {
367368 self.onPlaneDetected (@{
368369 @" id" : planeAnchor.identifier .UUIDString ,
@@ -373,7 +374,7 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forA
373374 // @"camera": @{ @"x": @(self.cameraOrigin.position.x), @"y": @(self.cameraOrigin.position.y), @"z": @(self.cameraOrigin.position.z) }
374375 });
375376 }
376-
377+
377378 // Plane *plane = [[Plane alloc] initWithAnchor: (ARPlaneAnchor *)anchor isHidden: NO];
378379 // [self.planes setObject:plane forKey:anchor.identifier];
379380 // [node addChildNode:plane];
@@ -384,13 +385,13 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer willUpdateNode:(SCNNode *)node
384385
385386- (void )renderer : (id <SCNSceneRenderer>)renderer didUpdateNode : (SCNNode *)node forAnchor : (ARAnchor *)anchor {
386387 ARPlaneAnchor *planeAnchor = (ARPlaneAnchor *)anchor;
387-
388+
388389 SCNNode *parent = [node parentNode ];
389390 // NSLog(@"%@", parent.name);
390391 // NSLog(@"%f %f %f", node.position.x, node.position.y, node.position.z);
391392 // NSLog(@"%f %f %f %f", node.rotation.x, node.rotation.y, node.rotation.z, node.rotation.w);
392-
393-
393+
394+
394395 // NSLog(@"%@", @{
395396 // @"id": planeAnchor.identifier.UUIDString,
396397 // @"alignment": @(planeAnchor.alignment),
@@ -399,7 +400,7 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didUpdateNode:(SCNNode *)node f
399400 // @"extent": @{ @"x": @(planeAnchor.extent.x), @"y": @(planeAnchor.extent.y), @"z": @(planeAnchor.extent.z) },
400401 // @"camera": @{ @"x": @(self.cameraOrigin.position.x), @"y": @(self.cameraOrigin.position.y), @"z": @(self.cameraOrigin.position.z) }
401402 // });
402-
403+
403404 if (self.onPlaneUpdate ) {
404405 self.onPlaneUpdate (@{
405406 @" id" : planeAnchor.identifier .UUIDString ,
@@ -410,12 +411,12 @@ - (void)renderer:(id <SCNSceneRenderer>)renderer didUpdateNode:(SCNNode *)node f
410411 // @"camera": @{ @"x": @(self.cameraOrigin.position.x), @"y": @(self.cameraOrigin.position.y), @"z": @(self.cameraOrigin.position.z) }
411412 });
412413 }
413-
414+
414415 Plane *plane = [self .planes objectForKey: anchor.identifier];
415416 if (plane == nil ) {
416417 return ;
417418 }
418-
419+
419420 [plane update: (ARPlaneAnchor *)anchor];
420421}
421422
@@ -433,13 +434,33 @@ - (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame {
433434 [sessionDelegate session: session didUpdateFrame: frame];
434435 }
435436 }
436- if (self.onFrameUpdate ) {
437+ if (self.onFeaturesDetected ) {
437438 dispatch_async (dispatch_get_main_queue (), ^{
438- self.onFrameUpdate (@{});
439+
440+ NSMutableArray * featurePoints = [NSMutableArray array ];
441+ for (int i = 0 ; i < frame.rawFeaturePoints .count ; i++) {
442+ vector_float3 point = frame.rawFeaturePoints .points [i];
443+
444+ NSString * pointId = [NSString stringWithFormat: @" featurepoint_%lld " ,frame.rawFeaturePoints.identifiers[i]];
445+
446+ [featurePoints addObject: @{
447+ @" x" : @(point[0 ]),
448+ @" y" : @(point[1 ]),
449+ @" z" : @(point[2 ]),
450+ @" id" :pointId,
451+ }];
452+
453+ }
454+
455+ self.onFeaturesDetected (@{
456+ @" featurePoints" :featurePoints
457+ });
439458 });
440459 }
441460}
442461
462+
463+
443464- (void )session : (ARSession *)session cameraDidChangeTrackingState : (ARCamera *)camera {
444465 if (self.onTrackingState ) {
445466 dispatch_async (dispatch_get_main_queue (), ^{
0 commit comments