Struct bevy_rapier2d::plugin::RapierContext
source · [−]pub struct RapierContext {
pub islands: IslandManager,
pub broad_phase: BroadPhase,
pub narrow_phase: NarrowPhase,
pub bodies: RigidBodySet,
pub colliders: ColliderSet,
pub impulse_joints: ImpulseJointSet,
pub multibody_joints: MultibodyJointSet,
pub ccd_solver: CCDSolver,
pub pipeline: PhysicsPipeline,
pub query_pipeline: QueryPipeline,
pub integration_parameters: IntegrationParameters,
/* private fields */
}
Expand description
The Rapier context, containing all the state of the physics engine.
Fields
islands: IslandManager
The island manager, which detects what object is sleeping (not moving much) to reduce computations.
broad_phase: BroadPhase
The broad-phase, which detects potential contact pairs.
narrow_phase: NarrowPhase
The narrow-phase, which computes contact points, tests intersections, and maintain the contact and intersection graphs.
bodies: RigidBodySet
The set of rigid-bodies part of the simulation.
colliders: ColliderSet
The set of colliders part of the simulation.
impulse_joints: ImpulseJointSet
The set of impulse joints part of the simulation.
multibody_joints: MultibodyJointSet
The set of multibody joints part of the simulation.
ccd_solver: CCDSolver
The solver, which handles Continuous Collision Detection (CCD).
pipeline: PhysicsPipeline
The physics pipeline, which advance the simulation step by step.
query_pipeline: QueryPipeline
The query pipeline, which performs scene queries (ray-casting, point projection, etc.)
integration_parameters: IntegrationParameters
The integration parameters, controlling various low-level coefficient of the simulation.
Implementations
sourceimpl RapierContext
impl RapierContext
sourcepub fn collider_parent(&self, entity: Entity) -> Option<Entity>
pub fn collider_parent(&self, entity: Entity) -> Option<Entity>
If the collider attached to entity
is attached to a rigid-body, this
returns the Entity
containing that rigid-body.
sourcepub fn collider_entity(&self, handle: ColliderHandle) -> Option<Entity>
pub fn collider_entity(&self, handle: ColliderHandle) -> Option<Entity>
Retrieve the Bevy entity the given Rapier collider (identified by its handle) is attached.
sourcepub fn rigid_body_entity(&self, handle: RigidBodyHandle) -> Option<Entity>
pub fn rigid_body_entity(&self, handle: RigidBodyHandle) -> Option<Entity>
Retrieve the Bevy entity the given Rapier rigid-body (identified by its handle) is attached.
sourcepub fn step_simulation(
&mut self,
gravity: Vect,
timestep_mode: TimestepMode,
events: Option<(EventWriter<'_, '_, CollisionEvent>, EventWriter<'_, '_, ContactForceEvent>)>,
hooks: &dyn PhysicsHooks,
time: &Time,
sim_to_render_time: &mut SimulationToRenderTime,
interpolation_query: Option<Query<'_, '_, (&RapierRigidBodyHandle, &mut TransformInterpolation)>>
)
pub fn step_simulation(
&mut self,
gravity: Vect,
timestep_mode: TimestepMode,
events: Option<(EventWriter<'_, '_, CollisionEvent>, EventWriter<'_, '_, ContactForceEvent>)>,
hooks: &dyn PhysicsHooks,
time: &Time,
sim_to_render_time: &mut SimulationToRenderTime,
interpolation_query: Option<Query<'_, '_, (&RapierRigidBodyHandle, &mut TransformInterpolation)>>
)
Advance the simulation, based on the given timestep mode.
sourcepub fn propagate_modified_body_positions_to_colliders(&mut self)
pub fn propagate_modified_body_positions_to_colliders(&mut self)
This method makes sure tha the rigid-body positions have been propagated to their attached colliders, without having to perform a srimulation step.
sourcepub fn update_query_pipeline(&mut self)
pub fn update_query_pipeline(&mut self)
Updates the state of the query pipeline, based on the collider positions known
from the last timestep or the last call to self.propagate_modified_body_positions_to_colliders()
.
sourcepub fn entity2body(&self) -> &HashMap<Entity, RigidBodyHandle>
pub fn entity2body(&self) -> &HashMap<Entity, RigidBodyHandle>
The map from entities to rigid-body handles.
sourcepub fn entity2collider(&self) -> &HashMap<Entity, ColliderHandle>
pub fn entity2collider(&self) -> &HashMap<Entity, ColliderHandle>
The map from entities to collider handles.
sourcepub fn entity2impulse_joint(&self) -> &HashMap<Entity, ImpulseJointHandle>
pub fn entity2impulse_joint(&self) -> &HashMap<Entity, ImpulseJointHandle>
The map from entities to impulse joint handles.
sourcepub fn entity2multibody_joint(&self) -> &HashMap<Entity, MultibodyJointHandle>
pub fn entity2multibody_joint(&self) -> &HashMap<Entity, MultibodyJointHandle>
The map from entities to multibody joint handles.
sourcepub fn cast_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, Real)>
pub fn cast_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, Real)>
Find the closest intersection between a ray and a set of collider.
Parameters
ray_origin
: the starting point of the ray to cast.ray_dir
: the direction of the ray to cast.max_toi
: the maximum time-of-impact that can be reported by this cast. This effectively limits the length of the ray toray.dir.norm() * max_toi
. UseReal::MAX
for an unbounded ray.solid
: if this istrue
an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If thisfalse
then the ray will hit the shape’s boundary even if its starts inside of it.filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn cast_ray_and_get_normal(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, RayIntersection)>
pub fn cast_ray_and_get_normal(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, RayIntersection)>
Find the closest intersection between a ray and a set of collider.
Parameters
ray_origin
: the starting point of the ray to cast.ray_dir
: the direction of the ray to cast.max_toi
: the maximum time-of-impact that can be reported by this cast. This effectively limits the length of the ray toray.dir.norm() * max_toi
. UseReal::MAX
for an unbounded ray.solid
: if this istrue
an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If thisfalse
then the ray will hit the shape’s boundary even if its starts inside of it.filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn intersections_with_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity, RayIntersection) -> bool
)
pub fn intersections_with_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_toi: Real,
solid: bool,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity, RayIntersection) -> bool
)
Find the all intersections between a ray and a set of collider and passes them to a callback.
Parameters
ray_origin
: the starting point of the ray to cast.ray_dir
: the direction of the ray to cast.max_toi
: the maximum time-of-impact that can be reported by this cast. This effectively limits the length of the ray toray.dir.norm() * max_toi
. UseReal::MAX
for an unbounded ray.solid
: if this istrue
an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If thisfalse
then the ray will hit the shape’s boundary even if its starts inside of it.filter
: set of rules used to determine which collider is taken into account by this scene query.callback
: function executed on each collider for which a ray intersection has been found. There is no guarantees on the order the results will be yielded. If this callback returnsfalse
, this method will exit early, ignore any further raycast.
sourcepub fn intersection_with_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape: &Collider,
filter: QueryFilter<'_>
) -> Option<Entity>
pub fn intersection_with_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape: &Collider,
filter: QueryFilter<'_>
) -> Option<Entity>
Gets the handle of up to one collider intersecting the given shape.
Parameters
shape_pos
- The position of the shape used for the intersection test.shape
- The shape used for the intersection test.filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn project_point(
&self,
point: Vect,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, PointProjection)>
pub fn project_point(
&self,
point: Vect,
solid: bool,
filter: QueryFilter<'_>
) -> Option<(Entity, PointProjection)>
Find the projection of a point on the closest collider.
Parameters
point
- The point to project.solid
- If this is set totrue
then the collider shapes are considered to be plain (if the point is located inside of a plain shape, its projection is the point itself). If it is set tofalse
the collider shapes are considered to be hollow (if the point is located inside of an hollow shape, it is projected on the shape’s boundary).filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn intersections_with_point(
&self,
point: Vect,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity) -> bool
)
pub fn intersections_with_point(
&self,
point: Vect,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity) -> bool
)
Find all the colliders containing the given point.
Parameters
point
- The point used for the containment test.filter
: set of rules used to determine which collider is taken into account by this scene query.callback
- A function called with each collider with a shape containing thepoint
. If this callback returnsfalse
, this method will exit early, ignore any further point projection.
sourcepub fn project_point_and_get_feature(
&self,
point: Vect,
filter: QueryFilter<'_>
) -> Option<(Entity, PointProjection, FeatureId)>
pub fn project_point_and_get_feature(
&self,
point: Vect,
filter: QueryFilter<'_>
) -> Option<(Entity, PointProjection, FeatureId)>
Find the projection of a point on the closest collider.
The results include the ID of the feature hit by the point.
Parameters
point
- The point to project.solid
- If this is set totrue
then the collider shapes are considered to be plain (if the point is located inside of a plain shape, its projection is the point itself). If it is set tofalse
the collider shapes are considered to be hollow (if the point is located inside of an hollow shape, it is projected on the shape’s boundary).filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn colliders_with_aabb_intersecting_aabb(
&self,
aabb: Aabb,
callback: impl FnMut(Entity) -> bool
)
pub fn colliders_with_aabb_intersecting_aabb(
&self,
aabb: Aabb,
callback: impl FnMut(Entity) -> bool
)
Finds all entities of all the colliders with an AABB intersecting the given AABB.
sourcepub fn cast_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape_vel: Vect,
shape: &Collider,
max_toi: Real,
filter: QueryFilter<'_>
) -> Option<(Entity, Toi)>
pub fn cast_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape_vel: Vect,
shape: &Collider,
max_toi: Real,
filter: QueryFilter<'_>
) -> Option<(Entity, Toi)>
Casts a shape at a constant linear velocity and retrieve the first collider it hits.
This is similar to ray-casting except that we are casting a whole shape instead of just a
point (the ray origin). In the resulting TOI
, witness and normal 1 refer to the world
collider, and are in world space.
Parameters
shape_pos
- The initial position of the shape to cast.shape_vel
- The constant velocity of the shape to cast (i.e. the cast direction).shape
- The shape to cast.max_toi
- The maximum time-of-impact that can be reported by this cast. This effectively limits the distance traveled by the shape toshapeVel.norm() * maxToi
.filter
: set of rules used to determine which collider is taken into account by this scene query.
sourcepub fn intersections_with_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape: &Collider,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity) -> bool
)
pub fn intersections_with_shape(
&self,
shape_pos: Vect,
shape_rot: Rot,
shape: &Collider,
filter: QueryFilter<'_>,
callback: impl FnMut(Entity) -> bool
)
Retrieve all the colliders intersecting the given shape.
Parameters
shapePos
- The position of the shape to test.shapeRot
- The orientation of the shape to test.shape
- The shape to test.filter
: set of rules used to determine which collider is taken into account by this scene query.callback
- A function called with the entities of each collider intersecting theshape
.
sourceimpl RapierContext
impl RapierContext
sourcepub fn contacts_with(
&self,
collider: Entity
) -> impl Iterator<Item = ContactPairView<'_>>
pub fn contacts_with(
&self,
collider: Entity
) -> impl Iterator<Item = ContactPairView<'_>>
All the contacts involving the non-sensor collider attached to the given entity.
sourcepub fn intersections_with(
&self,
collider: Entity
) -> impl Iterator<Item = (Entity, Entity, bool)> + '_
pub fn intersections_with(
&self,
collider: Entity
) -> impl Iterator<Item = (Entity, Entity, bool)> + '_
All the intersections involving the collider attached to the given entity.
Intersections between two colliders are reported only if at least one of them is a sensor.
sourcepub fn contact_pair(
&self,
collider1: Entity,
collider2: Entity
) -> Option<ContactPairView<'_>>
pub fn contact_pair(
&self,
collider1: Entity,
collider2: Entity
) -> Option<ContactPairView<'_>>
The contact pair involving two specific colliders.
If this returns None
, there is no contact between the two colliders.
If this returns Some
, then there may be a contact between the two colliders. Check the
result [ContactPair::has_any_active_collider
] method to see if there is an actual contact.
sourcepub fn intersection_pair(
&self,
collider1: Entity,
collider2: Entity
) -> Option<bool>
pub fn intersection_pair(
&self,
collider1: Entity,
collider2: Entity
) -> Option<bool>
The intersection pair involving two specific colliders (at least one being a sensor).
If this returns None
or Some(false)
, then there is no intersection between the two colliders.
If this returns Some(true)
, then there may be an intersection between the two colliders.
sourcepub fn contact_pairs(&self) -> impl Iterator<Item = ContactPairView<'_>>
pub fn contact_pairs(&self) -> impl Iterator<Item = ContactPairView<'_>>
All the contact pairs detected during the last timestep.
sourcepub fn intersection_pairs(
&self
) -> impl Iterator<Item = (Entity, Entity, bool)> + '_
pub fn intersection_pairs(
&self
) -> impl Iterator<Item = (Entity, Entity, bool)> + '_
All the intersection pairs detected during the last timestep.
Trait Implementations
sourceimpl Default for RapierContext
impl Default for RapierContext
sourceimpl<'de> Deserialize<'de> for RapierContext
impl<'de> Deserialize<'de> for RapierContext
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for RapierContext
impl Serialize for RapierContext
Auto Trait Implementations
impl !RefUnwindSafe for RapierContext
impl Send for RapierContext
impl Sync for RapierContext
impl Unpin for RapierContext
impl !UnwindSafe for RapierContext
Blanket Implementations
impl<T, U> AsBindGroupShaderType<U> for T where
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for T where
U: ShaderType,
&'a T: for<'a> Into<U>,
fn as_bind_group_shader_type(
&self,
_images: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
fn as_bind_group_shader_type(
&self,
_images: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
Return the T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> FromWorld for T where
T: Default,
impl<T> FromWorld for T where
T: Default,
fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using data from the given [World]
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> Serialize for T where
T: Serialize + ?Sized,
impl<T> Serialize for T where
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more