Skip to content

Commit 7d53edd

Browse files
committed
rm muldibody example
1 parent adc47ce commit 7d53edd

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

examples3d/all_examples3.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod debug_disabled3;
4545
mod debug_internal_edges3;
4646
mod debug_long_chain3;
4747
mod debug_multibody_ang_motor_pos3;
48+
mod debug_rm_multibody3;
4849
mod debug_sleeping_kinematic3;
4950
mod debug_two_cubes3;
5051
mod gyroscopic3;
@@ -146,6 +147,10 @@ pub fn main() {
146147
"(Debug) multibody ang. motor pos.",
147148
debug_multibody_ang_motor_pos3::init_world,
148149
),
150+
(
151+
"(Debug) remove multibody joint",
152+
debug_rm_multibody3::init_world,
153+
),
149154
];
150155

151156
// Lexicographic sort, with stress tests moved at the end of the list.

examples3d/debug_rm_multibody3.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use rapier_testbed3d::Testbed;
2+
use rapier3d::prelude::*;
3+
4+
pub fn init_world(testbed: &mut Testbed) {
5+
let mut bodies = RigidBodySet::new();
6+
let mut colliders = ColliderSet::new();
7+
let impulse_joints = ImpulseJointSet::new();
8+
let mut multibody_joints = MultibodyJointSet::new();
9+
10+
let root = bodies.insert(RigidBodyBuilder::fixed());
11+
colliders.insert_with_parent(ColliderBuilder::cuboid(0.5, 0.5, 0.5), root, &mut bodies);
12+
13+
let mut attached_bodies = vec![root];
14+
for i in 1..4 {
15+
let body = bodies.insert(RigidBodyBuilder::dynamic().translation(Vector::new(
16+
0.0,
17+
-2.0 * i as f32,
18+
0.0,
19+
)));
20+
colliders.insert_with_parent(ColliderBuilder::cuboid(0.5, 0.5, 0.5), body, &mut bodies);
21+
22+
multibody_joints.insert(
23+
*attached_bodies.last().unwrap(),
24+
body,
25+
SphericalJointBuilder::new()
26+
.local_anchor1(Point::new(0.0, -2.0, 0.0))
27+
.build()
28+
.data,
29+
true,
30+
);
31+
attached_bodies.push(body);
32+
}
33+
34+
// Remove this and the example won't crash.
35+
{
36+
let body =
37+
bodies.insert(RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 2.0, 0.0)));
38+
colliders.insert_with_parent(ColliderBuilder::cuboid(0.5, 0.5, 0.5), body, &mut bodies);
39+
}
40+
41+
testbed.add_callback(move |graphics, physics, _, run_state| {
42+
if run_state.timestep_id % 33 == 31 && attached_bodies.len() > 1 {
43+
let body = attached_bodies.pop().unwrap();
44+
physics.bodies.remove(
45+
body,
46+
&mut physics.islands,
47+
&mut physics.colliders,
48+
&mut physics.impulse_joints,
49+
&mut physics.multibody_joints,
50+
true,
51+
);
52+
if let Some(graphics) = graphics {
53+
graphics.remove_body(body);
54+
}
55+
}
56+
});
57+
58+
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
59+
testbed.look_at(point![20.0, 0.0, 0.0], point![0.0, 0.0, 0.0]);
60+
}

0 commit comments

Comments
 (0)