Skip to content

Commit

Permalink
Revert boxes3 example
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri committed Jul 26, 2023
1 parent 9aadb01 commit 73e3781
Showing 1 changed file with 2 additions and 151 deletions.
153 changes: 2 additions & 151 deletions bevy_rapier3d/examples/boxes3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,155 +17,6 @@ fn main() {
.run();
}

fn setup_compound(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
// Normal compound
// - Scaling works as expected
commands
.spawn(TransformBundle::default())
.insert(Name::new("Compound"))
.insert(RigidBody::Dynamic)
.insert(ToggleCollider)
.insert(ToggleScale)
.insert(Collider::compound(vec![
(Vec3::ZERO, Quat::IDENTITY, Collider::cuboid(0.5, 0.5, 0.5)),
(
Vec3::new(0.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::cuboid(0.5, 0.5, 0.5),
),
(
Vec3::new(-1.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::cuboid(0.5, 0.5, 0.5),
),
]));

let mesh = meshes.add(Mesh::from(shape::UVSphere {
radius: 0.2,
..default()
}));

commands
.spawn(PbrBundle {
mesh: mesh.clone(),
..default()
})
.insert(TransformBundle::from_transform(Transform {
translation: Vec3::new(-4.0, 0.0, 0.0),
..default()
}))
.insert(Name::new("Standalone collider"))
.insert(ToggleScale)
.insert(ToggleCollider)
.insert(Collider::cuboid(0.5, 0.5, 0.5));

commands
.spawn(PbrBundle {
mesh: mesh.clone(),
..default()
})
.insert(TransformBundle::from_transform(Transform {
translation: Vec3::new(4.0, 0.0, 0.0),
..default()
}))
.insert(Name::new("Compound via children"))
.insert(RigidBody::Dynamic)
.insert(ToggleScale)
//.insert(ToggleCollider)
.insert(Collider::cuboid(0.5, 0.5, 0.5))
.with_children(|children| {
children
.spawn(PbrBundle {
mesh: mesh.clone(),
..default()
})
.insert(TransformBundle::from_transform(Transform {
translation: Vec3::new(0.0, 1.0, 0.0),
..default()
}))
.insert(Name::new("Child collider"))
.insert(Collider::cuboid(0.5, 0.5, 0.5));

children
.spawn(PbrBundle {
mesh: mesh.clone(),
..default()
})
.insert(TransformBundle::from_transform(Transform {
translation: Vec3::new(-1.0, 1.0, 0.0),
..default()
}))
.insert(Name::new("Child collider"))
.insert(Collider::cuboid(0.5, 0.5, 0.5));
});
}

#[derive(Component)]
pub struct ToggleCollider;
#[derive(Component)]
pub struct ToggleScale;

fn toggle_compound(
keycode: Res<Input<KeyCode>>,
mut commands: Commands,
mut collider: Query<(Entity, &mut Collider), With<ToggleCollider>>,
mut scale: Query<(Entity, &mut Transform), With<ToggleScale>>,
) {
let new_collider = if keycode.just_pressed(KeyCode::Key1) {
Some(Collider::compound(vec![
(Vec3::ZERO, Quat::IDENTITY, Collider::cuboid(0.5, 0.5, 0.5)),
(
Vec3::new(0.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::cuboid(0.5, 0.5, 0.5),
),
(
Vec3::new(-1.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::cuboid(0.5, 0.5, 0.5),
),
]))
} else if keycode.just_pressed(KeyCode::Key2) {
Some(Collider::compound(vec![
(Vec3::ZERO, Quat::IDENTITY, Collider::ball(0.5)),
(
Vec3::new(0.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::ball(0.5),
),
(
Vec3::new(-1.0, 1.0, 0.0),
Quat::IDENTITY,
Collider::ball(0.5),
),
]))
} else {
None
};

let new_scale_ratio = if keycode.just_pressed(KeyCode::T) {
Some(1.1)
} else if keycode.just_pressed(KeyCode::R) {
Some(0.9)
} else {
None
};

if let Some(new_scale_ratio) = new_scale_ratio {
for (entity, mut transform) in &mut scale {
transform.scale *= new_scale_ratio;
transform.scale = transform.scale.max(Vec3::new(0.1, 0.1, 0.1));
transform.scale = transform.scale.min(Vec3::new(5.0, 5.0, 5.0));
}
}

if let Some(new_collider) = new_collider {
for (entity, mut collider) in &mut collider {
*collider = new_collider.clone();
}
}
}

fn setup_graphics(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-30.0, 30.0, 100.0)
Expand All @@ -189,7 +40,7 @@ pub fn setup_physics(mut commands: Commands) {
/*
* Create the cubes
*/
let num = 0;
let num = 8;
let rad = 1.0;

let shift = rad * 2.0 + rad;
Expand All @@ -205,7 +56,7 @@ pub fn setup_physics(mut commands: Commands) {
Color::hsl(260.0, 1.0, 0.7),
];

for j in 0usize..num {
for j in 0usize..20 {
for i in 0..num {
for k in 0usize..num {
let x = i as f32 * shift - centerx + offset;
Expand Down

0 comments on commit 73e3781

Please sign in to comment.