Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rapier context component #22

Draft
wants to merge 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d4ff57e
working rapierContext as component, but not ideal API.
Vrixyz Jun 25, 2024
3cb7676
systemparam exploration
Vrixyz Jun 25, 2024
a01395e
RapierContextEntityLink to know which RapierContext is referred to
Vrixyz Jun 25, 2024
4e7c36c
more rapierContext conf + broken events -> added a test which should …
Vrixyz Jun 25, 2024
4952ea5
fix events test
Vrixyz Jun 26, 2024
7a4ba5e
better support for multi world
Vrixyz Jun 26, 2024
24fd036
multiple worlds working + example
Vrixyz Jun 26, 2024
f900dac
progress multi world with change
Vrixyz Jun 27, 2024
d171fe4
cargo clippy + pr feedbacks
Vrixyz Jul 1, 2024
8dd49ee
less unwraps
Vrixyz Jul 2, 2024
2b262ea
ci without debug symbols
Vrixyz Jul 2, 2024
f849cd2
more tests + logs + better changelog
Vrixyz Jul 2, 2024
df3578e
more error logs in case of no rapier context
Vrixyz Jul 2, 2024
09d6f9d
Update dependencies to rapier 0.21 (#547)
Vrixyz Jul 3, 2024
9abe4c3
Added 'realistic' test for events (#544)
Vrixyz Jul 4, 2024
ac16f38
Merge remote-tracking branch 'upstream' into RapierContext_Component
Vrixyz Jul 4, 2024
941b52e
fix conflict
Vrixyz Jul 4, 2024
5669a8c
fix unwrap
Vrixyz Jul 4, 2024
0b9ca86
fix warning
Vrixyz Jul 4, 2024
f97027d
update dependencies to bevy 0.14 (#556)
Vrixyz Jul 5, 2024
f4643ef
address pr feedback
Vrixyz Jul 5, 2024
ecdacfd
Fix some cargo doc warnings + add cargo doc ci (#557)
Vrixyz Jul 7, 2024
84c776e
rapier 0.20 feature: `RevoluteJoint::angle` + more detailed joints en…
Vrixyz Jul 7, 2024
f17bd5b
chore: Release prep for 0.27.0 (#558)
Vrixyz Jul 7, 2024
f8b296a
address pr feedback
Vrixyz Jul 8, 2024
0e46610
Merge branch 'master' into RapierContext_Component
Vrixyz Jul 8, 2024
75c2195
fixed compilation
Vrixyz Jul 8, 2024
ccd2be7
fix doc comment
Vrixyz Jul 8, 2024
9142888
fixed joints3 example
Vrixyz Jul 8, 2024
ba0cd76
experiment on stepping to test system ordering and consistent ecs state
Vrixyz Jul 9, 2024
6d10fe6
fix compilation + warning
Vrixyz Jul 10, 2024
d0b07a0
better error handling when rapier context is missing
Vrixyz Jul 10, 2024
2676c35
add a name for rapier context entity
Vrixyz Jul 10, 2024
d190a1c
Add `TriMeshFlags` to `ComputedColliderShape::TriMesh` (#559)
DiSaber Jul 15, 2024
188dcc2
added initial benchmarks, similar to bevy_xpbd (#551)
Vrixyz Jul 18, 2024
3c98610
testbed: allow to select example (#565)
Vrixyz Jul 18, 2024
c6c9bbc
A few doc-link fixes (#562)
Vrixyz Jul 22, 2024
59477d9
Fix a crash when removing colliders in `TimestepMode::Interpolated` …
Vrixyz Jul 23, 2024
40be1f1
Merge branch 'master' into RapierContext_Component
Vrixyz Jul 23, 2024
deb0a06
rename an init function
Vrixyz Jul 23, 2024
cf165bd
apply pr suggestion
Vrixyz Jul 23, 2024
c539f29
update to rapier 0.22 (#568)
Vrixyz Jul 26, 2024
c556052
fix unexpected cfg warning (#573)
Vrixyz Jul 29, 2024
c2bed72
Per entity/collider debug rendering (#278)
barsoosayque Aug 2, 2024
aeab8c9
apply PR suggestions
Vrixyz Aug 12, 2024
07eefbb
Merge branch 'master' into RapierContext_Component
Vrixyz Aug 12, 2024
4cccde1
rename rapier context system params
Vrixyz Aug 12, 2024
cbfe138
fix clippy (+ random typo)
Vrixyz Aug 12, 2024
5dc5b2d
cargo fmt
Vrixyz Aug 12, 2024
030dc61
Fix typos. (#580)
waywardmonkeys Aug 26, 2024
d0961d0
Merge remote-tracking branch 'upstream' into RapierContext_Component
Vrixyz Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_CACHE_KEY: rust-cache-20240617
RUST_CACHE_KEY: rust-cache-20240701
CARGO_PROFILE_DEV_DEBUG: none

jobs:
check-fmt:
Expand All @@ -20,6 +21,18 @@ jobs:
components: rustfmt
- name: Check formatting
run: cargo fmt -- --check
doc:
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
prefix-key: ${{ env.RUST_CACHE_KEY }}
- name: Cargo doc
run: cargo doc
test:
runs-on: ubuntu-latest
env:
Expand Down
59 changes: 49 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
# Changelog

## v0.27.0-rc.1 (18 June 2024)
## Unreleased

**This is an update to Rapier 0.20 which includes several stability improvements
### Modified

- Update from rapier `0.21` to rapier `0.22`,
see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md).

### Fix

- Fix a crash when using `TimestepMode::Interpolated` and removing colliders
during a frame which would not run a simulation step.

### Added

- Added a `TriMeshFlags` parameter for `ComputedColliderShape`,
its default value is `TriMeshFlags::MERGE_DUPLICATE_VERTICES`,
which was its hardcoded behaviour.
- Added a way to configure which colliders should be debug rendered: `global` parameter for both
`RapierDebugColliderPlugin` and `DebugRenderContext`, as well as individual collider setup via
a `ColliderDebug` component.

### Modified

- `RapierContext`, `RapierConfiguration` and `RenderToSimulationTime` are now a `Component` instead of resources.
- Rapier now supports multiple independent physics worlds, see example `multi_world3` for usage details.
- Migration guide:
- `ResMut<mut RapierContext>` -> `WriteDefaultRapierContext`
- `Res<RapierContext>` -> `ReadDefaultRapierContext`
- Access to `RapierConfiguration` and `RenderToSimulationTime` should query for it
on the responsible entity owning the `RenderContext`.
- If you are building a library on top of `bevy_rapier` and would want to support multiple independent physics worlds too,
you can check out the details of [#545](https://github.com/dimforge/bevy_rapier/pull/545)
to get more context and information.

## v0.27.0 (07 July 2024)

**This is an update from rapier 0.19 to Rapier 0.21 which includes several stability improvements
and new features. Please have a look at the
[0.20 changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md) of Rapier.**
[0.20 and 0.21 changelogs](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md) of Rapier.**

### Modified

- Update to rapier `0.20`.
- Update from rapier `0.19` to rapier `0.21`.
- Update to nalgebra `0.33`.
- Update to bevy `0.14`.
- Renamed `has_any_active_contacts` to `has_any_active_contact` for better consistency with rapier.
- `ColliderDebugColor`'s property is now a `bevy::color::Hsla`.
- Added serialization support for `CollisionGroups`, `SolverGroups`, `ContactForceEventThreshold`, `ContactSkin`.
- `ImpulseJoint::data` and `MultibodyJoint::data` are now a more detailed enum `TypedJoint` instead of a `GenericJoint`.
You can still access its inner `GenericJoint` with `.as_ref()` or `as_mut()`.
- `data` fields from all joints (`FixedJoint`, …) are now public, and their getters removed.

### Added

- Derive `Debug` for `LockedAxes`.
- Expose `is_sliding_down_slope` to both `MoveShapeOutput` and `KinematicCharacterControllerOutput`.
- Added a First Person Shooter `character_controller` example for `bevy_rapier3d`.
- Added serialization support for `CollisionGroups`, `SolverGroups`, `ContactForceEventThreshold`, `ContactSkin`.
- Added `RapierContext::context.impulse_revolute_joint_angle` to compute the angle along a revolute joint’s principal axis.

### Fix

Expand Down Expand Up @@ -127,14 +166,14 @@ performance of the other parts of the simulation.

- Add a joint for simulating ropes: the `RopeJoint`.
- Add `Velocity::linear_velocity_at_point` to calculate the linear velocity at the given world-space point.
- Add the `ComputedColliderShape::ConvexHull` variant to automatcially calculate the convex-hull of an imported mesh.
- Add the `ComputedColliderShape::ConvexHull` variant to automatically calculate the convex-hull of an imported mesh.
- Implement `Reflect` for the debug-renderer.

### Fix

- Fix broken interpolation for rigid-bodies with the `TransformInterpolation` component.
- Fix compilation when `bevy_rapier` is being used with headless bevy.
- Improved performance of the writeback system by not iterting on non-rigid-body entities.
- Improved performance of the writeback system by not iterating on non-rigid-body entities.
- Fix typo by renaming `CuboidViewMut::sed_half_extents` to `set_half_extents`.
- Properly scale parented collider’s offset based on changes on its `ColliderScale`.

Expand All @@ -144,7 +183,7 @@ performance of the other parts of the simulation.

- Update to Bevy 0.10.
- The `PhysicsHooksWithQuery` trait has been renamed to by the `BevyPhysicsHooks`.
- Bevy resources and queries accessed by the physics hook are now specified by the implementor of `BevyPhysicsHooks`
- Bevy resources and queries accessed by the physics hook are now specified by the implementer of `BevyPhysicsHooks`
which must derive Bevy’s `SystemParam` trait. This implies that the physics hook’s `filter_contact_pair` (and
all its other methods) no longer take the Bevy `Query` as argument. Queries and resources are accessed through
`self`.
Expand Down Expand Up @@ -435,7 +474,7 @@ Finally, there is now a prelude: `use bevy_rapier2d::prelude::*`.
is used. It will silently ignore the shape instead.
- The crate has now a `render` feature that allows building it without any
rendering support (avoiding some dependencies that may not compile when
targetting WASM).
targeting WASM).

## 0.7.0

Expand Down Expand Up @@ -465,7 +504,7 @@ Finally, there is now a prelude: `use bevy_rapier2d::prelude::*`.

- It is now possible to attach multiple colliders to a single
rigid-body by using Bevy hierarchy: an entity contains
the `RigidBodyBuider` whereas its children contain the `ColliderBuilder`.
the `RigidBodyBuilder` whereas its children contain the `ColliderBuilder`.

### Changed

Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[workspace]
members = ["bevy_rapier2d", "bevy_rapier3d"]
members = ["bevy_rapier2d", "bevy_rapier3d", "bevy_rapier_benches3d"]
resolver = "2"

[workspace.lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(feature, values("dim2", "dim3"))',
] }

[profile.dev]
# Use slightly better optimization by default, as examples otherwise seem laggy.
opt-level = 1
Expand Down
16 changes: 11 additions & 5 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_rapier2d"
version = "0.27.0-rc.1"
version = "0.27.0"
authors = ["Sébastien Crozet <[email protected]>"]
description = "2-dimensional physics engine in Rust, official Bevy plugin."
documentation = "http://docs.rs/bevy_rapier2d"
Expand All @@ -17,6 +17,9 @@ edition = "2021"
path = "../src/lib.rs"
required-features = ["dim2"]

[lints]
workspace = true

[features]
default = ["dim2", "async-collider", "debug-render-2d"]
dim2 = []
Expand Down Expand Up @@ -44,21 +47,24 @@ headless = []
async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"]

[dependencies]
bevy = { version = "0.14.0-rc.3", default-features = false }
nalgebra = { version = "0.32.6", features = ["convert-glam027"] }
rapier2d = "0.20"
bevy = { version = "0.14", default-features = false }
nalgebra = { version = "0.33", features = ["convert-glam027"] }
rapier2d = "0.22"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
bevy = { version = "0.14.0-rc.3", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"x11",
"bevy_state",
"bevy_debug_stepping",
] }
oorandom = "11"
approx = "0.5.1"
glam = { version = "0.27", features = ["approx"] }
bevy-inspector-egui = "0.25.1"
bevy_egui = "0.28.0"

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
Expand Down
3 changes: 1 addition & 2 deletions bevy_rapier2d/examples/debug_despawn2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ fn spawn_cube(commands: &mut Commands, game: &mut Game) {
block_entities[*i],
RevoluteJointBuilder::new()
.local_anchor1(anchor_1)
.local_anchor2(anchor_2)
.build(),
.local_anchor2(anchor_2),
))
.id();
game.current_cube_joints.push(id);
Expand Down
117 changes: 117 additions & 0 deletions bevy_rapier2d/examples/debug_toggle2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use std::time::Duration;

pub use bevy::input::common_conditions::input_just_pressed;
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(
0xF9 as f32 / 255.0,
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
))
.add_systems(Startup, (setup_graphics, setup_physics))
.add_systems(
Update,
(
toggle_debug,
(|mut debug_render_context: ResMut<DebugRenderContext>| {
debug_render_context.enabled = !debug_render_context.enabled;
})
.run_if(input_just_pressed(KeyCode::KeyV)),
),
)
.run();
}

pub fn setup_graphics(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-30.0, 30.0, 100.0)
.looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y),
..Default::default()
});
}

#[derive(Component)]
pub struct DebugCooldown(pub Timer);

pub fn setup_physics(mut commands: Commands) {
/*
* Ground
*/
let ground_size = 200.1;
let ground_height = 0.1;

commands.spawn((
TransformBundle::from(Transform::from_xyz(0.0, -ground_height, 0.0)),
Collider::cuboid(ground_size, ground_height),
));

/*
* Create the cubes
*/
let num = 8;
let rad = 1.0;

let shift = rad * 2.0 + rad;
let centerx = shift * (num / 2) as f32;
let centery = shift / 2.0;
let centerz = shift * (num / 2) as f32;

let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
let mut color = 0;
let colors = [
Hsla::hsl(220.0, 1.0, 0.3),
Hsla::hsl(180.0, 1.0, 0.3),
Hsla::hsl(260.0, 1.0, 0.7),
];

for j in 0usize..20 {
for i in 0..num {
for k in 0usize..num {
let x = i as f32 * shift - centerx + offset;
let y = j as f32 * shift + centery + 3.0;
let z = k as f32 * shift - centerz + offset;
color += 1;

commands
.spawn(TransformBundle::from(Transform::from_rotation(
Quat::from_rotation_x(0.2),
)))
.with_children(|child| {
child.spawn((
TransformBundle::from(Transform::from_xyz(x, y, z)),
RigidBody::Dynamic,
Collider::cuboid(rad, rad),
ColliderDebugColor(colors[color % 3]),
ColliderDebug::AlwaysRender,
DebugCooldown(Timer::new(
Duration::from_secs_f32(0.4f32 + (i % 3 + (j + 1) % 3) as f32),
TimerMode::Repeating,
)),
));
});
}
}

offset -= 0.05 * rad * (num as f32 - 1.0);
}
}

pub fn toggle_debug(time: Res<Time>, mut query: Query<(&mut ColliderDebug, &mut DebugCooldown)>) {
for (mut debug, mut cooldown) in query.iter_mut() {
cooldown.0.tick(time.delta());
if cooldown.0.just_finished() {
*debug = match *debug {
ColliderDebug::AlwaysRender => ColliderDebug::NeverRender,
ColliderDebug::NeverRender => ColliderDebug::AlwaysRender,
}
}
}
}
3 changes: 2 additions & 1 deletion bevy_rapier2d/examples/player_movement2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fn main() {
#[derive(Component)]
pub struct Player(f32);

pub fn spawn_player(mut commands: Commands, mut rapier_config: ResMut<RapierConfiguration>) {
pub fn spawn_player(mut commands: Commands, mut rapier_config: Query<&mut RapierConfiguration>) {
let mut rapier_config = rapier_config.single_mut();
// Set gravity to 0.0 and spawn camera.
rapier_config.gravity = Vec2::ZERO;
commands.spawn(Camera2dBundle::default());
Expand Down
Loading