CameraState
Hoisted, observable camera state. Create with rememberCameraState and pass to io.github.erkko68.filament.compose.FilamentView for full control over the camera.
All fields are observable androidx.compose.runtime.MutableState — read them inside a composable to subscribe to changes, or write them from anywhere on the main thread to drive the camera imperatively.
Read-only matrices (viewMatrix, projectionMatrix) reflect the underlying Filament camera and are valid only while the state is attached to a FilamentView.
val cameraState = rememberCameraState(initialEye = Position(0f, 2f, 5f))
FilamentView(scene = scene, cameraState = cameraState)
// Read the view matrix from anywhere
LaunchedEffect(cameraState.eye) {
val v = cameraState.viewMatrix // may be null until attached
}Properties
Distance from the camera to the plane of focus in world units, used by PostProcessing(depthOfField = …) to place the focal plane. Ignored without DoF.
Projection matrix (view→clip) computed by Filament. Null until this state is attached to a io.github.erkko68.filament.compose.FilamentView.
Per-axis projection scaling; LensScaling.Identity leaves the frustum as computed.
Off-axis lens shift; LensShift.None leaves the projection centred.
View matrix (world→view) computed by Filament. Null until this state is attached to a io.github.erkko68.filament.compose.FilamentView.
Functions
Moves the camera to viewpoint over animationSpec (see CameraTransitions), along path. A gesture on the view, another animateTo or setting viewpoint, eye, target or up stops it where it is, and it then throws a CancellationException, as cancelling the calling coroutine does.
The viewpoint that frames a sphere of radius around center, seen from that direction (from center towards the eye; the camera's current one when null), just far enough to fit the view's current shape. An orthographic projection keeps its extents, so the eye sits at twice the radius. Before the view first lays out, the shape is taken as square.
Where position (world space) appears in the attached view, in pixels from its top-left corner, or null when it is behind the camera or this state isn't attached to a view yet. Reads the camera's state, so a caller in composition, layout or drawing re-runs when the camera moves or the view resizes. To pin an element there, use anchorTo.