Most visited

Recently visited

ViroViewARCore

public class ViroViewARCore
extends ViroView

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.viro.core.ViroView
           ↳ com.viro.core.ViroViewARCore


ViroViewARCore is a ViroView for rendering augmented reality scenes using Google's ARCore API for tracking. When using this view, the camera's real-time video feed will be rendered to the background of your ARScene, and the coordinate system of Viro's virtual content and the real world will be fused.

The coordinate system's origin is the location of the device when it starts the application. Units are in meters.

Summary

Nested classes

enum ViroViewARCore.AnchorDetectionType

ARCore, which underlies Viro's augmented reality system, can be set to detect various types of real world features (anchors) by continually scanning the incoming video feed from the device camera. 

Public constructors

ViroViewARCore(Context context, RendererStartListener rendererStartListener)

Create a new ViroViewARCore with the default RendererConfiguration.

ViroViewARCore(Context context, RendererStartListener rendererStartListener, RendererConfiguration config)

Create a new ViroViewARCore with the given RendererConfiguration, which determines the rendering techniques and rendering fidelity to use for this View.

Public methods

void dispose()

Release native resources associated with this ViroView.

int getCameraTextureName()

Get the OpenGL texture name (ID) that ViroCore uses to render the camera background each frame.

ViroMediaRecorder getRecorder()

Returns a ViroMediaRecorder, which can be used to take screenshots of the Scene or record video.

static boolean isSupported(Context context)

Checks if AR is supported on the target device and if the ARCore apk/sdk is present on the device.

void performARHitTest(Point point, ARHitTestListener callback)

Performs a hit-test searching for all real-world features at the given 2D point on the view.

void performARHitTestWithPosition(Vector position, ARHitTestListener callback)

Performs a hit-test along the ray from the camera's current position to the given position in world coordinates.

void performARHitTestWithRay(Vector ray, ARHitTestListener callback)

Performs a hit-test from the camera's position in the direction of the given ray.

void setAnchorDetectionTypes(EnumSet<ViroViewARCore.AnchorDetectionType> types)

Set the types of ARAnchors the system should attempt to detect and track.

void setCameraARHitTestListener(ARHitTestListener hitTestListener)

Set the ARHitTestListener.

void setCameraRotation(int rotation)

Set the rotation of the background camera view.

void setCameraRotationAutomatic(boolean automatic)
void setPointOfView(Node node)

Make the given Node the point of view for the user.

void setScene(Scene scene)

Set the Scene this ViroView should render.

Public constructors

ViroViewARCore

ViroViewARCore (Context context, 
                RendererStartListener rendererStartListener)

Create a new ViroViewARCore with the default RendererConfiguration.

Parameters
context Context: The activity context.

rendererStartListener RendererStartListener: Runnable to invoke when the renderer has finished initializing. Optional, may be null.

ViroViewARCore

ViroViewARCore (Context context, 
                RendererStartListener rendererStartListener, 
                RendererConfiguration config)

Create a new ViroViewARCore with the given RendererConfiguration, which determines the rendering techniques and rendering fidelity to use for this View.

Parameters
context Context: The activity context.

rendererStartListener RendererStartListener: Runnable to invoke when the renderer has finished initializing. Optional, may be null.

config RendererConfiguration: The RendererConfiguration to use.

Public methods

dispose

void dispose ()

Release native resources associated with this ViroView.

getCameraTextureName

int getCameraTextureName ()

Get the OpenGL texture name (ID) that ViroCore uses to render the camera background each frame. This may be used by advanced applications that want to process raw image data received from the camera. The texture is of type GL_TEXTURE_EXTERNAL_OES, and uses a samplerExternalOES in shaders. Returns 0 if the camera texture has not yet been initialized.

Returns
int The camera texture ID. Returns 0 if the camera texture has not yet been initialized.

getRecorder

ViroMediaRecorder getRecorder ()

Returns a ViroMediaRecorder, which can be used to take screenshots of the Scene or record video. Currently only the ViroViewARCore supports the media recorder.

Returns
ViroMediaRecorder The ViroMediaRecorder, or null if not supported by the platform.

isSupported

boolean isSupported (Context context)

Checks if AR is supported on the target device and if the ARCore apk/sdk is present on the device. If this method returns false, attempts to create ViroViewARCore will throw an exception

Parameters
context Context: The Context of your app

Returns
boolean

performARHitTest

void performARHitTest (Point point, 
                ARHitTestListener callback)

Performs a hit-test searching for all real-world features at the given 2D point on the view. Note that since a single 2D point on view corresponds to a 3D ray in the scene, multiple results may be returned (each at a different depth).

Parameters
point Point: Perform the hit-test at this Point in the 2D view's coordinate system.

callback ARHitTestListener: The callback that will receive the ARHitTestResult results.

performARHitTestWithPosition

void performARHitTestWithPosition (Vector position, 
                ARHitTestListener callback)

Performs a hit-test along the ray from the camera's current position to the given position in world coordinates. The hit-test returns all real-world features that are intersected by the ray.

Parameters
position Vector: Perform the hit-test along the ray from the camera's position to this position.

callback ARHitTestListener: The callback that will receive the ARHitTestResult results.

performARHitTestWithRay

void performARHitTestWithRay (Vector ray, 
                ARHitTestListener callback)

Performs a hit-test from the camera's position in the direction of the given ray. The hit-test returns all real-world features that are intersected by the ray.

Parameters
ray Vector: Perform the hit-test from the camera's position in the direction of this ray.

callback ARHitTestListener: The callback that will receive the ARHitTestResult results.

setAnchorDetectionTypes

void setAnchorDetectionTypes (EnumSet<ViroViewARCore.AnchorDetectionType> types)

Set the types of ARAnchors the system should attempt to detect and track. The ARScene.Listener will receive a callback whenever an ARAnchor of one of these enabled types is found.

Parameters
types EnumSet: The set of anchor types that should be tracked.

setCameraARHitTestListener

void setCameraARHitTestListener (ARHitTestListener hitTestListener)

Set the ARHitTestListener. When an ARHitTestListener is registered, it will be continually notified of hit tests from the camera's forward vector into the AR environment. This is an efficient way to be notified of real-world objects intersecting the center of the user's AR screen.

Parameters
hitTestListener ARHitTestListener: The callback that will receive the ARHitTestResult results.

setCameraRotation

void setCameraRotation (int rotation)

Set the rotation of the background camera view. This is derived from one of the Surface constants for rotation; e.g. ROTATION_0, ROTATION_90, ROTATION_180, or ROTATION_270.

Typically this value should be changed when the device orientation changes; e.g., in onConfigurationChanged(Configuration). For example:

  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
      mViroViewARCore.setCameraRotation(display.getRotation());
  }
 

Parameters
rotation int: The rotation constant for the background camera view.

setCameraRotationAutomatic

void setCameraRotationAutomatic (boolean automatic)

Parameters
automatic boolean

setPointOfView

void setPointOfView (Node node)

Make the given Node the point of view for the user. The Scene in this ViroView will be rendered from the perspective of the given Node's Camera. This method is used to change the user's view of the scene. Note that when in AR or VR modes, the point of view is automatically computed based on the device's rotation and position in the world. This method is primarily for use with ViroViewScene.

Parameters
node Node: The Node whose Camera will be used for the point of view.

setScene

void setScene (Scene scene)

Set the Scene this ViroView should render. ARScene should be used for augmented reality applications.

Parameters
scene Scene: The Scene to render in this ViroView.

Hooray!