Physics Box
Physics-aware Compose container.
PhysicsBox measures and places its children via Compose, registers each child as a physics body (when the child uses Modifier.physicsBody(...)), runs the physics simulation, and then renders the latest world snapshot by applying layer transforms (translationX/Y, rotationZ) during placement rather than forcing remeasure/relayout.
Mental model
Compose owns measurement and composition.
Physics engine owns motion and collisions.
A child becomes “physical” only if it is registered with
Modifier.physicsBody(key = ...).
State and commands
state is the single integration point with the simulation:
receives global step callbacks (
dispatchStep)provides pending commands drained and applied to the engine (e.g., reset, impulses, etc.)
controls pause/resume and solver parameters
Scaling and coordinates
The simulation runs in physics units (meters, seconds). Rendering and input happen in pixels. The mapping is controlled by config.worldScale (e.g., PxPerMeter).
Lifecycle
The physics engine instance is created with remember(...) and disposed with DisposableEffect. On dispose, the world is reset and boundaries are cleared.
Parameters
Holder of simulation state, step configuration and a command queue.
World configuration (scale, boundaries, stepping, etc.). The effective step config is merged with state.stepConfig.
Children content placed inside the physics container; use PhysicsBoxScope.physicsBody to register elements in the physics world.
Deprecated
PhysicsBox debug is not implemented yet. Parameter is reserved and currently ignored. Do not pass it.
Replace with
PhysicsBox(modifier = modifier, state = state, config = config, content = content)