Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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,359 changes: 2,258 additions & 1,101 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions crates/avian2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ parry-f64 = ["f64", "dep:parry2d-f64", "default-collider"]
# Enables the XPBD constraint solver for joints.
xpbd_joints = []

bevy_scene = ["bevy/bevy_scene"]
bevy_scene = ["bevy/bevy_world_serialization"]
bevy_picking = ["bevy/bevy_picking"]
serialize = [
"dep:serde",
Expand Down Expand Up @@ -77,18 +77,18 @@ bench = false

[dependencies]
avian_derive = { path = "../avian_derive", version = "0.2" }
bevy = { version = "0.18.0", default-features = false, features = [
bevy = { git = "https://github.com/bevyengine/bevy",default-features = false, features = [
"std",
"bevy_log",
] }
bevy_math = { version = "0.18.0", features = ["approx"] }
glam_matrix_extras = { version = "0.2", features = ["bevy_reflect"] }
bevy_heavy = { version = "0.4" }
bevy_transform_interpolation = { version = "0.4" }
bevy_math = { git = "https://github.com/bevyengine/bevy",features = ["approx"] }
glam_matrix_extras = { git = "https://github.com/jbuehler23/glam_matrix_extras", branch = "bsn", features = ["bevy_reflect"] }
bevy_heavy = { git = "https://github.com/jbuehler23/bevy_heavy", branch = "bsn" }
bevy_transform_interpolation = { git = "https://github.com/jbuehler23/bevy_transform_interpolation", branch = "bsn" }
libm = { version = "0.2", optional = true }
approx = "0.5"
parry2d = { version = "0.26", optional = true }
parry2d-f64 = { version = "0.26", optional = true }
parry2d = { version = "0.27", optional = true }
parry2d-f64 = { version = "0.27", optional = true }
obvhs = { version = "0.3" }
serde = { version = "1", features = ["derive"], optional = true }
derive_more = "2"
Expand All @@ -102,8 +102,8 @@ disqualified = { version = "1.0" }

[dev-dependencies]
examples_common_2d = { path = "../examples_common_2d" }
bevy = { version = "0.18.0", default-features = false, features = ["2d", "ui"] }
bevy_heavy = { version = "0.4", features = ["approx"] }
bevy = { git = "https://github.com/bevyengine/bevy",default-features = false, features = ["2d", "ui"] }
bevy_heavy = { git = "https://github.com/jbuehler23/bevy_heavy", branch = "bsn", features = ["approx"] }
glam = { version = "0.30", features = ["bytemuck"] }
bytemuck = "1.19"
criterion = { version = "0.8", features = ["html_reports"] }
Expand Down
22 changes: 11 additions & 11 deletions crates/avian3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ parry-f64 = ["f64", "dep:parry3d-f64", "default-collider"]
xpbd_joints = []

collider-from-mesh = ["bevy/bevy_mesh", "bevy/bevy_mikktspace", "3d"]
bevy_scene = ["bevy/bevy_scene"]
bevy_scene = ["bevy/bevy_world_serialization"]
bevy_picking = ["bevy/bevy_picking"]
serialize = [
"dep:serde",
Expand Down Expand Up @@ -79,18 +79,18 @@ bench = false

[dependencies]
avian_derive = { path = "../avian_derive", version = "0.2" }
bevy = { version = "0.18.0", default-features = false, features = [
bevy = { git = "https://github.com/bevyengine/bevy",default-features = false, features = [
"std",
"bevy_log",
] }
bevy_math = { version = "0.18.0", features = ["approx"] }
glam_matrix_extras = { version = "0.2", features = ["bevy_reflect"] }
bevy_heavy = { version = "0.4" }
bevy_transform_interpolation = { version = "0.4" }
bevy_math = { git = "https://github.com/bevyengine/bevy",features = ["approx"] }
glam_matrix_extras = { git = "https://github.com/jbuehler23/glam_matrix_extras", branch = "bsn", features = ["bevy_reflect"] }
bevy_heavy = { git = "https://github.com/jbuehler23/bevy_heavy", branch = "bsn" }
bevy_transform_interpolation = { git = "https://github.com/jbuehler23/bevy_transform_interpolation", branch = "bsn" }
libm = { version = "0.2", optional = true }
approx = "0.5"
parry3d = { version = "0.26", optional = true }
parry3d-f64 = { version = "0.26", optional = true }
parry3d = { version = "0.27", optional = true }
parry3d-f64 = { version = "0.27", optional = true }
obvhs = { version = "0.3" }
serde = { version = "1", features = ["derive"], optional = true }
derive_more = "2"
Expand All @@ -103,13 +103,13 @@ disqualified = { version = "1.0" }

[dev-dependencies]
examples_common_3d = { path = "../examples_common_3d" }
bevy = { version = "0.18.0", features = [
bevy = { git = "https://github.com/bevyengine/bevy",features = [
"3d",
"ui",
"https",
"experimental_bevy_feathers",
"bevy_feathers",
] }
bevy_heavy = { version = "0.4", features = ["approx"] }
bevy_heavy = { git = "https://github.com/jbuehler23/bevy_heavy", branch = "bsn", features = ["approx"] }
criterion = { version = "0.8", features = ["html_reports"] }
bevy_mod_debugdump = { version = "0.15" }
rand = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion crates/examples_common_2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024"
use-debug-plugin = []

[dependencies]
bevy = { version = "0.18.0", default-features = false, features = ["2d", "ui"] }
bevy = { git = "https://github.com/bevyengine/bevy", default-features = false, features = ["2d", "ui"] }
avian2d = { path = "../avian2d", default-features = false, features = [
"diagnostic_ui",
] }
Expand Down
2 changes: 1 addition & 1 deletion crates/examples_common_3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024"
use-debug-plugin = []

[dependencies]
bevy = { version = "0.18.0", default-features = false, features = ["3d", "ui"] }
bevy = { git = "https://github.com/bevyengine/bevy", default-features = false, features = ["3d", "ui"] }
avian3d = { path = "../avian3d", default-features = false, features = [
"diagnostic_ui",
] }
Expand Down
2 changes: 1 addition & 1 deletion src/ancestor_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<C: Component + TypePath> Plugin for AncestorMarkerPlugin<C> {
// until an ancestor that has other `AncestorMarker<C>` entities as children is encountered.
#[allow(clippy::type_complexity)]
app.add_observer(
|insert: On<Replace, (ChildOf, C)>,
|insert: On<Discard, (ChildOf, C)>,
mut commands: Commands,
collider_query: Query<&C>,
child_query: Query<&Children>,
Expand Down
8 changes: 4 additions & 4 deletions src/collider_tree/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {
);

// Cases 4
// Note: We use `Replace` here to run before Case 2.
// Note: We use `Discard` here to run before Case 2.
app.add_observer(
add_to_tree_on::<Replace, Disabled, (Without<ColliderDisabled>, Allow<Disabled>)>,
add_to_tree_on::<Discard, Disabled, (Without<ColliderDisabled>, Allow<Disabled>)>,
);
app.add_observer(add_to_tree_on::<Replace, ColliderDisabled, ()>);
app.add_observer(add_to_tree_on::<Discard, ColliderDisabled, ()>);

// Case 5
app.add_observer(
Expand Down Expand Up @@ -371,7 +371,7 @@ impl<C: AnyCollider> Plugin for ColliderTreeUpdatePlugin<C> {

// Case 11
app.add_observer(
|trigger: On<Replace, RigidBodyDisabled>,
|trigger: On<Discard, RigidBodyDisabled>,
body_query: Query<(&RigidBodyColliders, Has<RigidBodyDisabled>)>,
mut collider_query: Query<&ColliderTreeProxyKey, Without<ColliderDisabled>>,
mut trees: ResMut<ColliderTrees>| {
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collider/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
prelude::*,
};
#[cfg(all(feature = "bevy_scene", feature = "default-collider"))]
use bevy::scene::SceneInstance;
use bevy::world_serialization::{WorldAssetRoot as SceneRoot, WorldInstance as SceneInstance, WorldInstanceSpawner as SceneSpawner};
use bevy::{
ecs::{intern::Interned, schedule::ScheduleLabel},
prelude::*,
Expand Down
41 changes: 18 additions & 23 deletions src/collision/collider/collider_hierarchy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use bevy::{
///
/// [`Relationship`]: bevy::ecs::relationship::Relationship
#[derive(Component, Clone, Copy, Debug, PartialEq, Eq, Reflect)]
#[component(immutable, on_insert = <ColliderOf as Relationship>::on_insert, on_replace = <ColliderOf as Relationship>::on_replace)]
#[component(immutable, on_insert = <ColliderOf as Relationship>::on_insert, on_discard = <ColliderOf as Relationship>::on_discard)]
#[require(ColliderTransform)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
Expand All @@ -69,6 +69,8 @@ impl FromWorld for ColliderOf {
impl Relationship for ColliderOf {
type RelationshipTarget = RigidBodyColliders;

const ALLOW_SELF_REFERENTIAL: bool = true;

fn get(&self) -> Entity {
self.body
}
Expand Down Expand Up @@ -145,7 +147,7 @@ impl Relationship for ColliderOf {
}
}

fn on_replace(
fn on_discard(
mut world: DeferredWorld,
HookContext {
entity,
Expand All @@ -169,27 +171,20 @@ impl Relationship for ColliderOf {
if let Ok(mut body_mut) = world.get_entity_mut(body)
&& let Some(mut relationship_target) = body_mut.get_mut::<Self::RelationshipTarget>()
{
RelationshipSourceCollection::remove(
relationship_target.collection_mut_risky(),
entity,
);
if relationship_target.is_empty()
&& let Ok(mut entity) = world.commands().get_entity(body)
{
// this "remove" operation must check emptiness because in the event that an identical
// relationship is inserted on top, this despawn would result in the removal of that identical
// relationship ... not what we want!
entity.queue_handled(
|mut entity: EntityWorldMut| {
if entity
.get::<Self::RelationshipTarget>()
.is_some_and(RelationshipTarget::is_empty)
{
entity.remove::<Self::RelationshipTarget>();
}
},
|_, _| {},
);
RelationshipSourceCollection::remove(relationship_target.collection_mut_risky(), entity);
if relationship_target.len() == 0 {
let command = |mut entity: EntityWorldMut| {
if entity
.get::<Self::RelationshipTarget>()
.is_some_and(RelationshipTarget::is_empty)
{
entity.remove::<Self::RelationshipTarget>();
}
};

world
.commands()
.queue_silenced(command.with_entity(body));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collider/parry/contact_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn contact_manifolds(
prediction_distance,
)
{
let normal = rotation1 * contact.normal1;
let normal: Vector = rotation1 * contact.normal1;

// Make sure the normal is valid
if !normal.is_normalized() {
Expand Down
39 changes: 28 additions & 11 deletions src/collision/collider/parry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,8 @@ impl Collider {
/// defined by its vertex and index buffers.
#[cfg(feature = "3d")]
pub fn convex_decomposition(vertices: Vec<Vector>, indices: Vec<[u32; 3]>) -> Self {
SharedShape::convex_decomposition(&vertices, &indices).into()
let pv = vertices;
SharedShape::convex_decomposition(&pv, &indices).into()
}

/// Creates a collider shape with a compound shape obtained from the decomposition of a given polyline
Expand All @@ -975,7 +976,8 @@ impl Collider {
indices: Vec<[u32; 3]>,
params: VhacdParameters,
) -> Self {
SharedShape::convex_decomposition_with_params(&vertices, &indices, &params.clone().into())
let pv = vertices;
SharedShape::convex_decomposition_with_params(&pv, &indices, &params.clone().into())
.into()
}

Expand All @@ -990,7 +992,8 @@ impl Collider {
/// the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of the given points.
#[cfg(feature = "3d")]
pub fn convex_hull(points: Vec<Vector>) -> Option<Self> {
SharedShape::convex_hull(&points).map(Into::into)
let pv = points;
SharedShape::convex_hull(&pv).map(Into::into)
}

/// Creates a collider with a [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) shape **without** computing
Expand All @@ -1015,6 +1018,8 @@ impl Collider {
.iter()
.map(|c| c.as_i64vec3())
.collect::<Vec<_>>();
#[cfg(all(feature = "3d", not(feature = "f64")))]
let grid_coordinates = &grid_coordinates;
let shape = Voxels::new(voxel_size, grid_coordinates);
SharedShape::new(shape).into()
}
Expand All @@ -1023,7 +1028,8 @@ impl Collider {
///
/// Each voxel has the size `voxel_size` and contains at least one point from `points`.
pub fn voxels_from_points(voxel_size: Vector, points: &[Vector]) -> Self {
SharedShape::voxels_from_points(voxel_size, points).into()
let pp = points;
SharedShape::voxels_from_points(voxel_size, &pp).into()
}

/// Creates a voxel collider obtained from the decomposition of the given polyline into voxelized convex parts.
Expand All @@ -1045,7 +1051,8 @@ impl Collider {
voxel_size: Scalar,
fill_mode: FillMode,
) -> Self {
SharedShape::voxelized_mesh(vertices, indices, voxel_size, fill_mode.into()).into()
let pv = vertices;
SharedShape::voxelized_mesh(&pv, indices, voxel_size, fill_mode.into()).into()
}

/// Creates a voxel collider obtained from the decomposition of the given `Mesh` into voxelized convex parts.
Expand All @@ -1058,7 +1065,8 @@ impl Collider {
fill_mode: FillMode,
) -> Option<Self> {
extract_mesh_vertices_indices(mesh).map(|(vertices, indices)| {
SharedShape::voxelized_mesh(&vertices, &indices, voxel_size, fill_mode.into()).into()
let pv = &vertices;
SharedShape::voxelized_mesh(&pv, &indices, voxel_size, fill_mode.into()).into()
})
}

Expand Down Expand Up @@ -1094,8 +1102,9 @@ impl Collider {
indices: &[[u32; DIM]],
parameters: &VhacdParameters,
) -> Vec<Self> {
let pv = vertices;
SharedShape::voxelized_convex_decomposition_with_params(
vertices,
&pv,
indices,
&parameters.clone().into(),
)
Expand Down Expand Up @@ -1242,7 +1251,10 @@ impl Collider {
#[cfg(feature = "collider-from-mesh")]
pub fn convex_hull_from_mesh(mesh: &Mesh) -> Option<Self> {
extract_mesh_vertices_indices(mesh)
.and_then(|(vertices, _)| SharedShape::convex_hull(&vertices).map(|shape| shape.into()))
.and_then(|(vertices, _)| {
let pv = vertices;
SharedShape::convex_hull(&pv).map(|shape| shape.into())
})
}

/// Creates a compound shape obtained from the decomposition of a `Mesh`.
Expand All @@ -1264,7 +1276,8 @@ impl Collider {
#[cfg(feature = "collider-from-mesh")]
pub fn convex_decomposition_from_mesh(mesh: &Mesh) -> Option<Self> {
extract_mesh_vertices_indices(mesh).map(|(vertices, indices)| {
SharedShape::convex_decomposition(&vertices, &indices).into()
let pv = vertices;
SharedShape::convex_decomposition(&pv, &indices).into()
})
}

Expand Down Expand Up @@ -1295,8 +1308,9 @@ impl Collider {
parameters: &VhacdParameters,
) -> Option<Self> {
extract_mesh_vertices_indices(mesh).map(|(vertices, indices)| {
let pv = vertices;
SharedShape::convex_decomposition_with_params(
&vertices,
&pv,
&indices,
&parameters.clone().into(),
)
Expand Down Expand Up @@ -1690,7 +1704,10 @@ fn scale_shape(
));
#[cfg(feature = "3d")]
scaled.push((
make_pose(pose.translation * scale, pose.rotation),
make_pose(
pose.translation * scale,
Rotation(pose.rotation),
),
scale_shape(shape, scale, num_subdivisions)?,
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/collision/narrow_phase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn trigger_collision_events(
mut started: Local<Vec<CollisionStart>>,
mut ended: Local<Vec<CollisionEnd>>,
) {
let mut state = state.get_mut(world);
let mut state = state.get_mut(world).unwrap();

// Collect `CollisionStart` events.
for event in state.started.read() {
Expand Down
3 changes: 2 additions & 1 deletion src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub use total::{PhysicsTotalDiagnostics, PhysicsTotalDiagnosticsPlugin};
use crate::{PhysicsStepSystems, schedule::PhysicsSchedule};
use bevy::{
diagnostic::DiagnosticPath,
ecs::component::Mutable,
prelude::{App, IntoScheduleConfigs, ResMut, Resource, SystemSet},
};
#[cfg(feature = "bevy_diagnostic")]
Expand Down Expand Up @@ -127,7 +128,7 @@ pub enum PhysicsDiagnosticsSystems {
}

/// A trait for resources storing timers and counters for [physics diagnostics](crate::diagnostics).
pub trait PhysicsDiagnostics: Default + Resource {
pub trait PhysicsDiagnostics: Default + Resource<Mutability = Mutable> {
/// Maps diagnostic paths to their respective duration fields.
fn timer_paths(&self) -> Vec<(&'static DiagnosticPath, Duration)> {
Vec::new()
Expand Down
Loading
Loading