Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/Spatial/llms.txt
Use this file to discover all available pages before exploring further.
Scene is the root composable in Spatial. It creates an OpenGL-backed viewport inside your Compose UI, collects every 3D element declared in its content lambda into an internal scene graph, and submits a rendered frame to the render host on every recomposition. Everything visible in your 3D world — cubes, spheres, planes — lives inside a Scene.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
modifier | Modifier | Standard Compose Modifier applied to the underlying AndroidView. Use it to control layout (e.g. fillMaxSize(), weight()). |
renderHostFactory | SceneRenderHostFactory | Supplies the Android render host that drives the OpenGL surface. Use DefaultSceneRenderHostFactory in production. |
cameraState | CameraState | Observable state holder for the orbit camera. Defaults to rememberCameraState() (yaw = 0°, pitch = 0°, zoom = 1.0). |
gestures | SceneGestures | Gesture mode applied to the viewport. Defaults to Gestures.orbit(). Pass Gestures.orbitAndZoom() to also enable two-finger pinch zoom. |
content | @Composable () -> Unit | Composable lambda where you declare your 3D elements using Element.Cube, Element.Sphere, and Element.Plane. |
Basic Example
The following snippet mirrors the setup used inMainActivity — a full-screen scene with an orbit camera and three primitives:
How It Works Internally
WhenScene recomposes it executes the following pipeline:
Build the scene graph
rememberSceneGraph(content) runs the content lambda in a special Compose sub-composition that intercepts each Element.* call and records it as a SceneNode.Convert to renderable nodes
Each
SceneNode is mapped through SceneNode.toRenderableNode(), which resolves the Modifier3D chain into a column-major 4×4 model matrix and pairs it with a mesh identifier.Snapshot the camera
cameraState.snapshot() captures an immutable CameraSnapshot (yaw, pitch, zoom, version, source) at the current frame.Lifecycle
TheAndroidView inside Scene uses onRelease to clean up when the composable leaves the composition:
dispose() signals the render host to tear down its OpenGL context and release all GPU resources associated with the scene. You do not need to manage this manually.
Gesture input is wired through an internal
Modifier.sceneGestureInput applied to the AndroidView. Raw MotionEvent handling is fully managed by the library — you only need to choose a SceneGestures mode.