-
-
Notifications
You must be signed in to change notification settings - Fork 273
Rapier context as a Component #545
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
Merged
ThierryBerger
merged 36 commits into
dimforge:master
from
ThierryBerger:RapierContext_Component
Sep 9, 2024
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d4ff57e
working rapierContext as component, but not ideal API.
ThierryBerger 3cb7676
systemparam exploration
ThierryBerger a01395e
RapierContextEntityLink to know which RapierContext is referred to
ThierryBerger 4e7c36c
more rapierContext conf + broken events -> added a test which should …
ThierryBerger 4952ea5
fix events test
ThierryBerger 7a4ba5e
better support for multi world
ThierryBerger 24fd036
multiple worlds working + example
ThierryBerger f900dac
progress multi world with change
ThierryBerger d171fe4
cargo clippy + pr feedbacks
ThierryBerger 8dd49ee
less unwraps
ThierryBerger 2b262ea
ci without debug symbols
ThierryBerger f849cd2
more tests + logs + better changelog
ThierryBerger df3578e
more error logs in case of no rapier context
ThierryBerger ac16f38
Merge remote-tracking branch 'upstream' into RapierContext_Component
ThierryBerger 941b52e
fix conflict
ThierryBerger 5669a8c
fix unwrap
ThierryBerger 0b9ca86
fix warning
ThierryBerger f4643ef
address pr feedback
ThierryBerger f8b296a
address pr feedback
ThierryBerger 0e46610
Merge branch 'master' into RapierContext_Component
ThierryBerger 75c2195
fixed compilation
ThierryBerger ccd2be7
fix doc comment
ThierryBerger 9142888
fixed joints3 example
ThierryBerger ba0cd76
experiment on stepping to test system ordering and consistent ecs state
ThierryBerger 6d10fe6
fix compilation + warning
ThierryBerger d0b07a0
better error handling when rapier context is missing
ThierryBerger 2676c35
add a name for rapier context entity
ThierryBerger 40be1f1
Merge branch 'master' into RapierContext_Component
ThierryBerger deb0a06
rename an init function
ThierryBerger cf165bd
apply pr suggestion
ThierryBerger aeab8c9
apply PR suggestions
ThierryBerger 07eefbb
Merge branch 'master' into RapierContext_Component
ThierryBerger 4cccde1
rename rapier context system params
ThierryBerger cbfe138
fix clippy (+ random typo)
ThierryBerger 5dc5b2d
cargo fmt
ThierryBerger d0961d0
Merge remote-tracking branch 'upstream' into RapierContext_Component
ThierryBerger 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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_custom_initialization(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); | ||
| } | ||
ThierryBerger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.