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. 

enum ViroViewARCore.StartupError

Errors returned by the ViroViewARCore.StartupListener, in response to Viro failing to initialize. 

interface ViroViewARCore.StartupListener

Callback interface for responding to ViroViewARCore startup success or failure. 

Public constructors

ViroViewARCore(Context context, ViroViewARCore.StartupListener startupListener)

Create a new ViroViewARCore with the default RendererConfiguration.

ViroViewARCore(Context context, ViroViewARCore.StartupListener startupListener, 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 isDeviceCompatible(Context context)

Checks if ARCore is compatible with the target 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 setScene(Scene scene)

Set the Scene this ViroView should render.

Public constructors

ViroViewARCore

ViroViewARCore (Context context, 
                ViroViewARCore.StartupListener startupListener)

Create a new ViroViewARCore with the default RendererConfiguration. This constructor will immediately throw a DeviceNotCompatibleException if ARCore is not compatible with this device. You can also check for this condition with the static isDeviceCompatible(Context) method.

If ARCore is compatible with the device, then Viro will check if it is installed and prompt the user to install it if it isn't. Any error encountered during this process will be reported as a ViroViewARCore.StartupError to the provided ViroViewARCore.StartupListener. Many of these errors are asynchronous: for example, if the user does not have ARCore installed and declines to install it when prompted, or if the install fails.

Parameters
context Context: The activity context.

startupListener ViroViewARCore.StartupListener: Listener to respond to startup success or failure. Will be notified of any errors encountered while initializing AR and the renderer. Optional, may be null.

ViroViewARCore

ViroViewARCore (Context context, 
                ViroViewARCore.StartupListener startupListener, 
                RendererConfiguration config)

Create a new ViroViewARCore with the given RendererConfiguration, which determines the rendering techniques and rendering fidelity to use for this View. This constructor will immediately throw a DeviceNotCompatibleException if ARCore is not compatible with this device. You can also check for this condition with the static isDeviceCompatible(Context) method.

If ARCore is compatible with the device, then Viro will check if it is installed and prompt the user to install it if it isn't. Any error encountered during this process will be reported as a ViroViewARCore.StartupError to the provided ViroViewARCore.StartupListener. Many of these errors are asynchronous: for example, if the user does not have ARCore installed and declines to install it when prompted, or if the install fails.

Parameters
context Context: The activity context.

startupListener ViroViewARCore.StartupListener: Listener to respond to startup success or failure. Will be notified of any errors encountered while initializing AR and the renderer. Optional, may be null.

config RendererConfiguration: The RendererConfiguration to use. May be null to use the default configuration.

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.

isDeviceCompatible

boolean isDeviceCompatible (Context context)

Checks if ARCore is compatible with the target device. This does not indicate whether ARCore is installed. If this method returns false, attempts to create ViroViewARCore will throw an exception.

Parameters
context Context: The Context of your application.

Returns
boolean True if the current device is compatible with ARCore.

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.

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!