Sceneform Overview

Sceneform empowers Android developers to work with ARCore without learning 3D graphics and OpenGL. It includes a high-level scene graph API, realistic physically based renderer, an Android Studio plugin for importing, viewing, and building 3D assets, and easy integration into ARCore that makes it straightforward to build AR apps.

This page explains key concepts in Sceneform by exploring the code in the HelloSceneform sample app. To setup the sample, see the ARCore Quickstart.

Add an ArFragment

The Sceneform API includes ArFragment, which can be added to an Android layout file, like any Android Fragment. For example, here is activity_ux.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.google.ar.sceneform.samples.hellosceneform.HelloSceneformActivity">

  <fragment android:name="com.google.ar.sceneform.ux.ArFragment"
      android:id="@+id/ux_fragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

</FrameLayout>

When the activity is launched and the layout is inflated, the fragment automatically performs some required checks:

  • It checks whether a compatible version of ARCore is installed and prompts the user to install or update as necessary.
  • It checks whether the app has access to the camera and asks the user for permission if it has not yet been granted.

Once complete, the fragment creates an ArSceneView (accessible via getArSceneView() and an ARCore Session.

The ArSceneView renders the camera images from the session on to its surface. It also highlights Planes (with the default PlaneRenderer) when they are detected by ARCore and in front of the camera.

Create a renderable

A Renderable is a 3D model, consisting of meshes, materials, and textures, that can be rendered on the screen by Sceneform.

Sceneform provides three ways to create Renderables: from standard Android widgets, from basic shapes/materials, and from 3D asset files (OBJ, FBX, glTF).

The sample app creates a renderable from a 3D asset file andy.obj. The app's build.gradle includes a rule for converting the asset to a resource that Sceneform can read.

apply plugin: 'com.google.ar.sceneform.plugin'

sceneform.asset('sampledata/models/andy.obj',
        'default',
        'sampledata/models/andy.sfa',
        'src/main/res/raw/andy')

Here's how to load the resource as a renderable:

ModelRenderable.builder()
    .setSource(this, R.raw.andy)
    .build()
    .thenAccept(renderable -> andyRenderable = renderable)
    .exceptionally(
        throwable -> {
        Log.e(TAG, "Unable to load Renderable.", throwable);
        return null;
    });

Sceneform provides an Android Studio plugin that helps you import, convert, and preview 3D models. For more information, see Import and Preview 3D Assets.

Build the Scene

The fragment's ARSceneView has a Scene attached to it. The scene is a tree-like data structure that holds Nodes—which are the virtual objects to be rendered.

Node node = new Node();
node.setParent(arFragment.getArSceneView().getScene());
node.setRenderable(andyRenderable);

Each node contains all the information Sceneform needs to render it (including its position, orientation, and renderable object) as well as interact with it (including its collision shape and event listeners).

Nodes can be added to other nodes, forming a parent-child relationship. When a node is a child of another node, it moves, rotates, and scales with its parent—like how your arms move when your body moves. A node can have multiple children, but only one parent, thus forming a tree-like structure. This structure is known as the scene graph.

Each frame, Sceneform renders the scene graph from the Camera's point of view (defined by ARCore motion tracking). Your app can interact with the scene by listening for touch and gesture events, performing hitTests against nodes, and placing anchors. For more info, see Build and Interact with the Scene.

Send feedback about...