# Load and animate a GLB with lighting presets

Add `implementation("io.github.sceneview:sceneview:4.76.0")` to an Android
Compose app using the [supported toolchain](../quickstart.md). Put an animated
GLB at `app/src/main/assets/models/animated.glb`. An HTTPS URL also works.

The core composable is about 15 lines, excluding imports. It uses the bundled
neutral image-based environment, a key light and a softer fill light. Orbit,
pinch-to-zoom and two-finger pan are available by default.

```kotlin
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.github.sceneview.RenderQuality
import io.github.sceneview.SceneView
import io.github.sceneview.rememberEngine
import io.github.sceneview.rememberFillLightNode
import io.github.sceneview.rememberMainLightNode
import io.github.sceneview.rememberModelInstance
import io.github.sceneview.rememberModelLoader

@Composable
fun AnimatedGlbViewer(modelPath: String = "models/animated.glb", keyIntensity: Float = 100_000f) {
    val engine = rememberEngine()
    val loader = rememberModelLoader(engine)
    SceneView(
        modifier = Modifier.fillMaxSize(), engine = engine, modelLoader = loader,
        renderQuality = RenderQuality.Cinematic, autoFitContent = true,
        mainLightNode = rememberMainLightNode(engine) { intensity = keyIntensity },
        fillLightNode = rememberFillLightNode(engine) { intensity = keyIntensity * 0.3f },
    ) {
        rememberModelInstance(loader, modelPath)?.let { instance ->
            ModelNode(modelInstance = instance, autoAnimate = true, animationLoop = true)
        }
    }
}
```

`autoAnimate` plays the asset's animations; it cannot add motion to a static GLB.
Use `animationName = "Walk"` on `ModelNode` to select a clip that actually exists
in your asset. `autoFitContent` frames the model with the camera, preserving its
authored dimensions. `rememberModelInstance` returns `null` during loading or
after failure; use [load-state UI](native-ar-product-placement.md) when the user
needs progress or an error message.

Choose a rendering preset for the device: `RenderQuality.Cinematic` enables
costlier effects, `RenderQuality.Default` uses the standard setup, and
`RenderQuality.Performance` lowers rendering cost. These are rendering presets;
the key/fill intensities below are example lighting settings for this recipe.

| Lighting choice | `keyIntensity` | Fill (30% of key) |
|---|---:|---:|
| Soft | `50_000f` | `15_000f` |
| Studio | `100_000f` | `30_000f` |
| Bright | `150_000f` | `45_000f` |

Drive `keyIntensity` from Compose state to relight the scene. The remembered
light helpers reapply their configuration and request a frame when it changes.

## Optional HDR environment

For image-based lighting from your own asset, add these imports to the file:

```kotlin
import io.github.sceneview.ExperimentalSceneViewApi
import io.github.sceneview.environment.rememberHDREnvironment
import io.github.sceneview.rememberEnvironment
import io.github.sceneview.rememberEnvironmentLoader
```

Annotate `AnimatedGlbViewer` with `@OptIn(ExperimentalSceneViewApi::class)`.
Inside it, after creating `engine`, load a 2K HDR placed under your app's assets:

```kotlin
val environments = rememberEnvironmentLoader(engine)
val fallback = rememberEnvironment(environments)
val studio = rememberHDREnvironment(
    environmentLoader = environments,
    assetFileLocation = "environments/studio_2k.hdr",
    createSkybox = false,
)
```

Pass `environmentLoader = environments, environment = studio ?: fallback` to
`SceneView`. Loading keeps HDR reads and decoding off the main thread and runs
the Filament upload on the main thread. The initial load returns `null`; later
replacement loads retain the previous environment until ready. Hiding the skybox
keeps its image out of the background while retaining its lighting.

Source patterns: [ModelViewerDemo.kt](https://github.com/sceneview/sceneview/blob/v4.76.0/samples/android-demo/src/main/java/io/github/sceneview/demo/demos/ModelViewerDemo.kt),
[LightingDemo.kt](https://github.com/sceneview/sceneview/blob/v4.76.0/samples/android-demo/src/main/java/io/github/sceneview/demo/demos/LightingDemo.kt)
and [EnvironmentPresets.kt](https://github.com/sceneview/sceneview/blob/v4.76.0/sceneview/src/main/java/io/github/sceneview/environment/EnvironmentPresets.kt).
Verified by source inspection at 4.76.0; these snippets were not compiled or run on a device.
