viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

worldAlignment bug? #185

Closed domvon closed 6 years ago

domvon commented 6 years ago

Hi Viro team and community,

We are setting worldAligment="GravityAndHeading" but the the AR scene's Z-axis only aligns to North-South when the scene is initialized. No alignment adjustments seem to happen later on.

So if I launch the app near a magnetic source (motor, refrigerator, etc), the scene's Z-axis is of course completely off (totally expected). But less expected is the fact that the Z-axis stays off, and never realigns to North-South over time as I walk away from the source, unless the scene is reinitialized.

Is this a Viro issue? Or could this be how ARKit behaves? Our goal is to be constantly aligned. Any feedback or workaround is hugely appreciated. Thanks.

achuvm commented 6 years ago

Hey @domvon,

This is currently how ARKit behaves.

However, we do have a function resetARSession() on the ViroARSceneNavigator that will allow you reset tracking and that should also re-align the ARSession's world origin with heading.

You should invoke that method within your ViroARScene with this.props.arSceneNavigator.resetARSession(true, true).

To determine whether or not your heading is off, you can consider calculating the difference between the detected heading and the camera's Y rotation (keep in mind axis-rotations are dependent on the values of the other axis).

To grab the heading, you should be able to use any React Native compass/geolocation component such as react-native-simple-compass or react-native-compass.

You can get the camera's position with getCameraOrientationAsync() on ViroARScene.

Let us know if this works for you