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

Use Transform instead of Position and Rotation in examples #201

Merged
merged 95 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
32fd960
Fix contact points in penetration computation
Jondolf Sep 15, 2023
703748d
Update child collider positions based on parent
Jondolf Sep 15, 2023
984b4b6
Fix compound collider contact points
Jondolf Sep 15, 2023
f43c94a
Only debug render axes for rigid bodies
Jondolf Sep 15, 2023
f0f4f6f
Add `ColliderParent` and implement child collider collisions
Jondolf Sep 15, 2023
9cf7c51
Allow sensors, custom friction and restitution for child colliders
Jondolf Sep 15, 2023
5976ee6
Fix subshape rotations
Jondolf Sep 16, 2023
7d3d9b4
Document `ColliderParent`
Jondolf Sep 16, 2023
a21db10
Support arbirarily deep collider nesting and improve stability
Jondolf Sep 16, 2023
7aafd37
Fix lints
Jondolf Sep 16, 2023
d015e88
Fix lints
Jondolf Sep 17, 2023
a69d0b6
Merge branch 'main' into child-colliders
Jondolf Sep 23, 2023
bc762f3
Fix child collider initial position
Jondolf Sep 23, 2023
2e0dab6
Register `ColliderMassProperties` and `PreviousColliderOffset`
Jondolf Sep 24, 2023
1ebb48d
Remove unnecessary components from colliders without `RigidBody`
Jondolf Sep 24, 2023
bbd4618
Improve `Collider` documentation and document child colliders
Jondolf Sep 24, 2023
28db07a
Fix missing delimiter in docs
Jondolf Sep 24, 2023
81bdf3b
Wake up bodies when child colliders are transformed
Jondolf Sep 24, 2023
4332248
Fix missing delimiter in docs again
Jondolf Sep 24, 2023
85c66d2
Improve `ColliderParent` docs
Jondolf Sep 24, 2023
3f586c0
Merge branch 'main' into child-colliders
Jondolf Sep 25, 2023
362d0bf
Correctly handle removing colliders from rigid bodies
Jondolf Sep 26, 2023
6af30ab
Reset `ColliderParent` and `ColliderOffset` when rigid body is removed
Jondolf Sep 26, 2023
c57db60
Automatically add and remove `ColliderParent` and `ColliderOffset`
Jondolf Sep 28, 2023
b0b8187
Change 2D examples to use `Transform` instead of `Position`
Jondolf Sep 29, 2023
0d6b948
Merge branch 'main' into child-colliders
Jondolf Oct 9, 2023
8ed6dd7
Merge branch 'main' into child-colliders
Jondolf Oct 14, 2023
a1783dc
Merge branch 'main' into child-colliders
Jondolf Oct 18, 2023
be762d2
Refactor collider logic in `penetration_constraints`
Jondolf Oct 18, 2023
890ac0b
Merge branch 'main' into child-colliders
Jondolf Oct 18, 2023
3294886
Update comments
Jondolf Oct 18, 2023
c2ddfbf
Split up sleeping system into two
Jondolf Oct 18, 2023
ef203a3
Rename system
Jondolf Oct 18, 2023
5df76bc
Improve collider offset propagation
Jondolf Oct 18, 2023
e4944ea
Merge branch 'main' into child-colliders
Jondolf Oct 19, 2023
f555d38
Support rotation and scale for child colliders
Jondolf Oct 19, 2023
b857a31
Add support for collider scale based on transforms
Jondolf Oct 19, 2023
6c9e768
Replace old collider from mesh with `from_mesh` and `ComputedCollider`
Jondolf Oct 20, 2023
b92801f
Add `AsyncSceneCollider`
Jondolf Oct 20, 2023
9c174bf
Add `AsyncCollider`
Jondolf Oct 20, 2023
33c694c
Fix `scale_shape`
Jondolf Oct 20, 2023
34c48e0
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 20, 2023
1812ac1
Fix collision issue
Jondolf Oct 20, 2023
71fb1c5
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 20, 2023
8266f62
Improve `ColliderTransform` handling
Jondolf Oct 20, 2023
fdb929c
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 20, 2023
f006eb1
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 20, 2023
ae70d7e
Clarify comments
Jondolf Oct 20, 2023
9d7940f
Remove unsupported `collider-from-mesh` and `async-collider` from 2D
Jondolf Oct 20, 2023
b483d40
Remove unnecessary language specification in doc examples
Jondolf Oct 21, 2023
a95052b
Fix `ColliderTransform` change detection
Jondolf Oct 21, 2023
fee5c7a
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
ee11ddd
Fix child collider mass properties
Jondolf Oct 21, 2023
80dcdd8
Fix collision states
Jondolf Oct 21, 2023
6f47d8f
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
7633f64
Fix `init_transforms`
Jondolf Oct 21, 2023
df94905
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
71d631d
Fix cfg
Jondolf Oct 21, 2023
69f6d22
Remove unused variable
Jondolf Oct 21, 2023
a48914f
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 21, 2023
bcb2d70
Remove unused variable
Jondolf Oct 21, 2023
4a33805
Improve AABB precision for child colliders of rotating bodies
Jondolf Oct 21, 2023
825a85b
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
e6b76ce
Fix collider scales in examples
Jondolf Oct 21, 2023
7f8c604
Fix `chain_2d` example
Jondolf Oct 21, 2023
ec9cccc
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 21, 2023
87bc9ef
Add `Transform` for physics entities automatically if it's missing
Jondolf Oct 21, 2023
20c6c5e
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
fb88f9e
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 21, 2023
cdd4fb1
Fix code example in docs
Jondolf Oct 21, 2023
13c033c
Make `ColliderParent` optional in some systems
Jondolf Oct 21, 2023
9b0a2f6
Merge branch 'child-colliders' into collider-scale
Jondolf Oct 21, 2023
97b2bae
Merge branch 'collider-scale' into async-colliders
Jondolf Oct 21, 2023
47e0f0a
Fix doc code example
Jondolf Oct 21, 2023
f9d57a8
Rename `AsyncSceneCollider` methods and support collision layers
Jondolf Oct 22, 2023
a70d5e8
Merge branch 'main' into async-colliders
Jondolf Oct 22, 2023
2277b2b
Refactor and support density for `AsyncSceneCollider`
Jondolf Oct 23, 2023
5a31e54
Add `async_colliders` example and Ferris model
Jondolf Oct 23, 2023
80b9892
Remove `PreviousColliderMassProperties` and fix mass props for children
Jondolf Oct 24, 2023
49f3a28
Update densities in `async_collider` example
Jondolf Oct 24, 2023
aa77497
Fix transform change detection
Jondolf Oct 27, 2023
12bb212
Use separate methods instead of single `from_mesh` for `Collider`
Jondolf Oct 27, 2023
d2e3c8b
Fix lint
Jondolf Oct 27, 2023
d024391
Fix code example
Jondolf Oct 27, 2023
72f3b4b
Merge branch 'async-colliders' into transform-in-docs-and-examples
Jondolf Oct 27, 2023
e00e71d
Use `Transform` instead of `Position` in 3D examples
Jondolf Oct 27, 2023
a4ab636
Update README.md code example
Jondolf Oct 27, 2023
ed1e5f0
Merge branch 'main' into transform-in-docs-and-examples
Jondolf Oct 27, 2023
09ead9b
Fix duplicate components in example
Jondolf Oct 27, 2023
9500708
Fix math types and lint
Jondolf Oct 27, 2023
16fd26a
Fix math type
Jondolf Oct 27, 2023
6cd6b72
Fix math type
Jondolf Oct 28, 2023
6f3fd71
Fix math type
Jondolf Oct 28, 2023
49438a1
Fix math type
Jondolf Oct 28, 2023
351e8ea
Fix math type
Jondolf Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,25 @@ fn setup(
) {
// Plane
commands.spawn((
RigidBody::Static,
Collider::cuboid(8.0, 0.002, 8.0),
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane::from_size(8.0))),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
},
RigidBody::Static,
Collider::cuboid(8.0, 0.002, 8.0),
));
// Cube
commands.spawn((
RigidBody::Dynamic,
AngularVelocity(Vec3::new(2.5, 3.4, 1.6)),
Collider::cuboid(1.0, 1.0, 1.0),
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 4.0, 0.0),
..default()
},
RigidBody::Dynamic,
Position(Vec3::Y * 4.0),
AngularVelocity(Vec3::new(2.5, 3.4, 1.6)),
Collider::cuboid(1.0, 1.0, 1.0),
));
// Light
commands.spawn(PointLightBundle {
Expand Down
44 changes: 31 additions & 13 deletions crates/bevy_xpbd_2d/examples/chain_2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![allow(clippy::unnecessary_cast)]

use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::PrimaryWindow};
use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
window::PrimaryWindow,
};
use bevy_xpbd_2d::{math::*, prelude::*};
use examples_common_2d::XpbdExamplePlugin;

Expand All @@ -27,27 +31,40 @@ fn setup(

let particle_count = 100;
let particle_radius = 1.2;
let particle_mesh = MaterialMesh2dBundle {
mesh: meshes
.add(shape::Circle::new(particle_radius as f32).into())
.into(),
material: materials.add(ColorMaterial::from(Color::rgb(0.2, 0.7, 0.9))),
..default()
};
let particle_mesh: Mesh2dHandle = meshes
.add(shape::Circle::new(particle_radius as f32).into())
.into();
let particle_material = materials.add(ColorMaterial::from(Color::rgb(0.2, 0.7, 0.9)));

// Spawn kinematic particle that can follow the mouse
let mut previous_particle = commands
.spawn((particle_mesh.clone(), RigidBody::Kinematic, FollowMouse))
.spawn((
RigidBody::Kinematic,
FollowMouse,
MaterialMesh2dBundle {
mesh: particle_mesh.clone(),
material: particle_material.clone_weak(),
..default()
},
))
.id();

// Spawn the rest of the particles, connecting each one to the previous one with joints
for i in 1..particle_count {
let current_particle = commands
.spawn((
particle_mesh.clone(),
RigidBody::Dynamic,
Position(i as Scalar * Vector::NEG_Y * (particle_radius * 2.0 + 1.0)),
MassPropertiesBundle::new_computed(&Collider::ball(particle_radius), 1.0),
MaterialMesh2dBundle {
mesh: particle_mesh.clone(),
material: particle_material.clone_weak(),
transform: Transform::from_xyz(
0.0,
i as f32 * (particle_radius as f32 * 2.0 + 1.0),
0.0,
),
..default()
},
))
.id();

Expand All @@ -65,7 +82,7 @@ fn follow_mouse(
buttons: Res<Input<MouseButton>>,
windows: Query<&Window, With<PrimaryWindow>>,
camera: Query<(&Camera, &GlobalTransform)>,
mut follower: Query<&mut Position, With<FollowMouse>>,
mut follower: Query<&mut Transform, With<FollowMouse>>,
) {
if buttons.pressed(MouseButton::Left) {
let window = windows.single();
Expand All @@ -76,7 +93,8 @@ fn follow_mouse(
.cursor_position()
.and_then(|cursor| camera.viewport_to_world_2d(camera_transform, cursor))
{
follower_position.0 = cursor_world_pos.adjust_precision();
follower_position.translation =
cursor_world_pos.extend(follower_position.translation.z);
}
}
}
30 changes: 15 additions & 15 deletions crates/bevy_xpbd_2d/examples/collision_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ fn setup(
custom_size: Some(Vec2::new(500.0, 25.0)),
..default()
},
transform: Transform::from_xyz(0.0, -50.0, 0.0),
..default()
},
RigidBody::Static,
Position(Vector::NEG_Y * 50.0),
Collider::cuboid(500.0, 25.0),
CollisionLayers::new([Layer::Blue], [Layer::Blue]),
));
Expand All @@ -51,34 +51,34 @@ fn setup(
custom_size: Some(Vec2::new(500.0, 25.0)),
..default()
},
transform: Transform::from_xyz(0.0, -200.0, 0.0),
..default()
},
RigidBody::Static,
Position(Vector::NEG_Y * 200.0),
Collider::cuboid(500.0, 25.0),
CollisionLayers::new([Layer::Red], [Layer::Red]),
));

let marble_radius = 7.5;
let marble_mesh = meshes.add(shape::Circle::new(marble_radius as f32).into());
let marble_mesh = meshes.add(shape::Circle::new(marble_radius).into());

// Spawn blue marbles that belong on the blue layer and collide with blue
let blue_material = materials.add(ColorMaterial::from(Color::rgb(0.2, 0.7, 0.9)));
for x in -6..6 {
for y in 0..4 {
let position = Vector::new(
x as Scalar * (2.5 * marble_radius),
(y as Scalar) * (2.5 * marble_radius),
);
commands.spawn((
MaterialMesh2dBundle {
mesh: marble_mesh.clone().into(),
material: blue_material.clone(),
transform: Transform::from_xyz(
x as f32 * 2.5 * marble_radius,
y as f32 * 2.5 * marble_radius + 200.0,
0.0,
),
..default()
},
RigidBody::Dynamic,
Position(position + Vector::Y * 200.0),
Collider::ball(marble_radius),
Collider::ball(marble_radius as Scalar),
CollisionLayers::new([Layer::Blue], [Layer::Blue]),
));
}
Expand All @@ -88,19 +88,19 @@ fn setup(
let red_material = materials.add(ColorMaterial::from(Color::rgb(0.9, 0.3, 0.3)));
for x in -6..6 {
for y in -4..0 {
let position = Vector::new(
x as Scalar * (2.5 * marble_radius),
(y as Scalar) * (2.5 * marble_radius),
);
commands.spawn((
MaterialMesh2dBundle {
mesh: marble_mesh.clone().into(),
material: red_material.clone(),
transform: Transform::from_xyz(
x as f32 * 2.5 * marble_radius,
y as f32 * 2.5 * marble_radius + 200.0,
0.0,
),
..default()
},
RigidBody::Dynamic,
Position(position + Vector::Y * 200.0),
Collider::ball(marble_radius),
Collider::ball(marble_radius as Scalar),
CollisionLayers::new([Layer::Red], [Layer::Red]),
));
}
Expand Down
36 changes: 22 additions & 14 deletions crates/bevy_xpbd_2d/examples/distance_joint_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,42 @@ fn main() {
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());

let square = SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.2, 0.7, 0.9),
custom_size: Some(Vec2::splat(50.0)),
..default()
},
let square_sprite = Sprite {
color: Color::rgb(0.2, 0.7, 0.9),
custom_size: Some(Vec2::splat(50.0)),
..default()
};

let anchor = commands.spawn((square.clone(), RigidBody::Kinematic)).id();
let anchor = commands
.spawn((
SpriteBundle {
sprite: square_sprite.clone(),
..default()
},
RigidBody::Kinematic,
))
.id();

let object = commands
.spawn((
square,
SpriteBundle {
sprite: square_sprite,
transform: Transform::from_xyz(0.0, -100.0, 0.0),
..default()
},
RigidBody::Dynamic,
Position(-Vector::Y * 100.0),
MassPropertiesBundle::new_computed(&Collider::cuboid(50.0, 50.0), 1.0),
))
.id();

commands.spawn(
DistanceJoint::new(anchor, object)
.with_local_anchor_1(-Vector::Y * 25.0)
.with_local_anchor_2(Vector::ONE * 25.0)
.with_local_anchor_1(Vector::ZERO)
.with_local_anchor_2(Vector::ZERO)
.with_rest_length(100.0)
// .with_linear_velocity_damping(0.1)
.with_linear_velocity_damping(0.1)
.with_angular_velocity_damping(1.0)
.with_limits(55.0, 150.0)
.with_compliance(1.0 / 50000.0),
.with_limits(140.0, 150.0)
.with_compliance(0.00000001),
);
}
25 changes: 16 additions & 9 deletions crates/bevy_xpbd_2d/examples/fixed_joint_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ fn main() {
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());

let square = SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.2, 0.7, 0.9),
custom_size: Some(Vec2::splat(50.0)),
..default()
},
let square_sprite = Sprite {
color: Color::rgb(0.2, 0.7, 0.9),
custom_size: Some(Vec2::splat(50.0)),
..default()
};

let anchor = commands
.spawn((square.clone(), RigidBody::Kinematic, AngularVelocity(1.5)))
.spawn((
SpriteBundle {
sprite: square_sprite.clone(),
..default()
},
RigidBody::Kinematic,
AngularVelocity(1.5),
))
.id();

let object = commands
.spawn((
square,
SpriteBundle {
sprite: square_sprite,
transform: Transform::from_xyz(100.0, 0.0, 0.0),
..default()
},
RigidBody::Dynamic,
Position(Vector::X * 100.0),
MassPropertiesBundle::new_computed(&Collider::cuboid(50.0, 50.0), 1.0),
))
.id();
Expand Down
Loading