Expand description
Rapier 3D physics plugin for viewport-lib.
Wraps rapier3d behind the RuntimePlugin
trait so it runs inside a ViewportRuntime alongside any other viewport-lib
plugin. The crate is intentionally a thin adapter: it owns the lifecycle
integration and the NodeId translation layer, and re-exports rapier3d
and parry3d so consumers use rapier’s own types and builders directly.
§Quick start
use rapier_viewport_plugin::{RapierPlugin, RapierContactEvent, rapier3d::prelude::*};
use viewport_lib::{FixedTimestep, ViewportRuntime};
let mut rapier = RapierPlugin::new();
// Build bodies and colliders with rapier's own builders.
let floor_body = RigidBodyBuilder::fixed().build();
let floor_collider = ColliderBuilder::halfspace(Vector::z_axis()).build();
rapier.add_body(floor_id, floor_body, floor_collider);
let box_body = RigidBodyBuilder::dynamic()
.translation(glam::Vec3::new(0.0, 0.0, 5.0))
.build();
let box_collider = ColliderBuilder::cuboid(0.5, 0.5, 0.5)
.restitution(0.4)
.active_events(ActiveEvents::COLLISION_EVENTS)
.build();
rapier.add_body(box_id, box_body, box_collider);
let (prepare, simulate) = rapier.clone().into_plugins();
let runtime = ViewportRuntime::new()
.with_fixed_timestep(FixedTimestep::new(120.0))
.with_plugin(prepare)
.with_plugin(simulate);
// Per-frame:
// let output = runtime.step(&mut scene, &mut selection, &frame_ctx);
// for ev in output.events.drain::<RapierContactEvent>() { ... }For anything not in the curated API – impulses, velocity get/set, joints,
collision groups, sensor flags, locked axes, the query pipeline, character
controllers, etc. – reach in through RapierPlugin::with_body_mut,
RapierPlugin::with_collider_mut, or RapierPlugin::with_state_mut.
§Architecture
Two RuntimePlugin implementors share a single Arc<Mutex<RapierState>>:
| Phase | Plugin | What it does |
|---|---|---|
| Prepare | RapierPreparePlugin | Syncs fixed and kinematic body transforms from scene -> rapier |
| Simulate | RapierSimulatePlugin | Calls PhysicsPipeline::step, writes dynamic bodies back |
The user-facing RapierPlugin keeps a third reference to the same state,
so bodies can be added or removed at runtime while the simulation runs.
Re-exports§
pub use events::RapierContactEvent;pub use plugin::RapierPlugin;pub use plugin::RapierPreparePlugin;pub use plugin::RapierSimulatePlugin;pub use state::RapierState;pub use rapier3d;pub use parry3d;