Skip to content

Commit 6496926

Browse files
committed
rename
1 parent ba1f505 commit 6496926

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

ARKit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ARKit.propTypes = {
175175
planeDetection: PropTypes.bool,
176176
lightEstimation: PropTypes.bool,
177177
onPlaneDetected: PropTypes.func,
178-
onFrameUpdate: PropTypes.func,
178+
onFeaturesDetected: PropTypes.func,
179179
onPlaneUpdate: PropTypes.func,
180180
onTrackingState: PropTypes.func,
181181
onTapOnPlaneUsingExtent: PropTypes.func,

ios/RCTARKit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
3838
@property (nonatomic, assign) BOOL lightEstimation;
3939

4040
@property (nonatomic, copy) RCTBubblingEventBlock onPlaneDetected;
41-
@property (nonatomic, copy) RCTBubblingEventBlock onFrameUpdate;
41+
@property (nonatomic, copy) RCTBubblingEventBlock onFeaturesDetected;
4242
@property (nonatomic, copy) RCTBubblingEventBlock onPlaneUpdate;
4343
@property (nonatomic, copy) RCTBubblingEventBlock onTrackingState;
4444
@property (nonatomic, copy) RCTBubblingEventBlock onTapOnPlaneUsingExtent;

ios/RCTARKit.m

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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(), ^{

ios/RCTARKitManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ - (NSDictionary *)constantsToExport
6262
RCT_EXPORT_VIEW_PROPERTY(onPlaneDetected, RCTBubblingEventBlock)
6363
RCT_EXPORT_VIEW_PROPERTY(onPlaneUpdate, RCTBubblingEventBlock)
6464
RCT_EXPORT_VIEW_PROPERTY(onTrackingState, RCTBubblingEventBlock)
65-
RCT_EXPORT_VIEW_PROPERTY(onFrameUpdate, RCTBubblingEventBlock)
65+
RCT_EXPORT_VIEW_PROPERTY(onFeaturesDetected, RCTBubblingEventBlock)
6666
RCT_EXPORT_VIEW_PROPERTY(onEvent, RCTBubblingEventBlock)
6767

6868
RCT_EXPORT_METHOD(pause:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {

ios/RCTARKitNodes.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ - (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame {
218218
self.cameraOrigin.eulerAngles = SCNVector3Make(0, atan2f(z.x, z.z), 0);
219219
self.frontOfCamera.position = SCNVector3Make(pos.x - focDistance * z.x, pos.y - focDistance * z.y, pos.z - focDistance * z.z);
220220
self.frontOfCamera.eulerAngles = self.cameraOrigin.eulerAngles;
221+
221222
}
222223

223224
@end

0 commit comments

Comments
 (0)