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

Rapier context component #22

Draft
wants to merge 51 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d4ff57e
working rapierContext as component, but not ideal API.
Vrixyz Jun 25, 2024
3cb7676
systemparam exploration
Vrixyz Jun 25, 2024
a01395e
RapierContextEntityLink to know which RapierContext is referred to
Vrixyz Jun 25, 2024
4e7c36c
more rapierContext conf + broken events -> added a test which should …
Vrixyz Jun 25, 2024
4952ea5
fix events test
Vrixyz Jun 26, 2024
7a4ba5e
better support for multi world
Vrixyz Jun 26, 2024
24fd036
multiple worlds working + example
Vrixyz Jun 26, 2024
f900dac
progress multi world with change
Vrixyz Jun 27, 2024
d171fe4
cargo clippy + pr feedbacks
Vrixyz Jul 1, 2024
8dd49ee
less unwraps
Vrixyz Jul 2, 2024
2b262ea
ci without debug symbols
Vrixyz Jul 2, 2024
f849cd2
more tests + logs + better changelog
Vrixyz Jul 2, 2024
df3578e
more error logs in case of no rapier context
Vrixyz Jul 2, 2024
09d6f9d
Update dependencies to rapier 0.21 (#547)
Vrixyz Jul 3, 2024
9abe4c3
Added 'realistic' test for events (#544)
Vrixyz Jul 4, 2024
ac16f38
Merge remote-tracking branch 'upstream' into RapierContext_Component
Vrixyz Jul 4, 2024
941b52e
fix conflict
Vrixyz Jul 4, 2024
5669a8c
fix unwrap
Vrixyz Jul 4, 2024
0b9ca86
fix warning
Vrixyz Jul 4, 2024
f97027d
update dependencies to bevy 0.14 (#556)
Vrixyz Jul 5, 2024
f4643ef
address pr feedback
Vrixyz Jul 5, 2024
ecdacfd
Fix some cargo doc warnings + add cargo doc ci (#557)
Vrixyz Jul 7, 2024
84c776e
rapier 0.20 feature: `RevoluteJoint::angle` + more detailed joints en…
Vrixyz Jul 7, 2024
f17bd5b
chore: Release prep for 0.27.0 (#558)
Vrixyz Jul 7, 2024
f8b296a
address pr feedback
Vrixyz Jul 8, 2024
0e46610
Merge branch 'master' into RapierContext_Component
Vrixyz Jul 8, 2024
75c2195
fixed compilation
Vrixyz Jul 8, 2024
ccd2be7
fix doc comment
Vrixyz Jul 8, 2024
9142888
fixed joints3 example
Vrixyz Jul 8, 2024
ba0cd76
experiment on stepping to test system ordering and consistent ecs state
Vrixyz Jul 9, 2024
6d10fe6
fix compilation + warning
Vrixyz Jul 10, 2024
d0b07a0
better error handling when rapier context is missing
Vrixyz Jul 10, 2024
2676c35
add a name for rapier context entity
Vrixyz Jul 10, 2024
d190a1c
Add `TriMeshFlags` to `ComputedColliderShape::TriMesh` (#559)
DiSaber Jul 15, 2024
188dcc2
added initial benchmarks, similar to bevy_xpbd (#551)
Vrixyz Jul 18, 2024
3c98610
testbed: allow to select example (#565)
Vrixyz Jul 18, 2024
c6c9bbc
A few doc-link fixes (#562)
Vrixyz Jul 22, 2024
59477d9
Fix a crash when removing colliders in `TimestepMode::Interpolated` …
Vrixyz Jul 23, 2024
40be1f1
Merge branch 'master' into RapierContext_Component
Vrixyz Jul 23, 2024
deb0a06
rename an init function
Vrixyz Jul 23, 2024
cf165bd
apply pr suggestion
Vrixyz Jul 23, 2024
c539f29
update to rapier 0.22 (#568)
Vrixyz Jul 26, 2024
c556052
fix unexpected cfg warning (#573)
Vrixyz Jul 29, 2024
c2bed72
Per entity/collider debug rendering (#278)
barsoosayque Aug 2, 2024
aeab8c9
apply PR suggestions
Vrixyz Aug 12, 2024
07eefbb
Merge branch 'master' into RapierContext_Component
Vrixyz Aug 12, 2024
4cccde1
rename rapier context system params
Vrixyz Aug 12, 2024
cbfe138
fix clippy (+ random typo)
Vrixyz Aug 12, 2024
5dc5b2d
cargo fmt
Vrixyz Aug 12, 2024
030dc61
Fix typos. (#580)
waywardmonkeys Aug 26, 2024
d0961d0
Merge remote-tracking branch 'upstream' into RapierContext_Component
Vrixyz Sep 9, 2024
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
Prev Previous commit
Next Next commit
better error handling when rapier context is missing
  • Loading branch information
Vrixyz committed Jul 10, 2024

Verified

This commit was signed with the committer’s verified signature.
erikmd Erik Martin-Dorel
commit d0b07a06d6c1bf7159367123e6a29910cd151daf
27 changes: 0 additions & 27 deletions src/plugin/context/systemparams/rapier_context_access.rs
Original file line number Diff line number Diff line change
@@ -127,20 +127,6 @@ impl<'w, 's> RapierContextAccessMut<'w, 's> {
self.rapier_context.get_mut(link.0).ok()
}

/// Retrieves the rapier context component on this [`Entity`].
///
/// Calling this method on a rapier managed entity (rigid body, collider, joints...) will fail.
/// Given entity should have a [`RapierContext`].
///
/// SAFETY: This method will panic if its underlying query fails.
pub(crate) fn context_from_entity(
&mut self,
rapier_context_entity: Entity,
) -> Mut<RapierContext> {
self.try_context_from_entity(rapier_context_entity)
.unwrap_or_else(|| panic!("entity {rapier_context_entity} has no RapierContext."))
}

/// Retrieves the rapier context component on this [`Entity`].
///
/// Calling this method on a rapier managed entity (rigid body, collider, joints...) will fail.
@@ -152,16 +138,3 @@ impl<'w, 's> RapierContextAccessMut<'w, 's> {
self.rapier_context.get_mut(rapier_context_entity).ok()
}
}

/// Gets the default RapierContext.
///
/// SAFETY: Panics if no entity with [`DefaultRapierContext`] exist.
pub fn get_single_context(
default_context_access: &Query<Entity, With<DefaultRapierContext>>,
) -> Entity {
default_context_access.get_single().expect(
"No entity with `DefaultRapierContext` found.\
Please add a default `RapierContext` or a `RapierContextEntityLink`\
on the new rapier-managed entity.",
)
}
1 change: 1 addition & 0 deletions src/plugin/plugin.rs
Original file line number Diff line number Diff line change
@@ -304,6 +304,7 @@ pub fn insert_default_world(
RapierContextInitialization::NoAutomaticRapierContext => {}
RapierContextInitialization::InitializeDefaultRapierContext { length_unit } => {
commands.spawn((
Name("Rapier Context"),
RapierContext {
integration_parameters: IntegrationParameters {
length_unit: *length_unit,
27 changes: 17 additions & 10 deletions src/plugin/systems/collider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::dynamics::ReadMassProperties;
use crate::geometry::Collider;
use crate::plugin::context::systemparams::{get_single_context, RapierEntity};
use crate::plugin::context::systemparams::RapierEntity;
use crate::plugin::context::RapierContextEntityLink;
use crate::plugin::{
DefaultRapierContext, RapierConfiguration, RapierContext, RapierContextAccessMut,
@@ -344,15 +344,15 @@ pub fn init_colliders(
mut commands: Commands,
config: Query<&RapierConfiguration>,
mut context_access: RapierContextAccessMut,
default_context: Query<Entity, With<DefaultRapierContext>>,
default_context_access: Query<Entity, With<DefaultRapierContext>>,
colliders: Query<(ColliderComponents, Option<&GlobalTransform>), Without<RapierColliderHandle>>,
mut rigid_body_mprops: Query<&mut ReadMassProperties>,
parent_query: Query<&Parent>,
transform_query: Query<&Transform>,
) {
for (
(
(entity, context_link),
(entity, entity_context_link),
shape,
sensor,
mprops,
@@ -370,22 +370,29 @@ pub fn init_colliders(
global_transform,
) in colliders.iter()
{
let context_entity = context_link.map_or_else(
// Get rapier context from RapierContextEntityLink or insert its default value.
let context_entity = entity_context_link.map_or_else(
|| {
let context_entity = get_single_context(&default_context);
let context_entity = default_context_access.get_single().ok()?;
commands
.entity(entity)
.insert(RapierContextEntityLink(context_entity));
context_entity
Some(context_entity)
},
|link| link.0,
|link| Some(link.0),
);
let context = context_access
.context_from_entity(context_entity)
.into_inner();
let Some(context_entity) = context_entity else {
continue;
};

let config = config.get(context_entity).unwrap_or_else(|_| {
panic!("Failed to retrieve `RapierConfiguration` on entity {context_entity}.")
});
let Some(context) = context_access.try_context_from_entity(context_entity) else {
log::error!("Could not find entity {context_entity} with rapier context while initializing {entity}");
continue;
};
let context = context.into_inner();
let mut scaled_shape = shape.clone();
scaled_shape.set_scale(shape.scale, config.scaled_shape_subdivision);
let mut builder = ColliderBuilder::new(scaled_shape.raw.clone());
41 changes: 27 additions & 14 deletions src/plugin/systems/joint.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ use crate::dynamics::ImpulseJoint;
use crate::dynamics::MultibodyJoint;
use crate::dynamics::RapierImpulseJointHandle;
use crate::dynamics::RapierMultibodyJointHandle;
use crate::plugin::context::systemparams::get_single_context;
use crate::plugin::context::RapierContextEntityLink;
use crate::plugin::DefaultRapierContext;
use crate::plugin::RapierContextAccessMut;
@@ -12,7 +11,7 @@ use bevy::prelude::*;
pub fn init_joints(
mut commands: Commands,
mut context_access: RapierContextAccessMut,
default_context: Query<Entity, With<DefaultRapierContext>>,
default_context_access: Query<Entity, With<DefaultRapierContext>>,
impulse_joints: Query<
(Entity, Option<&RapierContextEntityLink>, &ImpulseJoint),
Without<RapierImpulseJointHandle>,
@@ -24,19 +23,26 @@ pub fn init_joints(
parent_query: Query<&Parent>,
) {
for (entity, entity_context_link, joint) in impulse_joints.iter() {
// Get rapier context from RapierContextEntityLink or insert its default value.
let context_entity = entity_context_link.map_or_else(
|| {
let context_entity = get_single_context(&default_context);
let context_entity = default_context_access.get_single().ok()?;
commands
.entity(entity)
.insert(RapierContextEntityLink(context_entity));
context_entity
Some(context_entity)
},
|link| link.0,
|link| Some(link.0),
);
let context = context_access
.context_from_entity(context_entity)
.into_inner();
let Some(context_entity) = context_entity else {
continue;
};

let Some(context) = context_access.try_context_from_entity(context_entity) else {
log::error!("Could not find entity {context_entity} with rapier context while initializing {entity}");
continue;
};
let context = context.into_inner();
let mut target = None;
let mut body_entity = entity;
while target.is_none() {
@@ -63,19 +69,26 @@ pub fn init_joints(
}

for (entity, entity_context_link, joint) in multibody_joints.iter() {
// Get rapier context from RapierContextEntityLink or insert its default value.
let context_entity = entity_context_link.map_or_else(
|| {
let context_entity = get_single_context(&default_context);
let context_entity = default_context_access.get_single().ok()?;
commands
.entity(entity)
.insert(RapierContextEntityLink(context_entity));
context_entity
Some(context_entity)
},
|link| link.0,
|link| Some(link.0),
);
let context = context_access
.context_from_entity(context_entity)
.into_inner();
let Some(context_entity) = context_entity else {
continue;
};

let Some(context) = context_access.try_context_from_entity(context_entity) else {
log::error!("Could not find entity {context_entity} with rapier context while initializing {entity}");
continue;
};
let context = context.into_inner();
let target = context.entity2body.get(&entity);

if let (Some(target), Some(source)) = (target, context.entity2body.get(&joint.parent)) {