ArSceneView

public class ArSceneView

A SurfaceView that integrates with ARCore and renders a scene.

Inherited Constants

Inherited Fields

Public Constructors

ArSceneView(Context context)
Constructs a ArSceneView object and binds it to an Android Context.
ArSceneView(Context context, AttributeSet attrs)
Constructs a ArSceneView object and binds it to an Android Context.

Public Methods

Frame
getArFrame()
Returns the most recent ARCore Frame if it is available.
int
getCameraStreamRenderPriority()
Get the render priority that control the order of rendering the camera stream.
PlaneRenderer
getPlaneRenderer()
Returns PlaneRenderer, used to control plane visualization.
Session
getSession()
Returns the ARCore Session used by this view.
boolean
isEnvironmentalHdrLightingAvailable()
Returns true if the ARCore camera is configured with Config.LightEstimationMode.ENVIRONMENTAL_HDR.
boolean
isLightDirectionUpdateEnabled()
Checks whether the sunlight is being updated every frame based on the Environmental HDR lighting estimate.
boolean
void
pause()
Pauses the rendering thread and ARCore session.
CompletableFuture<Void>
pauseAsync(Executor executor)
Non blocking call to pause the rendering thread and ARCore session.
void
resume()
Resumes the rendering thread and ARCore session.
CompletableFuture<Void>
resumeAsync(Executor executor)
Non blocking call to resume the rendering thread and ARCore session in the background

This must be called from onResume().

void
setCameraStreamRenderPriority(int priority)
Set the render priority to control the order of rendering the camera stream.
void
setLightDirectionUpdateEnabled(boolean isLightDirectionUpdateEnabled)
Sets whether the sunlight direction generated from Environmental HDR lighting should be updated every frame.
void
setLightEstimationEnabled(boolean enable)
Enable Light Estimation based on the camera feed.
void
setupSession(Session session)
Setup the view with an AR Session.

Inherited Methods

Public Constructors

public ArSceneView (Context context)

Constructs a ArSceneView object and binds it to an Android Context.

In order to have rendering work correctly, setupSession(Session) must be called.

Parameters
context the Android Context to use

public ArSceneView (Context context, AttributeSet attrs)

Constructs a ArSceneView object and binds it to an Android Context.

In order to have rendering work correctly, setupSession(Session) must be called.

Parameters
context the Android Context to use
attrs the Android AttributeSet to associate with

Public Methods

public Frame getArFrame ()

Returns the most recent ARCore Frame if it is available. The frame is updated at the beginning of each drawing frame. Callers of this method should not retain a reference to the return value, since it will be invalid to use the ARCore frame starting with the next frame.

public int getCameraStreamRenderPriority ()

Get the render priority that control the order of rendering the camera stream. The priority is between a range of 0 (rendered first) and 7 (rendered last).

The default value is 7, which forces the camera stream to render last. This is best for performance because it prevents overdraw. However, when using a material as an occluder (for example, in the augmented faces sample), this should be changed. Otherwise, the occluder will occlude the camera stream and black will be rendered.

public PlaneRenderer getPlaneRenderer ()

Returns PlaneRenderer, used to control plane visualization.

public Session getSession ()

Returns the ARCore Session used by this view.

public boolean isEnvironmentalHdrLightingAvailable ()

Returns true if the ARCore camera is configured with Config.LightEstimationMode.ENVIRONMENTAL_HDR. When Environmental HDR lighting mode is enabled, the resulting light estimates will be applied to the Sceneform Scene.

Returns
  • true if HDR lighting is enabled in Sceneform because ARCore HDR lighting estimation is enabled.

public boolean isLightDirectionUpdateEnabled ()

Checks whether the sunlight is being updated every frame based on the Environmental HDR lighting estimate.

Returns
  • true if the sunlight direction is updated every frame, false otherwise.

public boolean isLightEstimationEnabled ()

Returns
  • returns true if light estimation is enabled.

public void pause ()

Pauses the rendering thread and ARCore session.

This must be called from onPause().

public CompletableFuture<Void> pauseAsync (Executor executor)

Non blocking call to pause the rendering thread and ARCore session.

This should be called from onPause().

If pauseAsync is called while another pause or resume is in progress, the pause will be enqueued and happen after the current operation completes.

Parameters
executor
Returns
  • A CompletableFuture completed on the main thread on the pause has completed. The future Will will be completed exceptionally if the resume can not be done.

public void resume ()

Resumes the rendering thread and ARCore session.

This must be called from onResume().

Throws
CameraNotAvailableException if the camera can not be opened

public CompletableFuture<Void> resumeAsync (Executor executor)

Non blocking call to resume the rendering thread and ARCore session in the background

This must be called from onResume().

If called while another pause or resume is in progress, the resume will be enqueued and happen after the current operation completes.

Parameters
executor
Returns
  • A CompletableFuture completed on the main thread once the resume has completed. The future will be completed exceptionally if the resume can not be done.

public void setCameraStreamRenderPriority (int priority)

Set the render priority to control the order of rendering the camera stream. The priority is between a range of 0 (rendered first) and 7 (rendered last).

The default value is 7, which forces the camera stream to render last. This is best for performance because it prevents overdraw. However, when using a material as an occluder (for example, in the augmented faces sample), this should be changed. Otherwise, the occluder will occlude the camera stream and black will be rendered.

Parameters
priority

public void setLightDirectionUpdateEnabled (boolean isLightDirectionUpdateEnabled)

Sets whether the sunlight direction generated from Environmental HDR lighting should be updated every frame. If false the light direction will be updated a single time and then no longer change.

This may be used to turn off shadow direction updates when they are distracting or unwanted.

The default state is true, with sunlight direction updated every frame.

Parameters
isLightDirectionUpdateEnabled

public void setLightEstimationEnabled (boolean enable)

Enable Light Estimation based on the camera feed. The color and intensity of the sun's indirect light will be modulated by values provided by ARCore's light estimation. Lit objects in the scene will be affected.

Parameters
enable set to true to enable Light Estimation or false to use the default estimate, which is a pixel intensity of 1.0 and color correction value of white (1.0, 1.0, 1.0).

public void setupSession (Session session)

Setup the view with an AR Session. This method must be called once to supply the ARCore session. The session is needed for any rendering to occur.

The session is expected to be configured with the update mode of LATEST_CAMERA_IMAGE. Without this configuration, the updating of the ARCore session could block the UI Thread causing poor UI experience.

Parameters
session the ARCore session to use for this view