Most visited

Recently visited

ViroView

public abstract class ViroView
extends FrameLayout implements Application.ActivityLifecycleCallbacks

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.viro.core.ViroView
Known Direct Subclasses
ViroViewARCore ViroViewARCore is a ViroView for rendering augmented reality scenes using Google's ARCore API for tracking. 
ViroViewGVR ViroViewGVR is a ViroView for rendering content in stereo for VR headsets using the Google GVR SDK. 
ViroViewOVR ViroViewOVR is a ViroView for rendering content in stereo for VR headsets using the Oculus Mobile SDK. 
ViroViewScene ViroViewScene is a ViroView for rendering a Scene on a simple Android View. 


ViroView is the entrypoint for Viro applications, it enables the rendering of 3D AR and VR content to an Android View. To use ViroView, instantiate one of its subclasses:

With the desired ViroView instantiated, it can then be used by creating a Scene (or ARScene for AR), adding content to the Scene, and assigning it to the ViroView with setScene(Scene).

Note that after instantiation, the ViroView will validate your Viro API Key. To do this, pass your API key into AndroidManifest.xml metadata as .

Summary

Public methods

void dispose()

Release native resources associated with this ViroView.

final Controller getController()

Retrieve the Controller for this view.

float getFieldOfView()

Get the field of view for this camera, along the major (larger) axis.

Vector getLastCameraForwardRealtime()

Get the direction in which the Camera is facing (e.g.

Vector getLastCameraPositionRealtime()

Get the real-time world position from the current point of view (Camera).

Vector getLastCameraRotationEulerRealtime()

Get the real-time local orientation from the current point of view (Camera), expressed as three Euler angles.

abstract ViroMediaRecorder getRecorder()

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

Scene getScene()

Get the Scene that this ViroView is currently rendering.

final ViroContext getViroContext()

Get the ViroContext for this ViroView.

boolean isBloomEnabled()

Returns true if bloom is enabled for this ViroView.

boolean isHDREnabled()

Returns true if HDR rendering is enabled for this ViroView.

boolean isPBREnabled()

Returns true if physically-based rendering is enabled for this ViroView.

boolean isShadowsEnabled()

Returns true if dynamic shadows are enabled for this ViroView.

void performSceneHitTestRay(Vector origin, Vector ray, boolean isHighAccuracyTest, HitTestListener callback)

Performs a hit-test along the ray defined by the the given origin and direction in world coordinates.

void performSceneHitTestWithPoint(Point point, boolean isHighAccuracyTest, HitTestListener callback)

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

Vector projectPoint(Vector point)

Converts the given 3D point in the world into its corresponding 2D point on the screen.

abstract void recenterTracking()

For VR applications, re-centers the head orientation.

void setBloomEnabled(boolean enabled)

Enable or disable bloom.

void setCameraListener(CameraListener listener)

Set a CameraListener to receive updates whenever the camera's position or orientation changes.

void setFrameListener(FrameListener listener)

Set a FrameListener to receive updates when a frame is drawn.

void setHDREnabled(boolean enabled)

When HDR rendering is enabled, Viro uses a deeper color space and renders to a floating point texture, where a tone-mapping algorithm is applied to preserve fine details in both bright and dark regions of the scene.

void setPBREnabled(boolean enabled)

Enable or disable physically-based rendering.

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.

void setShadowsEnabled(boolean enabled)

Enable or disable rendering dynamic shadows.

abstract void setVRModeEnabled(boolean vrModeEnabled)

For VR applications, set this to true to render in stereo mode.

Vector unprojectPoint(Vector point)

Converts the given 2D point on the view into its corresponding 3D point in world coordinates.

Public methods

dispose

void dispose ()

Release native resources associated with this ViroView.

getController

Controller getController ()

Retrieve the Controller for this view. Controller represents the user interface through which the user interacts with the Scene. The exact form of Controller depends on the underlying platform. For example, for Daydream this represents the Daydream controller (the laser pointer). For Cardboard and GearVR, Controller is effectively the head-mounted display itself (and its tap button).

Returns
Controller The Controller for this ViroView.

getFieldOfView

float getFieldOfView ()

Get the field of view for this camera, along the major (larger) axis. Field of view is an angle that determines how wide or narrow the camera lens is when rendering the scene.

The major axis is the axis with the larger dimension: the X axis in landscape mode, or the Y axis in portrait mode. By specifying the field of view in terms of the major axis, Viro can keep the field of view consistent upon orientation changes, when the major/minor axes swap.

You can set the field of view when using a ViroViewScene by creating a Camera, setting the camera's field of view with setFieldOfView(float), and making that Camera's Node the point of view through setPointOfView(Node). The default field of view for ViroViewScene is 90 degrees.

The field of view cannot be set for ViroViewARCore or ViroViewGVR: on those platforms, field of view is fixed by the VR headset or AR camera.

Returns
float The field of view across the major axis, in degrees.

getLastCameraForwardRealtime

Vector getLastCameraForwardRealtime ()

Get the direction in which the Camera is facing (e.g. in the direction of the reticle).

Returns
Vector The direction the Camera is facing.

getLastCameraPositionRealtime

Vector getLastCameraPositionRealtime ()

Get the real-time world position from the current point of view (Camera). The position returned is real-time in that it is the position the Camera currently appears on-screen.

Returns
Vector The real-time position as a Vector.

getLastCameraRotationEulerRealtime

Vector getLastCameraRotationEulerRealtime ()

Get the real-time local orientation from the current point of view (Camera), expressed as three Euler angles. Specifically, the X component is rotation about the X axis (pitch), the Y component is rotation about the node's Y axis (yaw), and Z is the rotation around the node's Z axis (roll). This returns the real-time orientation, meaning the orientation of the Camera as it currently appears on-screen. The returned orientation is the Camera's world orientation.

Returns
Vector The rotation in Euler form as a Vector in radians.

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.

getScene

Scene getScene ()

Get the Scene that this ViroView is currently rendering.

Returns
Scene The Scene being rendered by this ViroView.

getViroContext

ViroContext getViroContext ()

Get the ViroContext for this ViroView. The ViroContext contains internal 3D state, and is needed when constructing certain geometries and objects.

Returns
ViroContext The ViroContext for this ViroView.

isBloomEnabled

boolean isBloomEnabled ()

Returns true if bloom is enabled for this ViroView.

Returns
boolean True if bloom is enabled.

isHDREnabled

boolean isHDREnabled ()

Returns true if HDR rendering is enabled for this ViroView.

Returns
boolean True if HDR is enabled.

isPBREnabled

boolean isPBREnabled ()

Returns true if physically-based rendering is enabled for this ViroView.

Returns
boolean True if PBR is enabled.

isShadowsEnabled

boolean isShadowsEnabled ()

Returns true if dynamic shadows are enabled for this ViroView.

Returns
boolean True if shadows are enabled.

performSceneHitTestRay

void performSceneHitTestRay (Vector origin, 
                Vector ray, 
                boolean isHighAccuracyTest, 
                HitTestListener callback)

Performs a hit-test along the ray defined by the the given origin and direction in world coordinates. The hit-test returns all real-world features that are intersected by the ray.

Parameters
origin Vector: The ray origin in world coordinates.

ray Vector: The normalized direction of the ray in world coordinates.

isHighAccuracyTest boolean: True if you want this hit-test to use the geometry of each object to find intersection points, false if you want to only use the bounding box of each object. Performing high accuracy hit-tests has a significant performance impact.

callback HitTestListener: The callback that will receive the ARHitTestResult results. Performs a hit-test from the camera's position in the direction of the given ray. The hit-test returns all virtual world features that are intersected by the ray.

performSceneHitTestWithPoint

void performSceneHitTestWithPoint (Point point, 
                boolean isHighAccuracyTest, 
                HitTestListener callback)

Performs a hit-test searching for all virtual 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 from this X, Y screen point.

isHighAccuracyTest boolean: True if you want this hit-test to use the geometry of each object to find intersection points, false if you want to only use the bounding box of each object. Performing high accuracy hit-tests has a significant performance impact.

callback HitTestListener: The callback that will receive the HitTestResult results.

projectPoint

Vector projectPoint (Vector point)

Converts the given 3D point in the world into its corresponding 2D point on the screen. Note that each 2D point on the view corresponds to a continuous segment of 3D points in the world, each at a different depth between the near and far clipping planes. The Z coordinate in the returned Vector identifies the depth of the projected point, where 0.0 coincides with the near clipping plane, 1.0 coincides with the far clipping plane, and all other values are linear interpolations between the two.

Parameters
point Vector: Get the 2D point corresponding to this 3D world coordinate.

Returns
Vector The 2D point in the view's coordinate system. The Z coordinate represents the depth from 0.0 to 1.0.

recenterTracking

void recenterTracking ()

For VR applications, re-centers the head orientation. This resets the yaw to zero, but leaves pitch and roll unmodified.

setBloomEnabled

void setBloomEnabled (boolean enabled)

Enable or disable bloom. Bloom adds a soft glow to bright areas in scene, simulating the way bright highlights appear to the human eye. To make an object bloom, this property must be enabled, and the objects's threshold for bloom must be set via setBloomThreshold(float).

Parameters
enabled boolean: True to enable bloom for this ViroView.

setCameraListener

void setCameraListener (CameraListener listener)

Set a CameraListener to receive updates whenever the camera's position or orientation changes. The camera is the current point of view of the user.

Parameters
listener CameraListener: The CameraListener to receive updates.

setFrameListener

void setFrameListener (FrameListener listener)

Set a FrameListener to receive updates when a frame is drawn.

Parameters
listener FrameListener: The FrameListener to receive updates.

setHDREnabled

void setHDREnabled (boolean enabled)

When HDR rendering is enabled, Viro uses a deeper color space and renders to a floating point texture, where a tone-mapping algorithm is applied to preserve fine details in both bright and dark regions of the scene. If HDR is disabled, then features like Bloom and PBR will not work, and tone-mapping will be disabled.

HDR is not supported on all devices.

Parameters
enabled boolean: True to enable HDR for this ViroView.

setPBREnabled

void setPBREnabled (boolean enabled)

Enable or disable physically-based rendering. Physically based rendering, or PBR, produces more realistic lighting results for your scenes, and provides a more intuitive workflow for artists. To use PBR, this property must be enabled, and Materials must use the PHYSICALLY_BASED lighting model. PBR is controlled by a variety of properties, see PHYSICALLY_BASED for details.

Parameters
enabled boolean: True to enable PBR for this ViroView.

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.

setShadowsEnabled

void setShadowsEnabled (boolean enabled)

Enable or disable rendering dynamic shadows. If shadows are disabled here, shadow casting Lights will simply not cast a shadow.

Shadows are not supported on all devices.

Parameters
enabled boolean: True to enable dynamic shadows for this ViroView.

setVRModeEnabled

void setVRModeEnabled (boolean vrModeEnabled)

For VR applications, set this to true to render in stereo mode. Stereo renders two images: one for the left eye and one for the right, each perturbed slightly to simulate depth. This mode is meant to be used in a VR headset. Set to false to render to the entire screen, for use when users do not have a headset.

Defaults to true.

Parameters
vrModeEnabled boolean: True to enable VR mode.

unprojectPoint

Vector unprojectPoint (Vector point)

Converts the given 2D point on the view into its corresponding 3D point in world coordinates. Note that each 2D point on the view corresponds to a continuous segment of 3D points in the world, each at a different depth between the near and far clipping planes. The Z coordinate in the given Vector identifies the depth to return, where 0.0 coincides with the near clipping plane, 1.0 coincides with the far clipping plane, and all other values are linear interpolations between the two.

This method can be used for advanced hit-testing against real-world or virtual objects.

Parameters
point Vector: Get the 3D ray corresponding to this point in the 2D view's coordinate system. The Z coordinate represents the depth from 0.0 to 1.0.

Returns
Vector The 3D point in world coordinates.

Hooray!