Import and Preview 3D Assets

Learn how to import 3D models, convert them into Sceneform format, and preview them in Android Studio.

Install the Google Sceneform Tools (Beta) plugin

In Android Studio open the Plugins settings:

  • Windows: File > Settings > Plugins > Browse Repositories
  • macOS: Android Studio > Preferences > Plugins

Then click Browse repositories and install the Google Sceneform Tools (Beta).

Import a 3D asset

Sceneform supports 3D assets in OBJ, FBX, and glTF formats. Follow these steps to import an asset:

  1. Verify that your project's app folder contains a sampledata folder. If the folder does not exist, create it by right-clicking the app folder in the Project window and then selecting New > Sample Data Directory.

    The sampledata folder is part of your Android Studio project, but its contents are not included in your APK.

  2. Copy the 3D asset into the sampledata folder.

    Do not copy the asset into the assets or res folders as this will cause it to be included in your APK unnecessarily.

  3. Right click the 3D asset and select Import Sceneform Asset to begin the import process.

    • Source Asset Path: The OBJ, FBX, or glTF asset to import.
    • Material Path: a value of default means the asset will use Sceneform's built-in material. Advanced users who have created a custom material can use it in the asset by specifying the *.mat file. For more information, see Using custom materials.
    • .sfa and .sfb Output Paths are described later.

When you click Finish, the wizard does the following:

  • Adds the Sceneform gradle plugin to your project's build.gradle if it doesn't already exist.

    dependencies {
        classpath 'com.google.ar.sceneform:plugin:1.4.0'
    }
    
  • Updates your app's build.gradle file to include an apply plugin line, and a sceneform.asset() entry for each imported asset:

    apply plugin: 'com.google.ar.sceneform.plugin'
    
    sceneform.asset('sampledata/models/andy.obj', // Source Asset Path
            'default',                            // Material Path
            'sampledata/models/andy.sfa',         // .sfa Output Path
            'src/main/res/raw/andy')              // .sfb Output Path
    

    These entries create two gradle tasks:

    • createAsset-<asset-name>: creates an SFA (Sceneform Asset Definition) file if it does not yet exist.

      The file contains a complete, human-readable description of the asset. It points to the models and textures in your source asset, and also defines materials by providing material parameters for Sceneform's physically based materials.

      This task will not overwrite an existing SFA file, which means any modifications you make to the SFA file after import won't be overwritten.

    • compileAsset-<asset-name>: compiles the SFA file into an SFB (the Sceneform Binary asset) file.

      This file gets built into your app's APK and is loaded at runtime to create the renderable.

    For more information, see the Sceneform Gradle Plugin reference.

  • Opens the SFA and SFB in the Viewer window, allowing you to iterate on the asset by modifying the SFA, compiling the asset, and previewing the SFB. See the SFA file format reference for a list of parameters you can tweak.

Create the Renderable

Once you have the asset in the SFB format, you can build a ModelRenderable and attach it to a node in the scene as follows:

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

Using custom materials

Sceneform's default materials make it easy for developers to get great looking results.

You can also use a custom material to deeply customize the way your assets look.

  1. Create a custom material definition file (*.mat). See the Custom Material Reference for more information.

  2. Apply the custom material to the asset in one of the following ways:

    • Specify the custom material in the wizard during the import process.

      If you have imported the asset before, you must delete the existing SFA and SFB file so that they can be regenerated. This method is preferred because the regenerated SFA's attributes and material parameters will match the ones supported by your custom material.

    • Open the asset definition file (*.sfa) change the source attribute.

      You might also need to manually add or remove attributes and material parameters in your SFA file to match the ones supported by your custom material.

Send feedback about...