-
-
Notifications
You must be signed in to change notification settings - Fork 274
Rapier 0.25 #651
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
Merged
Rapier 0.25 #651
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
367e280
update to rapier 0.25 + add voxel support + example for 2d
ThierryBerger 16858ca
add example for voxels in 3d
ThierryBerger c2c11f7
fix benches
ThierryBerger 9341ad7
update changelog
ThierryBerger 48523db
fix clippy
ThierryBerger d9c235c
add mutable view to voxels
ThierryBerger c2eaadc
avoid an unneeded warning in testbed while cleaning ; add debugdump f…
ThierryBerger 7f055bb
fix compilation + add link to issue
ThierryBerger 741a5b2
enable logs for dev-dependencies 2d
ThierryBerger 6edcaa9
fix compilation + clippy
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use bevy::prelude::*; | ||
| use bevy_rapier2d::prelude::*; | ||
| use nalgebra::{point, Vector2}; | ||
| use rapier2d::prelude::{SharedShape, VoxelPrimitiveGeometry}; | ||
|
|
||
| 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>::pixels_per_meter(10.0), | ||
| RapierDebugRenderPlugin::default(), | ||
| )) | ||
| .add_systems(Startup, (setup_graphics, setup_physics)) | ||
| .run(); | ||
| } | ||
|
|
||
| pub fn setup_graphics(mut commands: Commands) { | ||
| commands.spawn((Camera2d, Transform::from_xyz(0.0, 20.0, 0.0))); | ||
| } | ||
|
|
||
| pub fn setup_physics(mut commands: Commands) { | ||
| let scale = 15f32; | ||
| /* | ||
| * Create dynamic objects to fall on voxels. | ||
| */ | ||
| let nx = 50; | ||
| for i in 0..nx { | ||
| for j in 0..10 { | ||
| let falling_objects = (j + i) % 3; | ||
|
|
||
| let ball_radius = 0.5 * scale; | ||
| let co = match falling_objects { | ||
| 0 => Collider::ball(ball_radius), | ||
| 1 => Collider::cuboid(ball_radius, ball_radius), | ||
| 2 => Collider::capsule_y(ball_radius, ball_radius), | ||
| _ => unreachable!(), | ||
| }; | ||
| commands.spawn(( | ||
| Transform::from_xyz( | ||
| (i as f32 * 2.0 - nx as f32 / 2.0) * scale, | ||
| (20.0 + j as f32 * 2.0) * scale, | ||
| 0.0, | ||
| ), | ||
| RigidBody::Dynamic, | ||
| co, | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Voxelization. | ||
| */ | ||
| let polyline = vec![ | ||
| point![0.0, 0.0], | ||
| point![0.0, 10.0], | ||
| point![7.0, 4.0], | ||
| point![14.0, 10.0], | ||
| point![14.0, 0.0], | ||
| point![13.0, 7.0], | ||
| point![7.0, 2.0], | ||
| point![1.0, 7.0], | ||
| ] | ||
| .iter() | ||
| .map(|p| p * scale) | ||
| .collect::<Vec<_>>(); | ||
| let indices: Vec<_> = (0..polyline.len() as u32) | ||
| .map(|i| [i, (i + 1) % polyline.len() as u32]) | ||
| .collect(); | ||
|
|
||
| let shape = SharedShape::voxelized_mesh( | ||
| VoxelPrimitiveGeometry::PseudoCube, | ||
| &polyline, | ||
| &indices, | ||
| 0.2 * scale, | ||
| FillMode::default(), | ||
| ); | ||
| commands.spawn(( | ||
| Transform::from_xyz(-20.0 * scale, -10.0 * scale, 0.0), | ||
| Collider::from(shape), | ||
| )); | ||
|
|
||
| /* | ||
| * A voxel wavy floor. | ||
| */ | ||
| let voxel_size = Vector2::new(scale, scale); | ||
| let voxels: Vec<_> = (0..300) | ||
| .map(|i| { | ||
| let y = (i as f32 / 20.0).sin().clamp(-0.5, 0.5) * 20.0; | ||
| point![(i as f32 - 125.0) * voxel_size.x / 2.0, y * voxel_size.y] | ||
| }) | ||
| .collect(); | ||
| commands.spawn(( | ||
| Transform::from_xyz(0.0, 0.0, 0.0), | ||
| Collider::from(rapier2d::prelude::SharedShape::voxels_from_points( | ||
| VoxelPrimitiveGeometry::PseudoCube, | ||
| voxel_size, | ||
| &voxels, | ||
| )), | ||
| )); | ||
| } | ||
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,104 @@ | ||
| use bevy::prelude::*; | ||
| use bevy_rapier3d::prelude::*; | ||
| use nalgebra::{point, Isometry, Vector3}; | ||
| use rapier3d::prelude::VoxelPrimitiveGeometry; | ||
|
|
||
| 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)) | ||
| .run(); | ||
| } | ||
|
|
||
| pub fn setup_graphics(mut commands: Commands) { | ||
| commands.spawn(( | ||
| Camera3d::default(), | ||
| Transform::from_xyz(-100.0, 100.0, -100.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), | ||
| )); | ||
| } | ||
|
|
||
| pub fn setup_physics(mut commands: Commands) { | ||
| /* | ||
| * Create a voxelized wavy floor. | ||
| */ | ||
| let voxel_size = Vector3::new(1f32, 1f32, 1f32); | ||
| let mut samples = vec![]; | ||
| let n = 200; | ||
| for i in 0..n { | ||
| for j in 0..n { | ||
| let y = (i as f32 / n as f32 * 10.0).sin().clamp(-0.8, 0.8) | ||
| * (j as f32 / n as f32 * 10.0).cos().clamp(-0.8, 0.8) | ||
| * 16.0; | ||
|
|
||
| samples.push(point![ | ||
| i as f32 * voxel_size.x, | ||
| y * voxel_size.y, | ||
| j as f32 * voxel_size.z | ||
| ]); | ||
|
|
||
| if i == 0 || i == n - 1 || j == 0 || j == n - 1 { | ||
| // Create walls so the object at the edge don’t fall into the infinite void. | ||
| for k in 0..4 { | ||
| samples.push(point![ | ||
| i as f32 * voxel_size.x, | ||
| (y + k as f32) * voxel_size.y, | ||
| j as f32 * voxel_size.z | ||
| ]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| let collider = rapier3d::prelude::SharedShape::voxels_from_points( | ||
| VoxelPrimitiveGeometry::PseudoCube, | ||
| voxel_size, | ||
| &samples, | ||
| ); | ||
| let ground_position = Vec3::new(voxel_size.x / 2f32, 0.0, voxel_size.z / 2f32); | ||
| let floor_aabb = collider.compute_aabb(&Isometry::identity()); | ||
| commands.spawn(( | ||
| Transform::from_translation(ground_position), | ||
| Collider::from(collider), | ||
| )); | ||
|
|
||
| /* | ||
| * Create dynamic objects to fall on voxels. | ||
| */ | ||
| let extents = floor_aabb.extents() * 0.75; | ||
| let margin = (floor_aabb.extents() - extents) / 2.0; | ||
| let nik = 30; | ||
| for i in 0..nik { | ||
| for j in 0..5 { | ||
| for k in 0..nik { | ||
| let falling_objects = (j + i + k) % 3; | ||
|
|
||
| let ball_radius = 0.5; | ||
| let co = match falling_objects { | ||
| 0 => Collider::ball(ball_radius), | ||
| 1 => Collider::cuboid(ball_radius, ball_radius, ball_radius), | ||
| 2 => Collider::capsule_y(ball_radius, ball_radius), | ||
| _ => unreachable!(), | ||
| }; | ||
| commands.spawn(( | ||
| Transform::from_xyz( | ||
| floor_aabb.mins.x + margin.x + i as f32 * extents.x / nik as f32 | ||
| - ground_position.x, | ||
| floor_aabb.maxs.y + j as f32 * 2.0 - ground_position.y, | ||
| floor_aabb.mins.z + margin.z + k as f32 * extents.z / nik as f32 | ||
| - -ground_position.z, | ||
| ), | ||
| RigidBody::Dynamic, | ||
| co, | ||
| )); | ||
| } | ||
| } | ||
| } | ||
| } |
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.
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.
relying on nalgebra types here is not great, but I'm not sure duplicating API on library's side is great either 🤔