Skip to content

Commit c84c44d

Browse files
authored
feat(lambda-rs): add 2D colliders (#195)
## Summary Add 2D collider support on top of the rigid body implementation, including public builder APIs in `lambda-rs`, Rapier-backed shape attachment in `lambda-rs-platform`, integration coverage, and a demo that exercises material, density, local transform, and compound-collider behavior. This PR introduces circle, rectangle, capsule, and convex polygon colliders, supports attaching multiple colliders to a single rigid body, and verifies collision response through integration tests and a visual demo. ## Related Issues N/A ## Changes - Add `Collider2D`, `ColliderShape2D`, `Collider2DBuilder`, and collider validation/error handling to `lambda-rs` - Add Rapier-backed circle, rectangle, capsule, and convex polygon collider attachment to `lambda-rs-platform` - Support compound colliders by allowing multiple collider attachments per rigid body - Add density, friction, restitution, local offset, and local rotation support to collider construction - Add physics integration test modules for collider shapes, materials, and compound-collider behavior - Add a dedicated `physics_colliders_2d` demo covering primitives, materials, density, local rotation, and compound colliders - Centralize collider validation in `lambda-rs` and reduce backend error handling to backend-owned failures - Replace indirect body validation with direct live-handle validation - Remove the custom Rapier contact hook and encode friction/restitution through Rapier combine rules - Reduce unnecessary per-step backend work by skipping zero-force accumulator synchronization ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [x] Feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation (updates to docs, specs, tutorials, or comments) - [x] Refactor (code change that neither fixes a bug nor adds a feature) - [x] Performance (change that improves performance) - [x] Test (adding or updating tests) - [ ] Build/CI (changes to build process or CI configuration) ## Affected Crates - [x] `lambda-rs` - [x] `lambda-rs-platform` - [ ] `lambda-rs-args` - [ ] `lambda-rs-logging` - [x] Other: `demos/physics` ## Checklist - [x] Code follows the repository style guidelines (`cargo +nightly fmt --all`) - [x] Code passes clippy (`cargo clippy --workspace --all-targets -- -D warnings`) - [ ] Tests pass (`cargo test --workspace`) - [x] New code includes appropriate documentation - [x] Public API changes are documented - [ ] Breaking changes are noted in this PR description ## Testing **Commands run:** ```bash cargo +nightly fmt --all cargo build -p lambda-rs-platform --features physics-2d cargo build -p lambda-rs --features physics-2d cargo test -p lambda-rs --features physics-2d collider_2d::tests:: -- --nocapture cargo test -p lambda-rs-platform --features physics-2d rigid_body_exists_2d_reports_live_slots -- --nocapture cargo test -p lambda-rs-platform --features physics-2d collider_attachment_mass_plan -- --nocapture cargo test -p lambda-rs-platform --features physics-2d rapier_friction_encoding_preserves_public_combination_semantics -- --nocapture cargo test -p lambda-rs --features physics-2d physics_2d_friction_changes_sliding_velocity_decay -- --nocapture cargo test -p lambda-rs --features physics-2d physics_2d_restitution_changes_bounce_height -- --nocapture cargo test -p lambda-rs --features physics-2d physics_2d_density_affects_impulse_velocity_delta -- --nocapture cargo clippy --workspace --all-targets --features physics-2d -- -D warnings ``` **Manual verification steps (if applicable):** 1. Run `cargo run -p lambda-demos-physics --bin physics_colliders_2d --features physics-2d` 2. Verify circle, rectangle, capsule, and convex polygon bodies collide with the floor, ramp, walls, and divider 3. Verify friction changes sliding distance, restitution changes bounce, and density changes response to the applied impulse ## Screenshots/Recordings Not included in this draft. ## Platform Testing - [x] macOS - [ ] Windows - [ ] Linux ## Additional Notes - Full workspace tests were not run as part of this draft. Two force-lifetime tests were previously observed failing independently of the collider simplification work and should be evaluated separately before merge.
2 parents 52e6a34 + e940a4a commit c84c44d

File tree

16 files changed

+4295
-87
lines changed

16 files changed

+4295
-87
lines changed

crates/lambda-rs-platform/src/physics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
pub mod rapier2d;
88

99
pub use rapier2d::{
10+
Collider2DBackendError,
1011
PhysicsBackend2D,
1112
RigidBody2DBackendError,
1213
RigidBodyType2D,

0 commit comments

Comments
 (0)