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

Parry update (0.18?) #770

Merged
merged 11 commits into from
Jan 8, 2025
Prev Previous commit
Next Next commit
add example to test intersection
  • Loading branch information
Vrixyz authored and sebcrozet committed Jan 8, 2025
commit b24a9e0b8a2b3fa1976477bacd6c8562c8614682
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ resolver = "2"
#parry3d-f64 = { git = "https://github.com/dimforge/parry", branch = "master" }


parry2d = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
parry3d = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
parry2d-f64 = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
parry3d-f64 = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
# parry2d = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
# parry3d = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
# parry2d-f64 = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
# parry3d-f64 = { git = "https://github.com/Vrixyz/parry", branch = "273-shape-shape-best" }
parry2d = { path = "../parry/crates/parry2d" }
parry3d = { path = "../parry/crates/parry3d" }
parry2d-f64 = { path = "../parry/crates/parry2d-f64" }
parry3d-f64 = { path = "../parry/crates/parry3d-f64" }

# # For feature unstable-puffin-pr-235
# # See https://github.com/dimforge/rapier/issues/760.
Expand Down
4 changes: 2 additions & 2 deletions crates/rapier_testbed2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ default = ["dim2"]
dim2 = []
parallel = ["rapier/parallel", "num_cpus"]
other-backends = ["wrapped2d"]
profiling = ["dep:puffin_egui", "profiling/profile-with-puffin"]
profiler_ui = [] #["dep:puffin_egui", "profiling/profile-with-puffin"]
# See https://github.com/dimforge/rapier/issues/760.
unstable-puffin-pr-235 = []

[package.metadata.docs.rs]
features = ["parallel", "profiling"]
features = ["parallel", "profiler_ui"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feature change name is to avoid naming a feature the same as a dependency, + better represent what this does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, but I encountered problems with enabling profiling/profile-with-tracy without that change (because you cannot profile with 2 backends (puffin+tracy)), I imagine that enabled profiling too, so that feature name change would have fixed it.


[lints.clippy]
needless_lifetimes = "allow"
Expand Down
6 changes: 3 additions & 3 deletions crates/rapier_testbed2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ default = ["dim2"]
dim2 = []
parallel = ["rapier/parallel", "num_cpus"]
other-backends = ["wrapped2d"]
profiling = ["dep:puffin_egui", "profiling/profile-with-puffin"]
profiler_ui = [] #["dep:puffin_egui", "profiling/profile-with-puffin"]
# See https://github.com/dimforge/rapier/issues/760.
unstable-puffin-pr-235 = []

[package.metadata.docs.rs]
features = ["parallel", "other-backends", "profiling"]
features = ["parallel", "other-backends", "profiler_ui"]

[lints.clippy]
needless_lifetimes = "allow"
Expand All @@ -62,7 +62,7 @@ bevy_core_pipeline = "0.14"
bevy_pbr = "0.14"
bevy_sprite = "0.14"
profiling = "1.0"
puffin_egui = { version = "0.29", optional = true }
#puffin_egui = { version = "0.29", optional = true }

# Dependencies for native only.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/rapier_testbed3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
default = ["dim3"]
dim3 = []
parallel = ["rapier/parallel", "num_cpus"]
profiling = ["dep:puffin_egui", "profiling/profile-with-puffin"]
profiler_ui = [] #["dep:puffin_egui", "profiling/profile-with-puffin"]
# See https://github.com/dimforge/rapier/issues/760.
unstable-puffin-pr-235 = []

[package.metadata.docs.rs]
features = ["parallel", "profiling"]
features = ["parallel", "profiler_ui"]

[lints.clippy]
needless_lifetimes = "allow"
Expand Down
4 changes: 2 additions & 2 deletions crates/rapier_testbed3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ default = ["dim3"]
dim3 = []
parallel = ["rapier/parallel", "num_cpus"]
other-backends = ["physx", "physx-sys", "glam"]
profiling = ["dep:puffin_egui", "profiling/profile-with-puffin"]
profiler_ui = [] #["dep:puffin_egui", "profiling/profile-with-puffin"]
# See https://github.com/dimforge/rapier/issues/760.
unstable-puffin-pr-235 = []

[package.metadata.docs.rs]
features = ["parallel", "other-backends", "profiling"]
features = ["parallel", "other-backends", "profiler_ui"]

[lints.clippy]
needless_lifetimes = "allow"
Expand Down
2 changes: 1 addition & 1 deletion examples2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ usvg = "0.14"

[dependencies.rapier_testbed2d]
path = "../crates/rapier_testbed2d"
features = ["profiling"]
#features = ["profiler_ui"]

[dependencies.rapier2d]
path = "../crates/rapier2d"
Expand Down
2 changes: 2 additions & 0 deletions examples2d/all_examples2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod convex_polygons2;
mod damping2;
mod debug_box_ball2;
mod debug_compression2;
mod debug_intersection2;
mod debug_total_overlap2;
mod debug_vertical_column2;
mod drum2;
Expand Down Expand Up @@ -99,6 +100,7 @@ pub fn main() {
("Joint motor position", joint_motor_position2::init_world),
("(Debug) box ball", debug_box_ball2::init_world),
("(Debug) compression", debug_compression2::init_world),
("(Debug) intersection", debug_intersection2::init_world),
("(Debug) total overlap", debug_total_overlap2::init_world),
(
"(Debug) vertical column",
Expand Down
66 changes: 66 additions & 0 deletions examples2d/debug_intersection2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;

pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();

let rad = 1.0;
let collider = ColliderBuilder::ball(rad);

let count = 100;
for x in 0..count {
for y in 0..count {
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
(x as f32 - count as f32 / 2.0) * rad * 3.0,
(y as f32 - count as f32 / 2.0) * rad * 3.0
]);
let handle = bodies.insert(rigid_body);
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
testbed.set_initial_body_color(
handle,
[
x as f32 / count as f32,
(count - y) as f32 / count as f32,
0.5,
],
);
}
}

/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![0.0, 0.0], 50.0);

testbed.add_callback(move |graphics, physics, _, run| {
let slow_time = run.timestep_id as f32 / 3.0;
let intersection = physics.query_pipeline.intersection_with_shape(
&physics.bodies,
&physics.colliders,
&Isometry::translation(slow_time.cos() * 10.0, slow_time.sin() * 10.0),
&Ball::new(rad / 2.0),
QueryFilter::default(),
);

if let Some(graphics) = graphics {
for (handle, _) in physics.bodies.iter() {
graphics.set_body_color(handle, [0.5, 0.5, 0.5]);
}
if let Some(intersection) = intersection {
let collider = physics.colliders.get(intersection).unwrap();
let body_handle = collider.parent().unwrap();

graphics.set_body_color(body_handle, [1.0, 0.0, 0.0]);
}
}

//println!("intersection: {:?}", intersection);
});
}
2 changes: 1 addition & 1 deletion examples3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bincode = "1"

[dependencies.rapier_testbed3d]
path = "../crates/rapier_testbed3d"
features = ["profiling"]
features = ["profiler_ui"]

[dependencies.rapier3d]
path = "../crates/rapier3d"
Expand Down
2 changes: 1 addition & 1 deletion src_testbed/testbed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl TestbedApp {
}

pub fn run_with_init(mut self, mut init: impl FnMut(&mut App)) {
#[cfg(feature = "profiling")]
#[cfg(feature = "profiler_ui")]
puffin_egui::puffin::set_scopes_on(true);

let mut args = env::args();
Expand Down
2 changes: 1 addition & 1 deletion src_testbed/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn update_ui(
harness: &mut Harness,
debug_render: &mut DebugRenderPipelineResource,
) {
#[cfg(feature = "profiling")]
#[cfg(feature = "profiler_ui")]
{
let window = egui::Window::new("Profiling");
let window = window.default_open(false);
Expand Down