rapier 0.20 feature: RevoluteJoint::angle + more detailed joints enum#530
Merged
ThierryBerger merged 16 commits intodimforge:masterfrom Jul 7, 2024
Merged
Conversation
…ded from rapier 0.20.
ThierryBerger
commented
Jun 21, 2024
…ecify a lot of systems/filters the generic path could be interesting when/if bevy supports trait queries, but currently I feel it's not worth it.
ThierryBerger
commented
Jul 4, 2024
sebcrozet
reviewed
Jul 5, 2024
src/dynamics/joint.rs
Outdated
Comment on lines
31
to
58
| impl JointDescription { | ||
| /// The underlying generic joint. | ||
| pub fn generic_joint(&self) -> &GenericJoint { | ||
| match self { | ||
| JointDescription::FixedJoint(j) => &j.data, | ||
| JointDescription::GenericJoint(j) => j, | ||
| JointDescription::PrismaticJoint(j) => &j.data, | ||
| JointDescription::RevoluteJoint(j) => j.data(), | ||
| JointDescription::RopeJoint(j) => j.data(), | ||
| #[cfg(feature = "dim3")] | ||
| JointDescription::SphericalJoint(j) => j.data(), | ||
| JointDescription::SpringJoint(j) => j.data(), | ||
| } | ||
| } | ||
| /// The underlying generic joint. | ||
| pub fn generic_joint_mut(&mut self) -> &mut GenericJoint { | ||
| match self { | ||
| JointDescription::FixedJoint(ref mut j) => &mut j.data, | ||
| JointDescription::GenericJoint(ref mut j) => j, | ||
| JointDescription::PrismaticJoint(ref mut j) => &mut j.data, | ||
| JointDescription::RevoluteJoint(ref mut j) => &mut j.data, | ||
| JointDescription::RopeJoint(ref mut j) => &mut j.data, | ||
| #[cfg(feature = "dim3")] | ||
| JointDescription::SphericalJoint(ref mut j) => &mut j.data, | ||
| JointDescription::SpringJoint(ref mut j) => &mut j.data, | ||
| } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
These could be AsRef/AsMut implementations instead.
Contributor
Author
There was a problem hiding this comment.
true, I'll do that.
For the story behind this explicit naming: ideally I would have liked to wrap our joints (bevy_rapier::FixedJoint, etc...) around the correct joint from rapier (rapier::FixedJoint, etc.), so a user could use the relevant functions from rapier if some functions were not exposed by bevy_rapier (it can easily be forgotten...), but I had difficulties, probably the builder had to be updated significantly so I dropped the idea.
See #529 for similar reasoning logic.
Co-authored-by: Sébastien Crozet <sebastien@crozet.re>
RevoluteJoint::angleRevoluteJoint::angle + more detailed joints enum
ThierryBerger
commented
Jul 5, 2024
sebcrozet
approved these changes
Jul 7, 2024
Co-authored-by: Sébastien Crozet <sebastien@crozet.re>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add helper method to get the angle of a revolute joint ; from rapier 0.20.
We noticed a bug on joints because of rapier 0.20, so this builds up on #547.
I wanted to take the
ImpulseJointSetas parameter but that doesn't work withMultibodyJointSetso I settled to pass rigidbodies.I tried to implement a Generic
ImpulseJoint<JointDescription>, but that proved very impractical for functions such assync removal. we could revisit that if one day bevy supports trait queries, but currently I feel it's not worth it.Because we need both
ImpulseJointandRevoluteJointfromRapierContext, I couldn't settle on a better place thanRapierContextfor thisangle_for_entity_impulse_revolute_jointfunction.Failed improvements
I would have liked to make it more typed, but that's the best I could do.
I think it boils down to
bevy_rapier::ImpulseJointnot exposing directlybody1andbody2, which are necessary to compute the angle. I imagine it's current entity +bevy_rapier::ImpulseJoint::parent, but I went the route to get the data from rapier directly, it doesn't complicate the public facing API.I feel a method
angle(entity, entity)would only be more difficult to follow invariants.