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

update bevy_rapier to 0.28 + bevy to 0.15 #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions docs-examples/2d/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.14"
bevy_rapier2d = "0.27"
bevy = "0.15"
bevy_rapier2d = "0.28"
21 changes: 11 additions & 10 deletions docs-examples/2d/bevy/examples/advanced_collision_detection2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@ struct CustomInfo {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
/* Create the ground. */
let ground = commands
.spawn(Collider::cuboid(500.0, 50.0))
.insert(TransformBundle::from(Transform::from_xyz(0.0, -100.0, 0.0)))
.insert(Transform::from_xyz(0.0, -100.0, 0.0))
.id();
/* Create the bouncing ball. */
let ball1 = commands
.spawn(RigidBody::Dynamic)
.insert(ActiveEvents::CONTACT_FORCE_EVENTS)
.insert(Collider::ball(50.0))
.insert(Restitution::coefficient(0.7))
.insert(TransformBundle::from(Transform::from_xyz(
-55.0, 400.0, 0.0,
)))
.insert(Transform::from_xyz(-55.0, 400.0, 0.0))
.id();
commands.insert_resource(CustomInfo {
entity1: ground,
Expand All @@ -54,7 +52,7 @@ fn setup_physics(mut commands: Commands) {
.insert(ActiveEvents::COLLISION_EVENTS)
.insert(Collider::ball(50.0))
.insert(Restitution::coefficient(0.7))
.insert(TransformBundle::from(Transform::from_xyz(55.0, 300.0, 0.0)));
.insert(Transform::from_xyz(55.0, 300.0, 0.0));
}

// DOCUSAURUS: Events start
Expand All @@ -74,7 +72,7 @@ fn display_events(
// DOCUSAURUS: Events stop

// DOCUSAURUS: ContactGraph1 start
fn display_contact_info(rapier_context: Res<RapierContext>, custom_info: Res<CustomInfo>) {
fn display_contact_info(rapier_context: ReadDefaultRapierContext, custom_info: Res<CustomInfo>) {
let entity1 = custom_info.entity1; // A first entity with a collider attached.
let entity2 = custom_info.entity2; // A second entity with a collider attached.

Expand Down Expand Up @@ -121,7 +119,7 @@ fn display_contact_info(rapier_context: Res<RapierContext>, custom_info: Res<Cus

// DOCUSAURUS: ContactGraph2 start
fn display_contact_info_all_from_1_entity(
rapier_context: Res<RapierContext>,
rapier_context: ReadDefaultRapierContext,
custom_info: Res<CustomInfo>,
) {
let entity = custom_info.entity2; // An entity with a collider attached.
Expand All @@ -141,7 +139,10 @@ fn display_contact_info_all_from_1_entity(
// DOCUSAURUS: ContactGraph2 stop

// DOCUSAURUS: IntersectionGraph1 start
fn display_intersection_info(rapier_context: Res<RapierContext>, custom_info: Res<CustomInfo>) {
fn display_intersection_info(
rapier_context: ReadDefaultRapierContext,
custom_info: Res<CustomInfo>,
) {
let entity1 = custom_info.entity1; // A first entity with a collider attached.
let entity2 = custom_info.entity2; // A second entity with a collider attached.

Expand All @@ -157,7 +158,7 @@ fn display_intersection_info(rapier_context: Res<RapierContext>, custom_info: Re

// DOCUSAURUS: IntersectionGraph2 start
fn display_intersection_info_all_from_1_entity(
rapier_context: Res<RapierContext>,
rapier_context: ReadDefaultRapierContext,
custom_info: Res<CustomInfo>,
) {
let entity = custom_info.entity2; // An entity with a collider attached.
Expand Down
6 changes: 3 additions & 3 deletions docs-examples/2d/bevy/examples/basic_sim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
/* Create the ground. */
commands
.spawn(Collider::cuboid(500.0, 50.0))
.insert(TransformBundle::from(Transform::from_xyz(0.0, -100.0, 0.0)));
.insert(Transform::from_xyz(0.0, -100.0, 0.0));

/* Create the bouncing ball. */
commands
.spawn(RigidBody::Dynamic)
.insert(Collider::ball(50.0))
.insert(Restitution::coefficient(0.7))
.insert(TransformBundle::from(Transform::from_xyz(0.0, 400.0, 0.0)));
.insert(Transform::from_xyz(0.0, 400.0, 0.0));
}

fn print_ball_altitude(positions: Query<&Transform, With<RigidBody>>) {
Expand Down
2 changes: 1 addition & 1 deletion docs-examples/2d/bevy/examples/character_controller2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics_more(mut commands: Commands) {
Expand Down
12 changes: 6 additions & 6 deletions docs-examples/2d/bevy/examples/colliders2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
Expand All @@ -31,7 +31,7 @@ fn setup_physics(mut commands: Commands) {
commands
.spawn(Collider::cuboid(1.0, 2.0))
.insert(Sensor)
.insert(TransformBundle::from(Transform::from_xyz(2.0, 0.0, 0.0)))
.insert(Transform::from_xyz(2.0, 0.0, 0.0))
.insert(Friction::coefficient(0.7))
.insert(Restitution::coefficient(0.3))
.insert(ColliderMassProperties::Density(2.0));
Expand All @@ -50,11 +50,11 @@ fn setup_physics(mut commands: Commands) {
children
.spawn(Collider::ball(0.5))
// Position the collider relative to the rigid-body.
.insert(TransformBundle::from(Transform::from_xyz(0.0, 0.0, -1.0)));
.insert(Transform::from_xyz(0.0, 0.0, -1.0));
children
.spawn(Collider::ball(0.5))
// Position the collider relative to the rigid-body.
.insert(TransformBundle::from(Transform::from_xyz(0.0, 0.0, 1.0)));
.insert(Transform::from_xyz(0.0, 0.0, 1.0));
});
// DOCUSAURUS: Creation2 stop

Expand Down Expand Up @@ -88,7 +88,7 @@ fn setup_physics(mut commands: Commands) {
/* Set the collider position when the collider is created. */
commands
.spawn(Collider::cuboid(0.5, 0.5))
.insert(TransformBundle::from(Transform::from_xyz(1.0, 2.0, 0.0)));
.insert(Transform::from_xyz(1.0, 2.0, 0.0));
// DOCUSAURUS: Position1 stop

// DOCUSAURUS: Position2 start
Expand All @@ -100,7 +100,7 @@ fn setup_physics(mut commands: Commands) {
.with_children(|children| {
children
.spawn(Collider::cuboid(0.5, 0.5))
.insert(TransformBundle::from(Transform::from_xyz(1.0, 2.0, 0.0)));
.insert(Transform::from_xyz(1.0, 2.0, 0.0));
});
// DOCUSAURUS: Position2 stop

Expand Down
2 changes: 1 addition & 1 deletion docs-examples/2d/bevy/examples/colliders_compound2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
Expand Down
2 changes: 1 addition & 1 deletion docs-examples/2d/bevy/examples/joints2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
Expand Down
126 changes: 126 additions & 0 deletions docs-examples/2d/bevy/examples/multiple_contexts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use bevy::{input::common_conditions::input_just_pressed, prelude::*};
use bevy_rapier2d::prelude::*;

const N_CONTEXTS: usize = 2;

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,
// DOCUSAURUS: MultipleContexts_no_default start
RapierPhysicsPlugin::<NoUserData>::default()
.with_custom_initialization(RapierContextInitialization::NoAutomaticRapierContext),
// DOCUSAURUS: MultipleContexts_no_default stop
RapierDebugRenderPlugin::default(),
))
.add_systems(
Startup,
((create_contexts, setup_physics).chain(), setup_graphics),
)
.add_systems(Update, move_platforms)
.add_systems(
Update,
change_context.run_if(input_just_pressed(KeyCode::KeyC)),
)
.run();
}

fn create_contexts(mut commands: Commands) {
for i in 0..N_CONTEXTS {
// DOCUSAURUS: MultipleContexts_new start
let mut context = commands.spawn(RapierContext::default());
// DOCUSAURUS: MultipleContexts_new stop
context.insert(ContextId(i));
if i == 0 {
// DOCUSAURUS: MultipleContexts_custom_default start
context.insert(DefaultRapierContext);
// DOCUSAURUS: MultipleContexts_custom_default stop
}
}
}

fn setup_graphics(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 3.0, -10.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
));
}

#[derive(Component)]
pub struct ContextId(pub usize);

#[derive(Component)]
struct Platform {
starting_y: f32,
}

fn move_platforms(time: Res<Time>, mut query: Query<(&mut Transform, &Platform)>) {
for (mut transform, platform) in query.iter_mut() {
transform.translation.y = platform.starting_y + -time.elapsed_secs().sin();
}
}

/// Demonstrates how easy it is to move one entity to another context.
fn change_context(
query_context: Query<Entity, With<DefaultRapierContext>>,
mut query_links: Query<(Entity, &mut RapierContextEntityLink)>,
) {
let default_context = query_context.single();
for (e, mut link) in query_links.iter_mut() {
if link.0 == default_context {
continue;
}
link.0 = default_context;
println!("changing context of {} for context {}", e, link.0);
}
}

pub fn setup_physics(
context: Query<(Entity, &ContextId), With<RapierContext>>,
mut commands: Commands,
) {
for (context_entity, id) in context.iter() {
let id = id.0;

let color = [
Hsla::hsl(220.0, 1.0, 0.3),
Hsla::hsl(180.0, 1.0, 0.3),
Hsla::hsl(260.0, 1.0, 0.7),
][id % 3];

/*
* Ground
*/
let ground_size = 5.1;
let ground_height = 0.1;

let starting_y = (id as f32) * -0.5 - ground_height;

let mut platforms = commands.spawn((
Transform::from_xyz(0.0, starting_y, 0.0),
Collider::cuboid(ground_size, ground_height),
ColliderDebugColor(color),
RapierContextEntityLink(context_entity),
));
if id == 1 {
platforms.insert(Platform { starting_y });
}

/*
* Create the cube
*/

commands.spawn((
Transform::from_xyz(0.0, 1.0 + id as f32 * 5.0, 0.0),
RigidBody::Dynamic,
Collider::cuboid(0.5, 0.5),
ColliderDebugColor(color),
RapierContextEntityLink(context_entity),
));
}
}
4 changes: 2 additions & 2 deletions docs-examples/2d/bevy/examples/rigid_bodies2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
Expand All @@ -38,7 +38,7 @@ fn setup_physics(mut commands: Commands) {
// DOCUSAURUS: Position1 start
commands
.spawn(RigidBody::Dynamic)
.insert(TransformBundle::from(Transform::from_xyz(0.0, 5.0, 0.0)))
.insert(Transform::from_xyz(0.0, 5.0, 0.0))
// DOCUSAURUS: Position1 stop
.insert(Velocity {
linvel: Vec2::new(1.0, 2.0),
Expand Down
2 changes: 1 addition & 1 deletion docs-examples/2d/bevy/examples/rigid_bodies_continued2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn setup_physics(mut commands: Commands) {
Expand Down
Loading
Loading