Skip to content

Commit 1dbe6cf

Browse files
Jack SobocinskiJackSoby
authored andcommitted
add pinch
onpress remove onrpess add pan gesture update pan gesature' remove pan gesture fix panning update view add z stat remove z stat add reconzer stats debug translator and view remove pan completely remove panhandler add recongizer add name remove name update detection images load iamge from update url create images on the fly update ur update url stuff update image creation' update react antive arkit use cig image create ar refernce iamge clean up pinch functions and return image funcs add detection images update refernce images add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image add refernce image update image width updaet pinch update pinch gesture update pinch gesture update status of ui pinch update status of ui pinch update uipinch update scale for pinch update gesture handlers update gesture handlers update gesture handlers update scale update scale update pinch update pinch update pinch update pinch update pinch update pinch update pinch update dynmaic images add pan gesture add arview add maximum numner of touches add maximum numner of touches update to arview update arview upadte pan handler update gesture rec update images update images update arkit pan update dynmic images update dynamic images update dynamic images update pan handler handle tap handle tap handle tap update pan update pna update pand gesuture names remove pan gesture location tracking start location tracking expose aranchor function remov alt and declar distance var update location function' update location remove auto release update location logs' update test values update location tracking add option coords update option var pass add options to location add options var add @ before string add @ before string add landmark lat and long add floats as lat and long update landmark lat and long add else statement add else statement update location code update order of params update location func create matrix: udpate matrix log matrix result update matrix result log results update transform add new anchor update location params add landmark lat add landmark log update lat long options landmark lat initn number with float add double vlaue add double value add long diff add semicolon return angle add semicolons update location tracking add semicolons add rotation matrix init page with new value' update matrix roattion re trun distance transform update distance log distance add semicolon add log' return distance log y value add endlat add z test with float vlaue add location lat and long add semicolon remove all reference of options remove closing brace add dynamic double values' switch double to float remove * on float decleration add acuracy add vertical and horizontal accurcy get distance between points add bearing and degrees update location long change double to flaot add type to function return location remove brace update distance km update lat and long radians add smd4 make add semicolons add log for function result add semicolons update var names add indexes add itendifiers add transformation matrix remove dots checkout x value' access zero update vars log z value add a bunch of logs add more logs add ar anchor log transform log matrix update log remove bad logs add transform log remove log stuff log matrix log anchor: add transformation matrix update log logmatrix logmatrix upadate position abs add more ogs convert vector to json update syntax errors remove staic allocation update logs update logs log entire matrix log out new roattion matrix remove stupid logs and get rotation remove logs log vector 4s get vec 4' update logs update action update logs upodate new rotation add dynamic degree to calculation update bearing results add ditonary accessor redeclare vlaues add semicolons correctly access dict access rotation matrix add getrow update url update matrix info update x update w add anchjor add semicolon update location tracking update rotation add some logs to figure shit out try wiht distance transform add rotation info update rotation update location add semicolon update matrix accessor make float 4x4 update syntax make 4x4 update matrix update roatation matrix use simd_matrix update use of rotation change to 4x4 matrix create with hardcoded values use distance transform use complteted transfomration change aranchor init remove bearing degrees ad dmore accurate reading fix typo add in extra to function def add log and create voide function remove resolve create negitive rotation Scrub up the code import corelocation add astrik fix syntax errors fix syntax issues syntax issues rename location function and add anchorname use init with name return name in anchor result add name prop logic add semicolon add semicolon add nodename add anchor name log strings add tests add testname add anchor name move nsstring frist remove logs clean code for master merge addd min update distance function remove distance function add distance filter update distance transform change distance remove location code
1 parent bd5bfea commit 1dbe6cf

File tree

6 files changed

+673
-466
lines changed

6 files changed

+673
-466
lines changed

ARKit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ARKit extends Component {
5959
'onTapOnPlaneUsingExtent',
6060
'onTapOnPlaneNoExtent',
6161
'onRotationGesture',
62+
'onPinchGesture',
6263
'onPlaneDetected',
6364
'onPlaneRemoved',
6465
'onPlaneUpdated',
@@ -240,6 +241,7 @@ ARKit.propTypes = {
240241
onTapOnPlaneUsingExtent: PropTypes.func,
241242
onTapOnPlaneNoExtent: PropTypes.func,
242243
onRotationGesture: PropTypes.func,
244+
onPinchGesture: PropTypes.func,
243245
onEvent: PropTypes.func,
244246
isMounted: PropTypes.func,
245247
isInitialized: PropTypes.func,

ios/RCTARKit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "RCTARKitDelegate.h"
1414
#import "RCTARKitNodes.h"
1515
#import "RCTMultiPeer.h"
16+
@import CoreLocation;
1617

1718
typedef void (^RCTBubblingEventBlock)(NSDictionary *body);
1819
typedef void (^RCTARKitResolve)(id result);
@@ -64,6 +65,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
6465
@property (nonatomic, copy) RCTBubblingEventBlock onTapOnPlaneNoExtent;
6566

6667
@property (nonatomic, copy) RCTBubblingEventBlock onRotationGesture;
68+
@property (nonatomic, copy) RCTBubblingEventBlock onPinchGesture;
6769

6870
@property (nonatomic, copy) RCTBubblingEventBlock onEvent;
6971
@property (nonatomic, copy) RCTBubblingEventBlock onARKitError;
@@ -95,6 +97,8 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
9597
- (void)focusScene;
9698
- (void)clearScene;
9799
- (NSDictionary *)readCameraPosition;
100+
// - (void)getArAnchorPosition:(CLLocation *)location landmark:(CLLocation *)landmark anchorName:(NSString *)anchorName;
101+
98102
- (NSDictionary *)readCamera;
99103
- (NSDictionary* )getCurrentLightEstimation;
100104
- (NSArray * )getCurrentDetectedFeaturePoints;

ios/RCTARKit.m

Lines changed: 162 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ - (instancetype)initWithARView:(ARSCNView *)arView {
7676
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
7777
tapGestureRecognizer.numberOfTapsRequired = 1;
7878
[self.arView addGestureRecognizer:tapGestureRecognizer];
79-
79+
8080
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationFrom:)];
8181
[self.arView addGestureRecognizer:rotationGestureRecognizer];
82-
82+
83+
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchFrom:)];
84+
[self.arView addGestureRecognizer:pinchGestureRecognizer];
85+
8386
self.touchDelegates = [NSMutableArray array];
8487
self.rendererDelegates = [NSMutableArray array];
8588
self.sessionDelegates = [NSMutableArray array];
@@ -305,27 +308,134 @@ - (void)setWorldAlignment:(ARWorldAlignment)worldAlignment {
305308

306309
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110300
307310
- (void)setDetectionImages:(NSArray*) detectionImages {
308-
309-
if (@available(iOS 11.3, *)) {
310-
ARWorldTrackingConfiguration *configuration = self.configuration;
311-
NSSet *detectionImagesSet = [[NSSet alloc] init];
312-
for (id config in detectionImages) {
313-
if(config[@"resourceGroupName"]) {
314-
// TODO: allow bundle to be defined
315-
detectionImagesSet = [detectionImagesSet setByAddingObjectsFromSet:[ARReferenceImage referenceImagesInGroupNamed:config[@"resourceGroupName"] bundle:nil]];
316-
}
311+
if (@available(iOS 11.3, *)) {
312+
ARWorldTrackingConfiguration *configuration = self.configuration;
313+
NSSet *detectionImagesSet = [[NSSet alloc] init];
314+
for (id config in detectionImages) {
315+
316+
for (id url in config[@"arDetectionImages"]) {
317+
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: url]];
318+
319+
UIImage* uiimage = [[UIImage alloc] initWithData:imageData];
320+
321+
CGImageRef cgImage = [uiimage CGImage];
322+
323+
ARReferenceImage *image = [[ARReferenceImage alloc] initWithCGImage:cgImage orientation:kCGImagePropertyOrientationUp physicalWidth:1];
324+
image.name=url;
325+
detectionImagesSet = [detectionImagesSet setByAddingObject:image];
326+
327+
}
328+
329+
330+
if(config[@"resourceGroupName"]) {
331+
detectionImagesSet = [detectionImagesSet setByAddingObjectsFromSet:[ARReferenceImage referenceImagesInGroupNamed:config[@"resourceGroupName"] bundle:nil]];
332+
}
333+
334+
configuration.detectionImages = detectionImagesSet;
335+
[self resume];
317336
}
318-
configuration.detectionImages = detectionImagesSet;
319-
[self resume];;
320337
}
321338
}
339+
322340
#endif
323341
- (NSDictionary *)readCameraPosition {
324342
// deprecated
325343
SCNVector3 cameraPosition = self.nodeManager.cameraOrigin.position;
326344
return vectorToJson(cameraPosition);
327345
}
328346

347+
- (double)radiansFromDegrees:(float)degrees
348+
{
349+
return degrees * (M_PI/180.0);
350+
}
351+
352+
- (double)degreesFromRadians:(float)radians
353+
{
354+
return radians * (180.0/M_PI);
355+
}
356+
357+
- (void)getArAnchorPosition:(CLLocation *)location landmark:(CLLocation *)landmark anchorName:(NSString *)anchorName {
358+
359+
CLLocationDistance distance = [location distanceFromLocation:landmark];
360+
matrix_float4x4 distanceTransform = translatingIdentity(0, 0, -distance);
361+
362+
if(distance < 200){
363+
matrix_float4x4 distanceTransform = translatingIdentity(0, 0, -50);
364+
}
365+
366+
float rotation = angleBetweenPoints(location, landmark);
367+
368+
float tilt = angleOffHorizon(location, landmark);
369+
370+
simd_float4x4 tiltedTransformation = rotateVertically(distanceTransform, tilt);
371+
372+
simd_float4x4 completedTransformation = rotateHorizontally(tiltedTransformation, -rotation);
373+
374+
ARAnchor *localAnchor = [[ARAnchor alloc] initWithName:anchorName transform:completedTransformation];
375+
376+
[self.arView.session addAnchor:localAnchor];
377+
378+
return;
379+
}
380+
381+
static SCNVector3 toSCNVector3(simd_float4 float4) {
382+
SCNVector3 positionAbsolute = SCNVector3Make(float4.x, float4.y, float4.z);
383+
return positionAbsolute;
384+
}
385+
386+
387+
static float angleBetweenPoints(const CLLocation *location, const CLLocation *landmark) {
388+
float startLat = GLKMathDegreesToRadians(location.coordinate.latitude);
389+
float startLon = GLKMathDegreesToRadians(location.coordinate.longitude);
390+
float endLat = GLKMathDegreesToRadians(landmark.coordinate.latitude);
391+
float endLon = GLKMathDegreesToRadians(landmark.coordinate.longitude);
392+
393+
float lonDiff = endLon - startLon;
394+
float y = sin(lonDiff) * cos(endLat);
395+
float x = (cos(startLat) * sin(endLat)) - (sin(startLat) * cos(endLat) * cos(lonDiff));
396+
float angle = atan2(y, x);
397+
if(angle < 0){
398+
float finalAngle = angle + (M_PI * 2);
399+
return finalAngle;
400+
} else {
401+
return angle;
402+
}
403+
}
404+
405+
static matrix_float4x4 translatingIdentity(const float x, const float y, const float z) {
406+
matrix_float4x4 result = matrix_identity_float4x4;
407+
result.columns[3].x = x;
408+
result.columns[3].y = y;
409+
result.columns[3].z = z;
410+
return result;
411+
}
412+
413+
static float angleOffHorizon(const CLLocation *start, const CLLocation *end) {
414+
CLLocationDistance adjacent = [start distanceFromLocation:end];
415+
float opposite = end.altitude - start.altitude;
416+
return atan2(opposite, adjacent);
417+
}
418+
419+
static matrix_float4x4 rotateVertically(const matrix_float4x4 distanceTrans, const float radians) {
420+
GLKMatrix4 rotation = GLKMatrix4MakeXRotation(radians);
421+
return simd_mul(convert(rotation), distanceTrans);
422+
}
423+
424+
static matrix_float4x4 rotateHorizontally(const matrix_float4x4 titledTrans, const float radians) {
425+
GLKMatrix4 rotation = GLKMatrix4MakeYRotation(radians);
426+
return simd_mul(convert(rotation), titledTrans);
427+
}
428+
429+
static simd_float4x4 convert(const GLKMatrix4 matrix) {
430+
return simd_matrix(
431+
simd_make_float4(matrix.m00, matrix.m01, matrix.m02, matrix.m03),
432+
simd_make_float4(matrix.m10, matrix.m11, matrix.m12, matrix.m13),
433+
simd_make_float4(matrix.m20, matrix.m21, matrix.m22, matrix.m23),
434+
simd_make_float4(matrix.m30, matrix.m31, matrix.m32, matrix.m33)
435+
);
436+
}
437+
438+
329439
static NSDictionary * vectorToJson(const SCNVector3 v) {
330440
return @{ @"x": @(v.x), @"y": @(v.y), @"z": @(v.z) };
331441
}
@@ -385,7 +495,6 @@ -(ARWorldTrackingConfiguration *)configuration {
385495
#pragma mark - snapshot methods
386496

387497
- (void)hitTestSceneObjects:(const CGPoint)tapPoint resolve:(RCTARKitResolve)resolve reject:(RCTARKitReject)reject {
388-
389498
resolve([self.nodeManager getSceneObjectsHitResult:tapPoint]);
390499
}
391500

@@ -399,9 +508,6 @@ - (UIImage *)getSnapshot:(NSDictionary *)selection {
399508
}
400509

401510

402-
403-
404-
405511
- (UIImage *)getSnapshotCamera:(NSDictionary *)selection {
406512
CVPixelBufferRef pixelBuffer = self.arView.session.currentFrame.capturedImage;
407513
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
@@ -542,8 +648,14 @@ - (void)handleTapFrom: (UITapGestureRecognizer *)recognizer {
542648
//
543649
if(self.onTapOnPlaneUsingExtent) {
544650
// Take the screen space tap coordinates and pass them to the hitTest method on the ARSCNView instance
545-
NSDictionary * planeHitResult = [self getPlaneHitResult:tapPoint types:ARHitTestResultTypeExistingPlaneUsingExtent];
546-
self.onTapOnPlaneUsingExtent(planeHitResult);
651+
// NSDictionary * planeHitResult = [self getPlaneHitResult:tapPoint types:ARHitTestResultTypeExistingPlaneUsingExtent];
652+
// CGPoint point = CGPointMake( [pointDict[@"x"] floatValue], [pointDict[@"y"] floatValue] );
653+
NSDictionary *tap = @{
654+
@"x": @(tapPoint.x),
655+
@"y": @(tapPoint.y)
656+
};
657+
658+
self.onTapOnPlaneUsingExtent(tap);
547659
}
548660

549661
if(self.onTapOnPlaneNoExtent) {
@@ -570,6 +682,26 @@ - (void)handleRotationFrom: (UIRotationGestureRecognizer *)recognizer {
570682
}
571683
}
572684

685+
686+
- (void)handlePinchFrom: (UIPinchGestureRecognizer *)recognizer {
687+
688+
if( recognizer.state == UIGestureRecognizerStateBegan ||
689+
recognizer.state == UIGestureRecognizerStateChanged ||
690+
recognizer.state == UIGestureRecognizerStateEnded) {
691+
692+
if(self.onPinchGesture) {
693+
NSDictionary *pinchGesture = @{
694+
@"scale": @(recognizer.scale),
695+
@"velocity": @(recognizer.velocity)
696+
};
697+
698+
self.onPinchGesture(pinchGesture);
699+
}
700+
}
701+
}
702+
703+
704+
573705
#pragma mark - ARSCNViewDelegate
574706

575707
- (void)renderer:(id<SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time {
@@ -599,7 +731,7 @@ - (NSDictionary *)makeAnchorDetectionResult:(SCNNode *)node anchor:(ARAnchor *)a
599731
@"type": @"unkown",
600732
@"eulerAngles":vectorToJson(node.eulerAngles),
601733
@"position": vectorToJson([self.nodeManager getRelativePositionToOrigin:node.position]),
602-
@"positionAbsolute": vectorToJson(node.position)
734+
@"positionAbsolute": vectorToJson(node.position),
603735
};
604736
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithDictionary:baseProps];
605737

@@ -618,6 +750,16 @@ - (NSDictionary *)makeAnchorDetectionResult:(SCNNode *)node anchor:(ARAnchor *)a
618750
} else {
619751
// Fallback on earlier versions
620752
}
753+
NSLog(@"node.name:-%@", node.name);
754+
NSLog(@"anchor.name:-%@", anchor.name);
755+
756+
if(anchor.name != nil){
757+
NSDictionary* nameProps = @{
758+
@"name": anchor.name
759+
};
760+
761+
[dict addEntriesFromDictionary:nameProps];
762+
}
621763
return dict;
622764
}
623765

ios/RCTARKitManager.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ - (NSDictionary *)constantsToExport
189189
RCT_EXPORT_VIEW_PROPERTY(onTapOnPlaneUsingExtent, RCTBubblingEventBlock)
190190
RCT_EXPORT_VIEW_PROPERTY(onTapOnPlaneNoExtent, RCTBubblingEventBlock)
191191
RCT_EXPORT_VIEW_PROPERTY(onRotationGesture, RCTBubblingEventBlock)
192+
RCT_EXPORT_VIEW_PROPERTY(onPinchGesture, RCTBubblingEventBlock)
192193
RCT_EXPORT_VIEW_PROPERTY(onEvent, RCTBubblingEventBlock)
193194
RCT_EXPORT_VIEW_PROPERTY(onARKitError, RCTBubblingEventBlock)
194195
RCT_EXPORT_VIEW_PROPERTY(worldMap, NSObject);
@@ -449,6 +450,21 @@ - (void)storeImage:(UIImage *)image options:(NSDictionary *)options reject:(RCTP
449450
resolve([[ARKit sharedInstance] readCameraPosition]);
450451
}
451452

453+
// RCT_EXPORT_METHOD(addAnchorByLocation:(NSString *)anchorName locationLat:(float)locationLat locationLong:(float)locationLong landmarkLat:(float)landmarkLat landmarkLong:(float)landmarkLong locationHorizontalAccuracy:(float)locationHorizontalAccuracy landmarkHorizontalAccuracy:(float)landmarkHorizontalAccuracy locationVerticalAccuracy:(float)locationVerticalAccuracy landmarkVerticalAccuracy:(float)landmarkVerticalAccuracy locationAltitude:(float)locationAltitude landmarkAltitude:(float)landmarkAltitude resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
454+
// CLLocation *location = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(locationLat, locationLong)
455+
// altitude:locationAltitude
456+
// horizontalAccuracy:locationHorizontalAccuracy
457+
// verticalAccuracy:locationVerticalAccuracy
458+
// timestamp:[NSDate date]];
459+
// CLLocation *landmark = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(landmarkLat, landmarkLong)
460+
// altitude:landmarkAltitude
461+
// horizontalAccuracy:landmarkHorizontalAccuracy
462+
// verticalAccuracy:landmarkVerticalAccuracy
463+
// timestamp:[NSDate date]];
464+
465+
// [[ARKit sharedInstance] getArAnchorPosition:location landmark:landmark anchorName:anchorName];
466+
// }
467+
452468
RCT_EXPORT_METHOD(getCurrentLightEstimation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
453469
resolve([[ARKit sharedInstance] getCurrentLightEstimation]);
454470
}

0 commit comments

Comments
 (0)