bevy_rapier3d/dynamics/
joint.rs1use bevy::prelude::*;
2use rapier::dynamics::{ImpulseJointHandle, MultibodyJointHandle};
3
4pub use rapier::dynamics::{JointAxesMask, JointAxis, MotorModel};
5
6use super::{FixedJoint, GenericJoint, PrismaticJoint, RevoluteJoint, RopeJoint, SpringJoint};
7
8#[cfg(feature = "dim3")]
9use super::SphericalJoint;
10
11#[derive(Clone, Copy, Debug, PartialEq)]
13pub enum TypedJoint {
14 FixedJoint(FixedJoint),
16 GenericJoint(GenericJoint),
18 PrismaticJoint(PrismaticJoint),
20 RevoluteJoint(RevoluteJoint),
22 RopeJoint(RopeJoint),
24 #[cfg(feature = "dim3")]
26 SphericalJoint(SphericalJoint),
27 SpringJoint(SpringJoint),
29}
30
31impl AsMut<GenericJoint> for TypedJoint {
32 fn as_mut(&mut self) -> &mut GenericJoint {
33 match self {
34 TypedJoint::FixedJoint(ref mut j) => &mut j.data,
35 TypedJoint::GenericJoint(ref mut j) => j,
36 TypedJoint::PrismaticJoint(ref mut j) => &mut j.data,
37 TypedJoint::RevoluteJoint(ref mut j) => &mut j.data,
38 TypedJoint::RopeJoint(ref mut j) => &mut j.data,
39 #[cfg(feature = "dim3")]
40 TypedJoint::SphericalJoint(ref mut j) => &mut j.data,
41 TypedJoint::SpringJoint(ref mut j) => &mut j.data,
42 }
43 }
44}
45
46impl AsRef<GenericJoint> for TypedJoint {
47 fn as_ref(&self) -> &GenericJoint {
48 match self {
49 TypedJoint::FixedJoint(j) => &j.data,
50 TypedJoint::GenericJoint(j) => j,
51 TypedJoint::PrismaticJoint(j) => &j.data,
52 TypedJoint::RevoluteJoint(j) => &j.data,
53 TypedJoint::RopeJoint(j) => &j.data,
54 #[cfg(feature = "dim3")]
55 TypedJoint::SphericalJoint(j) => &j.data,
56 TypedJoint::SpringJoint(j) => &j.data,
57 }
58 }
59}
60
61#[derive(Copy, Clone, Debug, Component)]
63pub struct RapierImpulseJointHandle(pub ImpulseJointHandle);
64
65#[derive(Copy, Clone, Debug, Component)]
67pub struct RapierMultibodyJointHandle(pub MultibodyJointHandle);
68
69#[derive(Copy, Clone, Debug, PartialEq, Component)]
81pub struct ImpulseJoint {
82 pub parent: Entity,
84 pub data: TypedJoint,
86}
87
88impl ImpulseJoint {
89 pub fn new(parent: Entity, data: impl Into<TypedJoint>) -> Self {
91 Self {
92 parent,
93 data: data.into(),
94 }
95 }
96}
97
98#[derive(Copy, Clone, Debug, PartialEq, Component)]
108pub struct MultibodyJoint {
109 pub parent: Entity,
111 pub data: TypedJoint,
113}
114
115impl MultibodyJoint {
116 pub fn new(parent: Entity, data: TypedJoint) -> Self {
119 Self { parent, data }
120 }
121}