Search code examples
androidkotlinsurfaceviewgoogle-filament

How to set background color in Google Filament for Android?


I'm following this tutorial for Filament: https://medium.com/@philiprideout/getting-started-with-filament-on-android-d10b16f0ec67

How do I set the background color to white?

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        surfaceView = SurfaceView(this).apply {
            setContentView(this)
        }
        choreographer = Choreographer.getInstance()
        modelViewer = ModelViewer(surfaceView)
        surfaceView.setOnTouchListener(modelViewer)

        loadGlb("DamagedHelmet")

        modelViewer.scene.skybox = Skybox.Builder().build(modelViewer.engine)
        loadEnvironment("venetian_crossroads_2k")

    }

I've tried setting background color on the SurfaceView but that didn't work.

Currently, it looks like this (seems like the default is black):


Solution

  • I figured it out. I need to set the skybox color.

    For instance, this sets the color to red.

    modelViewer.view.blendMode = com.google.android.filament.View.BlendMode.OPAQUE
    modelViewer.scene.skybox = Skybox.Builder().color(0.81f, 0f, 0f, 0f).build(modelViewer.engine)