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

Async colliders #190

Merged
merged 83 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 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
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
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
3 changes: 1 addition & 2 deletions crates/bevy_xpbd_2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["gamedev", "physics", "simulation", "xpbd", "bevy"]
categories = ["game-development", "science", "simulation"]

[features]
default = ["2d", "f32", "collider-from-mesh", "parallel"]
default = ["2d", "f32", "parallel"]
2d = []
f32 = ["dep:parry2d"]
f64 = ["dep:parry2d-f64"]
Expand All @@ -24,7 +24,6 @@ enhanced-determinism = [
"parry2d-f64?/enhanced-determinism",
"glam/libm",
]
collider-from-mesh = ["bevy/bevy_render"]

[lib]
name = "bevy_xpbd_2d"
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_xpbd_3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["gamedev", "physics", "simulation", "xpbd", "bevy"]
categories = ["game-development", "science", "simulation"]

[features]
default = ["3d", "f32", "collider-from-mesh", "parallel"]
default = ["3d", "f32", "async-collider", "parallel"]
3d = []
f32 = ["dep:parry3d"]
f64 = ["dep:parry3d-f64"]
Expand All @@ -25,6 +25,7 @@ enhanced-determinism = [
"glam/libm",
]
collider-from-mesh = ["bevy/bevy_render"]
async-collider = ["bevy/bevy_scene", "bevy/bevy_gltf", "collider-from-mesh"]

[lib]
name = "bevy_xpbd_3d"
Expand Down Expand Up @@ -90,6 +91,10 @@ required-features = ["3d"]
name = "trimesh_shapes_3d"
required-features = ["3d"]

[[example]]
name = "async_colliders"
required-features = ["3d", "async-collider"]

[[bench]]
name = "cubes"
harness = false
Binary file added crates/bevy_xpbd_3d/assets/ferris.glb
Binary file not shown.
69 changes: 69 additions & 0 deletions crates/bevy_xpbd_3d/examples/async_colliders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! An example showcasing how to create colliders for meshes and scenes
//! using `AsyncCollider` and `AsyncSceneCollider` respectively.

use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;
use examples_common_3d::XpbdExamplePlugin;

fn main() {
App::new()
.add_plugins((DefaultPlugins, XpbdExamplePlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
assets: ResMut<AssetServer>,
) {
// Spawn ground and generate a collider for the mesh using AsyncCollider
commands.spawn((
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()
},
AsyncCollider(ComputedCollider::TriMesh),
RigidBody::Static,
));

// Spawn Ferris the crab and generate colliders for the scene using AsyncSceneCollider
commands.spawn((
SceneBundle {
// The model was made by RayMarch, licenced under CC0-1.0, and can be found here:
// https://github.com/RayMarch/ferris3d
scene: assets.load("ferris.glb#Scene0"),
transform: Transform::from_xyz(0.0, 2.0, 0.0).with_scale(Vec3::splat(2.0)),
..default()
},
// Create colliders using convex decomposition.
// This takes longer than creating a trimesh or convex hull collider,
// but is more performant for collision detection.
AsyncSceneCollider::new(Some(ComputedCollider::ConvexDecomposition(
VHACDParameters::default(),
)))
// Make the arms heavier to make it easier to stand upright
.with_density_for_name("armL_mesh", 5.0)
.with_density_for_name("armR_mesh", 5.0),
RigidBody::Dynamic,
));

// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 3000.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(2.0, 8.0, 2.0),
..default()
});

// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-5.0, 3.5, 5.5).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
2 changes: 1 addition & 1 deletion crates/bevy_xpbd_3d/examples/trimesh_shapes_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn setup(
for (i, shape) in shapes.into_iter().enumerate() {
commands.spawn((
RigidBody::Dynamic,
Collider::trimesh_from_bevy_mesh(&shape).unwrap(),
Collider::trimesh_from_mesh(&shape).unwrap(),
Position(Vector::new(
-14.5 / 2.0 + i as Scalar / (num_shapes - 1) as Scalar * 14.5,
2.0,
Expand Down
Loading