Skip to content

Commit eeee6b8

Browse files
authored
Merge pull request #102 from conorstrejcek/feature/ARWorldAlignment
Add `worldAlignment` prop to `ARKit` component
2 parents 5d00b87 + c854caa commit eeee6b8

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

ARKit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ ARKit.propTypes = {
176176
debug: PropTypes.bool,
177177
planeDetection: PropTypes.bool,
178178
lightEstimation: PropTypes.bool,
179+
worldAlignment: PropTypes.number,
179180
onPlaneDetected: PropTypes.func,
180181
onFeaturesDetected: PropTypes.func,
181182
onPlaneUpdate: PropTypes.func,

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ AppRegistry.registerComponent('ReactNativeARKit', () => ReactNativeARKit);
154154
| `debug` | `Boolean` | `false` | Debug mode will show the 3D axis and feature points detected.
155155
| `planeDetection` | `Boolean` | `false` | ARKit plane detection.
156156
| `lightEstimation` | `Boolean` | `false` | ARKit light estimation.
157+
| `worldAlignment` | `Enumeration` <br /> One of: `ARKit.ARWorldAlignment.Gravity`, `ARKit.ARWorldAlignment.GravityAndHeading`, `ARKit.ARWorldAlignment.Camera` (documentation [here](https://developer.apple.com/documentation/arkit/arworldalignment)) | `ARKit.ARWorldAlignment.Gravity` | **ARWorldAlignmentGravity** <br /> The coordinate system's y-axis is parallel to gravity, and its origin is the initial position of the device. **ARWorldAlignmentGravityAndHeading** <br /> The coordinate system's y-axis is parallel to gravity, its x- and z-axes are oriented to compass heading, and its origin is the initial position of the device. **ARWorldAlignmentCamera** <br /> The scene coordinate system is locked to match the orientation of the camera.|
157158

158159
##### Events
159160

ios/RCTARKit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
3636
@property (nonatomic, assign) BOOL debug;
3737
@property (nonatomic, assign) BOOL planeDetection;
3838
@property (nonatomic, assign) BOOL lightEstimation;
39+
@property (nonatomic, assign) ARWorldAlignment worldAlignment;
3940

4041
@property (nonatomic, copy) RCTBubblingEventBlock onPlaneDetected;
4142
@property (nonatomic, copy) RCTBubblingEventBlock onFeaturesDetected;

ios/RCTARKit.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ - (void)setLightEstimation:(BOOL)lightEstimation {
160160
[self resume];
161161
}
162162

163+
- (ARWorldAlignment)worldAlignment {
164+
ARConfiguration *configuration = self.session.configuration;
165+
return configuration.worldAlignment;
166+
}
167+
168+
- (void)setWorldAlignment:(ARWorldAlignment)worldAlignment {
169+
ARConfiguration *configuration = self.configuration;
170+
if (worldAlignment == ARWorldAlignmentGravityAndHeading) {
171+
configuration.worldAlignment = ARWorldAlignmentGravityAndHeading;
172+
} else if (worldAlignment == ARWorldAlignmentCamera) {
173+
configuration.worldAlignment = ARWorldAlignmentCamera;
174+
} else {
175+
configuration.worldAlignment = ARWorldAlignmentGravity;
176+
}
177+
[self resume];
178+
}
179+
163180
- (NSDictionary *)readCameraPosition {
164181
// deprecated
165182
SCNVector3 cameraPosition = self.nodeManager.cameraOrigin.position;

ios/RCTARKitManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ - (NSDictionary *)constantsToExport
5757
@"Back": [@(SCNChamferModeBack) stringValue],
5858
@"Front": [@(SCNChamferModeBack) stringValue],
5959

60+
},
61+
@"ARWorldAlignment": @{
62+
@"Gravity": @(ARWorldAlignmentGravity),
63+
@"GravityAndHeading": @(ARWorldAlignmentGravityAndHeading),
64+
@"Camera": @(ARWorldAlignmentCamera),
6065
}
6166
};
6267
}
6368

6469
RCT_EXPORT_VIEW_PROPERTY(debug, BOOL)
6570
RCT_EXPORT_VIEW_PROPERTY(planeDetection, BOOL)
6671
RCT_EXPORT_VIEW_PROPERTY(lightEstimation, BOOL)
72+
RCT_EXPORT_VIEW_PROPERTY(worldAlignment, NSInteger)
6773

6874
RCT_EXPORT_VIEW_PROPERTY(onPlaneDetected, RCTBubblingEventBlock)
6975
RCT_EXPORT_VIEW_PROPERTY(onPlaneUpdate, RCTBubblingEventBlock)

0 commit comments

Comments
 (0)