Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for UI rotation gestures #123

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ARKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';

import { pickColors, pickColorsFromFile } from './lib/pickColors';
import { position, transition } from './components/lib/propTypes';
import generateId from './components/lib/generateId';

const ARKitManager = NativeModules.ARKitManager;
Expand Down Expand Up @@ -69,9 +70,12 @@ class ARKit extends Component {
{...this.props}
onTapOnPlaneUsingExtent={this.callback('onTapOnPlaneUsingExtent')}
onTapOnPlaneNoExtent={this.callback('onTapOnPlaneNoExtent')}
onRotationGesture={this.callback('onRotationGesture')}
onPlaneDetected={this.callback('onPlaneDetected')}
onPlaneRemoved={this.callback('onPlaneRemoved')}
onPlaneUpdate={this.callback('onPlaneUpdate')}
onTrackingState={this.callback('onTrackingState')}
onARKitError={this.callback('onARKitError')}
onEvent={this._onEvent}
/>
{state}
Expand Down Expand Up @@ -175,10 +179,16 @@ ARKit.pickColorsFromFile = pickColorsFromFile;
ARKit.propTypes = {
debug: PropTypes.bool,
planeDetection: PropTypes.bool,
origin: PropTypes.shape({
position,
transition,
}),
lightEstimationEnabled: PropTypes.bool,
autoenablesDefaultLighting: PropTypes.bool,
worldAlignment: PropTypes.number,
onARKitError: PropTypes.func,
onPlaneDetected: PropTypes.func,
onPlaneRemoved: PropTypes.func,
onFeaturesDetected: PropTypes.func,
// onLightEstimation is called rapidly, better poll with
// ARKit.getCurrentLightEstimation()
Expand All @@ -187,6 +197,7 @@ ARKit.propTypes = {
onTrackingState: PropTypes.func,
onTapOnPlaneUsingExtent: PropTypes.func,
onTapOnPlaneNoExtent: PropTypes.func,
onRotationGesture: PropTypes.func,
onEvent: PropTypes.func,
};

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


### 2017-12-21

- added `onPlaneRemoved`
- added `eulerAngles` to detected planes
- added `onARKitError` to ARKit
- added `origin` property to ARKit
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class ReactNativeARKit extends Component {
onLightEstimation={e => console.log(e.nativeEvent)}
onPlaneDetected={console.log} // event listener for plane detection
onPlaneUpdate={console.log} // event listener for plane update
onPlaneRemoved={console.log} // arkit sometimes removes detected planes
>
<ARKit.Box
position={{ x: 0, y: 0, z: 0 }}
Expand Down Expand Up @@ -176,15 +177,29 @@ AppRegistry.registerComponent('ReactNativeARKit', () => ReactNativeARKit);
| `planeDetection` | `Boolean` | `false` | ARKit plane detection.
| `lightEstimationEnabled` | `Boolean` | `false` | ARKit light estimation.
| `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.|
| `origin` | `{position, transition}` | Usually `{0,0,0}` is where you launched the app. If you want to have a different origin, you can set it here. E.g. if you set `origin={{position: {0,-1, 0}, transition: {duration: 1}}}` the new origin will be one meter below. If you have any objects already placed, they will get moved down using the given transition. All hit-test functions or similar will report coordinates relative to that new origin as `position`. You can get the original coordinates with `positionAbsolute` in these functions |

##### Events

| Event Name | Returns | Notes
|---|---|---|
| `onPlaneDetected` | `{ id, center, extent }` | When a plane is first detected.
| `onARKitError` | `ARKiterror` | will report whether an error occured while initializing ARKit. A common error is when the user has not allowed camera access. Another error is, if you use `worldAlignment=GravityAndHeading` and location service is turned off |
| `onLightEstimation` | `{ ambientColorTemperature, ambientIntensity }` | Light estimation on every frame. Called rapidly, better use polling. See `ARKit.getCurrentLightEstimation()`
| `onFeaturesDetected` | `{ featurePoints}` | Detected Features on every frame (currently also not throttled). Usefull to display custom dots for detected features. You can also poll this information with `ARKit.getCurrentDetectedFeaturePoints()`
| `onPlaneUpdate` | `{ id, center, extent }` | When a detected plane is updated
| `onPlaneDetected` | `Plane` | When a plane is first detected.
| `onPlaneUpdate` | `Plane` | When a detected plane is updated
| `onPlaneRemoved` | `Plane` | When a detected plane is updated
| `onRotationGesture` | `{ rotation, velocity }` | The rotation gesture recognizer enters the `begin` state as soon as the position of the user’s fingers changes in a way that indicates that rotation has begun. After the initial change, subsequent changes cause the gesture recognizer to enter the `change` state and update the angle of rotation. When the user’s fingers lift from the screen, the gesture recognizer enters the `end` state.

The `Plane` object has the following properties:

| Property | Description
|---|---|
| `id` | a unique id identifying the plane |
| `position` | the position of the plane (relative to the origin) |
| `positionAbsolute` | the absolute position of the plane |
| `extent` | the extent of the plane |
| `eulerAngles` | the rotation of the plane |

##### Static methods

Expand Down Expand Up @@ -253,7 +268,7 @@ Most objects take a material property with these sub-props:
| `doubleSided` | boolean | render both sides, default is `true` |
| `litPerPixel` | boolean | calculate lighting per-pixel or vertex [litPerPixel](https://developer.apple.com/documentation/scenekit/scnmaterial/1462580-litperpixel) |
| `lightingModel` | `ARKit.LightingModel.*` | [LightingModel](https://developer.apple.com/documentation/scenekit/scnmaterial.lightingmodel) |
| `blendMode` | `ARKit.BlendMode.*` | [BlendMode](https://developer.apple.com/documentation/scenekit/scnmaterial/1462585-blendmode) |
| `blendMode` | `ARKit.BlendMode.*` | [BlendMode](https://developer.apple.com/documentation/scenekit/scnmaterial/1462585-blendmode) |
| `fillMode` | `ARKit.FillMode.*` | [FillMode](https://developer.apple.com/documentation/scenekit/scnmaterial/2867442-fillmode)
| `shaders` | Object with keys from `ARKit.ShaderModifierEntryPoint.*` and shader strings as values | [Shader modifiers](https://developer.apple.com/documentation/scenekit/scnshadable) |
| `colorBufferWriteMask` | `ARKit.ColorMask.*` | [color mask](https://developer.apple.com/documentation/scenekit/scncolormask). Set to ARKit.ColorMask.None so that an object is transparent, but receives deferred shadows. |
Expand Down
Loading