viromedia / viro

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

Move object along detected ground plane via camera center (without dragging/touch events) #990

Open skizzo opened 1 year ago

skizzo commented 1 year ago

Environment

  1. Development OS: Mac (OS: Ventura 13.3.1 (a))
  2. Device OS & Version: Android 12
  3. Version: ViroReact: 2.23.0, React Native: 0.71.7, React: 18.2.0
  4. Device(s): Samsung Galaxy A71 (SM-A715F)

Description

I would like to place an object (in my case, a simple ViroBox) on a ground plane that has been before detected manually. For this, I would need to continuously determine a 3D position on (/relative to) said ground floor (which itself is a very thing ViroBox) based on which direction the camera is currently facing.

I am aware that this could be achieved by using a drag plane, but need to avoid any user interaction except rotating the device, so manually dragging the object along the ground plane is not an option.

I tried to illustrate the issue in the following image:

ViroArCameraProjectionProblem_All

Possible Approaches

1: ViroARScene.performARHitTestWithPoint(x,y)

2: ViroARScene.getCameraOrientationAsync() + ViroBox.getTransformAsync()


So basically my question is: Can I (and if yes, how) "convert" the camera center (a 2D point) to a 3D point (either in world coordinates, or relative to my found anchor) in my Viro 3D scene?

Thank you for any insights and this great library in general!