pub struct ColliderTree {
pub bvh: Bvh2,
pub proxies: StableVec<ColliderTreeProxy>,
pub moved_proxies: Vec<ProxyId>,
pub workspace: ColliderTreeWorkspace,
}Expand description
A Bounding Volume Hierarchy (BVH) for accelerating queries on a set of colliders.
See the collider_tree module for more information.
Fields§
§bvh: Bvh2The underlying BVH structure.
proxies: StableVec<ColliderTreeProxy>The proxies stored in the tree.
moved_proxies: Vec<ProxyId>A list of moved proxies since the last update.
This is used during tree optimization to determine which proxies need to be reinserted or rebuilt.
workspace: ColliderTreeWorkspaceA workspace for reusing allocations across tree operations.
Implementations§
Source§impl ColliderTree
impl ColliderTree
Sourcepub fn ray_traverse_closest<F: FnMut(ProxyId) -> Scalar>(
&self,
ray: Ray3d,
max_distance: Scalar,
intersection_fn: F,
) -> Option<(ProxyId, Scalar)>
pub fn ray_traverse_closest<F: FnMut(ProxyId) -> Scalar>( &self, ray: Ray3d, max_distance: Scalar, intersection_fn: F, ) -> Option<(ProxyId, Scalar)>
Traverses the tree for the closest intersection with the given ray.
§Arguments
ray: The ray to be tested for intersection.max_distance: The maximum distance along the ray to consider for intersections.intersection_fn: A function that takes a proxy ID, and returns the distance to the intersection with that proxy. This function is called for each potential intersection found during traversal.
Sourcepub fn ray_traverse_all<F: FnMut(ProxyId) -> bool>(
&self,
ray: Ray3d,
max_distance: Scalar,
intersection_fn: F,
)
pub fn ray_traverse_all<F: FnMut(ProxyId) -> bool>( &self, ray: Ray3d, max_distance: Scalar, intersection_fn: F, )
Traverses the tree for all intersections with the given ray.
Terminates when all intersections within max_distance have been visited or when intersection_fn returns false for an intersection.
§Arguments
ray: The ray to be tested for intersection.max_distance: The maximum distance along the ray to consider for intersections.intersection_fn: A function that takes a proxy ID, and is called for each potential intersection found during traversal. Return false to halt traversal early.
Sourcepub fn sweep_traverse_closest<F: FnMut(ProxyId) -> Scalar>(
&self,
aabb: Aabb,
direction: Dir,
max_distance: Scalar,
target_distance: Scalar,
intersection_fn: F,
) -> Option<(ProxyId, Scalar)>
pub fn sweep_traverse_closest<F: FnMut(ProxyId) -> Scalar>( &self, aabb: Aabb, direction: Dir, max_distance: Scalar, target_distance: Scalar, intersection_fn: F, ) -> Option<(ProxyId, Scalar)>
Traverse the BVH by sweeping an AABB along a velocity vector, returning the closest hit.
§Arguments
aabb: The axis-aligned bounding box to be swept.direction: The direction along which to sweep the AABB.target_distance: The separation distance at which a hit is still considered valid.max_distance: The maximum distance along the sweep to consider for intersections.intersection_fn: A function that takes a proxy ID, and returns the distance to the intersection with that proxy. This function is called for each potential intersection found during traversal.
Sourcepub fn sweep_traverse_all<F: FnMut(ProxyId) -> bool>(
&self,
aabb: Aabb,
direction: Dir,
target_distance: Scalar,
max_distance: Scalar,
intersection_fn: F,
)
pub fn sweep_traverse_all<F: FnMut(ProxyId) -> bool>( &self, aabb: Aabb, direction: Dir, target_distance: Scalar, max_distance: Scalar, intersection_fn: F, )
Traverse the BVH by sweeping an AABB along a velocity vector, calling intersection_fn for each hit.
§Arguments
aabb: The axis-aligned bounding box to be swept.direction: The direction along which to sweep the AABB.target_distance: The separation distance at which a hit is still considered valid.max_distance: The maximum distance along the sweep to consider for intersections.intersection_fn: A function that takes a proxy ID, and is called for each potential intersection found during traversal. Return false to halt traversal early.
Sourcepub fn squared_distance_traverse_closest<F: FnMut(ProxyId) -> Scalar>(
&self,
point: Vector,
max_distance_squared: Scalar,
eval: F,
) -> Option<(ProxyId, Scalar)>
pub fn squared_distance_traverse_closest<F: FnMut(ProxyId) -> Scalar>( &self, point: Vector, max_distance_squared: Scalar, eval: F, ) -> Option<(ProxyId, Scalar)>
Traverse the BVH with a point, returning the closest proxy and its squared distance within max_distance_squared.
§Arguments
point: The point to be tested for proximity.max_distance_squared: The maximum distance from the point to consider for projections.eval: A function that takes a proxy ID and returns the squared distance from the point to that proxy. This function is called for each potential projection found during traversal.
Sourcepub fn point_traverse<F: FnMut(ProxyId) -> bool>(&self, point: Vector, eval: F)
pub fn point_traverse<F: FnMut(ProxyId) -> bool>(&self, point: Vector, eval: F)
Traverse the BVH with a point, calling eval for each intersection.
§Arguments
point: The point to be tested for intersection.eval: A function that takes a proxy ID and is called for each potential intersection found during traversal. Return false to halt traversal early.
Sourcepub fn aabb_traverse<F: FnMut(ProxyId) -> bool>(&self, aabb: Aabb, eval: F)
pub fn aabb_traverse<F: FnMut(ProxyId) -> bool>(&self, aabb: Aabb, eval: F)
Traverse the BVH with an AABB, calling eval for each intersection.
§Arguments
aabb: The axis-aligned bounding box to be tested for intersection.eval: A function that takes a proxy ID and is called for each potential intersection found during traversal. Return false to halt traversal early.
Source§impl ColliderTree
impl ColliderTree
Sourcepub fn add_proxy(&mut self, aabb: Aabb, proxy: ColliderTreeProxy) -> ProxyId
pub fn add_proxy(&mut self, aabb: Aabb, proxy: ColliderTreeProxy) -> ProxyId
Adds a proxy to the tree, returning its index.
Sourcepub fn remove_proxy(&mut self, proxy_id: ProxyId) -> Option<ColliderTreeProxy>
pub fn remove_proxy(&mut self, proxy_id: ProxyId) -> Option<ColliderTreeProxy>
Removes a proxy from the tree.
Returns true if the proxy was successfully removed, or false if the proxy ID was invalid.
Sourcepub fn get_proxy(&self, proxy_id: ProxyId) -> Option<&ColliderTreeProxy>
pub fn get_proxy(&self, proxy_id: ProxyId) -> Option<&ColliderTreeProxy>
Gets a proxy from the tree by its ID.
Returns None if the proxy ID is invalid.
Sourcepub fn get_proxy_mut(
&mut self,
proxy_id: ProxyId,
) -> Option<&mut ColliderTreeProxy>
pub fn get_proxy_mut( &mut self, proxy_id: ProxyId, ) -> Option<&mut ColliderTreeProxy>
Gets a mutable reference to a proxy from the tree by its ID.
Returns None if the proxy ID is invalid.
Sourcepub unsafe fn get_proxy_unchecked(
&self,
proxy_id: ProxyId,
) -> &ColliderTreeProxy
pub unsafe fn get_proxy_unchecked( &self, proxy_id: ProxyId, ) -> &ColliderTreeProxy
Gets a proxy from the tree by its ID without bounds checking.
§Safety
The caller must ensure that the proxy_id is valid.
Sourcepub unsafe fn get_proxy_unchecked_mut(
&mut self,
proxy_id: ProxyId,
) -> &mut ColliderTreeProxy
pub unsafe fn get_proxy_unchecked_mut( &mut self, proxy_id: ProxyId, ) -> &mut ColliderTreeProxy
Gets a mutable reference to a proxy from the tree by its ID without bounds checking.
§Safety
The caller must ensure that the proxy_id is valid.
Sourcepub fn get_proxy_aabb(&self, proxy_id: ProxyId) -> Option<Aabb>
pub fn get_proxy_aabb(&self, proxy_id: ProxyId) -> Option<Aabb>
Gets the AABB of a proxy in the tree.
Returns None if the proxy ID is invalid.
Sourcepub unsafe fn get_proxy_aabb_unchecked(&self, proxy_id: ProxyId) -> Aabb
pub unsafe fn get_proxy_aabb_unchecked(&self, proxy_id: ProxyId) -> Aabb
Gets the AABB of a proxy in the tree without bounds checking.
§Safety
The caller must ensure that the proxy_id is valid.
Sourcepub fn set_proxy_aabb(&mut self, proxy_id: ProxyId, aabb: Aabb)
pub fn set_proxy_aabb(&mut self, proxy_id: ProxyId, aabb: Aabb)
Updates the AABB of a proxy in the tree.
If the BVH should be refitted at the same time, consider using
resize_proxy_aabb instead.
If resizing a large number of proxies, consider calling this method
for each proxy and then calling refit_all once at the end.
Sourcepub fn resize_proxy_aabb(&mut self, proxy_id: ProxyId, aabb: Aabb)
pub fn resize_proxy_aabb(&mut self, proxy_id: ProxyId, aabb: Aabb)
Resizes the AABB of a proxy in the tree.
This is equivalent to calling set_proxy_aabb
and then refitting the BVH working up from the resized node.
For resizing a large number of proxies, consider calling set_proxy_aabb
for each proxy and then calling refit_all once at the end.
Sourcepub fn reinsert_proxy(&mut self, proxy_id: ProxyId, aabb: Aabb)
pub fn reinsert_proxy(&mut self, proxy_id: ProxyId, aabb: Aabb)
Updates the AABB of a proxy and reinserts it at an optimal place in the tree.
Sourcepub fn rebuild_full(&mut self)
pub fn rebuild_full(&mut self)
Fully rebuilds the tree from the given list of AABBs.
Sourcepub fn rebuild_partial(&mut self, leaves: &[u32])
pub fn rebuild_partial(&mut self, leaves: &[u32])
Rebuilds parts of the tree corresponding to the given list of leaf node indices.
Sourcepub fn optimize(&mut self, batch_size_ratio: f32)
pub fn optimize(&mut self, batch_size_ratio: f32)
Restructures the tree using parallel reinsertion, optimizing node locations based on SAH cost.
This can be used to improve query performance after the tree quality has degraded, for example after many proxy insertions and removals.
Sourcepub fn optimize_candidates(&mut self, candidates: &[u32], iterations: u32)
pub fn optimize_candidates(&mut self, candidates: &[u32], iterations: u32)
Restructures the tree using parallel reinsertion, optimizing node locations based on SAH cost.
Only the specified candidate proxies are considered for reinsertion.
Trait Implementations§
Source§impl Clone for ColliderTree
impl Clone for ColliderTree
Source§fn clone(&self) -> ColliderTree
fn clone(&self) -> ColliderTree
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for ColliderTree
impl Default for ColliderTree
Source§fn default() -> ColliderTree
fn default() -> ColliderTree
Auto Trait Implementations§
impl Freeze for ColliderTree
impl RefUnwindSafe for ColliderTree
impl Send for ColliderTree
impl Sync for ColliderTree
impl Unpin for ColliderTree
impl UnwindSafe for ColliderTree
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.