Struct bevy_rapier2d::plugin::RapierContext

source ·
pub struct RapierContext {
    pub islands: IslandManager,
    pub broad_phase: DefaultBroadPhase,
    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: DefaultBroadPhase

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§

source§

impl RapierContext

source

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.

source

pub fn rigid_body_colliders( &self, entity: Entity ) -> impl Iterator<Item = Entity> + '_

If entity is a rigid-body, this returns the collider Entitys attached to that rigid-body.

source

pub fn collider_entity(&self, handle: ColliderHandle) -> Option<Entity>

Retrieve the Bevy entity the given Rapier collider (identified by its handle) is attached.

source

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.

source

pub fn with_query_filter<T>( &self, filter: QueryFilter<'_>, f: impl FnOnce(RapierQueryFilter<'_>) -> T ) -> T

Calls the closure f once after converting the given QueryFilter into a raw rapier::QueryFilter.

source

pub fn with_query_filter_elts<T>( entity2collider: &HashMap<Entity, ColliderHandle>, entity2body: &HashMap<Entity, RigidBodyHandle>, colliders: &ColliderSet, filter: QueryFilter<'_>, f: impl FnOnce(RapierQueryFilter<'_>) -> T ) -> T

Without borrowing the RapierContext, calls the closure f once after converting the given QueryFilter into a raw rapier::QueryFilter.

source

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.

source

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.

source

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().

source

pub fn entity2body(&self) -> &HashMap<Entity, RigidBodyHandle>

The map from entities to rigid-body handles.

source

pub fn entity2collider(&self) -> &HashMap<Entity, ColliderHandle>

The map from entities to collider handles.

source

pub fn entity2impulse_joint(&self) -> &HashMap<Entity, ImpulseJointHandle>

The map from entities to impulse joint handles.

source

pub fn entity2multibody_joint(&self) -> &HashMap<Entity, MultibodyJointHandle>

The map from entities to multibody joint handles.

source

pub fn move_shape( &mut self, movement: Vect, shape: &Collider, shape_translation: Vect, shape_rotation: Rot, shape_mass: Real, options: &MoveShapeOptions, filter: QueryFilter<'_>, events: impl FnMut(CharacterCollision) ) -> MoveShapeOutput

Attempts to move shape, optionally sliding or climbing obstacles.

§Parameters
  • movement: the translational movement to apply.
  • shape: the shape to move.
  • shape_translation: the initial position of the shape.
  • shape_rotation: the rotation of the shape.
  • shape_mass: the mass of the shape to be considered by the impulse calculation if MoveShapeOptions::apply_impulse_to_dynamic_bodies is set to true.
  • options: configures the behavior of the automatic sliding and climbing.
  • filter: indicates what collider or rigid-body needs to be ignored by the obstacle detection.
  • events: callback run on each obstacle hit by the shape on its path.
source

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 to ray.dir.norm() * max_toi. Use Real::MAX for an unbounded ray.
  • solid: if this is true an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If this false 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.
source

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 to ray.dir.norm() * max_toi. Use Real::MAX for an unbounded ray.
  • solid: if this is true an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If this false 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.
source

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 to ray.dir.norm() * max_toi. Use Real::MAX for an unbounded ray.
  • solid: if this is true an impact at time 0.0 (i.e. at the ray origin) is returned if it starts inside of a shape. If this false 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 returns false, this method will exit early, ignore any further raycast.
source

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.
source

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 to true 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 to false 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.
source

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 the point. If this callback returns false, this method will exit early, ignore any further point projection.
source

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 to true 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 to false 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.
source

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.

source

pub fn cast_shape( &self, shape_pos: Vect, shape_rot: Rot, shape_vel: Vect, shape: &Collider, options: ShapeCastOptions, filter: QueryFilter<'_> ) -> Option<(Entity, ShapeCastHit)>

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 ShapeCastHit, witness and normal 1 refer to the world collider, and are in world space.

§Parameters
  • shape_pos - The initial translation of the shape to cast.
  • shape_rot - The rotation 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 to shapeVel.norm() * maxToi.
  • stop_at_penetration - If the casted shape starts in a penetration state with any collider, two results are possible. If stop_at_penetration is true then, the result will have a toi equal to start_time. If stop_at_penetration is false then the nonlinear shape-casting will see if further motion wrt. the penetration normal would result in tunnelling. If it does not (i.e. we have a separating velocity along that normal) then the nonlinear shape-casting will attempt to find another impact, at a time > start_time that could result in tunnelling.
  • filter: set of rules used to determine which collider is taken into account by this scene query.
source

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 the shape.
source§

impl RapierContext

source

pub fn contact_pairs_with( &self, collider: Entity ) -> impl Iterator<Item = ContactPairView<'_>>

All the contact pairs involving the non-sensor collider attached to the given entity.

The returned contact pairs identify pairs of colliders with intersecting bounding-volumes. To check if any geometric contact happened between the collider shapes, check [ContactPairView::has_any_active_contact].

source

pub fn intersection_pairs_with( &self, collider: Entity ) -> impl Iterator<Item = (Entity, Entity, bool)> + '_

All the intersection pairs involving the collider attached to the given entity, where at least one collider involved in the intersection is a sensor.

The returned contact pairs identify pairs of colliders (where at least one is a sensor) with intersecting bounding-volumes. To check if any geometric overlap happened between the collider shapes, check the returned boolean.

source

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.

source

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.

source

pub fn contact_pairs(&self) -> impl Iterator<Item = ContactPairView<'_>>

All the contact pairs detected during the last timestep.

source

pub fn intersection_pairs( &self ) -> impl Iterator<Item = (Entity, Entity, bool)> + '_

All the intersection pairs detected during the last timestep.

Trait Implementations§

source§

impl Default for RapierContext

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for RapierContext

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for RapierContext

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Resource for RapierContext
where Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

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.
source§

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.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromWorld for T
where T: Default,

source§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer ) -> Result<(), ErrorImpl>

source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Settings for T
where T: 'static + Send + Sync,

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,