forked from dimforge/bevy_rapier
-
Notifications
You must be signed in to change notification settings - Fork 1
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 ci nodebug #25
Open
Vrixyz
wants to merge
11
commits into
master
Choose a base branch
from
RapierContext_Component_ci_nodebug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4ff57e
working rapierContext as component, but not ideal API.
Vrixyz 3cb7676
systemparam exploration
Vrixyz a01395e
RapierContextEntityLink to know which RapierContext is referred to
Vrixyz 4e7c36c
more rapierContext conf + broken events -> added a test which should …
Vrixyz 4952ea5
fix events test
Vrixyz 7a4ba5e
better support for multi world
Vrixyz 24fd036
multiple worlds working + example
Vrixyz f900dac
progress multi world with change
Vrixyz d171fe4
cargo clippy + pr feedbacks
Vrixyz 8dd49ee
less unwraps
Vrixyz 2b262ea
ci without debug symbols
Vrixyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use bevy::{input::common_conditions::input_just_pressed, prelude::*}; | ||
use bevy_rapier3d::prelude::*; | ||
|
||
const N_WORLDS: 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, | ||
RapierPhysicsPlugin::<NoUserData>::default() | ||
.with_default_world(RapierContextInitialization::NoAutomaticRapierContext), | ||
RapierDebugRenderPlugin::default(), | ||
)) | ||
.add_systems( | ||
Startup, | ||
((create_worlds, setup_physics).chain(), setup_graphics), | ||
) | ||
.add_systems(Update, move_platforms) | ||
.add_systems( | ||
Update, | ||
change_world.run_if(input_just_pressed(KeyCode::KeyC)), | ||
) | ||
.run(); | ||
} | ||
|
||
fn create_worlds(mut commands: Commands) { | ||
for i in 0..N_WORLDS { | ||
let mut world = commands.spawn((RapierContext::default(), WorldId(i))); | ||
if i == 0 { | ||
world.insert(DefaultRapierContext); | ||
} | ||
} | ||
} | ||
|
||
fn setup_graphics(mut commands: Commands) { | ||
commands.spawn(Camera3dBundle { | ||
transform: Transform::from_xyz(0.0, 3.0, -10.0) | ||
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), | ||
..Default::default() | ||
}); | ||
} | ||
|
||
#[derive(Component)] | ||
pub struct WorldId(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_seconds().sin(); | ||
} | ||
} | ||
|
||
/// Demonstrates how easy it is to move one entity to another world. | ||
fn change_world( | ||
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 world of {} for world {}", e, link.0); | ||
} | ||
} | ||
|
||
pub fn setup_physics( | ||
context: Query<(Entity, &WorldId), 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(( | ||
TransformBundle::from(Transform::from_xyz(0.0, starting_y, 0.0)), | ||
Collider::cuboid(ground_size, ground_height, ground_size), | ||
ColliderDebugColor(color), | ||
RapierContextEntityLink(context_entity), | ||
)); | ||
if id == 1 { | ||
platforms.insert(Platform { starting_y }); | ||
} | ||
|
||
/* | ||
* Create the cube | ||
*/ | ||
|
||
commands.spawn(( | ||
TransformBundle::from(Transform::from_xyz(0.0, 1.0 + id as f32 * 5.0, 0.0)), | ||
RigidBody::Dynamic, | ||
Collider::cuboid(0.5, 0.5, 0.5), | ||
ColliderDebugColor(color), | ||
RapierContextEntityLink(context_entity), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently checking if that makes it less likely to exceed github's disk usage limits