physicsBody

fun Modifier.physicsBody(key: Any, config: PhysicsBodyConfig = PhysicsBodyConfig(), shape: PhysicsShape = PhysicsShape.Box, collisionFilter: CollisionFilter = CollisionFilter.Default, isDraggable: Boolean = true, dragConfig: DragConfig = DragConfig(), onCollision: (CollisionEvent) -> Unit? = null, onSleepChanged: (Boolean) -> Unit? = null, onDragStart: (DragEvent) -> Unit? = null, onDragEnd: (DragEvent) -> Unit? = null): Modifier

Registers this composable as a physics body in the nearest dev.zinchenko.physicsbox.layout.PhysicsBox scope.

The modifier binds a measured Compose node to a simulation body and enables the engine to drive its visual transform (translation/rotation) during placement.

Keys

key must be stable across recompositions and unique within a single PhysicsBox subtree. Prefer simple immutable keys (String, Long, enums). Reusing a key for different nodes or using non-stable keys leads to undefined behavior (including misrouted events).

Dragging

When isDraggable is enabled, pointer input may control the body via a drag controller. The behavior is tuned by dragConfig. Drag callbacks use DragEvent.

Collisions

onCollision receives contact information involving this body (see CollisionEvent). Use collisionFilter to configure collision inclusion/exclusion.

Parameters

key

Stable identity linking composable and body across recompositions.

config

Body material/motion parameters.

shape

Shape descriptor used to create the collision geometry.

collisionFilter

Collision filtering rules (category/mask/group override).

isDraggable

Enables pointer-driven dragging for this body.

dragConfig

Drag tuning parameters.

onCollision

Optional callback for contact events involving this body.

onSleepChanged

Optional callback when sleeping state changes. Callback parameter is isSleeping (true when the body is sleeping).

onDragStart

Optional callback when drag interaction starts.

onDragEnd

Optional callback when drag interaction ends (including cancel).