pub struct DynamicTree { /* private fields */ }Expand description
The dynamic tree structure. (b3DynamicTree)
A dynamic AABB tree broad-phase. Leaf nodes are proxies with an AABB, used to hold a user collision object. Nodes are pooled and relocatable, so node indices are used rather than pointers.
Implementations§
Source§impl DynamicTree
impl DynamicTree
Sourcepub fn create_proxy(
&mut self,
aabb: Aabb,
category_bits: u64,
user_data: u64,
) -> i32
pub fn create_proxy( &mut self, aabb: Aabb, category_bits: u64, user_data: u64, ) -> i32
Create a proxy in the tree as a leaf node. Returns the node index. (b3DynamicTree_CreateProxy)
Sourcepub fn destroy_proxy(&mut self, proxy_id: i32)
pub fn destroy_proxy(&mut self, proxy_id: i32)
Destroy a proxy. This asserts if the id is invalid. (b3DynamicTree_DestroyProxy)
Sourcepub fn move_proxy(&mut self, proxy_id: i32, aabb: Aabb)
pub fn move_proxy(&mut self, proxy_id: i32, aabb: Aabb)
Move a proxy to a new AABB by removing and reinserting into the tree. (b3DynamicTree_MoveProxy)
Sourcepub fn enlarge_proxy(&mut self, proxy_id: i32, aabb: Aabb)
pub fn enlarge_proxy(&mut self, proxy_id: i32, aabb: Aabb)
Enlarge a proxy and enlarge ancestors as necessary. (b3DynamicTree_EnlargeProxy)
Sourcepub fn set_category_bits(&mut self, proxy_id: i32, category_bits: u64)
pub fn set_category_bits(&mut self, proxy_id: i32, category_bits: u64)
Modify the category bits on a proxy. This is an expensive operation. (b3DynamicTree_SetCategoryBits)
Source§impl DynamicTree
impl DynamicTree
Sourcepub fn query(
&self,
aabb: Aabb,
mask_bits: u64,
require_all_bits: bool,
callback: impl FnMut(i32, u64) -> bool,
) -> TreeStats
pub fn query( &self, aabb: Aabb, mask_bits: u64, require_all_bits: bool, callback: impl FnMut(i32, u64) -> bool, ) -> TreeStats
Query an AABB for overlapping proxies. The callback is called for each proxy that overlaps the supplied AABB and passes the mask-bits filter; return false from the callback to stop. (b3DynamicTree_Query)
Sourcepub fn query_closest(
&self,
point: Vec3,
mask_bits: u64,
require_all_bits: bool,
callback: impl FnMut(f32, i32, u64) -> f32,
min_distance_sqr: &mut f32,
) -> TreeStats
pub fn query_closest( &self, point: Vec3, mask_bits: u64, require_all_bits: bool, callback: impl FnMut(f32, i32, u64) -> f32, min_distance_sqr: &mut f32, ) -> TreeStats
Query for the closest proxy to a point. The callback receives the current minimum squared distance and returns an updated distance for that proxy. (b3DynamicTree_QueryClosest)
Sourcepub fn ray_cast(
&self,
input: &RayCastInput,
mask_bits: u64,
require_all_bits: bool,
callback: impl FnMut(&RayCastInput, i32, u64) -> f32,
) -> TreeStats
pub fn ray_cast( &self, input: &RayCastInput, mask_bits: u64, require_all_bits: bool, callback: impl FnMut(&RayCastInput, i32, u64) -> f32, ) -> TreeStats
Ray cast against the proxies in the tree. The callback performs an exact ray cast when the proxy contains a shape, and returns the new ray fraction:
- return 0 to terminate the ray cast
- return a value less than the input max_fraction to clip the ray
- return the input max_fraction to continue without clipping
(b3DynamicTree_RayCast)
Sourcepub fn box_cast(
&self,
input: &BoxCastInput,
mask_bits: u64,
require_all_bits: bool,
callback: impl FnMut(&BoxCastInput, i32, u64) -> f32,
) -> TreeStats
pub fn box_cast( &self, input: &BoxCastInput, mask_bits: u64, require_all_bits: bool, callback: impl FnMut(&BoxCastInput, i32, u64) -> f32, ) -> TreeStats
Cast a swept AABB through the tree. The callback returns the new cast
fraction, with the same semantics as DynamicTree::ray_cast.
(b3DynamicTree_BoxCast)
Source§impl DynamicTree
impl DynamicTree
Source§impl DynamicTree
impl DynamicTree
Sourcepub fn validate_no_enlarged(&self)
pub fn validate_no_enlarged(&self)
Validate this tree has no enlarged AABBs. For testing. (b3DynamicTree_ValidateNoEnlarged)
Source§impl DynamicTree
impl DynamicTree
Sourcepub fn new(proxy_capacity: i32) -> DynamicTree
pub fn new(proxy_capacity: i32) -> DynamicTree
Constructing the tree initializes the node pool. (b3DynamicTree_Create)
Sourcepub fn destroy(&mut self)
pub fn destroy(&mut self)
Destroy the tree, freeing the node pool. (b3DynamicTree_Destroy)
Rust would drop the storage automatically; this mirrors the C function (which leaves a zeroed struct) so ported call sites and tests read the same.
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Dynamic tree version for serialization compatibility. (b3DynamicTree::version / B3_DYNAMIC_TREE_VERSION)
Sourcepub fn node_count(&self) -> i32
pub fn node_count(&self) -> i32
The number of allocated nodes.
Sourcepub fn proxy_count(&self) -> i32
pub fn proxy_count(&self) -> i32
Get the number of proxies created. (b3DynamicTree_GetProxyCount)
Sourcepub fn category_bits(&self, proxy_id: i32) -> u64
pub fn category_bits(&self, proxy_id: i32) -> u64
Get the category bits on a proxy. (b3DynamicTree_GetCategoryBits)
Sourcepub fn area_ratio(&self) -> f32
pub fn area_ratio(&self) -> f32
Get the ratio of the sum of the node areas to the root area. (b3DynamicTree_GetAreaRatio)
Sourcepub fn root_bounds(&self) -> Aabb
pub fn root_bounds(&self) -> Aabb
Get the bounding box that contains the entire tree. (b3DynamicTree_GetRootBounds)
Sourcepub fn byte_count(&self) -> i32
pub fn byte_count(&self) -> i32
Get the number of bytes used by this tree. (b3DynamicTree_GetByteCount)
Matches the C formula, which always counts leafBoxes/binIndices slots even when the median-split heuristic leaves those pointers null.
Sourcepub fn root_index(&self) -> i32
pub fn root_index(&self) -> i32
The root node index, or crate::core::NULL_INDEX for an empty tree.
(b3DynamicTree::root) Exposed read-only for visualization tooling that
walks the tree structure (the Tree Benchmark sample’s depth computation).
Sourcepub fn node_views(&self) -> Vec<TreeNodeView>
pub fn node_views(&self) -> Vec<TreeNodeView>
A read-only snapshot of every node slot in the pool (allocated and free),
indexed identically to the C m_tree.nodes[i] array so a caller can run the
sample’s breadth-first depth walk and per-level AABB draw. This mirrors the
C sample reaching directly into b3DynamicTree::nodes; the internal fields
stay private, so this is the only sanctioned window onto them.
Trait Implementations§
Source§impl Clone for DynamicTree
impl Clone for DynamicTree
Source§fn clone(&self) -> DynamicTree
fn clone(&self) -> DynamicTree
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more